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

    var self = this;
    this.Instance = null;
    var requestor = new PBWindow();
    var tab_1 = new TabControl(requestor);
    var dw_ph_mx_top = new DataWindow(requestor);
    var dw_ph_mx = new DataWindow(requestor);
    var dw_ph_hz = new DataWindow(requestor);
    var mle_1 = new MultiLineEdit(requestor);
    var dw_hz = new DataWindow(requestor);
    var dw_mkfhjb = new DataWindow(requestor);
    var sc_1 = new SplitContainer(requestor);
    var cb_sm = new CommandButton(requestor);
    var em_2 = new EditMask(requestor);
    var em_1 = new EditMask(requestor);
    var sle_tmh = new SingleLineEdit(requestor);
    var dw_spda = new DataWindow(requestor);
    var dw_mx_top = new DataWindow(requestor);
    var dw_mx = new DataWindow(requestor);
    var dw_tmbc = new DataWindow(requestor);
    var dw_print = new DataWindow(requestor);
    var dw_parameter = new DataWindow(requestor);
    var dw_init = new DataWindow(requestor);
    var dw_3 = new DataWindow(requestor);
    var dw_proxy = new DataWindow(requestor);
    var dw_pzbtm = new DataWindow(requestor);
    var dw_sort = new DataWindow(requestor);
    var dw_da_qx_mokuai = new DataWindow(requestor);
    var dw_xt_div_tree_no_parm = new DataWindow(requestor);
    var dw_xt_print_print2_cmzbm = new DataWindow(requestor);
    var dw_2 = new DataWindow(requestor);
    var sle_pptmfa_Value = new SingleLineEdit(requestor);
    var dw_ls_flda = new DataWindow(requestor);
    var dw_ddmx_top_tmlr = new DataWindow(requestor);
    var dw_import_PL = new DataWindow(requestor);
    var dw_1 = new DataWindow(requestor);
    var dw_ddfs = new DataWindow(requestor);
    var dw_da_qx_mokuai_print = new DataWindow(requestor);
    var dw_ysbx = new DataWindow(requestor);
    var dw_4 = new DataWindow(requestor);
    var dw_tmjqfs = new DataWindow(requestor);
    var dw_35_kc = new DataWindow(requestor);
    var tb_1 = new ToolStrip(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_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 (mle_1 == null) mle_1 = new MultiLineEdit(requestor);
        mle_1.Attach(win.Control("mle_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 (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 (em_2 == null) em_2 = new EditMask(requestor);
        em_2.Attach(win.Control("em_2"));
        if (em_1 == null) em_1 = new EditMask(requestor);
        em_1.Attach(win.Control("em_1"));
        if (sle_tmh == null) sle_tmh = new SingleLineEdit(requestor);
        sle_tmh.Attach(win.Control("sle_tmh"));
        if (dw_spda == null) dw_spda = new DataWindow(requestor);
        dw_spda.Attach(win.Control("dw_spda"));
        if (dw_mx_top == null) dw_mx_top = new DataWindow(requestor);
        dw_mx_top.Attach(win.Control("dw_mx_top"));
        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 (dw_print == null) dw_print = new DataWindow(requestor);
        dw_print.Attach(win.Control("dw_print"));
        if (dw_parameter == null) dw_parameter = new DataWindow(requestor);
        dw_parameter.Attach(win.Control("dw_parameter"));
        if (dw_init == null) dw_init = new DataWindow(requestor);
        dw_init.Attach(win.Control("dw_init"));
        if (dw_3 == null) dw_3 = new DataWindow(requestor);
        dw_3.Attach(win.Control("dw_3"));
        if (dw_proxy == null) dw_proxy = new DataWindow(requestor);
        dw_proxy.Attach(win.Control("dw_proxy"));
        if (dw_pzbtm == null) dw_pzbtm = new DataWindow(requestor);
        dw_pzbtm.Attach(win.Control("dw_pzbtm"));
        if (dw_sort == null) dw_sort = new DataWindow(requestor);
        dw_sort.Attach(win.Control("dw_sort"));
        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_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_2 == null) dw_2 = new DataWindow(requestor);
        dw_2.Attach(win.Control("dw_2"));
        if (sle_pptmfa_Value == null) sle_pptmfa_Value = new SingleLineEdit(requestor);
        sle_pptmfa_Value.Attach(win.Control("sle_pptmfa_Value"));
        if (dw_ls_flda == null) dw_ls_flda = new DataWindow(requestor);
        dw_ls_flda.Attach(win.Control("dw_ls_flda"));
        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_import_PL == null) dw_import_PL = new DataWindow(requestor);
        dw_import_PL.Attach(win.Control("dw_import_PL"));
        if (dw_1 == null) dw_1 = new DataWindow(requestor);
        dw_1.Attach(win.Control("dw_1"));
        if (dw_ddfs == null) dw_ddfs = new DataWindow(requestor);
        dw_ddfs.Attach(win.Control("dw_ddfs"));
        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_ysbx == null) dw_ysbx = new DataWindow(requestor);
        dw_ysbx.Attach(win.Control("dw_ysbx"));
        if (dw_4 == null) dw_4 = new DataWindow(requestor);
        dw_4.Attach(win.Control("dw_4"));
        if (dw_tmjqfs == null) dw_tmjqfs = new DataWindow(requestor);
        dw_tmjqfs.Attach(win.Control("dw_tmjqfs"));
        if (dw_35_kc == null) dw_35_kc = new DataWindow(requestor);
        dw_35_kc.Attach(win.Control("dw_35_kc"));
        if (tb_1 == null) tb_1 = new ToolStrip(requestor);
        tb_1.Attach(win.Control("tb_1"));
        if (ddlb_1 == null) ddlb_1 = new DropDownListBox(requestor);
        ddlb_1.Attach(win.Control("ddlb_1"));
        if (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_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.Znsm) == "function")
            win.AttachEvent("cb_sm", "Clicked", self.Znsm);

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

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

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

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

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

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

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

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

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

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

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

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

        if (typeof (self.Exit) == "function")
            win.AttachEvent("btn_Exit", "Clicked", self.Exit);

        if (typeof (self.SyncSpkh) == "function")
            win.AttachEvent("btn_1", "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.ImportTxt) == "function")
            win.AttachEvent("rbn_drTxt", "Clicked", self.ImportTxt);

        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.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_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;
        mle_1.Detach(); mle_1 = null;
        dw_hz.Detach(); dw_hz = null;
        dw_mkfhjb.Detach(); dw_mkfhjb = null;
        sc_1.Detach(); sc_1 = null;
        cb_sm.Detach(); cb_sm = null;
        em_2.Detach(); em_2 = null;
        em_1.Detach(); em_1 = null;
        sle_tmh.Detach(); sle_tmh = null;
        dw_spda.Detach(); dw_spda = null;
        dw_mx_top.Detach(); dw_mx_top = null;
        dw_mx.Detach(); dw_mx = null;
        dw_tmbc.Detach(); dw_tmbc = null;
        dw_print.Detach(); dw_print = null;
        dw_parameter.Detach(); dw_parameter = null;
        dw_init.Detach(); dw_init = null;
        dw_3.Detach(); dw_3 = null;
        dw_proxy.Detach(); dw_proxy = null;
        dw_pzbtm.Detach(); dw_pzbtm = null;
        dw_sort.Detach(); dw_sort = 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_xt_print_print2_cmzbm.Detach(); dw_xt_print_print2_cmzbm = null;
        dw_2.Detach(); dw_2 = null;
        sle_pptmfa_Value.Detach(); sle_pptmfa_Value = null;
        dw_ls_flda.Detach(); dw_ls_flda = null;
        dw_ddmx_top_tmlr.Detach(); dw_ddmx_top_tmlr = null;
        dw_import_PL.Detach(); dw_import_PL = null;
        dw_1.Detach(); dw_1 = null;
        dw_ddfs.Detach(); dw_ddfs = null;
        dw_da_qx_mokuai_print.Detach(); dw_da_qx_mokuai_print = null;
        dw_ysbx.Detach(); dw_ysbx = null;
        dw_4.Detach(); dw_4 = null;
        dw_tmjqfs.Detach(); dw_tmjqfs = null;
        dw_35_kc.Detach(); dw_35_kc = null;
        tb_1.Detach(); tb_1 = 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  设计器查找标志,请不要删除或修改

    var editMode = "";
    var webReq = new WebRequestor();
    var curW_OPEN_SIMPLE_CHOSE = new OpenWindowSimpleChoseBase();
    webReq.SetWebServiceUrl("/Service/ServiceDiaoBo.ashx");
    var webReq1 = new WebRequestor();
    webReq1.SetWebServiceUrl("/Service/ServiceKuCunGuanLi.ashx");

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

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


    var cur_W_TXTDR = new W_TXTDR();
    var curRowCount = 0;
    var reCurBigMax = 0;
    curSfqytmlsh = "0"     //是否启用条码流水号。 1启用，2不启用。
    var dwc = new DataWindowChild();
    var curSpkh = "";
    var curUpdateOldSt = "";
    var G_bEditFlag = false;
    var isAdd = false;
    var curSaoMiaoLie = 0;
    var cur_W_YW_ZNSM_DBYW = new W_YW_ZNSM_DBYW();
    var curW_DiaoBo_ChaXun = new W_DiaoBo_ChaXun();
    var curW_OPEN_BMDA = new OpenWindowQueryBase();
    var curBmbhAndBmmc = null; // 本单据默认部门！！！名称
    var curDjlx = "";
    var curYhbh = "";
    var curJdbh = "";
    var curQxlx = "";
    var curJjfs = ""; 
    var curJjfsDrkh = ""; 
    var curQjfs = "";
    var bxshow = "";       //版型是否显示
    var jqd = 0;
    var jqw = 0;
    var qybz = 0;
    var curGnqxStr = "";    //功能权限
    var curDygs = "1"; // 打印格式默认是1 二维格式。
    var curDypx = "1"; // 打印排序
    var title_value = "";
    var curSjc = "";
    var curTmlrms = ""; //条码录入模式
    var curDw = null;
    var SQL_Dw = null;
    var curYxfkcBmbh = "";   //已调用的检查负库存的部门编号
    var curSfyxfkc = "N";    //是否允许负库存

    var curCmBtRows = 0;
    var curCmBtCols = 0;
    var curCmBtRows1 = 0;
    var curCmBtCols1 = 0;
    //价格体系#是否按发货类型折扣#是否按订货出库#是否控制调换率#调换精确度#范围外调换处理#管理库存
    var curKhxx = "";
    var curKhxxDrkh = "";
    var curOldSpkh = "";
    var curJsqYS = 0;  //计数器颜色
    var curJsqBX = 0;  //计数器版型
    var curSpkhYsbhBxbh = "";  //当前行的【款号+颜色+版型】
    var curSpkhYsbhBxbhSFGetKCSL = "N"; //
    var curRedCm = "";  //当前变红的列。
    var curLastFocusColumn = "";
    var curW_PH_FenJian_List = new W_PH_FenJian_List();
    var curSfQyQDID = "0";  // 如果启用渠道ID,默认不启用
    var curJqm = "";
    var curQxLzfc = "";    // 当前用户对应权限的列字符串；
    var curDrbmRyJzbz = "1"; //调拨入库单记账时是否由调入部门人员记账 1表示是
    var curSetDisCount = 0; //整单折扣是否控制
    var curSelDays = ""; //默认该模块可查询天数
    var curSelSQL = "";
    var flag = "";
    var isPast = "N";
    var curSYGysbh = ""; //首页的供应商
    var curSYBmbh = ""; //首页的部门

    var curSftmsl = "N"; //为了解决扫描的时候 如果原来有值，当输入到大于库存数的时候，提示后 给当前数先+1，再-1；为了保留原来的数字
    var curFunctionId = "";
    var openflag = "";
    var mxflag = "";
    var curSFQYXTRZ = "";

    var curSfQYQXZ = "0";  // 是否启用新版权限组。
    var curUserGroupId = ""; //权限组编码
    var cur_W_HYHKDR = new W_HYHKDR();
    var curGdhdy = "0"; //固定行打印，默认不是固定行打印
    var curFormPzh = ""; //外边Pzh反调
    var zhengdanzhekouFlag = "N";
    var curQjfs = ""; //结算价取价方式
    var curSaveReturnValue = "N"
    var SelectTabFlag = "Y";
    var cueSmzt = "0"; //扫描状态；0单扫，1连扫
    var curSysteData = "";   //条码流水号打印用的。
    var curDbjs = ""; //调拨结算参数
    var curSfdzd = "0";
    var curMrbm = "";
    var curSFQYSJKZQ = "1";
    var curGlkc = "0"; //  1：管理库存；0：不管理库存
    //#region 记录条码流水号需要变量
    var curSmKcFlag = "Y";
    var curCompanyidLength = "";
    var curCompanyid = "";
    var curTmlshDeleteTimestamp = "";
    //#endregion 记录条码流水号需要变量
    //#region this.PostOpen
    this.PostOpen = function () {

        curSFQYSJKZQ = GetGlobalParm("XTCS", "SFQYSJKZQ", "qybz");
        dw_mx_top.Modify("dbck.protect='1'")
        curSysteData = requestor.GetParm("curDate");
        curDbjs = GetGlobalParm("XTCS", "SFQYDBJS", "qybz");
        curSysteData = curSysteData.replace(" ", "");
        curSfQyQDID = GetGlobalParm("XTCS", "SFQYQDID", "qybz");
        curSFQYXTRZ = GetGlobalParm("XTCS", "XT_LOG", "qybz");
        curSfQYQXZ = GetGlobalParm("XTCS", "SFQYQXZ-NEW", "qybz"); // 是否启用新版权限组。
        curUserGroupId = requestor.GetParm("curUserGroupId"); //权限组编码
        curJqm = requestor.GetParm("curJqm");
        curSelDays = requestor.GetParm("seldays");
        // self.InitQx();// 初始化权限
        curSYBmbh = requestor.GetParm("curBmbh");
        curSYGysbh = requestor.GetParm("curGysbh");
        curFunctionId = requestor.GetParm("curFunctionId");
        curFormPzh = requestor.GetParm("curFormPzh"); //从外界传入的凭证
        curSaveReturnValue = "N"
        var curQTPzh = requestor.GetParm("curQTPzh");
        curDzdPzh = requestor.GetParm("curDzdPzh");
        if (curDzdPzh.length > 0) {
            curSfdzd = "1";
        }

        curSfqytmlsh = requestor.GetParm("curSfqytmlsh");
        curDzdPzh = requestor.GetParm("curDzdPzh");
        if (dw_hz.RowCount() <= 0) {
            //self.Add();
        }
        else {
            self.SetEditMode("");
        }
        //#region 初始化数据窗口的title,单据类型


        curQxlx = requestor.GetParm("curQxlx");
        curYhbh = requestor.GetParm("curYhbh");
        curJdbh = requestor.GetParm("curJdbh");

        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;
        }


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


        //#region 业务精确度
        jqd = parseFloat(requestor.GetParm("curJqd").toString());
        jqw = parseInt(requestor.GetParm("curJqw").toString());

        if (jqw == "0") {
            dw_mx.Modify("lsj.editmask.mask='#########0'");
            dw_mx.Modify("lsjze.editmask.mask='#########0'");
            dw_mx.Modify("sumjsje.editmask.mask='#########0'");
            dw_hz.Modify("zjje.editmask.mask='#########0'");
            dw_hz.Modify("sum_zjje.editmask.mask='#########0'");

            dw_mx.Modify("lsj.editmask.mask='#########0'")
            dw_mx.Modify("lsjze.editmask.mask='#########0'")

        }
        else if (jqw == "1") {
            dw_mx.Modify("lsj.editmask.mask='#########0.0'");
            dw_mx.Modify("lsjze.editmask.mask='#########0.0'");
            dw_mx.Modify("sumjsje.editmask.mask='#########0.0'");
            dw_hz.Modify("zjje.editmask.mask='#########0.0'");
            dw_hz.Modify("sum_zjje.editmask.mask='#########0.0'");

            dw_mx.Modify("  lsj.editmask.mask='#########0.0' ")
            dw_mx.Modify("  lsjze.editmask.mask='#########0.0' ")
            //dw_mx.Modify("  sumjsje.editmask.mask='########.0' ")

        }
        else if (jqw == "2") {
            dw_mx.Modify("lsj.editmask.mask='#########0.00'");
            dw_mx.Modify("lsjze.editmask.mask='#########0.00'");
            dw_mx.Modify("sumjsje.editmask.mask='#########0.00'");
            dw_hz.Modify("zjje.editmask.mask='#########0.00'");
            dw_hz.Modify("sum_zjje.editmask.mask='#########0.00'");

            dw_mx.Modify("  lsj.editmask.mask='#########0.00' ")
            dw_mx.Modify("  lsjze.editmask.mask='#########0.00' ")
            //dw_mx.Modify("  sumjsje.editmask.mask='########.00' ")
        }
        else if (jqw == "3") {
            dw_mx.Modify("lsj.editmask.mask='#########0.000'");
            dw_mx.Modify("lsjze.editmask.mask='#########0.000'");
            dw_mx.Modify("sumjsje.editmask.mask='#########0.000'");
            dw_hz.Modify("zjje.editmask.mask='#########0.000'");
            dw_hz.Modify("sum_zjje.editmask.mask='#########0.000'");

            dw_mx.Modify("  lsj.editmask.mask='#######0.000' ")
            dw_mx.Modify("  lsjze.editmask.mask='#######0.000' ")
            // dw_mx.Modify("  sumjsje.editmask.mask='########.000' ")
        }

        //#endregion

        qybz = parseInt(requestor.GetParm("curQybz").toString());

        bxshow = parseInt(requestor.GetParm("bxshow").toString());

        if (requestor.GetParm("QJFS") == "ERROR") {
            alert("系统基础价取价方式获取错误！\n请检查参数档案!");
            return;
        } else {
            curQjfs = requestor.GetParm("QJFS");
        }

        dw_mx_top.Modify("DataWindow.Readonly=yes");
        dw_mx.Modify("DataWindow.Readonly=yes");
        em_1.SetEnabled(false); em_2.SetEnabled(false);
        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);
        }
        em_1.SetEnabled(false);
 em_2.SetEnabled(false);
 
         
    

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

        //                if (curDzdPzh.length > 0) {
        //                    dw_hz.Retrieve(curDzdPzh);
        //                    if (dw_hz.RowCount() > 0) {
        //                        self.dw_hz_DoubleClicked(0, 0, 1, "");
        //                    }
        //                }

        dw_mx_top.Modify("bzxx.edit.autohscroll=yes");

        //控制结算价

        if (curGnqxStr.indexOf("btn_AlterJsj") > -1) {
            dw_mx.Modify("lsj.protect='1'");
            dw_mx.Modify("zkl.protect='1'");

        } else {
            dw_mx.Modify("lsj.protect='0'");
            dw_mx.Modify("zkl.protect='0'");
        }
        //#endregion
        curCompanyidLength = requestor.GetParm("companyidLength");
        curCompanyid = requestor.GetParm("companyid");
    }
    //#endregion


