Main.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Globalization;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Media;
  10. using System.Security.Principal;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. using UAS_Tools_HY.PublicMethods;
  15. namespace UAS_MES_Tools
  16. {
  17. public partial class Main : Form
  18. {
  19. string _Account, _Password, _UserName;
  20. DataTable dt;
  21. Timer loadTime;
  22. string minTime, maxTime;
  23. public Main(string account, string password)
  24. {
  25. _Account = account;
  26. _Password = password;
  27. InitializeComponent();
  28. }
  29. private void Main_Load(object sender, EventArgs e)
  30. {
  31. currUser.Text = "当前账户: " + _Account;
  32. dt = ConnectDB.ExecuteSelect($"select * from employee where em_code = '{_Account}'");
  33. if (dt.Rows.Count > 0)
  34. {
  35. _UserName = dt.Rows[0]["em_name"].ToString();
  36. }
  37. loadTime_Tick(null, null);
  38. loadTime = new Timer();
  39. loadTime.Interval = 1000;
  40. loadTime.Tick += loadTime_Tick;
  41. loadTime.Start();
  42. SN.SelectAll();
  43. SN.Focus();
  44. settingLeftInput1.Text = BaseUtil.GetCacheData("SettingCount").ToString();
  45. settingLeftInput2.Text = BaseUtil.GetCacheData("SettingVolume").ToString();
  46. settingRightInput1.Text = BaseUtil.GetCacheData("SettingNGPath").ToString();
  47. settingRightInput2.Text = BaseUtil.GetCacheData("SettingExportPath").ToString();
  48. QDcheckbox1.Checked = true;
  49. QDdtp1.Value = QDdtp2.Value.AddDays(-1);
  50. }
  51. private void SN_KeyDown(object sender, KeyEventArgs e)
  52. {
  53. if (e.KeyCode != Keys.Enter) return;
  54. if (CheckEnter()) return;
  55. bool checkRes = false;
  56. DataGridViewRow row = new DataGridViewRow();
  57. row.CreateCells(Datas);
  58. row.Cells[0].Value = SN.Text.Trim();
  59. row.Cells[1].Value = "";
  60. row.Cells[2].Value = 1;
  61. row.Cells[3].Value = currTime.Text;
  62. row.Cells[4].Value = _UserName;
  63. row.Cells[5].Value = radio1.Checked ? "是" : "否";
  64. row.Cells[6].Value = checkRes ? "OK": "NG";
  65. Datas.Rows.Add(row);
  66. Datas.FirstDisplayedScrollingRowIndex = Datas.Rows.Count - 1;
  67. PlaySound("OK");
  68. }
  69. private void BoxNo_KeyDown(object sender, KeyEventArgs e)
  70. {
  71. if (e.KeyCode != Keys.Enter) return;
  72. if (CheckEnter()) return;
  73. BoxNo.Enabled = false;
  74. SN.SelectAll();
  75. SN.Focus();
  76. if (Datas.Rows.Count > 0)
  77. {
  78. foreach(DataGridViewRow item in Datas.Rows)
  79. {
  80. item.Cells[1].Value = BoxNo.Text.Trim();
  81. }
  82. }
  83. }
  84. private bool CheckEnter()
  85. {
  86. if (string.IsNullOrEmpty(settingLeftInput1.Text))
  87. {
  88. MessageBox.Show("请维护列表记录数", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  89. return true;
  90. }
  91. if (string.IsNullOrEmpty(settingLeftInput2.Text))
  92. {
  93. MessageBox.Show("请维护箱内容量", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  94. return true;
  95. }
  96. return false;
  97. }
  98. private void settingLeftSubmit_Click(object sender, EventArgs e)
  99. {
  100. if (string.IsNullOrEmpty(settingLeftInput1.Text))
  101. {
  102. MessageBox.Show("请输入列表记录数", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  103. return;
  104. }
  105. if (string.IsNullOrEmpty(settingLeftInput2.Text))
  106. {
  107. MessageBox.Show("请输入箱内容量", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  108. return;
  109. }
  110. BaseUtil.SetCacheData("SettingCount", settingLeftInput1.Text);
  111. BaseUtil.SetCacheData("SettingVolume", settingLeftInput2.Text);
  112. MessageBox.Show("已提交扫描设置", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  113. }
  114. private void settingRightSubmit_Click(object sender, EventArgs e)
  115. {
  116. if (string.IsNullOrEmpty(settingRightInput2.Text))
  117. {
  118. MessageBox.Show("请选择导出文件目录", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  119. return;
  120. }
  121. if(!string.IsNullOrEmpty(settingRightInput1.Text)) BaseUtil.SetCacheData("SettingNGPath", settingRightInput1.Text);
  122. BaseUtil.SetCacheData("SettingExportPath", settingRightInput2.Text);
  123. MessageBox.Show("已提交文件设置", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  124. }
  125. private void QDquery_Click(object sender, EventArgs e)
  126. {
  127. if (string.IsNullOrEmpty(QDInput1.Text) && string.IsNullOrEmpty(QDInput2.Text) && !QDcheckbox1.Checked)
  128. {
  129. MessageBox.Show("请添加筛选条件", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  130. return;
  131. }
  132. if (QDcheckbox1.Checked)
  133. {
  134. }
  135. }
  136. private void QDexport_Click(object sender, EventArgs e)
  137. {
  138. if(QDDatas.Rows.Count == 0)
  139. {
  140. MessageBox.Show("请筛选数据", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  141. return;
  142. }
  143. }
  144. private void boxBtn_Click(object sender, EventArgs e)
  145. {
  146. BoxNo.Enabled = true;
  147. BoxNo.Focus();
  148. BoxNo.SelectAll();
  149. }
  150. private void settingRightInput1_Click(object sender, EventArgs e)
  151. {
  152. using (OpenFileDialog openFileDialog = new OpenFileDialog())
  153. {
  154. openFileDialog.Title = "请选择告警文件";
  155. openFileDialog.Filter = "可执行文件 (*.wav)|*.wav|所有文件 (*.*)|*.*";
  156. openFileDialog.FilterIndex = 1;
  157. openFileDialog.RestoreDirectory = true;
  158. if (!string.IsNullOrEmpty(settingRightInput1.Text) && System.IO.File.Exists(settingRightInput1.Text))
  159. {
  160. openFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(settingRightInput1.Text);
  161. }
  162. else
  163. {
  164. openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
  165. }
  166. if (openFileDialog.ShowDialog() == DialogResult.OK)
  167. {
  168. settingRightInput1.Text = openFileDialog.FileName;
  169. }
  170. }
  171. }
  172. private void settingRightInput2_Click(object sender, EventArgs e)
  173. {
  174. using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
  175. {
  176. folderBrowserDialog.Description = "请选择导出文件夹";
  177. if (!string.IsNullOrEmpty(settingRightInput2.Text) && System.IO.Directory.Exists(settingRightInput2.Text))
  178. {
  179. folderBrowserDialog.SelectedPath = settingRightInput2.Text;
  180. }
  181. else
  182. {
  183. folderBrowserDialog.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // folderBrowserDialog.SelectedPath = "";
  184. }
  185. if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
  186. {
  187. settingRightInput2.Text = folderBrowserDialog.SelectedPath;
  188. }
  189. }
  190. }
  191. private void QDdtp1_ValueChanged(object sender, EventArgs e)
  192. {
  193. if (QDdtp1.Value > QDdtp2.Value)
  194. {
  195. QDdtp1.Value = QDdtp2.Value.AddDays(-1);
  196. MessageBox.Show("时间不得大于最大时间", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  197. return;
  198. }
  199. minTime = QDdtp1.Value.ToString("yyyy-mm-dd hh:mm:ss");
  200. }
  201. private void QDdtp2_ValueChanged(object sender, EventArgs e)
  202. {
  203. if (QDdtp2.Value < QDdtp1.Value)
  204. {
  205. QDdtp2.Value = QDdtp1.Value.AddDays(1);
  206. MessageBox.Show("时间不得小于最小时间", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  207. return;
  208. }
  209. maxTime = QDdtp2.Value.ToString("yyyy-mm-dd hh:mm:ss");
  210. }
  211. private void PlaySound(string type)
  212. {
  213. if (type == "OK")
  214. {
  215. using (var stream = UAS_Tools_HY.Properties.Resources.OK)
  216. {
  217. SoundPlayer player = new SoundPlayer(stream);
  218. player.Play();
  219. }
  220. }
  221. else
  222. {
  223. if (string.IsNullOrEmpty(settingRightInput1.Text))
  224. {
  225. using (var stream = UAS_Tools_HY.Properties.Resources.NG)
  226. {
  227. SoundPlayer player = new SoundPlayer(stream);
  228. player.Play();
  229. }
  230. }
  231. else
  232. {
  233. string customPath = settingRightInput1.Text.Trim();
  234. if (File.Exists(customPath))
  235. {
  236. SoundPlayer player = new SoundPlayer(customPath);
  237. player.Play();
  238. }
  239. }
  240. }
  241. }
  242. public void loadTime_Tick(object sender, EventArgs e)
  243. {
  244. string currentDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
  245. currTime.Text = currentDate;
  246. }
  247. }
  248. }