/// <summary> /// 增加一条数据 /// </summary> public string Add(Purchase.Model.PU_PriceJustMain model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.id != null) { strSql1.Append("id,"); strSql2.Append("" + model.id + ","); } if (model.ddate != null) { strSql1.Append("ddate,"); strSql2.Append("'" + model.ddate + "',"); } if (model.ccode != null) { strSql1.Append("ccode,"); strSql2.Append("'" + model.ccode + "',"); } if (model.cmaker != null) { strSql1.Append("cmaker,"); strSql2.Append("'" + model.cmaker + "',"); } if (model.cpersoncode != null) { strSql1.Append("cpersoncode,"); strSql2.Append("'" + model.cpersoncode + "',"); } if (model.cmainmemo != null) { strSql1.Append("cmainmemo,"); strSql2.Append("'" + model.cmainmemo + "',"); } if (model.cverifier != null) { strSql1.Append("cverifier,"); strSql2.Append("'" + model.cverifier + "',"); } if (model.dverifydate != null) { strSql1.Append("dverifydate,"); strSql2.Append("'" + model.dverifydate + "',"); } if (model.cdepcode != null) { strSql1.Append("cdepcode,"); strSql2.Append("'" + model.cdepcode + "',"); } if (model.ivtid != null) { strSql1.Append("ivtid,"); strSql2.Append("" + model.ivtid + ","); } if (model.cdefine1 != null) { strSql1.Append("cdefine1,"); strSql2.Append("'" + model.cdefine1 + "',"); } if (model.cdefine2 != null) { strSql1.Append("cdefine2,"); strSql2.Append("'" + model.cdefine2 + "',"); } if (model.cdefine3 != null) { strSql1.Append("cdefine3,"); strSql2.Append("'" + model.cdefine3 + "',"); } if (model.cdefine4 != null) { strSql1.Append("cdefine4,"); strSql2.Append("'" + model.cdefine4 + "',"); } if (model.cdefine5 != null) { strSql1.Append("cdefine5,"); strSql2.Append("" + model.cdefine5 + ","); } if (model.cdefine6 != null) { strSql1.Append("cdefine6,"); strSql2.Append("'" + model.cdefine6 + "',"); } if (model.cdefine7 != null) { strSql1.Append("cdefine7,"); strSql2.Append("" + model.cdefine7 + ","); } if (model.cdefine8 != null) { strSql1.Append("cdefine8,"); strSql2.Append("'" + model.cdefine8 + "',"); } if (model.cdefine9 != null) { strSql1.Append("cdefine9,"); strSql2.Append("'" + model.cdefine9 + "',"); } if (model.cdefine10 != null) { strSql1.Append("cdefine10,"); strSql2.Append("'" + model.cdefine10 + "',"); } if (model.cdefine11 != null) { strSql1.Append("cdefine11,"); strSql2.Append("'" + model.cdefine11 + "',"); } if (model.cdefine12 != null) { strSql1.Append("cdefine12,"); strSql2.Append("'" + model.cdefine12 + "',"); } if (model.cdefine13 != null) { strSql1.Append("cdefine13,"); strSql2.Append("'" + model.cdefine13 + "',"); } if (model.cdefine14 != null) { strSql1.Append("cdefine14,"); strSql2.Append("'" + model.cdefine14 + "',"); } if (model.cdefine15 != null) { strSql1.Append("cdefine15,"); strSql2.Append("" + model.cdefine15 + ","); } if (model.cdefine16 != null) { strSql1.Append("cdefine16,"); strSql2.Append("" + model.cdefine16 + ","); } if (model.ufts != null) { strSql1.Append("ufts,"); strSql2.Append("" + model.ufts + ","); } if (model.iverifystate != null) { strSql1.Append("iverifystate,"); strSql2.Append("" + model.iverifystate + ","); } if (model.ireturncount != null) { strSql1.Append("ireturncount,"); strSql2.Append("" + model.ireturncount + ","); } if (model.iswfcontrolled != null) { strSql1.Append("iswfcontrolled,"); strSql2.Append("" + (model.iswfcontrolled ? 1 : 0) + ","); } if (model.bTaxCost != null) { strSql1.Append("bTaxCost,"); strSql2.Append("" + model.bTaxCost + ","); } if (model.iSupplyType != null) { strSql1.Append("iSupplyType,"); strSql2.Append("" + model.iSupplyType + ","); } if (model.cMakeTime != null) { strSql1.Append("cMakeTime,"); strSql2.Append("'" + model.cMakeTime + "',"); } if (model.cModifyTime != null) { strSql1.Append("cModifyTime,"); strSql2.Append("'" + model.cModifyTime + "',"); } if (model.cAuditTime != null) { strSql1.Append("cAuditTime,"); strSql2.Append("'" + model.cAuditTime + "',"); } if (model.cModifyDate != null) { strSql1.Append("cModifyDate,"); strSql2.Append("'" + model.cModifyDate + "',"); } if (model.cReviser != null) { strSql1.Append("cReviser,"); strSql2.Append("'" + model.cReviser + "',"); } if (model.iPrintCount != null) { strSql1.Append("iPrintCount,"); strSql2.Append("" + model.iPrintCount + ","); } if (model.ccleanver != null) { strSql1.Append("ccleanver,"); strSql2.Append("'" + model.ccleanver + "',"); } if (model.csysbarcode != null) { strSql1.Append("csysbarcode,"); strSql2.Append("'" + model.csysbarcode + "',"); } if (model.cCurrentAuditor != null) { strSql1.Append("cCurrentAuditor,"); strSql2.Append("'" + model.cCurrentAuditor + "',"); } strSql.Append("insert into @u8.PU_PriceJustMain("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); return(strSql.ToString()); }
private void btnSave() { try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } string sErr = ""; string sSQL = ""; for (int i = 0; i < gridView1.RowCount; i++) { string sInvName = gridView1.GetRowCellDisplayText(i, gridColcInvName).ToString().Trim(); if (sInvName == "") { sErr = sErr + "行" + (i + 1).ToString() + " 存货不正确\n"; } string sVenName = gridView1.GetRowCellDisplayText(i, gridColcVenName).ToString().Trim(); if (sVenName == "") { sErr = sErr + "行" + (i + 1).ToString() + " 供应商不正确\n"; } decimal d含税单价 = ReturnObjectToDecimal(gridView1.GetRowCellDisplayText(i, gridCol含税单价), 6); if (d含税单价 <= 0) { sErr = sErr + "行" + (i + 1).ToString() + " 含税单价不正确\n"; } if (gridView1.GetRowCellDisplayText(i, gridCol税率).ToString().Trim() == "") { sErr = sErr + "行" + (i + 1).ToString() + " 税率不正确\n"; } decimal d税率 = ReturnObjectToDecimal(gridView1.GetRowCellDisplayText(i, gridCol税率), 6); if (d税率 < 0 || d税率 > 100) { sErr = sErr + "行" + (i + 1).ToString() + " 税率不正确\n"; } sSQL = "select isnull(bPurchase,0) as bPurchase from @u8.Inventory where cInvCode = 'aaaaaaaaaa'"; sSQL = sSQL.Replace("aaaaaaaaaa", gridView1.GetRowCellDisplayText(i, gridColcinvcode).ToString().Trim()); int iReturn = BaseFunction.ReturnInt(clsSQLCommond.ExecGetScalar(sSQL)); if (iReturn == 0) { sErr = sErr + "行" + (i + 1).ToString() + " 存货【" + gridView1.GetRowCellDisplayText(i, gridColcinvcode).ToString().Trim() + "】" + sInvName + " 不是采购件\n"; } } if (sErr.Length > 0) { throw new Exception(sErr); } ArrayList aList = new ArrayList(); sSQL = @" declare @p5 int set @p5=1000003974 declare @p6 int set @p6=1000042663 exec @u8.sp_getID N'00',N'200',N'puprice',1,@p5 output,@p6 output select @p5, @p6 "; DataTable dt = clsSQLCommond.ExecQuery(sSQL); long lID = ReturnObjectToLong(dt.Rows[0][0]); long lIDs = ReturnObjectToLong(dt.Rows[0][1]); sSQL = @" select cNumber as Maxnumber From @u8.VoucherHistory with (NOLOCK) Where CardNumber='PU03' and cContent is NULL "; dt = clsSQLCommond.ExecQuery(sSQL); long lCode = ReturnObjectToLong(dt.Rows[0][0]) + 1; string sCode = lCode.ToString(); while (sCode.Length < 10) { sCode = "0" + sCode; } Model.PU_PriceJustMain mod = new Purchase.Model.PU_PriceJustMain(); mod.id = lID; mod.ddate = BaseFunction.ReturnDate(FrameBaseFunction.ClsBaseDataInfo.sLogDate); mod.ccode = sCode; mod.cmaker = FrameBaseFunction.ClsBaseDataInfo.sUserName; mod.ivtid = 31338; mod.bTaxCost = 1; mod.iSupplyType = 1; mod.cMakeTime = DateTime.Now; mod.iPrintCount = 0; //mod.iverifystate = 0; mod.cverifier = FrameBaseFunction.ClsBaseDataInfo.sUserName; mod.dverifydate = BaseFunction.ReturnDate(FrameBaseFunction.ClsBaseDataInfo.sLogDate); mod.iverifystate = 2; mod.cmainmemo = gridView1.GetRowCellDisplayText(0, gridCol表头备注).ToString().Trim(); mod.csysbarcode = @"||putj|" + mod.ccode; mod.cAuditTime = mod.cMakeTime; DAL.PU_PriceJustMain dal = new Purchase.DAL.PU_PriceJustMain(); sSQL = dal.Add(mod); aList.Add(sSQL); int iRow = 0; bool bHas = false; for (int i = 0; i < gridView1.RowCount; i++) { if (!ReturnObjectToBool(gridView1.GetRowCellValue(i, gridCol选择))) { continue; } iRow += 1; lIDs += 1; Model.PU_PriceJustDetail mods = new Purchase.Model.PU_PriceJustDetail(); mods.autoid = lIDs; mods.id = lID; mods.operationtype = "0"; mods.cvencode = gridView1.GetRowCellDisplayText(i, gridColcVenCode).ToString().Trim(); mods.cinvcode = gridView1.GetRowCellDisplayText(i, gridColcinvcode).ToString().Trim(); mods.dstartdate = BaseFunction.ReturnDate(FrameBaseFunction.ClsBaseDataInfo.sLogDate); mods.bsales = 0; mods.fminquantity = 0; mods.iTaxRate = ReturnObjectToDecimal(gridView1.GetRowCellDisplayText(i, gridCol税率), 6); mods.iTaxUnitPrice = ReturnObjectToDecimal(gridView1.GetRowCellDisplayText(i, gridCol含税单价), 6); mods.iUnitPrice = ReturnObjectToDecimal(mods.iTaxUnitPrice / (1 + mods.iTaxRate / 100), 6); mods.cexch_name = "人民币"; mods.ivouchrowno = iRow; mods.cbodymemo = gridView1.GetRowCellDisplayText(i, gridCol表体备注).ToString().Trim(); mods.cbsysbarcode = @"||putj|" + mod.ccode + @"|" + mods.ivouchrowno.ToString(); mods.dstartdate = BaseFunction.ReturnDate(DateTime.Today.ToString("yyyy-MM-dd")); DAL.PU_PriceJustDetail dals = new Purchase.DAL.PU_PriceJustDetail(); sSQL = dals.Add(mods); aList.Add(sSQL); Model.Ven_Inv_Price modInv = new Purchase.Model.Ven_Inv_Price(); modInv.cVenCode = mods.cvencode; modInv.cInvCode = mods.cinvcode; modInv.dEnableDate = ReturnObjectToDatetime(mods.dstartdate); modInv.cExch_Name = mods.cexch_name; modInv.bPromotion = 0; modInv.iSupplyType = ReturnObjectToInt(mod.iSupplyType); modInv.btaxcost = 1; modInv.iLowerLimit = 0; modInv.iUnitPrice = Convert.ToDecimal(mods.iUnitPrice); modInv.iTaxRate = Convert.ToDecimal(mods.iTaxRate); modInv.iTaxUnitPrice = Convert.ToDecimal(mods.iTaxUnitPrice); sSQL = "select max(ipriceautoid) from @u8.ven_inv_price"; long l = ReturnObjectToLong(clsSQLCommond.ExecGetScalar(sSQL)); DAL.Ven_Inv_Price dalInv = new Purchase.DAL.Ven_Inv_Price(); sSQL = dalInv.Exists(modInv); DataTable dtInvPrice = clsSQLCommond.ExecQuery(sSQL); if (ReturnObjectToInt(dtInvPrice.Rows.Count) == 0) { l += 1; modInv.ipriceautoid = l; sSQL = dalInv.Add(modInv); aList.Add(sSQL); } else { modInv.Autoid = ReturnObjectToInt(dtInvPrice.Rows[0]["autoid"]); sSQL = dalInv.Update(modInv); aList.Add(sSQL); } bHas = true; } if (!bHas) { throw new Exception("没有需要保存的行"); } sSQL = @" update @u8.VoucherHistory set cNumber='aaaaaa' Where CardNumber='PU03' and cContent is NULL "; sSQL = sSQL.Replace("aaaaaa", lCode.ToString()); aList.Add(sSQL); if (lID > 1000000000) { lID = lID - 1000000000; } if (lIDs > 1000000000) { lIDs = lIDs - 1000000000; } sSQL = "update UFSystem..UA_Identity set iFatherId = " + lID.ToString() + ",iChildId = " + lIDs + " where cAcc_Id = '" + FrameBaseFunction.ClsBaseDataInfo.sUFDataBaseName.Substring(7, 3) + "' and cVouchType = 'puprice'"; aList.Add(sSQL); if (aList.Count > 0) { clsSQLCommond.ExecSqlTran(aList); MessageBox.Show("保存成功!\n" + mod.ccode); ((DataTable)gridControl1.DataSource).Rows.Clear(); } } catch (Exception ee) { throw new Exception(ee.Message); } }