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

    var self = this;
    var requestor = new PBWindow();
    var dw_1 = 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_1 == null) dw_1 = new DataWindow(requestor);
        dw_1.Attach(win.Control("dw_1"));
        if (tb_1 == null) tb_1 = new ToolStrip(requestor);
        tb_1.Attach(win.Control("tb_1"));

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

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

        if (typeof (self.Exit) == "function")
            win.AttachEvent("btn_1", "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_1.Detach(); dw_1 = null;
        tb_1.Detach(); tb_1 = null;
        requestor.Detach(); requestor = null;

        setTimeout(CollectGarbage, 100);
    }

    //以上代码由设计器自动生成,请不要手工修改
    //ExtPB.Net JavaScript End  设计器查找标志,请不要删除或修改
    var curYhbh = "";
    var curCdbh = "";
    var curBbmc = "";
    var curParent = "";
    var curEvalStr = "";
    this.SetDataWindow = function (parent, yhbh, cdbh, bbmc, evalStr) {
        curYhbh = yhbh;
        curCdbh = cdbh;
        curBbmc = bbmc;
        curParent = parent;
        curEvalStr = evalStr;
    }

    this.PostOpen = function () {
        dw_1.RetrieveEx("cdbh='" + curCdbh + "' and yhbh='" + curYhbh + "' and bbmc='" + curBbmc + "'");
        dw_1.SetFilter("mrgxtj='0'");
        dw_1.Filter();
    }

    this.Save = function () {
        var dwChanges = dw_1.GetChanges();
        if (dwChanges == "") {
            requestor.MessageBox("提示", "没有格式变更，不需要保存", ICON.Information);
            return;
        }

        $.ajax({
            type: "POST",
            url: "/Service/Ajax_XT.ashx",
            async: false,
            data: { curFlag: "report_format_open_save", dwObjects: dw_1.GetDataObject(), dwChanges: dwChanges, curYhbh: curYhbh, curCdbh: curCdbh, curBbmc: curBbmc },
            success: function (msg) {
                if (msg == "OK") {
                    requestor.MessageBox("提示", "保存成功", ICON.Information);
                    requestor.Close(); 
                    window.eval(curEvalStr);
                    return;
                }
                else {
                    requestor.MessageBox("提示", "出错了", ICON.StopSign);
                }
            },
            error: function (req) {
                requestor.MessageBox("提示", req.responseText, ICON.StopSign);
            }
        });
    }
    this.Exit = function () {
        requestor.Close();
    }
}