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

	 var self=this;
	 this.Instance=null;
	 var requestor= new PBWindow();
	 var dw_1= new DataWindow( requestor );
	 var st_YsyfDx= new StaticText( requestor );
	 var cb_Xzgys= new CommandButton( requestor );
	 var cb_Xzbm= new CommandButton( requestor );
	 var dp_RqEnd= new DatePicker( requestor );
	 var sle_Gysbh= new SingleLineEdit( requestor );
	 var sle_Pzh= new SingleLineEdit( requestor );
	 var dp_RqBegin= new DatePicker( requestor );
	 var sle_Lydh= new SingleLineEdit( requestor );
	 var sle_Bmbh= new SingleLineEdit( 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(dw_1 == null ) dw_1= new DataWindow( requestor );
		 dw_1.Attach( win.Control( "dw_1") ); 
		 if(st_YsyfDx == null ) st_YsyfDx= new StaticText( requestor );
		 st_YsyfDx.Attach( win.Control( "st_YsyfDx") ); 
		 if(cb_Xzgys == null ) cb_Xzgys= new CommandButton( requestor );
		 cb_Xzgys.Attach( win.Control( "cb_Xzgys") ); 
		 if(cb_Xzbm == null ) cb_Xzbm= new CommandButton( requestor );
		 cb_Xzbm.Attach( win.Control( "cb_Xzbm") ); 
		 if(dp_RqEnd == null ) dp_RqEnd= new DatePicker( requestor );
		 dp_RqEnd.Attach( win.Control( "dp_RqEnd") ); 
		 if(sle_Gysbh == null ) sle_Gysbh= new SingleLineEdit( requestor );
		 sle_Gysbh.Attach( win.Control( "sle_Gysbh") ); 
		 if(sle_Pzh == null ) sle_Pzh= new SingleLineEdit( requestor );
		 sle_Pzh.Attach( win.Control( "sle_Pzh") ); 
		 if(dp_RqBegin == null ) dp_RqBegin= new DatePicker( requestor );
		 dp_RqBegin.Attach( win.Control( "dp_RqBegin") ); 
		 if(sle_Lydh == null ) sle_Lydh= new SingleLineEdit( requestor );
		 sle_Lydh.Attach( win.Control( "sle_Lydh") ); 
		 if(sle_Bmbh == null ) sle_Bmbh= new SingleLineEdit( requestor );
		 sle_Bmbh.Attach( win.Control( "sle_Bmbh") ); 
		 if(tb_1 == null ) tb_1= new ToolStrip( requestor );
		 tb_1.Attach( win.Control( "tb_1") ); 

		 if(typeof(self.Xzgys)=="function") 
			 win.AttachEvent("cb_Xzgys","Clicked",self.Xzgys); 

		 if(typeof(self.Xzbm)=="function") 
			 win.AttachEvent("cb_Xzbm","Clicked",self.Xzbm); 

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

		 if(typeof(self.ReSet)=="function") 
			 win.AttachEvent("btn_ReSet","Clicked",self.ReSet); 

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

		 dw_1.Detach(); dw_1=null; 
		 st_YsyfDx.Detach(); st_YsyfDx=null; 
		 cb_Xzgys.Detach(); cb_Xzgys=null; 
		 cb_Xzbm.Detach(); cb_Xzbm=null; 
		 dp_RqEnd.Detach(); dp_RqEnd=null; 
		 sle_Gysbh.Detach(); sle_Gysbh=null; 
		 sle_Pzh.Detach(); sle_Pzh=null; 
		 dp_RqBegin.Detach(); dp_RqBegin=null; 
		 sle_Lydh.Detach(); sle_Lydh=null; 
		 sle_Bmbh.Detach(); sle_Bmbh=null; 
		 tb_1.Detach(); tb_1=null; 
		 requestor.Detach(); requestor=null; 

		 setTimeout(CollectGarbage, 100); 
	 }

	 //以上代码由设计器自动生成,请不要手工修改
	 //ExtPB.Net JavaScript End  设计器查找标志,请不要删除或修改

