using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using System.Collections.ObjectModel; using System.IO; using SmartX; using INT_LKD.Forms; using INT_LKD.DataStore; using INT_LKD.DialogForms; namespace INT_LKD.Controls { public partial class ControlMenuLogHistory : UserControl { #region Field private string SelectedNodeFullPath; private int ListBoxCount; private FormMenu m_ParentForm; private Define.E_DataType CurrentDataType; private List ListHistoryFile; private Collection CollectionListBox; #endregion #region Constructor public ControlMenuLogHistory(FormMenu parent) { InitializeComponent(); this.ParentForm = parent; this.Initialize(); this.DefaultSetting(); this.InitializeDesign(); } #endregion #region Property public FormMenu ParentForm { get { return this.m_ParentForm; } private set { this.m_ParentForm = value; } } #endregion #region Method private void Initialize() { } private void DefaultSetting() { this.CurrentDataType = Define.E_DataType.History; this.ListBoxCount = 0; this.ListHistoryFile = new List(); this.CollectionListBox = new Collection(); this.CollectionListBox.Clear(); this.CollectionListBox.Add(this.listBoxTime); this.CollectionListBox.Add(this.listBoxLoginID); this.CollectionListBox.Add(this.listBoxEvent); this.CollectionListBox.Add(this.listBoxDetail); this.CollectionListBox.Add(this.listBoxBefore); this.CollectionListBox.Add(this.listBoxAfter); this.CollectionListBox.Add(this.listBoxType); } public void InitializeDesign() { switch (this.ParentForm.ParentForm.SystemConfig.LANGUAGE) { case Define.E_LanguageID.Chinese: this.smartGroupBox1.Text = "日志 > 历史"; this.labelTitleList.Text = "档案清单"; this.labelTitleFileName.Text = "文件名"; this.labelTitleTime.Text = "时间"; this.labelTitleID.Text = "用户名"; this.labelTitleEvent.Text = "事件"; this.labelTitleDetail.Text = "细节"; this.labelTitleBefore.Text = "之前"; this.labelTitleAfter.Text = "之后"; this.labelTitleType.Text = "类型"; this.buttonBackup.ButtonText = "备份"; break; default: this.smartGroupBox1.Text = "Log > History"; this.labelTitleList.Text = "List"; this.labelTitleFileName.Text = "File name"; this.labelTitleTime.Text = "Time"; this.labelTitleID.Text = "ID"; this.labelTitleEvent.Text = "Event"; this.labelTitleDetail.Text = "Detail"; this.labelTitleBefore.Text = "Before"; this.labelTitleAfter.Text = "After"; this.labelTitleType.Text = "Type"; this.buttonBackup.ButtonText = "Backup"; break; } } public void LoadFile(string fullFilePath) { if (fullFilePath.Contains("_History") == false) return; this.smartFile1.FilePathName = fullFilePath; this.smartFile1.Open(); this.smartFile1.StringType.EncodingType = SmartX.SmartFile.Encodings.ANSI; try { this.smartFile1.StringType.FillBuffer(); long lineNum = this.smartFile1.StringType.GetCount(); this.ListBoxCount = (int)lineNum; for (int i = 1; i < lineNum; i++) { this.UpdateListBoxDataDisplay(this.smartFile1.StringType.ReadBuffer(i)); } } catch { DialogFormMessage myMsg = new DialogFormMessage(16, this.ParentForm.ParentForm.SystemConfig.LANGUAGE); myMsg.ShowDialog(); this.smartFile1.Close(); } this.smartFile1.Close(); } private void UpdateListBoxCount() { this.labelTotalIndex.Text = (this.ListBoxCount - 1).ToString(); if (this.ListBoxCount - 1 - this.listBoxTime.ViewRemainCount < 0) this.labelRemainIndex.Text = "0"; else this.labelRemainIndex.Text = (this.ListBoxCount - 1 - this.listBoxTime.ViewRemainCount).ToString(); } private void UpdateListBoxDataDisplay(string data) { if (data.Contains(",") == false) return; string[] sb = data.Split(','); // Date-생략, Time, LoginID, Event, Detail, Before, After, Type for (int i = 0; i < this.CollectionListBox.Count; i++) this.CollectionListBox[i].AddItem(sb[i + 1]); } private void UpdateDisplayFile() { int fileCount = 0; //TreeNode node; List years = new List(); List months = new List(); List days = new List(); this.treeView.Nodes.Clear(); this.ListHistoryFile.Clear(); DirectoryInfo dir = new DirectoryInfo(this.ParentForm.ParentForm.PathDataHistoryFolder); List fileNames = new List(); // 폴더 체크 if (dir.Exists == false) dir.Create(); // year 폴더 가져오기 DirectoryInfo[] yearDirectorys = dir.GetDirectories(); // year 폴더 정렬 years = this.ParentForm.DirectorySort(yearDirectorys); // Inspection File 리스트 생성 if (years.Count != 0) { // Year foreach (string year in years) { DataBackupYear y = new DataBackupYear(year); DirectoryInfo monthDir = new DirectoryInfo(string.Format("{0}{1}", this.ParentForm.ParentForm.PathDataHistoryFolder, year)); DirectoryInfo[] monthDirectorys = monthDir.GetDirectories(); months = this.ParentForm.DirectorySort(monthDirectorys); if (months.Count != 0) { // Month foreach (string month in months) { DirectoryInfo dayDir = new DirectoryInfo(string.Format("{0}{1}\\{2}", this.ParentForm.ParentForm.PathDataHistoryFolder, year, month)); FileInfo[] dayFiles = dayDir.GetFiles(); days = this.DayHistoryDirectorySort(dayFiles); DataBackupMonth m = new DataBackupMonth(month); m.Days = days; y.Months.Add(m); } this.ListHistoryFile.Add(y); } else { this.ListHistoryFile.Add(y); } } // node 생성 for (int i = 0; i < this.ListHistoryFile.Count; i++) { TreeNode node = new TreeNode(this.ListHistoryFile[i].Year); for (int j = 0; j < this.ListHistoryFile[i].Months.Count; j++) { TreeNode nodeMonth = new TreeNode(this.ListHistoryFile[i].Months[j].Month); for (int k = 0; k < this.ListHistoryFile[i].Months[j].Days.Count; k++) { nodeMonth.Nodes.Add(this.ListHistoryFile[i].Months[j].Days[k]); fileCount++; } node.Nodes.Add(nodeMonth); } this.treeView.Nodes.Add(node); } } this.labelCount.Text = fileCount.ToString(); } private List DayHistoryDirectorySort(FileInfo[] files) { List listFile = new List(); Dictionary dirNames = new Dictionary(); Dictionary dirNamesSort = new Dictionary(); foreach (FileInfo file in files) { if (file.Name.StartsWith("20") == true) dirNames.Add(file.Name, int.Parse(file.Name.Substring(0, 8))); } var vrList = dirNames.Keys.ToList(); vrList.Sort(); foreach (var v in vrList) dirNamesSort.Add(v, dirNames[v]); foreach (var v in dirNamesSort) listFile.Add(v.Key); return listFile; } public void DisplayRefresh() { this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplayMode = Define.E_DisplayModeStore.LogHistory; this.ParentForm.ParentForm.SetDisplayMode(Define.E_EquipmentMode.Menu); this.UpdateDisplayFile(); this.treeView.ExpandAll(); this.labelRemainIndex.Text = "0"; this.labelTotalIndex.Text = "0"; // User switch (this.ParentForm.ParentForm.CurrentSystemStatus.CurrentUser.Group) { case Define.E_UserGroup.None: this.Enabled = false; break; case Define.E_UserGroup.Level1: this.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level1.IsMenuAlarmLog; break; case Define.E_UserGroup.Level2: this.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level2.IsMenuAlarmLog; break; case Define.E_UserGroup.Level3: this.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMenuAlarmLog; break; case Define.E_UserGroup.Admin: this.Enabled = this.ParentForm.ParentForm.CurrentUserGroup.Level3.IsMenuAlarmLog; break; case Define.E_UserGroup.Developer: this.Enabled = true; break; case Define.E_UserGroup.NotLogin: this.Enabled = false; break; case Define.E_UserGroup.LogOut: this.Enabled = false; break; default: break; } } #endregion #region Event Handler private void treeViewHistory_AfterSelect(object sender, TreeViewEventArgs e) { this.labelFileName.Text = e.Node.Text; this.SelectedNodeFullPath = this.treeView.SelectedNode.FullPath; for (int i = 0; i < this.CollectionListBox.Count; i++) this.CollectionListBox[i].ClearAll(); this.LoadFile(this.ParentForm.ParentForm.PathDataHistoryFolder + this.treeView.SelectedNode.FullPath); this.UpdateListBoxCount(); } private void buttonBackup_Click(object sender, EventArgs e) { if (this.labelFileName.Text == "") return; this.ParentForm.FileCopy(Define.E_DataType.History, this.SelectedNodeFullPath); } private void buttonUp_Click(object sender, EventArgs e) { for (int i = 0; i < this.CollectionListBox.Count; i++) this.CollectionListBox[i].ScrollUp(); this.UpdateListBoxCount(); } private void buttonDown_Click(object sender, EventArgs e) { for (int i = 0; i < this.CollectionListBox.Count; i++) this.CollectionListBox[i].ScrollDown(); this.UpdateListBoxCount(); } #endregion } }