ITC81DB_2H/ITC81DB_0H/Controls/CenterBasic/ControlCenterBasicDataBacku...

285 lines
10 KiB
C#

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.IO;
using System.Text;
using System.Windows.Forms;
using SmartX;
using ITC81DB_0H.Forms;
using ITC81DB_0H.DialogForms;
using ITC81DB_0H_ImageDll;
namespace ITC81DB_0H.Controls
{
public partial class ControlCenterBasicDataBackup : UserControl
{
#region Field
private FormMenu m_ParentForm;
private int FileIndex;
#endregion
#region Constructor
public ControlCenterBasicDataBackup(FormMenu parent)
{
InitializeComponent();
this.ParentForm = parent;
this.InitializeDesign();
this.DefaultSetting();
}
#endregion
#region Property
public FormMenu ParentForm
{
get { return this.m_ParentForm; }
private set { this.m_ParentForm = value; }
}
#endregion
#region Method
public void InitializeDesign()
{
Class1 images = new Class1();
if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.English)
{
this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.engBackgroundDataBackup));
this.buttonDataBackupEnable.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON_Black));
this.buttonDataBackupEnable.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF_Black));
}
else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese)
{
this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.chnBackgroundDataBackup));
this.buttonDataBackupEnable.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnON_Black));
this.buttonDataBackupEnable.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.chnOFF_Black));
}
else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Czech)
{
}
else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Russian)
{
this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.rusBackgroundDataBackup));
this.buttonDataBackupEnable.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusON_Black));
this.buttonDataBackupEnable.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.rusOFF_Black));
}
else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German)
{
this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.gerBackgroundDataBackup));
this.buttonDataBackupEnable.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerON_Black));
this.buttonDataBackupEnable.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.gerOFF_Black));
}
else
{
this.smartGroupBox1.Image = new Bitmap(images.GetImage(Class1.ButtonImages.korBackgroundDataBackup));
this.buttonDataBackupEnable.DownImage = new Bitmap(images.GetImage(Class1.ButtonImages.engON_Black));
this.buttonDataBackupEnable.UpImage = new Bitmap(images.GetImage(Class1.ButtonImages.engOFF_Black));
}
}
private void DefaultSetting()
{
this.FileIndex = 0;
}
private void FileCopy(FileInfo file, string fileName)
{
try
{
if (this.FileIndex == 0)
{
file.CopyTo(fileName);
this.FileIndex = 0;
}
else
{
file.CopyTo(fileName.Insert(fileName.Length - 4, "_" + this.FileIndex.ToString()));
this.FileIndex = 0;
}
}
catch
{
this.FileIndex++;
this.FileCopy(file, fileName);
}
}
public void DisplayRefresh(SystemStatus status)
{
bool directoryCheck = false;
this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = DataStore.DisplayStore.BasicDataBackup;
this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus);
this.ParentForm.ParentForm.SetDisplayMode(DataStore.DisplayMode.Menu);
DirectoryInfo dir = new DirectoryInfo(this.ParentForm.ParentForm.PathDataBackupFolder);
directoryCheck = dir.Exists;
// 폴더 체크
if (directoryCheck == false)
dir.Create();
FileInfo[] files = dir.GetFiles();
this.listBoxDataList.Items.Clear();
foreach (FileInfo file in files)
{
if (file.Name.StartsWith("20") == true || file.Name.StartsWith("Communicationlog") == true || file.Name.EndsWith(".jpg") == true || file.Name.EndsWith(".txt") == true)
this.listBoxDataList.Items.Add(file.Name);
}
if (this.ParentForm.ParentForm.SystemConfig1.IsDataBackup == true)
this.buttonDataBackupEnable.ButtonDown();
else
this.buttonDataBackupEnable.ButtonUp();
this.labelFileCount.Text = this.listBoxDataList.Items.Count.ToString();
this.labelUsbId.Text = this.ParentForm.ParentForm.SystemConfig1.UsbID.ToString();
}
#endregion
#region Event Handler
private void buttonDataBackupEnable_Click(object sender, EventArgs e)
{
if (this.ParentForm.ParentForm.SystemConfig1.IsDataBackup == true)
{
this.ParentForm.ParentForm.SystemConfig1.IsDataBackup = false;
this.buttonDataBackupEnable.ButtonUp();
}
else
{
this.ParentForm.ParentForm.SystemConfig1.IsDataBackup = true;
this.buttonDataBackupEnable.ButtonDown();
}
this.ParentForm.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.ParentForm.SystemConfig1);
}
private void labelUsbId_Click(object sender, EventArgs e)
{
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelUsbId.Text, 2, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 99)
{
// 입력범위를 확인하세요
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language);
myMsg.ShowDialog();
}
else
{
this.labelUsbId.Text = myKeyPad.doubleValue.ToString();
this.ParentForm.ParentForm.SystemConfig1.UsbID = myKeyPad.IntValue;
this.ParentForm.ParentForm.SaveSystemConfigurationFile1(this.ParentForm.ParentForm.SystemConfig1);
}
}
}
private void buttonBackup_Click(object sender, EventArgs e)
{
int count = 0;
bool directoryCheck = false;
string filePath = "";
DirectoryInfo dir = new DirectoryInfo(this.ParentForm.ParentForm.PathDataBackupFolder);
directoryCheck = dir.Exists;
// 폴더 체크
if (directoryCheck == false)
dir.Create();
FileInfo[] checkLogFiles = dir.GetFiles();
this.ParentForm.ParentForm.smartFileCommunicationLog.Close();
this.ParentForm.ParentForm.IsCommunicationLogOpen = false;
this.ParentForm.ParentForm.smartFileCheckLog.Close();
this.ParentForm.ParentForm.IsErrorLogOpen = false;
count = this.listBoxDataList.Items.Count;
if (count == 0 && checkLogFiles.Length == 0)
{
DialogFormMessage msg = new DialogFormMessage(4, this.ParentForm.ParentForm.SystemConfig1.Language);
msg.ShowDialog();
return;
}
SmartSplash splash = new SmartSplash();
splash.CenterPosition = true;
splash.AnimationInterval = 200;
splash.LoadingImagePathname = "SmartLoading4";
splash.Start();
try
{
DirectoryInfo dinfo = new DirectoryInfo("하드 디스크\\");
dinfo.GetDirectories();
}
catch
{
splash.Finish();
DialogFormMessage msg = new DialogFormMessage(5, this.ParentForm.ParentForm.SystemConfig1.Language);
msg.ShowDialog();
return;
}
try
{
filePath = "하드 디스크\\";
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
if (file.Name.StartsWith("20") == true || file.Name.StartsWith("Communicationlog") == true
|| file.Name.EndsWith(".jpg") == true || file.Name.EndsWith(".txt") == true)
{
this.FileCopy(file, filePath + file.Name);
this.listBoxDataList.Items.Remove(file.Name);
file.Delete();
}
else if (file.Name.Contains("Checklog") == true)
{
this.FileCopy(file, filePath + file.Name);
file.Delete();
}
}
this.labelFileCount.Text = this.listBoxDataList.Items.Count.ToString();
// CheckLog
//this.ParentForm.ParentForm.smartFileCheckLog.Open();
//this.ParentForm.ParentForm.IsErrorLogOpen = true;
splash.Finish();
DialogFormMessage msg = new DialogFormMessage(count.ToString(), this.ParentForm.ParentForm.SystemConfig1.Language);
msg.ShowDialog();
}
catch
{
splash.Finish();
DialogFormMessage msg = new DialogFormMessage(6, this.ParentForm.ParentForm.SystemConfig1.Language);
msg.ShowDialog();
return;
}
}
#endregion
}
}