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

    var self = this;
    this.Instance = null;
    var requestor = new PBWindow();
    var dw_list = new DataWindow(requestor);
    var tb_1 = new ToolStrip(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 (dw_list == null) dw_list = new DataWindow(requestor);
        dw_list.Attach(win.Control("dw_list"));
        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.DoubleClicked) == "function")
            win.AttachEvent("dw_list", "DoubleClicked", self.DoubleClicked);

        if (typeof (self.List_DropDown) == "function")
            win.AttachEvent("dw_list", "RowFocusChanged", self.List_DropDown);

        if (typeof (self.Add) == "function")
            win.AttachEvent("btn_1", "Clicked", self.Add);

        if (typeof (self.Edit) == "function")
            win.AttachEvent("btn_2", "Clicked", self.Edit);

        if (typeof (self.Delete) == "function")
            win.AttachEvent("btn_3", "Clicked", self.Delete);

        if (typeof (self.Audit) == "function")
            win.AttachEvent("btn_4", "Clicked", self.Audit);

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

        if (typeof (self.OpenOrClose) == "function")
            win.AttachEvent("btn_6", "Clicked", self.OpenOrClose);

        if (typeof (self.Exit) == "function")
            win.AttachEvent("btn_9", "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();

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

        setTimeout(CollectGarbage, 100);
    }

    //以上代码由设计器自动生成,请不要手工修改
    //ExtPB.Net JavaScript End  设计器查找标志,请不要删除或修改
    var webReq = new WebRequestor();
    webReq.SetWebServiceUrl("/Service/ServiceCuXiaoFangAn.ashx");
    var curW_Mdxjdyz_Edit = new W_Mdxjdyz();
    this.PostOpen = function () {
        dw_list.Retrieve();
    }
    this.DoubleClicked = function (x, y, row, dwcName) {
        self.Edit();
    }
    this.Add = function () {

        curW_Mdxjdyz_Edit.SetDataWindow(dw_list, "") // 这个用来给子窗口Set当前数据窗口
        requestor.Open("/Service/LoadWindow.ashx?WinName=A8ERP.CuXiao.Mdxjdyz.W_Mdxjdyz&opFlag=ADD", curW_Mdxjdyz_Edit, null);
    }
    this.Edit = function () {
        if (dw_list.RowCount() < 1) {
            return;
        }
        var curPzh = dw_list.GetItemString(dw_list.GetRow(), "pzh");
        if (curPzh.length < 1) {
            requestor.MessageBox("提示", "请先选择方案后再修改。", ICON.StopSign);
            return
        }
        var CURFHJB = dw_list.GetItemString(dw_list.GetRow(), "FHJB");
        curW_Mdxjdyz_Edit.SetDataWindow(dw_list, curPzh) // 这个用来给子窗口Set当前数据窗口
        requestor.Open("/Service/LoadWindow.ashx?WinName=A8ERP.CuXiao.Mdxjdyz.W_Mdxjdyz&opFlag=EDIT" + "&CURFHJB=" + CURFHJB, curW_Mdxjdyz_Edit, null);
    }
    //#region 删除
    this.Delete = function () {
        if (dw_list.RowCount() < 1) {
            return;
        }
        var curPzh = dw_list.GetItemString(dw_list.GetRow(), "pzh");
        var curStatus = "";
        if (curPzh.length < 1) {
            requestor.MessageBox("提示", "请选择一笔数据", ICON.Exclamation);
            return;
        }

        if (!confirm("您确定要删除吗？")) {
            return;
        }
        webReq.Invoke("W_CuXiaoSheZhi_Delete", "curPzh=" + curPzh + "&curCXFS=mdxjdyz" );
        if (webReq.StatusCode() == 200) {
            requestor.MessageBox("提示", "删除成功!", ICON.Information);
            var rowId = dw_list.GetRow();
            dw_list.RowsDiscard(rowId, rowId, DWBUFFER.Primary);
        }
        else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
            return;
        }
    }

    //#endregion

    //#region 启用
    this.OpenOrClose = function () {
        if (dw_list.RowCount() < 1) {
            return;
        }
        var curPzh = dw_list.GetItemString(dw_list.GetRow(), "pzh");
        var curStatus = "";
        if (curPzh.length < 1) {
            requestor.MessageBox("提示", "请选择一笔数据", ICON.Exclamation);
            return;
        }
        var status = dw_list.GetItemString(dw_list.GetRow(), "qyzt");
        if (status == "1") {
            curStatus = "0";
        } else {
            curStatus = "1";
        }
        webReq.Invoke("W_CuXiaoSheZhi_Edit_EnableOrDisable", "curPzh=" + curPzh + "&curStatus=" + curStatus + "&curCXFS=mdxjdyz");
        if (webReq.StatusCode() == 200) {
            requestor.MessageBox("提示", "处理成功!", ICON.Information);
            var row = dw_list.GetRow()
            dw_list.Refresh();
            dw_list.ScrollToRow(row);
            return;
        }
        else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
            return;
        }
    }
    //#endregion   



    //#region 审核
    this.Audit = function () {
        if (dw_list.GetRow() < 1) {
            alert("请先选择一笔数据进行审核");
            return;
        }
        var pzh = dw_list.GetItemString(dw_list.GetRow(), "pzh");
        if (pzh.length < 1) {
            alert("凭证号异常");
            return;
        }
        if (!confirm("您确定要审核凭证号为[" + pzh + "]的方案吗？")) {
            return;
        }
        webReq.Invoke("W_YiBanCuXiaoSheZhi_Audit", "curPzh=" + pzh + "&curShjb=''" );
        if (webReq.StatusCode() == 200) {
            //#region 刷新汇总表
            dw_list.SetRedraw(false);
            dw_list.SetProcessing(true);

            //刷新
            // dw_list.Refresh();
            dw_list.Retrieve();
            //找到相应的记录
            var findRow = dw_list.Find("pzh='" + pzh + "' ", 1, dw_list.RowCount());
            if (findRow > 0) {
                dw_list.ScrollToRow(findRow);
            }
            dw_list.SetProcessing(false);
            dw_list.SetRedraw(true);
            //#endregion

        }
    }
    //#endregion

    //#region 退审
    this.UnAudit = function () {
        if (dw_list.GetRow() < 1) {
            alert("请先选择一笔数据进行退审");
            return;
        }
        var pzh = dw_list.GetItemString(dw_list.GetRow(), "pzh");
        if (pzh.length < 1) {
            alert("凭证号异常");
            return;
        }
        if (!confirm("您确定要退审凭证号为[" + pzh + "]的方案吗？")) {
            return;
        }
        webReq.Invoke("W_YiBanCuXiaoSheZhi_UnAudit", "curPzh=" + pzh);
        if (webReq.StatusCode() == 200) {

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

            //刷新
            //             dw_list.Refresh();
            dw_list.Retrieve();
            //找到相应的记录
            var findRow = dw_list.Find("pzh='" + pzh + "' ", 1, dw_list.RowCount());
            if (findRow > 0) {
                dw_list.ScrollToRow(findRow);
            }
            dw_list.SetProcessing(false);
            dw_list.SetRedraw(true);
            //#endregion             

            //   self.Hz_RowFocusChanged(dw_list.GetRow());
        }
    }
    //#endregion

    //#region this.DropDown
    this.List_DropDown = function () {
        if (dw_list.RowCount() < 1) {
            return;
        }
        var status = dw_list.GetItemString(dw_list.GetRow(), "qyzt");
        if (status == "1") {
            //启用着就要终止
            tb_1.SetImage("btn_6", "Custom024!")
            tb_1.SetText("btn_6", "终止");
        } else {
            //终止着就要启用
            tb_1.SetImage("btn_6", "Run!")
            tb_1.SetText("btn_6", "启用");
        }

        var fhStatus = dw_list.GetItemString(dw_list.GetRow(), "fhjb");
        if (fhStatus == "T") {
          
            tb_1.SetEnabled("btn_2", false);
            tb_1.SetEnabled("btn_3", false);
            tb_1.SetEnabled("btn_4", false);
            tb_1.SetEnabled("btn_5", true);
        } else {
            tb_1.SetEnabled("btn_2", true);
            tb_1.SetEnabled("btn_3", true);
            tb_1.SetEnabled("btn_4", true);
            tb_1.SetEnabled("btn_5", false);
        }
    }
    //#endregion
    //#region this.Exit
    this.Exit = function () {
        setTimeout("window.close();", 100);
    }
 }