INT69DB_2A/INT69DB_2A/Forms/FormDataViewer.cs

494 lines
17 KiB
C#

using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using SmartX;
using INT69DB_2A.DialogForms;
namespace INT69DB_2A.Forms
{
public partial class FormDataViewer : Form
{
#region Field
private int m_SelectNodeIndex;
private int RemainCNT;
private int StartIndex;
private int DataRemainCNT;
private int DataAllCNT;
public string PathDestinationFileName;
private FormMain m_ParentForm;
private Collection<string[]> CollectionHistoryData; // 파일에서 읽은 데이터
private List<string> ListDate;
private List<string> ListTime;
private List<string> ListLoginID;
private List<string> ListEvent;
private List<string> ListDetail;
private List<string> ListBefore;
private List<string> ListAfter;
private List<string> ListType;
#endregion
#region Constructor
public FormDataViewer(FormMain parent)
{
InitializeComponent();
this.ParentForm = parent;
this.InitializeDesign();
this.DefaultSetting();
this.InitializeControl();
}
#endregion
#region Property
public int SelectNodeIndex
{
get { return this.m_SelectNodeIndex; }
set { this.m_SelectNodeIndex = value; }
}
public FormMain ParentForm
{
get { return this.m_ParentForm; }
private set { this.m_ParentForm = value; }
}
#endregion
#region Method
private void InitializeDesign()
{
if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Korean)
{
}
else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.English)
{
this.labelTitle.Text = "Viewer";
}
else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
{
this.labelTitle.Text = "数据查看器";
}
else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
{
}
else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.German)
{
}
else
{
}
}
private void InitializeControl()
{
this.ClearData();
}
private void DefaultSetting()
{
this.SelectNodeIndex = -1;
this.StartIndex = 0;
this.RemainCNT = 0;
this.DataRemainCNT = 0;
this.DataAllCNT = 0;
this.PathDestinationFileName = "";
this.CollectionHistoryData = new Collection<string[]>();
//this.CollectionFileClassification = new Collection<List<string>>();
this.ListDate = new List<string>();
this.ListTime = new List<string>();
this.ListLoginID = new List<string>();
this.ListEvent = new List<string>();
this.ListDetail = new List<string>();
this.ListBefore = new List<string>();
this.ListAfter = new List<string>();
this.ListType = new List<string>();
}
private void ListBoxScrollDown()
{
//this.listBoxDate.ScrollDown();
this.listBoxTime.ScrollDown();
this.listBoxLoginID.ScrollDown();
this.listBoxEvent.ScrollDown();
this.listBoxDetail.ScrollDown();
this.listBoxBefore.ScrollDown();
this.listBoxAfter.ScrollDown();
this.listBoxType.ScrollDown();
this.ListBoxItemsCount();
}
private void ListBoxScrollDown(int value)
{
//this.listBoxDate.ScrollDown(value);
this.listBoxTime.ScrollDown(value);
this.listBoxLoginID.ScrollDown(value);
this.listBoxEvent.ScrollDown(value);
this.listBoxDetail.ScrollDown(value);
this.listBoxBefore.ScrollDown(value);
this.listBoxAfter.ScrollDown(value);
this.listBoxType.ScrollDown(value);
this.ListBoxItemsCount();
}
private void ListBoxScrollUp()
{
//this.listBoxDate.ScrollUp();
this.listBoxTime.ScrollUp();
this.listBoxLoginID.ScrollUp();
this.listBoxEvent.ScrollUp();
this.listBoxDetail.ScrollUp();
this.listBoxBefore.ScrollUp();
this.listBoxAfter.ScrollUp();
this.listBoxType.ScrollUp();
this.ListBoxItemsCount();
}
private void ListBoxScrollUp(int value)
{
//this.listBoxDate.ScrollUp(value);
this.listBoxTime.ScrollUp(value);
this.listBoxLoginID.ScrollUp(value);
this.listBoxEvent.ScrollUp(value);
this.listBoxDetail.ScrollUp(value);
this.listBoxBefore.ScrollUp(value);
this.listBoxAfter.ScrollUp(value);
this.listBoxType.ScrollUp(value);
this.ListBoxItemsCount();
}
private void ListBoxItemsCount()
{
if (this.listBoxTime.ItemCount == 0)
{
this.StartIndex = 0;
this.RemainCNT = 0;
this.DataRemainCNT = 0;
this.DataAllCNT = 0;
}
else
{
this.StartIndex = this.listBoxType.ViewStartItemIndex;
this.RemainCNT = this.listBoxType.ViewRemainCount;
}
this.labelItemsCount.Text = this.StartIndex.ToString() + " / " + this.RemainCNT.ToString();
this.labelRemainDataCount.Text = this.DataRemainCNT.ToString();
if (this.listBoxTime.ItemCount == 0)
this.labelItemCount.Text = "0 / 0";
else
this.labelItemCount.Text = (this.StartIndex + 29).ToString() + " / " + this.DataAllCNT.ToString();
}
private void UpdateListItem(DataViewerFilter filter)
{
bool enable = false;
// List Item Add
for (int i = 0; i < this.CollectionHistoryData.Count; i++)
{
// 필터 적용
switch (this.CollectionHistoryData[i][7])
{
case "Alarm":
enable = filter.TpyeAlarm;
break;
case "Operation":
enable = filter.TypeOperation;
break;
case "Parameter":
enable = filter.TypeParameter;
break;
default:
enable = false;
break;
}
if (enable == true)
{
this.ListDate.Add(this.CollectionHistoryData[i][0]);
this.ListTime.Add(this.CollectionHistoryData[i][1]);
this.ListLoginID.Add(this.CollectionHistoryData[i][2]);
this.ListEvent.Add(this.CollectionHistoryData[i][3]);
this.ListDetail.Add(this.CollectionHistoryData[i][4]);
this.ListBefore.Add(this.CollectionHistoryData[i][5]);
this.ListAfter.Add(this.CollectionHistoryData[i][6]);
this.ListType.Add(this.CollectionHistoryData[i][7]);
}
}
}
private void UpdateDisplay()
{
int cnt = 0;
if (this.ListDate.Count > 50)
{
cnt = 50;
this.DataRemainCNT = this.ListDate.Count - 50;
}
else
cnt = this.ListDate.Count;
for (int i = 0; i < cnt; i++)
{
//this.listBoxDate.AddItem(this.ListDate[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.listBoxBefore.AddItem(this.ListBefore[i]);
this.listBoxAfter.AddItem(this.ListAfter[i]);
this.listBoxType.AddItem(this.ListType[i]);
}
this.ListBoxItemsCount();
}
private void UpdateDisplayAddListBox()
{
int index = 0, range = 0;
SmartX.SmartSplash splash;
// 화면 표시 로딩시간 타이머 on
this.smartTimer1.StartWatch();
splash = new SmartX.SmartSplash();
splash.CenterPosition = true;
splash.AnimationInterval = 100;
splash.LoadingImagePathname = "SmartLoading4";
splash.Start();
index = this.ListDate.Count - this.DataRemainCNT;
if (this.DataRemainCNT > 50)
{
range = index + 50;
for (int i = index; i < range; i++)
{
//this.listBoxDate.AddItem(this.ListDate[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.listBoxBefore.AddItem(this.ListBefore[i]);
this.listBoxAfter.AddItem(this.ListAfter[i]);
this.listBoxType.AddItem(this.ListType[i]);
}
this.DataRemainCNT = this.DataRemainCNT - 50;
}
else
{
for (int i = index; i < this.ListDate.Count; i++)
{
//this.listBoxDate.AddItem(this.ListDate[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.listBoxBefore.AddItem(this.ListBefore[i]);
this.listBoxAfter.AddItem(this.ListAfter[i]);
this.listBoxType.AddItem(this.ListType[i]);
}
this.DataRemainCNT = 0;
}
this.ListBoxItemsCount();
splash.Finish();
// 화면 표시 로딩시간 타이머 off
this.smartTimer1.StopWatch();
this.labelDisplayUpdateElapsedTime.Text = this.smartTimer1.StopWatchElapsedMicrosecond.ToString();
}
public int DataRead(string filePath)
{
//string path = "";
int ret = 0, flag = 0;
long count = 0;
SmartSplash splash;
splash = new SmartSplash();
splash.CenterPosition = true;
splash.AnimationInterval = 100;
splash.LoadingImagePathname = "SmartLoading4";
splash.Start();
this.ClearData();
this.CollectionHistoryData.Clear();
// 파일 로딩 시간 타이머 ON
this.smartTimer1.StartWatch();
this.ParentForm.smartFileIO.FilePathName = filePath;
this.ParentForm.smartFileIO.Open(2000000);
this.ParentForm.smartFileIO.ReadStringAllBuffer();
try
{
count = this.ParentForm.smartFileIO.GetCount();
for (int i = 0; i < count; i++)
{
if (flag == 100)
{
Thread.Sleep(5);
flag = 0;
}
this.CollectionHistoryData.Add(this.ParentForm.smartFileIO.ReadStringBuffer(i).Split(','));
flag++;
}
this.ParentForm.smartFileIO.Close();
this.CollectionHistoryData.RemoveAt(0);
this.DataAllCNT = this.CollectionHistoryData.Count;
// 파일 로딩 시간 타이머 off
this.smartTimer1.StopWatch();
this.labelFileReadElapsedTime.Text = this.smartTimer1.StopWatchElapsedMicrosecond.ToString();
// 화면 표시 로딩시간 타이머 on
this.smartTimer1.StartWatch();
// File Name
string[] data = filePath.Split('\\');
this.labelFileName.Text = data[data.Length - 1];
// List 갱신
this.UpdateListItem(this.ParentForm.CurrentDataViewerFilter);
// 화면 표시
this.UpdateDisplay();
// 화면 표시 로딩시간 타이머 off
this.smartTimer1.StopWatch();
this.labelDisplayUpdateElapsedTime.Text = this.smartTimer1.StopWatchElapsedMicrosecond.ToString();
this.CollectionHistoryData.Clear();
ret = 0;
splash.Finish();
}
catch
{
this.CollectionHistoryData.Clear();
ret = -1;
splash.Finish();
DialogFormMessage msg = new DialogFormMessage(13, this.ParentForm.SystemConfig.Language);
msg.ShowDialog();
this.ParentForm.smartFileIO.Close();
}
return ret;
}
public void ClearData()
{
this.CollectionHistoryData.Clear();
//this.listBoxDate.ClearAll();
this.listBoxTime.ClearAll();
this.listBoxLoginID.ClearAll();
this.listBoxEvent.ClearAll();
this.listBoxDetail.ClearAll();
this.listBoxBefore.ClearAll();
this.listBoxAfter.ClearAll();
this.listBoxType.ClearAll();
this.ListDate.Clear();
this.ListTime.Clear();
this.ListLoginID.Clear();
this.ListEvent.Clear();
this.ListDetail.Clear();
this.ListBefore.Clear();
this.ListAfter.Clear();
this.ListType.Clear();
}
public void DisplayRefresh()
{
this.ParentForm.SystemConfig.CurrentForm = DataStore.FormStore.FormDataViewer;
this.labelFileName.Text = "";
this.ClearData();
this.ListBoxItemsCount();
}
#endregion
#region Event Handler
private void buttonBack_Click(object sender, EventArgs e)
{
this.ParentForm.ChildFormMenu.DisplayRefresh();
((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormMenu);
}
private void buttonFileSelect_Click(object sender, EventArgs e)
{
this.SelectNodeIndex = -1;
}
private void buttonFilter_Click(object sender, EventArgs e)
{
DialogFormDataViewerFilter form = new DialogFormDataViewerFilter(this);
if (form.ShowDialog() == DialogResult.OK)
{
// 필터적용
this.ClearData();
this.UpdateListItem(this.ParentForm.CurrentDataViewerFilter);
this.UpdateDisplay();
}
}
private void buttonUp_Click(object sender, EventArgs e)
{
if (this.StartIndex == 0)
return;
if (this.StartIndex < 6)
this.ListBoxScrollUp();
else
this.ListBoxScrollUp(50);
}
private void buttonDown_Click(object sender, EventArgs e)
{
if (this.RemainCNT == 0)
{
if (this.DataRemainCNT != 0)
{
this.UpdateDisplayAddListBox();
}
return;
}
if (this.RemainCNT < 6)
this.ListBoxScrollDown();
else
this.ListBoxScrollDown(50);
}
private void listBox_SelectedIndexChanged(object sender, EventArgs e)
{
SmartListBox lb = sender as SmartListBox;
if (lb == null)
return;
//this.listBoxDate.SelectItemIndex = lb.SelectItemIndex;
this.listBoxTime.SelectItemIndex = lb.SelectItemIndex;
this.listBoxLoginID.SelectItemIndex = lb.SelectItemIndex;
this.listBoxEvent.SelectItemIndex = lb.SelectItemIndex;
this.listBoxDetail.SelectItemIndex = lb.SelectItemIndex;
this.listBoxBefore.SelectItemIndex = lb.SelectItemIndex;
this.listBoxAfter.SelectItemIndex = lb.SelectItemIndex;
this.listBoxType.SelectItemIndex = lb.SelectItemIndex;
}
#endregion
}
}