///<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_CuXiaoChaXunFenXi() {

    var self = this;
    this.Instance = null;
    var requestor = new PBWindow();
    var rb_3 = new RadioButton(requestor);
    var rb_2 = new RadioButton(requestor);
    var rb_1 = new RadioButton(requestor);
    var ddlb_cxfs = new DropDownListBox(requestor);
    var sle_pzh = new SingleLineEdit(requestor);
    var sle_kh = new SingleLineEdit(requestor);
    var dp_zzrq_end = new DatePicker(requestor);
    var dp_zzrq_start = new DatePicker(requestor);
    var sle_bm = new SingleLineEdit(requestor);
    var dp_djrq_end = new DatePicker(requestor);
    var dp_djrq_start = new DatePicker(requestor);
    var dw_1 = new DataWindow(requestor);
    var dw_list = new DataWindow(requestor);
    var dw_temp = new DataWindow(requestor);
    var mle_1 = new MultiLineEdit(requestor);
    var tb_1 = new ToolStrip(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 (rb_3 == null) rb_3 = new RadioButton(requestor);
        rb_3.Attach(win.Control("rb_3"));
        if (rb_2 == null) rb_2 = new RadioButton(requestor);
        rb_2.Attach(win.Control("rb_2"));
        if (rb_1 == null) rb_1 = new RadioButton(requestor);
        rb_1.Attach(win.Control("rb_1"));
        if (ddlb_cxfs == null) ddlb_cxfs = new DropDownListBox(requestor);
        ddlb_cxfs.Attach(win.Control("ddlb_cxfs"));
        if (sle_pzh == null) sle_pzh = new SingleLineEdit(requestor);
        sle_pzh.Attach(win.Control("sle_pzh"));
        if (sle_kh == null) sle_kh = new SingleLineEdit(requestor);
        sle_kh.Attach(win.Control("sle_kh"));
        if (dp_zzrq_end == null) dp_zzrq_end = new DatePicker(requestor);
        dp_zzrq_end.Attach(win.Control("dp_zzrq_end"));
        if (dp_zzrq_start == null) dp_zzrq_start = new DatePicker(requestor);
        dp_zzrq_start.Attach(win.Control("dp_zzrq_start"));
        if (sle_bm == null) sle_bm = new SingleLineEdit(requestor);
        sle_bm.Attach(win.Control("sle_bm"));
        if (dp_djrq_end == null) dp_djrq_end = new DatePicker(requestor);
        dp_djrq_end.Attach(win.Control("dp_djrq_end"));
        if (dp_djrq_start == null) dp_djrq_start = new DatePicker(requestor);
        dp_djrq_start.Attach(win.Control("dp_djrq_start"));
        if (dw_1 == null) dw_1 = new DataWindow(requestor);
        dw_1.Attach(win.Control("dw_1"));
        if (dw_list == null) dw_list = new DataWindow(requestor);
        dw_list.Attach(win.Control("dw_list"));
        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 (tb_1 == null) tb_1 = new ToolStrip(requestor);
        tb_1.Attach(win.Control("tb_1"));

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

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

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

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

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

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

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

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

    }

    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();

        rb_3.Detach(); rb_3 = null;
        rb_2.Detach(); rb_2 = null;
        rb_1.Detach(); rb_1 = null;
        ddlb_cxfs.Detach(); ddlb_cxfs = null;
        sle_pzh.Detach(); sle_pzh = null;
        sle_kh.Detach(); sle_kh = null;
        dp_zzrq_end.Detach(); dp_zzrq_end = null;
        dp_zzrq_start.Detach(); dp_zzrq_start = null;
        sle_bm.Detach(); sle_bm = null;
        dp_djrq_end.Detach(); dp_djrq_end = null;
        dp_djrq_start.Detach(); dp_djrq_start = null;
        dw_1.Detach(); dw_1 = null;
        dw_list.Detach(); dw_list = null;
        dw_temp.Detach(); dw_temp = null;
        mle_1.Detach(); mle_1 = null;
        tb_1.Detach(); tb_1 = null;
        requestor.Detach(); requestor = null;

        setTimeout(CollectGarbage, 100);
    }

    //以上代码由设计器自动生成,请不要手工修改
    //ExtPB.Net JavaScript End  设计器查找标志,请不要删除或修改
    var sql_where = "";
    var sql = "";
    var curFabh01 = "";
    var curFabh02 = "";
    var curFabh03 = "";
    var curFabh04 = "";
    var curFabh05 = "";
    var curFabh06 = "";
    var curFabh07 = "";
    var curFabh08 = "";
    var curFabh09 = "";
    var curFabh10 = "";
    var curFabh11 = "";
    var curFabh12 = "";
    var curFabh13 = "";
    var sql_jbxx_list = "";
    var sql_jbxx_kh = "";
    var sql_jbxx_bm = "";
    var curCxfa = "01";
    var webReq = new WebRequestor();
    var cursjcd = "";
    webReq.SetWebServiceUrl("/Service/ServiceCuXiaoFangAn.ashx");
    this.PostOpen = function () {
        sle_bm.SetEnabled(false);
        //        var myDate = new Date();
        //        var nian = "2010";
        //        var yue = "01";
        //        var ri = "01";
        //        var objDate = new Date(nian, yue, ri);

        //        dp_djrq_start.SetValue(objDate.getVarDate());
        //        dp_djrq_end.SetValue(UtcDateFormatToString(new Date().getVarDate()))


        //        dp_zzrq_start.SetValue(objDate.getVarDate());
        //        dp_zzrq_end.SetValue("2030-01-01");


        dp_djrq_start.SetValue("2010-01-01");
        dp_djrq_end.SetValue("2030-01-01");


        dp_zzrq_start.SetValue("2010-01-01");
        dp_zzrq_end.SetValue("2030-01-01");




        //dp_zzrq_end.SetValue(UtcDateFormatToString(GoNextMonth()))

        cursjcd = GetYHMKQX();
    }
    var curW_OPEN_BMDA = new OpenWindowQueryBase();

    var curW_OPEN_BMDA_NEW = new OpenWindowQueryNewBase();
    var curW_OPEN_BMDA_URL = "OpenWindowQueryNewBase";
    
    
    this.ChangeBmbh = function (x, y, row, dwoName) {
        dwoName == "bmbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_CuXiaoChaXunFenXi, "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=all"), curW_OPEN_BMDA_NEW, null);
    }
    
    this.ChangeSpkh = function (x, y, row, dwoName) {
        dwoName == "spkh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_CuXiaoChaXunFenXi, "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.tongji = function () {
        curFabh01 = "";
        curFabh02 = "";
        curFabh03 = "";
        curFabh04 = "";
        curFabh05 = "";
        curFabh06 = "";
        curFabh07 = "";
        curFabh08 = "";
        curFabh09 = "";
        curFabh10 = "";
        curFabh11 = "";
        curFabh12 = "";
        curFabh13 = "";
        curCxfa = ddlb_cxfs.GetText();
        curCxfa = curCxfa.split("]")[0].substring(1, curCxfa.split("]")[0].length);
        if (curCxfa == "01") {
            curFabh01 = "CXA%"
        }
        else if (curCxfa == "02") {
            curFabh02 = "CXB%"
        }
        else if (curCxfa == "03") {
            curFabh03 = "CXC%";
        }
        else if (curCxfa == "04") {
            curFabh04 = "CXD%"
        }
        else if (curCxfa == "05") {
            curFabh05 = "CXE%"
        }
        else if (curCxfa == "06") {
            curFabh06 = "CXF%"
        }
        else if (curCxfa == "07") {
            curFabh07 = "CXG%"
        }
        else if (curCxfa == "08") {
            curFabh08 = "CXH%"
        }
        else if (curCxfa == "09") {
            curFabh09 = "CXI%"
        }
        else if (curCxfa == "10") {
            curFabh10 = "CXJ%"
        }
        else if (curCxfa == "11") {
            curFabh11 = "CXK%"
        }
        else if (curCxfa == "12") {
            curFabh12 = "CXL%"
        }
        else if (curCxfa == "13") {
            curFabh13 = "CXM%"
        }
        else {
            curFabh01 = "%"
            curFabh02 = "%"
            curFabh03 = "%"
            curFabh04 = "%"
            curFabh05 = "%"
            curFabh06 = "%"
            curFabh07 = "%"
            curFabh08 = "%"
            curFabh09 = "%"
            curFabh10 = "%"
            curFabh11 = "%"
            curFabh12 = "%"
            curFabh13 = "%"
        }
        sql_jbxx_list =
      "(select fabh,famc,pzh, ksrq, jsrq, kdrq, sdsdzt, kssj, zzsj, hdmc, hdyy, cxrsdzt, xq1, xq2, xq3, xq4, xq5, xq6, xq7, zklb, fdgz, bjl, qyzt from (" +
     "select '01' fabh,'一般促销设置' famc,pzh, ksrq, jsrq, kdrq, sdsdzt, kssj, zzsj, hdmc, hdyy, cxrsdzt, xq1, xq2, xq3, xq4, xq5, xq6, xq7, zklb, fdgz, bjl, qyzt " +
     "from dbo.da_cx_ybcxfa  where pzh like '" + curFabh01 + "' union all " +
     "select '02' fabh,'买X件让利Y件' famc,pzh, ksrq, jsrq, kdrq, sdsdzt, kssj, zzsj, hdmc, hdyy, cxrsdzt, xq1, xq2, xq3, xq4, xq5, xq6, xq7, '' zklb, ''fdgz,1 bjl, qyzt " +
     " from dbo.da_cx_mxjrlyj  where pzh like '" + curFabh02 + "' union all " +
     "select '03' fabh,'买X件打Y折' famc,pzh, ksrq, jsrq, kdrq, sdsdzt, kssj, zzsj, hdmc, hdyy, cxrsdzt, xq1, xq2, xq3, xq4, xq5, xq6, xq7, '' zklb, ''fdgz,1 bjl, qyzt " +
     "from dbo.da_cx_mxjdyz where pzh like '" + curFabh03 + "' union all " +
     "select '04' fabh,'买X件亨受某一特价' famc,pzh, ksrq, jsrq, kdrq, sdsdzt, kssj, zzsj, hdmc, hdyy, cxrsdzt, xq1, xq2, xq3, xq4, xq5, xq6, xq7, '' zklb, ''fdgz,1 bjl, qyzt " +
     "from dbo.da_cx_mxjxsmytj where pzh like'" + curFabh04 + "' union all " +
     "select '05' fabh,'买X件送Y件' famc,pzh, ksrq, jsrq, kdrq, sdsdzt, kssj, zzsj, hdmc, hdyy, cxrsdzt, xq1, xq2, xq3, xq4, xq5, xq6, xq7, '' zklb, ''fdgz,1 bjl, qyzt " +
     " from dbo.da_cx_mxjsyj where pzh like '" + curFabh05 + "' union all " +
    "select '06' fabh,'买X件送Y元赠券' famc,pzh, ksrq, jsrq, kdrq, sdsdzt, kssj, zzsj, hdmc, hdyy, cxrsdzt, xq1, xq2, xq3, xq4, xq5, xq6, xq7, '' zklb, ''fdgz,1 bjl, qyzt " +
    "from dbo.da_cx_mxjsyyzq  where pzh like '" + curFabh06 + "' union all " +
    "select '07' fabh,'买满X元加Y元送Z件商品' famc,pzh, ksrq, jsrq, kdrq, sdsdzt, kssj, zzsj, hdmc, hdyy, cxrsdzt, xq1, xq2, xq3, xq4, xq5, xq6, xq7, '' zklb, ''fdgz,1 bjl, qyzt " +
    "from dbo.da_cx_mmxyjyyzszsp where pzh like '" + curFabh07 + "' union all " +
    "select '08' fabh,'买满X元打Y折' famc,pzh, ksrq, jsrq, kdrq, sdsdzt, kssj, zzsj, hdmc, hdyy, cxrsdzt, xq1, xq2, xq3, xq4, xq5, xq6, xq7, '' zklb, ''fdgz,1 bjl, qyzt " +
   "from dbo.da_cx_mmxydyz where pzh like '" + curFabh08 + "' union all " +
    "select '09' fabh,'买满X元送Y元赠券' famc,pzh, ksrq, jsrq, kdrq, sdsdzt, kssj, zzsj, hdmc, hdyy, cxrsdzt, xq1, xq2, xq3, xq4, xq5, xq6, xq7, '' zklb, ''fdgz,1 bjl, qyzt " +
   "from dbo.da_cx_mmxysyyzq where pzh like '" + curFabh09 + "' union all " +
  "select '10' fabh,'买满X元让利Y元' famc,pzh, ksrq, jsrq, kdrq, sdsdzt, kssj, zzsj, hdmc, hdyy, cxrsdzt, xq1, xq2, xq3, xq4, xq5, xq6, xq7, '' zklb, ''fdgz,1 bjl, qyzt " +
  "from dbo.da_cx_mmxyrlyy where pzh like '" + curFabh10 + "' union all " +
  "select '11' fabh,'买满X元送Y元商品' famc,pzh, ksrq, jsrq, kdrq, sdsdzt, kssj, zzsj, hdmc, hdyy, cxrsdzt, xq1, xq2, xq3, xq4, xq5, xq6, xq7, '' zklb, ''fdgz,1 bjl, qyzt " +
  "from dbo.da_cx_mmxysyysp where pzh like '" + curFabh11 + "' union all " +
  "select '12' fabh,'买X件让利Y元' famc,pzh, ksrq, jsrq, kdrq, sdsdzt, kssj, zzsj, hdmc, hdyy, cxrsdzt, xq1, xq2, xq3, xq4, xq5, xq6, xq7, '' zklb, ''fdgz,1 bjl, qyzt " +
  "from dbo.da_cx_mxjrlyy where pzh like '" + curFabh12 + "' union all "+
  "SELECT '13' fabh ,'买满X元送某一特定商品' famc,pzh , kssj AS ksrq ,jssj AS kdrq ,jssj AS jsrq ,'0' sdsdzt ,NULL kssj ,NULL zzsj ,hdmc ,'' hdyy ,'0' cxrsdzt ,'' xq1 ,'' xq2 ,'' xq3 ,'' xq4 ,'' xq5 ,'' xq6 ,'' xq7 ,'' zklb , bzxx AS fdgz, 1 bjl ,qybz AS qyzt " +
  "FROM da_cx_mmxystdsp WHERE pzh LIKE '" + curFabh13 + "')a)a";
        sql_jbxx_kh = "(select pzh,spkh,ksmc,jldw,dpj,zkbfb,cxj from " +
"(select pzh,t1.spkh,t2.ksmc,t2.jldw,dpj,zkbfb,cxj  from  da_cx_ybcxfa_kh  t1 left join da_sp_spda t2 on t1.spkh=t2.spkh where pzh like '" + curFabh01 + "' union all " +
"select pzh,t1.spkh,t2.ksmc,t2.jldw,dpj,zkbfb,cxj  from  da_cx_mxjrlyj_kh  t1 left join da_sp_spda t2 on t1.spkh=t2.spkh where pzh like  '" + curFabh02 + "' union all " +
"select pzh,t1.spkh,t2.ksmc,t2.jldw,dpj,zkbfb,cxj  from  da_cx_mxjdyz_kh  t1 left join da_sp_spda t2 on t1.spkh=t2.spkh  where pzh like  '" + curFabh03 + "' union all " +
"select pzh,t1.spkh,t2.ksmc,t2.jldw,dpj,zkbfb,cxj  from  da_cx_mxjxsmytj_kh  t1 left join da_sp_spda t2 on t1.spkh=t2.spkh where pzh like '" + curFabh04 + "' union all " +
"select pzh,t1.spkh,t2.ksmc,t2.jldw,dpj,zkbfb,cxj  from  da_cx_mxjsyj_kh  t1 left join da_sp_spda t2 on t1.spkh=t2.spkh where pzh like '" + curFabh05 + "' union all " +
"select pzh,t1.spkh,t2.ksmc,t2.jldw,dpj,zkbfb,cxj  from  da_cx_mxjsyyzq_kh  t1 left join da_sp_spda t2 on t1.spkh=t2.spkh where pzh like '" + curFabh06 + "' union all " +
"select pzh,t1.spkh,t2.ksmc,t2.jldw,dpj,zkbfb,cxj  from  da_cx_mmxyjyyzszsp_kh  t1 left join da_sp_spda t2 on t1.spkh=t2.spkh where pzh like'" + curFabh07 + "'union all " +
"select pzh,t1.spkh,t2.ksmc,t2.jldw,dpj,zkbfb,cxj  from  da_cx_mmxydyz_kh  t1 left join da_sp_spda t2 on t1.spkh=t2.spkh where pzh like '" + curFabh08 + "'union all " +
"select pzh,t1.spkh,t2.ksmc,t2.jldw,dpj,zkbfb,cxj  from  da_cx_mmxysyyzq_kh  t1 left join da_sp_spda t2 on t1.spkh=t2.spkh where pzh like '" + curFabh09 + "'union all " +
"select pzh,t1.spkh,t2.ksmc,t2.jldw,dpj,zkbfb,cxj  from  da_cx_mmxyrlyy_kh  t1 left join da_sp_spda t2 on t1.spkh=t2.spkh where pzh like '" + curFabh10 + "'union all " +
"select pzh,t1.spkh,t2.ksmc,t2.jldw,dpj,zkbfb,cxj  from  da_cx_mmxysyysp_kh  t1 left join da_sp_spda t2 on t1.spkh=t2.spkh where pzh like'" + curFabh11 + "' union all " +
"select pzh,t1.spkh,t2.ksmc,t2.jldw,dpj,zkbfb,cxj  from  da_cx_mxjrlyy_kh  t1 left join da_sp_spda t2 on t1.spkh=t2.spkh  where pzh like '" + curFabh12 + "' union all " +
"SELECT pzh,t1.spkh,t2.ksmc,t2.jldw,je AS dpj,0 zkbfb,0 cxj FROM da_cx_mmxystdsp_fa t1 left join da_sp_spda t2 on t1.spkh=t2.spkh where pzh like '" + curFabh13 + "') b)b";
        sql_jbxx_bm = "(select pzh,bmbh,bmmc from " +
"(select pzh,t1.bmbh,t2.bmmc from da_cx_ybcxfa_bm  t1 left join da_bmda t2  on  t1.bmbh=t2.bmbh where pzh like '" + curFabh01 + "' union all " +
"select pzh,t1.bmbh,t2.bmmc  from  da_cx_mxjrlyj_bm  t1 left join da_bmda t2  on  t1.bmbh=t2.bmbh  where pzh like '" + curFabh02 + "'union all " +
"select  pzh,t1.bmbh,t2.bmmc from  da_cx_mxjdyz_bm   t1 left join da_bmda t2  on  t1.bmbh=t2.bmbh where pzh like '" + curFabh03 + "' union all " +
"select pzh,t1.bmbh,t2.bmmc  from  da_cx_mxjxsmytj_bm   t1 left join da_bmda t2  on  t1.bmbh=t2.bmbh where pzh like '" + curFabh04 + "' union all " +
"select pzh,t1.bmbh,t2.bmmc  from  da_cx_mxjsyj_bm t1 left join da_bmda t2  on  t1.bmbh=t2.bmbh where pzh like '" + curFabh05 + "' union all " +
"select pzh,t1.bmbh,t2.bmmc  from  da_cx_mxjsyyzq_bm  t1 left join da_bmda t2  on  t1.bmbh=t2.bmbh where pzh like '" + curFabh06 + "' union all " +
"select pzh,t1.bmbh,t2.bmmc  from  da_cx_mmxyjyyzszsp_bm  t1 left join da_bmda t2  on  t1.bmbh=t2.bmbh where pzh like '" + curFabh07 + "'union all " +
"select pzh,t1.bmbh,t2.bmmc  from  da_cx_mmxydyz_bm t1 left join da_bmda t2  on  t1.bmbh=t2.bmbh where pzh like '" + curFabh08 + "' union all " +
"select  pzh,t1.bmbh,t2.bmmc  from  da_cx_mmxysyyzq_bm t1 left join da_bmda t2  on  t1.bmbh=t2.bmbh where pzh like '" + curFabh09 + "' union all " +
"select pzh,t1.bmbh,t2.bmmc  from  da_cx_mmxyrlyy_bm   t1 left join da_bmda t2  on  t1.bmbh=t2.bmbh where pzh like '" + curFabh10 + "' union all " +
"select pzh,t1.bmbh,t2.bmmc  from  da_cx_mmxysyysp_bm  t1 left join da_bmda t2  on  t1.bmbh=t2.bmbh where pzh like '" + curFabh11 + "' union all " +
"select pzh,t1.bmbh,t2.bmmc  from  da_cx_mxjrlyy_bm  t1 left join da_bmda t2  on  t1.bmbh=t2.bmbh  where pzh like '" + curFabh12 + "' union all " +
"SELECT pzh,t1.bmbh,t2.bmmc FROM da_cx_mmxystdsp_bm t1 left join da_bmda t2 on t1.bmbh=t2.bmbh where pzh like '" + curFabh13 + "') c)c"

        sql = "select a.fabh,b.spkh,b.ksmc,b.jldw,Convert(char(10),a.kdrq,120)kdrq,a.pzh,a.famc,a.hdmc,a.qyzt,c.bmbh,c.bmmc,b.dpj,b.cxj,b.zkbfb," +
           "Convert(char(10),a.ksrq,120) ksrq,Convert(char(10),a.jsrq,120) jsrq,a.sdsdzt,Convert(char(8),a.kssj,114) kssj,Convert(char(8),a.zzsj,114)zzsj,a.cxrsdzt,a.xq1,a.xq2,a.xq3,a.xq4,a.xq5,a.xq6,a.xq7" +
       " from " + sql_jbxx_list + "," + sql_jbxx_kh + "," + sql_jbxx_bm + " where a.pzh=b.pzh and a.pzh=c.pzh and b.pzh=c.pzh ",
         self.SetSqlWhere();
        sql = sql + sql_where+" order by b.spkh";

        sql = self.SetFilter(sql);
        //return
        webReq.Invoke("GetSnataxFromSql", "ls_syntax=" + sql + "&flag=Grid");
        if (webReq.StatusCode() == 200) {

            syntax = webReq.ResponseText();
            mle_1.SetText(sql)
            dw_temp.Create(syntax);
            dw_list.SetFullState(dw_temp.GetFullState());
            dw_1.SetFullState(dw_temp.GetFullState());
            dw_list.Retrieve();
            //            gRowCount = dw_list.RowCount();
            var colCount = dw_list.Describe("DataWindow.Column.Count");
            self.SetItemName(colCount);
            self.ItemValueChange();
//            dw_list.Modify("DataWindow.Sparse='spkh\tksmc\tfabh\tfamc\tjldw'")
            dw_list.Modify("DataWindow.Sparse='spkh\tksmc\tfabh\tjldw'")
            dw_list.SetRowSelection(1);
        }
        else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.Information);
        }
    }
    //获取where 条件
    this.SetSqlWhere = function () {
        sql_where = " "

        var curQybz = "";
        var curbm = sle_bm.GetText();
        var curkh = sle_kh.GetText();
        var curpzh = sle_pzh.GetText();
        var curdjrq_1 = UtcDateFormatToString(dp_djrq_start.GetValue());
        var curdjrq_2 = UtcDateFormatToString(dp_djrq_end.GetValue());
        var curzzrq_1 = UtcDateFormatToString(dp_zzrq_start.GetValue());
        var curzzrq_2 = UtcDateFormatToString(dp_zzrq_end.GetValue());
       
        if (curbm.length > 0) {
            //alert("xxx")
            //sql_where += "and  c.bmbh in(" + curbm + ") ";
            var is_quotes = curbm.substring(0, 1);
            if (is_quotes == "'") {
                sql_where += " and c.bmbh in(" + curbm + ")";
            } else {
                var tempspkh = self.GetQuotes(curbm);
                sql_where += " and c.bmbh in(" + tempspkh + ")";
            }
        }
        if (curkh.length > 0) {
            //alert("xxx")
            //sql_where += "and  c.bmbh in(" + curbm + ") ";
            var is_quotes = curkh.substring(0, 1);
            if (is_quotes == "'") {
                sql_where += " and b.spkh in(" + curkh + ")";
            } else {
                var tempspkh = self.GetQuotes(curkh);
                sql_where += " and b.spkh in(" + tempspkh + ")";
            }
        }
        if (curpzh.length > 0) {
            sql_where += " and a.pzh='" + curpzh + "'";
        }
//        if (curkh.length > 0) {
//            // sql_where += " and b.spkh='" + curkh + "'";
//            var is_quotes = curkh.substring(0, 1);
//            if (is_quotes == "%") {
//                sql_where += " and b.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);
//                    sql_where += " and b.spkh in(" + tempspkh + ")";
//                }
//                else {
//                    if (is_quotes == "'") {
//                        sql_where += " and b.spkh in(" + curkh + ")";
//                    }
//                    else {
//                        sql_where += " and b.spkh like('" + curkh + "%')";
//                    }
//                }
//            }
//        }

        if (curdjrq_1.length > 0 && curdjrq_2.length > 0) {
            sql_where += " and a.ksrq>='" + curdjrq_1 + "'";
            sql_where += " and a.ksrq<='" + curdjrq_2 + "'";
        }
        if (curzzrq_1.length > 0 && curzzrq_2.length > 0) {
            sql_where += " and a.jsrq>='" + curzzrq_1 + "'";
            sql_where += " and a.jsrq<='" + curzzrq_2 + "'";
        }

        if (rb_2.GetChecked()) {
            sql_where += " and a.qyzt='1' ";
        }
        if (rb_3.GetChecked()) {
            sql_where += " and a.qyzt='0' ";
        }


    }

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

    this.SetSleValue = function (bmbh, str_value) {
        if ("''" == str_value)
            str_value = "";
        if ("bmbh" == bmbh)
            sle_bm.SetText(str_value);
        else if ("spkh" == bmbh)
            sle_kh.SetText(str_value);
        
    }
    this.SetFilter = function (str) {
        str = str.replace(/\+/g, "%2B");
        str = str.replace(/\&/g, "%26");
        str = str.replace(/\%/g, "%25");
        return str
    }
    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');
            //alert(ls_columnname);

            switch (ls_columnname) {
                case "qyzt":
                    ls_columntitle = "单据状态"
                    dw_list.Modify("qyzt.Alignment='2' qyzt.width='200'")
                    break;
                case "fabh":
                    ls_columntitle = "方案编号"
                    dw_list.Modify("fabh.Alignment='2' fabh.width='200'")
                    break;
                case "spkh":
                    ls_columntitle = "商品款号"
                    dw_list.Modify("spkh.Alignment='3' spkh.width='300'")
                    break;
                case "ksmc":
                    ls_columntitle = "款式名称"
                    dw_list.Modify("ksmc.Alignment='3' ksmc.width='400'")
                    break;
                case "jldw":
                    ls_columntitle = "单位"
                    dw_list.Modify("jldw.Alignment='2' jldw.width='100'")
                    break;
                case "kdrq":
                    ls_columntitle = "单据日期"
                    dw_list.Modify("kdrq.Alignment='2' kdrq.width='300'")
                    break;
                case "pzh":
                    ls_columntitle = "单据编号"
                    dw_list.Modify("pzh.Alignment='2' pzh.width='400'")
                    break;
                case "bmbh":
                    ls_columntitle = "部门编号"
                    dw_list.Modify("bmbh.Alignment='2' bmbh.width='280'")
                    break;
                case "bmmc":
                    ls_columntitle = "部门名称"
                    dw_list.Modify("bmmc.Alignment='3' bmmc.width='400'")
                    break;
                case "dpj":
                    ls_columntitle = "吊牌价"
                    dw_list.Modify("dpj.Alignment='1' dpj.width='200' dpj.format='0.00'")
                    break;
                case "cxj":
                    ls_columntitle = "促销价"
                    dw_list.Modify("cxj.Alignment='1' cxj.width='200'")
                    break;
                case "zkbfb":
                    ls_columntitle = "折扣百分比"
                    dw_list.Modify("zkbfb.Alignment='1' zkbfb.width='300'")
                    break
                case "ksrq":
                    ls_columntitle = "开始日期"
                    dw_list.Modify("ksrq.Alignment='2' ksrq.width='270'")
                    break
                case "jsrq":
                    ls_columntitle = "结束日期"
                    dw_list.Modify("jsrq.Alignment='2' jsrq.width='270'")
                    break;
                case "sdsdzt":
                    ls_columntitle = "时间设置"
                    dw_list.Modify("sdsdzt.Alignment='2' sdsdzt.width='240'")
                    break;
                case "kssj":
                    ls_columntitle = "开始时间"
                    dw_list.Modify("kssj.Alignment='2' kssj.width='300'")
                    break;
                case "zzsj":
                    ls_columntitle = "终止时间"
                    dw_list.Modify("zzsj.Alignment='2' zzsj.width='300'")
                    break;
                case "cxrsdzt":
                    ls_columntitle = "促销日"
                    dw_list.Modify("cxrsdzt.Alignment='2' cxrsdzt.width='180'")
                    break;
                case "xq1":
                    ls_columntitle = "星期一"
                    dw_list.Modify("xq1.Alignment='2' xq1.width='180' ")
                    break;
                case "xq2":
                    ls_columntitle = "星期二"
                    dw_list.Modify("xq2.Alignment='2' xq2.width='180' ")
                    break;
                case "xq3":
                    ls_columntitle = "星期三"
                    dw_list.Modify("xq3.Alignment='2' xq3.width='180' ")
                    break;
                case "xq4":
                    ls_columntitle = "星期四"
                    dw_list.Modify("xq4.Alignment='2' xq4.width='180' ")
                    break;
                case "xq5":
                    ls_columntitle = "星期五"
                    dw_list.Modify("xq5.Alignment='2' xq5.width='180' ")
                    break;
                case "xq6":
                    ls_columntitle = "星期六"
                    dw_list.Modify("xq6.Alignment='2' xq6.width='180' ")
                    break;
                case "xq7":
                    ls_columntitle = "星期日"
                    dw_list.Modify("xq7.Alignment='2' xq7.width='180' ")
                    break;
                case "hdmc":
                    ls_columntitle = "活动名称"
                    dw_list.Modify("hdmc.Alignment='3' hdmc.width='400' ")
                    break;
                case "famc":
                    ls_columntitle = "方案名称"
                    dw_list.Modify("famc.Alignment='3' famc.width='600' ")
                    break;
             
            }

            dw_list.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
            //dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");

        }

    }

    this.SetItemName1 = function (colCount) {
        var ls_columntitle = "";
        for (var li_loop1 = 1; li_loop1 <= colCount; li_loop1++) {
            var ls_columnname = dw_1.Describe('#' + String(li_loop1) + '.name');
            //alert(ls_columnname);

            switch (ls_columnname) {
                case "qyzt":
                    ls_columntitle = "单据状态"
                    dw_1.Modify("qyzt.Alignment='2' qyzt.width='200'")
                    break;
                case "fabh":
                    ls_columntitle = "方案编号"
                    dw_1.Modify("fabh.Alignment='2' fabh.width='200'")
                    break;
                case "spkh":
                    ls_columntitle = "商品款号"
                    dw_1.Modify("spkh.Alignment='3' spkh.width='300'")
                    break;
                case "ksmc":
                    ls_columntitle = "款式名称"
                    dw_1.Modify("ksmc.Alignment='3' ksmc.width='400'")
                    break;
                case "jldw":
                    ls_columntitle = "单位"
                    dw_1.Modify("jldw.Alignment='2' jldw.width='100'")
                    break;
                case "kdrq":
                    ls_columntitle = "单据日期"
                    dw_1.Modify("kdrq.Alignment='2' kdrq.width='300'")
                    break;
                case "pzh":
                    ls_columntitle = "单据编号"
                    dw_1.Modify("pzh.Alignment='2' pzh.width='400'")
                    break;
                case "bmbh":
                    ls_columntitle = "部门编号"
                    dw_1.Modify("bmbh.Alignment='2' bmbh.width='280'")
                    break;
                case "bmmc":
                    ls_columntitle = "部门名称"
                    dw_1.Modify("bmmc.Alignment='3' bmmc.width='400'")
                    break;
                case "dpj":
                    ls_columntitle = "吊牌价"
                    dw_1.Modify("dpj.Alignment='1' dpj.width='200' dpj.format='0.00'")
                    break;
                case "cxj":
                    ls_columntitle = "促销价"
                    dw_1.Modify("cxj.Alignment='1' cxj.width='200'")
                    break;
                case "zkbfb":
                    ls_columntitle = "折扣百分比"
                    dw_1.Modify("zkbfb.Alignment='1' zkbfb.width='300'")
                    break
                case "ksrq":
                    ls_columntitle = "开始日期"
                    dw_1.Modify("ksrq.Alignment='2' ksrq.width='270'")
                    break
                case "jsrq":
                    ls_columntitle = "结束日期"
                    dw_1.Modify("jsrq.Alignment='2' jsrq.width='270'")
                    break;
                case "sdsdzt":
                    ls_columntitle = "时间设置"
                    dw_1.Modify("sdsdzt.Alignment='2' sdsdzt.width='240'")
                    break;
                case "kssj":
                    ls_columntitle = "开始时间"
                    dw_1.Modify("kssj.Alignment='2' kssj.width='300'")
                    break;
                case "zzsj":
                    ls_columntitle = "终止时间"
                    dw_1.Modify("zzsj.Alignment='2' zzsj.width='300'")
                    break;
                case "cxrsdzt":
                    ls_columntitle = "促销日"
                    dw_1.Modify("cxrsdzt.Alignment='2' cxrsdzt.width='180'")
                    break;
                case "xq1":
                    ls_columntitle = "星期一"
                    dw_1.Modify("xq1.Alignment='2' xq1.width='180' ")
                    break;
                case "xq2":
                    ls_columntitle = "星期二"
                    dw_1.Modify("xq2.Alignment='2' xq2.width='180' ")
                    break;
                case "xq3":
                    ls_columntitle = "星期三"
                    dw_1.Modify("xq3.Alignment='2' xq3.width='180' ")
                    break;
                case "xq4":
                    ls_columntitle = "星期四"
                    dw_1.Modify("xq4.Alignment='2' xq4.width='180' ")
                    break;
                case "xq5":
                    ls_columntitle = "星期五"
                    dw_1.Modify("xq5.Alignment='2' xq5.width='180' ")
                    break;
                case "xq6":
                    ls_columntitle = "星期六"
                    dw_1.Modify("xq6.Alignment='2' xq6.width='180' ")
                    break;
                case "xq7":
                    ls_columntitle = "星期日"
                    dw_1.Modify("xq7.Alignment='2' xq7.width='180' ")
                    break;
                case "hdmc":
                    ls_columntitle = "活动名称"
                    dw_1.Modify("hdmc.Alignment='3' hdmc.width='400' ")
                    break;
                case "famc":
                    ls_columntitle = "方案名称"
                    dw_1.Modify("famc.Alignment='3' famc.width='600' ")
                    break;

            }

            dw_1.Modify(ls_columnname + "_t.text='" + ls_columntitle + "'");
            //dw_list.Modify(ls_columnname + ".width = '" + 400 + "'");

        }

    }




    //#region  双击pzh
    this.DoubleClicked = function (x, y, row, dwoname) {
        if (dwoname.indexOf("_t") < 0) {
            if (dwoname == "pzh") {

                //获取pzh
                var curpzh = "";
                var ywflag = "";
                var curRow = dw_list.GetRow();
                if (curRow > 0) {
                    curpzh = dw_list.GetItemString(curRow, "pzh");
                    ywflag = curpzh.substring(0, 3)
                    //反调到原单据    
                    if (ywflag == "CXA") {
                        self.OpenSheet("SJ225", "一般促销设置", curpzh, "");

                    }
                    if (ywflag == "CXB") {
                        self.OpenSheet("SJ226", "买X件让利Y件", curpzh, "");
                    }
                    if (ywflag == "CXC") {
                        self.OpenSheet("SJ227", "买X件打Y折", curpzh, "");
                    }
                    if (ywflag == "CXD") {
                        self.OpenSheet("SJ228", "买X件亨受某一特价", curpzh, "");
                    }
                    if (ywflag == "CXE") {
                        self.OpenSheet("SJ229", "买X件送Y件", curpzh, "");
                    }
                    if (ywflag == "CXF") {
                        self.OpenSheet("SJ230", "买X件送Y元赠券", curpzh, "");
                    }
                    if (ywflag == "CXG") {
                        self.OpenSheet("SJ231", "买满X元加Y元送Z件商品", curpzh, "");
                    }
                    if (ywflag == "CXH") {
                        self.OpenSheet("SJ232", "买满X元打Y折", curpzh, "");
                    }
                    if (ywflag == "CXI") {
                        self.OpenSheet("SJ233", "买满X元送Y元赠券", curpzh, "");
                    }
                    if (ywflag == "CXJ") {
                        self.OpenSheet("SJ234", "买满X元让利Y元", curpzh, "");
                    }
                    if (ywflag == "CXK") {
                        self.OpenSheet("SJ235", "买满X元送Y元商品", curpzh, "");
                    }
                    if (ywflag == "CXL") {
                        self.OpenSheet("SJ236", "买X件让利Y元", curpzh, "");
                    }
                    if (ywflag == "CXM") {
                        self.OpenSheet("SJ585", "买满X元送某一特定商品", curpzh, "");
                    }
                }
            }
        }
    }
    //#endregion

    //#region 跟踪单据


    this.OpenSheet = function (itemData, itemLabel, hyh, gysbh) {
        var tempitemData = itemData.substring(2, 5);

        var s = cursjcd.indexOf(tempitemData);

        if (s > -1) {
            var ts_1 = window.external.Control("ts_1");
            ts_1.CloseItem(itemData);
            ts_1.Open(itemData, itemLabel, '', encodeURI("/Service/OpenSheet.aspx?FunID=" + itemData + "&curDate=" + new Date().toLocaleTimeString() + "&Reload=Y&curFormPzh=" + hyh + "&curParam1=" + gysbh), true);
        }
        else {
            alert("您无此权限，请联系管理员！！")
        }

    }
    //#endregion 

    this.ItemValueChange = function () {
        var rowCount = dw_list.RowCount();
        for (var i = 1; i <= rowCount; i++) {

            var curqyzt = dw_list.GetItemString(i, "qyzt");
            var cursdsdzt = dw_list.GetItemString(i, "sdsdzt");
            var curcxrsdzt = dw_list.GetItemString(i, "cxrsdzt");
            var curxq1 = dw_list.GetItemString(i, "xq1");
            var curxq2 = dw_list.GetItemString(i, "xq2");
            var curxq3 = dw_list.GetItemString(i, "xq3");
            var curxq4 = dw_list.GetItemString(i, "xq4");
            var curxq5 = dw_list.GetItemString(i, "xq5");
            var curxq6 = dw_list.GetItemString(i, "xq6");
            var curxq7 = dw_list.GetItemString(i, "xq7");


            if (curqyzt == "1") {
                dw_list.SetItem(i, "qyzt", "已启用")
            }
            if (curqyzt == "0") {
                dw_list.SetItem(i, "qyzt", "未启用")
            }
            if (cursdsdzt == "1") {
                dw_list.SetItem(i, "sdsdzt", "已启用")
            }
            if (cursdsdzt == "0") {
                dw_list.SetItem(i, "sdsdzt", "未启用")
            }
            if (curcxrsdzt == "0") {
                dw_list.SetItem(i, "cxrsdzt", "未启用")
            }
            if (curcxrsdzt == "1") {
                dw_list.SetItem(i, "cxrsdzt", "已启用")
            }
            if (curxq1 == "0") {
                dw_list.SetItem(i, "xq1", "")
            }
            if (curxq1 == "1") {
                dw_list.SetItem(i, "xq1", "√")
            }
            if (curxq2 == "0") {
                dw_list.SetItem(i, "xq2", "")
            }
            if (curxq2 == "1") {
                dw_list.SetItem(i, "xq2", "√")
            }
            if (curxq3 == "0") {
                dw_list.SetItem(i, "xq3", "")
            }
            if (curxq3 == "1") {
                dw_list.SetItem(i, "xq3", "√")
            }
            if (curxq4 == "0") {
                dw_list.SetItem(i, "xq4", "")
            }
            if (curxq4 == "1") {
                dw_list.SetItem(i, "xq4", "√")
            } 
            if (curxq5 == "0") {
                dw_list.SetItem(i, "xq5", "")
            }
            if (curxq5 == "1") {
                dw_list.SetItem(i, "xq5", "√")
            }
            if (curxq6 == "0") {
                dw_list.SetItem(i, "xq6", "")
            }
            if (curxq6 == "1") {
                dw_list.SetItem(i, "xq6", "√")
            }
            if (curxq7 == "0") {
                dw_list.SetItem(i, "xq7", "")
            }
            if (curxq7 == "1") {
                dw_list.SetItem(i, "xq7", "√")
            }
            
        }

    }

    this.ItemValueChange1 = function () {
        var rowCount = dw_1.RowCount();
        for (var i = 1; i <= rowCount; i++) {

            var curqyzt = dw_1.GetItemString(i, "qyzt");
            var cursdsdzt = dw_1.GetItemString(i, "sdsdzt");
            var curcxrsdzt = dw_1.GetItemString(i, "cxrsdzt");
            var curxq1 = dw_1.GetItemString(i, "xq1");
            var curxq2 = dw_1.GetItemString(i, "xq2");
            var curxq3 = dw_1.GetItemString(i, "xq3");
            var curxq4 = dw_1.GetItemString(i, "xq4");
            var curxq5 = dw_1.GetItemString(i, "xq5");
            var curxq6 = dw_1.GetItemString(i, "xq6");
            var curxq7 = dw_1.GetItemString(i, "xq7");


            if (curqyzt == "1") {
                dw_1.SetItem(i, "qyzt", "已启用")
            }
            if (curqyzt == "0") {
                dw_1.SetItem(i, "qyzt", "未启用")
            }
            if (cursdsdzt == "1") {
                dw_1.SetItem(i, "sdsdzt", "已启用")
            }
            if (cursdsdzt == "0") {
                dw_1.SetItem(i, "sdsdzt", "未启用")
            }
            if (curcxrsdzt == "0") {
                dw_1.SetItem(i, "cxrsdzt", "未启用")
            }
            if (curcxrsdzt == "1") {
                dw_1.SetItem(i, "cxrsdzt", "已启用")
            }
            if (curxq1 == "0") {
                dw_1.SetItem(i, "xq1", "")
            }
            if (curxq1 == "1") {
                dw_1.SetItem(i, "xq1", "√")
            }
            if (curxq2 == "0") {
                dw_1.SetItem(i, "xq2", "")
            }
            if (curxq2 == "1") {
                dw_1.SetItem(i, "xq2", "√")
            }
            if (curxq3 == "0") {
                dw_1.SetItem(i, "xq3", "")
            }
            if (curxq3 == "1") {
                dw_1.SetItem(i, "xq3", "√")
            }
            if (curxq4 == "0") {
                dw_1.SetItem(i, "xq4", "")
            }
            if (curxq4 == "1") {
                dw_1.SetItem(i, "xq4", "√")
            }
            if (curxq5 == "0") {
                dw_1.SetItem(i, "xq5", "")
            }
            if (curxq5 == "1") {
                dw_1.SetItem(i, "xq5", "√")
            }
            if (curxq6 == "0") {
                dw_1.SetItem(i, "xq6", "")
            }
            if (curxq6 == "1") {
                dw_1.SetItem(i, "xq6", "√")
            }
            if (curxq7 == "0") {
                dw_1.SetItem(i, "xq7", "")
            }
            if (curxq7 == "1") {
                dw_1.SetItem(i, "xq7", "√")
            }

        }

    }

    this.Exit=function(){    
        setTimeout("window.close();", 100);
    }

    this.Print = function () {
        dw_list.PrintPreview();

    }
    this.exportAll = function () {
        dw_1.Retrieve();
        var colCount = dw_1.Describe("DataWindow.Column.Count");
        self.SetItemName1(colCount);
        self.ItemValueChange1();
        // dw_1.Modify("DataWindow.Sparse='spkh\tksmc\tfabh\tfamc\tjldw'")
        dw_1.Modify("DataWindow.Sparse='spkh\tksmc\tfabh\tjldw'")
        dw_1.SetRowSelection(1);
        dw_1.Export();
    }
 }