var CurOpenWindow = new OpenWindowQueryBase();

var curW_OPEN_BMDA_NEW = new OpenWindowQueryNewBase();
var curW_OPEN_BMDA_URL = "OpenWindowQueryNewBase";
    
    
    //var curYsyfDx = 2;
    //var bmFlag = 1;

    this.Xzbm = function () {
        //bmFlag = 1;
        curW_OPEN_BMDA_NEW.SetDataWindow(dw_1, "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.Xzgys = function () {
//        if (curYsyfDx == 1) {
//            CurOpenWindow.SetDataWindow(dw_1, "khbh", "khmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
//            requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowQueryBase&treeDw=dw_da_khda_fl_tree&listDw=dw_pub_khda_list&treeRootLabel=客户分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&selectStyle=multiple"), CurOpenWindow, null);
//        } else if (curYsyfDx == 2) {
        curW_OPEN_BMDA_NEW.SetDataWindow(dw_1, "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);
//        } else if (curYsyfDx == 3) {
//            bmFlag = 0;
//            CurOpenWindow.SetDataWindow(dw_1, "bmbh", "bmmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
//            requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowQueryBase&treeDw=dw_da_bmda_fl_tree&listDw=dw_pub_list_bmda&treeRootLabel=部门分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&selectStyle=multiple&curQxlx=cwcx"), CurOpenWindow, null);
//        }
    }

    this.SetSleValue = function (difBh, val) {
        if ("''" == val) {
            val = "";
        }
        if ("bmbh" == difBh) {
            //if (bmFlag == 1) {
                sle_Bmbh.SetText(val);
//            } else {
//                sle_Gysbh.SetText(val);
//            }
        } else if ("gysbh" == difBh) {
            sle_Gysbh.SetText(val);
        }
    }

    this.Query = function () {
        var sqlWhere = self.GetSqlWhere();
        dw_1.RetrieveEx(sqlWhere);
    }

    this.GetSqlWhere = function () {
        var sqlWhere = " (1=1) ";

        var rqBegin = UtcDateFormatToString(dp_RqBegin.GetValue());
        var rqEnd = UtcDateFormatToString(dp_RqEnd.GetValue());
        sqlWhere += " and (convert(date,cw_yfkzd.zdrq) between CONVERT(date, '" + rqBegin + "') and CONVERT(date, '" + rqEnd + "')) "
        var bmbh = sle_Bmbh.GetText();
        if (bmbh.length > 0) {
            sqlWhere += " and cw_yfkzd.bmbh in (" + bmbh + ") ";
        } else {
            sqlWhere += " and cw_yfkzd.bmbh in (select bmbh from da_qx_bmqxsz where yhbh = '" + requestor.GetParm("CurBmbh") + "' and cwcx = '1') ";
        }
        var gysbh = sle_Gysbh.GetText();
        if (gysbh.length > 0) {
            sqlWhere += " and cw_yfkzd.gysbh in (" + gysbh + ") ";
        }
        var pzh = sle_Pzh.GetText();
        if (pzh.length > 0) {
            sqlWhere += " and cw_yfkzd.zdbh like '%" + pzh + "%' ";
        }
        var lydh = sle_Lydh.GetText();
        if (lydh.length > 0) {
            sqlWhere += " and cw_yfkzd.lydh like '%" + lydh + "%' ";
        }

        return sqlWhere;
    }

//    this.YsyfDxZh = function (index) {
//        curYsyfDx = index;
//        if (curYsyfDx == 1) {
//            st_YsyfDx.SetText("客户编号：");
//        } else if (curYsyfDx == 2) {
//            st_YsyfDx.SetText("供应商编号：");
//        } else if (curYsyfDx == 3) {
//            st_YsyfDx.SetText("部门编号：");
//        }
//        self.ReSet();
//    }

    this.ReSet = function () {
        sle_Bmbh.SetText("");
        sle_Gysbh.SetText("");
        sle_Lydh.SetText("");
        sle_Pzh.SetText("");
    }

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