华恒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.

415 lines
17 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.Text;
  7. using System.Windows.Forms;
  8. using DevExpress.XtraEditors;
  9. using ICSSoft.Frame.WorkPoint.Entity;
  10. using ICSSoft.Frame.WorkPoint.BLL;
  11. using ICSSoft.Base.Config.AppConfig;
  12. using ICSSoft.Base.Config.DBHelper;
  13. using System.Text.RegularExpressions;
  14. using ICSSoft.Frame.Data.BLL;
  15. using ICSSoft.Frame.Data.Entity;
  16. using ICSSoft.Frame.Helper;
  17. using ICSSoft.Base.ReferForm.AppReferForm;
  18. namespace ICSSoft.Frame.APP
  19. {
  20. public partial class FormICSTPAdd : DevExpress.XtraEditors.XtraForm
  21. {
  22. ICSTP personInfo;
  23. int flag;
  24. public FormICSTPAdd()
  25. {
  26. InitializeComponent();
  27. flag = 0;
  28. txtTPCode.ReadOnly = false;
  29. comTPType.Items.Clear();
  30. comIsOverDate.Items.Clear();
  31. comTPType.Items.Add("正常班");
  32. comTPType.Items.Add("加班");
  33. comIsOverDate.Items.Add("是");
  34. comIsOverDate.Items.Add("否");
  35. DataTable dv = ICSTPBLL.SelectTPCode();
  36. txtID.Text = AppConfig.GetGuid();
  37. txtUser.Text = AppConfig.UserCode;
  38. txtUseTime.Text = DateTime.Now.ToShortDateString();
  39. }
  40. public FormICSTPAdd(string id,string shifttypecode,string shiftcode)
  41. {
  42. InitializeComponent();
  43. txtSHIFTTYPEID.Text = shifttypecode;
  44. txtSHIFTID.Text = shiftcode;
  45. flag = 1;
  46. labTop.Text = "修改时段信息";
  47. comTPType.Items.Clear();
  48. comIsOverDate.Items.Clear();
  49. comTPType.Items.Add("加班");
  50. comTPType.Items.Add("不加班");
  51. comIsOverDate.Items.Add("是");
  52. comIsOverDate.Items.Add("否");
  53. comTPType.DropDownStyle = ComboBoxStyle.DropDown;
  54. comIsOverDate.DropDownStyle = ComboBoxStyle.DropDown;
  55. SearchMandayInfo(id);
  56. }
  57. private void SearchMandayInfo(string Id)
  58. {
  59. personInfo = ICSTPBLL.SearchPersonInfoByCode(Id, AppConfig.AppConnectString);
  60. txtID.Text = personInfo.ID;
  61. txtTPCode.Text= personInfo.TPCODE;
  62. txtItemCode.Text = ICSSoft.Frame.Data.BLL.ICSTPBLL.SelectSTTPID(personInfo.SHIFTTYPEID).Rows[0][0].ToString();
  63. btnShift.Text = ICSSoft.Frame.Data.BLL.ICSTPBLL.SelectSTPID(personInfo.SHIFTID).Rows[0][0].ToString();
  64. rTPDesc.Text=personInfo.TPDESC;
  65. txtTPSeq.Text=personInfo.TPSEQ.ToString() ;
  66. comTPType.Text=personInfo.TPTYPE;
  67. dBegTime.EditValue = FormatHelper.ToTimeString(personInfo.TPBTIME);
  68. dEndTime.EditValue = FormatHelper.ToTimeString(personInfo.TPETIME);
  69. // dBegTime.Text = FormatHelper.ToTimeString(personInfo.TPBTIME);
  70. // dEndTime.Text = FormatHelper.ToTimeString(personInfo.TPETIME);
  71. comIsOverDate.Text=personInfo.ISOVERDATE ;
  72. txtUser.Text=personInfo.MUSER ;
  73. txtUseTime.Text=personInfo.MTIME.ToString();
  74. }
  75. #region 移动窗体
  76. private const int WM_NCHITTEST = 0x84;
  77. private const int HTCLIENT = 0x1;
  78. private const int HTCAPTION = 0x2;
  79. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  80. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  81. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  82. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  83. //重写窗体,使窗体可以不通过自带标题栏实现移动
  84. protected override void WndProc(ref Message m)
  85. {
  86. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  87. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  88. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  89. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  90. switch (m.Msg)
  91. {
  92. case WM_NCHITTEST:
  93. base.WndProc(ref m);
  94. if ((int)m.Result == HTCLIENT)
  95. m.Result = (IntPtr)HTCAPTION;
  96. return;
  97. }
  98. //拦截双击标题栏、移动窗体的系统消息
  99. if (m.Msg != 0xA3)
  100. {
  101. base.WndProc(ref m);
  102. }
  103. }
  104. #endregion
  105. private void btnClose_Click(object sender, EventArgs e)
  106. {
  107. this.Close();
  108. }
  109. private void btnCancle_Click(object sender, EventArgs e)
  110. {
  111. this.Close();
  112. this.DialogResult = DialogResult.Cancel;
  113. }
  114. private void btnOK_Click(object sender, EventArgs e)
  115. {
  116. //1、开始时间不能早于结束时间 2、时间在班次时间之内 3、时间段不能重叠
  117. Regex rex = new Regex(@"^\d+$");
  118. int i = 0;
  119. int j = 0;
  120. //时段代码
  121. DataTable dy=ICSTPBLL.SelectTPCode();
  122. if (flag == 0)
  123. {
  124. foreach (DataRow dr in dy.Rows)
  125. {
  126. if (txtTPCode.Text == dr[0].ToString())
  127. {
  128. i++;
  129. }
  130. }
  131. }
  132. //判断为空
  133. if (rTPDesc.Text == "" || txtTPSeq.Text == "" || dBegTime.Text == "" || dEndTime.Text == "" || dBegTime.Text == "" || dEndTime.Text == "")
  134. {
  135. ICSBaseSimpleCode.AppshowMessageBox("不可为空!");
  136. return;
  137. }
  138. //获取输入值 开始时间、结束时间、是否跨天
  139. int begtime;
  140. int endtime;
  141. if (dBegTime.Text.Length == 8)
  142. {
  143. begtime = int.Parse(dBegTime.Text.Substring(0, 2) + dBegTime.Text.Substring(3, 2) + dBegTime.Text.Substring(6, 2));
  144. }
  145. else
  146. {
  147. begtime = int.Parse(dBegTime.Text.Substring(0, 1) + dBegTime.Text.Substring(2, 2) + dBegTime.Text.Substring(5, 2));
  148. }
  149. if (dEndTime.Text.Length == 8)
  150. {
  151. endtime = int.Parse(dEndTime.Text.Substring(0, 2) + dEndTime.Text.Substring(3, 2) + dEndTime.Text.Substring(6, 2));
  152. }
  153. else
  154. {
  155. endtime = int.Parse(dEndTime.Text.Substring(0, 1) + dEndTime.Text.Substring(2, 2) + dEndTime.Text.Substring(5, 2));
  156. }
  157. // int begtime = int.Parse((dBegTime.Text.Substring(0,2)+dBegTime.Text.Substring(3,2)+dBegTime.Text.Substring(6,2)).ToString());
  158. // int endtime = int.Parse((dEndTime.Text.Substring(0, 2) + dEndTime.Text.Substring(3, 2) + dEndTime.Text.Substring(6, 2)).ToString());
  159. string isoverday=comIsOverDate.Text;
  160. if (isoverday == "是")
  161. {
  162. isoverday += 120000;
  163. }
  164. //获取表中存在的开始结束时间、是否跨天信息
  165. DataTable bt = ICSTPBLL.SelectTPTime(txtSHIFTTYPEID.Text,txtSHIFTID.Text);
  166. //判断时间段是否重叠
  167. foreach (DataRow dd in bt.Rows)
  168. {
  169. if (dd["ID"].ToString() != txtID.Text)
  170. {
  171. int tpbtime = int.Parse(dd[0].ToString());//开始时间
  172. int tpetime = int.Parse(dd[1].ToString());//结束时间
  173. string over = dd[3].ToString();
  174. if (over == "是")
  175. {
  176. tpetime += 120000;
  177. }
  178. if (begtime > tpbtime && begtime < tpetime)
  179. {
  180. j++;
  181. }
  182. else if (endtime > tpbtime && endtime < tpetime)
  183. {
  184. j++;
  185. }
  186. else if (begtime > tpbtime && endtime < tpetime)
  187. {
  188. j++;
  189. }
  190. else if (begtime < tpbtime && endtime > tpetime)
  191. {
  192. j++;
  193. }
  194. else if (isoverday == "是" && over == "是")
  195. {
  196. j++;
  197. }
  198. }
  199. }
  200. //获取班次的开始结束时间、是否跨天
  201. string sbt = ICSTPBLL.SelectBegTime(btnShift.Text).Rows[0][0].ToString();
  202. string set = ICSTPBLL.SelectEndTime(btnShift.Text).Rows[0][0].ToString();
  203. int sbegtime = int.Parse(sbt);
  204. int sendtime = int.Parse(set);
  205. string sisoverday =ICSTPBLL.SelectIsOverDay(btnShift.Text).Rows[0][0].ToString();
  206. if (sisoverday == "是")
  207. {
  208. sendtime += 120000;
  209. }
  210. if (!rex.Match(txtTPSeq.Text).Success)
  211. {
  212. ICSBaseSimpleCode.AppshowMessageBox("时段次序只可填入正整数!");
  213. return;
  214. }
  215. else if (i != 0 && flag == 0)//判断 新增 时[时段代码]是否唯一
  216. {
  217. ICSBaseSimpleCode.AppshowMessageBox("时段代码已存在!");
  218. return;
  219. }
  220. else if (endtime <= begtime )
  221. {
  222. ICSBaseSimpleCode.AppshowMessageBox("开始时间不能等于或早于结束时间!");
  223. return;
  224. }
  225. else if(j!=0)
  226. {
  227. ICSBaseSimpleCode.AppshowMessageBox("同一班制的时段时间不能重叠!");
  228. return;
  229. }
  230. else if(isoverday=="是" && sisoverday == "否")
  231. {
  232. ICSBaseSimpleCode.AppshowMessageBox("所属的[班次]没有跨天!");
  233. return;
  234. }
  235. else if(begtime<sbegtime||endtime>sendtime)
  236. {
  237. ICSBaseSimpleCode.AppshowMessageBox("时间超出[班次]时间范围!");
  238. return;
  239. }
  240. else if (comTPType.Text != "正常班" && comTPType.Text != "加班")
  241. {
  242. ICSBaseSimpleCode.AppshowMessageBox("[时段类型]错误!");
  243. return;
  244. }
  245. else if (comIsOverDate.Text != "是" && comIsOverDate.Text != "否")
  246. {
  247. ICSBaseSimpleCode.AppshowMessageBox("[是否跨天]错误!");
  248. return;
  249. }
  250. else
  251. {
  252. try
  253. {
  254. ICSTP personInfo = new ICSTP();
  255. personInfo.ID = txtID.Text;
  256. personInfo.TPCODE = txtTPCode.Text;
  257. personInfo.SHIFTTYPEID = ICSSoft.Frame.Data.BLL.ICSTPBLL.SelectSTTPID1(txtItemCode.Text).Rows[0][0].ToString();
  258. personInfo.SHIFTID = ICSSoft.Frame.Data.BLL.ICSTPBLL.SelectSTPID1(btnShift.Text).Rows[0][0].ToString();
  259. personInfo.TPDESC = rTPDesc.Text;
  260. personInfo.TPSEQ = int.Parse(txtTPSeq.Text);
  261. personInfo.TPTYPE = comTPType.Text;
  262. personInfo.TPBTIME = begtime;
  263. personInfo.TPETIME = endtime;
  264. // personInfo.TPBTIME = int.Parse(dBegTime.Text.Substring(0, 2) + dBegTime.Text.Substring(3, 2) + dBegTime.Text.Substring(6, 2));
  265. // personInfo.TPETIME = int.Parse(dEndTime.Text.Substring(0, 2) + dEndTime.Text.Substring(3, 2) + dEndTime.Text.Substring(6, 2));
  266. personInfo.ISOVERDATE = comIsOverDate.Text;
  267. personInfo.MUSER = txtUser.Text;
  268. personInfo.MUSERName = AppConfig.UserName;
  269. personInfo.MTIME = System.DateTime.Parse(txtUseTime.Text);
  270. personInfo.WorkPoint = AppConfig.WorkPointCode;
  271. ICSTPBLL.Add(personInfo, AppConfig.AppConnectString);
  272. ICSBaseSimpleCode.AppshowMessageBox("操作成功!");
  273. this.Close();
  274. }
  275. catch (Exception ex)
  276. {
  277. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  278. }
  279. }
  280. }
  281. private void txtItemCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  282. {
  283. if (btnShift.Text != "")
  284. {
  285. btnShift.Text = "";
  286. }
  287. txtItemCode.Text = "";
  288. ButtonEdit btn = (ButtonEdit)sender;
  289. string sql = @"select SHIFTTYPECODE as [班制代码],SHIFTTYPEDESC as [描述],EFFDATE as [开始时间],IVLDATE as [结束时间],ID
  290. from dbo.ICSSHIFTTYPE
  291. where WorkPoint='"+AppConfig.WorkPointCode+"'";
  292. sql = string.Format(sql);
  293. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  294. FormDataRefer reForm = new FormDataRefer();
  295. reForm.FormTitle = "班制信息";
  296. DataTable menuData = data;
  297. reForm.DataSource = menuData;
  298. reForm.MSelectFlag = false;
  299. reForm.RowIndexWidth = 35;
  300. reForm.HideCols.Add("ID");
  301. reForm.FormWidth = 800;
  302. reForm.FormHeight = 600;
  303. reForm.FilterKey = btn.Text;
  304. //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
  305. if (reForm.ShowDialog() == DialogResult.OK)
  306. {
  307. DataTable retData = reForm.ReturnData;
  308. foreach (DataRow dr in retData.Rows)
  309. {
  310. txtItemCode.Text = dr["班制代码"].ToString();
  311. }
  312. }
  313. }
  314. private void btnShift_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  315. {
  316. if(txtItemCode.Text=="")
  317. {
  318. ICSBaseSimpleCode.AppshowMessageBox("请先选择[班制代码]!");
  319. return;
  320. }
  321. btnShift.Text = "";
  322. ButtonEdit btn = (ButtonEdit)sender;
  323. string str = ICSTPBLL.SelectSTTPID1(txtItemCode.Text).Rows[0][0].ToString();
  324. string sql = @"select SHIFTCODE as [班次编码],SHIFTDESC as [描述],ISOVERDAY as [是否跨天],SHIFTBTIME as [开始时间],SHIFTETIME as [结束时间],ID
  325. from dbo.ICSSHIFT
  326. where SHIFTTYPEID='" + str + "' and WorkPoint='" + AppConfig.WorkPointCode + "'";
  327. sql = string.Format(sql);
  328. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  329. DataTable dt = new DataTable();
  330. dt.Columns.Add("SHIFTCODE", typeof(string));
  331. dt.Columns["SHIFTCODE"].ColumnName = "班次编码";
  332. dt.Columns.Add("SHIFTDESC", typeof(string));
  333. dt.Columns["SHIFTDESC"].ColumnName = "描述";
  334. dt.Columns.Add("ISOVERDAY", typeof(string));
  335. dt.Columns["ISOVERDAY"].ColumnName = "是否跨天";
  336. dt.Columns.Add("SHIFTBTIME", typeof(string));
  337. dt.Columns["SHIFTBTIME"].ColumnName = "开始时间";
  338. dt.Columns.Add("SHIFTETIME", typeof(string));
  339. dt.Columns["SHIFTETIME"].ColumnName = "结束时间";
  340. if (data != null && data.Rows.Count > 0)
  341. {
  342. for (int i = 0; i < data.Rows.Count;i++ )
  343. {
  344. DataRow dr = dt.NewRow();
  345. dr["班次编码"] = data.Rows[i]["班次编码"].ToString();
  346. dr["描述"] = data.Rows[i]["描述"].ToString();
  347. dr["是否跨天"] = data.Rows[i]["是否跨天"].ToString();
  348. dr["开始时间"] = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(data.Rows[i]["开始时间"].ToString()));
  349. dr["结束时间"] = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(int.Parse(data.Rows[i]["结束时间"].ToString()));
  350. dt.Rows.Add(dr);
  351. }
  352. }
  353. FormDataRefer reForm = new FormDataRefer();
  354. reForm.FormTitle = "班次信息";
  355. DataTable menuData = dt;
  356. reForm.DataSource = menuData;
  357. reForm.MSelectFlag = false;
  358. reForm.RowIndexWidth = 35;
  359. reForm.HideCols.Add("ID");
  360. reForm.FormWidth = 800;
  361. reForm.FormHeight = 600;
  362. reForm.FilterKey = btn.Text; //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
  363. if (reForm.ShowDialog() == DialogResult.OK)
  364. {
  365. DataTable retData = reForm.ReturnData;
  366. foreach (DataRow dr in retData.Rows)
  367. {
  368. btnShift.Text = dr["班次编码"].ToString();
  369. }
  370. }
  371. }
  372. private void txtTPCode_TextChanged(object sender, EventArgs e)
  373. {
  374. }
  375. }
  376. }