INT63DC_2C/INT63DC_2C/DialogForms/DialogFormDataStatistics.cs

295 lines
9.4 KiB
C#

using System;
using System.Linq;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using INT63DC_2C.Forms;
namespace INT63DC_2C.DialogForms
{
public partial class DialogFormDataStatistics : Form
{
#region Field
private FormDataStatistics m_ParentForm;
#endregion
#region Constructor
public DialogFormDataStatistics(FormDataStatistics parent)
{
InitializeComponent();
this.ParentForm = parent;
this.InitializeDesign();
this.InitializeContnrol();
this.DefaultSetting();
}
#endregion
#region Property
public FormDataStatistics ParentForm
{
get { return this.m_ParentForm; }
private set { this.m_ParentForm = value; }
}
#endregion
#region Method
private void InitializeDesign()
{
switch (this.ParentForm.ParentForm.SystemConfig.Language)
{
case DataStore.LanguageID.Korean:
case DataStore.LanguageID.English:
break;
case DataStore.LanguageID.Chinese:
#region Chinese
this.labelTitleDate.Text = "日期";
this.labelTitleProductNo.Text = "编号";
this.labelTitleID.Text = "标识符";
this.buttonRead.Text = "读取";
this.buttonClose.Text = "关闭";
#endregion
break;
case DataStore.LanguageID.Czech:
#region Czech
this.labelTitleDate.Text = "Datum";
this.labelTitleProductNo.Text = "Číslo";
this.labelTitleID.Text = "ID";
this.buttonRead.Text = "Přečíst vše";
this.buttonClose.Text = "Zavřít";
#endregion
break;
case DataStore.LanguageID.German:
#region German
this.labelTitleDate.Text = "Datum";
this.labelTitleProductNo.Text = "Nummer";
this.labelTitleID.Text = "ID";
this.buttonRead.Text = "Alles lesen";
this.buttonClose.Text = "Schließen";
#endregion
break;
case DataStore.LanguageID.Japanese:
#region Japanese
this.labelTitleDate.Text = "日付";
this.labelTitleProductNo.Text = "番号";
this.labelTitleID.Text = "ID";
this.buttonRead.Text = "読む";
this.buttonClose.Text = "クロㅡズ";
#endregion
break;
default:
break;
}
}
private void InitializeContnrol()
{
int x = 0, y = 0;
x = Screen.PrimaryScreen.Bounds.Width / 2 - this.Size.Width / 2;
y = Screen.PrimaryScreen.Bounds.Height / 2 - this.Size.Height / 2;
this.Location = new Point(x, y);
this.Size = new Size(450, 165);
}
private void DefaultSetting()
{
this.DisplayTreeViewUpdate();
this.labelNodeIndex.Text = "-";
this.labelFileName.Text = "-";
this.labelDate.Text = "-";
this.labelProductNo.Text = "-";
this.labelId.Text = "-";
}
private Collection<List<string>> FileClassification(List<string> files)
{
string date = "", date1 = "";
Collection<List<string>> fileClassification = new Collection<List<string>>();
List<string> list = new List<string>();
for (int i = 0; i < files.Count; i++)
{
date = files[i].Substring(0, 12);
if (i == 0)
date1 = date;
if (date == date1)
{
list.Add(files[i]);
}
else
{
date1 = date;
List<string> l = new List<string>();
foreach (string s in list)
l.Add(s);
fileClassification.Add(l);
list = new List<string>();
list.Add(files[i]);
}
}
List<string> ls = new List<string>();
foreach (string s in list)
ls.Add(s);
fileClassification.Add(ls);
return fileClassification;
}
private List<string> FileSort(FileInfo[] files)
{
List<string> listFiles = new List<string>();
Dictionary<string, int> fileNames = new Dictionary<string, int>();
Dictionary<string, int> fileNamesSort = new Dictionary<string, int>();
foreach (FileInfo file in files)
{
fileNames.Add(file.Name, int.Parse(file.Name.Substring(11, 1)));
}
var vrList = fileNames.Keys.ToList();
vrList.Sort();
foreach (var v in vrList)
fileNamesSort.Add(v, fileNames[v]);
foreach (var v in fileNamesSort)
listFiles.Add(v.Key);
return listFiles;
}
private List<string> FileSort(List<string> lst)
{
List<string> listFiles = new List<string>();
Dictionary<string, int> fileNames = new Dictionary<string, int>();
Dictionary<string, int> fileNamesSort = new Dictionary<string, int>();
foreach (string list in lst)
{
if (list.Length == 22)
fileNames.Add(list, int.Parse(list.Substring(13, 1)));
else
fileNames.Add(list, int.Parse(list.Substring(13, 2)));
}
// Lane 순서데로 오름차순 정렬
var vrList = fileNames.OrderBy(x => x.Value);
foreach (var v in vrList)
listFiles.Add(v.Key);
return listFiles;
}
private void DisplayTreeViewUpdate()
{
DirectoryInfo dir = new DirectoryInfo(this.ParentForm.ParentForm.PathDataBackupFolder);
List<string> fileNames = new List<string>();
// 폴더 체크
if (dir.Exists == false)
dir.Create();
FileInfo[] files = dir.GetFiles();
if (files.Length != 0)
{
// 파일 이름 순으로 정렬
fileNames = this.FileSort(files);
// 파일 날짜 순으로 분류
this.ParentForm.CollectionFileClassification = this.FileClassification(fileNames);
foreach (List<string> list in this.ParentForm.CollectionFileClassification)
{
TreeNode node = new TreeNode(list[0].Substring(0, 12));
for (int i = 0; i < list.Count; i++)
{
node.Nodes.Add(list[i]);
}
this.treeView1.Nodes.Add(node);
}
}
}
public void DisplayRefresh()
{
this.DisplayTreeViewUpdate();
}
#endregion
#region Event Handler
private void buttonRead_Click(object sender, EventArgs e)
{
if (this.ParentForm.SelectNodeIndex == -1)
return;
this.treeView1.Enabled = false;
this.buttonRead.Enabled = false;
this.buttonClose.Enabled = false;
if (this.treeView1.Nodes.Count != 0)
{
this.ParentForm.ClearData();
if (this.ParentForm.DataRead1() == 0)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
else
this.DialogResult = DialogResult.Cancel;
}
this.treeView1.Enabled = true;
this.buttonRead.Enabled = true;
this.buttonClose.Enabled = true;
}
private void buttonClose_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
string fileName = "";
if (e.Node.Parent == null)
{
fileName = e.Node.Text;
this.ParentForm.SelectNodeIndex = e.Node.Index;
//this.labelNodeIndex.Text = string.Format("{0}", this.ParentForm.SelectNodeIndex + 1);
}
else
{
fileName = e.Node.Parent.Text;
this.ParentForm.SelectNodeIndex = e.Node.Parent.Index;
//this.labelNodeIndex.Text = string.Format("{0}", this.ParentForm.SelectNodeIndex + 1);
}
this.labelFileName.Text = fileName;
this.labelDate.Text = string.Format("{0}.{1}.{2}", fileName.Substring(0, 4), fileName.Substring(4, 2), fileName.Substring(6, 2));
this.labelProductNo.Text = fileName.Substring(9, 1);
this.labelId.Text = fileName.Substring(11, 1);
}
#endregion
}
}