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

    var self = this;
    this.Instance = null;
    var requestor = new PBWindow();
    var dw_1 = new DataWindow(requestor);
    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_1 == null) dw_1 = new DataWindow(requestor);
        dw_1.Attach(win.Control("dw_1"));
        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.CloseQuery) == "function")
            win.AttachEvent("window", "CloseQuery", self.CloseQuery);

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

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

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

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

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

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

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

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

        if (typeof (self.OK) == "function")
            win.AttachEvent("btn_ok", "Clicked", self.OK);

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

        setTimeout(CollectGarbage, 100);
    }

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




    var curBmbh = "";
    var curParentSelf = ""
    var curFlag = "";
    var curDw_skmx = "";
    var curDw_mx = "";
    var curPzh = "";
    var editMode = "";
    var curSfcz = "0";
    var curYwlx = "";
    var dwc = new DataWindowChild();
 
    this.SetDataWindow = function (self, bmbh, flag, dw_skmx, dw_mx, pzh, eidtmode, sfcz) {
        curParentSelf = self;
        curBmbh = bmbh;
        curFlag = flag;
        curDw_skmx = dw_skmx;
        curDw_mx = dw_mx;
        curPzh = pzh;
        editMode = eidtmode;
        curSfcz = sfcz;

    }
//                     curDw_mx.SetItem(1, "bcsk", dw_list.GetItemNumber(1, "sum_bcsk"));
//                    curDw_mx.SetItem(1, "dj", dw_list.GetItemNumber(1, "sum_dj"));
//                    curDw_mx.SetItem(1, "bzj", dw_list.GetItemNumber(1, "sum_bzj"));
    this.CloseQuery = function () {
        dw_list.AcceptText();
        if (dw_list.GetItemNumber(1, "sum_bcsk") == 0 && dw_list.GetItemNumber(1, "sum_dj") == 0 && dw_list.GetItemNumber(1, "sum_bzj") == 0) {
            curParentSelf.ClickZhsk();
        }
    }

    this.PostOpen = function () {

        dw_list.Clear();
        dw_list.Reset();
        if (curFlag == "pf") {
            dw_list.Modify("dj.Visible='0'");
            dw_list.Modify("bzj.Visible='0'");
        }
        //        if (curYwlx == "PT" || curYwlx == "LT") {
        //            dw_mx.Modify("bcsk.editmask.mask='-#########0.00'");
        //            dw_mx.Modify("dj.editmask.mask='-#########0.00'");
        //            dw_mx.Modify("bzj.editmask.mask='-#########0.00'");
        //        }

        //        if (curYwlx == "PF" || curYwlx == "LC" || curYwlx == "CW") {
        //            dw_mx.Modify("bcsk.editmask.mask='#########0.00'");
        //            dw_mx.Modify("dj.editmask.mask='#########0.00'");
        //            dw_mx.Modify("bzj.editmask.mask='#########0.00'");
        //        }

        if (editMode == "Add") {
            dw_1.Retrieve(curBmbh)

            for (var i = 1; i <= dw_1.RowCount(); i++) {
                dw_list.InsertRow(0);
                dw_list.SetItem(i, "bcsk", dw_1.GetItemNumber(i, "bcsk"));
                dw_list.SetItem(i, "dj", dw_1.GetItemNumber(i, "dj"));
                dw_list.SetItem(i, "bzj", dw_1.GetItemNumber(i, "bzj"));
                dw_list.SetItem(i, "zh", dw_1.GetItemString(i, "zh"));
                dw_list.SetItem(i, "skx", dw_1.GetItemString(i, "csbh"));
                dw_list.SetItem(i, "csmc", dw_1.GetItemString(i, "csmc"));
                dw_list.SetItem(i, "zhlx", dw_1.GetItemString(i, "zhlx"));
                dw_list.SetItem(i, "pzh", curPzh);

                self.ItemFocusChanged(i, "zh");
            }
        } else {
            if (curSfcz == "1") {
                dw_1.Retrieve(curBmbh)


                for (var i = 1; i <= dw_1.RowCount(); i++) {
                    dw_list.InsertRow(0);
                    dw_list.SetItem(i, "bcsk", dw_1.GetItemNumber(i, "bcsk"));
                    dw_list.SetItem(i, "dj", dw_1.GetItemNumber(i, "dj"));
                    dw_list.SetItem(i, "bzj", dw_1.GetItemNumber(i, "bzj"));
                    dw_list.SetItem(i, "zh", dw_1.GetItemString(i, "zh"));
                    dw_list.SetItem(i, "skx", dw_1.GetItemString(i, "csbh"));
                    dw_list.SetItem(i, "csmc", dw_1.GetItemString(i, "csmc"));
                    dw_list.SetItem(i, "zhlx", dw_1.GetItemString(i, "zhlx"));
                    dw_list.SetItem(i, "pzh", curPzh);
                    self.ItemFocusChanged(i, "zh");
                }
            }
            else {
                dw_list.Retrieve(curBmbh, curPzh)

                if (dw_list.RowCount() == 0) {
                    dw_1.Retrieve(curBmbh)

                    for (var i = 1; i <= dw_1.RowCount(); i++) {
                        dw_list.InsertRow(0);
                        dw_list.SetItem(i, "bcsk", dw_1.GetItemNumber(i, "bcsk"));
                        dw_list.SetItem(i, "dj", dw_1.GetItemNumber(i, "dj"));
                        dw_list.SetItem(i, "bzj", dw_1.GetItemNumber(i, "bzj"));
                        dw_list.SetItem(i, "zh", dw_1.GetItemString(i, "zh"));
                        dw_list.SetItem(i, "skx", dw_1.GetItemString(i, "csbh"));
                        dw_list.SetItem(i, "csmc", dw_1.GetItemString(i, "csmc"));
                        dw_list.SetItem(i, "zhlx", dw_1.GetItemString(i, "zhlx"));
                        dw_list.SetItem(i, "pzh", curPzh);
                        self.ItemFocusChanged(i, "zh");


                    }
                }
            }
        }




    }


    this.Exit = function () {

        requestor.Close();
    }

    this.OK = function () {
        dw_list.AcceptText();
        var rowCount = curDw_skmx.RowCount()
        for (var i = 1; i <= dw_list.RowCount(); i++) {
            if (editMode == "Add") {
                curDw_skmx.InsertRow(0);
                curDw_skmx.SetItem(i, "bcsk", dw_list.GetItemNumber(i, "bcsk"));
                curDw_skmx.SetItem(i, "dj", dw_list.GetItemNumber(i, "dj"));
                curDw_skmx.SetItem(i, "bzj", dw_list.GetItemNumber(i, "bzj"));
                curDw_skmx.SetItem(i, "zh", dw_list.GetItemString(i, "zh"));
                curDw_skmx.SetItem(i, "skx", dw_list.GetItemString(i, "skx"));
                curDw_skmx.SetItem(i, "pzh", curPzh);


                if (curFlag == "pf") {
                    curDw_mx.SetItem(1, "bdsk", dw_list.GetItemNumber(1, "sum_bcsk"));
                } else {
                    curDw_mx.SetItem(1, "bcsk", dw_list.GetItemNumber(1, "sum_bcsk"));
                    curDw_mx.SetItem(1, "dj", dw_list.GetItemNumber(1, "sum_dj"));
                    curDw_mx.SetItem(1, "bzj", dw_list.GetItemNumber(1, "sum_bzj"));
                }
            } else {
                if (rowCount == 0) {
                    curDw_skmx.InsertRow(0);
                    curDw_skmx.SetItem(i, "bcsk", dw_list.GetItemNumber(i, "bcsk"));
                    curDw_skmx.SetItem(i, "dj", dw_list.GetItemNumber(i, "dj"));
                    curDw_skmx.SetItem(i, "bzj", dw_list.GetItemNumber(i, "bzj")); 
                    curDw_skmx.SetItem(i, "zh", dw_list.GetItemString(i, "zh"));
                    curDw_skmx.SetItem(i, "skx", dw_list.GetItemString(i, "skx"));
                    curDw_skmx.SetItem(i, "pzh", curPzh);


                    if (curFlag == "pf") {
                        curDw_mx.SetItem(1, "bdsk", dw_list.GetItemNumber(1, "sum_bcsk"));
                    } else {
                        curDw_mx.SetItem(1, "bcsk", dw_list.GetItemNumber(1, "sum_bcsk"));
                        curDw_mx.SetItem(1, "dj", dw_list.GetItemNumber(1, "sum_dj"));
                        curDw_mx.SetItem(1, "bzj", dw_list.GetItemNumber(1, "sum_bzj"));
                    }

                } else {

                    curDw_skmx.SetItem(i, "bcsk", dw_list.GetItemNumber(i, "bcsk"));
                    curDw_skmx.SetItem(i, "dj", dw_list.GetItemNumber(i, "dj"));
                    curDw_skmx.SetItem(i, "bzj", dw_list.GetItemNumber(i, "bzj"));
                    curDw_skmx.SetItem(i, "zh", dw_list.GetItemString(i, "zh"));
                    if (curFlag == "pf") {
                        curDw_mx.SetItem(1, "bdsk", dw_list.GetItemNumber(1, "sum_bcsk"));
                    } else {
                        curDw_mx.SetItem(1, "bcsk", dw_list.GetItemNumber(1, "sum_bcsk"));
                        curDw_mx.SetItem(1, "dj", dw_list.GetItemNumber(1, "sum_dj"));
                        curDw_mx.SetItem(1, "bzj", dw_list.GetItemNumber(1, "sum_bzj"));
                    }

                }

            }
        }


        //curParentSelf.EvalJs("curSfcz=\"0\"")
        self.Exit();

    }

