frmSchedulingShift.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.IO;
  6. using System.Diagnostics;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. using CoreFS.CA06;
  12. using Core.Mes.Client.Common;
  13. namespace Core.LgMes.Client.LgIntegrationQuery
  14. {
  15. public partial class frmSchedulingShift : Core.Mes.Client.Common.frmStyleBase
  16. {
  17. bool blChange = false; //判断是否发生变化。
  18. string ShiftCode = "";
  19. public frmSchedulingShift()
  20. {
  21. InitializeComponent();
  22. }
  23. private void frmSchedulingShift_Load(object sender, EventArgs e)
  24. {
  25. //初始化时间和查询条件
  26. this.uldtBeginTime.Value = DateTime.Today.AddDays(-7).ToString("yyyy-MM-dd") + " 00:00";
  27. this.uldtEndTime.Value = DateTime.Today.ToString("yyyy-MM-dd") + " 23:59"; ;
  28. this.cmbxShiftQuery.Enabled = false;
  29. ckbTime.Checked = true;
  30. this.uldtBeginTime.Enabled = true;
  31. this.uldtEndTime.Enabled = true;
  32. this.ultxtMan.Text =this.UserInfo.GetUserName();
  33. string strErr = "";
  34. ShiftCode = "";
  35. ArrayList arry = new ArrayList();
  36. arry.Add("GetCurrDuty.Select");
  37. CommonClientToServer cctos = new CommonClientToServer();
  38. cctos.ob = this.ob;
  39. DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBQuery",
  40. "doSimpleQuery", arry, out strErr);
  41. ShiftCode=ds.Tables[0].Rows[0][0].ToString();
  42. if (!string.IsNullOrEmpty(ShiftCode))
  43. {
  44. cmbxShift.SelectedIndex = Convert.ToInt16(ShiftCode.Substring(1, 1)) - 1;
  45. }
  46. //获取原有调度信息
  47. QueryShiftData();
  48. //其他岗位只有查询功能的限制
  49. if (this.Key.Contains("@Query") == true)
  50. {
  51. ultraExpandableGroupBox1.Visible = false;
  52. }
  53. }
  54. private void ckbTime_CheckedChanged(object sender, EventArgs e)
  55. {
  56. uldtBeginTime.Enabled = ckbTime.Checked;
  57. uldtEndTime.Enabled = ckbTime.Checked;
  58. }
  59. private void chkShift_CheckedChanged(object sender, EventArgs e)
  60. {
  61. cmbxShiftQuery.Enabled = chkShift.Checked;
  62. if (chkShift.Checked == true)
  63. {
  64. string ShiftCode = "", strErr="";
  65. ArrayList arry = new ArrayList();
  66. arry.Add("GetCurrDuty.Select");
  67. CommonClientToServer cctos = new CommonClientToServer();
  68. cctos.ob = this.ob;
  69. DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBQuery",
  70. "doSimpleQuery", arry, out strErr);
  71. ShiftCode = ds.Tables[0].Rows[0][0].ToString();
  72. if (!string.IsNullOrEmpty(ShiftCode))
  73. {
  74. cmbxShiftQuery.SelectedIndex = Convert.ToInt16(ShiftCode.Substring(1, 1)) - 1;
  75. }
  76. }
  77. else
  78. {
  79. cmbxShiftQuery.Text = "";
  80. }
  81. }
  82. public override void ToolBar_Click(object sender, string ToolbarKey)
  83. {
  84. switch (ToolbarKey)
  85. {
  86. case "Add":
  87. if (MessageBox.Show("你确认要增加调度交接班信息?", "提示", System.Windows.Forms.MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  88. return;
  89. if (string.IsNullOrEmpty(ultxtMan.Text))
  90. {
  91. MessageBox.Show("请输入交班人!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  92. }
  93. else if (string.IsNullOrEmpty(cmbxShift.Text))
  94. {
  95. MessageBox.Show("请选择班次!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  96. }
  97. else if (string.IsNullOrEmpty(txtContent.Text))
  98. {
  99. MessageBox.Show("请输入交班的内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  100. }
  101. else
  102. {
  103. AddShiftData();
  104. }
  105. break;
  106. case "Delete":
  107. if (ultraGrid.ActiveRow!=null)
  108. {
  109. System.Windows.Forms.DialogResult t = MessageBox.Show("你确认要删除所选择的行?", "提示", System.Windows.Forms.MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  110. if (t == System.Windows.Forms.DialogResult.Yes)
  111. {
  112. DeleteShiftData();
  113. }
  114. }
  115. else
  116. {
  117. MessageBox.Show("请选择你要删除的行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  118. }
  119. break;
  120. case "Update":
  121. if (MessageBox.Show("你确认要修改调度交接班信息?", "提示", System.Windows.Forms.MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  122. return;
  123. if (ultraGrid.ActiveRow != null)
  124. {
  125. UpdateShiftData();
  126. }
  127. else
  128. {
  129. MessageBox.Show("请选择你要修改的行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  130. }
  131. break;
  132. case "Query":
  133. QueryShiftData();
  134. break;
  135. case "Export":
  136. if (ultraGrid.Rows.Count > 0)
  137. {
  138. ExportExcel();
  139. }
  140. else
  141. MessageBox.Show("没有交班信息。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  142. break;
  143. case "Exit":
  144. this.Close();
  145. break;
  146. default:
  147. break;
  148. }
  149. }
  150. /// <summary>
  151. /// 获取调度交班信息
  152. /// </summary>
  153. private void QueryShiftData()
  154. {
  155. string strShift = "";
  156. string strStartTime = "";
  157. string strEndTime = "";
  158. string strErr = "";
  159. if (ckbTime.Checked == true)
  160. {
  161. if (Convert.ToDateTime(uldtBeginTime.Value) > Convert.ToDateTime(uldtEndTime.Value))
  162. {
  163. MessageBox.Show("时间条件的开始时间不能大于结束时间!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  164. return;
  165. }
  166. else
  167. {
  168. strStartTime = this.uldtBeginTime.DateTime.ToString("yyyy-MM-dd");
  169. strEndTime = this.uldtEndTime.DateTime.ToString("yyyy-MM-dd");
  170. }
  171. }
  172. if (chkShift.Checked == true)
  173. {
  174. strShift = Convert.ToString(cmbxShiftQuery.SelectedIndex+1);
  175. }
  176. ArrayList arry = new ArrayList();
  177. arry.Add("QueryShiftData.select");
  178. arry.Add(strStartTime);
  179. arry.Add(strEndTime);
  180. arry.Add(strShift);
  181. arry.Add(strShift);
  182. CommonClientToServer cctos = new CommonClientToServer();
  183. cctos.ob = this.ob;
  184. DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBQuery",
  185. "doSimpleQuery", arry, out strErr);
  186. dataSet1.Clear(); //清空原有行
  187. if (strErr =="" && ds != null)
  188. {
  189. if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
  190. {
  191. foreach (DataRow Dr in ds.Tables[0].Rows)
  192. {
  193. DataRow dr1 = dataSet1.Tables[0].NewRow();
  194. dr1["ID"] = Dr["ID"].ToString();
  195. dr1["SHIFTNAME"] = Dr["SHIFTNAME"].ToString();
  196. dr1["SHIFT"] = Dr["SHIFT"].ToString();
  197. dr1["SHIFTCONTENT"] = Dr["SHIFTCONTENT"].ToString();
  198. dr1["SHIFTDATE"] = Dr["SHIFTDATE"].ToString();
  199. dataSet1.Tables[0].Rows.Add(dr1);
  200. }
  201. }
  202. }
  203. }
  204. /// <summary>
  205. /// 增加调度交班信息
  206. /// </summary>
  207. private void AddShiftData()
  208. {
  209. string strShift ="";
  210. if (cmbxShift.SelectedIndex == 0)
  211. strShift = "1";
  212. else if (cmbxShift.SelectedIndex == 1)
  213. strShift = "2";
  214. else if (cmbxShift.SelectedIndex == 2)
  215. strShift = "3";
  216. else if (cmbxShift.SelectedIndex == 3)
  217. strShift = "4";
  218. string strShiftContent = txtContent.Text;
  219. string strShiftTime = DateTime.Now.ToString();
  220. string strShiftName = ultxtMan.Text;
  221. string strErr = "";
  222. ArrayList arry = new ArrayList();
  223. arry.Add("AddShiftData.select");
  224. arry.Add(strShiftName);
  225. arry.Add(strShift);
  226. arry.Add(strShiftContent);
  227. arry.Add(strShiftTime);
  228. CommonClientToServer cctos = new CommonClientToServer();
  229. cctos.ob = this.ob;
  230. DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  231. "doSimpleSave", arry, out strErr);
  232. if (strErr != "")
  233. {
  234. MessageBox.Show("保存失败!调度信息新增失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  235. }
  236. else
  237. {
  238. MessageBox.Show("调度信息新增成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  239. QueryShiftData();
  240. }
  241. }
  242. /// <summary>
  243. /// 删除交班调度信息
  244. /// </summary>
  245. private void DeleteShiftData()
  246. {
  247. if (ultraGrid.ActiveRow != null)
  248. {
  249. string strId = ultraGrid.ActiveRow.Cells["ID"].Value.ToString();
  250. string strErr = "";
  251. ArrayList arry = new ArrayList();
  252. arry.Add("DeleteShiftData.select");
  253. arry.Add(strId);
  254. CommonClientToServer cctos = new CommonClientToServer();
  255. cctos.ob = this.ob;
  256. DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  257. "doSimpleSave", arry, out strErr);
  258. if (strErr != "")
  259. {
  260. MessageBox.Show("删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  261. }
  262. else
  263. {
  264. MessageBox.Show("交班调度信息删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  265. QueryShiftData();
  266. ultxtMan.Text = "";
  267. cmbxShift.Text = "";
  268. ShiftTime.Text = "";
  269. txtContent.Text = "";
  270. }
  271. }
  272. }
  273. /// <summary>
  274. /// 选择要编辑的信息
  275. /// </summary>
  276. /// <param name="sender"></param>
  277. /// <param name="e"></param>
  278. private void ultraGrid_Click(object sender, EventArgs e)
  279. {
  280. DialogResult dlgR = DialogResult.None;
  281. if (ultraGrid.ActiveRow == null || ultraGrid.ActiveRow.Index < 0)
  282. {
  283. return;
  284. }
  285. else if (ultraGrid.ActiveRow.Index >= 0)
  286. {
  287. if (blChange == true && txtContent.Text.Trim().Length > 0)
  288. dlgR = MessageBox.Show("调度交班信息已更新请先增加或修改操作!", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk);
  289. if (dlgR == DialogResult.Yes || dlgR == DialogResult.Cancel) return;
  290. blChange = false;
  291. ultxtMan.Text = ultraGrid.ActiveRow.Cells["SHIFTNAME"].Value.ToString();
  292. cmbxShift.Text = ultraGrid.ActiveRow.Cells["SHIFT"].Text;
  293. ShiftTime.Text = ultraGrid.ActiveRow.Cells["SHIFTDATE"].Value.ToString();
  294. txtContent.Text = ultraGrid.ActiveRow.Cells["SHIFTCONTENT"].Value.ToString();
  295. }
  296. }
  297. /// <summary>
  298. /// 修改调度交班信息
  299. /// </summary>
  300. private void UpdateShiftData()
  301. {
  302. if (ultraGrid.ActiveRow != null)
  303. {
  304. string strShift = "";
  305. if (cmbxShift.SelectedIndex == 0)
  306. strShift = "1";
  307. else if (cmbxShift.SelectedIndex == 1)
  308. strShift = "2";
  309. else if (cmbxShift.SelectedIndex == 2)
  310. strShift = "3";
  311. else if (cmbxShift.SelectedIndex == 3)
  312. strShift = "4";
  313. string strId = ultraGrid.ActiveRow.Cells["ID"].Value.ToString();
  314. string strShiftName = ultxtMan.Text;
  315. string strShiftContent = txtContent.Text;
  316. string strShiftTime = DateTime.Now.ToString();
  317. string strErr = "";
  318. ArrayList arry = new ArrayList();
  319. arry.Add("UpdateShiftData.select");
  320. arry.Add(strShiftName);
  321. arry.Add(strShift);
  322. arry.Add(strShiftContent);
  323. arry.Add(strId);
  324. CommonClientToServer cctos = new CommonClientToServer();
  325. cctos.ob = this.ob;
  326. DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  327. "doSimpleSave", arry, out strErr);
  328. if (strErr != "")
  329. {
  330. MessageBox.Show("调度交班信息修改失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  331. }
  332. else
  333. {
  334. MessageBox.Show("调度交班信息修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  335. QueryShiftData();
  336. }
  337. }
  338. }
  339. /// <summary>
  340. /// 导出Excel
  341. /// </summary>
  342. private void ExportExcel()
  343. {
  344. try
  345. {
  346. string StrfileName = System.Windows.Forms.Application.StartupPath + "\\Report\\调度交班信息.xls";
  347. this.ultraGridExcelExporter1.Export(this.ultraGrid, StrfileName);
  348. ProcessStartInfo p = new ProcessStartInfo(StrfileName);
  349. p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
  350. p.WorkingDirectory = Path.GetDirectoryName(StrfileName);
  351. Process.Start(p);
  352. }
  353. catch (Exception ex)
  354. {
  355. MessageBox.Show(ex.Message);
  356. }
  357. }
  358. private void txtContent_TextChanged(object sender, EventArgs e)
  359. {
  360. //if (txtContent.Text.Trim().Length > 0)
  361. // blChange = true;
  362. }
  363. private void butClear_Click(object sender, EventArgs e)
  364. {
  365. if (MessageBox.Show("是否要清空交接班信息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
  366. {
  367. this.ultxtMan.Text = this.UserInfo.GetUserName();
  368. if (!string.IsNullOrEmpty(ShiftCode))
  369. {
  370. cmbxShift.SelectedIndex = Convert.ToInt16(ShiftCode.Substring(1, 1)) - 1;
  371. }
  372. ShiftTime.Value = DateTime.Now;
  373. txtContent.Clear();
  374. }
  375. }
  376. private void txtContent_KeyPress(object sender, KeyPressEventArgs e)
  377. {
  378. if(txtContent.Text.Trim().Length>0)
  379. blChange = true;
  380. }
  381. }
  382. }