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

    var self = this;
    this.Instance = null;
    var requestor = new PBWindow();
    var tab_1 = new TabControl(requestor);
    var dw_hz = new DataWindow(requestor);
    var dw_mkfhjb = new DataWindow(requestor);
    var sle_tmh = new SingleLineEdit(requestor);
    var dw_mx_top = new DataWindow(requestor);
    var dw_spda = new DataWindow(requestor);
    var dw_tmlsh_save_flag = new DataWindow(requestor);
    var dw_tmlst_list = new DataWindow(requestor);
    var dw_mdsp_list = new DataWindow(requestor);
    var dw_mx = new DataWindow(requestor);
    var dw_print = new DataWindow(requestor);
    var dw_pf_phd_id_name2 = new DataWindow(requestor);
    var dw_pf_phd_id_name = new DataWindow(requestor);
    var dw_35_kc = new DataWindow(requestor);
    var dw_ddmx_top_tmlr = new DataWindow(requestor);
    var dw_xt_div_tree_no_parm = new DataWindow(requestor);
    var dw_xt_print_print2_cmzbm = new DataWindow(requestor);
    var dw_3 = new DataWindow(requestor);
    var dw_proxy = new DataWindow(requestor);
    var dw_da_qx_mokuai = new DataWindow(requestor);
    var dw_sort = new DataWindow(requestor);
    var dw_parameter = new DataWindow(requestor);
    var dw_2 = new DataWindow(requestor);
    var dw_init = new DataWindow(requestor);
    var dw_pzbtm = new DataWindow(requestor);
    var dw_ddfs = new DataWindow(requestor);
    var sle_pptmfa_Value = new SingleLineEdit(requestor);
    var dw_1 = new DataWindow(requestor);
    var dw_tmjqfs = new DataWindow(requestor);
    var dw_Thfz = new DataWindow(requestor);
    var dw_bmkhye = new DataWindow(requestor);
    var dw_ls_flda = new DataWindow(requestor);
    var dw_tmbc = new DataWindow(requestor);
    var dw_ysbx = new DataWindow(requestor);
    var dw_bmkhye_new = new DataWindow(requestor);
    var dw_da_qx_mokuai_print = new DataWindow(requestor);
    var dw_import_PL = new DataWindow(requestor);
    var tb_1 = new ToolStrip(requestor);
    var ddlb_2 = new DropDownListBox(requestor);
    var ContextMenuStrip1 = new ContextMenu(requestor);
    var ContextMenuStrip2 = new ContextMenu(requestor);
    var ContextMenuStrip3 = new ContextMenu(requestor);

    if (typeof (this.bind) == "function") var baseBind = this.bind;
    this.bind = function (win) {
        self.Instance = win;
        if (typeof (baseBind) == "function") baseBind(win);

        if (requestor == null) requestor = new PBWindow();
        requestor.Attach(win);
        if (tab_1 == null) tab_1 = new TabControl(requestor);
        tab_1.Attach(win.Control("tab_1"));
        if (dw_hz == null) dw_hz = new DataWindow(requestor);
        dw_hz.Attach(win.Control("dw_hz"));
        if (dw_mkfhjb == null) dw_mkfhjb = new DataWindow(requestor);
        dw_mkfhjb.Attach(win.Control("dw_mkfhjb"));
        if (sle_tmh == null) sle_tmh = new SingleLineEdit(requestor);
        sle_tmh.Attach(win.Control("sle_tmh"));
        if (dw_mx_top == null) dw_mx_top = new DataWindow(requestor);
        dw_mx_top.Attach(win.Control("dw_mx_top"));
        if (dw_spda == null) dw_spda = new DataWindow(requestor);
        dw_spda.Attach(win.Control("dw_spda"));
        if (dw_tmlsh_save_flag == null) dw_tmlsh_save_flag = new DataWindow(requestor);
        dw_tmlsh_save_flag.Attach(win.Control("dw_tmlsh_save_flag"));
        if (dw_tmlst_list == null) dw_tmlst_list = new DataWindow(requestor);
        dw_tmlst_list.Attach(win.Control("dw_tmlst_list"));
        if (dw_mdsp_list == null) dw_mdsp_list = new DataWindow(requestor);
        dw_mdsp_list.Attach(win.Control("dw_mdsp_list"));
        if (dw_mx == null) dw_mx = new DataWindow(requestor);
        dw_mx.Attach(win.Control("dw_mx"));
        if (dw_print == null) dw_print = new DataWindow(requestor);
        dw_print.Attach(win.Control("dw_print"));
        if (dw_pf_phd_id_name2 == null) dw_pf_phd_id_name2 = new DataWindow(requestor);
        dw_pf_phd_id_name2.Attach(win.Control("dw_pf_phd_id_name2"));
        if (dw_pf_phd_id_name == null) dw_pf_phd_id_name = new DataWindow(requestor);
        dw_pf_phd_id_name.Attach(win.Control("dw_pf_phd_id_name"));
        if (dw_35_kc == null) dw_35_kc = new DataWindow(requestor);
        dw_35_kc.Attach(win.Control("dw_35_kc"));
        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_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_3 == null) dw_3 = new DataWindow(requestor);
        dw_3.Attach(win.Control("dw_3"));
        if (dw_proxy == null) dw_proxy = new DataWindow(requestor);
        dw_proxy.Attach(win.Control("dw_proxy"));
        if (dw_da_qx_mokuai == null) dw_da_qx_mokuai = new DataWindow(requestor);
        dw_da_qx_mokuai.Attach(win.Control("dw_da_qx_mokuai"));
        if (dw_sort == null) dw_sort = new DataWindow(requestor);
        dw_sort.Attach(win.Control("dw_sort"));
        if (dw_parameter == null) dw_parameter = new DataWindow(requestor);
        dw_parameter.Attach(win.Control("dw_parameter"));
        if (dw_2 == null) dw_2 = new DataWindow(requestor);
        dw_2.Attach(win.Control("dw_2"));
        if (dw_init == null) dw_init = new DataWindow(requestor);
        dw_init.Attach(win.Control("dw_init"));
        if (dw_pzbtm == null) dw_pzbtm = new DataWindow(requestor);
        dw_pzbtm.Attach(win.Control("dw_pzbtm"));
        if (dw_ddfs == null) dw_ddfs = new DataWindow(requestor);
        dw_ddfs.Attach(win.Control("dw_ddfs"));
        if (sle_pptmfa_Value == null) sle_pptmfa_Value = new SingleLineEdit(requestor);
        sle_pptmfa_Value.Attach(win.Control("sle_pptmfa_Value"));
        if (dw_1 == null) dw_1 = new DataWindow(requestor);
        dw_1.Attach(win.Control("dw_1"));
        if (dw_tmjqfs == null) dw_tmjqfs = new DataWindow(requestor);
        dw_tmjqfs.Attach(win.Control("dw_tmjqfs"));
        if (dw_Thfz == null) dw_Thfz = new DataWindow(requestor);
        dw_Thfz.Attach(win.Control("dw_Thfz"));
        if (dw_bmkhye == null) dw_bmkhye = new DataWindow(requestor);
        dw_bmkhye.Attach(win.Control("dw_bmkhye"));
        if (dw_ls_flda == null) dw_ls_flda = new DataWindow(requestor);
        dw_ls_flda.Attach(win.Control("dw_ls_flda"));
        if (dw_tmbc == null) dw_tmbc = new DataWindow(requestor);
        dw_tmbc.Attach(win.Control("dw_tmbc"));
        if (dw_ysbx == null) dw_ysbx = new DataWindow(requestor);
        dw_ysbx.Attach(win.Control("dw_ysbx"));
        if (dw_bmkhye_new == null) dw_bmkhye_new = new DataWindow(requestor);
        dw_bmkhye_new.Attach(win.Control("dw_bmkhye_new"));
        if (dw_da_qx_mokuai_print == null) dw_da_qx_mokuai_print = new DataWindow(requestor);
        dw_da_qx_mokuai_print.Attach(win.Control("dw_da_qx_mokuai_print"));
        if (dw_import_PL == null) dw_import_PL = new DataWindow(requestor);
        dw_import_PL.Attach(win.Control("dw_import_PL"));
        if (tb_1 == null) tb_1 = new ToolStrip(requestor);
        tb_1.Attach(win.Control("tb_1"));
        if (ddlb_2 == null) ddlb_2 = new DropDownListBox(requestor);
        ddlb_2.Attach(win.Control("ddlb_2"));
        if (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.PageSelectionChanged) == "function")
            win.AttachEvent("tab_1", "SelectionChanged", self.PageSelectionChanged);

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

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

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

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

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

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

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

        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_PeiHuo) == "function")
            win.AttachEvent("ddlb_2", "SelectionChanged", self.SelectionChanged_PeiHuo);

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

        if (typeof (self.UFenJian) == "function")
            win.AttachEvent("btn_UFenJian", "Clicked", self.UFenJian);

        if (typeof (self.CaiWuHeJia) == "function")
            win.AttachEvent("btn_cwhj", "Clicked", self.CaiWuHeJia);

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

        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("m_3", "Clicked", self.ImportTxt);

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

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

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

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

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

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

        if (typeof (self.ScanImport) == "function")
            win.AttachEvent("扫描枪导入ToolStripMenuItem", "Clicked", self.ScanImport);

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

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

    }

    if (typeof (this.unbind) == "function") var baseUnBind = this.unbind;
    this.unbind = function () {
        self.Instance = null;
        if (typeof (this.Release) == "function") this.Release();
        if (typeof (baseUnBind) == "function") baseUnBind();

        tab_1.Detach(); tab_1 = null;
        dw_hz.Detach(); dw_hz = null;
        dw_mkfhjb.Detach(); dw_mkfhjb = null;
        sle_tmh.Detach(); sle_tmh = null;
        dw_mx_top.Detach(); dw_mx_top = null;
        dw_spda.Detach(); dw_spda = null;
        dw_tmlsh_save_flag.Detach(); dw_tmlsh_save_flag = null;
        dw_tmlst_list.Detach(); dw_tmlst_list = null;
        dw_mdsp_list.Detach(); dw_mdsp_list = null;
        dw_mx.Detach(); dw_mx = null;
        dw_print.Detach(); dw_print = null;
        dw_pf_phd_id_name2.Detach(); dw_pf_phd_id_name2 = null;
        dw_pf_phd_id_name.Detach(); dw_pf_phd_id_name = null;
        dw_35_kc.Detach(); dw_35_kc = null;
        dw_ddmx_top_tmlr.Detach(); dw_ddmx_top_tmlr = 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_3.Detach(); dw_3 = null;
        dw_proxy.Detach(); dw_proxy = null;
        dw_da_qx_mokuai.Detach(); dw_da_qx_mokuai = null;
        dw_sort.Detach(); dw_sort = null;
        dw_parameter.Detach(); dw_parameter = null;
        dw_2.Detach(); dw_2 = null;
        dw_init.Detach(); dw_init = null;
        dw_pzbtm.Detach(); dw_pzbtm = null;
        dw_ddfs.Detach(); dw_ddfs = null;
        sle_pptmfa_Value.Detach(); sle_pptmfa_Value = null;
        dw_1.Detach(); dw_1 = null;
        dw_tmjqfs.Detach(); dw_tmjqfs = null;
        dw_Thfz.Detach(); dw_Thfz = null;
        dw_bmkhye.Detach(); dw_bmkhye = null;
        dw_ls_flda.Detach(); dw_ls_flda = null;
        dw_tmbc.Detach(); dw_tmbc = null;
        dw_ysbx.Detach(); dw_ysbx = null;
        dw_bmkhye_new.Detach(); dw_bmkhye_new = null;
        dw_da_qx_mokuai_print.Detach(); dw_da_qx_mokuai_print = null;
        dw_import_PL.Detach(); dw_import_PL = null;
        tb_1.Detach(); tb_1 = null;
        ddlb_2.Detach(); ddlb_2 = 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();
    var curW_CaiGou_ChaXun = new W_CaiGou_ChaXun();
    webReq.SetWebServiceUrl("/Service/ServiceCaiGouDingDan.ashx");
    //    var curW_PiFaMaiDuanTiXing_List = new W_PiFaMaiDuanTiXing_List();
    var webReq1 = new WebRequestor();
    webReq1.SetWebServiceUrl("/Service/ServiceKuCunGuanLi.ashx");

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

    var curMdjx = "0";
    var curW_OPEN_LSRKD = new W_PiFa_Lsrkd();
    var cur_W_TXTDR = new W_TXTDR();

    var curW_ScanImport = new W_ScanImport(); //扫描枪批量导入

    var curRowCount = 0;
    var reCurBigMax = 0;

    var dwc = new DataWindowChild();
    var curSpkh = "";
    var curUpdateOldSt = "";
    var G_bEditFlag = false;
    var isAdd = false;
    var curSaoMiaoLie = 0;
    var curW_PH_FenJian_List = new W_PH_FenJian_List();
    var curW_OPEN_BMDA = new OpenWindowQueryBase();
    var curBmbhAndBmmc = null; // 本单据默认部门！！！名称
    var curDjlx = "";
    var curYhbh = "";
    var curQxlx = "";
    var curJjfs = "";
    var curQjfs = "";
    var bxshow = "";       //版型是否显示
    var curTmlrms = ""; //条码录入模式
    //价格体系#是否按发货类型折扣#是否按订货出库#是否控制调换率#调换精确度#范围外调换处理#管理库存
    var curKhxx = "";
    var curCmbt = "";
    var jqd = 0;
    var jqw = 0;
    var curGnqxStr = "";    //功能权限
    var curJqdbm = "";
    var curDygs = "1"; // 打印格式默认是1 二维格式。
    var curDypx = "1"; // 打印排序
    var title_value = "";
    var curSjc = "";
    var curDw = null;
    var SQL_Dw = null;
    var curYxfkcBmbh = "";   //已调用的检查负库存的部门编号
    var curSfyxfkc = "N";    //是否允许负库存
    var curSysteData = "";   //条码流水号打印用的。
    var curSfqytmlsh = "0"     //是否启用条码流水号。 1启用，2不启用。

    var curCmBtRows = 0;
    var curCmBtCols = 0;
    var curCmBtRows1 = 0;
    var curCmBtCols1 = 0;

    var curOldSpkh = "";
    var curJsqYS = 0;  //计数器颜色
    var curJsqBX = 0;  //计数器版型
    var curSpkhYsbhBxbh = "";  //当前行的【款号+颜色+版型】
    var curSpkhYsbhBxbhSFGetKCSL = "N"; //
    var curRedCm = "";  //当前变红的列。
    var curLastFocusColumn = "";
    var curNewCyShiFouQy = "0"; //是否启用新版本财务
    var cueSmzt = "0"; //扫描状态；0单扫，1连扫
    var curSfQyQDID = "0";  // 如果启用渠道ID,默认不启用
    var curJqm = "";
    var curQxLzfc = "";    // 当前用户对应权限的列字符串；
    var curSetDisCount = 0; //整单折扣是否控制
    var flag = "";
    var curSelDays = ""; //默认该模块可查询天数
    var curSelSQL = "";

    var curSYGysbh = ""; //首页的客户
    var curSYBmbh = ""; //首页的部门

    var curFunctionId = "";
    var openflag = "";

    var curSfQYQXZ = "0";  // 是否启用新版权限组。
    var curUserGroupId = ""; //权限组编码
    var curTxtImportSplitString = ""; //TXT导入间隔符号“；”
    var cur_W_HYHKDR = new W_HYHKDR();
    var curSmslbs = 1;
    var curDzdPzh = "";
    var curGdhdy = "0"; //固定行打印，默认不是固定行打印
    var curCurCmbh = "";
    var curLastSpkhYsbhRow = "";
    var curFormPzh = ""; //外边Pzh反调
    var zhengdanzhekouFlag = "N";
    var curCheckKhxyedsaveFlag = "N";
    var curSaveReturnValue = "N";
    var curOldTopKhbh = "";          // 记录原始客户编号
    var curOldTopKhmc = "";          // 记录原始客户名称
    var curCheckKhxyedAuditeFlag = "0";
    var lastSortName = "";
    var SelectTabFlag = "Y";
    var curMDSPFlag = "0";
    var dw_mdsp_list = null;
    var curLxdz = "";
    var curPFSFJCKC = "1";  //批发出库单开单是否检查库存
    var curPFTSFJCKC = "1"; //批发退货单开单是否检查库存
    var curPFADHFHLXQJ = "0"; //批发按单行发货类型取价
    var curSfdzd = "0";
    var curSureTally = "N"; //是否可以记账

    var curCacheKcOrSqlKc = "0"; //做单显示的库存数据从哪来，0数据库，1缓存
    var isPast = "N";
    var delMxSpkh = ""; var updateBh = ""; var updateRq = "";
    var curMapUpdate = ""; //  new Map() ;
    var curMap = ""; //  new Map();
    var curW_DB_Cysl_list = new W_DB_Cysl_list();

    
    var curW_PH_HeJia_List = new W_PH_HeJia_List();
    var curMrbm = "";
    var curPzhStr = "";
    var curGysBMStr = "";
    var curFjdh = "";
    var curFjbz = "";
    var dpjson = null;
    var curSFQYSJKZQ = "1";
    //#region this.PostOpen
    this.PostOpen = function () {
        curSFQYSJKZQ = GetGlobalParm("XTCS", "SFQYSJKZQ", "qybz");



        //        curJsonSP.sss = "1";
        //        alert(curJsonSP.sss);
        if (dw_mdsp_list == null) {
            dw_mdsp_list = new DataWindow(requestor);
            dw_mdsp_list.Attach(requestor.Control("dw_mdsp_list"));
        }
        dpjson = eval("(" + requestor.GetParm("curJson") + ")");
        if (requestor.GetParm("curBmbhAndBmmc") != null && requestor.GetParm("curBmbhAndBmmc") != "") {
            curMrbm = requestor.GetParm("curBmbhAndBmmc").split("!!!")[0];
        }
        dw_mdsp_list.SetShowRetrieveMessage(false);
        curMDSPFlag = GetGlobalParm("XTCS", "MDSPKH", "qybz");
        dw_ddmx_top_tmlr.SetShowRetrieveMessage(false);
        dw_tmbc.SetShowRetrieveMessage(false);
        curSaveReturnValue = "N"
        curSfQyQDID = GetGlobalParm("XTCS", "SFQYQDID", "qybz");
        curPFSFJCKC = GetXiTongCanShu("PFSFJCKC", "XTCS", "qybz");
        curPFTSFJCKC = GetXiTongCanShu("PFTSFJCKC", "XTCS", "qybz");
        curSmslbs = parseInt(GetGlobalParm("TMSMSLBS", "PFTMSMSLBS", "bzxx"));
        curJqm = requestor.GetParm("curJqm");
        curSelDays = requestor.GetParm("seldays");
        curFunctionId = requestor.GetParm("curFunctionId");
        // self.InitQx();// 初始化权限 
        curSfqytmlsh = requestor.GetParm("curSfqytmlsh");
        curSysteData = requestor.GetParm("curDate");
        curSysteData = curSysteData.replace(" ", "");
        curNewCyShiFouQy = GetGlobalParm("xtcs", "CW_NEW", "qybz"); //是否启用新版本财务
        curPFADHFHLXQJ = GetGlobalParm("xtcs", "PFADHFHLXQJ", "qybz"); //批发按单行发货类型取价
        curSYBmbh = requestor.GetParm("curBmbh");
        curSYGysbh = requestor.GetParm("curGysbh");
        curDzdPzh = requestor.GetParm("curDzdPzh");
        var curQTPzh = requestor.GetParm("curQTPzh");
        if (curDzdPzh.length > 0) {
            curSfdzd = "1";
        }
        flag = requestor.GetParm("flag");
        curSfQYQXZ = GetGlobalParm("XTCS", "SFQYQXZ-NEW", "qybz"); // 是否启用新版权限组。
        curUserGroupId = requestor.GetParm("curUserGroupId"); //权限组编码
        curFormPzh = requestor.GetParm("curFormPzh"); //从外界传入的凭证

        curTxtImportSplitString = GetGlobalParm("XTCS", "TXT_IMPORT_SPLIT_STR", "csmc");

        if (curTxtImportSplitString.length < 1) {
            curTxtImportSplitString = ";";
        }

        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 初始化数据窗口的title,单据类型

        var title_value = requestor.GetParm("dw_yw_cg_top_title_value");

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

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

        //#region 强制修改权限
        curGnqxStr = requestor.GetParm("GnqxStr");
        if (curGnqxStr.indexOf("rbn_Qzxg") > -1) {
            ContextMenuStrip1.SetEnabled("rbn_qzxg", true);
        } else {
            ContextMenuStrip1.SetEnabled("rbn_qzxg", false);
        }
        if (curGnqxStr.indexOf("btn_AlterJsj") > -1) {
            dw_mx.Modify("lsj.protect='1'");
        } else {
            dw_mx.Modify("lsj.protect='0'");
        }
        //#endregion
        dw_mx_top.Modify("DataWindow.Readonly=yes");
        dw_mx.Modify("DataWindow.Readonly=yes");
        curDw = window.external.Control("dw_1");
        SQL_Dw = window.external.Control("dw_sql");
        bxshow = parseInt(requestor.GetParm("bxshow").toString());

        self.SelectionChanged_PeiHuo();
        if (dw_hz.RowCount() > 0) {
            var pzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
            dw_mx_top.Retrieve(pzh);
            dw_mx.Retrieve(pzh);
        }
        curTmlrms = GetGlobalTiaoMaLuRuMS(flag, "SCAN_BAG_FLAG_PF"); // 获取条码录入模式
        curCheckKhxyedAuditeFlag = GetGlobalParm("XTCS", "SFQY_YW_Audit_XYED", "qybz");

        ContextMenuStrip2.SetText("连扫ToolStripMenuItem", "单扫（√），连扫（×）");

        ContextMenuStrip2.SetVisible("扫描枪导入ToolStripMenuItem", false);


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

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

        if (curSfdzd != "0" && dw_hz.RowCount() > 0) {
            self.dw_hz_DoubleClicked(0, 0, 1, "");
        }
        dw_mx_top.Modify("bzxx.edit.autohscroll=yes");
        //        dw_hz.Modify("datawindow.detail.color='67108864' datawindow.detail.gradient.color='16777215' datawindow.detail.brushmode='1' ")


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


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

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

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


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


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

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


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


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

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

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


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

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

        }
    }

    //#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=CG&curFormPzh=" + curPzh + "&kdsj=" + curKdsj, true);
    }

    //#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);
        if (dw_mx_top.GetItemString(1, "lydh").substring(0, 2) == "RD") {
            if (flag == "CZ" && dwoName.substring(0, 2) == "cm" && dwoName.indexOf("cmz") < 0) {
                var curSpbh = dw_mx.GetItemString(row, "spkh") + dw_mx.GetItemString(row, "ysbh") + dw_mx.GetItemString(row, "bxbh") + dwoName;
                var curMapGetSpbh = self.DwGet(dw_pf_phd_id_name, curSpbh);
                //if (data > curMap.get(curSpbh)) { 
              
                if (data > curMapGetSpbh) {
                    requestor.MessageBox("提示", "修改数量只能比原始数值小", 3);
                    // dw_mx.SetItem(row, dwoName, curMap.get(curSpbh));
                    dw_mx.SetItem(row, dwoName, curMapGetSpbh);
                    return;
                }
                else if (data < 0) {

                    requestor.MessageBox("提示", "修改数量不能小于0", 3);
                    // dw_mx.SetItem(row, dwoName, curMap.get(curSpbh));
                    dw_mx.SetItem(row, dwoName, curMapGetSpbh);
                    return;
                }
                else {
                    if (dwoName.substring(0, 2) == "cm" && dwoName.indexOf("cmz") < 0) {


                        //curMapUpdate.Set(curPzh + curSpkh + curYsbh + curBxbh + curCmbt,)


                        curSpbh = dw_mx.GetItemString(dw_mx.GetRow(), "spkh") + dw_mx.GetItemString(dw_mx.GetRow(), "ysbh") + dw_mx.GetItemString(dw_mx.GetRow(), "bxbh") + dwoName;
                        //                        if (curMap.get(curSpbh) == null) {
                        //                             curMap.set(curSpbh, dw_mx.GetItemNumber(row, dwoName))                            
                        //                        } 
                        if (!self.DwHas(dw_pf_phd_id_name, curSpbh))
                            self.DwSet(dw_pf_phd_id_name, curSpbh, dw_mx.GetItemNumber(row, dwoName));


                        if (editMode == "Edit") {
                            var v = GetCmzMappingCm(dw_mx.GetItemString(row, "cmzbh"), dwoName);

                            var curPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
                            var curSpkh = dw_mx.GetItemString(row, "spkh");
                            var curYsbh = dw_mx.GetItemString(row, "ysbh");
                            var curBxbh = dw_mx.GetItemString(row, "bxbh");
                            var curBxbh = dw_mx.GetItemString(row, "bxbh");
                            var curCm = dw_mx.GetItemNumber(row, dwoName);
                            //                            dw_mx_top.SetItem(1, "bzxx", curPzh + "#" + curSpkh + curYsbh + curBxbh + v + "**********" + curCm)

                            var keyCm = curPzh + "#" + curSpkh + curYsbh + curBxbh + v;
                            var curMapUpdateGetSpbh = self.DwGet(dw_pf_phd_id_name2, curPzh + "#" + curSpkh + curYsbh + curBxbh + v);
                            //   var valueCm = curMapUpdate.get(curPzh + "#" + curSpkh + curYsbh + curBxbh + v)
                            var valueCm = curMapUpdateGetSpbh;
                            if (data.length < 1) data = 0
                            valueCm = valueCm.split("*")[0] + "*" + data;

                            //if (curMapUpdate.delete(curPzh + "#" + curSpkh + curYsbh + curBxbh + v)) {
                            //    curMapUpdate.set(keyCm, valueCm)
                            //}
                            self.DwDelete(dw_pf_phd_id_name2, curPzh + "#" + curSpkh + curYsbh + curBxbh + v);

                            self.DwSet(dw_pf_phd_id_name2, keyCm, valueCm);

                        }
                    }
                }


            }

        } else {
            if (editMode == "Edit") {
                var v = GetCmzMappingCm(dw_mx.GetItemString(row, "cmzbh"), dwoName);

                var curPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
                var curSpkh = dw_mx.GetItemString(row, "spkh");
                var curYsbh = dw_mx.GetItemString(row, "ysbh");
                var curBxbh = dw_mx.GetItemString(row, "bxbh");
                var curBxbh = dw_mx.GetItemString(row, "bxbh");
                //                var curCm = dw_mx.GetItemNumber(row, dwoName);
                //                            dw_mx_top.SetItem(1, "bzxx", curPzh + "#" + curSpkh + curYsbh + curBxbh + v + "**********" + curCm)
                if (dwoName.substring(0, 2) == "cm" && dwoName.indexOf("cmz") < 0) {
                    var keyCm = curPzh + "#" + curSpkh + curYsbh + curBxbh + v;

                    // var valueCm = curMapUpdate.get(curPzh + "#" + curSpkh + curYsbh + curBxbh + v)
                    var valueCm = self.DwGet(dw_pf_phd_id_name2, curPzh + "#" + curSpkh + curYsbh + curBxbh + v);
                    if (data.length < 1) data = 0
                    valueCm = valueCm.split("*")[0] + "*" + data;

                    //                            if (curMapUpdate.delete(curPzh + "#" + curSpkh + curYsbh + curBxbh + v)) {
                    //                                curMapUpdate.set(keyCm, valueCm)
                    //                            }

                    self.DwDelete(dw_pf_phd_id_name2, curPzh + "#" + curSpkh + curYsbh + curBxbh + v);
                    self.DwSet(dw_pf_phd_id_name2, keyCm, valueCm);
                }
            }
        }
    }

    //#endregion

    //#region this.dw_mx_itemFocusChange
    var cmflag = "N";
    var TempcurRow = 0;


    this.dw_mx_itemFocusChange = function (row, dwoName, data) {
        if (dwoName.substring(0, 2) == "cm" && dwoName.indexOf("cmz") < 0) {


            curSpbh = dw_mx.GetItemString(dw_mx.GetRow(), "spkh") + dw_mx.GetItemString(dw_mx.GetRow(), "ysbh") + dw_mx.GetItemString(dw_mx.GetRow(), "bxbh") + dwoName;



            if (self.DwGet(dw_pf_phd_id_name, curSpbh) == null) {
                //curMap.set(curSpbh, dw_mx.GetItemNumber(row, dwoName))

                self.DwSet(dw_pf_phd_id_name, curSpbh, dw_mx.GetItemNumber(row, dwoName));
            }

            if (editMode == "Edit") {
                var v = GetCmzMappingCm(dw_mx.GetItemString(row, "cmzbh"), dwoName);

                var curPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
                var curSpkh = dw_mx.GetItemString(row, "spkh");
                var curYsbh = dw_mx.GetItemString(row, "ysbh");
                var curBxbh = dw_mx.GetItemString(row, "bxbh");
                var curBxbh = dw_mx.GetItemString(row, "bxbh");
                var curCm = dw_mx.GetItemNumber(row, dwoName);


                var keyCm = curPzh + "#" + curSpkh + curYsbh + curBxbh + v;
                var valueCm = curCm + "*" + curCm;
                if (self.DwHas(dw_pf_phd_id_name2, keyCm) == false) {
                    //if (curMapUpdate.has(keyCm) == false) {
                    //curMapUpdate.set(keyCm, valueCm);

                    self.DwSet(dw_pf_phd_id_name2, keyCm, valueCm);
                }

            }
            var cur525Spkh = dw_mx.GetItemString(dw_mx.GetRow(), "spkh");
            var cur525Ysbh = dw_mx.GetItemString(dw_mx.GetRow(), "ysbh");
            //#region 处理库存的问题 --------begin-------

            self.setKCSL("", "", "", data, "");

            //#endregion 处理库存的问题 -----end---------     

            //#region 处理点亮的问题 --------begin-------
            self.setMdf(row, dwoName, cur525Spkh);

            //#endregion 处理点亮的问题 -----end------

        }
        curLastFocusColumn = dw_mx.GetColumnName();
        if (dw_mx.RowCount() > 0) {
            dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "sumzjsl"));
        } else {
            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;
        if (dw_mx_top.GetItemString(1, "gysbh") == "") {
            alert("请先选择部门!");
            dw_mx_top.SetColumn("gysbh");
            dw_mx_top.SetFocus();
            return;
        }
        if (dw_mx_top.GetItemString(1, "bmbh") == "") {
            alert("请先选择客户!");
            dw_mx_top.SetColumn("bmbh");
            dw_mx_top.SetFocus();
            return;
        }
        var dwoName = dw_mx.GetColumnName();

        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) {
                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, "gysbh");
            if (curSpkh.length < 1) {
                return;
            }
            dw_mx.GetChild("bxbh", dwc);
            dwc.Retrieve(curSpkh, "%");
            if (curBxbh.length < 1) {

                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


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

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

                } else {
                    curOldSpkh = data;

                    if (curJjfs == "CS03") {

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


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

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

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

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

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

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

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

            } catch (err) {

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

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

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

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

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

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


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

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

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

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

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

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

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

                                }

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

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

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

        }
        //折扣率
        else if (dwoName == "zkl") {
            if (curQjfs == "QDPJ")
                self.setJGJqd(row, dw_mx.GetItemNumber(row, "dpj") * parseFloat(data));
            if (curQjfs == "QLSJ")
                self.setJGJqd(row, dw_mx.GetItemNumber(row, "lsj") * parseFloat(data));

        }
        //折扣率=进价/零售价
        else if (dwoName == "jj") {
            var jg = parseFloat(data) + jqd;
            var len = (jg.toString()).split(".")[0].length + 1 + jqw;
            var zhjg = parseFloat((jg.toString()).substring(0, len));
            dw_mx.SetItem(row, "jj", zhjg);


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

            return 1;
        }

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

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

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

            // return 1;

        }
    }
    //#endregion


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

