/// <summary> /// 增加一条数据 /// </summary> public string Add(Purchase.Model.PU_PriceJustDetail model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.autoid != null) { strSql1.Append("autoid,"); strSql2.Append("" + model.autoid + ","); } if (model.id != null) { strSql1.Append("id,"); strSql2.Append("" + model.id + ","); } if (model.operationtype != null) { strSql1.Append("operationtype,"); strSql2.Append("'" + model.operationtype + "',"); } if (model.ipriceid != null) { strSql1.Append("ipriceid,"); strSql2.Append("" + model.ipriceid + ","); } if (model.cvencode != null) { strSql1.Append("cvencode,"); strSql2.Append("'" + model.cvencode + "',"); } if (model.cinvcode != null) { strSql1.Append("cinvcode,"); strSql2.Append("'" + model.cinvcode + "',"); } if (model.cfree1 != null) { strSql1.Append("cfree1,"); strSql2.Append("'" + model.cfree1 + "',"); } if (model.cfree2 != null) { strSql1.Append("cfree2,"); strSql2.Append("'" + model.cfree2 + "',"); } if (model.cfree3 != null) { strSql1.Append("cfree3,"); strSql2.Append("'" + model.cfree3 + "',"); } if (model.cfree4 != null) { strSql1.Append("cfree4,"); strSql2.Append("'" + model.cfree4 + "',"); } if (model.cfree5 != null) { strSql1.Append("cfree5,"); strSql2.Append("'" + model.cfree5 + "',"); } if (model.cfree6 != null) { strSql1.Append("cfree6,"); strSql2.Append("'" + model.cfree6 + "',"); } if (model.cfree7 != null) { strSql1.Append("cfree7,"); strSql2.Append("'" + model.cfree7 + "',"); } if (model.cfree8 != null) { strSql1.Append("cfree8,"); strSql2.Append("'" + model.cfree8 + "',"); } if (model.cfree9 != null) { strSql1.Append("cfree9,"); strSql2.Append("'" + model.cfree9 + "',"); } if (model.cfree10 != null) { strSql1.Append("cfree10,"); strSql2.Append("'" + model.cfree10 + "',"); } if (model.cbodymemo != null) { strSql1.Append("cbodymemo,"); strSql2.Append("'" + model.cbodymemo + "',"); } if (model.dstartdate != null) { strSql1.Append("dstartdate,"); strSql2.Append("'" + model.dstartdate + "',"); } if (model.denddate != null) { strSql1.Append("denddate,"); strSql2.Append("'" + model.denddate + "',"); } if (model.cdefine22 != null) { strSql1.Append("cdefine22,"); strSql2.Append("'" + model.cdefine22 + "',"); } if (model.cdefine23 != null) { strSql1.Append("cdefine23,"); strSql2.Append("'" + model.cdefine23 + "',"); } if (model.cdefine24 != null) { strSql1.Append("cdefine24,"); strSql2.Append("'" + model.cdefine24 + "',"); } if (model.cdefine25 != null) { strSql1.Append("cdefine25,"); strSql2.Append("'" + model.cdefine25 + "',"); } if (model.cdefine26 != null) { strSql1.Append("cdefine26,"); strSql2.Append("" + model.cdefine26 + ","); } if (model.cdefine27 != null) { strSql1.Append("cdefine27,"); strSql2.Append("" + model.cdefine27 + ","); } if (model.cdefine28 != null) { strSql1.Append("cdefine28,"); strSql2.Append("'" + model.cdefine28 + "',"); } if (model.cdefine29 != null) { strSql1.Append("cdefine29,"); strSql2.Append("'" + model.cdefine29 + "',"); } if (model.cdefine30 != null) { strSql1.Append("cdefine30,"); strSql2.Append("'" + model.cdefine30 + "',"); } if (model.cdefine31 != null) { strSql1.Append("cdefine31,"); strSql2.Append("'" + model.cdefine31 + "',"); } if (model.cdefine32 != null) { strSql1.Append("cdefine32,"); strSql2.Append("'" + model.cdefine32 + "',"); } if (model.cdefine33 != null) { strSql1.Append("cdefine33,"); strSql2.Append("'" + model.cdefine33 + "',"); } if (model.cdefine34 != null) { strSql1.Append("cdefine34,"); strSql2.Append("" + model.cdefine34 + ","); } if (model.cdefine35 != null) { strSql1.Append("cdefine35,"); strSql2.Append("" + model.cdefine35 + ","); } if (model.cdefine36 != null) { strSql1.Append("cdefine36,"); strSql2.Append("'" + model.cdefine36 + "',"); } if (model.cdefine37 != null) { strSql1.Append("cdefine37,"); strSql2.Append("'" + model.cdefine37 + "',"); } if (model.bsales != null) { strSql1.Append("bsales,"); strSql2.Append("" + model.bsales + ","); } if (model.fminquantity != null) { strSql1.Append("fminquantity,"); strSql2.Append("" + model.fminquantity + ","); } if (model.iUnitPrice != null) { strSql1.Append("iUnitPrice,"); strSql2.Append("" + model.iUnitPrice + ","); } if (model.iTaxRate != null) { strSql1.Append("iTaxRate,"); strSql2.Append("" + model.iTaxRate + ","); } if (model.iTaxUnitPrice != null) { strSql1.Append("iTaxUnitPrice,"); strSql2.Append("" + model.iTaxUnitPrice + ","); } if (model.cexch_name != null) { strSql1.Append("cexch_name,"); strSql2.Append("'" + model.cexch_name + "',"); } if (model.cTermCode != null) { strSql1.Append("cTermCode,"); strSql2.Append("'" + model.cTermCode + "',"); } if (model.ivouchrowno != null) { strSql1.Append("ivouchrowno,"); strSql2.Append("" + model.ivouchrowno + ","); } if (model.ijusttaxprice != null) { strSql1.Append("ijusttaxprice,"); strSql2.Append("" + model.ijusttaxprice + ","); } if (model.cbsysbarcode != null) { strSql1.Append("cbsysbarcode,"); strSql2.Append("'" + model.cbsysbarcode + "',"); } if (model.bEndPriceList != null) { strSql1.Append("bEndPriceList,"); strSql2.Append("" + model.bEndPriceList + ","); } strSql.Append("insert into @u8.PU_PriceJustDetail("); 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); } }