//    this.fjsm = function () {
//        dw_mx_top.AcceptText();
//        var itemData = "SJ893";
//        var itemLabel = "分拣扫描";
//        var ts_1 = window.external.Control("ts_1");
//        var curPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
//        var curKdsj = UtcDateFormatToString(dw_mx_top.GetItemDate(1, "kdrq"));
//        ts_1.CloseItem(itemData);
//        ts_1.Open(itemData, itemLabel, '', "/Service/OpenSheet.aspx?FunID=" + itemData + "&curDate=" + new Date().toLocaleTimeString() + "&curFormYwlx=DB&curFormPzh=" + curPzh + "&kdsj=" + curKdsj, true);
//    }

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

            tb_1.SetEnabled("btn_Edit", false);
            tb_1.SetEnabled("btn_Delete", false);
            tb_1.SetEnabled("btn_Audit", false);
            tb_1.SetEnabled("btn_UnAudit", false);
            tb_1.SetEnabled("btn_Tally", false);
            tb_1.SetEnabled("btn_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) {
        A8erp_Biz_Scan.Yw_Dw_Mx_EditChanged(dw_mx, dwc, row, dwoName, data);
    }
    //#endregion
//    this.dw_mx_top_focus_changed = function (row, dwoName, data) {
//        alert([dwoName]);
//    }

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

        //#region 处理负库存

        var curBmbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "dckh");
        if (curBmbh == "") {
            return;
        }
    //    alert([curGlkc]);
        if (curGlkc == "1") {
            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";         //不允许负库存  
                    }

                   // alert("curSfyxfkc1=" + curSfyxfkc);
                } else {
                   // alert("curGlkc=" + curGlkc);
                    if (curGlkc != "1") {

                        curSfyxfkc = "Y";         //允许负库存      
                    } else {

                        curSfyxfkc = "N";         //允许负库存     
                    }
                    // requestor.MessageBox("提示33", "是否允许负库存获取失败", ICON.StopSign);
                   // alert("curSfyxfkc2=" + curSfyxfkc);
                    return;
                }
            }
        } else {
            curSfyxfkc = "Y";         //允许负库存      
        }

        //#endregion

        if (dwoName.substring(0, 2) == "cm" && dwoName.indexOf("cmz") < 0) {

            // 处理库存的问题 --------begin-------
            self.setKCSL("", "", "", data, "");
            // 处理库存的问题 --------end---------     
            // 处理点亮的问题 --------begin-------
            self.setMdf(row, dwoName, dw_mx.GetItemString(dw_mx.GetRow(), "spkh"));
            // 处理点亮的问题 --------end---------
        }
        curLastFocusColumn = dw_mx.GetColumnName();
        if (dw_mx.RowCount() > 0) {
            dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "sumzjsl") + "' ");
            dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "sumzjsl"));
        } else {
            dw_mx_top.Modify(" countsl.text='0' ");
            dw_mx_top.SetItem(1, "zjsl", 0);
        }

    }
    //#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, "dckh") == "") {

            alert("请选择调出客户!");
            dw_mx_top.SetColumn("dckh");
            dw_mx_top.SetFocus();
            return;
        }
        if (dw_mx_top.GetItemString(1, "drkh") == "") {

            alert("请选择调入客户!");
            dw_mx_top.SetColumn("drkh");
            dw_mx_top.SetFocus();
            return;
        } 
         if (dw_mx_top.GetItemString(1, "zzck") == "") {

            alert("请选择中转仓库!");
            dw_mx_top.SetColumn("zzck");
            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");
            curYsbh = dw_mx.GetItemString(row, "ysbh");
            if (curSpkh.length < 1) {
                return;
            }
            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, "bxmc");
            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, flag) {
        var curCkbh = "";
        var curJSJ = 0;
        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, "cmzbh", "");

                    dw_mx.SetItem(row, "thj", 0);
                    dw_mx.SetItem(row, "thzk", 1);

                    dw_mx.SetItem(row, "xsj", 0);
                    dw_mx.SetItem(row, "xszk", 1);

                    requestor.MessageBox("提示[款号]", "未找到款号为[" + data + "]的记录，请检查!", ICON.StopSign);
                    return 1;
                } else {
                    curOldSpkh = data;
                    var curDckh = dw_mx_top.GetItemString(1, "dckh");
                    var curDrkh = dw_mx_top.GetItemString(1, "drkh");
                    var curZzck = dw_mx_top.GetItemString(1, "zzck");
                    // alert([data, curDckh, "pf", curJjfs + "#" + curZzck, curQjfs]);
                    dw_ls_flda.Retrieve(data, curDckh, "pf", curJjfs + "#" + curZzck, curQjfs);

                    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, "lsj", dw_ls_flda.GetItemNumber(1, "lsjg"));
                    dw_mx.SetItem(row, "dpj", dw_ls_flda.GetItemNumber(1, "dpjg"));

                    //#region 退货价
                    if (curJjfs == "ZKZZ" && dw_ls_flda.GetItemNumber(1, "pfzk") != 999) {
                        if (curQjfs == "QDPJ") {
                            dw_mx.SetItem(row, "thj", dw_ls_flda.GetItemNumber(1, "dpjg") * dw_ls_flda.GetItemNumber(1, "pfzk"));
                            self.setJGJqd(row, dw_ls_flda.GetItemNumber(1, "dpjg") * dw_ls_flda.GetItemNumber(1, "pfzk"));
                        }
                        if (curQjfs == "QLSJ") {
                            dw_mx.SetItem(row, "thj", dw_ls_flda.GetItemNumber(1, "lsjg") * dw_ls_flda.GetItemNumber(1, "pfzk"));
                            self.setJGJqd(row, dw_ls_flda.GetItemNumber(1, "lsjg") * dw_ls_flda.GetItemNumber(1, "pfzk"));
                        }
                    }
                    else {
                        dw_mx.SetItem(row, "thj", dw_ls_flda.GetItemNumber(1, "pfjg1"));
                        self.setJGJqd(row, dw_ls_flda.GetItemNumber(1, "pfjg1"));
                    }

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


                    if (curQjfs == "QDPJ") {
                        if (dw_ls_flda.GetItemNumber(1, "dpjg") == 0)
                            dw_mx.SetItem(row, "thzk", 1);
                        else {
                            if (curJjfs == "ZKZZ" && dw_ls_flda.GetItemNumber(1, "pfzk") != 999) {
                                dw_mx.SetItem(row, "thzk", dw_ls_flda.GetItemNumber(1, "pfzk"));
                            }
                            else {
                                if (dw_ls_flda.GetItemNumber(1, "pfjg1") == 0 || dw_ls_flda.GetItemNumber(1, "dpjg") == 0) {
                                    dw_mx.SetItem(row, "thzk", 1);
                                } else {
                                    dw_mx.SetItem(row, "thzk", dw_ls_flda.GetItemNumber(1, "pfjg1") / dw_ls_flda.GetItemNumber(1, "dpjg"));
                                }
                            }

                        }
                    }

                    if (curQjfs == "QLSJ") {
                        if (dw_ls_flda.GetItemNumber(1, "lsjg") == 0)
                            dw_mx.SetItem(row, "thzk", 1);
                        else {
                            if (curJjfs == "ZKZZ" && dw_ls_flda.GetItemNumber(1, "pfzk") != 999) {
                                dw_mx.SetItem(row, "thzk", dw_ls_flda.GetItemNumber(1, "pfzk"));
                            }
                            else {
                                if (dw_ls_flda.GetItemNumber(1, "pfjg1") == 0 || dw_ls_flda.GetItemNumber(1, "lsjg") == 0) {
                                    dw_mx.SetItem(row, "thzk", 1);
                                } else {
                                    dw_mx.SetItem(row, "thzk", dw_ls_flda.GetItemNumber(1, "pfjg1") / dw_ls_flda.GetItemNumber(1, "lsjg"));
                                }
                            }

                        }
                    }
                    //#endregion
                    // alert([data, curDrkh, "pf", curJjfsDrkh + "#" + curZzck, curQjfs]);
                    //#region 销售价
                    dw_ls_flda.Retrieve(data, curDrkh, "pf", curJjfsDrkh + "#" + curZzck, curQjfs);
                    if (curJjfsDrkh == "ZKZZ" && dw_ls_flda.GetItemNumber(1, "pfzk") != 999) {
                        if (curQjfs == "QDPJ") {
                            dw_mx.SetItem(row, "xsj", dw_ls_flda.GetItemNumber(1, "dpjg") * dw_ls_flda.GetItemNumber(1, "pfzk"));
                            self.setJGJqdXsj(row, dw_ls_flda.GetItemNumber(1, "dpjg") * dw_ls_flda.GetItemNumber(1, "pfzk"));
                        }
                        if (curQjfs == "QLSJ") {
                            dw_mx.SetItem(row, "xsj", dw_ls_flda.GetItemNumber(1, "lsjg") * dw_ls_flda.GetItemNumber(1, "pfzk"));
                            self.setJGJqdXsj(row, dw_ls_flda.GetItemNumber(1, "lsjg") * dw_ls_flda.GetItemNumber(1, "pfzk"));
                        }
                    }
                    else {
                        dw_mx.SetItem(row, "xsj", dw_ls_flda.GetItemNumber(1, "pfjg1"));
                        self.setJGJqdXsj(row, dw_ls_flda.GetItemNumber(1, "pfjg1"));
                    }

                    dw_mx.SetItem(row, "cmzbh", dw_ls_flda.GetItemString(1, "cmzbm"));
                    if (curQjfs == "QDPJ") {
                        if (dw_ls_flda.GetItemNumber(1, "dpjg") == 0)
                            dw_mx.SetItem(row, "xszk", 1);
                        else {
                            if (curJjfs == "ZKZZ" && dw_ls_flda.GetItemNumber(1, "pfzk") != 999) {
                                dw_mx.SetItem(row, "xszk", dw_ls_flda.GetItemNumber(1, "pfzk"));
                            }
                            else {
                                if (dw_ls_flda.GetItemNumber(1, "pfjg1") == 0 || dw_ls_flda.GetItemNumber(1, "dpjg") == 0) {
                                    dw_mx.SetItem(row, "xszk", 1);
                                } else {
                                    dw_mx.SetItem(row, "xszk", dw_ls_flda.GetItemNumber(1, "pfjg1") / dw_ls_flda.GetItemNumber(1, "dpjg"));
                                }
                            }

                        }
                    }

                    if (curQjfs == "QLSJ") {
                        if (dw_ls_flda.GetItemNumber(1, "lsjg") == 0)
                            dw_mx.SetItem(row, "xszk", 1);
                        else {
                            if (curJjfs == "ZKZZ" && dw_ls_flda.GetItemNumber(1, "pfzk") != 999) {
                                dw_mx.SetItem(row, "xszk", dw_ls_flda.GetItemNumber(1, "pfzk"));
                            }
                            else {
                                if (dw_ls_flda.GetItemNumber(1, "pfjg1") == 0 || dw_ls_flda.GetItemNumber(1, "lsjg") == 0) {
                                    dw_mx.SetItem(row, "xszk", 1);
                                } else {
                                    dw_mx.SetItem(row, "xszk", dw_ls_flda.GetItemNumber(1, "pfjg1") / dw_ls_flda.GetItemNumber(1, "lsjg"));
                                }
                            }

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

                    }

                    if (flag != "Y") {
                        for (var i = 1; i < curCmBtCols1; i++) {
                            dw_mx.SetItem(row, "cm" + i, 0);
                        }
                    }
                    // 处理点亮的问题 --------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(), "dpj", 0);
                dw_mx.SetItem(dw_mx.GetRow(), "lsj", 0);
                dw_mx.SetItem(dw_mx.GetRow(), "xszk", 1);
                dw_mx.SetItem(dw_mx.GetRow(), "thzk", 1);
                dw_mx.SetItem(dw_mx.GetRow(), "cmzbh", "");
                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") {

            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("提示689", "没有此商品编号", 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("提示703", "没有此商品编号", 1);
                        dw_mx.SetItem(row, "cm" + cNo, 0);
                        if (cNo >= curEnd) {// 到边境的时候跳到价格去
                            if (dw_mx.Describe("thj.visible") == '1') {
                                dw_mx.SetColumn("thj");
                            } else {
                                dw_mx.AcceptText();
                            }
                        } else {//没到边境的时候跳到下一个位置去
                            if (flag != "Y") {
                                dw_mx.SetColumn("cm" + parseInt(cNo+1));
                            } else {
                                dw_mx.SetColumn("cm" + parseInt(cNo));
                            }
                        }

                        dw_mx.SetFocus();
                        return 1;
                    } else {
                        //#region 采购退的时候要检查是否允许负库存,  curSfyxfkc == "Y" 允许，否则不允许 
                        //   alert(curSfyxfkc)
                        if (curSfyxfkc == "N") {
                            if (self.JudgeKc(row, dwoName, data) == 0) {
                                // dw_mx.SetItem(row, dwoName, 0);
                                if (flag != "Y") {
                                    if (curSftmsl == "Y") {
                                        dw_mx.SetItem(row, dwoName, dw_mx.GetItemNumber(row, dwoName) - 1);
                                        curSftmsl = "N";
                                    } else {
                                        dw_mx.SetItem(row, dwoName, 0);
                                    }
                                } else {
                                    dw_mx.AcceptText();
                                    dw_mx.SetItem(row, dwoName, dw_mx.GetItemNumber(row, dwoName) - 1);
                                }
                                dw_mx.SetColumn(dwoName);
                                dw_mx.SetFocus();
                                return 1;
                            }
                        }
                        //#endregion
                        //精确度，小数位数以及舍入
                        self.setJGJqd(row, dw_mx.GetItemNumber(row, "thj"));
                        self.setJGJqdXsj(row, dw_mx.GetItemNumber(row, "xsj"));
                        if (cNo >= curEnd) {// 到边境的时候跳到价格去
                            if (dw_mx.Describe("thj.visible") == '1') {
                                dw_mx.SetColumn("thj");
                            } else {
                                dw_mx.AcceptText();
                            }
                        } else {//没到边境的时候跳到下一个位置去
                            if (flag != "Y") {
                                dw_mx.SetColumn("cm" + parseInt(cNo+1));
                            } else {
                                dw_mx.SetColumn("cm" + parseInt(cNo));
                            }
                        }
                        dw_mx.SetFocus();
                        return 1;
                    }
                }
            }
        }
        else if (dwoName == "thzk" && parseFloat(data) >= 0 && parseFloat(data) <= 1) {
            if (curQjfs == "QDPJ")
                self.setJGJqd(row, dw_mx.GetItemNumber(row, "dpj") * parseFloat(data));
            else
                self.setJGJqd(row, dw_mx.GetItemNumber(row, "lsj") * parseFloat(data));
        }
        else if (dwoName == "thj") {
            if (parseFloat(data) >= 0) {

                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, "thj", zhjg);
                if (curQjfs == "QDPJ") {
                    if (dw_mx.GetItemNumber(row, "dpj") == 0)
                        dw_mx.SetItem(row, "thzk", 1);
                    else
                        dw_mx.SetItem(row, "thzk", zhjg / dw_mx.GetItemNumber(row, "dpj"));
                }
                else {
                    if (dw_mx.GetItemNumber(row, "lsj") == 0)
                        dw_mx.SetItem(row, "thzk", 1);
                    else
                        dw_mx.SetItem(row, "thzk", zhjg / dw_mx.GetItemNumber(row, "lsj"));
                }

                return 1;
            } else {
                requestor.MessageBox("提示", "输入有误！", ICON.Information);
                dw_mx.SetItem(row, dwoName, 0);
                return 1;
            }
        } else if (dwoName == "xszk" && parseFloat(data) >= 0 && parseFloat(data) <= 1) {
            if (curQjfs == "QDPJ")
                self.setJGJqdXsj(row, dw_mx.GetItemNumber(row, "dpj") * parseFloat(data));
            else
                self.setJGJqdXsj(row, dw_mx.GetItemNumber(row, "lsj") * parseFloat(data));
        }
        else if (dwoName == "xsj") {
            if (parseFloat(data) >= 0) {

                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, "xsj", zhjg);
                if (curQjfs == "QDPJ") {
                    if (dw_mx.GetItemNumber(row, "dpj") == 0)
                        dw_mx.SetItem(row, "xszk", 1);
                    else
                        dw_mx.SetItem(row, "xszk", zhjg / dw_mx.GetItemNumber(row, "dpj"));
                }
                else {
                    if (dw_mx.GetItemNumber(row, "lsj") == 0)
                        dw_mx.SetItem(row, "xszk", 1);
                    else
                        dw_mx.SetItem(row, "xszk", zhjg / dw_mx.GetItemNumber(row, "lsj"));
                }

                return 1;
            } else {
                requestor.MessageBox("提示", "输入有误！", ICON.Information);
                dw_mx.SetItem(row, dwoName, 0);
                return 1;
            }
        }

    }
    //#endregion

    //#region this.setJGJqd 
    this.setJGJqd = function (row, lsj) {

        var jg = GetAccAdd(lsj, jqd);
        var len = (jg.toString()).split(".")[0].length + 1 + jqw;
        var zhjg = parseFloat((jg.toString()).substring(0, len));
        dw_mx.SetItem(row, "thj", zhjg);

        return 1;
    }
    //#endregion


    //#region this.setJGJqd 
    this.setJGJqdXsj = function (row, lsj) {

        var jg = GetAccAdd(lsj, jqd);
        var len = (jg.toString()).split(".")[0].length + 1 + jqw;
        var zhjg = parseFloat((jg.toString()).substring(0, len));
        dw_mx.SetItem(row, "xsj", zhjg);

        return 1;
    }
    //#endregion

    //#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) {
            curColors = curLastChangecolor
        } else {
            curLastChangecolorSpkh = curSpkh;
            dw_mx.GetChild("spkh", dwc);
            if (curLastFocusColumn != "" && curLastFocusColumn != "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.setKCSL 设置库存数量
    this.setKCSL = function (bm, kh, ys, bx, cmStr) {

        dw_mx_top.AcceptText();
        dw_mx.AcceptText();
        var myBm = "";
        var myBmRk = "";
        var curPzh = dw_mx_top.GetItemString(1, "pzh");
   
       
            myBm = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "dckh"); // 部门
            myBmRk = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "drkh"); // 部门
       
   
        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") {

            return;
        } else {
            for (var i = 1; i < curCmBtCols1; i++) {
                dw_mx.Modify("kc" + i + "_t.Text='-'");
                dw_mx.Modify("rk" + i + "_t.Text='-'");
            }
        }
        curSpkhYsbhBxbh = myKh + myYs + myBx + dw_mx.GetRow();  //当前行的【款号+颜色+版型】
        curSpkhYsbhBxbhSFGetKCSL = "Y";

        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"));
        //#region 原本的出库方库存
      //  alert([myBm, myKh, myYs, myBx, myCmStr, myYwDate, "", requestor.GetParm("flag")])
        dw_35_kc.Retrieve(myBm, myKh, myYs, myBx, myCmStr, myYwDate, "", requestor.GetParm("flag")); //取库存数量
        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") == "DC" && 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 + "'");
                }
            }
        }
        //#endregion

        //#region 要显示入库方库存
 
            dw_35_kc.Retrieve(myBmRk, myKh, myYs, myBx, myCmStr, myYwDate, "", requestor.GetParm("flag")); //取库存数量
            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) {
 
        if (keyCode == 35) {
            dw_mx.AcceptText();
            if (dw_mx.GetItemNumber(dw_mx.GetRow(), "spsl") == 0) {
                requestor.MessageBox("提示", "请为当前行输入数量", 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(), "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(), "thj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "thj"));
                dw_mx.SetItem(dw_mx.RowCount(), "thzk", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "thzk"));
                dw_mx.SetItem(dw_mx.RowCount(), "xszk", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "xszk"));
                dw_mx.SetItem(dw_mx.RowCount(), "xsj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "xsj"));   
                dw_mx.SetItem(dw_mx.RowCount(), "cmzbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "cmzbh"));
                //复制行数据 ---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() == "thj") {
            if (keyCode == 13 || keyCode == 39) {
                if (dw_mx.GetItemNumber(dw_mx.GetRow(), "spsl") == 0) {
                    requestor.MessageBox("提示", "请为当前行输入数量", 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(), "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(), "thj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "thj"));
                    dw_mx.SetItem(dw_mx.RowCount(), "thzk", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "thzk"));
                    dw_mx.SetItem(dw_mx.RowCount(), "xszk", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "xszk"));
                    dw_mx.SetItem(dw_mx.RowCount(), "xsj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "xsj"));   
                    dw_mx.SetItem(dw_mx.RowCount(), "cmzbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "cmzbh"));
                    //复制行数据 ---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);

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

                        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("lsj.visible") == '1') {
                        dw_mx.SetColumn("lsj");
                    } else {
                        dw_mx.AcceptText();
                        if (dw_mx.GetItemNumber(dw_mx.GetRow(), "spsl") == 0) {
                            requestor.MessageBox("提示", "请为当前行输入数量", 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(), "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(), "thj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "thj"));
                            dw_mx.SetItem(dw_mx.RowCount(), "thzk", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "thzk"));
                            dw_mx.SetItem(dw_mx.RowCount(), "xszk", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "xszk"));
                            dw_mx.SetItem(dw_mx.RowCount(), "xsj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "xsj"));   
                            dw_mx.SetItem(dw_mx.RowCount(), "cmzbh", dw_mx.GetItemString(dw_mx.RowCount() - 1, "cmzbh"));
                            //复制行数据 ---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 {
                    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 (row > 0) {
            tab_1.SelectTab(2);
            //dw_mx.ShareDataOff();
            tb_1.SetEnabled("ddlb_1", false);
            tb_1.SetEnabled("btn_ChaXun", false);
            tb_1.SetEnabled("btn_Filter", false);
            tb_1.SetEnabled("btn_Export", true);
            var curPzh = dw_hz.GetItemString(row, "pzh");
            dw_mx_top.Retrieve(curPzh);
            dw_mx.Retrieve(curPzh);
           
        }
       // self.GetMaxXh();

    }
    //#endregion

    //#region 获取明细单号最大值
    this.GetMaxXh = function () {

//        if (dw_mx.RowCount() > 0) {
//            dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "sumzjsl") + "' ");
//            dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "sumzjsl"));
//            dw_mx_top.SetItem(1, "zjje", dw_mx.GetItemNumber(1, "sumjsje"));
//        } else {
//            dw_mx_top.Modify(" countsl.text='0' ");
//           // dw_mx_top.SetItem(1, "zjsl", 0);
//           // dw_mx_top.SetItem(1, "zjje", 0);
//        }
      var  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 curJzbz = "";
        if (row > 0) {

            tb_1.SetEnabled("btn_Trans", false);
            tb_1.SetEnabled("btn_Edit", false);
            tb_1.SetEnabled("btn_Save", false);
            tb_1.SetEnabled("btn_Delete", false);
            tb_1.SetEnabled("btn_InsertRow", false);
            tb_1.SetEnabled("btn_DeleteRow", false);
            tb_1.SetEnabled("btn_Cancel", false);
            tb_1.SetEnabled("btn_Tally", false);
            curJzbz = dw_hz.GetItemString(row, "jzbz");
      
            if (curJzbz == "√") {
                tb_1.SetEnabled("btn_Cancel", true);
            } else {
                tb_1.SetEnabled("btn_Tally", true);
                tb_1.SetEnabled("btn_Edit", true); 
                tb_1.SetEnabled("btn_Delete", true); 
                tb_1.SetEnabled("btn_Cancel", true);
            }
        }
    }
    //#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) {
        // 取尺码当前列ID
        var curColNo = dwoName.substring(2, dwoName.length);
        // 取尺码组编码
        var curChangecolor = self.GetChangecolor(data);
        if (curChangecolor.length > 0) {
            var mdf = new Array();
            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'"; // 行变粗，蓝色 
                    }
                    else {
                        cmzYs += " cm" + k + "0" + r + "_t.color='33554432'  cm" + k + "0" + r + "_t.Font.Weight='400'"; // 行变粗，蓝色
                    }
                }
            }
            dw_mx.Modify(cmzYs.toString());
            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;
            if (rowsNo > 1) {// 第一行 
                for (var a = curBeg; a <= curEnd; a++) { //循环咧        
                    if (a == curColNo && dwoName.substring(0, 2) == "cm") {// 当前点亮的列
                        dw_mx.Modify(" cm" + a + "0" + parseInt(rowsNo - 1) + "_t.color='255'  cm" + a + "0" + parseInt(rowsNo - 1) + "_t.Font.Weight='700'"); // 变红色
                        curRedCm = "cm" + a;
                    } 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 && dwoName.substring(0, 2) == "cm") {// 当前点亮的列
                        dw_mx.Modify(" cm" + a + "_t.color='255' cm" + a + "_t.Font.Weight='700'"); // 变红色
                        curRedCm = "cm" + a;
                    } else {
                        dw_mx.Modify(" cm" + a + "_t.color='16711680' cm" + a + "_t.Font.Weight='700'"); // 变蓝色
                    }
                }
            }
        }

    }

    //#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_DCFAudit", !bEditFlag);
        tb_1.SetEnabled("btn_Delete", !bEditFlag);
        tb_1.SetEnabled("btn_FenJian", !bEditFlag);
        tb_1.SetEnabled("btn_Audit", !bEditFlag);

        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);