//        if (dwoName == "spkh") {
//            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", "");
//                if (flag == "CR" || flag == "CT") {
//                    dw_mx.SetItem(row, "fztm", "");
//                }
//                for (var i = 1; i < curCmBtCols1; i++) {
//                    dw_mx.SetItem(row, "cm" + i, 0);
//                }
//            }
//            dw_mx.GetChild(dwoName, dwc);


//            if (dwc.RowCount() <= 0 && data.length > 0) {
//                requestor.MessageBox("提示[款号]", "未找到款号为[" + data + "]的记录，请检查!", ICON.StopSign);
//                dw_mx.SetItem(row, "spkh", "");
//                return;
//            } else {
//                dw_mx.SetItem(dw_mx.GetRow(), "ppmc", dwc.GetItemString(dwc.GetRow(), "ppmc"));
//            }
//            var findRow = dwc.Find("spkh='" + data + "' ", 1, dwc.RowCount());

//            if (findRow <= 0) {
//                dw_mx.SetItem(row, "spkh", "");
//                dw_mx.SetItem(row, "ksmc", "");
//                dw_mx.SetItem(row, "jldw", "");
//                dw_mx.SetItem(row, "jj", 0);
//                dw_mx.SetItem(row, "dpj", 0);
//                dw_mx.SetItem(row, "lsj", 0);
//                dw_mx.SetItem(row, "zkl", 1);
//                dw_mx.SetItem(row, "cmzbh", "");
//                if (flag == "CR" || flag == "CT") {
//                    dw_mx.SetItem(row, "fztm", "");
//                }
//                requestor.MessageBox("提示[款号]", "未找到款号为[" + data + "]的记录，请检查!", ICON.StopSign);
//                return 1;
//            } else {
//                curOldSpkh = data;
//                if (curJjfs == "CS03") {

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


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

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






