华恒Mes鼎捷代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

549 lines
21 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using ICSSoft.Base.ReferForm.AppReferForm;
  10. using ICSSoft.Base.Config.DBHelper;
  11. using ICSSoft.Base.Config.AppConfig;
  12. using System.Xml;
  13. using System.IO;
  14. using System.Reflection;
  15. using DevExpress.XtraEditors;
  16. using System.Configuration;
  17. namespace ICSSoft.Frame.WatchPanel
  18. {
  19. public partial class WatchSet : Form
  20. {
  21. public WatchSet()
  22. {
  23. InitializeComponent();
  24. this.Width = 700;
  25. this.Height = 533;
  26. ControlStatus(false);
  27. }
  28. #region 退出
  29. private void StripMenuExit_Click(object sender, EventArgs e)
  30. {
  31. this.Close();
  32. }
  33. private void btnExit_Click(object sender, EventArgs e)
  34. {
  35. this.Close();
  36. }
  37. #endregion
  38. private void StripMenu_Click(object sender, EventArgs e)
  39. {
  40. comName.Text = "";
  41. ControlStatus(true);
  42. comName.DropDownStyle = ComboBoxStyle.DropDown;
  43. }
  44. private void StripMenuAlter_Click(object sender, EventArgs e)
  45. {
  46. comName.Text = "";
  47. ControlStatus(true);
  48. comName.DropDownStyle = ComboBoxStyle.DropDownList;
  49. }
  50. #region 保存和修改
  51. private void btnSave_Click(object sender, EventArgs e)
  52. {
  53. if (BoolNull() == false)
  54. {
  55. MessageBox.Show("数值不能为空!");
  56. return;
  57. }
  58. String strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  59. String strFullPathToMyFile = Path.Combine(strAppDir, "WatchConfig.xml");
  60. XmlDocument xmlDoc = loadXml(strFullPathToMyFile);
  61. int m = 0;
  62. XmlNodeList xnls = xmlDoc.SelectSingleNode("WatchConfig/FacWatchConfig").ChildNodes; //XML中排序节点的集合
  63. for (int i = 0; i < xnls.Count; i++) //遍历节点集合
  64. {
  65. XmlElement xe = (XmlElement)xnls.Item(i); //获取相应节点的元素
  66. if (xe.GetAttribute("Name") == comName.Text)
  67. {
  68. m++;
  69. }
  70. }
  71. //增加
  72. if (m == 0)
  73. {
  74. XmlNode root = xmlDoc.SelectSingleNode("WatchConfig/FacWatchConfig");//查找<FacWatchConfig>
  75. XmlElement xe1 = xmlDoc.CreateElement("FacWatchConfig");//创建一个<FacWatchConfig>节点
  76. xe1.SetAttribute("Name", comName.Text);//设置该节点属性
  77. xe1.SetAttribute("CarStatus", cheCarStatus.Checked.ToString());
  78. xe1.SetAttribute("CarWatchStatus", cheCarWatchStatus.Checked.ToString());
  79. xe1.SetAttribute("CarPro", cheCarPro.Checked.ToString());
  80. xe1.SetAttribute("SSStatus", cheSSStatus.Checked.ToString());
  81. xe1.SetAttribute("AutoBetTime", txtAutoBetTime.Text);
  82. xe1.SetAttribute("ChangeTime", txtChangeTime.Text);
  83. xe1.SetAttribute("SS", btnSS.Text);
  84. xe1.SetAttribute("CarSS", btnCarSS.Text);
  85. xe1.SetAttribute("EquipID", btnEquipID.Text);
  86. xe1.SetAttribute("RightArea", cheRight.Checked.ToString());
  87. root.AppendChild(xe1);//添加到<FacWatchConfig>节点中
  88. saveXml(xmlDoc, strFullPathToMyFile); //最后必须要保存到XML文件中
  89. }
  90. else
  91. {
  92. XmlNode root = xmlDoc.SelectSingleNode("WatchConfig/FacWatchConfig");
  93. XmlNodeList xnl = xmlDoc.SelectSingleNode("WatchConfig/FacWatchConfig").ChildNodes;
  94. for (int i = 0; i < xnl.Count; i++)
  95. {
  96. XmlElement xe = (XmlElement)xnl.Item(i);
  97. if (xe.GetAttribute("Name") == comName.Text)
  98. {
  99. if (cheCarStatus.Checked.ToString() != xe.GetAttribute("CarStatus"))
  100. {
  101. xe.SetAttribute("CarStatus", cheCarStatus.Checked.ToString());
  102. }
  103. if (cheCarWatchStatus.Checked.ToString() != xe.GetAttribute("CarWatchStatus"))
  104. {
  105. xe.SetAttribute("CarWatchStatus", cheCarWatchStatus.Checked.ToString());
  106. }
  107. if (cheCarPro.Checked.ToString() != xe.GetAttribute("CarPro"))
  108. {
  109. xe.SetAttribute("CarPro", cheCarPro.Checked.ToString());
  110. }
  111. if (cheSSStatus.Checked.ToString() != xe.GetAttribute("SSStatus"))
  112. {
  113. xe.SetAttribute("SSStatus", cheSSStatus.Checked.ToString());
  114. }
  115. if (txtAutoBetTime.Text != xe.GetAttribute("AutoBetTime"))
  116. {
  117. xe.SetAttribute("AutoBetTime", txtAutoBetTime.Text);
  118. }
  119. if (txtChangeTime.Text != xe.GetAttribute("ChangeTime"))
  120. {
  121. xe.SetAttribute("ChangeTime", txtChangeTime.Text);
  122. }
  123. if (btnSS.Text != xe.GetAttribute("SS"))
  124. {
  125. xe.SetAttribute("SS", btnSS.Text);
  126. }
  127. if (btnCarSS.Text != xe.GetAttribute("CarSS"))
  128. {
  129. xe.SetAttribute("CarSS", btnCarSS.Text);
  130. }
  131. if (btnEquipID.Text != xe.GetAttribute("EquipID"))
  132. {
  133. xe.SetAttribute("EquipID", btnEquipID.Text);
  134. }
  135. //如果不相同则修改属性
  136. }
  137. }
  138. saveXml(xmlDoc, strFullPathToMyFile);
  139. }
  140. MessageBox.Show("Success!");
  141. resert();
  142. }
  143. #endregion
  144. #region 加载XML数据方法
  145. private XmlDocument loadXml(string filePath)
  146. {
  147. FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
  148. XmlDocument doc = new XmlDocument();
  149. doc.Load(stream);
  150. stream.Close();
  151. return doc;
  152. }
  153. #endregion
  154. #region 保存XML数据方法
  155. private void saveXml(XmlDocument doc, string filePath)
  156. {
  157. FileStream stream = new FileStream(filePath,
  158. FileMode.Create, FileAccess.Write);
  159. doc.Save(stream);
  160. stream.Close();
  161. }
  162. #endregion
  163. #region 名称下拉框数据加载
  164. private void comName_Click(object sender, EventArgs e)
  165. {
  166. comName.Items.Clear();
  167. String strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  168. String strFullPathToMyFile = Path.Combine(strAppDir, "WatchConfig.xml");
  169. XmlDocument xmlDoc = loadXml(strFullPathToMyFile);
  170. XmlNode root = xmlDoc.SelectSingleNode("WatchConfig/FacWatchConfig");
  171. XmlNodeList xnl = xmlDoc.SelectSingleNode("WatchConfig/FacWatchConfig").ChildNodes;
  172. for (int i = 0; i < xnl.Count; i++)
  173. {
  174. XmlElement xe = (XmlElement)xnl.Item(i);
  175. comName.Items.Add(xe.GetAttribute("Name"));
  176. }
  177. }
  178. #endregion
  179. #region 下拉框选择后加载数据
  180. private void comName_SelectedIndexChanged(object sender, EventArgs e)
  181. {
  182. String strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  183. String strFullPathToMyFile = Path.Combine(strAppDir, "WatchConfig.xml");
  184. XmlDocument xmlDoc = loadXml(strFullPathToMyFile);
  185. XmlNode root = xmlDoc.SelectSingleNode("WatchConfig/FacWatchConfig");
  186. XmlNodeList xnl = xmlDoc.SelectSingleNode("WatchConfig/FacWatchConfig").ChildNodes;
  187. for (int i = 0; i < xnl.Count; i++)
  188. {
  189. XmlElement xe = (XmlElement)xnl.Item(i);
  190. if (xe.GetAttribute("Name") == comName.Text)
  191. {
  192. cheCarStatus.Checked = xe.GetAttribute("CarStatus") == "True" ? true : false;
  193. cheCarWatchStatus.Checked = xe.GetAttribute("CarWatchStatus") == "True" ? true : false;
  194. cheCarPro.Checked = xe.GetAttribute("CarPro") == "True" ? true : false;
  195. cheSSStatus.Checked = xe.GetAttribute("SSStatus") == "True" ? true : false;
  196. txtAutoBetTime.Text = xe.GetAttribute("AutoBetTime");
  197. txtChangeTime.Text = xe.GetAttribute("ChangeTime");
  198. btnSS.Text = xe.GetAttribute("SS");
  199. btnCarSS.Text = xe.GetAttribute("CarSS");
  200. btnEquipID.Text = xe.GetAttribute("EquipID");
  201. cheRight.Checked = xe.GetAttribute("RightArea") == "True" ? true : false;
  202. }
  203. }
  204. }
  205. #endregion
  206. #region 判断控件值是否为空
  207. private bool BoolNull()
  208. {
  209. if (comName.Text == null)
  210. {
  211. return false;
  212. }
  213. if (txtAutoBetTime.Text == null)
  214. {
  215. return false;
  216. }
  217. if (txtChangeTime.Text == null)
  218. {
  219. return false;
  220. }
  221. if (btnSS.Text == null)
  222. {
  223. return false;
  224. }
  225. if (btnCarSS.Text == null)
  226. {
  227. return false;
  228. }
  229. if (btnEquipID.Text == null)
  230. {
  231. return false;
  232. }
  233. return true;
  234. }
  235. #endregion
  236. #region 包含的产线 buttonclick事件
  237. private void btnSS_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  238. {
  239. btnSS.Text = "";
  240. ButtonEdit btn = (ButtonEdit)sender;
  241. string sql = @"select SSCODE as 产线代码,SSTYPE as 产线类型,SSDESC as 产线描述 from dbo.ICSSS";
  242. sql = string.Format(sql);
  243. DataTable data = DBHelper.ExecuteDataset(GetConnectionStringsConfig(), CommandType.Text, sql).Tables[0];
  244. FormDataRefer reForm = new FormDataRefer();
  245. reForm.FormTitle = "产线";
  246. DataTable menuData = data;
  247. reForm.DataSource = menuData;
  248. reForm.MSelectFlag = true;
  249. reForm.RowIndexWidth = 35;
  250. //reForm.HideCols.Add("ID");
  251. reForm.FormWidth = 800;
  252. reForm.FormHeight = 600;
  253. reForm.FilterKey = btn.Text;
  254. if (reForm.ShowDialog() == DialogResult.OK)
  255. {
  256. DataTable retData = reForm.ReturnData;
  257. int count = retData.Rows.Count;
  258. foreach (DataRow dr in retData.Rows)
  259. {
  260. btnSS.Text += "," + dr["产线代码"].ToString();
  261. }
  262. }
  263. if (btnSS.Text.StartsWith(","))
  264. {
  265. btnSS.Text = btnSS.Text.Substring(1, btnSS.Text.Length-1);
  266. }
  267. }
  268. #endregion
  269. #region 车间包含的产线 buttonclick事件
  270. private void btnCarSS_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  271. {
  272. btnCarSS.Text = "";
  273. ButtonEdit btn = (ButtonEdit)sender;
  274. string sql = @"select SSCODE as 产线代码,SSTYPE as 产线类型,SSDESC as 产线描述 from dbo.ICSSS";
  275. sql = string.Format(sql);
  276. DataTable data = DBHelper.ExecuteDataset(GetConnectionStringsConfig(), CommandType.Text, sql).Tables[0];
  277. FormDataRefer reForm = new FormDataRefer();
  278. reForm.FormTitle = "产线";
  279. DataTable menuData = data;
  280. reForm.DataSource = menuData;
  281. reForm.MSelectFlag = true;
  282. reForm.RowIndexWidth = 35;
  283. //reForm.HideCols.Add("ID");
  284. reForm.FormWidth = 800;
  285. reForm.FormHeight = 600;
  286. reForm.FilterKey = btn.Text;
  287. if (reForm.ShowDialog() == DialogResult.OK)
  288. {
  289. DataTable retData = reForm.ReturnData;
  290. int count = retData.Rows.Count;
  291. foreach (DataRow dr in retData.Rows)
  292. {
  293. btnCarSS.Text += ","+dr["产线代码"].ToString();
  294. }
  295. if (btnCarSS.Text.StartsWith(","))
  296. {
  297. btnCarSS.Text = btnCarSS.Text.Substring(1, btnCarSS.Text.Length - 1);
  298. }
  299. }
  300. }
  301. #endregion
  302. #region 设备ID buttonclick事件
  303. private void btnEquipID_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  304. {
  305. btnEquipID.Text = "";
  306. ButtonEdit btn = (ButtonEdit)sender;
  307. string sql = @"select EQPID as 设备ID,EQPCode as 设备编号,EQPName as 设备名称,EQPStatus as 设备状态,EQPDESC as 设备描述 from dbo.ICSEquipment";
  308. sql = string.Format(sql);
  309. DataTable data = DBHelper.ExecuteDataset(GetConnectionStringsConfig(), CommandType.Text, sql).Tables[0];
  310. FormDataRefer reForm = new FormDataRefer();
  311. reForm.FormTitle = "设备";
  312. DataTable menuData = data;
  313. reForm.DataSource = menuData;
  314. reForm.MSelectFlag = true;
  315. reForm.HideCols.Add("设备ID");
  316. reForm.RowIndexWidth = 35;
  317. //reForm.HideCols.Add("ID");
  318. reForm.FormWidth = 800;
  319. reForm.FormHeight = 600;
  320. reForm.FilterKey = btn.Text;
  321. if (reForm.ShowDialog() == DialogResult.OK)
  322. {
  323. DataTable retData = reForm.ReturnData;
  324. int count = retData.Rows.Count;
  325. foreach (DataRow dr in retData.Rows)
  326. {
  327. btnEquipID.Text += "," + dr["设备编号"].ToString();
  328. }
  329. }
  330. if (btnEquipID.Text.StartsWith(","))
  331. {
  332. btnEquipID.Text = btnEquipID.Text.Substring(1, btnEquipID.Text.Length - 1);
  333. }
  334. }
  335. #endregion
  336. #region 获取数据库链接字符串
  337. private string GetConnectionStringsConfig()
  338. {
  339. string connectionstring = "";
  340. String strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  341. String strFullPathToMyFile = Path.Combine(strAppDir, "appwatch.xml");
  342. XmlDocument xmlDoc = loadXml(strFullPathToMyFile);
  343. XmlNodeList xnl = xmlDoc.SelectSingleNode("configuration").ChildNodes;
  344. for (int i = 0; i < xnl.Count; i++)
  345. {
  346. XmlElement xe = (XmlElement)xnl.Item(i);
  347. connectionstring = xe.GetAttribute("value");
  348. }
  349. return connectionstring;
  350. }
  351. #endregion
  352. #region 删除
  353. private void btnDel_Click(object sender, EventArgs e)
  354. {
  355. if (comName.Text == "")
  356. {
  357. MessageBox.Show("名称不可为空!");
  358. return;
  359. }
  360. if (MessageBox.Show("确定要删除该条数据吗?", "删除前确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
  361. {
  362. String strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  363. String strFullPathToMyFile = Path.Combine(strAppDir, "WatchConfig.xml");
  364. XmlDocument xmlDoc = loadXml(strFullPathToMyFile);
  365. XmlNode root = xmlDoc.SelectSingleNode("WatchConfig/FacWatchConfig");
  366. XmlNodeList xnl = xmlDoc.SelectSingleNode("WatchConfig/FacWatchConfig").ChildNodes;
  367. for (int i = 0; i < xnl.Count; i++)
  368. {
  369. XmlElement xe = (XmlElement)xnl.Item(i);
  370. if (xe.GetAttribute("Name") == comName.Text)
  371. {
  372. root.RemoveChild(xe);
  373. }
  374. }
  375. saveXml(xmlDoc, strFullPathToMyFile);
  376. resert();
  377. }
  378. }
  379. #endregion
  380. private void ControlStatus(bool bol)
  381. {
  382. comName.Visible = bol;
  383. txtAutoBetTime.ReadOnly = !bol;
  384. txtChangeTime.ReadOnly = !bol;
  385. btnSS.Properties.ReadOnly = !bol;
  386. btnCarSS.Properties.ReadOnly = !bol;
  387. btnEquipID.Properties.ReadOnly = !bol;
  388. cheCarStatus.Visible = bol;
  389. cheCarWatchStatus.Visible = bol;
  390. cheCarPro.Visible = bol;
  391. cheSSStatus.Visible = bol;
  392. cheRight.Visible = bol;
  393. }
  394. private void resert()
  395. {
  396. comName.Text = "";
  397. txtAutoBetTime.Text = "";
  398. txtChangeTime.Text = "";
  399. btnSS.Text = "";
  400. btnCarSS.Text = "";
  401. btnEquipID.Text = "";
  402. cheCarStatus.Checked = false;
  403. cheCarWatchStatus.Checked = false;
  404. cheCarPro.Checked = false;
  405. cheSSStatus.Checked = false;
  406. cheRight.Checked = false;
  407. }
  408. private void comName_TextChanged(object sender, EventArgs e)
  409. {
  410. }
  411. private void btnOutPut_Click(object sender, EventArgs e)
  412. {
  413. #region XML
  414. String strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
  415. String strFullPathToMyFile = Path.Combine(strAppDir, "WatchConfig.xml");
  416. XmlDocument xmlDoc = loadXml(strFullPathToMyFile);
  417. int m = 0;
  418. XmlNodeList xnls = xmlDoc.SelectSingleNode("WatchConfig/FacWatchConfig").ChildNodes; //XML中排序节点的集合
  419. for (int i = 0; i < xnls.Count; i++) //遍历节点集合
  420. {
  421. XmlElement xe = (XmlElement)xnls.Item(i); //获取相应节点的元素
  422. if (xe.GetAttribute("Name") == comName.Text)
  423. {
  424. m++;
  425. }
  426. }
  427. #endregion
  428. if( comName.Text=="" )
  429. {
  430. MessageBox.Show("名称不能为空!");
  431. return;
  432. }
  433. if (m == 0)
  434. {
  435. MessageBox.Show("该名称不存在!");
  436. return;
  437. }
  438. if(button1.BackColor!=Color.Blue&&button2.BackColor!=Color.Blue)
  439. {
  440. MessageBox.Show("车间产线必须选中一个!");
  441. return;
  442. }
  443. if (button1.BackColor == Color.Blue && button2.BackColor == Color.Blue)
  444. {
  445. MessageBox.Show("车间产线不能两个都选中!");
  446. return;
  447. }
  448. WatchData data = new WatchData();
  449. for (int i = 0; i < xnls.Count; i++)
  450. {
  451. XmlElement xe = (XmlElement)xnls.Item(i);
  452. if (xe.GetAttribute("Name") == comName.Text)
  453. {
  454. data.Name=comName.Text;
  455. data.CarStatus= xe.GetAttribute("CarStatus")=="True"?true:false;
  456. data.CarWatchStatus = xe.GetAttribute("CarWatchStatus") == "True" ? true : false;
  457. data.CarPro = xe.GetAttribute("CarPro") == "True" ? true : false;
  458. data.SSStatus = xe.GetAttribute("SSStatus") == "True" ? true : false;
  459. data.AutoBetTime= xe.GetAttribute("AutoBetTime");
  460. data.ChangeTime= xe.GetAttribute("ChangeTime");
  461. data.SS = xe.GetAttribute("SS");
  462. data.CarSS = xe.GetAttribute("CarSS");
  463. data.EquipID = xe.GetAttribute("EquipID");
  464. data.Right = xe.GetAttribute("RightArea") == "True" ? true : false;
  465. //如果不相同则修改属性
  466. }
  467. }
  468. if(button1.BackColor==Color.Blue)
  469. {
  470. FormWatch2 form1 = new FormWatch2();
  471. form1.ShowDialog();
  472. }
  473. if (button2.BackColor == Color.Blue)
  474. {
  475. FormWatch1 form1 = new FormWatch1(data);
  476. form1.ShowDialog();
  477. }
  478. }
  479. private void WatchSet_Load(object sender, EventArgs e)
  480. {
  481. }
  482. private void button1_Click(object sender, EventArgs e)
  483. {
  484. if (button1.BackColor == Color.White)
  485. {
  486. button1.BackColor = Color.Blue;
  487. button2.BackColor = Color.White;
  488. }
  489. else if (button1.BackColor == Color.Blue)
  490. {
  491. button1.BackColor = Color.White;
  492. }
  493. }
  494. private void button2_Click(object sender, EventArgs e)
  495. {
  496. if (button2.BackColor == Color.White)
  497. {
  498. button2.BackColor = Color.Blue;
  499. button1.BackColor = Color.White;
  500. }
  501. else if (button2.BackColor == Color.Blue)
  502. {
  503. button2.BackColor = Color.White;
  504. }
  505. }
  506. }
  507. }