em_2.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("bmbh2", dwc);
//            if (dwc.Find("bmbh='" + curBmbhAndBmmc.split("!!!")[0] + "'", 1, dwc.RowCount()) > 0) {
//                dw_mx_top.SetItem(1, "bmbh2", curBmbhAndBmmc.split("!!!")[0]);
//                dw_mx_top.SetItem(1, "bmmc2", 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, "kdr", curYhbh); 
      //  dw_mx_top.SetItem(1, "ywy", curYhbh);
//        if (ywbh == "DB") {
//            dw_mx_top.SetItem(1, "cgfs", "2");
//        }
//        else if (ywbh == "DZ") {
//            dw_mx_top.SetItem(1, "cgfs", "DBTZD");
//        }
//        else if (ywbh == "DR") {
//            dw_mx_top.SetItem(1, "cgfs", "CKDBRK");
//        }
//        else if (ywbh == "DC") {
//            dw_mx_top.SetItem(1, "cgfs", "CKDBCK");
//        }
        dw_mx.Reset();
        dw_mx.InsertRow(0)
        reCurBigMax = 1;
        self.SetEditMode("Add");
        isAdd = true;
        // 清空 审核章
      //  dw_mx_top.Modify("ysh_q_t.visible='0' ysh_t.visible='0' ysh_t.Text=''");
        //读取当地数据
        self.Page2Open();
        self.ClareKcAndCmzAll();
        dw_mx_top.Modify(" countsl.text='' ");
        dw_mx_top.SetItem(1, "zjsl", 0);
