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

function W_KeHuYeErTongJi() {

	 var self=this;
	 this.Instance=null;
	 var requestor= new PBWindow();
	 var cb_2= new CommandButton( requestor );
	 var cb_1= new CommandButton( requestor );
	 var rb_yk= new RadioButton( requestor );
	 var rb_qk= new RadioButton( requestor );
	 var rb_sy= new RadioButton( requestor );
	 var dp_2= new DatePicker( requestor );
	 var dp_1= new DatePicker( requestor );
	 var cbx_arq= new CheckBox( requestor );
	 var sle_bmbh= new SingleLineEdit( requestor );
	 var sle_khbh= new SingleLineEdit( 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(cb_2 == null ) cb_2= new CommandButton( requestor );
		 cb_2.Attach( win.Control( "cb_2") ); 
		 if(cb_1 == null ) cb_1= new CommandButton( requestor );
		 cb_1.Attach( win.Control( "cb_1") ); 
		 if(rb_yk == null ) rb_yk= new RadioButton( requestor );
		 rb_yk.Attach( win.Control( "rb_yk") ); 
		 if(rb_qk == null ) rb_qk= new RadioButton( requestor );
		 rb_qk.Attach( win.Control( "rb_qk") ); 
		 if(rb_sy == null ) rb_sy= new RadioButton( requestor );
		 rb_sy.Attach( win.Control( "rb_sy") ); 
		 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(cbx_arq == null ) cbx_arq= new CheckBox( requestor );
		 cbx_arq.Attach( win.Control( "cbx_arq") ); 
		 if(sle_bmbh == null ) sle_bmbh= new SingleLineEdit( requestor );
		 sle_bmbh.Attach( win.Control( "sle_bmbh") ); 
		 if(sle_khbh == null ) sle_khbh= new SingleLineEdit( requestor );
		 sle_khbh.Attach( win.Control( "sle_khbh") ); 
		 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.Changebmbh)=="function") 
			 win.AttachEvent("cb_2","Clicked",self.Changebmbh); 

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

		 if(typeof(self.Yk)=="function") 
			 win.AttachEvent("rb_yk","Clicked",self.Yk); 

		 if(typeof(self.Qk)=="function") 
			 win.AttachEvent("rb_qk","Clicked",self.Qk); 

		 if(typeof(self.Sy)=="function") 
			 win.AttachEvent("rb_sy","Clicked",self.Sy); 

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

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

	 }

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

		 cb_2.Detach(); cb_2=null; 
		 cb_1.Detach(); cb_1=null; 
		 rb_yk.Detach(); rb_yk=null; 
		 rb_qk.Detach(); rb_qk=null; 
		 rb_sy.Detach(); rb_sy=null; 
		 dp_2.Detach(); dp_2=null; 
		 dp_1.Detach(); dp_1=null; 
		 cbx_arq.Detach(); cbx_arq=null; 
		 sle_bmbh.Detach(); sle_bmbh=null; 
		 sle_khbh.Detach(); sle_khbh=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 lastSortName = "";
    var curYhbh = "";
    var curCdbh = "";
    var curKhyeJqdBm = "0"; // 精确到部门
    var curBbmc = "rb_sp";
    var curArqFlag = ""; //按日期；
  
    this.postOpen = function () {
        cbx_arq.SetChecked(true);
        curCdbh = requestor.GetParm("curCdbh");
        curYhbh = requestor.GetParm("curYhbh");
        curKhyeJqdBm = GetGlobalParm("cw_jqdbm", "jqdbm", "qybz");
        curKhdzdNew = GetGlobalParm("XTCS", "CW_NEW", "qybz");
    }
    this.Query = function () {
       // dw_list.SetClickHeaderSort(true);
        curArqFlag = cbx_arq.GetChecked();
        var curBeginDate = UtcDateFormatToString(dp_1.GetValue());
        var curEndDate = UtcDateFormatToString(dp_2.GetValue());
        var curKhs = sle_khbh.GetText();
        var curKhsFlag = "N";
        curKhs = curKhs.replace(new RegExp(/(')/g), '')
        if (curKhs.length > 0) {
            curKhsFlag = "Y";
        }
        var curBms = sle_bmbh.GetText();
        var curBmsFlag = "N";
        curBms = curBms.replace(new RegExp(/(')/g), '')
        if (curBms.length > 0) {
            curBmsFlag = "Y";
        }
        if (curKhyeJqdBm == "1") {

            if (curArqFlag) {
                dw_list.SetDataObject("da_cw_khye_bmkh_list_rye");
                dw_list.Retrieve(curBeginDate, curEndDate, curYhbh, curKhs, curKhsFlag, curBms, curBmsFlag);
            } else {
                dw_list.SetDataObject("da_cw_khye_bmkh_list");
                dw_list.RetrieveEx(self.GetSqlWhere(true));
            }
        }
        else {
            if (curArqFlag) {
                dw_list.SetDataObject("da_cw_khye_kh_list_rye");
                dw_list.Retrieve(curBeginDate, curEndDate, curYhbh, curKhs, curKhsFlag);
            } else {
                dw_list.SetDataObject("da_cw_khye_kh_list");
                dw_list.RetrieveEx(self.GetSqlWhere(true));
            }
        }

        if (rb_qk.GetChecked()) {
            if (curArqFlag) {
                dw_list.SetFilter("ljye<0");
            } else {
                dw_list.SetFilter("ye<0");
            }
            dw_list.Filter();
        }

        if (rb_yk.GetChecked()) {
            if (curArqFlag) {
                dw_list.SetFilter("ljye>0");
            } else {
                dw_list.SetFilter("ye>0");
            }
            dw_list.Filter();
        }


        dw_list.SetRowSelection("1");
        dw_list.Modify("khmc.width='140' ye.width='110' dj.width='110' bzj.width='110'");
    }

    //#region 获取where 条件
    this.GetSqlWhere = function (flag) {
        var realSql = " 1=1 ";
        var curBm = sle_bmbh.GetText();
        var curGys = sle_khbh.GetText();


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

        if (curGys.length > 0) {
            curGys = self.DealWords(curGys);

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

        }

       
        return realSql;
    }
    //#endregion

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

    this.Changebmbh = function (x, y, row, dwoName) {
        dwoName == "bmbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(self, "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.Changegys = function (x, y, row, dwoName) {
        dwoName == "khbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(self, "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);
    }

    //#endregion

    //#region 选中后赋值

    this.SetSleValue = function (difBh, val) {

        if ("''" == val)
            val = "";
        if ("bmbh" == difBh)
            sle_bmbh.SetText(val);
        else if ("khbh" == difBh)
            sle_khbh.SetText(val);
    }

    //#endregion

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

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

        return words;

    }
    //#endregion

//    this.Sy = function () {
//        if (curArqFlag) {
//            dw_list.SetFilter(" 1=1 ");
//        } else {
//            dw_list.SetFilter(" 1=1 ");
//        }
//        dw_list.Filter();
//    }

//    this.Qk = function () {
//        if (curArqFlag) {
//            dw_list.SetFilter("ljye<0");
//        } else {
//            dw_list.SetFilter("ye<0");
//        }
//        dw_list.Filter();
//    }

//    this.Yk = function () {
//        if (curArqFlag) {
//            dw_list.SetFilter("ljye>0");
//        } else {
//            dw_list.SetFilter("ye>0");
//        }
//        dw_list.Filter();
//    }




    this.dw_hz_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();
            }
        }

        if (row < 1) {
            return;
        }
        var curBeginDate = UtcDateFormatToString(dp_1.GetValue());
        var curEndDate = UtcDateFormatToString(dp_2.GetValue());
        var curKhbh = dw_list.GetItemString(row, "khbh");
        //如果不按日期,日期取最大值
        //        if (!curArqFlag) {
        //            curBeginDate = "2001-01-01";
        //            curEndDate = "2025-01-01";
        //        }
        var curBmbh = ""
        try {
            curBmbh = dw_list.GetItemString(row, "bmbh");
        } catch (e) {

        }
        var ts_1 = window.external.Control("ts_1");
        var curParam = curBeginDate + "@@@" + curEndDate + "@@@" + curKhbh + "@@@" + curBmbh
        var itemData = "SJ525"
        var itemLabel = "客户对账单";
        ts_1.CloseItem(itemData);
        // alert("/Service/OpenSheet.aspx?FunID=" + itemData + "&Reload=Y&curFromKHYE=" + curParam + "&curDate=" + new Date().toLocaleTimeString());
        ts_1.Open(itemData, itemLabel, '', "/Service/OpenSheet.aspx?FunID=" + itemData + "&Reload=Y&curFromKHYE=" + curParam + "&curDate=" + new Date().toLocaleTimeString(), true);

    }

   
}
W_KeHuYeErTongJi.prototype = new W_Tjfx_Base();