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

    var self = this;
    var requestor = new PBWindow();
    var ddlb_pjlx = new DropDownListBox(requestor);
    var sle_zdbm = new SingleLineEdit(requestor);
    var sle_zdr = new SingleLineEdit(requestor);
    var ddlb_wczt = new DropDownListBox(requestor);
    var ddlb_kplx = new DropDownListBox(requestor);
    var ddlb_pjzl = new DropDownListBox(requestor);
    var sle_fphm = new SingleLineEdit(requestor);
    var sle_kpje = new SingleLineEdit(requestor);
    var sle_jbr = new SingleLineEdit(requestor);
    var dp_2 = new DatePicker(requestor);
    var sle_wldw = new SingleLineEdit(requestor);
    var dp_1 = new DatePicker(requestor);
    var dw_1 = new DataWindow(requestor);
    var tb_1 = new ToolStrip(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 (ddlb_pjlx == null) ddlb_pjlx = new DropDownListBox(requestor);
        ddlb_pjlx.Attach(win.Control("ddlb_pjlx"));
        if (sle_zdbm == null) sle_zdbm = new SingleLineEdit(requestor);
        sle_zdbm.Attach(win.Control("sle_zdbm"));
        if (sle_zdr == null) sle_zdr = new SingleLineEdit(requestor);
        sle_zdr.Attach(win.Control("sle_zdr"));
        if (ddlb_wczt == null) ddlb_wczt = new DropDownListBox(requestor);
        ddlb_wczt.Attach(win.Control("ddlb_wczt"));
        if (ddlb_kplx == null) ddlb_kplx = new DropDownListBox(requestor);
        ddlb_kplx.Attach(win.Control("ddlb_kplx"));
        if (ddlb_pjzl == null) ddlb_pjzl = new DropDownListBox(requestor);
        ddlb_pjzl.Attach(win.Control("ddlb_pjzl"));
        if (sle_fphm == null) sle_fphm = new SingleLineEdit(requestor);
        sle_fphm.Attach(win.Control("sle_fphm"));
        if (sle_kpje == null) sle_kpje = new SingleLineEdit(requestor);
        sle_kpje.Attach(win.Control("sle_kpje"));
        if (sle_jbr == null) sle_jbr = new SingleLineEdit(requestor);
        sle_jbr.Attach(win.Control("sle_jbr"));
        if (dp_2 == null) dp_2 = new DatePicker(requestor);
        dp_2.Attach(win.Control("dp_2"));
        if (sle_wldw == null) sle_wldw = new SingleLineEdit(requestor);
        sle_wldw.Attach(win.Control("sle_wldw"));
        if (dp_1 == null) dp_1 = new DatePicker(requestor);
        dp_1.Attach(win.Control("dp_1"));
        if (dw_1 == null) dw_1 = new DataWindow(requestor);
        dw_1.Attach(win.Control("dw_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.Zdbm) == "function")
            win.AttachEvent("cb_zdbm", "Clicked", self.Zdbm);

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

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

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

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

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

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

    }

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

        ddlb_pjlx.Detach(); ddlb_pjlx = null;
        sle_zdbm.Detach(); sle_zdbm = null;
        sle_zdr.Detach(); sle_zdr = null;
        ddlb_wczt.Detach(); ddlb_wczt = null;
        ddlb_kplx.Detach(); ddlb_kplx = null;
        ddlb_pjzl.Detach(); ddlb_pjzl = null;
        sle_fphm.Detach(); sle_fphm = null;
        sle_kpje.Detach(); sle_kpje = null;
        sle_jbr.Detach(); sle_jbr = null;
        dp_2.Detach(); dp_2 = null;
        sle_wldw.Detach(); sle_wldw = null;
        dp_1.Detach(); dp_1 = null;
        dw_1.Detach(); dw_1 = null;
        tb_1.Detach(); tb_1 = null;
        requestor.Detach(); requestor = null;

        setTimeout(CollectGarbage, 100);
    }

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

    var curW_OPEN_BMDA = new OpenWindowQueryBase();

    var curW_OPEN_BMDA_NEW = new OpenWindowQueryNewBase();
    var curW_OPEN_BMDA_URL = "OpenWindowQueryNewBase";
    
    
    var curYhbh = "";

    //#region PostOpen
    this.PostOpen = function () {
        curYhbh = requestor.GetParm("curYhbh");
        sle_kpje.SetText("");
        sle_fphm.SetText("");
        sle_wldw.SetText("");
        sle_jbr.SetText("");
        sle_zdr.SetText("");
        sle_zdbm.SetText("");
        ddlb_wczt.SetText("全部");
        ddlb_kplx.SetText("全部");
        ddlb_pjzl.SetText("全部");
        ddlb_pjlx.SetText("全部");
        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()));
    }
    //#endregion

    //#region Function 呼出数据窗口的函数群 
    this.Wldw = function (x, y, row, dwoName) {
        dwoName == "wldw";
        curW_OPEN_BMDA.SetDataWindow(W_FaPiaoDanTongJi, "wldw", "dwmc", "M", self)   // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowQueryBase&treeDw=dw_da_wldw_fl_tree&listDw=dw_pub_wldw_list&treeRootLabel=分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&selectStyle=multiple"), curW_OPEN_BMDA, null);
    }

    this.Zdbm = function (x, y, row, dwoName) {
        dwoName == "bmbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_FaPiaoDanTongJi, "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.Jbr = function (x, y, row, dwoName) {
        dwoName == "ygbh";
        curW_OPEN_BMDA.SetDataWindow(W_FaPiaoDanTongJi, "ygbh", "ygmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowQueryBase&treeDw=dw_da_ryda_zw_tree&listDw=dw_pub_ygda_list&treeRootLabel=职务分类&treeData=csbh&treeLabel=csmc&treeParentData=fcsbh&treeLeave=islast&selectStyle=multiple"), curW_OPEN_BMDA, null);
    }

    this.Zdr = function (x, y, row, dwoName) {
        dwoName == "zdr";
        curW_OPEN_BMDA.SetDataWindow(W_FaPiaoDanTongJi, "zdr", "ygmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowQueryBase&treeDw=dw_da_ryda_zw_tree&listDw=dw_pub_ygda_list1&treeRootLabel=职务分类&treeData=csbh&treeLabel=csmc&treeParentData=fcsbh&treeLeave=islast&selectStyle=multiple"), curW_OPEN_BMDA, null);
    }
    //#endregion

    //#region 选中后赋值
    this.SetSleValue = function (difBh, val) {
        if ("''" == val)
            val = "";

        if ("bmbh" == difBh)
            sle_zdbm.SetText(val);
        else if ("zdr" == difBh)
            sle_zdr.SetText(val);
        else if ("ygbh" == difBh)
            sle_jbr.SetText(val);
        else if ("wldw" == difBh)
            sle_wldw.SetText(val);
    }

    //#endregion

    //#region Query
    this.Query = function () {
        var curKssj = UtcDateFormatToString(dp_1.GetValue());
        var curJssj = UtcDateFormatToString(dp_2.GetValue());
        var sqlWhere = " CONVERT(date,kprq,120) between '" + curKssj + "' and '" + curJssj + "' ";
     
        if (sle_kpje.GetText().length > 0) {
            sqlWhere += " and (kpje <= CONVERT(float," + sle_kpje.GetText() + ")) ";
        }
        if (sle_fphm.GetText().length > 0) {
            sqlWhere += " and (fphm like '%" + sle_fphm.GetText() + "%') ";
        }
        if (ddlb_pjzl.GetText() != "全部") {
            sqlWhere += " and (C.csmc = '" + ddlb_pjzl.GetText() + "') ";
        }
        if (ddlb_kplx.GetText() != "全部") {
            sqlWhere += " and (D.csmc = '" + ddlb_kplx.GetText() + "') ";
        }
        if (ddlb_wczt.GetText() != "全部") {
            sqlWhere += " and (fhjb.fhmc = '" + ddlb_wczt.GetText() + "') ";
        }
        if (ddlb_pjlx.GetText() != "全部") {
            sqlWhere += " and (pjlx = '" + ddlb_pjlx.GetText() + "') ";
        }
        if (sle_zdbm.GetText().length > 0) {
            sqlWhere += " and (aa.bmbh in (" + self.DealWords(sle_zdbm.GetText()) + ")) ";
        }
        if (sle_wldw.GetText().length > 0) {
            sqlWhere += " and (aa.wldw in (" + self.DealWords(sle_wldw.GetText()) + ")) ";
        }
        if (sle_jbr.GetText().length > 0) {
            sqlWhere += " and (jbr in (" + self.DealWords(sle_jbr.GetText()) + ")) ";
        }
        if (sle_zdr.GetText().length > 0) {
            sqlWhere += " and (kpr in (" + self.DealWords(sle_zdr.GetText()) + ")) ";
        }


        dw_1.RetrieveEx(sqlWhere);
    }
    //#endregion

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

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

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