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

	 var self=this;
	 var requestor= new PBWindow();
	 var mle_1= new MultiLineEdit( requestor );
	 var dw_2= new DataWindow( requestor );
	 var dw_1= new DataWindow( requestor );
	 var sle_cgfs= new SingleLineEdit( requestor );
	 var sle_jjbm= new SingleLineEdit( requestor );
	 var cbx_ks= new CheckBox( requestor );
	 var cbx_fs= new CheckBox( requestor );
	 var cbx_lb= new CheckBox( requestor );
	 var cbx_gys= new CheckBox( requestor );
	 var cbx_bm= new CheckBox( requestor );
	 var cbx_rq= new CheckBox( requestor );
	 var sle_gysbh= new SingleLineEdit( requestor );
	 var sle_bmbh= new SingleLineEdit( requestor );
	 var sle_ppbm= new SingleLineEdit( requestor );
	 var sle_lbbh= new SingleLineEdit( requestor );
	 var sle_pzh= new SingleLineEdit( requestor );
	 var sle_spkh= new SingleLineEdit( requestor );
	 var dp_2= new DatePicker( requestor );
	 var dp_1= new DatePicker( requestor );
	 var tb_1= new ToolStrip( requestor );
	 var sle_6= new SingleLineEdit( requestor );

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

		 if(requestor == null ) requestor= new PBWindow();
		 requestor.Attach(win);
		 if(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_1 == null ) dw_1= new DataWindow( requestor );
		 dw_1.Attach( win.Control( "dw_1") ); 
		 if(sle_cgfs == null ) sle_cgfs= new SingleLineEdit( requestor );
		 sle_cgfs.Attach( win.Control( "sle_cgfs") ); 
		 if(sle_jjbm == null ) sle_jjbm= new SingleLineEdit( requestor );
		 sle_jjbm.Attach( win.Control( "sle_jjbm") ); 
		 if(cbx_ks == null ) cbx_ks= new CheckBox( requestor );
		 cbx_ks.Attach( win.Control( "cbx_ks") ); 
		 if(cbx_fs == null ) cbx_fs= new CheckBox( requestor );
		 cbx_fs.Attach( win.Control( "cbx_fs") ); 
		 if(cbx_lb == null ) cbx_lb= new CheckBox( requestor );
		 cbx_lb.Attach( win.Control( "cbx_lb") ); 
		 if(cbx_gys == null ) cbx_gys= new CheckBox( requestor );
		 cbx_gys.Attach( win.Control( "cbx_gys") ); 
		 if(cbx_bm == null ) cbx_bm= new CheckBox( requestor );
		 cbx_bm.Attach( win.Control( "cbx_bm") ); 
		 if(cbx_rq == null ) cbx_rq= new CheckBox( requestor );
		 cbx_rq.Attach( win.Control( "cbx_rq") ); 
		 if(sle_gysbh == null ) sle_gysbh= new SingleLineEdit( requestor );
		 sle_gysbh.Attach( win.Control( "sle_gysbh") ); 
		 if(sle_bmbh == null ) sle_bmbh= new SingleLineEdit( requestor );
		 sle_bmbh.Attach( win.Control( "sle_bmbh") ); 
		 if(sle_ppbm == null ) sle_ppbm= new SingleLineEdit( requestor );
		 sle_ppbm.Attach( win.Control( "sle_ppbm") ); 
		 if(sle_lbbh == null ) sle_lbbh= new SingleLineEdit( requestor );
		 sle_lbbh.Attach( win.Control( "sle_lbbh") ); 
		 if(sle_pzh == null ) sle_pzh= new SingleLineEdit( requestor );
		 sle_pzh.Attach( win.Control( "sle_pzh") ); 
		 if(sle_spkh == null ) sle_spkh= new SingleLineEdit( requestor );
		 sle_spkh.Attach( win.Control( "sle_spkh") ); 
		 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(tb_1 == null ) tb_1= new ToolStrip( requestor );
		 tb_1.Attach( win.Control( "tb_1") ); 
		 if(sle_6 == null ) sle_6= new SingleLineEdit( requestor );
		 sle_6.Attach( win.Control( "sle_6") ); 

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

		 if(typeof(self.Query)=="function") 
			 win.AttachEvent("sle_cgfs","EditChanged",self.Query); 

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

		 if(typeof(self.Query)=="function") 
			 win.AttachEvent("sle_jjbm","EditChanged",self.Query); 

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

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

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

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

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

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

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

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

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

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

		 if(typeof(self.Query)=="function") 
			 win.AttachEvent("sle_gysbh","EditChanged",self.Query); 

		 if(typeof(self.Query)=="function") 
			 win.AttachEvent("sle_bmbh","EditChanged",self.Query); 

		 if(typeof(self.Query)=="function") 
			 win.AttachEvent("sle_ppbm","EditChanged",self.Query); 

		 if(typeof(self.Query)=="function") 
			 win.AttachEvent("sle_lbbh","EditChanged",self.Query); 

		 if(typeof(self.Query)=="function") 
			 win.AttachEvent("sle_pzh","EditChanged",self.Query); 

		 if(typeof(self.Query)=="function") 
			 win.AttachEvent("sle_spkh","EditChanged",self.Query); 

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

	 }

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

		 mle_1.Detach(); mle_1=null; 
		 dw_2.Detach(); dw_2=null; 
		 dw_1.Detach(); dw_1=null; 
		 sle_cgfs.Detach(); sle_cgfs=null; 
		 sle_jjbm.Detach(); sle_jjbm=null; 
		 cbx_ks.Detach(); cbx_ks=null; 
		 cbx_fs.Detach(); cbx_fs=null; 
		 cbx_lb.Detach(); cbx_lb=null; 
		 cbx_gys.Detach(); cbx_gys=null; 
		 cbx_bm.Detach(); cbx_bm=null; 
		 cbx_rq.Detach(); cbx_rq=null; 
		 sle_gysbh.Detach(); sle_gysbh=null; 
		 sle_bmbh.Detach(); sle_bmbh=null; 
		 sle_ppbm.Detach(); sle_ppbm=null; 
		 sle_lbbh.Detach(); sle_lbbh=null; 
		 sle_pzh.Detach(); sle_pzh=null; 
		 sle_spkh.Detach(); sle_spkh=null; 
		 dp_2.Detach(); dp_2=null; 
		 dp_1.Detach(); dp_1=null; 
		 tb_1.Detach(); tb_1=null; 
		 sle_6.Detach(); sle_6=null; 
		 requestor.Detach(); requestor=null; 

		 setTimeout(CollectGarbage, 100); 
	 }

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

    //#region 变量声明板块
    var curW_OPEN_BMDA = new OpenWindowQueryBase();
    var curW_OPEN_SIMPLE_CHOSE = new OpenWindowSimpleChoseBase();
    var curW_OPEN_BMDA_NEW = new OpenWindowQueryNewBase();
    var curW_OPEN_BMDA_URL = "OpenWindowQueryNewBase";
    var curOtherWidht = 1080;
    var curOtherHeight = 760;

    var curOpenWindowDoubleRowsChooseBase = new OpenWindowDoubleRowsChooseBase();

    webReq = new WebRequestor();
    webReq.SetWebServiceUrl("/Service/ServiceForDwSyndax.ashx");
    //#endregion


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

        if (!cbx_rq.GetChecked() && !cbx_bm.GetChecked() && !cbx_gys.GetChecked() && !cbx_lb.GetChecked() && !cbx_fs.GetChecked() && !cbx_ks.GetChecked()) {
            cbx_bm.SetChecked(true);
        }

        var dynamicShowStr = "";

        if (cbx_bm.GetChecked())
            dynamicShowStr += "bmbh,bmmc,";
        if (cbx_gys.GetChecked())
            dynamicShowStr += "gysbh,gysmc,";
        if (cbx_rq.GetChecked())
            dynamicShowStr += "cgrq,";
        if (cbx_lb.GetChecked())
            dynamicShowStr += "splbbh,splbmc,";
        if (cbx_fs.GetChecked())
            dynamicShowStr += "cgfsbh,cgfsmc,";
        if (cbx_ks.GetChecked())
            dynamicShowStr += "spkh,ksmc,";

        var finishSql = "select " + dynamicShowStr +
                        " SUM(ISNULL(sl,0)) as sl,max(ISNULL(lsj,0)) as lsj,max(ISNULL(jj,0)) as jj," +
                        " SUM(ISNULL(sl,0))*max(ISNULL(lsj,0)) as lsjze,SUM(ISNULL(sl,0))*max(ISNULL(jj,0)) as jjze  " +
                        " from ls_cg_cgdd_hzfx_mx where (1 = 1) " + self.GetSqlWhere() +
                        " group by " + dynamicShowStr.substring(0,dynamicShowStr.length-1);

        webReq.Invoke("dealDwSyndax", "sql=" + finishSql);

        if (webReq.StatusCode() == 200) {

            dw_1.Create(webReq.ResponseText());
            dw_1.Refresh();

        } else {

            alert("error!");
        }

    }
    //#endregion


    //#region Function 呼出数据窗口的函数群 

    this.ChangeBmbh = function (x, y, row, dwoName) {
        dwoName == "bmbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_HuiZongTongJi, "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"), curW_OPEN_BMDA_NEW, null);
    }

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

    this.ChangeGongYingShang = function (x, y, row, dwoName) {
        dwoName == "gysbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_HuiZongTongJi, "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.ChangeLeiBie = function (x, y, row, dwoName) {
        dwoName == "lbbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_HuiZongTongJi, "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.ChangeJiJie = function (x, y, row, dwoName) {
        dwoName == "jjbm";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_HuiZongTongJi, "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.ChangeFangShi = function (x, y, row, dwoName) {
        dwoName == "csbh";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_HuiZongTongJi, "csbh", "csmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_da_qj_csb_cgfs_list&selectStyle=multiple"), curW_OPEN_SIMPLE_CHOSE, null);
    }

    //选中后赋值

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

        if ("bmbh" == difBh)
            sle_bmbh.SetText(val);
        else if ("gysbh" == difBh)
            sle_gysbh.SetText(val);
        else if ("lbbh" == difBh)
            sle_lbbh.SetText(val);
        else if ("ppbm" == difBh)
            sle_ppbm.SetText(val);
        else if ("jjbm" == difBh)
            sle_jjbm.SetText(val);
        else if ("csbh" == difBh)
            sle_cgfs.SetText(val);
    }

    //#endregion


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

        var realSql = "";

        var beginDate = UtcDateFormatToString(dp_1.GetValue());
        var endDate = UtcDateFormatToString(dp_2.GetValue());
        var curPzh = sle_pzh.GetText();
        var curKh = sle_spkh.GetText();
        var curBm = sle_bmbh.GetText();
        var curPp = sle_ppbm.GetText();
        var curGys = sle_gysbh.GetText();
        var curLb = sle_lbbh.GetText();
        var curJj = sle_jjbm.GetText();
        var curFs = sle_cgfs.GetText();


        realSql += " and (cgrq between '" + beginDate + "' and '" + endDate + "')";


        if (curPzh.length > 0) {

            realSql += " and pzh ='" + curPzh + "'"
        }
        if (curKh.length > 0) {

            realSql += " and spkh ='" + curKh + "'"
        }
        if (curBm.length > 0) {

            curBm = self.DealWords(curBm);
            realSql += " and bmbh  in(" + curBm + ")"
        }
        if (curPp.length > 0) {

            curPp = self.DealWords(curPp);
            realSql += " and spppbh in(" + curPp + ")"
        }
        if (curGys.length > 0) {

            curGys = self.DealWords(curGys);
            realSql += " and gysbh in(" + curGys + ")"
        }
        if (curLb.length > 0) {

            curLb = self.DealWords(curLb);
            realSql += " and splbbh in(" + curLb + ")"
        }
        if (curJj.length > 0) {

            curJj = self.DealWords(curJj);
            realSql += " and spjjbh in(" + curJj + ")"
        }
        if (curFs.length > 0) {

            curFs = self.DealWords(curFs);
            realSql += " and cgfsbh in(" + curFs + ")"
        }

        return realSql;
    }
    //#endregion


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

        if (!(words.charAt(0) == "'"))
            words = "'" + words + "'";

        return words;

    }
    //#endregion


}