//                dw_mx.SetItem(row, "ksmc", dw_ls_flda.GetItemString(1, "ksmc"));
//                dw_mx.SetItem(row, "jldw", dw_ls_flda.GetItemString(1, "jldw"));
//                dw_mx.SetItem(row, "jj", dw_ls_flda.GetItemNumber(1, "lsjg"));
//                dw_mx.SetItem(row, "dpj", dw_ls_flda.GetItemNumber(1, "dpjg"));
//                if (curJjfs == "ZKZZ" && dw_ls_flda.GetItemNumber(1, "pfzk") != 999) {
//                    if (curQjfs == "QDPJ") {
//                        dw_mx.SetItem(row, "lsj", 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, "lsj", 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, "lsj", 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, "zkl", 1);
//                    else {
//                        if (curJjfs == "ZKZZ" && dw_ls_flda.GetItemNumber(1, "pfzk") != 999) {
//                            dw_mx.SetItem(row, "zkl", dw_ls_flda.GetItemNumber(1, "pfzk"));
//                        }
//                        else {
//                            dw_mx.SetItem(row, "zkl", 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, "zkl", 1);
//                    else {
//                        if (curJjfs == "ZKZZ" && dw_ls_flda.GetItemNumber(1, "pfzk") != 999) {
//                            dw_mx.SetItem(row, "zkl", dw_ls_flda.GetItemNumber(1, "pfzk"));
//                        }
//                        else {
//                            dw_mx.SetItem(row, "zkl", dw_ls_flda.GetItemNumber(1, "pfjg1") / dw_ls_flda.GetItemNumber(1, "lsjg"));
//                        }

//                    }
//                }

//                //alert([curMDSPFlag, flag, dw_mx.Describe("bxbh.visible")])
//                if (dw_mx.Describe("bxbh.visible") == "0") {
//                    dw_mx.SetItem(row, "bxbh", "-");
//                    dw_mx.SetItem(row, "bxmc", "-");

//                }

//                for (var i = 1; i < curCmBtCols1; i++) {
//                    dw_mx.SetItem(row, "cm" + i, 0);
//                }


//                // 处理点亮的问题 --------begin-------
//                self.setMdf(row, dwoName, data);
//                // 处理点亮的问题 --------end--------- 
//            }
//        }
//        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"));
//                //                if (curMDSPFlag == "1" && flag == "PT") {
//                //                    alert("222")
//                //                    self.SPMDSZCheck();
//                //                }
//                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 = 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;
//                var curCmzHaveDm = curChangecolor.split("#")[2].split(","); //尺码组中对应的代码
//                var curSpmxHaveDm = curChangecolor.split("#")[3].split(","); //商品明细中包含的代码              
//                //3#2,4#33,44,55,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,#AA,BB,CC,DD,EE,FF,GG
//                if (cNo > curEnd || cNo < curBeg) {
//                    requestor.MessageBox("提示", "没有此商品编号", 1);
//                    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("提示", "没有此商品编号", 1);
//                        dw_mx.SetItem(row, "cm" + cNo, 0);
//                        if (cNo >= curEnd) {// 到边境的时候跳到价格去
//                            if (dw_mx.Describe("lsj.visible") == "0") {
//                                dw_mx.SetColumn(curRedCm);
//                            } else {
//                                dw_mx.SetColumn("lsj");
//                            }
//                        } else {//没到边境的时候跳到下一个位置去
//                            dw_mx.SetColumn("cm" + parseInt(cNo + 1));
//                        }
//                        dw_mx.SetFocus();
//                        return 1;
//                    } else {
//                        if (self.JudgeKc(row, dwoName, data) == 0) {

//                            dw_mx.SetColumn(dwoName);
//                            dw_mx.SetFocus();
//                            return 1;
//                        }
//                        //精确度，小数位数以及舍入            
//                        if (dw_mx.RowCount() < 1) {
//                            return 1;
//                        }
//                        self.setJGJqd(row, dw_mx.GetItemNumber(row, "lsj")); //王飞0814修改前的调用
//                        if (cNo >= curEnd) {// 到边境的时候跳到价格去
//                            if (dw_mx.Describe("lsj.visible") == "0") {
//                                dw_mx.SetColumn(curRedCm);
//                            } else {
//                                dw_mx.SetColumn("lsj");
//                            }
//                        } else {//没到边境的时候跳到下一个位置去
//                            dw_mx.SetColumn("cm" + parseInt(cNo + 1));
//                        }
//                        dw_mx.SetFocus();
//                        return 1;
//                    }
//                }
//            }

//            return 1
//        }
//        else if (dwoName == "zkl" && parseFloat(data) > 0 && parseFloat(data) <= 1) {

//            if (curQjfs == "QDPJ")
//                self.setJGJqd(row, dw_mx.GetItemNumber(row, "dpj") * parseFloat(data)); //王飞0814修改前的调用
//            else
//                self.setJGJqd(row, dw_mx.GetItemNumber(row, "jj") * parseFloat(data)); //王飞0814修改前的调用

//        }
//        else if (dwoName == "lsj") {
//            if (parseFloat(data) >= 0) {
//                //return self.setJGJqd(row, parseFloat(data));
//                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, "lsj", zhjg);


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

//                return 1;
//            } else {
//                requestor.MessageBox("提示", "输入有误！", ICON.Information);
//                dw_mx.SetItem(row, dwoName, 0);
//                return 1;
//            }
//        } else if (dwoName == "fhlx") {
//            dw_mx.AcceptText();
//            self.SetRowFhlx(row, data, "Y");
//            return 1;

