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

    var self = this;
    var requestor = new PBWindow();
    var dw_edit = new DataWindow(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_edit == null) dw_edit = new DataWindow(requestor);
        dw_edit.Attach(win.Control("dw_edit"));

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

        if (typeof (self.Cancal) == "function")
            win.AttachEvent("cb_Quit", "Clicked", self.Cancal);

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

    }

    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_edit.Detach(); dw_edit = null;
        requestor.Detach(); requestor = null;

        setTimeout(CollectGarbage, 100);
    }

    //以上代码由设计器自动生成,请不要手工修改
    //ExtPB.Net JavaScript End  设计器查找标志,请不要删除或修改
    var dw_list = null;
    var curEditDw = null;
    var tv_1 = null;
    var curParentSelf = null;
    this.SetParentWindow = function (pTv, dw) {
        dw_list = dw;
        tv_1 = pTv;           
    }
    this.Save = function () {
     
    }
    this.Cancal = function () {
        requestor.Close();
    }
    this.Add = function () {

    }
    this.PostOpen = function () {
        var opflag = requestor.GetParm("opflag")
        if (opflag == "Edit") {
           // cb_Add.SetVisible(false);
            dw_edit.DeleteRow(0);
            dw_list.CopyDataEx(dw_list.GetRow(), dw_edit, 0);
            dw_edit.ResetUpdate();
        }
    }
    this.refTree = function (data, label, opflag) {
        var itemHanel = 0;
        if ("Add" == opflag) {
            itemHanel = tv_1.InsertItem(data, label);
            itemHanel = 1;
        }
        else {
            itemHanel = tv_1.UpdateItem(data, label);
            itemHanel = 1;
        }
        return itemHanel;
    }
    this.refList = function () {
        if (dw_list != null) {
            var row = dw_edit.GetRow();
            if (dw_edit.GetItemStatus(row, 0, DWBUFFER.Primary) == DWITEMSTATUS.NewModified) {
                dw_edit.CopyDataEx(dw_edit.GetRow(), dw_list, 0);
            }
            else {
                dw_edit.CopyDataEx(dw_edit.GetRow(), dw_list, dw_list.GetRow());
            }
            dw_list.Refresh();
        }
    }
    this.refListJldw = function () {
        if (dw_list != null) { 
            dw_list.Refresh(); 
        }
    }
    this.refListEx = function () {
        if (dw_list != null) {
            var row = dw_edit.GetRow();
            if (dw_edit.GetItemStatus(row, 0, DWBUFFER.Primary) == DWITEMSTATUS.NewModified) {
                dw_edit.CopyDataEx(dw_edit.GetRow(), dw_list, 0);
            }
            else {
                dw_edit.CopyDataEx(dw_edit.GetRow(), dw_list, dw_list.GetRow());
            } 
        }
    }
    this.PadLeft = function (str, v_length) {
        var tempstr = "";
            for (i = 0; i < v_length; i++) {
                tempstr += "0"
            }
            return tempstr + str
    }
}
