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

    var self = this;
    this.Instance = null;
    var requestor = new PBWindow();
    var rb_yhzh = new RadioButton(requestor);
    var rb_all = new RadioButton(requestor);
    var rb_xjzh = new RadioButton(requestor);
    var sle_zh = new SingleLineEdit(requestor);
    var sle_bm = new SingleLineEdit(requestor);
    var dp_4 = new DatePicker(requestor);
    var dp_2 = new DatePicker(requestor);
    var dp_3 = new DatePicker(requestor);
    var dp_1 = new DatePicker(requestor);
    var dw_list = new DataWindow(requestor);
    var tb_1 = new ToolStrip(requestor);
    var ContextMenuStrip1 = new ContextMenu(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_yhzh == null) rb_yhzh = new RadioButton(requestor);
        rb_yhzh.Attach(win.Control("rb_yhzh"));
        if (rb_all == null) rb_all = new RadioButton(requestor);
        rb_all.Attach(win.Control("rb_all"));
        if (rb_xjzh == null) rb_xjzh = new RadioButton(requestor);
        rb_xjzh.Attach(win.Control("rb_xjzh"));
        if (sle_zh == null) sle_zh = new SingleLineEdit(requestor);
        sle_zh.Attach(win.Control("sle_zh"));
        if (sle_bm == null) sle_bm = new SingleLineEdit(requestor);
        sle_bm.Attach(win.Control("sle_bm"));
        if (dp_4 == null) dp_4 = new DatePicker(requestor);
        dp_4.Attach(win.Control("dp_4"));
        if (dp_2 == null) dp_2 = new DatePicker(requestor);
        dp_2.Attach(win.Control("dp_2"));
        if (dp_3 == null) dp_3 = new DatePicker(requestor);
        dp_3.Attach(win.Control("dp_3"));
        if (dp_1 == null) dp_1 = new DatePicker(requestor);
        dp_1.Attach(win.Control("dp_1"));
        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 (ContextMenuStrip1 == null) ContextMenuStrip1 = new ContextMenu(requestor);
        ContextMenuStrip1.Attach(win.Control("ContextMenuStrip1"));

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

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

        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.Print) == "function")
            win.AttachEvent("btn_Preview", "Clicked", self.Print);

        if (typeof (self.Closed) == "function")
            win.AttachEvent("btn_Close", "Clicked", self.Closed);

        if (typeof (self.SaveGS) == "function")
            win.AttachEvent("保存格式ToolStripMenuItem", "Clicked", self.SaveGS);

        if (typeof (self.CleanGS) == "function")
            win.AttachEvent("清除格式ToolStripMenuItem", "Clicked", self.CleanGS);

    }

    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_yhzh.Detach(); rb_yhzh = null;
        rb_all.Detach(); rb_all = null;
        rb_xjzh.Detach(); rb_xjzh = null;
        sle_zh.Detach(); sle_zh = null;
        sle_bm.Detach(); sle_bm = null;
        dp_4.Detach(); dp_4 = null;
        dp_2.Detach(); dp_2 = null;
        dp_3.Detach(); dp_3 = null;
        dp_1.Detach(); dp_1 = null;
        dw_list.Detach(); dw_list = null;
        tb_1.Detach(); tb_1 = null;
        ContextMenuStrip1.Detach(); ContextMenuStrip1 = 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 = "";
    var curCdbh = "";
    var lastSortName = "";
    var curSelDays = ""; //默认该模块可查询天数
    var curW_OPEN_SIMPLE_CHOSE = new OpenWindowSimpleChoseBase();
    var curW_XJYINHLSZ_FROM_RJMX = new W_XJYINHLSZ_FROM_RJMX();
    this.PostOpen = function () {

        var curFormPzh = requestor.GetParm("curFormPzh");
        var curBeginDate = requestor.GetParm("curBeginDate");
        var curEndDate = requestor.GetParm("curEndDate");

        var myDate = new Date();
        var nian = myDate.getFullYear().toString();
        var yue = myDate.getMonth();
        var ri = "01";
        var objDate = new Date(nian, yue, ri);
        if (curFormPzh.length > 0) {
            rb_all.SetChecked(true);
            rb_xjzh.SetChecked(false);
            rb_yhzh.SetChecked(false);
            sle_zh.SetText(curFormPzh);
           // alert(new Date(curBeginDate));
            dp_1.SetValue(curBeginDate);
            dp_2.SetValue(curEndDate);
            self.Query();
            //            dw_list.RetrieveEx("hzb.zh='" + curFormPzh + "' and kdsj BETWEEN '" + curBeginDate + "' and '" + curEndDate + "'");
        } else {
            dp_1.SetValue(objDate.getVarDate())
        }
        sle_bm.SetEnabled(false);
        curYhbh = requestor.GetParm("curYhbh");
        curCdbh = requestor.GetParm("curCdbh");

        

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

        curSelDays = GetXiTongCanShu(curYhbh, curCdbh, "bzxx");

    }
    //#endregion

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

    this.Changebmbh = function (x, y, row, dwoName) {
        dwoName == "bmbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_XJYINHLSZ, "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.Changezhanghu = function (x, y, row, dwoName) {
        dwoName == "zhbh";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_XJYINHLSZ, "zhbh", "zhmc", "M", self)   // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_pub_yinhangzhanghao_list&selectStyle=multiple"), curW_OPEN_SIMPLE_CHOSE, null);
    }
    //#endregion

    //#region 选中后赋值

    this.SetSleValue = function (difBh, val) {

        if ("''" == val)
            val = "";
        if ("bmbh" == difBh)
            sle_bm.SetText(val);
        else if ("zhbh" == difBh)
            sle_zh.SetText(val);

    }

    //#endregion

    //#region 执行查询
    this.Query = function () {

        dw_list.RetrieveEx("1=1 " + self.GetSqlWhere(true));
        self.A8erp_Report_Style(dw_list);
    }
    //#endregion

    //#region 获取where 条件
    this.GetSqlWhere = function (flag) {
        var realSql = "";
        var curYhbh = requestor.GetParm("curYhbh")
        var curBm = sle_bm.GetText();
        var curzh = sle_zh.GetText();
        var curBeginDate = UtcDateFormatToString(dp_1.GetValue());
        var curEndDate = UtcDateFormatToString(dp_2.GetValue());
        var curBeginDate1 = UtcDateFormatToString(dp_3.GetValue());
        var curEndDate1 = UtcDateFormatToString(dp_4.GetValue());
        if (curSelDays != "-1") {
           curBeginDate = compareDate(curSelDays, curBeginDate);
        }
        if (curBm.length > 0) {
            curBm = self.DealWords(curBm);
            if (flag == true)
                realSql += " and bmbh  in(" + curBm + ")";
            else
                realSql += "and  bmbh  in('" + curBm + "')";
        } else {
            realSql += "and  bmbh in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and cwcx = '1')"
        }

        if (curzh.length > 0) {

            curzh = self.DealWords(curzh);
            if (flag == true)
                realSql += " and zh in(" + curzh + ")";
            else
                realSql += " and zh in('" + curzh + "')";
        }

        if (rb_xjzh.GetChecked()) {
            realSql += " and zhlx='0' ";
        }
        if (rb_yhzh.GetChecked()) {
            realSql += " and zhlx='1' ";
        }
        realSql += " and convert(date,kdsj,120) between '" + curBeginDate + "' and '" + curEndDate + "' ";
        realSql += " and convert(date,rq,120)  between '" + curBeginDate1 + "' and '" + curEndDate1 + "' ";
        return realSql;
    }
    //#endregion
    //#region Function DealWords
    this.DealWords = function (words) {

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

        return words;

    }
    //#endregion

    //退出操作
    this.Closed = function () {
        setTimeout("window.close()", 100); 
    }

    var curW_YW_LIST = null;
    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();
            }
        } else {

            //判断是否存在数据行


            var curPzh = "";
            var curDjlx = "";
            var curRow = dw_list.GetRow();
            if (curRow <= 0) {
                return;
            }
            if (curRow > 0) {
                curPzh = dw_list.GetItemString(curRow, "djbh");
                curDjlx = dw_list.GetItemString(curRow, "djlx");
            }
            var varQZ = curPzh.substring(0, 2);
            if (varQZ == "TT" || curPzh.substring(0, 4) == "CZMX" || curDjlx == "会员充值") {

                curW_YW_LIST = new W_Single_List_();
                requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.CaiWu.JinHuoFuKuanDan.W_Single_List_&curpzh=" + curPzh + "&curywlx=" + curDjlx), curW_YW_LIST, null);
            } else if (varQZ == "RJ" && curPzh.length == 28) {
                //#region 日结生成的现金银行账务
                curW_XJYINHLSZ_FROM_RJMX = new W_XJYINHLSZ_FROM_RJMX();
                requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.CaiWu.CaiWuTongJiFenXi.W_XJYINHLSZ_FROM_RJMX&curCreateCashBankPzh=" + curPzh + "&curywlx=" + curDjlx), curW_XJYINHLSZ_FROM_RJMX, null);

                //#endregion 
            }
            else {
          
                curW_YW_LIST = new W_YW_LIST();
                requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.CaiWu.JinHuoFuKuanDan.W_YW_LIST&curpzh=" + curPzh + "&curywlx=" + curDjlx), curW_YW_LIST, null);

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



    //#region 格式保存
    this.SaveGS = function () {
        var msg = savegs(dw_list, curYhbh, requestor.GetParm("curCdbh"));
        alert(msg);
    }
    //#endregion

    //#region 清除格式
    this.CleanGS = function () {
        var msg = qcgs(curYhbh, requestor.GetParm("curCdbh"));
        alert(msg);

    }
    //#endregion

    //#region 定义单据样式

    this.A8erp_Report_Style = function (curDw_List) {//67108864    15780518
        curDw_List.Modify("datawindow.detail.color='67108864' datawindow.detail.gradient.color='16777215' datawindow.detail.brushmode='1' ")
    }
    //#endregion
   
 
}