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

	 var self=this;
	 this.Instance=null;
	 var requestor= new PBWindow();
	 var tab_1= new TabControl( requestor );
	 var dw_mkfhjb= new DataWindow( requestor );
	 var dw_hz= new DataWindow( requestor );
	 var dw_mx= new DataWindow( requestor );
	 var dw_khye= new DataWindow( requestor );
	 var dw_mx_top= new DataWindow( requestor );
	 var tb_1= new ToolStrip( requestor );
	 var ddlb_1= new DropDownListBox( requestor );
	 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 ContextMenuStrip1= new ContextMenu( requestor );
	 var ContextMenuStrip2= 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(tab_1 == null ) tab_1= new TabControl( requestor );
		 tab_1.Attach( win.Control( "tab_1") ); 
		 if(dw_mkfhjb == null ) dw_mkfhjb= new DataWindow( requestor );
		 dw_mkfhjb.Attach( win.Control( "dw_mkfhjb") ); 
		 if(dw_hz == null ) dw_hz= new DataWindow( requestor );
		 dw_hz.Attach( win.Control( "dw_hz") ); 
		 if(dw_mx == null ) dw_mx= new DataWindow( requestor );
		 dw_mx.Attach( win.Control( "dw_mx") ); 
		 if(dw_khye == null ) dw_khye= new DataWindow( requestor );
		 dw_khye.Attach( win.Control( "dw_khye") ); 
		 if(dw_mx_top == null ) dw_mx_top= new DataWindow( requestor );
		 dw_mx_top.Attach( win.Control( "dw_mx_top") ); 
		 if(tb_1 == null ) tb_1= new ToolStrip( requestor );
		 tb_1.Attach( win.Control( "tb_1") ); 
		 if(ddlb_1 == null ) ddlb_1= new DropDownListBox( requestor );
		 ddlb_1.Attach( win.Control( "ddlb_1") ); 
		 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(ContextMenuStrip1 == null ) ContextMenuStrip1= new ContextMenu( requestor );
		 ContextMenuStrip1.Attach( win.Control( "ContextMenuStrip1") ); 
		 if(ContextMenuStrip2 == null ) ContextMenuStrip2= new ContextMenu( requestor );
		 ContextMenuStrip2.Attach( win.Control( "ContextMenuStrip2") ); 

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

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

		 if(typeof(self.Tab_1_Clicked)=="function") 
			 win.AttachEvent("tab_1","Clicked",self.Tab_1_Clicked); 

		 if(typeof(self.dw_hz_Clicked)=="function") 
			 win.AttachEvent("dw_hz","Clicked",self.dw_hz_Clicked); 

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

		 if(typeof(self.Hz_RowFocusChanged)=="function") 
			 win.AttachEvent("dw_hz","RowFocusChanged",self.Hz_RowFocusChanged); 

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

		 if(typeof(self.dw_mx_editChanged)=="function") 
			 win.AttachEvent("dw_mx","EditChanged",self.dw_mx_editChanged); 

		 if(typeof(self.dw_mx_itemChanged)=="function") 
			 win.AttachEvent("dw_mx","ItemChanged",self.dw_mx_itemChanged); 

		 if(typeof(self.dw_mx_keyDown)=="function") 
			 win.AttachEvent("dw_mx","KeyDown",self.dw_mx_keyDown); 

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

		 if(typeof(self.dw_mx_top_editChanged)=="function") 
			 win.AttachEvent("dw_mx_top","EditChanged",self.dw_mx_top_editChanged); 

		 if(typeof(self.Top_itemChanged)=="function") 
			 win.AttachEvent("dw_mx_top","ItemChanged",self.Top_itemChanged); 

		 if(typeof(self.Dw_mx_top_KeyDown)=="function") 
			 win.AttachEvent("dw_mx_top","KeyDown",self.Dw_mx_top_KeyDown); 

		 if(typeof(self.ChaXun)=="function") 
			 win.AttachEvent("btn_ChaXun","Clicked",self.ChaXun); 

		 if(typeof(self.SelectionChanged)=="function") 
			 win.AttachEvent("ddlb_1","SelectionChanged",self.SelectionChanged); 

		 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.UnAudit)=="function") 
			 win.AttachEvent("btn_UnAudit","Clicked",self.UnAudit); 

		 if(typeof(self.FAudit)=="function") 
			 win.AttachEvent("btn_FAudit","Clicked",self.FAudit); 

		 if(typeof(self.Tally)=="function") 
			 win.AttachEvent("btn_Tally","Clicked",self.Tally); 

		 if(typeof(self.InsertRow)=="function") 
			 win.AttachEvent("btn_InsertRow","Clicked",self.InsertRow); 

		 if(typeof(self.DeleteRow)=="function") 
			 win.AttachEvent("btn_DeleteRow","Clicked",self.DeleteRow); 

		 if(typeof(self.Save)=="function") 
			 win.AttachEvent("btn_Save","Clicked",self.Save); 

		 if(typeof(self.Cancel)=="function") 
			 win.AttachEvent("btn_Cancel","Clicked",self.Cancel); 

		 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(self.savegs)=="function") 
			 win.AttachEvent("保存格式ToolStripMenuItem","Clicked",self.savegs); 

		 if(typeof(self.qcgs)=="function") 
			 win.AttachEvent("清除格式ToolStripMenuItem","Clicked",self.qcgs); 

		 if(typeof(self.Copy)=="function") 
			 win.AttachEvent("复制凭证号ToolStripMenuItem","Clicked",self.Copy); 

		 if(typeof(self.CopyBzxx)=="function") 
			 win.AttachEvent("复制备注信息ToolStripMenuItem","Clicked",self.CopyBzxx); 

	 }

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

		 tab_1.Detach(); tab_1=null; 
		 dw_mkfhjb.Detach(); dw_mkfhjb=null; 
		 dw_hz.Detach(); dw_hz=null; 
		 dw_mx.Detach(); dw_mx=null; 
		 dw_khye.Detach(); dw_khye=null; 
		 dw_mx_top.Detach(); dw_mx_top=null; 
		 tb_1.Detach(); tb_1=null; 
		 ddlb_1.Detach(); ddlb_1=null; 
		 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; 
		 ContextMenuStrip1.Detach(); ContextMenuStrip1=null; 
		 ContextMenuStrip2.Detach(); ContextMenuStrip2=null; 
		 requestor.Detach(); requestor=null; 

		 setTimeout(CollectGarbage, 100); 
	 }

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

    var editMode = "";
    var curYhbh = "";
    var curW_OPEN = new OpenWindowQueryBase();
    var curW_CaiWuChaXun = new W_CaiWuChaXun();
    var dwc = new DataWindowChild();
    var webReq = new WebRequestor();
    var curZhbz = "";
    var curKhyeJqdBm = "0"; //1客户余额精确到部门。
    webReq.SetWebServiceUrl("/Service/ServiceCaiWu.ashx");

    var webReqTimestamp = new WebRequestor();
    webReqTimestamp.SetWebServiceUrl("/Service/GetPublicData.ashx");

    var webReq1 = new WebRequestor();
    webReq1.SetWebServiceUrl("/Service/ServiceKuCunGuanLi.ashx");
    var isAdd = false;
    var curSfQyQDID = "0";  // 如果启用渠道ID,默认不启用
    var curJqm = "";
    var curQxLzfc = "";    // 当前用户对应权限的列字符串；

    var curSelDays = ""; //默认该模块可查询天数
    var curSelSQL = "";

    var curSfQYQXZ = "0";  // 是否启用新版权限组。
    var curUserGroupId = ""; //权限组编码

    var curDzdPzh = "";
    var curDeleRow = 0;
    this.PostOpen = function () {
        curYhbh = requestor.GetParm("curYhbh");
        curKhyeJqdBm = GetGlobalParm("cw_jqdbm", "gys_jqdbm", "qybz");

        curSfQyQDID = GetGlobalParm("XTCS", "SFQYQDID", "qybz");
        curJqm = requestor.GetParm("curJqm");

        curSelDays = requestor.GetParm("seldays");
        curSfQYQXZ = GetGlobalParm("XTCS", "SFQYQXZ-NEW", "qybz"); // 是否启用新版权限组。
        curUserGroupId = requestor.GetParm("curUserGroupId"); //权限组编码
        curDzdPzh = requestor.GetParm("curDzdPzh");
//        alert(curDzdPzh);

        if (curDzdPzh.length > 0) {

            tab_1.SetSelectedTab(2);

            dw_mx_top.Retrieve(curDzdPzh);
            dw_mx.Retrieve(curDzdPzh);
            dw_mx_top.Modify("DataWindow.Readonly=yes");
            dw_mx.Modify("DataWindow.Readonly=yes")
            tab_1.SetEnabled(false);
            tb_1.SetVisible("btn_Add", false);

            tb_1.SetVisible("btn_Edit", false);
            tb_1.SetVisible("btn_Delete", false);
            tb_1.SetVisible("btn_Audit", false);
            tb_1.SetVisible("btn_UnAudit", false);
            tb_1.SetVisible("btn_FAudit", false);
            tb_1.SetVisible("btn_Tally", false);
            tb_1.SetVisible("btn_Save", false);
            tb_1.SetVisible("btn_Cancel", false);
            tb_1.SetVisible("btn_Filter", false);
            tb_1.SetVisible("btn_Export", false);
            tb_1.SetVisible("btn_ChaXun", false);
            tb_1.SetVisible("ddlb_1", false);
            dw_mx_top.Retrieve(dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh"));
            dw_mx.Retrieve(dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh"));
                        if (curKhyeJqdBm == "1") {
                            dw_mx_top.SetItem(1, "sdye", dw_mx_top.GetItemNumber(1, "bmsdjy"));
                            dw_mx_top.SetItem(1, "bdye", dw_mx_top.GetItemNumber(1, "bmljye"));

                            dw_mx_top.SetItem(1, "ssdjy", dw_mx_top.GetItemNumber(1, "bmsdjy"));
                            dw_mx_top.SetItem(1, "sljye", dw_mx_top.GetItemNumber(1, "bmljye"));


                        } else {
                            dw_mx_top.SetItem(1, "sdye", dw_mx_top.GetItemNumber(1, "sdjy"));
                            dw_mx_top.SetItem(1, "bdye", dw_mx_top.GetItemNumber(1, "ljye"));


                            dw_mx_top.SetItem(1, "ssdjy", dw_mx_top.GetItemNumber(1, "sdjy"));
                            dw_mx_top.SetItem(1, "sljye", dw_mx_top.GetItemNumber(1, "ljye"));
                        }
//                        if (curKhyeJqdBm == "1") {
//                            dw_mx_top.Modify("bmsdjy.visible = '1' bmsdjy_t.visible = '1' bmljye.visible = '1' bmljye_t.visible = '1'");
//                            dw_mx_top.Modify("sdjy.visible = '0' sdjy_t.visible = '0' ljye.visible = '0' ljye_t.visible = '0' ");
//                        } else {
//                            dw_mx_top.Modify("bmsdjy.visible = '0' bmsdjy_t.visible = '0'  bmljye.visible = '0' bmljye_t.visible = '0'");
//                            dw_mx_top.Modify("sdjy.visible = '1' sdjy_t.visible = '1' ljye.visible = '1' ljye_t.visible = '1' ");
//                        }
            return;

        }
        self.SelectionChanged();
        if (dw_hz.RowCount() > 0) {
            var pzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
            dw_mx_top.Retrieve(pzh);
            dw_mx.Retrieve(pzh);
                        if (curKhyeJqdBm == "1") {
                            dw_mx_top.SetItem(1, "sdye", dw_mx_top.GetItemNumber(1, "bmsdjy"));
                            dw_mx_top.SetItem(1, "bdye", dw_mx_top.GetItemNumber(1, "bmljye"));

                            dw_mx_top.SetItem(1, "ssdjy", dw_mx_top.GetItemNumber(1, "bmsdjy"));
                            dw_mx_top.SetItem(1, "sljye", dw_mx_top.GetItemNumber(1, "bmljye"));
                        } else {
                            dw_mx_top.SetItem(1, "sdye", dw_mx_top.GetItemNumber(1, "sdjy"));
                            dw_mx_top.SetItem(1, "bdye", dw_mx_top.GetItemNumber(1, "ljye"));


                            dw_mx_top.SetItem(1, "ssdjy", dw_mx_top.GetItemNumber(1, "sdjy"));
                            dw_mx_top.SetItem(1, "sljye", dw_mx_top.GetItemNumber(1, "ljye"));
                        }
//                        if (curKhyeJqdBm == "1") {
//                            dw_mx_top.Modify("bmsdjy.visible = '1' bmsdjy_t.visible = '1' bmljye.visible = '1' bmljye_t.visible = '1'");
//                            dw_mx_top.Modify("sdjy.visible = '0' sdjy_t.visible = '0' ljye.visible = '0' ljye_t.visible = '0' ");
//                        } else {
//                            dw_mx_top.Modify("bmsdjy.visible = '0' bmsdjy_t.visible = '0'  bmljye.visible = '0' bmljye_t.visible = '0'");
//                            dw_mx_top.Modify("sdjy.visible = '1' sdjy_t.visible = '1' ljye.visible = '1' ljye_t.visible = '1' ");
//                        }

        }
    }

    //#region 无数据时按钮处理
    this.SetButtomStatus = function () {
        // 汇总无数据时
        if (dw_hz.RowCount() < 1) {

            tb_1.SetEnabled("btn_Edit", false);
            tb_1.SetEnabled("btn_Delete", false);
            tb_1.SetEnabled("btn_Audit", false);
            tb_1.SetEnabled("btn_UnAudit", false);
            tb_1.SetEnabled("btn_Tally", false);
            tb_1.SetEnabled("btn_Print", false);
            tb_1.SetEnabled("btn_Export", false);

            tb_1.SetEnabled("btn_Save", false);
        }
    }
    //#endregion

    //#region this.dw_hz_DoubleClicked
    this.dw_hz_DoubleClicked = function (x, y, row, dowName) {
        if (row > 0) {
            tab_1.SelectTab(2);
            tb_1.SetEnabled("ddlb_1", false);
            tb_1.SetEnabled("btn_ChaXun", false);
            tb_1.SetEnabled("btn_Filter", false);
            tb_1.SetEnabled("btn_Export", true);
            var curPzh = dw_hz.GetItemString(row, "pzh");
            dw_mx_top.Retrieve(curPzh);
            dw_mx.Retrieve(curPzh);
            dw_mx_top.Modify("DataWindow.Readonly=yes");
            dw_mx.Modify("DataWindow.Readonly=yes");
            if (curKhyeJqdBm == "1") {
                dw_mx_top.SetItem(1, "sdye", dw_mx_top.GetItemNumber(1, "bmsdjy"));
                dw_mx_top.SetItem(1, "bdye", dw_mx_top.GetItemNumber(1, "bmljye"));

                dw_mx_top.SetItem(1, "ssdjy", dw_mx_top.GetItemNumber(1, "bmsdjy"));
                dw_mx_top.SetItem(1, "sljye", dw_mx_top.GetItemNumber(1, "bmljye"));
            } else {
                dw_mx_top.SetItem(1, "sdye", dw_mx_top.GetItemNumber(1, "sdjy"));
                dw_mx_top.SetItem(1, "bdye", dw_mx_top.GetItemNumber(1, "ljye"));

                dw_mx_top.SetItem(1, "ssdjy", dw_mx_top.GetItemNumber(1, "sdjy"));
                dw_mx_top.SetItem(1, "sljye", dw_mx_top.GetItemNumber(1, "ljye"));
            }
        }

        //打开明细的时候 没有记账的单据 重新获取 期初数据&结余数据
        if (dw_hz.GetItemString(dw_hz.GetRow(), "jzbz") != "1") {
            self.SetSdjy();
            self.SetLjjy();
        }
    }
    //#endregion

    this.Tab_1_Clicked = function (ind) {

        if (ind == "1") {
            tb_1.SetEnabled("ddlb_1", true);
            tb_1.SetEnabled("btn_ChaXun", true);
            tb_1.SetEnabled("btn_Filter", true);
            tb_1.SetEnabled("btn_Export", true);
            if (dw_hz.GetRow() < 1) {
                return;
            }
            self.Cancel();
            self.SelectionChanged_tab(dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh"));

        } else if (ind == "2") {
            tb_1.SetEnabled("ddlb_1", false);
            tb_1.SetEnabled("btn_ChaXun", false);
            tb_1.SetEnabled("btn_Filter", false);
            tb_1.SetEnabled("btn_Export", true);
            var curRowCount = dw_hz.RowCount();
            if (curRowCount < 1) {
//                if (dw_mx_top.RowCount() > 0) {
//                    dw_mx_top.Retrieve(dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh"));
//                    dw_mx.Retrieve(dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh"));
//                    if (curKhyeJqdBm == "1") {
//                        dw_mx_top.SetItem(1, "sdye", dw_mx_top.GetItemNumber(1, "bmsdjy"));
//                        dw_mx_top.SetItem(1, "bdye", dw_mx_top.GetItemNumber(1, "bmljye"));
//                    } else {
//                        dw_mx_top.SetItem(1, "sdye", dw_mx_top.GetItemNumber(1, "sdjy"));
//                        dw_mx_top.SetItem(1, "bdye", dw_mx_top.GetItemNumber(1, "ljye"));
//                    }
//                }
                //                                if (curKhyeJqdBm == "1") {
                //                                    dw_mx_top.Modify("bmsdjy.visible = '1' bmsdjy_t.visible = '1' bmljye.visible = '1' bmljye_t.visible = '1'");
                //                                    dw_mx_top.Modify("sdjy.visible = '0' sdjy_t.visible = '0' ljye.visible = '0' ljye_t.visible = '0' ");
                //                                } else {
                //                                    dw_mx_top.Modify("bmsdjy.visible = '0' bmsdjy_t.visible = '0'  bmljye.visible = '0' bmljye_t.visible = '0'");
                //                                    dw_mx_top.Modify("sdjy.visible = '1' sdjy_t.visible = '1' ljye.visible = '1' ljye_t.visible = '1' ");
                //                                }
                return;
            } if (dw_mx_top.RowCount() > 0) {
                var curPzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
                dw_mx_top.Retrieve(curPzh);
                dw_mx.Retrieve(curPzh);
                dw_mx_top.Modify("DataWindow.Readonly=yes");
                dw_mx.Modify("DataWindow.Readonly=yes");
                if (curKhyeJqdBm == "1") {
                    dw_mx_top.SetItem(1, "sdye", dw_mx_top.GetItemNumber(1, "bmsdjy"));
                    dw_mx_top.SetItem(1, "bdye", dw_mx_top.GetItemNumber(1, "bmljye"));


                    dw_mx_top.SetItem(1, "ssdjy", dw_mx_top.GetItemNumber(1, "bmsdjy"));
                    dw_mx_top.SetItem(1, "sljye", dw_mx_top.GetItemNumber(1, "bmljye"));



                } else {
                    dw_mx_top.SetItem(1, "sdye", dw_mx_top.GetItemNumber(1, "sdjy"));
                    dw_mx_top.SetItem(1, "bdye", dw_mx_top.GetItemNumber(1, "ljye"));


                    dw_mx_top.SetItem(1, "ssdjy", dw_mx_top.GetItemNumber(1, "sdjy"));
                    dw_mx_top.SetItem(1, "sljye", dw_mx_top.GetItemNumber(1, "ljye"));

                }
            }
            //                        if (curKhyeJqdBm == "1") {
            //                            dw_mx_top.Modify("bmsdjy.visible = '1' bmsdjy_t.visible = '1' bmljye.visible = '1' bmljye_t.visible = '1'");
            //                            dw_mx_top.Modify("sdjy.visible = '0' sdjy_t.visible = '0' ljye.visible = '0' ljye_t.visible = '0' ");
            //                        } else {
            //                            dw_mx_top.Modify("bmsdjy.visible = '0' bmsdjy_t.visible = '0'  bmljye.visible = '0' bmljye_t.visible = '0'");
            //                            dw_mx_top.Modify("sdjy.visible = '1' sdjy_t.visible = '1' ljye.visible = '1' ljye_t.visible = '1' ");
            //                        }

            //打开明细的时候 没有记账的单据 重新获取 期初数据&结余数据
            if (dw_hz.GetItemString(dw_hz.GetRow(), "jzbz") != "1") {
                self.SetSdjy();
                self.SetLjjy();
            }
        }
    }

    //#region SelectionChanged_tab
    this.SelectionChanged_tab = function (pzh) {
        var curTabindex = tab_1.GetSelectedTab();

        if (curTabindex == "1") {

            //self.Hz_RowFocusChanged(dw_hz.GetRow());

            var findRowaa = dw_hz.Find("pzh='" + pzh + "' ", 1, dw_hz.RowCount());
            dw_hz.ScrollToRow(findRowaa);
            self.Hz_RowFocusChanged(dw_hz.GetRow());

        } else if (curTabindex == "2") {
            //alert(curTabindex)
            var findRowaa = dw_hz.Find("pzh='" + pzh + "' ", 1, dw_hz.RowCount());
            dw_hz.ScrollToRow(findRowaa);
            self.Hz_RowFocusChanged(dw_hz.GetRow());
        }
    }
    //#endregion

    //#region this.Hz_RowFocusChanged  汇总行改变的时候
    this.Hz_RowFocusChanged = function (row) {
        if (row > 0) {
            var fhStatus = dw_hz.GetItemString(row, "fhjb");
            var curJzbz = dw_hz.GetItemString(row, "jzbz");

            if (fhStatus == "F") {
                tb_1.SetEnabled("btn_Audit", true);
                tb_1.SetEnabled("btn_UnAudit", false);
                tb_1.SetEnabled("btn_Tally", false);
                tb_1.SetEnabled("btn_Delete", true);
                tb_1.SetEnabled("btn_Edit", true);
            } else if (fhStatus == "T") {
                tb_1.SetEnabled("btn_Audit", false);
                tb_1.SetEnabled("btn_Edit", false);
                tb_1.SetEnabled("btn_Delete", false);

                if (dw_hz.GetItemString(row, "jzbz") == "1") {
                    tb_1.SetEnabled("btn_UnAudit", false);
                    tb_1.SetEnabled("btn_Tally", false);
                } else {
                    tb_1.SetEnabled("btn_UnAudit", true);
                    tb_1.SetEnabled("btn_Tally", true);
                }
            } else {
                tb_1.SetEnabled("btn_Audit", true);
                tb_1.SetEnabled("btn_UnAudit", true);
                tb_1.SetEnabled("btn_Tally", false);
                tb_1.SetEnabled("btn_Delete", true);
                tb_1.SetEnabled("btn_Edit", true);
            }

            var curFhjbs = dw_hz.GetItemString(dw_hz.GetRow(), "fhjb"); // 当前
           
            if (curFhjbs == "T") {
                var curRowNo = dw_mkfhjb.Find("fhjb='T'", 1, dw_mkfhjb.RowCount());  // 当前行
                tb_1.SetText("btn_Audit", dw_mkfhjb.GetItemString(curRowNo, "dygn"));
                dw_mx_top.Modify("ysh_q_t.visible='1' ysh_t.visible='1' ysh_t.Text='" + dw_mkfhjb.GetItemString(curRowNo, "fhmc") + "'");
            } else {
                var curRowNo = dw_mkfhjb.Find("fhjb='" + curFhjbs + "'", 1, dw_mkfhjb.RowCount());  // 当前行
                var curFhjbStrs = self.GetAuditStatus(curFhjbs);
                var curToFhjbs = curFhjbStrs.split("#")[0];
                tb_1.SetText("btn_Audit", dw_mkfhjb.GetItemString(curRowNo, "dygn"));

                if (curFhjbs != "F") {
                    dw_mx_top.Modify("ysh_q_t.visible='1' ysh_t.visible='1' ysh_t.Text='" + dw_hz.GetItemString(dw_hz.GetRow(), "fhjbmc") + "'");
                } else {
                    dw_mx_top.Modify("ysh_q_t.visible='0' ysh_t.visible='0' ysh_t.Text=''");
                }

            }
        }
    }
    //#endregion

    //#region this.Add
    this.Add = function () {
        if (editMode != "")
            return;
        curSelSQL = "";
        ddlb_1.SetText("未记账");
        dw_mx_top.Reset();
        dw_mx_top.ScrollToRow(dw_mx_top.InsertRow(0));
        var curAddMaxPzh = "";
        FunctionID = requestor.GetParm("FunctionID");
        curYhbh = requestor.GetParm("curYhbh");
        webReq.Invoke("GetXJPzh", "FunctionID=" + FunctionID);

        if (webReq.StatusCode() == 200) {
            curAddMaxPzh = webReq.ResponseText();
        } else {
            alert(webReq.ResponseText());
            return;
        }
        dw_mx_top.SetItem(1, "pzh", curAddMaxPzh);
        dw_mx_top.SetItem(1, "zdr", curYhbh);
        dw_mx.Reset();
        dw_mx.InsertRow(0);
        self.SetEditMode("Add");
        isAdd = true;
        tb_1.SetEnabled("ddlb_1", false);
        tb_1.SetEnabled("btn_UnAudit", false);
        tb_1.SetEnabled("btn_Tally", false);
        tb_1.SetEnabled("btn_ChaXun", false);
        tb_1.SetEnabled("btn_Filter", false);
        tb_1.SetEnabled("btn_Export", false);
        tb_1.SetEnabled("btn_InsertRow", true);
        tb_1.SetEnabled("btn_DeleteRow", true);

        tb_1.SetText("ddlb_1", "未记账");
        // 清空 审核章
        dw_mx_top.Modify("ysh_q_t.visible='0' ysh_t.visible='0' ysh_t.Text=''");
    }
    //#endregion   

    //#region this.CloseQuery
    this.CloseQuery = function () {
        if (editMode == "")
            return;

        dw_mx.AcceptText();
        dw_mx_top.AcceptText();
        if ((dw_mx_top.ModifiedCount() + dw_mx.DeletedCount() + dw_mx.ModifiedCount()) > 0) {
            if (requestor.MessageBox("提示", "数据还没有保存,是否继续退出?", ICON.Question, BUTTON.YesNo) == 2)
                return 1;
        } else {
            if (dw_hz.GetRow() < 1) {
                return;
            }
        }

        //释放对象
        dwc.Detach(); dwc = null;
    }
    //#endregion 

    //#region this.Exit
    this.Exit = function () {
        if (self.CloseQuery() == 1)
            return;
        setTimeout("window.close();", 100);
    }
    //#endregion  

    //#region this.SetEditMode
    this.SetEditMode = function (newMode) {

        editMode = newMode;
        var bEditFlag = false;
        G_bEditFlag = false;
        if (editMode != "") {
            bEditFlag = true;
            G_bEditFlag = true;
        }
        dw_hz.SetEnabled(!bEditFlag);

        tb_1.SetEnabled("btn_Print", !bEditFlag);
        tb_1.SetEnabled("btn_Add", !bEditFlag);
        tb_1.SetEnabled("btn_Edit", !bEditFlag);
        tb_1.SetEnabled("btn_Delete", !bEditFlag);
        tb_1.SetEnabled("btn_Audit", !bEditFlag);
        tb_1.SetEnabled("btn_ChaXun", !bEditFlag);

        tb_1.SetEnabled("btn_Save", bEditFlag);
        tb_1.SetEnabled("btn_Cancel", bEditFlag);

        if (bEditFlag) {
            tab_1.SelectTab(2);
            dw_mx_top.Modify("DataWindow.Readonly=no");
            dw_mx.Modify("DataWindow.Readonly=no");
            tb_1.SetEnabled("ddlb_1", false);
            tb_1.SetEnabled("btn_ChaXun", false);
            dw_mx_top.SetFocus();
        }
        else {
            dw_mx_top.Modify("DataWindow.Readonly=yes");
            dw_mx.Modify("DataWindow.Readonly=yes");
            var curTabindex = tab_1.GetSelectedTab();
            if (curTabindex == "1") {
                tb_1.SetEnabled("ddlb_1", true);
                tb_1.SetEnabled("btn_ChaXun", true);
            } else if (curTabindex == "2") {
                tb_1.SetEnabled("ddlb_1", false);
                tb_1.SetEnabled("btn_ChaXun", false);
            }
        }
    }
    //#endregion

    this.Dw_mx_top_KeyDown = function (key, keyFlag) {
        if (key == 13) {
            if (dw_mx_top.GetColumnName() == "bzxx") {
                dw_mx.SetColumn("sfkm");
                dw_mx.SetFocus();
                return 1;
            }
        }
    }

    //#region this.dw_mx_top_doubleClicked  双击弹出窗口

    this.dw_mx_top_doubleClicked = function (x, y, row, dwoName) {
        if (dw_mx_top.Describe("DataWindow.Readonly" == "no")) {
            if (dwoName == "bmbh") {
                curW_OPEN.SetDataWindow(dw_mx_top, "bmbh", "bmmc", "", self)   // 这个用来给子窗口Set当前数据窗口
                requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowQueryBase&treeDw=dw_da_bmda_fl_tree&listDw=dw_pub_list_bmda_yw&treeRootLabel=部门分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&curQxlx=cw"), curW_OPEN, null);
            }
            if (dwoName == "gysbh") {

                curW_OPEN.SetDataWindow(dw_mx_top, "gysbh", "gysmc", "", self)   // 这个用来给子窗口Set当前数据窗口
                requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowQueryBase&treeDw=dw_da_gysda_fl_tree&listDw=dw_pub_list_gysda&treeRootLabel=供应商分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&curQxlx=cw"), curW_OPEN, null);
            }
            self.SetSdjy();
        }
    }
    //#endregion

    this.SetSleValue = function (dwoName, data) {
        dw_mx_top.SetItem(dw_mx_top.GetRow(), dwoName, data.substring(1, data.length - 1));
        self.Top_itemChanged(dw_mx_top.GetRow(), dwoName, data.substring(1, data.length - 1));
    }

    //#region Top_itemChanged
    this.Top_itemChanged = function (row, dwoName, data) {
        if (dwoName == "bmbh") {
            dw_mx_top.GetChild(dwoName, dwc);
            var findRow = dwc.Find("bmbh='" + data + "' ", 1, dwc.RowCount());
            if (findRow <= 0) {
                requestor.MessageBox("提示", "未找到部门编号为[" + data + "]的记录，请检查!", ICON.StopSign);
                return 1;
            } else {
                dw_mx_top.SetItem(row, "bmmc", dwc.GetItemString(findRow, "bmmc"));
            }
            self.SetSdjy();
        } else if (dwoName == "gysbh") {
            dw_mx_top.GetChild(dwoName, dwc);
            var findRow = dwc.Find("gysbh='" + data + "' ", 1, dwc.RowCount());
            if (findRow > 0) {
                dw_mx_top.SetItem(row, "gysmc", dwc.GetItemString(findRow, "gysmc"));
            } else {
                requestor.MessageBox("提示", "未找到客户编号为[" + data + "]的记录，请检查!", ICON.StopSign);
                return 1;
            }
            self.SetSdjy();
        }
    }
    //#endregion

    //#region dw_mx_top_editChanged
    this.dw_mx_top_editChanged = function (row, dwoName, data) {

        if (dwoName == "bmbh") {
            dw_mx_top.GetChild(dwoName, dwc);
            if (data != "") {
                dwc.Retrieve("%" + data + "%", curYhbh, "cw");
            }
            else {
                dwc.Retrieve("%", curYhbh, "cw");
            }
        } else if (dwoName == "fyzh") {
            var bmbh = dw_mx_top.GetItemString(row, "bmbh");
            var fkfs = dw_mx_top.GetItemString(row, "fkfs");
            if (bmbh.length < 1) {
                requestor.MessageBox("提示", "请先选择部门！", ICON.Information);

                dw_mx_top.SetColumn("bmbh");
                dw_mx_top.SetFocus();
                return 1;
            }
            if (fkfs.length < 1) {
                requestor.MessageBox("提示", "请先选择付款方式！", ICON.Information);

                dw_mx_top.SetColumn("fkfs");
                dw_mx_top.SetFocus();
                return 1;
            }
        } else if (dwoName == "gysbh") {
            dw_mx_top.GetChild(dwoName, dwc);
            if (data != "") {
                dwc.Retrieve("%" + data + "%", curYhbh);
            }
            else {
                dwc.Retrieve("%", curYhbh);
            }
        }
        else if (dwoName == "ywy") {
            dw_mx_top.GetChild("ywy", dwc);
            dwc.Retrieve("%", curYhbh, "cw");
            if (data != "") {
                dwc.SetFilter("ygbh like '%" + data + "%'");
            }
            else {
                dwc.SetFilter("ygbh like '%'");
            }
            dwc.Filter();
        }
    }
    //#endregion


    //#region this.InsertRow
    this.InsertRow = function () {
        if (editMode == "") {
            return;
        }
        if (dw_mx_top.GetItemString(1, "bmbh") == "") {
            requestor.MessageBox("提示", "请选择部门！", ICON.Information);
            dw_mx_top.SetColumn("bmbh");
            dw_mx_top.SetFocus();
            return 1;
        } else if (dw_mx_top.GetItemString(1, "gysbh") == "") {
            requestor.MessageBox("提示", "请选择供应商！", ICON.Information);
            dw_mx_top.SetColumn("gysbh");
            dw_mx_top.SetFocus();
            return 1;
        }
        dw_mx.ScrollToRow(dw_mx.InsertRow(0));
        dw_mx.SetColumn("sfkm");
        dw_mx.SetFocus();
        dw_mx.ScrollFirstPage();
        dw_mx.ScrollToRow(dw_mx.RowCount());
    }
    //#endregion  

    //#region this.DeleteRow
    this.DeleteRow = function () {
        if (editMode == "")
            return;
        var row = dw_mx.GetRow();
        if (row <= 0)
            return;
        var status = dw_mx.GetItemStatus(row, 0, DWBUFFER.Primary);

        if (status == DWITEMSTATUS.DataModified || status == DWITEMSTATUS.NotModified) {
            if (requestor.MessageBox("提示", "是否确认删除当前明细记录?", ICON.Question, BUTTON.YesNo, 2) == 2) {
                dw_mx.SetFocus();
                return;
            }
        }

        dw_mx.DeleteRow(0);
        curDeleRow += 1;
        dw_mx.AcceptText();
        var ssdye = dw_mx_top.GetItemNumber(1, "ssdjy");
        dw_mx_top.SetItem(1, "sljye", ssdye - dw_mx.GetItemNumber(1, "sum_je"));
        dw_mx.SetFocus();

    }
    //#endregion  
    //#region this.dw_mx_keyDown 如果是在最后一行的金额列按回车，则自动增加一行

    this.dw_mx_keyDown = function (keyCode, keyFlags) {
        if (keyCode == 13) {
            if (dw_mx.GetColumnName() == "sm") {
                if (dw_mx.GetItemNumber(dw_mx.GetRow(), "je") == 0) {
                    requestor.MessageBox("提示", "请为当前行输入金额", 1);
                    dw_mx.SetColumn("je");
                    dw_mx.SetFocus();
                } else if (dw_mx.GetRow() == dw_mx.RowCount()) {

                    dw_mx.ScrollToRow(dw_mx.InsertRow(0));

                    dw_mx.SetColumn("sfkm");
                    dw_mx.SetFocus();
                }
                return 1;
            }
        }
        //        else if (keyCode == 37) {
        //            dw_mx.SetColumn("sfkm");
        //            dw_mx.SetFocus();
        //            return 1;
        //        }

    }
    //#endregion
    this.Save = function () {
        dw_mx_top.AcceptText();
        dw_mx.AcceptText();


        var curSdjy = dw_mx_top.GetItemNumber(1, "sdjy");
        var curLjye = dw_mx_top.GetItemNumber(1, "ljye");
        var curBmSdjy = dw_mx_top.GetItemNumber(1, "bmsdjy");
        var curBmLjye = dw_mx_top.GetItemNumber(1, "bmljye");
        var curSfkm = dw_mx_top.GetItemString(1, "ffkm");
        var curJe = dw_mx.GetItemNumber(1, "sum_je");
        var curSm = dw_mx_top.GetItemString(1, "sm");

        var curTopRow = dw_mx_top.GetRow();
        //        dw_mx_top.SetItem(curTopRow, "sdjy", curSdjy);
        //        dw_mx_top.SetItem(curTopRow, "ljye", curLjye);
        //        dw_mx_top.SetItem(curTopRow, "bmsdjy", curBmSdjy);
        //        dw_mx_top.SetItem(curTopRow, "bmljye", curBmLjye);
        //        dw_mx_top.SetItem(curTopRow, "ffkm", curSfkm);
        dw_mx_top.SetItem(curTopRow, "je", curJe);
        //        dw_mx_top.SetItem(curTopRow, "sm", curSm);

        var curLjye = -curJe + curSdjy;
        var curBmLjye = -curJe + curBmSdjy;
        dw_mx_top.SetItem(curTopRow, "ljye", curLjye);
        dw_mx_top.SetItem(curTopRow, "bmljye", curBmLjye);
        if (curKhyeJqdBm == "0") {
            dw_mx_top.SetItem(1, "bdye", curLjye);
        } else {
            dw_mx_top.SetItem(1, "bdye", curBmLjye);
        }
        dw_mx_top.SetItem(curTopRow, "zhbz", curZhbz);
        dw_mx_top.SetItem(curTopRow, "rq", UtcDateFormatToString(dw_mx_top.GetItemDate(curTopRow, "rq")));
        if (curJe == 0) {
            requestor.MessageBox("提示", "请输入金额!", ICON.Information);
            return;
        }
        if (curZhbz != "") {
            if (dw_mx_top.GetItemString(curTopRow, "fyzh") == "") {
                requestor.MessageBox("提示", "请输入费用账户!", ICON.Information);
                return;
            }
        }
        if (curDeleRow == 0) {
            if (dw_mx_top.ModifiedCount() <= 0) {
                alert("没有数据需要保存!");
                return;
            }
        }

        for (var i = 1; i <= dw_mx.RowCount(); i++) {
            if (dw_mx.GetItemString(i, "sfkm") == null || dw_mx.GetItemString(i, "sfkm") == "") {
                alert("收费科目不能为空!");
                return;
            }
        }
        dw_mx_top.GetChild("ywy", dwc);
//        dwc.Retrieve("%", curYhbh, "cw");
//        dwc.SetFilter("ygbh = '" + dw_mx_top.GetItemString(dw_mx_top.GetRow(), "ywy") + "'");
//        dwc.Filter();
//        if (dwc.RowCount() < 1) {
//            alert("业务员不存在!");
//            return;
//        }
//        if (dw_mx_top.GetItemString(dw_mx_top.GetRow(), "ywy") == "") {
//            alert("请检查业务员!");
//            return;
//        }
        var bmbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh");
        var rq = UtcDateTimeFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "rq"));
        webReq1.Invoke("GetTallystatus", "bmbh=" + bmbh + "&tzrq=" + rq + "&flag=2");
        if (webReq1.StatusCode() == 200) {
            requestor.MessageBox("提示", "本部门库存已结转,不可保存！", ICON.StopSign);
            return;
        }

        var Record = ReadLogAnalysis(null, dw_mx_top, null, "", editMode);

        if (!dw_mx_top.CheckData("*", "")) {
            return;
        }
        dw_mx_top.SetItem(1, "pzh", dw_mx_top.GetItemString(1, "pzh"));
        dw_mx.SetItem(1, "pzh", dw_mx.GetItemString(1, "pzh"));
        var dw_mx_top_data = dw_mx_top.GetChanges();
        var dw_mx_data = dw_mx.GetChanges();
        if (dw_mx_top_data == "") {
            return;
        }
        //#region 写日志
        var curPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
        if (curPzh.length > 0) {
            curPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh")
        } else {
            curPzh = "###";
            dw_mx_top.SetItem(dw_mx_top.GetRow(), "pzh", "###");
        }
        var curLogStr = "";
        if (editMode == "Add") {
            curLogStr = A8erp_Common.WriteLog(dw_mx_top, editMode, "DB");
        } else {
            curLogStr = "【凭证号：" + curPzh + "】" + A8erp_Common.WriteLog(dw_mx_top, editMode, "DB");
        }
        //#endregion
        webReq.Invoke("YW_CW_JHFYD_SAVE", "dw_Master=" + dw_mx_top_data + "&dw_Master1=" + dw_mx_data + "&hzDwName=" + dw_mx_top.GetDataObject() + "&mxDwName=" + dw_mx.GetDataObject() + "&recordFlag=" + curLogStr + "&curPzh=" + curPzh);

        if (webReq.StatusCode() == 200) {
            //服务器成功处理，返回单号
            tb_1.SetEnabled("btn_InsertRow", false);
            tb_1.SetEnabled("btn_DeleteRow", false);
            var rPzh = webReq.ResponseText();
            dw_mx_top.SetItem(dw_mx_top.GetRow(), "pzh", rPzh);

            dw_mx_top.ResetUpdate();
            dw_mx.ResetUpdate();
            if (curKhyeJqdBm == "1") {

                dw_mx_top.SetItem(1, "ssdjy", dw_mx_top.GetItemNumber(1, "bmsdjy"));
                dw_mx_top.SetItem(1, "sljye", dw_mx_top.GetItemNumber(1, "bmljye"));
            } else {

                dw_mx_top.SetItem(1, "ssdjy", dw_mx_top.GetItemNumber(1, "sdjy"));
                dw_mx_top.SetItem(1, "sljye", dw_mx_top.GetItemNumber(1, "ljye"));
            }
            //更新dw_hz,因为是分页的,直接复制会导致每页的记录数不一致了
            //所以采用刷新的记录的方式来更新列表 

            self.SelectionChanged(dw_hz.GetPageIndex());

            //找到相应的记录
            var findRow = dw_hz.Find("pzh='" + rPzh + "' ", 1, dw_hz.RowCount());
            if (findRow > 0) {
                dw_hz.ScrollToRow(findRow);
                self.SetEditMode("");
                tb_1.SetEnabled("btn_ChaXun", false);
                tb_1.SetEnabled("ddlb_1", false);
            } else {
                self.SelectionChanged_tab(rPzh);
                //self.Hz_RowFocusChanged(dw_hz.GetRow());
            }
            requestor.MessageBox("提示", "数据保存成功!", ICON.Information);

            if (isAdd) {
                isAdd = false;
            }
            //#region  审核的问题  dw_mkfhjb 
            if (findRow > 0) {
                var curFhjb = dw_hz.GetItemString(dw_hz.GetRow(), "fhjb");
                var fhjbRow = dw_mkfhjb.Find("fhjb='" + curFhjb + "'", 1, dw_mkfhjb.RowCount());
                if (fhjbRow > 0) {
                    tb_1.SetText("btn_Audit", dw_mkfhjb.GetItemString(fhjbRow, "dygn"));
                }
            }
            //#endregion          
        }
        else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
            dw_mx_top.SetFocus();
        }
    }

    this.SetSdjy = function () {
        dw_mx_top.AcceptText();
        var curBmbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh");
        var curKhbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "gysbh");
        if (curBmbh.length < 1 || curKhbh.length < 1) {
            return;
        }
        dw_khye.Retrieve(curBmbh, curKhbh);
        if (dw_khye.RowCount() > 0) {
            // 精确到部门
            if (curKhyeJqdBm == "1") {
                dw_mx_top.SetItem(1, "sdjy", dw_khye.GetItemNumber(1, "bmgysye"));
                dw_mx_top.SetItem(1, "bmljye", -dw_mx.GetItemNumber(1, "sum_je") + dw_khye.GetItemNumber(1, "bmgysye"));


                dw_mx_top.SetItem(1, "ssdjy", dw_khye.GetItemNumber(1, "bmgysye"));
                dw_mx_top.SetItem(1, "sljye", -dw_mx.GetItemNumber(1, "sum_je") + dw_khye.GetItemNumber(1, "bmgysye"));


            } else {
                // 不精确到部门
                dw_mx_top.SetItem(1, "sdjy", dw_khye.GetItemNumber(1, "gysye"));
                dw_mx_top.SetItem(1, "ljye", -dw_mx.GetItemNumber(1, "sum_je") + dw_khye.GetItemNumber(1, "gysye"));


                dw_mx_top.SetItem(1, "ssdjy", dw_khye.GetItemNumber(1, "gysye"));
                dw_mx_top.SetItem(1, "sljye", -dw_mx.GetItemNumber(1, "sum_je") + dw_khye.GetItemNumber(1, "gysye"));
            }
            dw_mx_top.SetItem(1, "bmsdjy", dw_khye.GetItemNumber(1, "bmgysye"));
            dw_mx_top.SetItem(1, "sdjy", dw_khye.GetItemNumber(1, "gysye"));
        }
    }

    this.SetLjjy = function () {
 
        dw_mx_top.AcceptText();
        dw_mx.AcceptText();

        var curSdjy = dw_mx_top.GetItemNumber(1, "sdjy");
        var curLjye = dw_mx_top.GetItemNumber(1, "ljye");
        var curBmSdjy = dw_mx_top.GetItemNumber(1, "bmsdjy");
        var curBmLjye = dw_mx_top.GetItemNumber(1, "bmljye");
//        var curSfkm = dw_mx_top.GetItemString(1, "sfkm");
        var curJe = dw_mx.GetItemNumber(1, "sum_je");
        var curSm = dw_mx_top.GetItemString(1, "sm");

        var curLjye = -curJe + curSdjy;
        var curBmLjye = -curJe + curBmSdjy;
        if (curKhyeJqdBm == "0") {
            dw_mx_top.SetItem(1, "bdye", curLjye);
        } else {
            dw_mx_top.SetItem(1, "bdye", curBmLjye);
        }

    }

    //#region 审核
    this.Audit = function () {

        if (dw_hz.GetRow() < 1) {
            alert("请先选择一笔数据进行审核");
            return;
        }
        var pzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");

        if (pzh.length < 1) {
            alert("凭证号异常");
            return;
        }
        if (!confirm("您确定要审核凭证号为[" + pzh + "]的单据吗？")) {
            return;
        }

        if (self.CheckJzbz()) {
            return;
        }
        var nextZt = self.GetNextZt(dw_hz.GetItemString(dw_hz.GetRow(), "fhjb"));
        webReq.Invoke("JHFYD_Audit", "PZH=" + pzh + "&DJZT=" + nextZt);
        if (webReq.StatusCode() == 200) {
            requestor.MessageBox("提示", "审核成功!", ICON.Information);
        
            //#region 刷新汇总表
            self.SelectionChanged(dw_hz.GetPageIndex());
            if (dw_hz.RowCount() == 0) {
                self.SetButtomStatus();
                return;
            }
            //找到相应的记录
            var findRow = dw_hz.Find("pzh='" + pzh + "' ", 1, dw_hz.RowCount());
            if (findRow > 0) {
                dw_hz.ScrollToRow(findRow);
            } else {
                self.SelectionChanged_tab(pzh);
            }
            //#endregion 

            // 下一笔将要显示在按钮上的功能
            if (findRow > 0) {
                var curFindRow = dw_mkfhjb.Find("fhjb='" + nextZt + "'", 1, dw_mkfhjb.RowCount());
                var curToButtonShowName = dw_mkfhjb.GetItemString(curFindRow, "dygn");
                var curToShowName = dw_mkfhjb.GetItemString(curFindRow, "fhmc");
                dw_mx_top.Modify("ysh_q_t.visible='1' ysh_t.visible='1' ysh_t.Text='" + curToShowName + "'");
                tb_1.SetText("btn_Audit", curToButtonShowName);
            }

            var curHzPzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
            if (pzh != curHzPzh) {
                tab_1.SetSelectedTab(1);
                tb_1.SetEnabled("ddlb_1", true);
                tb_1.SetEnabled("btn_ChaXun", true);
                tb_1.SetEnabled("btn_Filter", true);
                tb_1.SetEnabled("btn_Export", true);
            }
        } else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
        }
    }
    //#endregion

    //#region GetNextZt
    this.GetNextZt = function (curZt) {
        if ("F" == curZt) {
            var nextRow = dw_mkfhjb.Find(" fhjb='1' ", 1, dw_mkfhjb.RowCount());
            if (nextRow > 0) {
                return "1";
            } else {
                return "T";
            }
        } else {
            var nextZt = parseInt(curZt) + 1;
            var nextRow = dw_mkfhjb.Find(" fhjb='" + nextZt + "' ", 1, dw_mkfhjb.RowCount());
            if (nextRow > 0) {
                return nextZt + "";
            } else {
                return "T";
            }
        }
    }
    //#endregion

    //#region 退审
    this.UnAudit = function () {
        var curRow = dw_hz.GetRow();
        if (curRow < 1) {
            alert("请先选择一笔数据进行退审");
            return;
        }
        var pzh = dw_hz.GetItemString(curRow, "pzh");

        if (pzh.length < 1) {
            alert("凭证号异常");
            return;
        }
        if (!confirm("您确定要退审凭证号为[" + pzh + "]的单据吗？")) {
            return;
        }
        if (self.CheckJzbz()) {
            return;
        }
        webReq.Invoke("JHFYD_UnAudit", "PZH=" + pzh);
        if (webReq.StatusCode() == 200) {
            requestor.MessageBox("提示", "退审成功!", ICON.Information);

            //#region 刷新汇总表
            dw_hz.SetRedraw(false);
            dw_hz.SetProcessing(true);

            //刷新
            self.SelectionChanged(dw_hz.GetPageIndex());
            //找到相应的记录
            var findRow = dw_hz.Find("pzh='" + pzh + "' ", 1, dw_hz.RowCount());
            if (findRow > 0) {
                dw_hz.ScrollToRow(findRow);
            } else {
                self.SelectionChanged_tab(pzh);
                //self.Hz_RowFocusChanged(dw_hz.GetRow());
            }
            dw_hz.SetProcessing(false);
            dw_hz.SetRedraw(true);
            //#endregion             

            var curHzPzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
            if (pzh != curHzPzh) {
                tab_1.SetSelectedTab(1);
                tb_1.SetEnabled("ddlb_1", true);
                tb_1.SetEnabled("btn_ChaXun", true);
                tb_1.SetEnabled("btn_Filter", true);
                tb_1.SetEnabled("btn_Export", true);
            }
        } else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
        }
    }
    //#endregion  

    //#region 审核级别

    this.GetAuditStatus = function (curFhjb) {
        if (curFhjb == "T") {
            tb_1.SetEnabled("btn_Audit", false);
            tb_1.SetEnabled("btn_UnAudit", true);
            tb_1.SetEnabled("btn_Tally", true);
            return;
        }
        var fhjbRow = dw_mkfhjb.Find("fhjb='" + curFhjb + "'", 1, dw_mkfhjb.RowCount());  // 当前行

        var curShjbRow = 0;
        if (dw_mkfhjb.RowCount() - 2 == 0) {  //没有级别，只有2条数据
            curShjb = "T";
            curShjbRow = dw_mkfhjb.Find("fhjb='T'", 1, dw_mkfhjb.RowCount());  // 当前行
        } else {
            for (var i = 1; i <= dw_mkfhjb.RowCount() - 2; i++) {
                if (parseInt(curFhjb == "F" ? "0" : curFhjb) < parseInt(dw_mkfhjb.GetItemString(i, "fhjb"))) {
                    curShjb = dw_mkfhjb.GetItemString(i, "fhjb");
                    curShjbRow = i;
                    break;
                } else if (i == dw_mkfhjb.RowCount() - 2) {
                    curShjb = "T";
                    curShjbRow = dw_mkfhjb.Find("fhjb='T'", 1, dw_mkfhjb.RowCount());  // 当前行
                }

            }
        }
        return curShjb + "#" + curShjbRow
    }
    //#endregion

    //#region this.Cancel
    this.Cancel = function () {
        var pzh = "";
        if (dw_mx_top.RowCount() > 0) {
            dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
        }
        tab_1.SelectTab(1);
        self.SetEditMode("");
        dw_hz.RefreshDetails();

        tb_1.SetEnabled("ddlb_1", true);
        tb_1.SetEnabled("btn_ChaXun", true);
        tb_1.SetEnabled("btn_Filter", true);
        tb_1.SetEnabled("btn_Export", true);
        isAdd = false;
        self.SelectionChanged();
        var findRow = dw_hz.Find("pzh='" + pzh + "'", 1, dw_hz.RowCount());
        if (findRow > 0) {
            dw_hz.ScrollToRow(findRow);
        }
    }
    //#endregion  

    this.SelectionChanged = function (val) {
        var djzt = ddlb_1.GetText();
        var SqlWhere = "";
        if (djzt == "未记账") {
            djzt = "isnull(jzbz,'0')<>'1'";
        } else if (djzt == "已记账") {
            djzt = "isnull(jzbz,'0')='1'";
        } else if (djzt == "全部") {
            djzt = "";
        }
        else {
            djzt = "fhmc='" + djzt + "'";
        }
        if (curSelSQL.length > 0 && !isAdd) {
            SqlWhere = curSelSQL;
        }
        else {
            SqlWhere = "  a.bmbh in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and cw = '1') ";
            if (curSelDays != "-1") {
                //SqlWhere += " and CONVERT(date,rq,120) >CONVERT(date,GETDATE()-convert(int,'" + curSelDays + "'),120)";
                SqlWhere += " and CONVERT(date,rq,120) >='" + curSelDays + "'";
            }
        }
        if (djzt.length > 0) {
            // SqlWhere += " and ( isnull(fhmc,'未审核')+isnull(jzbz,'0') like '" + djzt + "')";
            SqlWhere += " and  " + djzt;
        }
        //SqlWhere += " and ( isnull(fhmc,'未审核')+isnull(jzbz,'0') like '" + djzt + "')";
        dw_hz.RetrieveEx(SqlWhere);

        var curPageCount = dw_hz.GetPageCount();
        try {
            if (arguments.length == 1) {
                if (parseInt(val) > curPageCount) {

                    dw_hz.SetPageIndex(curPageCount);

                } else {
                    dw_hz.SetPageIndex(val);

                }
                dw_hz.Refresh();
            }
        } catch (e) {
            alert("this.SelectionChanged Error.\r\n");
        }
    }

    //#region 查询界面
    this.ChaXun = function () {
        curW_CaiWuChaXun.SetDataWindow(self, dw_hz, "FK", curYhbh, ddlb_1.GetText(), curSelDays, "");
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.CaiWu.ChaXun.W_CaiWuChaXun&flag=FK"), curW_CaiWuChaXun, null);

    }
    //#endregion

    //#region this.EvalJs
    this.EvalJs = function (jsScript) {
        //alert(jsScript);
        eval(jsScript);
    }
    //#endregion

    //#region this.Edit
    this.Edit = function () {
        if (editMode != "")
            return;

        var row = dw_hz.GetRow();

        if (row <= 0)
            return;

        if (self.CheckJzbz()) {
            return;
        }

      
        dw_mx.Retrieve(dw_hz.GetItemString(row, "pzh"));
        dw_mx_top.Retrieve(dw_hz.GetItemString(row, "pzh"));
        if (curKhyeJqdBm == "1") {
            dw_mx_top.SetItem(1, "sdye", dw_mx_top.GetItemNumber(1, "bmsdjy"));
            dw_mx_top.SetItem(1, "bdye", dw_mx_top.GetItemNumber(1, "bmljye"));



            dw_mx_top.SetItem(1, "ssdjy", dw_mx_top.GetItemNumber(1, "bmsdjy"));
            dw_mx_top.SetItem(1, "sljye", dw_mx_top.GetItemNumber(1, "bmljye"));
        } else {
            dw_mx_top.SetItem(1, "sdye", dw_mx_top.GetItemNumber(1, "sdjy"));
            dw_mx_top.SetItem(1, "bdye", dw_mx_top.GetItemNumber(1, "ljye"));



            dw_mx_top.SetItem(1, "ssdjy", dw_mx_top.GetItemNumber(1, "sdjy"));
            dw_mx_top.SetItem(1, "sljye", dw_mx_top.GetItemNumber(1, "ljye"));
        }
        dw_hz.ReSelectRow(row);
        dw_hz.RefreshDetails();
        self.SetEditMode("Edit");

        tb_1.SetEnabled("ddlb_1", false);
        tb_1.SetEnabled("btn_ChaXun", false);
        tb_1.SetEnabled("btn_Filter", false);
        tb_1.SetEnabled("btn_Export", false);
        tb_1.SetEnabled("btn_InsertRow", true);
        tb_1.SetEnabled("btn_DeleteRow", true);
        //打开明细的时候 没有记账的单据 重新获取 期初数据&结余数据
        if (dw_hz.GetItemString(dw_hz.GetRow(), "jzbz") != "1") {
            self.SetSdjy();
            self.SetLjjy();
        }
    }
    //#endregion  

    //#region this.Delete
    this.Delete = function () {
        if (editMode != "")
            return;

        var row = dw_hz.GetRow();
        if (row <= 0)
            return;
        if (self.CheckJzbz()) {
            return;
        }
        dw_hz.ReSelectRow(row);
        dw_hz.RefreshDetails();

        var curPzh = tab_Changed(tab_1, dw_hz, dw_mx_top);

        if (requestor.MessageBox("提示", "是否确定需要删除凭证号为<" + curPzh + ">的单据?", ICON.Question, BUTTON.YesNo) == 2)
            return;

        webReq.Invoke("JHFYD_Delete", "curPzh=" + curPzh);

        if (webReq.StatusCode() == 200) {
            dw_hz.DeleteRow(row);
            tab_1.SelectTab(1);
            //dw_hz.RowsDiscard(row, row, DWBUFFER.Primary);
            requestor.MessageBox("提示", "删除成功!", ICON.Information);
            tb_1.SetEnabled("ddlb_1", true);
            tb_1.SetEnabled("btn_ChaXun", true);
            tb_1.SetEnabled("btn_Filter", true);
            tb_1.SetEnabled("btn_Export", true);
            if (dw_hz.GetRow() > 0) {
                curPzh = tab_Changed(tab_1, dw_hz, dw_mx_top);
                self.SelectionChanged_tab(curPzh);
            }
        }
        else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
        }
    }

    //#endregion  

    //#region 检查记账标志
    this.CheckJzbz = function () {
        var curTName = "";
        var curpzh = "";
        curpzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
        curTName = "cw_new_jhfyd";

        webReqTimestamp.Invoke("YW_GTE_PZH", "curTName=" + curTName + "&curPzh=" + curpzh);
        if (webReqTimestamp.StatusCode() == 200) {
            var curjzbz = webReqTimestamp.ResponseText();
            if (curjzbz == "1") {
                requestor.MessageBox("提示", "该记录已经记账！不能修改！！", ICON.StopSign);
                //#region 刷新汇总表
                dw_hz.SetRedraw(false);
                dw_hz.SetProcessing(true);

                //刷新
                self.SelectionChanged();
                //找到相应的记录
                var findRow = dw_hz.Find("pzh='" + curpzh + "' ", 1, dw_hz.RowCount());
                if (findRow > 0) {
                    dw_hz.ScrollToRow(findRow);
                } else {
                    self.Hz_RowFocusChanged(dw_hz.GetRow());
                }
                dw_hz.SetProcessing(false);
                dw_hz.SetRedraw(true);
                //#endregion 

                //   dw_mx_top.Modify("ysh_q_t.visible='0' ysh_t.visible='0' ysh_t.Text=''");
                tb_1.SetEnabled("btn_Save", false);
                tb_1.SetEnabled("btn_Audit", false);
                tb_1.SetEnabled("btn_UnAudit", false);
                tb_1.SetEnabled("btn_Tally", false);
                tb_1.SetEnabled("btn_Delete", false);
                tb_1.SetEnabled("btn_Edit", false);
                return true;
            } else {
                return false;
            }
        } else {
            requestor.MessageBox("获取记账标志失败", webReqTimestamp.ResponseText(), ICON.StopSign);
            return true;
        }

    }
    //#endregion

    //#region 记账
    this.Tally = function () {

        if (dw_hz.GetRow() < 1) {
            alert("请先选择一笔数据进行审核");
            return;
        }
        var pzh = tab_Changed(tab_1, dw_hz, dw_mx_top);

        if (pzh.length < 1) {
            alert("凭证号异常");
            return;
        }
        if (!confirm("您确定要记账凭证号为[" + pzh + "]的单据吗？")) {
            return;
        }
        //#region 检查本单据是否已经记账
        if (self.CheckJzbz()) {
            return;
        }
        //#endregion

        webReq.Invoke("Bill_CW_DJJZ_Check", "PZH=" + pzh + "&DJFL=" + "2");
        if (webReq.ResponseText() != "0") {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.Information);
            return;
        }
        webReq.Invoke("JHFYD_Tally", "curPzh=" + pzh);
        if (webReq.StatusCode() == 200) {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.Information);

            //tab_1.SetSelectedTab(1);
            //tb_1.SetEnabled("ddlb_1", true);
            //tb_1.SetEnabled("btn_ChaXun", true);
            tb_1.SetEnabled("btn_Filter", true);
            tb_1.SetEnabled("btn_Export", true);

            //#region 刷新汇总表
            dw_hz.SetRedraw(false);
            dw_hz.SetProcessing(true);

            //刷新
            self.SelectionChanged(dw_hz.GetPageIndex());
            //找到相应的记录
            var findRow = dw_hz.Find("pzh='" + pzh + "' ", 1, dw_hz.RowCount());
            if (findRow > 0) {
                dw_hz.ScrollToRow(findRow);
            } else {

                self.SelectionChanged_tab(pzh);
                //self.Hz_RowFocusChanged(dw_hz.GetRow());
            }
            dw_hz.SetProcessing(false);
            dw_hz.SetRedraw(true);
            //#endregion 
          
            if (findRow > 0) {
                dw_mx_top.Modify("ysh_q_t.visible='0' ysh_t.visible='0' ysh_t.Text=''");
                tb_1.SetEnabled("btn_Save", false);
                tb_1.SetEnabled("btn_Audit", false);
                tb_1.SetEnabled("btn_UnAudit", false);
                tb_1.SetEnabled("btn_Tally", false);
                tb_1.SetEnabled("btn_Delete", false);
                tb_1.SetEnabled("btn_Edit", false);
            } else {
                if (tab_1.GetSelectedTab() == "2") {
                    // 这里表示记账成功后在汇总页面没有找到当前行。所以直接把 【记账，退审】 按钮屏蔽
                    dw_mx_top.Modify("ysh_q_t.visible='0' ysh_t.visible='0' ysh_t.Text=''");
                    tb_1.SetEnabled("btn_Add", true);
                    tb_1.SetEnabled("btn_Edit", false);
                    tb_1.SetEnabled("btn_Delete", false);
                    tb_1.SetEnabled("btn_Audit", false);
                    tb_1.SetEnabled("btn_UnAudit", false);
                    tb_1.SetEnabled("btn_Tally", false);
                    tb_1.SetEnabled("btn_Save", false);
                    tb_1.SetEnabled("btn_Cancel", false);
                    tb_1.SetEnabled("btn_Filter", true);
                    tb_1.SetEnabled("btn_Print", true);
                    tb_1.SetEnabled("btn_Export", true);
                }
            }
        } else {
            //alert(webReq.ResponseText());
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
        }

    }
    //#endregion  

    //#region dw_mx_DoubleClicked
    this.dw_mx_DoubleClicked = function (x, y, row, dwoName) {
        if (dw_mx.Describe("DataWindow.Readonly" == "no")) {
            if (dwoName == "sfkm") {
                curW_OPEN.SetDataWindow(dw_mx, "kmbh", "kmmc", "CW", self, "sfkm", "kmmc")   // 这个用来给子窗口Set当前数据窗口
                requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowQueryBase&treeDw=dw_da_cy_kmlb_tree&listDw=dw_da_cy_kmda_list&treeRootLabel=科目分类&treeData=lbbh&treeLabel=lbmc&treeParentData=flbbh&treeLeave=islast&curQxlx=cw"), curW_OPEN, null);
            }
        }
    }
    this.SetSleValue = function (dwoName, data) {
        dw_mx.SetItem(dw_mx.GetRow(), dwoName, data.substring(1, data.length - 1));
        self.dw_mx_itemChanged(dw_mx.GetRow(), dwoName, data.substring(1, data.length - 1));
    }
    //#endregion

    //#region this.dw_mx_itemChanged
    this.dw_mx_itemChanged = function (row, dwoName, data) {
        if (dwoName == "sfkm") {
            dw_mx.GetChild(dwoName, dwc);
            var findRow = dwc.Find("kmbh='" + data + "' or kmmc='" + data + "'", 1, dwc.RowCount());
            if (findRow <= 0) {
                requestor.MessageBox("提示", "未找到科目为[" + data + "]的记录，请检查!", ICON.StopSign);
                return 1;
            } else {
                dw_mx.SetItem(row, "kmmc", dwc.GetItemString(findRow, "kmmc"));
            }
        } else if (dwoName == "je") {
            dw_mx.AcceptText();
            var ssdye = dw_mx_top.GetItemNumber(1, "ssdjy");
            dw_mx_top.SetItem(1, "sljye", ssdye - dw_mx.GetItemNumber(1, "sum_je"));
        }
    }
    //#endregion

    //#region dw_mx_editChanged
    this.dw_mx_editChanged = function (row, dwoName, data) {
        if (dwoName == "ffkm") {
            dw_mx.GetChild(dwoName, dwc);
            if (data != "") {
                dwc.Retrieve("%" + data + "%");
            }
            else {
                dwc.Retrieve("%");
            }
        }
    }
    //#endregion

    //#region  this.print

    this.print = function () {
        if (tab_1.GetSelectedTab() == "1") {
            if (dw_hz.RowCount() < 1) {
                return;
            }
        }
        var curPzh = "";
        var ssdjy = dw_mx_top.GetItemNumber(1, "ssdjy");
        var sljye = dw_mx_top.GetItemNumber(1, "sljye");
        if (tab_1.GetSelectedTab() == "1") {
            curPzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
        } else {
            curPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
        }
        self.Tab_1_Clicked(2);
        if (curSfQyQDID == "1") {
            A8erp_Biz_Print.Yw_Jhfyd_Print_Jqm(self, requestor, dw_hz, dw_mx_top, dw_mx, 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, curSfQyQDID, curJqm, curSfQYQXZ, curUserGroupId);
        } else {
            A8erp_Biz_Print.Yw_Jhfyd_Print(self, requestor, dw_hz, dw_mx_top, dw_mx, 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, curSfQyQDID, curJqm, curSfQYQXZ, curUserGroupId);

        }
        dw_mx_top.SetItem(1, "ssdjy", ssdjy);
        dw_mx_top.SetItem(1, "sljye", sljye);
        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;
    }

    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

    this.Copy = function () {

        var curPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
        requestor.ClipBoardNao(curPzh);
        requestor.MessageBox("提示", "凭证号【" + curPzh + "】已复制到剪贴板", ICON.None);
    }

    //#region 复制备注信息

    this.CopyBzxx = function () {

        var curBzxx = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bzxx");
        requestor.ClipBoard(curBzxx);
        requestor.MessageBox("提示", "备注信息【" + curBzxx + "】已复制到剪贴板", ICON.None);
    }
    //#endregion

    this.Export = function () {
        if (tab_1.GetSelectedTab() == "1") {
            dw_hz.Export()
        }
        else {
            dw_mx.Export();
        }
    }

}