using GThinking.N_COMPRESS; using GThinking.N_CONTROL; using GThinking.N_MISPRO; using GThinking.N_MISPRO.Caching; using GThinking.N_MISPRO.Data; using GThinking.N_MISPRO.MISPROAS; using GThinking.N_MISPRO.TableCache; using GThinking.N_MISPRO.Utility; using GThinking.N_MISPROAS; using GThinking.N_MISPROAS.Caching; using GThinking.N_MISPROAS.Services; using GThinking.N_MISPROAS.SysData; using GThinking.N_MODEL.Dialog; using GThinking.N_MODEL.Page; using GThinking.N_PUBLIC; using GThinking.N_PUBLIC2; using GThinking.N_WORKFLOW; using PdfSharp; using PdfSharp.Drawing; using PdfSharp.Drawing.Layout; using PdfSharp.Pdf; using System; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.Common; using System.Data.OleDb; using System.Drawing; using System.Drawing.Text; using System.IO; using System.Net; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Web; using System.Web.Script.Serialization; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.MobileControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml; namespace GThinking.U20261363_N_XLXSBJ { internal class BJFLCache : DbDataCacheBase { public DataTable dtXLXSBJFL; public DataView dvXLXSBJFLBy_BJFLID; public BJFLCache() : base("DBERP", "U20261363_N_XLXSBJ_XLXSBJFL", "XLXSBJFL") { } protected override void FillData(string subKey) { TDatabase db = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(db); SQL.Clear(); SQL.Add(@"select XLXSBJFL_BJFLID,XLXSBJFL_BJFLMC,XLXSBJFL_QYRQ,XLXSBJFL_TYBZ,XLXSBJFL_TYRQ,XLXSBJFL_BZ, XLXSBJFL_WHR,XLXSBJFL_WHRID,XLXSBJFL_WHSJ,XLXSBJFL_XSQYIDS,XLXSBJFL_JGBTJYSS,XLXSBJFL_MRCKC, XLXSBJFL_JGBIDS,XLXSBJFL_CPMLID,XLXSBJFL_XSJGBJJ,XLXSBJFL_XSJGBBJJCE,XLXSBJFL_BJJCLLX,XLXSBJFL_JSJJCLLX, XLXSBJFL_LJJCLLX,XLXSBJFL_TZCLHQ,XLXSBJFL_TZWLHQ,XLXSBJFL_TZJGBBJ,XLXSBJFL_TZBJBJBB,XLXSBJFL_XSTZCPBJ, XLXSBJFL_XSTZBJJE,XLXSBJFL_SDJGBCLHQFW,XLXSBJFL_BJDHQLY,XLXSBJFL_BJCPFZJS,XLXSBJFL_XHABJCSDP, XLXSBJFL_JYF,XLXSBJFL_YFWLID,XLXSBJFL_BJHYF,XLXSBJFL_MXBH,XLXSBJFL_TBJCLID,XLXSBJFL_LBJCLID, XLXSBJFL_ZLGZCLS,XLXSBJFL_BJDYBJTXS,XLXSBJFL_XJDYBJTXS,XLXSBJFL_BJQSTXS,XLXSBJFL_CPBJMRXSWS,XLXSBJFL_XTCPBJYZ, XLXSBJFL_ZDXJGS,XLXSBJFL_XSZDXJ,XLXSBJFL_ZDXJJCLLX,XLXSBJFL_JLRBJCP,XLXSBJFL_JGBBJBM,XLXSBJFL_XSCPBJXJ, XLXSBJFL_JLBJDHQ,XLXSBJFL_XHGGYMHJS,XLXSBJFL_XSXH,XLXSBJFL_BJFLTZM,XLXSBJFL_LJJCLPLTJFW,XLXSBJFL_ST, XLXSBJFL_BABZFGDY,XLXSBJFL_JMBGSYZID,XLXSBJFL_TZQCPBJGS,XLXSBJFL_XSYXJ,XLXSBJFL_XSXLBZMS,XLXSBJFL_TZBJDHQLJ, XLXSBJFL_TZBJ,XLXSBJFL_JGMBGRPID,XLXSBJFL_ZDXJJCLXX,XLXSBJFL_ZDXJJCLTXS,XLXSBJFL_BJLJJCLLX,XLXSBJFL_JSJBM,XLXSBJFL_JSJXSWS,XLXSBJFL_CJGS, XLXSBJFL_XSYZ,XLXSBJFL_XSYSCP,XLXSBJFL_ZDXJQZBJDFL,XLXSBJFL_TLJTZGXQTCL,XLXSBJFL_BJDHQLJBM,XLXSBJFL_ABJDHQJSBJ,XLXSBJFL_FJGBCPBJSBJ,XLXSBJFL_JMBGSBM, XLXSBJFL_BJBM,XLXSBJFL_XSTZZDXJ,XLXSBJFL_JSJGS,XLXSBJFL_JJZJGBXH,XLXSBJFL_YXJJCLLX,XLXSBJFL_XSFBH,XLXSBJFL_XSYLRYZID,XLXSBJFL_XSYKJJGHJ,XLXSBJFL_XSYKJJGLM,XLXSBJFL_XSLSBJ, XLXSBJFL_JGBBJZDWPID,XLXSBJFL_CPBJZDWPID,XLXSBJFL_LRBJCPWPID,XLXSBJFL_TZYLBL,XLXSBJFL_MYHSSX,XLXSBJFL_BJJCLBJRQDWCP,XLXSBJFL_LJJCLBJRQDWCP,XLXSBJFL_ZDXJJCLBJRQDWCP "); SQL.Add(" from XLXSBJFL "); SQL.Add(" where 1=1 "); SQL.ClassId = "U20261363_N_XLXSBJ.BJFLCache"; SQL.SqlId = "FillData_1"; DataSet ds = db.OpenDataSet(SQL); if (ds.Tables.Count > 0) { dtXLXSBJFL = ds.Tables[0]; dvXLXSBJFLBy_BJFLID = new DataView(dtXLXSBJFL, "", "XLXSBJFL_BJFLID", DataViewRowState.CurrentRows); } } } internal class BJFLJSLMCache : DbDataCacheBase { public DataTable dtXLXSBJFLJSLM; public DataView dvXLXSBJFLJSLMLBy_BJFLID; public BJFLJSLMCache() : base("DBERP", "U20261363_N_XLXSBJ_XLXSBJFLJSLM", "XLXSBJFLJSLM") { } protected override void FillData(string subKey) { TDatabase db = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(db); SQL.Clear(); SQL.Add(@"select XLXSBJFLJSLM_BJFLID,XLXSBJFLJSLM_JSLX,XLXSBJFLJSLM_LMLX,XLXSBJFLJSLM_LMID,XLXSBJFLJSLM_YCBZ"); SQL.Add(" from XLXSBJFLJSLM "); SQL.Add(" where 1=1 "); SQL.ClassId = "U20261363_N_XLXSBJ.BJFLJSLMCache"; SQL.SqlId = "FillData_1"; DataSet ds = db.OpenDataSet(SQL); if (ds.Tables.Count > 0) { dtXLXSBJFLJSLM = ds.Tables[0]; dvXLXSBJFLJSLMLBy_BJFLID = new DataView(dtXLXSBJFLJSLM, "", "XLXSBJFLJSLM_BJFLID", DataViewRowState.CurrentRows); } } } internal class BJFLYZCache : DbDataCacheBase { public DataTable dtXLXSBJFLYZ; public DataView dvXLXSBJFLYZBy_BJFLID; public BJFLYZCache() : base("DBERP", "U20261363_N_XLXSBJ_XLXSBJFLYZ", "XLXSBJFLYZ") { } protected override void FillData(string subKey) { TDatabase db = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(db); SQL.Clear(); SQL.Add(@"select XLXSBJFLYZ_BJFLID,XLXSBJFLYZ_YZID "); SQL.Add(" from XLXSBJFLYZ "); SQL.Add(" where 1=1 "); SQL.ClassId = "U20261363_N_XLXSBJ.BJFLYZCache"; SQL.SqlId = "FillData_1"; DataSet ds = db.OpenDataSet(SQL); if (ds.Tables.Count > 0) { dtXLXSBJFLYZ = ds.Tables[0]; dvXLXSBJFLYZBy_BJFLID = new DataView(dtXLXSBJFLYZ, "", "XLXSBJFLYZ_BJFLID", DataViewRowState.CurrentRows); } } } internal class JGBMLCache : DbDataCacheBase { public DataTable dtJGBML; public DataView dvJGBMLBy_MXBH; public DataView dvJGBMLBy_IDMX; public DataView dvJGBMLBy_JGBID; public JGBMLCache() : base("DBERP", "U20261363_N_XLXSBJ_XLXSJGB", "XLXSJGB") { } protected override void FillData(string subKey) { TDatabase db = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(db); SQL.Clear(); SQL.Add(@"select XLXSJGB_JGBID,XLXSJGB_YXQS,XLXSJGB_YXQZ,XLXSJGB_BZ,XLXSJGB_WHRID,XLXSJGB_WHR,XLXSJGB_WHSJ,XLXSJGB_MXBH, XLXSJGB_TJYS,XLXSJGB_JGBIDS,XLXSJGB_XSQYIDS,XLXSJGB_JGBMC,XLXSJGB_JGCIDS,XLXSJGB_CPMLID,XLXSJGB_BJLY,XLXSJGB_JSBLFS, XLXSJGB_JJLY,XLXSJGB_TJRGH,XLXSJGB_TJZT,XLXSJGB_TJKSSJ,XLXSJGB_TJWCSJ,XLXSJGB_JSGS,XLXSJGB_WSJGJSLY,XLXSJGB_ZZSL,XLXSJGB_MXPXFS "); SQL.Add(" from XLXSJGB "); SQL.Add(" where 1=1 "); SQL.ClassId = "U20261363_N_XLXSBJ.JGBMLCache"; SQL.SqlId = "FillData_1"; DataSet ds = db.OpenDataSet(SQL); if (ds.Tables.Count > 0) { dtJGBML = ds.Tables[0]; dvJGBMLBy_MXBH = new DataView(dtJGBML, "", "XLXSJGB_MXBH", DataViewRowState.CurrentRows); dvJGBMLBy_IDMX = new DataView(dtJGBML, "", "XLXSJGB_JGBID,XLXSJGB_MXBH", DataViewRowState.CurrentRows); dvJGBMLBy_JGBID = new DataView(dtJGBML, "", "XLXSJGB_JGBID", DataViewRowState.CurrentRows); } } } internal class JGBYZCache : DbDataCacheBase { public DataTable dtXLXSJGBYZ; public DataView dvXLXSJGBYZBy_JGBID; public JGBYZCache() : base("DBERP", "U20261363_N_XLXSBJ_XLXSJGBYZ", "XLXSJGBYZ") { } protected override void FillData(string subKey) { TDatabase db = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(db); SQL.Clear(); SQL.Add(@"select XLXSJGBYZ_JGBID,XLXSJGBYZ_YZID "); SQL.Add(" from XLXSJGBYZ "); SQL.Add(" where 1=1 "); SQL.ClassId = "U20261363_N_XLXSBJ.JGBYZCache"; SQL.SqlId = "FillData_1"; DataSet ds = db.OpenDataSet(SQL); if (ds.Tables.Count > 0) { dtXLXSJGBYZ = ds.Tables[0]; dvXLXSJGBYZBy_JGBID = new DataView(dtXLXSJGBYZ, "", "XLXSJGBYZ_JGBID", DataViewRowState.CurrentRows); } } } internal class KZXXCache : DbDataCacheBase { public DataSet dsXLXSBJKZXXSZ; public KZXXCache() : base("DBERP", "U20261363_N_XLXSBJ_XLXSBJKZXXSZ", "XLXSBJKZXXSZ") { } protected override void FillData(string subKey) { TDatabase db = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(db); SQL.Clear(); SQL.Add("select XLXSBJKZXXSZ_MC, XLXSBJKZXXSZ_SJLX, XLXSBJKZXXSZ_DYZD, isnull(XLXSBJKZXXSZ_BT,'N') as BT, XLXSBJKZXXSZ_SRFS, "); SQL.Add("XLXSBJKZXXSZ_MJLB,XLXSBJKZXXSZ_MJSQL,XLXSBJKZXXSZ_WIDTH, XLXSBJKZXXSZ_ROWS, XLXSBJKZXXSZ_JLDW,XLXSBJKZXXSZ_QSZ, "); SQL.Add("XLXSBJKZXXSZ_WHBZ,XLXSBJKZXXSZ_XSBZ,XLXSBJKZXXSZ_SYBJFLID,XLXSBJKZXXSZ_ZWCXTJ "); SQL.Add("from XLXSBJKZXXSZ "); SQL.Add("where 1=1 "); SQL.Add("order by XLXSBJKZXXSZ_BJSX, XLXSBJKZXXSZ_BH "); SQL.ClassId = "U20261363_N_XLXSBJ.KZXXCache"; SQL.SqlId = "FillData_1"; DataSet ds = db.OpenDataSet(SQL); if (ds.Tables.Count > 0) { dsXLXSBJKZXXSZ = ds; } } } internal class TZYZCache : DbDataCacheBase { public DataTable dtXLXSTZYZ; public DataView dvXLXSTZYZBy_YZID; public DataView dvYZBy_MXBHAndTJYS; public TZYZCache() : base("DBERP", "U20261363_N_XLXSBJ_XLXSTZYZ", "XLXSTZYZ") { } protected override void FillData(string subKey) { TDatabase db = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(db); SQL.Clear(); SQL.Add(@"select XLXSTZYZ_MXBH,XLXSTZYZ_YZID,XLXSTZYZ_YZMC,XLXSTZYZ_MRZ,XLXSTZYZ_XSXH,XLXSTZYZ_JJFS, XLXSTZYZ_MINC,XLXSTZYZ_TJYS,XLXSTZYZ_JGBID,XLXSTZYZ_TJYZID,XLXSTZYZ_BCYTJ,XLXSTZYZ_WPIDLIST,XLXSTZYZ_HCBZ , XLXSTZYZ_TJLX,XLXSTZYZ_TYZZYZID,XLXSTZYZ_YZZZD,XLXSTZYZ_ABJCPJYYZZ,XLXSTZYZ_ZDWPIDLIST,XLXSTZYZ_MRTJFW,XLXSTZYZ_YZZBT,XLXSTZYZ_TJMDID, XLXSTZYZ_FGQCP,XLXSTZYZ_BJCLID"); SQL.Add(" from XLXSTZYZ "); SQL.Add(" where 1=1 "); SQL.ClassId = "U20261363_N_XLXSBJ.TZYZCache"; SQL.SqlId = "FillData_1"; DataSet ds = db.OpenDataSet(SQL); if (ds.Tables.Count > 0) { dtXLXSTZYZ = ds.Tables[0]; dvXLXSTZYZBy_YZID = new DataView(dtXLXSTZYZ, "", "XLXSTZYZ_YZID", DataViewRowState.CurrentRows); dvYZBy_MXBHAndTJYS = new DataView(dtXLXSTZYZ, "", "XLXSTZYZ_MXBH,XLXSTZYZ_TJYS", DataViewRowState.CurrentRows); } } } internal class XLXSBJPZCache : DbDataCacheBase { public DataTable dtXLXSBJPZ; public DataView dvXLXSBJPZBy_MDID; public XLXSBJPZCache() : base("DBERP", "U20261363_N_XLXSBJ_XLXSBJPZ", "XLXSBJPZ") { } protected override void FillData(string subKey) { TDatabase db = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(db); SQL.Clear(); SQL.Add(@"select XLXSBJPZ_MDID,XLXSBJPZ_BJFLIDS,XLXSBJPZ_KHJSLY,XLXSBJPZ_WHR,XLXSBJPZ_WHRID,XLXSBJPZ_WHSJ,XLXSBJPZ_PFBJRBJ,XLXSBJPZ_MRCPYT,XLXSBJPZ_XSPWQD, XLXSBJPZ_XMJSLY,XLXSBJPZ_KHBT,XLXSBJPZ_XMBT,XLXSBJPZ_CLYLZJFS,XLXSBJPZ_ALMXZBJCL,XLXSBJPZ_ZDBMIDS,XLXSBJPZ_BJSLMRYZ,XLXSBJPZ_TCPBSYS,XLXSBJPZ_LCPBSYS, XLXSBJPZ_XZKHYQ,XLXSBJPZ_XZXMYQ,XLXSBJPZ_BMYSLIST,XLXSBJPZ_SQXMBAGL,XLXSBJPZ_KHTXYXZ,XLXSBJPZ_KHMCCF,XLXSBJPZ_BJY,XLXSBJPZ_KHMCXMMCCF,XLXSBJPZ_CPSLCFBL, XLXSBJPZ_XMMCCF,XLXSBJPZ_XMMCCZCF,XLXSBJPZ_XMMCCZCFGS,XLXSBJPZ_XMMCTSCZ,XLXSBJPZ_CPCF,XLXSBJPZ_CPCFBL,XLXSBJPZ_ZDZDLX,XLXSBJPZ_ZDZDYF,XLXSBJPZ_ZDQRWPID, XLXSBJPZ_CPCFGS,XLXSBJPZ_CPSLCF,XLXSBJPZ_CPSLCFGS,XLXSBJPZ_XHGGCF,XLXSBJPZ_XHGGCFBL,XLXSBJPZ_BAXMKHMCCF,XLXSBJPZ_MRZDR,XLXSBJPZ_YLZDMXTZ,XLXSBJPZ_BCYZDKH,XLXSBJPZ_BCYZDXM, XLXSBJPZ_BAXMMCCF,XLXSBJPZ_BAXMMCTXYCF,XLXSBJPZ_WBPPZXSX,XLXSBJPZ_TBJCLID,XLXSBJPZ_LBJCLID,XLXSBJPZ_LHJBJCLID,XLXSBJPZ_SJJLYBJCP,XLXSBJPZ_XSGYKH, XLXSBJPZ_MRGXLR,XLXSBJPZ_XHJQSX,XLXSBJPZ_GGJQSX,XLXSBJPZ_YXFCDJLDW,XLXSBJPZ_JLDWS,XLXSBJPZ_ZDYJLDWS,XLXSBJPZ_XSCPML,XLXSBJPZ_YXQCPWL,XLXSBJPZ_PJZLSFJRYZ, XLXSBJPZ_CPMLIDS,XLXSBJPZ_TDTGSCLID,XLXSBJPZ_LDTGSCLID,XLXSBJPZ_FJSCGS,XLXSBJPZ_APPCJSXFS,XLXSBJPZ_BJSFTJFS,XLXSBJPZ_BJXFTJFS,XLXSBJPZ_JLXJXXHZFS, XLXSBJPZ_ZDRGHS,XLXSBJPZ_MRXLBZID,XLXSBJPZ_XZMXKXX,XLXSBJPZ_YJTZRYLIST,XLXSBJPZ_PLTJKXX,XLXSBJPZ_TJBXYGHJGML,XLXSBJPZ_ZDZD,XLXSBJPZ_XSZBXX,XLXSBJPZ_CFCPBQFBZ, XLXSBJPZ_QYBJCPFZJS,XLXSBJPZ_XMKHMCXZ,XLXSBJPZ_JGBID,XLXSBJPZ_BBYSXH,XLXSBJPZ_MRJSFS,XLXSBJPZ_JGBJJFP,XLXSBJPZ_JLTZHCP,XLXSBJPZ_XJYROLEID,XLXSBJPZ_ZBLRGS, XLXSBJPZ_SJYROLEID,XLXSBJPZ_HJYROLEID,XLXSBJPZ_WXHYJGBID,XLXSBJPZ_TZBLYZID,XLXSBJPZ_KSDYZID,XLXSBJPZ_TZBLYZZLX,XLXSBJPZ_KSDYZZLX,XLXSBJPZ_JLBJWCSJ, XLXSBJPZ_TBFKZ3BB,XLXSBJPZ_FKSZDSCGCXM,XLXSBJPZ_MRDYDJ,XLXSBJPZ_JGBMRBSX,XLXSBJPZ_KSDREJCD,XLXSBJPZ_FZCHYZZ,XLXSBJPZ_THSFTGKBXH,XLXSBJPZ_BJDWQFZ,XLXSBJPZ_YFJSGS, XLXSBJPZ_YSCPCLCBGS1,XLXSBJPZ_CPCFXLBZ,XLXSBJPZ_WLQSTZBMIDS,XLXSBJPZ_WLQSTZRGHS,XLXSBJPZ_JGPSTZBMIDS,XLXSBJPZ_JGPSTZRGHS,XLXSBJPZ_YXTZCZBFZR,XLXSBJPZ_BZDPPDY,XLXSBJPZ_FKWLPPTX, XLXSBJPZ_BQKTZZDXJ,XLXSBJPZ_BQKTZBJ,XLXSBJPZ_KHLXRCF,XLXSBJPZ_LXDHCF,XLXSBJPZ_YCJGXGLM,XLXSBJPZ_CPFDCF,XLXSBJPZ_MXTMCBL,XLXSBJPZ_MXFDS,XLXSBJPZ_XYFDSCFBL,XLXSBJPZ_DYFDSCFBL, XLXSBJPZ_JGFKZD,XLXSBJPZ_KHJFKZD,XLXSBJPZ_JGBJGFKZD,XLXSBJPZ_WBBJDJXYS,XLXSBJPZ_QYBJDXTH,XLXSBJPZ_WBBJDDRYZ,XLXSBJPZ_KHMCXSBL,XLXSBJPZ_GXXSBJXDWL,XLXSBJPZ_XHZJSR,XLXSBJPZ_FZNRDRLM,XLXSBJPZ_TJGBFZBLBJ,XLXSBJPZ_ZCCF,XLXSBJPZ_CLJGXSWS "); SQL.Add(" from XLXSBJPZ "); SQL.Add(" where 1=1 "); SQL.ClassId = "U20261363_N_XLXSBJ.XLXSBJPZCache"; SQL.SqlId = "FillData_1"; DataSet ds = db.OpenDataSet(SQL); if (ds.Tables.Count > 0) { dtXLXSBJPZ = ds.Tables[0]; dvXLXSBJPZBy_MDID = new DataView(dtXLXSBJPZ, "", "XLXSBJPZ_MDID", DataViewRowState.CurrentRows); } } } internal static class ZDFXPZHelper { public const int ZDFX_MDID = 100860068; public static string GetPZColumn(int iMDID, string sColumn) { if (string.IsNullOrEmpty(sColumn) || !sColumn.StartsWith("XLXSBJPZ_")) return string.Empty; try { XLXSBJPZCache pzxxCache = new XLXSBJPZCache(); if (pzxxCache.CacheEnabled) { pzxxCache = (XLXSBJPZCache)pzxxCache.GetData(null); if (pzxxCache.dvXLXSBJPZBy_MDID != null) { foreach (DataRowView row in pzxxCache.dvXLXSBJPZBy_MDID.FindRows(iMDID)) { if (row.Row.Table.Columns.Contains(sColumn)) return row[sColumn].ToString().Trim(); } } } TDatabase db = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(db); SQL.Add(string.Format("select isnull({0},'') as PZVAL from XLXSBJPZ where XLXSBJPZ_MDID=:pMDID", sColumn)); SQL.ParamByName("pMDID").Value = iMDID; DataSet ds = db.OpenDataSet(SQL); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) return ds.Tables[0].Rows[0]["PZVAL"].ToString().Trim(); } catch { } return string.Empty; } public static bool IsGGSLCFEnabled() { return GetPZColumn(ZDFX_MDID, "XLXSBJPZ_GGSLCF") == "Y"; } public static double GetGGSLCFGS() { return CMISproConvert.StrToFloat(GetPZColumn(ZDFX_MDID, "XLXSBJPZ_GGSLCFGS"), 0); } public static double GetGGSLCFBL() { return CMISproConvert.StrToFloat(GetPZColumn(ZDFX_MDID, "XLXSBJPZ_GGSLCFBL"), 0); } } public class XLXSBJFJXX { //标签单元格 public static void createLabel(TableRow parentControl, string sDYZD, string sMC, int iRow) { TableCell CellFJXX = new TableCell(); CellFJXX.ColumnSpan = 1; if (iRow > 1) { CellFJXX.Attributes.Add("align", "right"); CellFJXX.Attributes.Add("valign", "top"); } else CellFJXX.Attributes.Add("align", "right"); //CellFJXX.Style.Add("width", "12%"); gtLabel lblMC = new gtLabel(); lblMC.ID = "lbl" + sDYZD; lblMC.Text = sMC + ":"; lblMC.Width = 100; CellFJXX.Controls.Add(lblMC); parentControl.Cells.Add(CellFJXX); } //数值框控件 public static void createNumTextBox(TableRow parentControl, string sDYZD, bool bBT, double fValue, string sJLDW) { TableCell CellFJXX = new TableCell(); CellFJXX.ColumnSpan = 1; CellFJXX.Attributes.Add("align", "left"); gtNumTextBox txtKZSZ = new gtNumTextBox(); txtKZSZ.ID = "txt" + sDYZD; txtKZSZ.DecimalPlaces = 2; txtKZSZ.Value = fValue; txtKZSZ.Width = 100; if (bBT) txtKZSZ.Tag = gtNumTextBox.DTagStates.Star; CellFJXX.Controls.Add(txtKZSZ); if (!sJLDW.Trim().Equals("")) { gtLabel lblJLDW = new gtLabel(); lblJLDW.ID = "txtJLDW" + sDYZD; lblJLDW.Text = sJLDW; CellFJXX.Controls.Add(lblJLDW); } parentControl.Cells.Add(CellFJXX); } //编辑框控件 public static void createTextBox(TableRow parentControl, string sDYZD, bool bBT, string sValue, int iRow, int iWidth, int iColumnSpan,int itotalWidth) { TableCell CellFJXX = new TableCell(); CellFJXX.ColumnSpan = 1; CellFJXX.Attributes.Add("align", "left"); gtTextBox txtKZZF = new gtTextBox(); txtKZZF.ID = "txt" + sDYZD; txtKZZF.Text = sValue; if(iRow>0) txtKZZF.MaxLength = 4000; else txtKZZF.MaxLength = 250; if (bBT) txtKZZF.Tag = gtTextBox.DTagStates.Star; if (iRow > 0) { txtKZZF.TextMode = TextBoxMode.MultiLine; txtKZZF.Rows = iRow > 6 ? 6 : iRow; if (itotalWidth > 0) { txtKZZF.Width = itotalWidth - 150; } else { txtKZZF.Style.Add("width", "90%"); } CellFJXX.ColumnSpan = iColumnSpan; } else { if (iWidth == 0) txtKZZF.Width = 120; else txtKZZF.Width = iWidth; } CellFJXX.Controls.Add(txtKZZF); parentControl.Cells.Add(CellFJXX); } //下拉单选 public static void createComboBox(TableRow parentControl, string sDYZD, bool bBT, string sValue, string sMJLB, string sMJSQL, int iWidth) { TableCell CellFJXX = new TableCell(); CellFJXX.ColumnSpan = 1; CellFJXX.Attributes.Add("align", "left"); gtComboBox cbxKZZF = new gtComboBox(); cbxKZZF.ID = "cbx" + sDYZD; if (iWidth == 0) cbxKZZF.Width = 120; else cbxKZZF.Width = iWidth; if (bBT) cbxKZZF.Tag = gtComboBox.DTagStates.Star; if (!sMJLB.Trim().Equals("")) { string[] array = sMJLB.Trim().Replace("\r\n", ",").Split(','); if (!bBT) cbxKZZF.Items.Add(new ListItem("", "")); foreach (string sItem in array) { cbxKZZF.Items.Add(new ListItem(sItem, sItem)); } cbxKZZF.ShowValue = false; } else if (!sMJSQL.Trim().Equals("")) TComboBox.SetComboBox("DBERP", cbxKZZF, sMJSQL.Trim(), !bBT); cbxKZZF.SelectedValue = sValue; CellFJXX.Controls.Add(cbxKZZF); parentControl.Cells.Add(CellFJXX); } //下拉多选 public static void createCheckedDropDownList(TableRow parentControl, string sDYZD, bool bBT, string sValue, string sMJLB, string sMJSQL, int iWidth) { TableCell CellFJXX = new TableCell(); CellFJXX.ColumnSpan = 1; CellFJXX.Attributes.Add("align", "left"); gtCheckedDropDownList cbxKZZF = new gtCheckedDropDownList(); cbxKZZF.ID = "cbx" + sDYZD; if (iWidth == 0) cbxKZZF.Width = 120; else cbxKZZF.Width = iWidth; if (bBT) cbxKZZF.Tag = gtCheckedDropDownList.DTagStates.Star; if (!sMJLB.Trim().Equals("")) { string[] array = sMJLB.Trim().Replace("\r\n", ",").Split(','); foreach (string sItem in array) { cbxKZZF.Items.Add(new ListItem(sItem, sItem)); } cbxKZZF.ShowValue = false; } else if (!sMJSQL.Trim().Equals("")) { TDatabase dberp = TContextDatabases.GetDatabase("DBERP"); TSQL sSQL = new TSQL(dberp); sSQL.Clear(); sSQL.Add(sMJSQL); DataSet dsSQL = dberp.OpenDataSet(sSQL); for (int j = 0; j < dsSQL.Tables[0].Rows.Count; j++) { cbxKZZF.Items.Add(new ListItem(dsSQL.Tables[0].Rows[j][1].ToString().Trim(), dsSQL.Tables[0].Rows[j][0].ToString().Trim())); } } cbxKZZF.SelectedValue = sValue; CellFJXX.Controls.Add(cbxKZZF); parentControl.Cells.Add(CellFJXX); } //日期控件 public static void createDateTimeTextBox(TableRow parentControl, string sDYZD, bool bBT, string sValue) { TableCell CellFJXX = new TableCell(); CellFJXX.ColumnSpan = 1; CellFJXX.Attributes.Add("align", "left"); gtDateTimeTextBox datKZRQ = new gtDateTimeTextBox(); datKZRQ.ID = "dat" + sDYZD; datKZRQ.Width = 72; if (bBT) datKZRQ.Tag = gtDateTimeTextBox.DTagStates.Star; datKZRQ.Text = CMISproConvert.ConvertDate(sValue); CellFJXX.Controls.Add(datKZRQ); parentControl.Cells.Add(CellFJXX); } //空白单元格 public static void createTableCell(TableRow parentControl, int iColumnSpan, int irow) { TableCell CellFJXX = new TableCell(); CellFJXX.ColumnSpan = iColumnSpan; gtLabel lblMC = new gtLabel(); lblMC.ID = "lblKZXXKBG" + irow.ToString().Trim(); lblMC.Text = ""; lblMC.Width = 100 * iColumnSpan; CellFJXX.Controls.Add(lblMC); parentControl.Cells.Add(CellFJXX); } public static void UpdateLBXSFJXX(string sBJDID) { TDatabase dberp = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(dberp); SQL.Clear(); SQL.Add(" select XLXSBJKZXXSZ_DYZD,XLXSBJKZXXSZ_MC,XLXSBJKZXXSZ_SJLX,XLXSBJKZXXSZ_SRFS,XLXSBJKZXXSZ_MJLB,XLXSBJKZXXSZ_MJSQL "); SQL.Add(" from XLXSBJKZXXSZ where isnull(XLXSBJKZXXSZ_LBXS,'N') = 'Y' order by XLXSBJKZXXSZ_BJSX,XLXSBJKZXXSZ_BH "); DataSet ds = dberp.OpenDataSet(SQL); if (ds.Tables[0].Rows.Count > 0) { string sLBXSFJXX = ""; SQL.Clear(); SQL.Add(" select XLXSBJKZXX_BJDID "); for (int i = 1; i <= 5; i++) { SQL.Add(" ,XLXSBJKZXX_KZSZ" + i.ToString().PadLeft(2, '0')); } for (int j = 1; j <= 10; j++) { SQL.Add(" ,XLXSBJKZXX_KZZF" + j.ToString().PadLeft(2, '0')); } for (int k = 1; k <= 5; k++) { SQL.Add(" ,XLXSBJKZXX_KZRQ" + k.ToString().PadLeft(2, '0')); } for (int l = 1; l <= 5; l++) { SQL.Add(" ,XLXSBJKZXX_KZWB" + l.ToString().PadLeft(2, '0')); } SQL.Add(" from XLXSBJKZXX where XLXSBJKZXX_BJDID = :pBJDID "); SQL.ParamByName("pBJDID").Value = sBJDID; DataSet dsKZXX = dberp.OpenDataSet(SQL); if (dsKZXX.Tables[0].Rows.Count > 0) { foreach (DataRow trow in ds.Tables[0].Rows) { if (!sLBXSFJXX.Equals("")) sLBXSFJXX += "\r\n"; string sDYZD = trow["XLXSBJKZXXSZ_DYZD"].ToString().Trim(); string sMC = trow["XLXSBJKZXXSZ_MC"].ToString().Trim(); string sSJLX = trow["XLXSBJKZXXSZ_SJLX"].ToString().Trim(); string sSRFS = trow["XLXSBJKZXXSZ_SRFS"].ToString().Trim(); string sValues = dsKZXX.Tables[0].Rows[0]["XLXSBJKZXX_" + sDYZD].ToString().Trim(); if (sSJLX.Equals("A")) { if (sValues.Equals("") || sValues.Equals("0")) sValues = ""; else sValues = strPadRight(sValues, 2); } else if (sSJLX.Equals("B")) { if (!sSRFS.Equals("A")) { string sMJLB = trow["XLXSBJKZXXSZ_MJLB"].ToString().Trim(); if (sMJLB.Equals("")) { string sMJSQL = trow["XLXSBJKZXXSZ_MJSQL"].ToString().Trim(); SQL.Clear(); SQL.Add(sMJSQL); DataSet dsMJ = dberp.OpenDataSet(SQL); if (dsMJ.Tables[0].Rows.Count > 0) { string sMJNAME = ""; string sMJValue = "," + sValues + ","; foreach (DataRow mjROW in dsMJ.Tables[0].Rows) { string sMJID = mjROW[0].ToString().Trim(); string sMJMC = mjROW[1].ToString().Trim(); if (sMJValue.Contains("," + sMJID + ",")) { if (!sMJNAME.Equals("")) sMJNAME += ","; sMJNAME += sMJMC; } } sValues = sMJNAME; } } } } else if (sSJLX.Equals("C")) { if (!sValues.Equals("")) sValues = CMISproConvert.StrToDateTime(sValues).ToShortDateString().Trim(); } sLBXSFJXX += sMC + ":" + sValues; } } SQL.Clear(); SQL.Add(" update XLXSBJD set XLXSBJD_LBXSFJXX = :pLBXSFJXX where XLXSBJD_BJDID = :pBJDID "); SQL.ParamByName("pLBXSFJXX").Value = sLBXSFJXX; SQL.ParamByName("pBJDID").Value = sBJDID; dberp.ExecSQL(SQL); } } public static string strPadRight(string s, int x) { string str = s; if (str.Split('.').Length == 2) { str = str.Split('.')[0] + "." + str.Split('.')[1].PadRight(x, '0'); } else { string tmp = "0"; if (x > 0) { tmp = tmp.PadRight(x, '0'); str = str + "." + tmp; } } return str; } } public class XLBJD_YZZCheck { /// /// /// /// /// /// /// /// /// /// 值域:exists|校验是否存在、selectBJDXH|查出短米点数不相等的明细序号、selectBJCP|查询短米点数不相等的报价产品小计行 public static void GetBJSLTJYS_SQL(TSQL SQL, string sBJDID, string sBJFLID, string sTJYS, string sYZID, string sBJU003, string useFor) { string sBJU003JSDW = XLBJDUtils.GetsJSDW(sBJU003, sBJU003); Dictionary dicLenJLDWTD = XLBJDUtils.GetLenJLDWTD(); if (sTJYS.Equals("2")) { if (useFor.Equals("exists")) { SQL.Add(" select top 1 tmp.XLXSBJDMX_XH"); } else if (useFor.Equals("selectBJDXH")) { SQL.Add(" select tmp.XLXSBJDMX_XH as BJDXH,"); SQL.Add(" (case when isnull(b.YZID,' ')<>' ' then isnull(b.YZZ,0) when isnull(a.YZID,' ')<>' ' then isnull(a.YZZ,0)"); SQL.Add(" else 0.0 end)"); SQL.Add(" *(case when isnull(XLXSBJDYZZ2BSY1_CPYT, ' ')=' ' then 1.0 else 0.0 end) as YZZ"); } else if (useFor.Equals("selectBJCP")) {//研发自测:王威 2025/09/12 01:21:15 SQL.Add(" select distinct upper(tmp.XLXSBJDMX_XLXHID) as XLXHID,tmp.XLXSBJDMX_XLGGID as XLGGID,tmp.XLXSBJDMX_XLBZID as XLBZID,isnull(tmp.XLXSBJDMX_DYDJID,' ') as DYDJID,' ' as XLXSBJDMX_XLYSID,"); for (int k = 1; k <= 20; k++) { if (sYZID.Equals("BJ" + k.ToString().PadLeft(2, '0'))) { SQL.Add(" (case when isnull(b.YZID,' ')<>' ' then isnull(b.YZZ,0) when isnull(a.YZID,' ')<>' ' then isnull(a.YZZ,0)"); SQL.Add(" else 0.0 end)"); SQL.Add(string.Format("*(case when isnull(XLXSBJDYZZ2BSY1_CPYT, ' ')=' ' then 1.0 else 0.0 end) as YZZ{0},", k.ToString().PadLeft(2, '0'))); } else SQL.Add(string.Format(" 0.0 as YZZ{0},", k.ToString().PadLeft(2, '0'))); } SQL.Add(string.Format(" BJD.sumBJSL,'{0}' as JLDW,'{1}' as YZID ", sBJU003, sYZID)); } SQL.Add(" from XLXSBJDMX tmp"); SQL.Add(" left join XLXSBJDYZZ0 on XLXSBJDYZZ0_BJDID=tmp.XLXSBJDMX_BJDID and XLXSBJDYZZ0_XH=tmp.XLXSBJDMX_XH"); SQL.Add(" left join "); SQL.Add(" (select XLXSBJDMX_BJDID as BJDID,upper(XLXSBJDMX_XLXHID)as XLXHID,XLXSBJDMX_XLGGID as XLGGID,XLXSBJDMX_XLBZID as XLBZID,isnull(XLXSBJDMX_DYDJID,' ') as DYDJID,"); if (sBJU003JSDW.Equals("M")) { SQL.Add(" sum(case when XLXSBJDMX_JLDW in('Km','千米')then 1000*XLXSBJDMX_BJSL "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when XLXSBJDMX_JLDW='{0}' then {1}*XLXSBJDMX_BJSL ", sKey, dicLenJLDWTD[sKey])); } SQL.Add(" else XLXSBJDMX_BJSL end)as sumBJSL"); } else if (sBJU003JSDW.Equals("Km")) { SQL.Add(" sum(case when XLXSBJDMX_JLDW in('M','米')then 0.001*XLXSBJDMX_BJSL "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when XLXSBJDMX_JLDW='{0}' then 0.001*{1}*XLXSBJDMX_BJSL ", sKey, dicLenJLDWTD[sKey])); } SQL.Add(" else XLXSBJDMX_BJSL end)as sumBJSL"); } //取报价单明细因子值之和 SQL.Add(string.Format(" ,sum(XLXSBJDYZZ0_YZZ{0}) as sumYZZ", sYZID.Replace("BJ", ""))); SQL.Add(" from XLXSBJDMX"); //关联报价单明细因子值 SQL.Add(" left join XLXSBJDYZZ0 on XLXSBJDYZZ0_BJDID= XLXSBJDMX_BJDID and XLXSBJDYZZ0_XH= XLXSBJDMX_XH "); SQL.Add(string.Format(" where XLXSBJDMX_BJDID='{0}'", sBJDID)); SQL.Add(" and (XLXSBJDMX_JLDW in('Km','M','千米','米')"); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" or XLXSBJDMX_JLDW='{0}'", sKey)); } SQL.Add(" )"); SQL.Add(" group by XLXSBJDMX_BJDID,upper(XLXSBJDMX_XLXHID),XLXSBJDMX_XLGGID,XLXSBJDMX_XLBZID,isnull(XLXSBJDMX_DYDJID,' ')"); SQL.Add(" )BJD on BJD.XLXHID=upper(tmp.XLXSBJDMX_XLXHID) and BJD.XLGGID=tmp.XLXSBJDMX_XLGGID and BJD.XLBZID=tmp.XLXSBJDMX_XLBZID and BJD.DYDJID=isnull(tmp.XLXSBJDMX_DYDJID,' ')"); SQL.Add(" left join XLXHB on XLXHB_XLXHID=XLXHID "); SQL.Add(" left join XLXSBJDYZZ2BSY1 on XLXSBJDYZZ2BSY1_CPYT= isnull(XLXHB_CPYT,' ')"); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZ2_DTCLID as DTCLID,XLXSBJDYZZ2_YZID as YZID,XLXSBJDYZZ2_YZZ as YZZ,DYDJB.XLDYDJB_DYDJID,"); SQL.Add(" XLXSBJDYZZ2_BJSLXX,XLXSBJDYZZ2_BJSLSX"); SQL.Add(" from XLXSBJDYZZ2,XLXSTZYZ,"); SQL.Add(" ("); SQL.Add(" select (case when XLDYDJB_XXLXDY>XLDYDJB_XXXXDY then XLDYDJB_XXLXDY else XLDYDJB_XXXXDY end)"); SQL.Add(" *(case XLDYDJB_DYJLDW when 'V' then 1 else 1000 end) as DY,XLDYDJB_DYDJID "); SQL.Add(" from XLDYDJB"); SQL.Add(" where 1=1"); SQL.Add(" ) DYDJB "); SQL.Add(" where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='2' and XLXSBJDYZZ2_JGBID=XLXSTZYZ_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZ2_YZID"); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSTZYZ_YZID)", sBJFLID)); SQL.Add(" and XLXSBJDYZZ2_DYXX<=DY and ((XLXSBJDYZZ2_DYSX<>0 and XLXSBJDYZZ2_DYSX>DY) or XLXSBJDYZZ2_DYSX=0)"); SQL.Add(string.Format(" and XLXSBJDYZZ2_YZID='{0}'", sYZID)); SQL.Add(" and XLXSBJDYZZ2_DTCLID=' '"); SQL.Add(" ) a on a.XLDYDJB_DYDJID = DYDJID "); SQL.Add(" and a.XLXSBJDYZZ2_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and ((a.XLXSBJDYZZ2_BJSLSX<>0 and a.XLXSBJDYZZ2_BJSLSX>BJD.sumBJSL) or a.XLXSBJDYZZ2_BJSLSX=0) "); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZ2_DTCLID as DTCLID,XLXSBJDYZZ2_YZID as YZID,XLXSBJDYZZ2_YZZ as YZZ,DYDJB.XLDYDJB_DYDJID,"); SQL.Add(" XLXSBJDYZZ2_BJSLXX,XLXSBJDYZZ2_BJSLSX"); SQL.Add(" from XLXSBJDYZZ2,XLXSTZYZ,"); SQL.Add(" ("); SQL.Add(" select (case when XLDYDJB_XXLXDY>XLDYDJB_XXXXDY then XLDYDJB_XXLXDY else XLDYDJB_XXXXDY end)"); SQL.Add(" *(case XLDYDJB_DYJLDW when 'V' then 1 else 1000 end) as DY,XLDYDJB_DYDJID "); SQL.Add(" from XLDYDJB"); SQL.Add(" where 1=1"); SQL.Add(" ) DYDJB "); SQL.Add(" where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='2' and XLXSBJDYZZ2_JGBID=XLXSTZYZ_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZ2_YZID"); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSTZYZ_YZID)", sBJFLID)); SQL.Add(" and XLXSBJDYZZ2_DYXX<=DY and ((XLXSBJDYZZ2_DYSX<>0 and XLXSBJDYZZ2_DYSX>DY) or XLXSBJDYZZ2_DYSX=0)"); SQL.Add(string.Format(" and XLXSBJDYZZ2_YZID='{0}'", sYZID)); SQL.Add(" and XLXSBJDYZZ2_DTCLID<>' '"); SQL.Add(" ) b on b.DTCLID=isnull(XLXHB_DTCLID,' ') and b.XLDYDJB_DYDJID = DYDJID"); SQL.Add(" and b.XLXSBJDYZZ2_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and ((b.XLXSBJDYZZ2_BJSLSX<>0 and b.XLXSBJDYZZ2_BJSLSX>BJD.sumBJSL) or b.XLXSBJDYZZ2_BJSLSX=0)"); SQL.Add(string.Format(" where tmp.XLXSBJDMX_BJDID='{0}'", sBJDID)); SQL.Add(" and (case when isnull(b.YZID,' ')<>' ' then isnull(b.YZZ,0) when isnull(a.YZID,' ')<>' ' then isnull(a.YZZ,0)"); SQL.Add(" else 0.0 end)"); SQL.Add(string.Format("*(case when isnull(XLXSBJDYZZ2BSY1_CPYT, ' ')=' ' then 1.0 else 0.0 end)<>XLXSBJDYZZ0_YZZ{0}", sYZID.Replace("BJ", ""))); SQL.Add(" and BJD.sumYZZ > 0 "); } else if (sTJYS.Equals("3")) { if (useFor.Equals("exists")) { SQL.Add(" select top 1 tmp.XLXSBJDMX_XH"); } else if (useFor.Equals("selectBJDXH")) { SQL.Add(" select tmp.XLXSBJDMX_XH as BJDXH,"); SQL.Add(" (case when isnull(d.YZID,' ')<>' ' then isnull(d.YZZ,0)when isnull(c.YZID,' ')<>' ' then isnull(c.YZZ,0)"); SQL.Add(" when isnull(b.YZID,' ')<>' ' then isnull(b.YZZ,0)when isnull(a.YZID,' ')<>' ' then isnull(a.YZZ,0)"); SQL.Add(" else 0.0 end)"); SQL.Add(" *(case when isnull(XLXSBJDYZZ3BSY1_CPYT, ' ')=' ' then 1.0 else 0.0 end)*(case when isnull(XLXSBJDYZZ3BSY2_XLXHID, ' ')=' ' then 1.0 else 0.0 end)*(case when isnull(XLXSBJDYZZ3BSY3_XLJBXHID, ' ')=' ' then 1.0 else 0.0 end) as YZZ"); } else if (useFor.Equals("selectBJCP")) {//研发自测:王威 2025/09/12 01:21:15 SQL.Add(" select distinct upper(tmp.XLXSBJDMX_XLXHID) as XLXHID,tmp.XLXSBJDMX_XLGGID as XLGGID,tmp.XLXSBJDMX_XLBZID as XLBZID,isnull(tmp.XLXSBJDMX_DYDJID,' ') as DYDJID,' ' as XLXSBJDMX_XLYSID,"); for (int k = 1; k <= 20; k++) { if (sYZID.Equals("BJ" + k.ToString().PadLeft(2, '0'))) { SQL.Add(" (case when isnull(d.YZID,' ')<>' ' then isnull(d.YZZ,0) when isnull(c.YZID,' ')<>' ' then isnull(c.YZZ,0)"); SQL.Add(" when isnull(b.YZID,' ')<>' ' then isnull(b.YZZ,0) when isnull(a.YZID,' ')<>' ' then isnull(a.YZZ,0)"); SQL.Add(" else 0.0 end)"); SQL.Add(string.Format("*(case when isnull(XLXSBJDYZZ3BSY1_CPYT, ' ')=' ' then 1.0 else 0.0 end)*(case when isnull(XLXSBJDYZZ3BSY2_XLXHID, ' ')=' ' then 1.0 else 0.0 end)*(case when isnull(XLXSBJDYZZ3BSY3_XLJBXHID, ' ')=' ' then 1.0 else 0.0 end) as YZZ{0},", k.ToString().PadLeft(2, '0'))); } else SQL.Add(string.Format(" 0.0 as YZZ{0},", k.ToString().PadLeft(2, '0'))); } SQL.Add(string.Format(" BJD.sumBJSL,'{0}' as JLDW,'{1}' as YZID ", sBJU003, sYZID)); } SQL.Add(" from XLXSBJDMX tmp"); SQL.Add(" left join XLXSBJDYZZ0 on XLXSBJDYZZ0_BJDID=tmp.XLXSBJDMX_BJDID and XLXSBJDYZZ0_XH=tmp.XLXSBJDMX_XH"); SQL.Add(" left join "); SQL.Add(" (select XLXSBJDMX_BJDID as BJDID,upper(XLXSBJDMX_XLXHID)as XLXHID,XLXSBJDMX_XLGGID as XLGGID,XLXSBJDMX_XLBZID as XLBZID,isnull(XLXSBJDMX_DYDJID,' ')as DYDJID,"); if (sBJU003JSDW.Equals("M")) { SQL.Add(" sum(case when XLXSBJDMX_JLDW in('Km','千米')then 1000*XLXSBJDMX_BJSL "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when XLXSBJDMX_JLDW='{0}' then {1}*XLXSBJDMX_BJSL ", sKey, dicLenJLDWTD[sKey])); } SQL.Add(" else XLXSBJDMX_BJSL end)as sumBJSL"); } else if (sBJU003JSDW.Equals("Km")) { SQL.Add(" sum(case when XLXSBJDMX_JLDW in('M','米') then 0.001*XLXSBJDMX_BJSL "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when XLXSBJDMX_JLDW='{0}' then 0.001*{1}*XLXSBJDMX_BJSL ", sKey, dicLenJLDWTD[sKey])); } SQL.Add(" else XLXSBJDMX_BJSL end) as sumBJSL"); } //取报价单明细因子值之和 SQL.Add(string.Format(" ,sum(XLXSBJDYZZ0_YZZ{0}) as sumYZZ", sYZID.Replace("BJ", ""))); SQL.Add(" from XLXSBJDMX"); //关联报价单明细因子值 SQL.Add(" left join XLXSBJDYZZ0 on XLXSBJDYZZ0_BJDID= XLXSBJDMX_BJDID and XLXSBJDYZZ0_XH= XLXSBJDMX_XH "); SQL.Add(string.Format(" where XLXSBJDMX_BJDID='{0}'", sBJDID)); SQL.Add(" and (XLXSBJDMX_JLDW in('Km','M','千米','米')"); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" or XLXSBJDMX_JLDW='{0}'", sKey)); } SQL.Add(" )"); SQL.Add(" group by XLXSBJDMX_BJDID,upper(XLXSBJDMX_XLXHID),XLXSBJDMX_XLGGID,XLXSBJDMX_XLBZID,isnull(XLXSBJDMX_DYDJID,' ')"); SQL.Add(" )BJD on BJD.XLXHID=upper(tmp.XLXSBJDMX_XLXHID) and BJD.XLGGID=tmp.XLXSBJDMX_XLGGID and BJD.XLBZID=tmp.XLXSBJDMX_XLBZID and BJD.DYDJID=isnull(tmp.XLXSBJDMX_DYDJID,' ')"); SQL.Add(" left join XLXHB on XLXHB_XLXHID=XLXHID "); SQL.Add(" left join XLDYDJB on XLDYDJB_DYDJID=DYDJID"); SQL.Add(" left join XLXSBJDYZZ3BSY1 on XLXSBJDYZZ3BSY1_CPYT= isnull(XLXHB_CPYT,' ')"); SQL.Add(" left join XLXSBJDYZZ3BSY2 on XLXSBJDYZZ3BSY2_XLXHID= XLXSBJDMX_XLXHID and XLXSBJDYZZ3BSY2_XLGGID= XLXSBJDMX_XLGGID and XLXSBJDYZZ3BSY2_XLBZID= XLXSBJDMX_XLBZID and XLXSBJDYZZ3BSY2_DYDJID= XLXSBJDMX_DYDJID "); SQL.Add(" left join XLXSBJDYZZ3BSY3 on XLXSBJDYZZ3BSY3_XLJBXHID= isnull(XLXHB_XLJBXHID,' ')"); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZ3_CPYT as CPYT,XLXSBJDYZZ3_DYDJFL as DYDJFL,XLXSBJDYZZ3_YZID as YZID,XLXSBJDYZZ3_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZ3_BJSLXX,XLXSBJDYZZ3_BJSLSX"); SQL.Add(" from XLXSBJDYZZ3,XLXSTZYZ"); SQL.Add(" where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='3' and XLXSBJDYZZ3_JGBID=XLXSTZYZ_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZ3_YZID"); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSTZYZ_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZ3_YZID='{0}'", sYZID)); SQL.Add(" and XLXSBJDYZZ3_CPYT=' ' and XLXSBJDYZZ3_DYDJFL=' '"); SQL.Add(" )a on "); SQL.Add(" a.XLXSBJDYZZ3_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and((a.XLXSBJDYZZ3_BJSLSX<>0 and a.XLXSBJDYZZ3_BJSLSX>BJD.sumBJSL)or a.XLXSBJDYZZ3_BJSLSX=0) "); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZ3_CPYT as CPYT,XLXSBJDYZZ3_DYDJFL as DYDJFL,XLXSBJDYZZ3_YZID as YZID,XLXSBJDYZZ3_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZ3_BJSLXX,XLXSBJDYZZ3_BJSLSX"); SQL.Add(" from XLXSBJDYZZ3,XLXSTZYZ"); SQL.Add(" where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='3' and XLXSBJDYZZ3_JGBID=XLXSTZYZ_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZ3_YZID"); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSTZYZ_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZ3_YZID='{0}'", sYZID)); SQL.Add(" and XLXSBJDYZZ3_CPYT=' ' and XLXSBJDYZZ3_DYDJFL<>' '"); SQL.Add(" )b on b.DYDJFL=XLDYDJB_DYDJFL"); SQL.Add(" and b.XLXSBJDYZZ3_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and((b.XLXSBJDYZZ3_BJSLSX<>0 and b.XLXSBJDYZZ3_BJSLSX>BJD.sumBJSL)or b.XLXSBJDYZZ3_BJSLSX=0)"); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZ3_CPYT as CPYT,XLXSBJDYZZ3_DYDJFL as DYDJFL,XLXSBJDYZZ3_YZID as YZID,XLXSBJDYZZ3_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZ3_BJSLXX,XLXSBJDYZZ3_BJSLSX"); SQL.Add(" from XLXSBJDYZZ3,XLXSTZYZ"); SQL.Add(" where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='3' and XLXSBJDYZZ3_JGBID=XLXSTZYZ_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZ3_YZID"); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSTZYZ_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZ3_YZID='{0}'", sYZID)); SQL.Add(" and XLXSBJDYZZ3_CPYT<>' ' and XLXSBJDYZZ3_DYDJFL=' '"); SQL.Add(" )c on c.CPYT=XLXHB_CPYT"); SQL.Add(" and c.XLXSBJDYZZ3_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and((c.XLXSBJDYZZ3_BJSLSX<>0 and c.XLXSBJDYZZ3_BJSLSX>BJD.sumBJSL)or c.XLXSBJDYZZ3_BJSLSX=0)"); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZ3_CPYT as CPYT,XLXSBJDYZZ3_DYDJFL as DYDJFL,XLXSBJDYZZ3_YZID as YZID,XLXSBJDYZZ3_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZ3_BJSLXX,XLXSBJDYZZ3_BJSLSX"); SQL.Add(" from XLXSBJDYZZ3,XLXSTZYZ"); SQL.Add(" where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='3' and XLXSBJDYZZ3_JGBID=XLXSTZYZ_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZ3_YZID"); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSTZYZ_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZ3_YZID='{0}'", sYZID)); SQL.Add(" and XLXSBJDYZZ3_CPYT<>' ' and XLXSBJDYZZ3_DYDJFL<>' '"); SQL.Add(" )d on d.CPYT=XLXHB_CPYT and d.DYDJFL=XLDYDJB_DYDJFL"); SQL.Add(" and d.XLXSBJDYZZ3_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and((d.XLXSBJDYZZ3_BJSLSX<>0 and d.XLXSBJDYZZ3_BJSLSX>BJD.sumBJSL)or d.XLXSBJDYZZ3_BJSLSX=0)"); SQL.Add(string.Format(" where tmp.XLXSBJDMX_BJDID='{0}'", sBJDID)); SQL.Add(" and (case when isnull(d.YZID,' ')<>' ' then isnull(d.YZZ,0)when isnull(c.YZID,' ')<>' ' then isnull(c.YZZ,0)"); SQL.Add(" when isnull(b.YZID,' ')<>' ' then isnull(b.YZZ,0)when isnull(a.YZID,' ')<>' ' then isnull(a.YZZ,0)"); SQL.Add(" else 0.0 end)"); SQL.Add(string.Format("*(case when isnull(XLXSBJDYZZ3BSY1_CPYT, ' ')=' ' then 1.0 else 0.0 end)*(case when isnull(XLXSBJDYZZ3BSY2_XLXHID, ' ')=' ' then 1.0 else 0.0 end)*(case when isnull(XLXSBJDYZZ3BSY3_XLJBXHID, ' ')=' ' then 1.0 else 0.0 end)<>XLXSBJDYZZ0_YZZ{0}", sYZID.Replace("BJ", ""))); SQL.Add(" and BJD.sumYZZ > 0 "); } else if (sTJYS.Equals("6")) { if (useFor.Equals("exists")) { SQL.Add(" select top 1 tmp.XLXSBJDMX_XH"); } else if (useFor.Equals("selectBJDXH")) { SQL.Add(" select tmp.XLXSBJDMX_XH as BJDXH,"); SQL.Add(" (case when isnull(a.YZID,' ')<>' ' then isnull(a.YZZ,0)*100.0/BJD.sumBJSL"); SQL.Add(" else 0.0 end) as YZZ"); } else if (useFor.Equals("selectBJCP")) {//研发自测:王威 2025/09/12 01:21:15 SQL.Add(" select distinct upper(tmp.XLXSBJDMX_XLXHID) as XLXHID,tmp.XLXSBJDMX_XLGGID as XLGGID,tmp.XLXSBJDMX_XLBZID as XLBZID,isnull(tmp.XLXSBJDMX_DYDJID,' ') as DYDJID,' ' as XLXSBJDMX_XLYSID,"); for (int k = 1; k <= 20; k++) { if (sYZID.Equals("BJ" + k.ToString().PadLeft(2, '0'))) { SQL.Add(" (case when isnull(a.YZID,' ')<>' ' then isnull(a.YZZ,0)*100.0/BJD.sumBJSL"); SQL.Add(string.Format(" else 0.0 end) as YZZ{0},", k.ToString().PadLeft(2, '0'))); } else SQL.Add(string.Format(" 0.0 as YZZ{0},", k.ToString().PadLeft(2, '0'))); } SQL.Add(string.Format(" BJD.sumBJSL,'{0}' as JLDW,'{1}' as YZID ", sBJU003, sYZID)); } SQL.Add(" from XLXSBJDMX tmp"); SQL.Add(" left join XLXSBJDYZZ0 on XLXSBJDYZZ0_BJDID=tmp.XLXSBJDMX_BJDID and XLXSBJDYZZ0_XH=tmp.XLXSBJDMX_XH"); SQL.Add(" left join "); SQL.Add(" (select XLXSBJDMX_BJDID as BJDID,upper(XLXSBJDMX_XLXHID)as XLXHID,XLXSBJDMX_XLGGID as XLGGID,XLXSBJDMX_XLBZID as XLBZID,isnull(XLXSBJDMX_DYDJID,' ')as DYDJID,"); if (sBJU003JSDW.Equals("M")) { SQL.Add(" sum(case when XLXSBJDMX_JLDW in('Km','千米')then 1000*XLXSBJDMX_BJSL "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when XLXSBJDMX_JLDW='{0}' then {1}*XLXSBJDMX_BJSL ", sKey, dicLenJLDWTD[sKey])); } SQL.Add(" else XLXSBJDMX_BJSL end)as sumBJSL"); } else if (sBJU003JSDW.Equals("Km")) { SQL.Add(" sum(case when XLXSBJDMX_JLDW in('M','米') then 0.001*XLXSBJDMX_BJSL "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when XLXSBJDMX_JLDW='{0}' then 0.001*{1}*XLXSBJDMX_BJSL ", sKey, dicLenJLDWTD[sKey])); } SQL.Add(" else XLXSBJDMX_BJSL end) as sumBJSL"); } //取报价单明细因子值之和 SQL.Add(string.Format(" ,sum(XLXSBJDYZZ0_YZZ{0}) as sumYZZ", sYZID.Replace("BJ", ""))); SQL.Add(" from XLXSBJDMX"); //关联报价单明细因子值 SQL.Add(" left join XLXSBJDYZZ0 on XLXSBJDYZZ0_BJDID= XLXSBJDMX_BJDID and XLXSBJDYZZ0_XH= XLXSBJDMX_XH "); SQL.Add(string.Format(" where XLXSBJDMX_BJDID='{0}'", sBJDID)); SQL.Add(" and (XLXSBJDMX_JLDW in('Km','M','千米','米')"); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" or XLXSBJDMX_JLDW='{0}'", sKey)); } SQL.Add(" )"); SQL.Add(" and XLXSBJDMX_BJSL<>0");//因素6需要限制报价数量不为0 SQL.Add(" group by XLXSBJDMX_BJDID,upper(XLXSBJDMX_XLXHID),XLXSBJDMX_XLGGID,XLXSBJDMX_XLBZID,isnull(XLXSBJDMX_DYDJID,' ')"); SQL.Add(" )BJD on BJD.XLXHID=upper(tmp.XLXSBJDMX_XLXHID) and BJD.XLGGID=tmp.XLXSBJDMX_XLGGID and BJD.XLBZID=tmp.XLXSBJDMX_XLBZID and BJD.DYDJID=isnull(tmp.XLXSBJDMX_DYDJID,' ')"); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZ6_YZID as YZID,XLXSBJDYZZ6_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZ6_BJSLXX,XLXSBJDYZZ6_BJSLSX"); SQL.Add(" from XLXSBJDYZZ6,XLXSTZYZ"); SQL.Add(" where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='6' and XLXSBJDYZZ6_JGBID=XLXSTZYZ_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZ6_YZID"); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSTZYZ_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZ6_YZID='{0}'", sYZID)); SQL.Add(" ) a on "); SQL.Add(" a.XLXSBJDYZZ6_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and ((a.XLXSBJDYZZ6_BJSLSX<>0 and a.XLXSBJDYZZ6_BJSLSX>BJD.sumBJSL) or a.XLXSBJDYZZ6_BJSLSX=0) "); SQL.Add(string.Format(" where tmp.XLXSBJDMX_BJDID='{0}'", sBJDID)); SQL.Add(" and (case when isnull(a.YZID,' ')<>' ' then RoundFix(isnull(a.YZZ,0)*100.0/BJD.sumBJSL,6)"); SQL.Add(string.Format(" else 0.0 end)<>RoundFix(XLXSBJDYZZ0_YZZ{0},6)", sYZID.Replace("BJ", ""))); SQL.Add(" and BJD.sumYZZ > 0 "); } else if (sTJYS.Equals("E")) { if (useFor.Equals("exists")) { SQL.Add(" select top 1 tmp.XLXSBJDMX_XH"); } else if (useFor.Equals("selectBJDXH")) { SQL.Add(" select tmp.XLXSBJDMX_XH as BJDXH,"); SQL.Add(" (case when isnull(c.YZID,' ')<>' ' then isnull(c.YZZ,0) when isnull(b.YZID,' ')<>' ' then isnull(b.YZZ,0) when isnull(a.YZID,' ')<>' ' then isnull(a.YZZ,0)"); SQL.Add(" else 0.0 end)"); SQL.Add(" *(case when isnull(XLXSBJDYZZEBSY1_CPYT, ' ')=' ' then 1.0 else 0.0 end)*(case when isnull(XLXSBJDYZZEBSY2_XLJBXHID, ' ')=' ' then 1.0 else 0.0 end) as YZZ "); } else if (useFor.Equals("selectBJCP")) {//研发自测:王威 2025/09/12 01:21:15 SQL.Add(" select distinct upper(tmp.XLXSBJDMX_XLXHID) as XLXHID,tmp.XLXSBJDMX_XLGGID as XLGGID,tmp.XLXSBJDMX_XLBZID as XLBZID,isnull(tmp.XLXSBJDMX_DYDJID,' ') as DYDJID,' ' as XLXSBJDMX_XLYSID,"); for (int k = 1; k <= 20; k++) { if (sYZID.Equals("BJ" + k.ToString().PadLeft(2, '0'))) { SQL.Add(" (case when isnull(c.YZID,' ')<>' ' then isnull(c.YZZ,0) when isnull(b.YZID,' ')<>' ' then isnull(b.YZZ,0) when isnull(a.YZID,' ')<>' ' then isnull(a.YZZ,0)"); SQL.Add(" else 0.0 end) "); SQL.Add(string.Format(" *(case when isnull(XLXSBJDYZZEBSY1_CPYT, ' ')=' ' then 1.0 else 0.0 end)*(case when isnull(XLXSBJDYZZEBSY2_XLJBXHID, ' ')=' ' then 1.0 else 0.0 end) as YZZ{0},", k.ToString().PadLeft(2, '0'))); } else SQL.Add(string.Format(" 0.0 as YZZ{0},", k.ToString().PadLeft(2, '0'))); } SQL.Add(string.Format(" BJD.sumBJSL,'{0}' as JLDW,'{1}' as YZID ", sBJU003, sYZID)); } SQL.Add(" from XLXSBJDMX tmp"); SQL.Add(" left join XLXSBJDYZZ0 on XLXSBJDYZZ0_BJDID=tmp.XLXSBJDMX_BJDID and XLXSBJDYZZ0_XH=tmp.XLXSBJDMX_XH"); SQL.Add(" left join "); SQL.Add(" (select XLXSBJDMX_BJDID as BJDID,upper(XLXSBJDMX_XLXHID)as XLXHID,XLXSBJDMX_XLGGID as XLGGID,XLXSBJDMX_XLBZID as XLBZID,isnull(XLXSBJDMX_DYDJID,' ') as DYDJID,"); if (sBJU003JSDW.Equals("M")) { SQL.Add(" sum(case when XLXSBJDMX_JLDW in('Km','千米')then 1000*XLXSBJDMX_BJSL "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when XLXSBJDMX_JLDW='{0}' then {1}*XLXSBJDMX_BJSL ", sKey, dicLenJLDWTD[sKey])); } SQL.Add(" else XLXSBJDMX_BJSL end)as sumBJSL"); } else if (sBJU003JSDW.Equals("Km")) { SQL.Add(" sum(case when XLXSBJDMX_JLDW in('M','米')then 0.001*XLXSBJDMX_BJSL "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when XLXSBJDMX_JLDW='{0}' then 0.001*{1}*XLXSBJDMX_BJSL ", sKey, dicLenJLDWTD[sKey])); } SQL.Add(" else XLXSBJDMX_BJSL end)as sumBJSL"); } //取报价单明细因子值之和 SQL.Add(string.Format(" ,sum(XLXSBJDYZZ0_YZZ{0}) as sumYZZ", sYZID.Replace("BJ", ""))); SQL.Add(" from XLXSBJDMX"); //关联报价单明细因子值 SQL.Add(" left join XLXSBJDYZZ0 on XLXSBJDYZZ0_BJDID= XLXSBJDMX_BJDID and XLXSBJDYZZ0_XH= XLXSBJDMX_XH "); SQL.Add(string.Format(" where XLXSBJDMX_BJDID='{0}'", sBJDID)); SQL.Add(" and (XLXSBJDMX_JLDW in('Km','M','千米','米')"); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" or XLXSBJDMX_JLDW='{0}'", sKey)); } SQL.Add(" )"); SQL.Add(" group by XLXSBJDMX_BJDID,upper(XLXSBJDMX_XLXHID),XLXSBJDMX_XLGGID,XLXSBJDMX_XLBZID,isnull(XLXSBJDMX_DYDJID,' ')"); SQL.Add(" )BJD on BJD.XLXHID=upper(tmp.XLXSBJDMX_XLXHID) and BJD.XLGGID=tmp.XLXSBJDMX_XLGGID and BJD.XLBZID=tmp.XLXSBJDMX_XLBZID and BJD.DYDJID=isnull(tmp.XLXSBJDMX_DYDJID,' ')"); SQL.Add(" left join XLXHB on XLXHB_XLXHID=BJD.XLXHID "); SQL.Add(" left join XLXSBJDYZZEBSY1 on XLXSBJDYZZEBSY1_CPYT= isnull(XLXHB_CPYT,' ')"); SQL.Add(" left join XLXSBJDYZZEBSY2 on XLXSBJDYZZEBSY2_XLJBXHID= isnull(XLXHB_XLJBXHID,' ')"); SQL.Add(" left join XLXSBJXLGGTHB on XLXSBJXLGGTHB_XLGGID = XLXSBJDMX_XLGGID "); SQL.Add(" left join XLGGB on XLGGB_XLGGID = XLXSBJXLGGTHB_XLGGIDCH and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add(" left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZE_XLXHID,XLXSBJDYZZE_DYDJID,XLXSBJDYZZE_YZID as YZID,XLXSBJDYZZE_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZE_ZXJMXX,XLXSBJDYZZE_ZXJMSX,XLXSBJDYZZE_BJSLXX,XLXSBJDYZZE_BJSLSX"); SQL.Add(" from XLXSBJDYZZE"); SQL.Add(" where exists(select 1 from XLXSTZYZ where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='E' and XLXSTZYZ_JGBID=XLXSBJDYZZE_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZE_YZID ) "); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSBJDYZZE_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZE_YZID='{0}'", sYZID)); SQL.Add(" and XLXSBJDYZZE_XLXHID=' ' and XLXSBJDYZZE_DYDJID=' '"); SQL.Add(" ) a on "); SQL.Add(" a.XLXSBJDYZZE_ZXJMXX<=isnull(XLDTJMZHB_DTJM1,0) and ((a.XLXSBJDYZZE_ZXJMSX<>0 and a.XLXSBJDYZZE_ZXJMSX>=isnull(XLDTJMZHB_DTJM1,0)) or a.XLXSBJDYZZE_ZXJMSX=0) "); SQL.Add(" and a.XLXSBJDYZZE_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and ((a.XLXSBJDYZZE_BJSLSX<>0 and a.XLXSBJDYZZE_BJSLSX>BJD.sumBJSL) or a.XLXSBJDYZZE_BJSLSX=0) "); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZE_XLXHID,XLXSBJDYZZE_DYDJID,XLXSBJDYZZE_YZID as YZID,XLXSBJDYZZE_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZE_ZXJMXX,XLXSBJDYZZE_ZXJMSX,XLXSBJDYZZE_BJSLXX,XLXSBJDYZZE_BJSLSX"); SQL.Add(" from XLXSBJDYZZE"); SQL.Add(" where exists(select 1 from XLXSTZYZ where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='E' and XLXSTZYZ_JGBID=XLXSBJDYZZE_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZE_YZID ) "); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSBJDYZZE_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZE_YZID='{0}'", sYZID)); SQL.Add(" and XLXSBJDYZZE_XLXHID<>' ' and XLXSBJDYZZE_DYDJID=' '"); SQL.Add(" ) b on b.XLXSBJDYZZE_XLXHID = XLXHID "); SQL.Add(" and b.XLXSBJDYZZE_ZXJMXX<=isnull(XLDTJMZHB_DTJM1,0) and ((b.XLXSBJDYZZE_ZXJMSX<>0 and b.XLXSBJDYZZE_ZXJMSX>=isnull(XLDTJMZHB_DTJM1,0)) or b.XLXSBJDYZZE_ZXJMSX=0) "); SQL.Add(" and b.XLXSBJDYZZE_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and ((b.XLXSBJDYZZE_BJSLSX<>0 and b.XLXSBJDYZZE_BJSLSX>BJD.sumBJSL) or b.XLXSBJDYZZE_BJSLSX=0) "); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZE_XLXHID,XLXSBJDYZZE_DYDJID,XLXSBJDYZZE_YZID as YZID,XLXSBJDYZZE_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZE_ZXJMXX,XLXSBJDYZZE_ZXJMSX,XLXSBJDYZZE_BJSLXX,XLXSBJDYZZE_BJSLSX"); SQL.Add(" from XLXSBJDYZZE"); SQL.Add(" where exists(select 1 from XLXSTZYZ where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='E' and XLXSTZYZ_JGBID=XLXSBJDYZZE_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZE_YZID ) "); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSBJDYZZE_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZE_YZID='{0}'", sYZID)); SQL.Add(" and XLXSBJDYZZE_XLXHID<>' ' and XLXSBJDYZZE_DYDJID<>' '"); SQL.Add(" ) c on c.XLXSBJDYZZE_XLXHID=XLXHID and c.XLXSBJDYZZE_DYDJID = DYDJID"); SQL.Add(" and c.XLXSBJDYZZE_ZXJMXX<=isnull(XLDTJMZHB_DTJM1,0) and ((c.XLXSBJDYZZE_ZXJMSX<>0 and c.XLXSBJDYZZE_ZXJMSX>=isnull(XLDTJMZHB_DTJM1,0)) or c.XLXSBJDYZZE_ZXJMSX=0) "); SQL.Add(" and c.XLXSBJDYZZE_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and ((c.XLXSBJDYZZE_BJSLSX<>0 and c.XLXSBJDYZZE_BJSLSX>BJD.sumBJSL) or c.XLXSBJDYZZE_BJSLSX=0)"); SQL.Add(string.Format(" where tmp.XLXSBJDMX_BJDID='{0}'", sBJDID)); SQL.Add(" and (case when isnull(c.YZID,' ')<>' ' then isnull(c.YZZ,0) when isnull(b.YZID,' ')<>' ' then isnull(b.YZZ,0) when isnull(a.YZID,' ')<>' ' then isnull(a.YZZ,0)"); SQL.Add(" else 0.0 end)"); SQL.Add(string.Format("*(case when isnull(XLXSBJDYZZEBSY1_CPYT, ' ')=' ' then 1.0 else 0.0 end)*(case when isnull(XLXSBJDYZZEBSY2_XLJBXHID, ' ')=' ' then 1.0 else 0.0 end)<>XLXSBJDYZZ0_YZZ{0}", sYZID.Replace("BJ", ""))); SQL.Add(" and BJD.sumYZZ > 0 "); } else if (sTJYS.Equals("G")) { if (useFor.Equals("exists")) { SQL.Add(" select top 1 tmp.XLXSBJDMX_XH"); } else if (useFor.Equals("selectBJDXH")) { SQL.Add(" select tmp.XLXSBJDMX_XH as BJDXH,"); SQL.Add(" (case when isnull(b.YZID,' ')<>' ' then isnull(b.YZZ,0) when isnull(a.YZID,' ')<>' ' then isnull(a.YZZ,0)"); SQL.Add(" else 0.0 end) as YZZ" ); } else if (useFor.Equals("selectBJCP")) {//研发自测:王威 2025/09/12 01:21:15 SQL.Add(" select distinct upper(tmp.XLXSBJDMX_XLXHID) as XLXHID,tmp.XLXSBJDMX_XLGGID as XLGGID,tmp.XLXSBJDMX_XLBZID as XLBZID,isnull(tmp.XLXSBJDMX_DYDJID,' ') as DYDJID,' ' as XLXSBJDMX_XLYSID,"); for (int k = 1; k <= 20; k++) { if (sYZID.Equals("BJ" + k.ToString().PadLeft(2, '0'))) { SQL.Add(" (case when isnull(b.YZID,' ')<>' ' then isnull(b.YZZ,0) when isnull(a.YZID,' ')<>' ' then isnull(a.YZZ,0)"); SQL.Add(" else 0.0 end) "); SQL.Add(string.Format(" as YZZ{0},", k.ToString().PadLeft(2, '0'))); } else SQL.Add(string.Format(" 0.0 as YZZ{0},", k.ToString().PadLeft(2, '0'))); } SQL.Add(string.Format(" BJD.sumBJSL,'{0}' as JLDW,'{1}' as YZID ", sBJU003, sYZID)); } SQL.Add(" from XLXSBJDMX tmp"); SQL.Add(" left join XLXSBJDYZZ0 on XLXSBJDYZZ0_BJDID=tmp.XLXSBJDMX_BJDID and XLXSBJDYZZ0_XH=tmp.XLXSBJDMX_XH"); SQL.Add(" left join "); SQL.Add(" (select XLXSBJDMX_BJDID as BJDID,upper(XLXSBJDMX_XLXHID)as XLXHID,XLXSBJDMX_XLGGID as XLGGID,XLXSBJDMX_XLBZID as XLBZID,isnull(XLXSBJDMX_DYDJID,' ') as DYDJID,"); if (sBJU003JSDW.Equals("M")) { SQL.Add(" sum(case when XLXSBJDMX_JLDW in('Km','千米')then 1000*XLXSBJDMX_BJSL "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when XLXSBJDMX_JLDW='{0}' then {1}*XLXSBJDMX_BJSL ", sKey, dicLenJLDWTD[sKey])); } SQL.Add(" else XLXSBJDMX_BJSL end)as sumBJSL"); } else if (sBJU003JSDW.Equals("Km")) { SQL.Add(" sum(case when XLXSBJDMX_JLDW in('M','米')then 0.001*XLXSBJDMX_BJSL "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when XLXSBJDMX_JLDW='{0}' then 0.001*{1}*XLXSBJDMX_BJSL ", sKey, dicLenJLDWTD[sKey])); } SQL.Add(" else XLXSBJDMX_BJSL end)as sumBJSL"); } //取报价单明细因子值之和 SQL.Add(string.Format(" ,sum(XLXSBJDYZZ0_YZZ{0}) as sumYZZ", sYZID.Replace("BJ", ""))); SQL.Add(" from XLXSBJDMX"); //关联报价单明细因子值 SQL.Add(" left join XLXSBJDYZZ0 on XLXSBJDYZZ0_BJDID= XLXSBJDMX_BJDID and XLXSBJDYZZ0_XH= XLXSBJDMX_XH "); SQL.Add(string.Format(" where XLXSBJDMX_BJDID='{0}'", sBJDID)); SQL.Add(" and (XLXSBJDMX_JLDW in('Km','M','千米','米')"); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" or XLXSBJDMX_JLDW='{0}'", sKey)); } SQL.Add(" )"); SQL.Add(" group by XLXSBJDMX_BJDID,upper(XLXSBJDMX_XLXHID),XLXSBJDMX_XLGGID,XLXSBJDMX_XLBZID,isnull(XLXSBJDMX_DYDJID,' ')"); SQL.Add(" )BJD on BJD.XLXHID=upper(tmp.XLXSBJDMX_XLXHID) and BJD.XLGGID=tmp.XLXSBJDMX_XLGGID and BJD.XLBZID=tmp.XLXSBJDMX_XLBZID and BJD.DYDJID=isnull(tmp.XLXSBJDMX_DYDJID,' ')"); SQL.Add(" left join XLXHB on XLXHB_XLXHID=BJD.XLXHID "); SQL.Add(" left join XLXSBJXLGGTHB on XLXSBJXLGGTHB_XLGGID = XLXSBJDMX_XLGGID "); SQL.Add(" left join XLGGB on XLGGB_XLGGID = XLXSBJXLGGTHB_XLGGIDCH and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add(" left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZG_DTCLID,XLXSBJDYZZG_XXJGID,XLXSBJDYZZG_DYDJID,XLXSBJDYZZG_YZID as YZID,XLXSBJDYZZG_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZG_ZXJMXX,XLXSBJDYZZG_ZXJMSX,XLXSBJDYZZG_BJSLXX,XLXSBJDYZZG_BJSLSX"); SQL.Add(" from XLXSBJDYZZG"); SQL.Add(" where exists(select 1 from XLXSTZYZ where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='G' and XLXSTZYZ_JGBID=XLXSBJDYZZG_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZG_YZID ) "); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSBJDYZZG_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZG_YZID='{0}'", sYZID)); SQL.Add(" and XLXSBJDYZZG_DTCLID=' ' "); SQL.Add(" ) a on "); SQL.Add(" a.XLXSBJDYZZG_ZXJMXX<=isnull(XLDTJMZHB_DTJM1,0) and ((a.XLXSBJDYZZG_ZXJMSX<>0 and a.XLXSBJDYZZG_ZXJMSX>=isnull(XLDTJMZHB_DTJM1,0)) or a.XLXSBJDYZZG_ZXJMSX=0) "); SQL.Add(" and a.XLXSBJDYZZG_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and ((a.XLXSBJDYZZG_BJSLSX<>0 and a.XLXSBJDYZZG_BJSLSX>BJD.sumBJSL) or a.XLXSBJDYZZG_BJSLSX=0) and a.XLXSBJDYZZG_DYDJID=isnull(XLXSBJDMX_DYDJID,' ') and a.XLXSBJDYZZG_XXJGID=XLGGB_XXJGID "); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZG_DTCLID,XLXSBJDYZZG_XXJGID,XLXSBJDYZZG_DYDJID,XLXSBJDYZZG_YZID as YZID,XLXSBJDYZZG_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZG_ZXJMXX,XLXSBJDYZZG_ZXJMSX,XLXSBJDYZZG_BJSLXX,XLXSBJDYZZG_BJSLSX"); SQL.Add(" from XLXSBJDYZZG"); SQL.Add(" where exists(select 1 from XLXSTZYZ where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='G' and XLXSTZYZ_JGBID=XLXSBJDYZZG_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZG_YZID ) "); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSBJDYZZG_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZG_YZID='{0}'", sYZID)); SQL.Add(" and XLXSBJDYZZG_DTCLID<>' ' "); SQL.Add(" ) b on b.XLXSBJDYZZG_DTCLID=XLXHB_DTCLID and "); SQL.Add(" b.XLXSBJDYZZG_ZXJMXX<=isnull(XLDTJMZHB_DTJM1,0) and ((b.XLXSBJDYZZG_ZXJMSX<>0 and b.XLXSBJDYZZG_ZXJMSX>=isnull(XLDTJMZHB_DTJM1,0)) or b.XLXSBJDYZZG_ZXJMSX=0) "); SQL.Add(" and b.XLXSBJDYZZG_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and ((b.XLXSBJDYZZG_BJSLSX<>0 and b.XLXSBJDYZZG_BJSLSX>BJD.sumBJSL) or b.XLXSBJDYZZG_BJSLSX=0) and b.XLXSBJDYZZG_DYDJID=isnull(XLXSBJDMX_DYDJID,' ') and b.XLXSBJDYZZG_XXJGID=XLGGB_XXJGID "); SQL.Add(string.Format(" where tmp.XLXSBJDMX_BJDID='{0}'", sBJDID)); SQL.Add(" and (case when isnull(b.YZID,' ')<>' ' then isnull(b.YZZ,0) when isnull(a.YZID,' ')<>' ' then isnull(a.YZZ,0)"); SQL.Add(" else 0.0 end)"); SQL.Add(string.Format(" <>XLXSBJDYZZ0_YZZ{0}", sYZID.Replace("BJ", ""))); SQL.Add(" and BJD.sumYZZ > 0 "); } else if (sTJYS.Equals("F")) { if (useFor.Equals("exists")) { SQL.Add(" select top 1 tmp.XLXSBJDMX_XH"); } else if (useFor.Equals("selectBJDXH")) { SQL.Add(" select tmp.XLXSBJDMX_XH as BJDXH,tmp.XLXSBJDMX_JLDW AS XLXSBJDMX_JLDW,"); SQL.Add(" (case when isnull(b.YZID,' ')<>' ' then RoundFix(isnull(b.YZZ,0)/BJD.sumBJSL,6) when isnull(a.YZID,' ')<>' ' then RoundFix(isnull(a.YZZ,0)/BJD.sumBJSL,6)"); SQL.Add(" else 0.0 end) as YZZ"); } else if (useFor.Equals("selectBJCP")) {//研发自测:王威 2025/09/12 01:21:15 SQL.Add(" select distinct upper(tmp.XLXSBJDMX_XLXHID) as XLXHID,tmp.XLXSBJDMX_XLGGID as XLGGID,tmp.XLXSBJDMX_XLBZID as XLBZID,isnull(tmp.XLXSBJDMX_DYDJID,' ') as DYDJID,' ' as XLXSBJDMX_XLYSID,"); for (int k = 1; k <= 20; k++) { if (sYZID.Equals("BJ" + k.ToString().PadLeft(2, '0'))) { SQL.Add(" (case when isnull(b.YZID,' ')<>' ' then RoundFix(isnull(b.YZZ,0)/BJD.sumBJSL,6) when isnull(a.YZID,' ')<>' ' then RoundFix(isnull(a.YZZ,0)/BJD.sumBJSL,6)"); SQL.Add(string.Format(" else 0.0 end) as YZZ{0},", k.ToString().PadLeft(2, '0'))); } else SQL.Add(string.Format(" 0.0 as YZZ{0},", k.ToString().PadLeft(2, '0'))); } SQL.Add(string.Format(" BJD.sumBJSL,'{0}' as JLDW,'{1}' as YZID ", sBJU003, sYZID)); } SQL.Add(" from XLXSBJDMX tmp"); SQL.Add(" left join XLXSBJDYZZ0 on XLXSBJDYZZ0_BJDID=tmp.XLXSBJDMX_BJDID and XLXSBJDYZZ0_XH=tmp.XLXSBJDMX_XH"); SQL.Add(" left join "); SQL.Add(" (select XLXSBJDMX_BJDID as BJDID,upper(XLXSBJDMX_XLXHID)as XLXHID,XLXSBJDMX_XLGGID as XLGGID,XLXSBJDMX_XLBZID as XLBZID,isnull(XLXSBJDMX_DYDJID,' ') as DYDJID,"); if (sBJU003JSDW.Equals("M")) { SQL.Add(" sum(case when XLXSBJDMX_JLDW in('Km','千米')then 1000*XLXSBJDMX_BJSL "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when XLXSBJDMX_JLDW='{0}' then {1}*XLXSBJDMX_BJSL ", sKey, dicLenJLDWTD[sKey])); } SQL.Add(" else XLXSBJDMX_BJSL end)as sumBJSL"); } else if (sBJU003JSDW.Equals("Km")) { SQL.Add(" sum(case when XLXSBJDMX_JLDW in('M','米')then 0.001*XLXSBJDMX_BJSL "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when XLXSBJDMX_JLDW='{0}' then 0.001*{1}*XLXSBJDMX_BJSL ", sKey, dicLenJLDWTD[sKey])); } SQL.Add(" else XLXSBJDMX_BJSL end)as sumBJSL"); } //取报价单明细因子值之和 SQL.Add(string.Format(" ,sum(XLXSBJDYZZ0_YZZ{0}) as sumYZZ", sYZID.Replace("BJ", ""))); SQL.Add(" from XLXSBJDMX"); //关联报价单明细因子值 SQL.Add(" left join XLXSBJDYZZ0 on XLXSBJDYZZ0_BJDID= XLXSBJDMX_BJDID and XLXSBJDYZZ0_XH= XLXSBJDMX_XH "); SQL.Add(string.Format(" where XLXSBJDMX_BJDID='{0}'", sBJDID)); SQL.Add(" and (XLXSBJDMX_JLDW in('Km','M','千米','米')"); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" or XLXSBJDMX_JLDW='{0}'", sKey)); } SQL.Add(" )"); SQL.Add(" and XLXSBJDMX_BJSL<>0");//因素F需要限制报价数量不为0 SQL.Add(" group by XLXSBJDMX_BJDID,upper(XLXSBJDMX_XLXHID),XLXSBJDMX_XLGGID,XLXSBJDMX_XLBZID,isnull(XLXSBJDMX_DYDJID,' ')"); SQL.Add(" )BJD on BJD.XLXHID=upper(tmp.XLXSBJDMX_XLXHID) and BJD.XLGGID=tmp.XLXSBJDMX_XLGGID and BJD.XLBZID=tmp.XLXSBJDMX_XLBZID and BJD.DYDJID=isnull(tmp.XLXSBJDMX_DYDJID,' ')"); SQL.Add(" left join XLXHB on XLXHB_XLXHID=tmp.XLXSBJDMX_XLXHID "); SQL.Add(" left join XLGGB on XLGGB_XLGGID = replace(tmp.XLXSBJDMX_XLGGID , '*','×') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZF_DYDJID,XLXSBJDYZZF_YZID as YZID,XLXSBJDYZZF_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZF_XXJGID,XLXSBJDYZZF_DTCLID,XLXSBJDYZZF_BJSLXX,XLXSBJDYZZF_BJSLSX"); SQL.Add(" from XLXSBJDYZZF"); SQL.Add(" where exists(select 1 from XLXSTZYZ where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='F' and XLXSTZYZ_JGBID=XLXSBJDYZZF_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZF_YZID ) "); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSBJDYZZF_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZF_YZID='{0}'", sYZID)); SQL.Add(" and XLXSBJDYZZF_XXJGID=' ' and XLXSBJDYZZF_DYDJID<>' '"); SQL.Add(" ) a on a.XLXSBJDYZZF_DYDJID = DYDJID AND a.XLXSBJDYZZF_DTCLID = XLXHB_DTCLID "); SQL.Add(" and a.XLXSBJDYZZF_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and ((a.XLXSBJDYZZF_BJSLSX<>0 and a.XLXSBJDYZZF_BJSLSX>BJD.sumBJSL) or a.XLXSBJDYZZF_BJSLSX=0) "); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZF_DYDJID,XLXSBJDYZZF_YZID as YZID,XLXSBJDYZZF_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZF_XXJGID,XLXSBJDYZZF_DTCLID,XLXSBJDYZZF_BJSLXX,XLXSBJDYZZF_BJSLSX"); SQL.Add(" from XLXSBJDYZZF"); SQL.Add(" where exists(select 1 from XLXSTZYZ where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='F' and XLXSTZYZ_JGBID=XLXSBJDYZZF_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZF_YZID ) "); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSBJDYZZF_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZF_YZID='{0}'", sYZID)); SQL.Add(" and XLXSBJDYZZF_XXJGID<>' ' and XLXSBJDYZZF_DYDJID<>' '");//需要查芯线结构ID SQL.Add(" ) b on b.XLXSBJDYZZF_XXJGID=XLGGB_XXJGID and b.XLXSBJDYZZF_DYDJID = DYDJID AND b.XLXSBJDYZZF_DTCLID = XLXHB_DTCLID "); SQL.Add(" and b.XLXSBJDYZZF_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and ((b.XLXSBJDYZZF_BJSLSX<>0 and b.XLXSBJDYZZF_BJSLSX>BJD.sumBJSL) or b.XLXSBJDYZZF_BJSLSX=0)"); SQL.Add(string.Format(" where tmp.XLXSBJDMX_BJDID='{0}'", sBJDID)); SQL.Add(" and (case when isnull(b.YZID,' ')<>' ' then RoundFix(isnull(b.YZZ,0)/sumBJSL,6) when isnull(a.YZID,' ')<>' ' then RoundFix(isnull(a.YZZ,0)/sumBJSL,6) "); if (sBJU003JSDW.Equals("M")) { SQL.Add(string.Format(" else 0.0 end)<> (case when tmp.XLXSBJDMX_JLDW in('Km','千米') then RoundFix(0.001*XLXSBJDYZZ0_YZZ{0},6) ", sYZID.Replace("BJ", ""))); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when tmp.XLXSBJDMX_JLDW='{0}' then RoundFix(XLXSBJDYZZ0_YZZ{2}/{1},6) ", sKey, dicLenJLDWTD[sKey], sYZID.Replace("BJ", ""))); } SQL.Add(string.Format(" else XLXSBJDYZZ0_YZZ{0} end) ", sYZID.Replace("BJ", ""))); } else if (sBJU003JSDW.Equals("Km")) { SQL.Add(string.Format(" else 0.0 end)<> (case when tmp.XLXSBJDMX_JLDW in('M','米') then RoundFix(1000*XLXSBJDYZZ0_YZZ{0},6) ", sYZID.Replace("BJ", ""))); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when tmp.XLXSBJDMX_JLDW='{0}' then RoundFix(XLXSBJDYZZ0_YZZ{2}*{1},6) ", sKey, dicLenJLDWTD[sKey], sYZID.Replace("BJ", ""))); } SQL.Add(string.Format(" else XLXSBJDYZZ0_YZZ{0} end) ", sYZID.Replace("BJ", ""))); } SQL.Add(" and BJD.sumYZZ > 0 "); } else if (sTJYS.Equals("H")) { if (useFor.Equals("exists")) { SQL.Add(" select top 1 tmp.XLXSBJDMX_XH"); } else if (useFor.Equals("selectBJDXH")) {//研发自测:王威 2025/09/12 01:21:15 SQL.Add(" select tmp.XLXSBJDMX_XH as BJDXH,tmp.XLXSBJDMX_JLDW AS XLXSBJDMX_JLDW,"); SQL.Add(" (case when isnull(a.YZID,' ')<>' ' then RoundFix(isnull(a.YZZ,0)/BJD.sumBJSL,6) when isnull(b.YZID,' ')<>' ' then RoundFix(isnull(b.YZZ,0)/BJD.sumBJSL,6) "); SQL.Add(" when isnull(c.YZID,' ')<>' ' then RoundFix(isnull(c.YZZ,0)/BJD.sumBJSL,6) when isnull(d.YZID,' ')<>' ' then RoundFix(isnull(d.YZZ,0)/BJD.sumBJSL,6) "); SQL.Add(" else 0.0 end) as YZZ"); } else if (useFor.Equals("selectBJCP")) { SQL.Add(" select distinct upper(tmp.XLXSBJDMX_XLXHID) as XLXHID,tmp.XLXSBJDMX_XLGGID as XLGGID,tmp.XLXSBJDMX_XLBZID as XLBZID,isnull(tmp.XLXSBJDMX_DYDJID,' ') as DYDJID,XLXSBJDMX_XLYSID,"); for (int k = 1; k <= 20; k++) { if (sYZID.Equals("BJ" + k.ToString().PadLeft(2, '0'))) { SQL.Add(" (case when isnull(a.YZID,' ')<>' ' then RoundFix(isnull(a.YZZ,0)/BJD.sumBJSL,6) when isnull(b.YZID,' ')<>' ' then RoundFix(isnull(b.YZZ,0)/BJD.sumBJSL,6) "); SQL.Add(" when isnull(c.YZID,' ')<>' ' then RoundFix(isnull(c.YZZ,0)/BJD.sumBJSL,6) when isnull(d.YZID,' ')<>' ' then RoundFix(isnull(d.YZZ,0)/BJD.sumBJSL,6) "); SQL.Add(string.Format(" else 0.0 end) as YZZ{0},", k.ToString().PadLeft(2, '0'))); } else SQL.Add(string.Format(" 0.0 as YZZ{0},", k.ToString().PadLeft(2, '0'))); } SQL.Add(string.Format(" BJD.sumBJSL,'{0}' as JLDW,'{1}' as YZID ", sBJU003, sYZID)); } SQL.Add(" from XLXSBJDMX tmp"); SQL.Add(" left join XLXSBJDYZZ0 on XLXSBJDYZZ0_BJDID=tmp.XLXSBJDMX_BJDID and XLXSBJDYZZ0_XH=tmp.XLXSBJDMX_XH"); SQL.Add(" left join "); SQL.Add(" (select XLXSBJDMX_BJDID as BJDID,upper(XLXSBJDMX_XLXHID)as XLXHID,XLXSBJDMX_XLGGID as XLGGID,XLXSBJDMX_XLBZID as XLBZID,isnull(XLXSBJDMX_DYDJID,' ') as DYDJID,XLXSBJDMX_XLYSID as XLYSID,"); if (sBJU003JSDW.Equals("M")) { SQL.Add(" sum(case when XLXSBJDMX_JLDW in('Km','千米')then 1000*XLXSBJDMX_BJSL "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when XLXSBJDMX_JLDW='{0}' then {1}*XLXSBJDMX_BJSL ", sKey, dicLenJLDWTD[sKey])); } SQL.Add(" else XLXSBJDMX_BJSL end)as sumBJSL"); } else if (sBJU003JSDW.Equals("Km")) { SQL.Add(" sum(case when XLXSBJDMX_JLDW in('M','米')then 0.001*XLXSBJDMX_BJSL "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when XLXSBJDMX_JLDW='{0}' then 0.001*{1}*XLXSBJDMX_BJSL ", sKey, dicLenJLDWTD[sKey])); } SQL.Add(" else XLXSBJDMX_BJSL end)as sumBJSL"); } //取报价单明细因子值之和 SQL.Add(string.Format(" ,sum(XLXSBJDYZZ0_YZZ{0}) as sumYZZ", sYZID.Replace("BJ", ""))); SQL.Add(" from XLXSBJDMX"); //关联报价单明细因子值 SQL.Add(" left join XLXSBJDYZZ0 on XLXSBJDYZZ0_BJDID= XLXSBJDMX_BJDID and XLXSBJDYZZ0_XH= XLXSBJDMX_XH "); SQL.Add(string.Format(" where XLXSBJDMX_BJDID='{0}'", sBJDID)); SQL.Add(" and (XLXSBJDMX_JLDW in('Km','M','千米','米')"); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" or XLXSBJDMX_JLDW='{0}'", sKey)); } SQL.Add(" )"); SQL.Add(" and XLXSBJDMX_BJSL<>0");//因素H需要限制报价数量不为0 SQL.Add(" group by XLXSBJDMX_BJDID,upper(XLXSBJDMX_XLXHID),XLXSBJDMX_XLGGID,XLXSBJDMX_XLBZID,isnull(XLXSBJDMX_DYDJID,' '),XLXSBJDMX_XLYSID"); SQL.Add(" )BJD on BJD.XLXHID=upper(tmp.XLXSBJDMX_XLXHID) and BJD.XLGGID=tmp.XLXSBJDMX_XLGGID and BJD.XLBZID=tmp.XLXSBJDMX_XLBZID and BJD.DYDJID=isnull(tmp.XLXSBJDMX_DYDJID,' ') and BJD.XLYSID=tmp.XLXSBJDMX_XLYSID "); SQL.Add(" left join XLXHB on XLXHB_XLXHID=tmp.XLXSBJDMX_XLXHID "); SQL.Add(" left join XLGGB on XLGGB_XLGGID = replace(tmp.XLXSBJDMX_XLGGID , '*','×') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add(" left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZH_XLXHID,XLXSBJDYZZH_DYDJID,XLXSBJDYZZH_XLYSID,XLXSBJDYZZH_YZID as YZID,XLXSBJDYZZH_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZH_ZXJMXX,XLXSBJDYZZH_ZXJMSX,XLXSBJDYZZH_BJSLXX,XLXSBJDYZZH_BJSLSX"); SQL.Add(" from XLXSBJDYZZH"); SQL.Add(" where exists(select 1 from XLXSTZYZ where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='H' and XLXSTZYZ_JGBID=XLXSBJDYZZH_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZH_YZID ) "); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSBJDYZZH_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZH_YZID='{0}'", sYZID)); SQL.Add(" and isnull(XLXSBJDYZZH_DYDJID,' ') <> ' ' and isnull(XLXSBJDYZZH_XLYSID,' ') <> ' ' "); SQL.Add(" ) a on a.XLXSBJDYZZH_XLXHID = XLXHID and a.XLXSBJDYZZH_DYDJID = DYDJID and a.XLXSBJDYZZH_XLYSID = XLYSID "); SQL.Add(" and a.XLXSBJDYZZH_ZXJMXX<=isnull(XLDTJMZHB_DTJM1,0) and ((a.XLXSBJDYZZH_ZXJMSX<>0 and a.XLXSBJDYZZH_ZXJMSX>=isnull(XLDTJMZHB_DTJM1,0)) or a.XLXSBJDYZZH_ZXJMSX=0) "); SQL.Add(" and a.XLXSBJDYZZH_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and ((a.XLXSBJDYZZH_BJSLSX<>0 and a.XLXSBJDYZZH_BJSLSX>BJD.sumBJSL) or a.XLXSBJDYZZH_BJSLSX=0) "); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZH_XLXHID,XLXSBJDYZZH_DYDJID,XLXSBJDYZZH_XLYSID,XLXSBJDYZZH_YZID as YZID,XLXSBJDYZZH_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZH_ZXJMXX,XLXSBJDYZZH_ZXJMSX,XLXSBJDYZZH_BJSLXX,XLXSBJDYZZH_BJSLSX"); SQL.Add(" from XLXSBJDYZZH"); SQL.Add(" where exists(select 1 from XLXSTZYZ where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='H' and XLXSTZYZ_JGBID=XLXSBJDYZZH_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZH_YZID ) "); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSBJDYZZH_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZH_YZID='{0}'", sYZID)); SQL.Add(" and isnull(XLXSBJDYZZH_DYDJID,' ') = ' ' and isnull(XLXSBJDYZZH_XLYSID,' ') <> ' ' "); SQL.Add(" ) b on b.XLXSBJDYZZH_XLXHID = XLXHID and b.XLXSBJDYZZH_XLYSID = XLYSID "); SQL.Add(" and b.XLXSBJDYZZH_ZXJMXX<=isnull(XLDTJMZHB_DTJM1,0) and ((b.XLXSBJDYZZH_ZXJMSX<>0 and b.XLXSBJDYZZH_ZXJMSX>=isnull(XLDTJMZHB_DTJM1,0)) or b.XLXSBJDYZZH_ZXJMSX=0) "); SQL.Add(" and b.XLXSBJDYZZH_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and ((b.XLXSBJDYZZH_BJSLSX<>0 and b.XLXSBJDYZZH_BJSLSX>BJD.sumBJSL) or b.XLXSBJDYZZH_BJSLSX=0) "); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZH_XLXHID,XLXSBJDYZZH_DYDJID,XLXSBJDYZZH_XLYSID,XLXSBJDYZZH_YZID as YZID,XLXSBJDYZZH_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZH_ZXJMXX,XLXSBJDYZZH_ZXJMSX,XLXSBJDYZZH_BJSLXX,XLXSBJDYZZH_BJSLSX"); SQL.Add(" from XLXSBJDYZZH"); SQL.Add(" where exists(select 1 from XLXSTZYZ where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='H' and XLXSTZYZ_JGBID=XLXSBJDYZZH_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZH_YZID ) "); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSBJDYZZH_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZH_YZID='{0}'", sYZID)); SQL.Add(" and isnull(XLXSBJDYZZH_DYDJID,' ') <> ' ' and isnull(XLXSBJDYZZH_XLYSID,' ') = ' ' "); SQL.Add(" ) c on c.XLXSBJDYZZH_XLXHID = XLXHID and c.XLXSBJDYZZH_DYDJID = DYDJID "); SQL.Add(" and c.XLXSBJDYZZH_ZXJMXX<=isnull(XLDTJMZHB_DTJM1,0) and ((c.XLXSBJDYZZH_ZXJMSX<>0 and c.XLXSBJDYZZH_ZXJMSX>=isnull(XLDTJMZHB_DTJM1,0)) or c.XLXSBJDYZZH_ZXJMSX=0) "); SQL.Add(" and c.XLXSBJDYZZH_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and ((c.XLXSBJDYZZH_BJSLSX<>0 and c.XLXSBJDYZZH_BJSLSX>BJD.sumBJSL) or c.XLXSBJDYZZH_BJSLSX=0) "); SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSBJDYZZH_XLXHID,XLXSBJDYZZH_DYDJID,XLXSBJDYZZH_XLYSID,XLXSBJDYZZH_YZID as YZID,XLXSBJDYZZH_YZZ as YZZ,"); SQL.Add(" XLXSBJDYZZH_ZXJMXX,XLXSBJDYZZH_ZXJMSX,XLXSBJDYZZH_BJSLXX,XLXSBJDYZZH_BJSLSX"); SQL.Add(" from XLXSBJDYZZH"); SQL.Add(" where exists(select 1 from XLXSTZYZ where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='H' and XLXSTZYZ_JGBID=XLXSBJDYZZH_JGBID and XLXSTZYZ_YZID=XLXSBJDYZZH_YZID ) "); SQL.Add(string.Format(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID='{0}' and XLXSBJFLYZ_YZID=XLXSBJDYZZH_YZID)", sBJFLID)); SQL.Add(string.Format(" and XLXSBJDYZZH_YZID='{0}'", sYZID)); SQL.Add(" and isnull(XLXSBJDYZZH_DYDJID,' ') = ' ' and isnull(XLXSBJDYZZH_XLYSID,' ') = ' ' "); SQL.Add(" ) d on d.XLXSBJDYZZH_XLXHID = XLXHID "); SQL.Add(" and d.XLXSBJDYZZH_ZXJMXX<=isnull(XLDTJMZHB_DTJM1,0) and ((d.XLXSBJDYZZH_ZXJMSX<>0 and d.XLXSBJDYZZH_ZXJMSX>=isnull(XLDTJMZHB_DTJM1,0)) or d.XLXSBJDYZZH_ZXJMSX=0) "); SQL.Add(" and d.XLXSBJDYZZH_BJSLXX<=BJD.sumBJSL"); SQL.Add(" and ((d.XLXSBJDYZZH_BJSLSX<>0 and d.XLXSBJDYZZH_BJSLSX>BJD.sumBJSL) or d.XLXSBJDYZZH_BJSLSX=0) "); SQL.Add(string.Format(" where tmp.XLXSBJDMX_BJDID='{0}'", sBJDID)); SQL.Add(" and (case when isnull(a.YZID,' ')<>' ' then RoundFix(isnull(a.YZZ,0)/sumBJSL,6) when isnull(b.YZID,' ')<>' ' then RoundFix(isnull(b.YZZ,0)/sumBJSL,6) "); SQL.Add(" when isnull(d.YZID,' ')<>' ' then RoundFix(isnull(d.YZZ,0)/sumBJSL,6) when isnull(d.YZID,' ')<>' ' then RoundFix(isnull(d.YZZ,0)/sumBJSL,6) "); if (sBJU003JSDW.Equals("M")) { SQL.Add(string.Format(" else 0.0 end)<> (case when tmp.XLXSBJDMX_JLDW in('Km','千米') then RoundFix(0.001*XLXSBJDYZZ0_YZZ{0},6) ", sYZID.Replace("BJ", ""))); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when tmp.XLXSBJDMX_JLDW='{0}' then RoundFix(XLXSBJDYZZ0_YZZ{2}/{1},6) ", sKey, dicLenJLDWTD[sKey], sYZID.Replace("BJ", ""))); } SQL.Add(string.Format(" else XLXSBJDYZZ0_YZZ{0} end) ", sYZID.Replace("BJ", ""))); } else if (sBJU003JSDW.Equals("Km")) { SQL.Add(string.Format(" else 0.0 end)<> (case when tmp.XLXSBJDMX_JLDW in('M','米') then RoundFix(1000*XLXSBJDYZZ0_YZZ{0},6) ", sYZID.Replace("BJ", ""))); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when tmp.XLXSBJDMX_JLDW='{0}' then RoundFix(XLXSBJDYZZ0_YZZ{2}*{1},6) ", sKey, dicLenJLDWTD[sKey], sYZID.Replace("BJ", ""))); } SQL.Add(string.Format(" else XLXSBJDYZZ0_YZZ{0} end) ", sYZID.Replace("BJ", ""))); } SQL.Add(" and BJD.sumYZZ > 0 "); } } } public class XLBJD_ZDTJYSInfo { //1|付款方式 public static void updBJDYZZ1(TDatabase dberp, TSQL sql, string sPJLX, string sBJFLID, string sBJDID) { sql.Clear(); sql.Add("select XLXSTZYZ_YZID,isnull(XLXSBJDYZZ1_YZZ,0) as YZZ from XLXSTZYZ"); sql.Add(" left join XLXSBJDYZZ1 on XLXSBJDYZZ1_JGBID=XLXSTZYZ_JGBID and XLXSBJDYZZ1_YZID=XLXSTZYZ_YZID and XLXSBJDYZZ1_PJLX=:pPJLX"); sql.Add(" where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='1'"); sql.Add(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID=:pBJFLID and XLXSBJFLYZ_YZID=XLXSTZYZ_YZID)"); sql.Add(" order by XLXSTZYZ_XSXH,XLXSTZYZ_YZID"); sql.ParamByName("pPJLX").Value = sPJLX; sql.ParamByName("pBJFLID").Value = sBJFLID; DataSet ds = dberp.OpenDataSet(sql); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string sYZID = ds.Tables[0].Rows[i]["XLXSTZYZ_YZID"].ToString().Trim(); string sYZZ = ds.Tables[0].Rows[i]["YZZ"].ToString().Trim(); dberp.ExecSQL(string.Format("update XLXSBJDYZZ0 set XLXSBJDYZZ0_YZZ{0}={1} where XLXSBJDYZZ0_BJDID='{2}'", sYZID.Replace("BJ", ""), sYZZ, sBJDID)); } } //8|付款期限 public static void updBJDYZZ8(TDatabase dberp, TSQL sql, string sFKQXNR, string sBJFLID, string sBJDID) { sql.Clear(); sql.Add("select XLXSTZYZ_YZID,isnull(XLXSBJDYZZ8_YZZ,0) as YZZ from XLXSTZYZ"); sql.Add(" left join XLXSBJDYZZ8 on XLXSBJDYZZ8_JGBID=XLXSTZYZ_JGBID and XLXSBJDYZZ8_YZID=XLXSTZYZ_YZID and XLXSBJDYZZ8_FKQXNR=:pFKQXNR"); sql.Add(" where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='8'"); sql.Add(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID=:pBJFLID and XLXSBJFLYZ_YZID=XLXSTZYZ_YZID)"); sql.Add(" order by XLXSTZYZ_XSXH,XLXSTZYZ_YZID"); sql.ParamByName("pFKQXNR").Value = sFKQXNR; sql.ParamByName("pBJFLID").Value = sBJFLID; DataSet ds = dberp.OpenDataSet(sql); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string sYZID = ds.Tables[0].Rows[i]["XLXSTZYZ_YZID"].ToString().Trim(); string sYZZ = ds.Tables[0].Rows[i]["YZZ"].ToString().Trim(); dberp.ExecSQL(string.Format("update XLXSBJDYZZ0 set XLXSBJDYZZ0_YZZ{0}={1} where XLXSBJDYZZ0_BJDID='{2}'", sYZID.Replace("BJ", ""), sYZZ, sBJDID)); } } //B|销售单位 public static void updBJDYZZB(TDatabase dberp, TSQL sql, string sSYDWID, string sBJFLID, string sBJDID) { sql.Clear(); sql.Add("select XLXSTZYZ_YZID,isnull(XLXSBJDYZZB_YZZ,0) as YZZ from XLXSTZYZ"); sql.Add(" left join XLXSBJDYZZB on XLXSBJDYZZB_JGBID=XLXSTZYZ_JGBID and XLXSBJDYZZB_YZID=XLXSTZYZ_YZID and XLXSBJDYZZB_SYDWID=:pSYDWID"); sql.Add(" where XLXSTZYZ_MXBH='BJD' and XLXSTZYZ_TJYS='B'"); sql.Add(" and exists(select 1 from XLXSBJFLYZ where XLXSBJFLYZ_BJFLID=:pBJFLID and XLXSBJFLYZ_YZID=XLXSTZYZ_YZID)"); sql.Add(" order by XLXSTZYZ_XSXH,XLXSTZYZ_YZID"); sql.ParamByName("pSYDWID").Value = sSYDWID; sql.ParamByName("pBJFLID").Value = sBJFLID; DataSet ds = dberp.OpenDataSet(sql); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { string sYZID = ds.Tables[0].Rows[i]["XLXSTZYZ_YZID"].ToString().Trim(); string sYZZ = ds.Tables[0].Rows[i]["YZZ"].ToString().Trim(); dberp.ExecSQL(string.Format("update XLXSBJDYZZ0 set XLXSBJDYZZ0_YZZ{0}={1} where XLXSBJDYZZ0_BJDID='{2}'", sYZID.Replace("BJ", ""), sYZZ, sBJDID)); } } } public class XLJGB_CLJGTZList { public static void AddXLXSJGBYZZ0(TDatabase dberp, string sMXBH, string sJGBID, string sTJYSList_, string sTJYSList1, string sTJYSList3, string sTJYSList4, string sTJYSList5, string sTJYSList8, string sTJYSList9, bool bInsertXLXSJGBYZZ0, string sJGCZBID, string sJGCZBBBID, double maxXH) { CMISproSession tSession = CMISproApp.GetSession(); TSQL SQL = new TSQL(dberp); //插入XLXSJGBMX记录后需要自动补齐XLXSJGBYZZ0记录 if (bInsertXLXSJGBYZZ0) { Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-InsXLXSJGBYZZ0-Begin")); //如果存在调价因素为空的因子 if (!sTJYSList_.Trim().Equals("")) { string[] sTJYZs = sTJYSList_.Split(','); SQL.Clear(); SQL.Add("insert into XLXSJGBYZZ0(XLXSJGBYZZ0_JGBID,XLXSJGBYZZ0_XH"); for (int i = 0; i < sTJYZs.Length; i++) { SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}", sTJYZs[i].Trim().Replace("JZ", ""))); } SQL.Add(") "); SQL.Add("select XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); for (int i = 0; i < sTJYZs.Length; i++) { SQL.Add(string.Format(",sum(CASE XLXSTZYZ_YZID WHEN '{0}' THEN XLXSJGBYZZ_YZZ ELSE 0 END) as YZZ{1}", sTJYZs[i].Trim(), sTJYZs[i].Trim().Replace("JZ", ""))); } SQL.Add(" from XLXSJGBMX,XLXSTZYZ,XLXSJGBYZZ "); SQL.Add("where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add("and XLXSTZYZ_MXBH='JZJ' and " + CMISproDataBase.GetWhereEqual("XLXSTZYZ_YZID", sTJYSList_.Trim())); SQL.Add("and XLXSTZYZ_TJYS=' ' and XLXSJGBYZZ_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ_YZID=XLXSTZYZ_YZID "); SQL.Add("and not exists "); SQL.Add("( "); SQL.Add("select 1 "); SQL.Add("from XLXSJGBYZZ0 "); SQL.Add("where XLXSJGBYZZ0_JGBID=:pJGBID "); SQL.Add("and XLXSJGBYZZ0_XH=XLXSJGBMX_XH "); SQL.Add(") "); SQL.Add(" group by XLXSJGBMX_JGBID,XLXSJGBMX_XH,XLXSJGBMX_JLDW"); SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-InsXLXSJGBYZZ0-调价因素为空1-end")); } else { SQL.Clear(); SQL.Add("insert into XLXSJGBYZZ0(XLXSJGBYZZ0_JGBID,XLXSJGBYZZ0_XH) "); SQL.Add("select XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(" from XLXSJGBMX "); SQL.Add("where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add("and not exists "); SQL.Add("( "); SQL.Add("select 1 "); SQL.Add("from XLXSJGBYZZ0 "); SQL.Add("where XLXSJGBYZZ0_JGBID=:pJGBID "); SQL.Add("and XLXSJGBYZZ0_XH=XLXSJGBMX_XH "); SQL.Add(") "); SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-InsXLXSJGBYZZ0-调价因素为空2-end")); } } //先清空TJYS<>' '的调价因子值 if (!sTJYSList1.Trim().Equals("") || !sTJYSList3.Trim().Equals("") || !sTJYSList4.Trim().Equals("") || !sTJYSList5.Trim().Equals("") || !sTJYSList8.Trim().Equals("") || !sTJYSList9.Trim().Equals("")) { Dictionary dicJGBFGQCPYZ = XLBJDInfo.GetJGBFGQCPYZ(sJGBID); string[] sTJYZ1 = sTJYSList1.Split(','); string[] sTJYZ3 = sTJYSList3.Split(','); string[] sTJYZ4 = sTJYSList4.Split(','); string[] sTJYZ5 = sTJYSList5.Split(','); string[] sTJYZ8 = sTJYSList8.Split(','); string[] sTJYZ9 = sTJYSList9.Split(','); bool bflag = false; SQL.Clear(); SQL.Add("update XLXSJGBYZZ0 set "); if (!sTJYSList1.Trim().Equals("")) { for (int i = 0; i < sTJYZ1.Length; i++) { int iYZZ = 0; if (dicJGBFGQCPYZ.ContainsKey(sTJYZ1[i].Trim())) iYZZ = -9999; if (i == 0) SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ1[i].Trim().Replace("JZ", ""), iYZZ)); else SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ1[i].Trim().Replace("JZ", ""), iYZZ)); bflag = true; } } if (!sTJYSList3.Trim().Equals("")) { for (int i = 0; i < sTJYZ3.Length; i++) { int iYZZ = 0; if (dicJGBFGQCPYZ.ContainsKey(sTJYZ3[i].Trim())) iYZZ = -9999; if (bflag) { SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ3[i].Trim().Replace("JZ", ""), iYZZ)); } else { if (i == 0) SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ3[i].Trim().Replace("JZ", ""), iYZZ)); else SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ3[i].Trim().Replace("JZ", ""), iYZZ)); } bflag = true; } } if (!sTJYSList4.Trim().Equals("")) { for (int i = 0; i < sTJYZ4.Length; i++) { int iYZZ = 0; if (dicJGBFGQCPYZ.ContainsKey(sTJYZ4[i].Trim())) iYZZ = -9999; if (bflag) { SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ4[i].Trim().Replace("JZ", ""), iYZZ)); } else { if (i == 0) SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ4[i].Trim().Replace("JZ", ""), iYZZ)); else SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ4[i].Trim().Replace("JZ", ""), iYZZ)); } bflag = true; } } if (!sTJYSList5.Trim().Equals("")) { for (int i = 0; i < sTJYZ5.Length; i++) { int iYZZ = 0; if (dicJGBFGQCPYZ.ContainsKey(sTJYZ5[i].Trim())) iYZZ = -9999; if (bflag) { SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ5[i].Trim().Replace("JZ", ""), iYZZ)); } else { if (i == 0) SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ5[i].Trim().Replace("JZ", ""), iYZZ)); else SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ5[i].Trim().Replace("JZ", ""), iYZZ)); } bflag = true; } } if (!sTJYSList8.Trim().Equals("")) { for (int i = 0; i < sTJYZ8.Length; i++) { int iYZZ = 0; if (dicJGBFGQCPYZ.ContainsKey(sTJYZ8[i].Trim())) iYZZ = -9999; if (bflag) { SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ8[i].Trim().Replace("JZ", ""), iYZZ)); } else { if (i == 0) SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ8[i].Trim().Replace("JZ", ""), iYZZ)); else SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ8[i].Trim().Replace("JZ", ""), iYZZ)); } bflag = true; } } if (!sTJYSList9.Trim().Equals("")) { for (int i = 0; i < sTJYZ9.Length; i++) { int iYZZ = 0; if (dicJGBFGQCPYZ.ContainsKey(sTJYZ9[i].Trim())) iYZZ = -9999; if (bflag) { SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ9[i].Trim().Replace("JZ", ""), iYZZ)); } else { if (i == 0) SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ9[i].Trim().Replace("JZ", ""), iYZZ)); else SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ9[i].Trim().Replace("JZ", ""), iYZZ)); } bflag = true; } } SQL.Add(" where XLXSJGBYZZ0_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBYZZ0_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and exists(select 1 from XLXSJGBMX"); SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID and XLXSJGBMX_XH=XLXSJGBYZZ0_XH "); SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.Add(" )"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pJGBID").Value = sJGBID; Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-清空TJYS<>' '的调价因子值-begin")); dberp.ExecSQL(SQL); Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-清空TJYS<>' '的调价因子值-end")); } int VID = CMISproDataBase.NewID("DBERP", "V_XLXSBJTJ"); DateTime TimeStamp = MISproUtils.GetServerTime(); //自动插入TJYS=1的调价因子值 if (!sTJYSList1.Trim().Equals("")) { string[] sTJYZ = sTJYSList1.Split(','); for (int i = 0; i < sTJYZ.Length; i++) { if (!sTJYZ[i].Trim().Equals("")) { TZYZXX yzxx = XLBJDUtils.GetYZXXByYZID(sTJYZ[i].Trim()); /* merge into 目标表 a using 源表 b on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……) when matched then update set a.更新字段=b.字段 when not matched then insert into a(字段1,字段2……)values(值1,值2……) */ SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ1_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add(" ,XLXSJGBYZZ1 "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" and XLXSJGBYZZ1_JGBID=:pTJJGBID and XLXSJGBYZZ1_YZID=:pYZID "); SQL.Add(" and XLXSJGBYZZ1_XLXHID=XLXSJGBMX_XLXHID and XLXSJGBYZZ1_XLGGID=XLXSJGBMX_XLGGID and XLXSJGBYZZ1_XLBZID=' ' and XLXSJGBYZZ1_DYDJID=XLXSJGBMX_DYDJID "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-TJYS=1-begin")); dberp.ExecSQL(SQL); Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-TJYS=1-end")); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ1_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX,XLXSJGBYZZ1 "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBYZZ1_XLXHID and XLXSCLQD_XLGGID=XLXSJGBYZZ1_XLGGID and XLXSCLQD_XLBZID=XLXSJGBYZZ1_XLBZID and XLXSCLQD_DYDJID=XLXSJGBYZZ1_DYDJID "); } SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" and XLXSJGBYZZ1_JGBID=:pTJJGBID and XLXSJGBYZZ1_YZID=:pYZID "); SQL.Add(" and XLXSJGBYZZ1_XLXHID=XLXSJGBMX_XLXHID and XLXSJGBYZZ1_XLGGID=XLXSJGBMX_XLGGID and XLXSJGBYZZ1_XLBZID=XLXSJGBMX_XLBZID and XLXSJGBYZZ1_DYDJID=XLXSJGBMX_DYDJID "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-TJYS=1-begin")); dberp.ExecSQL(SQL); Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-TJYS=1-end")); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); } } } //自动插入TJYS=3的调价因子值 if (!sTJYSList3.Trim().Equals("")) { string[] sTJYZ = sTJYSList3.Split(','); SQL.Clear(); SQL.Add("select XLXSJGB_XSQYIDS from XLXSJGB where XLXSJGB_MXBH=:pMXBH and XLXSJGB_JGBID=:pJGBID"); SQL.ParamByName("pMXBH").Value = sMXBH; SQL.ParamByName("pJGBID").Value = sJGBID; DataSet dsJGB = dberp.OpenDataSet(SQL); string sXSQYIDS = dsJGB.Tables[0].Rows[0][0].ToString().Trim(); sXSQYIDS = sXSQYIDS.Split(',')[0].Trim();//只取第一个区域设置的因子值 for (int i = 0; i < sTJYZ.Length; i++) { if (!sTJYZ[i].Trim().Equals("")) { SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add("select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH "); SQL.Add(string.Format(",isnull(YZZ,0) as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add("left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join "); SQL.Add("( "); SQL.Add(" select XLXSJGBYZZ3_XSQYID as XSQYID,XLXSJGBYZZ3_DTCLID as DTCLID,XLXSJGBYZZ3_YZID as YZID,XLXSJGBYZZ3_YZZ as YZZ"); SQL.Add(" from XLXSJGBYZZ3,XLXSTZYZ"); SQL.Add(" where XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_TJYS='3' and XLXSJGBYZZ3_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ3_YZID=XLXSTZYZ_YZID"); //型号、主芯截面都没有匹配 SQL.Add(" and XLXSJGBYZZ3_XLXHID=' '"); SQL.Add(" and XLXSJGBYZZ3_ZXJM=0"); SQL.Add(" and XLXSJGBYZZ3_XSQYID='" + sXSQYIDS + "'"); SQL.Add(" and XLXSJGBYZZ3_YZID=:pYZID"); SQL.Add(" ) a on a.DTCLID=XLXHB_DTCLID"); SQL.Add("where XLXSJGBMX_JGBID=:pJGBID and isnull(YZID,' ')<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add("select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH "); SQL.Add(string.Format(",isnull(YZZ,0) as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add("left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB1 on XLXSBJXLGGTHB_JGB1.XLXSBJXLGGTHB_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add("left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB1.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add("left join "); SQL.Add("( "); SQL.Add(" select XLXSJGBYZZ3_XSQYID as XSQYID,XLXSJGBYZZ3_DTCLID as DTCLID,XLXSJGBYZZ3_ZXJM as ZXJM,XLXSJGBYZZ3_YZID as YZID,XLXSJGBYZZ3_YZZ as YZZ"); SQL.Add(" from XLXSJGBYZZ3,XLXSTZYZ"); SQL.Add(" where XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_TJYS='3' and XLXSJGBYZZ3_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ3_YZID=XLXSTZYZ_YZID"); //主芯截面完全匹配 SQL.Add(" and XLXSJGBYZZ3_XLXHID=' ' "); SQL.Add(" and XLXSJGBYZZ3_ZXJM<>0 "); SQL.Add(" and XLXSJGBYZZ3_XSQYID='" + sXSQYIDS + "'"); SQL.Add(" and XLXSJGBYZZ3_YZID=:pYZID"); SQL.Add(" ) a on a.DTCLID=XLXHB_DTCLID"); SQL.Add(" and ((convert(char,a.ZXJM)=XLGGB_DTJMZHID) or (XLGGB_DTJMZHID like (rtrim(convert(char,a.ZXJM))||'/%'))) "); SQL.Add("where XLXSJGBMX_JGBID=:pJGBID and isnull(YZID,' ')<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add("select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH "); SQL.Add(string.Format(",isnull(YZZ,0) as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add("left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join "); SQL.Add("( "); SQL.Add(" select XLXSJGBYZZ3_XSQYID as XSQYID,XLXSJGBYZZ3_DTCLID as DTCLID,XLXSJGBYZZ3_XLXHID as XLXHID,XLXSJGBYZZ3_YZID as YZID,XLXSJGBYZZ3_YZZ as YZZ"); SQL.Add(" from XLXSJGBYZZ3,XLXSTZYZ"); SQL.Add(" where XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_TJYS='3' and XLXSJGBYZZ3_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ3_YZID=XLXSTZYZ_YZID"); //型号完全匹配 SQL.Add(" and XLXSJGBYZZ3_ZXJM=0"); SQL.Add(" and XLXSJGBYZZ3_XSQYID='" + sXSQYIDS + "'"); SQL.Add(" and XLXSJGBYZZ3_YZID=:pYZID"); SQL.Add(" ) a on a.DTCLID=XLXHB_DTCLID"); SQL.Add(" and a.XLXHID=XLXSJGBMX_XLXHID"); SQL.Add("where XLXSJGBMX_JGBID=:pJGBID and isnull(YZID,' ')<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add("select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH "); SQL.Add(string.Format(",isnull(YZZ,0) as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add("left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB2 on XLXSBJXLGGTHB_JGB2.XLXSBJXLGGTHB_XLGGID = XLXSJGBMX_XLGGID left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB2.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add("left join "); SQL.Add("( "); SQL.Add(" select XLXSJGBYZZ3_XSQYID as XSQYID,XLXSJGBYZZ3_DTCLID as DTCLID,XLXSJGBYZZ3_XLXHID as XLXHID,XLXSJGBYZZ3_ZXJM as ZXJM,XLXSJGBYZZ3_YZID as YZID,XLXSJGBYZZ3_YZZ as YZZ"); SQL.Add(" from XLXSJGBYZZ3,XLXSTZYZ"); SQL.Add(" where XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_TJYS='3' and XLXSJGBYZZ3_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ3_YZID=XLXSTZYZ_YZID"); //型号、主芯截面完全匹配 SQL.Add(" and XLXSJGBYZZ3_ZXJM<>0 "); SQL.Add(" and XLXSJGBYZZ3_XSQYID='" + sXSQYIDS + "'"); SQL.Add(" and XLXSJGBYZZ3_YZID=:pYZID"); SQL.Add(" ) a on a.DTCLID=XLXHB_DTCLID"); SQL.Add(" and a.XLXHID=XLXSJGBMX_XLXHID"); SQL.Add(" and ((convert(char,a.ZXJM)=XLGGB_DTJMZHID) or (XLGGB_DTJMZHID like (rtrim(convert(char,a.ZXJM))||'/%'))) "); //SQL.Add(" and ((to_char(a.ZXJM)=XLGGB_DTJMZHID) or (XLGGB_DTJMZHID like (rtrim(to_char(a.ZXJM))||'/%'))) "); SQL.Add("where XLXSJGBMX_JGBID=:pJGBID and isnull(YZID,' ')<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); } } } //自动插入TJYS=4的调价因子值 if (!sTJYSList4.Trim().Equals("")) { string[] sTJYZ = sTJYSList4.Split(','); for (int i = 0; i < sTJYZ.Length; i++) { if (!sTJYZ[i].Trim().Equals("")) { TZYZXX yzxx = XLBJDUtils.GetYZXXByYZID(sTJYZ[i].Trim()); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID,XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ4_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add("left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB3 on XLXSBJXLGGTHB_JGB3.XLXSBJXLGGTHB_XLGGID = XLXSJGBMX_XLGGID left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB3.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add("left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" left join ( "); SQL.Add(" select XLXSJGBYZZ4_XLXHID,XLXSJGBYZZ4_DYDJID,XLXSJGBYZZ4_XXJGID,XLXSJGBYZZ4_ZXJMXX,XLXSJGBYZZ4_ZXJMSX,XLXSJGBYZZ4_YZZ "); SQL.Add(" from XLXSJGBYZZ4 "); SQL.Add(" where XLXSJGBYZZ4_JGBID=:pTJJGBID and XLXSJGBYZZ4_YZID=:pYZID "); //1、优先级由低到高依次更新:电压、芯线结构为空 SQL.Add(" and XLXSJGBYZZ4_DYDJID=' '"); SQL.Add(" and XLXSJGBYZZ4_XXJGID=' ' "); SQL.Add(" ) a "); SQL.Add(" on XLXSJGBYZZ4_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" and XLXSJGBYZZ4_ZXJMXX<= ISNULL(XLDTJMZHB_DTJM1,0) and ((XLXSJGBYZZ4_ZXJMSX<>0 and XLXSJGBYZZ4_ZXJMSX>=ISNULL(XLDTJMZHB_DTJM1,0)) or XLXSJGBYZZ4_ZXJMSX=0)"); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID and XLXSJGBYZZ4_XLXHID<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID,XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ4_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add("left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB4 on XLXSBJXLGGTHB_JGB4.XLXSBJXLGGTHB_XLGGID = XLXSJGBMX_XLGGID left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB4.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add("left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" left join ( "); SQL.Add(" select XLXSJGBYZZ4_XLXHID,XLXSJGBYZZ4_DYDJID,XLXSJGBYZZ4_XXJGID,XLXSJGBYZZ4_ZXJMXX,XLXSJGBYZZ4_ZXJMSX,XLXSJGBYZZ4_YZZ "); SQL.Add(" from XLXSJGBYZZ4 "); SQL.Add(" where XLXSJGBYZZ4_JGBID=:pTJJGBID and XLXSJGBYZZ4_YZID=:pYZID "); //2、优先级由低到高依次更新:电压为空、芯线结构不为空 SQL.Add(" and XLXSJGBYZZ4_DYDJID=' '"); SQL.Add(" ) a "); SQL.Add(" on XLXSJGBYZZ4_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" and XLXSJGBYZZ4_ZXJMXX<= ISNULL(XLDTJMZHB_DTJM1,0) and ((XLXSJGBYZZ4_ZXJMSX<>0 and XLXSJGBYZZ4_ZXJMSX>=ISNULL(XLDTJMZHB_DTJM1,0)) or XLXSJGBYZZ4_ZXJMSX=0)"); SQL.Add(" and XLXSJGBYZZ4_XXJGID=XLGGB_XXJGID "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID and XLXSJGBYZZ4_XLXHID<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID,XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ4_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add(" left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB7 on XLXSBJXLGGTHB_JGB7.XLXSBJXLGGTHB_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add("left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB7.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add("left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" left join ( "); SQL.Add(" select XLXSJGBYZZ4_XLXHID,XLXSJGBYZZ4_DYDJID,XLXSJGBYZZ4_XXJGID,XLXSJGBYZZ4_ZXJMXX,XLXSJGBYZZ4_ZXJMSX,XLXSJGBYZZ4_YZZ "); SQL.Add(" from XLXSJGBYZZ4 "); SQL.Add(" where XLXSJGBYZZ4_JGBID=:pTJJGBID and XLXSJGBYZZ4_YZID=:pYZID "); //3、优先级由低到高依次更新:电压不为空、芯线结构为空 SQL.Add(" and XLXSJGBYZZ4_XXJGID=' '"); SQL.Add(" ) a "); SQL.Add(" on XLXSJGBYZZ4_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" and XLXSJGBYZZ4_ZXJMXX<= ISNULL(XLDTJMZHB_DTJM1,0) and ((XLXSJGBYZZ4_ZXJMSX<>0 and XLXSJGBYZZ4_ZXJMSX>=ISNULL(XLDTJMZHB_DTJM1,0)) or XLXSJGBYZZ4_ZXJMSX=0)"); SQL.Add(" and XLXSJGBYZZ4_DYDJID=XLXSJGBMX_DYDJID "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID and XLXSJGBYZZ4_XLXHID<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID,XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ4_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add(" left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB8 on XLXSBJXLGGTHB_JGB8.XLXSBJXLGGTHB_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add(" left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB8.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add(" left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" left join ( "); SQL.Add(" select XLXSJGBYZZ4_XLXHID,XLXSJGBYZZ4_DYDJID,XLXSJGBYZZ4_XXJGID,XLXSJGBYZZ4_ZXJMXX,XLXSJGBYZZ4_ZXJMSX,XLXSJGBYZZ4_YZZ "); SQL.Add(" from XLXSJGBYZZ4 "); SQL.Add(" where XLXSJGBYZZ4_JGBID=:pTJJGBID and XLXSJGBYZZ4_YZID=:pYZID "); //4、优先级由低到高依次更新:电压不为空、芯线结构不为空 SQL.Add(" ) a "); SQL.Add(" on XLXSJGBYZZ4_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" and XLXSJGBYZZ4_ZXJMXX<= ISNULL(XLDTJMZHB_DTJM1,0) and ((XLXSJGBYZZ4_ZXJMSX<>0 and XLXSJGBYZZ4_ZXJMSX>=ISNULL(XLDTJMZHB_DTJM1,0)) or XLXSJGBYZZ4_ZXJMSX=0)"); SQL.Add(" and XLXSJGBYZZ4_DYDJID=XLXSJGBMX_DYDJID "); SQL.Add(" and XLXSJGBYZZ4_XXJGID=XLGGB_XXJGID"); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID and XLXSJGBYZZ4_XLXHID<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); } } } //自动插入TJYS=5的调价因子值 if (!sTJYSList5.Trim().Equals("")) { string[] sTJYZ = sTJYSList5.Split(','); for (int i = 0; i < sTJYZ.Length; i++) { if (!sTJYZ[i].Trim().Equals("")) { SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID,XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ5_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSTZYZ,XLXSJGBYZZ5,XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add(" left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB9 on XLXSBJXLGGTHB_JGB9.XLXSBJXLGGTHB_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add(" left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB9.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add(" left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.Add(" and XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_YZID=:pYZID"); SQL.Add(" and XLXSTZYZ_TJYS='5' and XLXSJGBYZZ5_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ5_YZID=XLXSTZYZ_YZID "); SQL.Add(" and XLXSJGBYZZ5_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" and XLXSJGBYZZ5_ZXJMXX<=ISNULL(XLDTJMZHB_DTJM1,0) and ((XLXSJGBYZZ5_ZXJMSX<>0 and XLXSJGBYZZ5_ZXJMSX>=ISNULL(XLDTJMZHB_DTJM1,0)) or XLXSJGBYZZ5_ZXJMSX=0)"); SQL.Add(" and XLXSJGBYZZ5_ZXSXX<=XLGGB_GGZXS and ((XLXSJGBYZZ5_ZXSSX<>0 and XLXSJGBYZZ5_ZXSSX>=XLGGB_GGZXS) or XLXSJGBYZZ5_ZXSSX=0)"); //1、优先级由低到高依次更新:电压为空 SQL.Add(" and XLXSJGBYZZ5_DYDJID=' '"); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID,XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ5_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSTZYZ,XLXSJGBYZZ5,XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add("left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB10 on XLXSBJXLGGTHB_JGB10.XLXSBJXLGGTHB_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add("left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB10.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add("left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.Add(" and XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_YZID=:pYZID"); SQL.Add(" and XLXSTZYZ_TJYS='5' and XLXSJGBYZZ5_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ5_YZID=XLXSTZYZ_YZID "); SQL.Add(" and XLXSJGBYZZ5_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" and XLXSJGBYZZ5_ZXJMXX<=ISNULL(XLDTJMZHB_DTJM1,0) and ((XLXSJGBYZZ5_ZXJMSX<>0 and XLXSJGBYZZ5_ZXJMSX>=ISNULL(XLDTJMZHB_DTJM1,0)) or XLXSJGBYZZ5_ZXJMSX=0)"); SQL.Add(" and XLXSJGBYZZ5_ZXSXX<=XLGGB_GGZXS and ((XLXSJGBYZZ5_ZXSSX<>0 and XLXSJGBYZZ5_ZXSSX>=XLGGB_GGZXS) or XLXSJGBYZZ5_ZXSSX=0)"); //2、优先级由低到高依次更新:电压不为空 SQL.Add(" and XLXSJGBYZZ5_DYDJID=XLXSJGBMX_DYDJID "); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); } } } //自动插入TJYS=8的调价因子值 if (!sTJYSList8.Trim().Equals("")) { string[] sTJYZ = sTJYSList8.Split(','); for (int i = 0; i < sTJYZ.Length; i++) { if (!sTJYZ[i].Trim().Equals("")) { SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID,XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",ISNULL(XLXSJGBYZZ8_YZZ * XLXSCLQD_CLZL/1000,0) as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX,XLXSTZYZ,XLXSJGBYZZ8 "); SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBYZZ8_XLXHID and XLXSCLQD_XLGGID=XLXSJGBYZZ8_XLGGID and XLXSCLQD_XLBZID=XLXSJGBYZZ8_XLBZID and XLXSCLQD_DYDJID=XLXSJGBYZZ8_DYDJID "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" and XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_YZID=:pYZID"); SQL.Add(" and XLXSTZYZ_TJYS='8' and XLXSJGBYZZ8_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ8_YZID=XLXSTZYZ_YZID "); SQL.Add(" and XLXSJGBYZZ8_XLXHID=XLXSJGBMX_XLXHID and XLXSJGBYZZ8_XLGGID=XLXSJGBMX_XLGGID and XLXSJGBYZZ8_XLBZID=XLXSJGBMX_XLBZID and XLXSJGBYZZ8_DYDJID=XLXSJGBMX_DYDJID "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); } } } //自动插入TJYS=9的调价因子值 if (!sTJYSList9.Trim().Equals("")) { string[] sTJYZ = sTJYSList9.Split(','); for (int i = 0; i < sTJYZ.Length; i++) { if (!sTJYZ[i].Trim().Equals("")) { TZYZXX yzxx = XLBJDUtils.GetYZXXByYZID(sTJYZ[i].Trim()); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ9_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add(" ,XLXSJGBYZZ9 "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" and XLXSJGBYZZ9_JGBID=:pTJJGBID and XLXSJGBYZZ9_YZID=:pYZID "); SQL.Add(" and XLXSJGBYZZ9_XLXHID=XLXSJGBMX_XLXHID and XLXSJGBYZZ9_XLGGID=XLXSJGBMX_XLGGID and XLXSJGBYZZ9_DYDJID=XLXSJGBMX_DYDJID "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ9_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX,XLXSJGBYZZ9 "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBYZZ9_XLXHID and XLXSCLQD_XLGGID=XLXSJGBYZZ9_XLGGID and XLXSCLQD_DYDJID=XLXSJGBYZZ9_DYDJID "); } SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" and XLXSJGBYZZ9_JGBID=:pTJJGBID and XLXSJGBYZZ9_YZID=:pYZID "); SQL.Add(" and XLXSJGBYZZ9_XLXHID=XLXSJGBMX_XLXHID and XLXSJGBYZZ9_XLGGID=XLXSJGBMX_XLGGID and XLXSJGBYZZ9_DYDJID=XLXSJGBMX_DYDJID "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); } } } } //sTJYSList1:记录调价因素不为空的因子id //sTJYSList_:记录调价因素为空的因子id public static void AddXLXSJGBYZZ0(TDatabase dberp, string sMXBH, string sJGBID, string sTJYSList_, string sTJYSList1, string sTJYSList3, string sTJYSList4, string sTJYSList5, string sTJYSList8, string sTJYSList9, bool bInsertXLXSJGBYZZ0, string sJGCZBID, string sJGCZBBBID, double maxXH, string sBJU003) { CMISproSession tSession = CMISproApp.GetSession(); string sJJYZIDList = string.Empty; Dictionary dicLenJLDWTD = XLBJDUtils.GetLenJLDWTD(); TSQL SQL = new TSQL(dberp); //插入XLXSJGBMX记录后需要自动补齐XLXSJGBYZZ0记录 if (bInsertXLXSJGBYZZ0) { Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-InsXLXSJGBYZZ0-Begin")); //如果存在调价因素为空的因子 if (!sTJYSList_.Trim().Equals("")) { string[] sTJYZs = sTJYSList_.Split(','); SQL.Clear(); SQL.Add("insert into XLXSJGBYZZ0(XLXSJGBYZZ0_JGBID,XLXSJGBYZZ0_XH"); for (int i = 0; i < sTJYZs.Length; i++) { if (XLBJDUtils.GetYZXXByYZID(sTJYZs[i].Trim()).XLXSTZYZ_JJFS == "JJ") sJJYZIDList += sTJYZs[i].Trim() + ","; SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}", sTJYZs[i].Trim().Replace("JZ", ""))); } SQL.Add(") "); SQL.Add("select XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); for (int i = 0; i < sTJYZs.Length; i++) { SQL.Add(string.Format(",sum(CASE XLXSTZYZ_YZID WHEN '{0}' THEN XLXSJGBYZZ_YZZ ELSE 0 END) as YZZ{1}", sTJYZs[i].Trim(), sTJYZs[i].Trim().Replace("JZ", ""))); } SQL.Add(" from XLXSJGBMX,XLXSTZYZ,XLXSJGBYZZ "); SQL.Add("where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add("and XLXSTZYZ_MXBH='JZJ' and " + CMISproDataBase.GetWhereEqual("XLXSTZYZ_YZID", sTJYSList_.Trim())); SQL.Add("and XLXSTZYZ_TJYS=' ' and XLXSJGBYZZ_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ_YZID=XLXSTZYZ_YZID "); SQL.Add("and not exists "); SQL.Add("( "); SQL.Add("select 1 "); SQL.Add("from XLXSJGBYZZ0 "); SQL.Add("where XLXSJGBYZZ0_JGBID=:pJGBID "); SQL.Add("and XLXSJGBYZZ0_XH=XLXSJGBMX_XH "); SQL.Add(") "); SQL.Add(" group by XLXSJGBMX_JGBID,XLXSJGBMX_XH,XLXSJGBMX_JLDW"); SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-InsXLXSJGBYZZ0-调价因素为空1-end")); } else { SQL.Clear(); SQL.Add("insert into XLXSJGBYZZ0(XLXSJGBYZZ0_JGBID,XLXSJGBYZZ0_XH) "); SQL.Add("select XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(" from XLXSJGBMX "); SQL.Add("where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add("and not exists "); SQL.Add("( "); SQL.Add("select 1 "); SQL.Add("from XLXSJGBYZZ0 "); SQL.Add("where XLXSJGBYZZ0_JGBID=:pJGBID "); SQL.Add("and XLXSJGBYZZ0_XH=XLXSJGBMX_XH "); SQL.Add(") "); SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-InsXLXSJGBYZZ0-调价因素为空2-end")); } } //先清空TJYS<>' '的调价因子值 if (!sTJYSList1.Trim().Equals("") || !sTJYSList3.Trim().Equals("") || !sTJYSList4.Trim().Equals("") || !sTJYSList5.Trim().Equals("") || !sTJYSList8.Trim().Equals("") || !sTJYSList9.Trim().Equals("")) { Dictionary dicJGBFGQCPYZ = XLBJDInfo.GetJGBFGQCPYZ(sJGBID); string[] sTJYZ1 = sTJYSList1.Split(','); string[] sTJYZ3 = sTJYSList3.Split(','); string[] sTJYZ4 = sTJYSList4.Split(','); string[] sTJYZ5 = sTJYSList5.Split(','); string[] sTJYZ8 = sTJYSList8.Split(','); string[] sTJYZ9 = sTJYSList9.Split(','); bool bflag = false; SQL.Clear(); SQL.Add("update XLXSJGBYZZ0 set "); if (!sTJYSList1.Trim().Equals("")) { for (int i = 0; i < sTJYZ1.Length; i++) { int iYZZ = 0; if (dicJGBFGQCPYZ.ContainsKey(sTJYZ1[i].Trim())) iYZZ = -9999; if (i == 0) SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ1[i].Trim().Replace("JZ", ""), iYZZ)); else SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ1[i].Trim().Replace("JZ", ""), iYZZ)); bflag = true; } } if (!sTJYSList3.Trim().Equals("")) { for (int i = 0; i < sTJYZ3.Length; i++) { int iYZZ = 0; if (dicJGBFGQCPYZ.ContainsKey(sTJYZ3[i].Trim())) iYZZ = -9999; if (bflag) { SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ3[i].Trim().Replace("JZ", ""), iYZZ)); } else { if (i == 0) SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ3[i].Trim().Replace("JZ", ""), iYZZ)); else SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ3[i].Trim().Replace("JZ", ""), iYZZ)); } bflag = true; } } if (!sTJYSList4.Trim().Equals("")) { for (int i = 0; i < sTJYZ4.Length; i++) { int iYZZ = 0; if (dicJGBFGQCPYZ.ContainsKey(sTJYZ4[i].Trim())) iYZZ = -9999; if (bflag) { SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ4[i].Trim().Replace("JZ", ""), iYZZ)); } else { if (i == 0) SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ4[i].Trim().Replace("JZ", ""), iYZZ)); else SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ4[i].Trim().Replace("JZ", ""), iYZZ)); } bflag = true; } } if (!sTJYSList5.Trim().Equals("")) { for (int i = 0; i < sTJYZ5.Length; i++) { int iYZZ = 0; if (dicJGBFGQCPYZ.ContainsKey(sTJYZ5[i].Trim())) iYZZ = -9999; if (bflag) { SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ5[i].Trim().Replace("JZ", ""), iYZZ)); } else { if (i == 0) SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ5[i].Trim().Replace("JZ", ""), iYZZ)); else SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ5[i].Trim().Replace("JZ", ""), iYZZ)); } bflag = true; } } if (!sTJYSList8.Trim().Equals("")) { for (int i = 0; i < sTJYZ8.Length; i++) { int iYZZ = 0; if (dicJGBFGQCPYZ.ContainsKey(sTJYZ8[i].Trim())) iYZZ = -9999; if (bflag) { SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ8[i].Trim().Replace("JZ", ""), iYZZ)); } else { if (i == 0) SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ8[i].Trim().Replace("JZ", ""), iYZZ)); else SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ8[i].Trim().Replace("JZ", ""), iYZZ)); } bflag = true; } } if (!sTJYSList9.Trim().Equals("")) { for (int i = 0; i < sTJYZ9.Length; i++) { int iYZZ = 0; if (dicJGBFGQCPYZ.ContainsKey(sTJYZ9[i].Trim())) iYZZ = -9999; if (bflag) { SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ9[i].Trim().Replace("JZ", ""), iYZZ)); } else { if (i == 0) SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ9[i].Trim().Replace("JZ", ""), iYZZ)); else SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}={1}", sTJYZ9[i].Trim().Replace("JZ", ""), iYZZ)); } bflag = true; } } SQL.Add(" where XLXSJGBYZZ0_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBYZZ0_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and exists(select 1 from XLXSJGBMX"); SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID and XLXSJGBMX_XH=XLXSJGBYZZ0_XH "); SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.Add(" )"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pJGBID").Value = sJGBID; Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-清空TJYS<>' '的调价因子值-begin")); dberp.ExecSQL(SQL); Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-清空TJYS<>' '的调价因子值-end")); } int VID = CMISproDataBase.NewID("DBERP", "V_XLXSBJTJ"); DateTime TimeStamp = MISproUtils.GetServerTime(); //自动插入TJYS=1的调价因子值 if (!sTJYSList1.Trim().Equals("")) { string[] sTJYZ = sTJYSList1.Split(','); for (int i = 0; i < sTJYZ.Length; i++) { if (!sTJYZ[i].Trim().Equals("")) { TZYZXX yzxx = XLBJDUtils.GetYZXXByYZID(sTJYZ[i].Trim()); if (yzxx.XLXSTZYZ_JJFS == "JJ") sJJYZIDList += sTJYZ[i].Trim() + ","; SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ1_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add(" ,XLXSJGBYZZ1 "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" and XLXSJGBYZZ1_JGBID=:pTJJGBID and XLXSJGBYZZ1_YZID=:pYZID "); SQL.Add(" and XLXSJGBYZZ1_XLXHID=XLXSJGBMX_XLXHID and XLXSJGBYZZ1_XLGGID=XLXSJGBMX_XLGGID and XLXSJGBYZZ1_XLBZID=' ' and XLXSJGBYZZ1_DYDJID=XLXSJGBMX_DYDJID "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ1_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX,XLXSJGBYZZ1 "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBYZZ1_XLXHID and XLXSCLQD_XLGGID=XLXSJGBYZZ1_XLGGID and XLXSCLQD_XLBZID=XLXSJGBYZZ1_XLBZID and XLXSCLQD_DYDJID=XLXSJGBYZZ1_DYDJID "); } SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" and XLXSJGBYZZ1_JGBID=:pTJJGBID and XLXSJGBYZZ1_YZID=:pYZID "); SQL.Add(" and XLXSJGBYZZ1_XLXHID=XLXSJGBMX_XLXHID and XLXSJGBYZZ1_XLGGID=XLXSJGBMX_XLGGID and XLXSJGBYZZ1_XLBZID=XLXSJGBMX_XLBZID and XLXSJGBYZZ1_DYDJID=XLXSJGBMX_DYDJID "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); } } } //自动插入TJYS=3的调价因子值 if (!sTJYSList3.Trim().Equals("")) { string[] sTJYZ = sTJYSList3.Split(','); SQL.Clear(); SQL.Add("select XLXSJGB_XSQYIDS from XLXSJGB where XLXSJGB_MXBH=:pMXBH and XLXSJGB_JGBID=:pJGBID"); SQL.ParamByName("pMXBH").Value = sMXBH; SQL.ParamByName("pJGBID").Value = sJGBID; DataSet dsJGB = dberp.OpenDataSet(SQL); string sXSQYIDS = dsJGB.Tables[0].Rows[0][0].ToString().Trim(); sXSQYIDS = sXSQYIDS.Split(',')[0].Trim();//只取第一个区域设置的因子值 for (int i = 0; i < sTJYZ.Length; i++) { if (!sTJYZ[i].Trim().Equals("")) { TZYZXX yzxx = XLBJDUtils.GetYZXXByYZID(sTJYZ[i].Trim()); if (yzxx.XLXSTZYZ_JJFS == "JJ") sJJYZIDList += sTJYZ[i].Trim() + ","; SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add("select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH "); SQL.Add(string.Format(",isnull(YZZ,0) as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add("left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join "); SQL.Add("( "); SQL.Add(" select XLXSJGBYZZ3_XSQYID as XSQYID,XLXSJGBYZZ3_DTCLID as DTCLID,XLXSJGBYZZ3_YZID as YZID,XLXSJGBYZZ3_YZZ as YZZ"); SQL.Add(" from XLXSJGBYZZ3,XLXSTZYZ"); SQL.Add(" where XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_TJYS='3' and XLXSJGBYZZ3_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ3_YZID=XLXSTZYZ_YZID"); //型号、主芯截面都没有匹配 SQL.Add(" and XLXSJGBYZZ3_XLXHID=' '"); SQL.Add(" and XLXSJGBYZZ3_ZXJM=0"); SQL.Add(" and XLXSJGBYZZ3_XSQYID='" + sXSQYIDS + "'"); SQL.Add(" and XLXSJGBYZZ3_YZID=:pYZID"); SQL.Add(" ) a on a.DTCLID=XLXHB_DTCLID"); SQL.Add("where XLXSJGBMX_JGBID=:pJGBID and isnull(YZID,' ')<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add("select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH "); SQL.Add(string.Format(",isnull(YZZ,0) as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add("left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB11 on XLXSBJXLGGTHB_JGB11.XLXSBJXLGGTHB_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add("left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB11.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add("left join "); SQL.Add("( "); SQL.Add(" select XLXSJGBYZZ3_XSQYID as XSQYID,XLXSJGBYZZ3_DTCLID as DTCLID,XLXSJGBYZZ3_ZXJM as ZXJM,XLXSJGBYZZ3_YZID as YZID,XLXSJGBYZZ3_YZZ as YZZ"); SQL.Add(" from XLXSJGBYZZ3,XLXSTZYZ"); SQL.Add(" where XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_TJYS='3' and XLXSJGBYZZ3_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ3_YZID=XLXSTZYZ_YZID"); //主芯截面完全匹配 SQL.Add(" and XLXSJGBYZZ3_XLXHID=' ' "); SQL.Add(" and XLXSJGBYZZ3_ZXJM<>0 "); SQL.Add(" and XLXSJGBYZZ3_XSQYID='" + sXSQYIDS + "'"); SQL.Add(" and XLXSJGBYZZ3_YZID=:pYZID"); SQL.Add(" ) a on a.DTCLID=XLXHB_DTCLID"); SQL.Add(" and ((convert(char,a.ZXJM)=XLGGB_DTJMZHID) or (XLGGB_DTJMZHID like (rtrim(convert(char,a.ZXJM))||'/%'))) "); SQL.Add("where XLXSJGBMX_JGBID=:pJGBID and isnull(YZID,' ')<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add("select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH "); SQL.Add(string.Format(",isnull(YZZ,0) as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add("left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join "); SQL.Add("( "); SQL.Add(" select XLXSJGBYZZ3_XSQYID as XSQYID,XLXSJGBYZZ3_DTCLID as DTCLID,XLXSJGBYZZ3_XLXHID as XLXHID,XLXSJGBYZZ3_YZID as YZID,XLXSJGBYZZ3_YZZ as YZZ"); SQL.Add(" from XLXSJGBYZZ3,XLXSTZYZ"); SQL.Add(" where XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_TJYS='3' and XLXSJGBYZZ3_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ3_YZID=XLXSTZYZ_YZID"); //型号完全匹配 SQL.Add(" and XLXSJGBYZZ3_ZXJM=0"); SQL.Add(" and XLXSJGBYZZ3_XSQYID='" + sXSQYIDS + "'"); SQL.Add(" and XLXSJGBYZZ3_YZID=:pYZID"); SQL.Add(" ) a on a.DTCLID=XLXHB_DTCLID"); SQL.Add(" and a.XLXHID=XLXSJGBMX_XLXHID"); SQL.Add("where XLXSJGBMX_JGBID=:pJGBID and isnull(YZID,' ')<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add("select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH "); SQL.Add(string.Format(",isnull(YZZ,0) as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add("left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB12 on XLXSBJXLGGTHB_JGB12.XLXSBJXLGGTHB_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add("left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB12.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add("left join "); SQL.Add("( "); SQL.Add(" select XLXSJGBYZZ3_XSQYID as XSQYID,XLXSJGBYZZ3_DTCLID as DTCLID,XLXSJGBYZZ3_XLXHID as XLXHID,XLXSJGBYZZ3_ZXJM as ZXJM,XLXSJGBYZZ3_YZID as YZID,XLXSJGBYZZ3_YZZ as YZZ"); SQL.Add(" from XLXSJGBYZZ3,XLXSTZYZ"); SQL.Add(" where XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_TJYS='3' and XLXSJGBYZZ3_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ3_YZID=XLXSTZYZ_YZID"); //型号、主芯截面完全匹配 SQL.Add(" and XLXSJGBYZZ3_ZXJM<>0 "); SQL.Add(" and XLXSJGBYZZ3_XSQYID='" + sXSQYIDS + "'"); SQL.Add(" and XLXSJGBYZZ3_YZID=:pYZID"); SQL.Add(" ) a on a.DTCLID=XLXHB_DTCLID"); SQL.Add(" and a.XLXHID=XLXSJGBMX_XLXHID"); SQL.Add(" and ((convert(char,a.ZXJM)=XLGGB_DTJMZHID) or (XLGGB_DTJMZHID like (rtrim(convert(char,a.ZXJM))||'/%'))) "); //SQL.Add(" and ((to_char(a.ZXJM)=XLGGB_DTJMZHID) or (XLGGB_DTJMZHID like (rtrim(to_char(a.ZXJM))||'/%'))) "); SQL.Add("where XLXSJGBMX_JGBID=:pJGBID and isnull(YZID,' ')<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); } } } //自动插入TJYS=4的调价因子值 if (!sTJYSList4.Trim().Equals("")) { string[] sTJYZ = sTJYSList4.Split(','); for (int i = 0; i < sTJYZ.Length; i++) { if (!sTJYZ[i].Trim().Equals("")) { TZYZXX yzxx = XLBJDUtils.GetYZXXByYZID(sTJYZ[i].Trim()); if (yzxx.XLXSTZYZ_JJFS == "JJ") sJJYZIDList += sTJYZ[i].Trim() + ","; SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID,XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ4_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add("left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB13 on XLXSBJXLGGTHB_JGB13.XLXSBJXLGGTHB_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add("left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB13.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add("left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" left join ( "); SQL.Add(" select XLXSJGBYZZ4_XLXHID,XLXSJGBYZZ4_DYDJID,XLXSJGBYZZ4_XXJGID,XLXSJGBYZZ4_ZXJMXX,XLXSJGBYZZ4_ZXJMSX,XLXSJGBYZZ4_YZZ "); SQL.Add(" from XLXSJGBYZZ4 "); SQL.Add(" where XLXSJGBYZZ4_JGBID=:pTJJGBID and XLXSJGBYZZ4_YZID=:pYZID "); //1、优先级由低到高依次更新:电压、芯线结构为空 SQL.Add(" and XLXSJGBYZZ4_DYDJID=' '"); SQL.Add(" and XLXSJGBYZZ4_XXJGID=' ' "); SQL.Add(" ) a "); SQL.Add(" on XLXSJGBYZZ4_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" and XLXSJGBYZZ4_ZXJMXX<= ISNULL(XLDTJMZHB_DTJM1,0) and ((XLXSJGBYZZ4_ZXJMSX<>0 and XLXSJGBYZZ4_ZXJMSX>=ISNULL(XLDTJMZHB_DTJM1,0)) or XLXSJGBYZZ4_ZXJMSX=0)"); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID and XLXSJGBYZZ4_XLXHID<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID,XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ4_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add("left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB14 on XLXSBJXLGGTHB_JGB14.XLXSBJXLGGTHB_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add("left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB14.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add("left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" left join ( "); SQL.Add(" select XLXSJGBYZZ4_XLXHID,XLXSJGBYZZ4_DYDJID,XLXSJGBYZZ4_XXJGID,XLXSJGBYZZ4_ZXJMXX,XLXSJGBYZZ4_ZXJMSX,XLXSJGBYZZ4_YZZ "); SQL.Add(" from XLXSJGBYZZ4 "); SQL.Add(" where XLXSJGBYZZ4_JGBID=:pTJJGBID and XLXSJGBYZZ4_YZID=:pYZID "); //2、优先级由低到高依次更新:电压为空、芯线结构不为空 SQL.Add(" and XLXSJGBYZZ4_DYDJID=' '"); SQL.Add(" ) a "); SQL.Add(" on XLXSJGBYZZ4_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" and XLXSJGBYZZ4_ZXJMXX<= ISNULL(XLDTJMZHB_DTJM1,0) and ((XLXSJGBYZZ4_ZXJMSX<>0 and XLXSJGBYZZ4_ZXJMSX>=ISNULL(XLDTJMZHB_DTJM1,0)) or XLXSJGBYZZ4_ZXJMSX=0)"); SQL.Add(" and XLXSJGBYZZ4_XXJGID=XLGGB_XXJGID "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID and XLXSJGBYZZ4_XLXHID<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID,XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ4_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add(" left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB16 on XLXSBJXLGGTHB_JGB16.XLXSBJXLGGTHB_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add("left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB16.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add("left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" left join ( "); SQL.Add(" select XLXSJGBYZZ4_XLXHID,XLXSJGBYZZ4_DYDJID,XLXSJGBYZZ4_XXJGID,XLXSJGBYZZ4_ZXJMXX,XLXSJGBYZZ4_ZXJMSX,XLXSJGBYZZ4_YZZ "); SQL.Add(" from XLXSJGBYZZ4 "); SQL.Add(" where XLXSJGBYZZ4_JGBID=:pTJJGBID and XLXSJGBYZZ4_YZID=:pYZID "); //3、优先级由低到高依次更新:电压不为空、芯线结构为空 SQL.Add(" and XLXSJGBYZZ4_XXJGID=' '"); SQL.Add(" ) a "); SQL.Add(" on XLXSJGBYZZ4_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" and XLXSJGBYZZ4_ZXJMXX<= ISNULL(XLDTJMZHB_DTJM1,0) and ((XLXSJGBYZZ4_ZXJMSX<>0 and XLXSJGBYZZ4_ZXJMSX>=ISNULL(XLDTJMZHB_DTJM1,0)) or XLXSJGBYZZ4_ZXJMSX=0)"); SQL.Add(" and XLXSJGBYZZ4_DYDJID=XLXSJGBMX_DYDJID "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID and XLXSJGBYZZ4_XLXHID<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID,XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ4_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add(" left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB17 on XLXSBJXLGGTHB_JGB17.XLXSBJXLGGTHB_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add(" left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB17.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add(" left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" left join ( "); SQL.Add(" select XLXSJGBYZZ4_XLXHID,XLXSJGBYZZ4_DYDJID,XLXSJGBYZZ4_XXJGID,XLXSJGBYZZ4_ZXJMXX,XLXSJGBYZZ4_ZXJMSX,XLXSJGBYZZ4_YZZ "); SQL.Add(" from XLXSJGBYZZ4 "); SQL.Add(" where XLXSJGBYZZ4_JGBID=:pTJJGBID and XLXSJGBYZZ4_YZID=:pYZID "); //4、优先级由低到高依次更新:电压不为空、芯线结构不为空 SQL.Add(" ) a "); SQL.Add(" on XLXSJGBYZZ4_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" and XLXSJGBYZZ4_ZXJMXX<= ISNULL(XLDTJMZHB_DTJM1,0) and ((XLXSJGBYZZ4_ZXJMSX<>0 and XLXSJGBYZZ4_ZXJMSX>=ISNULL(XLDTJMZHB_DTJM1,0)) or XLXSJGBYZZ4_ZXJMSX=0)"); SQL.Add(" and XLXSJGBYZZ4_DYDJID=XLXSJGBMX_DYDJID "); SQL.Add(" and XLXSJGBYZZ4_XXJGID=XLGGB_XXJGID"); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID and XLXSJGBYZZ4_XLXHID<>' ' "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); } } } //自动插入TJYS=5的调价因子值 if (!sTJYSList5.Trim().Equals("")) { string[] sTJYZ = sTJYSList5.Split(','); for (int i = 0; i < sTJYZ.Length; i++) { if (!sTJYZ[i].Trim().Equals("")) { TZYZXX yzxx = XLBJDUtils.GetYZXXByYZID(sTJYZ[i].Trim()); if (yzxx.XLXSTZYZ_JJFS == "JJ") sJJYZIDList += sTJYZ[i].Trim() + ","; SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID,XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ5_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSTZYZ,XLXSJGBYZZ5,XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add(" left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB18 on XLXSBJXLGGTHB_JGB18.XLXSBJXLGGTHB_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add(" left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB18.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add(" left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.Add(" and XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_YZID=:pYZID"); SQL.Add(" and XLXSTZYZ_TJYS='5' and XLXSJGBYZZ5_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ5_YZID=XLXSTZYZ_YZID "); SQL.Add(" and XLXSJGBYZZ5_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" and XLXSJGBYZZ5_ZXJMXX<=ISNULL(XLDTJMZHB_DTJM1,0) and ((XLXSJGBYZZ5_ZXJMSX<>0 and XLXSJGBYZZ5_ZXJMSX>=ISNULL(XLDTJMZHB_DTJM1,0)) or XLXSJGBYZZ5_ZXJMSX=0)"); SQL.Add(" and XLXSJGBYZZ5_ZXSXX<=XLGGB_GGZXS and ((XLXSJGBYZZ5_ZXSSX<>0 and XLXSJGBYZZ5_ZXSSX>=XLGGB_GGZXS) or XLXSJGBYZZ5_ZXSSX=0)"); //1、优先级由低到高依次更新:电压为空 SQL.Add(" and XLXSJGBYZZ5_DYDJID=' '"); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID,XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ5_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSTZYZ,XLXSJGBYZZ5,XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add("left join XLXHB on XLXHB_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add("left join XLXSBJXLGGTHB XLXSBJXLGGTHB_JGB15 on XLXSBJXLGGTHB_JGB15.XLXSBJXLGGTHB_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add("left join XLGGB on XLGGB_XLGGID = isnull(XLXSBJXLGGTHB_JGB15.XLXSBJXLGGTHB_XLGGIDCH,' ') and XLGGB_XLGGJDGZ = isnull(XLXHB_XLGGJDGZ,'0') "); SQL.Add("left join XLDTJMZHB on XLDTJMZHB_DTJMZHID=XLGGB_DTJMZHID "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.Add(" and XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_YZID=:pYZID"); SQL.Add(" and XLXSTZYZ_TJYS='5' and XLXSJGBYZZ5_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ5_YZID=XLXSTZYZ_YZID "); SQL.Add(" and XLXSJGBYZZ5_XLXHID=XLXSJGBMX_XLXHID "); SQL.Add(" and XLXSJGBYZZ5_ZXJMXX<=ISNULL(XLDTJMZHB_DTJM1,0) and ((XLXSJGBYZZ5_ZXJMSX<>0 and XLXSJGBYZZ5_ZXJMSX>=ISNULL(XLDTJMZHB_DTJM1,0)) or XLXSJGBYZZ5_ZXJMSX=0)"); SQL.Add(" and XLXSJGBYZZ5_ZXSXX<=XLGGB_GGZXS and ((XLXSJGBYZZ5_ZXSSX<>0 and XLXSJGBYZZ5_ZXSSX>=XLGGB_GGZXS) or XLXSJGBYZZ5_ZXSSX=0)"); //2、优先级由低到高依次更新:电压不为空 SQL.Add(" and XLXSJGBYZZ5_DYDJID=XLXSJGBMX_DYDJID "); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); } } } //自动插入TJYS=8的调价因子值 if (!sTJYSList8.Trim().Equals("")) { string[] sTJYZ = sTJYSList8.Split(','); for (int i = 0; i < sTJYZ.Length; i++) { if (!sTJYZ[i].Trim().Equals("")) { SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID,XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH,"); SQL.Add(" case when XLXSJGBMX_JLDW in ('T', '吨') then isnull(XLXSJGBYZZ8_YZZ,0) "); SQL.Add(" when XLXSJGBMX_JLDW in ('Kg', '千克','公斤') then isnull(XLXSJGBYZZ8_YZZ,0)/1000 "); SQL.Add(string.Format(" else ISNULL(XLXSJGBYZZ8_YZZ * XLXSCLQD_CLZL/1000,0) end as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX,XLXSTZYZ,XLXSJGBYZZ8 "); SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBYZZ8_XLXHID and XLXSCLQD_XLGGID=XLXSJGBYZZ8_XLGGID and XLXSCLQD_XLBZID=XLXSJGBYZZ8_XLBZID and XLXSCLQD_DYDJID=XLXSJGBYZZ8_DYDJID "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" and XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_YZID=:pYZID"); SQL.Add(" and XLXSTZYZ_TJYS='8' and XLXSJGBYZZ8_JGBID=XLXSTZYZ_JGBID and XLXSJGBYZZ8_YZID=XLXSTZYZ_YZID "); SQL.Add(" and XLXSJGBYZZ8_XLXHID=XLXSJGBMX_XLXHID and XLXSJGBYZZ8_XLGGID=XLXSJGBMX_XLGGID and XLXSJGBYZZ8_XLBZID=XLXSJGBMX_XLBZID and XLXSJGBYZZ8_DYDJID=XLXSJGBMX_DYDJID "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); } } } //自动插入TJYS=9的调价因子值 if (!sTJYSList9.Trim().Equals("")) { string[] sTJYZ = sTJYSList9.Split(','); for (int i = 0; i < sTJYZ.Length; i++) { if (!sTJYZ[i].Trim().Equals("")) { TZYZXX yzxx = XLBJDUtils.GetYZXXByYZID(sTJYZ[i].Trim()); if (yzxx.XLXSTZYZ_JJFS == "JJ") sJJYZIDList += sTJYZ[i].Trim() + ","; SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ9_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add(" ,XLXSJGBYZZ9 "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" and XLXSJGBYZZ9_JGBID=:pTJJGBID and XLXSJGBYZZ9_YZID=:pYZID "); SQL.Add(" and XLXSJGBYZZ9_XLXHID=XLXSJGBMX_XLXHID and XLXSJGBYZZ9_XLGGID=XLXSJGBMX_XLGGID and XLXSJGBYZZ9_DYDJID=XLXSJGBMX_DYDJID "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into V_XLXSBJTJ(V_XLXSBJTJ_ID,V_XLXSBJTJ_JGBID,V_XLXSBJTJ_XH,V_XLXSBJTJ_YZZ,V_XLXSBJTJ_TIMESTAMP,V_XLXSBJTJ_WHR,V_XLXSBJTJ_WHRID,V_XLXSBJTJ_WHSJ) "); SQL.Add(" select :pID, XLXSJGBMX_JGBID as JGBID,XLXSJGBMX_XH as XH"); SQL.Add(string.Format(",XLXSJGBYZZ9_YZZ as YZZ{0},:pTIMESTAMP,:pWHR,:pWHRID,:pWHSJ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.Add(" from XLXSJGBMX,XLXSJGBYZZ9 "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBYZZ9_XLXHID and XLXSCLQD_XLGGID=XLXSJGBYZZ9_XLGGID and XLXSCLQD_DYDJID=XLXSJGBYZZ9_DYDJID "); } SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" and XLXSJGBYZZ9_JGBID=:pTJJGBID and XLXSJGBYZZ9_YZID=:pYZID "); SQL.Add(" and XLXSJGBYZZ9_XLXHID=XLXSJGBMX_XLXHID and XLXSJGBYZZ9_XLGGID=XLXSJGBMX_XLGGID and XLXSJGBYZZ9_DYDJID=XLXSJGBMX_DYDJID "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.ParamByName("pTJJGBID").Value = yzxx.XLXSTZYZ_JGBID.Trim(); SQL.ParamByName("pYZID").Value = sTJYZ[i].Trim(); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pTIMESTAMP").Value = TimeStamp; SQL.ParamByName("pWHR").Value = tSession.UserName; SQL.ParamByName("pWHRID").Value = tSession.UserName; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSJGBYZZ0 tar "); SQL.Add(" using V_XLXSBJTJ sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and V_XLXSBJTJ_ID=:pID and XLXSJGBYZZ0_JGBID=V_XLXSBJTJ_JGBID and XLXSJGBYZZ0_XH=V_XLXSBJTJ_XH "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}=V_XLXSBJTJ_YZZ ", sTJYZ[i].Trim().Replace("JZ", ""))); SQL.ParamByName("pID").Value = VID; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSBJTJ where V_XLXSBJTJ_ID=:pID "); SQL.ParamByName("pID").Value = VID; dberp.ExecSQL(SQL); } } } sJJYZIDList = sJJYZIDList.TrimEnd(','); if (!string.IsNullOrEmpty(sJJYZIDList)) { SQL.Clear(); SQL.Add("merge into XLXSJGBYZZ0 using( "); SQL.Add(" select XLXSJGBMX_XH as XH,("); SQL.Add(" case when :pBJU003 in ('KM', '千米') and XLXSJGBMX_JLDW in ('M', '米') then 0.001"); SQL.Add(" when :pBJU003 in ('M', '米') and XLXSJGBMX_JLDW in ('Km', '千米') then 1000.0"); SQL.Add(" when :pBJU003 in ('M', '米') and XLXSJGBMX_JLDW in ('M', '米') then 1.0"); SQL.Add(" when :pBJU003 in ('KM', '千米') and XLXSJGBMX_JLDW in ('Km', '千米') then 1.0"); string sTDDWList = "("; foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when :pBJU003 in ('KM', '千米') and XLXSJGBMX_JLDW='{0}' then 0.001*{1} ", sKey, dicLenJLDWTD[sKey])); SQL.Add(string.Format(" when :pBJU003 in ('M', '米') and XLXSJGBMX_JLDW='{0}' then {1} ", sKey, dicLenJLDWTD[sKey])); SQL.Add(string.Format(" when :pBJU003 = '{0}' and XLXSJGBMX_JLDW in ('Km', '千米') then 1000.0/{1} ", sKey, dicLenJLDWTD[sKey])); SQL.Add(string.Format(" when :pBJU003 = '{0}' and XLXSJGBMX_JLDW in ('M', '米') then 1.0/{1} ", sKey, dicLenJLDWTD[sKey])); sTDDWList += "'" + sKey + "',"; } sTDDWList = sTDDWList.TrimEnd(','); sTDDWList += ")"; SQL.Add(" when :pBJU003 in " + sTDDWList + " and XLXSJGBMX_JLDW in " + sTDDWList + " then 1.0"); SQL.Add(" when :pBJU003 in ('T', '吨') and XLXSJGBMX_JLDW in ('Kg', '千克', '公斤') then 0.001"); SQL.Add(" when :pBJU003 in ('KG', '千克', '公斤') and XLXSJGBMX_JLDW in ('T', '吨') then 1000.0"); SQL.Add(" when :pBJU003 in ('KG', '千克', '公斤') and XLXSJGBMX_JLDW in ('Kg', '千克', '公斤') then 1.0"); SQL.Add(" when :pBJU003 in ('T', '吨') and XLXSJGBMX_JLDW in ('T', '吨') then 1.0"); if (sBJU003.ToUpper().Equals("KM") || sBJU003.ToUpper().Equals("千米")) { SQL.Add(" when :pBJU003 in ('KM', '千米') and XLXSJGBMX_JLDW in ('Kg', '千克', '公斤') then (case when XLXSCLQD_CLZL = 0 then 0 else 1.0/XLXSCLQD_CLZL end)"); SQL.Add(" when :pBJU003 in ('M', '米') and XLXSJGBMX_JLDW in ('Kg', '千克', '公斤') then (case when XLXSCLQD_CLZL = 0 then 0 else (1.0/XLXSCLQD_CLZL)*1000.0 end)"); SQL.Add(" when :pBJU003 in ('KG', '千克', '公斤') and XLXSJGBMX_JLDW in ('Km', '千米') then XLXSCLQD_CLZL"); SQL.Add(" when :pBJU003 in ('KM', '千米') and XLXSJGBMX_JLDW in ('T', '吨') then (case when XLXSCLQD_CLZL = 0 then 0 else (1.0/XLXSCLQD_CLZL)*1000.0 end)"); SQL.Add(" when :pBJU003 in ('M', '米') and XLXSJGBMX_JLDW in ('T', '吨') then (case when XLXSCLQD_CLZL = 0 then 0 else (1.0/XLXSCLQD_CLZL)* 1000.0*1000.0 end)"); SQL.Add(" when :pBJU003 in ('KG', '千克', '公斤') and XLXSJGBMX_JLDW in ('Km', '千米') then XLXSCLQD_CLZL"); SQL.Add(" when :pBJU003 in ('T', '吨') and XLXSJGBMX_JLDW in ('Km', '千米') then XLXSCLQD_CLZL/1000.0"); SQL.Add(" when :pBJU003 in ('KG', '千克', '公斤') and XLXSJGBMX_JLDW in ('M', '米') then XLXSCLQD_CLZL/1000.0"); SQL.Add(" when :pBJU003 in ('T', '吨') and XLXSJGBMX_JLDW in ('M', '米') then XLXSCLQD_CLZL/1000.0/1000.0"); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when :pBJU003 in ('KG', '千克', '公斤') and XLXSJGBMX_JLDW='{0}' then {1}*XLXSCLQD_CLZL/1000.0 ", sKey, dicLenJLDWTD[sKey])); SQL.Add(string.Format(" when :pBJU003 in ('T', '吨') and XLXSJGBMX_JLDW='{0}' then {1}*XLXSCLQD_CLZL/1000.0/1000.0 ", sKey, dicLenJLDWTD[sKey])); SQL.Add(string.Format(" when :pBJU003 = '{0}' and XLXSJGBMX_JLDW in ('KG', '千克', '公斤') then 1000.0/XLXSCLQD_CLZL/{1} ", sKey, dicLenJLDWTD[sKey])); SQL.Add(string.Format(" when :pBJU003 = '{0}' and XLXSJGBMX_JLDW in ('T', '吨') then 1000.0*1000.0/XLXSCLQD_CLZL/{1} ", sKey, dicLenJLDWTD[sKey])); } } else if (sBJU003.ToUpper().Equals("米") || sBJU003.ToUpper().Equals("M")) { SQL.Add(" when :pBJU003 in ('KM', '千米') and XLXSJGBMX_JLDW in ('Kg', '千克', '公斤') then (case when XLXSCLQD_CLZL = 0 then 0 else (1.0/XLXSCLQD_CLZL)*(1/1000.0) end)"); SQL.Add(" when :pBJU003 in ('M', '米') and XLXSJGBMX_JLDW in ('Kg', '千克', '公斤') then (case when XLXSCLQD_CLZL = 0 then 0 else 1.0/XLXSCLQD_CLZL end)"); SQL.Add(" when :pBJU003 in ('KG', '千克', '公斤') and XLXSJGBMX_JLDW in ('Km', '千米') then XLXSCLQD_CLZL*1000.0"); SQL.Add(" when :pBJU003 in ('KM', '千米') and XLXSJGBMX_JLDW in ('T', '吨') then (case when XLXSCLQD_CLZL = 0 then 0 else (1.0/XLXSCLQD_CLZL) end)"); SQL.Add(" when :pBJU003 in ('M', '米') and XLXSJGBMX_JLDW in ('T', '吨') then (case when XLXSCLQD_CLZL = 0 then 0 else (1.0/XLXSCLQD_CLZL)*1000.0 end)"); SQL.Add(" when :pBJU003 in ('KG', '千克', '公斤') and XLXSJGBMX_JLDW in ('Km', '千米') then XLXSCLQD_CLZL*1000.0"); SQL.Add(" when :pBJU003 in ('T', '吨') and XLXSJGBMX_JLDW in ('Km', '千米') then XLXSCLQD_CLZL"); SQL.Add(" when :pBJU003 in ('KG', '千克', '公斤') and XLXSJGBMX_JLDW in ('M', '米') then XLXSCLQD_CLZL"); SQL.Add(" when :pBJU003 in ('T', '吨') and XLXSJGBMX_JLDW in ('M', '米') then XLXSCLQD_CLZL/1000.0"); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format(" when :pBJU003 in ('KG', '千克', '公斤') and XLXSJGBMX_JLDW='{0}' then {1}*XLXSCLQD_CLZL ", sKey, dicLenJLDWTD[sKey])); SQL.Add(string.Format(" when :pBJU003 in ('T', '吨') and XLXSJGBMX_JLDW='{0}' then {1}*XLXSCLQD_CLZL/1000.0 ", sKey, dicLenJLDWTD[sKey])); SQL.Add(string.Format(" when :pBJU003 = '{0}' and XLXSJGBMX_JLDW in ('KG', '千克', '公斤') then 1/XLXSCLQD_CLZL/{1} ", sKey, dicLenJLDWTD[sKey])); SQL.Add(string.Format(" when :pBJU003 = '{0}' and XLXSJGBMX_JLDW in ('T', '吨') then 1000.0/XLXSCLQD_CLZL/{1} ", sKey, dicLenJLDWTD[sKey])); } } SQL.Add(" when :pBJU003=upper(XLXSJGBMX_JLDW) and :pBJU003 not in ('M','KM','米','千米','KG','T','千克','公斤','吨') "); SQL.Add(" and XLXSJGBMX_JLDW not in ('M','Km','米','千米','Kg','T','千克','公斤','吨') "); foreach (string sKey in dicLenJLDWTD.Keys) { SQL.Add(string.Format("and XLXSJGBMX_JLDW<>'{0}' ", sKey)); } SQL.Add(" then 1.0 else 1.0"); SQL.Add(" end "); SQL.Add(" ) as HSBL "); SQL.Add(" from XLXSJGBMX "); SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID and XLXSCLQD_WPID='ZZZZ' "); SQL.Add("where XLXSJGBMX_JGBID=:pJGBID and isnull(XLXSCLQD_CLZL,0)<>0 "); if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } SQL.Add(" ) sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBYZZ0_JGBID=:pJGBID and XLXSJGBYZZ0_XH=XH "); if (maxXH != 0) { SQL.Add(" and XLXSJGBYZZ0_XH > :pmaxXH "); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" ) "); SQL.Add(" when matched then update set "); string[] JJYZIDnum = sJJYZIDList.Split(','); for (int j = 0; j < JJYZIDnum.Length; j++) { if (j == 0) SQL.Add(string.Format(" XLXSJGBYZZ0_YZZ{0}=XLXSJGBYZZ0_YZZ{0}*HSBL", JJYZIDnum[j].Trim().Replace("JZ", ""))); else SQL.Add(string.Format(",XLXSJGBYZZ0_YZZ{0}=XLXSJGBYZZ0_YZZ{0}*HSBL", JJYZIDnum[j].Trim().Replace("JZ", ""))); } SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pBJU003").Value = sBJU003; dberp.ExecSQL(SQL); } } //根据价格表专属的材料行情,重新计算价格表的材料成本、无税基准报价、含税基准报价 public static void DoCLCB(TDatabase dberp, string sMXBH, string sJGBID, string sWHRID, string sWHR, int iXSWS, string sJSBLFS, string sBJU003) { DoCLCB(dberp, sMXBH, sJGBID, sWHRID, sWHR, "", "", iXSWS, sJSBLFS,sBJU003); } //如果传入结构尺重表号,则只计算该结构尺重表下的产品 public static void DoCLCB(TDatabase dberp, string sMXBH, string sJGBID, string sWHRID, string sWHR, string sJGCZBID, string sJGCZBBBID, int iXSWS, string sJSBLFS, string sBJU003) { DoCLCB(dberp, sMXBH, sJGBID, sWHRID, sWHR, sJGCZBID, sJGCZBBBID, iXSWS, sJSBLFS, "",sBJU003); } //价格表调价因素3,则XLXSCLQD_JGBHSCB、XLXSCLQD_JGBWSCB只用来记录材料价价差 public static void DoCLCB(TDatabase dberp, string sMXBH, string sJGBID, string sWHRID, string sWHR, string sJGCZBID, string sJGCZBBBID, int iXSWS, string sJSBLFS, string sJGBID1,string sBJU003) { bool IsJGBID3 = false;//sJGBID1不为空可能是价格表设置了所依出厂价,用于导入基价用的,改为根据调价因素3判断 if (!sJGBID1.Equals("")) { if (CMISproDataBase.ExistsRecord("DBERP", string.Format("select 1 from XLXSJGB where XLXSJGB_JGBID='{0}' and XLXSJGB_TJYS='3'", sJGBID))) IsJGBID3 = true; } TSQL SQL = new TSQL(dberp); //据材料行情补齐销售价格表的材料行情 SQL.Clear(); SQL.Add("insert into XLXSCLHQ(XLXSCLHQ_JGBID,XLXSCLHQ_BJCLID,XLXSCLHQ_WSJG,XLXSCLHQ_HSJG,XLXSCLHQ_HSJGF,XLXSCLHQ_WSJGF,"); SQL.Add(" XLXSCLHQ_JGYBJCLID1,XLXSCLHQ_HSJG1,XLXSCLHQ_WSJG1,XLXSCLHQ_JGBL1,"); SQL.Add(" XLXSCLHQ_YXQS,XLXSCLHQ_YXQZ,XLXSCLHQ_BZ,XLXSCLHQ_WHRID,XLXSCLHQ_WHR,XLXSCLHQ_WHSJ)"); SQL.Add(" select :pJGBID,XLXSBJCL_BJCLID,isnull(XLXSCLHQ_WSJG,0.0),isnull(XLXSCLHQ_HSJG,0.0),isnull(XLXSCLHQ_HSJGF,0.0),isnull(XLXSCLHQ_WSJGF,0.0),"); SQL.Add(" isnull(XLXSCLHQ_JGYBJCLID1,' '),isnull(XLXSCLHQ_HSJG1,0.0),isnull(XLXSCLHQ_WSJG1,0.0),isnull(XLXSCLHQ_JGBL1,0.0),"); SQL.Add(" convert(datetime, '1900-01-01'),convert(datetime, '1900-01-01'),"); SQL.Add(" isnull(XLXSCLHQ_BZ,' '),:pWHRID,:pWHR,:pWHSJ "); SQL.Add(" from XLXSBJCL,"); SQL.Add("("); //取销售价格表没有的材料行情 SQL.Add("select XLXSCLHQ_BJCLID,XLXSCLHQ_WSJG,XLXSCLHQ_HSJG,XLXSCLHQ_HSJGF,XLXSCLHQ_WSJGF,"); SQL.Add(" XLXSCLHQ_JGYBJCLID1,XLXSCLHQ_HSJG1,XLXSCLHQ_WSJG1,XLXSCLHQ_JGBL1,"); SQL.Add(" XLXSCLHQ_BZ"); SQL.Add(" from XLXSCLHQ,"); SQL.Add("("); SQL.Add("select a.XLXSCLHQ_BJCLID as BJCLID,max(a.XLXSCLHQ_YXQS)as maxYXQS"); SQL.Add(" from XLXSCLHQ a"); SQL.Add(" where a.XLXSCLHQ_JGBID='ZZZZZZZZ' "); SQL.Add(" and a.XLXSCLHQ_YXQS<=:pRQ "); SQL.Add(" and isnull(a.XLXSCLHQ_YXQZ,convert(datetime,'9999-12-31'))>=:pRQ "); SQL.Add(" and not exists");//排除掉销售价格表已有的材料行情 SQL.Add("("); SQL.Add("select 1 from XLXSCLHQ b where b.XLXSCLHQ_JGBID=:pJGBID and b.XLXSCLHQ_BJCLID=a.XLXSCLHQ_BJCLID"); SQL.Add(")"); SQL.Add(" group by a.XLXSCLHQ_BJCLID"); SQL.Add(") c"); SQL.Add(" where XLXSCLHQ_JGBID='ZZZZZZZZ' "); SQL.Add(" and XLXSCLHQ_BJCLID=BJCLID "); SQL.Add(" and XLXSCLHQ_YXQS=maxYXQS"); SQL.Add(") d"); SQL.Add(" where XLXSCLHQ_BJCLID=XLXSBJCL_BJCLID"); SQL.Add(" and isnull(XLXSBJCL_BJCLMC,' ')<>' '"); //SQL.Add(" order by XLXSCLHQ_BJCLID"); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pWHRID").Value = sWHRID; SQL.ParamByName("pWHR").Value = sWHR; SQL.ParamByName("pWHSJ").Value = DateTime.Now; SQL.ParamByName("pRQ").Value = DateTime.Now.ToShortDateString(); dberp.ExecSQL(SQL); if (XLJGB_CLJGTZList.NeedJGBJJFP()) { //据物料行情补齐销售价格表的物料行情 InsertXLXSJGBWLHQbyJGBCLHQ(dberp, SQL, sJGBID, DateTime.Now.ToShortDateString(), sWHR, sWHRID, false); } //价格表调价因素3,则利用XLXSCLQD_JGBHSCB、XLXSCLQD_JGBWSCB记录的材料价价差更新价格表基价、表价 if (IsJGBID3) { XLBJDCalcUtils.UpdateJGBTJYS_3(dberp, SQL, sJGBID, iXSWS, sJSBLFS, sWHRID, sWHR, sJGBID1, "", 0); //UpdateCLCB_TJYS(dberp, sMXBH, sJGBID, sJGBID1, "3"); } else { //据材料行情、材料单耗计算材料成本 UpdateCLCB(dberp, SQL, sJGBID, sJGCZBID, sJGCZBBBID, iXSWS, sJSBLFS, sWHRID, sWHR, 0, sJGBID1, "", "", 0, 0, "", 0,sBJU003); } DoCPJJ(dberp, sMXBH, sJGBID, false, sJGCZBID, sJGCZBBBID, iXSWS, sJSBLFS, sWHRID, sWHR, 0, sBJU003); ReCalcWSJG(dberp,SQL,sJGBID,sMXBH,iXSWS,0); } public static void DoCPJJ(TDatabase dberp, string sMXBH, string sJGBID, bool bInsertXLXSJGBYZZ0, string sJGCZBID, string sJGCZBBBID, int iXSWS, string sJSBLFS, string sWHRID, string sWHR, double maxXH) { //据材料成本及调整因子的值计算无税产品单价、含税产品单价 TSQL SQL = new TSQL(dberp); SQL.Clear(); SQL.Add("select XLXSJGBYZ_YZID,XLXSTZYZ_JJFS,XLXSTZYZ_TJYZID,XLXSTZYZ_TJYS,XLXSJGB_JSGS "); SQL.Add(" from XLXSJGBYZ"); SQL.Add(" left join XLXSJGB on XLXSJGB_JGBID = XLXSJGBYZ_JGBID "); SQL.Add(" left join XLXSTZYZ on XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_YZID=XLXSJGBYZ_YZID"); SQL.Add(" where XLXSJGBYZ_JGBID=:pJGBID"); SQL.Add(" order by XLXSTZYZ_TJYZID,XLXSTZYZ_XSXH,XLXSJGBYZ_YZID"); SQL.ParamByName("pJGBID").Value = sJGBID; DataSet dsJGBYZ = dberp.OpenDataSet(SQL); if (dsJGBYZ.Tables[0].Rows.Count > 0) { string sJSGS = dsJGBYZ.Tables[0].Rows[0]["XLXSJGB_JSGS"].ToString().Trim(); string sTJYSList_ = "";//记录调价因素为空的因子id string sTJYSList1 = "";//记录调价因素为'1'的因子id string sTJYSList3 = "";//记录调价因素为'3'的因子id string sTJYSList4 = "";//记录调价因素为'4'的因子id string sTJYSList5 = "";//记录调价因素为'5'的因子id string sTJYSList8 = "";//记录调价因素为'8'的因子id string sTJYSList9 = "";//记录调价因素为'9'的因子id for (int i = 0; i < dsJGBYZ.Tables[0].Rows.Count; i++) { if (dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYS"].ToString().Trim().Equals("")) { sTJYSList_ += dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim() + ","; } else if (dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYS"].ToString().Trim().Equals("1")) { sTJYSList1 += dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim() + ","; } else if (dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYS"].ToString().Trim().Equals("3")) { sTJYSList3 += dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim() + ","; } else if (dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYS"].ToString().Trim().Equals("4")) { sTJYSList4 += dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim() + ","; } else if (dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYS"].ToString().Trim().Equals("5")) { sTJYSList5 += dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim() + ","; } else if (dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYS"].ToString().Trim().Equals("8")) { sTJYSList8 += dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim() + ","; } else if (dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYS"].ToString().Trim().Equals("9")) { sTJYSList9 += dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim() + ","; } } sTJYSList_ = sTJYSList_.TrimEnd(','); sTJYSList1 = sTJYSList1.TrimEnd(','); sTJYSList3 = sTJYSList3.TrimEnd(','); sTJYSList4 = sTJYSList4.TrimEnd(','); sTJYSList5 = sTJYSList5.TrimEnd(','); sTJYSList8 = sTJYSList8.TrimEnd(','); sTJYSList9 = sTJYSList9.TrimEnd(','); Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-Begin")); AddXLXSJGBYZZ0(dberp, sMXBH, sJGBID, sTJYSList_, sTJYSList1, sTJYSList3, sTJYSList4, sTJYSList5, sTJYSList8, sTJYSList9, bInsertXLXSJGBYZZ0, sJGCZBID, sJGCZBBBID, maxXH); Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-End")); if (sJSGS.Trim().Equals("")) { string sJDSQL = "1"; string sKDSQL = "1"; string sJJSQL = "0"; string sSXSQL = "1"; string sTJYZID = dsJGBYZ.Tables[0].Rows[0]["XLXSTZYZ_TJYZID"].ToString().Trim(); string sJJFS = dsJGBYZ.Tables[0].Rows[0]["XLXSTZYZ_JJFS"].ToString().Trim(); for (int i = 1; i < dsJGBYZ.Tables[0].Rows.Count; i++) { if (!sTJYZID.Equals(dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYZID"].ToString().Trim())) { if (sJJFS.Equals("JD")) sJDSQL = sJDSQL + "*(1+JDYZZ_" + sTJYZID + "/100.0)"; else if (sJJFS.Equals("KD")) sKDSQL = sKDSQL + "/(1-KDYZZ_" + sTJYZID + "/100.0)"; else if (sJJFS.Equals("JJ")) sJJSQL += "+JJYZZ_" + sTJYZID; else if (sJJFS.Equals("SX")) sSXSQL = sSXSQL + "*(case when SXYZZ_" + sTJYZID + ">=0 then 1/(1-SXYZZ_" + sTJYZID + "/100.0) else (1+SXYZZ_" + sTJYZID + "/100.0) end)"; sTJYZID = dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYZID"].ToString().Trim(); sJJFS = dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_JJFS"].ToString().Trim(); } } if (sJJFS.Equals("JD")) sJDSQL = sJDSQL + "*(1+JDYZZ_" + sTJYZID + "/100.0)"; else if (sJJFS.Equals("KD")) sKDSQL = sKDSQL + "/(1-KDYZZ_" + sTJYZID + "/100.0)"; else if (sJJFS.Equals("JJ")) sJJSQL += "+JJYZZ_" + sTJYZID; else if (sJJFS.Equals("SX")) sSXSQL = sSXSQL + "*(case when SXYZZ_" + sTJYZID + ">=0 then 1/(1-SXYZZ_" + sTJYZID + "/100.0) else (1+SXYZZ_" + sTJYZID + "/100.0) end)"; /* merge into 目标表 a using 源表 b on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……) when matched then update set a.更新字段=b.字段 when not matched then insert into a(字段1,字段2……)values(值1,值2……) */ Dictionary dicJGBTJYZ = XLBJDInfo.GetJGBBTYZ(sJGBID); Dictionary dicJGBFGQCPYZ = XLBJDInfo.GetJGBFGQCPYZ(sJGBID); SQL.Clear(); SQL.Add(" merge into XLXSJGBMX tar "); SQL.Add(" using ( "); SQL.Add("select JGBID,XH," + sJDSQL + " as JDYZZ," + sKDSQL + " as KDYZZ," + sJJSQL + " as JJYZZ," + sSXSQL + " as SXYZZ"); if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) SQL.Add(",JSYCBZ"); //if (dicJGBFGQCPYZ.Count > 0) // SQL.Add(",JGBTJYZYCBZ"); SQL.Add(" from "); SQL.Add("("); SQL.Add(" select XLXSJGBYZZ0_JGBID as JGBID,XLXSJGBYZZ0_XH as XH,"); if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add(" case "); if (dicJGBTJYZ.Count > 0) { foreach (string sKey in dicJGBTJYZ.Keys) { SQL.Add(string.Format(" when XLXSJGBYZZ0_YZZ" + sKey.Replace("JZ", "") + " = 0 then '{0}' ", sKey.Substring(3, 1))); } } if (dicJGBFGQCPYZ.Count > 0) { foreach (string sKey in dicJGBFGQCPYZ.Keys) { SQL.Add(string.Format(" when XLXSJGBYZZ0_YZZ" + sKey.Replace("JZ", "") + " = -9999 then '{0}' ", sKey.Substring(3, 1))); } } SQL.Add(" else 'S' "); SQL.Add(" end as JSYCBZ, "); } SQL.Add(" ("); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}", dsJGBYZ.Tables[0].Rows[0]["XLXSJGBYZ_YZID"].ToString().Trim().Replace("JZ", ""))); sTJYZID = dsJGBYZ.Tables[0].Rows[0]["XLXSTZYZ_TJYZID"].ToString().Trim(); sJJFS = dsJGBYZ.Tables[0].Rows[0]["XLXSTZYZ_JJFS"].ToString().Trim(); for (int i = 1; i < dsJGBYZ.Tables[0].Rows.Count; i++) { if (sTJYZID.Equals(dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYZID"].ToString().Trim())) { SQL.Add(string.Format("+XLXSJGBYZZ0_YZZ{0}", dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim().Replace("JZ", ""))); } else { if (sJJFS.Equals("JD")) SQL.Add(") as " + "JDYZZ_" + sTJYZID); else if (sJJFS.Equals("KD")) SQL.Add(") as " + "KDYZZ_" + sTJYZID); else if (sJJFS.Equals("JJ")) SQL.Add(") as " + "JJYZZ_" + sTJYZID); else if (sJJFS.Equals("SX")) SQL.Add(") as " + "SXYZZ_" + sTJYZID); sTJYZID = dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYZID"].ToString().Trim(); sJJFS = dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_JJFS"].ToString().Trim(); SQL.Add(",("); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}", dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim().Replace("JZ", ""))); } } if (sJJFS.Equals("JD")) SQL.Add(") as " + "JDYZZ_" + sTJYZID); else if (sJJFS.Equals("KD")) SQL.Add(") as " + "KDYZZ_" + sTJYZID); else if (sJJFS.Equals("JJ")) SQL.Add(") as " + "JJYZZ_" + sTJYZID); else if (sJJFS.Equals("SX")) SQL.Add(") as " + "SXYZZ_" + sTJYZID); SQL.Add(" from XLXSJGBYZZ0"); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSJGBMX on XLXSJGBMX_JGBID=:pJGBID and XLXSJGBMX_XH=XLXSJGBYZZ0_XH"); SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add(" where XLXSJGBYZZ0_JGBID=:pJGBID "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID = :pJGCZBID"); SQL.Add(" and XLXSCLQD_JGCZBBBID = :pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } if (maxXH != 0) { SQL.Add(" and XLXSJGBYZZ0_XH > :pmaxXH"); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" ) a"); SQL.Add(" ) sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBMX_JGBID=:pJGBID "); SQL.Add(" and XLXSJGBMX_JGBID=sor.JGBID "); SQL.Add(" and XLXSJGBMX_XH=XH "); //此处未传参数区分,暂先默认 SQL.Add(" and XLXSJGBMX_SYXH=0 "); //SQL.Add(" and XLXSJGBMX_JLDW in ('M','Km','米','千米') "); 需支持非长度单位导入基价以及计算表价 SQL.Add(" ) "); SQL.Add(" when matched then update set "); if (sJSBLFS.Equals("C1") || sJSBLFS.Equals("C2"))//C1|进一法(材料价各分项进一)、C2|进一法(材料价汇总进一) { //此处根据序号区分先加价还是先加点/扣点 if (XLBJDUtils.JJFirst_JGBYZ(sJGBID)) { //先加价 if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" )*-1 end ,"); } else { SQL.Add(string.Format("XLXSJGBMX_WSBJ=CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_HSBJ=CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_WSBJM=RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJM=RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) ,"); } } else { //先加点 if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0))*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0))*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0))*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0))*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6) "); SQL.Add(" )*-1 end ,"); } else { SQL.Add(string.Format("XLXSJGBMX_WSBJ=CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0))*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_HSBJ=CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0))*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_WSBJM=RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJM=RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) ,"); } } } else if (sJSBLFS.Equals("C3"))//C3|材料价汇总进一+表价进一到十位 { //此处根据序号区分先加价还是先加点/扣点 if (XLBJDUtils.JJFirst_JGBYZ(sJGBID)) { //先加价 if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" )*-1 end ,"); } else { SQL.Add(string.Format("XLXSJGBMX_WSBJ = CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_HSBJ = CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_WSBJM=RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJM=RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) ,"); } } else { //先加点 if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6) "); SQL.Add(" )*-1 end ,"); } else { SQL.Add(string.Format("XLXSJGBMX_WSBJ = CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_HSBJ = CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_WSBJM=RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJM=RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) ,"); } } } else { //此处根据序号区分先加价还是先加点/扣点 if (XLBJDUtils.JJFirst_JGBYZ(sJGBID)) { //先加价 if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end , "); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" )*-1 end ,"); } else { SQL.Add("XLXSJGBMX_WSBJ=RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJ=RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_WSBJM=RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJM=RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) ,"); } } else { //先加点 if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix(abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix(abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix(abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix(abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6) "); SQL.Add(" )*-1 end ,"); } else { SQL.Add("XLXSJGBMX_WSBJ=RoundFix(abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJ=RoundFix(abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_WSBJM=RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJM=RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ case when XLXSJGBMX_JLDW in ('Km','千米') then 0.001 when XLXSJGBMX_JLDW in ('M','米') then 1 else 0 end * isnull(JJYZZ,0)),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) ,"); } } } SQL.Add(" XLXSJGBMX_WHR=:pWHR, "); SQL.Add(" XLXSJGBMX_WHRID=:pWHRID, "); SQL.Add(" XLXSJGBMX_WHSJ=:pWHSJ "); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pWHR").Value = sWHR; SQL.ParamByName("pWHRID").Value = sWHRID; SQL.ParamByName("pWHSJ").Value = DateTime.Now.ToString(); string ss = SQL.Text; Mac.MacLog.TraceFormat(String.Format("DoCPJJ-merge-Begin")); dberp.ExecSQL(SQL); Mac.MacLog.TraceFormat(String.Format("DoCPJJ-merge-End")); } else { /* merge into 目标表 a using 源表 b on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……) when matched then update set a.更新字段=b.字段 when not matched then insert into a(字段1,字段2……)values(值1,值2……) */ Dictionary dicJGBYZJJF = GetJGBYZJJFS(sJGBID); Dictionary dicJGBTJYZ = XLBJDInfo.GetJGBBTYZ(sJGBID); Dictionary dicJGBFGQCPYZ = XLBJDInfo.GetJGBFGQCPYZ(sJGBID); string sJSGSKM = sJSGS; string sJSGSQT = sJSGS; foreach (string key in dicJGBYZJJF.Keys) { if (dicJGBYZJJF[key].Equals("JJ")) { sJSGSKM = sJSGSKM.Replace(key, "0.001 * " + key); sJSGSQT = sJSGSQT.Replace(key, "0 * " + key); } } SQL.Clear(); SQL.Add(" merge into XLXSJGBMX tar "); SQL.Add(" using ( "); SQL.Add("select JGBID,XH,XLXSJGBYZZ0_YZZ01,XLXSJGBYZZ0_YZZ02,XLXSJGBYZZ0_YZZ03,XLXSJGBYZZ0_YZZ04,XLXSJGBYZZ0_YZZ05,XLXSJGBYZZ0_YZZ06,XLXSJGBYZZ0_YZZ07,XLXSJGBYZZ0_YZZ08,XLXSJGBYZZ0_YZZ09,XLXSJGBYZZ0_YZZ10 "); if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) SQL.Add(",JSYCBZ"); //if (dicJGBFGQCPYZ.Count > 0) // SQL.Add(",JGBTJYZYCBZ"); SQL.Add(" from "); SQL.Add("("); SQL.Add(" select XLXSJGBYZZ0_JGBID as JGBID,XLXSJGBYZZ0_XH as XH,XLXSJGBYZZ0_YZZ01,XLXSJGBYZZ0_YZZ02,XLXSJGBYZZ0_YZZ03,XLXSJGBYZZ0_YZZ04,XLXSJGBYZZ0_YZZ05,XLXSJGBYZZ0_YZZ06,XLXSJGBYZZ0_YZZ07,XLXSJGBYZZ0_YZZ08,XLXSJGBYZZ0_YZZ09,XLXSJGBYZZ0_YZZ10 "); if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add(" , case "); if (dicJGBTJYZ.Count > 0) { foreach (string sKey in dicJGBTJYZ.Keys) { SQL.Add(string.Format(" when XLXSJGBYZZ0_YZZ" + sKey.Replace("JZ", "") + " = 0 then '{0}' ", sKey.Substring(3, 1))); } } if (dicJGBFGQCPYZ.Count > 0) { foreach (string sKey in dicJGBFGQCPYZ.Keys) { SQL.Add(string.Format(" when XLXSJGBYZZ0_YZZ" + sKey.Replace("JZ", "") + " = -9999 then '{0}' ", sKey.Substring(3, 1))); } } SQL.Add(" else 'S' "); SQL.Add(" end as JSYCBZ "); } SQL.Add(" from XLXSJGBYZZ0"); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" left join XLXSJGBMX on XLXSJGBMX_JGBID=:pJGBID and XLXSJGBMX_XH=XLXSJGBYZZ0_XH"); SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); } SQL.Add(" where XLXSJGBYZZ0_JGBID=:pJGBID "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID = :pJGCZBID"); SQL.Add(" and XLXSCLQD_JGCZBBBID = :pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } if (maxXH != 0) { SQL.Add(" and XLXSJGBYZZ0_XH > :pmaxXH"); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" ) a"); SQL.Add(" ) sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBMX_JGBID=:pJGBID "); SQL.Add(" and XLXSJGBMX_JGBID=sor.JGBID "); SQL.Add(" and XLXSJGBMX_XH=XH "); //此处未传参数区分,暂先默认 SQL.Add(" and XLXSJGBMX_SYXH=0 "); SQL.Add(" and XLXSJGBMX_JLDW in ('M','Km','米','千米') "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); if (sJSBLFS.Equals("C1") || sJSBLFS.Equals("C2"))//C1|进一法(材料价各分项进一)、C2|进一法(材料价汇总进一) { if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix({0}*{1},8))/{1}", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix({0}*{1},8))/{1}", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix({0}*{1},8))/{1}", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix({0}*{1},8))/{1}", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" )*-1 end ,"); } else { SQL.Add(string.Format("XLXSJGBMX_WSBJ=CEILING(RoundFix({0}*{1},8))/{1}", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_HSBJ=CEILING(RoundFix({0}*{1},8))/{1}", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_WSBJM=RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end), "); SQL.Add(string.Format("XLXSJGBMX_HSBJM=RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end), "); } } else if (sJSBLFS.Equals("C3"))//C3|材料价汇总进一+表价进一到十位 { if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix({0},{1})/10)*10", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix({0},{1})/10)*10", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix({0},{1})/10)*10", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix({0},{1})/10)*10", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" )*-1 end ,"); } else { SQL.Add(string.Format("XLXSJGBMX_WSBJ = CEILING(RoundFix({0},{1})/10)*10", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_HSBJ = CEILING(RoundFix({0},{1})/10)*10", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_WSBJM=RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) , "); SQL.Add(string.Format("XLXSJGBMX_HSBJM=RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end), "); } } else { if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix({0},{1})", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), iXSWS)); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix({0},{1})", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), iXSWS)); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix({0},{1})", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), iXSWS)); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix({0},{1})", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), iXSWS)); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end , "); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" )*-1 end ,"); } else { SQL.Add(string.Format("XLXSJGBMX_WSBJ=RoundFix({0},{1})", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), iXSWS)); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_HSBJ=RoundFix({0},{1})", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), iXSWS)); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_WSBJM=RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end), "); SQL.Add(string.Format("XLXSJGBMX_HSBJM=RoundFix(case when XLXSJGBMX_JLDW in ('Km','千米') then {0} when XLXSJGBMX_JLDW in ('M','米') then {1} else {2} end,6) ", sJSGSKM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"), sJSGSQT.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end), "); } } SQL.Add(" XLXSJGBMX_WHR=:pWHR, "); SQL.Add(" XLXSJGBMX_WHRID=:pWHRID, "); SQL.Add(" XLXSJGBMX_WHSJ=:pWHSJ "); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pWHR").Value = sWHR; SQL.ParamByName("pWHRID").Value = sWHRID; SQL.ParamByName("pWHSJ").Value = DateTime.Now.ToString(); string ss = SQL.Text; Mac.MacLog.TraceFormat(String.Format("DoCPJJ-merge-Begin")); dberp.ExecSQL(SQL); Mac.MacLog.TraceFormat(String.Format("DoCPJJ-merge-End")); } } else { Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-Begin")); AddXLXSJGBYZZ0(dberp, sMXBH, sJGBID, "", "", "", "", "", "", "", true, sJGCZBID, sJGCZBBBID, maxXH); Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-End")); } } //根据价格表专属的材料行情,重新计算价格表的材料成本、无税基准报价、含税基准报价 public static void DoCPJJ(TDatabase dberp, string sMXBH, string sJGBID, bool bInsertXLXSJGBYZZ0, int iXSWS, string sJSBLFS, string sWHRID, string sWHR,string sBJU003) { DoCPJJ(dberp, sMXBH, sJGBID, bInsertXLXSJGBYZZ0, "", "", iXSWS, sJSBLFS, sWHRID, sWHR, 0, sBJU003);//参数maxXH为0时的处理逻辑保持不变 } public static void DoCPJJ(TDatabase dberp, string sMXBH, string sJGBID, bool bInsertXLXSJGBYZZ0, int iXSWS, string sJSBLFS, string sWHRID, string sWHR, double maxXH, string sBJU003) { DoCPJJ(dberp, sMXBH, sJGBID, bInsertXLXSJGBYZZ0, "", "", iXSWS, sJSBLFS, sWHRID, sWHR, maxXH, sBJU003); } //如果传入结构尺重表号,则只计算该结构尺重表下的产品 public static void DoCPJJ(TDatabase dberp, string sMXBH, string sJGBID, bool bInsertXLXSJGBYZZ0, string sJGCZBID, string sJGCZBBBID, int iXSWS, string sJSBLFS, string sWHRID, string sWHR, double maxXH, string sBJU003) { //据材料成本及调整因子的值计算无税产品单价、含税产品单价 TSQL SQL = new TSQL(dberp); SQL.Clear(); SQL.Add("select XLXSJGBYZ_YZID,XLXSTZYZ_JJFS,XLXSTZYZ_TJYZID,XLXSTZYZ_TJYS,XLXSJGB_JSGS "); SQL.Add(" from XLXSJGBYZ"); SQL.Add(" left join XLXSJGB on XLXSJGB_JGBID = XLXSJGBYZ_JGBID "); SQL.Add(" left join XLXSTZYZ on XLXSTZYZ_MXBH='JZJ' and XLXSTZYZ_YZID=XLXSJGBYZ_YZID"); SQL.Add(" where XLXSJGBYZ_JGBID=:pJGBID"); SQL.Add(" order by XLXSTZYZ_TJYZID,XLXSTZYZ_XSXH,XLXSJGBYZ_YZID"); SQL.ParamByName("pJGBID").Value = sJGBID; DataSet dsJGBYZ = dberp.OpenDataSet(SQL); if (dsJGBYZ.Tables[0].Rows.Count > 0) { string sJSGS = dsJGBYZ.Tables[0].Rows[0]["XLXSJGB_JSGS"].ToString().Trim(); string sTJYSList_ = "";//记录调价因素为空的因子id string sTJYSList1 = "";//记录调价因素为'1'的因子id string sTJYSList3 = "";//记录调价因素为'3'的因子id string sTJYSList4 = "";//记录调价因素为'4'的因子id string sTJYSList5 = "";//记录调价因素为'5'的因子id string sTJYSList8 = "";//记录调价因素为'8'的因子id string sTJYSList9 = "";//记录调价因素为'9'的因子id for (int i = 0; i < dsJGBYZ.Tables[0].Rows.Count; i++) { if (dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYS"].ToString().Trim().Equals("")) { sTJYSList_ += dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim() + ","; } else if (dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYS"].ToString().Trim().Equals("1")) { sTJYSList1 += dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim() + ","; } else if (dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYS"].ToString().Trim().Equals("3")) { sTJYSList3 += dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim() + ","; } else if (dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYS"].ToString().Trim().Equals("4")) { sTJYSList4 += dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim() + ","; } else if (dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYS"].ToString().Trim().Equals("5")) { sTJYSList5 += dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim() + ","; } else if (dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYS"].ToString().Trim().Equals("8")) { sTJYSList8 += dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim() + ","; } else if (dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYS"].ToString().Trim().Equals("9")) { sTJYSList9 += dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim() + ","; } } sTJYSList_ = sTJYSList_.TrimEnd(','); sTJYSList1 = sTJYSList1.TrimEnd(','); sTJYSList3 = sTJYSList3.TrimEnd(','); sTJYSList4 = sTJYSList4.TrimEnd(','); sTJYSList5 = sTJYSList5.TrimEnd(','); sTJYSList8 = sTJYSList8.TrimEnd(','); sTJYSList9 = sTJYSList9.TrimEnd(','); Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-Begin")); AddXLXSJGBYZZ0(dberp, sMXBH, sJGBID, sTJYSList_, sTJYSList1, sTJYSList3, sTJYSList4, sTJYSList5, sTJYSList8, sTJYSList9, bInsertXLXSJGBYZZ0, sJGCZBID, sJGCZBBBID, maxXH, sBJU003); Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-End")); string sHSBLSQL = string.Empty; sHSBLSQL+=" (case when XLXSJGBMX_JLDW in ('M', '米') then 1"; sHSBLSQL+=" when XLXSJGBMX_JLDW in ('Km', '千米') then 0.001 "; if (sBJU003.ToUpper().Equals("KM") || sBJU003.ToUpper().Equals("千米")) { sHSBLSQL+=" when XLXSJGBMX_JLDW in ('Kg', '千克', '公斤') then (case when XLXSCLQD_CLZL = 0 then 1 else XLXSCLQD_CLZL/1000 end)"; sHSBLSQL+=" when XLXSJGBMX_JLDW in ('T', '吨') then (case when XLXSCLQD_CLZL = 0 then 1 else XLXSCLQD_CLZL/1000000.0 end)"; } else if (sBJU003.ToUpper().Equals("米") || sBJU003.ToUpper().Equals("M")) { sHSBLSQL+=" when XLXSJGBMX_JLDW in ('Kg', '千克', '公斤') then (case when XLXSCLQD_CLZL = 0 then 1 else XLXSCLQD_CLZL end)"; sHSBLSQL+=" when XLXSJGBMX_JLDW in ('T', '吨') then (case when XLXSCLQD_CLZL = 0 then 1 else XLXSCLQD_CLZL/1000 end)"; } sHSBLSQL+=" else 0 "; sHSBLSQL+=" end "; sHSBLSQL+=" ) "; if (sJSGS.Trim().Equals("")) { string sJDSQL = "1"; string sKDSQL = "1"; string sJJSQL = "0"; string sSXSQL = "1"; string sTJYZID = dsJGBYZ.Tables[0].Rows[0]["XLXSTZYZ_TJYZID"].ToString().Trim(); string sJJFS = dsJGBYZ.Tables[0].Rows[0]["XLXSTZYZ_JJFS"].ToString().Trim(); for (int i = 1; i < dsJGBYZ.Tables[0].Rows.Count; i++) { if (!sTJYZID.Equals(dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYZID"].ToString().Trim())) { if (sJJFS.Equals("JD")) sJDSQL = sJDSQL + "*(1+JDYZZ_" + sTJYZID + "/100.0)"; else if (sJJFS.Equals("KD")) sKDSQL = sKDSQL + "/(1-KDYZZ_" + sTJYZID + "/100.0)"; else if (sJJFS.Equals("JJ")) sJJSQL += "+JJYZZ_" + sTJYZID; else if (sJJFS.Equals("SX")) sSXSQL = sSXSQL + "*(case when SXYZZ_" + sTJYZID + ">=0 then 1/(1-SXYZZ_" + sTJYZID + "/100.0) else (1+SXYZZ_" + sTJYZID + "/100.0) end)"; sTJYZID = dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYZID"].ToString().Trim(); sJJFS = dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_JJFS"].ToString().Trim(); } } if (sJJFS.Equals("JD")) sJDSQL = sJDSQL + "*(1+JDYZZ_" + sTJYZID + "/100.0)"; else if (sJJFS.Equals("KD")) sKDSQL = sKDSQL + "/(1-KDYZZ_" + sTJYZID + "/100.0)"; else if (sJJFS.Equals("JJ")) sJJSQL += "+JJYZZ_" + sTJYZID; else if (sJJFS.Equals("SX")) sSXSQL = sSXSQL + "*(case when SXYZZ_" + sTJYZID + ">=0 then 1/(1-SXYZZ_" + sTJYZID + "/100.0) else (1+SXYZZ_" + sTJYZID + "/100.0) end)"; /* merge into 目标表 a using 源表 b on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……) when matched then update set a.更新字段=b.字段 when not matched then insert into a(字段1,字段2……)values(值1,值2……) */ Dictionary dicJGBTJYZ = XLBJDInfo.GetJGBBTYZ(sJGBID); Dictionary dicJGBFGQCPYZ = XLBJDInfo.GetJGBFGQCPYZ(sJGBID); SQL.Clear(); SQL.Add(" merge into XLXSJGBMX tar "); SQL.Add(" using ( "); SQL.Add("select XLXSCLQD_CLZL,JGBID,XH," + sJDSQL + " as JDYZZ," + sKDSQL + " as KDYZZ," + sJJSQL + " as JJYZZ," + sSXSQL + " as SXYZZ"); if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) SQL.Add(",JSYCBZ"); //if (dicJGBFGQCPYZ.Count > 0) // SQL.Add(",JGBTJYZYCBZ"); SQL.Add(" from "); SQL.Add("("); SQL.Add(" select isnull(XLXSCLQD_CLZL,0) as XLXSCLQD_CLZL,XLXSJGBYZZ0_JGBID as JGBID,XLXSJGBYZZ0_XH as XH ,"); if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("case "); if (dicJGBTJYZ.Count > 0) { foreach (string sKey in dicJGBTJYZ.Keys) { SQL.Add(string.Format(" when XLXSJGBYZZ0_YZZ" + sKey.Replace("JZ", "") + " = 0 then '{0}' ", sKey.Substring(3, 1))); } } if (dicJGBFGQCPYZ.Count > 0) { foreach (string sKey in dicJGBFGQCPYZ.Keys) { SQL.Add(string.Format(" when XLXSJGBYZZ0_YZZ" + sKey.Replace("JZ", "") + " = -9999 then '{0}' ", sKey.Substring(3, 1))); } } SQL.Add(" else 'S' "); SQL.Add(" end as JSYCBZ, "); } SQL.Add(" ("); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}", dsJGBYZ.Tables[0].Rows[0]["XLXSJGBYZ_YZID"].ToString().Trim().Replace("JZ", ""))); sTJYZID = dsJGBYZ.Tables[0].Rows[0]["XLXSTZYZ_TJYZID"].ToString().Trim(); sJJFS = dsJGBYZ.Tables[0].Rows[0]["XLXSTZYZ_JJFS"].ToString().Trim(); for (int i = 1; i < dsJGBYZ.Tables[0].Rows.Count; i++) { if (sTJYZID.Equals(dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYZID"].ToString().Trim())) { SQL.Add(string.Format("+XLXSJGBYZZ0_YZZ{0}", dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim().Replace("JZ", ""))); } else { if (sJJFS.Equals("JD")) SQL.Add(") as " + "JDYZZ_" + sTJYZID); else if (sJJFS.Equals("KD")) SQL.Add(") as " + "KDYZZ_" + sTJYZID); else if (sJJFS.Equals("JJ")) SQL.Add(") as " + "JJYZZ_" + sTJYZID); else if (sJJFS.Equals("SX")) SQL.Add(") as " + "SXYZZ_" + sTJYZID); sTJYZID = dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_TJYZID"].ToString().Trim(); sJJFS = dsJGBYZ.Tables[0].Rows[i]["XLXSTZYZ_JJFS"].ToString().Trim(); SQL.Add(",("); SQL.Add(string.Format("XLXSJGBYZZ0_YZZ{0}", dsJGBYZ.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim().Replace("JZ", ""))); } } if (sJJFS.Equals("JD")) SQL.Add(") as " + "JDYZZ_" + sTJYZID); else if (sJJFS.Equals("KD")) SQL.Add(") as " + "KDYZZ_" + sTJYZID); else if (sJJFS.Equals("JJ")) SQL.Add(") as " + "JJYZZ_" + sTJYZID); else if (sJJFS.Equals("SX")) SQL.Add(") as " + "SXYZZ_" + sTJYZID); SQL.Add(" from XLXSJGBYZZ0"); SQL.Add(" left join XLXSJGBMX on XLXSJGBMX_JGBID=:pJGBID and XLXSJGBMX_XH=XLXSJGBYZZ0_XH"); SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); SQL.Add(" where XLXSJGBYZZ0_JGBID=:pJGBID "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID = :pJGCZBID"); SQL.Add(" and XLXSCLQD_JGCZBBBID = :pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } if (maxXH != 0) { SQL.Add(" and XLXSJGBYZZ0_XH > :pmaxXH"); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" ) a"); SQL.Add(" ) sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBMX_JGBID=:pJGBID "); SQL.Add(" and XLXSJGBMX_JGBID=sor.JGBID "); SQL.Add(" and XLXSJGBMX_XH=XH "); //此处未传参数区分,暂先默认 SQL.Add(" and XLXSJGBMX_SYXH=0 "); //SQL.Add(" and XLXSJGBMX_JLDW in ('M','Km','米','千米') "); 需支持非长度单位导入基价以及计算表价 SQL.Add(" ) "); SQL.Add(" when matched then update set "); if (sJSBLFS.Equals("C1") || sJSBLFS.Equals("C2"))//C1|进一法(材料价各分项进一)、C2|进一法(材料价汇总进一) { //此处根据序号区分先加价还是先加点/扣点 if (XLBJDUtils.JJFirst_JGBYZ(sJGBID)) { //先加价 if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" )*-1 end ,"); } else { SQL.Add(string.Format("XLXSJGBMX_WSBJ=CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_HSBJ=CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_WSBJM=RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJM=RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) ,"); } } else { //先加点 if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0))*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0))*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0))*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0))*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6) "); SQL.Add(" )*-1 end ,"); } else { SQL.Add(string.Format("XLXSJGBMX_WSBJ=CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0))*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_HSBJ=CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0))*{0},8))/{0}", Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_WSBJM=RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJM=RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) ,"); } } } else if (sJSBLFS.Equals("C3"))//C3|材料价汇总进一+表价进一到十位 { //此处根据序号区分先加价还是先加点/扣点 if (XLBJDUtils.JJFirst_JGBYZ(sJGBID)) { //先加价 if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" )*-1 end ,"); } else { SQL.Add(string.Format("XLXSJGBMX_WSBJ = CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_HSBJ = CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_WSBJM=RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJM=RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) ,"); } } else { //先加点 if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format(" CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6) "); SQL.Add(" )*-1 end ,"); } else { SQL.Add(string.Format("XLXSJGBMX_WSBJ = CEILING(RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_HSBJ = CEILING(RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)),{0})/10)*10", iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_WSBJM=RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJM=RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) ,"); } } } else { //此处根据序号区分先加价还是先加点/扣点 if (XLBJDUtils.JJFirst_JGBYZ(sJGBID)) { //先加价 if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end , "); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6) "); SQL.Add(" )*-1 end ,"); } else { SQL.Add("XLXSJGBMX_WSBJ=RoundFix((abs(isnull(XLXSJGBMX_WSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJ=RoundFix((abs(isnull(XLXSJGBMX_HSJJ,0))+isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_WSBJM=RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJM=RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))+ " + sHSBLSQL + "* isnull(JJYZZ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) ,"); } } else { //先加点 if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix(abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix(abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix(abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix(abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6) "); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add("RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6) "); SQL.Add(" )*-1 end ,"); } else { SQL.Add("XLXSJGBMX_WSBJ=RoundFix(abs(isnull(XLXSJGBMX_WSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJ=RoundFix(abs(isnull(XLXSJGBMX_HSJJ,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+isnull(JJYZZ,0)," + iXSWS + ")"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_WSBJM=RoundFix((abs(isnull(XLXSJGBMX_WSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) ,"); SQL.Add("XLXSJGBMX_HSBJM=RoundFix((abs(isnull(XLXSJGBMX_HSJJM,0))*isnull(JDYZZ,1.0)*isnull(KDYZZ,1.0)*isnull(SXYZZ,1.0)+ " + sHSBLSQL + "* isnull(JJYZZ,0)),6)"); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) ,"); } } } SQL.Add(" XLXSJGBMX_WHR=:pWHR, "); SQL.Add(" XLXSJGBMX_WHRID=:pWHRID, "); SQL.Add(" XLXSJGBMX_WHSJ=:pWHSJ "); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pWHR").Value = sWHR; SQL.ParamByName("pWHRID").Value = sWHRID; SQL.ParamByName("pWHSJ").Value = DateTime.Now.ToString(); string ss = SQL.Text; Mac.MacLog.TraceFormat(String.Format("DoCPJJ-merge-Begin")); dberp.ExecSQL(SQL); Mac.MacLog.TraceFormat(String.Format("DoCPJJ-merge-End")); } else { /* merge into 目标表 a using 源表 b on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……) when matched then update set a.更新字段=b.字段 when not matched then insert into a(字段1,字段2……)values(值1,值2……) */ Dictionary dicJGBYZJJF = GetJGBYZJJFS(sJGBID); Dictionary dicJGBTJYZ = XLBJDInfo.GetJGBBTYZ(sJGBID); Dictionary dicJGBFGQCPYZ = XLBJDInfo.GetJGBFGQCPYZ(sJGBID); string sJSGSM = sJSGS; foreach (string key in dicJGBYZJJF.Keys) { if (dicJGBYZJJF[key].Equals("JJ")) { sJSGSM = sJSGSM.Replace(key, sHSBLSQL + " * " + key); } } SQL.Clear(); SQL.Add(" merge into XLXSJGBMX tar "); SQL.Add(" using ( "); SQL.Add("select XLXSCLQD_CLZL,JGBID,XH,XLXSJGBYZZ0_YZZ01,XLXSJGBYZZ0_YZZ02,XLXSJGBYZZ0_YZZ03,XLXSJGBYZZ0_YZZ04,XLXSJGBYZZ0_YZZ05,XLXSJGBYZZ0_YZZ06,XLXSJGBYZZ0_YZZ07,XLXSJGBYZZ0_YZZ08,XLXSJGBYZZ0_YZZ09,XLXSJGBYZZ0_YZZ10 "); if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) SQL.Add(",JSYCBZ"); //if (dicJGBFGQCPYZ.Count > 0) // SQL.Add(",JGBTJYZYCBZ"); SQL.Add(" from "); SQL.Add("("); SQL.Add(" select isnull(XLXSCLQD_CLZL,0) as XLXSCLQD_CLZL,XLXSJGBYZZ0_JGBID as JGBID,XLXSJGBYZZ0_XH as XH,XLXSJGBYZZ0_YZZ01,XLXSJGBYZZ0_YZZ02,XLXSJGBYZZ0_YZZ03,XLXSJGBYZZ0_YZZ04,XLXSJGBYZZ0_YZZ05,XLXSJGBYZZ0_YZZ06,XLXSJGBYZZ0_YZZ07,XLXSJGBYZZ0_YZZ08,XLXSJGBYZZ0_YZZ09,XLXSJGBYZZ0_YZZ10 "); if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add(" ,case "); if (dicJGBTJYZ.Count > 0) { foreach (string sKey in dicJGBTJYZ.Keys) { SQL.Add(string.Format(" when XLXSJGBYZZ0_YZZ" + sKey.Replace("JZ", "") + " = 0 then '{0}' ", sKey.Substring(3, 1))); } } if (dicJGBFGQCPYZ.Count > 0) { foreach (string sKey in dicJGBFGQCPYZ.Keys) { SQL.Add(string.Format(" when XLXSJGBYZZ0_YZZ" + sKey.Replace("JZ", "") + " = -9999 then '{0}' ", sKey.Substring(3, 1))); } } SQL.Add(" else 'S' "); SQL.Add(" end as JSYCBZ "); } SQL.Add(" from XLXSJGBYZZ0"); SQL.Add(" left join XLXSJGBMX on XLXSJGBMX_JGBID=:pJGBID and XLXSJGBMX_XH=XLXSJGBYZZ0_XH"); SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); SQL.Add(" where XLXSJGBYZZ0_JGBID=:pJGBID "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID = :pJGCZBID"); SQL.Add(" and XLXSCLQD_JGCZBBBID = :pJGCZBBBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } if (maxXH != 0) { SQL.Add(" and XLXSJGBYZZ0_XH > :pmaxXH"); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" ) a"); SQL.Add(" ) sor "); SQL.Add(" on( "); SQL.Add(" XLXSJGBMX_JGBID=:pJGBID "); SQL.Add(" and XLXSJGBMX_JGBID=sor.JGBID "); SQL.Add(" and XLXSJGBMX_XH=XH "); //此处未传参数区分,暂先默认 SQL.Add(" and XLXSJGBMX_SYXH=0 "); SQL.Add(" and XLXSJGBMX_JLDW in ('M','Km','米','千米') "); SQL.Add(" ) "); SQL.Add(" when matched then update set "); if (sJSBLFS.Equals("C1") || sJSBLFS.Equals("C2"))//C1|进一法(材料价各分项进一)、C2|进一法(材料价汇总进一) { if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix({0}*{1},8))/{1}", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix({0}*{1},8))/{1}", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix({0}*{1},8))/{1}", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix({0}*{1},8))/{1}", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix({0} ,6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" )*-1 end ,"); } else { SQL.Add(string.Format("XLXSJGBMX_WSBJ=CEILING(RoundFix({0}*{1},8))/{1}", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_HSBJ=CEILING(RoundFix({0}*{1},8))/{1}", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), Math.Pow(10.0, iXSWS))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_WSBJM=RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end), "); SQL.Add(string.Format("XLXSJGBMX_HSBJM=RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end), "); } } else if (sJSBLFS.Equals("C3"))//C3|材料价汇总进一+表价进一到十位 { if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix({0},{1})/10)*10", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix({0},{1})/10)*10", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("CEILING(RoundFix({0},{1})/10)*10", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("CEILING(RoundFix({0},{1})/10)*10", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" )*-1 end ,"); } else { SQL.Add(string.Format("XLXSJGBMX_WSBJ = CEILING(RoundFix({0},{1})/10)*10", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_HSBJ = CEILING(RoundFix({0},{1})/10)*10", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), iXSWS.ToString().Trim())); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_WSBJM=RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) , "); SQL.Add(string.Format("XLXSJGBMX_HSBJM=RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end), "); } } else { if (dicJGBTJYZ.Count > 0 || dicJGBFGQCPYZ.Count > 0) { SQL.Add("XLXSJGBMX_WSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix({0},{1})", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), iXSWS)); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix({0},{1})", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), iXSWS)); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJ="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix({0},{1})", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), iXSWS)); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix({0},{1})", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), iXSWS)); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) "); SQL.Add(" )*-1 end , "); SQL.Add("XLXSJGBMX_WSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" )*-1 end ,"); SQL.Add("XLXSJGBMX_HSBJM="); SQL.Add(" case when JSYCBZ='S' then "); SQL.Add(string.Format("RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end) "); SQL.Add("else ABS("); SQL.Add(string.Format("RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" )*-1 end ,"); } else { SQL.Add(string.Format("XLXSJGBMX_WSBJ=RoundFix({0},{1})", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJ,0))"), iXSWS)); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_HSBJ=RoundFix({0},{1})", sJSGS.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJ,0))"), iXSWS)); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJ,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJ,0) = 0 then 0 else 1 end) ,"); SQL.Add(string.Format("XLXSJGBMX_WSBJM=RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_WSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_WSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_WSJJM,0) = 0 then 0 else 1 end), "); SQL.Add(string.Format("XLXSJGBMX_HSBJM=RoundFix({0},6) ", sJSGSM.Replace("JZ", "XLXSJGBYZZ0_YZZ").Replace("JGBJJ", "abs(isnull(XLXSJGBMX_HSJJM,0))"))); SQL.Add(" * (case when isnull(XLXSJGBMX_HSJJM,0) < 0 then (-1) when isnull(XLXSJGBMX_HSJJM,0) = 0 then 0 else 1 end), "); } } SQL.Add(" XLXSJGBMX_WHR=:pWHR, "); SQL.Add(" XLXSJGBMX_WHRID=:pWHRID, "); SQL.Add(" XLXSJGBMX_WHSJ=:pWHSJ "); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pWHR").Value = sWHR; SQL.ParamByName("pWHRID").Value = sWHRID; SQL.ParamByName("pWHSJ").Value = DateTime.Now.ToString(); string ss = SQL.Text; Mac.MacLog.TraceFormat(String.Format("DoCPJJ-merge-Begin")); dberp.ExecSQL(SQL); Mac.MacLog.TraceFormat(String.Format("DoCPJJ-merge-End")); } } else { Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-Begin")); AddXLXSJGBYZZ0(dberp, sMXBH, sJGBID, "", "", "", "", "", "", "", true, sJGCZBID, sJGCZBBBID, maxXH, sBJU003); Mac.MacLog.TraceFormat(String.Format("AddXLXSJGBYZZ0-End")); } } public static Dictionary GetJGBYZJJFS(string sJGBID) { Dictionary dicJGBJJYZ = new Dictionary(); TDatabase dberp = TContextDatabases.GetDatabase("DBERP"); TSQL SQL = new TSQL(dberp); SQL.Clear(); SQL.Add(" SELECT XLXSJGBYZ_YZID,XLXSTZYZ_JJFS "); SQL.Add(" FROM XLXSJGBYZ "); SQL.Add(" LEFT JOIN XLXSTZYZ ON XLXSTZYZ_YZID = XLXSJGBYZ_YZID AND XLXSTZYZ_MXBH='JZJ' "); SQL.Add(" WHERE XLXSJGBYZ_JGBID = :pJGBID "); SQL.ParamByName("pJGBID").Value = sJGBID; DataSet ds = dberp.OpenDataSet(SQL); dicJGBJJYZ.Clear(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (!dicJGBJJYZ.ContainsKey(ds.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim())) dicJGBJJYZ.Add(ds.Tables[0].Rows[i]["XLXSJGBYZ_YZID"].ToString().Trim(), ds.Tables[0].Rows[i]["XLXSTZYZ_JJFS"].ToString().Trim()); } return dicJGBJJYZ; } public static void InsertXLXSJGBWLHQbyJGBCLHQ(TDatabase dberp, TSQL SQL, string sJGBID, string sRQ, string sWHR, string sWHRID, bool bCanUpdate) { SQL.Clear(); SQL.Add("merge into XLXSWLHQ "); SQL.Add("using "); SQL.Add("( "); SQL.Add("select :pJGBID as JGBID,XLXSBJCLWL_WLID as WLID, "); SQL.Add("case when XLXSCLHQ_BJCLID is not null and isnull(XLXSBJCL_JGYBJCLID,' ') <> ' ' then isnull(XLXSCLHQ_WSJG*XLXSWLHQ_JGBL1,0)+isnull(XLXSWLHQ_WSJGF,0) else isnull(XLXSWLHQ_WSJG,0) end as WSJG, "); SQL.Add("case when XLXSCLHQ_BJCLID is not null and isnull(XLXSBJCL_JGYBJCLID,' ') <> ' ' then isnull(XLXSCLHQ_HSJG*XLXSWLHQ_JGBL1,0)+isnull(XLXSWLHQ_HSJGF,0) else isnull(XLXSWLHQ_HSJG,0) end as HSJG, "); SQL.Add("isnull(XLXSWLHQ_WSJGF,0) as WSJGF,isnull(XLXSWLHQ_HSJGF,0) as HSJGF, "); SQL.Add("isnull(XLXSWLHQ_WSJG1,0.0) as WSJG1,isnull(XLXSWLHQ_HSJG1,0.0) as HSJG1,isnull(XLXSWLHQ_JGBL1,0.0) as JGBL1,isnull(XLXSWLHQ_JGYBJCLID1,' ') as JGYBJCLID1"); SQL.Add("from XLXSBJCLWL "); SQL.Add("left join "); SQL.Add(" (select XLXSWLHQ_WLID,XLXSWLHQ_WSJG,XLXSWLHQ_HSJG,XLXSWLHQ_WSJGF,XLXSWLHQ_HSJGF,"); SQL.Add(" XLXSWLHQ_JGYBJCLID1,XLXSWLHQ_WSJG1,XLXSWLHQ_HSJG1,XLXSWLHQ_JGBL1"); SQL.Add(" from XLXSWLHQ,"); SQL.Add(" ("); SQL.Add(" select XLXSWLHQ_WLID as WLID,max(XLXSWLHQ_YXQS) as maxYXQS"); SQL.Add(" from XLXSWLHQ"); SQL.Add(" where XLXSWLHQ_JGBID=' '"); SQL.Add(" and XLXSWLHQ_YXQS<=:pRQ and(XLXSWLHQ_YXQZ>=:pRQ or XLXSWLHQ_YXQZ is null)"); SQL.Add(" group by XLXSWLHQ_WLID"); SQL.Add(" ) a "); SQL.Add(" where XLXSWLHQ_JGBID=' ' "); SQL.Add(" and XLXSWLHQ_WLID=WLID "); SQL.Add(" and XLXSWLHQ_YXQS=maxYXQS "); SQL.Add(" ) c on XLXSWLHQ_WLID=XLXSBJCLWL_WLID "); SQL.Add("left join XLXSBJCL on XLXSBJCL_BJCLID=XLXSBJCLWL_BJCLID "); SQL.Add("left join XLXSCLHQ on XLXSCLHQ_JGBID=:pJGBID and XLXSCLHQ_BJCLID=XLXSBJCL_JGYBJCLID "); SQL.Add("where XLXSBJCL_BJHQ = '2' ");//and isnull(XLXSBJCL_JGYBJCLID,' ') <> ' ' 只有存在加工原料的物料才记!--存不存在加工原料的物料行情都记 SQL.Add(") B on (XLXSWLHQ_JGBID=B.JGBID and XLXSWLHQ_WLID=B.WLID) "); if (bCanUpdate) { SQL.Add("when matched then "); SQL.Add("update set XLXSWLHQ_WSJG=B.WSJG,XLXSWLHQ_HSJG=B.HSJG,XLXSWLHQ_WSJGF=B.WSJGF,XLXSWLHQ_HSJGF=B.HSJGF, "); SQL.Add(" XLXSWLHQ_WSJG1=B.WSJG1,XLXSWLHQ_HSJG1=B.HSJG1,XLXSWLHQ_JGBL1=B.JGBL1,"); SQL.Add(" XLXSWLHQ_WHR=:pWHR,XLXSWLHQ_WHRID=:pWHRID,XLXSWLHQ_WHSJ=:pWHSJ "); } SQL.Add("when not matched then "); SQL.Add("insert (XLXSWLHQ_JGBID,XLXSWLHQ_WLID,XLXSWLHQ_YXQS,XLXSWLHQ_YXQZ,XLXSWLHQ_WSJG,XLXSWLHQ_HSJG,XLXSWLHQ_WSJGF,XLXSWLHQ_HSJGF,"); SQL.Add(" XLXSWLHQ_JGYBJCLID1,XLXSWLHQ_HSJG1,XLXSWLHQ_WSJG1,XLXSWLHQ_JGBL1,"); SQL.Add(" XLXSWLHQ_WHR,XLXSWLHQ_WHRID,XLXSWLHQ_WHSJ) "); SQL.Add("values (B.JGBID,B.WLID,convert(datetime,'1900-01-01 00:00:00'),convert(datetime,'1900-01-01 00:00:00'),B.WSJG,B.HSJG,B.WSJGF,B.HSJGF,"); SQL.Add(" B.JGYBJCLID1,B.HSJG1,B.WSJG1,B.JGBL1,"); SQL.Add(" :pWHR,:pWHRID,:pWHSJ) "); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pRQ").Value = sRQ; SQL.ParamByName("pWHR").Value = sWHR; SQL.ParamByName("pWHRID").Value = sWHRID; SQL.ParamByName("pWHSJ").Value = DateTime.Now; dberp.ExecSQL(SQL); } /// /// 价格表基价复盘 /// /// public static bool NeedJGBJJFP() { return XLBJDUtils.GetXLXSBJPZXX(100860018).NeedJGBJJFP(); } public static void ReCalcWSJG(TDatabase dberp, TSQL SQL, string sJGBID, string sMXBH, int iXSWS, double maxXH) { JGBMLXX jgbxx = XLBJDUtils.GetXLXSJGBXX(sJGBID, sMXBH); if (jgbxx.XLXSJGB_TJYS == "1" && jgbxx.XLXSJGB_JJLY == "A" && jgbxx.XLXSJGB_BJLY == "J" && jgbxx.XLXSJGB_WSJGJSLY == "2") { SQL.Clear(); SQL.Add(string.Format(@"update XLXSJGBMX set XLXSJGBMX_WSJJ = roundfix(XLXSJGBMX_HSJJ*(1-:pZZSL/100),{0}), XLXSJGBMX_WSJJM = roundfix(XLXSJGBMX_HSJJM*(1- :pZZSL/100),6), XLXSJGBMX_WSBJ = roundfix(XLXSJGBMX_HSBJ*(1- :pZZSL/100),{0}), XLXSJGBMX_WSBJM = roundfix(XLXSJGBMX_HSBJM*(1- :pZZSL/100),6) where XLXSJGBMX_JGBID = :pJGBID and XLXSJGBMX_XH > :pMaxXH ",iXSWS)); SQL.ParamByName("pZZSL").Value = CMISproConvert.StrToFloat(jgbxx.XLXSJGB_ZZSL, 0); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pMaxXH").Value = maxXH; dberp.ExecSQL(SQL); } } public static void UpdateCLCB(TDatabase dberp, TSQL SQL, string sJGBID, int iXSWS, string sJSBLFS, string sWHRID, string sWHR,string sBJU003) { UpdateCLCB(dberp, SQL, sJGBID, "", "", iXSWS, sJSBLFS, sWHRID, sWHR, 0, "", "", "", 0, 0, "", 0, sBJU003);//参数maxXH为0时的处理逻辑保持不变 } public static void UpdateCLCB(TDatabase dberp, TSQL SQL, string sJGBID, int iXSWS, string sJSBLFS, string sWHRID, string sWHR, double maxXH, string sBJU003) { UpdateCLCB(dberp, SQL, sJGBID, "", "", iXSWS, sJSBLFS, sWHRID, sWHR, maxXH, "", "", "", 0, 0, "", 0, sBJU003); } //调价因素3价格表,则XLXSCLQD_JGBHSCB、XLXSCLQD_JGBWSCB只用来记录材料价价差 public static void UpdateCLCB(TDatabase dberp, TSQL SQL, string sJGBID, string sJGCZBID, string sJGCZBBBID, int iXSWS, string sJSBLFS, string sWHRID, string sWHR, double maxXH, string sJGBID1, string sTBJCLID_JGBBJ, string sLBJCLID_JGBBJ, double dTJ_JGBBJ, double dLJ_JGBBJ, string sBJDID, int iMinXH, string sBJDXHList, string sBJU003) { bool bExistsWLHQ = false;//是否存在物料行情报价材料 if (CMISproDataBase.ExistsRecord("DBERP", string.Format("select top 1 XLXSBJCL_BJCLID from XLXSBJCL where XLXSBJCL_BJHQ='2'"))) bExistsWLHQ = true; bool IsJGBID3 = false; if (!sJGBID1.Equals("")) { if (CMISproDataBase.ExistsRecord("DBERP", string.Format("select 1 from XLXSJGB where XLXSJGB_JGBID='{0}' and XLXSJGB_TJYS='3'", sJGBID))) IsJGBID3 = true; } bool bCPMLXZ = false; string sCPMLIDS = string.Empty; if (XLBJDUtils.IsJGEJGB(sJGBID) && !sBJDID.Equals("")) { //查询报价分类产品目录 SQL.Clear(); SQL.Add(@"select XLXSCPML_CPMLIDS from XLXSBJD left join XLXSBJFL on XLXSBJD_BJFLID=XLXSBJFL_BJFLID left join XLXSCPML on XLXSCPML_CPMLID=XLXSBJFL_CPMLID where XLXSBJD_BJDID=:pBJDID and isnull(XLXSCPML_CPMLIDS,' ')<>' ' "); SQL.ParamByName("pBJDID").Value = sBJDID; DataSet dsFLML = dberp.OpenDataSet(SQL); if (dsFLML.Tables[0].Rows.Count > 0) { bCPMLXZ = true; string[] sCPMLID_List = dsFLML.Tables[0].Rows[0][0].ToString().Trim().Split(','); sCPMLIDS = "("; for (int i = 0; i < sCPMLID_List.Length; i++) { sCPMLIDS += "'" + sCPMLID_List[i] + "',"; } sCPMLIDS = sCPMLIDS.TrimEnd(',') + ")"; } } string sBJFLID = ""; string sBJRQ = ""; string sTBJCLID = ""; string sLBJCLID = ""; double dTJ = 0.0; double dLJ = 0.0; string sBJDHQLX = "JGBHQ";//报价单行情类型 bool bNeedCalJGBEx = false;//被报价单调用时,是否需要重算衍生扩展价格表 if (!sBJDID.Trim().Equals("")) { SQL.Clear(); SQL.Add("select XLXSBJD_BJFLID,XLXSBJD_BJRQ,XLXSBJD_TJ,XLXSBJD_LJ, "); SQL.Add(" XLXSBJFL_BJDHQLY,XLXSBJFL_TZCLHQ,XLXSBJFL_TBJCLID,XLXSBJFL_LBJCLID"); SQL.Add(" from XLXSBJD"); SQL.Add(" left join XLXSBJFL on XLXSBJFL_BJFLID=XLXSBJD_BJFLID"); SQL.Add(" where XLXSBJD_BJDID=:pBJDID"); SQL.ParamByName("pBJDID").Value = sBJDID.Trim(); DataSet dsBJD = dberp.OpenDataSet(SQL); if (dsBJD.Tables[0].Rows.Count > 0) { sBJFLID = dsBJD.Tables[0].Rows[0]["XLXSBJD_BJFLID"].ToString().Trim(); sBJRQ = dsBJD.Tables[0].Rows[0]["XLXSBJD_BJRQ"].ToString().Trim(); sTBJCLID = dsBJD.Tables[0].Rows[0]["XLXSBJFL_TBJCLID"].ToString().Trim(); sLBJCLID = dsBJD.Tables[0].Rows[0]["XLXSBJFL_LBJCLID"].ToString().Trim(); dTJ = CMISproConvert.StrToFloat(dsBJD.Tables[0].Rows[0]["XLXSBJD_TJ"].ToString()); dLJ = CMISproConvert.StrToFloat(dsBJD.Tables[0].Rows[0]["XLXSBJD_LJ"].ToString()); string sBJDHQLY = dsBJD.Tables[0].Rows[0]["XLXSBJFL_BJDHQLY"].ToString().Trim(); if (sBJDHQLY.Equals("1"))//1|价格表行情 { //报价分类设置了“报价日行情材料” if (CMISproDataBase.ExistsRecord("DBERP", string.Format("select top 1 XLXSBJFLBJRHQCL_BJCLID from XLXSBJFLBJRHQCL where XLXSBJFLBJRHQCL_BJFLID='{0}'", sBJFLID))) { sBJDHQLX = "BJRCLHQ"; } else sBJDHQLX = "JGBHQ"; //允许调整材料行情且存在报价单材料行情时使用报价单材料行情计算 if (dsBJD.Tables[0].Rows[0]["XLXSBJFL_TZCLHQ"].ToString().Trim().Equals("Y")) { if (CMISproDataBase.ExistsRecord("DBERP", string.Format("select top 1 XLXSBJDCLHQ_BJCLID from XLXSBJDCLHQ where XLXSBJDCLHQ_BJDID='{0}'", sBJDID))) sBJDHQLX = "BJDHQ"; } } else//2|报价日行情 { sBJDHQLX = "BJRHQ"; if (CMISproDataBase.ExistsRecord("DBERP", string.Format("select top 1 XLXSBJDCLHQ_BJCLID from XLXSBJDCLHQ where XLXSBJDCLHQ_BJDID='{0}'", sBJDID))) sBJDHQLX = "BJDHQ"; } } if (CMISproDataBase.ExistsRecord("DBERP", string.Format("select top 1 XLXSJGBMX_XH from XLXSJGBMX where XLXSJGBMX_JGBID='{0}' and XLXSJGBMX_SYXH>0.0", sJGBID))) { bNeedCalJGBEx = true; } } bool bNeedAddWLHQ = bExistsWLHQ && (!IsJGBID3 || sBJDHQLX.Equals("BJDHQ"));//若调价因素3价格表,无需执行此分支,因为价格表行情不单独记录物料行情,所以这部分材料价价差始终是0 if (bExistsWLHQ) { SQL.Clear(); SQL.Add(" select XLXSBJCLWL_WLID,A.WL_MC as WLMC,XLXSBJCLWL_JGYWLID,B.WL_MC as JGYWLMC "); SQL.Add(" from XLXSBJCLWL "); SQL.Add(" left join WL A on A.WL_WLID = XLXSBJCLWL_WLID "); SQL.Add(" left join WL B on B.WL_WLID = XLXSBJCLWL_JGYWLID "); SQL.Add(" where XLXSBJCLWL_JGYWLID <> '-' "); DataSet dsCLWL = dberp.OpenDataSet(SQL); if (dsCLWL.Tables[0].Rows.Count > 0) { Dictionary DicWLHQ = new Dictionary(); string sBJDHQTS = ""; if (!sBJDID.Trim().Equals("")) { sBJDHQTS += "或更新报价单材料行情"; SQL.Clear(); SQL.Add(" select XLXSBJDWLHQ_WLID,"); SQL.Add(string.Format("case when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_WSJGF", sTBJCLID, dTJ)); SQL.Add(string.Format(" when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_WSJGF", sLBJCLID, dLJ)); SQL.Add(" else XLXSBJDWLHQ_WSJG end as WSJG, "); SQL.Add(string.Format("case when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_HSJGF", sTBJCLID, dTJ)); SQL.Add(string.Format(" when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_HSJGF", sLBJCLID, dLJ)); SQL.Add(" else XLXSBJDWLHQ_HSJG end as HSJG "); SQL.Add(" from XLXSBJDWLHQ where XLXSBJDWLHQ_BJDID = :pBJDID "); SQL.ParamByName("pBJDID").Value = sBJDID; DataSet dsBJDWLHQ = dberp.OpenDataSet(SQL); if (dsBJDWLHQ.Tables[0].Rows.Count > 0) { foreach (DataRow trow in dsBJDWLHQ.Tables[0].Rows) { string sWLID = trow["XLXSBJDWLHQ_WLID"].ToString().Trim(); if (!DicWLHQ.ContainsKey(sWLID)) { DicWLHQ.Add(sWLID, CMISproConvert.StrToFloat(trow["HSJG"].ToString().Trim())); } } } SQL.Clear(); SQL.Add(" select WLID,XLXSWLHQ_WSJG,XLXSWLHQ_HSJG "); SQL.Add(" from XLXSWLHQ, "); SQL.Add(" (select XLXSWLHQ_WLID as WLID,max(XLXSWLHQ_YXQS)as maxYXQS "); SQL.Add(" from XLXSWLHQ where XLXSWLHQ_JGBID=' ' "); SQL.Add(" and XLXSWLHQ_YXQS<=:pBJRQ and (XLXSWLHQ_YXQZ>=:pBJRQ or XLXSWLHQ_YXQZ is null) "); SQL.Add(" group by XLXSWLHQ_WLID "); SQL.Add(" ) wlhq "); SQL.Add(" where XLXSWLHQ_JGBID=' ' and XLXSWLHQ_WLID=WLID and XLXSWLHQ_YXQS=maxYXQS "); SQL.ParamByName("pBJRQ").Value = sBJRQ; DataSet dsSSWLHQ = dberp.OpenDataSet(SQL); if (dsSSWLHQ.Tables[0].Rows.Count > 0) { foreach (DataRow trow in dsSSWLHQ.Tables[0].Rows) { string sWLID = trow["WLID"].ToString().Trim(); if (!DicWLHQ.ContainsKey(sWLID)) { DicWLHQ.Add(sWLID, CMISproConvert.StrToFloat(trow["XLXSWLHQ_HSJG"].ToString().Trim())); } } } } else { SQL.Clear(); SQL.Add(" select WLID,XLXSWLHQ_WSJG,XLXSWLHQ_HSJG "); SQL.Add(" from XLXSWLHQ, "); SQL.Add(" (select XLXSWLHQ_WLID as WLID,max(XLXSWLHQ_YXQS)as maxYXQS "); SQL.Add(" from XLXSWLHQ where XLXSWLHQ_JGBID=' ' "); SQL.Add(" and XLXSWLHQ_YXQS<=:pBJRQ and (XLXSWLHQ_YXQZ>=:pBJRQ or XLXSWLHQ_YXQZ is null) "); SQL.Add(" group by XLXSWLHQ_WLID "); SQL.Add(" ) wlhq "); SQL.Add(" where XLXSWLHQ_JGBID=' ' and XLXSWLHQ_WLID=WLID and XLXSWLHQ_YXQS=maxYXQS "); SQL.ParamByName("pBJRQ").Value = DateTime.Now.ToShortDateString().Trim(); DataSet dsSSWLHQ = dberp.OpenDataSet(SQL); if (dsSSWLHQ.Tables[0].Rows.Count > 0) { foreach (DataRow trow in dsSSWLHQ.Tables[0].Rows) { string sWLID = trow["WLID"].ToString().Trim(); if (!DicWLHQ.ContainsKey(sWLID)) { DicWLHQ.Add(sWLID, CMISproConvert.StrToFloat(trow["XLXSWLHQ_HSJG"].ToString().Trim())); } } } } foreach (DataRow trow in dsCLWL.Tables[0].Rows) { string sWLID = trow["XLXSBJCLWL_WLID"].ToString().Trim(); double dWLHQ = 0; if (DicWLHQ.ContainsKey(sWLID)) dWLHQ = DicWLHQ[sWLID]; string sJGYWLID = trow["XLXSBJCLWL_JGYWLID"].ToString().Trim(); double dJGYWLHQ = 0; if (DicWLHQ.ContainsKey(sJGYWLID)) dJGYWLHQ = DicWLHQ[sJGYWLID]; if ((dWLHQ != dJGYWLHQ)&&(dWLHQ != 0)&&(dJGYWLHQ != 0)) { throw new Exception("【" + sWLID + "|" + trow["WLMC"].ToString().Trim() + "|" + dWLHQ.ToString() + "】与【" + trow["JGYWLMC"].ToString().Trim() + "|" + dJGYWLHQ.ToString() + "】存在加工关系,但价格不一致,无法计算,请检查物料行情数据" + sBJDHQTS + "!"); } } } } if (!sJGCZBID.Trim().Equals("")) { SQL.Clear(); SQL.Add("select :pJGCZBID as XLXSCLQD_JGCZBID,:pJGCZBBBID as XLXSCLQD_JGCZBBBID, XLJGCZBML_CZBLX from XLJGCZBML where XLJGCZBML_JGCZBID=:pJGCZBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } else { if (sBJDID.Trim().Equals(""))//sBJDID为空,说明是销售价格表模块调用 { SQL.Clear(); SQL.Add("select distinct XLXSCLQD_JGCZBID,XLXSCLQD_JGCZBBBID,XLJGCZBML_CZBLX"); SQL.Add(" from XLXSJGBMX"); SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID"); SQL.Add(" and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID"); SQL.Add(" left join XLJGCZBML on XLJGCZBML_JGCZBID=XLXSCLQD_JGCZBID"); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID"); SQL.Add(" and isnull(XLXSCLQD_JGCZBID,' ')<>' ' and XLXSCLQD_WPID='ZZZZ'"); //此处未传参数区分,暂先默认 SQL.Add(" and XLXSJGBMX_SYXH=0 "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); } if (!sJGCZBBBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH"); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" order by XLXSCLQD_JGCZBID"); SQL.ParamByName("pJGBID").Value = sJGBID; } else//sBJDID不为空,说明是被报价单调用 { if (bNeedCalJGBEx) { //此段执行是为了在JGB衍生加点的模式下能计算“报价单行情料价” SQL.Clear(); SQL.Add("select distinct XLXSCLQD_JGCZBID,XLXSCLQD_JGCZBBBID,XLJGCZBML_CZBLX"); SQL.Add(" from XLXSBJDMX"); SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSBJDMX_XLXHID and XLXSCLQD_XLGGID=XLXSBJDMX_XLGGID"); SQL.Add(" and XLXSCLQD_XLBZID=XLXSBJDMX_XLBZID and XLXSCLQD_DYDJID=XLXSBJDMX_DYDJID"); SQL.Add(" left join XLJGCZBML on XLJGCZBML_JGCZBID=XLXSCLQD_JGCZBID"); SQL.Add(" where XLXSBJDMX_BJDID=:pBJDID"); if(!sBJDXHList.Trim().Equals("")) SQL.Add(" and " + CMISproDataBase.GetWhereEqual("XLXSBJDMX_XH", sBJDXHList)); SQL.Add(" and XLXSBJDMX_XH >= :piMinXH"); SQL.Add(" and isnull(XLXSCLQD_JGCZBID,' ')<>' '"); SQL.Add(" order by XLXSCLQD_JGCZBID"); SQL.ParamByName("pBJDID").Value = sBJDID; SQL.ParamByName("piMinXH").Value = iMinXH; //衍生扩展的价格表支持被报价单重算,需要弄个临时表,将如下语句的查询结果插入到临时表中,然后用临时表与所依价格表明细进行关联 //select case when XLXSJGBMX_SYXH=0.0 then XLXSJGBMX_XH else XLXSJGBMX_SYXH end as XH //from XLXSJGBMX //where XLXSJGBMX_JGBID='21100001' //and exists(select 1 from XLXSBJDMX where XLXSBJDMX_BJDID='CZ/XMD2022100005' and XLXSBJDMX_XH>=0 // and XLXSBJDMX_XLXHID=XLXSJGBMX_XLXHID and XLXSBJDMX_XLGGID=XLXSJGBMX_XLGGID // and XLXSBJDMX_XLBZID=XLXSJGBMX_XLBZID and XLXSBJDMX_DYDJID=XLXSJGBMX_DYDJID) } else { SQL.Clear(); SQL.Add("select distinct XLXSCLQD_JGCZBID,XLXSCLQD_JGCZBBBID,XLJGCZBML_CZBLX"); SQL.Add(" from XLXSBJDMX"); SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSBJDMX_XLXHID and XLXSCLQD_XLGGID=XLXSBJDMX_XLGGID"); SQL.Add(" and XLXSCLQD_XLBZID=XLXSBJDMX_XLBZID and XLXSCLQD_DYDJID=XLXSBJDMX_DYDJID"); SQL.Add(" left join XLJGCZBML on XLJGCZBML_JGCZBID=XLXSCLQD_JGCZBID"); SQL.Add(" where XLXSBJDMX_BJDID=:pBJDID"); if (!sBJDXHList.Trim().Equals("")) SQL.Add(" and " + CMISproDataBase.GetWhereEqual("XLXSBJDMX_XH", sBJDXHList)); SQL.Add(" and XLXSBJDMX_XH >= :piMinXH"); SQL.Add(" and isnull(XLXSCLQD_JGCZBID,' ')<>' '"); SQL.Add(" order by XLXSCLQD_JGCZBID"); SQL.ParamByName("pBJDID").Value = sBJDID; SQL.ParamByName("piMinXH").Value = iMinXH; } //SQL.Add(" and exists ( "); //SQL.Add(" select top 1 XLXSBJDMX_XH from XLXSBJDMX "); //SQL.Add(" left join XLXSJGBMX a on a.XLXSJGBMX_JGBID=:pJGBID "); //SQL.Add(" and a.XLXSJGBMX_XLXHID=XLXSBJDMX_XLXHID and a.XLXSJGBMX_XLGGID=XLXSBJDMX_XLGGID "); //SQL.Add(" and a.XLXSJGBMX_XLBZID=XLXSBJDMX_XLBZID and a.XLXSJGBMX_DYDJID=XLXSBJDMX_DYDJID "); //SQL.Add(" where XLXSBJDMX_BJDID= :pBJDID and XLXSBJDMX_XH >= :piMinXH "); //SQL.Add(" and a.XLXSJGBMX_JGBID= XLXSJGBMX_JGBID "); //SQL.Add(" and (case when isnull(a.XLXSJGBMX_SYXH,0)=0 then a.XLXSJGBMX_XH else a.XLXSJGBMX_SYXH end)= XLXSJGBMX_XH"); //SQL.Add(" )"); //SQL.ParamByName("pBJDID").Value = sBJDID; //SQL.ParamByName("piMinXH").Value = iMinXH; } } Dictionary dicJGYLHSJG = new Dictionary(); Dictionary dicJGYLWSJG = new Dictionary(); if (bNeedAddWLHQ) { TSQL sSQL = new TSQL(dberp); sSQL.Add(" select XLXSCLHQ_BJCLID,XLXSCLHQ_HSJG,XLXSCLHQ_WSJG,isnull(JGYBJCLID,' ') as JGYBJCLID "); sSQL.Add(" from XLXSCLHQ "); sSQL.Add(" left join ( "); sSQL.Add(" select distinct XLXSBJCL_JGYBJCLID as JGYBJCLID "); sSQL.Add(" from XLXSBJCL where isnull(XLXSBJCL_JGYBJCLID,' ')<>' '"); sSQL.Add(" ) a on JGYBJCLID=XLXSCLHQ_BJCLID"); sSQL.Add(" where XLXSCLHQ_JGBID=:pJGBID "); sSQL.Add(" and isnull(JGYBJCLID,' ') <> ' ' "); sSQL.ParamByName("pJGBID").Value = sJGBID; DataSet dsJGYL = dberp.OpenDataSet(sSQL); if (dsJGYL.Tables[0].Rows.Count > 0) { foreach (DataRow trow in dsJGYL.Tables[0].Rows) { if (!dicJGYLHSJG.ContainsKey(trow["XLXSCLHQ_BJCLID"].ToString().Trim())) { dicJGYLHSJG.Add(trow["XLXSCLHQ_BJCLID"].ToString().Trim(), CMISproConvert.StrToFloat(trow["XLXSCLHQ_HSJG"].ToString().Trim())); dicJGYLWSJG.Add(trow["XLXSCLHQ_BJCLID"].ToString().Trim(), CMISproConvert.StrToFloat(trow["XLXSCLHQ_WSJG"].ToString().Trim())); } } } } DataSet dsJGCZB = dberp.OpenDataSet(SQL); for (int j = 0; j < dsJGCZB.Tables[0].Rows.Count; j++) { string tmpJGCZBID = dsJGCZB.Tables[0].Rows[j]["XLXSCLQD_JGCZBID"].ToString().Trim(); string tmpJGCZBBBID = dsJGCZB.Tables[0].Rows[j]["XLXSCLQD_JGCZBBBID"].ToString().Trim(); string tmpCZBLX = dsJGCZB.Tables[0].Rows[j]["XLJGCZBML_CZBLX"].ToString().Trim(); //标志材料行情/物料行情 int flag_1 = 0; int flag_2 = 0; string sCLQDL = ""; string sBJHQ = ""; string sBJRCLCB = ""; SQL.Clear(); SQL.Add("select XLJGCZBLM_CLQDL,isnull(XLXSBJCL_BJHQ,'1') as XLXSBJCL_BJHQ,isnull(XLJGCZBLM_BJRCLCB,'N') as XLJGCZBLM_BJRCLCB "); SQL.Add(" from XLJGCZBLM"); SQL.Add(" left join XLXSBJCL on XLXSBJCL_BJCLID=XLJGCZBLM_BJCLID"); SQL.Add(" where XLJGCZBLM_JGCZBID=:pJGCZBID"); SQL.Add(" and XLJGCZBLM_JGCZBBBID=:pJGCZBBBID"); SQL.Add(" and isnull(XLJGCZBLM_CLQDL,' ')<>' '"); SQL.Add(" order by XLJGCZBLM_CLQDL"); SQL.ParamByName("pJGCZBID").Value = tmpJGCZBID; SQL.ParamByName("pJGCZBBBID").Value = tmpJGCZBBBID; DataSet dsCLQDL = dberp.OpenDataSet(SQL); for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); if (sBJHQ.Equals("1"))//1|材料行情 { flag_1 = 1; } if (sBJHQ.Equals("2"))//2|物料行情 { flag_2 = 1; } if (1 == flag_1 && 1 == flag_2) { break; } } //B类尺重表都按材料行情计算 //B类实际上应当与下方一致,如果导入的报价材料没有物料行情 if (tmpCZBLX.Equals("B")) { /* merge into 目标表 a using 源表 b on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……) when matched then update set a.更新字段=b.字段 when not matched then insert into a(字段1,字段2……)values(值1,值2……) */ SQL.Clear(); SQL.Add(" merge into XLXSCLQD a "); SQL.Add(" using "); SQL.Add(" ("); SQL.Add(" select XLJGCZBLM_JGCZBID as JGCZBID, XLJGCZBLM_JGCZBBBID as JGCZBBBID,"); for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); SQL.Add(string.Format(" sum(case when XLJGCZBLM_CLQDL='{0}' then isnull(XLXSCLHQ_WSJG,0.0) else 0.0 end * case when isnull(XLJGCZBLM_BJRCLCB,'N') = 'Y' then 0 else 1 end ) as CLJG{1},", sCLQDL, sCLQDL.Replace("第", "").Replace("列", ""))); SQL.Add(string.Format(" sum(case when XLJGCZBLM_CLQDL='{0}' then isnull(XLXSCLHQ_HSJG,0.0) else 0.0 end * case when isnull(XLJGCZBLM_BJRCLCB,'N') = 'Y' then 0 else 1 end ) as HSJG{1},", sCLQDL, sCLQDL.Replace("第", "").Replace("列", ""))); } SQL.Add(" ' ' as MJBZ "); SQL.Add(" from XLJGCZBLM "); if (IsJGBID3) { SQL.Add(" left join ("); if (!sTBJCLID_JGBBJ.Trim().Equals("") || !sLBJCLID_JGBBJ.Trim().Equals(""))//存在铜铝报价材料ID时用传入的铜铝价代替材料清单中的铜铝报价材料价格 { SQL.Add(" select j3.XLXSCLHQ_BJCLID as XLXSCLHQ_BJCLID,"); SQL.Add(" case when ISNULL(j3.XLXSCLHQ_BJCLID, ' ') = :pTBJCLID then :pTJ - j1.XLXSCLHQ_HSJG "); SQL.Add(" when ISNULL(j3.XLXSCLHQ_BJCLID, ' ') = :pLBJCLID then :pLJ - j1.XLXSCLHQ_HSJG else j3.XLXSCLHQ_HSJG-j1.XLXSCLHQ_HSJG end as XLXSCLHQ_HSJG,"); SQL.Add(" case when ISNULL(j3.XLXSCLHQ_BJCLID, ' ') = :pTBJCLID then :pTJ - j1.XLXSCLHQ_WSJG "); SQL.Add(" when ISNULL(j3.XLXSCLHQ_BJCLID, ' ') = :pLBJCLID then :pLJ - j1.XLXSCLHQ_WSJG else j3.XLXSCLHQ_WSJG-j1.XLXSCLHQ_WSJG end as XLXSCLHQ_WSJG "); SQL.ParamByName("pTBJCLID").Value = sTBJCLID_JGBBJ; SQL.ParamByName("pLBJCLID").Value = sLBJCLID_JGBBJ; SQL.ParamByName("pTJ").Value = dTJ_JGBBJ; SQL.ParamByName("pLJ").Value = dLJ_JGBBJ; SQL.Add(" from XLXSCLHQ j1,XLXSCLHQ j3"); SQL.Add(" where j1.XLXSCLHQ_JGBID=:pJGBID1 and j3.XLXSCLHQ_JGBID=:pJGBID"); SQL.Add(" and j1.XLXSCLHQ_BJCLID=j3.XLXSCLHQ_BJCLID"); SQL.Add(" ) jj on XLXSCLHQ_BJCLID=XLJGCZBLM_BJCLID"); SQL.ParamByName("pJGBID1").Value = sJGBID1; SQL.ParamByName("pJGBID").Value = sJGBID; } else if (sBJDID.Trim().Equals(""))//sBJDID为空,说明是销售价格表模块调用 { SQL.Add(" select j3.XLXSCLHQ_BJCLID as XLXSCLHQ_BJCLID,"); SQL.Add(" j3.XLXSCLHQ_HSJG-j1.XLXSCLHQ_HSJG as XLXSCLHQ_HSJG,j3.XLXSCLHQ_WSJG-j1.XLXSCLHQ_WSJG as XLXSCLHQ_WSJG"); SQL.Add(" from XLXSCLHQ j1,XLXSCLHQ j3"); SQL.Add(" where j1.XLXSCLHQ_JGBID=:pJGBID1 and j3.XLXSCLHQ_JGBID=:pJGBID"); SQL.Add(" and j1.XLXSCLHQ_BJCLID=j3.XLXSCLHQ_BJCLID"); SQL.Add(" ) jj on XLXSCLHQ_BJCLID=XLJGCZBLM_BJCLID"); SQL.ParamByName("pJGBID1").Value = sJGBID1; SQL.ParamByName("pJGBID").Value = sJGBID; } else { SQL.Add(" select j3.XLXSCLHQ_BJCLID as XLXSCLHQ_BJCLID,"); SQL.Add(" case when isnull(XLXSBJDCLHQ_BJCLID,' ')=' ' then (j3.XLXSCLHQ_HSJG-j1.XLXSCLHQ_HSJG) else (XLXSBJDCLHQ_HSJG-j1.XLXSCLHQ_HSJG) end as XLXSCLHQ_HSJG,"); SQL.Add(" case when isnull(XLXSBJDCLHQ_BJCLID,' ')=' ' then (j3.XLXSCLHQ_WSJG-j1.XLXSCLHQ_WSJG) else (XLXSBJDCLHQ_WSJG-j1.XLXSCLHQ_WSJG) end as XLXSCLHQ_WSJG "); SQL.Add(" from XLXSCLHQ j1,XLXSCLHQ j3"); SQL.Add(" left join XLXSBJDCLHQ on XLXSBJDCLHQ_BJDID=:pBJDIDD and XLXSBJDCLHQ_BJCLID=j3.XLXSCLHQ_BJCLID"); SQL.Add(" where j1.XLXSCLHQ_JGBID=:pJGBID1 and j3.XLXSCLHQ_JGBID=:pJGBID"); SQL.Add(" and j1.XLXSCLHQ_BJCLID=j3.XLXSCLHQ_BJCLID"); SQL.Add(" ) jj on XLXSCLHQ_BJCLID=XLJGCZBLM_BJCLID"); SQL.ParamByName("pJGBID1").Value = sJGBID1; SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pBJDIDD").Value = sBJDID.Trim(); } } else { if (!sTBJCLID_JGBBJ.Trim().Equals("") || !sLBJCLID_JGBBJ.Trim().Equals("")) { SQL.Add(" left join ("); SQL.Add(" select XLXSCLHQ_BJCLID,"); SQL.Add(" case when ISNULL(XLXSCLHQ_BJCLID, ' ') = :pTBJCLID then :pTJ "); SQL.Add(" when isnull(XLXSCLHQ_JGYBJCLID1,' ')=:pTBJCLID then :pTJ*XLXSCLHQ_JGBL1+XLXSCLHQ_HSJGF"); SQL.Add(" when ISNULL(XLXSCLHQ_BJCLID, ' ') = :pLBJCLID then :pLJ "); SQL.Add(" when isnull(XLXSCLHQ_JGYBJCLID1,' ')=:pLBJCLID then :pLJ*XLXSCLHQ_JGBL1+XLXSCLHQ_HSJGF"); SQL.Add(" else XLXSCLHQ_HSJG end as XLXSCLHQ_HSJG,"); SQL.Add(" case when ISNULL(XLXSCLHQ_BJCLID, ' ') = :pTBJCLID then roundfix(:pTJ/(1+XLXSBJCL_ZZSL/100.0)," + XLBJDUtils.BJCLPriceDecimal + ") "); SQL.Add(" when isnull(XLXSCLHQ_JGYBJCLID1,' ')=:pTBJCLID then roundfix(:pTJ/(1+XLXSBJCL_ZZSL/100.0)," + XLBJDUtils.BJCLPriceDecimal + ")*XLXSCLHQ_JGBL1+XLXSCLHQ_WSJGF"); SQL.Add(" when ISNULL(XLXSCLHQ_BJCLID, ' ') = :pLBJCLID then roundfix(:pLJ/(1+XLXSBJCL_ZZSL/100.0)," + XLBJDUtils.BJCLPriceDecimal + ") "); SQL.Add(" when isnull(XLXSCLHQ_JGYBJCLID1,' ')=:pLBJCLID then roundfix(:pLJ/(1+XLXSBJCL_ZZSL/100.0)," + XLBJDUtils.BJCLPriceDecimal + ")*XLXSCLHQ_JGBL1+XLXSCLHQ_WSJGF"); SQL.Add(" else XLXSCLHQ_WSJG end as XLXSCLHQ_WSJG "); SQL.Add(" from XLXSCLHQ "); SQL.Add(" left join XLXSBJCL on XLXSBJCL_BJCLID=XLXSCLHQ_BJCLID"); SQL.Add(" where XLXSCLHQ_JGBID=:pJGBID ) jj on XLXSCLHQ_BJCLID=XLJGCZBLM_BJCLID"); SQL.ParamByName("pTBJCLID").Value = sTBJCLID_JGBBJ; SQL.ParamByName("pLBJCLID").Value = sLBJCLID_JGBBJ; SQL.ParamByName("pTJ").Value = dTJ_JGBBJ; SQL.ParamByName("pLJ").Value = dLJ_JGBBJ; SQL.ParamByName("pJGBID").Value = sJGBID; } else { if (sBJDHQLX.Equals("BJRCLHQ"))//报价日材料行情 { SQL.Add(" left join "); SQL.Add(" ("); SQL.Add(" select XLXSBJCL_BJCLID as XLXSCLHQ_BJCLID,"); SQL.Add(" case when isnull(XLXSBJFLBJRHQCL_BJCLID,' ')<>' ' then bjrclhq.CLJG else jgbclhq.CLJG end as XLXSCLHQ_WSJG, "); SQL.Add(" case when isnull(XLXSBJFLBJRHQCL_BJCLID,' ')<>' ' then bjrclhq.HSJG else jgbclhq.HSJG end as XLXSCLHQ_HSJG "); SQL.Add(" from XLXSBJCL"); SQL.Add(" left join XLXSBJFLBJRHQCL on XLXSBJFLBJRHQCL_BJFLID=:pBJFLID and XLXSBJFLBJRHQCL_BJCLID=XLXSBJCL_BJCLID"); //bjrclhq 报价材料之报价日行情 SQL.Add(" left join ("); SQL.Add(" select BJCLID,XLXSCLHQ_WSJG as CLJG,XLXSCLHQ_HSJG as HSJG"); SQL.Add(" from XLXSCLHQ,"); SQL.Add(" ("); SQL.Add(" select XLXSCLHQ_BJCLID as BJCLID,max(XLXSCLHQ_YXQS)as maxYXQS"); SQL.Add(" from XLXSCLHQ"); SQL.Add(" where XLXSCLHQ_JGBID='ZZZZZZZZ'"); SQL.Add(" and XLXSCLHQ_YXQS<=:pBJRQ and(XLXSCLHQ_YXQZ>=:pBJRQ or XLXSCLHQ_YXQZ is null)"); SQL.Add(" group by XLXSCLHQ_BJCLID"); SQL.Add(" ) a"); SQL.Add(" where XLXSCLHQ_JGBID='ZZZZZZZZ' "); SQL.Add(" and XLXSCLHQ_BJCLID=BJCLID"); SQL.Add(" and XLXSCLHQ_YXQS=maxYXQS"); SQL.Add(" )bjrclhq on bjrclhq.BJCLID=XLXSBJCL_BJCLID"); //jgbclhq 报价材料之价格表行情 SQL.Add(" left join ("); SQL.Add(" select XLXSCLHQ_BJCLID as BJCLID,XLXSCLHQ_WSJG as CLJG,XLXSCLHQ_HSJG as HSJG"); SQL.Add(" from XLXSCLHQ"); SQL.Add(" where XLXSCLHQ_JGBID<>'ZZZZZZZZ' and XLXSCLHQ_JGBID=:pJGBID"); SQL.Add(" )jgbclhq on jgbclhq.BJCLID=XLXSBJCL_BJCLID"); SQL.Add(" ) JGB on JGB.BJCLID=XLJGCZBLM_BJCLID"); SQL.ParamByName("pBJFLID").Value = sBJFLID; SQL.ParamByName("pBJRQ").Value = sBJRQ; SQL.ParamByName("pJGBID").Value = sJGBID; } else if (sBJDHQLX.Equals("BJRHQ"))//报价日行情 { SQL.Add(" left join "); SQL.Add(" ("); SQL.Add(" select XLXSCLHQ_BJCLID,XLXSCLHQ_WSJG,XLXSCLHQ_HSJG"); SQL.Add(" from XLXSCLHQ,"); SQL.Add(" ("); SQL.Add(" select XLXSCLHQ_BJCLID as BJCLID,max(XLXSCLHQ_YXQS)as maxYXQS"); SQL.Add(" from XLXSCLHQ"); SQL.Add(" where XLXSCLHQ_JGBID='ZZZZZZZZ'"); SQL.Add(" and XLXSCLHQ_YXQS<=:pBJRQ and(XLXSCLHQ_YXQZ>=:pBJRQ or XLXSCLHQ_YXQZ is null)"); SQL.Add(" group by XLXSCLHQ_BJCLID"); SQL.Add(" ) a"); SQL.Add(" where XLXSCLHQ_JGBID='ZZZZZZZZ' "); SQL.Add(" and XLXSCLHQ_BJCLID=BJCLID"); SQL.Add(" and XLXSCLHQ_YXQS=maxYXQS"); SQL.Add(" ) JGB on JGB.XLXSCLHQ_BJCLID=XLJGCZBLM_BJCLID"); SQL.ParamByName("pBJRQ").Value = sBJRQ; } else if (sBJDHQLX.Equals("BJDHQ"))//报价单行情 { SQL.Add(" left join "); SQL.Add(" ("); SQL.Add(" select XLXSBJDCLHQ_BJCLID as XLXSCLHQ_BJCLID,XLXSBJDCLHQ_WSJG as XLXSCLHQ_WSJG,XLXSBJDCLHQ_HSJG as XLXSCLHQ_HSJG"); SQL.Add(" from XLXSBJDCLHQ"); SQL.Add(string.Format(" where XLXSBJDCLHQ_BJDID='{0}'", sBJDID)); SQL.Add(" ) JGB on JGB.XLXSCLHQ_BJCLID=XLJGCZBLM_BJCLID"); } else//价格表行情 { SQL.Add(" left join XLXSCLHQ on XLXSCLHQ_JGBID=:pJGBID and XLXSCLHQ_BJCLID=XLJGCZBLM_BJCLID"); SQL.ParamByName("pJGBID").Value = sJGBID; } } } SQL.Add(" where XLJGCZBLM_JGCZBID=:pJGCZBID"); SQL.Add(" and XLJGCZBLM_JGCZBBBID=:pJGCZBBBID"); SQL.Add(" and isnull(XLJGCZBLM_CLQDL,' ')<>' '"); SQL.Add(" group by XLJGCZBLM_JGCZBID,XLJGCZBLM_JGCZBBBID"); SQL.Add(" ) b "); SQL.Add(" on( "); SQL.Add(" a.XLXSCLQD_JGCZBID=:pJGCZBID and a.XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.Add(" and a.XLXSCLQD_JGCZBID=b.JGCZBID and a.XLXSCLQD_JGCZBBBID=b.JGCZBBBID "); if (!sBJDID.Trim().Equals(""))//这段是否有必要限制到具体要重算的产品,还是整个尺重表一起算,需要看项目执行效果再定 { SQL.Add(" and exists ("); SQL.Add("select 1 "); SQL.Add(" from XLXSBJDMX"); SQL.Add(" where XLXSBJDMX_BJDID=:pBJDID"); if (!sBJDXHList.Trim().Equals("")) SQL.Add(" and " + CMISproDataBase.GetWhereEqual("XLXSBJDMX_XH", sBJDXHList)); SQL.Add(" and XLXSBJDMX_XH >= :piMinXH"); SQL.Add(" and XLXSBJDMX_XLXHID=a.XLXSCLQD_XLXHID and XLXSBJDMX_XLGGID=a.XLXSCLQD_XLGGID"); SQL.Add(" and XLXSBJDMX_XLBZID=a.XLXSCLQD_XLBZID and XLXSBJDMX_DYDJID=a.XLXSCLQD_DYDJID"); SQL.Add(" ) "); SQL.ParamByName("pBJDID").Value = sBJDID; SQL.ParamByName("piMinXH").Value = iMinXH; } SQL.Add(" ) "); SQL.Add(" when matched then update set a.XLXSCLQD_JGBWSCB= "); if (!IsJGBID3)//调价因素3价格表不进行负数的校验,因为此时CLJG{0}代表的是两个价格表行情之差 { if (1 == flag_1) { SQL.Add(" (case "); } for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("1") && !sBJRCLCB.Equals("Y"))//1|材料行情 { SQL.Add(string.Format(" when (a.XLXSCLQD_SL{0} > 0 and isnull(b.CLJG{0},0) = 0) then (-1) ", sCLQDL.Replace("第", "").Replace("列", ""))); } } if (1 == flag_1) { SQL.Add(" else 1 end)* "); } } SQL.Add(" ( "); if (sJSBLFS.Equals("C1"))//C1|进一法(材料价各分项进一) { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); SQL.Add(string.Format("CEILING(RoundFix(a.XLXSCLQD_SL{0}*b.CLJG{0}*(1+a.XLXSCLQD_SHL{0}/100)*a.XLXSCLQD_CLJGBL{0}*{1},8))/{1}+", sCLQDL.Replace("第", "").Replace("列", ""), Math.Pow(10.0, iXSWS))); } } else { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); SQL.Add(string.Format("a.XLXSCLQD_SL{0}*b.CLJG{0}*(1+a.XLXSCLQD_SHL{0}/100)*a.XLXSCLQD_CLJGBL{0}+", sCLQDL.Replace("第", "").Replace("列", ""))); } } SQL.Add("0), "); SQL.Add(" a.XLXSCLQD_JGBHSCB="); if (!IsJGBID3)//调价因素3价格表不进行负数的校验,因为此时CLJG{0}代表的是两个价格表行情之差 { if (1 == flag_1) { SQL.Add(" (case "); } for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("1") && !sBJRCLCB.Equals("Y"))//1|材料行情 { SQL.Add(string.Format(" when (a.XLXSCLQD_SL{0} > 0 and isnull(b.CLJG{0},0) = 0) then (-1) ", sCLQDL.Replace("第", "").Replace("列", ""))); } } if (1 == flag_1) { SQL.Add(" else 1 end)* "); } } SQL.Add(" ( "); if (sJSBLFS.Equals("C1"))//C1|进一法(材料价各分项进一) { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); SQL.Add(string.Format("CEILING(RoundFix(a.XLXSCLQD_SL{0}*b.HSJG{0}*(1+a.XLXSCLQD_SHL{0}/100)*a.XLXSCLQD_CLJGBL{0}*{1},8))/{1}+", sCLQDL.Replace("第", "").Replace("列", ""), Math.Pow(10.0, iXSWS))); } } else { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); SQL.Add(string.Format("a.XLXSCLQD_SL{0}*b.HSJG{0}*(1+a.XLXSCLQD_SHL{0}/100)*a.XLXSCLQD_CLJGBL{0}+", sCLQDL.Replace("第", "").Replace("列", ""))); } } SQL.Add("0) "); SQL.ParamByName("pJGCZBID").Value = tmpJGCZBID; SQL.ParamByName("pJGCZBBBID").Value = tmpJGCZBBBID; dberp.ExecSQL(SQL); } else//Z类A类C类 { /* merge into 目标表 a using 源表 b on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……) when matched then update set a.更新字段=b.字段 when not matched then insert into a(字段1,字段2……)values(值1,值2……) */ SQL.Clear(); SQL.Add(" merge into XLXSCLQD a "); SQL.Add(" using "); SQL.Add(" ("); SQL.Add(" select XLJGCZBLM_JGCZBID as JGCZBID, XLJGCZBLM_JGCZBBBID as JGCZBBBID,"); for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); if (sBJHQ.Equals("1"))//1|材料行情 { SQL.Add(string.Format(" sum(case when XLJGCZBLM_CLQDL='{0}' then isnull(XLXSCLHQ_WSJG,0.0) else 0.0 end * case when isnull(XLJGCZBLM_BJRCLCB,'N') = 'Y' then 0 else 1 end ) as CLJG{1},", sCLQDL, sCLQDL.Replace("第", "").Replace("列", ""))); SQL.Add(string.Format(" sum(case when XLJGCZBLM_CLQDL='{0}' then isnull(XLXSCLHQ_HSJG,0.0) else 0.0 end * case when isnull(XLJGCZBLM_BJRCLCB,'N') = 'Y' then 0 else 1 end ) as HSJG{1},", sCLQDL, sCLQDL.Replace("第", "").Replace("列", ""))); } } SQL.Add(" ' ' as MJBZ "); SQL.Add(" from XLJGCZBLM "); if (IsJGBID3) { SQL.Add(" left join ("); if (!sTBJCLID_JGBBJ.Trim().Equals("") || !sLBJCLID_JGBBJ.Trim().Equals(""))//存在铜铝报价材料ID时用传入的铜铝价代替材料清单中的铜铝报价材料价格 { SQL.Add(" select j3.XLXSCLHQ_BJCLID as XLXSCLHQ_BJCLID,"); SQL.Add(" case when ISNULL(j3.XLXSCLHQ_BJCLID, ' ') = :pTBJCLID then :pTJ - j1.XLXSCLHQ_HSJG "); SQL.Add(" when ISNULL(j3.XLXSCLHQ_BJCLID, ' ') = :pLBJCLID then :pLJ - j1.XLXSCLHQ_HSJG else j3.XLXSCLHQ_HSJG-j1.XLXSCLHQ_HSJG end as XLXSCLHQ_HSJG,"); SQL.Add(" case when ISNULL(j3.XLXSCLHQ_BJCLID, ' ') = :pTBJCLID then :pTJ - j1.XLXSCLHQ_WSJG "); SQL.Add(" when ISNULL(j3.XLXSCLHQ_BJCLID, ' ') = :pLBJCLID then :pLJ - j1.XLXSCLHQ_WSJG else j3.XLXSCLHQ_WSJG-j1.XLXSCLHQ_WSJG end as XLXSCLHQ_WSJG "); SQL.ParamByName("pTBJCLID").Value = sTBJCLID_JGBBJ; SQL.ParamByName("pLBJCLID").Value = sLBJCLID_JGBBJ; SQL.ParamByName("pTJ").Value = dTJ_JGBBJ; SQL.ParamByName("pLJ").Value = dLJ_JGBBJ; SQL.Add(" from XLXSCLHQ j1,XLXSCLHQ j3"); SQL.Add(" where j1.XLXSCLHQ_JGBID=:pJGBID1 and j3.XLXSCLHQ_JGBID=:pJGBID"); SQL.Add(" and j1.XLXSCLHQ_BJCLID=j3.XLXSCLHQ_BJCLID"); SQL.Add(" ) jj on XLXSCLHQ_BJCLID=XLJGCZBLM_BJCLID"); SQL.ParamByName("pJGBID1").Value = sJGBID1; SQL.ParamByName("pJGBID").Value = sJGBID; } else if (sBJDID.Trim().Equals(""))//sBJDID为空,说明是销售价格表模块调用 { SQL.Add(" select j3.XLXSCLHQ_BJCLID as XLXSCLHQ_BJCLID,"); SQL.Add(" j3.XLXSCLHQ_HSJG-j1.XLXSCLHQ_HSJG as XLXSCLHQ_HSJG,j3.XLXSCLHQ_WSJG-j1.XLXSCLHQ_WSJG as XLXSCLHQ_WSJG"); SQL.Add(" from XLXSCLHQ j1,XLXSCLHQ j3"); SQL.Add(" where j1.XLXSCLHQ_JGBID=:pJGBID1 and j3.XLXSCLHQ_JGBID=:pJGBID"); SQL.Add(" and j1.XLXSCLHQ_BJCLID=j3.XLXSCLHQ_BJCLID"); SQL.Add(" ) jj on XLXSCLHQ_BJCLID=XLJGCZBLM_BJCLID"); SQL.ParamByName("pJGBID1").Value = sJGBID1; SQL.ParamByName("pJGBID").Value = sJGBID; } else { SQL.Add(" select j3.XLXSCLHQ_BJCLID as XLXSCLHQ_BJCLID,"); SQL.Add(" case when isnull(XLXSBJDCLHQ_BJCLID,' ')=' ' then (j3.XLXSCLHQ_HSJG-j1.XLXSCLHQ_HSJG) else (XLXSBJDCLHQ_HSJG-j1.XLXSCLHQ_HSJG) end as XLXSCLHQ_HSJG,"); SQL.Add(" case when isnull(XLXSBJDCLHQ_BJCLID,' ')=' ' then (j3.XLXSCLHQ_WSJG-j1.XLXSCLHQ_WSJG) else (XLXSBJDCLHQ_WSJG-j1.XLXSCLHQ_WSJG) end as XLXSCLHQ_WSJG "); SQL.Add(" from XLXSCLHQ j1,XLXSCLHQ j3"); SQL.Add(" left join XLXSBJDCLHQ on XLXSBJDCLHQ_BJDID=:pBJDIDD and XLXSBJDCLHQ_BJCLID=j3.XLXSCLHQ_BJCLID"); SQL.Add(" where j1.XLXSCLHQ_JGBID=:pJGBID1 and j3.XLXSCLHQ_JGBID=:pJGBID"); SQL.Add(" and j1.XLXSCLHQ_BJCLID=j3.XLXSCLHQ_BJCLID"); SQL.Add(" ) jj on XLXSCLHQ_BJCLID=XLJGCZBLM_BJCLID"); SQL.ParamByName("pJGBID1").Value = sJGBID1; SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pBJDIDD").Value = sBJDID.Trim(); } } else { if (!sTBJCLID_JGBBJ.Trim().Equals("") || !sLBJCLID_JGBBJ.Trim().Equals("")) { SQL.Add(" left join ("); SQL.Add(" select XLXSCLHQ_BJCLID,"); SQL.Add(" case when ISNULL(XLXSCLHQ_BJCLID, ' ') = :pTBJCLID then :pTJ "); SQL.Add(" when isnull(XLXSCLHQ_JGYBJCLID1,' ')=:pTBJCLID then :pTJ*XLXSCLHQ_JGBL1+XLXSCLHQ_HSJGF"); SQL.Add(" when ISNULL(XLXSCLHQ_BJCLID, ' ') = :pLBJCLID then :pLJ "); SQL.Add(" when isnull(XLXSCLHQ_JGYBJCLID1,' ')=:pLBJCLID then :pLJ*XLXSCLHQ_JGBL1+XLXSCLHQ_HSJGF"); SQL.Add(" else XLXSCLHQ_HSJG end as XLXSCLHQ_HSJG,"); SQL.Add(" case when ISNULL(XLXSCLHQ_BJCLID, ' ') = :pTBJCLID then roundfix(:pTJ/(1+XLXSBJCL_ZZSL/100.0)," + XLBJDUtils.BJCLPriceDecimal + ") "); SQL.Add(" when isnull(XLXSCLHQ_JGYBJCLID1,' ')=:pTBJCLID then roundfix(:pTJ/(1+XLXSBJCL_ZZSL/100.0)," + XLBJDUtils.BJCLPriceDecimal + ")*XLXSCLHQ_JGBL1+XLXSCLHQ_WSJGF"); SQL.Add(" when ISNULL(XLXSCLHQ_BJCLID, ' ') = :pLBJCLID then roundfix(:pLJ/(1+XLXSBJCL_ZZSL/100.0)," + XLBJDUtils.BJCLPriceDecimal + ") "); SQL.Add(" when isnull(XLXSCLHQ_JGYBJCLID1,' ')=:pLBJCLID then roundfix(:pLJ/(1+XLXSBJCL_ZZSL/100.0)," + XLBJDUtils.BJCLPriceDecimal + ")*XLXSCLHQ_JGBL1+XLXSCLHQ_WSJGF"); SQL.Add(" else XLXSCLHQ_WSJG end as XLXSCLHQ_WSJG "); SQL.Add(" from XLXSCLHQ "); SQL.Add(" left join XLXSBJCL on XLXSBJCL_BJCLID=XLXSCLHQ_BJCLID"); SQL.Add(" where XLXSCLHQ_JGBID=:pJGBID ) jj on XLXSCLHQ_BJCLID=XLJGCZBLM_BJCLID"); SQL.ParamByName("pTBJCLID").Value = sTBJCLID_JGBBJ; SQL.ParamByName("pLBJCLID").Value = sLBJCLID_JGBBJ; SQL.ParamByName("pTJ").Value = dTJ_JGBBJ; SQL.ParamByName("pLJ").Value = dLJ_JGBBJ; SQL.ParamByName("pJGBID").Value = sJGBID; } else { if (sBJDHQLX.Equals("BJRCLHQ"))//报价日材料行情 { SQL.Add(" left join "); SQL.Add(" ("); SQL.Add(" select XLXSBJCL_BJCLID as XLXSCLHQ_BJCLID,"); SQL.Add(" case when isnull(XLXSBJFLBJRHQCL_BJCLID,' ')<>' ' then bjrclhq.CLJG else jgbclhq.CLJG end as XLXSCLHQ_WSJG, "); SQL.Add(" case when isnull(XLXSBJFLBJRHQCL_BJCLID,' ')<>' ' then bjrclhq.HSJG else jgbclhq.HSJG end as XLXSCLHQ_HSJG "); SQL.Add(" from XLXSBJCL"); SQL.Add(" left join XLXSBJFLBJRHQCL on XLXSBJFLBJRHQCL_BJFLID=:pBJFLID and XLXSBJFLBJRHQCL_BJCLID=XLXSBJCL_BJCLID"); //bjrclhq 报价材料之报价日行情 SQL.Add(" left join ("); SQL.Add(" select BJCLID,XLXSCLHQ_WSJG as CLJG,XLXSCLHQ_HSJG as HSJG"); SQL.Add(" from XLXSCLHQ,"); SQL.Add(" ("); SQL.Add(" select XLXSCLHQ_BJCLID as BJCLID,max(XLXSCLHQ_YXQS)as maxYXQS"); SQL.Add(" from XLXSCLHQ"); SQL.Add(" where XLXSCLHQ_JGBID='ZZZZZZZZ'"); SQL.Add(" and XLXSCLHQ_YXQS<=:pBJRQ and(XLXSCLHQ_YXQZ>=:pBJRQ or XLXSCLHQ_YXQZ is null)"); SQL.Add(" group by XLXSCLHQ_BJCLID"); SQL.Add(" ) a"); SQL.Add(" where XLXSCLHQ_JGBID='ZZZZZZZZ' "); SQL.Add(" and XLXSCLHQ_BJCLID=BJCLID"); SQL.Add(" and XLXSCLHQ_YXQS=maxYXQS"); SQL.Add(" )bjrclhq on bjrclhq.BJCLID=XLXSBJCL_BJCLID"); //jgbclhq 报价材料之价格表行情 SQL.Add(" left join ("); SQL.Add(" select XLXSCLHQ_BJCLID as BJCLID,XLXSCLHQ_WSJG as CLJG,XLXSCLHQ_HSJG as HSJG"); SQL.Add(" from XLXSCLHQ"); SQL.Add(" where XLXSCLHQ_JGBID<>'ZZZZZZZZ' and XLXSCLHQ_JGBID=:pJGBID"); SQL.Add(" )jgbclhq on jgbclhq.BJCLID=XLXSBJCL_BJCLID"); SQL.Add(" ) JGB on JGB.BJCLID=XLJGCZBLM_BJCLID"); SQL.ParamByName("pBJFLID").Value = sBJFLID; SQL.ParamByName("pBJRQ").Value = sBJRQ; SQL.ParamByName("pJGBID").Value = sJGBID; } else if (sBJDHQLX.Equals("BJRHQ"))//报价日行情 { SQL.Add(" left join "); SQL.Add(" ("); SQL.Add(" select XLXSCLHQ_BJCLID,XLXSCLHQ_WSJG,XLXSCLHQ_HSJG"); SQL.Add(" from XLXSCLHQ,"); SQL.Add(" ("); SQL.Add(" select XLXSCLHQ_BJCLID as BJCLID,max(XLXSCLHQ_YXQS)as maxYXQS"); SQL.Add(" from XLXSCLHQ"); SQL.Add(" where XLXSCLHQ_JGBID='ZZZZZZZZ'"); SQL.Add(" and XLXSCLHQ_YXQS<=:pBJRQ and(XLXSCLHQ_YXQZ>=:pBJRQ or XLXSCLHQ_YXQZ is null)"); SQL.Add(" group by XLXSCLHQ_BJCLID"); SQL.Add(" ) a"); SQL.Add(" where XLXSCLHQ_JGBID='ZZZZZZZZ' "); SQL.Add(" and XLXSCLHQ_BJCLID=BJCLID"); SQL.Add(" and XLXSCLHQ_YXQS=maxYXQS"); SQL.Add(" ) JGB on JGB.XLXSCLHQ_BJCLID=XLJGCZBLM_BJCLID"); SQL.ParamByName("pBJRQ").Value = sBJRQ; } else if (sBJDHQLX.Equals("BJDHQ"))//报价单行情 { SQL.Add(" left join "); SQL.Add(" ("); SQL.Add(" select XLXSBJDCLHQ_BJCLID as XLXSCLHQ_BJCLID,XLXSBJDCLHQ_WSJG as XLXSCLHQ_WSJG,XLXSBJDCLHQ_HSJG as XLXSCLHQ_HSJG"); SQL.Add(" from XLXSBJDCLHQ"); SQL.Add(string.Format(" where XLXSBJDCLHQ_BJDID='{0}'", sBJDID)); SQL.Add(" ) JGB on JGB.XLXSCLHQ_BJCLID=XLJGCZBLM_BJCLID"); } else//价格表行情 { SQL.Add(" left join XLXSCLHQ on XLXSCLHQ_JGBID=:pJGBID and XLXSCLHQ_BJCLID=XLJGCZBLM_BJCLID"); SQL.ParamByName("pJGBID").Value = sJGBID; } } } SQL.Add(" where XLJGCZBLM_JGCZBID=:pJGCZBID"); SQL.Add(" and XLJGCZBLM_JGCZBBBID=:pJGCZBBBID"); SQL.Add(" and isnull(XLJGCZBLM_CLQDL,' ')<>' '"); SQL.Add(" group by XLJGCZBLM_JGCZBID,XLJGCZBLM_JGCZBBBID"); SQL.Add(" ) b "); SQL.Add(" on( "); SQL.Add(" a.XLXSCLQD_JGCZBID=:pJGCZBID and a.XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.Add(" and a.XLXSCLQD_JGCZBID=b.JGCZBID and a.XLXSCLQD_JGCZBBBID=b.JGCZBBBID "); if (!sBJDID.Trim().Equals(""))//这段是否有必要限制到具体要重算的产品,还是整个尺重表一起算,需要看项目执行效果再定 { SQL.Add(" and exists ("); SQL.Add("select 1 "); SQL.Add(" from XLXSBJDMX"); SQL.Add(" where XLXSBJDMX_BJDID=:pBJDID"); if (!sBJDXHList.Trim().Equals("")) SQL.Add(" and " + CMISproDataBase.GetWhereEqual("XLXSBJDMX_XH", sBJDXHList)); SQL.Add(" and XLXSBJDMX_XH >= :piMinXH"); SQL.Add(" and XLXSBJDMX_XLXHID=a.XLXSCLQD_XLXHID and XLXSBJDMX_XLGGID=a.XLXSCLQD_XLGGID"); SQL.Add(" and XLXSBJDMX_XLBZID=a.XLXSCLQD_XLBZID and XLXSBJDMX_DYDJID=a.XLXSCLQD_DYDJID"); SQL.Add(" ) "); SQL.ParamByName("pBJDID").Value = sBJDID; SQL.ParamByName("piMinXH").Value = iMinXH; } SQL.Add(" ) "); SQL.Add(" when matched then update set a.XLXSCLQD_JGBWSCB= "); if (!IsJGBID3)//调价因素3价格表不进行负数的校验,因为此时CLJG{0}代表的是两个价格表行情之差 { //case 语句用于挑拣出用量大于0价格等于0的那一列,返回-1 if (1 == flag_1) { SQL.Add(" (case "); } for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("1") && !sBJRCLCB.Equals("Y"))//1|材料行情 { SQL.Add(string.Format(" when (XLXSCLQD_SL{0} > 0 and isnull(CLJG{0},0) = 0) then (-1) ", sCLQDL.Replace("第", "").Replace("列", ""))); } } if (1 == flag_1) { SQL.Add(" else 1 end)* "); } } SQL.Add(" ( "); if (sJSBLFS.Equals("C1"))//C1|进一法(材料价各分项进一) { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); if (sBJHQ.Equals("1"))//1|材料行情 { SQL.Add(string.Format("CEILING(RoundFix(XLXSCLQD_SL{0}*CLJG{0}*(1+XLXSCLQD_SHL{0}/100)*XLXSCLQD_CLJGBL{0}*{1},8))/{1}+", sCLQDL.Replace("第", "").Replace("列", ""), Math.Pow(10.0, iXSWS))); } } } else { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); if (sBJHQ.Equals("1"))//1|材料行情 { SQL.Add(string.Format("XLXSCLQD_SL{0}*CLJG{0}*(1+XLXSCLQD_SHL{0}/100)*XLXSCLQD_CLJGBL{0}+", sCLQDL.Replace("第", "").Replace("列", ""))); } } } if (bNeedAddWLHQ) { SQL.Add("1.0), ");//这里+1.0是为了解决即使材料价都为0,也要保证成本之和不为0 } else SQL.Add("0), "); SQL.Add(" a.XLXSCLQD_JGBHSCB="); if (!IsJGBID3)//调价因素3价格表不进行负数的校验,因为此时CLJG{0}代表的是两个价格表行情之差 { if (1 == flag_1) { SQL.Add(" (case "); } for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("1") && !sBJRCLCB.Equals("Y"))//1|材料行情 { SQL.Add(string.Format(" when (XLXSCLQD_SL{0} > 0 and isnull(CLJG{0},0) = 0) then (-1) ", sCLQDL.Replace("第", "").Replace("列", ""))); } } if (1 == flag_1) { SQL.Add(" else 1 end)* "); } } SQL.Add(" ( "); if (sJSBLFS.Equals("C1"))//C1|进一法(材料价各分项进一) { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); if (sBJHQ.Equals("1"))//1|材料行情 { SQL.Add(string.Format("CEILING(RoundFix(XLXSCLQD_SL{0}*HSJG{0}*(1+XLXSCLQD_SHL{0}/100)*XLXSCLQD_CLJGBL{0}*{1},8))/{1}+", sCLQDL.Replace("第", "").Replace("列", ""), Math.Pow(10.0, iXSWS))); } } } else { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); if (sBJHQ.Equals("1"))//1|材料行情 { SQL.Add(string.Format("XLXSCLQD_SL{0}*HSJG{0}*(1+XLXSCLQD_SHL{0}/100)*XLXSCLQD_CLJGBL{0}+", sCLQDL.Replace("第", "").Replace("列", ""))); } } } if (bNeedAddWLHQ) { SQL.Add("1.0) ");//这里+1.0是为了解决即使材料价都为0,也要保证成本之和不为0 } else SQL.Add("0) "); SQL.ParamByName("pJGCZBID").Value = tmpJGCZBID; SQL.ParamByName("pJGCZBBBID").Value = tmpJGCZBBBID; dberp.ExecSQL(SQL); if (bNeedAddWLHQ) { string sWLHQCLQDL = string.Empty;//记录物料行情的材料清单列 for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 sWLHQCLQDL += sCLQDL.Replace("第", "").Replace("列", "") + ","; } sWLHQCLQDL = sWLHQCLQDL.TrimEnd(','); string[] sWLHQCLQDList = sWLHQCLQDL.Split(','); if (sWLHQCLQDList.Length <= 20) { /* merge into 目标表 a using 源表 b on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……) when matched then update set a.更新字段=b.字段 when not matched then insert into a(字段1,字段2……)values(值1,值2……) */ SQL.Clear(); SQL.Add(" merge into XLXSCLQD a "); SQL.Add(" using "); SQL.Add(" (");//获取结构尺重表每个单元格所指报价物料的无税价格、含税价格 SQL.Add(" select XLXSCLQD_XLXHID as XLXHID,XLXSCLQD_XLGGID as XLGGID,XLXSCLQD_XLBZID as XLBZID, XLXSCLQD_DYDJID as DYDJID, "); for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { if (sBJDHQLX.Equals("BJDHQ"))//报价单行情 { SQL.Add(string.Format("case when isnull(d{0}.XLXSBJDWLHQ_WLID,' ')<>' ' then isnull(d{0}.WSJG,0) else isnull(c{0}.WSJG,0) end as WSJG{0}, ", sCLQDL.Replace("第", "").Replace("列", ""))); SQL.Add(string.Format("case when isnull(d{0}.XLXSBJDWLHQ_WLID,' ')<>' ' then isnull(d{0}.HSJG,0) else isnull(c{0}.HSJG,0) end as HSJG{0}, ", sCLQDL.Replace("第", "").Replace("列", ""))); } else { SQL.Add(string.Format(" isnull(c{0}.XLXSWLHQ_WSJG,0) as WSJG{0},isnull(c{0}.XLXSWLHQ_HSJG,0) as HSJG{0},", sCLQDL.Replace("第", "").Replace("列", ""))); } } } SQL.Add(" ' ' as MJBZ "); SQL.Add(" from XLXSCLQD");//这里不直接查XLXSCLQDWL的原因是XLXSCLQDWL可能还没有记录 SQL.Add(" left join XLXSCLQDWL on XLXSCLQDWL_JGCZBID=XLXSCLQD_JGCZBID and XLXSCLQDWL_JGCZBBBID=XLXSCLQD_JGCZBBBID and XLXSCLQDWL_JGCZBXH=XLXSCLQD_JGCZBXH and XLXSCLQDWL_DRHH=XLXSCLQD_DRHH"); for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { if (sBJDHQLX.Equals("BJDHQ"))//报价单行情 { //关联XLXSBJDWLHQ,获取报价单物料行情 SQL.Add(" left join "); SQL.Add(" ("); SQL.Add(" select XLXSBJDWLHQ_WLID,"); SQL.Add(string.Format("case when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_WSJGF", sTBJCLID, dTJ)); SQL.Add(string.Format(" when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_WSJGF", sLBJCLID, dLJ)); SQL.Add(" else XLXSBJDWLHQ_WSJG end as WSJG, "); SQL.Add(string.Format("case when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_HSJGF", sTBJCLID, dTJ)); SQL.Add(string.Format(" when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_HSJGF", sLBJCLID, dLJ)); SQL.Add(" else XLXSBJDWLHQ_HSJG end as HSJG "); SQL.Add(" from XLXSBJDWLHQ"); SQL.Add(" left join XLXSBJCLWL on XLXSBJCLWL_WLID=XLXSBJDWLHQ_WLID"); SQL.Add(" left join XLXSBJCL on XLXSBJCL_BJCLID=XLXSBJCLWL_BJCLID"); SQL.Add(string.Format(" where XLXSBJDWLHQ_BJDID='{0}'", sBJDID)); SQL.Add(string.Format(") d{0} on d{0}.XLXSBJDWLHQ_WLID=XLXSCLQDWL_WLID{0} ", sCLQDL.Replace("第", "").Replace("列", ""))); //关联XLXSWLHQ,获取物料行情 SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSWLHQ_WLID,"); SQL.Add(string.Format("case when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_WSJGF", sTBJCLID, dTJ)); SQL.Add(string.Format(" when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_WSJGF", sLBJCLID, dLJ)); SQL.Add(" else XLXSWLHQ_WSJG end as WSJG, "); SQL.Add(string.Format("case when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_HSJGF", sTBJCLID, dTJ)); SQL.Add(string.Format(" when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_HSJGF", sLBJCLID, dLJ)); SQL.Add(" else XLXSWLHQ_HSJG end as HSJG "); SQL.Add(" from XLXSWLHQ,"); SQL.Add(" ("); SQL.Add(" select XLXSWLHQ_WLID as WLID,max(XLXSWLHQ_YXQS)as maxYXQS"); SQL.Add(" from XLXSWLHQ"); SQL.Add(" where XLXSWLHQ_JGBID=' '"); SQL.Add(" and XLXSWLHQ_YXQS<=:pRQ and (XLXSWLHQ_YXQZ>=:pRQ or XLXSWLHQ_YXQZ is null)"); SQL.Add(" group by XLXSWLHQ_WLID"); SQL.Add(string.Format(") a{0} ", sCLQDL.Replace("第", "").Replace("列", ""))); SQL.Add(" left join XLXSBJCLWL on XLXSBJCLWL_WLID=WLID");//20.09.22新增 SQL.Add(" left join XLXSBJCL on XLXSBJCL_BJCLID=XLXSBJCLWL_BJCLID");//20.09.22新增 SQL.Add(" where XLXSWLHQ_JGBID=' ' and XLXSWLHQ_WLID=WLID and XLXSWLHQ_YXQS=maxYXQS"); SQL.Add(string.Format(") c{0} on c{0}.XLXSWLHQ_WLID=XLXSCLQDWL_WLID{0} ", sCLQDL.Replace("第", "").Replace("列", ""))); SQL.ParamByName("pRQ").Value = DateTime.Now.ToShortDateString(); } else { //Dictionary dicJGYLHSJG = new Dictionary(); //Dictionary dicJGYLWSJG = new Dictionary(); //TSQL sSQL = new TSQL(dberp); //sSQL.Add(" select XLXSCLHQ_BJCLID,XLXSCLHQ_HSJG,XLXSCLHQ_WSJG,isnull(JGYBJCLID,' ') as JGYBJCLID "); //sSQL.Add(" from XLXSCLHQ "); //sSQL.Add(" left join ( "); //sSQL.Add(" select distinct XLXSBJCL_JGYBJCLID as JGYBJCLID "); //sSQL.Add(" from XLXSBJCL where isnull(XLXSBJCL_JGYBJCLID,' ')<>' '"); //sSQL.Add(" ) a on JGYBJCLID=XLXSCLHQ_BJCLID"); //sSQL.Add(" where XLXSCLHQ_JGBID=:pJGBID "); //sSQL.Add(" and isnull(JGYBJCLID,' ') <> ' ' "); //sSQL.ParamByName("pJGBID").Value = sJGBID; //DataSet dsJGYL = dberp.OpenDataSet(sSQL); //if (dsJGYL.Tables[0].Rows.Count > 0) //{ // foreach (DataRow trow in dsJGYL.Tables[0].Rows) // { // if (!dicJGYLHSJG.ContainsKey(trow["XLXSCLHQ_BJCLID"].ToString().Trim())) // { // dicJGYLHSJG.Add(trow["XLXSCLHQ_BJCLID"].ToString().Trim(), CMISproConvert.StrToFloat(trow["XLXSCLHQ_HSJG"].ToString().Trim())); // dicJGYLWSJG.Add(trow["XLXSCLHQ_BJCLID"].ToString().Trim(), CMISproConvert.StrToFloat(trow["XLXSCLHQ_WSJG"].ToString().Trim())); // } // } //} SQL.Add(" left join"); SQL.Add(" ("); SQL.Add(" select XLXSWLHQ_WLID,"); //无税价格 if (dicJGYLWSJG.Count > 0) { SQL.Add(" case "); foreach (string BJCLID in dicJGYLWSJG.Keys) { SQL.Add(string.Format(" when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_WSJGF", BJCLID, dicJGYLWSJG[BJCLID])); } SQL.Add(" else XLXSWLHQ_WSJG end as XLXSWLHQ_WSJG, "); } else { SQL.Add(" XLXSWLHQ_WSJG, "); } //含税价格 if (dicJGYLHSJG.Count > 0) { SQL.Add(" case "); foreach (string BJCLID in dicJGYLHSJG.Keys) { SQL.Add(string.Format(" when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_HSJGF", BJCLID, dicJGYLHSJG[BJCLID])); } SQL.Add(" else XLXSWLHQ_HSJG end as XLXSWLHQ_HSJG "); } else { SQL.Add(" XLXSWLHQ_HSJG "); } SQL.Add(" from XLXSWLHQ"); SQL.Add(" left join XLXSBJCLWL on XLXSBJCLWL_WLID=XLXSWLHQ_WLID"); SQL.Add(" left join XLXSBJCL on XLXSBJCL_BJCLID=XLXSBJCLWL_BJCLID"); SQL.Add(" where 1=1"); if (XLJGB_CLJGTZList.NeedJGBJJFP()) { SQL.Add(" and XLXSWLHQ_JGBID=:pJGBID_JJFP"); SQL.ParamByName("pJGBID_JJFP").Value = sJGBID; } else { //同一个物料,在同一天当中只会存在一个价格,可以不用先查出maxYXQS SQL.Add(" and XLXSWLHQ_JGBID=' '"); SQL.Add(" and XLXSWLHQ_YXQS<=:pRQ and (XLXSWLHQ_YXQZ>=:pRQ or XLXSWLHQ_YXQZ is null)"); SQL.ParamByName("pRQ").Value = DateTime.Now.ToShortDateString(); } SQL.Add(string.Format(") c{0} on c{0}.XLXSWLHQ_WLID=XLXSCLQDWL_WLID{0} ", sCLQDL.Replace("第", "").Replace("列", ""))); } } } SQL.Add(" where XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID "); SQL.Add(" ) b "); SQL.Add(" on( "); SQL.Add(" a.XLXSCLQD_JGCZBID=:pJGCZBID and a.XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.Add(" and a.XLXSCLQD_XLXHID=b.XLXHID and a.XLXSCLQD_XLGGID=b.XLGGID "); SQL.Add(" and XLBZID=XLXSCLQD_XLBZID and DYDJID=XLXSCLQD_DYDJID "); if (!sBJDID.Trim().Equals(""))//这段是否有必要限制到具体要重算的产品,还是整个尺重表一起算,需要看项目执行效果再定 { SQL.Add(" and exists ("); SQL.Add("select 1 "); SQL.Add(" from XLXSBJDMX"); SQL.Add(" where XLXSBJDMX_BJDID=:pBJDID"); if (!sBJDXHList.Trim().Equals("")) SQL.Add(" and " + CMISproDataBase.GetWhereEqual("XLXSBJDMX_XH", sBJDXHList)); SQL.Add(" and XLXSBJDMX_XH >= :piMinXH"); SQL.Add(" and XLXSBJDMX_XLXHID=a.XLXSCLQD_XLXHID and XLXSBJDMX_XLGGID=a.XLXSCLQD_XLGGID"); SQL.Add(" and XLXSBJDMX_XLBZID=a.XLXSCLQD_XLBZID and XLXSBJDMX_DYDJID=a.XLXSCLQD_DYDJID"); SQL.Add(" ) "); SQL.ParamByName("pBJDID").Value = sBJDID; SQL.ParamByName("piMinXH").Value = iMinXH; } SQL.Add(" ) "); SQL.Add(" when matched then update set a.XLXSCLQD_JGBWSCB= "); //用量部分以abs计算,始终为正数,在case语句先判断材料部分是否是正数 //case 语句用于挑拣出用量大于0价格等于0的那一列,返回-1 SQL.Add(" (case when XLXSCLQD_JGBWSCB < 0 then (-1) "); for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { SQL.Add(string.Format(" when (XLXSCLQD_SL{0} > 0 and isnull(WSJG{0},0) = 0) then (-1) ", sCLQDL.Replace("第", "").Replace("列", ""))); } } SQL.Add(" else 1 end)* "); SQL.Add(" (abs(XLXSCLQD_JGBWSCB)-1.0+ ");//这里需要把上边材料行情部分算XLXSCLQD_JGBHSCB时加的1.0减掉 if (sJSBLFS.Equals("C1"))//C1|进一法(材料价各分项进一) { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { SQL.Add(string.Format("CEILING(RoundFix(XLXSCLQD_SL{0}*(1+XLXSCLQD_SHL{0}/100)*XLXSCLQD_CLJGBL{0}*isnull(WSJG{0},0)*{1},8))/{1}+", sCLQDL.Replace("第", "").Replace("列", ""), Math.Pow(10.0, iXSWS))); } } } else { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { SQL.Add(string.Format("XLXSCLQD_SL{0}*(1+XLXSCLQD_SHL{0}/100)*XLXSCLQD_CLJGBL{0}*isnull(WSJG{0},0)+", sCLQDL.Replace("第", "").Replace("列", ""))); } } } SQL.Add("0), "); SQL.Add(" XLXSCLQD_JGBHSCB="); SQL.Add(" (case when XLXSCLQD_JGBHSCB < 0 then (-1) "); for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { SQL.Add(string.Format(" when (XLXSCLQD_SL{0} > 0 and isnull(HSJG{0},0) = 0) then (-1) ", sCLQDL.Replace("第", "").Replace("列", ""))); } } SQL.Add(" else 1 end)* "); SQL.Add(" (abs(XLXSCLQD_JGBHSCB)-1.0+ ");//这里需要把上边材料行情部分算XLXSCLQD_JGBHSCB时加的1.0减掉 if (sJSBLFS.Equals("C1"))//C1|进一法(材料价各分项进一) { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { SQL.Add(string.Format("CEILING(RoundFix(XLXSCLQD_SL{0}*(1+XLXSCLQD_SHL{0}/100)*XLXSCLQD_CLJGBL{0}*isnull(HSJG{0},0)*{1},8))/{1}+", sCLQDL.Replace("第", "").Replace("列", ""), Math.Pow(10.0, iXSWS))); } } } else { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { SQL.Add(string.Format("XLXSCLQD_SL{0}*(1+XLXSCLQD_SHL{0}/100)*XLXSCLQD_CLJGBL{0}*isnull(HSJG{0},0)+", sCLQDL.Replace("第", "").Replace("列", ""))); } } } SQL.Add("0)"); SQL.ParamByName("pJGCZBID").Value = tmpJGCZBID; SQL.ParamByName("pJGCZBBBID").Value = tmpJGCZBBBID; dberp.ExecSQL(SQL); } else { DateTime TimeStamp = MISproUtils.GetServerTime(); int VnewID = CMISproDataBase.GetMaxXH("DBERP", "V_XLXSCLQDWLHQ", "V_XLXSCLQDWLHQ_ID", "") + 1; SQL.Clear(); SQL.Add(@"insert into V_XLXSCLQDWLHQ(V_XLXSCLQDWLHQ_ID,V_XLXSCLQDWLHQ_TIMESTAMP,V_XLXSCLQDWLHQ_JGCZBID,V_XLXSCLQDWLHQ_JGCZBBBID,V_XLXSCLQDWLHQ_JGCZBXH,V_XLXSCLQDWLHQ_DRHH,V_XLXSCLQDWLHQ_HSBZ) select :pID,:pTime,XLXSCLQD_JGCZBID, XLXSCLQD_JGCZBBBID,XLXSCLQD_JGCZBXH,XLXSCLQD_DRHH,:pHSBZ from XLXSCLQD where XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID and XLXSCLQD_WPID='ZZZZ' "); if (!sBJDID.Trim().Equals(""))//这段是否有必要限制到具体要重算的产品,还是整个尺重表一起算,需要看项目执行效果再定 { SQL.Add(" and exists ("); SQL.Add("select 1 "); SQL.Add(" from XLXSBJDMX"); SQL.Add(" where XLXSBJDMX_BJDID=:pBJDID"); if (!sBJDXHList.Trim().Equals("")) SQL.Add(" and " + CMISproDataBase.GetWhereEqual("XLXSBJDMX_XH", sBJDXHList)); SQL.Add(" and XLXSBJDMX_XH >= :piMinXH"); SQL.Add(" and XLXSBJDMX_XLXHID=XLXSCLQD_XLXHID and XLXSBJDMX_XLGGID=XLXSCLQD_XLGGID"); SQL.Add(" and XLXSBJDMX_XLBZID=XLXSCLQD_XLBZID and XLXSBJDMX_DYDJID=XLXSCLQD_DYDJID"); SQL.Add(" ) "); SQL.ParamByName("pBJDID").Value = sBJDID; SQL.ParamByName("piMinXH").Value = iMinXH; } SQL.ParamByName("pID").Value = VnewID; SQL.ParamByName("pTime").Value = TimeStamp; SQL.ParamByName("pHSBZ").Value = "N"; SQL.ParamByName("pJGCZBID").Value = tmpJGCZBID; SQL.ParamByName("pJGCZBBBID").Value = tmpJGCZBBBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(@"insert into V_XLXSCLQDWLHQ(V_XLXSCLQDWLHQ_ID,V_XLXSCLQDWLHQ_TIMESTAMP,V_XLXSCLQDWLHQ_JGCZBID,V_XLXSCLQDWLHQ_JGCZBBBID,V_XLXSCLQDWLHQ_JGCZBXH,V_XLXSCLQDWLHQ_DRHH,V_XLXSCLQDWLHQ_HSBZ) select :pID,:pTime,XLXSCLQD_JGCZBID, XLXSCLQD_JGCZBBBID,XLXSCLQD_JGCZBXH,XLXSCLQD_DRHH,:pHSBZ from XLXSCLQD where XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID and XLXSCLQD_WPID='ZZZZ' "); if (!sBJDID.Trim().Equals(""))//这段是否有必要限制到具体要重算的产品,还是整个尺重表一起算,需要看项目执行效果再定 { SQL.Add(" and exists ("); SQL.Add("select 1 "); SQL.Add(" from XLXSBJDMX"); SQL.Add(" where XLXSBJDMX_BJDID=:pBJDID"); if (!sBJDXHList.Trim().Equals("")) SQL.Add(" and " + CMISproDataBase.GetWhereEqual("XLXSBJDMX_XH", sBJDXHList)); SQL.Add(" and XLXSBJDMX_XH >= :piMinXH"); SQL.Add(" and XLXSBJDMX_XLXHID=XLXSCLQD_XLXHID and XLXSBJDMX_XLGGID=XLXSCLQD_XLGGID"); SQL.Add(" and XLXSBJDMX_XLBZID=XLXSCLQD_XLBZID and XLXSBJDMX_DYDJID=XLXSCLQD_DYDJID"); SQL.Add(" ) "); SQL.ParamByName("pBJDID").Value = sBJDID; SQL.ParamByName("piMinXH").Value = iMinXH; } SQL.ParamByName("pID").Value = VnewID; SQL.ParamByName("pTime").Value = TimeStamp; SQL.ParamByName("pHSBZ").Value = "Y"; SQL.ParamByName("pJGCZBID").Value = tmpJGCZBID; SQL.ParamByName("pJGCZBBBID").Value = tmpJGCZBBBID; dberp.ExecSQL(SQL); string sSQL_1 = " merge into V_XLXSCLQDWLHQ a " + " using (" + " select XLXSCLQD_JGCZBID,XLXSCLQD_JGCZBBBID,XLXSCLQD_JGCZBXH,XLXSCLQD_DRHH, "; string sSQL_2 = string.Empty; string sSQL_3 = " ' ' as MJBZ " + " from XLXSCLQD " + " left join XLXSCLQDWL on XLXSCLQDWL_JGCZBID=XLXSCLQD_JGCZBID and XLXSCLQDWL_JGCZBBBID=XLXSCLQD_JGCZBBBID and XLXSCLQDWL_JGCZBXH=XLXSCLQD_JGCZBXH and XLXSCLQDWL_DRHH=XLXSCLQD_DRHH "; string sSQL_4 = string.Empty; string sSQL_5 = " where XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID and XLXSCLQD_WPID='ZZZZ' " + " ) b " + " on( " + " V_XLXSCLQDWLHQ_ID=:pID and XLXSCLQD_JGCZBID=V_XLXSCLQDWLHQ_JGCZBID and XLXSCLQD_JGCZBBBID=V_XLXSCLQDWLHQ_JGCZBBBID and XLXSCLQD_JGCZBXH=V_XLXSCLQDWLHQ_JGCZBXH and XLXSCLQD_DRHH=V_XLXSCLQDWLHQ_DRHH and V_XLXSCLQDWLHQ_HSBZ=:pHSBZ " + " ) " + " when matched then update set V_XLXSCLQDWLHQ_HSBZ='Y' "; string sSQL_6 = string.Empty; for (int i = 0; i < sWLHQCLQDList.Length; i++) { if (sBJDHQLX.Equals("BJDHQ"))//报价单行情 { sSQL_2 += string.Format("case when isnull(d{0}.XLXSBJDWLHQ_WLID,' ')<>' ' then isnull(d{0}.WSJG,0) else isnull(c{0}.WSJG,0) end as WSJG{0}, ", sWLHQCLQDList[i]); sSQL_2 += string.Format("case when isnull(d{0}.XLXSBJDWLHQ_WLID,' ')<>' ' then isnull(d{0}.HSJG,0) else isnull(c{0}.HSJG,0) end as HSJG{0}, ", sWLHQCLQDList[i]); } else { sSQL_2 += string.Format(" isnull(c{0}.XLXSWLHQ_WSJG,0) as WSJG{0},isnull(c{0}.XLXSWLHQ_HSJG,0) as HSJG{0},", sWLHQCLQDList[i]); } if (sBJDHQLX.Equals("BJDHQ"))//报价单行情 { //关联XLXSBJDWLHQ,获取报价单物料行情 sSQL_4 += " left join "; sSQL_4 += " ("; sSQL_4 += " select XLXSBJDWLHQ_WLID,"; sSQL_4 += string.Format("case when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_WSJGF", sTBJCLID, dTJ); sSQL_4 += string.Format(" when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_WSJGF", sLBJCLID, dLJ); sSQL_4 += " else XLXSBJDWLHQ_WSJG end as WSJG, "; sSQL_4 += string.Format("case when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_HSJGF", sTBJCLID, dTJ); sSQL_4 += string.Format(" when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_HSJGF", sLBJCLID, dLJ); sSQL_4 += " else XLXSBJDWLHQ_HSJG end as HSJG "; sSQL_4 += " from XLXSBJDWLHQ"; sSQL_4 += " left join XLXSBJCLWL on XLXSBJCLWL_WLID=XLXSBJDWLHQ_WLID"; sSQL_4 += " left join XLXSBJCL on XLXSBJCL_BJCLID=XLXSBJCLWL_BJCLID"; sSQL_4 += string.Format(" where XLXSBJDWLHQ_BJDID='{0}'", sBJDID); sSQL_4 += string.Format(") d{0} on d{0}.XLXSBJDWLHQ_WLID=XLXSCLQDWL_WLID{0} ", sWLHQCLQDList[i]); //关联XLXSWLHQ,获取物料行情 sSQL_4 += " left join"; sSQL_4 += " ("; sSQL_4 += " select XLXSWLHQ_WLID,"; sSQL_4 += string.Format("case when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_WSJGF", sTBJCLID, dTJ); sSQL_4 += string.Format(" when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_WSJGF", sLBJCLID, dLJ); sSQL_4 += " else XLXSWLHQ_WSJG end as WSJG, "; sSQL_4 += string.Format("case when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_HSJGF", sTBJCLID, dTJ); sSQL_4 += string.Format(" when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_HSJGF", sLBJCLID, dLJ); sSQL_4 += " else XLXSWLHQ_HSJG end as HSJG "; sSQL_4 += " from XLXSWLHQ,"; sSQL_4 += " ("; sSQL_4 += " select XLXSWLHQ_WLID as WLID,max(XLXSWLHQ_YXQS)as maxYXQS"; sSQL_4 += " from XLXSWLHQ"; sSQL_4 += " where XLXSWLHQ_JGBID=' '"; sSQL_4 += " and XLXSWLHQ_YXQS<=:pRQ and (XLXSWLHQ_YXQZ>=:pRQ or XLXSWLHQ_YXQZ is null)"; sSQL_4 += " group by XLXSWLHQ_WLID"; sSQL_4 += string.Format(") a{0} ", sWLHQCLQDList[i]); sSQL_4 += " left join XLXSBJCLWL on XLXSBJCLWL_WLID=WLID";//20.09.22新增 sSQL_4 += " left join XLXSBJCL on XLXSBJCL_BJCLID=XLXSBJCLWL_BJCLID";//20.09.22新增 sSQL_4 += " where XLXSWLHQ_JGBID=' ' and XLXSWLHQ_WLID=WLID and XLXSWLHQ_YXQS=maxYXQS"; sSQL_4 += string.Format(") c{0} on c{0}.XLXSWLHQ_WLID=XLXSCLQDWL_WLID{0} ", sWLHQCLQDList[i]); //SQL.ParamByName("pRQ").Value = DateTime.Now.ToShortDateString(); } else { sSQL_4 += " left join"; sSQL_4 += " ("; sSQL_4 += " select XLXSWLHQ_WLID,"; //无税价格 if (dicJGYLWSJG.Count > 0) { sSQL_4 += " case "; foreach (string BJCLID in dicJGYLWSJG.Keys) { sSQL_4 += string.Format(" when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_WSJGF", BJCLID, dicJGYLWSJG[BJCLID]); } sSQL_4 += " else XLXSWLHQ_WSJG end as XLXSWLHQ_WSJG, "; } else { sSQL_4 += " XLXSWLHQ_WSJG, "; } //含税价格 if (dicJGYLHSJG.Count > 0) { sSQL_4 += " case "; foreach (string BJCLID in dicJGYLHSJG.Keys) { sSQL_4 += string.Format(" when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_HSJGF", BJCLID, dicJGYLHSJG[BJCLID]); } sSQL_4 += " else XLXSWLHQ_HSJG end as XLXSWLHQ_HSJG "; } else { sSQL_4 += " XLXSWLHQ_HSJG "; } sSQL_4 += " from XLXSWLHQ"; sSQL_4 += " left join XLXSBJCLWL on XLXSBJCLWL_WLID=XLXSWLHQ_WLID"; sSQL_4 += " left join XLXSBJCL on XLXSBJCL_BJCLID=XLXSBJCLWL_BJCLID"; sSQL_4 += " where 1=1"; if (XLJGB_CLJGTZList.NeedJGBJJFP()) { sSQL_4 += " and XLXSWLHQ_JGBID=:pJGBID_JJFP"; //SQL.ParamByName("pJGBID_JJFP").Value = sJGBID; } else { //同一个物料,在同一天当中只会存在一个价格,可以不用先查出maxYXQS sSQL_4 += " and XLXSWLHQ_JGBID=' '"; sSQL_4 += " and XLXSWLHQ_YXQS<=:pRQ and (XLXSWLHQ_YXQZ>=:pRQ or XLXSWLHQ_YXQZ is null)"; //SQL.ParamByName("pRQ").Value = DateTime.Now.ToShortDateString(); } sSQL_4 += string.Format(") c{0} on c{0}.XLXSWLHQ_WLID=XLXSCLQDWL_WLID{0} ", sWLHQCLQDList[i]); } sSQL_6 += string.Format(" ,V_XLXSCLQDWLHQ_JG{0} = HSJG{0} ", sWLHQCLQDList[i]); if ((i + 1) % 20 == 0 || i == sWLHQCLQDList.Length - 1) { SQL.Clear(); SQL.Add(sSQL_1); SQL.Add(sSQL_2); SQL.Add(sSQL_3); SQL.Add(sSQL_4); SQL.Add(sSQL_5); SQL.Add(sSQL_6); if (sBJDHQLX.Equals("BJDHQ"))//报价单行情 { SQL.ParamByName("pRQ").Value = DateTime.Now.ToShortDateString(); } else { if (XLJGB_CLJGTZList.NeedJGBJJFP()) { SQL.ParamByName("pJGBID_JJFP").Value = sJGBID; } else { SQL.ParamByName("pRQ").Value = DateTime.Now.ToShortDateString(); } } SQL.ParamByName("pID").Value = VnewID; SQL.ParamByName("pHSBZ").Value = "Y"; SQL.ParamByName("pJGCZBID").Value = tmpJGCZBID; SQL.ParamByName("pJGCZBBBID").Value = tmpJGCZBBBID; dberp.ExecSQL(SQL); sSQL_2 = string.Empty; sSQL_4 = string.Empty; sSQL_6 = string.Empty; } } sSQL_1 = " merge into V_XLXSCLQDWLHQ a " + " using (" + " select XLXSCLQD_JGCZBID,XLXSCLQD_JGCZBBBID,XLXSCLQD_JGCZBXH,XLXSCLQD_DRHH, "; sSQL_2 = string.Empty; sSQL_3 = " ' ' as MJBZ " + " from XLXSCLQD " + " left join XLXSCLQDWL on XLXSCLQDWL_JGCZBID=XLXSCLQD_JGCZBID and XLXSCLQDWL_JGCZBBBID=XLXSCLQD_JGCZBBBID and XLXSCLQDWL_JGCZBXH=XLXSCLQD_JGCZBXH and XLXSCLQDWL_DRHH=XLXSCLQD_DRHH "; sSQL_4 = string.Empty; sSQL_5 = " where XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID and XLXSCLQD_WPID='ZZZZ' " + " ) b " + " on( " + " V_XLXSCLQDWLHQ_ID=:pID and XLXSCLQD_JGCZBID=V_XLXSCLQDWLHQ_JGCZBID and XLXSCLQD_JGCZBBBID=V_XLXSCLQDWLHQ_JGCZBBBID and XLXSCLQD_JGCZBXH=V_XLXSCLQDWLHQ_JGCZBXH and XLXSCLQD_DRHH=V_XLXSCLQDWLHQ_DRHH and V_XLXSCLQDWLHQ_HSBZ=:pHSBZ " + " ) " + " when matched then update set V_XLXSCLQDWLHQ_HSBZ='N' "; sSQL_6 = string.Empty; for (int i = 0; i < sWLHQCLQDList.Length; i++) { if (sBJDHQLX.Equals("BJDHQ"))//报价单行情 { sSQL_2 += string.Format("case when isnull(d{0}.XLXSBJDWLHQ_WLID,' ')<>' ' then isnull(d{0}.WSJG,0) else isnull(c{0}.WSJG,0) end as WSJG{0}, ", sWLHQCLQDList[i]); sSQL_2 += string.Format("case when isnull(d{0}.XLXSBJDWLHQ_WLID,' ')<>' ' then isnull(d{0}.HSJG,0) else isnull(c{0}.HSJG,0) end as HSJG{0}, ", sWLHQCLQDList[i]); } else { sSQL_2 += string.Format(" isnull(c{0}.XLXSWLHQ_WSJG,0) as WSJG{0},isnull(c{0}.XLXSWLHQ_HSJG,0) as HSJG{0},", sWLHQCLQDList[i]); } if (sBJDHQLX.Equals("BJDHQ"))//报价单行情 { //关联XLXSBJDWLHQ,获取报价单物料行情 sSQL_4 += " left join "; sSQL_4 += " ("; sSQL_4 += " select XLXSBJDWLHQ_WLID,"; sSQL_4 += string.Format("case when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_WSJGF", sTBJCLID, dTJ); sSQL_4 += string.Format(" when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_WSJGF", sLBJCLID, dLJ); sSQL_4 += " else XLXSBJDWLHQ_WSJG end as WSJG, "; sSQL_4 += string.Format("case when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_HSJGF", sTBJCLID, dTJ); sSQL_4 += string.Format(" when isnull(XLXSBJDWLHQ_JGYBJCLID1,' ')<>' ' and XLXSBJDWLHQ_JGYBJCLID1='{0}' then {1}*XLXSBJDWLHQ_JGBL1+XLXSBJDWLHQ_HSJGF", sLBJCLID, dLJ); sSQL_4 += " else XLXSBJDWLHQ_HSJG end as HSJG "; sSQL_4 += " from XLXSBJDWLHQ"; sSQL_4 += " left join XLXSBJCLWL on XLXSBJCLWL_WLID=XLXSBJDWLHQ_WLID"; sSQL_4 += " left join XLXSBJCL on XLXSBJCL_BJCLID=XLXSBJCLWL_BJCLID"; sSQL_4 += string.Format(" where XLXSBJDWLHQ_BJDID='{0}'", sBJDID); sSQL_4 += string.Format(") d{0} on d{0}.XLXSBJDWLHQ_WLID=XLXSCLQDWL_WLID{0} ", sWLHQCLQDList[i]); //关联XLXSWLHQ,获取物料行情 sSQL_4 += " left join"; sSQL_4 += " ("; sSQL_4 += " select XLXSWLHQ_WLID,"; sSQL_4 += string.Format("case when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_WSJGF", sTBJCLID, dTJ); sSQL_4 += string.Format(" when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_WSJGF", sLBJCLID, dLJ); sSQL_4 += " else XLXSWLHQ_WSJG end as WSJG, "; sSQL_4 += string.Format("case when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_HSJGF", sTBJCLID, dTJ); sSQL_4 += string.Format(" when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_HSJGF", sLBJCLID, dLJ); sSQL_4 += " else XLXSWLHQ_HSJG end as HSJG "; sSQL_4 += " from XLXSWLHQ,"; sSQL_4 += " ("; sSQL_4 += " select XLXSWLHQ_WLID as WLID,max(XLXSWLHQ_YXQS)as maxYXQS"; sSQL_4 += " from XLXSWLHQ"; sSQL_4 += " where XLXSWLHQ_JGBID=' '"; sSQL_4 += " and XLXSWLHQ_YXQS<=:pRQ and (XLXSWLHQ_YXQZ>=:pRQ or XLXSWLHQ_YXQZ is null)"; sSQL_4 += " group by XLXSWLHQ_WLID"; sSQL_4 += string.Format(") a{0} ", sWLHQCLQDList[i]); sSQL_4 += " left join XLXSBJCLWL on XLXSBJCLWL_WLID=WLID";//20.09.22新增 sSQL_4 += " left join XLXSBJCL on XLXSBJCL_BJCLID=XLXSBJCLWL_BJCLID";//20.09.22新增 sSQL_4 += " where XLXSWLHQ_JGBID=' ' and XLXSWLHQ_WLID=WLID and XLXSWLHQ_YXQS=maxYXQS"; sSQL_4 += string.Format(") c{0} on c{0}.XLXSWLHQ_WLID=XLXSCLQDWL_WLID{0} ", sWLHQCLQDList[i]); //SQL.ParamByName("pRQ").Value = DateTime.Now.ToShortDateString(); } else { sSQL_4 += " left join"; sSQL_4 += " ("; sSQL_4 += " select XLXSWLHQ_WLID,"; //无税价格 if (dicJGYLWSJG.Count > 0) { sSQL_4 += " case "; foreach (string BJCLID in dicJGYLWSJG.Keys) { sSQL_4 += string.Format(" when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_WSJGF", BJCLID, dicJGYLWSJG[BJCLID]); } sSQL_4 += " else XLXSWLHQ_WSJG end as XLXSWLHQ_WSJG, "; } else { sSQL_4 += " XLXSWLHQ_WSJG, "; } //含税价格 if (dicJGYLHSJG.Count > 0) { sSQL_4 += " case "; foreach (string BJCLID in dicJGYLHSJG.Keys) { sSQL_4 += string.Format(" when isnull(XLXSWLHQ_JGYBJCLID1,' ')<>' ' and XLXSWLHQ_JGYBJCLID1='{0}' then {1}*XLXSWLHQ_JGBL1+XLXSWLHQ_HSJGF", BJCLID, dicJGYLHSJG[BJCLID]); } sSQL_4 += " else XLXSWLHQ_HSJG end as XLXSWLHQ_HSJG "; } else { sSQL_4 += " XLXSWLHQ_HSJG "; } sSQL_4 += " from XLXSWLHQ"; sSQL_4 += " left join XLXSBJCLWL on XLXSBJCLWL_WLID=XLXSWLHQ_WLID"; sSQL_4 += " left join XLXSBJCL on XLXSBJCL_BJCLID=XLXSBJCLWL_BJCLID"; sSQL_4 += " where 1=1"; if (XLJGB_CLJGTZList.NeedJGBJJFP()) { sSQL_4 += " and XLXSWLHQ_JGBID=:pJGBID_JJFP"; //SQL.ParamByName("pJGBID_JJFP").Value = sJGBID; } else { //同一个物料,在同一天当中只会存在一个价格,可以不用先查出maxYXQS sSQL_4 += " and XLXSWLHQ_JGBID=' '"; sSQL_4 += " and XLXSWLHQ_YXQS<=:pRQ and (XLXSWLHQ_YXQZ>=:pRQ or XLXSWLHQ_YXQZ is null)"; //SQL.ParamByName("pRQ").Value = DateTime.Now.ToShortDateString(); } sSQL_4 += string.Format(") c{0} on c{0}.XLXSWLHQ_WLID=XLXSCLQDWL_WLID{0} ", sWLHQCLQDList[i]); } sSQL_6 += string.Format(" ,V_XLXSCLQDWLHQ_JG{0} = WSJG{0} ", sWLHQCLQDList[i]); if ((i + 1) % 20 == 0 || i == sWLHQCLQDList.Length - 1) { SQL.Clear(); SQL.Add(sSQL_1); SQL.Add(sSQL_2); SQL.Add(sSQL_3); SQL.Add(sSQL_4); SQL.Add(sSQL_5); SQL.Add(sSQL_6); if (sBJDHQLX.Equals("BJDHQ"))//报价单行情 { SQL.ParamByName("pRQ").Value = DateTime.Now.ToShortDateString(); } else { if (XLJGB_CLJGTZList.NeedJGBJJFP()) { SQL.ParamByName("pJGBID_JJFP").Value = sJGBID; } else { SQL.ParamByName("pRQ").Value = DateTime.Now.ToShortDateString(); } } SQL.ParamByName("pID").Value = VnewID; SQL.ParamByName("pHSBZ").Value = "N"; SQL.ParamByName("pJGCZBID").Value = tmpJGCZBID; SQL.ParamByName("pJGCZBBBID").Value = tmpJGCZBBBID; dberp.ExecSQL(SQL); sSQL_2 = string.Empty; sSQL_4 = string.Empty; sSQL_6 = string.Empty; } } /* merge into 目标表 a using 源表 b on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……) when matched then update set a.更新字段=b.字段 when not matched then insert into a(字段1,字段2……)values(值1,值2……) */ SQL.Clear(); SQL.Add(" merge into XLXSCLQD a "); SQL.Add(" using "); SQL.Add(" (");//获取结构尺重表每个单元格所指报价物料的无税价格、含税价格 SQL.Add(" select V_XLXSCLQDWLHQ_ID,V_XLXSCLQDWLHQ_JGCZBID,V_XLXSCLQDWLHQ_JGCZBBBID,V_XLXSCLQDWLHQ_DRHH, "); for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { SQL.Add(string.Format(" V_XLXSCLQDWLHQ_JG{0} as WSJG{0}, ", sCLQDL.Replace("第", "").Replace("列", ""))); } } SQL.Add(" V_XLXSCLQDWLHQ_JGCZBXH "); SQL.Add(" from V_XLXSCLQDWLHQ");//这里不直接查XLXSCLQDWL的原因是XLXSCLQDWL可能还没有记录 SQL.Add(" where V_XLXSCLQDWLHQ_JGCZBID=:pJGCZBID and V_XLXSCLQDWLHQ_JGCZBBBID=:pJGCZBBBID and V_XLXSCLQDWLHQ_HSBZ<>'Y' and V_XLXSCLQDWLHQ_ID=:pID "); SQL.Add(" ) b "); SQL.Add(" on( "); SQL.Add(" a.XLXSCLQD_JGCZBID=:pJGCZBID and a.XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.Add(" and a.XLXSCLQD_JGCZBID=V_XLXSCLQDWLHQ_JGCZBID and a.XLXSCLQD_JGCZBBBID=V_XLXSCLQDWLHQ_JGCZBBBID "); SQL.Add(" and a.XLXSCLQD_DRHH=V_XLXSCLQDWLHQ_DRHH and a.XLXSCLQD_JGCZBXH=V_XLXSCLQDWLHQ_JGCZBXH "); if (!sBJDID.Trim().Equals(""))//这段是否有必要限制到具体要重算的产品,还是整个尺重表一起算,需要看项目执行效果再定 { SQL.Add(" and exists ("); SQL.Add("select 1 "); SQL.Add(" from XLXSBJDMX"); SQL.Add(" where XLXSBJDMX_BJDID=:pBJDID"); if (!sBJDXHList.Trim().Equals("")) SQL.Add(" and " + CMISproDataBase.GetWhereEqual("XLXSBJDMX_XH", sBJDXHList)); SQL.Add(" and XLXSBJDMX_XH >= :piMinXH"); SQL.Add(" and XLXSBJDMX_XLXHID=a.XLXSCLQD_XLXHID and XLXSBJDMX_XLGGID=a.XLXSCLQD_XLGGID"); SQL.Add(" and XLXSBJDMX_XLBZID=a.XLXSCLQD_XLBZID and XLXSBJDMX_DYDJID=a.XLXSCLQD_DYDJID"); SQL.Add(" ) "); SQL.ParamByName("pBJDID").Value = sBJDID; SQL.ParamByName("piMinXH").Value = iMinXH; } SQL.Add(" ) "); SQL.Add(" when matched then update set a.XLXSCLQD_JGBWSCB= "); //用量部分以abs计算,始终为正数,在case语句先判断材料部分是否是正数 //case 语句用于挑拣出用量大于0价格等于0的那一列,返回-1 SQL.Add(" (case when XLXSCLQD_JGBWSCB < 0 then (-1) "); for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { SQL.Add(string.Format(" when (XLXSCLQD_SL{0} > 0 and isnull(WSJG{0},0) = 0) then (-1) ", sCLQDL.Replace("第", "").Replace("列", ""))); } } SQL.Add(" else 1 end)* "); SQL.Add(" (abs(XLXSCLQD_JGBWSCB)-1.0+ ");//这里需要把上边材料行情部分算XLXSCLQD_JGBHSCB时加的1.0减掉 if (sJSBLFS.Equals("C1"))//C1|进一法(材料价各分项进一) { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { SQL.Add(string.Format("CEILING(RoundFix(XLXSCLQD_SL{0}*(1+XLXSCLQD_SHL{0}/100)*XLXSCLQD_CLJGBL{0}*isnull(WSJG{0},0)*{1},8))/{1}+", sCLQDL.Replace("第", "").Replace("列", ""), Math.Pow(10.0, iXSWS))); } } } else { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { SQL.Add(string.Format("XLXSCLQD_SL{0}*(1+XLXSCLQD_SHL{0}/100)*XLXSCLQD_CLJGBL{0}*isnull(WSJG{0},0)+", sCLQDL.Replace("第", "").Replace("列", ""))); } } } SQL.Add("0) "); SQL.ParamByName("pID").Value = VnewID; SQL.ParamByName("pJGCZBID").Value = tmpJGCZBID; SQL.ParamByName("pJGCZBBBID").Value = tmpJGCZBBBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" merge into XLXSCLQD a "); SQL.Add(" using "); SQL.Add(" (");//获取结构尺重表每个单元格所指报价物料的无税价格、含税价格 SQL.Add(" select V_XLXSCLQDWLHQ_ID,V_XLXSCLQDWLHQ_JGCZBID,V_XLXSCLQDWLHQ_JGCZBBBID,V_XLXSCLQDWLHQ_DRHH, "); for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { SQL.Add(string.Format(" V_XLXSCLQDWLHQ_JG{0} as HSJG{0}, ", sCLQDL.Replace("第", "").Replace("列", ""))); } } SQL.Add(" V_XLXSCLQDWLHQ_JGCZBXH "); SQL.Add(" from V_XLXSCLQDWLHQ");//这里不直接查XLXSCLQDWL的原因是XLXSCLQDWL可能还没有记录 SQL.Add(" where V_XLXSCLQDWLHQ_JGCZBID=:pJGCZBID and V_XLXSCLQDWLHQ_JGCZBBBID=:pJGCZBBBID and V_XLXSCLQDWLHQ_HSBZ='Y' and V_XLXSCLQDWLHQ_ID=:pID "); SQL.Add(" ) b "); SQL.Add(" on( "); SQL.Add(" a.XLXSCLQD_JGCZBID=:pJGCZBID and a.XLXSCLQD_JGCZBBBID=:pJGCZBBBID "); SQL.Add(" and a.XLXSCLQD_JGCZBID=V_XLXSCLQDWLHQ_JGCZBID and a.XLXSCLQD_JGCZBBBID=V_XLXSCLQDWLHQ_JGCZBBBID "); SQL.Add(" and a.XLXSCLQD_DRHH=V_XLXSCLQDWLHQ_DRHH and a.XLXSCLQD_JGCZBXH=V_XLXSCLQDWLHQ_JGCZBXH "); if (!sBJDID.Trim().Equals(""))//这段是否有必要限制到具体要重算的产品,还是整个尺重表一起算,需要看项目执行效果再定 { SQL.Add(" and exists ("); SQL.Add("select 1 "); SQL.Add(" from XLXSBJDMX"); SQL.Add(" where XLXSBJDMX_BJDID=:pBJDID"); if (!sBJDXHList.Trim().Equals("")) SQL.Add(" and " + CMISproDataBase.GetWhereEqual("XLXSBJDMX_XH", sBJDXHList)); SQL.Add(" and XLXSBJDMX_XH >= :piMinXH"); SQL.Add(" and XLXSBJDMX_XLXHID=a.XLXSCLQD_XLXHID and XLXSBJDMX_XLGGID=a.XLXSCLQD_XLGGID"); SQL.Add(" and XLXSBJDMX_XLBZID=a.XLXSCLQD_XLBZID and XLXSBJDMX_DYDJID=a.XLXSCLQD_DYDJID"); SQL.Add(" ) "); SQL.ParamByName("pBJDID").Value = sBJDID; SQL.ParamByName("piMinXH").Value = iMinXH; } SQL.Add(" ) "); SQL.Add(" when matched then update set a.XLXSCLQD_JGBHSCB= "); SQL.Add(" (case when XLXSCLQD_JGBHSCB < 0 then (-1) "); for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { SQL.Add(string.Format(" when (XLXSCLQD_SL{0} > 0 and isnull(HSJG{0},0) = 0) then (-1) ", sCLQDL.Replace("第", "").Replace("列", ""))); } } SQL.Add(" else 1 end)* "); SQL.Add(" (abs(XLXSCLQD_JGBHSCB)-1.0+ ");//这里需要把上边材料行情部分算XLXSCLQD_JGBHSCB时加的1.0减掉 if (sJSBLFS.Equals("C1"))//C1|进一法(材料价各分项进一) { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { SQL.Add(string.Format("CEILING(RoundFix(XLXSCLQD_SL{0}*(1+XLXSCLQD_SHL{0}/100)*XLXSCLQD_CLJGBL{0}*isnull(HSJG{0},0)*{1},8))/{1}+", sCLQDL.Replace("第", "").Replace("列", ""), Math.Pow(10.0, iXSWS))); } } } else { for (int i = 0; i < dsCLQDL.Tables[0].Rows.Count; i++) { sCLQDL = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_CLQDL"].ToString().Trim(); sBJHQ = dsCLQDL.Tables[0].Rows[i]["XLXSBJCL_BJHQ"].ToString().Trim(); sBJRCLCB = dsCLQDL.Tables[0].Rows[i]["XLJGCZBLM_BJRCLCB"].ToString().Trim(); if (sBJHQ.Equals("2") && !sBJRCLCB.Equals("Y"))//2|物料行情 { SQL.Add(string.Format("XLXSCLQD_SL{0}*(1+XLXSCLQD_SHL{0}/100)*XLXSCLQD_CLJGBL{0}*isnull(HSJG{0},0)+", sCLQDL.Replace("第", "").Replace("列", ""))); } } } SQL.Add("0)"); SQL.ParamByName("pID").Value = VnewID; SQL.ParamByName("pJGCZBID").Value = tmpJGCZBID; SQL.ParamByName("pJGCZBBBID").Value = tmpJGCZBBBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from V_XLXSCLQDWLHQ where V_XLXSCLQDWLHQ_ID=:pID "); SQL.ParamByName("pID").Value = VnewID; dberp.ExecSQL(SQL); } } } if (bCPMLXZ) { string tmpSQL = ""; if(!sBJDXHList.Trim().Equals("")) tmpSQL=" and " + CMISproDataBase.GetWhereEqual("XLXSBJDMX_XH", sBJDXHList); SQL.Clear(); SQL.Add(string.Format(@"merge into XLXSCLQD tag using( select XLXSCLQD_XLXHID as XLXHID,XLXSCLQD_XLGGID as XLGGID,XLXSCLQD_XLBZID as XLBZID,XLXSCLQD_DYDJID as DYDJID,CPMLID from( select XLXSCLQD_XLXHID,XLXSCLQD_XLGGID,XLXSCLQD_XLBZID,XLXSCLQD_DYDJID, case when isnull(A.XLXSBJXHML_CPMLID,' ')<>' ' then A.XLXSBJXHML_CPMLID else case when isnull(B.XLXSBJXHML_CPMLID,' ')<>' ' then B.XLXSBJXHML_CPMLID else ' ' end end as CPMLID from XLXSCLQD left join XLXSBJXHML A on A.XLXSBJXHML_XLXHID=XLXSCLQD_XLXHID and A.XLXSBJXHML_DYDJID <>' ' and A.XLXSBJXHML_DYDJID=XLXSCLQD_DYDJID left join XLXSBJXHML B on B.XLXSBJXHML_XLXHID=XLXSCLQD_XLXHID and B.XLXSBJXHML_DYDJID =' ' where 1=1 and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID and exists(select top 1 XLXSBJDMX_BJDID from XLXSBJDMX where XLXSBJDMX_BJDID=:pBJDID and XLXSBJDMX_XH >= :piMinXH {1} and XLXSBJDMX_XLXHID=XLXSCLQD_XLXHID and XLXSBJDMX_XLGGID=XLXSCLQD_XLGGID and XLXSBJDMX_XLBZID=XLXSCLQD_XLBZID and XLXSBJDMX_DYDJID=XLXSCLQD_DYDJID) )a where CPMLID <>' 'and CPMLID not in {0} )sor on (tag.XLXSCLQD_XLXHID=sor.XLXHID and tag.XLXSCLQD_XLGGID=sor.XLGGID and tag.XLXSCLQD_XLBZID=sor.XLBZID and tag.XLXSCLQD_DYDJID=sor.DYDJID and tag.XLXSCLQD_JGCZBID=:pJGCZBID and tag.XLXSCLQD_JGCZBBBID=:pJGCZBBBID ) when matched then update set tag.XLXSCLQD_JGBWSCB=0,tag.XLXSCLQD_JGBHSCB=0", sCPMLIDS, tmpSQL)); SQL.ParamByName("pJGCZBID").Value = tmpJGCZBID; SQL.ParamByName("pJGCZBBBID").Value = tmpJGCZBBBID; SQL.ParamByName("pBJDID").Value = sBJDID; SQL.ParamByName("piMinXH").Value = iMinXH; dberp.ExecSQL(SQL); } } if (sBJDID.Equals("")) { string tWHSJCondition = MISproUtils.GetServerTime().ToString();//这里ToString()是为了去除毫秒,因为UpdateJGBTJYS_3方法中根据查出的JJFPSJ限制其他数据时也只到秒 //重算价格表基价前清空基价、表价 SQL.Clear(); SQL.Add(" update XLXSJGBMX set XLXSJGBMX_WSJJ = 0, XLXSJGBMX_WSBJ = 0, XLXSJGBMX_HSJJ = 0, XLXSJGBMX_HSBJ = 0, "); SQL.Add(" XLXSJGBMX_HSJJM = 0,XLXSJGBMX_HSBJM = 0,XLXSJGBMX_WSJJM = 0,XLXSJGBMX_WSBJM = 0 ,"); SQL.Add(" XLXSJGBMX_WHR=:pWHR,XLXSJGBMX_WHRID=:pWHRID,XLXSJGBMX_WHSJ=:pWHSJ "); SQL.Add(" where XLXSJGBMX_JGBID=:pJGBID "); SQL.Add(" and XLXSJGBMX_SYXH=0 "); if (!sJGCZBID.Trim().Equals("") && !sJGCZBBBID.Trim().Equals("")) { SQL.Add(" and exists(select 1 from XLXSCLQD where XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID"); SQL.Add(" and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID and XLXSCLQD_WPID='ZZZZ' and XLXSCLQD_JGCZBID=:pJGCZBID and XLXSCLQD_JGCZBBBID=:pJGCZBBBID)"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH"); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pWHR").Value = sWHR; SQL.ParamByName("pWHRID").Value = sWHRID; SQL.ParamByName("pWHSJ").Value = tWHSJCondition; dberp.ExecSQL(SQL); if (dsJGCZB.Tables[0].Rows.Count > 0) { //WSJJM、WSBJM, string sHSBLSQL = string.Empty; sHSBLSQL += " (case when XLXSJGBMX_JLDW in ('M', '米') then 1"; sHSBLSQL += " when XLXSJGBMX_JLDW in ('Km', '千米') then 0.001 "; if (sBJU003.ToUpper().Equals("KM") || sBJU003.ToUpper().Equals("千米")) { sHSBLSQL += " when XLXSJGBMX_JLDW in ('Kg', '千克', '公斤') then 0.001 "; sHSBLSQL += " when XLXSJGBMX_JLDW in ('T', '吨') then 0.001"; } else if (sBJU003.ToUpper().Equals("米") || sBJU003.ToUpper().Equals("M")) { sHSBLSQL += " when XLXSJGBMX_JLDW in ('Kg', '千克', '公斤') then 1"; sHSBLSQL += " when XLXSJGBMX_JLDW in ('T', '吨') then 1 "; } sHSBLSQL += " else 0 "; sHSBLSQL += " end "; sHSBLSQL += " ) "; string sJJHSBLSQL=string.Empty; sJJHSBLSQL += " (case when XLXSJGBMX_JLDW in ('M', '米') then 1"; sJJHSBLSQL += " when XLXSJGBMX_JLDW in ('Km', '千米') then 1 "; if (sBJU003.ToUpper().Equals("KM") || sBJU003.ToUpper().Equals("千米")) { sJJHSBLSQL += " when XLXSJGBMX_JLDW in ('Kg', '千克', '公斤') then (case when XLXSCLQD_CLZL = 0 then 1 else 1/XLXSCLQD_CLZL end)"; sJJHSBLSQL += " when XLXSJGBMX_JLDW in ('T', '吨') then (case when XLXSCLQD_CLZL = 0 then 1 else 1000/XLXSCLQD_CLZL end)"; } else if (sBJU003.ToUpper().Equals("米") || sBJU003.ToUpper().Equals("M")) { sJJHSBLSQL += " when XLXSJGBMX_JLDW in ('Kg', '千克', '公斤') then (case when XLXSCLQD_CLZL = 0 then 1 else 1/XLXSCLQD_CLZL end)"; sJJHSBLSQL += " when XLXSJGBMX_JLDW in ('T', '吨') then (case when XLXSCLQD_CLZL = 0 then 1 else 1000/XLXSCLQD_CLZL end)"; } sJJHSBLSQL += " else 1 "; sJJHSBLSQL += " end "; sJJHSBLSQL += " ) "; /* merge into 目标表 a using 源表 b on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……) when matched then update set a.更新字段=b.字段 when not matched then insert into a(字段1,字段2……)values(值1,值2……) */ SQL.Clear(); SQL.Add(" merge into XLXSJGBMX a "); SQL.Add(" using XLXSCLQD b "); SQL.Add(" on ( "); SQL.Add(" XLXSJGBMX_JGBID=:pJGBID "); SQL.Add(" and XLXSJGBMX_XLXHID=XLXSCLQD_XLXHID and XLXSJGBMX_XLGGID=XLXSCLQD_XLGGID and XLXSJGBMX_XLBZID=XLXSCLQD_XLBZID and XLXSJGBMX_DYDJID=XLXSCLQD_DYDJID "); SQL.Add(" and XLXSJGBMX_SYXH=0 "); if (!sJGCZBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBID=:pJGCZBID"); SQL.ParamByName("pJGCZBID").Value = sJGCZBID.Trim(); } if (!sJGCZBBBID.Trim().Equals("")) { SQL.Add(" and XLXSCLQD_JGCZBBBID=:pJGCZBBBID"); SQL.ParamByName("pJGCZBBBID").Value = sJGCZBBBID.Trim(); } if (maxXH != 0) { SQL.Add(" and XLXSJGBMX_XH > :pmaxXH"); SQL.ParamByName("pmaxXH").Value = maxXH; } SQL.Add(" ) "); SQL.Add(" when matched then update set "); if (sJSBLFS.Equals("C1") || sJSBLFS.Equals("C2") || sJSBLFS.Equals("C3"))//C1|进一法(材料价各分项进一)、C2|进一法(材料价汇总进一)、C3|材料价汇总进一+表价进一到十位 { SQL.Add(string.Format(" XLXSJGBMX_WSJJ=CEILING(RoundFix(" + sJJHSBLSQL + " *isnull(XLXSCLQD_JGBWSCB,0)*{0},8))/{0},XLXSJGBMX_HSJJ=CEILING(RoundFix(" + sJJHSBLSQL + " *isnull(XLXSCLQD_JGBHSCB,0)*{0},8))/{0},", Math.Pow(10.0, iXSWS))); if (sJSBLFS.Equals("C3")) SQL.Add(string.Format(" XLXSJGBMX_WSBJ=CEILING(RoundFix(" + sJJHSBLSQL + " *isnull(XLXSCLQD_JGBWSCB,0),{0})/10)*10,XLXSJGBMX_HSBJ=CEILING(RoundFix(" + sJJHSBLSQL + " *isnull(XLXSCLQD_JGBHSCB,0),{0})/10)*10,", iXSWS.ToString().Trim())); else SQL.Add(string.Format(" XLXSJGBMX_WSBJ=CEILING(RoundFix(" + sJJHSBLSQL + " *isnull(XLXSCLQD_JGBWSCB,0)*{0},8))/{0},XLXSJGBMX_HSBJ=CEILING(" + sJJHSBLSQL + " *RoundFix(isnull(XLXSCLQD_JGBHSCB,0)*{0},8))/{0},", Math.Pow(10.0, iXSWS))); SQL.Add(" XLXSJGBMX_WSJJM = RoundFix(" + sHSBLSQL + " * XLXSCLQD_JGBWSCB ,6),"); SQL.Add(" XLXSJGBMX_HSJJM = RoundFix(" + sHSBLSQL + " * XLXSCLQD_JGBHSCB ,6),"); SQL.Add(" XLXSJGBMX_WSBJM = RoundFix(" + sHSBLSQL + " * XLXSCLQD_JGBWSCB ,6),"); SQL.Add(" XLXSJGBMX_HSBJM = RoundFix(" + sHSBLSQL + " * XLXSCLQD_JGBHSCB ,6),"); } else { SQL.Add(" XLXSJGBMX_WSJJ=RoundFix(" + sJJHSBLSQL + " *isnull(XLXSCLQD_JGBWSCB,0)," + iXSWS + "),XLXSJGBMX_HSJJ=RoundFix(" + sJJHSBLSQL + " *isnull(XLXSCLQD_JGBHSCB,0)," + iXSWS + "),"); SQL.Add(" XLXSJGBMX_WSBJ=RoundFix(" + sJJHSBLSQL + " *isnull(XLXSCLQD_JGBWSCB,0)," + iXSWS + "),XLXSJGBMX_HSBJ=RoundFix(" + sJJHSBLSQL + " *isnull(XLXSCLQD_JGBHSCB,0)," + iXSWS + "),"); SQL.Add(" XLXSJGBMX_WSJJM=RoundFix(" + sHSBLSQL + " * isnull(XLXSCLQD_JGBWSCB,0) ,6),"); SQL.Add(" XLXSJGBMX_HSJJM=RoundFix(" + sHSBLSQL + " * isnull(XLXSCLQD_JGBHSCB,0) ,6),"); SQL.Add(" XLXSJGBMX_WSBJM=RoundFix(" + sHSBLSQL + " * isnull(XLXSCLQD_JGBWSCB,0) ,6),"); SQL.Add(" XLXSJGBMX_HSBJM=RoundFix(" + sHSBLSQL + " * isnull(XLXSCLQD_JGBHSCB,0) ,6),"); } SQL.Add(" XLXSJGBMX_WHR=:pWHR, "); SQL.Add(" XLXSJGBMX_WHRID=:pWHRID, "); SQL.Add(" XLXSJGBMX_WHSJ=:pWHSJ "); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pWHR").Value = sWHR; SQL.ParamByName("pWHRID").Value = sWHRID; SQL.ParamByName("pWHSJ").Value = tWHSJCondition; dberp.ExecSQL(SQL); } if (XLJGB_CLJGTZList.NeedJGBJJFP()) { //把这一波更新的价格表明细对应的复盘数据删除 SQL.Clear(); SQL.Add("delete from XLXSJGBCLQD where XLXSJGBCLQD_JGBID=:pJGBID and exists(select 1 from XLXSJGBMX where XLXSJGBMX_JGBID=XLXSJGBCLQD_JGBID and XLXSJGBMX_XH=XLXSJGBCLQD_XH and XLXSJGBMX_WHSJ=:pWHSJ) "); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pWHSJ").Value = tWHSJCondition; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from XLXSJGBYLLM where XLXSJGBYLLM_JGBID=:pJGBID and not exists(select 1 from XLXSJGBCLQD where XLXSJGBCLQD_JGBID=XLXSJGBYLLM_JGBID and XLXSJGBYLLM_JGCZBID=XLXSJGBCLQD_JGCZBID and XLXSJGBYLLM_JGCZBBBID=XLXSJGBCLQD_JGCZBBBID and XLXSJGBYLLM_JJFPSJ=XLXSJGBCLQD_JJFPSJ)"); SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add("delete from XLXSJGBCLQDWL where XLXSJGBCLQDWL_JGBID=:pJGBID and exists(select 1 from XLXSJGBMX where XLXSJGBMX_JGBID=XLXSJGBCLQDWL_JGBID and XLXSJGBMX_XH=XLXSJGBCLQDWL_XH and XLXSJGBMX_WHSJ=:pWHSJ) "); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pWHSJ").Value = tWHSJCondition; dberp.ExecSQL(SQL); string sSQL = ""; SQL.Clear(); SQL.Add(" insert into XLXSJGBCLQD "); SQL.Add(" (XLXSJGBCLQD_JGBID,XLXSJGBCLQD_XH,XLXSJGBCLQD_JGCZBID,XLXSJGBCLQD_JGCZBBBID,XLXSJGBCLQD_JGCZBXH,XLXSJGBCLQD_DRHH,XLXSJGBCLQD_JJFPSJ "); for (int i = 1; i <= 80; i++) { SQL.Add(",XLXSJGBCLQD_ZL" + i.ToString().PadLeft(2, '0')); sSQL += string.Format(",isnull(XLXSCLQD_SL{0}*XLXSCLQD_CLJGBL{0}*(1+XLXSCLQD_SHL{0}/100.0),0) as ZL{0}", i.ToString().PadLeft(2, '0')); } SQL.Add(" )"); SQL.Add(" select XLXSJGBMX_JGBID,XLXSJGBMX_XH,XLXSCLQD_JGCZBID,XLXSCLQD_JGCZBBBID,isnull(XLXSCLQD_JGCZBXH,0),isnull(XLXSCLQD_DRHH,0),:pJJFPSJ "); SQL.Add(sSQL); SQL.Add(" from XLXSJGBMX "); SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add(" and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); SQL.Add(" and isnull(XLXSCLQD_WPID,' ')='ZZZZ' "); SQL.Add(" where XLXSJGBMX_JGBID = :pJGBID "); SQL.Add(" and not exists(select 1 from XLXSJGBCLQD where XLXSJGBCLQD_JGBID=XLXSJGBMX_JGBID and XLXSJGBCLQD_XH=XLXSJGBMX_XH)"); SQL.ParamByName("pJJFPSJ").Value = tWHSJCondition; SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); SQL.Clear(); SQL.Add(" insert into XLXSJGBYLLM(XLXSJGBYLLM_JGBID,XLXSJGBYLLM_JGCZBID,XLXSJGBYLLM_JGCZBBBID,XLXSJGBYLLM_CZBLMBH,XLXSJGBYLLM_HLMLX,XLXSJGBYLLM_JJFPSJ, "); SQL.Add(" XLXSJGBYLLM_CZBLMMC,XLXSJGBYLLM_CLQDL,XLXSJGBYLLM_BJCLID,XLXSJGBYLLM_WHRID,XLXSJGBYLLM_WHR,XLXSJGBYLLM_WHSJ) "); SQL.Add(" select :pJGBID as JGBID,XLJGCZBLM_JGCZBID,XLJGCZBLM_JGCZBBBID,XLJGCZBLM_CZBLMBH,XLJGCZBLM_HLMLX,:pJJFPSJ, "); SQL.Add(" XLJGCZBLM_CZBLMMC,XLJGCZBLM_CLQDL,XLJGCZBLM_BJCLID,:pWHR,:pWHRID,:pWHSJ "); SQL.Add(" from XLJGCZBLM "); SQL.Add(" where isnull(XLJGCZBLM_CLQDL,' ')<>' ' "); SQL.Add(" and exists( "); SQL.Add(" select 1 from XLXSJGBMX "); SQL.Add(" left join XLXSCLQD on XLXSCLQD_XLXHID=XLXSJGBMX_XLXHID and XLXSCLQD_XLGGID=XLXSJGBMX_XLGGID "); SQL.Add(" and XLXSCLQD_XLBZID=XLXSJGBMX_XLBZID and XLXSCLQD_DYDJID=XLXSJGBMX_DYDJID "); SQL.Add(" where XLXSJGBMX_JGBID = :pJGBID and XLXSJGBMX_WHSJ=:pWHSJ "); SQL.Add(" and XLJGCZBLM_JGCZBID=XLXSCLQD_JGCZBID and XLJGCZBLM_JGCZBBBID=XLXSCLQD_JGCZBBBID "); SQL.Add(" ) "); SQL.ParamByName("pJGBID").Value = sJGBID; SQL.ParamByName("pWHR").Value = sWHR; SQL.ParamByName("pWHRID").Value = sWHRID; SQL.ParamByName("pJJFPSJ").Value = tWHSJCondition; SQL.ParamByName("pWHSJ").Value = tWHSJCondition; dberp.ExecSQL(SQL); SQL.Clear(); sSQL = ""; SQL.Add(" insert into XLXSJGBCLQDWL(XLXSJGBCLQDWL_JGBID,XLXSJGBCLQDWL_XH "); for (int i = 1; i <= 80; i++) { SQL.Add(",XLXSJGBCLQDWL_WLID" + i.ToString().PadLeft(2, '0')); sSQL += string.Format(",XLXSCLQDWL_WLID{0}", i.ToString().PadLeft(2, '0')); } SQL.Add(" )"); SQL.Add(" select XLXSJGBCLQD_JGBID,XLXSJGBCLQD_XH "); SQL.Add(sSQL); SQL.Add(" from XLXSJGBCLQD "); SQL.Add(" left join XLXSCLQDWL on XLXSCLQDWL_JGCZBID=XLXSJGBCLQD_JGCZBID and XLXSCLQDWL_JGCZBBBID=XLXSJGBCLQD_JGCZBBBID "); SQL.Add(" and XLXSCLQDWL_JGCZBXH=XLXSJGBCLQD_JGCZBXH and XLXSCLQDWL_DRHH=XLXSJGBCLQD_DRHH "); SQL.Add(" where XLXSJGBCLQD_JGBID = :pJGBID "); SQL.Add(" and not exists(select 1 from XLXSJGBCLQDWL where XLXSJGBCLQDWL_JGBID=XLXSJGBCLQD_JGBID and XLXSJGBCLQDWL_XH=XLXSJGBCLQD_XH)"); SQL.ParamByName("pJGBID").Value = sJGBID; dberp.ExecSQL(SQL); } } } //调价因素3价格表,则XLXSCLQD_JGBHSCB、XLXSCLQD_JGBWSCB只用来记录材料价价差 public static void UpdateCLCB(TDatabase dberp, TSQL SQL, string sJGBID, string sJGCZBID, string sJGCZBBBID, int iXSWS, string sJSBLFS, string sWHRID, string sWHR, double maxXH, string sJGBID1, string sTBJCLID_JGBBJ, string sLBJCLID_JGBBJ, double dTJ_JGBBJ, double dLJ_JGBBJ, string sBJDID, int iMinXH, string sBJU003) { UpdateCLCB(dberp, SQL, sJGBID, sJGCZBID, sJGCZBBBID, iXSWS, sJSBLFS, sWHRID, sWHR, maxXH, sJGBID1, sTBJCLID_JGBBJ, sLBJCLID_JGBBJ, dTJ_JGBBJ, dLJ_JGBBJ, sBJDID, iMinXH, "", sBJU003); } } }