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

    var self = this;
    this.Instance = null;
    var requestor = new PBWindow();
    var cb_7 = new CommandButton(requestor);
    var st_6 = new StaticText(requestor);
    var sle_spkh = new SingleLineEdit(requestor);
    var st_rqgs = new StaticText(requestor);
    var sle_kdr = new SingleLineEdit(requestor);
    var sle_cgfs = new SingleLineEdit(requestor);
    var sle_cgy = new SingleLineEdit(requestor);
    var dw_2 = new DataWindow(requestor);
    var dw_1 = new DataWindow(requestor);
    var cb_1 = new CommandButton(requestor);
    var sle_jzr = new SingleLineEdit(requestor);
    var sle_gys = new SingleLineEdit(requestor);
    var sle_bm = new SingleLineEdit(requestor);
    var dp_2 = new DatePicker(requestor);
    var dp_1 = new DatePicker(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 (cb_7 == null) cb_7 = new CommandButton(requestor);
        cb_7.Attach(win.Control("cb_7"));
        if (st_6 == null) st_6 = new StaticText(requestor);
        st_6.Attach(win.Control("st_6"));
        if (sle_spkh == null) sle_spkh = new SingleLineEdit(requestor);
        sle_spkh.Attach(win.Control("sle_spkh"));
        if (st_rqgs == null) st_rqgs = new StaticText(requestor);
        st_rqgs.Attach(win.Control("st_rqgs"));
        if (sle_kdr == null) sle_kdr = new SingleLineEdit(requestor);
        sle_kdr.Attach(win.Control("sle_kdr"));
        if (sle_cgfs == null) sle_cgfs = new SingleLineEdit(requestor);
        sle_cgfs.Attach(win.Control("sle_cgfs"));
        if (sle_cgy == null) sle_cgy = new SingleLineEdit(requestor);
        sle_cgy.Attach(win.Control("sle_cgy"));
        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 (cb_1 == null) cb_1 = new CommandButton(requestor);
        cb_1.Attach(win.Control("cb_1"));
        if (sle_jzr == null) sle_jzr = new SingleLineEdit(requestor);
        sle_jzr.Attach(win.Control("sle_jzr"));
        if (sle_gys == null) sle_gys = new SingleLineEdit(requestor);
        sle_gys.Attach(win.Control("sle_gys"));
        if (sle_bm == null) sle_bm = new SingleLineEdit(requestor);
        sle_bm.Attach(win.Control("sle_bm"));
        if (dp_2 == null) dp_2 = new DatePicker(requestor);
        dp_2.Attach(win.Control("dp_2"));
        if (dp_1 == null) dp_1 = new DatePicker(requestor);
        dp_1.Attach(win.Control("dp_1"));

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

        if (typeof (self.Changekh) == "function")
            win.AttachEvent("cb_7", "Clicked", self.Changekh);

        if (typeof (self.CleanSpkh) == "function")
            win.AttachEvent("st_6", "DoubleClicked", self.CleanSpkh);

        if (typeof (self.Changekdr) == "function")
            win.AttachEvent("cb_9", "Clicked", self.Changekdr);

        if (typeof (self.Changetzfs) == "function")
            win.AttachEvent("cb_6", "Clicked", self.Changetzfs);

        if (typeof (self.Changecgy) == "function")
            win.AttachEvent("cb_5", "Clicked", self.Changecgy);

        if (typeof (self.Cancel) == "function")
            win.AttachEvent("cb_4", "Clicked", self.Cancel);

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

        if (typeof (self.ADD) == "function")
            win.AttachEvent("cb_2", "Clicked", self.ADD);

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

        if (typeof (self.Ok) == "function")
            win.AttachEvent("cb_1", "Clicked", self.Ok);

        if (typeof (self.Changejzr) == "function")
            win.AttachEvent("cb_fs", "Clicked", self.Changejzr);

        if (typeof (self.Changegys) == "function")
            win.AttachEvent("cb_kh", "Clicked", self.Changegys);

        if (typeof (self.Changebmbh) == "function")
            win.AttachEvent("cb_bm", "Clicked", self.Changebmbh);

    }

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

        cb_7.Detach(); cb_7 = null;
        st_6.Detach(); st_6 = null;
        sle_spkh.Detach(); sle_spkh = null;
        st_rqgs.Detach(); st_rqgs = null;
        sle_kdr.Detach(); sle_kdr = null;
        sle_cgfs.Detach(); sle_cgfs = null;
        sle_cgy.Detach(); sle_cgy = null;
        dw_2.Detach(); dw_2 = null;
        dw_1.Detach(); dw_1 = null;
        cb_1.Detach(); cb_1 = null;
        sle_jzr.Detach(); sle_jzr = null;
        sle_gys.Detach(); sle_gys = null;
        sle_bm.Detach(); sle_bm = null;
        dp_2.Detach(); dp_2 = null;
        dp_1.Detach(); dp_1 = null;
        requestor.Detach(); requestor = null;

        setTimeout(CollectGarbage, 100);
    }

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

    var curParentDw = null;
    var curParentSelf = "";
    var curFlag = "";
    var curYhbh = "";
    var curDjzt = "";
    var curSelDays = "";
    var curlylx = "";
    var curW_OPEN_BMDA = new OpenWindowQueryBase();
    var curW_OPEN_SIMPLE_CHOSE = new OpenWindowSimpleChoseBase();
    var curW_OPEN_BMDA_NEW = new OpenWindowQueryNewBase();
    var curW_OPEN_BMDA_URL = "OpenWindowQueryNewBase";
    this.SetDataWindow = function (Selfs, ParentDw, YwFlag, yhbh, djzt, cxts, lylx) {
        curParentSelf = Selfs;
        curParentDw = ParentDw;
        curFlag = YwFlag;
        curYhbh = yhbh;
        curDjzt = djzt;
        curSelDays = cxts;
        curlylx = lylx
    }

    this.PostOpen = function () {
        var myDate = new Date();
        var nian = myDate.getFullYear().toString();
        var yue = myDate.getMonth();
        var ri = "01";
        var objDate = new Date(nian, yue, ri);
        dp_1.SetValue(objDate.getVarDate());
        dp_2.SetValue(UtcDateFormatToString(new Date().getVarDate()));
        self.GetColoumName();
        dw_1.SetColumn("mcz");
        dw_1.SetFocus();
    }

    //#region Function 呼出数据窗口的函数群 

    this.Changebmbh = function (x, y, row, dwoName) {
        dwoName == "bmbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(self, "bmbh", "bmmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base." + curW_OPEN_BMDA_URL + "&treeDw=dw_da_bmda_fl_tree&listDw=dw_pub_list_bmda&treeRootLabel=部门分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&selectStyle=multiple&curQxlx=cg"), curW_OPEN_BMDA_NEW, null);
    }

    this.Changegys = function (x, y, row, dwoName) {
        dwoName == "gysbh";
        curW_OPEN_BMDA_NEW.SetDataWindow(W_CaiGou_ChaXun, "gysbh", "gysmc", "M", self)
        //curW_OPEN_BMDA_NEW.SetDataWindow(W_YW_CG_ZDYBB_Main, "gysbh", "gysmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base." + curW_OPEN_BMDA_URL + "&treeDw=dw_da_gysda_fl_tree&listDw=dw_pub_list_gysda&treeRootLabel=供应商分类&treeData=flbh&treeLabel=flmc&treeParentData=fflbh&treeLeave=islast&selectStyle=multiple"), curW_OPEN_BMDA_NEW, null);

    }

    this.Changetzfs = function (x, y, row, dwoName) {
        dwoName == "csbh";
        var curDw = "";
        if (curFlag == "CG" || curFlag == "CS") {
            curDw = "dw_pub_list_qj_csb_ddfs";
        } else {
            curDw = "dw_pub_list_qj_csb_rkfs_csbh";
        }
        curW_OPEN_SIMPLE_CHOSE.SetDataWindow(self, "csbh", "csmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowSimpleChoseBase&listDw=" + curDw + "&selectStyle=multiple"), curW_OPEN_SIMPLE_CHOSE, null);
    }

    //记账人
    this.Changejzr = function (x, y, row, dwoName) {
        dwoName == "ygbh";
        curW_OPEN_BMDA.SetDataWindow(self, "ygbh", "ygmc", "M", self)
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowQueryBase&treeDw=dw_da_ryda_zw_tree&listDw=dw_pub_ygda_list_cx&treeRootLabel=职务分类&treeData=csbh&treeLabel=csmc&treeParentData=fcsbh&treeLeave=islast&selectStyle=multiple&flag=cg"), curW_OPEN_BMDA, null);
    }
    //采购员
    this.Changecgy = function (x, y, row, dwoName) {
        dwoName == "cgy";
        curW_OPEN_BMDA.SetDataWindow(self, "ygbh", "ygmc", "YG", self, "cgy")
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowQueryBase&treeDw=dw_da_ryda_zw_tree&listDw=dw_pub_ygda_list_cx&treeRootLabel=职务分类&treeData=csbh&treeLabel=csmc&treeParentData=fcsbh&treeLeave=islast&selectStyle=multiple&flag=cg"), curW_OPEN_BMDA, null);
    }
    //开单人
    this.Changekdr = function (x, y, row, dwoName) {
        dwoName == "kdr";
        curW_OPEN_BMDA.SetDataWindow(self, "ygbh", "ygmc", "YG", self, "kdr")
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base.OpenWindowQueryBase&treeDw=dw_da_ryda_zw_tree&listDw=dw_pub_ygda_list_cx&treeRootLabel=职务分类&treeData=csbh&treeLabel=csmc&treeParentData=fcsbh&treeLeave=islast&selectStyle=multiple&flag=cg"), curW_OPEN_BMDA, null);
    }
    // 商品款号

    this.Changekh = function (x, y, row, dwoName) {
        dwoName == "spkh";
        curW_OPEN_BMDA_NEW.SetDataWindow(self, "spkh", "ksmc", "M", self)  // 这个用来给子窗口Set当前数据窗口
        requestor.Open(encodeURI("/Service/LoadWindow.ashx?WinName=A8ERP.DangAn.Base." + curW_OPEN_BMDA_URL + "&treeDw=dw_da_sp_lbda_tree&listDw=dw_da_sp_spda_1&treeRootLabel=商品分类&treeData=lbbh&treeLabel=lbmc&treeParentData=flbbh&treeLeave=islast&selectStyle=multiple&curQxlx=all"), curW_OPEN_BMDA_NEW, null);
    }
    //#endregion

    //#region 选中后赋值

    this.SetSleValue = function (difBh, val) {
        if ("''" == val)
            val = "";

        if ("bmbh" == difBh)
            sle_bm.SetText(val);
        else if ("gysbh" == difBh)
            sle_gys.SetText(val);
        else if ("csbh" == difBh)
            sle_cgfs.SetText(val);
        else if ("ygbh" == difBh)
            sle_jzr.SetText(val);
        else if ("cgy" == difBh)
            sle_cgy.SetText(val);
        else if ("kdr" == difBh)
            sle_kdr.SetText(val);
        else if ("spkh" == difBh)
            sle_spkh.SetText(val);
    }

    //#endregion

    this.Ok = function () {
        dw_1.AcceptText();

        var sql = self.GetSqlWhere();

        if (curSelDays != "-1") {
            sql += " and CONVERT(date,kdrq,120) >='" + curSelDays + "'";
        }
        curParentSelf.EvalJs("curSelSQL=\"" + sql + "\"");

        if (curFlag == "CZ") {
            if (curDjzt == "未入库") {
                curDjzt = " and isnull(phbz,'0') = '0'";

            } else if (curDjzt == "入库中") {
                curDjzt = "and isnull(phbz,'0') = '1'";

            } else if (curDjzt == "已入库") {
                curDjzt = "and isnull(zdbz,'0') = '2'";

            } else if (curDjzt == "已转单") {
                curDjzt = "and isnull(zdbz,'0') = '1'";

            } else if (curDjzt == "未转单") {
                curDjzt = "and isnull(zdbz,'0') = '0'";
            } else {
                curDjzt = "and 1=1";
            }

        } else {
            if (curDjzt == "未记账") {
                curDjzt = "isnull(jzbz,'0')<>'1'";
            } else if (curDjzt == "已记账") {
                curDjzt = "isnull(jzbz,'0')='1'";
            } else if (curDjzt == "全部") {
                curDjzt = "";
            } else if (curDjzt == "未审核") {//2020-1215修改汇总查询方式加
                djzt = "isnull(shbz,'0')<>'T'";
            } else if (curDjzt == "已审核") {//2020-1215修改汇总查询方式加
                djzt = "isnull(shbz,'0')='T'";
            }

            else if (curDjzt == "已转单") {
                curDjzt = "已转单";
            }
            else if (curDjzt == "未转单") {
                curDjzt = "未转单";
            }
            else {
                curDjzt = "fhmc='" + curDjzt + "'";
            }
            //        alert([curFlag, curlylx])
            if (curFlag == "CG") {

                if (curDjzt == "已转单" || curDjzt == "未转单") {
                    sql += " AND (case when (select COUNT(pzh) from (select pzh from (select pzh,lydh,djlx from yw_cg_rkdhz union all select pzh,lydh,djlx from yw_cg_rkdhz_ls union all select pzh,lydh,djlx from yw_cg_tzdhz union all select pzh,lydh,djlx from yw_cg_tzdhz_ls) bb where lydh=a.pzh )t)>0 then '已转单' else '未转单' end)= '" + djzt + "' ";
                }
                else {
                    if (curDjzt.length > 0) {
                        sql += " and  " + curDjzt;
                    }
                }

                // sql = sql + " and  (fhmc+isnull(jzbz,'0')+(case when (select COUNT(pzh)  from (select pzh from (select pzh,lydh,djlx from yw_cg_rkdhz union all select pzh,lydh,djlx from yw_cg_rkdhz_ls union all select pzh,lydh,djlx from yw_cg_tzdhz union all select pzh,lydh,djlx from yw_cg_tzdhz_ls) bb where  lydh=a.pzh )t)>0 then '已转单' else '未转单' end) like '%" + curDjzt + "%')";
            } else if (curFlag == "CR" || curFlag == "CT") {
                if (curlylx == "全部单据") {
                    sql += " and  1=1";
                }
                else if (curlylx == "新增单据") {
                    sql += " and (lydh is null or lydh ='')";
                }
                else if (curlylx == "转接单据") {
                    sql += " and lydh <> ''";
                }
                if (curDjzt.length > 0) {
                    sql += " and  " + curDjzt;
                }
            }
            else {

                if (curDjzt.length > 0) {
                    sql += " and  " + curDjzt;
                }
                // sql = sql + "and ( fhmc+isnull(jzbz,'0') like '" + curDjzt + "')";
            }
        }

        
        if (curFlag == "CZ") {
            curParentDw.RetrieveEx(sql);
        } else {
            curParentSelf.SelectionChanged(sql);
        }
        // curParentDw.RetrieveEx(sql); 2020-12-15修改汇总查询方式把这一行屏蔽了
        requestor.Close();
    }

    //#region Function GetSqlWhere
    this.GetSqlWhere = function () {

        var realSql = "";
        var beginDate = UtcDateFormatToString(dp_1.GetValue());
        var endDate = UtcDateFormatToString(dp_2.GetValue());
        var curKh = sle_gys.GetText();
        var curBm = sle_bm.GetText();
        var curFs = sle_cgfs.GetText();
        var curJzr = sle_jzr.GetText();
        var curCgy = sle_cgy.GetText();
        var curKdr = sle_kdr.GetText();
        var curSpkh = sle_spkh.GetText();

        realSql += " (CONVERT(date,kdrq) between '" + beginDate + "' and '" + endDate + "')  ";

        if (curBm.length > 0) {
            var is_quotes = curBm.substring(0, 1);
            if (is_quotes == "%") {
                realSql += " and a.bmbh like ('" + curBm + "%')";
            }
            else {
                var curflag = curBm.substr(curBm.length - 1, 1);
                if (curflag == "," || curflag == "，") {
                    curBm = curBm.substring(0, curBm.length - 1);
                    var tempspkh = self.GetQuotes(curBm);
                    realSql += " and a.bmbh in(" + tempspkh + ")";
                }
                else {
                    if (is_quotes == "'") {
                        realSql += " and a.bmbh in(" + curBm + ")";
                    }
                    else {
                        realSql += " and a.bmbh like('" + curBm + "%')";
                    }
                }

            }
        } else {
            realSql += "and a.bmbh in(select bmbh  from da_qx_bmqxsz where yhbh = '" + curYhbh + "' and cg = '1')"
        }

        if (curKh.length > 0) {

            var is_quotes = curKh.substring(0, 1);
            if (is_quotes == "%") {
                realSql += " and a.gysbh like ('" + curKh + "%')";
            }
            else {
                var curflag = curKh.substr(curKh.length - 1, 1);
                if (curflag == "," || curflag == "，") {
                    curKh = curKh.substring(0, curKh.length - 1);
                    var tempspkh = self.GetQuotes(curKh);
                    realSql += " and a.gysbh in(" + tempspkh + ")";
                }
                else {
                    if (is_quotes == "'") {
                        realSql += " and a.gysbh in(" + curKh + ")";
                    }
                    else {
                        realSql += " and a.gysbh like('" + curKh + "%')";
                    }
                }

            }
        } else {
            realSql += "and a.gysbh in(select gysbh from da_qx_gysda where yhbh='" + curYhbh + "' and bz3='1' )"
        }

        if (curFs.length > 0) {
            var is_quotes = curFs.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and a.cgfs in(" + curFs + ")";
            } else {
                var tempspkh = self.GetQuotes(curFs);
                realSql += " and a.cgfs in(" + tempspkh + ")";
            }
        }

        if (curJzr.length > 0) {
            var is_quotes = curJzr.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and a.jzr in(" + curJzr + ")";
            } else {
                var tempspkh = self.GetQuotes(curJzr);
                realSql += " and a.jzr in(" + tempspkh + ")";
            }
        }

        if (curCgy.length > 0) {
            var is_quotes = curCgy.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and a.cgy in(" + curCgy + ")";
            } else {
                var tempspkh = self.GetQuotes(curCgy);
                realSql += " and a.cgy in(" + tempspkh + ")";
            }
        }

        if (curKdr.length > 0) {
            var is_quotes = curKdr.substring(0, 1);
            if (is_quotes == "'") {
                realSql += " and a.kdr in(" + curKdr + ")";
            } else {
                var tempspkh = self.GetQuotes(curKdr);
                realSql += " and a.kdr in(" + tempspkh + ")";
            }
        }

        if (curSpkh.length > 0) {
            var is_quotes = curSpkh.substring(0, 1);
            var tableName = ""
            if (curFlag == "CG") {
                tableName = "yw_cg_ddmx";
            }
            else if (curFlag == "CZ") {
                tableName = "yw_cg_tzdmx";
            }
            else if (curFlag == "CR") {
                tableName = "yw_cg_rkdmx";
            }
            else if (curFlag == "CS") {
                tableName = "yw_cg_ddmx";
            }
            else if (curFlag == "CD") {
                tableName = "yw_cg_tzdmx";
            }

            else if (curFlag == "CT") {
                tableName = "yw_cg_rkdmx";
            }

            if (is_quotes == "'") {
                realSql += " and a.pzh IN (SELECT a.pzh FROM  " + tableName + " a WHERE spkh IN (" + curSpkh + "))";
            } else {
                var tempspkh = self.GetQuotes(curSpkh);
                realSql += " and a.pzh IN (SELECT a.pzh FROM  " + tableName + " a WHERE spkh IN (" + tempspkh + "))";
            }

        }

        for (var i = 1; i <= dw_1.RowCount(); i++) {
            var curMcz = dw_1.GetItemString(i, "mcz");

            if (curMcz.length > 0) {
                var curBh = dw_1.GetItemString(i, "bh");
                var curTj = dw_1.GetItemString(i, "tj");
                //包含
                if (curTj == "1") {
                    if (curBh == "jzsj") {
                        realSql += " and ( convert(date,a." + curBh + ") like '%" + curMcz + "%')";
                    } else if (curBh == "xxly") {
                        realSql += " and ( a." + curBh + " in( select csbh from da_qj_csb where csfl = 'XXLY' and UPPER(csmc) like UPPER('%" + curMcz + "%')))";
                    } else if (curBh == "fklx") {
                        realSql += " and ( a." + curBh + " in( select csbh from da_qj_csb where csfl = 'FKLX' and UPPER(csmc) like UPPER('%" + curMcz + "%')))";
                    } else if (curBh != "zjsl" && curBh != "zjje") {
                        realSql += " and ( UPPER(a." + curBh + ") like UPPER('%" + curMcz + "%'))";
                    }
                }
                //等于
                else if (curTj == "2") {
                    if (curBh == "jzsj") {
                        realSql += " and ( convert(date,a." + curBh + ")  = '" + curMcz + "')";
                    } else if (curBh == "zjsl" || curBh == "zjje") {
                        realSql += " and ( a." + curBh + " = " + curMcz + ")";
                    } else if (curBh == "xxly") {
                        realSql += " and ( a." + curBh + " in( select csbh from da_qj_csb where csfl = 'XXLY' and UPPER(csmc) = UPPER('" + curMcz + "')))";
                    } else if (curBh == "fklx") {
                        realSql += " and ( a." + curBh + " in( select csbh from da_qj_csb where csfl = 'FKLX' and UPPER(csmc) = UPPER('" + curMcz + "')))";
                    } else {
                        realSql += " and ( UPPER(a." + curBh + ") = UPPER('" + curMcz + "'))";
                    }
                }
                //大于
                else if (curTj == "3") {
                    if (curBh == "jzsj") {
                        realSql += " and ( convert(date,a." + curBh + ") > '" + curMcz + "')";
                    } else if (curBh == "zjsl" || curBh == "zjje") {
                        realSql += " and ( a." + curBh + " > " + curMcz + ")";
                    } else if (curBh == "xxly") {
                        realSql += " and ( a." + curBh + " in( select csbh from da_qj_csb where csfl = 'XXLY' and UPPER(csmc)> UPPER('" + curMcz + "')))";
                    } else if (curBh == "fklx") {
                        realSql += " and ( a." + curBh + " in( select csbh from da_qj_csb where csfl = 'FKLX' and UPPER(csmc) > UPPER('" + curMcz + "')))";
                    } else if (curBh != "pzh" && curBh != "lydh" && curBh != "bzxx") {
                        realSql += " and ( UPPER(a." + curBh + ") > UPPER('" + curMcz + "')）";
                    }
                }
                //小于
                else if (curTj == "4") {
                    if (curBh == "jzsj") {
                        realSql += " and ( convert(date,a." + curBh + ") <  '" + curMcz + "')";
                    } else if (curBh == "zjsl" || curBh == "zjje") {
                        realSql += " and ( a." + curBh + " <" + curMcz + ")";
                    } else if (curBh == "xxly") {
                        realSql += " and ( a." + curBh + " in( select csbh from da_qj_csb where csfl = 'XXLY' and UPPER(csmc)< UPPER('" + curMcz + "')))";
                    } else if (curBh == "fklx") {
                        realSql += " and ( a." + curBh + " in( select csbh from da_qj_csb where csfl = 'FKLX' and UPPER(csmc) < UPPER('" + curMcz + "')))";
                    } else if (curBh != "pzh" && curBh != "lydh" && curBh != "bzxx") {
                        realSql += " and ( UPPER(a." + curBh + ") < UPPER('" + curMcz + "'))";
                    }
                }
                //大于等于
                else if (curTj == "5") {
                    if (curBh == "jzsj") {
                        realSql += " and ( convert(date,a." + curBh + ")  >= '" + curMcz + "')";
                    } else if (curBh == "zjsl" || curBh == "zjje") {
                        realSql += " and ( a." + curBh + " >= " + curMcz + ")";
                    } else if (curBh == "xxly") {
                        realSql += " and ( a." + curBh + " in( select csbh from da_qj_csb where csfl = 'XXLY' and UPPER(csmc)>= UPPER('" + curMcz + "')))";
                    } else if (curBh == "fklx") {
                        realSql += " and ( a." + curBh + " in( select csbh from da_qj_csb where csfl = 'FKLX' and UPPER(csmc) >= UPPER('" + curMcz + "')))";
                    } else if (curBh != "pzh" && curBh != "lydh" && curBh != "bzxx") {
                        realSql += " and ( UPPER(a." + curBh + ") >= UPPER('" + curMcz + "'))";
                    }
                }
                //小于等于
                else if (curTj == "6") {
                    if (curBh == "jzsj") {
                        realSql += " and ( convert(date,a." + curBh + ") <= '" + curMcz + "')";
                    } else if (curBh == "zjsl" || curBh == "zjje") {
                        realSql += " and ( a." + curBh + " <=" + curMcz + ")";
                    } else if (curBh == "xxly") {
                        realSql += " and ( a." + curBh + " in( select csbh from da_qj_csb where csfl = 'XXLY' and UPPER(csmc) <= UPPER('" + curMcz + "')))";
                    } else if (curBh == "fklx") {
                        realSql += " and ( a." + curBh + " in( select csbh from da_qj_csb where csfl = 'FKLX' and UPPER(csmc) <= UPPER('" + curMcz + "')))";
                    } else if (curBh != "pzh" && curBh != "lydh" && curBh != "bzxx") {
                        realSql += " and ( UPPER(a." + curBh + ") <= UPPER('" + curMcz + "'))";
                    }
                }
            }
        }

        return realSql;
    }
    //#endregion

    //#region 处理引号的问题
    this.GetQuotes = function (curValue) {
        var temp1 = curValue.split(",")
        var ret_Value = "";
        for (var i = 0; i < temp1.length; i++) {
            if (ret_Value.length > 0) {
                ret_Value += "'" + temp1[i] + "',";
            }
            else {
                ret_Value = "'" + temp1[i] + "',"
            }
        }
        return ret_Value.substr(0, ret_Value.length - 1);
    }
    //#endregion

    this.ADD = function () {
        var rows = dw_1.InsertRow(0);
        dw_1.ScrollToRow(rows);
        dw_1.SetColumn("mc");
        dw_1.SetFocus();
        dw_1.SetItem(rows, "tj", "等于");
        dw_1.ScrollToRow(dw_1.RowCount());

    }

    //#region this.DeleteRow
    this.Delete = function () {

        var row = dw_1.GetRow();
        if (row <= 0)
            return;

        dw_1.DeleteRow(0);
        dw_1.SetFocus();

    }
    //#endregion

    this.Cancel = function () {
        requestor.Close();
    }

    this.GetColoumName = function () {
        var colCount = dw_2.Describe("DataWindow.Column.Count");
        var value = "";
        for (var li_loop1 = 1; li_loop1 <= colCount; li_loop1++) {
            var ls_columnname = dw_2.Describe('#' + String(li_loop1) + '.name');
            var ls_columnname_t = dw_2.Describe(ls_columnname + "_t.text");

            if (ls_columnname != "kdrq" && ls_columnname != "jzbz" && ls_columnname != "bmbh" && ls_columnname != "cgy" && ls_columnname != "jzr" && ls_columnname != "kdr" && ls_columnname != "bmmc" && ls_columnname != "gysbh" && ls_columnname != "gysmc" && ls_columnname != "cgfs" && ls_columnname != "fhjb" && ls_columnname != "fhjbmc") {
                if (!(ls_columnname == "jzsj" && (curFlag == "CZ" || curFlag == "CD"))) {
                    var curRows = dw_1.InsertRow(0);
                    dw_1.SetItem(curRows, "bh", ls_columnname);
                    dw_1.SetItem(curRows, "mc", ls_columnname_t);
                }
            }
        }
        var curRq_y = 612;
        for (var i = 1; i <= dw_1.RowCount(); i++) {
            curRq_y += 76;
            if (dw_1.GetItemString(i, "bh") == "jzsj") {
              
                break;
            } 
        }
        
        st_rqgs.SetY(curRq_y);
        st_rqgs.SetText("如:" + UtcDateFormatToString(new Date().getVarDate()));
    }

    this.CleanSpkh = function () {

        sle_spkh.SetText("");
    }

 }