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

285 lines
12 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 System.Data.SqlClient;
  10. using ICSSoft.Frame.Data.BLL;
  11. using ICSSoft.Base.Language.Tool;
  12. using ICSSoft.Base.UserControl.MessageControl;
  13. using ICSSoft.Base.Report.Filter;
  14. using ICSSoft.Base.Config.DBHelper;
  15. using ICSSoft.Base.UserControl.FormControl;
  16. using ICSSoft.Base.ReferForm.AppReferForm;
  17. using ICSSoft.Base.Lable.PrintTool;
  18. using ICSSoft.Base.Config.AppConfig;
  19. using ICSSoft.Base.Report.GridReport;
  20. using ICSSoft.Frame.APP.Entity;
  21. using ICSSoft.Frame.APP;
  22. using ICSSoft.Frame.Data.Entity;
  23. namespace ICSSoft.Frame.APP
  24. {
  25. public partial class FormICSItemOPPriceAdd : DevExpress.XtraEditors.XtraForm
  26. {
  27. ICSItemOPPrice EQPSTPUIModel;
  28. int flag;
  29. string eqpstpid;
  30. public FormICSItemOPPriceAdd()
  31. {
  32. InitializeComponent();
  33. init();
  34. chargeFormState("Add");
  35. flag = 0;
  36. eqpstpid = AppConfig.GetGuid();
  37. }
  38. public FormICSItemOPPriceAdd(string id)
  39. {
  40. InitializeComponent();
  41. init();
  42. chargeFormState("Edit");
  43. SearchTypeInfo(id);
  44. flag = 1;
  45. eqpstpid = id;
  46. }
  47. private void chargeFormState(string state)
  48. {
  49. switch (state)
  50. {
  51. case "Add":
  52. txtMUSERName.Text = AppConfig.UserName;
  53. txtMTIME.Text = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss").ToString();
  54. txtMUSERName.Properties.ReadOnly = true;
  55. txtMTIME.Properties.ReadOnly = true;
  56. break;
  57. case "Edit":
  58. //txtItemCode.Properties.Buttons[0].Visible = false;
  59. //txtItemCode.Enabled = false;
  60. gluItemCode.Properties.Buttons[0].Visible = false;
  61. gluItemCode.Enabled = false;
  62. txtOPCODE.Properties.Buttons[0].Visible = false;
  63. txtOPCODE.Enabled = false;
  64. break;
  65. }
  66. }
  67. private void SearchTypeInfo(string id)
  68. {
  69. DataTable dt = ICSItemOPPriceBLL.searchInfoByID(id, AppConfig.AppConnectString);
  70. if (dt != null && dt.Rows.Count > 0)
  71. {
  72. eqpstpid = dt.Rows[0]["ID"].ToString();
  73. //txtItemCode.Text = dt.Rows[0]["ITEMCODE"].ToString();
  74. gluItemCode.Text = dt.Rows[0]["ITEMCODE"].ToString();
  75. txtOPCODE.Text = dt.Rows[0]["OPCODE"].ToString();
  76. txtItemName.Text = dt.Rows[0]["ItemName"].ToString();
  77. txtOPDESC.Text = dt.Rows[0]["OPDESC"].ToString();
  78. if (!string.IsNullOrEmpty(dt.Rows[0]["Price"].ToString()))
  79. {
  80. txtPrice.Text = dt.Rows[0]["Price"].ToString();
  81. }
  82. else
  83. {
  84. txtPrice.Text = "0";
  85. }
  86. txtMUSERName.Text = AppConfig.UserName;
  87. txtMTIME.Text = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss").ToString();
  88. }
  89. }
  90. private string check()
  91. {
  92. string msg = "";
  93. Decimal decValue = 0m;
  94. //if (txtItemCode.Text.Trim() == "")
  95. // msg += "存货编码不能为空!\n";
  96. if (gluItemCode.Text.Trim() == "")
  97. msg += "存货编码不能为空!\n";
  98. if (txtOPCODE.Text.Trim() == "")
  99. msg += "工序代码不能为空!\n";
  100. //if (txtEQPTypeCode.Text.Trim() == "")
  101. // msg += "设备类型不能为空!\n";
  102. if (txtPrice.Text.Trim() == "")
  103. msg += "价格不能为空!\n";
  104. else
  105. {
  106. if (!Decimal.TryParse(txtPrice.Text.Trim(), out decValue))
  107. {
  108. msg += "价格格式不正确!\n";
  109. }
  110. }
  111. //if (txtRTIME.Text.Trim() == "")
  112. // msg += "准备工时不能为空!\n";
  113. //else
  114. //{
  115. // if (!Decimal.TryParse(txtRTIME.Text.Trim(), out decValue))
  116. // {
  117. // msg += "准备工时格式不正确!\n";
  118. // }
  119. //}
  120. //if (flag == 0)
  121. //{
  122. // //if (!ICSItemOPPriceBLL.IsIncluding(txtItemCode.Text.Trim(), txtOPCODE.Text.Trim(), txtEQPCODE.Text.Trim(), AppConfig.AppConnectString))
  123. // if (!ICSItemOPPriceBLL.IsIncluding(gluItemCode.Text.Trim(), txtOPCODE.Text.Trim(), "", AppConfig.AppConnectString))
  124. // msg += "该产品工序设备类型对应的价格信息已存在!\n";
  125. //}
  126. return msg;
  127. }
  128. private void btnOK_Click(object sender, EventArgs e)
  129. {
  130. try
  131. {
  132. string msg = check();
  133. if (!string.IsNullOrEmpty(msg))
  134. {
  135. ICSBaseSimpleCode.AppshowMessageBox(msg);
  136. return;
  137. }
  138. ICSItemOPPrice eqpstp = new ICSItemOPPrice();
  139. eqpstp.ID = eqpstpid;
  140. //eqpstp.ITEMCODE = txtItemCode.Text;
  141. eqpstp.ITEMCODE = gluItemCode.Text;
  142. eqpstp.OPCODE = txtOPCODE.Text;
  143. eqpstp.Price =Convert.ToDecimal(txtPrice.Text.Equals("")? "0":txtPrice.Text);
  144. eqpstp.MUSER = AppConfig.UserId;
  145. eqpstp.MUSERName = AppConfig.UserName;
  146. eqpstp.MTIME = DateTime.Now;
  147. eqpstp.WorkPoint = AppConfig.WorkPointCode;
  148. eqpstp.EATTRIBUTE1 = "" ;
  149. ICSItemOPPriceBLL.Add(eqpstp, AppConfig.AppConnectString);
  150. if (flag == 0)
  151. {
  152. ICSBaseSimpleCode.AppshowMessageBox("增加成功");
  153. this.Close();
  154. this.DialogResult = DialogResult.Yes;
  155. }
  156. else if (flag == 1)
  157. {
  158. ICSBaseSimpleCode.AppshowMessageBox("修改成功");
  159. this.Close();
  160. this.DialogResult = DialogResult.Yes;
  161. }
  162. }
  163. catch (Exception ex) {
  164. MessageBox.Show(ex.Message);
  165. }
  166. }
  167. #region 关闭
  168. private void btnCancle_Click(object sender, EventArgs e)
  169. {
  170. this.Close();
  171. //this.DialogResult = DialogResult.Cancel;
  172. }
  173. private void btnClose_Click(object sender, EventArgs e)
  174. {
  175. this.Close();
  176. //this.DialogResult = DialogResult.Cancel;
  177. }
  178. #endregion
  179. private void gluItemCode_EditValueChanged(object sender, EventArgs e)
  180. {
  181. var o = gluItemCode.Properties.GetRowByKeyValue(gluItemCode.EditValue);
  182. if (o is DataRowView)
  183. {
  184. DataRowView RowView = o as DataRowView;
  185. txtItemName.Text = RowView.Row["存货名称"].ToString();
  186. }
  187. init3();
  188. }
  189. private void init3()
  190. {
  191. #region 工序代码
  192. // string sql2 = @"select distinct
  193. // a.OPCODE as [工序代码],
  194. // b.OPDESC as [工序]
  195. // from ICSITEMROUTE2OP a
  196. // left join ICSOP b on a.OPCODE=b.OPCODE
  197. //where a.ITEMCODE='" + gluItemCode.Text + "' and 1=1";
  198. // DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql2).Tables[0];
  199. // if (data == null || data.Rows.Count == 0)
  200. // {
  201. string sql2 = @"select distinct
  202. a.OPCODE as [],
  203. c.OPDESC as []
  204. from ICSITEMROUTE2OPLot a
  205. left join ICSINVENTORY b on a.ITEMCODE=b.INVCODE
  206. left join ICSOP c on a.OPCODE=c.OPCODE
  207. where b.INVCODE='" + gluItemCode.Text + "' and 1=1";
  208. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql2).Tables[0];
  209. //}
  210. txtOPCODE.Properties.ValueMember = "工序代码";
  211. txtOPCODE.Properties.DisplayMember = "工序代码";
  212. txtOPCODE.Properties.DataSource = data;
  213. txtOPCODE.Properties.NullText = "";//空时的值
  214. txtOPCODE.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  215. txtOPCODE.Properties.ValidateOnEnterKey = true;//回车确认
  216. txtOPCODE.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  217. txtOPCODE.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  218. //自适应宽度
  219. txtOPCODE.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  220. #endregion
  221. }
  222. #region 初始化查询条件
  223. private void init()
  224. {
  225. #region 存货编码
  226. string sql = "SELECT DISTINCT INVCODE AS [存货编码],INVNAME AS [存货名称] FROM ICSINVENTORY ORDER BY INVCODE";
  227. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  228. gluItemCode.Properties.ValueMember = "存货编码";
  229. gluItemCode.Properties.DisplayMember = "存货编码";
  230. gluItemCode.Properties.DataSource = dt;
  231. gluItemCode.Properties.NullText = "";//空时的值
  232. gluItemCode.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  233. gluItemCode.Properties.ValidateOnEnterKey = true;//回车确认
  234. gluItemCode.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  235. gluItemCode.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  236. //自适应宽度
  237. gluItemCode.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  238. #endregion
  239. #region 工序代码
  240. string sql2 = "SELECT DISTINCT null AS [工序代码],null as [工序] ";
  241. DataTable dt2 = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql2).Tables[0];
  242. txtOPCODE.Properties.ValueMember = "工序代码";
  243. txtOPCODE.Properties.DisplayMember = "工序代码";
  244. txtOPCODE.Properties.DataSource = dt2;
  245. txtOPCODE.Properties.NullText = "";//空时的值
  246. txtOPCODE.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体
  247. txtOPCODE.Properties.ValidateOnEnterKey = true;//回车确认
  248. txtOPCODE.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  249. txtOPCODE.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容
  250. //自适应宽度
  251. txtOPCODE.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  252. #endregion
  253. }
  254. #endregion
  255. private void txtOPCODE_EditValueChanged(object sender, EventArgs e)
  256. {
  257. var o = txtOPCODE.Properties.GetRowByKeyValue(txtOPCODE.EditValue);
  258. if (o is DataRowView)
  259. {
  260. DataRowView RowView = o as DataRowView;
  261. txtOPCODE.Text = RowView.Row["工序代码"].ToString();
  262. txtOPDESC.Text = RowView.Row["工序"].ToString();
  263. }
  264. }
  265. }
  266. }