//        if (ControlDiscount(dw_mx, "DB") == "1") {
//            curSetDisCount = 1;
//        }
//        if (curSetDisCount == 1) {
//            em_1.SetEnabled(true);
//        }
//        else {
//            em_1.SetEnabled(false);
//         }
        tb_1.SetEnabled("ddlb_1", false);
 
     //   tb_1.SetEnabled("btn_ChaXun", false);
        tb_1.SetEnabled("btn_Filter", false);
        tb_1.SetEnabled("btn_Export", true);
        tb_1.SetEnabled("btn_Trans", false);
        tb_1.SetEnabled("btn_Tally", false);
        
        openflag = "Add"
        mxflag = openflag;
        //新增的时候。初始化折扣卡=1
        em_1.SetText("1"); 
        em_2.SetText("1");
        if (curSfqytmlsh == "1") {
            curSysteData = curSysteData + 1;
        }
//        if (requestor.GetParm("flag") == "DC") {
//            dw_mx_top.SetItem(1, "TmSmFlag", "0");
//            if (curSfqytmlsh == "1") {
//                dw_mx_top.Modify("tmsmflag.visible='1' ");
//            }
//            curTmlshDeleteTimestamp = new Date().getTime();
//            cb_sm.SetVisible(true);
//        }
    }
    //#endregion 
    this.sdSpxx = function () {
        if (requestor.GetParm("flag") == "DC" ) {
            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' ");
            }
        }
    }
    //#region this.Exit
    this.Exit = function () {

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

    //#region this.InsertRow
    this.InsertRow = function () {
        if (editMode == "")
            return;
        dw_mx.ScrollToRow(dw_mx.InsertRow(0));
        if (dw_mx.RowCount() > 1) {
            dw_mx.SetItem(dw_mx.GetRow(), "dpj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "dpj"));
            dw_mx.SetItem(dw_mx.GetRow(), "lsj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "lsj"));
            dw_mx.SetItem(dw_mx.GetRow(), "thzk", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "thzk"));
            dw_mx.SetItem(dw_mx.GetRow(), "thj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "thj"));
            dw_mx.SetItem(dw_mx.GetRow(), "xszk", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "xszk"));
            dw_mx.SetItem(dw_mx.GetRow(), "xsj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "xsj"));
            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());
        mxflag="Add"
    }
    //#endregion  

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

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

        dw_mx.DeleteRow(0);
        dw_mx.SetFocus();

    }
    //#endregion  

    //#region this.Cancel
    this.Cancel = function () {
//        if (requestor.MessageBox("提示", "数据还没有保存,是否继续取消?", 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("btn_ChaXun", true);
        tb_1.SetEnabled("btn_Filter", true);
        tb_1.SetEnabled("btn_Export", true);
        em_1.SetEnabled(false);
        em_2.SetEnabled(false);
        tb_1.SetEnabled("btn_InsertRow", false);
        tb_1.SetEnabled("btn_DeleteRow", false);
        tb_1.SetEnabled("btn_Save", false);  
        isAdd = false;
        self.SelectionChanged();
        var findRow = dw_hz.Find("pzh='" + pzh + "'", 1, dw_hz.RowCount());
        if (findRow > 0) {
            dw_hz.ScrollToRow(findRow);
        }
        cb_sm.SetVisible(false);
        sle_tmh.SetVisible(false);
    }
    //#endregion  

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

        var row = dw_hz.GetRow();
 
        if (row <= 0)
            return;
 
        if (self.CheckJzbz()) {
            return;
        }
 
        //#region 处理时间戳，【判断是否被占用】---------------begin--------------

        //        webReqTimestamp.Invoke("YW_TIMESTAMP_REC", "curPzh=" + dw_hz.GetItemString(dw_hz.GetRow(), "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----------------

        dw_hz.ReSelectRow(row);
        dw_hz.RefreshDetails();
        tab_1.SelectTab(2);
        self.SetEditMode("Edit");
        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"));
        }

        // self.GetMaxXh();

        tb_1.SetEnabled("ddlb_1", false);
        tb_1.SetEnabled("btn_ChaXun", false);
        tb_1.SetEnabled("btn_Filter", false);
        tb_1.SetEnabled("btn_Export", true);

        tb_1.SetEnabled("btn_Tally", false);

        if (ControlDiscount(dw_mx, "DY_THJ") == "1") {
            em_1.SetEnabled(true);
        }
        else {
            em_1.SetEnabled(false);
        }
        if (ControlDiscount(dw_mx, "DY_XSJ") == "1") {
            em_2.SetEnabled(true);
        }
        else {
            em_2.SetEnabled(false);
        }

        openflag = "Edit";
        mxflag = openflag;
        //self.dw_mx_top_itemChanged(dw_mx_top.GetRow(), "zzck", dw_mx_top.GetItemString(dw_mx_top.GetRow(), "zzck"));
        //新增的时候。初始化折扣卡=0
        em_1.SetText("1");
        em_2.SetText("1");
        self.setKCSL("", "", "", 0, "");
    }

    //#endregion  

    //#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 == "√") {
            requestor.MessageBox("提示", "该单据已记账，不能被强制修改！", ICON.StopSign);
            return;
        }
        webReqTimestamp.Invoke("YW_TIMESTAMP_REC", "curPzh=" + dw_hz.GetItemString(dw_hz.GetRow(), "pzh") + "&curFlag=QZXG&curLAST_SJC=XX");
        if (webReqTimestamp.StatusCode() == 200) {
            var findRow = dw_hz.Find("pzh='" + dw_hz.GetItemString(dw_hz.GetRow(), "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.Delete
    this.Delete = function () {
        var curLyPzh = "";
        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 (self.CheckJzbz()) {
            return;
        }
 

        webReq.Invoke("KeHuDiaoBoDan_Delete", "curPzh=" + curPzh );
        if (webReq.StatusCode() == 200) {

         
            dw_hz.DeleteRow(row);
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.Information);
            tab_1.SetSelectedTab(1);
            tb_1.SetEnabled("ddlb_1", true);
          //  tb_1.SetEnabled("btn_ChaXun", true);
            tb_1.SetEnabled("btn_Filter", true);
            tb_1.SetEnabled("btn_Export", true);
            if (dw_hz.GetRow() > 0) {
                curPzh = tab_Changed(tab_1, dw_hz, dw_mx_top);
                self.SelectionChanged_tab(curPzh);
            }
            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") {

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

            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 () {
        dw_mx_top.AcceptText();
        dw_mx.AcceptText();

        if (!isAdd) {
//            if (self.CheckJzbz()) {
//                return;
//            }
//            if (self.CheckTrans()) {
//                return;
//            }
        }
        dw_mx_top.SetItem(1, "dckh", dw_mx_top.GetItemString(1, "dckh"));
        dw_mx.SetItem(dw_mx.RowCount(), "cm35", dw_mx.GetItemNumber(dw_mx.RowCount(), "cm35"));
        if ((dw_mx_top.ModifiedCount() + dw_mx.DeletedCount() + dw_mx.ModifiedCount()) <= 0) {
            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";
                }
                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;
        }
     
        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 tzrq = UtcDateTimeFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "kdrq"));
        var dckh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "dckh");
        dw_mx_top.SetItem(dw_mx_top.GetRow(), "kdrq", UtcDateFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "kdrq")));
        webReq1.Invoke("GetTallystatus", "bmbh=" + dckh + "&tzrq=" + tzrq + "&flag=2");
        if (webReq1.StatusCode() == 200) {
            requestor.MessageBox("提示", "本部门库存已结转,不可保存！", ICON.StopSign);
            return;
        }
        if (dw_mx.RowCount() > 0) {
            dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "sumzjsl"));
            dw_mx_top.SetItem(1, "lsjze", dw_mx.GetItemNumber(1, "sumjsje"));

            dw_mx_top.SetItem(1, "thje", dw_mx.GetItemNumber(1, "sumthje"));
            dw_mx_top.SetItem(1, "xsje", dw_mx.GetItemNumber(1, "sumxsje"));
        } else {
            dw_mx_top.SetItem(1, "zjsl", 0);
            dw_mx_top.SetItem(1, "lsjze", 0);

            dw_mx_top.SetItem(1, "thje", 0);
            dw_mx_top.SetItem(1, "xsje", 0);
        }
    
        

        var dw_mx_top_data = dw_mx_top.GetChanges();
        var dw_mx_data = dw_mx.GetChanges();
        if (dw_mx_top_data == "" && dw_mx_data == "")
            return;
        var flag = requestor.GetParm("flag");

        webReq.Invoke("KeHuDiaoBoDan_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 + "&curSysDate=" + curSysteData + "&curLogStr=" + "&bfpzh=" + dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh") + "&isPast=" + isPast + "&curTmlshDeleteTimestamp=" + curTmlshDeleteTimestamp);

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

            //服务器成功处理，返回单号
            var rPzh = webReq.ResponseText(); 
            //刷新 
            self.SelectionChanged();
            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);
            } else {
                self.SelectionChanged_tab(rPzh);
            }

            self.SetEditMode("");
            curSaveReturnValue = "Y"
            if (zhengdanzhekouFlag == "N") {
                requestor.MessageBox("提示", "数据保存成功!", ICON.Information);
            }
            cb_sm.SetVisible(false);
            sle_tmh.SetVisible(false);

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

