private void btnSplit_Click(object sender, EventArgs e) { btnTxtBarCode.Focus(); txtSplitQty.Focus(); string sErr = ""; int iCount = 0; try { GetBarCodeStatus(btnTxtBarCode.Text.Trim()); if (BaseFunction.ReturnDecimal(txtSplitQty.Text) <= 0 || BaseFunction.ReturnDecimal(txtSplitQty.Text) > BaseFunction.ReturnDecimal(txtLotQTY.Text)) { throw new Exception("Split Qty is err"); } string sBarCodeNew = ""; SqlConnection conn = new SqlConnection(Conn); conn.Open(); SqlTransaction tran = conn.BeginTransaction(); try { string sSQL = "select getdate()"; DateTime dNow = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]); DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd")); sSQL = @" select * from _BarCodeLabel where 1=1 order by BarCode desc "; sSQL = sSQL.Replace("1=1", "1=1 and BarCode = '" + btnTxtBarCode.Text.Trim() + "'"); sSQL = sSQL.Replace("1=1", "1=1 and iSOsID = '" + txtiSOsID.Text.Trim() + "'"); DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt == null || dt.Rows.Count == 0) { throw new Exception("Please scan barcode"); } string sStatus = BaseFunction.ReturnStatus(dt.Rows[0]["status"].ToString().Trim()); if (sStatus.ToLower() == "pending") { throw new Exception("Lot no is pending err\n"); } sProcess1 = dt.Rows[0]["Process"].ToString().Trim(); sSQL = @" select * FROM _BarStatus where 1=1 order by iID desc "; sSQL = sSQL.Replace("1=1", "1=1 and BarCode like '" + btnTxtBarCode.Text.Trim() + "%'"); sSQL = sSQL.Replace("1=1", "1=1 and iSOsID = '" + txtiSOsID.Text.Trim() + "'"); DataTable dtBarStatus = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; decimal dLotQtyOld = BaseFunction.ReturnDecimal(dt.Rows[0]["LotQTY"], 2); DAL._BarCodeLabel dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._BarCodeLabel(); Model._BarCodeLabel model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._BarCodeLabel(); model = dal.DataRowToModel(dt.Rows[0]); if (btnTxtBarCode2.Text.Trim() == "") { string[] sBarCodeList = btnTxtBarCode.Text.Split('-'); sSQL = @" select BarCode as BarCodeNew from _BarCodeLabel where 1=1 order by iID desc "; sSQL = sSQL.Replace("1=1", "1=1 and BarCode like '" + sBarCodeList[0].Trim() + "%'"); sSQL = sSQL.Replace("1=1", "1=1 and iSOsID = '" + txtiSOsID.Text.Trim() + "'"); DataTable dtBarCodeNew = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; sBarCodeList = dtBarCodeNew.Rows[0]["BarCodeNew"].ToString().Trim().Split('-'); sBarCodeNew = sBarCodeList[0].Trim(); if (sBarCodeList.Length == 1) { sBarCodeNew = sBarCodeNew + "-0001"; } else { int iCou = BaseFunction.ReturnInt(sBarCodeList[1]) + 1; string sCou = iCou.ToString(); while (sCou.Length < 4) { sCou = "0" + sCou; } sBarCodeNew = sBarCodeList[0] + "-" + sCou; } model.oldBarCode = btnTxtBarCode.Text.Trim(); model.BarCode = sBarCodeNew; model.LOTQTY = BaseFunction.ReturnDecimal(txtSplitQty.Text.Trim()); sSQL = dal.Add(model); iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); Model.BarStatus models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus(); models.BarCode = model.oldBarCode; models.Type = "调整"; models.QTY = dLotQtyOld - BaseFunction.ReturnDecimal(txtSplitQty.Text.Trim()); models.UpdateTime = dNow; models.CreateDate = dNowDate; models.CreateUid = sUserID; models.iSOsID = BaseFunction.ReturnLong(txtiSOsID.Text); models.RoutingFrom = dtBarStatus.Rows[0]["RoutingFrom"].ToString().Trim(); models.RoutingTo = dtBarStatus.Rows[0]["RoutingTo"].ToString().Trim(); DAL.BarStatus dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus(); sSQL = dals.Add(models); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); //回写上一道工序的结束时间 sSQL = @" declare @iID int select @iID = max(iID) from _BarStatus where [BarCode] = '{0}' and iSOsID = '{1}' and iID < ( select max(iID) as maxID from _BarStatus where [BarCode] = '{0}' and iSOsID = '{1}' ) update _BarStatus set EndTime = '{2}' where iID = @iID and [BarCode] = '{0}' and iSOsID = '{1}' "; sSQL = string.Format(sSQL, models.BarCode, models.iSOsID, dNow); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus(); models.BarCode = model.BarCode; models.Type = "调整"; models.QTY = model.LOTQTY; models.UpdateTime = dNow; models.CreateDate = dNowDate; models.CreateUid = sUserID; models.iSOsID = BaseFunction.ReturnLong(txtiSOsID.Text); models.RoutingFrom = dtBarStatus.Rows[0]["RoutingFrom"].ToString().Trim(); models.RoutingTo = dtBarStatus.Rows[0]["RoutingTo"].ToString().Trim(); dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus(); sSQL = dals.Add(models); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); //回写上一道工序的结束时间 sSQL = @" declare @iID int select @iID = max(iID) from _BarStatus where [BarCode] = '{0}' and iSOsID = '{1}' and iID < ( select max(iID) as maxID from _BarStatus where [BarCode] = '{0}' and iSOsID = '{1}' ) update _BarStatus set EndTime = '{2}' where iID = @iID and [BarCode] = '{0}' and iSOsID = '{1}' "; sSQL = string.Format(sSQL, models.BarCode, models.iSOsID, dNow); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" update _BarCodeLabel set LotQTY = aaaaaa where BarCode = 'bbbbbb' "; sSQL = sSQL.Replace("aaaaaa", (dLotQtyOld - BaseFunction.ReturnDecimal(txtSplitQty.Text.Trim())).ToString()); sSQL = sSQL.Replace("bbbbbb", model.oldBarCode); iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } else { sSQL = "select * from _BarCodeLabel where BarCode = '" + btnTxtBarCode2.Text.Trim() + "' "; DataTable dtBarCodeTemp = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dtBarCodeTemp == null || dtBarCodeTemp.Rows.Count == 0) { btnTxtBarCode2.Text = ""; btnTxtBarCode2.Focus(); throw new Exception("BarCode is not exists"); } sProcess2 = dtBarCodeTemp.Rows[0]["Process"].ToString().Trim(); if (sProcess1 != sProcess2) { throw new Exception("Both Lot are not in the same process"); } sSQL = "update _BarCodeLabel set LotQTY = LotQTY - " + BaseFunction.ReturnDecimal(txtSplitQty.Text, 2) + " where BarCode = '" + btnTxtBarCode.Text.Trim() + "' and iSOsID = " + txtiSOsID.Text.Trim(); iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = "update _BarCodeLabel set LotQTY = LotQTY + " + BaseFunction.ReturnDecimal(txtSplitQty.Text, 2) + " where BarCode = '" + btnTxtBarCode2.Text.Trim() + "' and iSOsID = " + txtiSOsID.Text.Trim(); iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); Model.BarStatus models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus(); models.BarCode = btnTxtBarCode.Text.Trim(); models.Type = "调整"; models.QTY = dLotQtyOld - BaseFunction.ReturnDecimal(txtSplitQty.Text.Trim()); models.UpdateTime = dNow; models.CreateDate = dNowDate; models.CreateUid = sUserID; models.iSOsID = BaseFunction.ReturnLong(txtiSOsID.Text); models.RoutingFrom = dtBarStatus.Rows[0]["RoutingFrom"].ToString().Trim(); models.RoutingTo = dtBarStatus.Rows[0]["RoutingTo"].ToString().Trim(); DAL.BarStatus dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus(); sSQL = dals.Add(models); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus(); models.BarCode = btnTxtBarCode2.Text.Trim(); models.Type = "调整"; decimal dQty = BaseFunction.ReturnDecimal(txtLotQTY2.Text) + BaseFunction.ReturnDecimal(txtSplitQty.Text); if ((BaseFunction.ReturnDecimal(txtLotSize.Text) == 1 && dQty > BaseFunction.ReturnDecimal(txtOrderQTY.Text)) || (BaseFunction.ReturnDecimal(txtLotSize.Text) > 1 && dQty > BaseFunction.ReturnDecimal(txtLotSize.Text))) { throw new Exception("Qty is err"); } models.QTY = dQty; models.UpdateTime = dNow; models.CreateDate = dNowDate; models.CreateUid = sUserID; models.iSOsID = BaseFunction.ReturnLong(txtiSOsID.Text); models.RoutingFrom = dtBarStatus.Rows[0]["RoutingFrom"].ToString().Trim(); models.RoutingTo = dtBarStatus.Rows[0]["RoutingTo"].ToString().Trim(); dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus(); sSQL = dals.Add(models); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } if (sErr.Length > 0) { throw new Exception(sErr); } if (iCount > 0) { tran.Commit(); btnTxtBarCode_ButtonClick(null, null); SetTxtNull(); } } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
private void btnSplit_Click(object sender, EventArgs e) { try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } string sBarCode = lBarCodeScaned.Text.Trim(); SqlConnection conn = new SqlConnection(Conn); conn.Open(); SqlTransaction tran = conn.BeginTransaction(); try { string sSQL = "select getdate()"; DateTime dNow = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]); DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd")); sSQL = @" select * from _BarCodeLabel where 1=1 order by BarCode desc "; sSQL = sSQL.Replace("1=1", "1=1 and BarCode = '" + sBarCode + "'"); sSQL = sSQL.Replace("1=1", "1=1 and iSOsID = '" + txtiSOsID.Text.Trim() + "'"); DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt == null || dt.Rows.Count == 0) { throw new Exception("Please scan barcode"); } if (BaseFunction.ReturnDecimal(txtLotQTY.Text.Trim()) != BaseFunction.ReturnDecimal(dt.Rows[0]["LOTQTY"])) { throw new Exception("Please scan the bar code again"); } if (BaseFunction.ReturnDecimal(txtLotQTY.Text.Trim()) != BaseFunction.ReturnDecimal(gridView1.Columns["LOTQTY"].SummaryItem.SummaryValue)) { throw new Exception("Qty err"); } sSQL = @" update [_BarCodeLabel] set LOTQTY = 0,[Status] = '调整' where BarCode = '{0}' and iSOsID = '{1}' "; sSQL = string.Format(sSQL, lBarCodeScaned.Text.Trim(), txtiSOsID.Text.Trim()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); Model.BarStatus models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus(); models.BarCode = lBarCodeScaned.Text.Trim(); models.Type = "调整"; models.QTY = 0; models.UpdateTime = dNow; models.CreateDate = dNowDate; models.CreateUid = sUserID; models.iSOsID = BaseFunction.ReturnLong(txtiSOsID.Text); models.RoutingFrom = dt.Rows[0]["Process"].ToString().Trim(); models.RoutingTo = dt.Rows[0]["Process"].ToString().Trim(); DAL.BarStatus dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus(); sSQL = dals.Add(models); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); //回写上一道工序的结束时间 sSQL = @" declare @iID int select @iID = max(iID) from _BarStatus where [BarCode] = '{0}' and iSOsID = '{1}' and iID < ( select max(iID) as maxID from _BarStatus where [BarCode] = '{0}' and iSOsID = '{1}' ) update _BarStatus set EndTime = '{2}' where iID = @iID and [BarCode] = '{0}' and iSOsID = '{1}' "; sSQL = string.Format(sSQL, models.BarCode, models.iSOsID, dNow); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); for (int i = 0; i < gridView1.RowCount; i++) { string sBarCodeNew = gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim(); decimal dQty = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLOTQTY)); if (sBarCodeNew == "") { continue; } DAL._BarCodeLabel dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._BarCodeLabel(); Model._BarCodeLabel model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._BarCodeLabel(); model = dal.DataRowToModel(dt.Rows[0]); model.oldBarCode = sBarCode; model.BarCode = sBarCodeNew; model.LOTQTY = dQty; model.Status = "调整"; if (sBarCode == sBarCodeNew) { sSQL = dal.Update(model, model.BarCode, model.iSOsID); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } else { sSQL = dal.Add(model); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus(); models.BarCode = model.BarCode; models.Type = "调整"; models.QTY = dQty; models.UpdateTime = dNow; models.CreateDate = dNowDate; models.CreateUid = sUserID; models.iSOsID = BaseFunction.ReturnLong(txtiSOsID.Text); models.RoutingFrom = model.Process; models.RoutingTo = model.Process; dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus(); sSQL = dals.Add(models); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); //回写上一道工序的结束时间 sSQL = @" declare @iID int select @iID = max(iID) from _BarStatus where [BarCode] = '{0}' and iSOsID = '{1}' and iID < ( select max(iID) as maxID from _BarStatus where [BarCode] = '{0}' and iSOsID = '{1}' ) update _BarStatus set EndTime = '{2}' where iID = @iID and [BarCode] = '{0}' and iSOsID = '{1}' "; sSQL = string.Format(sSQL, models.BarCode, models.iSOsID, dNow); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" update _BarCodeLabel set IQCStatus = 'IQC-Sort' where BarCode = '{0}' and iSOsID = {1} "; sSQL = string.Format(sSQL, model.BarCode, model.iSOsID); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } tran.Commit(); MessageBox.Show("Split is ok"); } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { FrmMsgBox frm = new FrmMsgBox(); frm.richTextBox1.Text = ee.Message; frm.ShowDialog(); } }
private void btnSplit_Click(object sender, EventArgs e) { try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } string sBarCode = btnTxtBarCode.Text.Trim(); GetBarCodeStatus(sBarCode); SqlConnection conn = new SqlConnection(Conn); conn.Open(); SqlTransaction tran = conn.BeginTransaction(); try { string sSOsID = ""; string sSQL = "select getdate()"; DateTime dNow = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]); DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd")); sSQL = @" select * from _BarCodeLabel where 1=1 and iSOsID = 'aaaaaaaa' order by BarCode desc "; sSQL = sSQL.Replace("1=1", "1=1 and BarCode = '" + sBarCode + "'"); sSQL = sSQL.Replace("aaaaaaaa", liSOsID.Text.Trim()); DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt == null || dt.Rows.Count == 0) { throw new Exception("Please scan barcode"); } sSOsID = dt.Rows[0]["iSOsID"].ToString().Trim(); sSQL = @" update [_BarCodeLabel] set LOTQTY = 0,[Status] = '调整' where BarCode = '{0}' and iSOsID = '{1}' "; sSQL = string.Format(sSQL, sBarCode, sSOsID); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); Model.BarStatus models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus(); models.BarCode = sBarCode; models.Type = "调整"; models.QTY = 0; models.UpdateTime = dNow; models.CreateDate = dNowDate; models.CreateUid = sUserID; models.iSOsID = BaseFunction.ReturnLong(sSOsID); models.RoutingFrom = dt.Rows[0]["Process"].ToString().Trim(); models.RoutingTo = dt.Rows[0]["Process"].ToString().Trim(); DAL.BarStatus dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus(); sSQL = dals.Add(models); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); //回写上一道工序的结束时间 sSQL = @" declare @iID int select @iID = max(iID) from _BarStatus where [BarCode] = '{0}' and iSOsID = '{1}' and iID < ( select max(iID) as maxID from _BarStatus where [BarCode] = '{0}' and iSOsID = '{1}' ) update _BarStatus set EndTime = '{2}' where iID = @iID and [BarCode] = '{0}' and iSOsID = '{1}' "; sSQL = string.Format(sSQL, models.BarCode, models.iSOsID, dNow); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); for (int i = 0; i < gridView1.RowCount; i++) { string sBarCodeNew = gridView1.GetRowCellValue(i, gridColLOTNO).ToString().Trim(); decimal dQty = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColPrintQTY)); if (sBarCodeNew == "") { continue; } sSQL = @" select * from [dbo].[_BarCodeLabel] where BarCode = '{0}' and iSOsID = '{1}' "; sSQL = string.Format(sSQL, sBarCodeNew, sSOsID); DataTable dtExist = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dtExist != null && dtExist.Rows.Count > 0) { throw new Exception("Barcode " + sBarCodeNew + " is exists"); } DAL._BarCodeLabel dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._BarCodeLabel(); Model._BarCodeLabel model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._BarCodeLabel(); model = dal.DataRowToModel(dt.Rows[0]); model.oldBarCode = sBarCode; model.BarCode = sBarCodeNew; model.LOTQTY = dQty; model.Status = "调整"; if (sBarCode == sBarCodeNew) { sSQL = dal.Update(model, model.BarCode, model.iSOsID); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } else { sSQL = dal.Add(model); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus(); models.BarCode = model.BarCode; models.Type = "调整"; models.QTY = dQty; models.UpdateTime = dNow; models.CreateDate = dNowDate; models.CreateUid = sUserID; models.iSOsID = BaseFunction.ReturnLong(sSOsID); models.RoutingFrom = model.Process; models.RoutingTo = model.Process; dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus(); sSQL = dals.Add(models); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); //回写上一道工序的结束时间 sSQL = @" declare @iID int select @iID = max(iID) from _BarStatus where [BarCode] = '{0}' and iSOsID = '{1}' and iID < ( select max(iID) as maxID from _BarStatus where [BarCode] = '{0}' and iSOsID = '{1}' ) update _BarStatus set EndTime = '{2}' where iID = @iID and [BarCode] = '{0}' and iSOsID = '{1}' "; sSQL = string.Format(sSQL, models.BarCode, models.iSOsID, dNow); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); // sSQL = @" //update _BarCodeLabel set IQCStatus = 'IQC-Sort' //where BarCode = '{0}' and iSOsID = {1} //"; // sSQL = string.Format(sSQL, model.BarCode, model.iSOsID); // DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } tran.Commit(); MessageBox.Show("OK"); } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }