///<reference path="/Scripts/ExtPB_Net.js" />
///<reference path="/Scripts/MyExtPB.js" />
///<reference path="/Scripts/ExtPB_Dll_Pb_Http.js" />
///<reference path="/Scripts/MyExtPb_Input.js" />
///<reference  path="/CaiGou/CaiGouTongJiFenxi/W_CG_HZ_Base.win.js" /> 

//注意,需要在对象定义后面，手工增加以下代码实现对象继承
// W_JQYS_DB.prototype = new W_CG_HZ_Base( ); 

function W_JQYS_DB() {

    var self = this;
    var requestor = new PBWindow();
    var cbx_bz = new CheckBox(requestor);
    var rb_rq = new RadioButton(requestor);
    var rb_dcbm = new RadioButton(requestor);
    var rb_drbm = new RadioButton(requestor);
    var rb_sp = new RadioButton(requestor);
    var cbx_drbm = new CheckBox(requestor);
    var sle_dcbm = new SingleLineEdit(requestor);
    var cbx_pzh = new CheckBox(requestor);
    var cbx_fs = new CheckBox(requestor);
    var cbx_zdr = new CheckBox(requestor);
    var cbx_lb = new CheckBox(requestor);
    var cbx_dcbm = new CheckBox(requestor);
    var cbx_rq = new CheckBox(requestor);
    var sle_pzh = new SingleLineEdit(requestor);
    var sle_fs = new SingleLineEdit(requestor);
    var sle_ml = new SingleLineEdit(requestor);
    var sle_jj = new SingleLineEdit(requestor);
    var sle_lb = new SingleLineEdit(requestor);
    var sle_kh = new SingleLineEdit(requestor);
    var sle_gys = new SingleLineEdit(requestor);
    var sle_pp = new SingleLineEdit(requestor);
    var sle_drbm = new SingleLineEdit(requestor);
    var dp_2 = new DatePicker(requestor);
    var dp_1 = new DatePicker(requestor);
    var dw_format = new DataWindow(requestor);
    var dw_list = new DataWindow(requestor);
    var mle_1 = new MultiLineEdit(requestor);
    var dw_temp = new DataWindow(requestor);
    var tb_1 = new ToolStrip(requestor);
    var ddlb_nf = new DropDownListBox(requestor);
    var ddlb_sex = new DropDownListBox(requestor);
    var cb_3 = new CommandButton(requestor);
    var sle_formatname = new SingleLineEdit(requestor);
    var cb_Save = new CommandButton(requestor);
    var cb_Select = new CommandButton(requestor);
    var ContextMenuStrip1 = new ContextMenu(requestor);
    if (typeof (this.bind) == "function") var baseBind = this.bind;
    this.bind = function (win) {
        if (typeof (baseBind) == "function") baseBind(win);

        if (requestor == null) requestor = new PBWindow();
        requestor.Attach(win);
        if (cbx_bz == null) cbx_bz = new CheckBox(requestor);
        cbx_bz.Attach(win.Control("cbx_bz"));
        if (rb_rq == null) rb_rq = new RadioButton(requestor);
        rb_rq.Attach(win.Control("rb_rq"));
        if (rb_dcbm == null) rb_dcbm = new RadioButton(requestor);
        rb_dcbm.Attach(win.Control("rb_dcbm"));
        if (rb_drbm == null) rb_drbm = new RadioButton(requestor);
        rb_drbm.Attach(win.Control("rb_drbm"));
        if (rb_sp == null) rb_sp = new RadioButton(requestor);
        rb_sp.Attach(win.Control("rb_sp"));
        if (cbx_drbm == null) cbx_drbm = new CheckBox(requestor);
        cbx_drbm.Attach(win.Control("cbx_drbm"));
        if (sle_dcbm == null) sle_dcbm = new SingleLineEdit(requestor);
        sle_dcbm.Attach(win.Control("sle_dcbm"));
        if (cbx_pzh == null) cbx_pzh = new CheckBox(requestor);
        cbx_pzh.Attach(win.Control("cbx_pzh"));
        if (cbx_fs == null) cbx_fs = new CheckBox(requestor);
        cbx_fs.Attach(win.Control("cbx_fs"));
        if (cbx_zdr == null) cbx_zdr = new CheckBox(requestor);
        cbx_zdr.Attach(win.Control("cbx_zdr"));
        if (cbx_lb == null) cbx_lb = new CheckBox(requestor);
        cbx_lb.Attach(win.Control("cbx_lb"));
        if (cbx_dcbm == null) cbx_dcbm = new CheckBox(requestor);
        cbx_dcbm.Attach(win.Control("cbx_dcbm"));
        if (cbx_rq == null) cbx_rq = new CheckBox(requestor);
        cbx_rq.Attach(win.Control("cbx_rq"));
        if (sle_pzh == null) sle_pzh = new SingleLineEdit(requestor);
        sle_pzh.Attach(win.Control("sle_pzh"));
        if (sle_fs == null) sle_fs = new SingleLineEdit(requestor);
        sle_fs.Attach(win.Control("sle_fs"));
        if (sle_ml == null) sle_ml = new SingleLineEdit(requestor);
        sle_ml.Attach(win.Control("sle_ml"));
        if (sle_jj == null) sle_jj = new SingleLineEdit(requestor);
        sle_jj.Attach(win.Control("sle_jj"));
        if (sle_lb == null) sle_lb = new SingleLineEdit(requestor);
        sle_lb.Attach(win.Control("sle_lb"));
        if (sle_kh == null) sle_kh = new SingleLineEdit(requestor);
        sle_kh.Attach(win.Control("sle_kh"));
        if (sle_gys == null) sle_gys = new SingleLineEdit(requestor);
        sle_gys.Attach(win.Control("sle_gys"));
        if (sle_pp == null) sle_pp = new SingleLineEdit(requestor);
        sle_pp.Attach(win.Control("sle_pp"));
        if (sle_drbm == null) sle_drbm = new SingleLineEdit(requestor);
        sle_drbm.Attach(win.Control("sle_drbm"));
        if (dp_2 == null) dp_2 = new DatePicker(requestor);
        dp_2.Attach(win.Control("dp_2"));
        if (dp_1 == null) dp_1 = new DatePicker(requestor);
        dp_1.Attach(win.Control("dp_1"));
        if (dw_format == null) dw_format = new DataWindow(requestor);
        dw_format.Attach(win.Control("dw_format"));
        if (dw_list == null) dw_list = new DataWindow(requestor);
        dw_list.Attach(win.Control("dw_list"));
        if (mle_1 == null) mle_1 = new MultiLineEdit(requestor);
        mle_1.Attach(win.Control("mle_1"));
        if (dw_temp == null) dw_temp = new DataWindow(requestor);
        dw_temp.Attach(win.Control("dw_temp"));
        if (tb_1 == null) tb_1 = new ToolStrip(requestor);
        tb_1.Attach(win.Control("tb_1"));
        if (ddlb_nf == null) ddlb_nf = new DropDownListBox(requestor);
        ddlb_nf.Attach(win.Control("ddlb_nf"));
        if (ddlb_sex == null) ddlb_sex = new DropDownListBox(requestor);
        ddlb_sex.Attach(win.Control("ddlb_sex"));
        if (sle_formatname == null) sle_formatname = new SingleLineEdit(requestor);
        sle_formatname.Attach(win.Control("sle_formatname"));
        if (ContextMenuStrip1 == null) ContextMenuStrip1 = new ContextMenu(requestor);
        ContextMenuStrip1.Attach(win.Control("ContextMenuStrip1"));
        if (cb_Save == null) cb_Save = new CommandButton(requestor);
        cb_Save.Attach(win.Control("cb_Save"));
        if (cb_Select == null) cb_Select = new CommandButton(requestor);
        cb_Select.Attach(win.Control("cb_Select"));
        if (cb_3 == null) cb_3 = new CommandButton(requestor);
        cb_3.Attach(win.Control("cb_3"));

        if (typeof (self.PostOpen) == "function")
            win.AttachEvent("window", "PostOpen", self.PostOpen);

        if (typeof (self.setcbx) == "function")
            win.AttachEvent("cbx_bz", "Clicked", self.setcbx);

        if (typeof (self.rb_bm) == "function")
            win.AttachEvent("rb_rq", "Clicked", self.rb_bm);

        if (typeof (self.rb_bm) == "function")
            win.AttachEvent("rb_dcbm", "Clicked", self.rb_bm);

        if (typeof (self.rb_bm) == "function")
            win.AttachEvent("rb_drbm", "Clicked", self.rb_bm);

        if (typeof (self.rb_sp) == "function")
            win.AttachEvent("rb_sp", "Clicked", self.rb_sp);

        if (typeof (self.setcbx) == "function")
            win.AttachEvent("cbx_drbm", "Clicked", self.setcbx);

        if (typeof (self.Changebmbh2) == "function")
            win.AttachEvent("cb_9", "Clicked", self.Changebmbh2);

        if (typeof (self.setcbx) == "function")
            win.AttachEvent("cbx_pzh", "Clicked", self.setcbx);

        if (typeof (self.setcbx) == "function")
            win.AttachEvent("cbx_fs", "Clicked", self.setcbx);

        if (typeof (self.setcbx) == "function")
            win.AttachEvent("cbx_zdr", "Clicked", self.setcbx);

        if (typeof (self.setcbx) == "function")
            win.AttachEvent("cbx_lb", "Clicked", self.setcbx);

        if (typeof (self.setcbx) == "function")
            win.AttachEvent("cbx_dcbm", "Clicked", self.setcbx);

        if (typeof (self.setcbx) == "function")
            win.AttachEvent("cbx_rq", "Clicked", self.setcbx);

        if (typeof (self.Changetzfs) == "function")
            win.AttachEvent("cb_8", "Clicked", self.Changetzfs);

        if (typeof (self.Changeml) == "function")
            win.AttachEvent("cb_7", "Clicked", self.Changeml);

        if (typeof (self.Changejj) == "function")
            win.AttachEvent("cb_6", "Clicked", self.Changejj);

        if (typeof (self.Changelb) == "function")
            win.AttachEvent("cb_5", "Clicked", self.Changelb);

        if (typeof (self.Changekh) == "function")
            win.AttachEvent("cb_4", "Clicked", self.Changekh);

        if (typeof (self.Changegys) == "function")
            win.AttachEvent("cb_3", "Clicked", self.Changegys);

        if (typeof (self.Changepinpai) == "function")
            win.AttachEvent("cb_2", "Clicked", self.Changepinpai);

        if (typeof (self.Changebmbh1) == "function")
            win.AttachEvent("cb_1", "Clicked", self.Changebmbh1);

        if (typeof (self.TongJi) == "function")
            win.AttachEvent("btn_Query", "Clicked", self.TongJi);

        if (typeof (self.Print) == "function")
            win.AttachEvent("btn_Print", "Clicked", self.Print);

        if (typeof (self.SelectGS) == "function")
            win.AttachEvent("cb_Select", "Clicked", self.SelectGS);

        if (typeof (self.SaveGS) == "function")
            win.AttachEvent("cb_Save", "Clicked", self.SaveGS);

        if (typeof (self.ReportOp) == "function")
            win.AttachEvent("列格式保存ToolStripMenuItem", "Clicked", self.ReportOp);

        if (typeof (self.ReportClare) == "function")
            win.AttachEvent("清空当前窗口所有格式ToolStripMenuItem", "Clicked", self.ReportClare);

        if (typeof (self.picpreview) == "function")
            win.AttachEvent("浏览图片ToolStripMenuItem", "Clicked", self.picpreview);

        if (typeof (self.DoubleClicked) == "function")
            win.AttachEvent("dw_List", "DoubleClicked", self.DoubleClicked);

        if (typeof (self.ReportSave) == "function")
            win.AttachEvent("xxxxxxaToolStripMenuItem", "Clicked", self.ReportSave);

        if (typeof (self.Exit) == "function")
            win.AttachEvent("btn_Exit", "Clicked", self.Exit);
  
    }

    if (typeof (this.unbind) == "function") var baseUnBind = this.unbind;
    this.unbind = function () {
        if (typeof (this.Release) == "function") this.Release();
        if (typeof (baseUnBind) == "function") baseUnBind();

        cbx_bz.Detach(); cbx_bz = null;
        rb_rq.Detach(); rb_rq = null;
        rb_dcbm.Detach(); rb_dcbm = null;
        rb_drbm.Detach(); rb_drbm = null;
        rb_sp.Detach(); rb_sp = null;
        cbx_drbm.Detach(); cbx_drbm = null;
        sle_dcbm.Detach(); sle_dcbm = null;
        cbx_pzh.Detach(); cbx_pzh = null;
        cbx_fs.Detach(); cbx_fs = null;
        cbx_zdr.Detach(); cbx_zdr = null;
        cbx_lb.Detach(); cbx_lb = null;
        cbx_dcbm.Detach(); cbx_dcbm = null;
        cbx_rq.Detach(); cbx_rq = null;
        sle_pzh.Detach(); sle_pzh = null;
        sle_fs.Detach(); sle_fs = null;
        sle_ml.Detach(); sle_ml = null;
        sle_jj.Detach(); sle_jj = null;
        sle_lb.Detach(); sle_lb = null;
        sle_kh.Detach(); sle_kh = null;
        sle_gys.Detach(); sle_gys = null;
        sle_pp.Detach(); sle_pp = null;
        sle_drbm.Detach(); sle_drbm = null;
        dp_2.Detach(); dp_2 = null;
        dp_1.Detach(); dp_1 = null;
        dw_format.Detach(); dw_format = null;
        dw_list.Detach(); dw_list = null;
        mle_1.Detach(); mle_1 = null;
        dw_temp.Detach(); dw_temp = null;
        tb_1.Detach(); tb_1 = null;
        requestor.Detach(); requestor = null;
        ddlb_nf.Detach(); ddlb_nf = null;
        ddlb_sex.Detach(); ddlb_sex = null;
        cb_3.Detach(); cb_3 = null;
        sle_formatname.Detach(); sle_formatname = null;
        cb_Save.Detach(); cb_Save = null;
        cb_Select.Detach(); cb_Select = null;
        ContextMenuStrip1.Detach(); ContextMenuStrip1 = null;
        setTimeout(CollectGarbage, 100);
    }

    //以上代码由设计器自动生成,请不要手工修改
    //ExtPB.Net JavaScript End  设计器查找标志,请不要删除或修改

    //#region 变量声明板块
    var curW_OPEN_BMDA = new OpenWindowQueryBase();

    var curW_OPEN_BMDA_NEW = new OpenWindowQueryNewBase();
    var curW_OPEN_BMDA_URL = "OpenWindowQueryNewBase";
    
    
    var curW_OPEN_SIMPLE_CHOSE = new OpenWindowSimpleChoseBase();

    var curOtherWidht = 1080;
    var curOtherHeight = 760;

    var curOpenWindowDoubleRowsChooseBase = new OpenWindowDoubleRowsChooseBase();
    var gRowCount = 0;
    var ywflag = "";
    var curYhbh = "";
    webReq = new WebRequestor();
    webReq.SetWebServiceUrl("/Service/ServiceForDwSyndax.ashx");

    webReq_Print = new WebRequestor();
    webReq_Print.SetWebServiceUrl("/Service/Ajax_XT.ashx");
    var curYhmc = "";

    var C_CheckValue = "";
    var curBbmc = "rb_sp";
    var curCdbh = ""
    var jgtxlist = "";
    var ExistGYS = "";

    var ExistJJ = "N";
    var ExistLSJ = "N";
    var ExistDPJ = "N";
    var ExistDBJ = "N";

    //报表名称
    var curBBMCNew = "";
    var curBBPZH = "";
    var curOptype = "0" //0 ：保存  1：修改 
    var cur_Open_Window = null;
    var ChildDWCheckValue = "";
    var curDw_format_hz = null; //格式汇总窗口
    var curDw_format_mx = null; //格式明细窗口
    var Exel_FH_Flag = "1";
    var curW_Base_Report_Open_Mx_Ex = new W_Base_Report_Open_Mx_Ex();
    var curUserId = "";
    var curcbx_gs = 0;
    var xsmrgs = 0;
    var curPzh = "";
    var syntax = "";
    var evealStr = "";
    var lastSortName = "";
    var isFirstSave = "";
    var curW_KC_PIC = new W_KC_PIC();
    //#endregion

    //#region Function Query
    this.Query = function () {

        var dynamicShowStr = "";
        var dynamicShowString = "";

        var dynamicShowStr1 = "";
        var dynamicShowString1 = "";

        var dynamicShowStrEnd = "";
        var dynamicShowStringEnd = "";

        var curSql = ""
        var curRows = "";
        var curCols = "";
        var curValues = "";
        var curColTypes = "";
        var sy = "";
        var finishSql = "";
        C_CheckValue = "";
        dw_temp.Reset();
        //#region 表头显示
        
        if (cbx_lb.GetChecked()) {
            dynamicShowStr += "hplb as lbbh,lbmc as lbmc,";
            dynamicShowString += "b.hplb,c.lbmc,";
            C_CheckValue += "cbx_lb,"
        }
        if (cbx_drbm.GetChecked()) {
            if (ywflag == "DZ") {
                dynamicShowStr1 += "h.bmbh1  bmbh,d.bmmc  bmmc,";
                dynamicShowString1 += ",h.bmbh1,d.bmmc";
            } else {
                dynamicShowStr1 += "a.khbh  bmbh,d.bmmc  bmmc,";
                dynamicShowString1 += ",a.khbh,d.bmmc";
            }
            C_CheckValue += "cbx_drbm,"
        }
        if (cbx_dcbm.GetChecked()) {
            if (ywflag == "DZ") {
                dynamicShowStr1 += "h.bmbh2  bmbh2,e.bmmc  bmmc2,";
                dynamicShowString1 += ",h.bmbh2,e.bmmc";
            } else {
                dynamicShowStr1 += "a.bmbh2 as bmbh2,e.bmmc  bmmc2,";
                dynamicShowString1 += ",a.bmbh2,e.bmmc";
            }
            C_CheckValue += "cbx_dcbm,"
        }
        if (cbx_rq.GetChecked()) {
            dynamicShowStr1 += " convert(varchar(10),kdrq,23) as rq,";
            dynamicShowString1 += " ,convert(varchar(10), kdrq,23)";
            C_CheckValue += "cbx_rq,"
        }
        if (cbx_pzh.GetChecked()) {
            dynamicShowStr1 += "a.pzh as pzh,";
            dynamicShowString1 += ",a.pzh";
            C_CheckValue += "cbx_pzh,"
        }
        if (cbx_zdr.GetChecked()) {
            if (ywflag == "DZ") {
                dynamicShowStrEnd += ",h.kdr  kdr";
                dynamicShowStringEnd += ",h.kdr";
            } else {
                dynamicShowStrEnd += ",a.kdr as kdr";
                dynamicShowStringEnd += ",a.kdr";
            }
            C_CheckValue += "cbx_zdr,"
        }
        if (cbx_fs.GetChecked()) {
            dynamicShowStrEnd += " ,f.csmc   cgfs";
            dynamicShowStringEnd += ",f.csmc";
            C_CheckValue += "cbx_fs,"
        }
        if (cbx_bz.GetChecked()) {
            if (ywflag == "DZ") {
                dynamicShowStrEnd += ",h.bzxx  bzxx";
                dynamicShowStringEnd += ",h.bzxx";
            } else {
                dynamicShowStrEnd += ",a.bzxx   bzxx";
                dynamicShowStringEnd += ",a.bzxx";
            }
            C_CheckValue += "cbx_bz,"
        }
        //#endregion

        //#region 水平
        if (ywflag == "DB") {
            var finishSql = "select " + dynamicShowStr + "a.spkh,b.ksmc,b.jldw,a.ysbh,g.ysmc," + dynamicShowStr1 +
                            "SUM(a.sl) zjsl,SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) lsj, SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0)) as lsjze," +
                            "SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) jj, SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0)) as jjze,SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) dpj, SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0)) as dpjze  " + dynamicShowStrEnd +
                            " from (SELECT * FROM  dbo.yw_db_dbddtz UNION ALL SELECT * FROM  dbo.yw_db_dbddtz_LS) a left join  da_sp_spda b on a.spkh=b.spkh " +
                            " left join da_sp_lbda c on c.lbbh=b.hplb  " +
                            "left join da_bmda d on d.bmbh=a.khbh  " +
                            "left join da_bmda e on a.bmbh2=e.bmbh " +
                             "left join da_sp_ysda g on a.yslsh=g.yslsh " +
                            "left join  (select * from da_qj_csb where  csfl='CG_DDFS') f on a.cgfs=f.csbh  where djlx='1'" +
                             " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DB') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                            self.GetSqlWhere() + " group by " + dynamicShowString + "a.spkh,b.ksmc,b.jldw,a.ysbh,g.ysmc" + dynamicShowString1 + dynamicShowStringEnd;
        }
        else if (ywflag == "DZ") {
            finishSql = "select  " + dynamicShowStr + "a.spkh,a.ksmc,a.jldw,a.ysbh,a.ysmc," + dynamicShowStr1 +
                        "SUM(ISNULL(cm1,0)+ISNULL(cm2,0)+ISNULL(cm3,0)+ISNULL(cm4,0)+ISNULL(cm5,0)+ISNULL(cm6,0)+ISNULL(cm7,0)+ISNULL(cm8,0)+ISNULL(cm9,0)+ISNULL(cm10,0)+ISNULL(cm11,0)+ISNULL(cm12,0)+ISNULL(cm13,0)+ISNULL(cm14,0)+ISNULL(cm15,0)+ISNULL(cm16,0)+ISNULL(cm17,0)+ISNULL(cm18,0)+ISNULL(cm19,0)+ISNULL(cm20,0)+ISNULL(cm21,0)+ISNULL(cm22,0)+ISNULL(cm23,0)+ISNULL(cm24,0)+ISNULL(cm25,0)+ISNULL(cm26,0)+ISNULL(cm27,0)+ISNULL(cm28,0)++ISNULL(cm29,0)+ISNULL(cm30,0)+ISNULL(cm31,0)+ISNULL(cm32,0)+ISNULL(cm33,0)+ISNULL(cm34,0)+ISNULL(cm35,0)) as zjsl," +
                        "max(ISNULL(a.lsj,0)) as lsj," +
                        "SUM(ISNULL(cm1,0)+ISNULL(cm2,0)+ISNULL(cm3,0)+ISNULL(cm4,0)+ISNULL(cm5,0)+ISNULL(cm6,0)+ISNULL(cm7,0)+ISNULL(cm8,0)+ISNULL(cm9,0)+ISNULL(cm10,0)+ISNULL(cm11,0)+ISNULL(cm12,0)+ISNULL(cm13,0)+ISNULL(cm14,0)+ISNULL(cm15,0)+ISNULL(cm16,0)+ISNULL(cm17,0)+ISNULL(cm18,0)+ISNULL(cm19,0)+ISNULL(cm20,0)+ISNULL(cm21,0)+ISNULL(cm22,0)+ISNULL(cm23,0)+ISNULL(cm24,0)+ISNULL(cm25,0)+ISNULL(cm26,0)+ISNULL(cm27,0)+ISNULL(cm28,0)++ISNULL(cm29,0)+ISNULL(cm30,0)+ISNULL(cm31,0)+ISNULL(cm32,0)+ISNULL(cm33,0)+ISNULL(cm34,0)+ISNULL(cm35,0))*max(ISNULL(a.lsj,0)) as lsjze," +
                        "max(ISNULL(a.jj,0)) as jj," +
                         "SUM(ISNULL(cm1,0)+ISNULL(cm2,0)+ISNULL(cm3,0)+ISNULL(cm4,0)+ISNULL(cm5,0)+ISNULL(cm6,0)+ISNULL(cm7,0)+ISNULL(cm8,0)+ISNULL(cm9,0)+ISNULL(cm10,0)+ISNULL(cm11,0)+ISNULL(cm12,0)+ISNULL(cm13,0)+ISNULL(cm14,0)+ISNULL(cm15,0)+ISNULL(cm16,0)+ISNULL(cm17,0)+ISNULL(cm18,0)+ISNULL(cm19,0)+ISNULL(cm20,0)+ISNULL(cm21,0)+ISNULL(cm22,0)+ISNULL(cm23,0)+ISNULL(cm24,0)+ISNULL(cm25,0)+ISNULL(cm26,0)+ISNULL(cm27,0)+ISNULL(cm28,0)++ISNULL(cm29,0)+ISNULL(cm30,0)+ISNULL(cm31,0)+ISNULL(cm32,0)+ISNULL(cm33,0)+ISNULL(cm34,0)+ISNULL(cm35,0))*max(ISNULL(a.jj,0)) as jjze  " + dynamicShowStrEnd +
                         " from yw_db_tzdmx a left join yw_db_tzdhz h on a.pzh=h.pzh " +
                        " left join  da_sp_spda b on a.spkh=b.spkh " +
                        " left join da_sp_lbda c on c.lbbh=b.hplb  " +
                          "left join da_bmda d on d.bmbh=h.bmbh1  " +
                        "left join da_bmda e on h.bmbh2=e.bmbh " +
                         "left join  (select * from da_qj_csb where  csfl='DBFS') f on h.cgfs=f.csbh  where djlx='1'" +
                                " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DZ') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                          self.GetSqlWhere() + " group by " + dynamicShowString + "a.spkh,a.ksmc,a.jldw,a.ysbh,a.ysmc" + dynamicShowString1 + dynamicShowStringEnd;
        }
        else if (ywflag == "DC") {
            finishSql = "select " + dynamicShowStr + "a.spkh,b.ksmc,b.jldw,a.ysbh,g.ysmc," + dynamicShowStr1 +
                        "SUM(a.sl) zjsl,SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) lsj, SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0)) as lsjze, " +
                        "SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) jj, SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0)) as jjze,SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) dpj, SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0)) as dpjze  " + dynamicShowStrEnd +
                        " from (SELECT * FROM   dbo.yw_db_dbrkdtz UNION ALL SELECT * FROM  yw_db_dbrkdtz_ls) a left join  da_sp_spda b on a.spkh=b.spkh " +
                        " left join da_sp_lbda c on c.lbbh=b.hplb  " +
                        "left join da_bmda d on d.bmbh=a.khbh  " +
                        "left join da_bmda e on a.bmbh2=e.bmbh " +
                         "left join da_sp_ysda g on a.yslsh=g.yslsh " +
                        "left join  (select * from da_qj_csb where  csfl='DBFS') f on a.cgfs=f.csbh  where djlx='1'" +
                         " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DC') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                           self.GetSqlWhere() + " group by " + dynamicShowString + "a.spkh,b.ksmc,b.jldw,a.ysbh,g.ysmc" + dynamicShowString1 + dynamicShowStringEnd;
        }
        else if (ywflag == "DR") {
            finishSql = "select  " + dynamicShowStr + "a.spkh,b.ksmc,b.jldw,a.ysbh,g.ysmc," + dynamicShowStr1 +
                        "SUM(a.sl) zjsl,SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) lsj, SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0)) as lsjze," +
                        "SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) jj, SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0)) as jjze,SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) dpj, SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0)) as dpjze  " + dynamicShowStrEnd +
                        " from (SELECT * FROM   dbo.yw_db_dbrkdtz UNION ALL SELECT * FROM  yw_db_dbrkdtz_ls) a left join  da_sp_spda b on a.spkh=b.spkh " +
                        " left join da_sp_lbda c on c.lbbh=b.hplb  " +
                        "left join da_bmda d on d.bmbh=a.khbh  " +
                        "left join da_bmda e on a.bmbh2=e.bmbh " +
                         "left join da_sp_ysda g on a.yslsh=g.yslsh " +
                        "left join  (select * from da_qj_csb where  csfl='DBFS') f on a.cgfs=f.csbh  where djlx='2'" +
                         " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DR') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                        self.GetSqlWhere() + " group by " + dynamicShowString + "a.spkh,b.ksmc,b.jldw,a.ysbh,g.ysmc" + dynamicShowString1 + dynamicShowStringEnd;
        }
        //#endregion

        if (rb_drbm.GetChecked()) {
            //#region 调入部门
            if (ywflag == "DB") {
                curSql = "select a.spkh,b.ksmc,a.ysbh,g.ysmc,b.jldw,d.bmmc,SUM(a.sl) zjsl,SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) lsj, SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0)) as lsjze," +
                        "SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) jj, SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0)) as jjze,SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) dpj, SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0)) as dpjze  " +
                        " from (SELECT * FROM  dbo.yw_db_dbddtz UNION ALL SELECT * FROM  dbo.yw_db_dbddtz_LS) a left join  da_sp_spda b on a.spkh=b.spkh " +
                            " left join da_sp_lbda c on c.lbbh=b.hplb  " +
                            "left join da_bmda d on d.bmbh=a.khbh  " +
                            "left join da_sp_ysda g on a.yslsh=g.yslsh " +
                            "left join  (select * from da_qj_csb where  csfl='CG_DDFS') f on a.cgfs=f.csbh  where djlx='1'" +
                             " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DB') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                            self.GetSqlWhere() + " group by a.spkh,b.ksmc,b.jldw,d.bmmc,a.khbh,a.ysbh,g.ysmc";
            }
            else if (ywflag == "DZ") {
                curSql = "select a.spkh,a.ksmc,a.ysbh,a.ysmc,a.jldw,d.bmmc," +
                      "SUM(ISNULL(cm1,0)+ISNULL(cm2,0)+ISNULL(cm3,0)+ISNULL(cm4,0)+ISNULL(cm5,0)+ISNULL(cm6,0)+ISNULL(cm7,0)+ISNULL(cm8,0)+ISNULL(cm9,0)+ISNULL(cm10,0)+ISNULL(cm11,0)+ISNULL(cm12,0)+ISNULL(cm13,0)+ISNULL(cm14,0)+ISNULL(cm15,0)+ISNULL(cm16,0)+ISNULL(cm17,0)+ISNULL(cm18,0)+ISNULL(cm19,0)+ISNULL(cm20,0)+ISNULL(cm21,0)+ISNULL(cm22,0)+ISNULL(cm23,0)+ISNULL(cm24,0)+ISNULL(cm25,0)+ISNULL(cm26,0)+ISNULL(cm27,0)+ISNULL(cm28,0)++ISNULL(cm29,0)+ISNULL(cm30,0)+ISNULL(cm31,0)+ISNULL(cm32,0)+ISNULL(cm33,0)+ISNULL(cm34,0)+ISNULL(cm35,0)) as zjsl," +
                       "max(ISNULL(a.lsj,0)) as lsj," +
                       "SUM(ISNULL(cm1,0)+ISNULL(cm2,0)+ISNULL(cm3,0)+ISNULL(cm4,0)+ISNULL(cm5,0)+ISNULL(cm6,0)+ISNULL(cm7,0)+ISNULL(cm8,0)+ISNULL(cm9,0)+ISNULL(cm10,0)+ISNULL(cm11,0)+ISNULL(cm12,0)+ISNULL(cm13,0)+ISNULL(cm14,0)+ISNULL(cm15,0)+ISNULL(cm16,0)+ISNULL(cm17,0)+ISNULL(cm18,0)+ISNULL(cm19,0)+ISNULL(cm20,0)+ISNULL(cm21,0)+ISNULL(cm22,0)+ISNULL(cm23,0)+ISNULL(cm24,0)+ISNULL(cm25,0)+ISNULL(cm26,0)+ISNULL(cm27,0)+ISNULL(cm28,0)++ISNULL(cm29,0)+ISNULL(cm30,0)+ISNULL(cm31,0)+ISNULL(cm32,0)+ISNULL(cm33,0)+ISNULL(cm34,0)+ISNULL(cm35,0))*max(ISNULL(a.lsj,0)) as lsjze," +
                       "max(ISNULL(a.dpj,0)) as dpj," +
                       "SUM(ISNULL(cm1,0)+ISNULL(cm2,0)+ISNULL(cm3,0)+ISNULL(cm4,0)+ISNULL(cm5,0)+ISNULL(cm6,0)+ISNULL(cm7,0)+ISNULL(cm8,0)+ISNULL(cm9,0)+ISNULL(cm10,0)+ISNULL(cm11,0)+ISNULL(cm12,0)+ISNULL(cm13,0)+ISNULL(cm14,0)+ISNULL(cm15,0)+ISNULL(cm16,0)+ISNULL(cm17,0)+ISNULL(cm18,0)+ISNULL(cm19,0)+ISNULL(cm20,0)+ISNULL(cm21,0)+ISNULL(cm22,0)+ISNULL(cm23,0)+ISNULL(cm24,0)+ISNULL(cm25,0)+ISNULL(cm26,0)+ISNULL(cm27,0)+ISNULL(cm28,0)++ISNULL(cm29,0)+ISNULL(cm30,0)+ISNULL(cm31,0)+ISNULL(cm32,0)+ISNULL(cm33,0)+ISNULL(cm34,0)+ISNULL(cm35,0))*max(ISNULL(a.dpj,0)) as dpjze  " +
                       " from yw_db_tzdmx a left join yw_db_tzdhz h on a.pzh=h.pzh " +
                     " left join  da_sp_spda b on a.spkh=b.spkh " +
                      "left join  da_sp_lbda c on c.lbbh=b.hplb " +
                        "left join  da_bmda d  on h.bmbh1= d.bmbh  " +
                        "left join  (select * from da_qj_csb where  csfl='DBFS') f on h.cgfs=f.csbh  where djlx='1'" +
                         " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DZ') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                             self.GetSqlWhere() + " group by a.spkh,a.ksmc,a.ysbh,a.ysmc,a.jldw,d.bmmc,h.bmbh1";
            }
            else if (ywflag == "DC") {
                curSql = "select a.spkh,b.ksmc,a.ysbh,g.ysmc,b.jldw,d.bmmc,SUM(a.sl) zjsl,SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) lsj, SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0)) as lsjze, " +
                    "SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) jj, SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0)) as jjze,SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) dpj, SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0)) as dpjze  " +
                    " from (SELECT * FROM   dbo.yw_db_dbrkdtz UNION ALL SELECT * FROM  yw_db_dbrkdtz_ls) a left join  da_sp_spda b on a.spkh=b.spkh " +
                        " left join da_sp_lbda c on c.lbbh=b.hplb  " +
                        "left join da_bmda d on d.bmbh=a.khbh  " +
                        "left join da_sp_ysda g on a.yslsh=g.yslsh " +
                        "left join  (select * from da_qj_csb where  csfl='DBFS') f on a.cgfs=f.csbh  where djlx='1'" +
                         " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DC') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                            self.GetSqlWhere() + " group by a.spkh,b.ksmc,a.ysbh,g.ysmc,b.jldw,d.bmmc,a.khbh";
            }
            else if (ywflag == "DR") {
                curSql = "select a.spkh,b.ksmc,a.ysbh,g.ysmc,b.jldw,d.bmmc,SUM(a.sl) zjsl,SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) lsj, SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0)) as lsjze," +
                    "SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) jj, SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0)) as jjze,SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) dpj, SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0)) as dpjze  " +
                    " from (SELECT * FROM   dbo.yw_db_dbrkdtz UNION ALL SELECT * FROM  yw_db_dbrkdtz_ls) a left join  da_sp_spda b on a.spkh=b.spkh " +
                        " left join da_sp_lbda c on c.lbbh=b.hplb  " +
                        "left join da_bmda d on d.bmbh=a.khbh  " +
                        "left join da_sp_ysda g on a.yslsh=g.yslsh " +
                        "left join  (select * from da_qj_csb where  csfl='DBFS') f on a.cgfs=f.csbh  where djlx='2'" +
                         " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DR') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                            self.GetSqlWhere() + " group by a.spkh,b.ksmc,a.ysbh,g.ysmc,b.jldw,d.bmmc,a.khbh";
            }
            //#endregion 
            curRows = "spkh#款号,ksmc#款名,ysbh#颜色编号,ysmc#颜色名称,jldw#单位";
            curCols = "bmmc";
            curValues = "zjsl#数量";
            curColTypes = "spkh#char(50),ksmc#char(200),jldw#char(10),ysbh#char(20),ysmc#char(50),zjsl#decimal(18)";

            if (ExistDBJ == "Y") {
                curValues += ",lsjze#调拨金额"
                curColTypes += ",lsjze#decimal(2)"
            }

            if (ExistDPJ == "Y") {
                curValues += ",dpjze#吊牌金额"
                curColTypes += ",dpjze#decimal(2)"
            }

            if (ExistLSJ == "Y") {
                curValues += ",jjze#零售金额"
                curColTypes += ",jjze#decimal(2)"
            }
            sy = GetCrosstabDateWindowSyntax(curRows, curCols, curValues, curColTypes, curSql)
            dw_temp.Create(sy);
            dw_temp.Refresh();
            dw_list.SetFullState(dw_temp.GetFullState());
        }
        //#region 调出部门
        if (rb_dcbm.GetChecked()) {
          
            if (ywflag == "DB") {
                curSql = "select a.spkh,b.ksmc,a.ysbh,g.ysmc,b.jldw,e.bmmc,SUM(a.sl) zjsl,SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) lsj, SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0)) as lsjze," +
                        "SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) jj, SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0)) as jjze,SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) dpj, SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0)) as dpjze  " +
                        " from (SELECT * FROM  dbo.yw_db_dbddtz UNION ALL SELECT * FROM  dbo.yw_db_dbddtz_LS) a left join  da_sp_spda b on a.spkh=b.spkh " +
                            " left join da_sp_lbda c on c.lbbh=b.hplb  " +
                            "left join da_bmda e on a.bmbh2=e.bmbh " +
                             "left join da_sp_ysda g on a.yslsh=g.yslsh " +
                            " where djlx='1'" +
                             " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DB') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                            self.GetSqlWhere() + " group by a.spkh,b.ksmc,b.jldw,e.bmmc,a.bmbh2,a.ysbh,g.ysmc";
            }
            else if (ywflag == "DZ") {
                curSql = "select a.spkh,a.ksmc,a.ysbh,a.ysmc,a.jldw,e.bmmc," +
                      "SUM(ISNULL(cm1,0)+ISNULL(cm2,0)+ISNULL(cm3,0)+ISNULL(cm4,0)+ISNULL(cm5,0)+ISNULL(cm6,0)+ISNULL(cm7,0)+ISNULL(cm8,0)+ISNULL(cm9,0)+ISNULL(cm10,0)+ISNULL(cm11,0)+ISNULL(cm12,0)+ISNULL(cm13,0)+ISNULL(cm14,0)+ISNULL(cm15,0)+ISNULL(cm16,0)+ISNULL(cm17,0)+ISNULL(cm18,0)+ISNULL(cm19,0)+ISNULL(cm20,0)+ISNULL(cm21,0)+ISNULL(cm22,0)+ISNULL(cm23,0)+ISNULL(cm24,0)+ISNULL(cm25,0)+ISNULL(cm26,0)+ISNULL(cm27,0)+ISNULL(cm28,0)++ISNULL(cm29,0)+ISNULL(cm30,0)+ISNULL(cm31,0)+ISNULL(cm32,0)+ISNULL(cm33,0)+ISNULL(cm34,0)+ISNULL(cm35,0)) as zjsl," +
                       "max(ISNULL(a.lsj,0)) as lsj," +

                       " SUM(ISNULL(cm1,0)+ISNULL(cm2,0)+ISNULL(cm3,0)+ISNULL(cm4,0)+ISNULL(cm5,0)+ISNULL(cm6,0)+ISNULL(cm7,0)+ISNULL(cm8,0)+ISNULL(cm9,0)+ISNULL(cm10,0)+ISNULL(cm11,0)+ISNULL(cm12,0)+ISNULL(cm13,0)+ISNULL(cm14,0)+ISNULL(cm15,0)+ISNULL(cm16,0)+ISNULL(cm17,0)+ISNULL(cm18,0)+ISNULL(cm19,0)+ISNULL(cm20,0)+ISNULL(cm21,0)+ISNULL(cm22,0)+ISNULL(cm23,0)+ISNULL(cm24,0)+ISNULL(cm25,0)+ISNULL(cm26,0)+ISNULL(cm27,0)+ISNULL(cm28,0)++ISNULL(cm29,0)+ISNULL(cm30,0)+ISNULL(cm31,0)+ISNULL(cm32,0)+ISNULL(cm33,0)+ISNULL(cm34,0)+ISNULL(cm35,0))*max(ISNULL(a.lsj,0)) as lsjze," +
                       "max(ISNULL(a.jj,0)) as jj," +
                       "SUM(ISNULL(cm1,0)+ISNULL(cm2,0)+ISNULL(cm3,0)+ISNULL(cm4,0)+ISNULL(cm5,0)+ISNULL(cm6,0)+ISNULL(cm7,0)+ISNULL(cm8,0)+ISNULL(cm9,0)+ISNULL(cm10,0)+ISNULL(cm11,0)+ISNULL(cm12,0)+ISNULL(cm13,0)+ISNULL(cm14,0)+ISNULL(cm15,0)+ISNULL(cm16,0)+ISNULL(cm17,0)+ISNULL(cm18,0)+ISNULL(cm19,0)+ISNULL(cm20,0)+ISNULL(cm21,0)+ISNULL(cm22,0)+ISNULL(cm23,0)+ISNULL(cm24,0)+ISNULL(cm25,0)+ISNULL(cm26,0)+ISNULL(cm27,0)+ISNULL(cm28,0)++ISNULL(cm29,0)+ISNULL(cm30,0)+ISNULL(cm31,0)+ISNULL(cm32,0)+ISNULL(cm33,0)+ISNULL(cm34,0)+ISNULL(cm35,0))*max(ISNULL(a.jj,0)) as jjze  " +
                       " from yw_db_tzdmx a left join yw_db_tzdhz h on a.pzh=h.pzh " +
                     " left join  da_sp_spda b on a.spkh=b.spkh " +
                      "left join  da_sp_lbda c on c.lbbh=b.hplb " +
                        "left join  da_bmda e  on h.bmbh2= e.bmbh  " +
                        "left join  (select * from da_qj_csb where  csfl='DBFS') f on h.cgfs=f.csbh  where djlx='1'" +
                          " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DZ') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                            self.GetSqlWhere() + " group by a.spkh,a.ksmc,a.ysbh,a.ysmc,a.jldw,h.bmbh2,e.bmmc";
            }
            else if (ywflag == "DC") {
                curSql = "select a.spkh,b.ksmc,a.ysbh,g.ysmc,b.jldw,e.bmmc,SUM(a.sl) zjsl,SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) lsj, SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0)) as lsjze," +
                    "SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) jj, SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0)) as jjze,SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) dpj, SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0)) as dpjze  " +
                    " from (SELECT * FROM   dbo.yw_db_dbrkdtz UNION ALL SELECT * FROM  yw_db_dbrkdtz_ls) a left join  da_sp_spda b on a.spkh=b.spkh " +
                        " left join da_sp_lbda c on c.lbbh=b.hplb  " +
                        "left join da_bmda e on e.bmbh=a.bmbh2  " +
                         "left join da_sp_ysda g on a.yslsh=g.yslsh " +
                        "left join  (select * from da_qj_csb where  csfl='DBFS') f on a.cgfs=f.csbh  where djlx='1'" +
                         " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DC') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                            self.GetSqlWhere() + " group by a.spkh,b.ksmc,b.jldw,e.bmmc,a.bmbh2,a.ysbh,g.ysmc";
            }
            else if (ywflag == "DR") {
                curSql = "select a.spkh,b.ksmc,a.ysbh,g.ysmc,b.jldw,e.bmmc,SUM(a.sl) zjsl,SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) lsj, SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0)) as lsjze, " +
                    "SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) jj, SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0)) as jjze,SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) dpj, SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0)) as dpjze  " +
                    " from (SELECT * FROM   dbo.yw_db_dbrkdtz UNION ALL SELECT * FROM  yw_db_dbrkdtz_ls) a left join  da_sp_spda b on a.spkh=b.spkh " +
                        " left join da_sp_lbda c on c.lbbh=b.hplb  " +
                        "left join da_bmda e on e.bmbh=a.bmbh2  " +
                         "left join da_sp_ysda g on a.yslsh=g.yslsh " +
                        "left join  (select * from da_qj_csb where  csfl='DBFS') f on a.cgfs=f.csbh  where djlx='2'" +
                         " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DR') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                            self.GetSqlWhere() + " group by a.spkh,b.ksmc,b.jldw,e.bmmc,a.bmbh2,a.ysbh,g.ysmc";
            }
            curRows = "spkh#款号,ksmc#款名,ysbh#颜色编号,ysmc#颜色名称,jldw#单位";
            curCols = "bmmc";
            curValues = "zjsl#数量";
            curColTypes = "spkh#char(50),ksmc#char(200),jldw#char(10),ysbh#char(20),ysmc#char(50),zjsl#decimal(18)";
            if (ExistDBJ == "Y") {
                curValues += ",lsjze#调拨金额"
                curColTypes += ",lsjze#decimal(2)"
            }

            if (ExistDPJ == "Y") {
                curValues += ",dpjze#吊牌金额"
                curColTypes += ",dpjze#decimal(2)"
            }

            if (ExistLSJ == "Y") {
                curValues += ",jjze#零售金额"
                curColTypes += ",jjze#decimal(2)"
            }
            sy = GetCrosstabDateWindowSyntax(curRows, curCols, curValues, curColTypes, curSql)
            dw_temp.Create(sy);
            dw_temp.Refresh();
            dw_list.SetFullState(dw_temp.GetFullState());
        }
        //#endregion
        //#region 日期
        else if (rb_rq.GetChecked()) {
            if (ywflag == "DB") {
                curSql = "select a.spkh,b.ksmc,a.ysbh,g.ysmc,b.jldw,CONVERT(date,a.kdrq) as kdrq,SUM(a.sl) zjsl,SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) lsj, SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0)) as lsjze," +
                        "SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) jj, SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0)) as jjze,SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) dpj, SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0)) as dpjze  " +
                      " from (SELECT * FROM  dbo.yw_db_dbddtz UNION ALL SELECT * FROM  dbo.yw_db_dbddtz_LS) a left join  da_sp_spda b on a.spkh=b.spkh " +
                       " left join da_sp_lbda c on c.lbbh=b.hplb  " +
                        "left join da_sp_ysda g on a.yslsh=g.yslsh " +
                       " where djlx='1'" +
                         " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DB') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                            self.GetSqlWhere() + " group by a.spkh,b.ksmc,b.jldw,CONVERT(date,a.kdrq),a.ysbh,g.ysmc";
            }
            else if (ywflag == "DZ") {
                curSql = "select a.spkh,a.ksmc,a.ysbh,a.ysmc,a.jldw,CONVERT(date,h.kdrq) as kdrq," +
                       "SUM(ISNULL(cm1,0)+ISNULL(cm2,0)+ISNULL(cm3,0)+ISNULL(cm4,0)+ISNULL(cm5,0)+ISNULL(cm6,0)+ISNULL(cm7,0)+ISNULL(cm8,0)+ISNULL(cm9,0)+ISNULL(cm10,0)+ISNULL(cm11,0)+ISNULL(cm12,0)+ISNULL(cm13,0)+ISNULL(cm14,0)+ISNULL(cm15,0)+ISNULL(cm16,0)+ISNULL(cm17,0)+ISNULL(cm18,0)+ISNULL(cm19,0)+ISNULL(cm20,0)+ISNULL(cm21,0)+ISNULL(cm22,0)+ISNULL(cm23,0)+ISNULL(cm24,0)+ISNULL(cm25,0)+ISNULL(cm26,0)+ISNULL(cm27,0)+ISNULL(cm28,0)++ISNULL(cm29,0)+ISNULL(cm30,0)+ISNULL(cm31,0)+ISNULL(cm32,0)+ISNULL(cm33,0)+ISNULL(cm34,0)+ISNULL(cm35,0)) as zjsl," +
                       "max(ISNULL(a.lsj,0)) as lsj," +

                       " SUM(ISNULL(cm1,0)+ISNULL(cm2,0)+ISNULL(cm3,0)+ISNULL(cm4,0)+ISNULL(cm5,0)+ISNULL(cm6,0)+ISNULL(cm7,0)+ISNULL(cm8,0)+ISNULL(cm9,0)+ISNULL(cm10,0)+ISNULL(cm11,0)+ISNULL(cm12,0)+ISNULL(cm13,0)+ISNULL(cm14,0)+ISNULL(cm15,0)+ISNULL(cm16,0)+ISNULL(cm17,0)+ISNULL(cm18,0)+ISNULL(cm19,0)+ISNULL(cm20,0)+ISNULL(cm21,0)+ISNULL(cm22,0)+ISNULL(cm23,0)+ISNULL(cm24,0)+ISNULL(cm25,0)+ISNULL(cm26,0)+ISNULL(cm27,0)+ISNULL(cm28,0)++ISNULL(cm29,0)+ISNULL(cm30,0)+ISNULL(cm31,0)+ISNULL(cm32,0)+ISNULL(cm33,0)+ISNULL(cm34,0)+ISNULL(cm35,0))*max(ISNULL(a.lsj,0)) as lsjze," +
                        "max(ISNULL(a.jj,0)) as jj," +
                       "SUM(ISNULL(cm1,0)+ISNULL(cm2,0)+ISNULL(cm3,0)+ISNULL(cm4,0)+ISNULL(cm5,0)+ISNULL(cm6,0)+ISNULL(cm7,0)+ISNULL(cm8,0)+ISNULL(cm9,0)+ISNULL(cm10,0)+ISNULL(cm11,0)+ISNULL(cm12,0)+ISNULL(cm13,0)+ISNULL(cm14,0)+ISNULL(cm15,0)+ISNULL(cm16,0)+ISNULL(cm17,0)+ISNULL(cm18,0)+ISNULL(cm19,0)+ISNULL(cm20,0)+ISNULL(cm21,0)+ISNULL(cm22,0)+ISNULL(cm23,0)+ISNULL(cm24,0)+ISNULL(cm25,0)+ISNULL(cm26,0)+ISNULL(cm27,0)+ISNULL(cm28,0)++ISNULL(cm29,0)+ISNULL(cm30,0)+ISNULL(cm31,0)+ISNULL(cm32,0)+ISNULL(cm33,0)+ISNULL(cm34,0)+ISNULL(cm35,0))*max(ISNULL(a.jj,0)) as jjze  " +
                       " from yw_db_tzdmx a left join yw_db_tzdhz h on a.pzh=h.pzh " +
                     " left join  da_sp_spda b on a.spkh=b.spkh " +
                        "left join  da_sp_lbda d on d.lbbh=b.hplb " +
                        "left join  (select * from da_qj_csb where  csfl='DBFS') f on h.cgfs=f.csbh  where djlx='1'" +
                                          " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DZ') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                            self.GetSqlWhere() + " group by a.spkh,a.ksmc,a.ysbh,a.ysmc,a.jldw,CONVERT(date,h.kdrq)";
            }
            else if (ywflag == "DC") {
                curSql = "select a.spkh,b.ksmc,a.ysbh,g.ysmc,b.jldw,CONVERT(date,a.kdrq) as kdrq,SUM(a.sl) zjsl,SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) lsj, SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0)) as lsjze," +
                    "SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) jj, SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0)) as jjze,SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) dpj, SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0)) as dpjze  " +
                  " from (SELECT * FROM   dbo.yw_db_dbrkdtz UNION ALL SELECT * FROM  yw_db_dbrkdtz_ls) a left join  da_sp_spda b on a.spkh=b.spkh " +
                   " left join da_sp_lbda c on c.lbbh=b.hplb  " +
                    "left join da_sp_ysda g on a.yslsh=g.yslsh " +
                   " where djlx='1'" +
                     " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DC') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                            self.GetSqlWhere() + " group by a.spkh,b.ksmc,b.jldw,CONVERT(date,a.kdrq),a.ysbh,g.ysmc";

            }
            else if (ywflag == "DR") {
                curSql = "select a.spkh,b.ksmc,a.ysbh,g.ysmc,b.jldw,CONVERT(date,a.kdrq) as kdrq,SUM(a.sl) zjsl,SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) lsj, SUM(ISNULL(a.sl,0)*ISNULL(a.lsj,0)) as lsjze," +
                    "SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) jj, SUM(ISNULL(a.sl,0)*ISNULL(a.jj,0)) as jjze,SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0))/(CASE WHEN SUM(a.sl)=0 THEN 1 ELSE SUM(a.sl) END) dpj, SUM(ISNULL(a.sl,0)*ISNULL(a.dpj,0)) as dpjze  " +
                  " from (SELECT * FROM   dbo.yw_db_dbrkdtz UNION ALL SELECT * FROM  yw_db_dbrkdtz_ls) a left join  da_sp_spda b on a.spkh=b.spkh " +
                   " left join da_sp_lbda c on c.lbbh=b.hplb  " +
                   "left join da_sp_ysda g on a.yslsh=g.yslsh " +
                   " where djlx='2'" +
                     " AND  CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','DR') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE() " +
                      self.GetSqlWhere() + " group by a.spkh,b.ksmc,b.jldw,CONVERT(date,a.kdrq),a.ysbh,g.ysmc";
            }
            curRows = "spkh#款号,ksmc#款名,ysbh#颜色编号,ysmc#颜色名称,jldw#单位";
            curCols = "kdrq";
            curValues = "zjsl#数量";
            curColTypes = "spkh#char(50),ksmc#char(200),jldw#char(10),ysbh#char(20),ysmc#char(50),zjsl#decimal(18)";
            if (ExistDBJ == "Y") {
                curValues += ",lsjze#调拨金额"
                curColTypes += ",lsjze#decimal(2)"
            }

            if (ExistDPJ == "Y") {
                curValues += ",dpjze#吊牌金额"
                curColTypes += ",dpjze#decimal(2)"
            }

            if (ExistLSJ == "Y") {
                curValues += ",jjze#零售金额"
                curColTypes += ",jjze#decimal(2)"
            }
            sy = GetCrosstabDateWindowSyntax(curRows, curCols, curValues, curColTypes, curSql)
            mle_1.SetText(sy);
            dw_temp.Create(sy);
            dw_temp.Refresh();
            dw_list.SetFullState(dw_temp.GetFullState());

        }
        //#endregion
        else if (rb_sp.GetChecked()) {
            mle_1.SetText(finishSql);
            curBbmc = rb_sp.GetName();
            finishSql = finishSql.replace(/\%/g, "%25");
            finishSql = finishSql.replace(/\+/g, "%2B");
            finishSql = finishSql.replace(/\&/g, "%26");
            self.DrawDataWindow(finishSql);
            //#region 格式保存#处理format
            //排序
            DWSort(dw_format, dw_list);
            //#endregion
            self.SetValue(C_CheckValue, curBbmc, curCdbh, curYhbh);
        }
        //控制价格


        if (ExistDPJ == "N") {
            self.ControlPrice(jgtxlist, "dpj");
        }

        if (ExistDBJ == "N") {
            self.ControlPrice(jgtxlist, "dbj");
        }
        if (ExistLSJ == "N") {
            self.ControlPrice(jgtxlist, "lsj");
        }
        dw_list.Modify("zjsl.format='0' jjze.format='0.00' lsjze.format='0.00'");
        dw_list.Modify("sum_zjsl.format='0' sum_jjze.format='0.00' sum_lsjze.format='0.00'");
        dw_list.Modify("grand_sum_zjsl.format='0' grand_sum_jjze.format='0.00' grand_sum_lsjze.format='0.00'");
        dw_list.Modify("sum_grand_sum_zjsl.format='0' sum_grand_sum_jjze.format='0.00' sum_grand_sum_lsjze.format='0.00'");
    }
    //#endregion

    this.ControlPrice = function (str1, str2) {
        //alert([str1, str2])
        var s = str1.indexOf(str2);

        if (s > -1) {
            
        }
        else {
            if (str2 == "lsj") {

                dw_list.Modify("jj.visible='0'");
                dw_list.Modify("jjze.visible='0'");

            }
            else if (str2 == "dpj") {
                dw_list.Modify("dpj.visible='0'");
                dw_list.Modify("dpjze.visible='0'");
            }
            else if (str2 == "dbj") {
                dw_list.Modify("lsj.visible='0'");
                dw_list.Modify("lsjze.visible='0'");
            }

        }
    }

    //#region Function 呼出数据窗口的函数群 
    //调入部门
    this.Changebmbh1 = function (x, y, row, dwoName) {
      
        dwoName == "bmbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_JQYS_DB, "bmbh", "bmmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base." + curW_OPEN_BMDA_URL + "&treeDw=dw_da_bmda_fl_tree&listDw=dw_pub_list_bmda&treeRootLabel=部门分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&selectStyle=multiple&curQxlx=dbcx"), curW_OPEN_BMDA_NEW, null);
    }
    //调出部门
    this.Changebmbh2 = function (x, y, row, dwoName) {
        dwoName == "bmbh2";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_JQYS_DB, "bmbh2", "bmmc2", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base." + curW_OPEN_BMDA_URL + "&treeDw=dw_da_bmda_fl_tree&listDw=dw_pub_list_bmda_dhbm&treeRootLabel=部门分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&selectStyle=multiple&curQxlx=dbcx"), curW_OPEN_BMDA_NEW, null);
    }
    this.Changepinpai = function (x, y, row, dwoName) {
        dwoName == "ppbm";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_JQYS_DB, "ppbm", "ppmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_sp_sppp_by_yhbh&selectStyle=multiple&flag=ywcx"), curW_OPEN_SIMPLE_CHOSE, null);
    }

    this.Changegys = function (x, y, row, dwoName) {
        dwoName == "gysbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_JQYS_DB, "gysbh", "gysmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base." + curW_OPEN_BMDA_URL + "&treeDw=dw_da_gysda_fl_tree&listDw=dw_pub_list_gysda&treeRootLabel=供应商分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&selectStyle=multiple"), curW_OPEN_BMDA_NEW, null);
    }

    this.Changekh = function (x, y, row, dwoName) {
        dwoName == "spkh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_JQYS_DB, "spkh", "ksmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base." + curW_OPEN_BMDA_URL + "&treeDw=dw_da_sp_lbda_tree&listDw=dw_da_sp_spda_1&treeRootLabel=商品分类&treeData=lbbh&treeLabel=lbmc&treeParentData=flbbh&treeLeave=islast&selectStyle=multiple&curQxlx=all"), curW_OPEN_BMDA_NEW, null);
    }

    this.Changelb = function (x, y, row, dwoName) {
        dwoName == "lbbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_JQYS_DB, "lbbh", "lbmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base." + curW_OPEN_BMDA_URL + "&treeDw=dw_da_sp_lbda_tree&listDw=dw_da_sp_lbda_list&treeRootLabel=商品分类&treeData=lbbh&treeLabel=lbmc&treeParentData=flbbh&treeLeave=islast&selectStyle=multiple"), curW_OPEN_BMDA_NEW, null);
    }

    this.Changejj = function (x, y, row, dwoName) {
        dwoName == "jjbm";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_JQYS_DB, "jjbm", "jjmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_da_sp_jjda_list&selectStyle=multiple"), curW_OPEN_SIMPLE_CHOSE, null);
    }


    this.Changeml = function (x, y, row, dwoName) {
        dwoName == "mlbh";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_JQYS_DB, "mlbh", "mlmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_da_sp_mlda_list&selectStyle=multiple"), curW_OPEN_SIMPLE_CHOSE, null);
    }

    this.Changetzfs = function (x, y, row, dwoName) {



        if (ywflag == "DB") {
            dwoName == "csbh";
            curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_JQYS_DB, "csbh", "csmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
            requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_pub_list_qj_csb_ddfs&selectStyle=multiple&flag=csbhdb"), curW_OPEN_SIMPLE_CHOSE, null);
        }
        else {
            dwoName == "dbfs";
            curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_JQYS_DB, "dbfs", "dbmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
            requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_pub_list_qj_csb_dbfs&selectStyle=multiple&flag=csbhdb"), curW_OPEN_SIMPLE_CHOSE, null);

        }
//        dwoName == "fsbh";
//        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_JQYS_DB, "fsbh", "fsmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
//        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_ls_cgfs&selectStyle=multiple"), curW_OPEN_SIMPLE_CHOSE, null);
    }
    //#endregion

    //#region 选中后赋值

    this.SetSleValue = function (difBh, val) {
        if ("''" == val)
            val = "";

        if ("bmbh" == difBh)
            sle_drbm.SetText(val);
        if ("bmbh2" == difBh)
            sle_dcbm.SetText(val);
        else if ("lbbh" == difBh)
            sle_lb.SetText(val);
        else if ("ppbm" == difBh)
            sle_pp.SetText(val);
        else if ("jjbm" == difBh)
            sle_jj.SetText(val);
        else if ("spkh" == difBh)
            sle_kh.SetText(val);
        else if ("csbh" == difBh)
            sle_fs.SetText(val);
        else if ("dbfs" == difBh)
            sle_fs.SetText(val);
        else if ("mlbh" == difBh)
            sle_ml.SetText(val);
        else if ("gysbh" == difBh)
            sle_gys.SetText(val);
    }

    //#endregion

    //#region Function GetSqlWhere
    this.GetSqlWhere = function () {
        var realSql = "";
        curYhbh = requestor.GetParm("curYhbh")
        var beginDate = UtcDateFormatToString(dp_1.GetValue());
        var endDate = UtcDateFormatToString(dp_2.GetValue());
        var curPzh = sle_pzh.GetText();
        var curGys = sle_gys.GetText();
        var curDrbm = sle_drbm.GetText();
        var curDcbm = sle_dcbm.GetText();
        var curPp = sle_pp.GetText();
        var curKh = sle_kh.GetText();
        var curLb = sle_lb.GetText();
        var curJj = sle_jj.GetText();
        var curFs = sle_fs.GetText();
        var curMl = sle_ml.GetText();
        var curSex = ddlb_sex.GetText();
        var curNF = ddlb_nf.GetText();
        if (ywflag == "DZ") {
            realSql += " and (CONVERT(date,h.kdrq) between '" + beginDate + "' and '" + endDate + "')";
        } else {
            realSql += " and (CONVERT(date,a.kdrq) between '" + beginDate + "' and '" + endDate + "')";
        }

        if (curKh.length > 0) {
            var is_quotes = curKh.substring(0, 1);
            if (is_quotes == "%") {

                realSql += " and a.spkh like('" + curKh + "%')";
            } else {
                var curflag = curKh.substr(curKh.length - 1, 1);

                if (curflag == "," || curflag == "，") {
                    curKh = curKh.substring(0, curKh.length - 1);
                    var tempspkh = self.GetQuotes(curKh);
                    realSql += " and a.spkh in(" + tempspkh + ")";
                } else {
                    if (is_quotes == "'") {
                        realSql += " and a.spkh in(" + curKh + ")";
                    } else {
                        realSql += " and a.spkh like('" + curKh + "%')";
                    }
                }
            }
        }

        if (curDrbm.length > 0) {
            var is_quotes = curDrbm.substring(0, 1);
            if (ywflag == "DZ") {
                if (is_quotes == "'") {
                    realSql += " and h.bmbh1 in(" + curDrbm + ")";
                } else {
                    var tempspkh = self.GetQuotes(curDrbm);
                    realSql += " and h.bmbh1 in(" + tempspkh + ")";
                }
            } else {
                //判断掉出部门
                if (curDcbm.length > 0) {
                    if (is_quotes == "'") {
                        realSql += " and a.khbh in(" + curDrbm + ")";
                    } else {
                        var tempspkh = self.GetQuotes(curDrbm);
                        realSql += " and a.khbh in(" + tempspkh + ")";
                    }
                }
                if (curDcbm.length <= 0) {
                    if (is_quotes == "'") {
                        realSql += " and (a.khbh in(" + curDrbm + ")";
                    } else {
                        var tempspkh = self.GetQuotes(curDrbm);
                        realSql += " and (a.khbh in(" + tempspkh + ")";
                    }
                }
            }
        } else {
            if (ywflag == "DZ")
                realSql += "and (h.bmbh1 in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and dbcx = '1')"
            else
                realSql += "and (a.khbh in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and dbcx = '1')"
        }

        if (curDcbm.length > 0) {
            var is_quotes = curDcbm.substring(0, 1);
            if (ywflag == "DZ") {
                if (is_quotes == "'") {
                    realSql += " and h.bmbh2 in(" + curDcbm + ")";
                } else {
                    var tempspkh = self.GetQuotes(curDcbm);
                    realSql += " and h.bmbh2 in(" + tempspkh + ")";
                }
            } else {
                //判断调入部门
                if (curDrbm.length > 0) {
                    if (is_quotes == "'") {
                        realSql += " and a.bmbh2 in(" + curDcbm + ")";
                    } else {
                        var tempspkh = self.GetQuotes(curDcbm);
                        realSql += " and a.bmbh2 in(" + tempspkh + ")";
                    }
                }
                if (curDrbm.length <= 0) {
                    if (is_quotes == "'") {
                        realSql += " and a.bmbh2 in(" + curDcbm + "))";
                    } else {
                        var tempspkh = self.GetQuotes(curDcbm);
                        realSql += " and a.bmbh2 in(" + tempspkh + "))";
                    }
                }
            }
        } else {
            if (ywflag == "DZ") {
                realSql += " and h.bmbh2 in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and dbcx = '1'))"
            } else {
                realSql += " and a.bmbh2 in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and dbcx = '1'))"
            }
        }

        if (curPp.length > 0) {
            var is_quotes = curPp.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and jypp in(" + curPp + ")";
            } else {
                var tempspkh = self.GetQuotes(curPp);
                realSql += " and jypp in(" + tempspkh + ")";
            }
        } else {
            realSql += "and  jypp in(select ppbh from da_qx_ppda  where yhbh='" + curYhbh + "')"
        }

        if (curGys.length > 0) {
            var is_quotes = curGys.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and b.gysbh in(" + curGys + ")";
            } else {
                var tempspkh = self.GetQuotes(curGys);
                realSql += " and b.gysbh in(" + tempspkh + ")";
            }
        } else {
            realSql += "and  b.gysbh in(select gysbh from da_qx_gysda  where yhbh='" + curYhbh + "')"
        }

        if (curLb.length > 0) {
            var is_quotes = curLb.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and b.hplb in(" + curLb + ")";
            } else {
                var tempspkh = self.GetQuotes(curLb);
                realSql += " and b.hplb in(" + tempspkh + ")";
            }
        }

        if (curJj.length > 0) {
            var is_quotes = curJj.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and b.spjj in(" + curJj + ")";
            } else {
                var tempspkh = self.GetQuotes(curJj);
                realSql += " and b.spjj in(" + tempspkh + ")";
            }
        }

        if (curFs.length > 0) {
            if (ywflag == "DZ") {
                var is_quotes = curFs.substring(0, 1);
                if (is_quotes == "'") {
                    realSql += " and h.cgfs in(" + curFs + ")";
                } else {
                    var tempspkh = self.GetQuotes(curFs);
                    realSql += " and h.cgfs in(" + tempspkh + ")";
                }
            } else {
                var is_quotes = curFs.substring(0, 1);
                if (is_quotes == "'") {
                    realSql += " and a.cgfs in(" + curFs + ")";
                } else {
                    var tempspkh = self.GetQuotes(curFs);
                    realSql += " and a.cgfs in(" + tempspkh + ")";
                }
            }
        }

        if (curMl.length > 0) {
            var is_quotes = curMl.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and b.spml in(" + curMl + ")";
            } else {
                var tempspkh = self.GetQuotes(curMl);
                realSql += " and b.spml in(" + tempspkh + ")";
            }
        }

        if (curPzh.length > 0) {
            var is_quotes = curPzh.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and a.pzh in(" + curPzh + ")";
            } else {
                var tempspkh = self.GetQuotes(curPzh);
                realSql += " and a.pzh in(" + tempspkh + ")";
            }
        }
        if (curSex.length > 0) {
            if (curSex == "女") { realSql += " and  b.spxb='" + 0 + "'"; }
            else if (curSex == "男") { realSql += " and  b.spxb='" + 1 + "'"; }
            else if (curSex == "中性") { realSql += " and  b.spxb='" + 2 + "'"; }

        }
        if (curNF.length > 0) {
            if (curNF != "--") {
                realSql += " and  b.spnf='" + curNF + "'";
            }
        }
        //        if (ywflag == "DB") {
        //            realSql += " and   CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','QDDDJQYS') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE()";
        //        }
        //        if (ywflag == "DZ") {
        //            realSql += " and   CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','QDTZDJQYS') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE()";
        //        }
        //        if (ywflag == "DC") {
        //            realSql += " and   CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','QDCKDJQYS') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE()";
        //        }
        //        if (ywflag == "DR") {
        //            realSql += " and   CAST(CONVERT(VARCHAR(10),DATEADD(DAY,  CAST([DBO].[F_GET_DJ_CXTS]('" + curYhbh + "','QDRKDJQYS') AS INT) ,KDRQ),120) AS DATETIME) >= GETDATE()";
        //        }
        return realSql;
    }
    //#endregion

    //#region 处理引号的问题
    this.GetQuotes = function (curValue) {
        var temp1 = curValue.split(",")
        var ret_Value = "";
        for (var i = 0; i < temp1.length; i++) {
            if (ret_Value.length > 0) {
                ret_Value += "'" + temp1[i] + "',";
            }
            else {
                ret_Value = "'" + temp1[i] + "',"
            }
        }
        return ret_Value.substr(0, ret_Value.length - 1);
    }
    //#endregion

    //#region Function DealWords
    this.DealWords = function (words) {

        var temChar = words.toString().charAt(0);
        if (!(temChar == "'"))
            words = "'" + words + "'";
        return words;
    }
    //#endregion

    this.PostOpen = function () {
        curDw_format_hz = window.external.Control("dw_format_hz");
        curDw_format_mx = window.external.Control("dw_format");
        Exel_FH_Flag = GetGlobalParm("Excel_FH_Flag", "Excel_FH_Flag", "qybz");
        if (Exel_FH_Flag.length < 1) {
            Exel_FH_Flag = "1";
        }

        ywflag = requestor.GetParm("ywflag");
        curYhbh = requestor.GetParm("curYhbh");
        curYhmc = requestor.GetParm("curYhmc"); //curYhmc
        curCdbh = requestor.GetParm("curCdbh");
        jgtxlist = requestor.GetParm("curjgqx");
//        var myDate = new Date();
//        var nian = myDate.getFullYear().toString();
//        var yue = myDate.getMonth();
//        var ri = "01";
//        var objDate = new Date(nian, yue, ri);
//        dp_1.SetValue(objDate.getVarDate())
        dp_1.SetValue(UtcDateFormatToString(new Date().getVarDate()))
        dp_2.SetValue(UtcDateFormatToString(new Date().getVarDate()))
        var v_CheckBoxState = GetCheckBoxValue(dw_format, curYhbh, curCdbh, curBbmc);
        if (v_CheckBoxState.length > 1) {
            window.eval(v_CheckBoxState);
        }
        jgtxlist = requestor.GetParm("curjgqx");
        ExistGYS = ExistJG(jgtxlist, "gysbh");
        ExistJJ = ExistJG(jgtxlist, "jj");
        ExistLSJ = ExistJG(jgtxlist, "lsj");
        ExistDPJ = ExistJG(jgtxlist, "dpj");
        ExistDBJ = ExistJG(jgtxlist, "dbj");
        // 供应商
        if (ExistGYS == "N") {

            cb_3.SetEnabled(false);
            sle_gys.SetEnabled(false);
        }
        else {
           
            cb_3.SetEnabled(true);
            sle_gys.SetEnabled(true);
        }
        curPzh = requestor.GetParm("pzh");
        curBbmc = requestor.GetParm("bbmc");
        curBbfl = requestor.GetParm("bbfl");
        var context = curPzh + "#" + curBbmc + "#" + curBbfl;
        self.SetBBMC(context, "1");
        if (curOptype == "1" && curBBMCNew.length > 0) {
            sle_formatname.SetText(curBBMCNew);
            self.ClearAndTJ(true);
        } else {
            sle_formatname.SetText("");
            curBBPZH = "";
        }
    }
    //#region checkBox关闭还是打开状态
    this.CbxEnable = function (bv) {
        cbx_pzh.SetEnabled(bv);
        cbx_rq.SetEnabled(bv);
        cbx_drbm.SetEnabled(bv);
        cbx_dcbm.SetEnabled(bv);
        cbx_lb.SetEnabled(bv);
        cbx_fs.SetEnabled(bv);
        cbx_zdr.SetEnabled(bv);
        cbx_bz.SetEnabled(bv);

    }

    //#endregion
    this.rb_sp = function (b) {
        self.CbxEnable(b);
        cb_Save.SetEnabled(true);
        cb_Select.SetEnabled(true);
    }
    this.rb_drbm = function (b) {
        self.CbxEnable(!b);
        cb_Save.SetEnabled(false);
        cb_Select.SetEnabled(false);

    }
    this.rb_dcbm = function (b) {
        self.CbxEnable(!b);
        cb_Save.SetEnabled(false);
        cb_Select.SetEnabled(false);
    }
    this.rb_rq = function (b) {
        self.CbxEnable(!b);
        cb_Save.SetEnabled(false);
        cb_Select.SetEnabled(false);
    }

    //#region Function DrawDataWindow
    this.DrawDataWindow = function (parameter) {

        webReq.Invoke("GetSnataxAndDataFromSql", "sql=" + parameter + "&flag=Grid");
        //mle_1.SetText(parameter);
        if (webReq.StatusCode() == 200) {

            dw_temp.SetFullState(webReq.ResponseText());
            //dw_temp.Refresh();
            dw_list.SetFullState(dw_temp.GetFullState());
            dw_list.SetRowSelection(1);
            gRowCount = dw_list.RowCount();
            var colCount = dw_list.Describe("DataWindow.Column.Count");
            self.SetItemName(colCount);

        } else {
            alert("error!");
        }
            dw_list.Modify(" create text(band=header alignment='2' text='序号' border='0' color='33554432' x='0' y='0' height='76' width='183' html.valueishtml='0'  name=xh_t visible='1'  font.face='Tahoma' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='536870912' background.transparency='0' background.gradient.color='8421504' background.gradient.transparency='0' background.gradient.angle='0' background.brushmode='0' background.gradient.repetition.mode='0' background.gradient.repetition.count='0' background.gradient.repetition.length='100' background.gradient.focus='0' background.gradient.scale='100' background.gradient.spread='100' tooltip.backcolor='134217752' tooltip.delay.initial='0' tooltip.delay.visible='32000' tooltip.enabled='0' tooltip.hasclosebutton='0' tooltip.icon='0' tooltip.isbubble='0' tooltip.maxwidth='0' tooltip.textcolor='134217751' tooltip.transparency='0' transparency='0' )")
            dw_list.Modify("xh_t.y='" + dw_list.Describe("sl_t.y") + "'");
    }
    //#endregion 

    //#region 设置标题名称
    this.SetItemName = function (colCount) {

        var ls_columntitle = "";
        for (var li_loop1 = 1; li_loop1 <= colCount; li_loop1++) {
            var ls_columnname = dw_list.Describe('#' + String(li_loop1) + '.name');
            switch (ls_columnname) {
                case "bmbh":
                    ls_columntitle = "调入部门编号"
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;

                case "bmmc":
                    ls_columntitle = "调入部门名称";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "bmbh2":
                    ls_columntitle = "调出部门编号"
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;

                case "bmmc2":
                    ls_columntitle = "调出部门名称";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "spkh":
                    ls_columntitle = "商品款式";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "ksmc":
                    ls_columntitle = "款式名称";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "ysbh":
                    ls_columntitle = "颜色编号";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "ysmc":
                    ls_columntitle = "颜色名称";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "jldw":
                    ls_columntitle = "单位";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "rq":
                    ls_columntitle = "日期";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 300 + "'");
                    break;
                case "pzh":
                    ls_columntitle = "凭证号";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 500 + "'");
                    break;
                case "cgfs":
                    ls_columntitle = "调拨方式";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;

                case "lbbh":
                    ls_columntitle = "类别编号";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "lbmc":
                    ls_columntitle = "类别名称";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;

                case "kdr":
                    ls_columntitle = "制单人";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "bzxx":
                    ls_columntitle = "备注";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;

                case "zjsl":
                    ls_columntitle = "数量";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".edit.name='#####' " + ls_columnname + ".editmask.mask='#####' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "jjze":
                    ls_columntitle = "零售总额";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".format='0.00' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "lsjze":
                    ls_columntitle = "调拨总额";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".format='0.00' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "dpjze":
                    ls_columntitle = "吊牌总额";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".format='0.00' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "jj":
                    ls_columntitle = "零售价";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".format='0.00' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "lsj":
                    ls_columntitle = "调拨价";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".format='0.00' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;

                case "dpj":
                    ls_columntitle = "吊牌价";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".format='0.00' ")
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;

            }
        }
        self.SetSummary();
    }

    this.SetSummary = function () {
        var ls_bqkcx = "";
        var ls_lswidth = "";
        var ls_syntax = '';
        var ls_bqkcwidth = "";
        var ls_bqrkwidth = "";
        ls_spmcx = dw_list.Describe("lbmc.x");
        ls_slx = dw_list.Describe("zjsl.x");
        ls_slwidth = dw_list.Describe("zjsl.width")
        ls_lszjex = dw_list.Describe("lsjze.x");
        ls_lszjewidth = dw_list.Describe("lsjze.width")
        ls_jjzex = dw_list.Describe("jjze.x");
        ls_jjzewidth = dw_list.Describe("jjze.width")

        ls_dpjzex = dw_list.Describe("dpjze.x");
        ls_dpjzewidth = dw_list.Describe("dpjze.width")


        ls_syntax = dw_list.Modify("DataWindow.summary.Height=90");
        ls_syntax = ls_syntax + "create compute(band=summary alignment='1' expression='sum(dpjze  for all)' border='0' color='128' x='" + ls_dpjzex + "' y='8' height='52' width='" + ls_dpjzewidth + "' name=sum_dpjze  visible='1' font.face='Arial' font.height='-9' font.weight='700'  font.family='2' font.pitch='2' font.charset='0' background.mode='1' background.color='536870912' format='0.00')";
        ls_syntax = ls_syntax + "create compute(band=summary alignment='1' expression='sum(lsjze  for all)' border='0' color='128' x='" + ls_lszjex + "' y='8' height='52' width='" + ls_lszjewidth + "' name=sum_lsze  visible='1' font.face='Arial' font.height='-9' font.weight='700'  font.family='2' font.pitch='2' font.charset='0' background.mode='1' background.color='536870912' format='0.00')";
        ls_syntax = ls_syntax + "create compute(band=summary alignment='1' expression='sum(jjze  for all)' border='0' color='128' x='" + ls_jjzex + "' y='8' height='52' width='" + ls_jjzewidth + "' name=sum_jjze  visible='1' font.face='Arial' font.height='-9' font.weight='700'  font.family='2' font.pitch='2' font.charset='0' background.mode='1' background.color='536870912'  format='0.00')";
        ls_syntax = ls_syntax + "create compute(band=summary alignment='1' expression='sum(zjsl  for all)' border='0' color='128' x='" + ls_slx + "' y='8' height='52' width='" + ls_slwidth + "' name=sum_zjsl  visible='1' font.face='Arial' font.height='-9' font.weight='700'  font.family='2' font.pitch='2' font.charset='0' background.mode='1' background.color='536870912'  format='#####')";
        ls_syntax = ls_syntax + "create text(band=summary alignment='1'  text='(" + gRowCount + "行)合计:' border='0' color='128' x='" + ls_spmcx + "'  y='0' height='60' width='" + ls_slwidth + "' html.valueishtml='0'   name=t_1 visible='1'  font.face='Arial' font.height='-9' font.weight='700'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='1073741824')";
        ls_syntax = ls_syntax + "create compute(band=detail alignment='2' expression='getrow()' border='0' color='33554432' x='0' y='8' height='72' width='215' format='[GENERAL]' html.valueishtml='0' name=xh  visible='1'  font.face='Arial' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='1073741824')";
        dw_list.Modify(ls_syntax);
    }
    //#endregion

    //#region exit
    this.Exit = function () {
        setTimeout("window.close()", 100);
    }
    //#endregion

    //#region 打印处理
    this.Print = function () {
        var curHeadString_rq = "";
        var curHeadString = "";
        var curFootString = "";
        var rq1 = UtcDateFormatToString(dp_1.GetValue())
        var rq2 = UtcDateFormatToString(dp_2.GetValue())
        if (rq1 == rq2) {
            curHeadString_rq = "日期：" + rq1
        } else {
            curHeadString_rq = "日期：" + rq1 + "到" + rq2 + "之间"
        }

        //#region 条件显示
        var bmmc = sle_drbm.GetText();
        var curHeadStringBM = Report_Print(bmmc, "DRBM");

        var dcbmmc = sle_dcbm.GetText();
        var curHeadStringDCBM = Report_Print(dcbmmc, "DCBM");

        var gysmc = sle_gys.GetText();
        var curHeadStringGYS = Report_Print(gysmc, "GYS");

        var ppmc = sle_pp.GetText();
        var curFootStringPP = Report_Print(ppmc, "PP");

        var khmc = sle_kh.GetText();
        var curFootStringKH = Report_Print(khmc, "KH");

        var fsmc = sle_fs.GetText();
        var curFootStringFS = Report_Print(fsmc, "DBFS");

        var lbmc = sle_lb.GetText();
        var curFootStringLB = Report_Print(lbmc, "LB");

        var jjmc = sle_jj.GetText();
        var curFootStringJJ = Report_Print(jjmc, "JJ");

        var mlmc = sle_ml.GetText();
        var curFootStringML = Report_Print(mlmc, "ML");

        //#endregion

        var ywflag = requestor.GetParm("ywflag");
        var curTitleName = ""
        if (ywflag == "DB") {
            curTitleName = "调拨订货单【精确到颜色】";
        } else if (ywflag == "DZ") {
            curTitleName = "调拨通知单【精确到颜色】";
        } else if (ywflag == "DC") {
            curTitleName = "调拨出库单【精确到颜色】";
        } else if (ywflag == "DR") {
            curTitleName = "调拨入库单【精确到颜色】";
        }
        curFootString = "制单人：" + curYhmc + "&&&【" + GetErpProductTypeName() + "软件】" + UtcDateTimeFormatToString(new Date().getVarDate()) +
                    "&&&" + curFootStringPP + "," + curFootStringKH + "," + curFootStringFS + "," + curFootStringLB +
                    "," + curFootStringJJ + "," + curFootStringML
        
        curHeadString = curHeadString_rq + "&&&" + curHeadStringGYS + "&&&" + curHeadStringBM + "&&&" + curHeadStringDCBM;
        A8erp_Report.NaoErpReportPrint(dw_list, curTitleName, curHeadString, curFootString);
    }
    //#endregion

    //#region 设置报表名称和凭证号

    this.SetBBMC = function (context, optype) {
        if (context.length > 0) {
            curBBPZH = context.split("#")[0];
            curBBMCNew = context.split("#")[1];
            isFirstSave = context.split("#")[2];
            if (optype == "1") {
                curBbmc = context.split("#")[2];
                self.SetBbfl(curBbmc);
            }
        }
        curOptype = optype;
    }
    //#endregion

    //#region 报表格式选择
    this.SelectGS = function () {
        self.SelectBBFL();
        cur_Open_Window = new W_Base_BB_List();
        cur_Open_Window.SetParentWindow(self);
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.KuCun.TongJiFenXi.Base.W_Base_BB_List" + "&opFlag=DB" + "&FunID=" + curCdbh + "&bbfl=" + curBbmc + "&dataObject=dw_pub_all_report_format_hz"), cur_Open_Window, null);

        if (curOptype == "1" && curBBMCNew.length > 0) {
            sle_formatname.SetText(curBBMCNew);
            self.ClearAndTJ(true);
        } else {
            sle_formatname.SetText("");
            curBBPZH = "";
        }
        //刷新
    }
    //#endregion

    //#region 格式保存#报表格式清空
    this.ReportClare = function () {
        var tempPzh = "";
        if (curDw_format_hz.RowCount() > 0) {
            tempPzh = curDw_format_hz.GetItemString("1", "pzh");
        }
//        if (tempPzh.length <= 0 || sle_formatname.GetText().length <= 0) {
//            requestor.MessageBox("提示", "请先选择报表格式", ICON.StopSign);
//            return;
//        }
        curDw_format_mx.Reset();
        curDw_format_hz.Reset();
        sle_formatname.SetText("");
        self.TongJi();
    }
    this.ClearAndTJ = function (isTj) {
        curDw_format_hz.RetrieveEx("pzh='" + curBBPZH + "'");
        curDw_format_mx.RetrieveEx("pzh='" + curBBPZH + "'");
        curDw_format_mx.SetFilter("mrgxtj='1'");
        curDw_format_mx.Filter();
        xsmrgs = curDw_format_mx.RowCount();
        cbx_rq.SetChecked(false);
        cbx_drbm.SetChecked(false);
        cbx_dcbm.SetChecked(false);
        cbx_zdr .SetChecked(false);
        cbx_lb.SetChecked(false);
        cbx_bz.SetChecked(false);
        cbx_fs.SetChecked(false);
        cbx_pzh.SetChecked(false);
        cbx_bz.SetChecked(false);
        //界面控制
        evealStr = "";
        for (var i = 1; i <= curDw_format_mx.RowCount(); i++) {
            evealStr += curDw_format_mx.GetItemString(i, "col") + ".SetChecked(true);";
        }
        eval(evealStr);

        curDw_format_mx.SetFilter("");
        curDw_format_mx.Filter();
        curDw_format_mx.SetFilter("mrgxtj='0'");
        curDw_format_mx.Filter();
        if (isTj == true) {
            //self.TongJi();
            if (curDw_format_mx.RowCount() <= 0) {
                sle_formatname.SetText("");
            }
        }
    }
    //#endregion

    //#region 水平/部门/日期

    this.SetBbfl = function (bbfl) {
        if (bbfl == "rb_sp") {
            rb_sp.SetChecked(true);
        }
        else if (bbfl == "rb_bm") {
            rb_bm.SetChecked(true);
        }
        else if (bbfl == "rb_rq") {
            rb_rq.SetChecked(true);
        }
        else if (bbfl == "rb_gys") {
            rb_gys.SetChecked(true);
        }
    }
    //#endregion

    //#region 保存
    this.SaveGS = function () {
        self.SelectBBFL();

       // curBBMCNew = "";
        if (curBbmc.length > 0) {
            cur_Open_Window = new W_Base_SaveOP();
            cur_Open_Window.SetParentWindow(self, curCdbh);
            requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.KuCun.TongJiFenXi.Base.W_Base_SaveOP" + "&opFlag=CG" + "&Bbfl=" + curBbmc + "&dataObject=dw_kctjfx_top"), cur_Open_Window, null);
        }
        if (curBBMCNew.length <= 0 || curOptype != 0) {
            return;
        }
        sle_formatname.SetText(curBBMCNew);
        self.ReportSave();
    }
    //#endregion

    //#region 获取报表分类
    this.SelectBBFL = function () {

        if (rb_sp.GetChecked()) {
            curBbmc = "rb_sp";
        }
        if (rb_drbm.GetChecked()) {
            curBbmc = "rb_drbm";
        }
        if (rb_rq.GetChecked()) {
            curBbmc = "rb_rq";
        }
        if (rb_dcbm.GetChecked()) {
            curBbmc = "rb_dcbm";
        }
    }
    //#endregion

    //#region 提交
    this.ReportSave = function () {
        self.PropertCheckStatus();
        alert("curBbmc=" + curBbmc);
        alert("curBBMCNew=" + curBBMCNew);
        var msg = ReportSaveEx(dw_list, curDw_format_hz, curDw_format_mx, curYhbh, curCdbh, curBbmc, curBBPZH, curYhbh, curBBMCNew, ChildDWCheckValue, jgtxlist, isFirstSave);
        if (msg == "OK") {
            requestor.MessageBox("提示", "保存成功", ICON.Information);
            curDw_format_mx.ResetUpdate();
            curDw_format_mx.SetFilter("mrgxtj='1'");
            curCol = requestor.GetParm("curCol");
            curDw_format_mx.Filter();
            xsmrgs = curDw_format_mx.RowCount();
            curDw_format_mx.SetFilter("");
            curDw_format_mx.Filter();
            curDw_format_mx.SetFilter("mrgxtj='0'");
            curDw_format_mx.Filter();
            self.TongJi();
            return;
        }
        else {
            requestor.MessageBox("提示", msg, ICON.StopSign);
        }
    }
    //#endregion

    //#region 获取被选中复选框
    this.PropertCheckStatus = function () {
        ChildDWCheckValue = "";
        //日期
        if (cbx_rq.GetChecked()) {
            ChildDWCheckValue += "cbx_rq,"
        }
        //调出部门
        if (cbx_drbm.GetChecked()) {
            ChildDWCheckValue += "cbx_drbm,"
        }
        //调入部门
        if (cbx_dcbm.GetChecked()) {
            ChildDWCheckValue += "cbx_dcbm,"
        }
        //供应商
        if (cbx_pzh.GetChecked()) {
            ChildDWCheckValue += "cbx_pzh,"
        }
        //类别
        if (cbx_lb.GetChecked()) {
            ChildDWCheckValue += "cbx_lb,"
        }
        //单据
        if (cbx_zdr.GetChecked()) {
            ChildDWCheckValue += "cbx_zdr,"
        }
        //方式
        if (cbx_fs.GetChecked()) {
            ChildDWCheckValue += "cbx_fs,"
        }
        //凭证号
        if (cbx_bz.GetChecked()) {
            ChildDWCheckValue += "cbx_pzh,"
        }

    }
    //#endregion

    //#region 定义title高度
    this.A8erp_Report_Header_Row_Height = function (curDw_List) {
        curDw_List.Modify("datawindow.header.height='76'");
    }
    //#endregion

    //#region 定义Detail高度
    this.A8erp_Report_Detail_Row_Height = function (curDw_List) {
        curDw_List.Modify("datawindow.detail.height='76'");
    }
    //#endregion

    //#region 定义单据样式

    this.A8erp_Report_Style = function (curDw_List) {//67108864    15780518
        curDw_List.Modify("datawindow.detail.color='67108864' datawindow.detail.gradient.color='16777215' datawindow.detail.brushmode='1' ")
    }
    //#endregion

    //#region FormatSave
    this.FormatSave = function () {
        curDw_format_mx.SetRedraw(false);

        //        if (curcbx_gs != xsmrgs) {
        //            dw_list.Modify("cm1.Format='###' cm2.Format='###' cm3.Format='###' cm4.Format='###' cm5.Format='###' cm6.Format='###' cm7.Format='###' cm8.Format='###' cm9.Format='###' cm10.Format='###' cm11.Format='###' cm12.Format='###' cm13.Format='###' cm14.Format='###' cm15.Format='###' cm16.Format='###' cm17.Format='###' cm18.Format='###' cm19.Format='###' cm20.Format='###' cm21.Format='###' cm22.Format='###' cm23.Format='###' cm24.Format='###' cm25.Format='###' cm26.Format='###' cm27.Format='###' cm28.Format='###' cm29.Format='###' cm30.Format='###' cm31.Format='###' cm32.Format='###' cm33.Format='###' cm34.Format='###' cm35.Format='###'");
        //            if (Exel_FH_Flag == "1") {
        //                dw_list.Modify("DataWindow.Sparse='spkh\tksmc\tjldw\tysbh\tysmc\tbxbh\tbxmc'");
        //            }
        //            return
        //        }
        curDw_format_mx.SetSort("col_x A");
        curDw_format_mx.Sort();
        for (var i = 1; i <= curDw_format_mx.RowCount(); i++) {
            var curCol = curDw_format_mx.GetItemString(i, "col");

            var curVisible = curDw_format_mx.GetItemString(i, "visible");
            dw_list.Modify(curCol + ".visible='0'");
            dw_list.Modify(curCol + ".visible='" + curVisible + "'");

            var curWidth = curDw_format_mx.GetItemNumber(i, "width");
            dw_list.Modify(curCol + ".width='" + curWidth + "'");

            var curColHz = curDw_format_mx.GetItemString(i, "col_hz");
            dw_list.Modify(curCol + "_t.Text='" + curColHz + "'");

            var curfont_face = curDw_format_mx.GetItemString(i, "font_face");
            dw_list.Modify(curCol + ".Font.Face='" + curfont_face + "'");

            var curfont_height = curDw_format_mx.GetItemString(i, "font_height");
            dw_list.Modify(curCol + ".Font.Height='" + curfont_height + "'");

            var curfont_weight = curDw_format_mx.GetItemString(i, "font_weight");
            dw_list.Modify(curCol + ".Font.Weight='" + curfont_weight + "'");

            var curfont_italic = curDw_format_mx.GetItemString(i, "font_italic");
            dw_list.Modify(curCol + ".Font.Italic='" + curfont_italic + "'");

            var curfont_underline = curDw_format_mx.GetItemString(i, "font_underline");
            dw_list.Modify(curCol + ".Font.Underline='" + curfont_underline + "'");

            var curCol_border = curDw_format_mx.GetItemString(i, "col_border");
            dw_list.Modify(curCol + ".Border='" + curCol_border + "'");

            var ls_color = curDw_format_mx.GetItemString(i, "color");
            dw_list.Modify(curCol + ".Color='" + curCol_border + "'");

            var ls_format = curDw_format_mx.GetItemString(i, "format");
            dw_list.Modify(curCol + ".Format='" + ls_format + "'");

            var ls_alignment = curDw_format_mx.GetItemString(i, "alignment");
            dw_list.Modify(curCol + ".Alignment='" + ls_alignment + "'");

            var ls_alignment = curDw_format_mx.GetItemString(i, "tabsequence");
            dw_list.Modify(curCol + ".TabSequence='" + ls_alignment + "'");

            var li_bg_mode = curDw_format_mx.GetItemString(i, "bg_mode");
            dw_list.Modify(curCol + ".Background.Mode='" + li_bg_mode + "'");

            var ls_bg_color = curDw_format_mx.GetItemString(i, "bg_color");
            dw_list.Modify(curCol + ".Background.Color='" + ls_bg_color + "'");
        }
        curDw_format_mx.SetRedraw(true);
        //#endregion
    }

    //#endregion

    //#region 格式保存#报表列格式操作
    this.ReportOp = function () {
        if (curBBPZH.length <= 0 || sle_formatname.GetText().length <= 0) {
            requestor.MessageBox("提示", "请先选择报表格式", ICON.StopSign);
            return;
        }

        curW_Base_Report_Open_Mx_Ex.SetDataWindow(self, curUserId, curCdbh, curBbmc, curBBPZH, "curParent.ClearAndTJ(true);");
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.Base.W_Base_Report_Open_Mx_Ex"), curW_Base_Report_Open_Mx_Ex, null);
        curDw_format_hz.RetrieveEx("pzh='" + curBBPZH + "'");
        curDw_format_mx.RetrieveEx("pzh='" + curBBPZH + "'");
    }
    //#endregion

    //#region  执行查询
    this.TongJi = function () {

        dw_list.SetRedraw(false);
        curcbx_gs = 0;
        //self.GetTableYM();
        if (rb_sp.GetChecked()) {
            self.Query(); //规格
            // dw_list.Modify("cm1.Format='###' cm2.Format='###' cm3.Format='###' cm4.Format='###' cm5.Format='###' cm6.Format='###' cm7.Format='###' cm8.Format='###' cm9.Format='###' cm10.Format='###' cm11.Format='###' cm12.Format='###' cm13.Format='###' cm14.Format='###' cm15.Format='###' cm16.Format='###' cm17.Format='###' cm18.Format='###' cm19.Format='###' cm20.Format='###' cm21.Format='###' cm22.Format='###' cm23.Format='###' cm24.Format='###' cm25.Format='###' cm26.Format='###' cm27.Format='###' cm28.Format='###' cm29.Format='###' cm30.Format='###' cm31.Format='###' cm32.Format='###' cm33.Format='###' cm34.Format='###' cm35.Format='###'");
            if (Exel_FH_Flag == "1") {
                dw_list.Modify("DataWindow.Sparse='spkh\tksmc\tjldw\tysbh\tysmc\tbxbh\tbxmc'");
            }
            self.FormatSave();
            dw_list.SetSort("spkh,ksmc,v.ysbh,v.ysmc,v.bxbh,v.bxmc");
            dw_list.Sort();
            //给Title加颜色。。
            A8erp_Report.ReportDataWindowHeaderColor(dw_list);
            self.A8erp_Report_Style(dw_list);
            self.A8erp_Report_Header_Row_Height(dw_list, false);
            self.A8erp_Report_Detail_Row_Height(dw_list);
            //JS样式。
        }
        if (rb_dcbm.GetChecked()) {
            self.Query(); // 款式
            dw_list.SetSort("spkh,ksmc,v.ysbh,v.ysmc,v.bxbh,v.bxmc");
            dw_list.Sort();
        }
        if (rb_drbm.GetChecked()) {
            self.Query(); // 款式
            dw_list.SetSort("spkh,ksmc,v.ysbh,v.ysmc,v.bxbh,v.bxmc");
            dw_list.Sort();
        }
        if (rb_rq.GetChecked()) {
            self.Query(); // 款式
            dw_list.SetSort("spkh,ksmc,v.ysbh,v.ysmc,v.bxbh,v.bxmc");
            dw_list.Sort();
        }
        dw_list.SetRedraw(true);

        //requestor.ClipBoard(dw_list.Describe("datawindow.syntax"))

    }
    //#endregion

    //#region SetValue
    this.SetValue = function (str1, str2, str3, str4) {

        ChildDWCheckValue = str1;
        curBbmc = str2;
        curCdbh = str3;
        curUserId = str4;
    }
    //#endregion

    //#region 双击标题排序
    this.DoubleClicked = function (x, y, row, dwcName) {

        if (dwcName.indexOf("_t") > -1) {
            var curColName = dwcName.split("_")[0];
            if (curColName == lastSortName) {
                dw_list.SetSort(curColName + " A");
                lastSortName = "";
                dw_list.Sort();
            } else {
                dw_list.SetSort(curColName + " D");
                lastSortName = dwcName.split("_")[0];
                dw_list.Sort();
            }
        }
    }
    //#endregion

    //#region 图片预览
    this.picpreview = function () {
        var cloumCount = 0;
        var cloumName = "";
        cloumCount = parseInt(dw_list.Describe("datawindow.column.count"));
        for (var i = 1; i <= cloumCount; i++) {
            cloumName += dw_list.Describe("#" + String(i) + ".name")
        }
        if (cloumName.indexOf("spkh") > -1) {
            var curRow = dw_list.GetRow();
            //图片的跳转
            if (curRow > 0) {
                var curspkh = dw_list.GetItemString(curRow, "spkh")
                var picuploadflag = 0;
                curW_KC_PIC.SetDataWindow(dw_list, curspkh, self, picuploadflag, "");
                requestor.Open("/Service/LoadWindow.ashx?WinName= A8ERP.KuCun.TongJiFenXi.W_KC_PIC&curSpkh=" + curspkh, curW_KC_PIC);
            }
        } else {
            requestor.MessageBox("提示", "请选择款号条件统计后再预览图片!", ICON.Information);
        }


    }
    //#endregion

    //#region 右键保存
    this.RightKey = function () {
        if (sle_formatname.GetText().toString().length > 0) {
            self.ReportSave();
        }
        else {
            requestor.MessageBox("提示", "请选择格式后再保存!", ICON.Information);
        }
    }
    //#endregion
}