INT69DB_2A/INT69DB_2A/Forms/FormInitialization.cs

453 lines
20 KiB
C#

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using INT69DB_2A_ImageDll;
using INT69DB_2A.Part11_UserManager;
namespace INT69DB_2A.Forms
{
public partial class FormInitialization : Form
{
#region Field
private FormMain m_ParentForm;
private int Time = 0;
#endregion
#region Constructor
public FormInitialization(FormMain parent)
{
InitializeComponent();
this.ParentForm = parent;
this.InitializeDesign();
this.DefaultSetting();
}
#endregion
#region Property
public FormMain ParentForm
{
get { return this.m_ParentForm; }
private set { this.m_ParentForm = value; }
}
#endregion
#region Method
private void InitializeDesign()
{
ImageDll images = new ImageDll();
if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Korean)
{
}
else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.English)
{
this.labelTitle.Text = "Initialization";
this.labelResetWait.Text = "Wait a minute...";
this.labelResetRestart.Text = "Turn OFF the power and then turn ON the power";
this.labelResetFail.Text = "Initialization failed";
}
else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
{
this.labelTitle.Text = "回复出厂设置";
this.labelResetWait.Text = "请稍等...";
this.labelResetRestart.Text = "关掉电源,然后在打开电源";
this.labelResetFail.Text = "初始化失敗";
}
else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
{
this.labelTitle.Text = "初期化";
this.labelResetWait.Text = "しばらくお待ちください。";
this.labelResetRestart.Text = "電源を再起動してください。";
this.labelResetFail.Text = "初期化失敗";
}
else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
{
}
else
{
}
}
private void DefaultSetting()
{
this.progressBarResetBar.Value = 0;
}
private void TransmissionRemoveFile()
{
bool removeFolderCheck = false;
FileInfo[] oldFiles, removeOldFiles;
DirectoryInfo directoryFolderSystem2 = new DirectoryInfo(this.ParentForm.PathSystemFileFolder2);
DirectoryInfo directoryFolderRemove = new DirectoryInfo(this.ParentForm.PathRemoveFileFolder);
removeFolderCheck = directoryFolderRemove.Exists;
oldFiles = directoryFolderSystem2.GetFiles();
if (removeFolderCheck == false)
directoryFolderRemove.Create();
else
{
removeOldFiles = directoryFolderRemove.GetFiles();
if (removeOldFiles.Length >= 100)
{
foreach (FileInfo subFile in removeOldFiles)
subFile.Delete();
}
}
foreach (FileInfo subFile in oldFiles)
subFile.MoveTo(this.ParentForm.PathRemoveFileFolder + DateTime.Now.ToString("yyyyMMddHHmmss") + subFile.Name.ToString());
}
public void ResetConfigurationFile()
{
string fullFilePath = "";
bool fileCheck = false;
StructSystemConfigurationItem structItem1;
StructSystemConfigurationItem1 structItem2;
fullFilePath = this.ParentForm.PathSystemFileFolder1 + "system.cfg";
this.ParentForm.smartFileIO.FilePathName = fullFilePath;
FileInfo fileInfo = new FileInfo(fullFilePath);
fileCheck = fileInfo.Exists;
this.ParentForm.smartFileIO.Open(this.ParentForm.BufferSmartUart);
this.ParentForm.SystemConfig.Initialization();
#region StructItem1
structItem1.IsDataBackup = this.ParentForm.SystemConfig.IsDataBackup;
structItem1.IsPingTimer = this.ParentForm.SystemConfig.IsPingTimer;
structItem1.IsFeedingConveyor = this.ParentForm.SystemConfig.IsFeedingConveyor;
structItem1.IsEachNG = this.ParentForm.SystemConfig.IsEachNG;
structItem1.IsDischargeConveyor = this.ParentForm.SystemConfig.IsDischargeConveyor;
structItem1.IsImpellerMotorDirectionCW = this.ParentForm.SystemConfig.IsImpellerMotorDirectionCW;
structItem1.IsPart11 = this.ParentForm.SystemConfig.IsPart11;
structItem1.IsWeightViewForward = this.ParentForm.SystemConfig.IsWeightViewForward;
structItem1.DecimalPlaces = this.ParentForm.SystemConfig.DecimalPlaces;
structItem1.EthernetPort = this.ParentForm.SystemConfig.EthernetPort;
structItem1.EquipmentColumns = this.ParentForm.SystemConfig.EquipmentColumns;
structItem1.EquipmentID = this.ParentForm.SystemConfig.EquipmentID;
structItem1.EquipmentMode = this.ParentForm.SystemConfig.EquipmentMode;
structItem1.ProductNumber = this.ParentForm.SystemConfig.ProductNumber;
structItem1.DummyInt1 = 1;
structItem1.DischargeConveyorDirectionCW = (int)this.ParentForm.SystemConfig.DischargeConveyorDirectionCW;
structItem1.UsbID = this.ParentForm.SystemConfig.UsbID;
structItem1.DummyString6 = "";
structItem1.Unit = this.ParentForm.SystemConfig.Unit;
structItem1.Language = this.ParentForm.SystemConfig.Language;
structItem1.ImpellerMotorBaudrate = this.ParentForm.SystemConfig.ImpellerMotorBaudrate;
structItem1.ImpellerMotorAnglePass = this.ParentForm.SystemConfig.ImpellerMotorAnglePass;
structItem1.SerialNumber = this.ParentForm.SystemConfig.SerialNumber;
// Dummy bool
structItem1.IsEmergencyStopEntrySensorError = this.ParentForm.SystemConfig.IsEmergencyStopEntrySensorError;
structItem1.IsIntegratedTransmission = this.ParentForm.SystemConfig.IsIntegratedTransmission;
structItem1.IsLogin = this.ParentForm.SystemConfig.IsLogin;
structItem1.IsFeedingConveyorRunPass = this.ParentForm.SystemConfig.IsFeedingConveyorRunPass;
// Dummy int
structItem1.StepMotorType = this.ParentForm.SystemConfig.StepMotorType;
structItem1.ImpellerMotorAngleNG = this.ParentForm.SystemConfig.ImpellerMotorAngleNG;
structItem1.InputSensorSelect = this.ParentForm.SystemConfig.InputSensorSelect;
structItem1.Serial3BaudRate = this.ParentForm.SystemConfig.Serial3BaudRate;
structItem1.Serial3Mode = this.ParentForm.SystemConfig.Serial3Mode;
// Dummy string
structItem1.User_Level1_Name = this.ParentForm.SystemConfig.User_Level1_Name;
structItem1.User_Level2_Name = this.ParentForm.SystemConfig.User_Level2_Name;
structItem1.User_Level3_Name = this.ParentForm.SystemConfig.User_Level3_Name;
structItem1.DummyString4 = "";
structItem1.DummyString5 = "";
#endregion
this.ParentForm.smartFileIO.WriteStructure(structItem1, 0);
#region StructItem2
structItem2.DummyBool1 = false;
structItem2.DummyBool2 = false;
structItem2.DummyBool3 = false;
structItem2.DummyBool4 = false;
structItem2.DummyBool5 = false;
structItem2.DummyBool6 = false;
structItem2.DummyBool7 = false;
structItem2.DummyBool8 = false;
structItem2.DummyBool9 = false;
structItem2.DummyBool10 = false;
structItem2.DummyBool11 = false;
structItem2.DummyBool12 = false;
structItem2.DummyBool13 = false;
structItem2.DummyBool14 = false;
structItem2.DummyBool15 = false;
structItem2.DummyBool16 = false;
structItem2.DummyBool17 = false;
structItem2.DummyBool18 = false;
structItem2.IsAlarmContinuousNGEnable = this.ParentForm.SystemConfig.IsAlarmContinuousNGEnable;
structItem2.IsAlarmTotalPassCntEnable = this.ParentForm.SystemConfig.IsAlarmTotalPassCntEnable;
structItem2.DummyInt1 = 0;
structItem2.DummyInt2 = 0;
structItem2.DummyInt3 = 0;
structItem2.DummyInt4 = 0;
structItem2.DummyInt5 = 0;
structItem2.DummyInt6 = 0;
structItem2.DummyInt7 = 0;
structItem2.AlarmContinuousNG = this.ParentForm.SystemConfig.AlarmContinuousNG;
structItem2.AlarmTotalPassCnt = this.ParentForm.SystemConfig.AlarmTotalPassCnt;
structItem2.ModbusTcpStartAddress = this.ParentForm.SystemConfig.ModbusTcpStartAddress;
structItem2.ModbusRtuSlaveID = this.ParentForm.SystemConfig.ModbusRtuSlaveID;
structItem2.ModbusTcpAddress1 = this.ParentForm.SystemConfig.ModbusTcpAddress1;
structItem2.ModbusTcpAddress2 = this.ParentForm.SystemConfig.ModbusTcpAddress2;
structItem2.EthernetLocalPort = this.ParentForm.SystemConfig.EthernetLocalPort;
structItem2.EthernetOperationMode = this.ParentForm.SystemConfig.EthernetOperationMode;
structItem2.EthernetMode = this.ParentForm.SystemConfig.EthernetMode;
structItem2.EthernetServerPort = this.ParentForm.SystemConfig.EthernetServerPort;
structItem2.DummyInt10 = 0;
structItem2.AutomaticLogout = this.ParentForm.SystemConfig.AutomaticLogout;
structItem2.DataStoragePeriod = this.ParentForm.SystemConfig.DataStoragePeriod;
structItem2.DummyString1 = "";
structItem2.DummyString2 = "";
structItem2.DummyString3 = "";
structItem2.DummyString4 = "";
structItem2.DummyString5 = "";
structItem2.EthernetServerAddress = this.ParentForm.SystemConfig.EthernetServerAddress;
structItem2.DummyString7 = "";
structItem2.DummyString8 = "";
structItem2.DummyString9 = "";
structItem2.DummyString10 = "";
#endregion
this.ParentForm.smartFileIO.WriteStructure(structItem2, 1);
this.ParentForm.smartFileIO.Close();
}
public void ResetProductFile()
{
bool fileCheck = false;
string fullFilePath = "";
StructProductItem structItem;
fullFilePath = this.ParentForm.PathSystemFileFolder2 + "ProductItem.int";
this.ParentForm.smartFileIO.FilePathName = fullFilePath;
FileInfo fileInfo = new FileInfo(fullFilePath);
fileCheck = fileInfo.Exists;
this.ParentForm.smartFileIO.Open(this.ParentForm.BufferSmartUart);
this.ParentForm.CurrentProductItem.Initialization();
for (int i = 0; i < 1000; i++)
{
structItem.Number = i + 1;
structItem.Name = string.Format("Product {0}", i + 1);
structItem.LotNo = string.Format("Lot {0}", i + 1);
structItem.OverRange = this.ParentForm.CurrentProductItem.OverRange;
structItem.PassRange = this.ParentForm.CurrentProductItem.PassRange;
structItem.UnderRange = this.ParentForm.CurrentProductItem.UnderRange;
structItem.TareRange = this.ParentForm.CurrentProductItem.TareRange;
structItem.DummyString1 = "";
structItem.DummyString2 = "";
structItem.DummyString3 = "";
structItem.DummyString4 = "";
structItem.DummyString5 = "";
structItem.DummyString6 = "";
structItem.DummyString7 = "";
structItem.DummyString8 = "";
this.ParentForm.smartFileIO.WriteStructure_Begin(structItem, i);
if (i % 50 == 0)
this.progressBarResetBar.Value += 1;
}
this.ParentForm.smartFileIO.WriteStructure_End();
this.ParentForm.smartFileIO.Close();
}
public void ResetJudgmentSetFile()
{
bool fileCheck = false;
string fullFilePath = "";
StructJudgmentSetItem structItem;
fullFilePath = this.ParentForm.PathSystemFileFolder2 + "JudgmentSetItem.int";
this.ParentForm.smartFileIO.FilePathName = fullFilePath;
FileInfo fileInfo = new FileInfo(fullFilePath);
fileCheck = fileInfo.Exists;
this.ParentForm.smartFileIO.Open(this.ParentForm.BufferSmartUart);
this.ParentForm.CurrentJudgmentSetItem.Initialization();
for (int i = 0; i < 1000; i++)
{
structItem.Filter = this.ParentForm.CurrentJudgmentSetItem.Filter;
structItem.JudgmentDelayTime = this.ParentForm.CurrentJudgmentSetItem.JudgmentDelayTime;
structItem.DoubleDelayTime = this.ParentForm.CurrentJudgmentSetItem.DoubleDelayTime;
structItem.JudgmentCount = this.ParentForm.CurrentJudgmentSetItem.JudgmentCount;
structItem.FeedSpeed = this.ParentForm.CurrentJudgmentSetItem.FeedSpeed;
structItem.DynamicCorrection = this.ParentForm.CurrentJudgmentSetItem.DynamicCorrection;
structItem.RejectConveyorDelayTime = this.ParentForm.CurrentJudgmentSetItem.RejectConveyorDelayTime;
structItem.RejectConveyorOperatingTime = this.ParentForm.CurrentJudgmentSetItem.RejectConveyorRunTime;
structItem.FeedingConveyorDelayTime = this.ParentForm.CurrentJudgmentSetItem.RejectConveyorDelayTime;
structItem.FeedingConveyorOperatingTime = this.ParentForm.CurrentJudgmentSetItem.RejectConveyorRunTime;
structItem.Sorter1Mode = this.ParentForm.CurrentJudgmentSetItem.Sorter1Mode;
structItem.Sorter1DelayTime = this.ParentForm.CurrentJudgmentSetItem.Sorter1DelayTime;
structItem.Sorter1OperatingTime = this.ParentForm.CurrentJudgmentSetItem.Sorter1RunTime;
structItem.Sorter2Mode = this.ParentForm.CurrentJudgmentSetItem.Sorter2Mode;
structItem.Sorter2DelayTime = this.ParentForm.CurrentJudgmentSetItem.Sorter2DelayTime;
structItem.Sorter2OperatingTime = this.ParentForm.CurrentJudgmentSetItem.Sorter2RunTime;
structItem.Sorter3Mode = this.ParentForm.CurrentJudgmentSetItem.Sorter3Mode;
structItem.Sorter3DelayTime = this.ParentForm.CurrentJudgmentSetItem.Sorter3DelayTime;
structItem.Sorter3OperatingTime = this.ParentForm.CurrentJudgmentSetItem.Sorter3RunTime;
structItem.Sorter4Mode = this.ParentForm.CurrentJudgmentSetItem.Sorter4Mode;
structItem.Sorter4DelayTime = this.ParentForm.CurrentJudgmentSetItem.Sorter4DelayTime;
structItem.Sorter4OperatingTime = this.ParentForm.CurrentJudgmentSetItem.Sorter4RunTime;
structItem.DummyInt1 = 0;
structItem.DummyInt2 = 0;
structItem.DummyInt3 = 0;
structItem.DummyInt4 = 0;
structItem.ForcedZeroDelayTime = this.ParentForm.CurrentJudgmentSetItem.ForcedZeroDelayTime;
structItem.DummyString1 = "";
structItem.DummyString2 = "";
structItem.DummyString3 = "";
structItem.DummyString4 = "";
structItem.DummyString5 = "";
this.ParentForm.smartFileIO.WriteStructure_Begin(structItem, i);
if (i % 50 == 0)
this.progressBarResetBar.Value += 1;
}
this.ParentForm.smartFileIO.WriteStructure_End();
this.ParentForm.smartFileIO.Close();
}
public void ResetCountFile()
{
string fullFilePath = "";
bool fileCheck = false;
StructCounter structItem;
fullFilePath = this.ParentForm.PathSystemFileFolder2 + "counterItem.int";
this.ParentForm.smartFileIO.FilePathName = fullFilePath;
FileInfo fileInfo = new FileInfo(fullFilePath);
fileCheck = fileInfo.Exists;
this.ParentForm.smartFileIO.Open(this.ParentForm.BufferSmartUart);
for (int i = 0; i < 1000; i++)
{
structItem.OverCount1 = 0;
structItem.PassCount1 = 0;
structItem.UnderCount1 = 0;
structItem.ExNGCount1 = 0;
structItem.OverCount2 = 0;
structItem.PassCount2 = 0;
structItem.UnderCount2 = 0;
structItem.ExNGCount2 = 0;
structItem.OverCount3 = 0;
structItem.PassCount3 = 0;
structItem.UnderCount3 = 0;
structItem.ExNGCount3 = 0;
structItem.OverCount4 = 0;
structItem.PassCount4 = 0;
structItem.UnderCount4 = 0;
structItem.ExNGCount4 = 0;
structItem.OverCount5 = 0;
structItem.PassCount5 = 0;
structItem.UnderCount5 = 0;
structItem.ExNGCount5 = 0;
structItem.OverCount6 = 0;
structItem.PassCount6 = 0;
structItem.UnderCount6 = 0;
structItem.ExNGCount6 = 0;
structItem.DummyInt1 = 0;
structItem.DummyInt2 = 0;
structItem.DummyInt3 = 0;
structItem.DummyInt4 = 0;
structItem.DummyInt5 = 0;
structItem.DummyInt6 = 0;
structItem.DummyInt7 = 0;
structItem.DummyInt8 = 0;
structItem.DummyInt9 = 0;
structItem.DummyInt10 = 0;
this.ParentForm.smartFileIO.WriteStructure_Begin(structItem, i);
if (i % 50 == 0)
this.progressBarResetBar.Value += 1;
}
this.ParentForm.smartFileIO.WriteStructure_End();
this.ParentForm.smartFileIO.Close();
}
private void ResetUserListFile()
{
UserManager.UserManager_UserAllDel();
}
public void DisplayRefresh()
{
this.ParentForm.SystemConfig.CurrentForm = DataStore.FormStore.FormFactory;
this.labelResetWait.Visible = true;
this.labelResetRestart.Visible = false;
this.progressBarResetBar.Value = 0;
this.TransmissionRemoveFile();
this.ResetUserListFile();
this.progressBarResetBar.Value += 10;
this.ResetProductFile();
this.progressBarResetBar.Value += 10;
this.ResetJudgmentSetFile();
this.progressBarResetBar.Value += 10;
this.ResetCountFile();
this.progressBarResetBar.Value = 100;
this.labelResetWait.Visible = false;
this.labelResetRestart.Visible = true;
}
#endregion
#region Event Handler
private void timer1_Tick(object sender, EventArgs e)
{
this.Time++;
if (this.Time == 2)
{
this.ParentForm.ChildFormFactoryInitialize.DisplayRefresh();
this.timer1.Enabled = false;
this.Time = 0;
}
}
private void buttonBack_Click(object sender, EventArgs e)
{
this.ParentForm.ChildFormMenu.DisplayRefresh();
((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormMenu);
}
#endregion
}
}