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

function W_JHFKDHZTJ() {

	 var self=this;
	 this.Instance=null;
	 var requestor= new PBWindow();
	 var sle_bm= new SingleLineEdit( requestor );
	 var ddlb_1= new DropDownListBox( requestor );
	 var sle_fkfs= new SingleLineEdit( requestor );
	 var sle_gys= 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 );
	 var cb_2 = new CommandButton(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_bm == null ) sle_bm= new SingleLineEdit( requestor );
		 sle_bm.Attach( win.Control( "sle_bm") ); 
		 if(ddlb_1 == null ) ddlb_1= new DropDownListBox( requestor );
		 ddlb_1.Attach( win.Control( "ddlb_1") ); 
		 if(sle_fkfs == null ) sle_fkfs= new SingleLineEdit( requestor );
		 sle_fkfs.Attach( win.Control( "sle_fkfs") ); 
		 if(sle_gys == null ) sle_gys= new SingleLineEdit( requestor );
		 sle_gys.Attach( win.Control( "sle_gys") ); 
		 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 (cb_2 == null) cb_2 = new CommandButton(requestor);
		 cb_2.Attach(win.Control("cb_2"));

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

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

		 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.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 (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_bm.Detach(); sle_bm=null; 
		 ddlb_1.Detach(); ddlb_1=null; 
		 sle_fkfs.Detach(); sle_fkfs=null; 
		 sle_gys.Detach(); sle_gys=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;
		 cb_2.Detach(); cb_2 = 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 curJgtx = "";
    var ExistGYS = "";
    var curYhbh = "";
    var curCdbh = "";
    var curSelDays = ""; //默认该模块可查询天数
    this.PostOpen = function () {

        curYhbh = requestor.GetParm("curYhbh");
        curCdbh = requestor.GetParm("curCdbh");
        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()))
        ddlb_1.SetText("全部");
        dw_list.SetClickHeaderSort(false);
        curJgtx = requestor.GetParm("jgtxlist");
        ExistGYS = ExistJG(curJgtx, "gysbh");
        // 供应商
        if (ExistGYS == "N") {
//            cbx_gys.SetEnabled(false);
//            cbx_gys.SetChecked(false);
            cb_2.SetEnabled(false);
            sle_gys.SetEnabled(false);
        }
        else {
//            cbx_gys.SetEnabled(true);
            cb_2.SetEnabled(true);
            sle_gys.SetEnabled(true);
        }
        curSelDays = GetXiTongCanShu(curYhbh, curCdbh, "bzxx");
    }
    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
    //#region 调出窗口
    this.Changebmbh = function (x, y, row, dwoName) {
        dwoName == "bmbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_JHFKDHZTJ, "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 == "gysbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_JHFKDHZTJ, "gysbh", "gysmc", "M", self)   // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base." + curW_OPEN_BMDA_URL + "&treeDw=dw_da_gysda_fl_tree&listDw=dw_pub_list_gysda&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_JHFKDHZTJ, "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.Changefklx = function (x, y, row, dwoName) {
        dwoName == "csbh";
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(W_JHFKDHZTJ, "csbh", "csmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_pub_list_qj_csb_fklx&selectStyle=multiple"), curW_OPEN_SIMPLE_CHOSE, null);
    }
    this.SetSleValue = function (difBh, val) {

        if ("''" == val)
            val = "";
        if ("bmbh" == difBh)
            sle_bm.SetText(val);
        else if ("gysbh" == difBh)
            sle_gys.SetText(val);
        else if ("skfs" == difBh)
            sle_fkfs.SetText(val)
        else if ("csbh" == difBh)
            sle_fklx.SetText(val)
    }
    //#endregion
    this.Query = function () {
//        dw_temp.RetrieveEx("1=1 " + self.GetSqlWhere(true));
//        dw_list.SetFullState(dw_temp.GetFullState());
//        dw_list.SetRowSelection("1");
//        DWSort(dw_format, dw_list);
        dw_list.RetrieveEx("1=1 " + self.GetSqlWhere(true));
        dw_list.SetRowSelection("1");
        //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());
        var curgys = sle_gys.GetText();
        var curfkfs = sle_fkfs.GetText();
        var curfklx = ddlb_1.GetText();
        var curBm = sle_bm.GetText();
        if (curSelDays != "-1") {
            beginDate = compareDate(curSelDays, beginDate);
        }
        if (flag == true)
            realSql += " and (CONVERT(date, rq) between '" + beginDate + "' and '" + endDate + "')";
        else
            realSql += " and (CONVERT(date,rq) between '" + beginDate + "' and '" + endDate + "')";


        if (curgys.length > 0) {

            curgys = self.DealWords(curgys);
            if (flag == true)
                realSql += " and cw_new_jhfkd.gysbh in(" + curgys + ")";
            else
                realSql += " and cw_new_jhfkd.gysbh in('" + curgys + "')";
        } else {
            realSql += "and cw_new_jhfkd.gysbh in(select gysbh  from da_qx_gysda where yhbh = '" + curYhbh + "'and bz3 = '1')"
        }
        if (curBm.length > 0) {
            curBm = self.DealWords(curBm);
            if (flag == true)
                realSql += " and cw_new_jhfkd.bmbh  in(" + curBm + ")";
            else
                realSql += "and  cw_new_jhfkd.bmbh  in('" + curBm + "')";
        } else {
            realSql += "and cw_new_jhfkd.bmbh in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and cwcx = '1')"
        }
        if (curfkfs.length > 0) {
            curfkfs = self.DealWords(curfkfs);
            if (flag == true)
                realSql += " and fkfs in(" + curfkfs + ")";
            else
                realSql += " and fkfs in('" + curfkfs + "')";
        }
        if (curfklx != "全部") {
            if (curfklx == "应付款") {
                curfklx = "2";
            } else if (curfklx == "应收款") {
                curfklx = "1";
            } else if (curfklx == "定金") {
                curfklx = "3";
            }
            realSql += " and fklx =('" + curfklx + "')";
        }
        return realSql;

    }
    this.DealWords = function (words) {

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

        return words;

    }

    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("da_cw_jhfkdhztj_list");
        self.Query();
    }
}
W_JHFKDHZTJ.prototype = new W_Tjfx_Base();