锐腾搅拌上料功能
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.

302 lines
11 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.Entity;
  15. using ICSSoft.Base.ReferForm.AppReferForm;
  16. using ICSSoft.Frame.Data.BLL;
  17. using ICSSoft.Frame.Helper;
  18. namespace ICSSoft.Frame.APP
  19. {
  20. public partial class FormICSShiftAdd : DevExpress.XtraEditors.XtraForm
  21. {
  22. FormICSShiftUIModel shiftUIModel;
  23. int Flag;
  24. /// <summary>
  25. /// add new
  26. /// </summary>
  27. public FormICSShiftAdd()
  28. {
  29. InitializeComponent();
  30. chargeFormState("Add");
  31. Flag = 0;
  32. }
  33. /// <summary>
  34. /// edit
  35. /// </summary>
  36. /// <param name="cPersonCode"></param>
  37. public FormICSShiftAdd(string SHIFTCODE)
  38. {
  39. InitializeComponent();
  40. chargeFormState("Edit");
  41. SearchShiftInfo(SHIFTCODE);
  42. Flag = 1;
  43. }
  44. private void chargeFormState(string state)
  45. {
  46. switch (state)
  47. {
  48. case "Add":
  49. txtSHIFTCODE.Properties.ReadOnly = false;
  50. txtSHIFTSEQ.Properties.ReadOnly = false;
  51. txtMUSERName.Text = AppConfig.UserName;
  52. txtMTIME.Text = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString();
  53. txtMUSERName.Properties.ReadOnly = true;
  54. txtMTIME.Properties.ReadOnly = true;
  55. break;
  56. case "Edit":
  57. txtSHIFTCODE.Properties.ReadOnly = true;
  58. txtSHIFTSEQ.Properties.ReadOnly = false;
  59. txtMUSERName.Properties.ReadOnly = true;
  60. txtMTIME.Properties.ReadOnly = true;
  61. break;
  62. }
  63. }
  64. #region 移动窗体
  65. private const int WM_NCHITTEST = 0x84;
  66. private const int HTCLIENT = 0x1;
  67. private const int HTCAPTION = 0x2;
  68. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  69. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  70. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  71. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  72. //重写窗体,使窗体可以不通过自带标题栏实现移动
  73. protected override void WndProc(ref Message m)
  74. {
  75. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  76. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  77. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  78. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  79. switch (m.Msg)
  80. {
  81. case WM_NCHITTEST:
  82. base.WndProc(ref m);
  83. if ((int)m.Result == HTCLIENT)
  84. m.Result = (IntPtr)HTCAPTION;
  85. return;
  86. }
  87. //拦截双击标题栏、移动窗体的系统消息
  88. if (m.Msg != 0xA3)
  89. {
  90. base.WndProc(ref m);
  91. }
  92. }
  93. #endregion
  94. private void SearchShiftInfo(string SHIFTCODE)
  95. {
  96. shiftUIModel = ICSShiftBLL.SearchShiftInfoByCode(SHIFTCODE, AppConfig.AppConnectString);
  97. txtSHIFTCODE.Text = shiftUIModel.SHIFTCODE;
  98. txtSHIFTTYPECODE.Text = shiftUIModel.shifttype.SHIFTTYPECODE;
  99. txtSHIFTSEQ.Text = shiftUIModel.SHIFTSEQ.ToString();
  100. txtSHIFTDESC.Text = shiftUIModel.SHIFTDESC;
  101. dtSHIFTBTIME.EditValue = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(shiftUIModel.SHIFTBTIME);
  102. dtSHIFTETIME.EditValue = ICSSoft.Frame.Helper.FormatHelper.ToTimeString(shiftUIModel.SHIFTETIME);
  103. txtISOVERDAY.Text = shiftUIModel.ISOVERDAY;
  104. txtMUSERName.Text = AppConfig.UserName;
  105. txtMTIME.Text = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString();
  106. }
  107. #region 关闭
  108. private void btnCancle_Click(object sender, EventArgs e)
  109. {
  110. this.Close();
  111. this.DialogResult = DialogResult.Cancel;
  112. }
  113. private void btnClose_Click(object sender, EventArgs e)
  114. {
  115. this.Close();
  116. this.DialogResult = DialogResult.Cancel;
  117. }
  118. #endregion
  119. #region 班制代码按钮
  120. private void txtShiftTypeCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  121. {
  122. ButtonEdit btn = (ButtonEdit)sender;
  123. string sql = "select distinct SHIFTTYPECODE as [班制代码],SHIFTTYPEDESC as [班制描述] from dbo.ICSSHIFTTYPE with(nolock) WHERE 1=1";
  124. //object obj = AppConfig.InvokeWebservice(AppConfig.BaseServiceUri, "WebBaseService", "BaseService", "GetHuaRongErpConnectString", new object[] { });
  125. //if (obj == null)
  126. //{
  127. // ICSBaseSimpleCode.AppshowMessageBox(1, "ERP数据库连接取得失败!");
  128. //}
  129. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  130. FormDataRefer reForm = new FormDataRefer();
  131. reForm.FormTitle = "班制信息";
  132. DataTable menuData = data;
  133. reForm.DataSource = menuData;
  134. reForm.MSelectFlag = false;
  135. reForm.RowIndexWidth = 35;
  136. reForm.HideCols.Add("ID");
  137. reForm.FormWidth = 500;
  138. reForm.FormHeight = 500;
  139. //reForm.FilterKey = btn.Text;
  140. //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
  141. if (reForm.ShowDialog() == DialogResult.OK)
  142. {
  143. DataTable retData = reForm.ReturnData;
  144. foreach (DataRow dr in retData.Rows)
  145. {
  146. txtSHIFTTYPECODE.Text = dr["班制代码"].ToString();
  147. //txtItemName.Text = dr["存货名称"].ToString();
  148. }
  149. }
  150. }
  151. #endregion
  152. #region 新增 修改
  153. private void btnOK_Click(object sender, EventArgs e)
  154. {
  155. if (Flag == 0)
  156. {
  157. bool b = ICSShiftBLL.IsIncludingShiftCode(txtSHIFTCODE.Text.Trim(), AppConfig.AppConnectString);
  158. if (!b)
  159. {
  160. ICSBaseSimpleCode.AppshowMessageBox("班次代码已经存在");
  161. return;
  162. }
  163. }
  164. //bool a = ICSShiftBLL.IsIncludingInShiftSeq(int.Parse(txtSHIFTSEQ.Text.Trim()), ICSShiftBLL.SelectShiftTypeId(txtSHIFTTYPECODE.Text).Rows[0][0].ToString());
  165. //if (!a)
  166. //{
  167. // ICSBaseSimpleCode.AppshowMessageBox("班次次序在班制中已经存在");
  168. // return;
  169. //}
  170. if (txtSHIFTSEQ.Text.Trim() == "")
  171. {
  172. ICSBaseSimpleCode.AppshowMessageBox("班次次序不能为空!");
  173. return;
  174. }
  175. if (txtSHIFTTYPECODE.Text.Trim() == "")
  176. {
  177. ICSBaseSimpleCode.AppshowMessageBox("班制代码不能为空!");
  178. return;
  179. }
  180. if (txtSHIFTDESC.Text.Trim() == "")
  181. {
  182. ICSBaseSimpleCode.AppshowMessageBox("班次描述不能为空!");
  183. return;
  184. }
  185. if (txtISOVERDAY.SelectedItem ==null)
  186. {
  187. ICSBaseSimpleCode.AppshowMessageBox("请选择是否跨天!");
  188. return;
  189. }
  190. FormICSShiftUIModel shiftInfo = new FormICSShiftUIModel();
  191. shiftInfo.ID = AppConfig.GetGuid();
  192. shiftInfo.SHIFTCODE = txtSHIFTCODE.Text.Trim();
  193. shiftInfo.SHIFTTYPEID = ICSSoft.Frame.Data.BLL.ICSShiftBLL.SelectShiftTypeId(txtSHIFTTYPECODE.Text).Rows[0][0].ToString();
  194. shiftInfo.SHIFTSEQ = int.Parse(txtSHIFTSEQ.Text.Trim());
  195. shiftInfo.SHIFTDESC = txtSHIFTDESC.Text.Trim();
  196. int bt;
  197. int et;
  198. if (dtSHIFTBTIME.Text.Length == 8)
  199. {
  200. bt = int.Parse(dtSHIFTBTIME.Text.Substring(0, 2) + dtSHIFTBTIME.Text.Substring(3, 2) + dtSHIFTBTIME.Text.Substring(6, 2));
  201. }
  202. else
  203. {
  204. bt = int.Parse(dtSHIFTBTIME.Text.Substring(0, 1) + dtSHIFTBTIME.Text.Substring(2, 2) + dtSHIFTBTIME.Text.Substring(5, 2));
  205. }
  206. if (dtSHIFTETIME.Text.Length==8)
  207. {
  208. et = int.Parse(dtSHIFTETIME.Text.Substring(0, 2) + dtSHIFTETIME.Text.Substring(3, 2) + dtSHIFTETIME.Text.Substring(6, 2));
  209. }
  210. else
  211. {
  212. et = int.Parse(dtSHIFTETIME.Text.Substring(0, 1) + dtSHIFTETIME.Text.Substring(2, 2) + dtSHIFTETIME.Text.Substring(5, 2));
  213. }
  214. shiftInfo.SHIFTBTIME = bt;
  215. shiftInfo.SHIFTETIME = et;
  216. int dt = bt - et;
  217. if ((dt > 0||dt==0) && txtISOVERDAY.Text == "否" || dt < 0 && txtISOVERDAY.Text == "是")
  218. {
  219. ICSBaseSimpleCode.AppshowMessageBox("选择是否跨天有误,请重新选择!");
  220. return;
  221. }
  222. shiftInfo.ISOVERDAY = txtISOVERDAY.Text;
  223. shiftInfo.MUSER = AppConfig.UserId;
  224. shiftInfo.MUSERName = AppConfig.UserName;
  225. shiftInfo.MTIME = System.DateTime.Parse(txtMTIME.Text);
  226. shiftInfo.WorkPoint = AppConfig.WorkPointCode;
  227. shiftInfo.EATTRIBUTE1 = null;
  228. try
  229. {
  230. ICSShiftBLL.Add(shiftInfo, AppConfig.AppConnectString);
  231. this.Close();
  232. ICSBaseSimpleCode.AppshowMessageBox("操作成功");
  233. }
  234. catch (Exception ex)
  235. {
  236. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  237. }
  238. }
  239. #endregion
  240. private void FormICSShiftAdd_Load()
  241. {
  242. DataTable dt = new DataTable();
  243. dt = ICSShiftBLL.GetShiftCode();
  244. string str = dt.Rows[0]["SHIFTCODE"].ToString();
  245. if (str == "1101000001")
  246. {
  247. txtSHIFTCODE.Text = (int.Parse(str) + 1).ToString();
  248. }
  249. else
  250. {
  251. str = "1101000001";
  252. }
  253. }
  254. }
  255. }