private void btnSave_Click(object sender, EventArgs e) { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } txtBarCode.Focus(); string sErr = ""; int iCount = 0; try { string sProcess = gridView1.GetRowCellValue(0, gridColProcess).ToString().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")); int iYear = dNow.Year; int iPeriod = dNow.Month; string s期间 = BaseFunction.ReturnDate(iYear.ToString() + "-" + iPeriod.ToString() + "-01").ToString("yyyyMM"); sSQL = "select isnull(bflag_ST,0) as bflag from GL_mend where iYPeriod = '" + s期间 + "'"; DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt == null || dt.Rows.Count == 0) { throw new Exception("Access module state failure"); } int i结账 = BaseFunction.ReturnInt(dt.Rows[0]["bflag"]); if (i结账 > 0) { throw new Exception(dNow.ToString("yyyy-MM") + " have checked out"); } #region 必须销售类型是“WP”,状态非关闭。 回写销售订单数量,并新增其它出库单(数量增加红字出库单,数量减少蓝字出库单) for (int i = 0; i < gridView1.RowCount; i++) { long lSOsID = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColiSOsID)); string sBarCode = gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim(); decimal dLotQTY = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLOTQTY)); decimal dOrderQTY = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColcbdefine4)); string siSOsID = gridView1.GetRowCellValue(i, gridColiSOsID).ToString().Trim(); sSQL = @" select LOTQTY from [dbo].[_BarCodeLabel] where Barcode = '{0}' and iSOsID = {1} "; sSQL = string.Format(sSQL, sBarCode, lSOsID); DataTable dtBarCodeLabel = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dLotQTY == BaseFunction.ReturnDecimal(dtBarCodeLabel.Rows[0]["LOTQTY"])) { continue; } decimal dQTYtc = BaseFunction.ReturnDecimal(dtBarCodeLabel.Rows[0]["LOTQTY"]) - dLotQTY; if (dLotQTY > dOrderQTY) { sErr = sErr + "Row " + (i + 1).ToString() + " lotqty is err\n"; continue; } if (gridView1.GetRowCellValue(i, gridColLOTQTY).ToString().Trim() == "") { sErr = sErr + "Row " + (i + 1).ToString() + " lotqty is err\n"; continue; } if (BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLOTQTY).ToString().Trim()) == 0) { sErr = sErr + "Row " + (i + 1).ToString() + " lotqty is 0 err\n"; continue; } //回写条码数量 sSQL = @"update [_BarCodeLabel] set [Status] = '调整', orderqty = aaaaaa, LOTQTY = aaaaaa where BarCode = 'bbbbbb' and iSOsID = " + gridView1.GetRowCellValue(i, gridColiSOsID).ToString().Trim(); sSQL = sSQL.Replace("aaaaaa", dLotQTY.ToString()); sSQL = sSQL.Replace("bbbbbb", sBarCode); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); Model.BarStatus model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus(); model.BarCode = sBarCode; model.iSOsID = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColiSOsID)); model.Type = "调整"; model.RoutingFrom = gridView1.GetRowCellValue(i, gridColProcess).ToString().Trim(); model.RoutingTo = gridView1.GetRowCellValue(i, gridColProcess).ToString().Trim(); model.UpdateTime = dNow; model.QTY = dLotQTY; model.CreateUid = sUserID; model.CreateDate = dNow; DAL.BarStatus dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus(); sSQL = dal.Add(model); iCount += 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, model.BarCode, model.iSOsID, dNow); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); //回写销售订单数量 sSQL = @"update SO_SODetails set iQuantity = aaaaaa where iSOsID = bbbbbb"; sSQL = sSQL.Replace("aaaaaa", dLotQTY.ToString()); sSQL = sSQL.Replace("bbbbbb", lSOsID.ToString()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); //回写销售订单金额 sSQL = @" update SO_SODetails set iMoney = iQuantity * iUnitPrice,iSum = iTaxUnitPrice * iQuantity,iTax = iTaxUnitPrice * iQuantity - iQuantity * iUnitPrice ,iNatMoney = iNatUnitPrice * iQuantity , iNatSum = iNatMoney * (1 + iTaxRate / 100),iNatTax = iNatMoney * (1 + iTaxRate / 100) - iNatUnitPrice * iQuantity where iSOsID = bbbbbb "; sSQL = sSQL.Replace("bbbbbb", lSOsID.ToString()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); //------------------------------------------------------------------------ #region 步生成其它出库单 sSQL = @" select * from SO_SOMain a inner join SO_SODetails b on a.ID = b.ID left join _SystemSet c on a.cSTCode = c.cSTCode inner join Inventory d on b.cInvCode = d.cInvCode where b.iSOsID = aaaaaa order by b.autoid "; sSQL = sSQL.Replace("aaaaaa", lSOsID.ToString().Trim()); DataTable dtSOMain = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dtSOMain == null || dtSOMain.Rows.Count == 0) { throw new Exception("Sale Order not exists err"); } string sCTCode = dtSOMain.Rows[0]["cSTCode"].ToString().Trim(); //DateTime dDate = BaseFunction.ReturnDate(dtSOMain.Rows[0]["dDate"]); DateTime dDate = DateTime.Today; sSQL = "select isnull(bflag_ST,0) as bflag from GL_mend where iYPeriod = '" + dDate.ToString("yyyyMM") + "'"; dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt == null || dt.Rows.Count == 0) { throw new Exception("Access module state failure"); } int i结账RD = BaseFunction.ReturnInt(dt.Rows[0]["bflag"]); if (i结账RD > 0) { throw new Exception(dDate.ToString("yyyy-MM") + " have checked out"); } //获得单据号 sSQL = "select cNumber from VoucherHistory with (ROWLOCK) Where cSeed = 'aaaaaa' AND cContentRule = 'YYYY' AND CardNumber = '0302' ORDER BY cNumber DESC"; sSQL = sSQL.Replace("aaaaaa", dDate.ToString("yyyy")); dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; long lCodeRD = 0; if (dt != null && dt.Rows.Count > 0) { lCodeRD = BaseFunction.ReturnLong(dt.Rows[0]["cNumber"]); } else { lCodeRD = 0; } long lIDRD = -1; long lIDRDDetails = -1; sSQL = @" declare @p5 int set @p5=aaaaaa declare @p6 int set @p6=bbbbbb exec sp_GetId N'00',N'dddddd',N'rd',cccccc,@p5 output,@p6 output,default select @p5, @p6 "; sSQL = sSQL.Replace("aaaaaa", lIDRD.ToString()); sSQL = sSQL.Replace("bbbbbb", lIDRDDetails.ToString()); sSQL = sSQL.Replace("cccccc", 1.ToString()); sSQL = sSQL.Replace("dddddd", sAccID); dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; lIDRD = BaseFunction.ReturnLong(dt.Rows[0][0]) - 1; lIDRDDetails = BaseFunction.ReturnLong(dt.Rows[0][1]) - 1; //ArrayList aList = new ArrayList(); Model.RdRecord09 modelRD = new Model.RdRecord09(); lIDRD += 1; modelRD.ID = lIDRD; modelRD.bRdFlag = 0; modelRD.cVouchType = "09"; modelRD.cBusType = "其他出库"; modelRD.cSource = "库存"; //modelRD.cBusCode = modelRD.cWhCode = dtSOMain.Rows[0]["cWhCode"].ToString().Trim(); //需要仓库默认值 if (dtSOMain.Rows[0]["cWhCode"].ToString().Trim() == "") { throw new Exception("Please set default warehouse"); } modelRD.dDate = dDate; //需要默认值 lCodeRD += 1; string sCodeRD = lCodeRD.ToString(); while (sCodeRD.Length < 6) { sCodeRD = "0" + sCodeRD; } modelRD.cCode = "MR" + dNow.ToString("yyyy") + sCodeRD; modelRD.cRdCode = "AD"; //需要默认值 if (dtSOMain.Rows[0]["cRdCode"].ToString().Trim() == "") { throw new Exception("Please set RdCode"); } //modelRD.cDepCode = "" //modelRD.cPersonCode; //modelRD.cPTCode; //modelRD.cSTCode; //modelRD.cCusCode; //modelRD.cVenCode; //modelRD.cOrderCode; //modelRD.cARVCode; //modelRD.cBillCode; //modelRD.cDLCode; //modelRD.cProBatch; modelRD.cHandler = sUserName; //modelRD.cMemo; modelRD.bTransFlag = false; //modelRD.cAccounter; modelRD.cMaker = sUserName; modelRD.cDefine1 = dtSOMain.Rows[0]["cDefine1"].ToString(); modelRD.cDefine2 = dtSOMain.Rows[0]["cDefine2"].ToString(); modelRD.cDefine3 = dtSOMain.Rows[0]["cDefine3"].ToString(); if (dtSOMain.Rows[0]["cDefine4"].ToString().Trim() != "") { modelRD.cDefine4 = BaseFunction.ReturnDate(dtSOMain.Rows[0]["cDefine4"]); } if (dtSOMain.Rows[0]["cDefine5"].ToString().Trim() != "") { modelRD.cDefine5 = BaseFunction.ReturnLong(dtSOMain.Rows[0]["cDefine5"]); } if (dtSOMain.Rows[0]["cDefine6"].ToString().Trim() != "") { modelRD.cDefine6 = BaseFunction.ReturnDate(dtSOMain.Rows[0]["cDefine6"]); } if (dtSOMain.Rows[0]["cDefine7"].ToString().Trim() != "") { modelRD.cDefine7 = BaseFunction.ReturnDecimal(dtSOMain.Rows[0]["cDefine7"]); } modelRD.cDefine8 = dtSOMain.Rows[0]["cDefine8"].ToString(); modelRD.cDefine9 = dtSOMain.Rows[0]["cDefine9"].ToString(); modelRD.cDefine10 = dtSOMain.Rows[0]["cDefine10"].ToString(); //modelRD.dKeepDate; modelRD.dVeriDate = dDate; modelRD.bpufirst = false; modelRD.biafirst = false; //modelRD.iMQuantity; //modelRD.dARVDate; //modelRD.cChkCode; //modelRD.dChkDate; //modelRD.cChkPerson; modelRD.VT_ID = 85; modelRD.bIsSTQc = false; modelRD.cDefine11 = dtSOMain.Rows[0]["cDefine11"].ToString(); modelRD.cDefine12 = dtSOMain.Rows[0]["cDefine12"].ToString(); modelRD.cDefine13 = dtSOMain.Rows[0]["cDefine13"].ToString(); modelRD.cDefine14 = dtSOMain.Rows[0]["cDefine14"].ToString(); if (dtSOMain.Rows[0]["cDefine15"].ToString() != "") { modelRD.cDefine15 = BaseFunction.ReturnLong(dtSOMain.Rows[0]["cDefine15"]); } if (dtSOMain.Rows[0]["cDefine16"].ToString() != "") { modelRD.cDefine16 = BaseFunction.ReturnDecimal(dtSOMain.Rows[0]["cDefine16"]); } //modelRD.gspcheck; //modelRD.ufts; //modelRD.iExchRate; //modelRD.cExch_Name; modelRD.bOMFirst = false; modelRD.bFromPreYear = false; modelRD.bIsLsQuery = false; modelRD.bIsComplement = 0; modelRD.iDiscountTaxType = 0; modelRD.ireturncount = 0; modelRD.iverifystate = 0; modelRD.iswfcontrolled = 0; //modelRD.cModifyPerson; //modelRD.dModifyDate; //modelRD.dnmaketime; //modelRD.dnmodifytime; modelRD.dnverifytime = dNow; modelRD.bredvouch = 0; //modelRD.iFlowId; //modelRD.cPZID; //modelRD.cSourceLs; //modelRD.cSourceCodeLs; modelRD.iPrintCount = 0; //modelRD.ctransflag; //modelRD.csysbarcode; //modelRD.cCurrentAuditor; DAL.RdRecord09 dalRD = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.RdRecord09(); sSQL = dalRD.Add(modelRD); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); lIDRDDetails += 1; Model.rdrecords09 modelsRD = new Model.rdrecords09(); modelsRD.AutoID = lIDRDDetails; modelsRD.ID = modelRD.ID; modelsRD.cInvCode = dtSOMain.Rows[0]["cInvCode"].ToString().Trim(); //if (dtSOMain.Rows[0]["iNum"].ToString().Trim() != "") //{ // modelsRD.iNum = BaseFunction.ReturnDecimal(dtSOMain.Rows[0]["iNum"]); //} modelsRD.iQuantity = dQTYtc; //modelsRD.iUnitCost; //modelsRD.iPrice; //modelsRD.iAPrice; //modelsRD.iPUnitCost; //modelsRD.iPPrice; modelsRD.cBatch = gridView1.GetRowCellValue(i, gridColcBatch).ToString().Trim(); //modelsRD.cVouchCode; //modelsRD.cInVouchCode; //modelsRD.cinvouchtype; //modelsRD.iSOutQuantity; //modelsRD.iSOutNum; //modelsRD.cFree1; //modelsRD.cFree2; modelsRD.iFlag = 0; //modelsRD.iFNum; //modelsRD.iFQuantity; //modelsRD.dVDate; //modelsRD.iTrIds; //modelsRD.cPosition; //modelsRD.cDefine22; //modelsRD.cDefine23; //modelsRD.cDefine24; //modelsRD.cDefine25; //modelsRD.cDefine26; //modelsRD.cDefine27; //modelsRD.cItem_class; //modelsRD.cItemCode; //modelsRD.cName; //modelsRD.cItemCName; //modelsRD.cFree3; //modelsRD.cFree4; //modelsRD.cFree5; //modelsRD.cFree6; //modelsRD.cFree7; //modelsRD.cFree8; //modelsRD.cFree9; //modelsRD.cFree10; //modelsRD.cBarCode; //modelsRD.iNQuantity; //modelsRD.iNNum; //modelsRD.cAssUnit; //modelsRD.dMadeDate; //modelsRD.iMassDate; //modelsRD.cDefine28; //modelsRD.cDefine29; //modelsRD.cDefine30; //modelsRD.cDefine31; //modelsRD.cDefine32; //modelsRD.cDefine33; //modelsRD.cDefine34; //modelsRD.cDefine35; //modelsRD.cDefine36; //modelsRD.cDefine37; //modelsRD.iCheckIds; //modelsRD.cBVencode; //modelsRD.chVencode; //modelsRD.bGsp; //modelsRD.cGspState; //modelsRD.cCheckCode; //modelsRD.iCheckIdBaks; //modelsRD.cRejectCode; //modelsRD.iRejectIds; //modelsRD.cCheckPersonCode; //modelsRD.dCheckDate; //modelsRD.cMassUnit; //modelsRD.bChecked; modelsRD.bLPUseFree = false; //modelsRD.iRSRowNO; //modelsRD.iOriTrackID; //modelsRD.coritracktype; //modelsRD.cbaccounter; //modelsRD.dbKeepDate; modelsRD.bCosting = true; modelsRD.bVMIUsed = false; //modelsRD.iVMISettleQuantity; //modelsRD.iVMISettleNum; //modelsRD.cvmivencode; //modelsRD.iInvSNCount; //modelsRD.cwhpersoncode; //modelsRD.cwhpersonname; //modelsRD.cserviceoid; //modelsRD.cbserviceoid; //modelsRD.iinvexchrate; //modelsRD.corufts; //modelsRD.strContractGUID; modelsRD.iExpiratDateCalcu = 0; //modelsRD.cExpirationdate; //modelsRD.dExpirationdate; //modelsRD.cciqbookcode; //modelsRD.iBondedSumQty; //modelsRD.iorderdid; modelsRD.iordertype = 0; //modelsRD.iordercode; //modelsRD.iorderseq; //modelsRD.isodid; modelsRD.isotype = 0; modelsRD.csocode = dtSOMain.Rows[0]["cSOCode"].ToString().Trim(); //modelsRD.isoseq //modelsRD.cBatchProperty1; //modelsRD.cBatchProperty2; //modelsRD.cBatchProperty3; //modelsRD.cBatchProperty4; //modelsRD.cBatchProperty5; //modelsRD.cBatchProperty6; //modelsRD.cBatchProperty7; //modelsRD.cBatchProperty8; //modelsRD.cBatchProperty9; //modelsRD.cBatchProperty10; //modelsRD.cbMemo; modelsRD.irowno = 1; //modelsRD.strowguid; //modelsRD.rowufts; //modelsRD.ipreuseqty; //modelsRD.ipreuseinum; //modelsRD.cbsourcecodels; //modelsRD.iGroupNO; //modelsRD.iDebitIDs; //modelsRD.idebitchildids; //modelsRD.OutCopiedQuantity; //modelsRD.cbsysbarcode DAL.rdrecords09 dalsRD = new DAL.rdrecords09(); sSQL = dalsRD.Add(modelsRD); iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" if exists (select * from CurrentStock where cInvCode = '@cInvCode' and cWhCode = '@cWhCode' and isnull(cFree1,'') = @cFree1 and isnull(cFree2,'') = @cFree2 and isnull(cFree3,'') = @cFree3 and isnull(cFree4,'') = @cFree4 and isnull(cFree5,'') = @cFree5 and isnull(cFree6,'') = @cFree6 and isnull(cFree7,'') = @cFree7 and isnull(cFree8,'') = @cFree8 and isnull(cFree9,'') = @cFree9 and isnull(cFree10,'') = @cFree10 and isnull(cBatch,'') = @cBatch ) update CurrentStock set iQuantity = isnull(iQuantity,0) + @iQuantity where cInvCode = '@cInvCode' and cWhCode = '@cWhCode' and isnull(cFree1,'') = @cFree1 and isnull(cFree2,'') = @cFree2 and isnull(cFree3,'') = @cFree3 and isnull(cFree4,'') = @cFree4 and isnull(cFree5,'') = @cFree5 and isnull(cFree6,'') = @cFree6 and isnull(cFree7,'') = @cFree7 and isnull(cFree8,'') = @cFree8 and isnull(cFree9,'') = @cFree9 and isnull(cFree10,'') = @cFree10 and isnull(cBatch,'') = @cBatch else begin declare @itemid varchar(20); declare @iCount int; select @iCount=count(itemid) from CurrentStock where cInvCode = '@cInvCode'; if( @iCount > 0 ) select @itemid=itemid from CurrentStock where cInvCode = '@cInvCode'; else select @itemid=max(itemid+1) from CurrentStock insert into CurrentStock(cWhCode,cInvCode,iQuantity,itemid, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10,cBatch,iSoDid) values('@cWhCode','@cInvCode', @iQuantity,@itemid, @cFree1, @cFree2, @cFree3, @cFree4, @cFree5, @cFree6, @cFree7, @cFree8, @cFree9, @cFree10,@cBatch,'') end "; sSQL = sSQL.Replace("@cInvCode", modelsRD.cInvCode); sSQL = sSQL.Replace("@cWhCode", modelRD.cWhCode); sSQL = sSQL.Replace("@iQuantity", (-1 * modelsRD.iQuantity).ToString()); sSQL = sSQL.Replace("@iNum", (-1 * modelsRD.iNum).ToString()); sSQL = sSQL.Replace("@cFree10", modelsRD.cFree10 == null ? "''" : "'" + modelsRD.cFree10 + "'"); sSQL = sSQL.Replace("@cFree1", modelsRD.cFree1 == null ? "''" : "'" + modelsRD.cFree1 + "'"); sSQL = sSQL.Replace("@cFree2", modelsRD.cFree2 == null ? "''" : "'" + modelsRD.cFree2 + "'"); sSQL = sSQL.Replace("@cFree3", modelsRD.cFree3 == null ? "''" : "'" + modelsRD.cFree3 + "'"); sSQL = sSQL.Replace("@cFree4", modelsRD.cFree4 == null ? "''" : "'" + modelsRD.cFree4 + "'"); sSQL = sSQL.Replace("@cFree5", modelsRD.cFree5 == null ? "''" : "'" + modelsRD.cFree5 + "'"); sSQL = sSQL.Replace("@cFree6", modelsRD.cFree6 == null ? "''" : "'" + modelsRD.cFree6 + "'"); sSQL = sSQL.Replace("@cFree7", modelsRD.cFree7 == null ? "''" : "'" + modelsRD.cFree7 + "'"); sSQL = sSQL.Replace("@cFree8", modelsRD.cFree8 == null ? "''" : "'" + modelsRD.cFree8 + "'"); sSQL = sSQL.Replace("@cFree9", modelsRD.cFree9 == null ? "''" : "'" + modelsRD.cFree9 + "'"); sSQL = sSQL.Replace("@cBatch", modelsRD.cBatch == null ? "''" : "'" + modelsRD.cBatch + "'"); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" exec ST_SaveForStock N'09',N'aaaaaa',1,0 ,1 "; sSQL = sSQL.Replace("aaaaaa", lIDRD.ToString()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" exec ST_SaveForTrackStock N'09',N'aaaaaa', 0 ,1 "; sSQL = sSQL.Replace("aaaaaa", lIDRD.ToString()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" exec IA_SP_WriteUnAccountVouchForST 'aaaaaa',N'09' "; sSQL = sSQL.Replace("aaaaaa", lIDRD.ToString()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); if (lIDRD > 1000000000) { lIDRD = lIDRD - 1000000000; } if (lIDRDDetails > 1000000000) { lIDRDDetails = lIDRDDetails - 1000000000; } sSQL = "update UFSystem..UA_Identity set iFatherId = " + lIDRD.ToString() + ",iChildId = " + lIDRDDetails + " where cAcc_Id = '" + sAccID + "' and cVouchType = 'rd'"; DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" if exists(select * from VoucherHistory where CardNumber = '0302' and cSeed = 'aaaaaa' AND cContentRule = 'YYYY') update VoucherHistory set cNumber = bbbbbb where CardNumber = '0302' and cSeed = 'aaaaaa' AND cContentRule = 'YYYY' else insert into VoucherHistory(CardNumber,cContent,cContentRule,cSeed,cNumber,bEmpty) values('0302','日期','YYYY','aaaaaa','bbbbbb',0) "; sSQL = sSQL.Replace("aaaaaa", dDate.ToString("yyyy")); sSQL = sSQL.Replace("bbbbbb", lCodeRD.ToString()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); #endregion //------------------------------------------------------------------------ } #endregion if (sErr.Length > 0) { throw new Exception(sErr); } if (iCount > 0) { tran.Commit(); MessageBox.Show("OK\n"); SetTxtNull(); gridControl1.DataSource = DbHelperSQL.Query(sSQLBar); txtBarCode.Focus(); } } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
private void btnSave_Click(object sender, EventArgs e) { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } string sErr = ""; int iCount = 0; try { if (lookUpEditProcess.EditValue == null || lookUpEditProcess.EditValue.ToString().Trim() == "") { lookUpEditProcess.Focus(); throw new Exception("Please choose warehouse"); } string sProcess = lookUpEditProcess.EditValue.ToString().Trim(); if (lookUpEditcCusCode.EditValue == null || lookUpEditcCusCode.EditValue.ToString().Trim() == "") { lookUpEditcCusCode.Focus(); throw new Exception("Please choose customer"); } string sCusCode = lookUpEditcCusCode.EditValue.ToString().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")); int iYear = dNow.Year; int iPeriod = dNow.Month; string s期间 = BaseFunction.ReturnDate(iYear.ToString() + "-" + iPeriod.ToString() + "-01").ToString("yyyyMM"); sSQL = "select isnull(bflag_SA,0) as bflag from GL_mend where iYPeriod = '" + s期间 + "'"; DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt == null || dt.Rows.Count == 0) { throw new Exception("Access module state failure"); } int i结账 = BaseFunction.ReturnInt(dt.Rows[0]["bflag"]); if (i结账 > 0) { throw new Exception(dNow.ToString("yyyy-MM") + " have checked out"); } //获得单据号 sSQL = "select max(cNumber) as cNumber from VoucherHistory with (ROWLOCK) Where (cSeed = 'DPaaaaaa' or cSeed = 'aaaaaa') AND cContentRule like '%YYYY%' AND CardNumber = '01' ORDER BY cNumber DESC"; sSQL = sSQL.Replace("aaaaaa", dNow.ToString("yyyy")); dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; long lCodeDis = 0; if (dt != null && dt.Rows.Count > 0) { lCodeDis = BaseFunction.ReturnLong(dt.Rows[0]["cNumber"]); } else { lCodeDis = 0; } lCodeDis += 1; string sCodeDis = lCodeDis.ToString(); while (sCodeDis.Length < 6) { sCodeDis = "0" + sCodeDis; } sSQL = "select count(1) as iCou from WareHouse WHERE cWhCode = '" + lookUpEditProcess.EditValue.ToString().Trim() + "' and cwhmemo like '%R%' "; int iWhR = BaseFunction.ReturnInt(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]); if (iWhR > 0) { sCodeDis = "FC" + dNow.ToString("yyyy") + sCodeDis; } else { sCodeDis = "DP" + dNow.ToString("yyyy") + sCodeDis; } long lIDDis = -1; long lIDDisDetails = -1; sSQL = @" declare @p5 int set @p5=aaaaaa declare @p6 int set @p6=bbbbbb exec sp_GetId N'00',N'dddddd',N'DISPATCH',cccccc,@p5 output,@p6 output,default select @p5, @p6 "; sSQL = sSQL.Replace("aaaaaa", lIDDis.ToString()); sSQL = sSQL.Replace("bbbbbb", lIDDisDetails.ToString()); sSQL = sSQL.Replace("cccccc", 1.ToString()); sSQL = sSQL.Replace("dddddd", sAccID); dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; lIDDis = BaseFunction.ReturnLong(dt.Rows[0][0]) - 1; lIDDisDetails = BaseFunction.ReturnLong(dt.Rows[0][1]) - 1; long lSOsID = BaseFunction.ReturnLong(gridView1.GetRowCellValue(0, gridColiSOsID)); sSQL = @" select * from SO_SOMain a inner join SO_SODetails b on a.ID = b.ID left join _SystemSet c on a.cSTCode = c.cSTCode inner join Inventory d on b.cInvCode = d.cInvCode inner join Customer e on a.cCusCode = e.cCusCode where b.iSOsID = aaaaaa order by b.autoid "; sSQL = sSQL.Replace("aaaaaa", lSOsID.ToString().Trim()); DataTable dtSOMain = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; Model.DispatchList modelDis = new Model.DispatchList(); lIDDis += 1; modelDis.DLID = lIDDis; modelDis.cDLCode = sCodeDis; modelDis.cVouchType = "05"; modelDis.cSTCode = dtSOMain.Rows[0]["cSTCode"].ToString().Trim(); modelDis.dDate = dNowDate; modelDis.cDepCode = dtSOMain.Rows[0]["cDepCode"].ToString().Trim(); modelDis.SBVID = 0; modelDis.cSOCode = dtSOMain.Rows[0]["cSOCode"].ToString().Trim(); modelDis.cCusCode = dtSOMain.Rows[0]["cCusCode"].ToString().Trim(); modelDis.cPayCode = dtSOMain.Rows[0]["cPayCode"].ToString().Trim(); modelDis.cShipAddress = dtSOMain.Rows[0]["cCusOAddress"].ToString().Trim(); modelDis.cexch_name = dtSOMain.Rows[0]["cexch_name"].ToString().Trim(); modelDis.iExchRate = BaseFunction.ReturnDecimal(dtSOMain.Rows[0]["iExchRate"]); modelDis.iTaxRate = BaseFunction.ReturnDecimal(dtSOMain.Rows[0]["iTaxRate"]); modelDis.bFirst = false; modelDis.bReturnFlag = false; modelDis.bSettleAll = false; modelDis.cMemo = dtSOMain.Rows[0]["cMemo"].ToString().Trim(); modelDis.cMaker = sUserName; modelDis.iSale = 0; modelDis.cCusName = dtSOMain.Rows[0]["cCusName"].ToString().Trim(); modelDis.iVTid = 71; modelDis.cBusType = dtSOMain.Rows[0]["cBusType"].ToString().Trim(); modelDis.bIAFirst = false; modelDis.bCredit = false; modelDis.iverifystate = 0; modelDis.iswfcontrolled = 0; modelDis.bARFirst = false; modelDis.dcreatesystime = dNow; modelDis.iflowid = 0; modelDis.bsigncreate = false; modelDis.bcashsale = false; modelDis.bneedbill = true; modelDis.baccswitchflag = false; modelDis.bsaleoutcreatebill = false; modelDis.cinvoicecompany = dtSOMain.Rows[0]["cinvoicecompany"].ToString().Trim(); DAL.DispatchList dalDis = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.DispatchList(); sSQL = dalDis.Add(modelDis); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); for (int i = 0; i < gridView1.RowCount; i++) { if (!BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColchoose))) { continue; } if (gridView1.GetRowCellValue(i, gridColcCusCode).ToString().Trim() != lookUpEditcCusCode.EditValue.ToString().Trim()) { sErr = sErr + "Row " + (i + 1) + " customer err \n"; continue; } lSOsID = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColiSOsID)); sSQL = @" select * from SO_SOMain a inner join SO_SODetails b on a.ID = b.ID left join SaleType c on a.cSTCode = c.cSTCode inner join Inventory d on b.cInvCode = d.cInvCode inner join [_BarCodeLabel] e on e.[iSOsID] = b.[iSOsID] left join SO_SODetails_extradefine f on f.iSOsID = b.iSOsID where b.iSOsID = aaaaaa order by b.autoid "; sSQL = sSQL.Replace("aaaaaa", lSOsID.ToString().Trim()); DataTable dtSODetails = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dtSODetails == null || dtSODetails.Rows.Count == 0) { throw new Exception("Sale Order not exists err"); } string sBarCode = gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim(); lIDDisDetails += 1; Model.DispatchLists modelsDis = new Model.DispatchLists(); modelsDis.AutoID = lIDDisDetails; modelsDis.DLID = modelDis.DLID; modelsDis.iCorID = 0; modelsDis.cWhCode = lookUpEditProcess.EditValue.ToString().Trim(); modelsDis.cInvCode = dtSODetails.Rows[0]["cInvCode"].ToString().Trim(); modelsDis.iQuantity = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLOTQTY)); modelsDis.iNum = 0; modelsDis.iTaxRate = BaseFunction.ReturnDecimal(dtSODetails.Rows[0]["iTaxRate"]); modelsDis.iQuotedPrice = BaseFunction.ReturnDecimal(dtSODetails.Rows[0]["iQuotedPrice"]); modelsDis.iUnitPrice = BaseFunction.ReturnDecimal(dtSODetails.Rows[0]["iUnitPrice"]); modelsDis.iTaxUnitPrice = BaseFunction.ReturnDecimal(dtSODetails.Rows[0]["iTaxUnitPrice"]); modelsDis.iMoney = modelsDis.iUnitPrice * modelsDis.iQuantity; modelsDis.iSum = modelsDis.iTaxUnitPrice * modelsDis.iQuantity; modelsDis.iTax = modelsDis.iSum - modelsDis.iMoney; modelsDis.iDisCount = 0; modelsDis.iNatUnitPrice = BaseFunction.ReturnDecimal(dtSODetails.Rows[0]["iNatUnitPrice"]); modelsDis.iNatMoney = modelsDis.iNatUnitPrice * modelsDis.iQuantity; modelsDis.iNatSum = modelsDis.iNatUnitPrice * (1 + modelsDis.iTaxRate / 100) * modelsDis.iQuantity; modelsDis.iNatTax = modelsDis.iNatSum - modelsDis.iNatMoney; modelsDis.iNatDisCount = 0; modelsDis.iSettleNum = 0; modelsDis.iSettleQuantity = 0; modelsDis.cBatch = gridView1.GetRowCellValue(i, gridColcustlot).ToString().Trim(); modelsDis.bSettleAll = false; modelsDis.cMemo = dtSODetails.Rows[0]["cMemo"].ToString().Trim(); modelsDis.iTB = 0; modelsDis.TBQuantity = 0; modelsDis.iSOsID = lSOsID; modelsDis.iDLsID = lIDDisDetails; modelsDis.KL = 100; modelsDis.KL2 = 0; modelsDis.cInvName = dtSODetails.Rows[0]["cInvName"].ToString().Trim(); modelsDis.cDefine22 = dtSODetails.Rows[0]["cDefine22"].ToString().Trim(); modelsDis.cDefine23 = dtSODetails.Rows[0]["cDefine23"].ToString().Trim(); modelsDis.cDefine24 = dtSODetails.Rows[0]["cDefine24"].ToString().Trim(); modelsDis.cDefine25 = dtSODetails.Rows[0]["cDefine25"].ToString().Trim(); modelsDis.cDefine26 = BaseFunction.ReturnDecimal(dtSODetails.Rows[0]["cDefine26"]); modelsDis.cDefine27 = BaseFunction.ReturnDecimal(dtSODetails.Rows[0]["cDefine27"]); modelsDis.fOutQuantity = 0; modelsDis.fOutNum = 0; modelsDis.fSaleCost = 0; modelsDis.fSalePrice = 0; modelsDis.bIsSTQc = false; modelsDis.cUnitID = dtSODetails.Rows[0]["cUnitID"].ToString().Trim(); modelsDis.fEnSettleQuan = 0; modelsDis.fEnSettleSum = 0; modelsDis.cDefine28 = dtSODetails.Rows[0]["cDefine28"].ToString().Trim(); modelsDis.cDefine29 = dtSODetails.Rows[0]["cDefine29"].ToString().Trim(); modelsDis.cDefine30 = dtSODetails.Rows[0]["cDefine30"].ToString().Trim(); modelsDis.cDefine31 = dtSODetails.Rows[0]["cDefine31"].ToString().Trim(); modelsDis.cDefine32 = dtSODetails.Rows[0]["cDefine32"].ToString().Trim(); modelsDis.cDefine33 = dtSODetails.Rows[0]["cDefine33"].ToString().Trim(); modelsDis.cDefine34 = BaseFunction.ReturnLong(dtSODetails.Rows[0]["cDefine34"]); modelsDis.cDefine35 = BaseFunction.ReturnLong(dtSODetails.Rows[0]["cDefine35"]); modelsDis.cDefine36 = BaseFunction.ReturnDate(dtSODetails.Rows[0]["cDefine36"]); modelsDis.cDefine37 = BaseFunction.ReturnDate(dtSODetails.Rows[0]["cDefine37"]); modelsDis.bgift = false; modelsDis.cSoCode = dtSODetails.Rows[0]["cSoCode"].ToString().Trim(); modelsDis.cMassUnit = BaseFunction.ReturnLong(dtSODetails.Rows[0]["cMassUnit"]); modelsDis.bQANeedCheck = false; modelsDis.bQAUrgency = false; modelsDis.bQAChecking = false; modelsDis.bQAChecked = false; modelsDis.fsumsignquantity = 0; modelsDis.fsumsignnum = 0; modelsDis.bcosting = false; modelsDis.cordercode = dtSODetails.Rows[0]["cSTCode"].ToString().Trim(); modelsDis.iorderrowno = BaseFunction.ReturnLong(dtSODetails.Rows[0]["irowno"]); modelsDis.irowno = i + 1; modelsDis.iExpiratDateCalcu = 0; modelsDis.bneedsign = false; modelsDis.frlossqty = 0; modelsDis.bsaleprice = true; modelsDis.bgift = false; modelsDis.bmpforderclosed = false; modelsDis.bIAcreatebill = false; DAL.DispatchLists dalsDis = new DAL.DispatchLists(); sSQL = dalsDis.Add(modelsDis); iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); Model.DispatchLists_extradefine mods_extradeine = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.DispatchLists_extradefine(); mods_extradeine.iDLsID = modelsDis.iDLsID; mods_extradeine.cbdefine1 = dtSODetails.Rows[0]["cbdefine1"].ToString().Trim(); mods_extradeine.cbdefine2 = dtSODetails.Rows[0]["cbdefine2"].ToString().Trim(); mods_extradeine.cbdefine3 = dtSODetails.Rows[0]["cbdefine3"].ToString().Trim(); mods_extradeine.cbdefine4 = BaseFunction.ReturnDecimal(dtSODetails.Rows[0]["cbdefine4"]); mods_extradeine.cbdefine5 = gridView1.GetRowCellValue(i, gridColCartonNo).ToString().Trim(); mods_extradeine.cbdefine6 = dtSODetails.Rows[0]["cbdefine6"].ToString().Trim(); mods_extradeine.cbdefine7 = dtSODetails.Rows[0]["cbdefine7"].ToString().Trim(); mods_extradeine.cbdefine8 = dtSODetails.Rows[0]["cbdefine8"].ToString().Trim(); mods_extradeine.cbdefine9 = dtSODetails.Rows[0]["cbdefine9"].ToString().Trim(); mods_extradeine.cbdefine10 = dtSODetails.Rows[0]["cbdefine10"].ToString().Trim(); DAL.DispatchLists_extradefine dal_extradefine = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.DispatchLists_extradefine(); sSQL = dal_extradefine.Add(mods_extradeine); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" SELECT SUM(ISNULL(iQuantity,0) - ISNULL(fOutQuantity,0)) AS iSumQTY FROM dbo.CurrentStock WITH(NOLOCK) where cInvCode = '@cInvCode' and cWhCode = '@cWhCode' and isnull(cFree1,'') = @cFree1 and isnull(cFree2,'') = @cFree2 and isnull(cFree3,'') = @cFree3 and isnull(cFree4,'') = @cFree4 and isnull(cFree5,'') = @cFree5 and isnull(cFree6,'') = @cFree6 and isnull(cFree7,'') = @cFree7 and isnull(cFree8,'') = @cFree8 and isnull(cFree9,'') = @cFree9 and isnull(cFree10,'') = @cFree10 and isnull(cBatch,'') = @cBatch "; sSQL = sSQL.Replace("@cInvCode", modelsDis.cInvCode); sSQL = sSQL.Replace("@cWhCode", modelsDis.cWhCode); sSQL = sSQL.Replace("@iQuantity", modelsDis.iQuantity.ToString()); sSQL = sSQL.Replace("@iNum", modelsDis.iNum.ToString()); sSQL = sSQL.Replace("@cFree10", modelsDis.cFree10 == null ? "''" : "'" + modelsDis.cFree10 + "'"); sSQL = sSQL.Replace("@cFree1", modelsDis.cFree1 == null ? "''" : "'" + modelsDis.cFree1 + "'"); sSQL = sSQL.Replace("@cFree2", modelsDis.cFree2 == null ? "''" : "'" + modelsDis.cFree2 + "'"); sSQL = sSQL.Replace("@cFree3", modelsDis.cFree3 == null ? "''" : "'" + modelsDis.cFree3 + "'"); sSQL = sSQL.Replace("@cFree4", modelsDis.cFree4 == null ? "''" : "'" + modelsDis.cFree4 + "'"); sSQL = sSQL.Replace("@cFree5", modelsDis.cFree5 == null ? "''" : "'" + modelsDis.cFree5 + "'"); sSQL = sSQL.Replace("@cFree6", modelsDis.cFree6 == null ? "''" : "'" + modelsDis.cFree6 + "'"); sSQL = sSQL.Replace("@cFree7", modelsDis.cFree7 == null ? "''" : "'" + modelsDis.cFree7 + "'"); sSQL = sSQL.Replace("@cFree8", modelsDis.cFree8 == null ? "''" : "'" + modelsDis.cFree8 + "'"); sSQL = sSQL.Replace("@cFree9", modelsDis.cFree9 == null ? "''" : "'" + modelsDis.cFree9 + "'"); sSQL = sSQL.Replace("@cBatch", modelsDis.cBatch == null ? "''" : "'" + modelsDis.cBatch + "'"); decimal dUseQTY = BaseFunction.ReturnDecimal(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0]["iSumQTY"], 6); if (dUseQTY < modelsDis.iQuantity) { sErr = sErr + "Row " + (i + 1).ToString() + " is not enough\n"; continue; } sSQL = @" update CurrentStock set fOutQuantity = isnull(fOutQuantity,0) + @iQuantity where cInvCode = '@cInvCode' and cWhCode = '@cWhCode' and isnull(cFree1,'') = @cFree1 and isnull(cFree2,'') = @cFree2 and isnull(cFree3,'') = @cFree3 and isnull(cFree4,'') = @cFree4 and isnull(cFree5,'') = @cFree5 and isnull(cFree6,'') = @cFree6 and isnull(cFree7,'') = @cFree7 and isnull(cFree8,'') = @cFree8 and isnull(cFree9,'') = @cFree9 and isnull(cFree10,'') = @cFree10 and isnull(cBatch,'') = @cBatch "; sSQL = sSQL.Replace("@cInvCode", modelsDis.cInvCode); sSQL = sSQL.Replace("@cWhCode", modelsDis.cWhCode); sSQL = sSQL.Replace("@iQuantity", modelsDis.iQuantity.ToString()); sSQL = sSQL.Replace("@iNum", modelsDis.iNum.ToString()); sSQL = sSQL.Replace("@cFree10", modelsDis.cFree10 == null ? "''" : "'" + modelsDis.cFree10 + "'"); sSQL = sSQL.Replace("@cFree1", modelsDis.cFree1 == null ? "''" : "'" + modelsDis.cFree1 + "'"); sSQL = sSQL.Replace("@cFree2", modelsDis.cFree2 == null ? "''" : "'" + modelsDis.cFree2 + "'"); sSQL = sSQL.Replace("@cFree3", modelsDis.cFree3 == null ? "''" : "'" + modelsDis.cFree3 + "'"); sSQL = sSQL.Replace("@cFree4", modelsDis.cFree4 == null ? "''" : "'" + modelsDis.cFree4 + "'"); sSQL = sSQL.Replace("@cFree5", modelsDis.cFree5 == null ? "''" : "'" + modelsDis.cFree5 + "'"); sSQL = sSQL.Replace("@cFree6", modelsDis.cFree6 == null ? "''" : "'" + modelsDis.cFree6 + "'"); sSQL = sSQL.Replace("@cFree7", modelsDis.cFree7 == null ? "''" : "'" + modelsDis.cFree7 + "'"); sSQL = sSQL.Replace("@cFree8", modelsDis.cFree8 == null ? "''" : "'" + modelsDis.cFree8 + "'"); sSQL = sSQL.Replace("@cFree9", modelsDis.cFree9 == null ? "''" : "'" + modelsDis.cFree9 + "'"); sSQL = sSQL.Replace("@cBatch", modelsDis.cBatch == null ? "''" : "'" + modelsDis.cBatch + "'"); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); //sSQL = "update SO_SODetails set [iFHQuantity] = isnull(iFHQuantity,0) + aaaaaa,iFHNum = isnull(iFHNum ,0) + bbbbbb,iFHMoney = (isnull(iFHQuantity,0) + aaaaaa) * iTaxUnitPrice where iSOsID = cccccc"; //sSQL = sSQL.Replace("aaaaaa", modelsDis.iQuantity.ToString()); //sSQL = sSQL.Replace("bbbbbb", modelsDis.iNum.ToString()); //sSQL = sSQL.Replace("cccccc", lSOsID.ToString()); //DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = "update _BarCodeLabel set iDispatchLists = 'cccccc', [Status] = '发货' where BarCode = 'aaaaaa' and iSOsID = bbbbbb"; sSQL = sSQL.Replace("aaaaaa", gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim()); sSQL = sSQL.Replace("bbbbbb", lSOsID.ToString()); sSQL = sSQL.Replace("cccccc", modelsDis.AutoID.ToString()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); Model.BarStatus modBarStatus = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus(); modBarStatus.BarCode = gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim(); modBarStatus.iSOsID = lSOsID; modBarStatus.Type = "发货"; modBarStatus.UpdateTime = dNow; modBarStatus.QTY = modelsDis.iQuantity; modBarStatus.CreateUid = sUserID; modBarStatus.CreateDate = dNow; DAL.BarStatus dalBarStatus = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus(); sSQL = dalBarStatus.Add(modBarStatus); 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, modBarStatus.BarCode, modBarStatus.iSOsID, dNow); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" update a set iFHQuantity = b.iQty, iFHNum = b.iNum from SO_SODetails a left join (select sum(iQuantity) as iQty,sum(iNum) as iNum,iSOSid from DispatchLists group by iSOSid) b on a.iSOsID = b.iSOsID where a.iSOsID = aaaaaa "; sSQL = sSQL.Replace("aaaaaa", modelsDis.iSOsID.ToString()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } if (lIDDis > 1000000000) { lIDDis = lIDDis - 1000000000; } if (lIDDisDetails > 1000000000) { lIDDisDetails = lIDDisDetails - 1000000000; } sSQL = "update UFSystem..UA_Identity set iFatherId = " + lIDDis.ToString() + ",iChildId = " + lIDDisDetails + " where cAcc_Id = '" + sAccID + "' and cVouchType = 'DISPATCH'"; DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" if exists(select * from VoucherHistory where (cSeed = 'DPaaaaaa' or cSeed = 'aaaaaa') AND cContentRule like '%YYYY%' AND CardNumber = '01') update VoucherHistory set cNumber = bbbbbb where (cSeed = 'DPaaaaaa' or cSeed = 'aaaaaa') AND cContentRule like '%YYYY%' AND CardNumber = '01' else insert into VoucherHistory(CardNumber,cContent,cContentRule,cSeed,cNumber,bEmpty) values('01',N'手工输入|单据日期',N'DP|YYYY','DPaaaaaa','bbbbbb',0) "; sSQL = sSQL.Replace("aaaaaa", dNow.ToString("yyyy")); sSQL = sSQL.Replace("bbbbbb", lCodeDis.ToString()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); if (sErr.Trim() != "") { throw new Exception(sErr); } //string sRDCode = AuditDispatchList(sCodeDis, tran); //if (sRDCode.Trim() == "") //{ // throw new Exception("Create data err\n"); //} if (iCount > 0) { tran.Commit(); MessageBox.Show("OK\n" + modelDis.cDLCode); SetTxtNull(); gridControl1.DataSource = DBNull.Value; lookUpEditProcess.Focus(); } } 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 btnPrint_Click(object sender, EventArgs e) { string sErr = ""; int iCount = 0; try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } 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")); DataTable dtGrid = ((DataTable)gridControl1.DataSource).Copy(); dtGrid.TableName = "dtGrid"; DataColumn dc = new DataColumn(); dc.ColumnName = "BarCreateDate"; dtGrid.Columns.Add(dc); for (int i = dtGrid.Rows.Count - 1; i >= 0; i--) { if (!BaseFunction.ReturnBool(dtGrid.Rows[i]["choose"])) { dtGrid.Rows.RemoveAt(i); } } sSQL = @" select MAX(SUBSTRING(BarCode,9,4)) from _BarCodeLabel where SUBSTRING(BarCode,3,6) = 'aaaaaa' "; sSQL = sSQL.Replace("aaaaaa", dNowDate.ToString("yyMMdd")); DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; long lBarList = BaseFunction.ReturnLong(dt.Rows[0][0]); for (int i = 0; i < dtGrid.Rows.Count; i++) { long iLotSize = BaseFunction.ReturnLong(dtGrid.Rows[0]["LotSize"]); if (iLotSize <= 0) { sErr = sErr + "Row " + (i + 1).ToString() + " lot qty err\n"; continue; } sSQL = "select count(1) from [_BarCodeLabel] where 1=1 and isnull(printCount,0) >0 and [iSOsID] = " + dtGrid.Rows[i]["iSOsID"].ToString().Trim() + " and [RDsID] = '" + dtGrid.Rows[i]["RdsAutoid"].ToString().Trim() + "'"; if (dtGrid.Rows[i]["cSTCode"].ToString().ToLower().Trim() == "os") { sSQL = sSQL.Replace("1=1", "1=1 and Batch = '" + dtGrid.Rows[i]["cBatch"].ToString().Trim() + "'"); } dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (BaseFunction.ReturnInt(dt.Rows[0][0], -1) != 0) { sErr = sErr + dtGrid.Rows[i]["ORDNO"] + " " + dtGrid.Rows[i]["iRowNo"] + " is printed\n"; continue; } long dOrderQTY = BaseFunction.ReturnLong(dtGrid.Rows[i]["ORDQTY"]); long dLOTQTY = BaseFunction.ReturnLong(dtGrid.Rows[i]["LOTQTY"]); if (dtGrid.Rows[i]["LOTNO"].ToString().Trim() != "") { dLOTQTY = 1; } if (dLOTQTY == 1 || dtGrid.Rows[i]["LOTNO"].ToString().Trim() != "") { dLOTQTY = dOrderQTY; } ////OS 业务使用入库单作为 dOrderQTY用于判断打印循环 //if (dtGrid.Rows[i]["cSTCode"].ToString().ToLower().Trim() == "os") //{ // dOrderQTY = dLOTQTY; //} while (dOrderQTY > 0) { lBarList += 1; Model._BarCodeLabel model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._BarCodeLabel(); dtGrid.Rows[i]["BarCreateDate"] = "Printed on " + dNow.ToString("yyyy/MM/dd HH:mm:ss"); if (dtGrid.Rows[i]["LOTNO"].ToString().Trim() == "") { string sBarList = lBarList.ToString(); while (sBarList.Length < 4) { sBarList = "0" + sBarList; } model.BarCode = dtGrid.Rows[i]["cSTCode"].ToString().Trim() + dNowDate.ToString("yyMMdd") + sBarList; } else { model.BarCode = dtGrid.Rows[i]["LOTNO"].ToString().Trim(); } dtGrid.Rows[i]["barcode"] = model.BarCode; model.SaleOrderNo = dtGrid.Rows[i]["ORDNO"].ToString().Trim(); model.SaleOrderRowNo = BaseFunction.ReturnLong(dtGrid.Rows[i]["iRowNo"]); model.iSOsID = BaseFunction.ReturnLong(dtGrid.Rows[i]["iSOsID"]); model.cInvCode = dtGrid.Rows[i]["ITEMNO"].ToString().Trim(); model.cInvName = dtGrid.Rows[i]["ITEMDESC"].ToString().Trim(); model.DEPT = dtGrid.Rows[i]["DEPT"].ToString().Trim(); model.CUST = dtGrid.Rows[i]["CUST"].ToString().Trim(); model.ORDERNO = dtGrid.Rows[i]["ORDNO"].ToString().Trim(); model.CUSTDO = dtGrid.Rows[i]["CUSTDO"].ToString().Trim(); model.LOTNO = dtGrid.Rows[i]["LOTNO"].ToString().Trim(); model.ORDERQTY = BaseFunction.ReturnLong(dtGrid.Rows[i]["ORDQTY"]); model.CUSTLOT = dtGrid.Rows[i]["CUSTLOT"].ToString().Trim(); model.LotSize = BaseFunction.ReturnDecimal(dtGrid.Rows[i]["LotSize"], 2); model.Batch = dtGrid.Rows[i]["cBatch"].ToString().Trim(); model.RDsID = BaseFunction.ReturnLong(dtGrid.Rows[i]["RdsAutoid"]); model.RDType = dtGrid.Rows[i]["RDsType"].ToString().Trim(); model.Process = dtGrid.Rows[i]["cWhCode"].ToString().Trim(); if (dOrderQTY >= dLOTQTY) { model.LOTQTY = dLOTQTY; dOrderQTY = dOrderQTY - dLOTQTY; } else { model.LOTQTY = dOrderQTY; dOrderQTY = 0; } model.LOTQTY2 = model.LOTQTY; model.RECDate = BaseFunction.ReturnDate(dtGrid.Rows[i]["RECDTE"]); model.DueDate = BaseFunction.ReturnDate(dtGrid.Rows[i]["DUEDTE"]); model.Creater = sUserID; model.CreateDate = dNow; model.PrintTime = dNow; model.PrintCount = 1; model.Status = "新增"; DAL._BarCodeLabel dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._BarCodeLabel(); 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.BarCode; models.Type = "新增"; models.UpdateTime = dNow; models.QTY = model.LOTQTY; models.CreateDate = dNowDate; models.CreateUid = sUserID; models.iSOsID = model.iSOsID; models.RoutingFrom = "新增"; models.RoutingTo = model.Process; DAL.BarStatus dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus(); sSQL = dals.Add(models); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } //} //else //{ // sSQL = "update _BarCodeLabel set Status = '新增', printTime = getdate(), PrintCount = 1, createdate = '" + dNow + "' where BarCode = '" + dtGrid.Rows[i]["LOTNO"].ToString().Trim() + "' and iSOsID = " + dtGrid.Rows[i]["iSOsID"].ToString().Trim(); // iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); //} } if (sErr.Length > 0) { throw new Exception(sErr); } if (iCount == 0) { throw new Exception("Please choose data\n" + sErr); } Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } sSQL = @" select a.barCode, a.SaleOrderNo, a.SaleOrderRowNo, a.iSOsID, a.cInvCode, a.cInvName, a.cInvStd, Inv.cInvDepCode as DEPT ,b.cDepName as DEPTName, CUST,ORDERNO AS ORDNO, CUSTDO, LOTNO, ORDERQTY, LOTQTY, RECDate, DueDate, Creater, CreateDate ,PrintTime, PrintCount, a.cInvCode AS ITEMNO, a.cInvName AS ITEMDESC ,RECDate,DueDate ,cast(null as varchar(50)) as RECDate2,cast(null as varchar(50)) as DueDate2 ,ORDERQTY as ORDQTY ,CUSTLOT ,'Printed on ' as PrintInfo ,c.cMemo ,Inv.cInvDefine6 ,Inv.cComUnitCode as cUnitID from _BarCodeLabel a inner join Inventory Inv on a.cInvCode = Inv.cInvCode left join Department b on Inv.cInvDepCode = b.cDepCode left join SO_SODetails c on c.iSOsID = a.iSOsID where creater = '{0}' and createdate = '{1}' order by a.barCode "; sSQL = string.Format(sSQL, sUserID, dNow); DataTable dtBarCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; for (int i = 0; i < dtBarCode.Rows.Count; i++) { dtBarCode.Rows[i]["PrintInfo"] = "Printed on " + BaseFunction.ReturnDate(dtBarCode.Rows[i]["PrintTime"]).ToString("yyyy/MM/dd HH:mm:ss"); dtBarCode.Rows[i]["RECDate2"] = BaseFunction.ReturnDate(dtBarCode.Rows[i]["RECDate"]).ToString("yyyy-MM-dd"); dtBarCode.Rows[i]["DueDate2"] = BaseFunction.ReturnDate(dtBarCode.Rows[i]["DueDate"]).ToString("yyyy-MM-dd"); } Rep.dsPrint.Tables.Clear(); Rep.dsPrint.Tables.Add(dtBarCode.Copy()); Rep.dsPrint.Tables[0].TableName = "dtGrid"; if (radioPreview.Checked) { Rep.ShowPreview(); } if (radioPrint.Checked) { if (lookUpEditPrinter.Text.Trim() == "") { lookUpEditPrinter.Focus(); throw new Exception("Please choose printer"); } Rep.PrinterName = lookUpEditPrinter.Text.Trim(); Rep.Print(); } if (iCount > 0) { tran.Commit(); GetGrid(); } } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
private void btnSave_Click(object sender, EventArgs e) { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } txtBarCode.Focus(); string sErr = ""; int iCount = 0; try { if (gridView1.RowCount < 1) { throw new Exception("Please scan barcode"); } string sProcess = gridView1.GetRowCellValue(0, gridColProcess).ToString().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")); for (int i = 0; i < gridView1.RowCount; i++) { long lSOsID = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColiSOsID)); sSQL = @" select * from SO_SOMain a inner join SO_SODetails b on a.ID = b.ID left join _SystemSet c on a.cSTCode = c.cSTCode inner join Inventory d on b.cInvCode = d.cInvCode inner join [_BarCodeLabel] e on e.[iSOsID] = b.[iSOsID] where b.iSOsID = aaaaaa order by b.autoid "; sSQL = sSQL.Replace("aaaaaa", lSOsID.ToString().Trim()); DataTable dtSODetails = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dtSODetails == null || dtSODetails.Rows.Count == 0) { throw new Exception("Sale Order not exists err"); } //if (gridView1.GetRowCellValue(i, gridColcCusCode).ToString().Trim() != sCusCode) //{ // sErr = sErr + "Row " + (i + 1).ToString() + " customer err\n"; // continue; //} string sBarCode = gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim(); Model._SalesShipment model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._SalesShipment(); model.cCusCode = gridView1.GetRowCellValue(i, gridColcCusCode).ToString().Trim(); model.CreateDate = dNow; model.CreateUid = sUserID; model.cSOCode = gridView1.GetRowCellValue(i, gridColcSOCode).ToString(); model.cSTCode = gridView1.GetRowCellValue(i, gridColcSTCode).ToString(); model.CurrQTY = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColCurrQTY)); //model.DEPT model.Description = gridView1.GetRowCellValue(i, gridColDescription).ToString(); model.iSOsID = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColiSOsID)); model.ItemNO = gridView1.GetRowCellValue(i, gridColItemNO).ToString(); model.LotNO = sBarCode; model.LOTQTY = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLOTQTY)); model.OrderQTY = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColOrderQTY)); model.OtherQTY = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColOtherQTY)); model.Process = gridView1.GetRowCellValue(i, gridColProcess).ToString(); //model.ProcessNext = gridView1.GetRowCellValue(i,gridCol model.SaleOrderRow = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColSaleOrderRow)); //model.Status = "ship" model.CartonNo = gridView1.GetRowCellValue(i, gridColCartonNo).ToString().Trim(); DAL._SalesShipment dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._SalesShipment(); sSQL = dal.Add(model); iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = "update _BarCodeLabel set [Status] = 'Pending' where BarCode = 'aaaaaa' and iSOsID = bbbbbb"; sSQL = sSQL.Replace("aaaaaa", gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim()); sSQL = sSQL.Replace("bbbbbb", model.iSOsID.ToString()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); Model.BarStatus modBarStatus = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus(); modBarStatus.BarCode = gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim(); modBarStatus.iSOsID = lSOsID; modBarStatus.Type = "Pending"; modBarStatus.UpdateTime = dNow; modBarStatus.QTY = model.LOTQTY; modBarStatus.CreateUid = sUserID; modBarStatus.CreateDate = dNow; modBarStatus.RoutingFrom = lookUpEditProcess.EditValue.ToString().Trim(); modBarStatus.RoutingTo = lookUpEditProcess.EditValue.ToString().Trim(); DAL.BarStatus dalBarStatus = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus(); sSQL = dalBarStatus.Add(modBarStatus); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } if (sErr.Trim() != "") { throw new Exception(sErr); } if (iCount > 0) { tran.Commit(); SetTxtNull(); gridControl1.DataSource = DbHelperSQL.Query(sSQLBar); txtBarCode.Focus(); } } 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) { 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 = 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); } }
private void btnSave_Click(object sender, EventArgs e) { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } txtBarCode.Focus(); string sErr = ""; int iCount = 0; try { string sProcess = gridView1.GetRowCellValue(0, gridColProcess).ToString().Trim(); string sProcessNext = gridView1.GetRowCellValue(0, gridColProcessNext).ToString().Trim(); if (sProcess == sProcessNext) { throw new Exception("Process is err"); } 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")); int iYear = dNow.Year; int iPeriod = dNow.Month; string s期间 = BaseFunction.ReturnDate(iYear.ToString() + "-" + iPeriod.ToString() + "-01").ToString("yyyyMM"); sSQL = "select isnull(bflag_ST,0) as bflag from GL_mend where iYPeriod = '" + s期间 + "'"; DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt == null || dt.Rows.Count == 0) { throw new Exception("Access module state failure"); } int i结账 = BaseFunction.ReturnInt(dt.Rows[0]["bflag"]); if (i结账 > 0) { throw new Exception(dNow.ToString("yyyy-MM") + " have checked out"); } //判断是否转入质检工序 bool bIQCIn = false; //材料入库检验 bool bOQCIn = false; //产品销售出库检验 sSQL = @" select cWhMemo from Warehouse where cWhCode = '{0}' "; sSQL = string.Format(sSQL, lookUpEditProcessNext.EditValue.ToString().Trim()); dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt.Rows[0]["cWhMemo"].ToString().Trim().ToLower().Contains("iqc")) { bIQCIn = true; } if (dt.Rows[0]["cWhMemo"].ToString().Trim().ToLower().Contains("oqc")) { bOQCIn = true; } //判断是否从质检工序转出 bool bIQCOut = false; //材料入库检验工序转出 bool bOQCOut = false; //产品销售出库检验工序转出 sSQL = @" select cWhMemo from Warehouse where cWhCode = '{0}' "; sSQL = string.Format(sSQL, lookUpEditProcess.EditValue.ToString().Trim()); dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt.Rows[0]["cWhMemo"].ToString().Trim().ToLower().Contains("iqc")) { bIQCOut = true; } if (dt.Rows[0]["cWhMemo"].ToString().Trim().ToLower().Contains("oqc")) { bOQCOut = true; } #region 流转 long lID = -1; long lIDDetails = -1; sSQL = @" declare @p5 int set @p5=aaaaaa declare @p6 int set @p6=bbbbbb exec sp_GetId N'00',N'dddddd',N'tr',1,@p5 output,@p6 output,default select @p5, @p6 "; sSQL = sSQL.Replace("aaaaaa", lID.ToString()); sSQL = sSQL.Replace("bbbbbb", lIDDetails.ToString()); sSQL = sSQL.Replace("dddddd", sAccID); dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; lID = BaseFunction.ReturnLong(dt.Rows[0][0]) - 1; lIDDetails = BaseFunction.ReturnLong(dt.Rows[0][1]) - 1; ////获得单据号 sSQL = "select * from VoucherHistory with (ROWLOCK) Where CardNumber='0304' AND cContentRule = 'YYYY' AND cSeed = 'aaaaaa'"; sSQL = sSQL.Replace("aaaaaa", dNow.ToString("yyyy")); dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; long lCode = 0; if (dt != null && dt.Rows.Count > 0) { lCode = BaseFunction.ReturnLong(dt.Rows[0]["cNumber"]); } else { lCode = 0; } lCode += 1; string sCode = lCode.ToString(); while (sCode.Length < 6) { sCode = "0" + sCode; } sCode = "TR" + dNow.ToString("yyyy") + sCode; Model.TransVouch mod = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.TransVouch(); mod.cTVCode = sCode; mod.dTVDate = dNowDate; mod.cOWhCode = lookUpEditProcess.EditValue.ToString().Trim(); mod.cIWhCode = lookUpEditProcessNext.EditValue.ToString().Trim(); mod.cODepCode = null; mod.cIDepCode = null; mod.cPersonCode = null; mod.cIRdCode = "TI"; mod.cORdCode = "TO"; mod.cTVMemo = null; mod.cDefine1 = null; mod.cDefine2 = null; mod.cDefine3 = null; mod.cDefine4 = null; mod.cDefine5 = null; mod.cDefine6 = null; mod.cDefine7 = null; mod.cDefine8 = null; mod.cDefine9 = null; mod.cDefine10 = null; mod.cAccounter = null; mod.iNetLock = 1; lID += 1; mod.ID = lID; mod.VT_ID = 89; mod.cMaker = sUserName; mod.dnmaketime = dNow; mod.cVerifyPerson = sUserName; mod.dVerifyDate = dNowDate; mod.cPSPCode = null; mod.cMPoCode = null; mod.iQuantity = 0; mod.bTransFlag = null; mod.cDefine11 = null; mod.cDefine12 = null; mod.cDefine13 = null; mod.cDefine14 = null; mod.cDefine15 = null; mod.cDefine16 = null; mod.iproorderid = null; mod.cTranRequestCode = null; mod.cVersion = null; mod.BomId = null; mod.cFree1 = null; mod.cFree2 = null; mod.cFree3 = null; mod.cFree4 = null; mod.cFree5 = null; mod.cFree6 = null; mod.cFree7 = null; mod.cFree8 = null; mod.cFree9 = null; mod.cFree10 = null; mod.cAppTVCode = null; mod.csource = "1"; mod.itransflag = "正向"; mod.cModifyPerson = null; mod.dModifyDate = null; mod.dnmaketime = dNow; mod.dnmodifytime = null; mod.ireturncount = null; mod.iverifystate = null; mod.iswfcontrolled = 0; mod.csourceguid = null; mod.csysbarcode = "||st12||" + mod.cTVCode; DAL.TransVouch dalTR = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.TransVouch(); sSQL = dalTR.Add(mod); iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); mod.cCurrentAuditor = null; int iRow = 0; for (int i = 0; i < gridView1.RowCount; i++) { if (!BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColchoose))) { continue; } string sBarCode = gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim(); sSQL = @" select * from _BarCodeLabel where [BarCode] = '{0}' and iSOsID = {1}"; sSQL = string.Format(sSQL, sBarCode, gridView1.GetRowCellValue(i, gridColiSOsID).ToString()); dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt == null || dt.Rows.Count == 0) { sErr = sErr + "row " + (i + 1).ToString() + "is not exists \n"; continue; } if (dt.Rows[0]["CloseUid"].ToString().Trim() != "") { sErr = sErr + "row " + (i + 1).ToString() + " is closed \n"; continue; } if (dt.Rows[0]["Process"].ToString().Trim().ToLower() != lookUpEditProcess.EditValue.ToString().Trim().ToLower()) { sErr = sErr + "row " + (i + 1).ToString() + " process is changed \n"; continue; } if (BaseFunction.ReturnDecimal(dt.Rows[0]["LotQTY"]) != BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLOTQTY))) { sErr = sErr + "row " + (i + 1).ToString() + " number is changed \n"; continue; } if (dt.Rows[0]["IQCStatus"].ToString() != gridView1.GetRowCellValue(i, gridColIQCStatus).ToString().Trim()) { sErr = sErr + "row " + (i + 1).ToString() + " iqcstatus is changed \n"; continue; } if (dt.Rows[0]["OQCStatus"].ToString() != gridView1.GetRowCellValue(i, gridColOQCStatus).ToString().Trim()) { sErr = sErr + "row " + (i + 1).ToString() + " iqcstatus is changed \n"; continue; } iRow += 1; Model.BarStatus model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus(); model.BarCode = sBarCode; model.iSOsID = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColiSOsID)); model.Type = "工序流转"; if (bIQCIn) { model.Type = "IQC"; sSQL = @" update _IQC_RMDF set ClosedUid = '{0}',dtmClose = getdate() where LotNo = '{1}' and iSOsID = '{2}' and isnull(ClosedUid,'') <> '' "; sSQL = string.Format(sSQL, sUserID, model.BarCode, model.iSOsID); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } if (bOQCIn) { model.Type = "OQC"; } model.RoutingFrom = lookUpEditProcess.EditValue.ToString().Trim(); model.RoutingTo = lookUpEditProcessNext.EditValue.ToString().Trim(); model.UpdateTime = dNow; model.QTY = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLOTQTY)); model.CreateUid = sUserID; model.CreateDate = dNow; DAL.BarStatus dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus(); sSQL = dal.Add(model); iCount += 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, sBarCode, model.iSOsID, dNow); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); if (bIQCOut) { sSQL = @" select * from _BarCodeLabel where [BarCode] = '{0}' and iSOsID = '{1}' "; sSQL = string.Format(sSQL, sBarCode, model.iSOsID); DataTable dtQC = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; string sIQCStatus = dtQC.Rows[0]["IQCStatus"].ToString().Trim().ToLower(); sIQCStatus = sIQCStatus.Replace(" ", ""); if (!sIQCStatus.ToLower().StartsWith("iqc")) { sErr = sErr + "row " + (i + 1).ToString() + " IQC not passed \n"; continue; } } if (bOQCOut) { sSQL = @" select * from _BarCodeLabel where [BarCode] = '{0}' and iSOsID = '{1}' "; sSQL = string.Format(sSQL, sBarCode, model.iSOsID); DataTable dtQC = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; string sOQCStatus = dtQC.Rows[0]["OQCStatus"].ToString().Trim().ToLower(); sOQCStatus = sOQCStatus.Replace(sOQCStatus, " "); if (sOQCStatus == "oqc-ONHOLD".ToLower()) { sErr = sErr + "row " + (i + 1).ToString() + " OQC onhold \n"; continue; } } //回写 BarCodeLabel sSQL = "update [_BarCodeLabel] set process = '" + model.RoutingTo + "',Status = '流转' where [BarCode] = '" + sBarCode + "' and iSOsID = '" + model.iSOsID + "'"; DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); if (bIQCIn) { sSQL = "update [_BarCodeLabel] set IQCStatus = 'Pending IQC',Status = 'IQC' where [BarCode] = '" + sBarCode + "' and iSOsID = '" + model.iSOsID + "'"; int iRunCou = DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } if (bOQCIn) { sSQL = "update [_BarCodeLabel] set OQCStatus = 'Pending OQC',Status = 'OQC' where [BarCode] = '" + sBarCode + "' and iSOsID = '" + model.iSOsID + "'"; DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } Model.TransVouchs mods = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.TransVouchs(); mods.cTVCode = mod.cTVCode; mods.cInvCode = gridView1.GetRowCellValue(i, gridColItemNO).ToString().Trim(); mods.iTVNum = null; mods.iTVQuantity = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLOTQTY)); lIDDetails += 1; mods.autoID = lIDDetails; mods.ID = mod.ID; mods.bCosting = true; mods.irowno = iRow; mods.coutposcode = null; mods.cinposcode = null; mods.cTVBatch = gridView1.GetRowCellValue(i, gridColcBatch).ToString().Trim(); mods.cbsysbarcode = "||st12|" + mod.cTVCode + "|" + iRow.ToString(); DAL.TransVouchs dalTRs = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.TransVouchs(); sSQL = dalTRs.Add(mods); iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } if (sErr.Length > 0) { throw new Exception(sErr); } if (lID > 1000000000) { lID = lID - 1000000000; } if (lIDDetails > 1000000000) { lIDDetails = lIDDetails - 1000000000; } sSQL = "update UFSystem..UA_Identity set iFatherId = " + lID.ToString() + ",iChildId = " + lIDDetails + " where cAcc_Id = '" + sAccID + "' and cVouchType = 'tr'"; DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = @" if exists(select * from VoucherHistory where CardNumber='0304' AND cContentRule = 'YYYY' AND cSeed = 'bbbbbb') update VoucherHistory set cNumber = aaaaaa where CardNumber = '0304' AND cContentRule = 'YYYY' AND cSeed = 'bbbbbb' else insert into VoucherHistory(CardNumber,cContent,cContentRule,cSeed,cNumber,bEmpty) values('0304','日期','YYYY','bbbbbb','aaaaaa',0) "; sSQL = sSQL.Replace("aaaaaa", lCode.ToString()); sSQL = sSQL.Replace("bbbbbb", dNow.ToString("yyyy")); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); clsU8 cls = new clsU8(); cls.TransVouch_Audit_U8V111(tran, mod.cTVCode, sAccID, sUserName); #endregion if (iCount > 0) { tran.Commit(); MessageBox.Show("OK\n"); SetTxtNull(); gridControl1.DataSource = DbHelperSQL.Query(sSQLBar); txtBarCode.Focus(); } } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { FrmMsgBox frm = new FrmMsgBox(); frm.richTextBox1.Text = ee.Message; frm.ShowDialog(); } gridColScanTime.SortOrder = DevExpress.Data.ColumnSortOrder.Descending; }