BasicInformationSettings.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. using Resources;
  2. using SmartCoalApplication.MeasureProcedure;
  3. using SmartCoalApplication.Resources;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using System.Xml;
  14. namespace SmartCoalApplication.Setup
  15. {
  16. internal partial class BasicInformationSettings : Form
  17. {
  18. private List<List<string>> leixingMingchengs = new List<List<string>>();
  19. private int indexLeixing = new int();
  20. private int indexMingcheng = new int();
  21. private MeasureSettingDialog measureSettingDialog;
  22. public BasicInformationSettings()
  23. {
  24. InitializeComponent();
  25. InitializeLanguageText();
  26. this.Icon = PdnInfo.AppIcon;
  27. }
  28. public BasicInformationSettings(MeasureSettingDialog measureSettingDialog)
  29. {
  30. InitializeComponent();
  31. InitializeLanguageText();
  32. this.Icon = PdnInfo.AppIcon;
  33. this.measureSettingDialog = measureSettingDialog;
  34. }
  35. private void InitializeLanguageText()
  36. {
  37. this.Text = PdnResources.GetString("NewBasicInfoSetting");
  38. this.groupBox1.Text = PdnResources.GetString("NewType");
  39. this.groupBox2.Text = PdnResources.GetString("Menu.operation.text");
  40. this.buttonClose.Text = PdnResources.GetString("Menu.File.Close.Text");
  41. this.buttonDelete.Text = PdnResources.GetString("NewDelete");
  42. this.buttonEdit.Text = PdnResources.GetString("NewEdit");
  43. this.buttonAdd.Text = PdnResources.GetString("NewAdd");
  44. this.groupBox3.Text = PdnResources.GetString("NewName");
  45. }
  46. private void BasicInformationSettings_Load(object sender, EventArgs e)
  47. {
  48. string[] leixings = { PdnResources.GetString("NewFactoryArea"), PdnResources.GetString("NewLaboratory"), PdnResources.GetString("NewLayers"), PdnResources.GetString("NewMadeOf"), PdnResources.GetString("NewFrequency")};
  49. for (int i = 0; i < leixings.Length; i++)
  50. {
  51. listBoxLeixing.Items.Add(leixings[i]);
  52. List<string> newLeixingMingcheng = new List<string>();
  53. leixingMingchengs.Add(newLeixingMingcheng);
  54. }
  55. ReadXml();
  56. }
  57. private void timer1_Tick(object sender, EventArgs e)
  58. {
  59. //DateTime time = DateTime.Now;
  60. // (DateTime.Now-time).TotalSeconds;
  61. }
  62. /// <summary>
  63. /// 添加名稱
  64. /// </summary>
  65. private void buttonAdd_Click(object sender, EventArgs e)
  66. {
  67. indexLeixing = listBoxLeixing.SelectedIndex;
  68. if (indexLeixing == -1) {
  69. MessageBox.Show(PdnResources.GetString("NewPleaseSelectType"));
  70. return;
  71. }
  72. Xinzeng from2 = new Xinzeng("", 1);
  73. from2.TransferEvent += AddMingcheng;
  74. from2.StartPosition = FormStartPosition.CenterScreen;
  75. from2.ShowDialog();
  76. }
  77. private void AddMingcheng(string mingcheng)
  78. {
  79. if (leixingMingchengs[indexLeixing].Contains(mingcheng))
  80. {
  81. MessageBox.Show(PdnResources.GetString("BasicInformationSetting.ReapeatedName"));
  82. return;
  83. }
  84. leixingMingchengs[indexLeixing].Add(mingcheng);
  85. listBoxMingcheng.DataSource = null;
  86. listBoxMingcheng.DataSource = leixingMingchengs[indexLeixing];
  87. WriteXml();
  88. }
  89. /// <summary>
  90. /// 修改名稱
  91. /// </summary>
  92. private void buttonEdit_Click(object sender, EventArgs e)
  93. {
  94. indexLeixing = listBoxLeixing.SelectedIndex;
  95. if (indexLeixing == -1)
  96. {
  97. MessageBox.Show(PdnResources.GetString("NewPleaseSelectType"));
  98. return;
  99. }
  100. if (listBoxMingcheng.SelectedIndex == -1)
  101. {
  102. return;
  103. }
  104. var chooseData = listBoxMingcheng.SelectedItem.ToString();
  105. indexMingcheng = listBoxMingcheng.SelectedIndex;
  106. Xinzeng from3 = new Xinzeng(chooseData, 2);
  107. from3.TransferEvent += EditMingcheng;
  108. from3.StartPosition = FormStartPosition.CenterScreen;
  109. from3.ShowDialog();
  110. }
  111. private void EditMingcheng(string mingcheng)
  112. {
  113. indexLeixing = listBoxLeixing.SelectedIndex;
  114. if (indexLeixing == -1)
  115. {
  116. MessageBox.Show(PdnResources.GetString("NewPleaseSelectType"));
  117. return;
  118. }
  119. if (leixingMingchengs[indexLeixing].Contains(mingcheng) && leixingMingchengs[indexLeixing].IndexOf(mingcheng) != indexMingcheng)
  120. {
  121. MessageBox.Show(PdnResources.GetString("BasicInformationSetting.ReapeatedName"));
  122. return;
  123. }
  124. leixingMingchengs[indexLeixing][indexMingcheng] = mingcheng;
  125. listBoxMingcheng.DataSource = null;
  126. listBoxMingcheng.DataSource = leixingMingchengs[indexLeixing];
  127. WriteXml();
  128. }
  129. /// <summary>
  130. /// 刪除名稱
  131. /// </summary>
  132. private void buttonDelete_Click(object sender, EventArgs e)
  133. {
  134. indexLeixing = listBoxLeixing.SelectedIndex;
  135. if (indexLeixing == -1)
  136. {
  137. MessageBox.Show(PdnResources.GetString("NewPleaseSelectType"));
  138. return;
  139. }
  140. indexMingcheng = listBoxMingcheng.SelectedIndex;
  141. if (indexMingcheng == -1)
  142. {
  143. MessageBox.Show(PdnResources.GetString("NewPleaseSelectDeleteData"));
  144. return;
  145. }
  146. if (leixingMingchengs[indexLeixing].Count == 0)
  147. MessageBox.Show(PdnResources.GetString("NewTheContentEmpty"));
  148. DialogResult result = MessageBox.Show(PdnResources.GetString("NewLrrecoverableAfterDeletion"), PdnResources.GetString("NewDelete"), MessageBoxButtons.OKCancel);
  149. if (result == DialogResult.OK)
  150. {
  151. leixingMingchengs[indexLeixing].RemoveAt(indexMingcheng);
  152. listBoxMingcheng.DataSource = null;
  153. listBoxMingcheng.DataSource = leixingMingchengs[indexLeixing];
  154. WriteXml();
  155. }
  156. }
  157. /// <summary>
  158. /// 關閉界面
  159. /// </summary>
  160. private void buttonClose_Click(object sender, EventArgs e)
  161. {
  162. this.Close();
  163. }
  164. private void listBoxLeixing_MouseDown(object sender, MouseEventArgs e)
  165. {
  166. indexLeixing = listBoxLeixing.SelectedIndex;
  167. if (indexLeixing == -1) {
  168. return;
  169. }
  170. listBoxMingcheng.DataSource = null;
  171. listBoxMingcheng.DataSource = leixingMingchengs[indexLeixing];
  172. }
  173. private void listBoxMingcheng_MouseDown(object sender, MouseEventArgs e)
  174. {
  175. indexMingcheng = listBoxMingcheng.SelectedIndex;
  176. }
  177. private void WriteXml()
  178. {
  179. XmlDocument xDoc = new XmlDocument();
  180. XmlDeclaration declaration = xDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
  181. xDoc.AppendChild(declaration);
  182. //根结点
  183. XmlElement genjiedian = xDoc.CreateElement("leixings");
  184. xDoc.AppendChild(genjiedian);
  185. //规程结点
  186. for (int i = 0; i < leixingMingchengs.Count; i++)
  187. {
  188. XmlElement leixing = xDoc.CreateElement(PdnResources.GetString("NewType"));
  189. genjiedian.AppendChild(leixing);
  190. for (int j = 0; j < leixingMingchengs[i].Count; j++)
  191. {
  192. XmlElement mingcheng = xDoc.CreateElement(PdnResources.GetString("NewName"));//名称
  193. leixing.AppendChild(mingcheng);
  194. mingcheng.InnerText = leixingMingchengs[i][j];
  195. }
  196. }
  197. string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\basicInformation.xml";
  198. xDoc.Save(filePath);
  199. }
  200. private void ReadXml()
  201. {
  202. XmlDocument xDoc = new XmlDocument();
  203. string filePath = Application.StartupPath + "\\Config\\" + Program.instance.SettingPrefix + "\\basicInformation.xml";
  204. if (System.IO.File.Exists(filePath))
  205. {
  206. xDoc.Load(filePath);
  207. }
  208. else
  209. {
  210. XmlDeclaration declaration = xDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
  211. xDoc.AppendChild(declaration);
  212. //根结点
  213. XmlElement genjiedian = xDoc.CreateElement("leixings");
  214. xDoc.AppendChild(genjiedian);
  215. //规程结点
  216. for (int i = 0; i < 5; i++)
  217. {
  218. XmlElement leixing = xDoc.CreateElement(PdnResources.GetString("NewType"));
  219. genjiedian.AppendChild(leixing);
  220. }
  221. xDoc.Save(filePath);
  222. }
  223. XmlNode rootNode = xDoc.SelectSingleNode("leixings");
  224. XmlNodeList leixingList = rootNode.ChildNodes;
  225. for (int i = 0; i < leixingList.Count; i++)
  226. {
  227. //List<string> newListString = new List<string>();
  228. //leixingMingchengs.Add(newListString);
  229. XmlNodeList leixingChild = leixingList[i].ChildNodes;
  230. for (int j = 0; j < leixingChild.Count; j++)
  231. {
  232. string mingcheng = "";
  233. mingcheng = leixingChild[j].InnerText;
  234. leixingMingchengs[i].Add(mingcheng);
  235. }
  236. }
  237. }
  238. private void beforeClosing(object sender, FormClosingEventArgs e)
  239. {
  240. if (this.measureSettingDialog != null) {
  241. this.measureSettingDialog.resetInformation();
  242. }
  243. }
  244. }
  245. }