///<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_XHYSKMX.prototype = new W_Tjfx_Base( ); 

function W_XHYSKMX() {

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

		 if(typeof(self.ywychanges)=="function") 
			 win.AttachEvent("cb_ywy","Clicked",self.ywychanges); 

		 if(typeof(self.bmchanges)=="function") 
			 win.AttachEvent("cb_bm","Clicked",self.bmchanges); 

		 if(typeof(self.skfschanges)=="function") 
			 win.AttachEvent("cb_skfs","Clicked",self.skfschanges); 

		 if(typeof(self.khchanges)=="function") 
			 win.AttachEvent("cb_kh","Clicked",self.khchanges); 

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

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

		 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(); 

		 sle_ckfs.Detach(); sle_ckfs=null; 
		 sle_ywy.Detach(); sle_ywy=null; 
		 sle_bm.Detach(); sle_bm=null; 
		 sle_skfs.Detach(); sle_skfs=null; 
		 sle_kh.Detach(); sle_kh=null; 
		 dp_2.Detach(); dp_2=null; 
		 dp_1.Detach(); dp_1=null; 
		 dw_temp.Detach(); dw_temp=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 lastSortName = "";

    var curW_OPEN_SIMPLE_CHOSE = new OpenWindowSimpleChoseBase();
    var curW_YW_LIST = new W_YW_LIST();
    var curKhyeJqdBm = "0";
    var curYhbh = "";
    var curCdbh = "";
    var curSelDays = ""; //默认该模块可查询天数

    //#region PostOpen
    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()));
        curKhyeJqdBm = GetGlobalParm("cw_jqdbm", "jqdbm", "qybz");
        curYhbh = requestor.GetParm("curYhbh");
        curCdbh = requestor.GetParm("curCdbh");
        curSelDays = GetXiTongCanShu(curYhbh, curCdbh, "bzxx");
    }
    //#endregion

    this.Query = function () {
//        dw_temp.RetrieveEx("1=1 " + self.GetSqlWhere(true));
//        dw_list.SetFullState(dw_temp.GetFullState());

        dw_list.RetrieveEx("1=1 " + self.GetSqlWhere(true));
        dw_list.SetRowSelection("1");
    }

    //#region 获取where 条件
    this.GetSqlWhere = function (flag) {
        var realSql = "";
        var beginDate = UtcDateFormatToString(dp_1.GetValue());
        var endDate = UtcDateFormatToString(dp_2.GetValue());
        var curYhbh = requestor.GetParm("curYhbh")
        var curBm = sle_bm.GetText();
        var curKh = sle_kh.GetText();
        var curYwy = sle_ywy.GetText();
        var curSkfs = sle_skfs.GetText();
        var curCkfs = sle_ckfs.GetText();
        if (curSelDays != "-1") {
            beginDate = compareDate(curSelDays, beginDate);
        }
        realSql += " and (CONVERT(date,rq) between '" + beginDate + "' and '" + endDate + "')";


        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 (curKh.length > 0) {

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

            curYwy = self.DealWords(curYwy);
            if (flag == true)
                realSql += " and ywy in(" + curYwy + ")";
            else
                realSql += " and ywy in('" + curYwy + "')";
        }
        if (curSkfs.length > 0) {

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

            curCkfs = self.DealWords(curCkfs);
            if (flag == true)
                realSql += " and cgfs in(" + curCkfs + ")";
            else
                realSql += " and cgfs in('" + curCkfs + "')";
        }
        return realSql;
    }

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

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

        return words;

    }
    //#endregion
    //#endregion

    //#region Function 呼出数据窗口的函数群 
    this.bmchanges = function (x, y, row, dwoName) {
        dwoName == "bmbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_XHYSKMX, "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=cwcx"), curW_OPEN_BMDA_NEW, null);
    }

    this.khchanges = function (x, y, row, dwoName) {
        dwoName == "khbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_XHYSKMX, "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&curQxlx=cwcx"), curW_OPEN_BMDA_NEW, null);
    }

    this.ckfschanges = function (x, y, row, dwoName) {
        dwoName == "csbh";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_XHYSKMX, "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.skfschanges = function (x, y, row, dwoName) {
        dwoName == "skfs";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_XHYSKMX, "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.ywychanges = function (x, y, row, dwoName) {
        dwoName == "yhbh";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_XHYSKMX, "yhbh", "yhmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_pub_pos_yyyorsky_list&selectStyle=multiple&flag=skybh"), 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 ("csbh" == difBh)
            sle_ckfs.SetText(val);
        else if ("skfs" == difBh)
            sle_skfs.SetText(val);
        else if ("yhbh" == difBh)
            sle_ywy.SetText(val);
    }
    //#endregion

    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 curRow = dw_list.GetRow();
            if (curRow > 0) {
                curPzh = dw_list.GetItemString(curRow, "pzh");
                requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.CaiWu.CaiWuTongJiFenXi.W_YW_LIST&curpzh=" + curPzh + "&curJqdbm=" + curKhyeJqdBm), curW_YW_LIST, null);
            }
        }
    }


    this.SaveGS = function () {

        if (savegs(dw_list, curYhbh, curCdbh) == "保存成功！") {
            requestor.MessageBox("提示", "保存成功", ICON.Information);
        } else {
            requestor.MessageBox("提示", "保存失败", ICON.StopSign);
        }

    }
    this.CleanGS = function () {
        qcgs(curYhbh, curCdbh);
        dw_list.SetDataObject("dw_null");
        dw_list.SetDataObject("dw_cwtjfx_xhysdmx_list");
        self.Query();
    }
}
W_XHYSKMX.prototype = new W_Tjfx_Base();