OQC_Inspection.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Text;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. using UAS_MES_NEW.CustomControl.DataGrid_View;
  8. using UAS_MES_NEW.DataOperate;
  9. using UAS_MES_NEW.Entity;
  10. using UAS_MES_NEW.PublicMethod;
  11. namespace UAS_MES_NEW.OQC
  12. {
  13. public partial class OQC_Inspection : Form
  14. {
  15. AutoSizeFormClass asc = new AutoSizeFormClass();
  16. DataHelper dh;
  17. LogStringBuilder sql = new LogStringBuilder();
  18. DataTable dt;
  19. //用来存放已打开过的行
  20. List<DataGridViewRow> dgvr = new List<DataGridViewRow>();
  21. string ErrorMessage = "";
  22. public OQC_Inspection()
  23. {
  24. InitializeComponent();
  25. }
  26. private void 生成送检批_Load(object sender, EventArgs e)
  27. {
  28. asc.controllInitializeSize(this);
  29. dh = SystemInf.dh;
  30. //工单号放大镜配置
  31. ma_code.TableName = "make";
  32. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号";
  33. ma_code.FormName = Name;
  34. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode" };
  35. ma_code.Condition = "ma_statuscode='STARTED'";
  36. }
  37. private void Clean_Click(object sender, EventArgs e)
  38. {
  39. OperateResult.Clear();
  40. }
  41. private void NewBatch_Click(object sender, EventArgs e)
  42. {
  43. if (CheckStep())
  44. {
  45. string ob_id = dh.GetSEQ("OQCBatch_SEQ");
  46. string checkno = "";
  47. LogicHandler.GetSerialNumByCaller("Make!CheckQC", out checkno);
  48. sql.Clear();
  49. sql.Append("insert into OQCBatch (ob_id, ob_checkno ,ob_status, ob_source,ob_indate,ob_checkman) ");
  50. sql.Append("values( '" + ob_id + "','" + checkno + "', 'ENTERING', '新增', sysdate, '" + User.UserName + "')");
  51. dh.ExecuteSql(sql.GetString(), "insert");
  52. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "生成新品", "生成新批次成功", "", ob_checkno.Text);
  53. //生成成功,将批次号,以及批次状态写入页面
  54. BaseUtil.SetFormValue(Controls, dh.getFieldsDataByCondition("OQCBatch", new string[] { "ob_checkno", "ob_status" }, "ob_id='" + ob_id + "'"));
  55. }
  56. }
  57. private void 生成送检批_SizeChanged(object sender, EventArgs e)
  58. {
  59. asc.controlAutoSize(this);
  60. }
  61. private void bi_outboxcode_KeyDown(object sender, KeyEventArgs e)
  62. {
  63. if (e.KeyCode == Keys.Enter)
  64. {
  65. //只允许用户操作在录入状态的箱号
  66. if (ob_status.Text == "在录入")
  67. {
  68. //如果勾选了撤销
  69. if (WithDraw.Checked)
  70. {
  71. dt = (DataTable)dh.ExecuteSql("select obd_obid from OQCBatchDetail where obd_outboxcode='" + pa_outboxcode.Text + "'", "select");
  72. if (dt.Rows.Count > 0)
  73. {
  74. dh.ExecuteSql("delete from OQCBatchDetail where obd_outboxcode='" + pa_outboxcode.Text + "'", "delete");
  75. dh.UpdateByCondition("OQCBatch", "ob_batchqty =(select count(1) from OQCBatchDetail where obd_checkno='" + ob_checkno.Text + "')", "ob_checkno='" + ob_checkno.Text + "'");
  76. dh.UpdateByCondition("OQCBatch", "ob_prodcode=''", "ob_batchqty=0");
  77. GetBatch.PerformClick();
  78. OperateResult.AppendText(">>箱号已从送检批中移除\n", Color.Green);
  79. }
  80. else OperateResult.AppendText(">>箱号不在抽检明细中\n", Color.Red);
  81. }
  82. //未勾选撤销
  83. else
  84. {
  85. dt = (DataTable)dh.ExecuteSql("select pa_prodcode,pa_makecode from package where pa_outboxcode='" + pa_outboxcode.Text + "'", "select");
  86. if (dt.Rows.Count > 0)
  87. {
  88. string pa_prodcode = dt.Rows[0]["pa_prodcode"].ToString();
  89. string pa_makecode = dt.Rows[0]["pa_makecode"].ToString();
  90. if (dt.Rows[0]["pa_prodcode"].ToString() == ma_prodcode.Text || ma_prodcode.Text == "")
  91. {
  92. dt = dh.getFieldsDataByCondition("OQCBatchDetail", new string[] { "obd_checkno" }, "obd_outboxcode='" + pa_outboxcode.Text + "'");
  93. //如果不存在送检批中
  94. if (dt.Rows.Count == 0)
  95. {
  96. if (ma_prodcode.Text == "")
  97. {
  98. dh.UpdateByCondition("Oqcbatch", "ob_prodcode='" + pa_prodcode + "'", "ob_checkno='" + ob_checkno.Text + "'");
  99. }
  100. if (pa_makecode == "")
  101. {
  102. string macode = dh.getFieldDataByCondition("packagedetail", "pd_makecode", "pd_outboxcode='" + pa_outboxcode.Text + "'").ToString();
  103. dh.UpdateByCondition("Oqcbatch", "ob_makecode='" + pa_makecode + "'", "ob_checkno='" + ob_checkno.Text + "'");
  104. }
  105. sql.Clear();
  106. sql.Append("insert into OQCBatchDetail (obd_id,obd_obid,obd_checkno, obd_sncode,obd_outboxcode,");
  107. sql.Append("obd_makecode, obd_builddate) select OQCBatchDetail_seq.nextval,(select ob_id from OQCBatch where ob_checkno='" + ob_checkno.Text + "'),'" + ob_checkno.Text + "',v_barcode");
  108. sql.Append(",v_outboxcode,v_makecode,sysdate from MES_PACKAGE_VIEW where v_outboxcode='" + pa_outboxcode.Text + "'");
  109. dh.ExecuteSql(sql.GetString(), "insert");
  110. string obd_id = dh.getFieldDataByCondition("OQCBatchDetail", "obd_id", "obd_outboxcode='" + pa_outboxcode.Text + "'").ToString();
  111. dh.UpdateByCondition("OQCBatch", "ob_nowcheckqty =(select count(1) from OQCBatchDetail where obd_checkno='" + ob_checkno.Text + "')", "ob_checkno='" + ob_checkno.Text + "'");
  112. dh.UpdateByCondition("makeserial", "ms_checkno='" + ob_checkno.Text + "'", "ms_outboxcode='" + pa_outboxcode.Text + "'");
  113. GetBatch.PerformClick();
  114. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "生成新品", pa_outboxcode.Text + "成功维护到送检批", "", ob_checkno.Text);
  115. OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "成功维护到送检批\n", Color.Green, pa_outboxcode);
  116. }
  117. //存在则进行提示
  118. else OperateResult.AppendText(">>箱号已存在送检批" + dt.Rows[0]["obd_checkno"] + "中\n", Color.Red, pa_outboxcode);
  119. }
  120. else OperateResult.AppendText(">>箱内产品与抽检批次产品不一致\n", Color.Red, pa_outboxcode);
  121. }
  122. else OperateResult.AppendText(">>箱号" + pa_outboxcode.Text + "不存在\n", Color.Red, pa_outboxcode);
  123. }
  124. }
  125. else OperateResult.AppendText(">>只允许在录入状态的抽检批才允许操作\n", Color.Red, pa_outboxcode);
  126. }
  127. }
  128. private void GetBatch_Click(object sender, EventArgs e)
  129. {
  130. if (CheckStep())
  131. {
  132. DataTable[] dt = LogicHandler.GetOQCBatch(ms_sncode.Text, obd_outboxcode.Text, ob_checkno.Text, "OQCSendCheck", out ErrorMessage);
  133. if (ErrorMessage == "")
  134. {
  135. BaseUtil.SetFormValue(Controls, dt[0]);
  136. BaseUtil.FillDgvWithDataTable(CheckBatchDGV, dt[1]);
  137. }
  138. else
  139. {
  140. BaseUtil.CleanForm(this);
  141. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  142. }
  143. }
  144. }
  145. private void dataGridViewExpand1_DataError(object sender, DataGridViewDataErrorEventArgs e)
  146. {
  147. }
  148. private bool CheckStep()
  149. {
  150. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  151. {
  152. return true;
  153. }
  154. else
  155. {
  156. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  157. return false;
  158. }
  159. }
  160. /// <summary>
  161. /// 全选Grid中的数据,对展开时包含明细也进行了判断
  162. /// </summary>
  163. /// <param name="sender"></param>
  164. /// <param name="e"></param>
  165. private void ChooseAll_Click(object sender, EventArgs e)
  166. {
  167. if (!CheckNoSourceCheck())
  168. {
  169. OperateResult.AppendText(">>自动生成的批次只允许点击送检\n", Color.Red);
  170. return;
  171. }
  172. for (int i = 0; i < CheckBatchDGV.Rows.Count; i++)
  173. {
  174. if (CheckBatchDGV.Rows[i].Cells[0] is DataGridViewCheckBoxCell)
  175. {
  176. if (CheckBatchDGV.Rows[i].Cells[0].Value == null || (bool)CheckBatchDGV.Rows[i].Cells[0].Value == false)
  177. {
  178. CheckBatchDGV.Rows[i].Cells[0].Value = true;
  179. }
  180. else
  181. {
  182. CheckBatchDGV.Rows[i].Cells[0].Value = false;
  183. }
  184. }
  185. }
  186. }
  187. private void RemoveAll_Click(object sender, EventArgs e)
  188. {
  189. if (!CheckNoSourceCheck())
  190. {
  191. OperateResult.AppendText(">>自动生成的批次只允许点击送检\n", Color.Red);
  192. return;
  193. }
  194. if (CheckBatchDGV.Rows.Count > 0)
  195. {
  196. if (MessageBox.Show(this.ParentForm, "确认移除全部箱号?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString() == "Yes")
  197. {
  198. DataTable dt = (DataTable)dh.ExecuteSql("select ob_status,ob_source from OQCBatch where ob_checkno='" + ob_checkno.Text + "'", "select");
  199. if (dt.Rows.Count > 0)
  200. {
  201. if (dt.Rows[0]["ob_status"].ToString() == "ENTERING")
  202. {
  203. List<string> DeleteID = new List<string>();
  204. //判断有多少勾选了
  205. for (int i = 0; i < CheckBatchDGV.Rows.Count; i++)
  206. DeleteID.Add(CheckBatchDGV.Rows[i].Cells["obd_id"].Value.ToString());
  207. if (DeleteID.Count > 0)
  208. {
  209. //删除全部明细
  210. dh.DeleteDataByID("OQCBatchDetail", "obd_id", DeleteID.ToArray());
  211. dh.UpdateByCondition("OQCBatch", "ob_nowcheckqty=0,ob_prodcode=''", "ob_checkno='" + ob_checkno.Text + "'");
  212. GetBatch.PerformClick();
  213. BaseUtil.CleanControlsText(ob_batchqty, obd_outboxcode);
  214. OperateResult.AppendText(">>批次" + ob_checkno.Text + "已全部移除\n", Color.Green);
  215. }
  216. }
  217. else OperateResult.AppendText(">>只允许移除在录入状态的抽检品的箱号\n", Color.Red);
  218. }
  219. else OperateResult.AppendText(">>抽检批次号不存在\n", Color.Red);
  220. }
  221. }
  222. }
  223. /// <summary>
  224. /// 删除当前的单据
  225. /// </summary>
  226. /// <param name="sender"></param>
  227. /// <param name="e"></param>
  228. private void Delete_Click(object sender, EventArgs e)
  229. {
  230. if (!CheckNoSourceCheck())
  231. {
  232. OperateResult.AppendText(">>自动生成的批次只允许点击送检\n", Color.Red);
  233. return;
  234. }
  235. if (dh.CheckExist("OQCBatch", "ob_checkno='" + ob_checkno.Text + "'") && ob_status.Text == "在录入")
  236. {
  237. dh.ExecuteSql("delete from OQCBatch where ob_checkno='" + ob_checkno.Text + "'", "delete");
  238. dh.ExecuteSql("delete from OQCBatchDetail where obd_checkno='" + ob_checkno.Text + "'", "delete");
  239. OperateResult.AppendText(">>抽检批次" + ob_checkno.Text + "已删除\n", Color.Green);
  240. BaseUtil.CleanForm(this);
  241. }
  242. else OperateResult.AppendText(">>抽检批次不存在或者单据状态不是在录入\n", Color.Red);
  243. }
  244. /// <summary>
  245. /// 送检按钮
  246. /// </summary>
  247. /// <param name="sender"></param>
  248. /// <param name="e"></param>
  249. private void SendOQC_Click(object sender, EventArgs e)
  250. {
  251. if (dh.CheckExist("OQCBatch", "ob_checkno='" + ob_checkno.Text + "'") && ob_status.Text == "在录入")
  252. {
  253. dh.UpdateByCondition("OQCBatch", "ob_status='UNCHECK'", "ob_checkno='" + ob_checkno.Text + "'");
  254. OperateResult.AppendText(">>抽检批次" + ob_checkno.Text + "已送检\n", Color.Green);
  255. }
  256. else
  257. {
  258. BaseUtil.CleanForm(this);
  259. OperateResult.AppendText(">>抽检批次不存在或者单据状态不是在录入\n", Color.Red);
  260. }
  261. }
  262. private void ob_checkno_TextChanged(object sender, EventArgs e)
  263. {
  264. if (ob_checkno.Text != "")
  265. SendOQC.Enabled = true;
  266. else
  267. SendOQC.Enabled = false;
  268. }
  269. private void ob_checkno_KeyDown(object sender, KeyEventArgs e)
  270. {
  271. if (e.KeyCode == Keys.Enter)
  272. GetBatch.PerformClick();
  273. }
  274. private void obd_outboxcode_KeyDown(object sender, KeyEventArgs e)
  275. {
  276. if (e.KeyCode == Keys.Enter)
  277. GetBatch.PerformClick();
  278. }
  279. private void ms_sncode_KeyDown(object sender, KeyEventArgs e)
  280. {
  281. if (e.KeyCode == Keys.Enter)
  282. GetBatch.PerformClick();
  283. }
  284. private void OQC_Inspection_FormClosing(object sender, FormClosingEventArgs e)
  285. {
  286. dh.Dispose();
  287. }
  288. private bool CheckNoSourceCheck()
  289. {
  290. if (ob_source.Text != "")
  291. {
  292. if (ob_source.Text == "工序")
  293. {
  294. return false;
  295. }
  296. }
  297. return true;
  298. }
  299. }
  300. }