//    this.EditChanged = function (row, downame, data) {

//        if (curYwlx == "PT" || curYwlx == "LT") {
//            if (downame == "dj" || downame == "bcsk" || downame == "bzj") {
//                dw_list.SetItem(row, downame, -Math.abs(data))
//            }
//        }
//    }

    this.DropDown = function (s) {


        dw_list.GetChild("zh", dwc);
        dwc.SetFilter("");
        dwc.Filter();
        if (dw_list.GetItemString(dw_list.GetRow(), "zhlx") == "1") {
            dwc.SetFilter("zhfl='1'");
            dwc.Filter();
        } else if (dw_list.GetItemString(dw_list.GetRow(), "zhlx") == "0") {

            dwc.SetFilter("zhfl='0'");
            dwc.Filter();
        } else {
            dwc.SetFilter("zhfl='error'");
            dwc.Filter();
        }


       

    }
    this.ItemFocusChanged = function (row, docName) {
        var curData = "";
        if (row > 0) {
            curData = dw_list.GetItemString(row, "zh");
        }
        if (row > 0 && docName == "zh") {
            dw_list.SetItem(row, "zhmc", curData);
        }
    }

    this.ItemChanged = function (row, docName, data) {
        //         alert([row, downame, data])
        //        dw_list.GetChild("zh", dwc);
        //        dwc.SetFilter("");
        //        dwc.Filter();
        //        dw_list.AcceptText();
        //        return 1;
        if (row > 0  && docName=="zh") {
            dw_list.SetItem(row, "zhmc",data);
        }

    }

    this.DragDrop = function () {
        alert();
    }
}