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

	 var self=this;
	 this.Instance=null;
	 var requestor= new PBWindow();
	 var dw_da_qx_mokuai_print= new DataWindow( requestor );
	 var dw_parameter= new DataWindow( requestor );
	 var dw_xt_div_tree_no_parm= new DataWindow( requestor );
	 var dw_3= new DataWindow( requestor );
	 var dw_proxy= new DataWindow( requestor );
	 var dw_da_qx_mokuai= new DataWindow( requestor );
	 var dw_sort= new DataWindow( requestor );
	 var dw_print= new DataWindow( requestor );
	 var dw_2= new DataWindow( requestor );
	 var dw_init= new DataWindow( requestor );
	 var dw_mx_print= new DataWindow( requestor );
	 var dw_hz= 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(dw_da_qx_mokuai_print == null ) dw_da_qx_mokuai_print= new DataWindow( requestor );
		 dw_da_qx_mokuai_print.Attach( win.Control( "dw_da_qx_mokuai_print") ); 
		 if(dw_parameter == null ) dw_parameter= new DataWindow( requestor );
		 dw_parameter.Attach( win.Control( "dw_parameter") ); 
		 if(dw_xt_div_tree_no_parm == null ) dw_xt_div_tree_no_parm= new DataWindow( requestor );
		 dw_xt_div_tree_no_parm.Attach( win.Control( "dw_xt_div_tree_no_parm") ); 
		 if(dw_3 == null ) dw_3= new DataWindow( requestor );
		 dw_3.Attach( win.Control( "dw_3") ); 
		 if(dw_proxy == null ) dw_proxy= new DataWindow( requestor );
		 dw_proxy.Attach( win.Control( "dw_proxy") ); 
		 if(dw_da_qx_mokuai == null ) dw_da_qx_mokuai= new DataWindow( requestor );
		 dw_da_qx_mokuai.Attach( win.Control( "dw_da_qx_mokuai") ); 
		 if(dw_sort == null ) dw_sort= new DataWindow( requestor );
		 dw_sort.Attach( win.Control( "dw_sort") ); 
		 if(dw_print == null ) dw_print= new DataWindow( requestor );
		 dw_print.Attach( win.Control( "dw_print") ); 
		 if(dw_2 == null ) dw_2= new DataWindow( requestor );
		 dw_2.Attach( win.Control( "dw_2") ); 
		 if(dw_init == null ) dw_init= new DataWindow( requestor );
		 dw_init.Attach( win.Control( "dw_init") ); 
		 if(dw_mx_print == null ) dw_mx_print= new DataWindow( requestor );
		 dw_mx_print.Attach( win.Control( "dw_mx_print") ); 
		 if(dw_hz == null ) dw_hz= new DataWindow( requestor );
		 dw_hz.Attach( win.Control( "dw_hz") ); 
		 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.dw_hz_DoubleClicked)=="function") 
			 win.AttachEvent("dw_hz","DoubleClicked",self.dw_hz_DoubleClicked); 

		 if(typeof(self.Add)=="function") 
			 win.AttachEvent("btn_Add","Clicked",self.Add); 

		 if(typeof(self.Edit)=="function") 
			 win.AttachEvent("btn_Edit","Clicked",self.Edit); 

		 if(typeof(self.Delete)=="function") 
			 win.AttachEvent("btn_Delete","Clicked",self.Delete); 

		 if(typeof(self.Audit)=="function") 
			 win.AttachEvent("btn_Audit","Clicked",self.Audit); 

		 if(typeof(self.Print)=="function") 
			 win.AttachEvent("btn_Print","Clicked",self.Print); 

		 if(typeof(self.Export)=="function") 
			 win.AttachEvent("btn_Export","Clicked",self.Export); 

		 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_da_qx_mokuai_print.Detach(); dw_da_qx_mokuai_print=null; 
		 dw_parameter.Detach(); dw_parameter=null; 
		 dw_xt_div_tree_no_parm.Detach(); dw_xt_div_tree_no_parm=null; 
		 dw_3.Detach(); dw_3=null; 
		 dw_proxy.Detach(); dw_proxy=null; 
		 dw_da_qx_mokuai.Detach(); dw_da_qx_mokuai=null; 
		 dw_sort.Detach(); dw_sort=null; 
		 dw_print.Detach(); dw_print=null; 
		 dw_2.Detach(); dw_2=null; 
		 dw_init.Detach(); dw_init=null; 
		 dw_mx_print.Detach(); dw_mx_print=null; 
		 dw_hz.Detach(); dw_hz=null; 
		 tb_1.Detach(); tb_1=null; 
		 requestor.Detach(); requestor=null; 

		 setTimeout(CollectGarbage, 100); 
	 }

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



    var curYhbh = "", curQxStr="";
    var curW_GysJsd_Edit = new W_GysJsd_Edit();
 
    var webReq = new WebRequestor();
    webReq.SetWebServiceUrl("/Service/ServiceCaiWu.ashx");

       var curSelDays = ""; //默认该模块可查询天数
    var curSelSQL = "";
    var curSfQYQXZ = "0";  // 是否启用新版权限组。
    var curUserGroupId = ""; //权限组编码
    var curDzdPzh = "";

    this.PostOpen = function () {
        curYhbh = requestor.GetParm("curYhbh");
        curKhyeJqdBm = "1";
        curSfQYQXZ = "1"
        curUserGroupId = requestor.GetParm("curUserGroupId"); //权限组编码
        curSfQyQDID = "1"
        curJqm = requestor.GetParm("curJqm");
        curQxStr = requestor.GetParm("curQxStr");

    }
    this.dw_hz_DoubleClicked = function () {
        self.Edit();
    }
    this.Add = function () { 
        curW_GysJsd_Edit.SetDataWindow("Add",self, dw_hz,"");
        requestor.Open("/Service/LoadWindow.ashx?WinName=A8ERP.CaiWu.GysJsd.W_GysJsd_Edit&curParm1=ADD", curW_GysJsd_Edit, null);  
    }
    this.Edit = function () {
        var row = dw_hz.GetRow();
        if (row < 1) {
            requestor.MessageBox("提示", "请选择要编辑的单据行！", ICON.Information);
            return;
        }
        var curPzh = dw_hz.GetItemString(row, "pzh");
        curW_GysJsd_Edit.SetDataWindow("Edit", self, dw_hz, curPzh);
        alert(curQxStr);
        requestor.Open("/Service/LoadWindow.ashx?WinName=A8ERP.CaiWu.GysJsd.W_GysJsd_Edit&curParm1=EDIT&curPzh=" + curPzh + "&CURGNQXSTR=" + curQxStr, curW_GysJsd_Edit, null);

    }
    this.Delete = function () {

        var curPzh = "";
        var curPzhRow = 0;
        if (dw_hz.RowCount() < 1) {
            requestor.MessageBox("提示", "您还没有勾选采购单，请检查。", ICON.StopSign);
            return;
        } else {
            curPzhRow = dw_hz.GetRow();
            curPzh = dw_hz.GetItemString(curPzhRow, "pzh");

            if (!confirm("您确定要删除凭证号【" + curPzh + "】的供应商结算单？")) {
                return;
            }
        }

        //#endregion
        webReq.Invoke("DeleteGysJsd", "curPzh=" + curPzh);

        if (webReq.StatusCode() == 200) {
            var curMsg = webReq.ResponseText();
            if (curMsg.split('#')[0] == "Y") {
                requestor.MessageBox("提示", "删除成功!", ICON.Information);
                dw_hz.DeleteRow(curPzhRow);
            } else {
                requestor.MessageBox("提示", curMsg.split('#')[1], ICON.StopSign);
                return;
            }
        }
        else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
        }

    }
    this.Audit = function () {
        var curPzh = "";
        var curPzhRow = 0;
        if (dw_hz.RowCount() < 1) {
            requestor.MessageBox("提示", "您还没有勾选采购单，请检查。", ICON.StopSign);
            return;
        } else {
            curPzhRow = dw_hz.GetRow();
            curPzh = dw_hz.GetItemString(curPzhRow, "pzh");
            if (!confirm("您确定要审核凭证号【" + curPzh + "】的供应商结算单？")) {
                return;
            }
        }

        //#endregion
        webReq.Invoke("AuditGysJsd", "curPzh=" + curPzh);

        if (webReq.StatusCode() == 200) {
            var curMsg = webReq.ResponseText();
            if (curMsg.split('#')[0] == "Y") {
                requestor.MessageBox("提示", "审核成功!", ICON.Information);
                dw_hz.SetItem(curPzhRow, "shbz", "1");
                dw_hz.Refresh();
                dw_hz.ScrollToRow(curPzhRow);
            } else {
                requestor.MessageBox("提示", curMsg.split('#')[1], ICON.StopSign);
                return;
            }
        }
        else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
        }

    }

  

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

        dw_hz.Export();
    } 
    
     this.Print = function () {
        var row = dw_hz.GetRow();
        if (row < 1) {
            requestor.MessageBox("提示", "请选择要编辑的单据行！", ICON.Information);
            return;
        }
        var curPzh = dw_hz.GetItemString(row, "pzh");
        dw_print.Retrieve(curPzh);
    }

    //#region this.Print
    this.Print = function () {
        var row = dw_hz.GetRow();
        if (row < 1) {
            requestor.MessageBox("提示", "请选择要编辑的单据行！", ICON.Information);
            return;
        }
        var curPzh = dw_hz.GetItemString(row, "pzh");
        dw_mx_print.Retrieve(curPzh);

        var v = A8erp_Biz_Print.Yw_Gysjsd_Print_Jqm(self, requestor, dw_hz, dw_hz, dw_mx_print, dw_print, dw_proxy, dw_sort, dw_xt_div_tree_no_parm, dw_da_qx_mokuai, dw_da_qx_mokuai_print, dw_parameter, dw_init, curKhyeJqdBm, curPzh, "1", curJqm, curSfQYQXZ, curUserGroupId);
        if (v == "N") {
            return;
        } 
        dw_print.PrintPreview();
    }

    this.isMyHave = function (str1, str2) {
        var re = "-1";
        if (str1.length > 0 && str2.length > 0) {
            var str1s = str1.split("@");
            for (var i = 0; i < str1s.length; i++) {
                if (str1s[i].split("#")[0] == str2) {
                    return str1s[i].split("#")[1];
                    break;
                }
            }
        }
        return re;
    }
    //#endregion

    //#region  排序和宽度。。
    this.DoSort = function (curSortStrs, isReturnStrBool) {
        if (curSortStrs == null || curSortStrs.length < 1) {
            return;
        }
        var curSortStringArr = curSortStrs.split(",");
        var curModifyStr = "";
        for (var i = 0; i < curSortStringArr.length; i++) {
            curModifyStr += curSortStringArr[i].split("#")[0] + ".x='" + curSortStringArr[i].split("#")[1] + "' ";
            curModifyStr += curSortStringArr[i].split("#")[0] + ".width='" + curSortStringArr[i].split("#")[2] + "' ";
        }
        if (isReturnStrBool) {
            return curModifyStr.toString();
        } else {
            dw_print.Modify(curModifyStr.toString());
        }

    }
    this.isHave = function (str1, str2) {
        var re = false;
        if (str1.length > 0 && str2.length > 0) {
            var str1s = str1.split(",");
            for (var i = 0; i < str1s.length; i++) {
                if (str1s[i] == str2) {
                    return true;
                    break;
                }
            }
        }
        return re;
    }
    this.getMyNewStr = function (allColArr, noVisibleColStr) {   //  所有列，不显示的列，返回：要显示的所有列

        var curShowcolArrs = "";
        for (var i = 0; i < allColArr.length; i++) {
            if (!self.isHave(noVisibleColStr, allColArr[i].split("#")[0])) {  // 要显示           
                if (curShowcolArrs.length > 0) {
                    curShowcolArrs += "@" + allColArr[i];
                } else {
                    curShowcolArrs += allColArr[i];
                }
            }
        }
        return curShowcolArrs;
    }


    //#endregion 

    //#region 格式保存
    this.savegs = function () {

        var msg = savegs(dw_hz, curYhbh, requestor.GetParm("curFunctionId"));
        alert(msg);
    }
    //#endregion

    //#region 清除保存
    this.qcgs = function () {
        var msg = qcgs(curYhbh, requestor.GetParm("curFunctionId"));
        alert(msg);

    }
    //#endregion
}