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

    var self = this;
    this.Instance = null;
    var requestor = new PBWindow();
    var cb_spkh = new CommandButton(requestor);
    var dp_2 = new DatePicker(requestor);
    var dp_1 = new DatePicker(requestor);
    var sle_dc = new SingleLineEdit(requestor);
    var sle_dr = new SingleLineEdit(requestor);
    var sle_spkh = new SingleLineEdit(requestor);
    var sle_tmh = new SingleLineEdit(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) {
        self.Instance = win;
        if (typeof (baseBind) == "function") baseBind(win);

        if (requestor == null) requestor = new PBWindow();
        requestor.Attach(win);
        if (cb_spkh == null) cb_spkh = new CommandButton(requestor);
        cb_spkh.Attach(win.Control("cb_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 (sle_dc == null) sle_dc = new SingleLineEdit(requestor);
        sle_dc.Attach(win.Control("sle_dc"));
        if (sle_dr == null) sle_dr = new SingleLineEdit(requestor);
        sle_dr.Attach(win.Control("sle_dr"));
        if (sle_spkh == null) sle_spkh = new SingleLineEdit(requestor);
        sle_spkh.Attach(win.Control("sle_spkh"));
        if (sle_tmh == null) sle_tmh = new SingleLineEdit(requestor);
        sle_tmh.Attach(win.Control("sle_tmh"));
        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.ChangeDc) == "function")
            win.AttachEvent("cb_dc", "Clicked", self.ChangeDc);

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

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

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

        if (typeof (self.Exit) == "function")
            win.AttachEvent("btn_Exit", "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();

        cb_spkh.Detach(); cb_spkh = null;
        dp_2.Detach(); dp_2 = null;
        dp_1.Detach(); dp_1 = null;
        sle_dc.Detach(); sle_dc = null;
        sle_dr.Detach(); sle_dr = null;
        sle_spkh.Detach(); sle_spkh = null;
        sle_tmh.Detach(); sle_tmh = 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 = new OpenWindowQueryNewBase();
    var curW_OPEN_BMDA_URL = "OpenWindowQueryNewBase";

    this.Query = function () {

        var curBeginDate = UtcDateFormatToString(dp_1.GetValue());
        var curEndData = UtcDateFormatToString(dp_2.GetValue());
        var curTmh = sle_tmh.GetText();
        var curSpkh = sle_spkh.GetText();
        var curBMbh = sle_dr.GetText();
        var curBMbh1 = sle_dc.GetText();
        var str = " (convert(date,b.kdsj,120) between '" + curBeginDate + "' and '" + curEndData + "') ";
        if (curTmh.length > 0) {
            str += " and (tmlsh='" + curTmh + "')";
        }
        if (curSpkh.length > 0) {
            str += " and (a.spkh in (" + curSpkh + "))";
        }

        if (curBMbh.length > 0) {
            str += " and (b.bmbh1 in (" + curBMbh + "))";
        }
        if (curBMbh1.length > 0) {
            str += " and (b.bmbh2 in (" + curBMbh1 + "))";
        }
        dw_1.RetrieveEx(str);



    }
    //#region 呼出函数
    this.ChangeSpkh = function (x, y, row, dwoName) {
        dwoName == "spkh";

        curW_OPEN_BMDA_NEW.SetDataWindow(W_DiaoBoFaHuoTiaoMaChaXun, "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.ChangeDr = function (x, y, row, dwoName) {
        dwoName == "bmbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_DiaoBoFaHuoTiaoMaChaXun, "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.ChangeDc = function (x, y, row, dwoName) {
        dwoName == "bmbh2";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_DiaoBoFaHuoTiaoMaChaXun, "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);
    }

    //#endregion

    //#region SetSleValue
    this.SetSleValue = function (difBh, val) {
        if ("''" == val)
            val = "";
        else if ("spkh" == difBh)
            sle_spkh.SetText(val);

        if ("bmbh" == difBh)
            sle_dr.SetText(val);
        if ("bmbh2" == difBh)
            sle_dc.SetText(val);
    }
    //#endregion

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

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

    this.PostOpen = function () {
        sle_dc.SetEnabled(false);
        sle_dr.SetEnabled(false);
    }
 }