OQC_Inspection.cs 14 KB

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