///<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" />

function W_ZXFXTJ() {

    var self = this;
    this.Instance = null;
    var requestor = new PBWindow();
    var ddlb_nf = new DropDownListBox(requestor);
    var rb_hx = new RadioButton(requestor);
    var rb_zx = new RadioButton(requestor);
    var rb_ys = new RadioButton(requestor);
    var rb_kh = new RadioButton(requestor);
    var cbx_drbm = new CheckBox(requestor);
    var sle_dcbm = new SingleLineEdit(requestor);
    var cbx_lb = new CheckBox(requestor);
    var cbx_dcbm = new CheckBox(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 ddlb_sex = new DropDownListBox(requestor);
    var dw_format_hz = new DataWindow(requestor);
    var dw_format = new DataWindow(requestor);
    var dw_temp = new DataWindow(requestor);
    var mle_1 = new MultiLineEdit(requestor);
    var dw_2 = new DataWindow(requestor);
    var dw_list = new DataWindow(requestor);
    var dw_zxsl = new DataWindow(requestor);
    var dw_hxsl = new DataWindow(requestor);
    var tb_1 = new ToolStrip(requestor);
    var ContextMenuStrip1 = new ContextMenu(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);

    if (typeof (this.bind) == "function") var baseBind = this.bind;
    this.bind = function (win) {
        self.Instance = win;
        if (typeof (baseBind) == "function") baseBind(win);

        if (requestor == null) requestor = new PBWindow();
        requestor.Attach(win);
        if (ddlb_nf == null) ddlb_nf = new DropDownListBox(requestor);
        ddlb_nf.Attach(win.Control("ddlb_nf"));
        if (rb_hx == null) rb_hx = new RadioButton(requestor);
        rb_hx.Attach(win.Control("rb_hx"));
        if (rb_zx == null) rb_zx = new RadioButton(requestor);
        rb_zx.Attach(win.Control("rb_zx"));
        if (rb_ys == null) rb_ys = new RadioButton(requestor);
        rb_ys.Attach(win.Control("rb_ys"));
        if (rb_kh == null) rb_kh = new RadioButton(requestor);
        rb_kh.Attach(win.Control("rb_kh"));
        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_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 (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 (ddlb_sex == null) ddlb_sex = new DropDownListBox(requestor);
        ddlb_sex.Attach(win.Control("ddlb_sex"));
        if (dw_format_hz == null) dw_format_hz = new DataWindow(requestor);
        dw_format_hz.Attach(win.Control("dw_format_hz"));
        if (dw_format == null) dw_format = new DataWindow(requestor);
        dw_format.Attach(win.Control("dw_format"));
        if (dw_temp == null) dw_temp = new DataWindow(requestor);
        dw_temp.Attach(win.Control("dw_temp"));
        if (mle_1 == null) mle_1 = new MultiLineEdit(requestor);
        mle_1.Attach(win.Control("mle_1"));
        if (dw_2 == null) dw_2 = new DataWindow(requestor);
        dw_2.Attach(win.Control("dw_2"));
        if (dw_list == null) dw_list = new DataWindow(requestor);
        dw_list.Attach(win.Control("dw_list"));
        if (dw_zxsl == null) dw_zxsl = new DataWindow(requestor);
        dw_zxsl.Attach(win.Control("dw_zxsl"));
        if (dw_hxsl == null) dw_hxsl = new DataWindow(requestor);
        dw_hxsl.Attach(win.Control("dw_hxsl"));
        if (tb_1 == null) tb_1 = new ToolStrip(requestor);
        tb_1.Attach(win.Control("tb_1"));
        if (ContextMenuStrip1 == null) ContextMenuStrip1 = new ContextMenu(requestor);
        ContextMenuStrip1.Attach(win.Control("ContextMenuStrip1"));
        if (sle_formatname == null) sle_formatname = new SingleLineEdit(requestor);
        sle_formatname.Attach(win.Control("sle_formatname"));

        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.SelectGS) == "function")
            win.AttachEvent("cb_Select", "Clicked", self.SelectGS);

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

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

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

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

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

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

        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.RowFocusChanged) == "function")
            win.AttachEvent("dw_list", "RowFocusChanged", self.RowFocusChanged);

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

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

        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.RightKey) == "function")
            win.AttachEvent("xxxxxxaToolStripMenuItem", "Clicked", self.RightKey);

    }

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

        sle_formatname.Detach(); sle_formatname = null;
        ddlb_nf.Detach(); ddlb_nf = null;
        rb_hx.Detach(); rb_hx = null;
        rb_zx.Detach(); rb_zx = null;
        rb_ys.Detach(); rb_ys = null;
        rb_kh.Detach(); rb_kh = null;
        cbx_drbm.Detach(); cbx_drbm = null;
        sle_dcbm.Detach(); sle_dcbm = null;
        cbx_lb.Detach(); cbx_lb = null;
        cbx_dcbm.Detach(); cbx_dcbm = 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;
        ddlb_sex.Detach(); ddlb_sex = null;
        dw_format_hz.Detach(); dw_format_hz = null;
        dw_format.Detach(); dw_format = null;
        dw_temp.Detach(); dw_temp = null;
        mle_1.Detach(); mle_1 = null;
        dw_2.Detach(); dw_2 = null;
        dw_list.Detach(); dw_list = null;
        dw_zxsl.Detach(); dw_zxsl = null;
        dw_hxsl.Detach(); dw_hxsl = null;
        tb_1.Detach(); tb_1 = null;
        ContextMenuStrip1.Detach(); ContextMenuStrip1 = null;
        requestor.Detach(); requestor = null;
        cb_3.Detach(); cb_3 = null;
        cb_Save.Detach(); cb_Save = null;
        cb_Select.Detach(); cb_Select = 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 ColorRow = 1;
    var realSql = "";
    var realSql1 = "";
    webReq = new WebRequestor();
    webReq.SetWebServiceUrl("/Service/ServiceForDwSyndax.ashx");
    var curW_Base_Report_Open_Mx_Ex = new W_Base_Report_Open_Mx_Ex();
    var curBbmc = "rb_kh";
    var ChildDWCheckValue = "";
    var curCdbh = "";
    var curUserId = "";
    var curQDID = "";
    var jgtxlist = "";
    var curBBPZH = "";
    var curBBMCNew = "";

    webReq_Print = new WebRequestor();
    webReq_Print.SetWebServiceUrl("/Service/Ajax_XT.ashx");
    var curYhmc = "";
    var curJgtx = "";
    var ExistGYS = "";
    var curCol = "";
    //报表名称
    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();
    var curSelDays = "";
    //#endregion



    this.ReportSave = function () {
        var msg = ReportSaveEx(dw_list, dw_format_hz, dw_format, curUserId, curCdbh, curBbmc, curBBPZH, curQDID, curBBMCNew, ChildDWCheckValue);
        if (msg == "OK") {
            requestor.MessageBox("提示", "保存成功", ICON.Information);
            dw_format.ResetUpdate();
            dw_format.SetFilter("mrgxtj='1'");
           
            dw_format.Filter();
            xsmrgs = dw_format.RowCount();
            dw_format.SetFilter("");
            dw_format.Filter();
            dw_format.SetFilter("mrgxtj='0'");
            dw_format.Filter();
            self.TongJi();
            return;
        }
        else {
            requestor.MessageBox("提示", msg, ICON.StopSign);
        }
    }

    //    //#region 格式保存#报表格式操作
    //    this.ReportOp = function () {
    //        curW_Base_Report_Open_Mx.SetDataWindow(self, curUserId, curCdbh, curBbmc, "curParent.TongJi();");
    //        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.Base.W_Base_Report_Open_Mx"), curW_Base_Report_Open_Mx, null);
    //    }

    //#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);
    }

    this.ClearAndTJ = function (isTj) {
        dw_format_hz.RetrieveEx("pzh='" + curBBPZH + "'");
        dw_format.RetrieveEx("pzh='" + curBBPZH + "'");
        dw_format.SetFilter("mrgxtj='1'");
        dw_format.Filter();
        xsmrgs = dw_format.RowCount();
        cbx_dcbm.SetChecked(false);
        cbx_drbm.SetChecked(false);
        cbx_lb.SetChecked(false);
        //界面控制
        var evealStr = "";
        for (var i = 1; i <= dw_format.RowCount(); i++) {
            evealStr += dw_format.GetItemString(i, "col") + ".SetChecked(true);";
        }
        window.eval(evealStr);
        dw_format.SetFilter("");
        dw_format.Filter();
        dw_format.SetFilter("mrgxtj='0'");
        dw_format.Filter();
        if (isTj == true) {
            self.TongJi();
            if (dw_format.RowCount() <= 0) {
                sle_formatname.SetText("");
            }
        }
    }

    this.SetBbfl = function (bbfl) {
        if (bbfl == "rb_kh") {
            rb_kh.SetChecked(true);
        }
        else if (bbfl == "rb_ys") {
            rb_ys.SetChecked(true);
        }
        else if (bbfl == "rb_hx") {
            rb_hx.SetChecked(true);
        }
        else if (bbfl == "rb_zx") {
            rb_zx.SetChecked(true);
        }

    }
    //#endregion  

    //#region 设置报表名称和凭证号
    this.SetBBMC = function (context, optype) {
        if (context.length > 0) {
            curBBPZH = context.split("#")[0];
            curBBMCNew = context.split("#")[1];
            if (optype == "1") {
                curBbmc = context.split("#")[2];
                self.SetBbfl(curBbmc);
            }
        }
        curOptype = optype;
    }
    //#endregion

    //#region 获取报表分类

    this.SelectBBFL = function () {
        if (rb_kh.GetChecked()) {
            curBbmc = "rb_kh";
        }
        if (rb_ys.GetChecked()) {
            curBbmc = "rb_ys";
        }
        if (rb_hx.GetChecked()) {
            curBbmc = "rb_hx";
        }
        if (rb_zx.GetChecked()) {
            curBbmc = "rb_zx";
        }

    }
    //#endregion

    var curOptype = "";
    //选择报表格式
    this.SaveGS = function () {
        self.SelectBBFL();
        curBBMCNew = "";
        if (curBbmc.length > 0) {
            cur_Open_Window = new W_Base_SaveOP();
            cur_Open_Window.SetParentWindow(self, requestor.GetParm("FunctionID"));
            requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.KuCun.TongJiFenXi.Base.W_Base_SaveOP" + "&opFlag=DB" + "&Bbfl=" + curBbmc + "&dataObject=dw_kctjfx_top"), cur_Open_Window, null);
        }
        if (curBBMCNew.length <= 0 || curOptype != 0) {
            return;
        }
        sle_formatname.SetText(curBBMCNew);
        self.ReportSave();
    }
    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 = ""; 
        }
        //刷新
    }

    //#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();
    }
    //#endregion

    //#region PostOpen
    this.PostOpen = function () {
        sle_dcbm.SetEnabled(false);
        sle_drbm.SetEnabled(false);
        sle_gys.SetEnabled(false);
        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";
        }
        dw_temp.SetVisible(false);
        ywflag = requestor.GetParm("ywflag");
        curCdbh = requestor.GetParm("curCdbh");
        curYhbh = requestor.GetParm("curYhbh");
        curUserId = requestor.GetParm("curYhbh");
        curYhmc = requestor.GetParm("curYhmc"); //curYhmc
        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_2.SetValue(UtcDateFormatToString(new Date().getVarDate()))
        curCol = requestor.GetParm("curCol");
        curJgtx = requestor.GetParm("jgtxlist");
        ExistGYS = ExistJG(curJgtx, "gysbh");
        // 供应商
        if (ExistGYS == "N") {

            cb_3.SetEnabled(false);
        }
        else {

            cb_3.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 查询天数的

        curSelDays = GetXiTongCanShu(curUserId, curCdbh, "bzxx");

        //#endregion 
    }
    //#endregion

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

        var dynamicShowStr = "";
        var dynamicShowStr1 = "";
        var dynamicShowStr2 = "";
        var dynamicShowStr3 = "";
        var dynamicShowStr4 = "";
        var dynamicShowString = "";
        var dynamicShowString1 = "";
        var curSql = ""
        var curRows = "";
        var curCols = "";
        var curValues = "";
        var curColTypes = "";
        var sy = "";
        var finishSql = "";
        var curYhbh = requestor.GetParm("curYhbh")
        ChildDWCheckValue = "";
        dw_temp.Reset();
        //#region 表头显示
        if (cbx_lb.GetChecked()) {
            dynamicShowStr += "b.hplb hplb,d.lbmc lbmc,";
            dynamicShowString += ",b.hplb,d.lbmc";
            dynamicShowStr1 += "t2.hplb,t4.lbmc,";
            dynamicShowString1 += ",t2.hplb,t4.lbmc";
            dynamicShowStr2 += "hplb,lbmc,";
            dynamicShowStr3 += "cg_ddb.hplb,cg_ddb.lbmc,";
            ChildDWCheckValue += "cbx_lb,"
        }
        if (cbx_drbm.GetChecked()) {
            dynamicShowStr += " a.khbh  bmbh,c.bmmc  bmmc,";
            dynamicShowString += " ,a.khbh,c.bmmc";
            dynamicShowStr1 += " t1.khbh as bmbh ,t3.bmmc as bmmc,";
            dynamicShowString1 += " ,t1.khbh,t3.bmmc";
            dynamicShowStr2 += " bmbh ,bmmc,";
            dynamicShowStr3 += " cg_ddb.bmbh ,cg_ddb.bmmc,";
            ChildDWCheckValue += "cbx_drbm,"
        }
        if (cbx_dcbm.GetChecked()) {
            dynamicShowStr += " a.bmbh2  bmbh2,e.bmmc  bmmc2,";
            dynamicShowString += " ,a.bmbh2,e.bmmc";
            dynamicShowStr1 += " t1.bmbh2 as bmbh2 ,t3.bmmc as bmmc2,";
            dynamicShowString1 += " ,t1.bmbh2,t3.bmmc";
            dynamicShowStr2 += " bmbh2 ,bmmc2,";
            dynamicShowStr3 += " cg_ddb.bmbh2 ,cg_ddb.bmmc2,";
            ChildDWCheckValue += "cbx_dcbm,"
        }
        //#endregion
        self.GetSqlWhere();
        //#region 款号
        if (rb_kh.GetChecked()) {
            curBbmc = rb_kh.GetName();
            var finishSql_dd = "(select a.khbh bmbh ,c.bmmc bmmc,a.bmbh2 as bmbh2,e.bmmc bmmc2,b.hplb,d.lbmc,a.spkh,b.ksmc,b.jldw, a.cmzbh,a.cmbh,a.yslsh,a.bxbh,"+ 
                               " SUM(a.sl) ddbzjsl, avg(a.lsj) lsj,sum(a.sl*a.lsj) lsjze,avg(a.jj) jj,sum(a.sl*a.jj) jjze " +
                               " from (select * from  yw_db_dbddtz union all select * from  yw_db_dbddtz_ls)  a left join  da_sp_spda b on a.spkh=b.spkh " +
                               "left join  da_bmda c  on a.khbh= c.bmbh  " +
                               "left join  da_sp_lbda d on d.lbbh=b.hplb " +
                               "left join  da_bmda e on e.bmbh=a.bmbh2 " +
                               "left join  (select * from da_qj_csb where  csfl='CG_CGFS') f on a.cgfs=f.csbh  where a.djlx='1'  " +
                               realSql + " group by a.khbh,c.bmmc,a.bmbh2,e.bmmc,b.hplb,d.lbmc,a.spkh,b.ksmc,b.jldw, a.cmzbh,a.cmbh,a.yslsh,a.bxbh) as cg_ddb left join "
            var finishSql_rk = "(select t1.khbh bmbh ,t3.bmmc bmmc,t1.bmbh2 as bmbh2,t5.bmmc bmmc2,t2.hplb,t4.lbmc,t1.spkh,t2.ksmc,t2.jldw, t1.cmzbh,t1.cmbh,t1.yslsh,t1.bxbh," +
                               "SUM(t1.sl) rkbzjsl, avg(t1.lsj) lsj,sum(t1.sl*t1.lsj) lsjze,avg(t1.jj) jj,sum(t1.sl*t1.jj) jjze " +
                               "  from (select * from yw_db_dbrkdtz union all select * from yw_db_dbrkdtz_ls) t1 left join  da_sp_spda t2 on t1.spkh=t2.spkh " +
                               "left join  da_bmda t3  on t1.khbh= t3.bmbh  " +
                               "left join  da_sp_lbda t4 on t4.lbbh=t2.hplb " +
                               "left join  da_bmda t5 on t5.bmbh=t1.bmbh2 " +
                               "left join  (select * from da_qj_csb where  csfl='CG_CGFS') t6 on t1.cgfs=t6.csbh  where t1.djlx='1' " +
                                realSql1 + " group by  t1.khbh,t3.bmmc,t1.bmbh2,t5.bmmc,t2.hplb,t4.lbmc,t1.spkh,t2.ksmc,t2.jldw, t1.cmzbh,t1.cmbh,t1.yslsh,t1.bxbh) as cg_rkb  on cg_ddb.spkh=cg_rkb.spkh and cg_ddb.bmbh=cg_rkb.bmbh and cg_ddb.bmbh2=cg_rkb.bmbh2  and cg_ddb.hplb=cg_rkb.hplb  AND cg_ddb.yslsh=cg_rkb.yslsh and  cg_ddb.cmbh=cg_rkb.cmbh and cg_ddb.bxbh=cg_rkb.bxbh "
            var sendsql = "select " + dynamicShowStr3 + " cg_ddb.spkh,cg_ddb.ksmc,cg_ddb.jldw,sum(isnull(ddbzjsl,0))ddbzjsl,sum(isnull(rkbzjsl,0))rkbzjsl,sum(isnull(ddbzjsl,0))-sum(isnull(rkbzjsl,0)) sqsl, sum(isnull(rkbzjsl,0))/sum(isnull(ddbzjsl,0)) dhbl from  " + finishSql_dd + finishSql_rk +
                           " where 1=1 " +
                           " group by " + dynamicShowStr3 + "cg_ddb.spkh,cg_ddb.ksmc,cg_ddb.jldw"
            requestor.ClipBoard(sendsql)
            sendsql = sendsql.replace(/\+/g, "%2B");
            sendsql = sendsql.replace(/\&/g, "%26");
            sendsql = sendsql.replace(/\%/g, "%25");
            self.DrawDataWindow(sendsql);
            DWSort(dw_format, dw_list);
            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);
        }
        //#endregion

        //#region 颜色
        else if (rb_ys.GetChecked()) {
            curBbmc = rb_ys.GetName();
            var finishSql_dd = "(select a.khbh bmbh ,c.bmmc bmmc,a.bmbh2 as bmbh2,e.bmmc bmmc2,b.hplb,d.lbmc,a.spkh,b.ksmc,b.jldw, a.cmzbh,a.cmbh,a.yslsh,a.ysbh,g.ysmc,a.bxbh,"+ 
                               "SUM(a.sl) ddbzjsl, avg(a.lsj) lsj,sum(a.sl*a.lsj) lsjze,avg(a.jj) jj,sum(a.sl*a.jj) jjze " +
                               " from (select * from  yw_db_dbddtz union all select * from  yw_db_dbddtz_ls) a left join  da_sp_spda b on a.spkh=b.spkh " +
                               "left join  da_bmda c  on a.khbh= c.bmbh  " +
                               "left join  da_sp_lbda d on d.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='CG_CGFS') f on a.cgfs=f.csbh  where a.djlx='1' " +
                               realSql + " group by  a.khbh,c.bmmc,a.bmbh2,e.bmmc,b.hplb,d.lbmc,a.spkh,b.ksmc,b.jldw, a.cmzbh,a.cmbh,a.yslsh,a.ysbh,g.ysmc,a.bxbh) as cg_ddb left join "
            var finishSql_rk = "(select t1.khbh bmbh ,t3.bmmc bmmc,t1.bmbh2 as bmbh2,t5.bmmc bmmc2,t2.hplb,t4.lbmc,t1.spkh,t2.ksmc,t2.jldw, t1.cmzbh,t1.cmbh,t1.yslsh,t1.ysbh,t7.ysmc,t1.bxbh," +
                               "SUM(t1.sl) rkbzjsl, avg(t1.lsj) lsj,sum(t1.sl*t1.lsj) lsjze,avg(t1.jj) jj,sum(t1.sl*t1.jj) jjze " +
                               " from (select * from yw_db_dbrkdtz union all select * from yw_db_dbrkdtz_ls) t1 left join  da_sp_spda t2 on t1.spkh=t2.spkh " +
                               "left join  da_bmda t3  on t1.khbh= t3.bmbh  " +
                               "left join  da_sp_lbda t4 on t4.lbbh=t2.hplb " +
                                "left join  da_bmda t5 on t5.bmbh=t1.bmbh2 " +
                                "left join  da_sp_ysda t7 on t1.yslsh=t7.yslsh "+
                               "left join  (select * from da_qj_csb where  csfl='CG_CGFS') t6 on t1.cgfs=t6.csbh  where t1.djlx='1' " +
                                realSql1 + " group by  t1.khbh,t3.bmmc,t1.bmbh2,t5.bmmc,t2.hplb,t4.lbmc,t1.spkh,t2.ksmc,t2.jldw, t1.cmzbh,t1.cmbh,t1.yslsh,t1.ysbh,t7.ysmc,t1.bxbh) as cg_rkb on   cg_ddb.spkh=cg_rkb.spkh and cg_ddb.bmbh=cg_rkb.bmbh and cg_ddb.bmbh2=cg_rkb.bmbh2 and cg_ddb.hplb=cg_rkb.hplb  AND cg_ddb.yslsh=cg_rkb.yslsh and  cg_ddb.cmbh=cg_rkb.cmbh and cg_ddb.bxbh=cg_rkb.bxbh  "
            var sendsql = "select " + dynamicShowStr3 + " cg_ddb.spkh,cg_ddb.ksmc,cg_ddb.jldw,cg_ddb.ysbh,cg_ddb.ysmc,sum(isnull(ddbzjsl,0))ddbzjsl,sum(isnull(rkbzjsl,0))rkbzjsl,sum(isnull(ddbzjsl,0))-sum(isnull(rkbzjsl,0)) sqsl, sum(isnull(rkbzjsl,0))/sum(isnull(ddbzjsl,0)) dhbl from  " + finishSql_dd + finishSql_rk +
                         " where 1=1 " +
                        " group by " + dynamicShowStr3 + "cg_ddb.spkh,cg_ddb.ksmc,cg_ddb.jldw,cg_ddb.ysbh,cg_ddb.ysmc"
            requestor.ClipBoard(sendsql)
            sendsql = sendsql.replace(/\+/g, "%2B");
            sendsql = sendsql.replace(/\&/g, "%26");
            sendsql = sendsql.replace(/\%/g, "%25");
            self.DrawDataWindow(sendsql);
            DWSort(dw_format, dw_list);
            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);
        }
        //#endregion 

        //#region 纵向
        else if (rb_zx.GetChecked()) {
            curBbmc = rb_zx.GetName();
            var finishSql_dd = "(select b.hplb hplb ,d.lbmc lbmc ,"+
                               "a.spkh,b.ksmc,b.jldw,a.yslsh,a.ysbh,g.ysmc,a.cmzbh,a.cmbh,a.bxbh,a.khbh,c.bmmc khmc, a.bmbh2, e.bmmc bmmc,SUM(a.sl) ddbzjsl, avg(a.lsj) lsj,sum(a.sl*a.lsj) lsjze,avg(a.jj) jj,sum(a.sl*a.jj) jjze,b.jypp,k.ppmc,b.spml,j.mlmc,b.spnf,b.spjj,h.jjmc,b.spsx,b.spsx1,b.spsx2 " +
                               "from (select * from yw_db_dbddtz union all select * from yw_db_dbddtz_ls) a  left join  da_sp_spda b on a.spkh=b.spkh " +
                               "left join  da_bmda c  on a.khbh= c.bmbh  " +
                               "left join  da_sp_lbda d on d.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 da_sp_jjda h on b.spjj=h.jjbm " +
                                "left join da_sp_mlda j on j.mlbh=b.spml " +
                               " left join da_sp_ppda k on k.ppbm=b.jypp " +
                               "left join  (select * from da_qj_csb where  csfl='CG_CGFS') f on a.cgfs=f.csbh  where a.djlx='1'  " +
                               realSql + " group by  a.spkh,b.ksmc,a.khbh,a.bmbh2,b.jldw,a.yslsh,a.ysbh,g.ysmc,a.cmzbh,a.cmbh,a.bxbh,b.jypp,k.ppmc,b.spml,j.mlmc,b.spnf,b.spjj,h.jjmc,b.spsx,b.spsx1,b.spsx2, b.hplb ,d.lbmc , a.khbh ,c.bmmc ,a.bmbh2 ,e.bmmc) as cg_ddb left join ";
            var finishSql_rk = "(select t2.hplb ,t4.lbmc ," +
                               "t1.spkh,t2.ksmc,t2.jldw,t1.yslsh,t1.ysbh,t7.ysmc,t1.cmzbh,t1.cmbh,t1.bxbh,t1.khbh ,t3.bmmc khmc,t1.bmbh2 ,t5.bmmc bmmc,SUM(t1.sl) rkbzjsl, avg(t1.lsj) lsj,sum(t1.sl*t1.lsj) lsjze,avg(t1.jj) jj,sum(t1.sl*t1.jj) jjze " +
                               "from (select * from yw_db_dbrkdtz union all select * from yw_db_dbrkdtz_ls) t1  left join  da_sp_spda t2 on t1.spkh=t2.spkh " +
                               "left join  da_bmda t3  on t1.khbh= t3.bmbh  " +
                               "left join  da_sp_lbda t4 on t4.lbbh=t2.hplb " +
                               "left join  da_bmda t5 on t5.bmbh=t1.bmbh2 " +
                               "left join da_sp_ysda t7 on t1.yslsh=t7.yslsh " +
                               "left join  (select * from da_qj_csb where  csfl='CG_CGFS') t6 on t1.cgfs=t6.csbh  where t1.djlx='1'  " +
                                realSql1 + " group by  t1.spkh,t2.ksmc,t2.jldw,t1.yslsh,t1.ysbh,t1.khbh,t1.bmbh2,t7.ysmc,t1.cmzbh,t1.cmbh,t1.bxbh,t2.hplb ,t4.lbmc ,t1.khbh ,t3.bmmc ,t1.bmbh2 ,t5.bmmc ) as cg_rkb on (cg_ddb.spkh=cg_rkb.spkh and cg_ddb.khbh=cg_rkb.khbh and cg_ddb.bmbh2=cg_rkb.bmbh2 and cg_ddb.hplb=cg_rkb.hplb  AND cg_ddb.yslsh=cg_rkb.yslsh and  cg_ddb.cmbh=cg_rkb.cmbh and cg_ddb.bxbh=cg_rkb.bxbh ) ";
            var sendsql = " select cg_ddb.hplb hplb ,cg_ddb.lbmc lbmc,cg_ddb.spkh spkh,cg_ddb.ksmc ksmc ,cg_ddb.jldw jldw ,cg_ddb.ysbh ysbh,cg_ddb.ysmc ysmc, cg_ddb.khbh bmbh,cg_ddb.bmmc bmmc ,cg_ddb.bmbh2 bmbh2,cg_ddb.bmmc bmmc2 ," +
                        "sum(isnull(ddbzjsl,0))ddzjsl,  sum(isnull(rkbzjsl,0))rkzjsl,sum(isnull(ddbzjsl,0)-isnull(rkbzjsl,0)) sqsl, " +
                        "avg(cg_ddb.jj) ddjj,avg(cg_ddb.lsj) ddlsj,sum(cg_ddb.lsjze) ddlsjze,sum(cg_ddb.jjze)  ddjjze, " +
                        "avg(cg_rkb.jj) rkjj,avg(cg_rkb.lsj) rklsj,sum(cg_rkb.lsjze) rklsjze,sum(cg_rkb.jjze)  rkjjze, " +
                        "sum(isnull(cg_ddb.jjze,0)-isnull(cg_rkb.jjze,0))/(case when  sum(isnull(ddbzjsl,0))-sum(isnull(rkbzjsl,0))=0  then 1 else sum(isnull(ddbzjsl,0))-sum(isnull(rkbzjsl,0)) end) sqjj, " +
                        "avg(cg_ddb.lsj) sqlsj, " +
                        "sum(isnull(cg_ddb.lsjze,0)-isnull(cg_rkb.lsjze,0)) sqlsjze,sum(isnull(cg_ddb.jjze,0)-isnull(cg_rkb.jjze,0)) sqjjze, " +
                        "cg_ddb.cmzbh,cg_ddb.cmbh," +
                        "cg_ddb.jypp,cg_ddb.ppmc,cg_ddb.spml,cg_ddb.mlmc,cg_ddb.spnf,cg_ddb.spjj,cg_ddb.jjmc,cg_ddb.spsx,cg_ddb.spsx1,cg_ddb.spsx2  " +
                       "  from    " + finishSql_dd + finishSql_rk +
                       " group by  cg_ddb.spkh,cg_ddb.ksmc,cg_ddb.jldw,cg_ddb.ysbh,cg_ddb.ysmc,cg_ddb.cmzbh,cg_ddb.cmbh,cg_ddb.jypp,cg_ddb.ppmc,cg_ddb.spml,cg_ddb.mlmc,cg_ddb.spnf,cg_ddb.spjj,cg_ddb.jjmc,cg_ddb.spsx,cg_ddb.spsx1,cg_ddb.spsx2,cg_ddb.hplb,cg_ddb.lbmc,cg_ddb.khbh,cg_ddb.khmc,cg_ddb.bmbh2,cg_ddb.bmmc "
            requestor.ClipBoard(sendsql)
            sendsql = sendsql.replace(/\+/g, "%2B");
            sendsql = sendsql.replace(/\&/g, "%26");
            sendsql = sendsql.replace(/\%/g, "%25");
            webReq.Invoke("DB_ZXFX_CMZX", "ls_syntax=" + sendsql + "&flag=CMZX");
            if (webReq.StatusCode() == 200) {
                dw_zxsl.Retrieve()
                dw_list.SetFullState(dw_zxsl.GetFullState());
                self.Controlhl();
                DWSort(dw_format, dw_list);
                requestor.CloseLoading();
            }
            else {
                requestor.MessageBox("提示", webReq.ResponseText(), ICON.Information);
            }
            A8erp_Report.ReportDataWindowHeaderColor(dw_list);
        }
        //#endregion


        //#region 横向
        else if (rb_hx.GetChecked()) {
            curBbmc = rb_hx.GetName();
            var finishSql_dd = "(select b.hplb hplb ,d.lbmc lbmc ," +
                               "a.spkh,b.ksmc,b.jldw,a.yslsh,a.ysbh,g.ysmc,a.cmzbh,a.cmbh,a.bxbh,a.khbh,c.bmmc khmc, a.bmbh2, e.bmmc bmmc,SUM(a.sl) ddbzjsl, avg(a.lsj) lsj,sum(a.sl*a.lsj) lsjze,avg(a.jj) jj,sum(a.sl*a.jj) jjze,b.jypp,k.ppmc,b.spml,j.mlmc,b.spnf,b.spjj,h.jjmc,b.spsx,b.spsx1,b.spsx2 " +
                               "from (select * from yw_db_dbddtz union all select * from yw_db_dbddtz_ls) a  left join  da_sp_spda b on a.spkh=b.spkh " +
                               "left join  da_bmda c  on a.khbh= c.bmbh  " +
                               "left join  da_sp_lbda d on d.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 da_sp_jjda h on b.spjj=h.jjbm " +
                                "left join da_sp_mlda j on j.mlbh=b.spml " +
                               " left join da_sp_ppda k on k.ppbm=b.jypp " +
                               "left join  (select * from da_qj_csb where  csfl='CG_CGFS') f on a.cgfs=f.csbh  where a.djlx='1'  " +
                               realSql + " group by  a.spkh,b.ksmc,a.khbh,a.bmbh2,b.jldw,a.yslsh,a.ysbh,g.ysmc,a.cmzbh,a.cmbh,a.bxbh,b.jypp,k.ppmc,b.spml,j.mlmc,b.spnf,b.spjj,h.jjmc,b.spsx,b.spsx1,b.spsx2, b.hplb ,d.lbmc , a.khbh ,c.bmmc ,a.bmbh2 ,e.bmmc) as cg_ddb left join ";
            var finishSql_rk = "(select t2.hplb ,t4.lbmc ," +
                               "t1.spkh,t2.ksmc,t2.jldw,t1.yslsh,t1.ysbh,t7.ysmc,t1.cmzbh,t1.cmbh,t1.bxbh,t1.khbh ,t3.bmmc khmc,t1.bmbh2 ,t5.bmmc bmmc,SUM(t1.sl) rkbzjsl, avg(t1.lsj) lsj,sum(t1.sl*t1.lsj) lsjze,avg(t1.jj) jj,sum(t1.sl*t1.jj) jjze " +
                               "from (select * from yw_db_dbrkdtz union all select * from yw_db_dbrkdtz_ls) t1  left join  da_sp_spda t2 on t1.spkh=t2.spkh " +
                               "left join  da_bmda t3  on t1.khbh= t3.bmbh  " +
                               "left join  da_sp_lbda t4 on t4.lbbh=t2.hplb " +
                               "left join  da_bmda t5 on t5.bmbh=t1.bmbh2 " +
                               "left join da_sp_ysda t7 on t1.yslsh=t7.yslsh " +
                               "left join  (select * from da_qj_csb where  csfl='CG_CGFS') t6 on t1.cgfs=t6.csbh  where t1.djlx='1'  " +
                                realSql1 + " group by  t1.spkh,t2.ksmc,t2.jldw,t1.yslsh,t1.ysbh,t1.khbh,t1.bmbh2,t7.ysmc,t1.cmzbh,t1.cmbh,t1.bxbh, t2.hplb ,t4.lbmc ,t1.khbh ,t3.bmmc ,t1.bmbh2 ,t5.bmmc ) as cg_rkb on (cg_ddb.spkh=cg_rkb.spkh and cg_ddb.khbh=cg_rkb.khbh and cg_ddb.bmbh2=cg_rkb.bmbh2 and cg_ddb.hplb=cg_rkb.hplb  AND cg_ddb.yslsh=cg_rkb.yslsh and  cg_ddb.cmbh=cg_rkb.cmbh and cg_ddb.bxbh=cg_rkb.bxbh ) ";
            var sendsql = " select cg_ddb.hplb hplb ,cg_ddb.lbmc lbmc,cg_ddb.spkh spkh,cg_ddb.ksmc ksmc ,cg_ddb.jldw jldw ,cg_ddb.ysbh ysbh,cg_ddb.ysmc ysmc, cg_ddb.khbh bmbh,cg_ddb.bmmc bmmc ,cg_ddb.bmbh2 bmbh2,cg_ddb.bmmc bmmc2 ," +
                        "sum(isnull(ddbzjsl,0))ddzjsl,  sum(isnull(rkbzjsl,0))rkzjsl,sum(isnull(ddbzjsl,0)-isnull(rkbzjsl,0)) sqsl, " +
                        "avg(cg_ddb.jj) ddjj,avg(cg_ddb.lsj) ddlsj,sum(cg_ddb.lsjze) ddlsjze,max(cg_ddb.jjze)  ddjjze, " +
                        "avg(cg_rkb.jj) rkjj,avg(cg_rkb.lsj) rklsj,sum(cg_rkb.lsjze) rklsjze,max(cg_rkb.jjze)  rkjjze, " +
                        "sum(isnull(cg_ddb.jjze,0)-isnull(cg_rkb.jjze,0))/(case when  sum(isnull(ddbzjsl,0))-sum(isnull(rkbzjsl,0))=0  then 1 else sum(isnull(ddbzjsl,0))-sum(isnull(rkbzjsl,0)) end) sqjj, " +
                        "avg(cg_ddb.lsj) sqlsj, " +
                        "sum(isnull(cg_ddb.lsjze,0)-isnull(cg_rkb.lsjze,0)) sqlsjze,sum(isnull(cg_ddb.jjze,0)-isnull(cg_rkb.jjze,0)) sqjjze, " +
                        "cg_ddb.cmzbh,cg_ddb.cmbh," +
                        "cg_ddb.jypp,cg_ddb.ppmc,cg_ddb.spml,cg_ddb.mlmc,cg_ddb.spnf,cg_ddb.spjj,cg_ddb.jjmc,cg_ddb.spsx,cg_ddb.spsx1,cg_ddb.spsx2  " +
                       "  from    " + finishSql_dd + finishSql_rk +
                       " group by  cg_ddb.spkh,cg_ddb.ksmc,cg_ddb.jldw,cg_ddb.ysbh,cg_ddb.ysmc,cg_ddb.cmzbh,cg_ddb.cmbh,cg_ddb.jypp,cg_ddb.ppmc,cg_ddb.spml,cg_ddb.mlmc,cg_ddb.spnf,cg_ddb.spjj,cg_ddb.jjmc,cg_ddb.spsx,cg_ddb.spsx1,cg_ddb.spsx2,cg_ddb.hplb,cg_ddb.lbmc,cg_ddb.khbh,cg_ddb.khmc,cg_ddb.bmbh2,cg_ddb.bmmc "

            sendsql = sendsql.replace(/\+/g, "%2B");
            sendsql = sendsql.replace(/\&/g, "%26");
            sendsql = sendsql.replace(/\%/g, "%25");
            webReq.Invoke("DB_ZXFX_CMZX", "ls_syntax=" + sendsql + "&flag=CMHX");
            if (webReq.StatusCode() == 200) {
                dw_hxsl.Retrieve()
                dw_list.SetFullState(dw_hxsl.GetFullState());
                self.Controlhl();
                DWSort(dw_format, dw_list);
              
            }
            else {
                requestor.MessageBox("提示", webReq.ResponseText(), ICON.Information);
            }
            requestor.CloseLoading();
            A8erp_Report.ReportDataWindowHeaderColor(dw_list);
            self.A8erp_Report_Style(dw_list);
            self.A8erp_Report_Detail_Row_Height(dw_list);
        }
        //#endregion

        

    }
   
    //#endregion

    //#region 显示屏蔽列
    this.Controlhl = function () {

        if (!cbx_drbm.GetChecked()) {

            dw_list.Modify("bmbh.visible='0' bmmc.visible='0'")
        }

        if (!cbx_dcbm.GetChecked()) {

            dw_list.Modify("khbh.visible='0' khmc.visible='0'")
        }

        if (!cbx_lb.GetChecked()) {

            dw_list.Modify("hplb.visible='0' lbmc.visible='0'")
        }

        if (rb_zx.GetChecked()) {

            for (var i = 1; i <= parseInt(curCol); i++) {
                dw_list.Modify("cm" + i + ".visible='1'");
                dw_list.Modify("cm" + i + ".width = '150'");
                dw_list.SetFormat("cm" + i, '######')
            }
        }
        else if (rb_hx.GetChecked()) {
            for (var i = 1; i <= parseInt(curCol); i++) {

                dw_list.Modify("cm" + i + ".visible='1'");
                dw_list.Modify("cm" + i + ".width = '150'");
                dw_list.SetFormat("cm" + i, '######')

                dw_list.Modify("k" + i + ".visible='1'");
                dw_list.Modify("k" + i + ".width = '150'");
                dw_list.SetFormat("k" + i, '######')

                dw_list.Modify("j" + i + ".visible='1'");
                dw_list.Modify("j" + i + ".width = '150'");
                dw_list.SetFormat("j" + i, '######')
            }
        }

    }
    //#endregion

    //#region 表头颜色
    this.RowFocusChanged = function () {
        if (rb_zx.GetChecked() || rb_hx.GetChecked()) {
            for (var i = 1; i < 36; i++) {
                var str = "";
                if (ColorRow == "1") {
                    str = "cm" + i;
                }
                else {
                    str = "cm" + i + "0" + (parseInt(ColorRow) - 1);
                }
                dw_list.Modify(str + "_t.color='33554432'" + str + "_t.Font.Weight='400'");
            }
            var row = dw_list.GetRow();
            if (row < 1) {
                return;
            }
            var cmzbh = dw_list.GetItemString(row, "cmzbh");
            var spkh = dw_list.GetItemString(row, "spkh");
            dw_2.Retrieve(cmzbh, spkh);
            var modifyColor = dw_2.GetItemString(1, "colorchange").split("#")[0].toString();

            for (var i = 1; i < 36; i++) {

                var str = "";
                if (modifyColor == "1") {
                    str = "cm" + i;
                }
                else {
                    str = "cm" + i + "0" + (parseInt(modifyColor) - 1);
                }
                dw_list.Modify(str + "_t.color='16711680'" + str + "_t.Font.Weight='700'");

            }
            ColorRow = modifyColor;
        }
    }
    //#endregion

    //#region Function DrawDataWindow
    this.DrawDataWindow = function (parameter) {
        webReq.Invoke("GetSnataxAndDataFromSql", "sql=" + parameter);
        if (webReq.StatusCode() == 200) {
            dw_temp.SetFullState(webReq.ResponseText());
            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 "hplb":
                    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 "jldw":
                    ls_columntitle = "单位";
                    dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
                    dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");
                    break;
                case "ddbzjsl":
                    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 "rkbzjsl":
                    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 "sqsl":
                    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 "dhbl":
                    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 "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 "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;

            }
        }
        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("ddbzjsl.x");
        ls_slwidth = dw_list.Describe("ddbzjsl.width")
        ls_lszjex = dw_list.Describe("rkbzjsl.x");
        ls_lszjewidth = dw_list.Describe("rkbzjsl.width")
        ls_jjzex = dw_list.Describe("sqsl.x");
        ls_jjzewidth = dw_list.Describe("sqsl.width")
        ls_syntax = dw_list.Modify("DataWindow.summary.Height=90");
        ls_syntax = ls_syntax + "create compute(band=summary alignment='1' expression='sum(rkbzjsl  for all)' border='0' color='128' x='" + ls_lszjex + "' y='8' height='52' width='" + ls_lszjewidth + "' name=sum_rkbzjsl  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 compute(band=summary alignment='1' expression='sum(sqsl  for all)' border='0' color='128' x='" + ls_jjzex + "' y='8' height='52' width='" + ls_jjzewidth + "' name=sun_sqsl  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 compute(band=summary alignment='1' expression='sum(ddbzjsl  for all)' border='0' color='128' x='" + ls_slx + "' y='8' height='52' width='" + ls_slwidth + "' name=sum_ddbzjsl  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 Function 呼出数据窗口的函数群 
    //调入部门
    //调入部门
    this.Changebmbh1 = function (x, y, row, dwoName) {

        dwoName == "bmbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_ZXFXTJ, "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_ZXFXTJ, "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_ZXFXTJ, "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_ZXFXTJ, "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_ZXFXTJ, "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_ZXFXTJ, "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_ZXFXTJ, "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_ZXFXTJ, "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);
    }
    //#endregion

    //#region 选中后赋值
    this.SetSleValue = function (difBh, val) {
        if ("''" == val)
            val = "";
        if ("bmbh" == difBh)
            sle_drbm.SetText(val);
        else 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 ("mlbh" == difBh)
            sle_ml.SetText(val);
        else if ("gysbh" == difBh)
            sle_gys.SetText(val);
    }
    //#endregion

    //#region Function GetSqlWhere
    this.GetSqlWhere = function () {
        realSql = "";
        realSql1 = "";
        var curYhbh = requestor.GetParm("curYhbh")
        var beginDate = UtcDateFormatToString(dp_1.GetValue());
        var endDate = UtcDateFormatToString(dp_2.GetValue());

        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 curMl = sle_ml.GetText();
        var curSex = ddlb_sex.GetText();
        var curNF = ddlb_nf.GetText();


        if (curSelDays != "-1") {
            var tempBeginDate = compareDate(curSelDays, beginDate);

            realSql += " and (CONVERT(date,a.kdrq) between '" + tempBeginDate + "' and '" + endDate + "')";
            realSql1 += " and (CONVERT(date,t1.kdrq) between '" + tempBeginDate + "' and '" + endDate + "')";
        }
        else {
            realSql += " and (CONVERT(date,a.kdrq) between '" + beginDate + "' and '" + endDate + "')";
            realSql1 += " and (CONVERT(date,t1.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 + "%')";
                realSql1 += " and t1.spkh like('" + curKh + "%')";
            } else {
                var curflag = curKh.substr(curKh.length - 1, 1);

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

        if (curDrbm.length > 0) {
            var is_quotes = curDrbm.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and a.khbh in(" + curDrbm + ")";
                realSql1 += " and t1.khbh in(" + curDrbm + ")";
            } else {
                var tempspkh = GetQuotes(curDrbm);
                realSql += " and a.khbh in(" + tempspkh + ")";
                realSql1 += " and t1.khbh in(" + tempspkh + ")";
            }
        } else {
            realSql += "and a.khbh in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and kccx = '1')";
            realSql1 += "and t1.khbh in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and kccx = '1')";
        }

        if (curDcbm.length > 0) {
            var is_quotes = curDcbm.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and a.bmbh2 in(" + curDcbm + ")";
                realSql1 += " and t1.bmbh2 in(" + curDcbm + ")";
            } else {
                var tempspkh = GetQuotes(curDcbm);
                realSql += " and a.bmbh2 in(" + tempspkh + ")";
                realSql1 += " and t1.bmbh2 in(" + tempspkh + ")";
            }
        } else {
            realSql += "and a.bmbh2 in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and kccx = '1')";
            realSql1 += "and t1.bmbh2 in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and kccx = '1')";
        }

        if (curPp.length > 0) {
            var is_quotes = curPp.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and jypp in(" + curPp + ")";
                realSql1 += " and jypp in(" + curPp + ")";
            } else {
                var tempspkh = GetQuotes(curPp);
                realSql += " and jypp in(" + tempspkh + ")";
                realSql1 += " and jypp in(" + tempspkh + ")";
            }
        } else {
            realSql += "and  jypp in(select ppbh from da_qx_ppda  where yhbh='" + curYhbh + "')";
            realSql1 += "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 + ")";
                realSql1 += " and t2.gysbh in(" + curGys + ")";
            } else {
                var tempspkh =GetQuotes(curGys);
                realSql += " and b.gysbh in(" + tempspkh + ")";
                realSql1 += " and t2.gysbh in(" + tempspkh + ")";
            }
        } else {
            realSql += "and  b.gysbh in(select gysbh from da_qx_gysda  where yhbh='" + curYhbh + "')";
            realSql1 += "and t2.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 + ")";
                realSql1 += " and t2.hplb in(" + curLb + ")";
            } else {
                var tempspkh = GetQuotes(curLb);
                realSql += " and b.hplb in(" + tempspkh + ")";
                realSql1 += " and t2.hplb in(" + tempspkh + ")";
            }
        }

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

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

        }
        if (curNF.length > 0) {
            if (curNF != "--") {
                realSql += " and  b.spnf='" + curNF + "'";
                realSql1 += " and  t2.spnf='" + curNF + "'";
            }
        }
    }
    //#endregion

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

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

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

    //#region checkBox关闭还是打开状态
    this.CbxEnable = function (bv, obj) {
        var tempbbmc = obj.Name;
        cbx_dcbm.SetChecked(false);
        cbx_drbm.SetChecked(false);
        cbx_lb.SetChecked(false);
        if (tempbbmc.length > 1) {
            var v_CheckBoxState = GetCheckBoxValueCommon(dw_format, curBBPZH)
            if (v_CheckBoxState.length > 1) {
                window.eval(v_CheckBoxState);
            }
        }
    }

    //#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 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 curTitleName = "调拨单执行分析"
        curFootString = "制单人：" + curYhmc + "&&&【" + GetErpProductTypeName() + "软件】" + UtcDateTimeFormatToString(new Date().getVarDate()) +
                    "&&&" + curFootStringPP + "," + curFootStringKH +  "," + 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=PF" + "&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 = "";
        }
        //刷新
    }
    //#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();
    }
    //#endregion
    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_drbm.SetChecked(false);
        cbx_dcbm.SetChecked(false);
        cbx_lb.SetChecked(false);

        //界面控制
        var 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.Query();
            if (curDw_format_mx.RowCount() <= 0) {
                sle_formatname.SetText("");
            }
        }
    }
    //#endregion

    //#region 横向/纵向

    this.SetBbfl = function (bbfl) {
        if (bbfl == "rb_kh") {
            rb_kh.SetChecked(true);
        }
        else if (bbfl == "rb_ys") {
            rb_ys.SetChecked(true);
        }
        else if (bbfl == "rb_cmzx") {
            rb_cmzx.SetChecked(true);
        }
        else if (bbfl == "rb_cmhx") {
            rb_cmhx.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=PF" + "&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_kh.GetChecked()) {
            curBbmc = "rb_kh";
        }
        if (rb_ys.GetChecked()) {
            curBbmc = "rb_ys";
        }
        if (rb_zx.GetChecked()) {
            curBbmc = "rb_zx";
        }
        if (rb_hx.GetChecked()) {
            curBbmc = "rb_hx";
        }
    }
    //#endregion 

    //#region 提交
    this.ReportSave = function () {
        self.PropertCheckStatus();
        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_drbm.GetChecked()) {
            ChildDWCheckValue += "cbx_drbm,"
        }
        //凭证号
        if (cbx_dcbm.GetChecked()) {
            ChildDWCheckValue += "cbx_dcbm,"
        }
        //类别
        if (cbx_lb.GetChecked()) {
            ChildDWCheckValue += "cbx_lb,"
        }
    }
    //#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.TongJi = function () {
        dw_list.SetRedraw(false);
        curcbx_gs = 0;
        //self.GetTableYM();
        if (rb_kh.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_ys.GetChecked()) {
            self.Query(); // 款式
            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();
            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);
        }
        if (rb_zx.GetChecked()) {
            self.Query(); // 款式
            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();
            A8erp_Report.ReportDataWindowHeaderColor(dw_list);
            self.A8erp_Report_Style(dw_list);
            self.A8erp_Report_Detail_Row_Height(dw_list);
        }
        if (rb_hx.GetChecked()) {
            self.Query(); // 款式
            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();
            A8erp_Report.ReportDataWindowHeaderColor(dw_list);
            self.A8erp_Report_Style(dw_list);
            self.A8erp_Report_Detail_Row_Height(dw_list);
        }
        dw_list.SetRedraw(true);

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

    }
    //#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 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
}