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

    var self = this;
    this.Instance = null;
    var requestor = new PBWindow();
    var tab_1 = new TabControl(requestor);
    var dw_hz = new DataWindow(requestor);
    var dw_mkfhjb = new DataWindow(requestor);
    var dw_ph_mx_top = new DataWindow(requestor);
    var dw_ph_mx = new DataWindow(requestor);
    var dw_ph_hz = new DataWindow(requestor);
    var tb_paging = new ToolStrip(requestor);
    var sle_Count = new SingleLineEdit(requestor);
    var sle_Page = new SingleLineEdit(requestor);
    var sc_1 = new SplitContainer(requestor);
    var cb_sm = new CommandButton(requestor);
    var dw_cgddgsykc = new DataWindow(requestor);
    var sle_tmh = new SingleLineEdit(requestor);
    var em_1 = new EditMask(requestor);
    var dw_mx_top = new DataWindow(requestor);
    var dw_spda = new DataWindow(requestor);
    var dw_mdsp_list = new DataWindow(requestor);
    var dw_mx = new DataWindow(requestor);
    var dw_tmbc = new DataWindow(requestor);
    var sle_pptmfa_Value = new SingleLineEdit(requestor);
    var dw_error_list = new DataWindow(requestor);
    var dw_35_kc = new DataWindow(requestor);
    var dw_ysbx = new DataWindow(requestor);
    var dw_pzbtm = new DataWindow(requestor);
    var dw_tmjqfs = new DataWindow(requestor);
    var dw_ddmx_top_tmlr = new DataWindow(requestor);
    var dw_1 = new DataWindow(requestor);
    var dw_proxy = new DataWindow(requestor);
    var dw_3 = new DataWindow(requestor);
    var dw_xt_print_print2_cmzbm = new DataWindow(requestor);
    var dw_sort = new DataWindow(requestor);
    var dw_init = new DataWindow(requestor);
    var dw_parameter = new DataWindow(requestor);
    var dw_da_qx_mokuai = new DataWindow(requestor);
    var dw_xt_div_tree_no_parm = new DataWindow(requestor);
    var dw_print = new DataWindow(requestor);
    var dw_da_qx_mokuai_print = new DataWindow(requestor);
    var dw_import_PL = new DataWindow(requestor);
    var dw_ls_flda = new DataWindow(requestor);
    var tb_1 = new ToolStrip(requestor);
    var ddlb_2 = new DropDownListBox(requestor);
    var ddlb_1 = new DropDownListBox(requestor);
    var ContextMenuStrip1 = new ContextMenu(requestor);
    var ContextMenuStrip2 = new ContextMenu(requestor);
    var ContextMenuStrip3 = 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_hz == null) dw_hz = new DataWindow(requestor);
        dw_hz.Attach(win.Control("dw_hz"));
        if (dw_mkfhjb == null) dw_mkfhjb = new DataWindow(requestor);
        dw_mkfhjb.Attach(win.Control("dw_mkfhjb"));
        if (dw_ph_mx_top == null) dw_ph_mx_top = new DataWindow(requestor);
        dw_ph_mx_top.Attach(win.Control("dw_ph_mx_top"));
        if (dw_ph_mx == null) dw_ph_mx = new DataWindow(requestor);
        dw_ph_mx.Attach(win.Control("dw_ph_mx"));
        if (dw_ph_hz == null) dw_ph_hz = new DataWindow(requestor);
        dw_ph_hz.Attach(win.Control("dw_ph_hz"));
        if (tb_paging == null) tb_paging = new ToolStrip(requestor);
        tb_paging.Attach(win.Control("tb_paging"));
        if (sle_Count == null) sle_Count = new SingleLineEdit(requestor);
        sle_Count.Attach(win.Control("sle_Count"));
        if (sle_Page == null) sle_Page = new SingleLineEdit(requestor);
        sle_Page.Attach(win.Control("sle_Page"));
        if (sc_1 == null) sc_1 = new SplitContainer(requestor);
        sc_1.Attach(win.Control("sc_1"));
        if (cb_sm == null) cb_sm = new CommandButton(requestor);
        cb_sm.Attach(win.Control("cb_sm"));
        if (dw_cgddgsykc == null) dw_cgddgsykc = new DataWindow(requestor);
        dw_cgddgsykc.Attach(win.Control("dw_cgddgsykc"));
        if (sle_tmh == null) sle_tmh = new SingleLineEdit(requestor);
        sle_tmh.Attach(win.Control("sle_tmh"));
        if (em_1 == null) em_1 = new EditMask(requestor);
        em_1.Attach(win.Control("em_1"));
        if (dw_mx_top == null) dw_mx_top = new DataWindow(requestor);
        dw_mx_top.Attach(win.Control("dw_mx_top"));
        if (dw_spda == null) dw_spda = new DataWindow(requestor);
        dw_spda.Attach(win.Control("dw_spda"));
        if (dw_mdsp_list == null) dw_mdsp_list = new DataWindow(requestor);
        dw_mdsp_list.Attach(win.Control("dw_mdsp_list"));
        if (dw_mx == null) dw_mx = new DataWindow(requestor);
        dw_mx.Attach(win.Control("dw_mx"));
        if (dw_tmbc == null) dw_tmbc = new DataWindow(requestor);
        dw_tmbc.Attach(win.Control("dw_tmbc"));
        if (sle_pptmfa_Value == null) sle_pptmfa_Value = new SingleLineEdit(requestor);
        sle_pptmfa_Value.Attach(win.Control("sle_pptmfa_Value"));
        if (dw_error_list == null) dw_error_list = new DataWindow(requestor);
        dw_error_list.Attach(win.Control("dw_error_list"));
        if (dw_35_kc == null) dw_35_kc = new DataWindow(requestor);
        dw_35_kc.Attach(win.Control("dw_35_kc"));
        if (dw_ysbx == null) dw_ysbx = new DataWindow(requestor);
        dw_ysbx.Attach(win.Control("dw_ysbx"));
        if (dw_pzbtm == null) dw_pzbtm = new DataWindow(requestor);
        dw_pzbtm.Attach(win.Control("dw_pzbtm"));
        if (dw_tmjqfs == null) dw_tmjqfs = new DataWindow(requestor);
        dw_tmjqfs.Attach(win.Control("dw_tmjqfs"));
        if (dw_ddmx_top_tmlr == null) dw_ddmx_top_tmlr = new DataWindow(requestor);
        dw_ddmx_top_tmlr.Attach(win.Control("dw_ddmx_top_tmlr"));
        if (dw_1 == null) dw_1 = new DataWindow(requestor);
        dw_1.Attach(win.Control("dw_1"));
        if (dw_proxy == null) dw_proxy = new DataWindow(requestor);
        dw_proxy.Attach(win.Control("dw_proxy"));
        if (dw_3 == null) dw_3 = new DataWindow(requestor);
        dw_3.Attach(win.Control("dw_3"));
        if (dw_xt_print_print2_cmzbm == null) dw_xt_print_print2_cmzbm = new DataWindow(requestor);
        dw_xt_print_print2_cmzbm.Attach(win.Control("dw_xt_print_print2_cmzbm"));
        if (dw_sort == null) dw_sort = new DataWindow(requestor);
        dw_sort.Attach(win.Control("dw_sort"));
        if (dw_init == null) dw_init = new DataWindow(requestor);
        dw_init.Attach(win.Control("dw_init"));
        if (dw_parameter == null) dw_parameter = new DataWindow(requestor);
        dw_parameter.Attach(win.Control("dw_parameter"));
        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_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_print == null) dw_print = new DataWindow(requestor);
        dw_print.Attach(win.Control("dw_print"));
        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_import_PL == null) dw_import_PL = new DataWindow(requestor);
        dw_import_PL.Attach(win.Control("dw_import_PL"));
        if (dw_ls_flda == null) dw_ls_flda = new DataWindow(requestor);
        dw_ls_flda.Attach(win.Control("dw_ls_flda"));
        if (tb_1 == null) tb_1 = new ToolStrip(requestor);
        tb_1.Attach(win.Control("tb_1"));
        if (ddlb_2 == null) ddlb_2 = new DropDownListBox(requestor);
        ddlb_2.Attach(win.Control("ddlb_2"));
        if (ddlb_1 == null) ddlb_1 = new DropDownListBox(requestor);
        ddlb_1.Attach(win.Control("ddlb_1"));
        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 (ContextMenuStrip3 == null) ContextMenuStrip3 = new ContextMenu(requestor);
        ContextMenuStrip3.Attach(win.Control("ContextMenuStrip3"));

        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.SelectionChanging) == "function")
            win.AttachEvent("tab_1", "SelectionChanging", self.SelectionChanging);

        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.PageQuery) == "function")
            win.AttachEvent("sle_Count", "KeyDown", self.PageQuery);

        if (typeof (self.First) == "function")
            win.AttachEvent("btn_first", "Clicked", self.First);

        if (typeof (self.LastPage) == "function")
            win.AttachEvent("btn_prior", "Clicked", self.LastPage);

        if (typeof (self.PageQuery) == "function")
            win.AttachEvent("sle_Page", "KeyDown", self.PageQuery);

        if (typeof (self.NextPage) == "function")
            win.AttachEvent("btn_next", "Clicked", self.NextPage);

        if (typeof (self.Last) == "function")
            win.AttachEvent("btn_last", "Clicked", self.Last);

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

        if (typeof (self.Znsm) == "function")
            win.AttachEvent("cb_sm", "Clicked", self.Znsm);

        if (typeof (self.sle_tmh_Double_PinPai) == "function")
            win.AttachEvent("sle_tmh", "DoubleClicked", self.sle_tmh_Double_PinPai);

        if (typeof (self.sle_tmh_Modified) == "function")
            win.AttachEvent("sle_tmh", "KeyDown", self.sle_tmh_Modified);

        if (typeof (self.em_zdzk) == "function")
            win.AttachEvent("em_1", "KeyDown", self.em_zdzk);

        if (typeof (self.MxTopClicked) == "function")
            win.AttachEvent("dw_mx_top", "Clicked", self.MxTopClicked);

        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.dw_mx_top_itemChanged) == "function")
            win.AttachEvent("dw_mx_top", "ItemChanged", self.dw_mx_top_itemChanged);

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

        if (typeof (self.dw_mx_Clicked) == "function")
            win.AttachEvent("dw_mx", "Clicked", self.dw_mx_Clicked);

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

        if (typeof (self.dw_mx_DropDown) == "function")
            win.AttachEvent("dw_mx", "DropDown", self.dw_mx_DropDown);

        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_itemFocusChange) == "function")
            win.AttachEvent("dw_mx", "ItemFocusChanged", self.dw_mx_itemFocusChange);

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

        if (typeof (self.RFC_LiShiBaoCun) == "function")
            win.AttachEvent("dw_mx", "RowFocusChanged", self.RFC_LiShiBaoCun);

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

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

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

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

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

        if (typeof (self.PH_FAudit) == "function")
            win.AttachEvent("btn_PH_FAudit", "Clicked", self.PH_FAudit);

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

        if (typeof (self.QZXG) == "function")
            win.AttachEvent("rbn_qzxg", "Clicked", self.QZXG);

        if (typeof (self.DateCopy) == "function")
            win.AttachEvent("rbn_djfz", "Clicked", self.DateCopy);

        if (typeof (self.DatePast) == "function")
            win.AttachEvent("rbn_djzt", "Clicked", self.DatePast);

        if (typeof (self.SetPrint) == "function")
            win.AttachEvent("打印机设置ToolStripMenuItem", "Clicked", self.SetPrint);

        if (typeof (self.Dy1) == "function")
            win.AttachEvent("尺码横向ToolStripMenuItem", "Clicked", self.Dy1);

        if (typeof (self.Dy2) == "function")
            win.AttachEvent("尺码分组ToolStripMenuItem", "Clicked", self.Dy2);

        if (typeof (self.Dy3) == "function")
            win.AttachEvent("尺码纵向ToolStripMenuItem", "Clicked", self.Dy3);

        if (typeof (self.Dy4) == "function")
            win.AttachEvent("款式汇总ToolStripMenuItem", "Clicked", self.Dy4);

        if (typeof (self.SetPrintSort) == "function")
            win.AttachEvent("按序号升序ToolStripMenuItem", "Clicked", self.SetPrintSort);

        if (typeof (self.SetPrintSort) == "function")
            win.AttachEvent("按款号升序ToolStripMenuItem", "Clicked", self.SetPrintSort);

        if (typeof (self.Gdhdy) == "function")
            win.AttachEvent("固定行数打印ToolStripMenuItem", "Clicked", self.Gdhdy);

        if (typeof (self.ImporExcel) == "function")
            win.AttachEvent("rbn_drcel", "Clicked", self.ImporExcel);

        if (typeof (self.ImporTxt) == "function")
            win.AttachEvent("rbn_drtxt", "Clicked", self.ImporTxt);

        if (typeof (self.ShowPic) == "function")
            win.AttachEvent("图片浏览ToolStripMenuItem", "Clicked", self.ShowPic);

        if (typeof (self.fjsm) == "function")
            win.AttachEvent("分拣扫描ToolStripMenuItem", "Clicked", self.fjsm);

        if (typeof (self.LSRKD) == "function")
            win.AttachEvent("rkljts", "Clicked", self.LSRKD);

        if (typeof (self.ShowDjPic) == "function")
            win.AttachEvent("浏览单据图片ToolStripMenuItem", "Clicked", self.ShowDjPic);

        if (typeof (self.TopSetTmlrSptm) == "function")
            win.AttachEvent("商品条码ToolStripMenuItem", "Clicked", self.TopSetTmlrSptm);

        if (typeof (self.TopSetTmlrPmb) == "function")
            win.AttachEvent("配码包ToolStripMenuItem", "Clicked", self.TopSetTmlrPmb);

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

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

        if (typeof (self.liansao) == "function")
            win.AttachEvent("连扫ToolStripMenuItem", "Clicked", self.liansao);

        if (typeof (self.savegs) == "function")
            win.AttachEvent("格式保存ToolStripMenuItem", "Clicked", self.savegs);

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

    }

    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_hz.Detach(); dw_hz = null;
        dw_mkfhjb.Detach(); dw_mkfhjb = null;
        dw_ph_mx_top.Detach(); dw_ph_mx_top = null;
        dw_ph_mx.Detach(); dw_ph_mx = null;
        dw_ph_hz.Detach(); dw_ph_hz = null;
        tb_paging.Detach(); tb_paging = null;
        sle_Count.Detach(); sle_Count = null;
        sle_Page.Detach(); sle_Page = null;
        sc_1.Detach(); sc_1 = null;
        cb_sm.Detach(); cb_sm = null;
        dw_cgddgsykc.Detach(); dw_cgddgsykc = null;
        sle_tmh.Detach(); sle_tmh = null;
        em_1.Detach(); em_1 = null;
        dw_mx_top.Detach(); dw_mx_top = null;
        dw_spda.Detach(); dw_spda = null;
        dw_mdsp_list.Detach(); dw_mdsp_list = null;
        dw_mx.Detach(); dw_mx = null;
        dw_tmbc.Detach(); dw_tmbc = null;
        sle_pptmfa_Value.Detach(); sle_pptmfa_Value = null;
        dw_error_list.Detach(); dw_error_list = null;
        dw_35_kc.Detach(); dw_35_kc = null;
        dw_ysbx.Detach(); dw_ysbx = null;
        dw_pzbtm.Detach(); dw_pzbtm = null;
        dw_tmjqfs.Detach(); dw_tmjqfs = null;
        dw_ddmx_top_tmlr.Detach(); dw_ddmx_top_tmlr = null;
        dw_1.Detach(); dw_1 = null;
        dw_proxy.Detach(); dw_proxy = null;
        dw_3.Detach(); dw_3 = null;
        dw_xt_print_print2_cmzbm.Detach(); dw_xt_print_print2_cmzbm = null;
        dw_sort.Detach(); dw_sort = null;
        dw_init.Detach(); dw_init = null;
        dw_parameter.Detach(); dw_parameter = null;
        dw_da_qx_mokuai.Detach(); dw_da_qx_mokuai = null;
        dw_xt_div_tree_no_parm.Detach(); dw_xt_div_tree_no_parm = null;
        dw_print.Detach(); dw_print = null;
        dw_da_qx_mokuai_print.Detach(); dw_da_qx_mokuai_print = null;
        dw_import_PL.Detach(); dw_import_PL = null;
        dw_ls_flda.Detach(); dw_ls_flda = null;
        tb_1.Detach(); tb_1 = null;
        ddlb_2.Detach(); ddlb_2 = null;
        ddlb_1.Detach(); ddlb_1 = null;
        ContextMenuStrip1.Detach(); ContextMenuStrip1 = null;
        ContextMenuStrip2.Detach(); ContextMenuStrip2 = null;
        ContextMenuStrip3.Detach(); ContextMenuStrip3 = null;
        requestor.Detach(); requestor = null;

        setTimeout(CollectGarbage, 100);
    }

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

    //#region 
    var editMode = "";

    var webReq = new WebRequestor();
    webReq.SetWebServiceUrl("/Service/ServiceCaiGouDingDan.ashx");

    var webReq1 = new WebRequestor();
    webReq1.SetWebServiceUrl("/Service/ServiceKuCunGuanLi.ashx");

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

    var webReq_pf = new WebRequestor();
    webReq_pf.SetWebServiceUrl("/Service/ServicePiFaDingDan.ashx");

    var curW_PH_FenJian_List = new W_PH_FenJian_List();
    var curW_OPEN_SIMPLE_CHOSE = new OpenWindowSimpleChoseBase();
    var curW_CaiGou_ChaXun = new W_CaiGou_ChaXun();
    var cur_W_Main_Error_List = new W_Main_Error_List();
    var cur_W_HYHKDR = new W_HYHKDR();
    var curSfqytmlsh = "0"     //是否启用条码流水号。 1启用，2不启用。
    var curSysteData = "";   //条码流水号打印用的。
    var curRowCount = 0;
    var reCurBigMax = 0;
    var curSmKcFlag = "Y";
    var dwc = new DataWindowChild();
    var curSpkh = "";
    var curUpdateOldSt = "";
    var G_bEditFlag = false;
    var isAdd = false;
    var curSaoMiaoLie = 0;
    var curTmlshDeleteTimestamp = "";
    var curW_OPEN_BMDA = new OpenWindowQueryBase();
    var curW_OPEN_BMDA_NEW = new OpenWindowQueryNewBase();
    var curW_OPEN_BMDA_URL = "OpenWindowQueryNewBase";
    var curBmbhAndBmmc = null; // 本单据默认部门！！！名称
    var curW_OPEN_LSRKD = new W_CaiGou_Rkjl();
    var cur_W_YW_ZNSM_CGYW = new W_YW_ZNSM_CGYW();
    var curDjlx = "";
    var curYhbh = ""
    var curQxlx = "";
    var curDygs = "1";      // 打印格式默认是1 二维格式。
    var curDypx = "1";      // 打印排序
    var title_value = "";
    var curJjfs = "";       //计价方式（客户）
    var curQjfs = "";       //取基础价方式（系统）
    var curSjc = "";
    var curTmlrms = "";     //条码录入模式
    var curGnqxStr = "";    //功能权限
    var bxshow = "";       //版型是否显示
    var jqd = 0;
    var jqw = 0;
    var curDw = null;
    var SQL_Dw = null;
    var curYxfkcBmbh = "";   //已调用的检查负库存的部门编号
    var curSfyxfkc = "N";    //是否允许负库存
    var cueSmzt = "0"; //扫描状态；0单扫，1连扫
    var curCmBtRows = 0;
    var curCmBtCols = 0;
    var curCmBtRows1 = 0;
    var curCmBtCols1 = 0;

    var curOldSpkh = "";
    var curJsqYS = 0;  //计数器颜色
    var curJsqBX = 0;  //计数器版型
    var curSpkhYsbhBxbh = "";  //当前行的【款号+颜色+版型】
    var curSpkhYsbhBxbhSFGetKCSL = "N"; //
    var curRedCm = "";  //当前变红的列。
    var curLastFocusColumn = "";
    var curSFQYSJKZQ = "0";


    var curSfQyQDID = "0";  // 如果启用渠道ID,默认不启用
    var curJqm = "";
    var curQxLzfc = "";    // 当前用户对应权限的列字符串；

    var curSetDisCount = 0; //设置整单折扣是否显示
    var curSelDays = ""; //默认该模块可查询天数
    var curSelSQL = "";
    var flag = "";

    var curSYGysbh = ""; //首页的供应商
    var curSYBmbh = ""; //首页的部门

    var curSftmsl = "N"; //为了解决扫描的时候 如果原来有值，当输入到大于库存数的时候，提示后 给当前数先+1，再-1；为了保留原来的数字
    var curFunctionId = "";
    var openflag = "";
    var curSfQYQXZ = "0";  // 是否启用新版权限组。
    var curUserGroupId = ""; //权限组编码
    var curGdhdy = "0"; //固定行打印，默认不是固定行打印
    var curSFQY_CGYW_JJZE_SHURU = "0";
    var isFlag_NewRow = "N"
    var curFormPzh = ""; //外边Pzh反调
    var zhengdanzhekouFlag = "N";
    var curDzdPzh = "";
    var curYwLrSfjckc = "N#N";    // 退申请单，退通知单
    var curSaveReturnValue = "N";
    var SelectTabFlag = "Y";
    var curMDSPFlag = "0";
    var DDYWGSYKCFlag = "0";
    var CGDDYWGSYKCFlag = "N";
    var curSfdzd = "0";
    var isPast = "N";
    var curMrbm = "";
    var curjgqx = "";
    var curDzdPzh = "";
    var curCompanyidLength = "";
    var curCompanyid = "";
    var curDdYxfs = "0";            //批发订单是否允许输入负数。
    var curLastSortNameNew = "";
    var curLastSort = "A";
    var lastSortName = "";
    var curFhjlDwList = null;
    var curYW_AUTOCOMPLETE_LEN = "1";
    //#endregion 

    //#region this.PostOpen
    this.PostOpen = function () {

        dw_mx_top.Modify("bmbh.DDDW.PercentWidth='300'");
        dw_mx_top.Modify("gysbh.DDDW.PercentWidth='300'");
        curSFQYSJKZQ = GetGlobalParm("XTCS", "SFQYSJKZQ", "qybz");
        sle_Page.SetText("1");
        curSfqytmlsh = requestor.GetParm("curSfqytmlsh");
        curSysteData = requestor.GetParm("curDate");
        curSysteData = curSysteData.replace(" ", "");
        curjgqx = requestor.GetParm("curjgqx");
        curMDSPFlag = GetGlobalParm("XTCS", "SPMDGYS", "qybz");
        curYwLrSfjckc = GetGlobalParm("YW_LR_SFJCKC", "CG", "bzxx"); // 退申请单，退通知单
        curSfQyQDID = GetGlobalParm("XTCS", "SFQYQDID", "qybz");
        DDYWGSYKCFlag = GetGlobalParm("XTCS", "CGDDGSYKCFLAG", "qybz");
        curJqm = requestor.GetParm("curJqm");
        curSelDays = requestor.GetParm("seldays");
        curSYBmbh = requestor.GetParm("curBmbh");
        curSYGysbh = requestor.GetParm("curGysbh");
        curFunctionId = requestor.GetParm("curFunctionId");
        curSfQYQXZ = GetGlobalParm("XTCS", "SFQYQXZ-NEW", "qybz"); // 是否启用新版权限组。
        curUserGroupId = requestor.GetParm("curUserGroupId"); //权限组编码
        curSFQY_CGYW_JJZE_SHURU = requestor.GetParm("curSFQY_CGYW_JJZE_SHURU"); //是否启用伟志进价金额可以手动输入
        curFormPzh = requestor.GetParm("curFormPzh"); //从外界传入的凭证
        curDzdPzh = requestor.GetParm("curDzdPzh");
        curDdYxfs = GetGlobalParm("XTCS", "XT_DJ_YXFS", "qybz");  // 订单输入负数。
        ContextMenuStrip1.SetVisible("分拣扫描ToolStripMenuItem", false);

        curYW_AUTOCOMPLETE_LEN = GetGlobalParm("XTCS", "YW_AUTOCOMPLETE_LEN", "bzxx"); // 业务录入前几个字母提示（默认1）。
        if (curYW_AUTOCOMPLETE_LEN == "") {
            curYW_AUTOCOMPLETE_LEN = "1";
        }
        curCompanyidLength = requestor.GetParm("companyidLength");
        curCompanyid = requestor.GetParm("companyid");
        curBf = curDzdPzh
        if (curDzdPzh.length > 0) {
            curSfdzd = "1";
        }
        curSaveReturnValue = "N"
        if (curDzdPzh.length > 0) {
            tb_1.SetText("ddlb_1", "已记账");
        }
        if (dw_hz.RowCount() <= 0) {
        }
        else {
            self.SetEditMode("");
        }
        //#region 初始化数据窗口的title,单据类型

        title_value = requestor.GetParm("dw_yw_cg_top_title_value");
        var init_djlx_value = requestor.GetParm("dw_yw_cg_top_title_init_djlx_value");
        var curYhbh_value = requestor.GetParm("curYhbh");
        var curQxlx_value = requestor.GetParm("curQxlx");
        if (title_value != null && title_value.length > 0) {
            dw_mx_top.Modify("title_t.Text='" + title_value + "'");
        }
        if (init_djlx_value != null && init_djlx_value.length > 0) {
            curDjlx = init_djlx_value;
        }
        if (curYhbh_value != null && curYhbh_value.length > 0) {
            curYhbh = curYhbh_value;
        }
        if (curYhbh_value != null && curYhbh_value.length > 0) {
            curQxlx = curQxlx_value;
        }

        //#endregion
        if (requestor.GetParm("QJFS") == "ERROR") {
            alert("系统基础价取价方式获取错误！\n请检查参数档案!");
            return;
        } else {
            curQjfs = requestor.GetParm("QJFS");
        }
        if (requestor.GetParm("curBmbhAndBmmc") != null && requestor.GetParm("curBmbhAndBmmc") != "") {
            curMrbm = requestor.GetParm("curBmbhAndBmmc").split("!!!")[0];
        }

        curRowAndCol = requestor.GetParm("curRowAndCol");
        if (curRowAndCol.length > 0) {
            curCmBtRows = curRowAndCol.split('#')[0];
            curCmBtCols = curRowAndCol.split('#')[1];
            curCmBtRows1 = parseInt(curRowAndCol.split('#')[0]) + 1;
            curCmBtCols1 = parseInt(curRowAndCol.split('#')[1]) + 1;
        }
        dw_mx_top.Modify("DataWindow.Readonly=yes");
        dw_mx.Modify("DataWindow.Readonly=yes");
        em_1.SetEnabled(false);

        jqd = parseFloat(requestor.GetParm("curJqd").toString());
        jqw = parseInt(requestor.GetParm("curJqw").toString());
        if (jqw == "0") {


            dw_mx.Modify("  jj.editmask.mask='#########' ")
            dw_mx.Modify("  jjze.editmask.mask='########' ")
            dw_mx.Modify("  zje.editmask.mask='########' ")

            dw_mx.Modify("jj.format='#########0'");
            dw_mx.Modify("jjze.format='#########0'");
            dw_mx.Modify("zje.format='#########0'");

            dw_mx.Modify("hjjze.format='#########00'");
            dw_hz.Modify("zjje.format='#########00'");
            dw_hz.Modify("sum_zjje.format='#########00'");


        }
        else if (jqw == "1") {


            dw_mx.Modify("  jj.editmask.mask='#######0.0' ")
            dw_mx.Modify("  jjze.editmask.mask='#######0.0' ")
            dw_mx.Modify("  zje.editmask.mask='#######0.0' ")

            dw_mx.Modify("jj.format='#########0.0'");
            dw_mx.Modify("jjze.format='#########0.0'");
            dw_mx.Modify("zje.format='#########0.0'");
            dw_mx.Modify("hjjze.format='#########0.0'");
            dw_hz.Modify("hjjze.format='#########0.0'");
            dw_hz.Modify("zjje.format='#########0.0'");
            dw_hz.Modify("sum_zjje.format='#########0.0'");


        }
        else if (jqw == "2") {


            dw_mx.Modify("  jj.editmask.mask='#######0.00' ")
            dw_mx.Modify("  jjze.editmask.mask='#######0.00' ")
            dw_mx.Modify("  zje.editmask.mask='######0.00' ")

            dw_mx.Modify("jj.format='#########0.00'");
            dw_mx.Modify("jjze.format='#########0.00'");
            dw_mx.Modify("zje.format='#########0.00'");
            dw_mx.Modify("hjjze.format='#########0.00'");
            dw_hz.Modify("zjje.format='#########0.00'");
            dw_hz.Modify("sum_zjje.format='#########0.00'");

        }
        else if (jqw == "3") {


            dw_mx.Modify("  jj.editmask.mask='#######0.000' ")
            dw_mx.Modify("  jjze.editmask.mask='#######0.000' ")
            dw_mx.Modify("  zje.editmask.mask='#######0.000' ")

            dw_mx.Modify("jj.format='#########0.000'");
            dw_mx.Modify("jjze.format='#########0.000'");
            dw_mx.Modify("zje.format='#########0.000'");
            dw_mx.Modify("hjjze.format='#########0.000'");
            dw_hz.Modify("zjje.format='#########0.000'");
            dw_hz.Modify("sum_zjje.format='#########0.000'");

        }
        bxshow = parseInt(requestor.GetParm("bxshow").toString());
        curDw = window.external.Control("dw_1");
        SQL_Dw = window.external.Control("dw_sql");
        flag = requestor.GetParm("flag");

        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 (curFormPzh.length > 0) {
                dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zsl") + "' ");
                dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "zsl"));
            }

        }


        //#region 强制修改权限
        curGnqxStr = requestor.GetParm("GnqxStr");
        if (curGnqxStr.indexOf("rbn_Qzxg") > -1) {
            ContextMenuStrip1.SetEnabled("rbn_qzxg", true);
        } else {
            ContextMenuStrip1.SetEnabled("rbn_qzxg", false);
        }

        if (curGnqxStr.indexOf("btn_Print") > -1) {
            tb_1.SetEnabled("btn_Print", true);
        } else {
            tb_1.SetEnabled("btn_Print", false);
        }
        if (curGnqxStr.indexOf("btn_Export") > -1) {
            tb_1.SetEnabled("btn_Export", true);
        } else {
            tb_1.SetEnabled("btn_Export", false);
        }
        if (curGnqxStr.indexOf("btn_Edit") > -1) {
            tb_1.SetEnabled("btn_Edit", true);
        } else {
            tb_1.SetEnabled("btn_Edit", false);
        }

        //控制结算价

        if (curGnqxStr.indexOf("btn_AlterJsj") > -1) {
            dw_mx.Modify("jj.protect='1'");
            dw_mx.Modify("zkl.protect='1'");
        } else {
            dw_mx.Modify("jj.protect='0'");
            dw_mx.Modify("zkl.protect='0'");
        }
        //#endregion


        //#region 获取条码还是配码包
        curTmlrms = GetGlobalTiaoMaLuRuMS(flag, "SCAN_BAG_FLAG_CG");
        //#endregion



        //#region 获取当前业务默认打印格式{打印格式，是否固定行打印}
        var curMrdygsAndSfgdhda = GetGlobalYw35ColPrintGs(curFunctionId);
        curDygs = curMrdygsAndSfgdhda.split("#")[0];   //打印格式
        curGdhdy = curMrdygsAndSfgdhda.split("#")[1];  //是否固定行打印
        //#endregion

        //#region 获取首页商品档案缓存数据 GetWelcomeSpda
        GetWelcomeSpda(dw_mx, dw_spda, dwc);

        //#endregion
        if (curSfdzd != "0" && dw_hz.RowCount() > 0) {
            self.dw_hz_DoubleClicked(0, 0, 1, "");
        }
        dw_mx_top.Modify("bzxx.edit.autohscroll=yes");

        dw_hz.Modify("kdsj.format='[time]'")
        ContextMenuStrip1.SetVisible("分拣扫描ToolStripMenuItem", false);
    }
    //#endregion
    this.setFhjlDwList = function (dw) {
        curFhjlDwList = dw;
    }
    this.fhjl = function () {
        try {
            dw_mx.AcceptText();
            var spkh = dw_mx.GetItemString(dw_mx.GetRow(), "spkh");
            if (spkh != "") {
              

                var reportSrv = new ReportSrv();
                var sql = " a.spkh='" + spkh + "' and a.bmbh='" + dw_mx_top.GetItemString(1, "bmbh") + "' and a.gysbh='" + dw_mx_top.GetItemString(1, "gysbh") + "'";
                curFhjlDwList.RetrieveEx(sql);

                dw_mx.GetChild("spkh", dwc);
                dwc.SetFilter("");
                dwc.Filter();
                var curChangecolor = "";
                var vFind = dwc.Find("spkh='" + spkh + "'", 1, dwc.RowCount());
                if (vFind > 0) {
                    curChangecolor = dwc.GetItemString(vFind, "cmbtxx");
                }

                if (reportSrv.Instance == null) {
                    curFhjlDwList.GetReportSrv(reportSrv);
                }
                var rowsNo = curChangecolor.split("#")[0];
                var cmfwattr = curChangecolor.split("#")[1].split(",");
                for (var i = 1; i <= 35; i++) {
                    reportSrv.SetColumnVisible("cm" + i, false);
                }
                reportSrv.SetColumnVisible("jj", false);
                reportSrv.SetColumnVisible("zjje", false);
                var curCmbt = "";
                for (var i = parseInt(cmfwattr[0]); i <= parseInt(cmfwattr[1]); i++) {
                    reportSrv.SetColumnVisible("cm" + i, true);

                    if (rowsNo > 1) {// 第一行 
                        curCmbt = dw_mx.Describe(" cm" + i + "0" + parseInt(rowsNo - 1) + "_t.text");
                    } else {
                        curCmbt = dw_mx.Describe(" cm" + i + "_t.text");
                    }

                    curFhjlDwList.Modify("cm" + i + "_t.text='" + curCmbt + "'");
                    curFhjlDwList.Modify("cm" + i + ".width='50'");
                }
                if (dw_mx.Describe("jj.visible") == '1') {
                    reportSrv.SetColumnVisible("jj", true);
                    reportSrv.SetColumnVisible("zjje", true);
                }
                reportSrv.UpdateRequestor();
            }
        } catch (e) { 
        }

    }
    this.LSRKD = function () {
        curW_OPEN_LSRKD.SetDataWindow(dw_mx_top.GetItemString(1, "bmbh"), dw_mx_top.GetItemString(1, "gysbh"), dw_mx.GetItemString(dw_mx.GetRow(), "spkh"), self, dw_mx.Describe("jj.visible"));
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.CaiGou.Base.W_CaiGou_Rkjl&spkh=" + dw_mx.GetItemString(dw_mx.GetRow(), "spkh") + ""), curW_OPEN_LSRKD, null);
        dw_mx.SetColumn("spkh");
        dw_mx.SetFocus();
        return 1;
    }
    this.MxTopClicked = function (x, y, row, name) {
        if (name == "tmsmflag" || name == "deletetm") {
            self.Myfocus();
        }
    }
    this.LastPage = function () {
        var Page = Number(sle_Page.GetText());
        if (Page != 1) {
            sle_Page.SetText(Page - 1);
            self.SelectionChanged("NextPage");
        }

    }
    this.NextPage = function () {
        var Page = Number(sle_Page.GetText());
        var MaxPage = tb_paging.GetText("lbl_MaxPage");
        if (Page != MaxPage) {
            sle_Page.SetText(Page + 1);
            self.SelectionChanged("NextPage");
        }

    }
    this.PageQuery = function (key, k, o) {
        if (key == 13) {
            if (o.name == "sle_Count") {
                sle_Page.SetText(1);
                self.SelectionChanged();
            } else {
                var Page = Number(sle_Page.GetText());
                var MaxPage = tb_paging.GetText("lbl_MaxPage");
                if (Page > MaxPage) {
                    sle_Page.SetText(MaxPage);
                }
                self.SelectionChanged("NextPage");
            }

        }
    }
    this.First = function () {
        sle_Page.SetText(1);
        self.SelectionChanged();
    }
    this.Last = function () {

        sle_Page.SetText(tb_paging.GetText("lbl_MaxPage"));
        self.SelectionChanged("NextPage");
    }
    //#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_FAudit", false);
            tb_1.SetEnabled("btn_Tally", false);
            tb_1.SetEnabled("btn_Trans", false);
            tb_1.SetEnabled("btn_Print", false);
            tb_1.SetEnabled("btn_Export", false);

            tb_1.SetEnabled("btn_InsertRow", false);
            tb_1.SetEnabled("btn_DeleteRow", false);
            tb_1.SetEnabled("btn_Save", false);

        }
    }
    //#endregion

    //#region this.dw_mx_editChanged填充行数据  √

    //填充行数据
    this.dw_mx_editChanged = function (row, dwoName, data) {
        if (flag == "CR") {
            if (dwoName.substring(0, 2) == "cm") {
                var rkfs = CheckGysdaYfhmx(dw_mx_top.GetItemString(1, "bmbh"), dw_mx_top.GetItemString(1, "gysbh"), dw_mx.GetItemString(row, "spkh"), dw_mx.GetItemString(row, "ysbh"));
                dw_mx.SetItem(row, "rkfs", rkfs);
            }
        }
        if (flag == "CT") {
            if (dwoName.substring(0, 2) == "cm") {
                dw_mx.SetItem(row, "rkfs", "TUIHUO");
            }
        }
        if (dwoName == "spkh") {
            if (data.length >= parseInt(curYW_AUTOCOMPLETE_LEN)) {
                A8erp_Biz_Scan.Yw_Dw_Mx_EditChanged(dw_mx, dwc, row, dwoName, data);
            }
        } else {
            A8erp_Biz_Scan.Yw_Dw_Mx_EditChanged(dw_mx, dwc, row, dwoName, data);
        }
    }
    //#endregion

    //#region this.dw_mx_itemFocusChange
    var cmflag = "N";
    var TempcurRow = 0;
    this.dw_mx_itemFocusChange = function (row, dwoName, data) {

        //#region 处理负库存
        if (requestor.GetParm("flag") == "CT") {
            var curBmbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh");
            if (curBmbh == "") {
                return;
            }
            if (curBmbh != curYxfkcBmbh) {
                webReqTimestamp.Invoke("GetSfyxfkcByBmbh", "curBmbh=" + curBmbh + "&tzrq=" + new Date());
                if (webReqTimestamp.StatusCode() == 200) {
                    // 允许负库存
                    if (webReqTimestamp.ResponseText() == "1") {
                        curYxfkcBmbh = curBmbh;   //已调用的检查负库存的部门编号
                        curSfyxfkc = "Y";         //允许负库存                
                    } else {
                        curYxfkcBmbh = curBmbh;   //已调用的检查负库存的部门编号
                        curSfyxfkc = "N";         //不允许负库存  
                    }
                } else {
                    requestor.MessageBox("提示33", "是否允许负库存获取失败", ICON.StopSign);
                    return;
                }
            }
        }
        //#endregion
        A8erp_Biz_Scan.Yw_Dw_Mx_ItemFocusChange(self, dw_mx, row, dwoName, data);
        curLastFocusColumn = dw_mx.GetColumnName();
        if (dw_mx.RowCount() > 0) {
            dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zsl") + "' ");
            dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "zsl"));
        } else {
            dw_mx_top.Modify(" countsl.text='0' ");
            dw_mx_top.SetItem(1, "zjsl", 0);
        }

        if (flag == "CT" && dwoName.substring(0, 2) == "cm" && dwoName.length <= 4 && curMDSPFlag == "1") {
            var tempspkh = dw_mx.GetItemString(row, "spkh");
            var tempysbh = dw_mx.GetItemString(row, "ysbh");
            var tempbxbh = dw_mx.GetItemString(row, "bxbh");
            if (tempspkh.length > 0 && tempysbh.length > 0 && tempbxbh.length > 0) {
                if (TempcurRow != row) {
                    cmflag = "N";
                }
                if (cmflag == "N") {
                    var tempfilter = "";

                    tempfilter = "UPPER(bmbh)=UPPER('" + dw_mx_top.GetItemString(1, "bmbh") + "') and UPPER(spkh)=UPPER('" + tempspkh + "') and UPPER(ysbh)=UPPER('" + tempysbh + "') and UPPER(bxbh)=UPPER('" + tempbxbh + "')"
                    dw_mdsp_list.SetFilter(tempfilter)
                    dw_mdsp_list.Filter()
                    if (dw_mdsp_list.RowCount() > 0) {

                        dw_mdsp_list.SetFilter("")
                        dw_mdsp_list.Filter()
                        cmflag = "Y";
                        TempcurRow = row;
                        tempfilter = "";
                        if (requestor.MessageBox("提示", "该商品已买断，是否继续录入?", ICON.Question, BUTTON.YesNo, 2) == 2) {
//                            dw_mx.SetItem(dw_mx.GetRow(), "spkh", "");
//                            dw_mx.SetItem(dw_mx.GetRow(), "bxbh", "");
//                            dw_mx.SetItem(dw_mx.GetRow(), "ysbh", "");
//                            dw_mx.SetItem(dw_mx.GetRow(), "ysmc", "");
//                            dw_mx.SetItem(dw_mx.GetRow(), "jldw", "");
//                            dw_mx.SetItem(dw_mx.GetRow(), "bxmc", "");
                            //                            dw_mx.SetItem(dw_mx.GetRow(), "ksmc", "");
                            dw_mx.DeleteRow(dw_mx.GetRow());
                            TempcurRow = "";
                            dw_mx.SetColumn("spkh");
                            dw_mx.SetFocus();
                            curSmKcFlag = "N";
                            return 1;
                        }
                    }
                }
            }
        }
    }
    //#endregion

    //#region this.dw_mx_DropDown  √
    this.dw_mx_DropDown = function () {


        var row = dw_mx.GetRow();
        if (row <= 0) {
            return;
        }
        var dwoName = dw_mx.GetColumnName();
        if (dw_mx_top.GetItemString(1, "bmbh") == "") {
            alert("请先选择部门!");
            dw_mx_top.SetColumn("bmbh");
            dw_mx_top.SetFocus();
            return;
        }
        if (dw_mx_top.GetItemString(1, "gysbh") == "") {
            alert("请先选择供应商!");
            dw_mx_top.SetColumn("gysbh");
            dw_mx_top.SetFocus();
            return;
        }
        if (dwoName == "spkh") {
            var curSpkh483 = dw_mx.GetItemString(row, "spkh");
            dw_mx.GetChild("spkh", dwc);
            dwc.SetFilter("");
            dwc.Filter();
            findRow = dwc.Find("spkh='" + curSpkh483 + "'", 1, dwc.RowCount());
            if (findRow > 0) {
                if (findRow == 1)
                    dwc.SelectRow(1, true);
                else
                    dwc.ScrollToRow(findRow);
            } else {
                dwc.SelectRow(0);
            }
        } else if (dwoName == "ysbh") {
            curSpkh = dw_mx.GetItemString(row, "spkh");
            if (curSpkh.length < 1) {
                // dw_mx.SetColumn("spkh")
                // dw_mx.SetFocus();
                return 1;
            }
            curYsbh = dw_mx.GetItemString(row, "ysbh");
            dw_mx.GetChild("ysbh", dwc);
            dwc.Retrieve(curSpkh, "%");
            if (curYsbh.length < 1) {
                if (dwc.RowCount() > 0) {
                    dw_mx.SetItem(row, "ysbh", dwc.GetItemString(1, "ysbh"));
                    dw_mx.SetItem(row, "ysmc", dwc.GetItemString(1, "ysmc"));
                    dw_mx.SetItem(row, "yslsh", dwc.GetItemString(1, "yslsh"));
                    curYsbh = dwc.GetItemString(1, "ysbh");
                }
            }
            findRow = dwc.Find("ysbh='" + curYsbh + "'", 1, dwc.RowCount());
            if (findRow > 0) {
                if (findRow == 1)
                    dwc.SelectRow(1, true);
                else
                    dwc.ScrollToRow(findRow);

                //#region 选中款号的同时 SET 版型 且调用一次库存 


                //#region 版型 
                if (dw_mx.Describe("bxbh.visible") == "0") {
                    dw_mx.SetItem(row, "bxbh", "-");
                    dw_mx.SetItem(row, "bxmc", "-");
                } else {
                    dw_mx.GetChild("bxbh", dwc);
                    dwc.Retrieve(curSpkh, "%");
                    if (dwc.RowCount() > 0) {
                        dw_mx.SetItem(row, "bxbh", dwc.GetItemString(1, "bxbh"));
                        dw_mx.SetItem(row, "bxmc", dwc.GetItemString(1, "bxmc"));
                    }
                }
                //#endregion 
                // 处理库存的问题 --------begin-------
                self.setKCSL("", "", "", 0, "");
                // 处理库存的问题 --------end---------   

                //#endregion

            }

        } else if (dwoName == "bxbh") {
            curSpkh = dw_mx.GetItemString(row, "spkh");
            curBxbh = dw_mx.GetItemString(row, "bxbh");
            if (curSpkh.length < 1) {
                return;
            }
            dw_mx.GetChild("bxbh", dwc);
            dwc.Retrieve(curSpkh, "%");

            if (curBxbh.length < 1) {
                if (dwc.RowCount() > 0) {
                    dw_mx.SetItem(row, "bxbh", dwc.GetItemString(1, "bxbh"));
                    dw_mx.SetItem(row, "bxmc", dwc.GetItemString(1, "bxmc"));
                    curBxbh = dwc.GetItemString(1, "bxbh");
                }
            }
            findRow = dwc.Find("bxbh='" + curBxbh + "'", 1, dwc.RowCount());
            if (findRow > 0) {
                if (findRow == 1)
                    dwc.SelectRow(1, true);
                else
                    dwc.ScrollToRow(findRow);
            }
            //#endregion 
            // 处理库存的问题 --------begin-------
            self.setKCSL("", "", "", 0, "");
            // 处理库存的问题 --------end---------   

        }

    }
    //#endregion

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

        if (dwoName == "spkh") {
            try {
                curJsqYS = 0;
                curJsqBX = 0;
                if (data.length > 0 && curOldSpkh != data) {
                    dw_mx.SetItem(row, "ysbh", "");
                    dw_mx.SetItem(row, "ysmc", "");
                    dw_mx.SetItem(row, "yslsh", "");
                    dw_mx.SetItem(row, "bxbh", "");
                    dw_mx.SetItem(row, "bxmc", "");
                    for (var i = 1; i < curCmBtCols1; i++) {
                        dw_mx.SetItem(row, "cm" + i, 0);
                    }
                }
                dw_mx.GetChild(dwoName, dwc);
                var findRow = dwc.Find("spkh='" + data + "' ", 1, dwc.RowCount());
                if (findRow <= 0) {
                    dw_mx.SetItem(row, "spkh", "");
                    dw_mx.SetItem(row, "ksmc", "");
                    dw_mx.SetItem(row, "jldw", "");
                    dw_mx.SetItem(row, "jj", 0);
                    dw_mx.SetItem(row, "dpj", 0);
                    dw_mx.SetItem(row, "lsj", 0);
                    dw_mx.SetItem(row, "zkl", 1);
                    dw_mx.SetItem(row, "cmzbh", "");
                    requestor.MessageBox("提示[款号]", "未找到款号为[" + data + "]的记录，请检查!", ICON.StopSign);
                    return 1;

                } else {
                    curOldSpkh = data;

                    if (curJjfs == "CS03") {

                        if (flag == "CR" || flag == "CT") {


                            dw_ls_flda.Retrieve(data, dw_mx_top.GetItemString(1, "gysbh"), "cg", curJjfs + "#" + dw_mx_top.GetItemString(1, "bmbh"), curQjfs);
                        }
                        else {
                            dw_ls_flda.Retrieve(data, dw_mx_top.GetItemString(1, "gysbh"), "cg", curJjfs + "#" + dw_mx_top.GetItemString(1, "bmbh"), curQjfs); //FLDA 
                        }

                    }
                    else {
                        dw_ls_flda.Retrieve(data, dw_mx_top.GetItemString(1, "gysbh"), "cg", curJjfs + "#" + dw_mx_top.GetItemString(1, "bmbh"), curQjfs); //FLDA 
                    }
                    dw_mx.SetItem(row, "ksmc", dw_ls_flda.GetItemString(1, "ksmc"));
                    dw_mx.SetItem(row, "jldw", dw_ls_flda.GetItemString(1, "jldw"));
                    dw_mx.SetItem(row, "jj", dw_ls_flda.GetItemNumber(1, "jhjg"));
                    dw_mx.SetItem(row, "dpj", dw_ls_flda.GetItemNumber(1, "dpjg"));
                    dw_mx.SetItem(row, "lsj", dw_ls_flda.GetItemNumber(1, "lsjg"));
                    if (requestor.GetParm("flag") == "CT" || requestor.GetParm("flag") == "CR") {

                        dw_mx.SetItem(row, "hgys", dw_ls_flda.GetItemString(1, "gysbh"));
                        dw_mx.SetItem(row, "hgysmc", dw_ls_flda.GetItemString(1, "gysmc"));
                        dw_mx.SetItem(row, "gysmc", dwc.GetItemString(dwc.GetRow(), "gysmc"));
                        dw_mx.SetItem(row, "ppmc", dwc.GetItemString(dwc.GetRow(), "ppmc"));
                        dw_mx.SetItem(row, "fztm", dw_ls_flda.GetItemString(1, "fztm"));
                        dw_mx.SetItem(row, "lshyj", dw_ls_flda.GetItemNumber(1, "lshyj"));
                    }

                    if (curQjfs == "QDPJ") {
                        if (dw_ls_flda.GetItemNumber(1, "dpjg") == 0)
                            dw_mx.SetItem(row, "zkl", 1);
                        else
                            dw_mx.SetItem(row, "zkl", dw_ls_flda.GetItemNumber(1, "jhjg") / dw_ls_flda.GetItemNumber(1, "dpjg"));
                    }
                    if (curQjfs == "QLSJ") {
                        if (dw_ls_flda.GetItemNumber(1, "lsjg") == 0)
                            dw_mx.SetItem(row, "zkl", 1);
                        else
                            dw_mx.SetItem(row, "zkl", dw_ls_flda.GetItemNumber(1, "jhjg") / dw_ls_flda.GetItemNumber(1, "lsjg"));
                    }

                    dw_mx.SetItem(row, "cmzbh", dw_ls_flda.GetItemString(1, "cmzbm"));

                    if (dw_mx.Describe("bxbh.visible") == "0") {
                        dw_mx.SetItem(row, "bxbh", "-");
                        dw_mx.SetItem(row, "bxmc", "-");
                    }
                }

                // 处理点亮的问题 --------begin-------
                self.setMdf(row, dwoName, data);
                // 处理点亮的问题 --------end---------

            } catch (err) {

                alert("异常，将清空本行数据。\r\n \r\n   详细信息：\r\n \r\n    " + err.description);

                dw_mx.SetItem(dw_mx.GetRow(), "spkh", "");
                dw_mx.SetItem(dw_mx.GetRow(), "ksmc", "");
                dw_mx.SetItem(dw_mx.GetRow(), "ysbh", "");
                dw_mx.SetItem(dw_mx.GetRow(), "yslsh", "");
                dw_mx.SetItem(dw_mx.GetRow(), "bxbh", "");
                dw_mx.SetItem(dw_mx.GetRow(), "bxmc", "");
                dw_mx.SetItem(dw_mx.GetRow(), "jldw", "");
                dw_mx.SetItem(dw_mx.GetRow(), "jj", 0);
                dw_mx.SetItem(dw_mx.GetRow(), "dpj", 0);
                dw_mx.SetItem(dw_mx.GetRow(), "lsj", 0);
                dw_mx.SetItem(dw_mx.GetRow(), "zkl", 1);
                dw_mx.SetItem(dw_mx.GetRow(), "cmzbh", "");
                dw_mx.SetItem(dw_mx.GetRow(), "rkfs", "");

                return 1;
            }
        }
        else if (dwoName == "ysbh") {
            dw_mx.GetChild(dwoName, dwc);
            var findRow = dwc.Find("ysbh='" + data + "' ", 1, dwc.RowCount());
            if (findRow <= 0) {
                requestor.MessageBox("提示", "未找到颜色编号为[" + data + "]的记录，请检查!", ICON.StopSign);
                return 1;
            } else {
                dw_mx.SetItem(row, "ysmc", dwc.GetItemString(findRow, "ysmc"));
                dw_mx.SetItem(row, "yslsh", dwc.GetItemString(findRow, "yslsh"));

                for (var i = 1; i < curCmBtCols1; i++) {
                    dw_mx.SetItem(row, "cm" + i, 0);
                }
                // 处理库存的问题 --------begin-------
                self.setKCSL("", "", "", 0, "");
                // 处理库存的问题 --------end---------   
            }
        }

        else if (dwoName == "bxbh") {
            dw_mx.GetChild(dwoName, dwc);
            var findRow = dwc.Find("bxbh='" + data + "' ", 1, dwc.RowCount());
            if (findRow <= 0) {
                requestor.MessageBox("提示", "未找到版型编号为[" + data + "]的记录，请检查!", ICON.StopSign);
                return 1;
            } else {
                dw_mx.SetItem(row, "bxmc", dwc.GetItemString(findRow, "bxmc"));

                for (var i = 1; i < curCmBtCols1; i++) {
                    dw_mx.SetItem(row, "cm" + i, 0);
                }
                // 处理库存的问题 --------begin-------
                self.setKCSL("", "", "", 0, "");
                // 处理库存的问题 --------end---------   
            }
        }
        else if (dwoName.substring(0, 2) == "cm") {

            self.SyntaxHjjzeByJjze();
            var c = dwoName;
            var cNo = new Number(c.replace("cm", ""));
            //  取尺码组编码 
            var curChangecolor = self.GetChangecolor();

            if (curChangecolor.length > 0) {
                var rowsNo = curChangecolor.split("#")[0];    //选中行
                var rowsScope = curChangecolor.split("#")[1]; //尺码范围   
                var beginNo = rowsScope.split(",")[0];        //范围是从0开始的
                var endNo = rowsScope.split(",")[1];
                beginNo = parseInt(beginNo) - 1;
                endNo = parseInt(endNo) - 1;
                var curBeg = parseInt(beginNo) + 1;          // 范围是从0开始的，尺码+1.
                var curEnd = parseInt(endNo) + 1;
                var curCmzHaveDm = curChangecolor.split("#")[2].split(","); //尺码组中对应的代码
                var curSpmxHaveDm = curChangecolor.split("#")[3].split(","); //商品明细中包含的代码              
                //3#2,4#33,44,55,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#AA,BB,CC,DD,EE,FF,GG
                if (cNo > curEnd || cNo < curBeg) {

                    requestor.MessageBox("提示1", "没有此商品编号", 1);
                    dw_mx.SetItem(row, "cm" + cNo, 0);
                    dw_mx.SetColumn("cm" + cNo);
                    dw_mx.SetFocus();
                    return 1;
                } else {

                    var isHave = false;
                    for (var k = 0; k < curSpmxHaveDm.length && !isHave; k++) {
                        if (curSpmxHaveDm[k] == curCmzHaveDm[cNo - curBeg]) { //尺码代代码是否有商品明细资料
                            isHave = true;
                        }
                    }
                    if (!isHave) {

                        requestor.MessageBox("提示2", "没有此商品编号", 1);
                        dw_mx.SetItem(row, "cm" + cNo, 0);

                        if (cNo >= curEnd) {// 到边境的时候跳到价格去
                            dw_mx.SetColumn("jj");
                        } else {//没到边境的时候跳到下一个位置去
                            dw_mx.SetColumn("cm" + parseInt(cNo + 1));
                        }

                        dw_mx.SetFocus();
                        return 1;
                    } else {
                        //#region 采购退的时候要检查是否允许负库存,  curSfyxfkc == "Y" 允许，否则不允许                        
                        if (curSfyxfkc == "N") {
                            if (self.JudgeKc(row, dwoName, data) == 0) {
                                // 如果是扫描的时候每次-1，如果是录入单的时候直接情况=0；
                                if (curSftmsl == "Y") {
                                    dw_mx.SetItem(row, dwoName, dw_mx.GetItemNumber(row, dwoName) - 1);
                                    curSftmsl = "N";
                                } else {
                                    dw_mx.SetItem(row, dwoName, 0);

                                }
                                self.SyntaxHjjzeByJjze();
                                dw_mx.SetColumn(dwoName);
                                dw_mx.SetFocus();
                                return 1;
                            }
                        }
                        //#endregion
                        //精确度，小数位数以及舍入
                        //dw_mx.SetItem(row, "lsj", dw_mx.GetItemNumber(row, "lsj") + jqd);
                        //self.setJGJqd(row, dw_mx.GetItemNumber(row, "lsj"));
                        if (cNo >= curEnd) {// 到边境的时候跳到价格去

                            if (dw_mx.Describe("jj.visible") == '1') {
                                //dw_mx.SetColumn("jj");
                                return 0;
                            } else {
                                dw_mx.AcceptText();

                            }
                        } else {//没到边境的时候跳到下一个位置去
                            dw_mx.SetColumn("cm" + parseInt(cNo + 1));
                        }
                        dw_mx.SetFocus();
                        return 1;
                    }
                }
            }

        }
        //折扣率
        else if (dwoName == "zkl") {
            if (curQjfs == "QDPJ")
                self.setJGJqd(row, dw_mx.GetItemNumber(row, "dpj") * parseFloat(data));
            if (curQjfs == "QLSJ")
                self.setJGJqd(row, dw_mx.GetItemNumber(row, "lsj") * parseFloat(data));
            self.SyntaxHjjzeByJjze();
        }
        //折扣率=进价/零售价
        else if (dwoName == "jj") {
            var jg = parseFloat(data) + jqd;
            var len = (jg.toString()).split(".")[0].length + 1 + jqw;
            var zhjg = parseFloat((jg.toString()).substring(0, len));
            dw_mx.SetItem(row, "jj", zhjg);


            if (curQjfs == "QDPJ") {
                if (dw_mx.GetItemNumber(row, "dpj") == 0)
                    dw_mx.SetItem(row, "zkl", 1);
                else
                    dw_mx.SetItem(row, "zkl", zhjg / dw_mx.GetItemNumber(row, "dpj"));
            }
            else {
                if (dw_mx.GetItemNumber(row, "lsj") == 0)
                    dw_mx.SetItem(row, "zkl", 1);
                else
                    dw_mx.SetItem(row, "zkl", zhjg / dw_mx.GetItemNumber(row, "lsj"));
            }
            self.SyntaxHjjzeByJjze();
            return 1;
        }

        //折扣率=进价/零售价
        else if (dwoName == "hjjze") {

            var rSpsl = dw_mx.GetItemNumber(row, "spsl");
            var rJg = parseFloat(data) / rSpsl;
            var jg = parseFloat(rJg) + jqd;
            var len = (jg.toString()).split(".")[0].length + 1 + jqw;
            var zhjg = parseFloat((jg.toString()).substring(0, len));
            dw_mx.SetItem(row, "jj", zhjg);

            if (curQjfs == "QDPJ") {
                if (dw_mx.GetItemNumber(row, "dpj") == 0)
                    dw_mx.SetItem(row, "zkl", 1);
                else
                    dw_mx.SetItem(row, "zkl", zhjg / dw_mx.GetItemNumber(row, "dpj"));
            }
            else {
                if (dw_mx.GetItemNumber(row, "jj") == 0)
                    dw_mx.SetItem(row, "zkl", 1);
                else
                    dw_mx.SetItem(row, "zkl", zhjg / dw_mx.GetItemNumber(row, "jj"));
            }

            // return 1;

        }
    }
    //#endregion

    this.SyntaxHjjzeByJjze = function () {
        if (flag == "CR" || flag == "CT") {
            dw_mx.AcceptText();
            var rr = dw_mx.GetRow();
            var rJj = dw_mx.GetItemNumber(rr, "jj");
            var rSpsl = dw_mx.GetItemNumber(rr, "spsl");
            //  var rZkl = dw_mx.GetItemNumber(rr, "zkl");
            var rHjjze = rJj * rSpsl;
            dw_mx.SetItem(dw_mx.GetRow(), "hjjze", rHjjze);
        }
        return 1;

    }

    //#region 取changecolor
    var curLastChangecolor = "";
    var curLastChangecolorSpkh = "";
    this.GetChangecolor = function (curKh) {
        var curColors = "";
        var curSpkh = "";
        if (arguments.length == 1) {
            curSpkh = curKh;
        } else {
            curSpkh = dw_mx.GetItemString(dw_mx.GetRow(), "spkh");
        }

        if (curSpkh.length < 1) {

            return curColors;
        }
        if (curLastChangecolorSpkh == curSpkh && curLastChangecolorSpkh != "") {

            curColors = curLastChangecolor
        } else {
            curLastChangecolorSpkh = curSpkh;

            dw_mx.GetChild("spkh", dwc);
            if (curLastFocusColumn != "spkh" && dw_mx.GetColumnName() != "spkh") 
            {
                dwc.SetFilter("");
                dwc.Filter();
            }
            var vFind = dwc.Find("spkh='" + curSpkh + "'", 1, dwc.RowCount());
            if (vFind > 0) {
                curColors = dwc.GetItemString(vFind, "cmbtxx");
                curLastChangecolor = curColors;
            }
        }

        return curColors;
    }

    //#endregion

    //#region 价格精确度。
    this.setJGJqd = function (row, lsj) {
        var jg = GetAccAdd(lsj, jqd);
        //alert(jg);
        var len = (jg.toString()).split(".")[0].length + 1 + jqw;
        var zhjg = parseFloat((jg.toString()).substring(0, len));
        dw_mx.SetItem(row, "jj", zhjg);
        return 1;
    }
    //#endregion

    //#region 设置库存数量显示
    this.setKCSL = function (bm, kh, ys, bx, cmStr) {
        dw_mx_top.AcceptText();
        dw_mx.AcceptText();
        var myBm = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh"); // 部门     
        var myKh = dw_mx.GetItemString(dw_mx.GetRow(), "spkh");       //商品款号        
        var myYs = dw_mx.GetItemString(dw_mx.GetRow(), "ysbh");      //颜色编号 
        var myBx = dw_mx.GetItemString(dw_mx.GetRow(), "bxbh");       // 版型编号 
        var myCmStr = cmStr
        if (curSpkhYsbhBxbh == myKh + myYs + myBx + dw_mx.GetRow() && curSpkhYsbhBxbhSFGetKCSL == "Y") {
            if (flag == "CG" && DDYWGSYKCFlag == "1") {
                //                for (var i = 1; i < curCmBtCols1; i++) {
                //                    dw_mx.Modify("rk" + i + "_t.Text='-'");
                //                }
            }
            else {
                return;
            }
        } else {
            for (var i = 1; i < curCmBtCols1; i++) {
                dw_mx.Modify("kc" + i + "_t.Text='-'");
                dw_mx.Modify("rk" + i + "_t.Text='-'");

            }
        }
        var curChangeCols = self.GetChangecolor();
        if (curChangeCols == "") {
            return;
        }

        var curChangecolor = curChangeCols.split("#")[2]; // 尺码组
        var curStartEnd = curChangeCols.split("#")[1]; //尺码范围
        var curStartNum = curStartEnd.split(",")[0]; // 尺码范围开始位置
        var myCmStr = curChangecolor.split(",,")[0]; //尺码组
        var myYwDate = UtcDateFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "kdrq"));
        dw_35_kc.Retrieve(myBm, myKh, myYs, myBx, myCmStr, myYwDate, "", requestor.GetParm("flag"), myKh); //取库存数量       
        if (dw_35_kc.RowCount() > 0) {
            var kcslStr = dw_35_kc.GetItemString(1, "kcsls"); // 库存数量字符串
            if (kcslStr.length > 0) {
                for (var t = 0; t < kcslStr.split("#").length; t++) {
                    var kcValue = parseInt(kcslStr.split("#")[t].split(",")[1]);
                    if ((requestor.GetParm("flag") == "CT" || requestor.GetParm("flag") == "CS" || requestor.GetParm("flag") == "CD") && editMode == "Edit") {
                        kcValue += self.ModifyKcsl(myKh, myYs, myBx, "cm" + (parseInt(t) + parseInt(curStartNum)));
                    }
                    if (kcValue == 0) {//如果库存数量=0的时候，显示“-”否则显示相应的库存数量
                        kcValue = "-";
                    }
                    dw_mx.Modify("kc" + (parseInt(t) + parseInt(curStartNum)) + "_t.Text='" + kcValue + "'");
                }
            }
            curSpkhYsbhBxbh = myKh + myYs + myBx + dw_mx.GetRow();  //当前行的【款号+颜色+版型】
            curSpkhYsbhBxbhSFGetKCSL = "Y";
        }


        //#region 要显示供应商方库存

        if (requestor.GetParm("flag") == "CG" && CGDDYWGSYKCFlag == "Y") {
            var myGysbh = dw_mx_top.GetItemString(1, "gysbh");
            dw_35_kc.Retrieve(myGysbh, myKh, myYs, myBx, myCmStr, myYwDate, "", requestor.GetParm("flag"), myKh); //取库存数量 
            if (dw_35_kc.RowCount() > 0) {

                var kcslStr = dw_35_kc.GetItemString(1, "kcsls"); // 库存数量字符串
                if (kcslStr.length > 0) {
                    for (var t = 0; t < kcslStr.split("#").length; t++) {

                        var kcValue = parseInt(kcslStr.split("#")[t].split(",")[1]);
                        if (kcValue == 0) {//如果库存数量=0的时候，显示“-”否则显示相应的库存数量
                            kcValue = "-";
                        }
                        dw_mx.Modify("rk" + (parseInt(t) + parseInt(curStartNum)) + "_t.Text='" + kcValue + "'");
                    }
                }
            }
        }
        //#endregion
    }
    //#endregion

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

    this.dw_mx_keyDown = function (keyCode, keyFlags) {
        // alert([keyCode, keyFlags])
        if (keyCode == 35) {
            dw_mx.AcceptText();
            if (dw_mx.GetItemNumber(dw_mx.GetRow(), "spsl") == 0) {
                requestor.MessageBox("提示840", "请为当前行输入数量", 1);
                dw_mx.SetColumn(curRedCm);
                dw_mx.SetFocus();
            } else if (dw_mx.GetRow() == dw_mx.RowCount()) {
                dw_mx.ScrollToRow(dw_mx.InsertRow(0));
                //复制行数据 ---begin---
                dw_mx.SetItem(dw_mx.RowCount(), "spkh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "spkh"));
                dw_mx.SetItem(dw_mx.RowCount(), "ksmc", dw_mx.GetItemString(dw_mx.RowCount() - 1, "ksmc"));
                dw_mx.SetItem(dw_mx.RowCount(), "ysbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "ysbh"));
                dw_mx.SetItem(dw_mx.RowCount(), "ysmc", dw_mx.GetItemString(dw_mx.RowCount() - 1, "ysmc"));
                dw_mx.SetItem(dw_mx.RowCount(), "yslsh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "yslsh"));
                dw_mx.SetItem(dw_mx.RowCount(), "bxbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "bxbh"));
                dw_mx.SetItem(dw_mx.RowCount(), "bxmc", dw_mx.GetItemString(dw_mx.RowCount() - 1, "bxmc"));
                dw_mx.SetItem(dw_mx.RowCount(), "jldw", dw_mx.GetItemString(dw_mx.RowCount() - 1, "jldw"));
                dw_mx.SetItem(dw_mx.RowCount(), "jj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "jj"));
                dw_mx.SetItem(dw_mx.RowCount(), "lsj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "lsj"));
                dw_mx.SetItem(dw_mx.RowCount(), "dpj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "dpj"));
                dw_mx.SetItem(dw_mx.RowCount(), "cmzbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "cmzbh"));
                dw_mx.SetItem(dw_mx.RowCount(), "zkl", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "zkl"));
                //复制行数据 ---end-----
                dw_mx.SetColumn("spkh");
                dw_mx.SetFocus();
            } else if (dw_mx.GetColumnName().substring(0, 2) == "cm") {
                dw_mx.ScrollToRow(dw_mx.InsertRow(0));
                //复制行数据 ---begin---
                dw_mx.SetItem(dw_mx.RowCount(), "spkh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "spkh"));
                dw_mx.SetItem(dw_mx.RowCount(), "ksmc", dw_mx.GetItemString(dw_mx.RowCount() - 1, "ksmc"));
                dw_mx.SetItem(dw_mx.RowCount(), "ysbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "ysbh"));
                dw_mx.SetItem(dw_mx.RowCount(), "ysmc", dw_mx.GetItemString(dw_mx.RowCount() - 1, "ysmc"));
                dw_mx.SetItem(dw_mx.RowCount(), "yslsh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "yslsh"));
                dw_mx.SetItem(dw_mx.RowCount(), "bxbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "bxbh"));
                dw_mx.SetItem(dw_mx.RowCount(), "bxmc", dw_mx.GetItemString(dw_mx.RowCount() - 1, "bxmc"));
                dw_mx.SetItem(dw_mx.RowCount(), "jldw", dw_mx.GetItemString(dw_mx.RowCount() - 1, "jldw"));
                dw_mx.SetItem(dw_mx.RowCount(), "jj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "jj"));
                dw_mx.SetItem(dw_mx.RowCount(), "lsj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "lsj"));
                dw_mx.SetItem(dw_mx.RowCount(), "dpj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "dpj"));
                dw_mx.SetItem(dw_mx.RowCount(), "cmzbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "cmzbh"));
                dw_mx.SetItem(dw_mx.RowCount(), "zkl", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "zkl"));
                //复制行数据 ---end-----

                dw_mx.SetColumn("spkh");
                dw_mx.SetFocus();

            } else {
                dw_mx.ScrollToRow(dw_mx.GetRow() + 1);
                dw_mx.SetColumn("spkh");
                dw_mx.SetFocus();
            }
            return 1;
        } else if (dw_mx.GetColumnName() == "jj") {
            if (keyCode == 13 || keyCode == 39) {
                if (dw_mx.GetItemNumber(dw_mx.GetRow(), "spsl") == 0) {
                    requestor.MessageBox("提示890", "请为当前行输入数量", 1);
                    dw_mx.SetColumn(curRedCm);
                    dw_mx.SetFocus();
                } else if (dw_mx.GetRow() == dw_mx.RowCount()) {
                    //dw_mx.RowsCopy(dw_mx.GetRow(), dw_mx.GetRow(), DWBUFFER.Primary, dw_mx, dw_mx.RowCount() + 1, DWBUFFER.Primary);
                    dw_mx.ScrollToRow(dw_mx.InsertRow(0));
                    //复制行数据 ---begin---
                    dw_mx.SetItem(dw_mx.RowCount(), "spkh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "spkh"));
                    dw_mx.SetItem(dw_mx.RowCount(), "ksmc", dw_mx.GetItemString(dw_mx.RowCount() - 1, "ksmc"));
                    dw_mx.SetItem(dw_mx.RowCount(), "ysbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "ysbh"));
                    dw_mx.SetItem(dw_mx.RowCount(), "ysmc", dw_mx.GetItemString(dw_mx.RowCount() - 1, "ysmc"));
                    dw_mx.SetItem(dw_mx.RowCount(), "yslsh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "yslsh"));
                    dw_mx.SetItem(dw_mx.RowCount(), "bxbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "bxbh"));
                    dw_mx.SetItem(dw_mx.RowCount(), "bxmc", dw_mx.GetItemString(dw_mx.RowCount() - 1, "bxmc"));
                    dw_mx.SetItem(dw_mx.RowCount(), "jldw", dw_mx.GetItemString(dw_mx.RowCount() - 1, "jldw"));
                    dw_mx.SetItem(dw_mx.RowCount(), "jj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "jj"));
                    dw_mx.SetItem(dw_mx.RowCount(), "lsj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "lsj"));
                    dw_mx.SetItem(dw_mx.RowCount(), "dpj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "dpj"));
                    dw_mx.SetItem(dw_mx.RowCount(), "cmzbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "cmzbh"));
                    dw_mx.SetItem(dw_mx.RowCount(), "zkl", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "zkl"));
                    //复制行数据 ---end-----

                    dw_mx.SetColumn("spkh");
                    dw_mx.SetFocus();
                } else {
                    dw_mx.ScrollToRow(dw_mx.GetRow() + 1);
                    dw_mx.SetColumn("spkh");
                    dw_mx.SetFocus();

                }
                return 1;
            } else if (keyCode == 37) {
                // 取尺码组编码
                var curChangecolor = self.GetChangecolor();
                if (curChangecolor.length > 0) {
                    var rowsScope = curChangecolor.split("#")[1]; //尺码范围   
                    var endNo = rowsScope.split(",")[1];
                    dw_mx.SetColumn("cm" + endNo);
                    dw_mx.SetFocus();
                }
                return 1;
            }
        } else if (dw_mx.GetColumnName() == "bxbh") {
            if (keyCode == 13 || keyCode == 39) {
                // 取尺码组编码
                var curChangecolor = self.GetChangecolor();
                if (curChangecolor.length > 0) {
                    var rowsNo = curChangecolor.split("#")[0];    //选中行
                    var rowsScope = curChangecolor.split("#")[1]; //尺码范围   
                    var beginNo = rowsScope.split(",")[0];        //范围是从0开始的
                    var endNo = rowsScope.split(",")[1];
                    beginNo = parseInt(beginNo) - 1;
                    endNo = parseInt(endNo) - 1;
                    var curBeg = parseInt(beginNo) + 1;          // 范围是从0开始的，尺码+1.
                    var curEnd = parseInt(endNo) + 1;
                    dw_mx.SetColumn("cm" + curBeg);
                    //  alert("cm" + curBeg);
                    dw_mx.SetFocus();
                }
                return 1;
            } else if (keyCode == 37) {
                dw_mx.SetColumn("ysbh");
                dw_mx.SetFocus();
                return 1;
            }
        }
        else if (dw_mx.GetColumnName() == "ysbh") {
            if (keyCode == 13 || keyCode == 39) {
                if (dw_mx.Describe("bxbh.Visible") != "0") {
                    dw_mx.SetColumn("bxbh");
                    dw_mx.SetFocus();
                } else {
                    // 取尺码组编码
                    var curChangecolor = self.GetChangecolor();
                    if (curChangecolor.length > 0) {
                        var rowsNo = curChangecolor.split("#")[0];    //选中行
                        var rowsScope = curChangecolor.split("#")[1]; //尺码范围   
                        var beginNo = rowsScope.split(",")[0];        //范围是从0开始的
                        var endNo = rowsScope.split(",")[1];
                        beginNo = parseInt(beginNo) - 1;
                        endNo = parseInt(endNo) - 1;
                        var curBeg = parseInt(beginNo) + 1;          // 范围是从0开始的，尺码+1.
                        var curEnd = parseInt(endNo) + 1;
                        dw_mx.SetColumn("cm" + curBeg);
                        //  alert("cm" + curBeg);
                        dw_mx.SetFocus();
                    }
                }
                return 1;
            } else if (keyCode == 37) {
                dw_mx.SetColumn("spkh");
                dw_mx.SetFocus();
                return 1;
            }
        } else if (dw_mx.GetColumnName().substring(0, 2) == "cm") {
            var c = dw_mx.GetColumnName();
            var cNo = new Number(c.replace("cm", ""));
            var curChangecolor = self.GetChangecolor();

            if (curChangecolor.length > 0) {
                var rowsNo = curChangecolor.split("#")[0];    //选中行
                var rowsScope = curChangecolor.split("#")[1]; //尺码范围   
                var beginNo = rowsScope.split(",")[0];        //范围是从0开始的
                var endNo = rowsScope.split(",")[1];
                beginNo = parseInt(beginNo) - 1;
                endNo = parseInt(endNo) - 1;
                var curBeg = parseInt(beginNo) + 1;          // 范围是从0开始的，尺码+1.
                var curEnd = parseInt(endNo) + 1;
            } else {
                return 1;
            }
            if (keyCode == 13 || keyCode == 39) {
                if (cNo >= curEnd) {
                    if (dw_mx.Describe("jj.visible") == '1') {
                        dw_mx.SetColumn("jj");
                    } else {
                        // 如果进价被屏蔽，就自动跳到下一行---begin--------------。
                        dw_mx.AcceptText();
                        if (dw_mx.GetItemNumber(dw_mx.GetRow(), "spsl") == 0) {
                            requestor.MessageBox("提示1009", "请为当前行输入数量", ICON.Exclamation);
                            dw_mx.SetColumn("cm" + parseInt(curEnd));
                        } else if (dw_mx.GetRow() == dw_mx.RowCount()) {
                            dw_mx.ScrollToRow(dw_mx.InsertRow(0));
                            //复制行数据 ---begin---
                            dw_mx.SetItem(dw_mx.RowCount(), "spkh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "spkh"));
                            dw_mx.SetItem(dw_mx.RowCount(), "ksmc", dw_mx.GetItemString(dw_mx.RowCount() - 1, "ksmc"));
                            dw_mx.SetItem(dw_mx.RowCount(), "ysbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "ysbh"));
                            dw_mx.SetItem(dw_mx.RowCount(), "ysmc", dw_mx.GetItemString(dw_mx.RowCount() - 1, "ysmc"));
                            dw_mx.SetItem(dw_mx.RowCount(), "yslsh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "yslsh"));
                            dw_mx.SetItem(dw_mx.RowCount(), "bxbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "bxbh"));
                            dw_mx.SetItem(dw_mx.RowCount(), "bxmc", dw_mx.GetItemString(dw_mx.RowCount() - 1, "bxmc"));
                            dw_mx.SetItem(dw_mx.RowCount(), "jldw", dw_mx.GetItemString(dw_mx.RowCount() - 1, "jldw"));
                            dw_mx.SetItem(dw_mx.RowCount(), "jj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "jj"));
                            dw_mx.SetItem(dw_mx.RowCount(), "lsj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "lsj"));
                            dw_mx.SetItem(dw_mx.RowCount(), "dpj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "dpj"));
                            dw_mx.SetItem(dw_mx.RowCount(), "cmzbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "cmzbh"));
                            dw_mx.SetItem(dw_mx.RowCount(), "zkl", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "zkl"));
                            //复制行数据 ---end----- 
                            dw_mx.SetColumn("spkh");

                        } else {
                            dw_mx.ScrollToRow(dw_mx.GetRow() + 1);
                            dw_mx.SetColumn("spkh");
                        }

                        // 如果进价被屏蔽，就自动跳到下一行---end--------------。
                    }
                    dw_mx.SetFocus();
                } else {
                    dw_mx.SetColumn("cm" + (parseInt(cNo) + 1));
                    dw_mx.SetFocus();
                }
                return 1;
            } else if (keyCode == 37) {
                if (curBeg < parseInt(cNo)) {
                    dw_mx.SetColumn("cm" + (parseInt(cNo) - 1));
                    dw_mx.SetFocus();
                } else if (dw_mx.Describe("bxbh.Visible") == "1") {
                    dw_mx.SetColumn("bxbh");
                    dw_mx.SetFocus();
                } else {
                    dw_mx.SetColumn("ysbh");
                    dw_mx.SetFocus();
                }
                return 1;
            }
        } else if (dw_mx.GetColumnName() == "spkh" && (keyCode == 13 || keyCode == 39)) {
            dw_mx.SetColumn("ysbh");
            dw_mx.SetFocus();
            return 1;
        }
    }
    //#endregion

    //#region this.dw_hz_DoubleClicked
    this.dw_hz_DoubleClicked = function (x, y, row, dowName) {

        if (dowName.indexOf("_t") > -1) {
            var curColName = dowName.split("_")[0];
            curLastSortNameNew = curColName;
            if (curColName == lastSortName) {
                dw_hz.SetSort(curColName + " A");
                lastSortName = "";
                dw_hz.Sort();
                curLastSort = "A";

            } else {
                dw_hz.SetSort(curColName + " D");
                lastSortName = dowName.split("_")[0];
                dw_hz.Sort();
                curLastSort = "D";
            }
        } else {
            if (row > 0) {
                tab_1.SelectTab(2);
                dw_mx.ShareDataOff();
                tb_1.SetEnabled("ddlb_1", false);
                tb_1.SetEnabled("ddlb_2", 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);
                self.GetSFYSGYSKCFlag();
            } else {
                if (dowName.indexOf("_t") > -1) {
                    Dwsort(dw_hz, dowName);
                }

            }
            self.GetMaxXh();
        
        }

    }
    //#endregion

    //    this.dw_hz_Clicked = function (x, y, row, dwoName) {
    //        alert(dwoName);
    //    }

    //#region 获取明细单号最大值
    this.GetMaxXh = function () {
        if (dw_mx.RowCount() > 0) {
            dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zsl") + "' ");
            dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "zsl"));
            dw_mx_top.SetItem(1, "zjje", dw_mx.GetItemNumber(1, "zje"));
        } else {
            dw_mx_top.Modify(" countsl.text='0' ");
            //  dw_mx_top.SetItem(1, "zjsl",0);
            //  dw_mx_top.SetItem(1, "zjje",0);
        }
        curRowCount = dw_mx.RowCount();
        var curBigMaxMxdh = "";
        if (curRowCount >= 1) {
            curBigMaxMxdh = dw_mx.GetItemString(curRowCount, "mxdh");
            reCurBigMax = new Number(curBigMaxMxdh.substring(curBigMaxMxdh.length - 6, curBigMaxMxdh.length)) + 1;

        } else {
            reCurBigMax = 1;
        }
    }
    //#endregion

    //#region this.Hz_RowFocusChanged  汇总行改变的时候
    this.Hz_RowFocusChanged = function (row) {

        var PhLydh = "";
        if (row > 0) {
            var fhStatus = dw_hz.GetItemString(row, "fhjb");
            var curFlag = requestor.GetParm("flag");
            if (curFlag == "CR") {
                PhLydh = dw_hz.GetItemString(row, "phlydh");
            }
            var curJzbz = "";
            curJzbz = dw_hz.GetItemString(row, "jzbz");
            if (curFlag == "CZ" || curFlag == "CD") {
                if (curJzbz == "1") {
                    tb_1.SetEnabled("btn_Trans", true);
                } else {
                    tb_1.SetEnabled("btn_Trans", false);
                }
            } else {
                tb_1.SetEnabled("btn_FAudit", false);

                if (curFlag == "CR") {
                    if (PhLydh.length < 1) {

                        tb_1.SetEnabled("btn_PH_Print", false);
                        tb_1.SetEnabled("btn_PH_FAudit", false);

                    } else {
                        if (fhStatus != "F") {
                            tb_1.SetEnabled("btn_PH_Print", true);
                            tb_1.SetEnabled("btn_PH_FAudit", false);
                        } else {
                            if (curJzbz == "1") {
                                tb_1.SetEnabled("btn_PH_FAudit", false);
                                tb_1.SetEnabled("btn_PH_Print", false);
                            } else {
                                tb_1.SetEnabled("btn_PH_FAudit", true);
                                tb_1.SetEnabled("btn_PH_Print", true);
                            }
                        }

                    }
                }
                if (curJzbz == "1") {
                    tb_1.SetEnabled("btn_Trans", true);
                } else {
                    tb_1.SetEnabled("btn_Trans", false);
                }
            }

            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_FenJian", true);
                tb_1.SetEnabled("btn_FAudit", false);
                try {
                    if (dw_hz.GetItemString(row, "jzbz") == "1") {
                        tb_1.SetEnabled("btn_Tally", false);
                        tb_1.SetEnabled("btn_Edit", false);
                    } else {
                        //     tb_1.SetEnabled("btn_Tally", true);
                        tb_1.SetEnabled("btn_Edit", true);
                    }
                } catch (e) {

                }
            } else if (fhStatus == "T") {
                tb_1.SetEnabled("btn_Audit", false);
                tb_1.SetEnabled("btn_Edit", false);
                tb_1.SetEnabled("btn_Delete", false);
                tb_1.SetEnabled("btn_FenJian", false);
                try {
                    if (dw_hz.GetItemString(row, "jzbz") == "1") {
                        tb_1.SetEnabled("btn_UnAudit", false);
                        tb_1.SetEnabled("btn_Tally", false);
                        tb_1.SetEnabled("btn_FAudit", true);
                    } else {
                        tb_1.SetEnabled("btn_UnAudit", true);
                        tb_1.SetEnabled("btn_Tally", true);
                        tb_1.SetEnabled("btn_FAudit", true);
                    }
                } catch (e) {

                }

            } 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_FAudit", false);
            }

            var curFhjbs = dw_hz.GetItemString(dw_hz.GetRow(), "fhjb"); // 当前
            //alert(curFhjbs)
            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=''");
                }

            }
        }
        self.SetButtomStatus();
    }
    //#endregion

    //#region this.dw_hz_Clicked
    this.dw_hz_Clicked = function (x, y, row, dwoName) {
        //  dw_hz.SelectRow(0, false);
        //  dw_hz.SelectRow(row, true);
        //  alert(row);
    }
    //#endregion

    //#region this.ClareKcAndCmzAll
    this.ClareKcAndCmzAll = function () {
        var cmzYs = "";
        for (var r = 0; r < curCmBtRows1; r++) {
            for (var k = 1; k < curCmBtCols1; k++) {
                if (r == 0) {
                    cmzYs += " cm" + k + "_t.color='33554432'  cm" + k + "_t.Font.Weight='400'"; // 行变粗，蓝色 
                    cmzYs += "kc" + k + "_t.Text='-'";
                }
                else {
                    cmzYs += " cm" + k + "0" + r + "_t.color='33554432'  cm" + k + "0" + r + "_t.Font.Weight='400'"; // 行变粗，蓝色
                }
            }
        }
        dw_mx.Modify(cmzYs.toString());

        curOldSpkh = "";
        curJsqYS = 0;  //计数器颜色
        curJsqBX = 0;  //计数器版型
        curSpkhYsbhBxbh = "";  //当前行的【款号+颜色+版型】
        curSpkhYsbhBxbhSFGetKCSL = "N"; //
        curRedCm = "";  //当前变红的列。

    }
    //#endregion

    //#region this.setMdf
    this.setMdf = function (row, dwoName, data) {
        curRedCm = A8erp_Biz_Scan.Yw_ShowCmz_Color(self, dw_mx, row, dwoName, data, curCmBtRows1, curCmBtCols1);
    }

    //#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_FAudit", !bEditFlag);
        tb_1.SetEnabled("btn_ChaXun", !bEditFlag);
        tb_1.SetEnabled("btn_Trans", !bEditFlag);
        if (requestor.GetParm("flag") == "CR" || requestor.GetParm("flag") == "CT") {
            if (curSfqytmlsh == "1" && GetXiTongCanShu("tmlshsdspxx", "xtcs", "qybz") == "1") {
                tb_1.SetEnabled("btn_InsertRow", false);
                tb_1.SetEnabled("btn_DeleteRow", false);
            } else {
                tb_1.SetEnabled("btn_InsertRow", bEditFlag);
                tb_1.SetEnabled("btn_DeleteRow", bEditFlag);
            }
        } else {
            tb_1.SetEnabled("btn_InsertRow", bEditFlag);
            tb_1.SetEnabled("btn_DeleteRow", bEditFlag);
        }

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

        sle_tmh.SetVisible(bEditFlag);  // 条码录入
        em_1.SetEnabled(bEditFlag);


        if (bEditFlag) {
            SelectTabFlag = "N";
            tab_1.SelectTab(2);
            tb_1.SetEnabled("btn_ChaXun", false);
            dw_mx_top.Modify("DataWindow.Readonly=no");
            dw_mx.Modify("DataWindow.Readonly=no");
            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("btn_ChaXun", true);
            } else if (curTabindex == "2") {
                tb_1.SetEnabled("btn_ChaXun", false);
            }
        }
    }
    //#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;
                }
                webReqTimestamp.Invoke("YW_TIMESTAMP_REC", "curPzh=" + dw_hz.GetItemString(dw_hz.GetRow(), "pzh") + "&curFlag=SAVE_END&curLAST_SJC=XX");
                if (webReqTimestamp.StatusCode() == 200) {
                    //alert("时间戳已统一");
                }
                else {
                    requestor.MessageBox("提示(时间戳)", webReqTimestamp.ResponseText(), ICON.StopSign);
                }
            }
        }

        //释放对象
        dwc.Detach(); dwc = null;
    }
    //#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));
        sle_tmh.SetText(""); //清空条码号 
        var curAddMaxPzh = "";
        //执行保存的WebService  
        curBmbhAndBmmc = requestor.GetParm("curBmbhAndBmmc");

        if ((curBmbhAndBmmc.split("!!!")[0]).length > 0) {
            dw_mx_top.GetChild("bmbh", dwc);
            if (dwc.Find("bmbh='" + curBmbhAndBmmc.split("!!!")[0] + "'", 0, dwc.RowCount()) > 0) {
                dw_mx_top.SetItem(1, "bmbh", curBmbhAndBmmc.split("!!!")[0]);
                dw_mx_top.SetItem(1, "bmmc", curBmbhAndBmmc.split("!!!")[1]);
            }
        }
        var ywbh = requestor.GetParm("flag");
        webReq.Invoke("GetCaiGouDingDanMaxPzh", "curYwbh=" + ywbh + "&curBmbh=" + curBmbhAndBmmc.split("!!!")[0]);
        if (webReq.StatusCode() == 200) {
            curAddMaxPzh = webReq.ResponseText();
        } else {
            alert(webReq.ResponseText());
            return;
        }
        dw_mx_top.SetItem(1, "pzh", curAddMaxPzh);
        dw_mx_top.SetItem(1, "cgry", curYhbh);
        if (ywbh == "CZ" || ywbh == "CR") {
            dw_mx_top.SetItem(1, "cgfs", "7");
        }
        else if (ywbh == "CS" || ywbh == "CD" || ywbh == "CT") {
            dw_mx_top.SetItem(1, "cgfs", "5");
        }
        if (ywbh == "CR") {
            dw_mx_top.SetItem(1, "rkfs", "SHOUDAN");
        }

        if (flag == "CT") {
            dw_mx_top.SetItem(1, "rkfs", "TUIHUO");
            dw_mx_top.Modify("rkfs.protect='1'");
            // dw_mx.Modify("rkfs.protect='1'");
        }
        dw_mx.Reset();

        reCurBigMax = 1;
        self.SetEditMode("Add");
        dw_mx.InsertRow(0);
        isAdd = true;
        // 清空 审核章
        dw_mx_top.Modify("ysh_q_t.visible='0' ysh_t.visible='0' ysh_t.Text=''");
        //读取当地数据

        self.ClareKcAndCmzAll();
        dw_mx_top.Modify(" countsl.text='' ");
        //启用条码流水号，新增的时候把时间改变一下，修改的时候也改变一下，目的为了保证条码号对应的凭照的唯一。
        if (curSfqytmlsh == "1") {
            curSysteData = curSysteData + 1;
        }

        if (ControlDiscount(dw_mx, "CG") == "1") {
            curSetDisCount = 1;
        }
        if (curSetDisCount == 1) {
            em_1.SetEnabled(true);
        }
        else
        { em_1.SetEnabled(false); }
        tb_1.SetEnabled("ddlb_1", false);
        tb_1.SetEnabled("ddlb_2", 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_FAudit", false);
        //采购通知&采购退通知。
        if (ywbh == "CZ" || ywbh == "CD") {
            tb_1.SetText("ddlb_1", "全部")
            tb_1.SetEnabled("btn_Trans", false);
        } else {
            tb_1.SetText("ddlb_1", "未记账");

        }
        //新增的时候。初始化折扣卡=1
        openflag = "Add";
        em_1.SetText("1");
        if (ywbh == "CR" || ywbh == "CT") {
            dw_mx_top.SetItem(1, "TmSmFlag", "0");
            if (curSfqytmlsh == "1") {
                dw_mx_top.Modify("tmsmflag.visible='1' ");
                if (flag == "CT") {
                    dw_mx_top.Modify("rkfs.protect='0'");
                    dw_mx_top.GetChild("rkfs", dwc);
                    dwc.Reset();
                    var InsertRow = dwc.InsertRow();
                    dwc.SetItem(InsertRow, "csbh", "TUIHUO");
                    dwc.SetItem(InsertRow, "csmc", "退货");

                    InsertRow = dwc.InsertRow();
                    dwc.SetItem(InsertRow, "csbh", "DAIXIAO");
                    dwc.SetItem(InsertRow, "csmc", "代销");
                    curLastRkfs = "TUIHUO";
                }
                dw_mx.Modify("rkfs.protect='1'");

            }
            cb_sm.SetVisible(true);
        }


        dw_mx_top.Modify("bmbh.protect='0'");
        dw_mx_top.Modify("gysbh.protect='0'");

        dw_mx_top.Modify("rkfs.protect='0'");
    }
    this.sdSpxx = function () {
        if (requestor.GetParm("flag") == "CR" || requestor.GetParm("flag") == "CT") {
            var curLydh = dw_mx_top.GetItemString(1, "lydh");
            if (curSfqytmlsh == "1") {
                if (curLydh.substring(0, 2) == "SM") {
                    dw_mx.Modify("spkh.protect='1'");
                    dw_mx.Modify("ysbh.protect='1'");
                    dw_mx.Modify("bxbh.protect='1'");
                    dw_mx_top.Modify("bmbh.protect='1'");
                    dw_mx_top.Modify("gysbh.protect='1'");
                    for (var i = 1; i <= 35; i++) {
                        dw_mx.Modify("cm" + i + ".protect='1'");
                    }
                    tb_1.SetEnabled("btn_InsertRow", false);
                    tb_1.SetEnabled("btn_DeleteRow", false);
                    sle_tmh.SetVisible(false);
                    dw_mx_top.Modify("tmsmflag.visible='0' ");
                } else {
                 //   cb_sm.SetVisible(false);
                    dw_mx_top.Modify("tmsmflag.visible='1' ");
                }
            } else {
                dw_mx_top.Modify("tmsmflag.visible='0' ");
            }
        }
    }
    //#endregion   

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

        // var curGlobalCsbDw = window.external.Control("nvo");
        //  alert(curGlobalCsbDw.GetMachineKey());
        // curNvoScanMusic = requestor.Instance.Global.AppInfo;

        // var ts = requestor.Instance.Global.AppInfo;

        //  if (ts != null) {
        //       ts.A8erpPlayScanYes()
        //    }

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




    //#region this.InsertRow
    this.InsertRow = function () {

        if (requestor.GetParm("flag") == "CR" || requestor.GetParm("flag") == "CT") {
            if (curSfqytmlsh == "1" && GetXiTongCanShu("tmlshsdspxx", "xtcs", "qybz") == "1") {
                alert("启用录单禁止修改商品编号，不能手动新增");
                return;
            }
        }
        if (editMode == "")
            return;
        dw_mx.ScrollToRow(dw_mx.InsertRow(0));
        if (dw_mx.RowCount() > 1) {
            dw_mx.SetItem(dw_mx.GetRow(), "jj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "jj"));
            dw_mx.SetItem(dw_mx.GetRow(), "zkl", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "zkl"));
            dw_mx.SetItem(dw_mx.GetRow(), "lsj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "lsj"));
            dw_mx.SetItem(dw_mx.GetRow(), "dpj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "dpj"));
            dw_mx.SetItem(dw_mx.GetRow(), "ksmc", dw_mx.GetItemString(dw_mx.RowCount() - 1, "ksmc"));
            dw_mx.SetItem(dw_mx.GetRow(), "cmzbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "cmzbh"));
            dw_mx.SetItem(dw_mx.GetRow(), "jldw", dw_mx.GetItemString(dw_mx.RowCount() - 1, "jldw"));
            dw_mx.SetItem(dw_mx.GetRow(), "spkh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "spkh"));
        }

        dw_mx.SetColumn("spkh");
        dw_mx.SetFocus();
        dw_mx.ScrollFirstPage();
        dw_mx.ScrollToRow(dw_mx.RowCount());
        isFlag_NewRow = "Y"
    }
    //#endregion  

    //#region this.DeleteRow
    this.DeleteRow = function () {
        if (requestor.GetParm("flag") == "CR" || requestor.GetParm("flag") == "CT") {
            if (curSfqytmlsh == "1" && GetXiTongCanShu("tmlshsdspxx", "xtcs", "qybz") == "1") {
                alert("启用录单禁止修改商品编号，不能手动删除");
                return;
            }
        }
        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);

        curOldSpkh = "";
        curJsqYS = 0;  //计数器颜色
        curJsqBX = 0;  //计数器版型
        curSpkhYsbhBxbh = "";  //当前行的【款号+颜色+版型】
        curSpkhYsbhBxbhSFGetKCSL = "N"; //
        curRedCm = "";  //当前变红的列。


        dw_mx.SetFocus();

    }
    //#endregion  

    //#region this.Cancel
    this.Cancel = function () {
        //        if (requestor.MessageBox("提示Cancel", "数据还没有保存,是否继续取消?", ICON.Question, BUTTON.YesNo) == 2) {
        //            return 1;
        //        }
        var pzh = "";
        if (dw_mx_top.RowCount() > 0) {
            pzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
            dw_hz.RefreshDetails();
        }
        self.SetEditMode("");
        tab_1.SelectTab(1);
        tb_1.SetEnabled("ddlb_1", true);
        tb_1.SetEnabled("ddlb_2", 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);
        }
        if (flag == "CR" || flag == "CT") {
                cb_sm.SetVisible(false);
                sle_tmh.SetVisible(false);
        }
    }
    //#endregion  

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

        var row = dw_hz.GetRow();

        if (row <= 0)
            return;
        if (self.CheckJzbz()) {
            return;
        }
        if (self.CheckTrans()) {
            return;
        }
        //#region 处理时间戳，【判断是否被占用】---------------begin--------------
        webReqTimestamp.Invoke("YW_TIMESTAMP_REC", "curPzh=" + dw_hz.GetItemString(row, "pzh") + "&curFlag=OPEN&curLAST_SJC=XX");
        if (webReqTimestamp.StatusCode() == 200) {
            var resmsg = webReqTimestamp.ResponseText();

            if (resmsg.split("#")[0] == "N") {
                requestor.MessageBox("提示", "此单据正在被其他人打开,您不能打开。");
                return;
            } else {
                curSjc = resmsg.split("#")[1];
                dw_mx.Retrieve(dw_hz.GetItemString(dw_hz.GetRow(), "pzh"));
            }
        }
        else {
            requestor.MessageBox("提示(时间戳)", webReqTimestamp.ResponseText(), ICON.StopSign);
        }
        //#endregion 处理时间戳，【判断是否被占用】---------------end----------------
        webReq.Invoke("GetJJFS", "CusId=" + dw_hz.GetItemString(1, "gysbh"));
        if (webReq.StatusCode() == 200) {
            curJjfs = webReq.ResponseText();

        } else {
            alert(webReq.ResponseText());
            return;
        }
        dw_hz.ReSelectRow(row);
        dw_hz.RefreshDetails();
        self.SetEditMode("Edit");
        dw_1.Retrieve(dw_hz.GetItemString(dw_hz.GetRow(), "pzh"));
        if (dw_hz.RowCount() > 0) {
            dw_mx_top.Retrieve(dw_hz.GetItemString(dw_hz.GetRow(), "pzh"));

            dw_mx.Retrieve(dw_hz.GetItemString(dw_hz.GetRow(), "pzh"));


        }
        //启用条码流水号，新增的时候把时间改变一下，修改的时候也改变一下，目的为了保证条码号对应的凭照的唯一。
        if (curSfqytmlsh == "1") {
            curSysteData = curSysteData + 2;
        }
        self.GetMaxXh();
        tb_1.SetEnabled("ddlb_1", false);
        tb_1.SetEnabled("ddlb_2", false);
        tb_1.SetEnabled("btn_ChaXun", false);
        tb_1.SetEnabled("btn_Filter", false);
        tb_1.SetEnabled("btn_Export", false);

        if (ControlDiscount(dw_mx, "CG") == "1") {
            curSetDisCount = 1;
        }
        if (curSetDisCount == 1) {
            em_1.SetEnabled(true);
        }
        else
        { em_1.SetEnabled(false); }
        openflag = "Edit";
        //新增的时候。初始化折扣卡=0
        self.ClareKcAndCmzAll();
        em_1.SetText("1");
        self.GetSFYSGYSKCFlag();
        if (requestor.GetParm("flag") == "CR" || requestor.GetParm("flag") == "CT") {
            dw_mx_top.SetItem(1, "TmSmFlag", "0");
            if (curSfqytmlsh == "1") {
                if (flag == "CT") {
                    dw_mx_top.Modify("rkfs.protect='0'");
                    dw_mx.Modify("rkfs.protect='0'");
                    dw_mx_top.GetChild("rkfs", dwc);
                    dwc.Reset();
                    var InsertRow = dwc.InsertRow();
                    dwc.SetItem(InsertRow, "csbh", "TUIHUO");
                    dwc.SetItem(InsertRow, "csmc", "退货");

                    InsertRow = dwc.InsertRow();
                    dwc.SetItem(InsertRow, "csbh", "DAIXIAO");
                    dwc.SetItem(InsertRow, "csmc", "代销");

                        dw_mx_top.Modify("rkfs.protect='1'");
                        dw_mx.Modify("rkfs.protect='1'");
                        dw_mx.GetChild("rkfs", dwc);
                        var findRow = dwc.Find("csbh='DAIXIAO'", 1, dwc.RowCount());
                        if (findRow > 0) {
                            dwc.DeleteRow(findRow);
                        }
                        dw_mx_top.Modify("bmbh.protect='1'");
                        dw_mx_top.Modify("gysbh.protect='1'");
                }
               
            } else {
                if (flag == "CT") {
                    dw_mx_top.SetItem(1, "rkfs", "TUIHUO");
                    dw_mx_top.Modify("rkfs.protect='1'");
                    // dw_mx.Modify("rkfs.protect='1'");
                }
            }
            curTmlshDeleteTimestamp = new Date().getTime();
            cb_sm.SetVisible(true);
        }
       
        self.sdSpxx();
    }

    //#endregion  

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

        var row = dw_hz.GetRow();
        if (row <= 0)
            return;

        dw_hz.ReSelectRow(row);
        dw_hz.RefreshDetails();

        //        var status = dw_List.GetItemString(row, "Status");
        //        if (status != "录入") {
        //            requestor.MessageBox("提示", "当前订单的状态为<" + status + ">,不能被删除!", 1);
        //            return;
        //        }

        var curPzh = tab_Changed(tab_1, dw_hz, dw_mx_top);
        //var curPzh = dw_hz.GetItemString(row, "pzh");
        if (requestor.MessageBox("提示", "是否确定需要删除凭证号为<" + curPzh + ">的订单?", ICON.Question, BUTTON.YesNo) == 2)
            return;
        //#region 检查本单据是否已经记账，转单
        if (self.CheckJzbz()) {
            return;
        }
        if (self.CheckTrans()) {
            return;
        }
        //#endregion
        var tableNameHz = requestor.GetParm("tableNameHz");
        var tableNameMx = requestor.GetParm("tableNameMx");

        var Record = "删除: ";
        Record += dw_hz.GetItemString(row, "pzh");
        Record += "成功";

        webReq.Invoke("CaiGouDingDan_Delete", "curPzh=" + curPzh + "&tableNameHz=" + tableNameHz + "&tableNameMx=" + tableNameMx + "&curJzbz=" + dw_hz.GetItemString(dw_hz.GetRow(), "jzbz") + "&curRecord=" + Record + "&curId=" + curFunctionId);

        if (webReq.StatusCode() == 200) {
            // dw_hz.RowsDiscard(row, row, DWBUFFER.Primary);
            dw_hz.DeleteRow(row);
            requestor.MessageBox("提示", webReq.ResponseText());
            tab_1.SetSelectedTab(1);
            tb_1.SetEnabled("ddlb_1", true);
            tb_1.SetEnabled("ddlb_2", 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);
            }
            if (flag == "CR" || flag == "CT") {
                cb_sm.SetVisible(false);
                sle_tmh.SetVisible(false);
            }
        }
        else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
        }
    }

    //#endregion  

    //#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.Save 保存。。
    this.Save = function () {
        var flag = requestor.GetParm("flag");
        dw_mx_top.AcceptText();
        dw_mx.AcceptText();

        dw_mx_top.SetItem(1, "bmbh", dw_mx_top.GetItemString(1, "bmbh"));
        dw_mx_top.SetItem(1, "djlx", curDjlx);
        if ((dw_mx_top.ModifiedCount() + dw_mx.DeletedCount() + dw_mx.ModifiedCount()) <= 0) {
            alert("没有数据需要保存!");
            return;
        }
        if (!isAdd) {
            if (self.CheckJzbz()) {
                return;
            }
            if (self.CheckTrans()) {
                return;
            }
        }
        if (CheckJzbz(dw_mx_top.GetItemString(1, "pzh"),"yw_cg_rkdhz") != "Y") {
            alert("当前单据已记账!");
            return ;
        }
        var curCheckNullValue = "";
        var curCheckFuValue = "";
        for (row = dw_mx.RowCount(); row > 0; row--) {
            if (dw_mx.Describe("bxbh.visible") == "0") {
                dw_mx.SetItem(row, "bxbh", "-");
                dw_mx.SetItem(row, "bxmc", "-");
            }
            var curRkh = requestor.Trim(dw_mx.GetItemString(row, "spkh"));
            var curRysbh = requestor.Trim(dw_mx.GetItemString(row, "ysbh"));
            var curRyslsh = requestor.Trim(dw_mx.GetItemString(row, "yslsh"));
            var curRbxbh = requestor.Trim(dw_mx.GetItemString(row, "bxbh"));
            var curRspsl = dw_mx.GetItemNumber(row, "spsl");
            if (curRspsl == 0) {
                dw_mx.DeleteRow(row);
            } else {

                if (curRkh == "" || curRysbh == "" || curRyslsh == "" || curRbxbh == "") {
                    curCheckNullValue += "请检查第[" + row + "]行数据的款号，颜色或者版型输入是否正确" + ";\r\n";
                }
                if (flag == "CG") {
                    if (curDdYxfs != "1") {
                        for (col = 1; col <= curCmBtCols; col++) {
                            var cmValue = dw_mx.GetItemNumber(row, "cm" + col);
                            if (cmValue < 0) {
                                curCheckFuValue += "请检查第[" + row + "]行,第[" + col + "]列不能输入负数" + ";\r\n";
                            }
                        }
                    }
                } else {
                    for (col = 1; col <= curCmBtCols; col++) {
                        var cmValue = dw_mx.GetItemNumber(row, "cm" + col);
                        if (cmValue < 0) {
                            curCheckFuValue += "请检查第[" + row + "]行,第[" + col + "]列不能输入负数" + ";\r\n";
                        }
                    }
                }
            }
            if (isPast == "Y") {
                dw_mx.SetItem(row, "pzh", dw_mx.GetItemString(row, "pzh"));
            }

        }
        if (dw_mx.RowCount() < 1) {
            return;
        }
        dw_mx.SetItem(dw_mx.RowCount(), "cm35", dw_mx.GetItemNumber(dw_mx.RowCount(), "cm35"));
        if (curCheckNullValue.length > 0) {
            requestor.MessageBox("提示", curCheckNullValue.toString(), ICON.StopSign);
            return;
        }
        if (curCheckFuValue.length > 0) {
            requestor.MessageBox("提示", curCheckFuValue.toString(), ICON.StopSign);
            return;
        }
        var curPzh = dw_mx_top.GetItemString(1, "pzh");

        if (dw_mx.RowCount() == 0) {
            alert("无明细记录!");
            dw_mx.SetFocus();
            return;
        }
        //进行数据数据校验
        if (dw_mx_top.ModifiedCount() > 0 || dw_mx.GetItemString(dw_mx_top.GetRow(), "pzh") == "") {
            if (!dw_mx_top.CheckData("*", ""))
                return;
        }
        if (dw_mx.ModifiedCount() > 0) {
            if (!dw_mx.CheckData("*", ""))
                return;
        }


        var bmbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh");

        var tzrq = UtcDateTimeFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "kdrq"));
        dw_mx_top.SetItem(dw_mx_top.GetRow(), "kdrq", UtcDateFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "kdrq")));
        webReq1.Invoke("GetTallystatus", "bmbh=" + bmbh + "&tzrq=" + tzrq + "&flag=2");

        if (webReq1.StatusCode() == 200) {
            requestor.MessageBox("提示", "本部门库存已结转,不可保存！", ICON.StopSign);
            return;
        }

        dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "zsl"));
        dw_mx_top.SetItem(1, "zjje", dw_mx.GetItemNumber(1, "zje"));
        if (flag == "CR" || flag == "CT") {
            dw_mx_top.SetItem(1, "lsjze", dw_mx.GetItemNumber(1, "sum_lsjze"));
            if (curSFQY_CGYW_JJZE_SHURU == "1") {
                dw_mx_top.SetItem(1, "zjje", dw_mx.GetItemNumber(1, "sum_hjjze"));
            }
        }

        var dw_mx_top_data = dw_mx_top.GetChanges();
        var dw_mx_data = dw_mx.GetChanges();
        var mxFullState = dw_mx.GetFullState();
        if (dw_mx_top_data == "" && dw_mx_data == "")
            return;

        if (dw_mx.DeletedCount() > 0) {
            // alert("1删除" + dw_mx.DeletedCount() );
            var delmxdh = dw_mx.GetItemString(1, "mxdh", DWBUFFER.Delete);
            // alert("2删除" + dw_mx.DeletedCount() + "行数据" + "##" + delmxdh);
        }
        //#region 处理时间戳，【判断是否被占用】---------------begin--------------
        if (!isAdd) {
            webReqTimestamp.Invoke("YW_TIMESTAMP_REC", "curPzh=" + dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh") + "&curFlag=SAVE&curLAST_SJC=" + curSjc + "&times=" + new Date());
            if (webReqTimestamp.StatusCode() == 200) {
                var resmsg = webReqTimestamp.ResponseText();
                if (resmsg.split("#")[0] == "N") {
                    requestor.MessageBox("提示", "此单据正在被其他人保存,您不能保存。");
                    return;
                }
            }
            else {
                requestor.MessageBox("提示(时间戳)", webReqTimestamp.ResponseText(), ICON.StopSign);
            }
        }
        //#endregion 处理时间戳，【判断是否被占用】---------------end----------------

        //#region 写日志
        var hzrz = "";
        var mxrz = "";
        var curLogStr = "";
        //        if (openflag == "Add") {
        //            hzrz = A8erp_Common.WriteLog(dw_mx_top, openflag, "DB");
        //            mxrz = A8erp_Common.WriteLog(dw_mx, openflag, "DB");
        //            curLogStr = hzrz + mxrz;
        //        } else {
        //            hzrz = A8erp_Common.WriteLog(dw_mx_top, openflag); //A8erp_Common.
        //            mxrz = A8erp_Common.WriteLog(dw_mx, openflag, "DB", "dbmx", "spkh", "ksmc");
        //            curLogStr = "【凭证号：" + dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh") + "】" + hzrz + mxrz;
        //        }
        //#endregion
        //return;

        webReq.Invoke("CaiGouDingDan_Save", "dw_Master=" + dw_mx_top_data + "&dw_Detail=" + dw_mx_data + "&hzDwName=" + dw_mx_top.GetDataObject() + "&mxDwName=" + dw_mx.GetDataObject() + "&flag=" + flag + "&curOpenFlag=" + openflag + "&curId=" + curFunctionId + "&curLogStr=" + curLogStr + "&bfpzh=" + dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh") + "&isPast=" + isPast + "&mxFullState=" + mxFullState + "&curTmlshDeleteTimestamp=" + curTmlshDeleteTimestamp + "&curSysDate=" + curSysteData);

        if (webReq.StatusCode() == 200) {

            //服务器成功处理，返回单号
            var rPzh = webReq.ResponseText();
            //刷新 
            curFormPzh = "";
            //            if (isAdd) {
            //                dw_hz.RetrieveEx("a.pzh='" + rPzh + "'");
            //            } else {

            //            }
            if (flag == "CR") {
                webReq.Invoke("CaiGouDingDan_Save_Rkfs", "pzh=" + rPzh);
            }

            self.SelectionChanged();
            sle_Page.SetText(1);
            //找到相应的记录 
            dw_mx_top.Retrieve(rPzh);
            //dw_import_PL.ShareDataOff();
            dw_mx.Retrieve(rPzh);

            var findRow = dw_hz.Find("pzh='" + rPzh + "' ", 1, dw_hz.RowCount());
            if (findRow > 0) {
                dw_hz.ScrollToRow(findRow);
                self.SetEditMode("");
            } else {
                self.SelectionChanged_tab(rPzh);
            }


            curSaveReturnValue = "Y"
            if (zhengdanzhekouFlag == "N") {
                requestor.MessageBox("提示", "数据保存成功!", ICON.Information);
            }
            if (isAdd && isPast == "Y") {
                DELETE_PZH_TO_YW(curPzh);
                isAdd = false;
            }
            //删除临时保存文件
            self.DelFile();
            self.ClareKcAndCmzAll();
            dw_mx_top.SetFocus();
            //#region  审核的问题  dw_mkfhjb 

            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"));
                tb_1.SetEnabled("btn_Audit", true);
                tb_1.SetEnabled("btn_UnAudit", false);
                tb_1.SetEnabled("btn_FAudit", false);
                tb_1.SetEnabled("btn_Tally", false);
                tb_1.SetEnabled("btn_Delete", true);
                tb_1.SetEnabled("btn_Edit", true);
                tb_1.SetEnabled("btn_Save", false);
                tb_1.SetEnabled("btn_Trans", false);
                tb_1.SetEnabled("btn_Filter", true);
                tb_1.SetEnabled("btn_Export", true);
            }
            //#endregion           
            A8erp_Biz_Scan.Yw_Dw_Mx_ItemFocusChange(self, dw_mx, 1, "cm", "");
            //-------------每次保存完删除业务表临时凭证号对应数据--------
            if (flag == "CR" || flag == "CT") {
                cb_sm.SetVisible(false);
                sle_tmh.SetVisible(false);
            }
            isPast = "N";
            //-----------------------------------------------------------
        }
        else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
            dw_mx_top.SetFocus();
        }
        zhengdanzhekouFlag = "N";
    }
    //#endregion   

    //#region this.formartStr  
    this.formartStr = function (n) {

        var curN = n + "";
        var leftLength = 6 - (curN.length);
        var ret = "";
        for (var i = 1; i <= leftLength; i++) {
            ret = ret + "0";
        }
        return (ret + curN);
    }
    //#endregion  

    //#region 反审核
    this.FAudit = function () {
        if (editMode != "")
            return;

        //        var row = dw_hz.GetRow();
        //        if (row <= 0)
        //            return;

        //        dw_hz.ReSelectRow(row);
        //        dw_hz.RefreshDetails();

        var curPzh = tab_Changed(tab_1, dw_hz, dw_mx_top);
        //var curPzh = dw_hz.GetItemString(row, "pzh");
        if (requestor.MessageBox("提示", "是否确定反审核凭证号为<" + curPzh + ">的订单?", ICON.Question, BUTTON.YesNo) == 2)
            return;
        if (flag != "CG") {
            if (self.CheckJzbz()) {
                return;
            }
        }

        webReq.Invoke("CaiGouDingDan_FAudit", "curPzh=" + curPzh + "&curId=" + curFunctionId);
        if (webReq.StatusCode() == 200) {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.Information);
            //#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 {
                tab_1.SetSelectedTab(1);
                tb_1.SetEnabled("ddlb_1", true);
                tb_1.SetEnabled("ddlb_2", true);
                tb_1.SetEnabled("btn_ChaXun", true);
                tb_1.SetEnabled("btn_Filter", true);
                tb_1.SetEnabled("btn_Export", true);
                self.SelectionChanged_tab(curPzh);
                //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_Audit", true);
                tb_1.SetEnabled("btn_UnAudit", false);
                tb_1.SetEnabled("btn_FAudit", false);
                tb_1.SetEnabled("btn_Tally", false);
                tb_1.SetEnabled("btn_Delete", true);
                tb_1.SetEnabled("btn_Edit", true);
                tb_1.SetEnabled("btn_Save", false);
                tb_1.SetEnabled("btn_Trans", false);
            }
        }
        else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
        }
    }
    //#endregion
    // -------------------------------------------------dw_mx_top-------------------------------------begin------------

    //#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") {
                if (curSfqytmlsh == "1" && flag == "CT" &&  openflag == "Edit") {
                    return;
                }
                curW_OPEN_BMDA.SetDataWindow(dw_mx_top, "bmbh", "bmmc")  // 这个用来给子窗口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=cg"), curW_OPEN_BMDA, null);
                self.ClareKcAndCmzAll();
                self.dw_mx_top_itemChanged(dw_mx_top.GetRow(), "bmbh", dw_mx_top.GetItemString(1, "bmbh"));
            }
            if (dwoName == "gysbh") {
                if (curSfqytmlsh == "1" && flag == "CT" && openflag == "Edit") {
                    return;
                }
                curW_OPEN_BMDA.SetDataWindow(dw_mx_top, "gysbh", "gysmc", "M", 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=cg"), curW_OPEN_BMDA, null);
            }
        }
    }
    //#endregion 

    //#region this.dw_mx_top_editChanged  自动查供应商

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

        if (dwoName == "gysbh") {
            dw_mx_top.GetChild(dwoName, dwc);
            if (data != "") {
                dwc.Retrieve("%" + data + "%", curYhbh);
            }
            else {
                dwc.Retrieve("%", curYhbh);
            }
            //            if (flag == "CG" && DDYWGSYKCFlag == "1") {
            //                //
            //              //  self.GetSFYSGYSKCFlag();
            //            }
        } else if (dwoName == "bmbh") {

            dw_mx_top.GetChild(dwoName, dwc);
            if (data != "") {
                dwc.Retrieve("%" + data + "%", curYhbh, curQxlx);
            }
            else {
                dwc.Retrieve("%", curYhbh, curQxlx);
            }
            //            if (flag == "CG" && DDYWGSYKCFlag == "1") {
            //                //
            //               // self.GetSFYSGYSKCFlag();
            //            }

        } else if (dwoName == "cgry") {
            dw_mx_top.GetChild(dwoName, dwc);
            if (data != "") {
                dwc.Retrieve("%" + data + "%", curYhbh, "cg");
            }
            else {
                dwc.Retrieve("%", curYhbh, "cg");
            }
        }
    }
    //#endregion 

    //#region this.dw_mx_top_itemChanged  检查供应商数据完整性
    var curLastBmbh = "";
    var curLastGysbh = "";
    var curLastRkfs = "";
    this.dw_mx_top_itemChanged = function (row, dwoName, data) {
        dw_mx_top.AcceptText();
        var gysbh = dw_mx_top.GetItemString(row, "gysbh");
        var bmbh = dw_mx_top.GetItemString(row, "bmbh");
        var rkfs = "";
        if (flag == "CT" || flag == "CR") {
            rkfs = dw_mx_top.GetItemString(row, "rkfs");
        }
        if (dwoName == "gysbh") {
            if (gysbh == bmbh) {
                requestor.MessageBox("提示", "部门和供应商不可相同！", ICON.Information);
                dw_mx_top.SetItem(row, dwoName, curLastGysbh);
                return 1;
            }
            dw_mx_top.GetChild(dwoName, dwc);
            dwc.Retrieve("%", curYhbh);
            var findRow = dwc.Find("UPPER(gysbh)=UPPER('" + data + "') ", 1, dwc.RowCount());
            if (findRow <= 0) {
                requestor.MessageBox("提示", "未找到供应商编号为==[" + data + "]的记录，请检查!", ICON.StopSign);
                dw_mx_top.SetItemNull(row, dwoName);
                dwc.Retrieve("%", curYhbh);
                return 1;
            } else {
                dw_mx_top.SetItem(row, "gysmc", dwc.GetItemString(findRow, "gysmc"));
            }
            webReq.Invoke("GetJJFS", "CusId=" + data);
            if (webReq.StatusCode() == 200) {
                curJjfs = webReq.ResponseText();
            } else {
                alert(webReq.ResponseText());
                return;
            }
            var curHaveMx = "N";
            dw_mx.AcceptText();
            for (row = 1; row <= dw_mx.RowCount(); row++) {
                var curRkh = requestor.Trim(dw_mx.GetItemString(row, "spkh"));
                if (curRkh.length > 0) {
                    curHaveMx = "Y";
                    break;
                } else {
                    continue;
                }
            }
            if (curHaveMx == "Y" && editMode != "") {
                if (!confirm("切换供应商会清空已录入的数据，您确定要继续吗？")) {
                    if (flag == "CT" && curSfqytmlsh == "1") {
                        dw_mx_top.SetItem(row, dwoName, curLastGysbh);
                    }
                    return 1;
                }
                for (var i = 1; i <= dw_mx.RowCount(); i++) {

                    for (row = dw_mx.RowCount(); row > 0; row--) {
                        dw_mx.DeleteRow(row);
                    }
                    dw_mx.ScrollToRow(dw_mx.InsertRow(0));
                    dw_mx.SetColumn("spkh");
                    dw_mx.SetFocus();
                }
                self.DeleteAllTmlsh();
            }

            if (flag == "CG" && DDYWGSYKCFlag == "1") {
                //
                self.GetSFYSGYSKCFlag();
            }
            curLastGysbh = gysbh;
        } else if (dwoName == "bmbh") {
            if (gysbh == bmbh) {
                requestor.MessageBox("提示", "部门和供应商不可相同！", ICON.Information);
                dw_mx_top.SetItem(row, dwoName, curLastBmbh);
                return 1;
            }
            if (flag == "CT" && curSfqytmlsh == "1") {
                var curHaveMx = "N";
                dw_mx.AcceptText();
                for (r = 1; r <= dw_mx.RowCount(); r++) {
                    var curRkh = requestor.Trim(dw_mx.GetItemString(r, "spkh"));
                    if (curRkh.length > 0) {
                        curHaveMx = "Y";
                        break;
                    } else {
                        continue;
                    }
                }
                if (curHaveMx == "Y" && editMode != "") {
                    if (!confirm("切换部门会清空已录入的数据，您确定要继续吗？")) {
                        dw_mx_top.SetItem(row, dwoName, curLastBmbh);
                        return 1;
                    }
                    for (var i = 1; i <= dw_mx.RowCount(); i++) {

                        for (ow = dw_mx.RowCount(); ow > 0; ow--) {
                            dw_mx.DeleteRow(ow);
                        }
                        dw_mx.ScrollToRow(dw_mx.InsertRow(0));
                        dw_mx.SetColumn("spkh");
                        dw_mx.SetFocus();
                    }
                    self.DeleteAllTmlsh();
                }
            }
            dw_mx_top.GetChild(dwoName, dwc);
            dwc.Retrieve("%", curYhbh, curQxlx);
            var findRow = dwc.Find("UPPER(bmbh)=UPPER('" + data + "') ", 1, dwc.RowCount());
            if (findRow <= 0) {
                requestor.MessageBox("提示", "未找到部门编号为1111[" + data + "]的记录，请检查!", ICON.StopSign);
                dw_mx_top.SetItemNull(row, dwoName);
                dwc.Retrieve("%", curYhbh, curQxlx);
                return 1;
            } else {
                dw_mx_top.SetItem(row, "bmmc", dwc.GetItemString(findRow, "bmmc"));

                //#region 加载买断商品

                if (curMDSPFlag == "1" && flag == "CT") {
                    dw_mdsp_list.RetrieveEx("bmbh='" + data + "'");
                }

                if (flag == "CG" && DDYWGSYKCFlag == "1") {
                    //
                    self.GetSFYSGYSKCFlag();
                }
                //#endregion
            }
            curLastBmbh = bmbh;
            self.ClareKcAndCmzAll();
        } else if (dwoName == "cgry") {
            dw_mx_top.GetChild(dwoName, dwc);
            var findRow = dwc.Find("ygbh='" + data + "' ", 1, dwc.RowCount());
            if (findRow <= 0) {
                requestor.MessageBox("提示", "未找到采购员编号为[" + data + "]的记录，请检查!", ICON.StopSign);
                dw_mx_top.SetItemNull(row, dwoName);
                dwc.Retrieve("%", curYhbh, "cg");
                return 1;
            }
        } else if (dwoName == "rkfs") {
            if (curSfqytmlsh == "1" && flag == "CT") {
                var curHaveMx = "N";
                dw_mx.AcceptText();
                for (r = 1; r <= dw_mx.RowCount(); r++) {
                    var curRkh = requestor.Trim(dw_mx.GetItemString(r, "spkh"));
                    if (curRkh.length > 0) {
                        curHaveMx = "Y";
                        break;
                    } else {
                        continue;
                    }
                }
                if (curHaveMx == "Y" && editMode != "") {
                    if (!confirm("切换入库方式会清空已录入的数据，您确定要继续吗？")) {
                        dw_mx_top.SetItem(row, "rkfs", curLastRkfs);
                        return 1;
                    }
                    for (var i = 1; i <= dw_mx.RowCount(); i++) {

                        for (ro = dw_mx.RowCount(); ro > 0; ro--) {
                            dw_mx.DeleteRow(ro);
                        }
                        dw_mx.ScrollToRow(dw_mx.InsertRow(0));
                        dw_mx.SetColumn("spkh");
                        dw_mx.SetFocus();
                    }
                    self.DeleteAllTmlsh();
                }
            } else if (flag == "CR") {
                dw_mx_top.AcceptText();
                var rkfs = dw_mx_top.GetItemString(1, "rkfs");
                for (var i = 1; i <= dw_mx.RowCount(); i++) {
                    dw_mx.SetItem(i, "rkfs", rkfs);
                }
            }
            curLastRkfs = rkfs;

        }

    }
    //#endregion

    this.DeleteAllTmlsh = function () {
        if (curSfqytmlsh == "1" && (flag == "CT" || flag == "CR")) {
            webReqTimestamp.Invoke("TMJL_DELETE", "tableName=da_xt_print_tmlsh_cg&pzh=" + dw_mx_top.GetItemString(1, "pzh") + "&flag=ALL&curTmlshDeleteTimestamp=" + curTmlshDeleteTimestamp + "&curSysDate=" + curSysteData + "&tmh=1&openflag=1");
            curSysteData = curSysteData + 5;
        }
    }
    //#region this.dw_mx_top_keyDown  如果是在最后一行的金额列按回车，则自动增加一行

    this.dw_mx_top_keyDown = function (keyCode, keyFlags) {
        if (keyCode == 13 && dw_mx_top.GetColumnName() == "bzxx") {
            if (dw_mx_top.GetItemString(1, "bmbh") == "") {

                alert("请先选订货择部门1!");
                dw_mx_top.SetColumn("bmbh");
                dw_mx_top.SetFocus();
                return;
            }
            if (dw_mx.RowCount()>0&& dw_mx.GetItemString(1, "spkh") != "") {
                dw_mx.ScrollToRow(dw_mx.InsertRow(0));
                dw_mx.SetColumn("spkh");
                dw_mx.SetFocus();
            } else {
                dw_mx.ScrollToRow(1);
                dw_mx.SetColumn("spkh");
                dw_mx.SetFocus();
            }
            return 1;
        }
    }
    //#endregion 

    //#region this.sle_tmh_Modified  条码录入
    this.sle_tmh_Modified = function (key) {

        var txt = sle_tmh.GetText().toUpperCase();
        if (txt.length < 1) {
            sle_tmh.SetText("");
            sle_tmh.SetFocus();
            return 1;
        }
        if (key != 13) {
            return;
        }
        if (!G_bEditFlag) {
            alert("请先单击修改！");
            return;
        }
        var curBmbh = dw_mx_top.GetItemString("1", "bmbh");
        var curGysbh = dw_mx_top.GetItemString("1", "gysbh");
        var curJqlb = dw_tmjqfs.GetItemString(1, "csbh");    // 截取方式
        //var curStartString = dw_tmjqfs.GetItemString(1, "bzxx"); // 截取范围

        if (curBmbh.length < 1) {
            alert("请输入订货部门");
            return;
        }
        if (curGysbh.length < 1) {
            alert("请检查客户");
            return;
        }
        if (curJjfs.length < 1) {
            alert("请检查计价方式");
            return;
        }
        if (curQjfs.length < 1) {
            alert("请检查取价方式");
            return;
        }
        var ls_tmh = "";
        ls_tmh = sle_tmh.GetText().toUpperCase()
        // 扫描方式：配置包条码
        if (curTmlrms == "PZBTM") {
            dw_pzbtm.Retrieve(txt);
            for (var i = 1; i <= dw_pzbtm.RowCount(); i++) {
                ls_tmh = dw_pzbtm.GetItemString(i, "tmh");
                //                // 条码不能为空
                if (ls_tmh.length < 1) {
                    alert("输入的条码不存在，请重新输入！");
                    sle_tmh.SetText("");
                    sle_tmh.SetFocus();
                    return 1;
                }
                dw_ddmx_top_tmlr.Retrieve(ls_tmh, curGysbh, "CG", curJjfs, curQjfs);
                if (dw_ddmx_top_tmlr.RowCount() == 0) {

                    alert("输入的条码不存在，请重新输入！");
                    sle_tmh.SetText("");
                    sle_tmh.SetFocus();
                    return 1;
                }

                // 取尺码点亮信息
                var curChangecolor = dw_ddmx_top_tmlr.GetItemString(1, "changecolor");
                var mdf = new Array();
                if (i == dw_pzbtm.RowCount()) {
                    for (var r = 0; r < curCmBtRows1; r++) {
                        for (var k = 1; k < curCmBtCols1; k++) {
                            if (r == 0) {
                                dw_mx.Modify(" cm" + k + "_t.color='33554432'  cm" + k + "_t.Font.Weight='400'  "); // 行变粗，蓝色 
                            } else {
                                dw_mx.Modify(" cm" + k + "0" + r + "_t.color='33554432'  cm" + k + "0" + r + "_t.Font.Weight='400' "); // 行变粗，蓝色
                            }
                        }
                    }
                }

                if (curChangecolor.length > 0) {
                    var rowsNo = curChangecolor.split("#")[0];    //选中行
                    var rowsScope = curChangecolor.split("#")[1]; //尺码范围   
                    var beginNo = rowsScope.split(",")[0];        //范围是从0开始的
                    var endNo = rowsScope.split(",")[1];
                    beginNo = parseInt(beginNo) - 1;
                    endNo = parseInt(endNo) - 1;
                    var curBeg = parseInt(beginNo) + 1;          // 范围是从0开始的，尺码+1.
                    var curEnd = parseInt(endNo) + 1;
                    var curCurCmbh = dw_ddmx_top_tmlr.GetItemString(1, "cmbh"); //当前扫描的尺码编号
                    var curColNo = 0;
                    var curCmzHaveDm = curChangecolor.split("#")[2].split(","); //尺码组中对应的代码
                    for (var y = 0; y < curCmzHaveDm.length; y++) {
                        if (curCurCmbh == curCmzHaveDm[y]) {
                            curColNo = y;
                            break;
                        }
                    }
                    curColNo += curBeg;
                    curSaoMiaoLie = "cm" + curColNo;
                    // 取尺码当前列ID
                    if (i == dw_pzbtm.RowCount()) {
                        if (rowsNo > 1) {// 第一行 
                            for (var a = curBeg; a <= curEnd; a++) { //循环咧        
                                if (a == curColNo) {// 当前点亮的列
                                    dw_mx.Modify(" cm" + a + "0" + parseInt(rowsNo - 1) + "_t.color='255'  cm" + a + "0" + parseInt(rowsNo - 1) + "_t.Font.Weight='700'  "); // 变红色
                                } else {
                                    dw_mx.Modify(" cm" + a + "0" + parseInt(rowsNo - 1) + "_t.color='16711680'  cm" + a + "0" + parseInt(rowsNo - 1) + "_t.Font.Weight='700'  "); // 变蓝色
                                }
                            }
                        } else {
                            for (var a = curBeg; a <= curEnd; a++) { //循环咧     
                                if (a == curColNo) {// 当前点亮的列
                                    dw_mx.Modify(" cm" + a + "_t.color='255' cm" + a + "_t.Font.Weight='700' "); // 变红色
                                } else {
                                    dw_mx.Modify(" cm" + a + "_t.color='16711680' cm" + a + "_t.Font.Weight='700' "); // 变蓝色
                                }
                            }
                        }
                    }
                }
                // 检查是否已经存在款号-------begin----

                var tmSpkh = dw_ddmx_top_tmlr.GetItemString(1, "spkh");
                var tmYslsh = dw_ddmx_top_tmlr.GetItemString(1, "yslsh");
                var tmBxbh = dw_ddmx_top_tmlr.GetItemString(1, "bxbh");


                if (flag == "CT" && curMDSPFlag == "1") {
                    var tempfilter = "";
                    tempfilter = "UPPER(bmbh)=UPPER('" + dw_mx_top.GetItemString(1, "bmbh") + "') and UPPER(spkh)=UPPER('" + tmSpkh + "') and UPPER(ysbh)=UPPER('" + tmYsbh + "') and UPPER(bxbh)=UPPER('" + tmBxbh + "')"
                    dw_mdsp_list.SetFilter(tempfilter);
                    dw_mdsp_list.Filter();
                    if (dw_mdsp_list.RowCount() > 0) {
                        dw_mdsp_list.SetFilter("");
                        dw_mdsp_list.Filter();
                        if (requestor.MessageBox("提示", "该商品已买断，是否继续录入?", ICON.Question, BUTTON.YesNo, 2) == 2) {
                            sle_tmh.SetText("");
                            return;
                        }
                    }
                }

                var mxFindRow = dw_mx.Find("spkh='" + tmSpkh + "' and yslsh='" + tmYslsh + "' and bxbh='" + tmBxbh + "'", 1, dw_mx.RowCount());
                if (mxFindRow > 0) { // 该款该色已存在，只需要改变数量
                    dw_mx.ScrollToRow(mxFindRow);
                    var curCmSl = dw_mx.GetItemNumber(mxFindRow, curSaoMiaoLie);
                    dw_mx.SetItem(mxFindRow, curSaoMiaoLie, parseInt(curCmSl) + dw_pzbtm.GetItemNumber(i, "sl"));
                    dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zsl") + "' ");
                    dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "zsl"));
                } else {           // 该款该色不存在，新增行 
                    if (dw_mx.RowCount() > 0) {
                        if (dw_mx.GetItemNumber(dw_mx.GetRow(), "zsl") == 0) {
                            dw_mx.DeleteRow(dw_mx.GetRow());
                        }
                    }
                    dw_mx.ScrollToRow(dw_mx.InsertRow(0));
                    var newRow = dw_mx.RowCount();
                    dw_mx.SetItem(newRow, "spkh", dw_ddmx_top_tmlr.GetItemString(1, "spkh"));
                    dw_mx.SetItem(newRow, "ksmc", dw_ddmx_top_tmlr.GetItemString(1, "ksmc"));
                    dw_mx.SetItem(newRow, "yslsh", dw_ddmx_top_tmlr.GetItemString(1, "yslsh"));
                    dw_mx.SetItem(newRow, "ysbh", dw_ddmx_top_tmlr.GetItemString(1, "ysbh"));
                    dw_mx.SetItem(newRow, "ysmc", dw_ddmx_top_tmlr.GetItemString(1, "ysmc"));
                    dw_mx.SetItem(newRow, "jldw", dw_ddmx_top_tmlr.GetItemString(1, "jldw"));
                    dw_mx.SetItem(newRow, "bxbh", dw_ddmx_top_tmlr.GetItemString(1, "bxbh"));
                    dw_mx.SetItem(newRow, "bxmc", dw_ddmx_top_tmlr.GetItemString(1, "bxmc"));
                    dw_mx.SetItem(newRow, "jj", dw_ddmx_top_tmlr.GetItemNumber(1, "jhjg"));
                    dw_mx.SetItem(newRow, "dpj", dw_ddmx_top_tmlr.GetItemNumber(1, "dpjg"));
                    dw_mx.SetItem(newRow, "lsj", dw_ddmx_top_tmlr.GetItemNumber(1, "lsjg"));
                    if (curQjfs == "QDPJ") {
                        if (dw_ddmx_top_tmlr.GetItemNumber(1, "dpjg") == 0)
                            dw_mx.SetItem(newRow, "zkl", 1);
                        else
                            dw_mx.SetItem(newRow, "zkl", dw_ddmx_top_tmlr.GetItemNumber(1, "jhjg") / dw_ddmx_top_tmlr.GetItemNumber(1, "dpjg"));
                    }
                    if (curQjfs == "QLSJ") {
                        if (dw_ddmx_top_tmlr.GetItemNumber(1, "lsjg") == 0)
                            dw_mx.SetItem(newRow, "zkl", 1);
                        else
                            dw_mx.SetItem(newRow, "zkl", dw_ddmx_top_tmlr.GetItemNumber(1, "jhjg") / dw_ddmx_top_tmlr.GetItemNumber(1, "lsjg"));
                    }

                    dw_mx.SetItem(newRow, "cmzbh", dw_ddmx_top_tmlr.GetItemString(1, "cmzbm"));
                    dw_mx.SetItem(newRow, curSaoMiaoLie, dw_pzbtm.GetItemNumber(i, "sl"));
                    dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zsl") + "' ");
                    dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "zsl"));
                    if (flag == "CT") {
                        dw_mx.SetItem(newRow, "rkfs", "TUIHUO");
                    }
                    if (flag == "CR") {
                        var rkfs = CheckGysdaYfhmx(dw_mx_top.GetItemString(1, "bmbh"), dw_mx_top.GetItemString(1, "gysbh"), dw_ddmx_top_tmlr.GetItemString(1, "spkh"), dw_ddmx_top_tmlr.GetItemString(1, "ysbh"));
                        dw_mx.SetItem(newRow, "rkfs", rkfs)
                    }

                }
            }
            sle_tmh.SetText("");
            sle_tmh.SetFocus();
            return 1;
        } else {


            curSmKcFlag = "Y";
            if (curJjfs == "CS03") {

                if (flag == "CR" || flag == "CT") {
                    dw_ddmx_top_tmlr.Retrieve(ls_tmh, curGysbh, "CG", curJjfs + "#" + dw_mx_top.GetItemString(1, "bmbh"), curQjfs);
                }
                else {
                    dw_ddmx_top_tmlr.Retrieve(ls_tmh, curGysbh, "CG", curJjfs, curQjfs);
                }
            }
            else {
                dw_ddmx_top_tmlr.Retrieve(ls_tmh, curGysbh, "CG", curJjfs, curQjfs);
            }

            dw_ddmx_top_tmlr.Retrieve(ls_tmh, curGysbh, "CG", curJjfs, curQjfs);
            if (dw_ddmx_top_tmlr.RowCount() == 0) {
                AutoPlayerVideoByPb(requestor, "N");
                alert("输入的条码不存在，请重新输入！");
                self.Myfocus();
                return -1;
            }
            var curRfidFlag = "";
            if (ls_tmh.substring(0, curCompanyidLength) == curCompanyid) {
                curRfidFlag = "Y";
            }
            if (curRfidFlag == "Y") {
                curJqlb = "3";
            } else {
                var pptmfa = CSTMFA(ls_tmh);
                if (pptmfa == "Y") {//Y品牌条码右截取
                    curJqlb = "3"; //系统条码右截取
                } else if (pptmfa != "Y") {
                    curJqlb = "30"; //30无意义，只要不等于3就行
                }
            }
            if (curSfqytmlsh == "1" && flag == "CT" && curJqlb != "3" && dw_mx_top.GetItemString(dw_mx_top.GetRow(), "rkfs") == "DAIXIAO") {
                alert("代销退货必须输入条码流水号");
                self.Myfocus();
                return -1;
            }
            //#region 取尺码点亮信息
            var curChangecolor = dw_ddmx_top_tmlr.GetItemString(1, "changecolor");
            var mdf = new Array();
            for (var r = 0; r < curCmBtRows1; r++) {
                for (var k = 1; k < curCmBtCols1; k++) {
                    if (r == 0) {
                        dw_mx.Modify(" cm" + k + "_t.color='33554432'  cm" + k + "_t.Font.Weight='400'  "); // 行变粗，蓝色 
                    } else {
                        dw_mx.Modify(" cm" + k + "0" + r + "_t.color='33554432'  cm" + k + "0" + r + "_t.Font.Weight='400' "); // 行变粗，蓝色
                    }
                }
            }
            if (curChangecolor.length > 0) {
                var rowsNo = curChangecolor.split("#")[0];    //选中行
                var rowsScope = curChangecolor.split("#")[1]; //尺码范围   
                var beginNo = rowsScope.split(",")[0];        //范围是从0开始的
                var endNo = rowsScope.split(",")[1];
                beginNo = parseInt(beginNo) - 1;
                endNo = parseInt(endNo) - 1;
                var curBeg = parseInt(beginNo) + 1;          // 范围是从0开始的，尺码+1.
                var curEnd = parseInt(endNo) + 1;
                var curCurCmbh = dw_ddmx_top_tmlr.GetItemString(1, "cmbh"); //当前扫描的尺码编号
                var curColNo = 0;
                var curCmzHaveDm = curChangecolor.split("#")[2].split(","); //尺码组中对应的代码
                for (var y = 0; y < curCmzHaveDm.length; y++) {
                    if (curCurCmbh == curCmzHaveDm[y]) {
                        curColNo = y;
                        break;
                    }
                }
                curColNo += curBeg;
                curSaoMiaoLie = "cm" + curColNo;
                // 取尺码当前列ID
                if (rowsNo > 1) {// 第一行 
                    for (var a = curBeg; a <= curEnd; a++) { //循环咧        
                        if (a == curColNo) {// 当前点亮的列
                            dw_mx.Modify(" cm" + a + "0" + parseInt(rowsNo - 1) + "_t.color='255'  cm" + a + "0" + parseInt(rowsNo - 1) + "_t.Font.Weight='700'  "); // 变红色
                        } else {
                            dw_mx.Modify(" cm" + a + "0" + parseInt(rowsNo - 1) + "_t.color='16711680'  cm" + a + "0" + parseInt(rowsNo - 1) + "_t.Font.Weight='700'  "); // 变蓝色
                        }
                    }
                } else {
                    for (var a = curBeg; a <= curEnd; a++) { //循环咧     
                        if (a == curColNo) {// 当前点亮的列
                            dw_mx.Modify(" cm" + a + "_t.color='255' cm" + a + "_t.Font.Weight='700' "); // 变红色
                        } else {
                            dw_mx.Modify(" cm" + a + "_t.color='16711680' cm" + a + "_t.Font.Weight='700' "); // 变蓝色
                        }
                    }
                }
            }
            //#endregion 取尺码点亮信息
            // 检查是否已经存在款号-------begin----

            var tmSpkh = dw_ddmx_top_tmlr.GetItemString(1, "spkh");
            var tmYslsh = dw_ddmx_top_tmlr.GetItemString(1, "yslsh");
            var tmBxbh = dw_ddmx_top_tmlr.GetItemString(1, "bxbh");
            var mxFindRow = dw_mx.Find("spkh='" + tmSpkh + "' and yslsh='" + tmYslsh + "' and bxbh='" + tmBxbh + "'", 1, dw_mx.RowCount());
            if ((flag == "CS" || flag == "CD") && dw_mx_top.GetItemString(1, "deletetm") == "1") {
                if (mxFindRow > 0) {
                    var curCmSl = dw_mx.GetItemNumber(mxFindRow, curSaoMiaoLie);
                    if (curCmSl > 0) {
                        dw_mx.SetItem(mxFindRow, curSaoMiaoLie, parseInt(curCmSl) - 1);
                        dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zsl") + "' ");
                        dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "zsl"));
                        if (dw_mx.GetItemNumber(mxFindRow, "spsl") < 1) {
                            dw_mx.DeleteRow(mxFindRow);
                        }
                    } else {
                        alert("条码号【" + ls_tmh + "】未在本单录入！");
                    }
                } else {
                    alert("条码号【" + ls_tmh + "】未在本单录入！");
                }
                self.Myfocus();
                return 1;
            }
            //#region 条码删除
            if (flag == "CR" || flag == "CT") {
                if (dw_mx_top.GetItemString(1, "TmSmFlag") == "1") {
                    if (mxFindRow > 0) {
                        if (curSfqytmlsh == "1" && (curJqlb == "3" || curRfidFlag == "Y")) {
                            webReqTimestamp.Invoke("TMJL_DELETE", "tableName=da_xt_print_tmlsh_cg&pzh=" + dw_mx_top.GetItemString(1, "pzh") + "&tmh=" + ls_tmh + "&openflag=" + openflag + "&curTmlshDeleteTimestamp=" + curTmlshDeleteTimestamp + "&curSysDate=" + curSysteData);
                            if (webReqTimestamp.StatusCode() == 200) {
                                var curCmSl = dw_mx.GetItemNumber(mxFindRow, curSaoMiaoLie);
                                dw_mx.SetItem(mxFindRow, curSaoMiaoLie, parseInt(curCmSl) - 1);
                                dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zsl") + "' ");
                                dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "zsl"));
                                if (dw_mx.GetItemNumber(mxFindRow, "spsl") < 1) {
                                    dw_mx.DeleteRow(mxFindRow);
                                }
                                alert("删除成功");
                            } else {
                                alert("条码号【" + ls_tmh + "】未在本单录入1！");
                            }

                        } else {
                            alert("条码号【" + ls_tmh + "】未在本单录入2！");
                        }
                    } else {
                        alert("条码号【" + ls_tmh + "】未在本单录入3！");
                    }
                    self.Myfocus();
                    return 1;
                }
            }
            //#endregion

            if (curSfqytmlsh == "1" && (curJqlb == "3" || curRfidFlag == "Y")) {
                webReqTimestamp.Invoke("CheckTmlsh", "curTableName=da_xt_print_tmlsh_cg&curPzh=" + dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh") + "&curTmlsh=" + ls_tmh + "&sjc=" + curSysteData + "&curTmlshDeleteTimestamp=" + curTmlshDeleteTimestamp);
                if (webReqTimestamp.StatusCode() != 200) {
                    alert("该条码流水号已经扫描过,请勿重复扫描。");
                    self.Myfocus();
                    return 1;     //判断是否能扫描存在改记录不能扫描
                }
            }
            var CT_RKFS = "TUIHUO";
            //#region CT验证发货类型
            if (curSfqytmlsh == "1" && (curJqlb == "3" || curRfidFlag == "Y") && flag == "CT") {
                var checkRkfs = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "rkfs");
                webReqTimestamp.Invoke("CheckTmlshFhlx", "ywlx=CT&bmbh=" + curGysbh + "&khbh=" + curBmbh + "&dxFlag=" + dw_mx_top.GetItemString(dw_mx_top.GetRow(), "rkfs") + "&tmh=" + ls_tmh + "&spkh=" + tmSpkh + "&yslsh=" + tmYslsh + "&ysbh=" + dw_ddmx_top_tmlr.GetItemString(1, "ysbh") + "&bxbh=" + tmBxbh);
                var curStr = webReqTimestamp.ResponseText();
                if (curStr.split("#")[0] == "Y") {
                    if (checkRkfs == "DAIXIAO") {
                        CT_RKFS = "DAIXIAO";
                        dw_ddmx_top_tmlr.SetItem(1, "jhjg", curStr.split("#")[1]);
                    }
                } else if (curStr.split("#")[0] == "E") {
                    alert(curStr.split("#")[1]);
                    self.Myfocus();
                    return 1;
                } else if (curStr.split("#")[0] == "N") {
                    if (requestor.MessageBox("提示", curStr.split("#")[1], ICON.Question, BUTTON.YesNo) == 2) {
                        return 1;
                    }
                }
            }
            //#endregion
            if (mxFindRow > 0) { // 该款该色已存在，只需要改变数量



                dw_mx.ScrollToRow(mxFindRow);
                var curCmSl = dw_mx.GetItemNumber(mxFindRow, curSaoMiaoLie);
                dw_mx.SetItem(mxFindRow, curSaoMiaoLie, parseInt(curCmSl) + 1);
                dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zsl") + "' ");
                dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "zsl"));
            } else {           // 该款该色不存在，新增行
                if (dw_mx.RowCount() > 0) {
                    if (dw_mx.GetItemNumber(dw_mx.GetRow(), "zsl") == 0) {
                        dw_mx.DeleteRow(dw_mx.GetRow());
                    }
                }
                dw_mx.ScrollToRow(dw_mx.InsertRow(0));
                var newRow = dw_mx.RowCount();
                dw_mx.SetItem(newRow, "spkh", dw_ddmx_top_tmlr.GetItemString(1, "spkh"));
                dw_mx.SetItem(newRow, "ksmc", dw_ddmx_top_tmlr.GetItemString(1, "ksmc"));
                dw_mx.SetItem(newRow, "yslsh", dw_ddmx_top_tmlr.GetItemString(1, "yslsh"));
                dw_mx.SetItem(newRow, "ysbh", dw_ddmx_top_tmlr.GetItemString(1, "ysbh"));
                dw_mx.SetItem(newRow, "ysmc", dw_ddmx_top_tmlr.GetItemString(1, "ysmc"));
                dw_mx.SetItem(newRow, "jldw", dw_ddmx_top_tmlr.GetItemString(1, "jldw"));
                dw_mx.SetItem(newRow, "bxbh", dw_ddmx_top_tmlr.GetItemString(1, "bxbh"));
                dw_mx.SetItem(newRow, "bxmc", dw_ddmx_top_tmlr.GetItemString(1, "bxmc"));
                dw_mx.SetItem(newRow, "jj", dw_ddmx_top_tmlr.GetItemNumber(1, "jhjg"));
                dw_mx.SetItem(newRow, "lsj", dw_ddmx_top_tmlr.GetItemNumber(1, "lsjg"));
                dw_mx.SetItem(newRow, "dpj", dw_ddmx_top_tmlr.GetItemNumber(1, "dpjg"));
                if (flag == "CT") {
                    dw_mx.SetItem(newRow, "rkfs", CT_RKFS);
                }
                if (flag == "CR") {
                    var rkfs = CheckGysdaYfhmx(dw_mx_top.GetItemString(1, "bmbh"), dw_mx_top.GetItemString(1, "gysbh"), dw_ddmx_top_tmlr.GetItemString(1, "spkh"), dw_ddmx_top_tmlr.GetItemString(1, "ysbh"));
                    dw_mx.SetItem(newRow, "rkfs", rkfs)
                }

                if (curQjfs == "QDPJ") {
                    if (dw_ddmx_top_tmlr.GetItemNumber(1, "dpjg") == 0)
                        dw_mx.SetItem(newRow, "zkl", 1);
                    else
                        dw_mx.SetItem(newRow, "zkl", dw_ddmx_top_tmlr.GetItemNumber(1, "jhjg") / dw_ddmx_top_tmlr.GetItemNumber(1, "dpjg"));
                }
                if (curQjfs == "QLSJ") {
                    if (dw_ddmx_top_tmlr.GetItemNumber(1, "lsjg") == 0)
                        dw_mx.SetItem(newRow, "zkl", 1);
                    else
                        dw_mx.SetItem(newRow, "zkl", dw_ddmx_top_tmlr.GetItemNumber(1, "jhjg") / dw_ddmx_top_tmlr.GetItemNumber(1, "lsjg"));
                }
                //获取行供应商
                if (curJjfs == "CS03") {

                    if (flag == "CR" || flag == "CT") {


                        dw_ls_flda.Retrieve(dw_ddmx_top_tmlr.GetItemString(1, "spkh"), dw_mx_top.GetItemString(1, "gysbh"), "cg", curJjfs + "#" + dw_mx_top.GetItemString(1, "bmbh"), curQjfs);
                    }
                    else {
                        dw_ls_flda.Retrieve(dw_ddmx_top_tmlr.GetItemString(1, "spkh"), dw_mx_top.GetItemString(1, "gysbh"), "cg", curJjfs + "#" + dw_mx_top.GetItemString(1, "bmbh"), curQjfs); //FLDA 
                    }

                }
                else {
                    dw_ls_flda.Retrieve(dw_ddmx_top_tmlr.GetItemString(1, "spkh"), dw_mx_top.GetItemString(1, "gysbh"), "cg", curJjfs + "#" + dw_mx_top.GetItemString(1, "bmbh"), curQjfs); //FLDA 
                }
                if (requestor.GetParm("flag") == "CT" || requestor.GetParm("flag") == "CR") {
                    dw_mx.SetItem(newRow, "hgys", dw_ls_flda.GetItemString(1, "gysbh"));
                    dw_mx.SetItem(newRow, "hgysmc", dw_ls_flda.GetItemString(1, "gysmc"));
                    dw_mx.SetItem(newRow, "jypp", dw_ls_flda.GetItemString(1, "jypp"));
                    dw_mx.SetItem(newRow, "ppmc", dw_ls_flda.GetItemString(1, "ppmc"));
                    dw_mx.SetItem(newRow, "hplb", dw_ls_flda.GetItemString(1, "hplb"));
                    dw_mx.SetItem(newRow, "lbmc", dw_ls_flda.GetItemString(1, "lbmc"));
                }


                //获取行供应商
                dw_mx.SetItem(newRow, "cmzbh", dw_ddmx_top_tmlr.GetItemString(1, "cmzbm"));
                dw_mx.SetItem(newRow, curSaoMiaoLie, 1);
                dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zsl") + "' ");
                dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "zsl"));
            }



            dw_ls_flda.Retrieve(tmSpkh, curGysbh, "CG", curJjfs, curQjfs); //FLDA 
            // 处理库存的问题 --------begin-------
            self.setKCSL("", "", "", "", "");
            // 处理库存的问题 --------end---------

            curSftmsl = "Y";

            self.dw_mx_itemChanged(dw_mx.GetRow(), curSaoMiaoLie, dw_mx.GetItemNumber(dw_mx.GetRow(), curSaoMiaoLie))
            //#region 插入条码纪录表 

            if ((flag == "CR" || flag == "CT") && curSmKcFlag == "Y") {

                if (curSfqytmlsh == "1" && curJqlb == "3") {
                    var tmbcRow = 0;
                    if (dw_tmbc.RowCount() > 0) {
                        tmbcRow = 1;
                    }
                    else {
                        tmbcRow = dw_tmbc.InsertRow();
                    }
                    dw_tmbc.SetItem(tmbcRow, "tmlsh", ls_tmh);
                    if (curRfidFlag == "Y") {
                        dw_tmbc.SetItem(tmbcRow, "tmh", ls_tmh);
                        dw_tmbc.SetItem(tmbcRow, "lsh", ls_tmh);
                    } else {
                        dw_tmbc.SetItem(tmbcRow, "tmh", ls_tmh.substring(0, ls_tmh.length - CSTMFAJQWS(ls_tmh)));
                        dw_tmbc.SetItem(tmbcRow, "lsh", ls_tmh.substring(ls_tmh.length - CSTMFAJQWS(txt), ls_tmh.length));
                    }
                    dw_tmbc.SetItem(tmbcRow, "spkh", dw_ddmx_top_tmlr.GetItemString(1, "spkh"));
                    dw_tmbc.SetItem(tmbcRow, "ysbh", dw_ddmx_top_tmlr.GetItemString(1, "ysbh"));
                    dw_tmbc.SetItem(tmbcRow, "bxbh", dw_ddmx_top_tmlr.GetItemString(1, "bxbh"));
                    dw_tmbc.SetItem(tmbcRow, "cmbh", curCurCmbh);
                    dw_tmbc.SetItem(tmbcRow, "spbh", dw_ddmx_top_tmlr.GetItemString(1, "spkh") + dw_ddmx_top_tmlr.GetItemString(1, "ysbh") + dw_ddmx_top_tmlr.GetItemString(1, "bxbh") + curCurCmbh);
                    dw_tmbc.SetItem(tmbcRow, "bmbh", dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh"));
                    dw_tmbc.SetItem(tmbcRow, "gysbh", curGysbh);
                    dw_tmbc.SetItem(tmbcRow, "pzh", dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh"));
                    dw_tmbc.SetItem(tmbcRow, "sjc", curSysteData);
                    webReqTimestamp.Invoke("TMJL_SAVE", "dwObject=da_xt_print_yw_tmh_cg_save&dwChange=" + dw_tmbc.GetChanges() + "tzrq=" + new Date());
                    if (webReqTimestamp.StatusCode() == 200) {
                        //alert("222")
                    } else {
                        requestor.MessageBox("提示33", "条码纪录保存失败", ICON.StopSign);
                        self.Myfocus();
                        return 1;
                    }
                }
            }
            //#endregion

            AutoPlayerVideoByPb(requestor, "Y");
            self.fhjl();
            if (cueSmzt == "0") {
                self.Myfocus();
                return -1;
            } else {
                self.SetMyFocus();
                return 1;
            }
            // 检查是否已经存在款号--------end-----
        }
    }
    //#endregion

    //#region this.em_zdzk 计算折扣
    this.em_zdzk = function (key) {
        if (CheckJzbz(dw_mx_top.GetItemString(1, "pzh"), "yw_cg_rkdhz") != "Y") {
            alert("当前单据已记账!");
            return ;
        }
        var row = dw_mx.RowCount();
        var zkl = parseFloat(em_1.GetText());

        if (key == 13) {
            if (row == 0) {
                alert("请先输入明细!");
                dw_mx.SetFocus();
                return;
            }

            //获取单据号


            var curZkl = em_1.GetText();
            if (curZkl.length > 1) {
                zhengdanzhekouFlag = "Y"
                self.Save();
                if (curSaveReturnValue == "N") {
                    requestor.MessageBox("提示", "整单折扣修改失败1！", ICON.StopSign);
                    return;
                }
                dw_mx_top.AcceptText();
                var curPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
                webReq.Invoke("Batch_Edit_ZDZK", "curPzh=" + curPzh + "&curZkl=" + curZkl);
                if (webReq.StatusCode() == 200) {
                    dw_mx.Retrieve(curPzh);
                    requestor.MessageBox("提示", "数据保存成功!", ICON.Information);
                }
                else {
                    requestor.MessageBox("提示", "整单折扣修改失败！", ICON.StopSign);
                }
            }

        }
    }
    //#endregion

    //#region 选择品牌条码截取方案
    this.sle_tmh_Double_PinPai = function (f, x, y) {

        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(dw_mx_top, "ppbh", "ppmc", "M", self, "Y")  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=dw_da_sp_pptmfa_list&selectStyle="), curW_OPEN_SIMPLE_CHOSE, null);

    }
    this.SetPPTMFAValue = function (v) {
        sle_pptmfa_Value.SetText(v);
    }
    //#endregion

    // -------------------------------------------------dw_mx_top-------------------------------------end--------------

    //--------------------------------------------------右键功能--------------------------------------begin------------

    //#region this.QZXG(强制修改)
    this.QZXG = function () {

        if (dw_hz.GetRow() < 1) {
            return;
        }

        var jzbz = dw_hz.GetItemString(dw_hz.GetRow(), "jzbz");
        var fhjb = dw_hz.GetItemString(dw_hz.GetRow(), "fhjb");

        if (fhjb == "T") {
            requestor.MessageBox("提示", "该单据已审核，不能被强制修改！", ICON.StopSign);
            return;
        }
        if (jzbz == "1") {
            requestor.MessageBox("提示", "该单据已记账，不能被强制修改！", ICON.StopSign);
            return;
        }
        var pzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh")
        webReqTimestamp.Invoke("YW_TIMESTAMP_REC", "curPzh=" + dw_hz.GetItemString(dw_hz.GetRow(), "pzh") + "&curFlag=QZXG&curLAST_SJC=XX");
        if (webReqTimestamp.StatusCode() == 200) {
            //    self.SelectionChanged();
            var findRow = dw_hz.Find("pzh='" + pzh + "'", 1, dw_hz.RowCount());
            //dw_hz.Refresh();
            dw_hz.ScrollToRow(findRow);
            self.SetEditMode("");
            tab_1.SelectTab(1);
        }
        else {
            requestor.MessageBox("提示(时间戳)", webReqTimestamp.ResponseText(), ICON.StopSign);
        }
    }
    //#endregion

    //#region 单据复制
    this.DateCopy = function () {
        if (curSFQYSJKZQ == "1") {
            var curPzh = dw_mx_top.GetItemString(1, "pzh");

            if (dw_mx.RowCount() < 1) {
                requestor.MessageBox("提示", "无数据可复制！", ICON.Information);
                return;
            }

            FUN_COPY_TO_PAST(curPzh, "COPY", "", "");

        } else {
            if (dw_mx.RowCount() < 1) {
                requestor.MessageBox("提示", "无数据可复制！", ICON.Information);
                return;
            }
            requestor.ShowLoading("复制中......请勿关闭程序。");
            curDw.Retrieve();
            var row = 0;
            for (var i = 1; i <= dw_mx.RowCount(); i++) {
                if (i == 1) {
                    row = 1;
                } else {
                    row = curDw.InsertRow(0);
                    curDw.ScrollToRow(row);
                }
                curDw.SetItem(row, "spkh", dw_mx.GetItemString(i, "spkh"));
                curDw.SetItem(row, "ksmc", dw_mx.GetItemString(i, "ksmc"));
                curDw.SetItem(row, "ysbh", dw_mx.GetItemString(i, "ysbh"));
                curDw.SetItem(row, "ysmc", dw_mx.GetItemString(i, "ysmc"));
                curDw.SetItem(row, "bxbh", dw_mx.GetItemString(i, "bxbh"));
                curDw.SetItem(row, "bxmc", dw_mx.GetItemString(i, "bxmc"));
                curDw.SetItem(row, "jldw", dw_mx.GetItemString(i, "jldw"));
                curDw.SetItem(row, "yslsh", dw_mx.GetItemString(i, "yslsh"));
                curDw.SetItem(row, "spsl", dw_mx.GetItemNumber(i, "spsl"));
                for (var k = 1; k < curCmBtCols1; k++) {
                    curDw.SetItem(row, "cm" + k, dw_mx.GetItemNumber(i, "cm" + k));
                }
            }
            requestor.CloseLoading();
            curDw.AcceptText();
        }
    }
    //#endregion

    //#region 单据粘贴
    this.DatePast = function () {
        if (CheckJzbz(dw_mx_top.GetItemString(1, "pzh"), "yw_cg_rkdhz") != "Y") {
            alert("当前单据已记账!");
            return ;
        }
        if (requestor.GetParm("flag") == "CR" || requestor.GetParm("flag") == "CT") {
            if (curSfqytmlsh == "1") {
                var curLydh = dw_mx_top.GetItemString(1, "lydh");
                if (curLydh.substring(0, 2) == "SM") {
                    if (dw_mx.RowCount() > 0 && dw_mx.GetItemString(1, "spkh") != "") {
                        alert("本单是纵向扫描，不可粘贴。");
                        return;
                    }
                }
            }
        }
        var flag = requestor.GetParm("flag");
        if (curSFQYSJKZQ == "1") {
            if (editMode == "Add") {
                var curPzh = dw_mx_top.GetItemString(1, "pzh");
                var curKhbh = dw_mx_top.GetItemString(1, "bmbh");
                var curBmbh = dw_mx_top.GetItemString(1, "gysbh");

                //执行保存的WebService  


                var maseege = FUN_COPY_TO_PAST(curPzh, "PAST", curKhbh, curBmbh);
                if (maseege == "Y") {
                    dw_mx.Retrieve(curPzh);
                    isPast = "Y"
                    self.Save();
                    // dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zsl") + "' ");
                }
                else {
                    requestor.MessageBox("粘贴失败", maseege.split("#")[1], ICON.Information);
                    isPast = "N"
                    return;

                }
            }
        } else {
            if (curDw.RowCount() < 1) {
                requestor.MessageBox("提示", "无数据可粘贴！", ICON.Information);
                return;
            }
            if (!curDw.GetItemString(1, "spkh").length > 0) {
                requestor.MessageBox("提示", "无数据可粘贴！", ICON.Information);
                return;
            }
            requestor.ShowLoading("复制中......请勿关闭程序。");
            var row = 0;
            for (var i = 1; i <= curDw.RowCount(); i++) {


                row = dw_mx.InsertRow(0);
                dw_mx.ScrollToRow(row);
                dw_mx.SetItem(row, "spkh", curDw.GetItemString(i, "spkh"));
                dw_mx.SetItem(row, "ksmc", curDw.GetItemString(i, "ksmc"));
                dw_mx.SetItem(row, "ysbh", curDw.GetItemString(i, "ysbh"));
                dw_mx.SetItem(row, "ysmc", curDw.GetItemString(i, "ysmc"));
                dw_mx.SetItem(row, "bxbh", curDw.GetItemString(i, "bxbh"));
                dw_mx.SetItem(row, "bxmc", curDw.GetItemString(i, "bxmc"));
                dw_mx.SetItem(row, "jldw", curDw.GetItemString(i, "jldw"));
                dw_mx.SetItem(row, "yslsh", curDw.GetItemString(i, "yslsh"));


                if (flag == "CR") {
                    var rkfs = CheckGysdaYfhmx(dw_mx_top.GetItemString(1, "bmbh"), dw_mx_top.GetItemString(1, "gysbh"), curDw.GetItemString(i, "spkh"), curDw.GetItemString(i, "ysbh"));
                    dw_mx.SetItem(row, "rkfs", rkfs)
                }
                if (flag == "CT") {
                    dw_mx.SetItem(row, "rkfs", "TUIHUO");
                }

                dw_mx.GetChild("spkh", dwc);
                dwc.SetFilter(" spkh='" + dw_mx.GetItemString(dw_mx.GetRow(), "spkh") + "'");
                dwc.Filter();
                if (dwc.RowCount() > 0) {
                    if (flag == "CR" || flag == "CT") {
                        dw_mx.SetItem(row, "gysmc", dwc.GetItemString(1, "gysmc"));
                    }
                }

                for (var k = 1; k < curCmBtCols1; k++) {
                    dw_mx.SetItem(row, "cm" + k, curDw.GetItemNumber(i, "cm" + k));

                }
                //区域价格
                dw_ls_flda.Retrieve(curDw.GetItemString(i, "spkh"), dw_mx_top.GetItemString(1, "gysbh"), "cg", curJjfs, curQjfs); //FLDA 
                dw_mx.SetItem(row, "jj", dw_ls_flda.GetItemNumber(1, "jhjg"));
                dw_mx.SetItem(row, "lsj", dw_ls_flda.GetItemNumber(1, "lsjg"));
                dw_mx.SetItem(row, "dpj", dw_ls_flda.GetItemNumber(1, "dpjg"));
                if (curQjfs == "QDPJ") {

                    if (dw_ls_flda.GetItemNumber(1, "dpjg") == "0") {
                        dw_mx.SetItem(row, "zkl", 1);
                    }
                    else {
                        dw_mx.SetItem(row, "zkl", dw_ls_flda.GetItemNumber(1, "jhjg") / dw_ls_flda.GetItemNumber(1, "dpjg"));
                    }
                }
                else {
                    if (dw_ls_flda.GetItemNumber(1, "lsjg") == "0") {
                        dw_mx.SetItem(row, "zkl", 1);
                    }
                    else {
                        dw_mx.SetItem(row, "zkl", dw_ls_flda.GetItemNumber(1, "jhjg") / dw_ls_flda.GetItemNumber(1, "lsjg"));
                    }
                }

                dw_mx.SetItem(row, "cmzbh", dw_ls_flda.GetItemString(1, "cmzbm"));
                if (flag == "CR" || flag == "CT") {
                    dw_mx.SetItem(row, "hjjze", dw_ls_flda.GetItemNumber(1, "jhjg") * dw_mx.GetItemNumber(row, "spsl"));
                }
                dw_mx.SetItem(row, "yslsh", curDw.GetItemString(i, "yslsh"));
            }
            if (dw_mx.RowCount() > 0) {
                dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zsl") + "' ");
                dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "zsl"));
            } else {
                dw_mx_top.Modify(" countsl.text='0' ");
                dw_mx_top.SetItem(1, "zjsl", 0);
            }
            // curDw.Reset()
            requestor.CloseLoading();
        }
    }


    this.ExportExcel = function () {

        dw_mx.Export();
    }


    var curFlag = "";
    var curTbflag = "";
    //#region 导入返回后的处理
    this.GetRetVFlag = function (str1, str2) {

        self.SelectionChanged();
        dw_mx_top.Retrieve(str2);
        dw_mx.Retrieve(str2);
        var findRow = dw_hz.Find("pzh='" + str2 + "' ", 1, dw_hz.RowCount());

        if (findRow > 0) {
            dw_hz.ScrollToRow(findRow);
            self.SetEditMode("");
        } else {
            self.SelectionChanged_tab(str2);
        }
        dw_mx_top.SetFocus();
        if (dw_mx.RowCount() > 0) {
            dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zsl") + "' ");
        } else {
            dw_mx_top.Modify(" countsl.text='0' ");
        }
        //#region  审核的问题  dw_mkfhjb
        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"));
            tb_1.SetEnabled("btn_Audit", true);
            tb_1.SetEnabled("btn_UnAudit", false);
            tb_1.SetEnabled("btn_FAudit", false);
            tb_1.SetEnabled("btn_Tally", false);
            tb_1.SetEnabled("btn_Delete", true);
            tb_1.SetEnabled("btn_Edit", true);
            tb_1.SetEnabled("btn_Save", false);
            tb_1.SetEnabled("btn_Trans", false);
            tb_1.SetEnabled("btn_Filter", true);
            tb_1.SetEnabled("btn_Export", true);
            tb_1.SetEnabled("btn_InsertRow", false);
            tb_1.SetEnabled("btn_DeleteRow", false);
        }
        //#endregion 
    }
    //#endregion 
    //#region EXCEL数据导入
    this.ImporExcel = function () {

        //跳转页面
        dw_mx_top.AcceptText();
        var curgysbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "gysbh");
        if (curgysbh.length < 1) {
            alert("供应商编号不能为空");
            return;
        }

        var curbmbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh");
        if (curbmbh.length < 1) {
            alert("部门编号不能为空");
            return;
        }

        var currq = UtcDateFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "kdrq"));
        if (currq.length < 1) {
            alert("日期不能为空");
            return;
        }

        var currkfs = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "cgfs");
        if (currkfs.length < 1) {
            alert("采购方式不能为空");
            return;
        }


        cur_W_HYHKDR.SetDataWindow(W_Main, self)
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.import.W_HYHKDR&FunctionID=" + curFunctionId + "&gysbh=" + curgysbh + "&bmbh=" + curbmbh + "&rkfs=" + currkfs + "&kdrq=" + currq), cur_W_HYHKDR, null);
        return
    }
    //#endregion 

    //#region TXT数据导入
    this.ImporTxt = function () {



        //跳转页面
        dw_mx_top.AcceptText();
        var curgysbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "gysbh");
        if (curgysbh.length < 1) {
            alert("供应商编号不能为空");
            return;
        }

        var curbmbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh");
        if (curbmbh.length < 1) {
            alert("部门编号不能为空");
            return;
        }

        var currq = UtcDateFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "kdrq"));
        if (currq.length < 1) {
            alert("日期不能为空");
            return;
        }

        var currkfs = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "cgfs");
        if (currkfs.length < 1) {
            alert("采购方式不能为空");
            return;
        }

        var curPpfa = sle_pptmfa_Value.GetText();
        cur_W_TXTDR.SetDataWindow(W_Main, self)
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.import.W_TXTDR&FunctionID=" + curFunctionId + "&gysbh=" + curgysbh + "&bmbh=" + curbmbh + "&rkfs=" + currkfs + "&kdrq=" + currq + "&pptmfa=" + curPpfa), cur_W_TXTDR, null);
        return
    }
    //#endregion 


    //#region 数据导入检查
    this.ImporExcelCheck = function (xlsSheet) {

        dw_ysbx.Retrieve();
        var rowIndex_check = parseFloat(requestor.GetParm("RowAndCol").split("@")[0]) + 2;
        var tempspkh = Trim(xlsSheet.Cells(rowIndex_check, 2).Text);
        while (tempspkh.length > 0 && tempspkh != "合计：") {
            var tempysbh = Trim(xlsSheet.Cells(rowIndex_check, 4).Text);
            //alert(["xxxx", tempspkh,tempysbh])
            dw_ls_flda.Retrieve(tempspkh, dw_mx_top.GetItemString(1, "gysbh"), "cg", curJjfs, curQjfs); //FLDA
            if (dw_ls_flda.RowCount() < 1) {
                var editrow = dw_error_list.InsertRow(dw_error_list.RowCount() + 1);
                dw_error_list.SetItem(dw_error_list.RowCount(), "hanghao", rowIndex_check);
                dw_error_list.SetItem(dw_error_list.RowCount(), "msg", "款号【" + tempspkh + "】不存在！");

            }
            if (bxshow == "0") {
                dw_ysbx.SetFilter(" spkh='" + tempspkh + "' and ysbh='" + tempysbh + "'");
                dw_ysbx.Filter();
                if (dw_ysbx.RowCount() < 1) {
                    var editrow = dw_error_list.InsertRow(dw_error_list.RowCount() + 1);
                    dw_error_list.SetItem(dw_error_list.RowCount(), "hanghao", rowIndex_check);
                    //dw_error_list.SetItem(dw_error_list.RowCount(), "cdbh", "SJ5555");
                    dw_error_list.SetItem(dw_error_list.RowCount(), "msg", "款号【" + tempspkh + "】的颜色【" + tempysbh + "】不存在！");

                }
                dw_ysbx.SetFilter("");
                dw_ysbx.Filter();
            }
            if (bxshow == "1") {
                var tempbxbh = Trim(xlsSheet.Cells(rowIndex_check, 6).Text);
                dw_ysbx.SetFilter(" spkh='" + tempspkh + "' and ysbh='" + tempysbh + "' and bxbh='" + tempbxbh + "'");
                dw_ysbx.Filter()
                if (dw_ysbx.RowCount() < 1) {
                    var editrow = dw_error_list.InsertRow(dw_error_list.RowCount() + 1);
                    dw_error_list.SetItem(dw_error_list.RowCount(), "hanghao", rowIndex_check);
                    //dw_error_list.SetItem(dw_error_list.RowCount(), "cdbh", "SJ5555");
                    dw_error_list.SetItem(dw_error_list.RowCount(), "msg", "款号【" + tempspkh + "】的颜色【" + tempysbh + "】或版型【" + tempbxbh + "】不存在!");
                }
                dw_ysbx.SetFilter("");
                dw_ysbx.Filter();
            }
            rowIndex_check++;
            tempspkh = Trim(xlsSheet.Cells(rowIndex_check, 2).Text);

        }



    }
    //#endregion 
    //--------------------------------------------------右键功能---------------------------------------end-------------

    //#region this.RFC_LiShiBaoCun行失去焦点对画面进行零时保存
    this.RFC_LiShiBaoCun = function () {

        return;
        if (dw_mx.RowCount() <= 0) {
            //数据窗口无数据时退出
            return;
        }

        try {

            //临时保存导出目录
            var mfile = "C:\\Documents and Settings\\All Users\\Application Data\\ExtPB.Net\\125\\Exp";
            var fso = new ActiveXObject("Scripting.FileSystemObject");
            //如果创建不了 1执行regsvr32 scrrun.dll这个，2修改ie设置对未标记安全的Activex脚本启用

            if (!fso.FolderExists(mfile)) {
                //判断并创建目录
                fso.CreateFolder(mfile);
            }

            var fldr = fso.GetFolder(mfile);
            var filesEnum = new Enumerator(fldr.files);
            //遍历Exp目录下所有文件
            while (!filesEnum.atEnd()) {
                var fileObj, fileName = "";
                fileObj = filesEnum.item();
                fileName = fileObj.Name.toString();
                if (fileName.indexOf(dw_mx.GetStringData2()) >= 0) {
                    //删除文件
                    fso.DeleteFile(mfile + "\\" + fileName);
                }

                filesEnum.moveNext();
            }

            //获得当前时间
            var Day_Now = new Date();
            var m = Day_Now.getMonth() + 1;
            m = m > 9 ? m : '0' + m;
            var mydate = Day_Now.getYear().toString() + m.toString() + Day_Now.getDate().toString() + Day_Now.getHours().toString() + Day_Now.getMinutes().toString() + Day_Now.getSeconds().toString();
            //获得画面名称
            var Arrwin = new Array;
            Arrwin = requestor.GetName().split(".");
            var winname = Arrwin[Arrwin.length - 1].toString();
            //获取用户id
            var id = requestor.GetParm("curUserId");

            //画面数据临时保存
            dw_mx_top.SaveAs(mfile + "\\" + id + "_" + winname + "_" + dw_mx_top.GetName() + "_" + mydate + ".txt", SAVEASTYPE.Text, false, 3);

            dw_mx.SaveAs(mfile + "\\" + id + "_" + winname + "_" + dw_mx.GetName() + "_" + mydate + ".txt", SAVEASTYPE.Text, false, 3);




        }
        catch (e) {
            //            alert(e.ToString());
            return;
        }

    }
    //#endregion 

    //#region 临时保存
    this.Page2Open = function () {
        return;
        try {
            //临时保存导出目录
            var mfile = "C:\\Documents and Settings\\All Users\\Application Data\\ExtPB.Net\\125\\Exp";
            var fso = new ActiveXObject("Scripting.FileSystemObject");
            var fldr = fso.GetFolder(mfile);
            var filesEnum = new Enumerator(fldr.files);

            var top_fileName = "";
            var mx_fileName = "";
            //获得画面名称
            var Arrwin = new Array;
            Arrwin = requestor.GetName().split(".");
            var winname = Arrwin[Arrwin.length - 1].toString();
            //获取用户id
            var id = requestor.GetParm("id");

            //遍历Exp目录下所有文件
            while (!filesEnum.atEnd()) {
                var fileObj, fileName = "";
                fileObj = filesEnum.item();
                fileName = fileObj.Name.toString();
                if (fileName.indexOf(id + "_" + winname) >= 0) {
                    if (fileName.indexOf("top") >= 0) {
                        top_fileName = fileName;
                    }
                    if (fileName.indexOf("mx") >= 0) {
                        mx_fileName = fileName;
                    }
                }

                filesEnum.moveNext();
            }
            if (top_fileName != "" || mx_fileName != "") {
                if (confirm("有未保存的单据需要导入嘛？")) {
                    if (top_fileName != "") {
                        dw_mx_top.ImportFile(mfile + "\\" + top_fileName);
                    }
                    if (mx_fileName != "") {
                        dw_mx.ImportFile(mfile + "\\" + mx_fileName);
                    }
                }
            }

        }
        catch (e) {
            //            alert(e.ToString());
            return;
        }
    }
    //#endregion

    //#region this.DelFile 
    this.DelFile = function () {

        try {

            //临时保存导出目录
            var mfile = "C:\\Documents and Settings\\All Users\\Application Data\\ExtPB.Net\\125\\Exp";
            var fso = new ActiveXObject("Scripting.FileSystemObject");
            var fldr = fso.GetFolder(mfile);
            var filesEnum = new Enumerator(fldr.files);

            //获得画面名称
            var Arrwin = new Array;
            Arrwin = requestor.GetName().split(".");
            var winname = Arrwin[Arrwin.length - 1].toString();
            //获取用户id
            var id = requestor.GetParm("id");

            //遍历Exp目录下所有文件
            while (!filesEnum.atEnd()) {
                var fileObj, fileName = "";
                fileObj = filesEnum.item();
                fileName = fileObj.Name.toString();
                if (fileName.indexOf(id + "_" + winname) >= 0) {
                    //删除文件
                    fso.DeleteFile(mfile + "\\" + fileName);
                }

                filesEnum.moveNext();
            }

        }
        catch (e) {
            //            alert(e.ToString());
            return;
        }

    }
    //#endregion

    //#region 审核
    this.Audit = function () {
        var curShjb = "F";
        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;
        }
        if (self.CheckJzbz()) {
            return;
        }

        var curFhjb = dw_hz.GetItemString(dw_hz.GetRow(), "fhjb"); // 当前
        var curFhjbStr = self.GetAuditStatus(curFhjb);
        var curToFhjb = curFhjbStr.split("#")[0];
        var curToShowName = dw_mkfhjb.GetItemString(curFhjbStr.split("#")[1], "fhmc");
        webReq.Invoke("CaiGouDingDan_Audit", "curPzh=" + pzh + "&curShjb=" + curToFhjb + "&curId=" + curFunctionId);
        if (webReq.StatusCode() == 200) {
            requestor.MessageBox("提示", "审核成功", ICON.Information);
            //#region 刷新汇总表
            //            dw_hz.SetRedraw(false);
            //            dw_hz.SetProcessing(true);

            //刷新
            //            dw_hz.Retrieve(curDjlx, curYhbh, ddlb_1.GetText());
            // self.SelectionChanged(dw_hz.GetPageIndex());
            if (dw_hz.RowCount() == 0) {
                self.SetButtomStatus();
                return;
            }
            self.SelectionChanged();
            //找到相应的记录
            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) {

            //                var curNextFhjbStr = self.GetAuditStatus(curToFhjb);
            //                var curToButtonShowName = dw_mkfhjb.GetItemString(curFhjbStr.split("#")[1], "dygn");
            //                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("ddlb_2", true);
                tb_1.SetEnabled("btn_ChaXun", true);
                tb_1.SetEnabled("btn_Filter", true);
                tb_1.SetEnabled("btn_Export", true);
            }
        } else {
            requestor.MessageBox("提示", "审核失败！", ICON.StopSign);
        }
    }
    //#endregion

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

        var pzh = tab_Changed(tab_1, dw_hz, dw_mx_top);
        //var pzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
        if (pzh.length < 1) {
            alert("凭证号异常");
            return;
        }
        if (!confirm("您确定要退审凭证号为[" + pzh + "]的单据吗？")) {
            return;
        }
        if (flag == "CZ" || flag == "CD") {
            var sql = "select 1 from yw_cg_rkdhz where lydh='" + pzh + "'";
            SQL_Dw.Retrieve(sql);
            if (SQL_Dw.RowCount() > 0) {
                requestor.MessageBox("提示", "该单据已转单，不可退审！", ICON.Information);
                return;
            }
        } else {
            if (self.CheckJzbz()) {
                return;
            }
        }

        webReq.Invoke("CaiGouDingDan_UnAudit", "curPzh=" + pzh + "&curId=" + curFunctionId);
        if (webReq.StatusCode() == 200) {
            requestor.MessageBox("提示", "退审成功！", ICON.Information);
            //#region 刷新汇总表
            dw_hz.SetRedraw(false);
            dw_hz.SetProcessing(true);
            self.SelectionChanged();
            //刷新
            // 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("ddlb_2", true);
                tb_1.SetEnabled("btn_ChaXun", true);
                tb_1.SetEnabled("btn_Filter", true);
                tb_1.SetEnabled("btn_Export", true);
            }
        } else {
            requestor.MessageBox("提示", "退审失败！", 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;
        var curShjb = "F";
        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.Tally = function (cur2_CI_JZ) {
        var curGPzh = "";

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

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




        var bmbh = dw_hz.GetItemString(dw_hz.GetRow(), "bmbh");
        var tzrq = UtcDateTimeFormatToString(dw_hz.GetItemDate(dw_hz.GetRow(), "kdrq"));
        if ("CR" == requestor.GetParm("flag") || "CT" == requestor.GetParm("flag")) {
            webReq1.Invoke("GetTallystatus", "bmbh=" + bmbh + "&tzrq=" + tzrq + "&flag=1");
            if (webReq1.StatusCode() == 200) {
                requestor.MessageBox("提示", "本部门上月库存未结转或本月已经结转,不可审核记账！", ICON.StopSign);
                return;
            }
            if ("CR" == requestor.GetParm("flag") || "CT" == requestor.GetParm("flag")) {
                pzh += "#N";
            }
        }

        webReq.Invoke("CaiGouDingDan_Tally", "curPzh=" + pzh + "&curId=" + curFunctionId);
        if (webReq.StatusCode() == 200) {
            var curMsg = webReq.ResponseText();
            if (curMsg.split("#")[0] == "Y") {
                requestor.MessageBox("提示", "记账成功", 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);
                tb_1.SetEnabled("btn_FAudit", true);
                tb_1.SetEnabled("btn_UnAudit", false);
                tb_1.SetEnabled("btn_Tally", false);
                tb_1.SetEnabled("btn_FenJian", false);

            } else if (curMsg.split("#")[0] == "E") {
                requestor.MessageBox("提示", "程序出现异常，返回码[" + curMsg.split("#")[1] + "].", ICON.Exclamation);
                return;
            } else if (curMsg.split("#")[0] == "T") {
                requestor.MessageBox("提示", "提示信息:\r\n " + curMsg.split("#")[1] + ".", ICON.Exclamation);
                return;
            } else if (curMsg.split("#")[0] == "T1") {
                //检查负库存提示信息，【提示且confirm】
                if (confirm(curMsg.split("#")[1])) {
                    //#region
                    webReq.Invoke("CaiGouDingDan_Tally", "curPzh=" + pzh.replace("#N", "#Y") + "&curId=" + curFunctionId);
                    if (webReq.StatusCode() == 200) {
                        var curMsg = webReq.ResponseText();
                        if (curMsg.split("#")[0] == "Y") {
                            requestor.MessageBox("提示", "记账成功", ICON.Information);
                            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_FAudit", true);
                            tb_1.SetEnabled("btn_Tally", false);
                            tb_1.SetEnabled("btn_Trans", true);
                            tb_1.SetEnabled("btn_InsertRow", false);
                            tb_1.SetEnabled("btn_DeleteRow", 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);
                            tb_1.SetEnabled("btn_FenJian", false);
                        } else if (curMsg.split("#")[0] == "E") {
                            requestor.MessageBox("提示", "程序出现异常，返回码[" + curMsg.split("#")[1] + "].", ICON.Exclamation);
                            return;
                        } else if (curMsg.split("#")[0] == "T") {
                            requestor.MessageBox("提示", "提示信息:\r\n " + curMsg.split("#")[1] + ".", ICON.Exclamation);
                            return;
                        }
                    }
                    //#endregion

                } else {
                    return;
                }
            }
            //#region 刷新汇总表


            //刷新
            //  self.SelectionChanged(dw_hz.GetPageIndex());
            //找到相应的记录
            self.SelectionChanged();
            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) {
                dw_mx_top.Modify("ysh_q_t.visible='0' ysh_t.visible='0' ysh_t.Text=''");
                tb_1.SetEnabled("btn_Audit", false);
                tb_1.SetEnabled("btn_UnAudit", false);
                tb_1.SetEnabled("btn_FAudit", true);
                tb_1.SetEnabled("btn_Tally", false);
                tb_1.SetEnabled("btn_Update", false);
                tb_1.SetEnabled("btn_Delete", false);
                tb_1.SetEnabled("btn_Save", false);
                tb_1.SetEnabled("btn_FenJian", 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_FAudit", true);
                    tb_1.SetEnabled("btn_Tally", false);
                    tb_1.SetEnabled("btn_Trans", true);
                    tb_1.SetEnabled("btn_InsertRow", false);
                    tb_1.SetEnabled("btn_DeleteRow", 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);
                    tb_1.SetEnabled("btn_FenJian", false);
                }
            }

        } else {
            alert(webReq.ResponseText());
        }

    }
    //#endregion

    //#region 判断库存是否充足
    this.JudgeKc = function (row, dwoName, data) {


        if (requestor.GetParm("flag") == "CR" || requestor.GetParm("flag") == "CG" || requestor.GetParm("flag") == "CZ") {
            return -1;
        }
        if (requestor.GetParm("flag") == "CS") {

            if (dwoName.substring(0, 2) != "cm") {
                return -1;
            }
            if (curYwLrSfjckc.split("#")[0] != "Y") {
                return -1;
            }

        }

        if (requestor.GetParm("flag") == "CD") {

            if (dwoName.substring(0, 2) != "cm") {
                return -1;
            }
            if (curYwLrSfjckc.split("#")[1] != "Y") {
                return -1;
            }

        }

        if (requestor.GetParm("flag") == "CT") {

            if (dwoName.substring(0, 2) != "cm") {
                return -1;
            }
        }

        var spkh = dw_mx.GetItemString(row, "spkh");
        var ysbh = dw_mx.GetItemString(row, "ysbh");
        var bxbh = dw_mx.GetItemString(row, "bxbh");
        var cmNo = dwoName.substring(2, dwoName.length)
        var kcslStr = dw_mx.Describe("kc" + cmNo + "_t.text");
        var curSl = 0;
        for (var i = 1; i <= dw_mx.RowCount(); i++) {
            if (dw_mx.GetItemString(i, "spkh") == spkh && dw_mx.GetItemString(i, "ysbh") == ysbh && dw_mx.GetItemString(i, "bxbh") == bxbh && i != row) {
                curSl += dw_mx.GetItemNumber(i, dwoName);
            }
        }
        if (kcslStr == "-" || (curSl + parseInt(data)) > parseInt(kcslStr)) {
            alert("库存数量不足！");
            curSmKcFlag = "N";
            return 0;
        }

        return 1;
    }
    //#endregion

    //#region 修改显示库存数量
    this.ModifyKcsl = function (kh, ys, bx, cm) {
        var row = dw_1.Find("spkh='" + kh + "' and ysbh='" + ys + "' and bxbh='" + bx + "'", 1, dw_1.RowCount());
        if (row > 0) {
            var cksl = dw_1.GetItemNumber(row, cm);
            return cksl;
        }
        return 0;
    }
    //#endregion

    //#region 格式1
    this.Dy1 = function () {
        curDygs = "1";
    }
    //#endregion

    //#region 格式2
    this.Dy2 = function () {
        curDygs = "2";
    }
    //#endregion

    //#region 格式3
    this.Dy3 = function (kh, ys, bx, cm) {
        curDygs = "3";
    }
    //#endregion

    //#region 格式4
    this.Dy4 = function (kh, ys, bx, cm) {
        curDygs = "4";
    }
    //#endregion


    //#region this.Print
    this.print = function () {
        if (tab_1.GetSelectedTab() == "1") {
            if (dw_hz.RowCount() < 1) {
                return;
            }
        }
        var czr = requestor.GetParm("curYhbh");
        // var pzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh")
        var time = new Date();    // 程序计时的月从0开始取值后+1    
        var m = time.getMonth() + 1;
        var t = time.getFullYear() + "-" + m + "-" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
        if (curSfQyQDID == "1") {
            var v = A8erp_Biz_Print.Yw_Cg_35_Print_Jqm(self, requestor, dw_hz, dw_mx, dw_mx_top, dw_print, dw_proxy, dw_sort, curDygs, dw_xt_div_tree_no_parm, dw_xt_print_print2_cmzbm, dw_da_qx_mokuai, dw_da_qx_mokuai_print, dw_parameter, dw_init, curDygs, title_value, curDypx, curCmBtRows1, curCmBtCols1, dw_3, curSfQyQDID, curJqm, curSfQYQXZ, curUserGroupId, tab_1);
            if (v == "N") {
                return;
            }
        } else {
            A8erp_Biz_Print.Yw_Cg_35_Print(self, requestor, dw_hz, dw_mx, dw_mx_top, dw_print, dw_proxy, dw_sort, curDygs, dw_xt_div_tree_no_parm, dw_xt_print_print2_cmzbm, dw_da_qx_mokuai, dw_da_qx_mokuai_print, dw_parameter, dw_init, curDygs, title_value, curDypx, curCmBtRows1, curCmBtCols1, dw_3, curSfQyQDID, curJqm, curSfQYQXZ, curUserGroupId, tab_1);
        }
        //#region 固定行打印
        // 固定行打印不预览  
        if (curGdhdy == "1") {
            var curGdhRowsStr = GetGlobalParm("PRINT_GD_ROW", "ROWS_CG", "BZXX"); //是否启用新版本财务
            if (curGdhRowsStr == "") {
                curGdhRowsStr = "10#10#10#10";
            }
            var curRetStr = "";
            var curPageSize = curGdhRowsStr.split("#")[3];
            var curPageCount = 0;
            var curPage = 0;

            if (curDygs == "4") {
                var curPrintPzh = "";
                var curTabindex = tab_1.GetSelectedTab();
                if (curTabindex == "1") {
                    curPrintPzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
                } else if (curTabindex == "2") {
                    curPrintPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
                }
                var dw_pub_sql = window.external.Control("dw_sql");
                if (flag == "CR" || flag == "CT") {
                    dw_pub_sql.Retrieve("select distinct spkh from yw_cg_rkdmx where pzh='" + curPrintPzh + "' order by spkh ");
                } else if (flag == "CG" || flag == "CS") {
                    dw_pub_sql.Retrieve("select distinct spkh from yw_cg_ddmx where pzh='" + curPrintPzh + "' order by spkh ");
                } else {
                    dw_pub_sql.Retrieve("select distinct spkh from yw_cg_tzdmx where pzh='" + curPrintPzh + "' order by spkh ");
                }

                if (dw_pub_sql.RowCount() > 0) {
                    curPageCount = (dw_pub_sql.RowCount() % curPageSize) == 0 ? (dw_pub_sql.RowCount() / curPageSize) : Math.ceil(dw_pub_sql.RowCount() / curPageSize);
                }
                for (var page = 1; page <= curPageCount; page++) {
                    var curPageSpkh = "";
                    var curPageRowStart = (page - 1) * curPageSize + 1
                    var curPageRowEnd = page * curPageSize;
                    for (var r = curPageRowStart; r <= curPageRowEnd && r <= dw_pub_sql.RowCount(); r++) {
                        curPageSpkh += "'" + (dw_pub_sql.GetItemString(r, "value")) + "',";
                    }
                    dw_print.Modify("my_ym.text='[页码：" + page + "/" + curPageCount + "]'");
                    self.ExecGdhdy(dw_print, curPageSpkh.substring(0, curPageSpkh.length - 1));
                }
            }
        } else {
            dw_print.PrintPreview();
        }
        //#endregion 



        var curTabindex = tab_1.GetSelectedTab();
        if (curTabindex == "1") {
            curPrintPzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
        } else if (curTabindex == "2") {
            curPrintPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
        }

        Print_Times(czr, curPrintPzh, t);
    }
    //#endregion  

    //#region 固定行打印

    this.Gdhdy = function () {
        if (curGdhdy == "0") {
            curGdhdy = "1";
        } else {
            curGdhdy = "0";
        }
    }
    //#endregion  

    //#region 执行固定行打印

    this.ExecGdhdy = function (dw_prints, spkhStr) {
        dw_prints.SetFilter("spkh in(" + spkhStr + ")");
        dw_prints.Filter();
        dw_prints.Modify("DataWindow.Print.Paper.Size='256'");
        dw_prints.Modify("DataWindow.Print.CustomPage.Length='114'");
        dw_prints.Modify("DataWindow.Print.CustomPage.Width='260'");
        dw_prints.Print();
        dw_prints.SetFilter("");
        dw_prints.Filter();
    }
    //#endregion  

    //#region isHave 
    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 格式=2的时候给每个group加尺码
    this.getHeader1Cmz = function (cm) {
        var str = "";
        for (var i = 1; i <= dw_xt_print_print2_cmzbm.RowCount(); i++) {
            var cmzbm = dw_xt_print_print2_cmzbm.GetItemString(i, "cmzbm");
            var cmbt = dw_xt_print_print2_cmzbm.GetItemString(i, "cmbt");
            if (str.length > 0) {
                str += ",";
            }
            str += "if(cmzbh='" + cmzbm + "',describe('" + cm + cmbt + "_t.text' ) ";
        }
        str += ",'--'";
        for (var i = 1; i <= dw_xt_print_print2_cmzbm.RowCount(); i++) {
            str += ")";
        }

        return str;
    }
    //#endregion

    //#region 格式=3的时候给每个行加尺码
    this.GetCMBT_BY_CMZBH_CMBH = function (curCmzbh, c) {

        var str = "";
        var findRows = dw_xt_print_print2_cmzbm.Find("cmzbm='" + curCmzbh + "'", 1, dw_xt_print_print2_cmzbm.RowCount());
        var curBtRow = dw_xt_print_print2_cmzbm.GetItemString(findRows, "cmbt");

        str = dw_print.Describe(c + curBtRow + "_t.text");

        //        for (var i = 1; i <= dw_xt_print_print2_cmzbm.RowCount(); i++) {
        //            var cmzbm = dw_xt_print_print2_cmzbm.GetItemString(i, "cmzbm");
        //            var cmbt = dw_xt_print_print2_cmzbm.GetItemString(i, "cmbt"); 
        //                     if(str.length>0){
        //                      str+=",";
        //                     }
        //                str += "if(cmzbm='" + cmzbm + "',describe('"+cm+ cmbt + "_t.text' ) ";            
        //        }
        //        str+=",'--'";
        //        for (var i = 1; i <= dw_xt_print_print2_cmzbm.RowCount(); i++) { 
        //            str += ")";
        //        } 

        return str;
    }
    //#endregion

    this.SetPrintSort = function (a, b) {
        curDypx = b;
    }

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

    //#region 转单按钮处理
    this.Trans = function () {

        var curPzh = tab_Changed(tab_1, dw_hz, dw_mx_top);
        //var curPzh = dw_mx_top.GetItemString(1, "pzh");
        if (curPzh.length < 1) {
            requestor.MessageBox("提示", "凭证号获取失败！", ICON.StopSign);
            return;
        }
        if (!confirm("确定将单据【" + curPzh + "】转入下一业务吗？")) {
            return;
        }
        webReq.Invoke("CaiGouDingDan_Trans", "curPzh=" + curPzh + "&curId=" + curFunctionId);
        if (webReq.StatusCode() == 200) {
            if (webReq.ResponseText().split("#")[0] == "OK") {

                requestor.MessageBox("提示", "转单成功", ICON.Information);
                self.SelectionChanged();
                //dw_hz.Refresh();
                var findRow = dw_hz.Find("pzh='" + curPzh + "' ", 1, dw_hz.RowCount());
                if (findRow > 0) {
                    dw_hz.ScrollToRow(findRow);
                } else {
                    self.SelectionChanged_tab(curPzh);
                }
                tab_1.SelectTab(1);
                tb_1.SetEnabled("ddlb_1", true);
                tb_1.SetEnabled("ddlb_2", true);
            } else {
                requestor.MessageBox("提示", webReq.ResponseText().split("#")[1], ICON.StopSign);
            }
        } else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
        }
    }
    //#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 if (djzt == "已转单") {
            djzt = "已转单";
        }
        else if (djzt == "未转单") {
            djzt = "未转单";
        } else if (djzt == "未审核") {
            djzt = "isnull(shbz,'0')<>'T'";
        } else if (djzt == "已审核") {
            djzt = "isnull(shbz,'0')='T'";
        }
        else {
            djzt = "fhmc='" + djzt + "'";
        }
        var lylx = ddlb_2.GetText();

        if (curDzdPzh.length > 0) {
            SqlWhere += "  a.pzh='" + curDzdPzh + "'";
            curDzdPzh = "";
        }

        else if (curSelSQL.length > 0 && !isAdd) {
            if (val != "NextPage") {
                sle_Page.SetText(1);
            }
            SqlWhere = curSelSQL;
        }
        else {
            SqlWhere = "  a.bmbh in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "'and cg = '1') and a.gysbh in (select gysbh from da_qx_gysda where  bz3 = '1'and yhbh ='" + curYhbh + "')";
            if (curSYGysbh.length > 0 || curSYBmbh.length > 0) {

                if (curSYBmbh.length > 0) {
                    SqlWhere += " and a.bmbh='" + curSYBmbh + "'";
                    curSYBmbh = "";
                }
            } else {
                if (curSelDays != "-1") {
                    SqlWhere += " and CONVERT(date,kdrq,120) >='" + curSelDays + "'";
                }
            }

        }

        if (flag == "CG") {

            if (djzt == "已转单" || djzt == "未转单") {
                SqlWhere += " AND (case when (select COUNT(pzh) from (select pzh from (select pzh,lydh,djlx from yw_cg_rkdhz union all select pzh,lydh,djlx from yw_cg_rkdhz_ls union all select pzh,lydh,djlx from yw_cg_tzdhz union all select pzh,lydh,djlx from yw_cg_tzdhz_ls) bb where lydh=a.pzh )t)>0 then '已转单' else '未转单' end)= '" + djzt + "' ";
            }
            else {
                if (djzt.length > 0) {
                    SqlWhere += " and  " + djzt;
                }
            }
        }
        else {

            if (djzt.length > 0) {
                SqlWhere += " and  " + djzt;
            }
            //SqlWhere += " and ( fhmc+isnull(jzbz,'0') like '" + djzt + "')";
        }
        //外界传入的凭证
        if (flag == "CR" || flag == "CT") {

            if (lylx == "全部单据") {
                SqlWhere += " and  1=1";
            }
            else if (lylx == "新增单据") {
                SqlWhere += " and (lydh is null or lydh ='') ";
            }
            else if (lylx == "转接单据") {
                SqlWhere += " and lydh <> ''";
            }

        }
        //alert("SqlWhere" + SqlWhere)
        if (curFormPzh.length > 0) {
            SqlWhere = "a.pzh='" + curFormPzh + "'";
            // dw_hz.RetrieveEx(SqlWhere);
            // tab_1.SetSelectedTab(2);

        } //else {

        //                        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");
        //                        }


        dw_hz.SetRedraw(false);

        var RowCount = sle_Count.GetText();
        var columnSql = "";
        var fromSql = "";
        var whereSql = "";
        var columnModifyStr = "";
        if (flag == "CR" || flag == "CT") {
            columnSql = "          CASE ROW_NUMBER() OVER ( ORDER BY a.kdrq DESC , a.kdsj DESC , RIGHT(a.pzh, 7) DESC )%(" + RowCount + ") WHEN 0 THEN  ROW_NUMBER() OVER ( ORDER BY a.kdrq DESC , a.kdsj DESC , RIGHT(a.pzh, 7) DESC ) / (" + RowCount + ") ELSE            ROW_NUMBER() OVER ( ORDER BY a.kdrq DESC , a.kdsj DESC , RIGHT(a.pzh, 7) DESC ) / (" + RowCount + ") + 1 END page ,  CASE WHEN shbz = 'T' THEN '已审核'             ELSE '未审核'        END fhjbmc ,        CASE WHEN  ISNULL(jzbz,'0')=1 THEN '√' ELSE '' END showJzbz ,ISNULL(jzbz,'0') jzbz,       CONVERT(DATE,kdrq,120) kdrq,        pzh ,        gysbh ,        '' gysmc ,        bmbh ,        '' bmmc ,        zjsl ,        zjje ,        lsjze ,        kdr ,        '' kdrmc ,        cgy ,        '' cgymc ,        shr czr ,  '' czrmc ,       jzr ,        '' jzrmc ,        kdsj ,        shsj ,        jzsj ,        xxly ,        '' xxlymc ,        lydh ,        cgfs ,        '' cgfsmc ,        bzxx ,        fklx ,        '' fklxmc ,         CASE WHEN shbz = 'T' THEN 'T'                         ELSE 'F'                    END  fhjb ,        phlydh ,fjbz";
            fromSql = " FROM    ( SELECT    *          FROM      yw_cg_rkdhz(NOLOCK)         ";
            if (curSelSQL.length > 0) {
                fromSql += " UNION ALL          SELECT    *          FROM      yw_cg_rkdhz_ls(NOLOCK)        ";
            }
            if (curBf.length > 0) {
                fromSql += " UNION ALL          SELECT    *          FROM      yw_cg_rkdhz_ls(NOLOCK)        ";
            }
            fromSql += "    ) a ";

            if (flag == "CR") {
                whereSql = " where a.djlx = '1' AND " + SqlWhere;
            } else {
                whereSql = " where a.djlx = '2' AND " + SqlWhere;
            }
            columnModifyStr = "  fhjbmc.color='134217856' fhjbmc.font.weight='700'   showJzbz.color='128' jzbz.visible='0' czr.visible='0' cgfs.visible='0' fklx.visible='0' xxly.visible='0' fhjb.visible='0' phlydh.visible='0' fklxmc.visible='0' phlydh.visible='0'  jzr.visible='0' ";

        } else if (flag == "CG" || flag == "CS") {
            columnSql = "          CASE ROW_NUMBER() OVER ( ORDER BY a.kdrq DESC , a.kdsj DESC , RIGHT(a.pzh, 7) DESC )%(" + RowCount + ") WHEN 0 THEN  ROW_NUMBER() OVER ( ORDER BY a.kdrq DESC , a.kdsj DESC , RIGHT(a.pzh, 7) DESC ) / (" + RowCount + ") ELSE            ROW_NUMBER() OVER ( ORDER BY a.kdrq DESC , a.kdsj DESC , RIGHT(a.pzh, 7) DESC ) / (" + RowCount + ") + 1 END page ,  CASE WHEN shbz = 'T' THEN 'T'                         ELSE 'F'                    END  fhjb ,      CASE WHEN shbz = 'T' THEN '已审核'             ELSE '未审核'        END fhjbmc ,         CASE WHEN  ISNULL(jzbz,'0')=1 THEN '√' ELSE '' END showJzbz ,ISNULL(jzbz,'0') jzbz,          pzh ,         bmbh ,        '' bmmc ,         kdrq ,         gysbh ,        '' gysmc ,         zjsl ,         zjje ,        cgy ,        '' cgymc ,          kdr ,        '' kdrmc ,           xxly ,        '' xxlymc ,        lydh ,      CASE WHEN zdzt = '已转单' THEN  zdzt                         ELSE '未转单'                    END       zdzt ,        jzr ,        '' jzrmc ,          jzsj ,        bzxx ,         cgfs ,        '' cgfsmc ,         kdsj ,        shr czr ,   '' czrmc ,              shsj ";
            fromSql = " FROM    ( SELECT    *          FROM      yw_cg_ddhz(NOLOCK)        ";
            if (curSelSQL.length > 0) {
                fromSql += " UNION ALL          SELECT    *          FROM      yw_cg_ddhz_ls(NOLOCK)        ";
            }
            fromSql += "    ) a ";
            if (flag == "CG") {
                whereSql = " where a.djlx = '1' AND " + SqlWhere;
            } else {
                whereSql = " where a.djlx = '2' AND " + SqlWhere;
            }
            columnModifyStr = "  fhjbmc.color='134217856' fhjbmc.font.weight='700'   showJzbz.color='128' jzbz.visible='0'  czr.visible='0' cgfs.visible='0'  xxly.visible='0' fhjb.visible='0' jzr.visible='0' ";
        } else if (flag == "CD") {
            columnSql = "           CASE ROW_NUMBER() OVER ( ORDER BY a.kdrq DESC , a.kdsj DESC , RIGHT(a.pzh, 7) DESC )%(" + RowCount + ") WHEN 0 THEN  ROW_NUMBER() OVER ( ORDER BY a.kdrq DESC , a.kdsj DESC , RIGHT(a.pzh, 7) DESC ) / (" + RowCount + ") ELSE            ROW_NUMBER() OVER ( ORDER BY a.kdrq DESC , a.kdsj DESC , RIGHT(a.pzh, 7) DESC ) / (" + RowCount + ") + 1 END page ,  CASE WHEN shbz = 'T' THEN '已审核'             ELSE '未审核'        END fhjbmc ,        CASE WHEN  ISNULL(jzbz,'0')=1 THEN '√' ELSE '' END showJzbz ,ISNULL(jzbz,'0') jzbz,       CONVERT(DATE,kdrq,120) kdrq,        pzh ,        gysbh ,        '' gysmc ,        bmbh ,        '' bmmc ,        zjsl ,        zjje ,                kdr ,        '' kdrmc ,        cgy ,        '' cgymc ,        shr czr ,  '' czrmc ,       jzr ,        '' jzrmc ,        kdsj ,        shsj ,        jzsj ,        xxly ,        '' xxlymc ,        lydh ,        cgfs ,        '' cgfsmc ,        bzxx ,        fklx ,        '' fklxmc ,         CASE WHEN shbz = 'T' THEN 'T'                         ELSE 'F'                    END  fhjb   ";
            fromSql = " FROM    ( SELECT    *          FROM      yw_cg_tzdhz(NOLOCK)          ";
            if (curSelSQL.length > 0) {
                fromSql += " UNION ALL          SELECT    *          FROM      yw_cg_tzdhz_ls(NOLOCK)        ";
            }
            fromSql += "    ) a ";
            whereSql = " where a.djlx = '2' AND " + SqlWhere;
            columnModifyStr = "  fhjbmc.color='134217856' fhjbmc.font.weight='700'   showJzbz.color='128' jzbz.visible='0' czr.visible='0' cgfs.visible='0' fklx.visible='0' xxly.visible='0' fhjb.visible='0'  fklxmc.visible='0'   jzr.visible='0' ";
        }
        var f = YwHzQuery(columnSql, fromSql, whereSql, sle_Page.GetText(), RowCount, flag, curFunctionId);

        dw_hz.SetFullState(f.split("#")[0]);
        dw_hz.Modify(" DataWindow.Header.Color='15780518' DataWindow.Header.gradient.color='16777215' DataWindow.Header.brushmode='2' DataWindow.detail.height='80'  DataWindow.Header.height='80'   ");
        dw_hz.Modify(" create compute(band=detail alignment='2' expression='getrow()' border='0' color='33554432' x='5' y='13' height='80' width='183' format='[GENERAL]' html.valueishtml='0'  name=xh  visible='1'  font.face='微软雅黑' font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='1' background.color='553648127' background.transparency='0' background.gradient.color='8421504' background.gradient.transparency='0' background.gradient.angle='0' background.brushmode='0' background.gradient.repetition.mode='0' background.gradient.repetition.count='0' background.gradient.repetition.length='100' background.gradient.focus='0' background.gradient.scale='100' background.gradient.spread='100' tooltip.backcolor='134217752' tooltip.delay.initial='0' tooltip.delay.visible='32000' tooltip.enabled='0' tooltip.hasclosebutton='0' tooltip.icon='0' tooltip.isbubble='0' tooltip.maxwidth='0' tooltip.textcolor='134217751' tooltip.transparency='0' transparency='0' )");
        dw_hz.Modify(" create text(band=header alignment='2' text='序号' border='0' color='33554432' x='0' y='5' height='76' width='183'  font.face='微软雅黑' html.valueishtml='0'  name=xh_t visible='1'   font.height='-9' font.weight='400'  font.family='2' font.pitch='2' font.charset='0' background.mode='2' background.color='536870912' background.transparency='0' background.gradient.color='8421504' background.gradient.transparency='0' background.gradient.angle='0' background.brushmode='0' background.gradient.repetition.mode='0' background.gradient.repetition.count='0' background.gradient.repetition.length='100' background.gradient.focus='0' background.gradient.scale='100' background.gradient.spread='100' tooltip.backcolor='134217752' tooltip.delay.initial='0' tooltip.delay.visible='32000' tooltip.enabled='0' tooltip.hasclosebutton='0' tooltip.icon='0' tooltip.isbubble='0' tooltip.maxwidth='0' tooltip.textcolor='134217751' tooltip.transparency='0' transparency='0' )");
        dw_hz.Modify(" datawindow.detail.color='16777215\tif(currentrow()=getrow(), 12639424,if(mod(getrow(),2)=0,16382457, 16777215) )' ");

        dw_hz.Modify(columnModifyStr);

        dw_hz.Modify(" DataWindow.detail.height='90' page.visible='0' kdr.visible='0' cgy.visible='0'");

        tb_paging.SetText("lbl_MaxPage", f.split("#")[1]);
        tb_paging.SetText("lbl_RowCount", "，共" + f.split("#")[2] + "条");
        if (curFormPzh.length > 0) {
            tab_1.SetSelectedTab(2);
        }



        if (curjgqx.indexOf("jj") != -1) {
            dw_hz.Modify("zjje.visible='0'");
        }
        if (curjgqx.indexOf("lsj") != -1) {
            dw_hz.Modify("lsjze.visible='0'");
        }


        dw_hz.SetSort(" kdrq desc kdsj desc");
        dw_hz.Sort();
        dw_hz.SetRedraw(true);
     //   requestor.ClipBoardNao(dw_hz.Describe("datawindow.syntax"));
        self.Hz_RowFocusChanged(dw_hz.GetRow());

        // }

    }
    this.SelectCh = function () {
        if (curLastSortNameNew != "") {
            dw_hz.SetSort(curLastSortNameNew + " " + curLastSort);
            dw_hz.Sort();

            var pzh = "";
            if (dw_mx_top.RowCount() > 0) {
                pzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
            }
            var findRow = dw_hz.Find("pzh='" + pzh + "'", 1, dw_hz.RowCount());
            if (findRow > 0) {
                dw_hz.ScrollToRow(findRow);
            }
        }
    }
    //#region this.EvalJs

    this.EvalJs = function (jsScript) {

        eval(jsScript);
    }
    //#endregion

    //#region 检查记账标志
    this.CheckJzbz = function (curFlag) {
        var curTName = "";
        var curpzh = "";
        var flag = requestor.GetParm("flag");

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

        if (flag == "CG" || flag == "CS") {
            curTName = "yw_cg_ddhz";
        }
        else if (flag == "CR" || flag == "CT") {
            curTName = "yw_cg_rkdhz";
        }
        if (flag != "CZ" && flag != "CD") {
            webReqTimestamp.Invoke("YW_GTE_PZH", "curTName=" + curTName + "&curPzh=" + curpzh);
            if (webReqTimestamp.StatusCode() == 200) {

                var curjzbz = webReqTimestamp.ResponseText();

                if (curFlag == "JZ") {
                    //未审核。
                    if (curjzbz == "N") {
                        requestor.MessageBox("提示", "该记录还未审核，不能记账", ICON.StopSign);
                        tb_1.SetEnabled("btn_Audit", true);
                        tb_1.SetEnabled("btn_UnAudit", true);
                        tb_1.SetEnabled("btn_Tally", false);
                        tb_1.SetEnabled("btn_Update", false);
                        tb_1.SetEnabled("btn_Delete", false);
                        tb_1.SetEnabled("btn_Save", false);
                        return true;
                    }
                }

                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 
                    if (findRow > 0) {
                        dw_mx_top.Modify("ysh_q_t.visible='0' ysh_t.visible='0' ysh_t.Text=''");
                        tb_1.SetEnabled("btn_Audit", false);
                        tb_1.SetEnabled("btn_UnAudit", false);
                        tb_1.SetEnabled("btn_Tally", false);
                        tb_1.SetEnabled("btn_Update", false);
                        tb_1.SetEnabled("btn_Delete", false);
                        tb_1.SetEnabled("btn_Save", false);
                    }
                    return true;
                } else {
                    return false;
                }
            } else {
                requestor.MessageBox("获取记账标志失败", webReqTimestamp.ResponseText(), ICON.StopSign);
                return true;
            }
        } else {
            return false;
        }
    }
    //#endregion

    //#region 删除修改保存时检查是否转单
    this.CheckTrans = function () {

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

        webReqTimestamp.Invoke("YW_GTE_TRANS", "curPzh=" + curpzh);
        if (webReqTimestamp.StatusCode() == 200) {
            var curtrans = webReqTimestamp.ResponseText();
            if (curtrans == "ERROR") {
                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 
                return true;
            } else {
                return false;
            }
        } else {
            requestor.MessageBox("获取转单状态失败", webReqTimestamp.ResponseText(), ICON.StopSign);
            return true;
        }
    }
    //#endregion
    this.SelectionChanging = function (ind) {
        //        return;
        //        if (ind == 2) {

        //            dw_mx.AcceptText();
        //            dw_mx_top.AcceptText();

        //            if (dw_mx.GetChanges() != "" || dw_mx_top.GetChanges() != "") {

        //                if (requestor.MessageBox("提示^", "数据还没有保存,是否继续取消?", ICON.Question, BUTTON.YesNo) == 2) {


        //                    return 1;
        //                } else {

        //                    self.Cancel();
        //                    return 1;

        //                }
        //            }
        //        }
    }
    this.Tab_1_Clicked = function (ind) {
        if (ind == "1") {


            dw_mx.AcceptText();
            dw_mx_top.AcceptText();

            if (dw_mx.GetChanges() != "") {

                if (requestor.MessageBox("提示^", "数据还没有保存,是否继续取消?", ICON.Question, BUTTON.YesNo) == 2) {

                    tab_1.SelectTab(2);
                    return 1;
                } else {

                    self.Cancel();
                    self.SelectCh();
                    return 1;

                }
            }


            tb_1.SetEnabled("ddlb_1", true);
            tb_1.SetEnabled("ddlb_2", true);
            tb_1.SetEnabled("btn_ChaXun", true);
            tb_1.SetEnabled("btn_Filter", true);
            tb_1.SetEnabled("btn_Export", true);
            self.Cancel();
            self.SelectCh();
            if (dw_hz.GetRow() < 1) {
                return;
            }


            if (flag == "KP") {
                self.SelectionChanged_tab(dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh"), dw_mx_top.GetItemString(dw_mx_top.GetRow(), "sgdj"));
            } else {
                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("ddlb_2", 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) {
                dw_mx_top.Retrieve("");
                dw_mx.Retrieve("");
                return -1;
            }
            var curPzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
            if (flag == "KP") {
                dw_mx_top.Retrieve(curPzh, dw_hz.GetItemString(dw_hz.GetRow(), "sgdj"));
                dw_mx.Retrieve(curPzh, dw_hz.GetItemString(dw_hz.GetRow(), "sgdj"));
            } else {


                dw_mx_top.Retrieve(curPzh);
                dw_mx.Retrieve(curPzh);
            }
            self.GetSFYSGYSKCFlag();
        }
    }



    this.dw_mx_Clicked = function (x, y, row, dwoName, data) {

        if (row < 1) {
            return;
        }
        self.fhjl();
        if (dwoName.substring(0, 2) == "cm") {
            //处理点亮的问题 --------begin-------
            var curSpkh = dw_mx.GetItemString(row, "spkh");
            curOldSpkh = curSpkh;
            self.setMdf(row, dwoName, curSpkh);
            // 处理点亮的问题 --------end---------
        }
        A8erp_Biz_Scan.Yw_Dw_Mx_ItemFocusChange(self, dw_mx, row, dwoName, data);
    }

    //#region 查询界面
    this.ChaXun = function () {
        curW_CaiGou_ChaXun.SetDataWindow(self, dw_hz, flag, curYhbh, ddlb_1.GetText(), curSelDays, ddlb_2.GetText());
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.CaiGou.Base.W_CaiGou_ChaXun&flag=" + flag), curW_CaiGou_ChaXun, null);

    }
    //#endregion


    this.TopSetTmlrPmb = function () {
        curTmlrms = "PZBTM";
    }
    this.TopSetTmlrSptm = function () {
        curTmlrms = "TM";
    }

    //#region 打印预览
    this.SetPrint = function () {
        if (curSfQyQDID == "1") {
            A8erp_Biz_Print.Yw_Cg_35_Print_Jqm(self, requestor, dw_hz, dw_mx, dw_mx_top, dw_print, dw_proxy, dw_sort, curDygs, dw_xt_div_tree_no_parm, dw_xt_print_print2_cmzbm, dw_da_qx_mokuai, dw_da_qx_mokuai_print, dw_parameter, dw_init, curDygs, title_value, curDypx, curCmBtRows1, curCmBtCols1, dw_3, curSfQyQDID, curJqm, curSfQYQXZ, curUserGroupId, tab_1);
        } else {
            A8erp_Biz_Print.Yw_Cg_35_Print(self, requestor, dw_hz, dw_mx, dw_mx_top, dw_print, dw_proxy, dw_sort, curDygs, dw_xt_div_tree_no_parm, dw_xt_print_print2_cmzbm, dw_da_qx_mokuai, dw_da_qx_mokuai_print, dw_parameter, dw_init, curDygs, title_value, curDypx, curCmBtRows1, curCmBtCols1, dw_3, curSfQyQDID, curJqm, curSfQYQXZ, curUserGroupId, tab_1);
        }

        dw_print.PrintPreview();

    }
    //#endregion

    //#region 浏览图片
    this.ShowPic = function () {

        if (dw_mx.GetRow() < 1) {
            alert("选中一行明细查看图片");
            return;
        }
        var curSpkh = dw_mx.GetItemString(dw_mx.GetRow(), "spkh");
        if (curSpkh.length < 1) {
            alert("商品款号为空，请检查");
            return;
        }
        var curW_KC_PIC = new W_KC_PIC();
        curW_KC_PIC.SetDataWindow(null, curSpkh, self, "0", "");
        requestor.Open("/Service/LoadWindow.ashx?WinName= A8ERP.KuCun.TongJiFenXi.W_KC_PIC&curSpkh=" + curSpkh, curW_KC_PIC);

    }
    //#endregion

    //#region 浏览图片
    this.ShowDjPic = function () {
        var curPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
        if (curPzh.length < 1) {

            alert("当前单据无图片");
            return;
        }

        var curW_KC_Dj_PIC = new W_KC_Dj_PIC();
        curW_KC_Dj_PIC.SetDataWindow(null, curPzh, self, "0", "");
        requestor.Open("/Service/LoadWindow.ashx?WinName= A8ERP.KuCun.TongJiFenXi.W_KC_Dj_PIC&curPzh=" + curPzh, curW_KC_Dj_PIC);

    }
    //#endregion

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

    //#region 复制备注信息

    this.CopyBzxx = function () {

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

    //#region 款号，款名排序

    this.dw_mx_doubleClicked = function (x, y, row, dwcName) {

        if (dwcName == "spkh_t") {
            if (curSortKhFalg == "Y") {

                dw_mx.SetSort("spkh A");
                curSortKhFalg = "N";
            } else {

                dw_mx.SetSort("spkh D");
                curSortKhFalg = "Y";
            }
            dw_mx.Sort();
        } else if (dwcName == "ksmc_t") {
            if (curSortKhFalg == "Y") {
                dw_mx.SetSort("ksmc A");
                curSortKhFalg = "N";
            } else {

                dw_mx.SetSort("ksmc D");
                curSortKhFalg = "Y";
            }
            dw_mx.Sort();
        }
    }
    //#endregion  

    //#region 款号，款名排序
    var curSortKhFalg = "Y";
    this.dw_mx_doubleClicked = function (x, y, row, dwcName) {

        if (dwcName == "spkh_t") {
            if (curSortKhFalg == "Y") {

                dw_mx.SetSort("spkh A");
                curSortKhFalg = "N";
            } else {

                dw_mx.SetSort("spkh D");
                curSortKhFalg = "Y";
            }
            dw_mx.Sort();
        } else if (dwcName == "ksmc_t") {
            if (curSortKhFalg == "Y") {
                dw_mx.SetSort("ksmc A");
                curSortKhFalg = "N";
            } else {

                dw_mx.SetSort("ksmc D");
                curSortKhFalg = "Y";
            }
            dw_mx.Sort();
        }
    }
    //#endregion

    //#region 格式保存
    this.savegs = function () {
        var msg = savegs(dw_hz, curYhbh, curFunctionId);
        alert(msg);
    }
    //#endregion

    //#region 清除格式
    this.qcgs = function () {
        var msg = qcgs(curYhbh, curFunctionId);
        alert(msg);

    }
    //#endregion

    this.Myfocus = function () {
        setTimeout(self.SetMyFocus, 1);
    }
    this.SetMyFocus = function () {
        sle_tmh.SetText("");
        sle_tmh.SetFocus();
        return 1;
    }

    this.Export = function () {
        if (tab_1.GetSelectedTab() == "1") {
            dw_hz.Export()
        }
        else {
            dw_mx.Export();
        }
    }
    //#region 获取是否显示供应商库存的标志
    this.GetSFYSGYSKCFlag = function () {
        dw_mx_top.AcceptText();
        var tempbmbh = dw_mx_top.GetItemString(1, "bmbh");
        var tempgyshbh = dw_mx_top.GetItemString(1, "gysbh");

        if (tempbmbh.length > 0 && tempgyshbh.length > 0) {
            dw_cgddgsykc.Retrieve(tempbmbh, tempgyshbh);
            if (dw_cgddgsykc.RowCount() > 0) {
                CGDDYWGSYKCFlag = dw_cgddgsykc.GetItemString(1, "cgddgysflag")
            }
        }
        A8erp_Biz_Scan.Yw_Dw_Mx_ItemFocusChange(self, dw_mx, 1, "cm", "");
    }
    //#endregion 

    this.liansao = function () {
        if (cueSmzt == "0") {
            cueSmzt = "1";
        } else {
            cueSmzt = "0";
        }

    }

    this.AutoPeiHuo = function () {
        var itemData = "SJ955";
        var itemLabel = "日常订单配货";
        var ts_1 = window.external.Control("ts_1");
        ts_1.CloseItem(itemData);
        ts_1.Open(itemData, itemLabel, '', "/Service/OpenSheet.aspx?FunID=" + itemData + "&curFlag=CG&curMrbm=" + curMrbm + "&curDate=" + new Date().toLocaleTimeString(), true); // + "&curFormYwlx=PF&curFormPzh=" + curPzh + "&kdsj=" + curKdsj, true);
    }


    this.PH_Print = function () {

        //            var pzh = "";
        //            pzh = dw_hz.GetItemString(dw_hz.GetRow(), "lydh")
        var phpzh = "";
        phpzh = dw_hz.GetItemString(dw_hz.GetRow(), "phlydh")
        if (phpzh == "") {
            requestor.MessageBox("提示", "无配货单,请勿打印!", ICON.Information);
            return;
        }
        if (tab_1.GetSelectedTab() == "1") {
            if (dw_hz.RowCount() < 1) {
                return;
            }


            dw_ph_mx_top.Retrieve(phpzh);
            dw_ph_mx.Retrieve(phpzh);
            dw_ph_hz.Retrieve(phpzh);
        }

        if (tab_1.GetSelectedTab() == "2") {
            if (dw_mx_top.RowCount() < 1) {
                return;
            }
            //                else {
            pzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "lydh")

            dw_ph_mx_top.Retrieve(phpzh);
            dw_ph_mx.Retrieve(phpzh);
            dw_ph_hz.Retrieve(phpzh);
            //                }
        }
        var czr = requestor.GetParm("curYhbh");

        var time = new Date();    // 程序计时的月从0开始取值后+1    
        var m = time.getMonth() + 1;
        var t = time.getFullYear() + "-" + m + "-" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();

        var v = A8erp_Biz_Print.Yw_Cg_35_PHDPrint_Jqm(self, requestor, dw_ph_hz, dw_ph_mx, dw_ph_mx_top, dw_print, dw_proxy, dw_sort, curDygs, dw_xt_div_tree_no_parm, dw_xt_print_print2_cmzbm, dw_da_qx_mokuai, dw_da_qx_mokuai_print, dw_parameter, dw_init, curDygs, title_value, curDypx, curCmBtRows1, curCmBtCols1, dw_3, curSfQyQDID, curJqm, curSfQYQXZ, curUserGroupId, tab_1);
        if (v == "N") {
            return;
        }
        dw_print.PrintPreview();
        if (phpzh != "") {
            webReq.Invoke("Update_Mark", "curVar=1&curPZH=" + phpzh);

            if (webReq.StatusCode() == 200) {
                //requestor.MessageBox("提示", webReq.ResponseText(), ICON.Information);

            } else {
                requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
            }
        }

        //#endregion
    }


    this.PH_FAudit = function () {
        if (flag == "CR") {
            var pzh = dw_hz.GetItemString(dw_hz.GetRow(), "phlydh")
            if (pzh == "") {
                requestor.MessageBox("提示", "无配货单,请勿反审!", ICON.Information);
                return;
            }
            var curPzh = tab_Changed(tab_1, dw_hz, dw_mx_top);


            if (confirm("反审操作会删除分拣记录和当前批发出库单，是否继续？")) {
                webReq.Invoke("Un_PHAudit", "curPZH=" + curPzh);

                if (webReq.StatusCode() == 200) {
                    requestor.MessageBox("提示", webReq.ResponseText(), ICON.Information);
                    self.Tab_1_Clicked(1);

                } else {
                    requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
                }

            }
        }

    }

    function tab_Changed_Fjbz(tab_1, dw_hz, dw_mx_top) {
        var curTabindex = tab_1.GetSelectedTab();
        var fjbz = "";

        if (curTabindex == "1") {
            if (dw_hz.GetRow() > 0) {
                fjbz = dw_hz.GetItemString(dw_hz.GetRow(), "fjbz");
            }


        } else if (curTabindex == "2") {

            if (dw_mx_top.GetRow() > 0) {
                fjbz = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "fjbz");
            }
        }
        return fjbz;
    }

    this.fjsm = function () {
        if (requestor.GetParm("flag") == "CR" || requestor.GetParm("flag") == "CT") {
            if (curSfqytmlsh == "1") {
                var curLydh = dw_mx_top.GetItemString(1, "lydh");
                if (curLydh.substring(0, 2) == "SM") {
                    if (dw_mx.RowCount() > 0 && dw_mx.GetItemString(1, "spkh") != "") {
                        alert("本单是纵向扫描，不可分拣。");
                        return;
                    }
                }
            }
        }
        var curPzh = tab_Changed(tab_1, dw_hz, dw_mx_top);
        var curFjbz = tab_Changed_Fjbz(tab_1, dw_hz, dw_mx_top);
        var curKhbh = dw_mx_top.GetItemString(1, "bmbh")
        var curBmbh = dw_mx_top.GetItemString(1, "gysbh")

        var curJzbz = dw_hz.GetItemString(dw_hz.GetRow(), "jzbz")
        if (curJzbz == "1") {
            requestor.MessageBox("提示", "当前单据已记账!", ICON.Information);
            return;
        }


        if (curPzh.length < 1) {
            requestor.MessageBox("提示", "请选择单据后分拣!", ICON.Information);
            return;
        }

        webReq_pf.Invoke("PF_FenJian_Initialize", "curPzhStr=" + curPzh + ",&Flag=CG"); // Flag=1 分拣初始化);
        if (webReq_pf.StatusCode() == 200) {
            var rPzh = webReq_pf.ResponseText();
            if (rPzh.split("#")[0] == "H") {


                if (confirm("当前单据已存在分拣，是否打开？")) {
                    curW_PH_FenJian_List.SetDataWindow(self, rPzh.split("#")[1], curFjbz, curKhbh, "cg", curJjfs, curBmbh, curQjfs);
                    requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.PiFa.PiFaBase.W_PH_FenJian_List&curFlag=CG"), curW_PH_FenJian_List, null);
                } else {
                    return;
                }

            } else {
                curW_PH_FenJian_List.SetDataWindow(self, curPzh, "0", curKhbh, "cg", curJjfs, curBmbh, curQjfs);
                requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.PiFa.PiFaBase.W_PH_FenJian_List&curFlag=CG"), curW_PH_FenJian_List, null);
            }
        } else {
            requestor.MessageBox("提示", "数据保存失败!\r\n" + webReq_pf.ResponseText(), ICON.StopSign);
        }


    }



    this.SyncSpkh = function () {


        //        var curGlobalCsbDw = window.external.Control("dw_spda");
        //        curDw_mx.GetChild("spkh", dwc);
        //        curDw_proxy.SetFullState(curGlobalCsbDw.GetFullState());
        //        curDw_proxy.ShareData(dwc);


        ///   GetApplicationSpda("");

        // curGlobalCsbDw.SetFullState(FullStateStr);


        requestor.ShowLoading("正在刷新商品缓存信息，请稍等...");



        $.ajax({
            type: "POST",
            url: "/Service/Ajax_DA.ashx",
            async: false,
            data: { curFlag: "ApplicationSpdaReturnFullState" },
            success: function (msg) {

                var curGlobalCsbDw = window.external.Control("dw_spda");
                curGlobalCsbDw.SetFullState(msg);
                //#region 获取首页商品档案缓存数据 GetWelcomeSpda
                GetWelcomeSpda(dw_mx, dw_spda, dwc);
                //#endregion

                requestor.CloseLoading();


                alert("货品同步成功");
            },
            error: function (msg) {
                alert(msg);

                requestor.CloseLoading();
            }
        });
    }

    this.Znsm = function () {
        dw_mx_top.AcceptText();
        var flag = requestor.GetParm("flag");
        if (flag == "CR" || flag == "CT") {
            if (curSfqytmlsh == "1") {
                var curLydh = dw_mx_top.GetItemString(1, "lydh");
                if (curLydh.substring(0, 2) != "SM") {
                    if (dw_mx.RowCount() > 0 && dw_mx.GetItemString(1, "spkh") != "") {
                        if (requestor.MessageBox("提示", "此操作会清除本单所有明细数据，是否继续？", ICON.Question, BUTTON.YesNo) == 2)
                            return;
                    }
                }
            }
        }
        var bmbh = dw_mx_top.GetItemString(1, "bmbh");
        var bmmc = dw_mx_top.GetItemString(1, "bmmc");
        var gysbh = dw_mx_top.GetItemString(1, "gysbh");
        var gysmc = dw_mx_top.GetItemString(1, "gysmc");
        var rq =  UtcDateFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "kdrq"));
        var pzh = dw_mx_top.GetItemString(1, "pzh");
        var lydh = dw_mx_top.GetItemString(1, "lydh");
        if (bmbh == "") {
            alert("请选择部门");
            return;
        }
        if (gysbh == "") {
            alert("请选择供应商");
            return;
        }
        cur_W_YW_ZNSM_CGYW.SetDataWindow(self, bmbh, bmmc, gysbh, gysmc, rq, pzh, lydh, flag, dw_mx_top.GetItemString(dw_mx_top.GetRow(), "rkfs"), dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bzxx"), curJjfs, curQjfs, curjgqx);
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.YeWuZongHeFenXi.W_YW_ZNSM_CGYW&pfpzh=" + pzh + "&ywlx=" + flag + "&smPzh=" + lydh), cur_W_YW_ZNSM_CGYW, null);
    }

    this.ZnsmFd = function (rPzh) {


            //服务器成功处理，返回单号
           
            //刷新 
            curFormPzh = "";
            //            if (isAdd) {
            //                dw_hz.RetrieveEx("a.pzh='" + rPzh + "'");
            //            } else {

            //            }
            if (flag == "CR") {
                webReq.Invoke("CaiGouDingDan_Save_Rkfs", "pzh=" + rPzh);
            }

            self.SelectionChanged();
            sle_Page.SetText(1);
            //找到相应的记录 
            dw_mx_top.Retrieve(rPzh);
            //dw_import_PL.ShareDataOff();
            dw_mx.Retrieve(rPzh);

            var findRow = dw_hz.Find("pzh='" + rPzh + "' ", 1, dw_hz.RowCount());
            if (findRow > 0) {
                dw_hz.ScrollToRow(findRow);
                self.SetEditMode("");
            } else {
                self.SelectionChanged_tab(rPzh);
            }


            curSaveReturnValue = "Y"
            if (zhengdanzhekouFlag == "N") {
               // requestor.MessageBox("提示", "数据保存成功!", ICON.Information);
            }
            if (isAdd && isPast == "Y") {
                DELETE_PZH_TO_YW(curPzh);
                isAdd = false;
            }
            //删除临时保存文件
            self.DelFile();
            self.ClareKcAndCmzAll();
            dw_mx_top.SetFocus();
            //#region  审核的问题  dw_mkfhjb 

            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"));
                tb_1.SetEnabled("btn_Audit", true);
                tb_1.SetEnabled("btn_UnAudit", false);
                tb_1.SetEnabled("btn_FAudit", false);
                tb_1.SetEnabled("btn_Tally", false);
                tb_1.SetEnabled("btn_Delete", true);
                tb_1.SetEnabled("btn_Edit", true);
                tb_1.SetEnabled("btn_Save", false);
                tb_1.SetEnabled("btn_Trans", false);
                tb_1.SetEnabled("btn_Filter", true);
                tb_1.SetEnabled("btn_Export", true);
            }
            //#endregion           
            A8erp_Biz_Scan.Yw_Dw_Mx_ItemFocusChange(self, dw_mx, 1, "cm", "");
            //-------------每次保存完删除业务表临时凭证号对应数据--------

            isPast = "N";
            //-----------------------------------------------------------
            if (flag == "CR" || flag == "CT") {
               
                    cb_sm.SetVisible(false);
                    sle_tmh.SetVisible(false);

                }
        dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zsl") + "' ");
        dw_mx_top.Modify("tmsmflag.visible='0' ");
    }
}