//        }
//    }
//    //#endregion


    this.SetRowFhlx = function (row, data, isChoose) {

        //#region 按发货类型取价格
        if (curPFADHFHLXQJ == "1") {

            if (flag == "CR" || flag == "DT") {
                if (isChoose != "Y") {
                    //  不是在行上手动选择的发货类型的，且是价格追踪的话，不取价格。

                    webReq.Invoke("GetKhSfjgzzAndAfhlxzk", "CusId=" + dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh"));
                    if (webReq.StatusCode() == 200) {
                        var curRetMsg = webReq.ResponseText();
                        var curShiFouJgzz = curRetMsg.split("#")[0];
                        var curShiFouAfhlxzk = curRetMsg.split("#")[1];
                        //价格追踪不重新按发货类型取价
                        if (curShiFouJgzz == "Y") {
                            return 1;
                        }
                        //不是按发货类型折扣 不重新按发货类型取价
                        if (curShiFouAfhlxzk != "Y") {
                            return 1;
                        }
                    }
                } else {


                    webReq.Invoke("GetKhSfjgzzAndAfhlxzk", "CusId=" + dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh"));
                    if (webReq.StatusCode() == 200) {
                        var curRetMsg = webReq.ResponseText();
                        var curShiFouJgzz = curRetMsg.split("#")[0];
                        var curShiFouAfhlxzk = curRetMsg.split("#")[1];
                        //  alert(curRetMsg);
                        //价格追踪不重新按发货类型取价
                        //  if (curShiFouJgzz == "Y") {
                        //      return;
                        //   }
                        //不是按发货类型折扣 不重新按发货类型取价
                        if (curShiFouAfhlxzk != "Y") {
                            return 1;
                        }
                    }
                }
                dw_mx.Modify("fhlx.protect='0'");
                webReq.Invoke("GetFHLXZKL", "CusId=" + dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh") + "&FHLX=" + data);
                if (webReq.StatusCode() == 200) {
                    var fhlxzkl = parseFloat(webReq.ResponseText());
                    if (curQjfs == "QLSJ") {
                        dw_mx.SetItem(row, "lsj", dw_mx.GetItemNumber(row, "jj") * fhlxzkl);
                        self.setJGJqd(row, dw_mx.GetItemNumber(row, "jj") * fhlxzkl);
                    } else {
                        dw_mx.SetItem(row, "lsj", dw_mx.GetItemNumber(row, "dpj") * fhlxzkl);
                        self.setJGJqd(row, dw_mx.GetItemNumber(row, "dpj") * fhlxzkl);
                    }
                    dw_mx.SetItem(row, "zkl", fhlxzkl);
                    dw_mx.SetItem(row, "fhlx", data);
                }
            }
        }
        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;
    }
    this.GetChangecolor_Sm = 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 != "spkh") {
            //                dwc.SetFilter("");
            //                dwc.Filter();
            //            }
            dw_mx.GetChild("spkh", dwc);
            dwc.SetFilter("");
            dwc.Filter();
            var vFind = dwc.Find("spkh='" + curSpkh + "'", 1, dwc.RowCount());
            if (vFind > 0) {
                curColors = dwc.GetItemString(vFind, "cmbtxx");
                curLastChangecolor = curColors;
            }
        }
        return curColors;
    }
    //#endregion

    //#region this.setJGJqd 
    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, "lsj", zhjg);
        return 1;

    }
    //#endregion



    //#region this.setKCSL 加载页面标号
    this.setKCSL = function (bm, kh, ys, bx, cmStr, curSCAN) {

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

        var myBm = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "gysbh"); // 部门     
        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 myYwDate = UtcDateFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "kdrq"));
        var myKhbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh");

        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='-'");
            }
        }
        var curChangeCols = "";
        if (curSCAN == "SCAN") {
            curChangeCols = self.GetChangecolor_Sm();
        } else {
            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]; //尺码组

        if (curCacheKcOrSqlKc == "0") {
            requestor.ClipBoard("'" + myBm + "','" + myKh + "','" + myYs + "','" + myBx + "','" + myCmStr + "','" + myYwDate + "','" + myKhbh + "','" + requestor.GetParm("flag"))
            dw_35_kc.Retrieve(myBm, myKh, myYs, myBx, myCmStr, myYwDate, myKhbh, requestor.GetParm("flag")); //取库存数量
        } else {
            dw_35_kc.Reset();
            var CacheKcStr = GetCacheKcsl(myBm, myKh, myYs, myBx, myCmStr, myYwDate, myKhbh, requestor.GetParm("flag"));
            dw_35_kc.InsertRow(1);
            dw_35_kc.SetItem(1, "kcsls", CacheKcStr);
        }
        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("kc" + (parseInt(t) + parseInt(curStartNum)) + "_t.Text='" + kcValue + "'");
                }
            }

            curSpkhYsbhBxbh = myKh + myYs + myBx + dw_mx.GetRow();  //当前行的【款号+颜色+版型】
            curSpkhYsbhBxbhSFGetKCSL = "Y";


        }


    }


    //#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(), "zjsl") == 0) {
                requestor.MessageBox("提示1000", "请为当前行输入数量", 1);
                dw_mx.SetColumn(curRedCm);
                dw_mx.SetFocus();
            } else if (dw_mx.GetRow() == dw_mx.RowCount()) {
                //dw_mx.RowsCopy(dw_mx.GetRow(), dw_mx.GetRow(), DWBUFFER.Primary, dw_mx, dw_mx.RowCount() + 1, DWBUFFER.Primary);
                if (dw_mx_top.GetItemString(1, "lydh").substring(0, 2) != "RD") {
                    dw_mx.ScrollToRow(dw_mx.InsertRow(0));

                    //复制行数据 ---begin---
                    var curMaxRow = dw_mx.RowCount();
                    dw_mx.SetItem(curMaxRow, "spkh", dw_mx.GetItemString(curMaxRow - 1, "spkh"));
                    dw_mx.SetItem(curMaxRow, "ksmc", dw_mx.GetItemString(curMaxRow - 1, "ksmc"));
                    dw_mx.SetItem(curMaxRow, "ysbh", dw_mx.GetItemString(curMaxRow - 1, "ysbh"));
                    dw_mx.SetItem(curMaxRow, "ysmc", dw_mx.GetItemString(curMaxRow - 1, "ysmc"));
                    dw_mx.SetItem(curMaxRow, "cmzbh", dw_mx.GetItemString(curMaxRow - 1, "cmzbh"));
                    dw_mx.SetItem(curMaxRow, "yslsh", dw_mx.GetItemString(curMaxRow - 1, "yslsh"));
                    dw_mx.SetItem(curMaxRow, "bxbh", dw_mx.GetItemString(curMaxRow - 1, "bxbh"));
                    dw_mx.SetItem(curMaxRow, "bxmc", dw_mx.GetItemString(curMaxRow - 1, "bxmc"));
                    dw_mx.SetItem(curMaxRow, "jldw", dw_mx.GetItemString(curMaxRow - 1, "jldw"));
                    dw_mx.SetItem(curMaxRow, "dpj", dw_mx.GetItemNumber(curMaxRow - 1, "dpj"));
                    dw_mx.SetItem(curMaxRow, "lsj", dw_mx.GetItemNumber(curMaxRow - 1, "lsj"));
                    dw_mx.SetItem(curMaxRow, "jj", dw_mx.GetItemNumber(curMaxRow - 1, "jj"));
                    dw_mx.SetItem(curMaxRow, "zkl", dw_mx.GetItemNumber(curMaxRow - 1, "zkl"));
                    //                if (requestor.GetParm("flag") == "CG" || requestor.GetParm("flag") == "PT") {
                    //                    dw_mx.SetItem(curMaxRow, "fhlx", dw_mx.GetItemString(curMaxRow - 1, "fhlx"));
                    //                    dw_mx.SetItem(curMaxRow, "cklx", dw_mx.GetItemString(curMaxRow - 1, "cklx"));
                    //                }
                    //复制行数据 ---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() == "lsj") {
            if (keyCode == 13 || keyCode == 39) {
                if (dw_mx.GetItemNumber(dw_mx.GetRow(), "zjsl") == 0) {
                    requestor.MessageBox("提示1038", "请为当前行输入数量", 1);
                    dw_mx.SetColumn(curRedCm);
                    dw_mx.SetFocus();
                } else if (dw_mx.GetRow() == dw_mx.RowCount()) {
                    if (dw_mx_top.GetItemString(1, "lydh").substring(0, 2) != "RD") {
                        dw_mx.ScrollToRow(dw_mx.InsertRow(0));

                        //复制行数据 ---begin---
                        var curMaxRow = dw_mx.RowCount();
                        dw_mx.SetItem(curMaxRow, "spkh", dw_mx.GetItemString(curMaxRow - 1, "spkh"));
                        dw_mx.SetItem(curMaxRow, "ksmc", dw_mx.GetItemString(curMaxRow - 1, "ksmc"));
                        dw_mx.SetItem(curMaxRow, "ysbh", dw_mx.GetItemString(curMaxRow - 1, "ysbh"));
                        dw_mx.SetItem(curMaxRow, "ysmc", dw_mx.GetItemString(curMaxRow - 1, "ysmc"));
                        dw_mx.SetItem(curMaxRow, "cmzbh", dw_mx.GetItemString(curMaxRow - 1, "cmzbh"));
                        dw_mx.SetItem(curMaxRow, "yslsh", dw_mx.GetItemString(curMaxRow - 1, "yslsh"));
                        dw_mx.SetItem(curMaxRow, "bxbh", dw_mx.GetItemString(curMaxRow - 1, "bxbh"));
                        dw_mx.SetItem(curMaxRow, "bxmc", dw_mx.GetItemString(curMaxRow - 1, "bxmc"));
                        dw_mx.SetItem(curMaxRow, "jldw", dw_mx.GetItemString(curMaxRow - 1, "jldw"));
                        dw_mx.SetItem(curMaxRow, "dpj", dw_mx.GetItemNumber(curMaxRow - 1, "dpj"));
                        dw_mx.SetItem(curMaxRow, "lsj", dw_mx.GetItemNumber(curMaxRow - 1, "lsj"));
                        dw_mx.SetItem(curMaxRow, "jj", dw_mx.GetItemNumber(curMaxRow - 1, "jj"));
                        dw_mx.SetItem(curMaxRow, "zkl", dw_mx.GetItemNumber(curMaxRow - 1, "zkl"));
                        //                    if (requestor.GetParm("flag") == "CG" || requestor.GetParm("flag") == "PT") {
                        //                        dw_mx.SetItem(curMaxRow, "fhlx", dw_mx.GetItemString(curMaxRow - 1, "fhlx"));
                        //                        dw_mx.SetItem(curMaxRow, "cklx", dw_mx.GetItemString(curMaxRow - 1, "cklx"));
                        //                    }
                        //复制行数据 ---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") == "0" || curGnqxStr.indexOf("btn_AlterJsj") > -1) {
                        dw_mx.AcceptText();
                        if (dw_mx.GetItemNumber(dw_mx.GetRow(), "zjsl") == 0) {
                            requestor.MessageBox("提示1156", "请为当前行输入数量", 1);
                            dw_mx.SetColumn(curRedCm);
                            dw_mx.SetFocus();
                        } else if (dw_mx.GetRow() == dw_mx.RowCount()) {
                            if (dw_mx_top.GetItemString(1, "lydh").substring(0, 2) != "RD") {
                                dw_mx.ScrollToRow(dw_mx.InsertRow(0));


                                //复制行数据 ---begin---
                                var curMaxRow = dw_mx.RowCount();
                                dw_mx.SetItem(curMaxRow, "spkh", dw_mx.GetItemString(curMaxRow - 1, "spkh"));
                                dw_mx.SetItem(curMaxRow, "ksmc", dw_mx.GetItemString(curMaxRow - 1, "ksmc"));
                                dw_mx.SetItem(curMaxRow, "ysbh", dw_mx.GetItemString(curMaxRow - 1, "ysbh"));
                                dw_mx.SetItem(curMaxRow, "ysmc", dw_mx.GetItemString(curMaxRow - 1, "ysmc"));
                                dw_mx.SetItem(curMaxRow, "cmzbh", dw_mx.GetItemString(curMaxRow - 1, "cmzbh"));
                                dw_mx.SetItem(curMaxRow, "yslsh", dw_mx.GetItemString(curMaxRow - 1, "yslsh"));
                                dw_mx.SetItem(curMaxRow, "bxbh", dw_mx.GetItemString(curMaxRow - 1, "bxbh"));
                                dw_mx.SetItem(curMaxRow, "bxmc", dw_mx.GetItemString(curMaxRow - 1, "bxmc"));
                                dw_mx.SetItem(curMaxRow, "jldw", dw_mx.GetItemString(curMaxRow - 1, "jldw"));
                                dw_mx.SetItem(curMaxRow, "dpj", dw_mx.GetItemNumber(curMaxRow - 1, "dpj"));
                                dw_mx.SetItem(curMaxRow, "lsj", dw_mx.GetItemNumber(curMaxRow - 1, "lsj"));
                                dw_mx.SetItem(curMaxRow, "jj", dw_mx.GetItemNumber(curMaxRow - 1, "jj"));
                                dw_mx.SetItem(curMaxRow, "zkl", dw_mx.GetItemNumber(curMaxRow - 1, "zkl"));
                                //                            if (requestor.GetParm("flag") == "CG" || requestor.GetParm("flag") == "PT") {
                                //                                dw_mx.SetItem(curMaxRow, "fhlx", dw_mx.GetItemString(curMaxRow - 1, "fhlx"));
                                //                                dw_mx.SetItem(curMaxRow, "cklx", dw_mx.GetItemString(curMaxRow - 1, "cklx"));
                                //                            }
                                //复制行数据 ---end-----

                                dw_mx.SetColumn("spkh");
                                dw_mx.SetFocus();
                            }
                        }
                    } else {
                        dw_mx.SetColumn("lsj");
                    }
                    dw_mx.SetFocus();
                } else {
                    dw_mx.SetColumn("cm" + (parseInt(cNo) + 1));
                    dw_mx.SetFocus();
                }
                return 1;
            } else if (keyCode == 37) {
                if (curBeg < parseInt(cNo)) {
                    dw_mx.SetColumn("cm" + (parseInt(cNo) - 1));
                    dw_mx.SetFocus();
                } else if (dw_mx.Describe("bxbh.Visible") == "1") {
                    dw_mx.SetColumn("bxbh");
                    dw_mx.SetFocus();
                } else {
                    dw_mx.SetColumn("ysbh");
                    dw_mx.SetFocus();
                }
                return 1;
            }
        } else if (dw_mx.GetColumnName() == "spkh" && (keyCode == 13 || keyCode == 39)) {

            dw_mx.AcceptText();
            if (dwc.RowCount() <= 0 && dw_mx.GetItemString(dw_mx.GetRow(), "spkh").length > 0) {
                requestor.MessageBox("提示1[款号]", "未找到款号为[" + dw_mx.GetItemString(dw_mx.GetRow(), "spkh") + "]的记录，请检查!", ICON.StopSign);
                dw_mx.SetItem(dw_mx.GetRow(), "spkh", "");
                return;
            } else {

                dw_mx.SetItem(dw_mx.GetRow(), "ppmc", dwc.GetItemString(dwc.GetRow(), "ppmc"));
            }

            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) {
            var curPhlydh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
            var curKdrq = dw_hz.GetItemDate(dw_hz.GetRow(), "kdrq");
            var curKdr = "";
            var curFjbz = dw_hz.GetItemString(dw_hz.GetRow(), "fjbz");
            var curFjdh = dw_hz.GetItemString(dw_hz.GetRow(), "fjdh");
            if (dowName == "yczt" || dowName == "cysl") {
                if (curFjbz > "1") {
                    curW_DB_Cysl_list.SetDataWindow(self, curFjdh, curPhlydh, curKdrq, curKdr,"CG");
                    requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.PiFa.PiFaBase.W_DB_Cysl_list"), curW_DB_Cysl_list, null);
                    return;
                }

            }
            dw_mx.ShareDataOff();
            tab_1.SelectTab(2);
            tb_1.SetEnabled("ddlb_2", false);
            tb_1.SetEnabled("btn_ChaXun", false);
            tb_1.SetEnabled("btn_Filter", false);
            tb_1.SetEnabled("btn_FenJian", false);

            tb_1.SetEnabled("btn_cwhj", false);
            tb_1.SetEnabled("btn_Export", true);


            var curPhbz = dw_hz.GetItemString(row, "phbz");
            if (curPhbz == "0") {
                tb_1.SetEnabled("btn_Add", true);
                tb_1.SetEnabled("btn_Edit", true);
                tb_1.SetEnabled("btn_Delete", true);
                tb_1.SetEnabled("btn_Trans", true);
            }
            else if (curPhbz == "1") {
                tb_1.SetEnabled("btn_Add", true);
                tb_1.SetEnabled("btn_Edit", false);
                tb_1.SetEnabled("btn_Delete", false);
                tb_1.SetEnabled("btn_Trans", false);
            }
            else if (curPhbz == "2") {
                tb_1.SetEnabled("btn_Add", true);
                tb_1.SetEnabled("btn_Edit", false);
                tb_1.SetEnabled("btn_Delete", false);


            }
            if (curFjdh > "1") {
                tb_1.SetEnabled("btn_Add", true);
                tb_1.SetEnabled("btn_Edit", false);
                tb_1.SetEnabled("btn_Delete", false);


            }
            var curPzh = dw_hz.GetItemString(row, "pzh");
            dw_mx_top.Retrieve(curPzh);
            dw_mx.Retrieve(curPzh);
            //打开明细的时候 没有记账的单据 重新获取 期初数据&结余数据

            if (dw_hz.GetItemString(dw_hz.GetRow(), "phbz") != "1") {
                self.GetKhQjfs();
            }
        }
        self.GetMaxXh();
    }
    //#endregion

    //#region this.GetMaxXh
    this.GetMaxXh = function () {
        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) {
        if (row < 1) {
            return;
        }
        var curPhbz = dw_hz.GetItemString(row, "phbz");
        var curFjbz = dw_hz.GetItemString(row, "fjbz");
        var curZdbz = dw_hz.GetItemString(row, "zdbz");

        if (curFjbz >= "1") {
            tb_1.SetEnabled("btn_Add", true);
            tb_1.SetEnabled("btn_Edit", false);
            tb_1.SetEnabled("btn_Delete", false);
            tb_1.SetEnabled("btn_FenJian", true);
            tb_1.SetEnabled("btn_cwhj", true);

        } else {
            tb_1.SetEnabled("btn_Add", true);
            tb_1.SetEnabled("btn_Edit", true);
            tb_1.SetEnabled("btn_Delete", true);
            tb_1.SetEnabled("btn_FenJian", true);
            tb_1.SetEnabled("btn_cwhj", 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.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'"); // 变红色
                        curCmbt = dw_mx.Describe(" cm" + a + "0" + parseInt(rowsNo - 1) + "_t.text");
                        if (editMode == "Edit") {


                        }
                        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'"); // 变红色
                        curCmbt = dw_mx.Describe(" cm" + a + "_t.text");

                        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_Delete", !bEditFlag);
        tb_1.SetEnabled("btn_Audit", !bEditFlag);
        tb_1.SetEnabled("btn_ChaXun", !bEditFlag);
        if (dw_mx_top.GetItemString(1, "lydh").substring(0, 2) == "RD") {
            tb_1.SetEnabled("btn_InsertRow", false);
        } else {
            tb_1.SetEnabled("btn_InsertRow", bEditFlag);
        }
        tb_1.SetEnabled("btn_DeleteRow", bEditFlag);
        tb_1.SetEnabled("btn_Save", bEditFlag);
        tb_1.SetEnabled("btn_Cancel", bEditFlag);
        sle_tmh.SetVisible(bEditFlag);  // 条码录入


        if (bEditFlag) {
            SelectTabFlag = "N";
            tab_1.SelectTab(2);
            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");
        }
    }
    //#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_2.SetText("未记账");
        dw_mx_top.Reset();
        dw_mx_top.ScrollToRow(dw_mx_top.InsertRow(0));
        sle_tmh.SetText(""); //清空条码号

        var curAddMaxPzh = "";
        //执行保存的WebService  
        curBmbhAndBmmc = requestor.GetParm("curBmbhAndBmmc");
        if ((curBmbhAndBmmc.split("!!!")[0]).length > 0) {
            dw_mx_top.GetChild("bmbh", dwc);
            if (dwc.Find("bmbh='" + curBmbhAndBmmc.split("!!!")[0] + "'", 0, dwc.RowCount()) > 0) {
                dw_mx_top.SetItem(1, "bmbh", curBmbhAndBmmc.split("!!!")[0]);
                dw_mx_top.SetItem(1, "bmmc", curBmbhAndBmmc.split("!!!")[1]);
            }
        }
        var ywbh = requestor.GetParm("flag");
        webReq.Invoke("GetCaiGouDingDanMaxPzh", "curYwbh=" + ywbh + "&curBmbh=" + curBmbhAndBmmc.split("!!!")[0]);
        if (webReq.StatusCode() == 200) {
            curAddMaxPzh = webReq.ResponseText();
        } else {
            alert(webReq.ResponseText());
            return;
        }
        dw_mx_top.SetItem(1, "pzh", curAddMaxPzh);
        dw_mx_top.SetItem(1, "cgy", curYhbh);

        if (ywbh == "CZ") {
            dw_mx_top.SetItem(1, "cgfs", "1");
        }

        dw_mx.Reset();
        dw_1.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();

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

        tb_1.SetEnabled("btn_ChaXun", false);
        tb_1.SetEnabled("btn_Filter", false);
        tb_1.SetEnabled("btn_FenJian", false);
        tb_1.SetEnabled("btn_cwhj", false);

        //采购通知&采购退通知。
        if (ywbh == "CZ") {
            tb_1.SetText("ddlb_2", "全部");
        } else {
            tb_1.SetText("ddlb_2", "未记账");
        }
        openflag = "Add"
        //新增的时候。初始化折扣卡=1

    }
    //#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.Exit
    this.Exit = function () {
        if (self.CloseQuery() == 1)
            return;
        setTimeout("window.close();", 100);


    }
    //#endregion  

    //#region this.InsertRow
    this.InsertRow = function () {
        if (editMode == "")
            return;
        if (dw_mx_top.GetItemString(1, "lydh").substring(0, 2) != "RD") {
            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(), "jj", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "jj"));
                dw_mx.SetItem(dw_mx.GetRow(), "zkl", dw_mx.GetItemNumber(dw_mx.RowCount() - 1, "zkl"));
                dw_mx.SetItem(dw_mx.GetRow(), "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.SetItem(dw_mx.GetRow(), "bzxx", dw_mx.GetItemString(dw_mx.RowCount() - 1, "bzxx"));
            }
            dw_mx.SetColumn("spkh");
            dw_mx.SetFocus();
            dw_mx.ScrollFirstPage();
            dw_mx.ScrollToRow(dw_mx.RowCount());
        }
    }
    //#endregion  

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

        var curPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
        var curSpkh = dw_mx.GetItemString(row, "spkh");
        var curYsbh = dw_mx.GetItemString(row, "ysbh");
        var curBxbh = dw_mx.GetItemString(row, "bxbh");
        var curBxbh = dw_mx.GetItemString(row, "bxbh");
        var curCm = "";
        var keyCm = "";
        var valueCm = "";
        cmflag = "N";
        if (status == DWITEMSTATUS.DataModified || status == DWITEMSTATUS.NotModified) {
            if (requestor.MessageBox("提示", "是否确认删除当前明细记录?", ICON.Question, BUTTON.YesNo, 2) == 2) {
                dw_mx.SetFocus();
                return;
            }
        }

        if (editMode == "Edit") {

            for (var i = 1; i <= 35; i++) {

                var v = GetCmzMappingCm(dw_mx.GetItemString(row, "cmzbh"), "cm" + i);
                curCm = dw_mx.GetItemNumber(row, "cm" + i);
                keyCm = curPzh + "#" + curSpkh + curYsbh + curBxbh + v;
                valueCm = curCm + "*" + 0;

                self.DwSet(dw_pf_phd_id_name2, keyCm, valueCm);
                //  curMapUpdate.set(keyCm, valueCm);

            }

        }

        curLastSpkhYsbhRow = "";
        dw_mx.DeleteRow(0);
        dw_mx.SetFocus();

    }
    //#endregion  

    //#region this.Cancel
    this.Cancel = function () {
        //        if (requestor.MessageBox("提示", "数据还没有保存,是否继续取消?", ICON.Question, BUTTON.YesNo) == 2) {
        //            return 1;
        //        }
        curFormPzh = "";
        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_2", true);
        tb_1.SetEnabled("btn_ChaXun", true);
        tb_1.SetEnabled("btn_Filter", true);
        tb_1.SetEnabled("btn_Export", true);

        isAdd = false;
        self.SelectionChanged_PeiHuo();
        var findRow = dw_hz.Find("pzh='" + pzh + "'", 1, dw_hz.RowCount());
        if (findRow > 0) {
            dw_hz.ScrollToRow(findRow);
        }
    }
    //#endregion

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

        curSpkh = "";
        curUpdateOldSt = "";
        G_bEditFlag = false;
        isAdd = false;
        curSaoMiaoLie = 0;

        curW_OPEN_BMDA = new OpenWindowQueryBase();
        curBmbhAndBmmc = null; // 本单据默认部门！！！名称
        curDjlx = "";
        curYhbh = "";
        curQxlx = "";
        curJjfs = "";
        curQjfs = "";
        bxshow = "";       //版型是否显示
        curTmlrms = ""; //条码录入模式
        //价格体系#是否按发货类型折扣#是否按订货出库#是否控制调换率#调换精确度#范围外调换处理#管理库存
        curKhxx = "";
        curCmbt = "";
        jqd = 0;
        jqw = 0;
        curGnqxStr = "";    //功能权限
        curJqdbm = "";
        curDygs = "1"; // 打印格式默认是1 二维格式。
        curDypx = "1"; // 打印排序
        title_value = "";
        curSjc = "";
        curDw = null;
        SQL_Dw = null;
        curYxfkcBmbh = "";   //已调用的检查负库存的部门编号
        curSfyxfkc = "N";    //是否允许负库存
        curSysteData = "";   //条码流水号打印用的。
        curSfqytmlsh = "0"     //是否启用条码流水号。 1启用，2不启用。

        curCmBtRows = 0;
        curCmBtCols = 0;
        curCmBtRows1 = 0;
        curCmBtCols1 = 0;

        curOldSpkh = "";
        curJsqYS = 0;  //计数器颜色
        curJsqBX = 0;  //计数器版型
        curSpkhYsbhBxbh = "";  //当前行的【款号+颜色+版型】
        curSpkhYsbhBxbhSFGetKCSL = "N"; //
        curRedCm = "";  //当前变红的列。
        curLastFocusColumn = "";
        curNewCyShiFouQy = "0"; //是否启用新版本财务

        curSfQyQDID = "0";  // 如果启用渠道ID,默认不启用
        curJqm = "";
        curQxLzfc = "";    // 当前用户对应权限的列字符串；
        curSetDisCount = 0; //整单折扣是否控制
        flag = "";
        curSelDays = ""; //默认该模块可查询天数
        //     curSelSQL = "";

        curSYGysbh = ""; //首页的客户
        curSYBmbh = ""; //首页的部门

        curFunctionId = "";
        openflag = "";

        curSfQYQXZ = "0";  // 是否启用新版权限组。
        curUserGroupId = ""; //权限组编码
        curTxtImportSplitString = ""; //TXT导入间隔符号“；”
        cur_W_HYHKDR = new W_HYHKDR();
        curSmslbs = 1;
        curDzdPzh = "";
        curGdhdy = "0"; //固定行打印，默认不是固定行打印
        curCurCmbh = "";
        curLastSpkhYsbhRow = "";

        self.PostOpen();

    }
    //#endregion

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

        var row = dw_hz.GetRow();

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

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

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

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


        }
        self.GetMaxXh();
        tb_1.SetEnabled("ddlb_1", false);
        tb_1.SetEnabled("ddlb_2", false);
        tb_1.SetEnabled("btn_ChaXun", false);
        tb_1.SetEnabled("btn_Filter", false);
        tb_1.SetEnabled("btn_Export", false);

        if (ControlDiscount(dw_mx, "CG") == "1") {
            curSetDisCount = 1;
        }
