///<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" />
///<reference  path="/Base/W_MyBase_1.win.js" /> 

//注意,需要在对象定义后面，手工增加以下代码实现对象继承
// W_CuXiaoFangAnSheZhi.prototype = new W_MyBase_1( ); 

function W_CuXiaoFangAnSheZhi() {

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

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

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

    }

    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;
        q_famc.Detach(); q_famc = 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");
    
    this.Delete = function () {
        var row = dw_list.GetRow();
        if (row <= 0)
            return;
        if (requestor.MessageBox("提示", "是否确认删除当前记录", ICON.Question, BUTTON.YesNo) == 2) {
            dw_list.SetFocus();
            return;
        }
        var curFabh = dw_list.GetItemString(row, "fabh");
        webReq.Invoke("W_CuXiaoFangAnSheZhi_Delete", "curFabh=" + curFabh);
        if (webReq.StatusCode() == 200) {
            dw_list.RowsDiscard(row, row, 0); 
            requestor.MessageBox("提示", "记录删除成功!", ICON.Information);
        }
        else {
            requestor.MessageBox("提示", webReq.ResponseText(), ICON.StopSign);
        }
    }
    
    this.Query = function () {
       
        dw_list.SetFilter("");
        dw_list.Filter();
        var curdqbh = requestor.Trim(sle_qcbmbh.GetText()).toUpperCase();
        var curdqmc = requestor.Trim(sle_qcbmmc.GetText()).toUpperCase();
        var str = " (1=1) ";
        if (curdqbh.length > 0) {
            str += " and (Upper(csbh) like '%" + curdqbh + "%')"
        }
        if (curdqmc.length > 0) {
            str += " and (Upper(csmc) like '%" + curdqmc + "%')"
        }

        dw_list.SetFilter(str);
        dw_list.Filter();
    }
    this.EditChanged = function (tex) {
        dw_list.SetFilter("");
        dw_list.Filter();
        if (requestor.Trim(tex).length > 0) {
            dw_list.SetFilter("Upper(famc) like '%" + tex.toUpperCase() + "%'");
            dw_list.Filter();
        }
        dw_list.SetSort("fabh");
        dw_list.Sort();
    }
} 
W_CuXiaoFangAnSheZhi.prototype = new W_MyBase_1(); 