//            dw_mx_top.GetChild("bmbh1", dwc);
//            dwc.Retrieve("%", curYhbh, "DB");
//            dw_mx_top.GetChild("bmbh2", dwc);
//            dwc.Retrieve("%", curYhbh, "DBC");
//            //#endregion           
            //-------------每次保存完删除业务表临时凭证号对应数据--------

            //-----------------------------------------------------------
            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 (curGnqxStr.indexOf("btn_FAudit") <= -1) {
            alert("您没有反审核权限，请检查。");
            return;
        } 
        

        if (dw_hz.GetRow() < 1) {
            alert("请先选择一笔数据进行反审核");
            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;
        //        if (self.CheckJzbz()) {
        //            return;
        //        }
        webReq.Invoke("DiaoBoDingDan_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 {

                self.SelectionChanged_tab(curPzh);
                //self.Hz_RowFocusChanged(dw_hz.GetRow());
            }
            dw_hz.SetProcessing(false);
            dw_hz.SetRedraw(true);
            //#endregion 

            dw_mx_top.Modify("ysh_q_t.visible='1' ysh_t.visible='1' ysh_t.Text='已审核'");
            tb_1.SetEnabled("btn_Audit", false);
            tb_1.SetEnabled("btn_UnAudit", true);
            tb_1.SetEnabled("btn_Tally", true);
            tb_1.SetEnabled("btn_Update", false);
            tb_1.SetEnabled("btn_Delete", false);
            tb_1.SetEnabled("btn_Save", false);
        }
        else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
        }
    }
    //#endregion

    //#region 记账模式改变，1表示调入部门统一记账
    this.DCFAudit = function () {
        if (curGnqxStr.indexOf("btn_FAudit") <= -1) {
            alert("您没有反审核权限，请检查。");
            return;
        } 
        var row = dw_hz.GetRow();
        if (row < 1)
            return;
        //        alert((dw_hz.GetItemString(row, "lydh")).substring(0, 2));
        if ((dw_hz.GetItemString(row, "lydh")).substring(0, 2) != "DC") {
            requestor.MessageBox("提示", "调拨入库单不是由调拨出库单转单而来，没有该功能！", ICON.Information);
            return;
        }
        if (self.CheckJzbz()) {
            return;
        }
        var curPzh = dw_hz.GetItemString(row, "pzh");
        webReq.Invoke("DCFAudit", "curPzh=" + curPzh + "&curId=" + curFunctionId);
        if (webReq.StatusCode() == 200) {
            if (webReq.ResponseText() == "1") {
                requestor.MessageBox("提示", "调拨入库单反审成功！", ICON.Information);

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

                //刷新
                self.SelectionChanged();

                self.Hz_RowFocusChanged(dw_hz.GetRow());
                dw_hz.SetProcessing(false);
                dw_hz.SetRedraw(true);
                //#endregion 

                dw_mx_top.Modify("ysh_q_t.visible='0' ysh_t.visible='0' ysh_t.Text=''");
                tb_1.SetEnabled("btn_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);
            } else {
                requestor.MessageBox("提示", "调拨入库单反审失败！", ICON.StopSign);
            }
        } 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 == "bmbh1") {
        //                curW_OPEN_BMDA.SetDataWindow(dw_mx_top, "bmbh", "bmmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        //                if (flag == "DC") {
        //                    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=db"), curW_OPEN_BMDA, null);
        //                } else {
        //                    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=dbc"), curW_OPEN_BMDA, null);
        //                }
        //                self.ClareKcAndCmzAll();
        //            }
        //            if (dwoName == "bmbh2") {
        //                curW_OPEN_BMDA.SetDataWindow(dw_mx_top, "bmbh", "bmmc", "", self, "bmbh2", "bmmc2")  // 这个用来给子窗口Set当前数据窗口
        //                if (flag == "DC") {
        //                    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=dbc"), curW_OPEN_BMDA, null);
        //                } else {
        //                    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=db"), curW_OPEN_BMDA, null);
        //                }
        //                self.ClareKcAndCmzAll();
        //            }
        //        }

        if (dw_mx_top.Describe("DataWindow.Readonly") == "no") {
            if (dwoName == "zzck") {
                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=pf"), curW_OPEN_BMDA, null);
                self.ClareKcAndCmzAll();
                self.dw_mx_top_itemChanged(dw_mx_top.GetRow(), "zzck", dw_mx_top.GetItemString(dw_mx_top.GetRow(), "zzck"))
            } else if (dwoName == "dckh") {

                curW_OPEN_BMDA.SetDataWindow(dw_mx_top, "khbh", "khmc", "客户调拨单调出客户")   // 这个用来给子窗口Set当前数据窗口
                requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowQueryBase&treeDw=dw_da_khda_fl_tree&listDw=dw_pub_khda_list_all_yw&treeRootLabel=客户分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&curQxlx=pf"), curW_OPEN_BMDA, null);
           
                self.dw_mx_top_itemChanged(dw_mx_top.GetRow(), "dckh", dw_mx_top.GetItemString(dw_mx_top.GetRow(), "dckh"));
            
            } else if (dwoName == "drkh") {

                curW_OPEN_BMDA.SetDataWindow(dw_mx_top, "khbh", "khmc", "客户调拨单调入客户")   // 这个用来给子窗口Set当前数据窗口
                requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowQueryBase&treeDw=dw_da_khda_fl_tree&listDw=dw_pub_khda_list_all_yw&treeRootLabel=客户分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&curQxlx=pf"), curW_OPEN_BMDA, null);
                self.dw_mx_top_itemChanged(dw_mx_top.GetRow(), "drkh", dw_mx_top.GetItemString(dw_mx_top.GetRow(), "drkh"));
            } else if (dwoName == "ywy") {
                curW_OPEN_BMDA.SetDataWindow(dw_mx_top, "ygbh", "ygmc", "客户调拨单业务员")  // 这个用来给子窗口Set当前数据窗口
                requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowQueryBase&treeDw=dw_da_ryda_zw_tree&listDw=dw_da_ygda_list_1&treeRootLabel=职务分类&treeData=csbh&treeLabel=csmc&treeParentData=fcsbh&treeLeave=islast&selectStyle=multiple1&flag=pifabase"), curW_OPEN_BMDA, null);
            }
        }
    }
    //#endregion 

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

    this.dw_mx_top_editChanged = function (row, dwoName, data) {
        if (dwoName == "dckh") {
            dw_mx_top.GetChild(dwoName, dwc);
            if (data != "") {
                dwc.Retrieve("%" + data + "%", curYhbh);
            }
            else {
                dwc.Retrieve("%", curYhbh);
            }
        } else if (dwoName == "drkh") {
            dw_mx_top.GetChild(dwoName, dwc);
            if (data != "") {
                dwc.Retrieve("%" + data + "%", curYhbh);
            }
            else {
                dwc.Retrieve("%", curYhbh);
            }
        } else if (dwoName == "zzck") {


            dw_mx_top.GetChild(dwoName, dwc);
            if (data != "") {
                dwc.Retrieve("%" + data + "%", curYhbh, curQxlx);
            }
            else {
                dwc.Retrieve("%", curYhbh, curQxlx);
            }
        } else if (dwoName == "ywy") {
            dw_mx_top.GetChild("ywy", dwc);
            if (data != "") {
                dwc.Retrieve("%" + data + "%", curYhbh, "pf");
            } else {
                dwc.Retrieve("%", curYhbh, "pf");
            }
        }

    }
    //#endregion 
     
    //#region this.dw_mx_top_itemChanged
    var curLastZzck = "";
    var curOldTopZzck = "";
    var curOldTopZzckmc = "";

    var curLastDckh = "";
    var curOldTopDckh = "";
    var curOldTopDckhmc = "";

    var curLastDrkh = "";
    var curOldTopDrkh = "";
    var curOldTopDrkhmc = "";
    this.dw_mx_top_itemChanged = function (row, dwoName, data) {

        dw_mx_top.AcceptText();
        var partPzh = requestor.GetParm("flag");
        var dckh = dw_mx_top.GetItemString(row, "dckh");
        var drkh = dw_mx_top.GetItemString(row, "drkh");
        var zzck = dw_mx_top.GetItemString(row, "zzck");
        
        if (dwoName == "dckh") {
            if (dckh == drkh) {
                requestor.MessageBox("提示", "调出客户和调入客户不可相同！", ICON.Information);
                dw_mx_top.SetItem(row, "dckh", "");
                dw_mx_top.SetItem(row, "dckhmc", "");
                return 1;
            } else if (zzck == dckh) {
                requestor.MessageBox("提示", "调出客户和中转仓库不可相同！", ICON.Information);
                dw_mx_top.SetItem(row, "dckh", "");
                dw_mx_top.SetItem(row, "dckhmc", "");
                return 1;
            }

            dw_mx_top.GetChild(dwoName, dwc);
            dwc.Retrieve("%", curYhbh);
            var findRow = dwc.Find("khbh='" + data + "' ", 1, dwc.RowCount());
            if (findRow <= 0) {

                dw_mx_top.SetItemNull(row, dwoName);
                dwc.Retrieve("%", curYhbh);
                dw_mx_top.SetItemNull(row, "dckhmc")
                requestor.MessageBox("提示", "未找到客户编号为[" + data + "]的记录，请检查!", ICON.StopSign);

                return 1;
            } else {

                //#region 判断已选择客户且已录入明细数据，则不能切换客户
                dw_mx_top.SetItem(dw_mx_top.GetRow(), "dckhmc", dwc.GetItemString(findRow, "khmc"));
                var curDckh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "dckh");
                if (curDckh.length > 0 && curOldTopDckh.length > 0 && curDckh != curOldTopDckh) {
                    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") {
                        if (!confirm("切换中转仓库会清空已录入的数据，您确定要继续吗？")) {

                            dw_mx_top.SetItem(row, "dckh", curOldTopDckh);
                            dw_mx_top.SetItem(row, "dckhmc", curOldTopDckhmc);
                            return 1;

                        } else {
                            for (row = dw_mx.RowCount(); row > 0; row--) {
                                dw_mx.DeleteRow(row);
                            }
                            dw_mx.ScrollToRow(dw_mx.InsertRow(0));
                            //self.DeleteAllTmlsh();
                        }
                    }

                }
                //#endregion

                curOldTopDckh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "dckh");
                curOldTopDckhmc = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "dckhmc");


            }

            webReq_pf.Invoke("GetKHXX", "CusId=" + data);
            if (webReq_pf.StatusCode() == 200) {
                curKhxx = webReq_pf.ResponseText();
                curJjfs = curKhxx.split("#")[0];
                curGlkc = curKhxx.split("#")[6];
            } else {
                alert(webReq.ResponseText());
            }

            self.ClareKcAndCmzAll();
            return 1;

        } 
        if (dwoName == "drkh") {
            if (dckh == drkh) {
                requestor.MessageBox("提示", "调出客户和调入客户不可相同！", ICON.Information);
                dw_mx_top.SetItem(row, "drkh", "");
                dw_mx_top.SetItem(row, "drkhmc", "");
                return 1;
            } else if (zzck == drkh) {
                requestor.MessageBox("提示", "调入客户和中转仓库不可相同！", ICON.Information);
                dw_mx_top.SetItem(row, "drkh", "");
                dw_mx_top.SetItem(row, "drkhmc", "");
                return 1;
            }
             


            dw_mx_top.GetChild(dwoName, dwc);
            dwc.Retrieve("%", curYhbh);
            var findRow = dwc.Find("khbh='" + data + "' ", 1, dwc.RowCount());
            if (findRow <= 0) {

                dw_mx_top.SetItemNull(row, dwoName);
                dwc.Retrieve("%", curYhbh);
                dw_mx_top.SetItemNull(row, "drkhmc")
                requestor.MessageBox("提示", "未找到客户编号为[" + data + "]的记录，请检查!", ICON.StopSign);

                return 1;
            } else {

                //#region 判断已选择客户且已录入明细数据，则不能切换客户
                dw_mx_top.SetItem(dw_mx_top.GetRow(), "drkhmc", dwc.GetItemString(findRow, "khmc"));
                var curDrkh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "drkh");
                if (curDrkh.length > 0 && curOldTopDrkh.length > 0 && curDrkh != curOldTopDrkh) {
                    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") {
                        if (!confirm("切换调入客户会清空已录入的数据，您确定要继续吗？")) {

                            dw_mx_top.SetItem(row, "drkh", curOldTopDrkh);
                            dw_mx_top.SetItem(row, "drkhmc", curOldTopDrkhmc);
                            return 1;

                        } else {
                            for (row = dw_mx.RowCount(); row > 0; row--) {
                                dw_mx.DeleteRow(row);
                            }
                            dw_mx.ScrollToRow(dw_mx.InsertRow(0));
                           // self.DeleteAllTmlsh();
                        }
                    }

                }
                //#endregion

                curOldTopDrkh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "drkh");
                curOldTopDrkhmc = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "drkhmc");


            }
            webReq_pf.Invoke("GetKHXX", "CusId=" + data);
            if (webReq_pf.StatusCode() == 200) {
                curKhxxDrkh = webReq_pf.ResponseText();
                curJjfsDrkh = curKhxxDrkh.split("#")[0];
            } else {
                alert(webReq_pf.ResponseText());
            }


            self.ClareKcAndCmzAll();
            return 1;

        } else if (dwoName == "ywy") {

            dw_mx_top.GetChild(dwoName, dwc);
            dwc.Refresh();
            var findRow = dwc.Find("ygbh='" + data + "' ", 1, dwc.RowCount());
            if (findRow <= 0) {
                requestor.MessageBox("提示", "未找到员工编号为[" + data + "]的记录，请检查!", ICON.StopSign);
                return 1;
            } else {

                dw_mx.AcceptText();
                dw_mx_top.SetItem(dw_mx_top.GetRow(), "ywymc", dwc.GetItemString(findRow, "ygmc"));

            }

        } else if (dwoName == "zzck") {
            if (drkh == zzck || dckh == zzck) {
                requestor.MessageBox("提示", "调出客户，调入客户和中转仓库不可相同！", ICON.Information);
                dw_mx_top.SetItem(row, "zzck", "");
                dw_mx_top.SetItem(row, "zzckmc", "");
                return 1;
            }

            dw_mx_top.GetChild(dwoName, dwc);
            dwc.Refresh();
            var findRow = dwc.Find("bmbh='" + data + "' ", 1, dwc.RowCount());
            if (findRow <= 0) {
                requestor.MessageBox("提示", "未找到部门编号为[" + data + "]的记录，请检查!", ICON.StopSign);
                return 1;
            } else {
                var curHaveMx = "N";
                dw_mx.AcceptText();
                dw_mx_top.SetItem(dw_mx_top.GetRow(), "zzckmc", dwc.GetItemString(findRow, "bmmc"));
                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") {
                    if (!confirm("切换中转仓库会清空已录入的数据，您确定要继续吗？")) {
                        dw_mx_top.SetItem(row, "zzck", curOldTopZzck);
                        dw_mx_top.SetItem(row, "zzckmc", curOldTopZzckmc);
                        return 1;
                    } else {
                        for (r = dw_mx.RowCount(); r > 0; r--) {
                            dw_mx.DeleteRow(r);
                        }
                       // self.DeleteAllTmlsh();
                    }
                }



            }

            curOldTopZzck = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "zzck");
            curOldTopZzckmc = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "zzckmc");
            curLastZzck = curOldTopZzck;
            self.ClareKcAndCmzAll();
        }
    }
    //#endregion

    //#region dw_mx_top_Clicked
    this.dw_mx_top_Clicked = function (x, y, row, dwcName) {
        if (dwcName == "tmsmflag") {
            self.Myfocus();
        }
        if (flag == "DR") {
            return;
        }
        var curKhjsValue = "";
        if (dwcName == "bmbh1") {
            dw_mx_top.GetChild(dwcName, dwc);
            if (flag == "DC") {
                dwc.Retrieve("%", curYhbh, "db");
            } else {
                dwc.Retrieve("%", curYhbh, "dbc");
            }
        }
        if (dwcName == "bmbh2") {
            dw_mx_top.GetChild(dwcName, dwc);
            if (flag == "DC") {
                dwc.Retrieve("%", curYhbh, "dbc");
            } else {
                dwc.Retrieve("%", curYhbh, "db");
            }
        }
        if (flag == "DC" || flag == "DR") {
            if (dw_mx_top.Describe("DataWindow.Readonly") == "yes") {
                return;
            }
            if (dwcName == "khjs") {

                curKhjsValue = dw_mx_top.GetItemString(1, "khjs")
                if (dw_mx.RowCount() > 0) {
                    if (dw_mx_top.GetItemString(1, "bmbh2").length > 0) {
                        if (requestor.MessageBox("提示^", "切换客户结算会清空明细行和部门,是否继续？", ICON.Question, BUTTON.YesNo) == 1) {
                            dw_mx.Reset();
                            dw_mx_top.SetItem(1, "bmbh1", "");
                            dw_mx_top.SetItem(1, "bmbh2", "");
                            dw_mx_top.ScrollToRow(dw_mx.InsertRow(0));

                        } else {
                            dw_mx_top.SetItem(1, "khjs", curKhjsValue);
                            return;
                        }
                    }
                }
                if (Trim(dw_mx_top.GetItemString(1, "khjs")).length == 0 || dw_mx_top.GetItemString(1, "khjs") == "0") {
                    dw_mx_top.Modify("dbck.Protect='0'");
                    dw_mx_top.SetItem(1, "khjs", "1");
                    dw_mx.Modify("lsj.Protect='1'");
                    dw_mx.Modify("zkl.Protect='1'");
                    em_1.SetEnabled(false);

                }
                else {
                    dw_mx_top.Modify("dbck.Protect='1'")
                    dw_mx_top.SetItem(1, "khjs", "0");
                    dw_mx.Modify("lsj.Protect='0'");
                    dw_mx.Modify("zkl.Protect='0'");
                }

            }
        }
        if (dwcName == "dbck") {
            dw_mx_top.GetChild(dwcName, dwc);
            if (flag == "DC") {
                dwc.Retrieve("%", curYhbh, "dbj");
            }
        }
    }
    //#endregion

    //#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, "bmbh1") == "") {

                alert("请选择调入部门!");
                dw_mx_top.SetColumn("bmbh1");
                dw_mx_top.SetFocus();
                return;
            }
            if (dw_mx_top.GetItemString(1, "bmbh2") == "") {

                alert("请选择调出部门!");
                dw_mx_top.SetColumn("bmbh2");
                dw_mx_top.SetFocus();
                return;
            }
            if (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 = requestor.Trim(sle_tmh.GetText().toUpperCase());
        var curJSJG = 0;
        if (txt.length < 1) {
            sle_tmh.SetText("");
            sle_tmh.SetFocus();
            return 1;
        }
        if (key != 13) {
            return;
        }
        if (!G_bEditFlag) {
            alert("请先单击修改！");
            return;
        }
        dw_mx.AcceptText();
        dw_ddmx_top_tmlr.Retrieve(txt, "", "", "", "");

        if (dw_ddmx_top_tmlr.RowCount() == 0) {

            alert("输入的条码不存在，请重新输入！");
            self.Myfocus();
            return -1;
        }

        var tmSpkh = dw_ddmx_top_tmlr.GetItemString(1, "spkh");
        curOldSpkh = tmSpkh;
        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());
        var curSaoMiaoLie = "";
        var curChangecolor = dw_ddmx_top_tmlr.GetItemString(1, "changecolor");
        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;
        }
        if (mxFindRow > 0) { // 该款该色已存在，只需要改变数量
            dw_mx.ScrollToRow(mxFindRow);
            var curCmSl = dw_mx.GetItemNumber(mxFindRow, curSaoMiaoLie);
            dw_mx.SetItem(mxFindRow, curSaoMiaoLie, parseInt(curCmSl) + 1);
        } else {           // 该款该色不存在，新增行
            if (dw_mx.RowCount() > 0) {
                if (dw_mx.GetItemNumber(dw_mx.GetRow(), "spsl") == 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, "cmzbh", dw_ddmx_top_tmlr.GetItemString(1, "cmzbm"));
            dw_mx.SetItem(newRow, curSaoMiaoLie, 1);
        }
        self.dw_mx_itemChanged(dw_mx.GetRow(), "spkh", dw_ddmx_top_tmlr.GetItemString(1, "spkh"), "Y");
        self.setKCSL("", "", "", 0, "");
        self.dw_mx_itemChanged(dw_mx.GetRow(), curSaoMiaoLie, dw_mx.GetItemNumber(dw_mx.GetRow(), curSaoMiaoLie), "Y");
        self.Myfocus();

    }
    //#endregion   

    //#region this.em_zdzk 计算折扣
    this.em_zdzk = function (key, flag, s) {
        var curIsThzkOrXszk = "";
        var zkl = "";
        if (s.Name == "em_1") {
            curIsThzkOrXszk = "THZK";
            zkl = parseFloat(em_1.GetText());
        } else {
            curIsThzkOrXszk = "XSZK";
            zkl = parseFloat(em_2.GetText());
        }
 
        var row = dw_mx.RowCount();


        if (key == 13) {
       
            if (row == 0) {
                alert("请先输入明细!");
                dw_mx.SetFocus();
                return;
            }
            //var curPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");

            if (zkl  > 0 ) {
             

                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("KeHuDiaoBoDan_Batch_Edit_ZDZK", "curPzh=" + curPzh + "&curZkl=" + zkl + "&curIsThzkOrXszk=" + curIsThzkOrXszk);
                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.rbn_qzxg 

    this.rbn_qzxg = function () {
        var pzh = dw_mx_top.GetItemString(1, "pzh");
        if (!confirm("您确定要强制修改吗？")) {
            return;
        }
        // 处理时间戳，【强制修改】---------------begin--------------
        var xmlHttp = null;
        if (window.XMLHttpRequest)
            xmlHttp = new window.XMLHttpRequest();
        else
            xmlHttp = new ActiveXObject("MSXML2.XMLHTTP.6.0");

        xmlHttp.open("POST", "/Service/GetPublicData.ashx", false);
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
        xmlHttp.send("curFlag=CG_HZ_CHECK_TIMESTAMP&curOpFlag=5&curTableName=cg_ddhz&curUpdateOldSt=&curPzh=" + pzh + "&curDate=" + new Date());
        if (xmlHttp.status == 200) {
            if (xmlHttp.responseText != "OK") {
                requestor.MessageBox("提示", xmlHttp.responseText);
                return;
            } else {
                self.SetEditMode("");
                tab_1.SelectTab(1);
            }
        } else {
            requestor.MessageBox("提示", xmlHttp.responseText, ICON.StopSign);
            return;
        }
        // 处理时间戳，【强制修改】---------------end--------------

    }
    //#endregion   


//    //#region 单据粘贴
//    this.DatePast = function () {
//        if (editMode == "Add" || editMode == "Edit") {
//            var curPzh = dw_mx_top.GetItemString(1, "pzh");
//            var curKhbh = dw_mx_top.GetItemString(1, "bmbh1");
//            var curBmbh = dw_mx_top.GetItemString(1, "bmbh2");

//            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, "zjsl") + "' ");
//            }
//            else {
//                requestor.MessageBox("粘贴失败", maseege.split("#")[1], ICON.Information);
//                isPast = "N"
//                return;

//            }
//        }
//    }
    var curFlag = "";
    var curTbflag = "";
    this.GetRetVFlag = function (str1, str2) {
        curFlag = str1;
        curTbflag = 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();
        dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zjsl") + "' ");
        //#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);
        }
    }
    //#region ImporExcel
    this.ImporExcel = function () {
        dw_mx_top.AcceptText();
        var curdcbm = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh2");
        var curdrbm = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh1");
        if (curdrbm == curdcbm) {
            requestor.MessageBox("提示", "调入部门和调出部门不可相同！", ICON.Information);
            dw_mx_top.SetItem(dw_mx_top.GetRow(), "bmbh1", "");
            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;
        }
        if (curdcbm.length < 1 || curdrbm.length < 1) {
            alert("调入或调出部门不能为空");
            return;
        }
        cur_W_HYHKDR.SetDataWindow(W_DiaoBo_Base, self)
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.import.W_HYHKDR&FunctionID=" + curFunctionId + "&DRBM=" + curdrbm + "&DCBM=" + curdcbm + "&kdrq=" + currq + "&rkfs=" + currkfs), cur_W_HYHKDR, null);
    }
    //#endregion

    //#region ImporTXT
    this.ImportTxt = function () {

        dw_mx_top.AcceptText();
        var curdcbm = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh2");
        var curdrbm = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh1");

        if (curdrbm == curdcbm) {
            requestor.MessageBox("提示", "调入部门和调出部门不可相同！", ICON.Information);
            dw_mx_top.SetItem(dw_mx_top.GetRow(), "bmbh1", "");
            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;
        }
        if (curdcbm.length < 1 || curdrbm.length < 1) {
            alert("调入或调出部门不能为空");
            return;
        }
        var curPpfa = sle_pptmfa_Value.GetText();
        cur_W_TXTDR.SetDataWindow(W_DiaoBo_Base, self)
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.import.W_TXTDR&FunctionID=" + curFunctionId + "&DRBM=" + curdrbm + "&DCBM=" + curdcbm + "&kdrq=" + currq + "&rkfs=" + currkfs+ "&pptmfa=" + curPpfa), cur_W_TXTDR, null);
    }
    //#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 () {
        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);
        //var pzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
        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 刷新汇总表
            self.SelectionChanged(dw_hz.GetPageIndex());
            if (dw_hz.RowCount() == 0) {
                self.SetButtomStatus();
                return;
            }
            //找到相应的记录
            var findRow = dw_hz.Find("pzh='" + pzh + "' ", 1, dw_hz.RowCount());
            if (findRow > 0) {
                dw_hz.ScrollToRow(findRow);
            } else {

                self.SelectionChanged_tab(pzh);
            }
            //#endregion

            // 下一笔将要显示在按钮上的功能
            if (findRow > 0) {
                var 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("btn_ChaXun", true);
                tb_1.SetEnabled("btn_Filter", true);
                tb_1.SetEnabled("btn_Export", true);
            }
        } else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
        }
    }
    //#endregion

    //#region 退审
    this.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 == "DZ") {
            var sql = "select 1 from yw_db_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 + "&curQybz=" + qybz + "&curId=" + curFunctionId);
        if (webReq.StatusCode() == 200) {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.Information);

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

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

            if (findRow > 0) {
                dw_hz.ScrollToRow(findRow);
            } else {
                self.SelectionChanged_tab(pzh);
            }
            dw_hz.SetProcessing(false);
            dw_hz.SetRedraw(true);
            //#endregion             

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

    //#region 审核级别

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

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

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


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

        if (dw_hz.GetRow() < 1) {
            alert("请先选择一笔数据进行审核");
            return;
        }
        var pzh = dw_hz.GetItemString(dw_hz.GetRow(),"pzh");
        if (!confirm("您确定要记账凭证号为[" + pzh + "]的单据吗？")) {
            return;
        }

        if (self.CheckJzbz("JZ")) {
            return;
        }
        var curFlag = requestor.GetParm("flag");


        var tzrq = UtcDateTimeFormatToString(dw_hz.GetItemDate(dw_hz.GetRow(), "kdrq"));
        var bmbh = dw_hz.GetItemString(dw_hz.GetRow(), "zzck");
      

        webReq1.Invoke("GetTallystatus", "bmbh=" + bmbh + "&tzrq=" + tzrq + "&flag=1");
        if (webReq1.StatusCode() == 200) {
            requestor.MessageBox("提示", "中转仓库上月库存未结转,不可审核记账！", ICON.StopSign);
            return;
        } 

        webReq.Invoke("KeHuDiaoBoDan_Tally", "curPzh=" + pzh + "&curDate=" + new Date().toLocaleTimeString());
        if (webReq.StatusCode() == 200) {
            var curMsg = webReq.ResponseText();
            //订单或通知单

            if (curMsg.split("#")[0] == "Y") {
                requestor.MessageBox("提示", "记账成功", ICON.Information);
            } else {
                alert( curMsg.split("#")[1]);
                return;
            }
            //tab_1.SetSelectedTab(1);
            //tb_1.SetEnabled("ddlb_1", true);
            //tb_1.SetEnabled("btn_ChaXun", true);
            tb_1.SetEnabled("btn_Filter", true);
            tb_1.SetEnabled("btn_Export", true);

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

            //刷新
            self.SelectionChanged(dw_hz.GetPageIndex());
            //找到相应的记录
            var findRow = dw_hz.Find("pzh='" + pzh + "' ", 1, dw_hz.RowCount());
            if (findRow > 0) {
                dw_hz.ScrollToRow(findRow);
            } else {
                self.SelectionChanged_tab(pzh);
            }
            dw_hz.SetProcessing(false);
            dw_hz.SetRedraw(true);
            //#endregion 
            if (findRow > 0) {
             
                tb_1.SetEnabled("btn_Tally", false);
                tb_1.SetEnabled("btn_Update", false);
                tb_1.SetEnabled("btn_Delete", false);
                tb_1.SetEnabled("btn_Save", false);
            } else {
                if (tab_1.GetSelectedTab() == "2") {
                    // 这里表示记账成功后在汇总页面没有找到当前行。所以直接把 【记账，退审】 按钮屏蔽
                  
                    tb_1.SetEnabled("btn_Add", true);
                    tb_1.SetEnabled("btn_Edit", false);
                    tb_1.SetEnabled("btn_Delete", false); 
                    tb_1.SetEnabled("btn_Tally", false);
    
                    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);
                }
            }
        } else {
            requestor.MessageBox("提示", "记账失败！", ICON.StopSign);
        }
    }
    //#endregion    
  

    //#region 判断库存是否充足
    this.JudgeKc = function (row, dwoName, data) {
        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);
            }
        }

        //alert([kcslStr, curSl, parseInt(data)]);
        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;
            }
            else {
                pzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
            }
        }
        if (tab_1.GetSelectedTab() == "2") {
            if (dw_mx_top.RowCount() > 0) {
                pzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
            }
            else {
                return;
            }
        }
        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();
 
        A8erp_Biz_Print.Yw_Db_35_KHDBD_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);
 
        dw_print.PrintPreview();

       // requestor.ClipBoardNao(dw_print.Describe("datawindow.syntax"));
    }
    //#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

    //#region 设置打印排序
    this.SetPrintSort = function (a, b) {
        curDypx = b;
    }
    //#endregion

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

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

        var curPzh = tab_Changed(tab_1, dw_hz, dw_mx_top);
      
        //var curPzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
        if (curPzh.length < 1) {
            requestor.MessageBox("提示", "凭证号获取失败！", ICON.StopSign);
            return;
        }

        if (!confirm("确定将单据【" + curPzh + "】转入下一业务吗？")) {
            return;
        }
        webReq.Invoke("DiaoBoDingDan_Trans", "curPzh=" + curPzh + "&curId=" + curFunctionId);
        if (webReq.StatusCode() == 200) {
            if (webReq.ResponseText().split("#")[0] == "OK") {

                requestor.MessageBox("提示", "转单成功", ICON.Information);
                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);
            } 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 = " 1=1 ";
        } 

    
        dw_hz.RetrieveEx(djzt); 
        var curPageCount = dw_hz.GetPageCount();
        try {
            if (arguments.length == 1) {
                if (parseInt(val) > curPageCount) {
                    dw_hz.SetPageIndex(curPageCount);
                } else {
                    dw_hz.SetPageIndex(val);
                }
                dw_hz.Refresh();
            }
        } catch (e) {
            alert("this.SelectionChanged Error.\r\n");
        }
    }

    //#region this.EvalJs

    this.EvalJs = function (jsScript) {

        eval(jsScript);
    }
    //#endregion

    //#region 检查记账标志
    this.CheckJzbz = function (curFlag) {
        var curTName = "";
        var curpzh = ""; 
       
            curpzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
            curTName = "yw_db_khdbdhz"; 
         
            webReqTimestamp.Invoke("YW_GTE_PZH", "curTName=" + curTName + "&curPzh=" + curpzh);
            if (webReqTimestamp.StatusCode() == 200) {
                var curjzbz = webReqTimestamp.ResponseText();
               
                if (curjzbz == "Y") {
                    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.SelectionChanged_tab(pzh);
                        //self.Hz_RowFocusChanged(dw_hz.GetRow());
                    }
                    dw_hz.SetProcessing(false);
                    dw_hz.SetRedraw(true);
                    //#endregion 
                
          
                    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 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) {
//        if (ind == 2) {
//            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 (SelectTabFlag == "Y" && curHaveMx == "Y" && dw_mx.RowCount() > 0 && editMode != "") {
//                requestor.MessageBox("提示", "当前单据未保存，请保存或取消！", ICON.StopSign);
//                return 1;
//            }
//        }
//        SelectTabFlag = "Y";

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

                    return 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);
            self.Cancel();
            if (dw_hz.GetRow() < 1) {
                return;
            }
           
            self.SelectionChanged_tab(dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh"));
        } else if (ind == "2")  {
            tb_1.SetEnabled("ddlb_1", false);
            tb_1.SetEnabled("btn_ChaXun", false);
            tb_1.SetEnabled("btn_Filter", false);
            tb_1.SetEnabled("btn_Export", true);

            var curRowCount = dw_hz.RowCount();
            if (curRowCount < 1) {
                dw_mx_top.Retrieve("");
                dw_mx.Retrieve("");
                return;
            }
            var curPzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
            dw_mx_top.Retrieve(curPzh);
            dw_mx.Retrieve(curPzh);
            self.setKCSL("", "", "", 0, "");
        }
    }

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

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

    //#region 查询界面
    this.ChaXun = function () {

        curW_DiaoBo_ChaXun.SetDataWindow(self, dw_hz, flag, curYhbh, ddlb_1.GetText(), curJdbh, curSelDays);
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DiaoBo.Base.W_DiaoBo_ChaXun&flag=" + flag), curW_DiaoBo_ChaXun, null);

    }
    //#endregion

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

    //#region 打印预览
    this.SetPrint = function () {

        if (curSfQyQDID == "1") {
            A8erp_Biz_Print.Yw_Db_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_Db_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, 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.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 款号，款名排序
    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();
        }
    }

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

    }

    //#region 单据复制
    this.DateCopy = function () {

        if (curSFQYSJKZQ == "1") {
            if (dw_mx.RowCount() < 1) {
                requestor.MessageBox("提示", "无数据可复制！", ICON.Information);
                return;
            }
            var curPzh = dw_mx_top.GetItemString(1, "pzh");
            FUN_COPY_TO_PAST(curPzh, "COPY", "", "");
        } else {
            if (dw_mx.RowCount() < 1) {
                requestor.MessageBox("提示", "无数据可复制！", ICON.Information);
                return;
            }
            curDw.Retrieve();
            requestor.ShowLoading("复制中......请勿关闭程序。");
            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"));
                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 (requestor.GetParm("flag") == "DC"  ) {
            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;
                    }
                }
            }
        }

        if (curSFQYSJKZQ == "1") {
            if (editMode == "Add" ) {
                var curPzh = dw_mx_top.GetItemString(1, "pzh");
                var curKhbh = dw_mx_top.GetItemString(1, "bmbh1");
                var curBmbh = dw_mx_top.GetItemString(1, "bmbh2");

                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, "zjsl") + "' ");
                }
                else {
                    requestor.MessageBox("粘贴失败", maseege.split("#")[1], ICON.Information);
                    isPast = "N"
                    return;

                }
            }

        } else {
            if (curDw.RowCount() < 1) {
                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"));
                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, "bmbh1"), "db", curJjfs, curQjfs); //FLDA 
                dw_mx.SetItem(row, "lsj", dw_ls_flda.GetItemNumber(1, "dbjg"));
                dw_mx.SetItem(row, "dpj", dw_ls_flda.GetItemNumber(1, "dpjg"));
                dw_mx.SetItem(row, "jj", dw_ls_flda.GetItemNumber(1, "lsjg"));

                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, "dbjg") / 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, "dbjg") / dw_ls_flda.GetItemNumber(1, "lsjg"));
                }

                dw_mx.SetItem(row, "cmzbh", dw_ls_flda.GetItemString(1, "cmzbm"));
            }
            dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "sumzjsl") + "' ");
            dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "sumzjsl"));
            dw_mx_top.SetItem(1, "zjje", dw_mx.GetItemNumber(1, "sumjsje"));
            requestor.CloseLoading();
        }

    }
    //#endregion

    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=DB&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_Db_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, "调拨配货单", 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 == "DC") {
            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);
                }

            }
        }

    }


    this.fjsm = function () {


        var curPzh = tab_Changed(tab_1, dw_hz, dw_mx_top);
        var curFjbz = self.tab_Changed_Fjbz(tab_1, dw_hz, dw_mx_top);
        var curGysbh = dw_mx_top.GetItemString(1, "bmbh1");


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


        webReq_pf.Invoke("PF_FenJian_Initialize", "curPzhStr=" + curPzh + ",&Flag=DB"); // Flag=1 分拣初始化);
        if (webReq_pf.StatusCode() == 200) {
            var rPzh = webReq_pf.ResponseText();

            if (rPzh.split("#")[0] == "H") {
                if (confirm("当前单据已存在分拣，是否打开？")) { // curJjfs + "#" + curDbck
                    curW_PH_FenJian_List.SetDataWindow(self, rPzh.split("#")[1], curFjbz, curGysbh, "db", curJjfs,"", curQjfs);
                    requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.PiFa.PiFaBase.W_PH_FenJian_List&curFlag=DB"), curW_PH_FenJian_List, null);
                } else {
                    return;
                }
            } else {
                curW_PH_FenJian_List.SetDataWindow(self, curPzh, "0", curGysbh, "db", curJjfs,"" ,curQjfs);//, curFjbz, curKhbh, "qd", curJjfs, curBmbh, curQjfs
                requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.PiFa.PiFaBase.W_PH_FenJian_List&curFlag=DB"), curW_PH_FenJian_List, null);
            }
        } else {
            requestor.MessageBox("提示", "数据保存失败!\r\n" + webReq_pf.ResponseText(), ICON.StopSign);
        }


    }



    this.tab_Changed_Fjbz = function (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.SyncSpkh = function () {
     
        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 == "DC" ) {
            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, "bmbh2");
        var bmmc = dw_mx_top.GetItemString(1, "bmmc2");
        var drbmbh = dw_mx_top.GetItemString(1, "bmbh1");
        var bmmc1 = dw_mx_top.GetItemString(1, "bmmc1");
        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 (drbmbh == "") {
            alert("请选择入出部门");
            return;
        }
        cur_W_YW_ZNSM_DBYW.SetDataWindow(self, bmbh, bmmc, drbmbh, bmmc1, rq, pzh, lydh, flag, dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bzxx"), curJjfs, curQjfs);
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.YeWuZongHeFenXi.W_YW_ZNSM_DBYW&pfpzh=" + pzh + "&ywlx=" + flag + "&smPzh=" + lydh), cur_W_YW_ZNSM_DBYW, null);
    }
    this.ZnsmFd = function (rPzh) {


        //服务器成功处理，返回单号
      
        //            dw_mx_top.SetItem(dw_mx_top.GetRow(), "pzh", rPzh);
        //            if (isAdd) {
        //                for (row = 1; row <= dw_mx.RowCount(); row++) {
        //                    dw_mx.SetItem(row, "pzh", rPzh);
        //                    dw_mx.SetItem(row, "mxdh", rPzh + "_" + self.formartStr(row));
        //                }
        //                curBigMaxMxdh = dw_mx.GetItemString(dw_mx.RowCount(), "mxdh");
        //                reCurBigMax = new Number(curBigMaxMxdh.substring(curBigMaxMxdh.length - 6, curBigMaxMxdh.length)) + 1;
        //                //isAdd = false;
        //            }
        //            dw_mx_top.ResetUpdate();
        //            dw_mx.ResetUpdate();
        //更新dw_hz,因为是分页的,直接复制会导致每页的记录数不一致了
        //所以采用刷新的记录的方式来更新列表 

        //刷新 
        self.SelectionChanged();
        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);
        } else {
            self.SelectionChanged_tab(rPzh);
        }

        self.SetEditMode("");
        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"));
        }

        dw_mx_top.GetChild("bmbh1", dwc);
        dwc.Retrieve("%", curYhbh, "DB");
        dw_mx_top.GetChild("bmbh2", dwc);
        dwc.Retrieve("%", curYhbh, "DBC");
        //#endregion           
        //-------------每次保存完删除业务表临时凭证号对应数据--------

        //-----------------------------------------------------------
        isPast = "N";
        //-----------------------------------------------------------

            cb_sm.SetVisible(false);
            sle_tmh.SetVisible(false);

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