//        if (curSetDisCount == 1) {
//            em_1.SetEnabled(true);
//        }
//        else
//        { em_1.SetEnabled(false); }
        openflag = "Edit";
        //新增的时候。初始化折扣卡=0
        self.ClareKcAndCmzAll();
//        em_1.SetText("1");
        //self.GetSFYSGYSKCFlag();
    }

    //#endregion  

    //#region SelectionChanged_PeiHuo_tab
    this.SelectionChanged_PeiHuo_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") {
            //alert(curTabindex)
            var findRowaa = dw_hz.Find("pzh='" + pzh + "' ", 1, dw_hz.RowCount());
            dw_hz.ScrollToRow(findRowaa);
            self.Hz_RowFocusChanged(dw_hz.GetRow());
        }
    }
    //#endregion


    //--------------------------------------------------右键功能--------------------------------------begin------------
    //#region this.QZXG(强制修改)
    this.LSRKD = function () {
        curW_OPEN_LSRKD.SetDataWindow(dw_mx_top.GetItemString(1, "gysbh"), dw_mx_top.GetItemString(1, "bmbh"), dw_mx.GetItemString(dw_mx.GetRow(), "spkh"));
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.PiFa.PiFaBase.W_PiFa_Lsrkd&spkh=" + dw_mx.GetItemString(dw_mx.GetRow(), "spkh") + ""), curW_OPEN_LSRKD, null);
    }
    //#endregion

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


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

        var phbz = dw_hz.GetItemString(dw_hz.GetRow(), "phbz");
        var fhjb = dw_hz.GetItemString(dw_hz.GetRow(), "fjbz");
        if (phbz == "1") {
            requestor.MessageBox("提示", "该单据已发货，不能被强制修改！", ICON.StopSign);
            return;
        }
        if (fhjb == "1") {
            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  



    this.ExportExcel = function () {
        dw_mx.Export();
    }
    var curFlag = "";
    var curTbflag = "";

    //#region  导入返回检索数据
    this.GetRetVFlag = function (str1, str2) {
        self.Update_Mark("5", str2);
        curFlag = str1;
        curTbflag = str2;
        self.SelectionChanged_PeiHuo();
        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_PeiHuo_tab(str2);
        }
        dw_mx_top.SetFocus();

        dw_mx_top.Modify("zjsl.text='" + dw_mx.GetItemNumber(1, "sumzjsl") + "' ");

        if (dw_mx.RowCount() > 0) {
            dw_mx_top.Modify("zjsl.text='" + dw_mx.GetItemNumber(1, "sumzjsl") + "' ");
        } else {
            dw_mx_top.Modify("zjsl.text='0' ");
        };



        tb_1.SetEnabled("btn_Add", true);
        tb_1.SetEnabled("btn_Edit", true);
        tb_1.SetEnabled("btn_Delete", true);
        tb_1.SetEnabled("btn_Trans", true);
        tb_1.SetEnabled("btn_UTrans", 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", false);
        tb_1.SetEnabled("btn_Print", true);
        tb_1.SetEnabled("btn_Export", true);
        tb_1.SetEnabled("btn_ChaXun", false);
        //#region  处理TXT导入之后，上期余额被清空的BUG
        //        self.SetSdjyAndLjjy();
        //#endregion


    }
    //#endregion

    this.Update_Mark = function (val, pzh) {
        //        alert(["curVar=" + val + "&curPZH=" + pzh])
        webReq.Invoke("Update_Mark", "curVar=" + val + "&curPZH=" + pzh);

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

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

    //#region import
    this.ImporExcel = function () {
        if (dw_mx_top.GetItemString(1, "lydh").substring(0, 2) == "RD") {
            requestor.MessageBox("提示", "日常配货生成单据，不允许导入数据！", ICON.Information);
            return;
        }
        dw_mx_top.AcceptText();
        var curskfs = "skfs";
        //客户
        var curkh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh");
        if (curkh.length < 1) {
            alert("客户编号不能为空");
            return;
        }
        //部门
        var curbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "gysbh");
        if (curbh.length < 1) {
            alert("部门编号不能为空");
            return;
        }


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

        var currq = UtcDateFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "kdrq"));
        if (currq.length < 1) {
            alert("日期不能为空");
            return;
        }
        cur_W_HYHKDR.SetDataWindow(W_CaiGou_PeiHuoDan, self)
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.import.W_HYHKDR&FunctionID=" + curFunctionId + "&bmbh=" + curkh + "&gysbh=" + curbh + "&skfs=" + curskfs + "&rkfs=" + currkfs + "&kdrq=" + currq), cur_W_HYHKDR, null);

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

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

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

        if (self.CheckTrans()) {
            return;
        }
        dw_hz.ReSelectRow(row);
        dw_hz.RefreshDetails();

        var curJzbz = "";
        var flag = requestor.GetParm("flag");

        var curLypzh = "";
        var curBmbh = "";
        var curKhbh = "";
        curLypzh = dw_mx_top.GetItemString(1, "lydh");
        curBmbh = dw_mx_top.GetItemString(1, "gysbh");
        curKhbh = dw_mx_top.GetItemString(1, "bmbh");

        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;

        var tableNameHz = requestor.GetParm("tableNameHz");
        var tableNameMx = requestor.GetParm("tableNameMx");

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

        webReq.Invoke("CaiGouDingDan_Delete", "curPzh=" + curPzh + "&tableNameHz=" + tableNameHz + "&tableNameMx=" + tableNameMx + "&curJzbz=" + curJzbz + "&curRecord=" + "&curId=" + curFunctionId + "&curLypzh=" + curLypzh + "&curBmbh=" + curBmbh + "&curKhbh=" + curKhbh);
        if (webReq.StatusCode() == 200) {
            //dw_hz.RowsDiscard(row, row, DWBUFFER.Primary);

            dw_hz.DeleteRow(row);
            requestor.MessageBox("提示", webReq.ResponseText());
            tab_1.SetSelectedTab(1);
            tb_1.SetEnabled("ddlb_1", true);
            tb_1.SetEnabled("ddlb_2", true);
            tb_1.SetEnabled("btn_ChaXun", true);
            tb_1.SetEnabled("btn_Filter", true);
            tb_1.SetEnabled("btn_Export", true);
            if (dw_hz.GetRow() > 0) {
                curPzh = tab_Changed(tab_1, dw_hz, dw_mx_top);
                self.SelectionChanged_tab(curPzh);

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

    //#endregion  


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

        if (curTabindex == "1") {

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

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

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

    //#region this.Save 保存。。

    this.Save = function () {
        var curMapStr = "";
        //for循环取Map的所有键值
//        if (editMode == "Edit") {
//            var value = "0*0";
//            var key = "";
//            for (var i = 1; i <= dw_pf_phd_id_name2.RowCount(); i++) {

//                value = dw_pf_phd_id_name2.GetItemString(i, "name");
//                key = dw_pf_phd_id_name2.GetItemString(i, "id");
//                if (value != "0*0") {
//                    if (value.split("*")[0] != value.split("*")[1]) {
//                        var curMapGetSpbh = self.DwGet(dw_pf_phd_id_name2, key);

//                        curMapStr += key + "#" + curMapGetSpbh + "@";
//                    }
//                }
//            }
//        }

        requestor.ClipBoard(curMapStr);
        //return;

        //
        dw_mx_top.AcceptText();
        dw_mx.AcceptText();
        if (!isAdd) {

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

        dw_mx_top.SetItem(1, "gysbh", dw_mx_top.GetItemString(1, "gysbh"));
        dw_mx_top.SetItem(1, "djlx", curDjlx);
        if ((dw_mx_top.ModifiedCount() + dw_mx.DeletedCount() + dw_mx.ModifiedCount()) <= 0) {
            alert("没有数据需要保存!");
            return;
        }
        var flag = requestor.GetParm("flag");
        var curLypzh = "";
        var curBmbh = "";
        var curKhbh = "";
        curLypzh = dw_mx_top.GetItemString(1, "lydh");
        curBmbh = dw_mx_top.GetItemString(1, "gysbh");
        curKhbh = dw_mx_top.GetItemString(1, "bmbh");

        var skfsbz = "";
        var curZh = "";
        var curSkfs = "";




        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, "zjsl");
            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;
        }
        dw_mx.SetItem(dw_mx.RowCount(), "cm35", dw_mx.GetItemNumber(dw_mx.RowCount(), "cm35"));
        if (curCheckNullValue.length > 0) {
            requestor.MessageBox("提示", curCheckNullValue.toString(), ICON.StopSign);
            return;
        }
        if (curCheckFuValue.length > 0) {
            requestor.MessageBox("提示", curCheckFuValue.toString(), ICON.StopSign);
            return;
        }

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

        if (dw_mx.ModifiedCount() > 0) {
            if (!dw_mx.CheckData("*", ""))
                return;
        }
        var gysbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "gysbh");
        var tzrq = UtcDateTimeFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "kdrq"));
        dw_mx_top.SetItem(dw_mx_top.GetRow(), "kdrq", UtcDateFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "kdrq")));
        webReq1.Invoke("GetTallystatus", "gysbh=" + gysbh + "&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"));
        } else {
            dw_mx_top.SetItem(1, "zjsl", 0);
        };

        if (dw_mx.RowCount() > 0) {
            dw_mx_top.SetItem(1, "zjje", dw_mx.GetItemNumber(1, "sumjsje"));
        } else {
            dw_mx_top.SetItem(1, "zjje", 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 nrow = 0;
        var ljqk = 0;


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

        dw_mx_top_data = dw_mx_top.GetChanges();
        dw_mx_data = dw_mx.GetChanges();



        webReq.Invoke("CaiGouDingDan_Save", "dw_Master=" + dw_mx_top_data + "&dw_Detail=" + dw_mx_data + "&hzDwName=" + dw_mx_top.GetDataObject() + "&flag=" + flag + "&mxDwName=" + dw_mx.GetDataObject() + "&ywFlag=" + flag + "&curSysDate=" + curSysteData + "&curOpenFlag=" + openflag + "&curId=" + curFunctionId + "&curLogStr=" + "&curPzh=" + curPzh + "&curLypzh=" + curLypzh + "&curBmbh=" + curBmbh + "&curKhbh=" + curKhbh + "&curMapStr=" + curMapStr + "&bfpzh=" + dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh"));

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

            //服务器成功处理，返回单号
            var rPzh = webReq.ResponseText();

            self.SelectionChanged_PeiHuo();
            dw_mx_top.Retrieve(rPzh);
            dw_mx.Retrieve(rPzh);

            //找到相应的记录

            var findRow = dw_hz.Find("pzh='" + rPzh + "' ", 1, dw_hz.RowCount());
            if (findRow > 0) {
                dw_hz.ScrollToRow(findRow);
                self.SetEditMode("");
            } else {
                self.SelectionChanged_PeiHuo_tab(rPzh);
                //self.Hz_RowFocusChanged(dw_hz.GetRow());
            }
            curSaveReturnValue = "Y"
            if (zhengdanzhekouFlag == "N") {

                requestor.MessageBox("提示", "数据保存成功!", ICON.Information);
                tb_1.SetEnabled("btn_Export", true);
            }


            //   self.InitParm();
            if (isAdd && isPast == "Y") {
                DELETE_PZH_TO_YW(curPzh);
                isAdd = false;
            }
            //删除临时保存文件
            self.DelFile();
            self.ClareKcAndCmzAll();
            dw_mx_top.SetFocus();

            tb_1.SetEnabled("btn_Add", true);
            tb_1.SetEnabled("btn_Edit", true);
            tb_1.SetEnabled("btn_Delete", true);
            tb_1.SetEnabled("btn_Trans", true);
            tb_1.SetEnabled("btn_UTrans", 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", false);
            tb_1.SetEnabled("btn_Print", true);
            tb_1.SetEnabled("btn_Export", true);
            tb_1.SetEnabled("btn_ChaXun", false);
            //-------------每次保存完删除业务表临时凭证号对应数据--------

            isPast = "N";
            //-----------------------------------------------------------
        }
        else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
            dw_mx_top.SetFocus();
        }
        zhengdanzhekouFlag = "N";
    }
    //#endregion   

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

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




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

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

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

    this.dw_mx_top_editChanged = function (row, dwoName, data) {
        if (dwoName == "bmbh") {
            dw_mx_top.GetChild(dwoName, dwc);
            if (data != "") {
                dwc.Retrieve("%" + data + "%", curYhbh,"cg");
            }
            else {
                dwc.Retrieve("%", curYhbh, "cg");
            }
        } else if (dwoName == "gysbh") {
            dw_mx_top.GetChild(dwoName, dwc);
            if (data != "") {
                dwc.Retrieve("%" + data + "%", curYhbh);
            }
            else {
                dwc.Retrieve("%", curYhbh);
            }
        } else if (dwoName == "cgy") {
            dw_mx_top.GetChild("cgy", dwc);
            if (data != "") {
                dwc.Retrieve("%" + data + "%", curYhbh, "cg");
            } else {
                dwc.Retrieve("%", curYhbh, "cg");
            }
        }
    }
    //#endregion 

    //#region this.dw_mx_top_itemChanged  检查供应商数据完整性

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

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

//            if (flag == "CG" && DDYWGSYKCFlag == "1") {
//                //
//                self.GetSFYSGYSKCFlag();
//            }
        } else if (dwoName == "bmbh") {
            if (gysbh == bmbh) {
                requestor.MessageBox("提示", "部门和供应商不可相同！", ICON.Information);
                dw_mx_top.SetItem(row, dwoName, "");
                return 1;
            }
            dw_mx_top.GetChild(dwoName, dwc);
            dwc.Retrieve("%", curYhbh, curQxlx);
            var findRow = dwc.Find("UPPER(bmbh)=UPPER('" + data + "') ", 1, dwc.RowCount());
            if (findRow <= 0) {
                requestor.MessageBox("提示", "未找到部门编号为1111[" + data + "]的记录，请检查!", ICON.StopSign);
                dw_mx_top.SetItemNull(row, dwoName);
                dwc.Retrieve("%", curYhbh, curQxlx);
                return 1;
            } else {
                dw_mx_top.SetItem(row, "bmmc", dwc.GetItemString(findRow, "bmmc"));

                //#region 加载买断商品

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

//                if (flag == "CG" && DDYWGSYKCFlag == "1") {
//                    //
//                    self.GetSFYSGYSKCFlag();
//                }
//                //#endregion
            }
            self.ClareKcAndCmzAll();
        } else if (dwoName == "cgy") {
            dw_mx_top.GetChild(dwoName, dwc);
            var findRow = dwc.Find("ygbh='" + data + "' ", 1, dwc.RowCount());
            if (findRow <= 0) {
                requestor.MessageBox("提示", "未找到采购员编号为[" + data + "]的记录，请检查!", ICON.StopSign);
                dw_mx_top.SetItemNull(row, dwoName);
                dwc.Retrieve("%", curYhbh, "cg");
                return 1;
            }
        } else if (dwoName == "rkfs") {
            if (flag == "CT" || flag == "CR") {
                dw_mx_top.AcceptText();
                var rkfs = dw_mx_top.GetItemString(1, "rkfs");
                for (var i = 1; i <= dw_mx.RowCount(); i++) {
                    dw_mx.SetItem(i, "rkfs", rkfs);
                }
            }

        }

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

                alert("请先选订货择部门1!");
                dw_mx_top.SetColumn("gysbh");
                dw_mx_top.SetFocus();
                return;
            }
            if (dw_mx.GetItemString(1, "spkh") != "") {
                if (dw_mx_top.GetItemString(1, "lydh").substring(0, 2) != "RD") {
                    dw_mx.ScrollToRow(dw_mx.InsertRow(0));

                    dw_mx.SetColumn("spkh");
                    dw_mx.SetFocus();
                }
            } else {
                dw_mx.ScrollToRow(1);
                dw_mx.SetColumn("spkh");
                dw_mx.SetFocus();
            }
            return 1;
        }
    }
    //#endregion 



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

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


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

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

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

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

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


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

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

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

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



            if (curJjfs == "CS03") {

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

            dw_ddmx_top_tmlr.Retrieve(ls_tmh, curGysbh, "CG", curJjfs, curQjfs);
            if (dw_ddmx_top_tmlr.RowCount() == 0) {
                AutoPlayerVideoByPb(requestor, "N");
                alert("输入的条码不存在，请重新输入！");
                self.Myfocus();
                return -1;
            }

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

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

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

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


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

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


                //获取行供应商
                dw_mx.SetItem(newRow, "cmzbh", dw_ddmx_top_tmlr.GetItemString(1, "cmzbm"));
                dw_mx.SetItem(newRow, curSaoMiaoLie, 1);
                dw_mx_top.Modify(" countsl.text='" + dw_mx.GetItemNumber(1, "zjsl") + "' ");
                dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "zjsl"));
            }
            dw_ls_flda.Retrieve(tmSpkh, curGysbh, "CG", curJjfs, curQjfs); //FLDA 
            // 处理库存的问题 --------begin-------
            self.setKCSL("", "", "", "", "");
            // 处理库存的问题 --------end---------

            curSftmsl = "Y";

            self.dw_mx_itemChanged(dw_mx.GetRow(), curSaoMiaoLie, dw_mx.GetItemNumber(dw_mx.GetRow(), curSaoMiaoLie))

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

    //#region GetNoYcslForKcsl 扫描不减预出库
    this.GetNoYcslForKcsl = function (curKh, curYsbh, curBx, curCmCol, sl) {
        var curFindDw_Kchc = dw_1.Find("spkh='" + curKh + "' and ysbh='" + curYsbh + "' and bxbh='" + curBx + "'", 1, dw_1.RowCount());
        if (curFindDw_Kchc > 0) {
            var curHcsl = dw_1.GetItemNumber(curFindDw_Kchc, curCmCol);

            return parseInt(sl) + parseInt(curHcsl)

        } else {
            //    alert([sl]);
            return sl;
        }

    }
    //#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--------------

    //#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 (ex) {
            //            alert(ex.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

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

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

            tb_1.SetEnabled("btn_Edit", false);
            tb_1.SetEnabled("btn_Delete", false);
            tb_1.SetEnabled("btn_Audit", false);
            tb_1.SetEnabled("btn_UnAudit", false);
            tb_1.SetEnabled("btn_Tally", false);
            tb_1.SetEnabled("btn_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.JudgeKc = function (row, dwoName, data) {
        if (!(requestor.GetParm("flag") == "CT" || requestor.GetParm("flag") == "CR")) {
            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;

        if (!(requestor.GetParm("flag") == "CT" && curKhxx.split("#")[6] == "0")) {

            //不允许负库存
            if (curSfyxfkc == "N") {
                for (var i = 1; i <= dw_mx.RowCount(); i++) {
                    if (dw_mx.GetItemString(i, "spkh") == spkh && dw_mx.GetItemString(i, "ysbh") == ysbh && dw_mx.GetItemString(i, "bxbh") == bxbh && i != row) {
                        curSl += dw_mx.GetItemNumber(i, dwoName);
                    }
                }
                if (kcslStr == "-" || (curSl + parseInt(data)) > parseInt(kcslStr)) {
                    dw_mx.SetItem(row, dwoName, 0);
                    requestor.MessageBox("提示", "库存数量不足！", ICON.Information);
                    return 0;
                }
            }
        }
        //alert(dw_35_kc.GetItemString(1, "kcsls"));
        if (dw_mx.GetItemNumber(row, "zjsl") == 0) {

            dw_mx.SetItem(row, "cklx", "THRK");

        }
        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 () {
        //alert(tab_1.GetSelectedTab());
        var pzh = "";
        if (tab_1.GetSelectedTab() == "1") {
            if (dw_hz.RowCount() < 1) {
                return;
            }
        }

        if (tab_1.GetSelectedTab() == "2") {
            if (dw_mx_top.RowCount() < 1) {
                return;
            }
            else {
                pzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh")
            }
        }
        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();
        if (curSfQyQDID == "1") {
            var v = A8erp_Biz_Print.Yw_Pf_35_Print_Jqm(self, requestor, dw_hz, dw_mx, dw_mx_top, dw_print, dw_proxy, dw_sort, curDygs, dw_xt_div_tree_no_parm, dw_xt_print_print2_cmzbm, dw_da_qx_mokuai, dw_da_qx_mokuai_print, dw_parameter, dw_init, curDygs, title_value, curDypx, curCmBtRows1, curCmBtCols1, dw_3, curSfQyQDID, curJqm, curSfQYQXZ, curUserGroupId, tab_1);
            if (v == "N") {
                return;
            }
        } else {
            A8erp_Biz_Print.Yw_Pf_35_Print(self, requestor, dw_hz, dw_mx, dw_mx_top, dw_print, dw_proxy, dw_sort, curDygs, dw_xt_div_tree_no_parm, dw_xt_print_print2_cmzbm, dw_da_qx_mokuai, dw_da_qx_mokuai_print, dw_parameter, dw_init, curDygs, title_value, curDypx, curCmBtRows1, curCmBtCols1, dw_3, curSfQyQDID, curJqm, curSfQYQXZ, curUserGroupId, tab_1);
        }
        //#region 固定行打印
        // 固定行打印不预览 
        if (curGdhdy == "1") {
            var curGdhRowsStr = GetGlobalParm("PRINT_GD_ROW", "ROWS_PF", "BZXX"); //是否启用新版本财务
            if (curGdhRowsStr == "") {
                curGdhRowsStr = "10#10#10#10";
            }
            var curRetStr = "";
            var curPageSize = curGdhRowsStr.split("#")[3];
            var curPageCount = 0;
            var curPage = 0;

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

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

        Print_Times(czr, pzh, t);


    }
    //#endregion  

    //#region 固定行打印

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

    }
    //#endregion  

    //#region 执行固定行打印

    this.ExecGdhdy = function (dw_prints, spkhStr) {
        dw_prints.SetFilter("spkh in(" + spkhStr + ")");
        dw_prints.Filter();
        dw_prints.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) {
        dw_mx_top.SetItem(dw_mx_top.GetRow(), dwoName, data.substring(1, data.length - 1));
        self.dw_mx_top_itemChanged(dw_mx_top.GetRow(), dwoName, data.substring(1, data.length - 1));
    }


    //#region this.EvalJs

    this.EvalJs = function (jsScript) {
        //alert(jsScript);
        eval(jsScript);
    }
    //#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_PeiHuo();
                //找到相应的记录
                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

    //#region this.Tab_1_Clicked
    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_2", true);
            tb_1.SetEnabled("btn_ChaXun", true);
            tb_1.SetEnabled("btn_Filter", true);
            tb_1.SetEnabled("btn_Export", true);
            tb_1.SetEnabled("btn_cwhj", true);
            tb_1.SetEnabled("btn_FenJian", true);

            var curPhbz = dw_hz.GetItemString(dw_hz.GetRow(), "phbz");
            var curFjbz = dw_hz.GetItemString(dw_hz.GetRow(), "fjbz");
            var curZdbz = dw_hz.GetItemString(dw_hz.GetRow(), "zdbz");
            if (curPhbz == "0") {
                tb_1.SetEnabled("btn_Add", true);
                tb_1.SetEnabled("btn_Edit", true);
                tb_1.SetEnabled("btn_Delete", true);
                tb_1.SetEnabled("btn_Trans", false);
            }
            else if (curPhbz == "1") {
                tb_1.SetEnabled("btn_Add", true);
                tb_1.SetEnabled("btn_Edit", false);
                tb_1.SetEnabled("btn_Delete", false);
                tb_1.SetEnabled("btn_Trans", false);
            }
            else if (curPhbz == "2") {
                tb_1.SetEnabled("btn_Add", true);
                tb_1.SetEnabled("btn_Edit", false);
                tb_1.SetEnabled("btn_Delete", false);
                tb_1.SetEnabled("btn_Trans", false);

            }



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


            //self.SelectionChanged_PeiHuo_tab(self.GetPzh());


        } else if (ind == "2") {
            tb_1.SetEnabled("ddlb_2", false);
            tb_1.SetEnabled("btn_ChaXun", false);
            tb_1.SetEnabled("btn_Filter", false);
            tb_1.SetEnabled("btn_cwhj", false);
            tb_1.SetEnabled("btn_FenJian", false);
            
            tb_1.SetEnabled("btn_Export", true);
            var curRowCount = dw_hz.RowCount();
            if (curRowCount < 1) {
                dw_mx_top.ScrollToRow(dw_mx_top.InsertRow(0));
                return;
            }
            var curPzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");

            dw_mx_top.Retrieve(curPzh);
            dw_mx.Retrieve(curPzh);

            //打开明细的时候 没有记账的单据 重新获取 期初数据&结余数据
            if (dw_hz.RowCount() > 0) {
                if (dw_hz.GetItemString(dw_hz.GetRow(), "phbz") != "1") {
                    self.GetKhQjfs();
                }
            }
            self.setKCSL("", "", "", 0, "");
        }
        curPzhStr = "";
        curFjdh = "";
        curGysBMStr = "";
    }
    //#endregion

    //#region this.GetPzh
    this.GetPzh = function () {
        var pzh = "";
        if (tab_1.GetSelectedTab() == "1") {
            pzh = dw_hz.GetItemString(dw_hz.GetRow(), "pzh");
        } else {
            pzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
        }
        return pzh;
    }
    //#endregion

    //#region this.dw_mx_Clicked
    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);
            // 处理点亮的问题 --------end---------
            self.setKCSL("", "", "", 0, "");
        }
    }
    //#endregion

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

    }
    //#endregion

    //#region ImportTxt
    this.ImportTxt = function () {
        if (dw_mx_top.GetItemString(1, "lydh").substring(0, 2) == "RD") {
            requestor.MessageBox("提示", "日常配货生成单据，不允许导入数据！", ICON.Information);
            return;
        }

        dw_mx_top.AcceptText();
        var curskfs = "skfs";
        //客户
        var curkh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh");
        if (curkh.length < 1) {
            alert("客户编号不能为空");
            return;
        }
        //部门
        var curbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "gysbh");
        if (curbh.length < 1) {
            alert("部门编号不能为空");
            return;
        }



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

        var currq = UtcDateFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "kdrq"));
        if (currq.length < 1) {
            alert("日期不能为空");
            return;
        }
        var curPpfa = sle_pptmfa_Value.GetText();
        cur_W_TXTDR.SetDataWindow(W_CaiGou_PeiHuoDan, self)
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.import.W_TXTDR&FunctionID=" + curFunctionId + "&bmbh=" + curkh + "&gysbh=" + curbh + "&skfs=" + curskfs + "&rkfs=" + currkfs + "&kdrq=" + currq + "&pptmfa=" + curPpfa), cur_W_TXTDR, null);
        return;
        var curStrNotImportStr = "";
        var curStrNotImportNumber = 0;
        if (!G_bEditFlag) {
            alert("请先单击修改！");
            return;
        }
        var curBmbh = dw_mx_top.GetItemString("1", "gysbh");
        var curGysbh = dw_mx_top.GetItemString("1", "bmbh");
        if (curBmbh.length < 1) {
            alert("请输入部门");
            return;
        }
        if (curGysbh.length < 1) {
            alert("请输入客户");
            return;
        }
        var fileName = requestor.GetFileOpenName("提示", "", ".txt", "Txt文件(*.txt),*.txt;", "");
        if (!requestor.FileExists(fileName)) {
            requestor.MessageBox("提示", "文件[ " + fileName + " ]不存在,请检查!", ICON.StopSign);
            return;
        }
        var curImportStr = ReadTxtFile(fileName);
        if (curImportStr.length < 1) {
            requestor.MessageBox("提示", "文件内容错误,请检查!", ICON.StopSign);
            return;
        }
        var curJqlb = dw_tmjqfs.GetItemString(1, "csbh");    // 截取方式
        var curStartString = dw_tmjqfs.GetItemString(1, "bzxx"); // 截取范围
        // 处理品牌条码方案 begin
        var curPpfa = sle_pptmfa_Value.GetText();
        if (curPpfa.length > 0) {
            curJqlb = curPpfa.split("#")[0];
            curStartString = curPpfa.split("#")[1];
        }
        // 处理品牌条码方案 end  

        var curTmh = "";
        var curImportStrArr = curImportStr.split("!!");
        requestor.ShowLoading("导入中......请勿关闭程序。");

        //#region for
        for (var i = 0; i < curImportStrArr.length; i++) {
            //#region 获取条码号
            var txt = curImportStrArr[i].split(curTxtImportSplitString)[0];
            //右丢弃
            if (curJqlb == "3") {
                curTmh = txt.substring(0, txt.length - curStartString);
            } else if (curJqlb == "1") {
                //左截取
                curTmh = txt.substring(0, curStartString);
            } else if (curJqlb == "2") {
                //中截取
                var curStart = curStartString.split("-")[0];
                var curEnd = curStartString.split("-")[1];
                curTmh = txt.substring(curStart - 1, curEnd);
            }
            var curNumber = curImportStrArr[i].split(curTxtImportSplitString)[1];
            //以上条码号curTmh,数量curNumber已OK
            ls_tmh = curTmh;
            //#endregion

            dw_ddmx_top_tmlr.Retrieve(ls_tmh, curGysbh, "CG", curJjfs + "#" + dw_mx_top.GetItemString(1, "gysbh"), curQjfs);
            if (dw_ddmx_top_tmlr.RowCount() == 0) {
                curStrNotImportStr += "\r\n" + ls_tmh + curTxtImportSplitString + "" + curNumber;
                curStrNotImportNumber += parseInt(curNumber);
                continue;
            }

            // 取尺码点亮信息
            var curChangecolor = dw_ddmx_top_tmlr.GetItemString(1, "changecolor");
            var mdf = new Array();
            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];
                myCmStrTmlr = curChangecolor.split(",,")[0]; //尺码组
                beginNo = parseInt(beginNo) - 1;
                endNo = parseInt(endNo) - 1;
                var curBeg = parseInt(beginNo) + 1;          // 范围是从0开始的，尺码+1.
                var curEnd = parseInt(endNo) + 1;
                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;
                myColTmlr = curColNo;
                myPrintCol = curColNo;
            }
            // 检查是否已经存在款号-------begin----

            var tmSpkh = dw_ddmx_top_tmlr.GetItemString(1, "spkh");
            var tmYslsh = dw_ddmx_top_tmlr.GetItemString(1, "yslsh");
            var tmYsbh = dw_ddmx_top_tmlr.GetItemString(1, "ysbh");

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

            //#region 该款该色已存在，只需要改变数量
            if (mxFindRow > 0) {
                dw_mx.ScrollToRow(mxFindRow);
                var curCmSl = dw_mx.GetItemNumber(mxFindRow, curSaoMiaoLie);
                dw_mx.SetItem(mxFindRow, curSaoMiaoLie, parseInt(curCmSl) + parseInt(curNumber));
                dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "sumzjsl"));
            } else {
                if (dw_mx.RowCount() > 0) {
                    // 该款该色不存在，新增行
                    if (dw_mx.GetItemNumber(dw_mx.GetRow(), "zjsl") == 0) {
                        dw_mx.DeleteRow(dw_mx.GetRow());
                    }
                }
                if (dw_mx_top.GetItemString(1, "lydh").substring(0, 2) != "RD") {
                    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, "lsj", dw_ddmx_top_tmlr.GetItemNumber(1, "pfjg1"));
                    self.setJGJqd(newRow, dw_ddmx_top_tmlr.GetItemNumber(1, "pfjg1"));
                    dw_mx.SetItem(newRow, "dpj", dw_ddmx_top_tmlr.GetItemNumber(1, "dpjg"));

                    if (dw_ddmx_top_tmlr.GetItemNumber(1, "dpjg") == 0) {
                        dw_mx.SetItem(newRow, "zkl", 1);
                    } else {
                        dw_mx.SetItem(newRow, "zkl", dw_ddmx_top_tmlr.GetItemNumber(1, "pfjg1") / dw_ddmx_top_tmlr.GetItemNumber(1, "dpjg"));
                    }
                    dw_mx.SetItem(newRow, "cmzbh", dw_ddmx_top_tmlr.GetItemString(1, "cmzbm"));
                    dw_mx.SetItem(newRow, curSaoMiaoLie, parseInt(curNumber));
                }
                dw_mx_top.SetItem(1, "zjsl", dw_mx.GetItemNumber(1, "sumzjsl"));
                dw_mx_top.SetItem(1, "djlx", "3");
            }
            //#endregion
            // 检查是否已经存在款号--------end----- 
        }
        //#endregion
        requestor.CloseLoading();
        if (curStrNotImportStr.length > 0) {
            if (requestor.MessageBox("提示", "导入失败(" + curStrNotImportNumber + ")件：\r\n" + curStrNotImportStr.toString() + "\r\n\r\n是否复制到剪切板？", ICON.Question, BUTTON.YesNo) == 2) {
                return;
            } else {
                requestor.ClipBoard("导入失败(" + curStrNotImportNumber + ")件：\r\n" + curStrNotImportStr.toString());
                requestor.MessageBox("提示", "导入失败数据已复制到剪切板。", ICON.Information);
            }
        } else {
            requestor.MessageBox("提示", "全部导入成功", ICON.Information);
        }
    }

    //#endregion

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

    //#region 获取客户取价方式
    this.GetKhQjfs = function () {
        if (dw_mx_top.GetRow() < 1) {
            return;
        }

        var curKhbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh");
        if (curKhbh.length < 1) {
            return;
        }
        webReq.Invoke("GetKHXX", "CusId=" + curKhbh);
        if (webReq.StatusCode() == 200) {
            curKhxx = webReq.ResponseText();
            curJjfs = curKhxx.split("#")[0];

        }
    }
    //#endregion


    //#region 打印预览
    this.SetPrint = function () {
        if (curSfQyQDID == "1") {
            A8erp_Biz_Print.Yw_Pf_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_Pf_35_Print(self, requestor, dw_hz, dw_mx, dw_mx_top, dw_print, dw_proxy, dw_sort, curDygs, dw_xt_div_tree_no_parm, dw_xt_print_print2_cmzbm, dw_da_qx_mokuai, dw_da_qx_mokuai_print, dw_parameter, dw_init, curDygs, title_value, curDypx, curCmBtRows1, curCmBtCols1, dw_3, curSfQyQDID, curJqm, curSfQYQXZ, curUserGroupId, tab_1);
        }
        return;
        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.ClipBoard(curBzxx);
        requestor.MessageBox("提示", "备注信息【" + curBzxx + "】已复制到剪贴板", ICON.None);
    }
    //#endregion


    //#region 双击标题排序
    this.dw_mx_doubleClicked = function (x, y, row, dwcName) {
        if (dwcName.indexOf("_t") > -1) {
            var curColName = dwcName.split("_")[0];
            if (curColName == lastSortName) {
                dw_mx.SetSort(curColName + " A");
                lastSortName = "";
                dw_mx.Sort();
            } else {
                dw_mx.SetSort(curColName + " D");
                lastSortName = dwcName.split("_")[0];
                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.Export = function () {
        if (tab_1.GetSelectedTab() == "1") {
            dw_hz.Export()
        }
        else {
            dw_mx.Export();
        }
    }
    this.liansao = function () {
        if (cueSmzt == "0") {
            cueSmzt = "1";
            ContextMenuStrip2.SetText("连扫ToolStripMenuItem", "单扫（×），连扫（√）");
        } else {
            cueSmzt = "0";
            ContextMenuStrip2.SetText("连扫ToolStripMenuItem", "单扫（√），连扫（×）");
        }

    }
    //#region  this.ScanImport条码批量扫描
    this.ScanImport = function () {
        dw_mx_top.AcceptText();
        var curskfs = "skfs";
        //客户
        var curkh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "bmbh");
        if (curkh.length < 1) {
            alert("客户编号不能为空");
            return;
        }
        //部门
        var curbh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "gysbh");
        if (curbh.length < 1) {
            alert("部门编号不能为空");
            return;
        }

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

        var currq = UtcDateFormatToString(dw_mx_top.GetItemDate(dw_mx_top.GetRow(), "kdrq"));
        if (currq.length < 1) {
            alert("日期不能为空");
            return;
        }
        var curPzh = dw_mx_top.GetItemString(dw_mx_top.GetRow(), "pzh");
        var curYwFlag = curPzh.substring(0, 2);
        curW_ScanImport.SetDataWindow(self, curkh, curbh, curskfs, currkfs, currq, curYwFlag, "XX");
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.ScanImport.W_ScanImport"), curW_ScanImport, null);

    }
    //#endregion

    this.RefreshSdjy = function () {
        curJqdbm = requestor.GetParm("curJqdbm");
        var row = dw_mx_top.GetRow();
        var bmbh = dw_mx_top.GetItemString(row, "bmbh");
        //#region 老版本财务
        if (curNewCyShiFouQy == "0") {
            if (curJqdbm == "1") { //精确到部门
                if (dw_mx_top.GetItemString(row, "gysbh") != "") {
                    dw_bmkhye.Retrieve(dw_mx_top.GetItemString(row, "gysbh"), bmbh, "1");
                    var nrow = dw_bmkhye.RowCount();
                    if (nrow > 0) {
                        dw_mx_top.SetItem(row, "sdjy", dw_bmkhye.GetItemNumber(1, "ye"));
                    } else {
                        dw_mx_top.SetItem(row, "sdjy", 0);
                    }
                }
            } else {
                dw_bmkhye.Retrieve("00", bmbh, "0");
                var nrow = dw_bmkhye.RowCount();
                if (nrow > 0) {
                    dw_mx_top.SetItem(row, "khsdjy", dw_bmkhye.GetItemNumber(1, "ye"));
                } else {
                    dw_mx_top.SetItem(row, "khsdjy", 0);
                }
            }
        }
        //#endregion

        //#region 新版本财务
        else {
            if (curJqdbm == "1") { //精确到部门
                if (dw_mx_top.GetItemString(dw_mx_top.GetRow(), "gysbh") != "") {
                    dw_bmkhye_new.Retrieve(dw_mx_top.GetItemString(dw_mx_top.GetRow(), "gysbh"), bmbh);
                    var nrow = dw_bmkhye_new.RowCount();
                    if (nrow > 0) {
                        dw_mx_top.SetItem(dw_mx_top.GetRow(), "sdjy", dw_bmkhye_new.GetItemNumber(1, "bmkhye"));
                    } else {
                        dw_mx_top.SetItem(dw_mx_top.GetRow(), "sdjy", 0);
                    }
                }
            } else {
                dw_bmkhye_new.Retrieve(dw_mx_top.GetItemString(dw_mx_top.GetRow(), "gysbh"), bmbh);
                var nrow = dw_bmkhye_new.RowCount();
                if (nrow > 0) {
                    dw_mx_top.SetItem(dw_mx_top.GetRow(), "khsdjy", dw_bmkhye_new.GetItemNumber(1, "khye"));
                } else {
                    dw_mx_top.SetItem(dw_mx_top.GetRow(), "khsdjy", 0);
                }
            }
        }
        //#endregion
    }

    this.RetrieveEnd = function () {
        var flag = requestor.GetParm("flag");
        if (flag == "PD") {
            self.RefreshSdjy();
        }
    }

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

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

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

                //执行保存的WebService  


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

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


                row = dw_mx.InsertRow(0);
                dw_mx.ScrollToRow(row);
                dw_mx.SetItem(row, "spkh", curDw.GetItemString(i, "spkh"));
                dw_mx.SetItem(row, "ksmc", curDw.GetItemString(i, "ksmc"));
                dw_mx.SetItem(row, "ysbh", curDw.GetItemString(i, "ysbh"));
                dw_mx.SetItem(row, "ysmc", curDw.GetItemString(i, "ysmc"));
                dw_mx.SetItem(row, "bxbh", curDw.GetItemString(i, "bxbh"));
                dw_mx.SetItem(row, "bxmc", curDw.GetItemString(i, "bxmc"));
                dw_mx.SetItem(row, "jldw", curDw.GetItemString(i, "jldw"));
                dw_mx.SetItem(row, "yslsh", curDw.GetItemString(i, "yslsh"));
                for (var k = 1; k < curCmBtCols1; k++) {
                    dw_mx.SetItem(row, "cm" + k, curDw.GetItemNumber(i, "cm" + k));

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

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

                dw_mx.SetItem(row, "cmzbh", dw_ls_flda.GetItemString(1, "cmzbm"));
                if (flag == "CR" || flag == "CT") {
                    dw_mx.SetItem(row, "hjjze", dw_ls_flda.GetItemNumber(1, "jhjg") * curDw.GetItemNumber(i, "spsl"));
                }
            }
            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);
            }
            // curDw.Reset()
            requestor.CloseLoading();
        }
    }
    //#endregion

    //        全部
    //        未配货
    //        配货中
    //        已发货
    //        未分拣
    //        分拣中
    //        已分拣
    //        未转单
    //        已转单

    this.SelectionChanged_PeiHuo = function (val) {

        var djzt = Trim(ddlb_2.GetText());
        var SqlWhere = "";
        if (djzt == "未分拣") {   //0、null代表未配货  1代表配货中、2代表 已发货
            SqlWhere += "  isnull(fjbz,'0')='0'";
        } else if (djzt == "分拣中") {
            SqlWhere += "  isnull(fjbz,'0')='1'";
        } else if (djzt == "已分拣") {
            SqlWhere += "  isnull(fjbz,'0')='2'";
        } else if (djzt == "核价中") {
            SqlWhere += "  isnull(fjbz,'0')='3'";
        } else if (djzt == "已入库") {
            SqlWhere += "  isnull(fjbz,'0')='4'";
        } else if (djzt == "全部") {
            SqlWhere += "  1 = 1";
        }
        dw_hz.RetrieveEx(SqlWhere);
        var curPageCount = dw_hz.GetPageCount();
        try {
            if (arguments.length == 1) {
                if (parseInt(val) > curPageCount) {

                    dw_hz.SetPageIndex(curPageCount);

                } else {
                    dw_hz.SetPageIndex(val);

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





    function GetCmzMappingCm(cmzbm, cm) {
        var curZrow = JsonFilter(cmzbm);
        if (curZrow != 9999) {
            return eval("dpjson.tableData[" + curZrow + "]." + cm);
        } else {
            return "不存在您查找的尺码组";
        }
    }

    function JsonFilter(curCmzbm) {
        for (var i = 0; i < dpjson.tableData.length; i++) {
            if (dpjson.tableData[i].cmzbm == curCmzbm) {
                return i;
            }
        }
        return 9999;
    }

    this.containsKey = function (_key) {
        var bln = false;
        try {
            for (i = 0; i < curMapUpdate.size; i++) {
                if (curMapUpdate[i].key == _key) {
                    bln = true;
                }
            }
        } catch (e) {
            bln = false;
        }
        return bln;
    }


    this.DwGet = function (dw, key) {
        var r = dw.Find("id='" + key + "'", 1, dw.RowCount());

        //        alert([1111,r])
        if (r < 1) {
            return null;
        } else {
            if (dw.GetDataObject() == "dw_pf_phd_id_name2") {
                var v = dw.GetItemString(r, "name");
            } else {
                var v = dw.GetItemNumber(r, "name");
            }

            return v;
        }
    }

    this.DwSet = function (dw, key, value) {
        var r = dw.Find("id='" + key + "'", 1, dw.RowCount());
        if (r < 1) {
            r = dw.InsertRow(0);
        }
        dw.SetItem(r, "id", key);
        dw.SetItem(r, "name", value);
    }

    this.DwHas = function (dw, key) {
        var r = dw.Find("id='" + key + "'", 1, dw.RowCount());
        if (r > 0) {
            return true;
        }
        return false;
    }
    
    this.DwDelete = function (dw, key) {
        var r = dw.Find("id='" + key + "'", 1, dw.RowCount());
        if (r > 0) {
            dw.DeleteRow(r);
        }
        return false;
    }


    this.FenJian = function () {


        var arr = curGysBMStr.split(",");
        var curFirstBm = arr[0] + ",";
        var curBfbm = curGysBMStr;

        var curReGysBm = "";
        for (var i = 0; i < arr.length; i++) {
            curBfbm = curBfbm.replace(curFirstBm, "");
        }
        curReGysBm = curBfbm;
        var curReFjdh = curFjdh;
        curReFjdh = curReFjdh.replace(/,/g, "");
        if (curReFjdh.length > 0) {
            if (confirm("分拣单号[" + curFjdh.split(",")[0] + "]的单据已分拣,是否继续打开!")) {
                curW_PH_FenJian_List.SetDataWindow(self, curFjdh.split(",")[0]);
                requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.CaiGou.Base.W_PH_FenJian_List"), curW_PH_FenJian_List, null);
                return;
            }
            else { return }

        }
        if (curPzhStr.length < 1) {
            requestor.MessageBox("提示", "请选择单据后分拣!", ICON.Information);
            return;
        }
        if (curReGysBm.length > 0) {
            requestor.MessageBox("提示", "请选择相同供应商部门通知单进行分拣!", ICON.Information);
            return;
        }

        webReq.Invoke("CG_FenJian_Initialize", "curPzhStr=" + curPzhStr + "&Flag=1"); // Flag=1 分拣初始化);
        if (webReq.StatusCode() == 200) {
            var rPzh = webReq.ResponseText();
            curW_PH_FenJian_List.SetDataWindow(self, rPzh);
            requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.CaiGou.Base.W_PH_FenJian_List"), curW_PH_FenJian_List, null);

        } else {
            requestor.MessageBox("提示", "数据保存失败!\r\n" + webReq.ResponseText(), ICON.StopSign);
        }


    }


    this.CaiWuHeJia = function () {

        curW_PH_HeJia_List.SetDataWindow(self);
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.CaiGou.Base.W_PH_HeJia_List"), curW_PH_HeJia_List, null);


    }
    var arr = new Array()
    var arrRep = new Array()
    this.Clicked_Hz = function (x, t, row, dowName) {
        var xz = "";
        var pzh = "";
        var fjbz = "";
        var fjdh = "";
        var gysbh = "";
        var bmbh = "";
        if (dowName == "xz") {
            xz = dw_hz.GetItemString(row, "xz");
            pzh = dw_hz.GetItemString(row, "pzh");
            fjbz = dw_hz.GetItemString(row, "fjbz");
            fjdh = dw_hz.GetItemString(row, "fjdh");
            gysbh = dw_hz.GetItemString(row, "gysbh");
            bmbh = dw_hz.GetItemString(row, "bmbh");

            if (xz == "1") {
                dw_hz.SetItem(row, "xz", "");
                curPzhStr = curPzhStr.replace(pzh + ",", "");
                curFjdh = curFjdh.replace(fjdh + ",", "");
                curGysBMStr = curGysBMStr.replace(gysbh + bmbh + ",", "");
                curFjbz = curFjbz.replace(fjdh + ",", "");
                 

            } else {
                dw_hz.SetItem(row, "xz", "1");
                curPzhStr += pzh + ",";
                curFjdh += fjdh + ",";
                curGysBMStr += gysbh + bmbh + ",";
                curFjbz += curFjbz + ",";
            }

        }
    }

    this.checkVal = function(key) {
        if (arr.indexOf(key) > -1) {
            // 存在
            arr.push(key);
        } else {
            //不存在
            if (arr.length > 0) {
                arr.push(key);
                arr.push("N");
            } else {
                arr.push(key);
            }
        }
    }
    this.RegEval = function (val) {
        window.eval(val);
    }



    this.UFenJian = function () {
        var arr = curFjdh.split(",");
        var curFirstFjdh = arr[0] + ",";
        var curBfFjdh = curFjdh;
        var curReGysBm = "";
        var curFjbz = "";
        for (var i = 0; i < arr.length; i++) {
            curBfFjdh = curBfFjdh.replace(curFirstFjdh, "");
        }
        //        alert(curBfFjdh)
        if (curBfFjdh.length <= 0) {
            if (arr[0].length < 1) {
                requestor.MessageBox("提示", "请选择分拣中或者已分拣的单据!", ICON.Information);
                return
            }
            var curRow = dw_hz.Find("fjdh='" + arr[0]+"'", 1, dw_hz.RowCount())
            if (curRow > 0) {
                curFjbz = dw_hz.GetItemString(curRow, "fjbz");
            }
//            alert(curFjbz)
            if (curFjbz < "3" && curFjbz > "0") {
                if (confirm("取消分拣单号[" + arr[0] + "]的分拣单据并清除原有分拣记录,是否继续？")) {

                    self.Update_Mark("9", arr[0]);
                    self.Tab_1_Clicked(1);
                }
            } else {
                requestor.MessageBox("提示", "请选择分拣中或者已分拣的单据!", ICON.Information);
            }
        } else {
            requestor.MessageBox("提示", "请选择同一分拣单号进行取消分拣!", ICON.Information);

        }
    }
}