You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
excelImport/Source/ExcelImprot/Dialog/StartupDialog.cs

132 lines
3.7 KiB

3 years ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ExcelImprot.Dialog
{
public partial class StartupDialog : Form
{
private delegate void PropertyDelegate(Control objMother, Control objControl, EnableType eType, bool bValue);
private delegate void MessageDelegate(string strMessage);
private delegate void Startup_Act();
private MainWindow _wndMain;
bool _bControllerInitialized = true;
public StartupDialog()
{
InitializeComponent();
InitVariables();
}
private void InitVariables()
{
ShowMessage("프로그램 구동을 준비합니다.");
prgBar.Style = ProgressBarStyle.Marquee;
prgBar.MarqueeAnimationSpeed = 30;
bgwInitializer.WorkerSupportsCancellation = true;
bgwInitializer.RunWorkerAsync();
}
private void Initialize()
{
_bControllerInitialized = MainController.GetInstance().Initialize();
//Application.Idle += FinishingDialog;
}
private void FinishingDialog()
{
//Application.Idle -= FinishingDialog;
if (!_bControllerInitialized)
{
ShowMessage("프로그램 구동준비에 실패하였습니다. 프로그램을 종료합니다.");
Exit();
return;
}
ShowMessage("프로그램 구동 준비가 완료되었습니다. 프로그램을 시작합니다.");
EnableProperty(this, this, EnableType.Visible, false);
_wndMain = new MainWindow();
EnableProperty(this, _wndMain, EnableType.Visible, true);
}
private void EnableProperty(Control objMother, Control objControl, EnableType eType, bool bValue)
{
if (objMother.InvokeRequired)
{
PropertyDelegate objDelegate = new PropertyDelegate(EnableProperty);
objMother.Invoke(objDelegate, new object[] { objMother, objControl, eType, bValue });
}
else
{
switch (eType)
{
case EnableType.Enabled:
objControl.Enabled = bValue;
break;
case EnableType.Visible:
objControl.Visible = bValue;
break;
default:
break;
}
}
}
private void ShowMessage(string strMessage)
{
if (InvokeRequired)
{
MessageDelegate objDelegate = new MessageDelegate(ShowMessage);
Invoke(objDelegate, strMessage);
}
else
{
txtCurrentMessage.Text = strMessage;
Application.DoEvents();
}
}
private void Exit()
{
if (MainController.GetInstance().OpenedExcel != null)
MainController.GetInstance().OpenedExcel.CloseOpenedExcel();
Application.ExitThread();
Application.Exit();
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
private void bgwInitializer_DoWork(object sender, DoWorkEventArgs e)
{
Initialize();
}
private void bgwInitializer_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
FinishingDialog();
}
}
public enum EnableType
{
Visible,
Enabled
}
}