|
@@ -0,0 +1,199 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.ComponentModel;
|
|
|
+using System.Data;
|
|
|
+using System.Drawing;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using System.Windows.Forms;
|
|
|
+using System.Xml;
|
|
|
+
|
|
|
+namespace OTSRegister
|
|
|
+{
|
|
|
+ public partial class Form1 : Form
|
|
|
+ {
|
|
|
+ List<string> list_str = new List<string>();
|
|
|
+ IDictionary<String, List<String>> infos = new Dictionary<String, List<String>>();
|
|
|
+ public Form1()
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void button1_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ OpenFileDialog ofd = new OpenFileDialog();
|
|
|
+ if (ofd.ShowDialog() == DialogResult.OK)
|
|
|
+ {
|
|
|
+ var a = ReadXML(ofd.FileName);
|
|
|
+ //List<string> list_str = new List<string>();
|
|
|
+ List<string> list_time = new List<string>();
|
|
|
+ a.TryGetValue("ID", out list_str);
|
|
|
+ label2.Text ="cpu:"+ list_str[0];
|
|
|
+ label3.Text = "硬盘:"+list_str[1];
|
|
|
+ a.TryGetValue("Time", out list_time);
|
|
|
+ string time_Day;
|
|
|
+ if (Convert.ToInt32(list_time[2]) < 10)
|
|
|
+ {
|
|
|
+ time_Day = "0" + list_time[2];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ time_Day = list_time[2];
|
|
|
+ }
|
|
|
+ string time_Month;
|
|
|
+ if (Convert.ToInt32(list_time[1]) < 10)
|
|
|
+ {
|
|
|
+ time_Month = "0" + list_time[1];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ time_Month = list_time[1];
|
|
|
+ }
|
|
|
+ label4.Text ="有效期至:"+ list_time[0].ToString() + "-" + time_Month + "-" + time_Day;
|
|
|
+ DateTime dt = DateTime.ParseExact(list_time[0].ToString() + time_Month + time_Day, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
|
|
|
+ //TimePicker.Value = dt;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static IDictionary<String, List<String>> ReadXML(string address)
|
|
|
+ {
|
|
|
+ IDictionary<String, List<String>> infos = new Dictionary<String, List<String>>();
|
|
|
+
|
|
|
+ if (File.Exists(address))
|
|
|
+ {
|
|
|
+ XmlDocument xmlDoc = new XmlDocument();
|
|
|
+
|
|
|
+ xmlDoc.Load(address);
|
|
|
+
|
|
|
+ XmlNode xn = xmlDoc.SelectSingleNode("infos");
|
|
|
+
|
|
|
+ XmlNodeList xnl = xn.ChildNodes;
|
|
|
+
|
|
|
+ foreach (XmlNode xnf in xnl)
|
|
|
+ {
|
|
|
+ XmlElement xe = (XmlElement)xnf;
|
|
|
+
|
|
|
+ XmlNode nameNode = xe.SelectSingleNode("ID");
|
|
|
+
|
|
|
+ string name = nameNode.InnerText;
|
|
|
+ Console.WriteLine(name);
|
|
|
+ XmlNode filelist = xe.SelectSingleNode("filelist");
|
|
|
+
|
|
|
+ List<String> list = new List<string>();
|
|
|
+
|
|
|
+ foreach (XmlNode item in filelist.ChildNodes)
|
|
|
+ {
|
|
|
+ list.Add(item.InnerText);
|
|
|
+ }
|
|
|
+
|
|
|
+ infos.Add(name, list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return infos;
|
|
|
+ }
|
|
|
+
|
|
|
+ private string ConvertBinary(string str)
|
|
|
+ {
|
|
|
+ string strBytes = null;
|
|
|
+ byte[] data = Encoding.Unicode.GetBytes(str);
|
|
|
+ for (int i = 0; i < data.Count(); i++)
|
|
|
+ {
|
|
|
+ if (strBytes == null)
|
|
|
+ {
|
|
|
+ strBytes = data[i].ToString().PadLeft(2, '0');
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ strBytes = strBytes + "," + data[i].ToString().PadLeft(2, '0');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return strBytes;
|
|
|
+ }
|
|
|
+ public static void SaveXML(IDictionary<String, List<String>> infos, string address)
|
|
|
+ {
|
|
|
+ if (infos == null || infos.Count == 0)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ XmlDocument xmlDoc = new XmlDocument();
|
|
|
+
|
|
|
+ XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
|
|
|
+
|
|
|
+ xmlDoc.AppendChild(dec);
|
|
|
+
|
|
|
+ XmlElement _infos = xmlDoc.CreateElement("infos");
|
|
|
+
|
|
|
+ foreach (KeyValuePair<String, List<String>> item in infos)
|
|
|
+ {
|
|
|
+ XmlElement info = xmlDoc.CreateElement("info");
|
|
|
+
|
|
|
+ XmlElement name = xmlDoc.CreateElement("ID");
|
|
|
+ name.InnerText = item.Key;
|
|
|
+
|
|
|
+ info.AppendChild(name);
|
|
|
+
|
|
|
+ XmlNode filelist = xmlDoc.CreateElement("filelist");
|
|
|
+
|
|
|
+ info.AppendChild(filelist);
|
|
|
+
|
|
|
+ foreach (String number in item.Value)
|
|
|
+ {
|
|
|
+ XmlElement filed = xmlDoc.CreateElement("filed");
|
|
|
+ filed.InnerText = number;
|
|
|
+
|
|
|
+ filelist.AppendChild(filed);
|
|
|
+ }
|
|
|
+
|
|
|
+ _infos.AppendChild(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ xmlDoc.AppendChild(_infos);
|
|
|
+
|
|
|
+ xmlDoc.Save(address);
|
|
|
+
|
|
|
+ }
|
|
|
+ private void button2_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ SaveFileDialog sfd = new SaveFileDialog();
|
|
|
+ sfd.Filter = "(*.txt)|*.txt|(*.*)|*.*";
|
|
|
+ sfd.FileName = "RegistrationProofreading";
|
|
|
+ if (sfd.ShowDialog() == DialogResult.OK)
|
|
|
+ {
|
|
|
+ string cpu = ConvertBinary(list_str[0]);
|
|
|
+ string Disk = ConvertBinary(list_str[1]);
|
|
|
+ string Year = ConvertBinary(TimePicker.Value.Year.ToString());
|
|
|
+ string set_Month;
|
|
|
+ if (Convert.ToInt32(TimePicker.Value.Month.ToString()) < 10)
|
|
|
+ {
|
|
|
+ set_Month = "0" + TimePicker.Value.Month.ToString();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ set_Month = TimePicker.Value.Month.ToString();
|
|
|
+ }
|
|
|
+ string Month = ConvertBinary(set_Month);
|
|
|
+ string set_Day;
|
|
|
+ if (Convert.ToInt32(TimePicker.Value.Day.ToString()) < 10)
|
|
|
+ {
|
|
|
+ set_Day = "0" + TimePicker.Value.Day.ToString();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ set_Day = TimePicker.Value.Day.ToString();
|
|
|
+ }
|
|
|
+ string Day = ConvertBinary(set_Day);
|
|
|
+
|
|
|
+ infos.Add("ID", new List<string>() { cpu, Disk });
|
|
|
+ infos.Add("Time", new List<string>() { Year, Month, Day.ToString() });
|
|
|
+ SaveXML(infos, sfd.FileName);
|
|
|
+ }
|
|
|
+ MessageBox.Show("生成成功!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|