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

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

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

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

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

    }

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

        tb_1.Detach(); tb_1 = null;
        dw_2.Detach(); dw_2 = null;
        dw_1.Detach(); dw_1 = null;
        requestor.Detach(); requestor = null;

        setTimeout(CollectGarbage, 100);
    }

    //以上代码由设计器自动生成,请不要手工修改
    //ExtPB.Net JavaScript End  设计器查找标志,请不要删除或修改
    var webReq = new WebRequestor();
    webReq.SetWebServiceUrl("/Service/ServiceCaiWu.ashx");
    var curKhbh = "";
    var curLydh = "";
    var xhskhpzh = "";
    var curSelf = "";
    var curDwMx
    var curRedoFlag = "N";
    var curCloseFlag = "N";
    this.PostOpen = function () {
        curRedoFlag = "N";
        curCloseFlag = "N";
        if (requestor.GetParm("flag") == "N") {
            tb_1.SetEnabled("btn_Redo", false);
        }
        tb_1.SetEnabled("btn_Save", false);
        curKhbh = requestor.GetParm("curKhbh");
        curLydh = requestor.GetParm("lydh");
        xhskhpzh = requestor.GetParm("xhskhpzh");
        dw_2.SetVisible(false);

    }
    this.SetDataWindow = function (self, dw_mx) {
        curSelf = self;
        curDwMx = dw_mx;
    }
    this.Redo = function () {
        if (dw_1.RowCount() < 1) {
            return;
        }
        //        dw_2.Retrieve(curLydh, curKhbh);
        //        dw_1.SetVisible(false);
        //        dw_2.SetVisible(true);
        //        tb_1.SetEnabled("btn_Save", true);
        webReq.Invoke("YW_CW_XHSKD_SPKH_REDO", "xhskhpzh=" + xhskhpzh + "&curLydh=" + curLydh + "&curKhbh=" + curKhbh);

        if (webReq.StatusCode() == 200) {
            dw_1.Retrieve(curLydh);
            requestor.MessageBox("提示", "取价成功！", ICON.Information);
                tb_1.SetEnabled("btn_Save", true);
            curRedoFlag = "Y";
        } else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
        }
    }
    this.Save = function () {
        if (dw_1.RowCount() < 1) {
            return;
        }
        webReq.Invoke("YW_CW_XHSKD_SPKH_REDO_SAVE", "xhskhpzh=" + xhskhpzh + "&bcsyhk=" + curDwMx.GetItemNumber(curDwMx.GetRow(), "bcyshk") + "&jsj=" + dw_1.GetItemNumber(1, "compute_4"));
        if (webReq.StatusCode() == 200) {
            requestor.MessageBox("提示", "保存成功！", ICON.Information);
            curDwMx.Refresh();
            curSelf.SetSdjy();
            curSelf.SetLjjy();
            requestor.Close();
            curCloseFlag = "Y";
        } else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
        }
    }
    this.Exit = function () {
        requestor.Close();
    }
    this.CloseQuery = function () {
        if (dw_1.RowCount() < 1) {
            return;
        }

        if (curRedoFlag == "Y" && curCloseFlag == "N") {
            self.Save();
        }
    }
 }