///<reference path="/Scripts/ExtPB_Net.js" />
///<reference path="/Scripts/MyExtPB.js" />
///<reference path="/Scripts/ExtPB_Dll_Pb_Http.js" />

function W_MoRenCaiGouBuMenSheZhi() {

    var self = this;
    var requestor = new PBWindow();
    var dw_mrbm = new DataWindow(requestor);
    var tb_1 = new ToolStrip(requestor);

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

        if (requestor == null) requestor = new PBWindow();
        requestor.Attach(win);
        if (dw_mrbm == null) dw_mrbm = new DataWindow(requestor);
        dw_mrbm.Attach(win.Control("dw_mrbm"));
        if (tb_1 == null) tb_1 = new ToolStrip(requestor);
        tb_1.Attach(win.Control("tb_1"));

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

        if (typeof (self.dw_mrbm_doubleClicked) == "function")
            win.AttachEvent("dw_mrbm", "DoubleClicked", self.dw_mrbm_doubleClicked);

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

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

    }

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

        dw_mrbm.Detach(); dw_mrbm = null;
        tb_1.Detach(); tb_1 = null;
        requestor.Detach(); requestor = null;

        setTimeout(CollectGarbage, 100);
    }

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


    //#region this.Exit  
    this.CloseQuery = function () {

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

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


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

    this.Save = function () {

        if (dw_mrbm.AcceptText() != 1)
            return false;

        //数据没有修改
        if ((dw_mrbm.ModifiedCount()) <= 0)
            return false;

        var v1 = dw_mrbm.GetItemString(dw_mrbm.GetRow(), "ywbh");
        var v2 = dw_mrbm.GetItemString(dw_mrbm.GetRow(), "bmbh");
       
        var msg = new Array();
        if (v1.length < 1) {
            msg.push("请检查目录设置中对于的代码？");
             }

        //执行保存的WebService
        var success = false;
        var curDwObject = dw_mrbm.GetDataObject();
        var curDwChange = dw_mrbm.GetChanges();


        webReq.Invoke("MoRenBuMen_Save", "dataObject=" + curDwObject + "&dwChanges=" + curDwChange);
        if (webReq.StatusCode() == 200) {
            dw_mrbm.ResetUpdate();
            success = true;
            alert('数据保存成功');
        }
        else {
            requestor.MessageBox("提示", "数据保存失败!详细信息为：\r\n" + webReq.ResponseText(), ICON.StopSign);
        }
        dw_mrbm.SetFocus();
        return success;

    }

    var curW_OPEN_BMDA = new OpenWindowQueryBase();

    this.dw_mrbm_doubleClicked = function (x, y, row, dwoName) {
        if (dwoName == "bmbh") {
            curW_OPEN_BMDA.SetDataWindow(dw_mrbm, "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&treeRootLabel=部门分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&curQxlx=" + requestor.GetParm("curQxlx")), curW_OPEN_BMDA, null);
        }

    }
}