///<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" />
///<reference  path="/Base/W_Tjfx_Base.win.js" /> 

//注意,需要在对象定义后面，手工增加以下代码实现对象继承
// W_XHYSDHZTJ.prototype = new W_Tjfx_Base( ); 

function W_XHYSDHZTJ() {

    var self = this;
    this.Instance = null;
    var requestor = new PBWindow();
    var sle_skfs = new SingleLineEdit(requestor);
    var sle_kh = new SingleLineEdit(requestor);
    var sle_bm = new SingleLineEdit(requestor);
    var dp_2 = new DatePicker(requestor);
    var dp_1 = new DatePicker(requestor);
    var dw_temp = new DataWindow(requestor);
    var dw_format = new DataWindow(requestor);
    var dw_list = 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 (sle_skfs == null) sle_skfs = new SingleLineEdit(requestor);
        sle_skfs.Attach(win.Control("sle_skfs"));
        if (sle_kh == null) sle_kh = new SingleLineEdit(requestor);
        sle_kh.Attach(win.Control("sle_kh"));
        if (sle_bm == null) sle_bm = new SingleLineEdit(requestor);
        sle_bm.Attach(win.Control("sle_bm"));
        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 (dw_temp == null) dw_temp = new DataWindow(requestor);
        dw_temp.Attach(win.Control("dw_temp"));
        if (dw_format == null) dw_format = new DataWindow(requestor);
        dw_format.Attach(win.Control("dw_format"));
        if (dw_list == null) dw_list = new DataWindow(requestor);
        dw_list.Attach(win.Control("dw_list"));
        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.Changeskfs) == "function")
            win.AttachEvent("cb_3", "Clicked", self.Changeskfs);

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

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

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

    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_skfs.Detach(); sle_skfs = null;
        sle_kh.Detach(); sle_kh = null;
        sle_bm.Detach(); sle_bm = null;
        dp_2.Detach(); dp_2 = null;
        dp_1.Detach(); dp_1 = null;
        dw_temp.Detach(); dw_temp = null;
        dw_format.Detach(); dw_format = null;
        dw_list.Detach(); dw_list = 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 curW_OPEN_SIMPLE_CHOSE = new OpenWindowSimpleChoseBase();
    var curYhbh = "";
    var curCdbh = "";
    var curBbmc = "";
    var curSelDays = ""; //默认该模块可查询天数
    this.PostOpen = function () {
        sle_bm.SetEnabled(false);
        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()))
        dw_list.SetRowSelection("1");
        dw_list.SetClickHeaderSort(false);
        curCdbh = requestor.GetParm("curCdbh");
        curYhbh = requestor.GetParm("curYhbh");
        curSelDays = GetXiTongCanShu(curYhbh, curCdbh, "bzxx");
//        dw_format.RetrieveEx("cdbh='" + curCdbh + "' and yhbh='" + curYhbh + "' and bbmc='" + curBbmc + "'");
    }
    var lastSortName = "";
    //#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
    this.Changebmbh = function (x, y, row, dwoName) {
        dwoName == "bmbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_XHYSDHZTJ, "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.Changekhbh = function (x, y, row, dwoName) {
        dwoName == "khbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_XHYSDHZTJ, "khbh", "khmc", "M", self)   // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base." + curW_OPEN_BMDA_URL + "&treeDw=dw_da_khda_fl_tree&listDw=dw_pub_khda_list_all&treeRootLabel=客户分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&selectStyle=multiple"), curW_OPEN_BMDA_NEW, null);
    }
    this.Changeskfs = function (x, y, row, dwoName) {
        dwoName == "skfs";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_XHYSDHZTJ, "skfs", "skmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_pub_list_qj_csb_skfs&selectStyle=multiple"), curW_OPEN_SIMPLE_CHOSE, null);
    }
    this.SetSleValue = function (difBh, val) {

        if ("''" == val)
            val = "";
        if ("bmbh" == difBh)
            sle_bm.SetText(val);
        else if ("khbh" == difBh)
            sle_kh.SetText(val);
        else if ("skfs" == difBh)
            sle_skfs.SetText(val)
    }
    this.Query = function () {
        dw_temp.RetrieveEx("1=1 " + self.GetSqlWhere(true));
        dw_list.SetFullState(dw_temp.GetFullState());
        DWSort(dw_format, dw_list);
        //self.SetValue(C_CheckValue, curBbmc, curCdbh, curYhbh);
    }
    this.GetSqlWhere = function (flag) {
        var realSql = "";
        var curYhbh = requestor.GetParm("curYhbh")
        var beginDate = UtcDateFormatToString(dp_1.GetValue());
        var endDate = UtcDateFormatToString(dp_2.GetValue());
        if (curSelDays != "-1") {
            beginDate = compareDate(curSelDays, beginDate);
        }
        var curBm = sle_bm.GetText();
        var curKh = sle_kh.GetText();
        var curskfs = sle_skfs.GetText();
        if (flag == true)
            realSql += " and (CONVERT(date, rq) between '" + beginDate + "' and '" + endDate + "')";
        else
            realSql += " and (CONVERT(date,rq) between '" + beginDate + "' and '" + endDate + "')";

        if (curBm.length > 0) {
            curBm = self.DealWords(curBm);
            if (flag == true)
                realSql += " and cw_new_xhskd.bmbh  in(" + curBm + ")";
            else
                realSql += "and  cw_new_xhskd.bmbh  in('" + curBm + "')";
        } else {
            realSql += "and cw_new_xhskd.bmbh in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and cwcx = '1')"
        }
        if (curKh.length > 0) {

            curKh = self.DealWords(curKh);
            if (flag == true)
                realSql += " and cw_new_xhskd.khbh in(" + curKh + ")";
            else
                realSql += " and cw_new_xhskd.khbh in('" + curKh + "')";
        } else {
            realSql += "and cw_new_xhskd.khbh in(select khbh  from da_qx_khda where yhbh = '" + curYhbh + "'and bz3 = '1')"
        }

        if (curskfs.length > 0) {
            curskfs = self.DealWords(curskfs);
            if (flag == true)
                realSql += " and skfs in(" + curskfs + ")";
            else
                realSql += " and skfs in('" + curskfs + "')";
        }
        return realSql;

    }
    this.DealWords = function (words) {

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

        return words;

    }
}
W_XHYSDHZTJ.prototype = new W_Tjfx_Base();