using System; using System.Linq; using System.Collections.ObjectModel; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.IO; using System.Text; using System.Windows.Forms; using System.Threading; using SmartX; using ITC81DB_0H.Forms; using ITC81DB_0H.DialogForms; using ITC81DB_2H_ImageDll; using ITC81DB_2H.Datastore; namespace ITC81DB_0H.Controls { public partial class ControlCenterLogHistory : UserControl { #region Field private FormMenu m_ParentForm; private int FileIndex; private int TotalCount; private int CurrentCount; private static int ListBoxLineCount = 16; // 화면에 보여지는 listBox 줄 수 private string SelectedNodeFullPath; private List ListHistoryFile; private Collection CollectionListBox; private Collection CollectionData; // 파일에서 읽은 데이터 private List ListTime; private List ListLoginID; private List ListEvent; private List ListDetail; #endregion #region Constructor public ControlCenterLogHistory(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() { if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.English) { this.labelTitleFileList.Text = "File List"; this.labelTitleFileName.Text = "File name"; this.labelTitleFind.Text = "Search line"; } else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Chinese) { this.labelTitleFileList.Text = "档案清单"; this.labelTitleFileName.Text = "文件名"; this.labelTitleFind.Text = "搜索行"; } else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Czech) { this.labelTitleFileList.Text = "File List"; this.labelTitleFileName.Text = "File name"; this.labelTitleFind.Text = "Vyhledávací řádek"; } else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Russian) { this.labelTitleFileList.Text = "Список файлов"; this.labelTitleFileName.Text = "Имя файла"; this.labelTitleFind.Text = "Строка поиска"; } else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.German) { this.labelTitleFileList.Text = "Dateiliste"; this.labelTitleFileName.Text = "Dateinamen"; this.labelTitleFind.Text = "Suchzeile"; } else if (this.ParentForm.ParentForm.SystemConfig1.Language == Define.E_LanguageID.Spanish) { this.labelTitleFileList.Text = "Lista de archivos"; this.labelTitleFileName.Text = "Nombre del archivo"; this.labelTitleFind.Text = "Línea de búsqueda"; } else { this.labelTitleFileList.Text = "파일 목록"; this.labelTitleFileName.Text = "파일 이름"; this.labelTitleFind.Text = "Search line"; } } private void DefaultSetting() { this.FileIndex = 0; this.TotalCount = 0; this.ListHistoryFile = new List(); this.CollectionData = new Collection(); this.ListTime = new List(); this.ListLoginID = new List(); this.ListEvent = new List(); this.ListDetail = 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); } private void UpdateListBoxCount() { this.labelTotalIndex.Text = this.TotalCount.ToString(); this.labelCurrentIndex.Text = this.CurrentCount.ToString(); } private void UpdateListBoxDataDisplay(string data) { if (data.Contains(",") == false) return; string[] sb = data.Split(','); string temp = ""; this.listBoxTime.AddItem(sb[1]); this.listBoxLoginID.AddItem(sb[2]); this.listBoxEvent.AddItem(sb[3]); this.listBoxDetail.AddItem(sb[4]); } 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); // History 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 void UpdateInitialStatus() { this.labelFileName.Text = ""; this.labelCurrentIndex.Text = "0"; this.labelTotalIndex.Text = "0"; this.labelFind.Text = ""; this.ClearListBox(); this.ClearData(); } public void ClearData() { this.CollectionData.Clear(); this.ListTime.Clear(); this.ListLoginID.Clear(); this.ListEvent.Clear(); this.ListDetail.Clear(); } public void ClearListBox() { for (int i = 0; i < this.CollectionListBox.Count; i++) this.CollectionListBox[i].ClearAll(); } private void ListBoxScrollUp(int value) { if (this.CurrentCount == ListBoxLineCount || (this.CurrentCount < ListBoxLineCount && this.CurrentCount == this.TotalCount)) return; int start = 0, last = 0; this.ClearListBox(); if (this.CurrentCount - value <= ListBoxLineCount) { start = 0; last = ListBoxLineCount; this.CurrentCount = ListBoxLineCount; } else { this.CurrentCount = this.CurrentCount - value; start = this.CurrentCount - ListBoxLineCount; last = this.CurrentCount; } for (int i = start; i < last; i++) { this.listBoxTime.AddItem(this.ListTime[i]); this.listBoxLoginID.AddItem(this.ListLoginID[i]); this.listBoxEvent.AddItem(this.ListEvent[i]); this.listBoxDetail.AddItem(this.ListDetail[i]); } this.UpdateListBoxCount(); } private void ListBoxScrollDown(int value) { if (this.TotalCount == this.CurrentCount) return; int start = 0, last = 0; this.ClearListBox(); if (this.CurrentCount + value >= this.TotalCount) { start = this.TotalCount - ListBoxLineCount; last = this.TotalCount; this.CurrentCount = this.TotalCount; } else { this.CurrentCount = this.CurrentCount + value; start = this.CurrentCount - ListBoxLineCount; last = this.CurrentCount; } for (int i = start; i < last; i++) { this.listBoxTime.AddItem(this.ListTime[i]); this.listBoxLoginID.AddItem(this.ListLoginID[i]); this.listBoxEvent.AddItem(this.ListEvent[i]); this.listBoxDetail.AddItem(this.ListDetail[i]); } this.UpdateListBoxCount(); } 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("H") == true) dirNames.Add(file.Name, int.Parse(file.Name.Substring(1, 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; } 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 LoadFile(string fullFilePath) { this.smartFile1.FilePathName = fullFilePath; this.smartFile1.Open(2000000); this.smartFile1.ReadStringAllBuffer(); try { long lineNum = this.smartFile1.GetCount(); this.TotalCount = (int)lineNum; for (int i = 1; i < lineNum; i++) { this.UpdateListBoxDataDisplay(this.smartFile1.ReadStringBuffer(i)); } } catch { DialogFormMessage myMsg = new DialogFormMessage(16, this.ParentForm.ParentForm.SystemConfig1.Language); myMsg.ShowDialog(); this.smartFile1.Close(); } this.smartFile1.Close(); } private void UpdateListData() { // List Item Add for (int i = 0; i < this.CollectionData.Count; i++) { this.ListTime.Add(this.CollectionData[i][1]); this.ListLoginID.Add(this.CollectionData[i][2]); this.ListEvent.Add(this.CollectionData[i][3]); this.ListDetail.Add(this.CollectionData[i][4]); } } private void UpdateInitialListBoxDataDisplay() { if (this.TotalCount > ListBoxLineCount) { for (int i = this.CurrentCount - ListBoxLineCount; i < this.TotalCount; i++) { this.listBoxTime.AddItem(this.ListTime[i]); this.listBoxLoginID.AddItem(this.ListLoginID[i]); this.listBoxEvent.AddItem(this.ListEvent[i]); this.listBoxDetail.AddItem(this.ListDetail[i]); } } else { for (int i = 0; i < this.TotalCount; i++) { this.listBoxTime.AddItem(this.ListTime[i]); this.listBoxLoginID.AddItem(this.ListLoginID[i]); this.listBoxEvent.AddItem(this.ListEvent[i]); this.listBoxDetail.AddItem(this.ListDetail[i]); } } } public void LoadFileLast15Datas(string fullFilePath) { int flag = 0; this.smartFile1.FilePathName = fullFilePath; this.smartFile1.Open(2000000); this.smartFile1.ReadStringAllBuffer(); try { this.ClearData(); this.ClearListBox(); this.ParentForm.SplashStart(); long lineNum = this.smartFile1.GetCount(); for (int i = 0; i < lineNum; i++) { if (flag == 100) { Thread.Sleep(5); flag = 0; } this.CollectionData.Add(this.smartFile1.ReadStringBuffer(i).Split(',')); flag++; } this.smartFile1.Close(); this.CollectionData.RemoveAt(0); this.TotalCount = this.CollectionData.Count; this.CurrentCount = this.TotalCount; // File Name string[] data = fullFilePath.Split('\\'); this.labelFileName.Text = data[data.Length - 1]; // List 갱신 this.UpdateListData(); // listBox 표시 this.UpdateInitialListBoxDataDisplay(); this.UpdateListBoxCount(); this.labelFind.Text = this.CurrentCount.ToString(); this.smartFile1.Close(); this.ParentForm.SplashFinish(); this.Enabled = true; } catch { DialogFormMessage myMsg = new DialogFormMessage(16, this.ParentForm.ParentForm.SystemConfig1.Language); myMsg.ShowDialog(); this.smartFile1.Close(); this.ParentForm.SplashFinish(); } } public void DisplayRefresh(SystemStatus status) { this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = Define.E_DisplayStore.LogHistory; this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus); this.ParentForm.ParentForm.SetDisplayMode(Define.E_DisplayMode.Menu); this.UpdateDisplayFile(); this.treeView.ExpandAll(); this.UpdateInitialStatus(); this.TotalCount = 0; if (int.Parse(this.labelCount.Text) == 0) { DialogFormMessage msg = new DialogFormMessage(37, this.ParentForm.ParentForm.SystemConfig1.Language); msg.ShowDialog(); return; } } #endregion #region Event Handler private void treeView_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Node.Text.Substring(0, 1) == "H") { if (e.Node.Checked == true) e.Node.Checked = false; else e.Node.Checked = true; this.labelFileName.Text = e.Node.Text; this.SelectedNodeFullPath = this.treeView.SelectedNode.FullPath; } //else //{ // var node = e.Node; // int count = node.Nodes.Count; // for (int i = 0; i < count; i++) // node.Nodes[i].Checked = node.Checked; //} } private void buttonRead_Click(object sender, EventArgs e) { if (this.labelFileName.Text == "" || this.labelFileName.Text == null) return; this.Enabled = false; this.LoadFileLast15Datas(this.ParentForm.ParentForm.PathDataHistoryFolder + this.SelectedNodeFullPath); } private void labelFind_Click(object sender, EventArgs e) { if (this.listBoxTime.ItemCount == 0) return; string value = ""; DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelFind.Text, 6, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language); if (myKeyPad.ShowDialog() == DialogResult.OK) { if (myKeyPad.doubleValue < 0) { // 입력범위를 확인하세요 DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language); myMsg.ShowDialog(); } else if (myKeyPad.doubleValue > this.TotalCount) { this.labelFind.Text = this.TotalCount.ToString(); } else { this.labelFind.Text = myKeyPad.StringValue; } } } private void buttonFind_Click(object sender, EventArgs e) { if (this.labelFind.Text == "" || this.labelFind.Text == null || this.listBoxTime.ItemCount == 0) return; int start = 0, last = 0; int index = int.Parse(this.labelFind.Text); try { this.ClearListBox(); if (this.TotalCount > ListBoxLineCount) { if (index - ListBoxLineCount < 0) { start = 0; last = ListBoxLineCount; this.CurrentCount = ListBoxLineCount; } else { start = index - ListBoxLineCount; last = index; this.CurrentCount = index; } } else { start = 0; last = this.TotalCount; this.CurrentCount = this.TotalCount; } for (int i = start; i < last; i++) { this.listBoxTime.AddItem(this.ListTime[i]); this.listBoxLoginID.AddItem(this.ListLoginID[i]); this.listBoxEvent.AddItem(this.ListEvent[i]); this.listBoxDetail.AddItem(this.ListDetail[i]); } this.UpdateListBoxCount(); this.smartFile1.Close(); } catch { DialogFormMessage myMsg = new DialogFormMessage(16, this.ParentForm.ParentForm.SystemConfig1.Language); myMsg.ShowDialog(); this.smartFile1.Close(); } } private void buttonBackup_Click(object sender, EventArgs e) { this.ParentForm.Backup(Define.E_DataType.History, this.treeView); } private void buttonUp_Click(object sender, EventArgs e) { this.ListBoxScrollUp(ListBoxLineCount); } private void buttonDown_Click(object sender, EventArgs e) { this.ListBoxScrollDown(ListBoxLineCount); } private void listBox_Click(object sender, EventArgs e) { SmartX.SmartListBox listBox = sender as SmartX.SmartListBox; listBox.SelectItemIndex = -1; } #endregion } }