public QueryObject InitQueryObjectByEns(Entities ens, bool IsShowSearchKey, DTSearchWay dw, string dtKey, Attrs attrs, AttrsOfSearch attrsOfSearch, AttrSearchs searchAttrs)
        {
            QueryObject qo = new QueryObject(ens);

            #region 关键字
            string keyVal = "";
            //Attrs attrs = en.EnMap.Attrs;
            if (IsShowSearchKey)
            {
                TB keyTB = this.GetTBByID("TB_Key");
                if (keyTB != null)
                {
                    keyVal = keyTB.Text.Trim();
                }
                else
                {
                    UserRegedit ur = new UserRegedit();
                    //ur.MyPK = WebUser.No + ens.GetNewEntity.ClassID + "_SearchAttrs";
                    QueryObject urObj = new QueryObject(ur);
                    urObj.AddWhere("MyPK", WebUser.No + ens.GetNewEntity.ClassID + "_SearchAttrs");
                    urObj.DoQuery();

                    keyVal = ur.SearchKey;
                }
                this.Page.Session["SKey"] = keyVal;
            }

            if (keyVal.Length >= 1)
            {
                Attr attrPK = new Attr();
                foreach (Attr attr in attrs)
                {
                    if (attr.IsPK)
                    {
                        attrPK = attr;
                        break;
                    }
                }
                int i = 0;
                foreach (Attr attr in attrs)
                {
                    switch (attr.MyFieldType)
                    {
                    case FieldType.Enum:
                    case FieldType.FK:
                    case FieldType.PKFK:
                        continue;

                    default:
                        break;
                    }


                    if (attr.MyDataType != DataType.AppString)
                    {
                        continue;
                    }

                    if (attr.MyFieldType == FieldType.RefText)
                    {
                        continue;
                    }

                    if (attr.Key == "FK_Dept")
                    {
                        continue;
                    }

                    i++;
                    if (i == 1)
                    {
                        /* 第一次进来。 */
                        qo.addLeftBracket();
                        switch (SystemConfig.AppCenterDBType)
                        {
                        case BP.DA.DBType.Oracle:
                        case BP.DA.DBType.Informix:
                            qo.AddWhere(attr.Key, " LIKE ", " '%'||" + SystemConfig.AppCenterDBVarStr + "SKey||'%'");
                            break;

                        case BP.DA.DBType.MySQL:
                            qo.AddWhere(attr.Key, " LIKE ", "CONCAT('%'," + SystemConfig.AppCenterDBVarStr + "SKey,'%')");
                            break;

                        default:
                            qo.AddWhere(attr.Key, " LIKE ", " '%'+" + SystemConfig.AppCenterDBVarStr + "SKey+'%'");
                            break;
                        }
                        continue;
                    }
                    qo.addOr();

                    switch (SystemConfig.AppCenterDBType)
                    {
                    case BP.DA.DBType.Oracle:
                    case BP.DA.DBType.Informix:
                        qo.AddWhere(attr.Key, " LIKE ", "'%'||" + SystemConfig.AppCenterDBVarStr + "SKey||'%'");
                        break;

                    case BP.DA.DBType.MySQL:
                        qo.AddWhere(attr.Key, " LIKE ", "CONCAT('%'," + SystemConfig.AppCenterDBVarStr + "SKey,'%')");
                        break;

                    default:
                        qo.AddWhere(attr.Key, " LIKE ", "'%'+" + SystemConfig.AppCenterDBVarStr + "SKey+'%'");
                        break;
                    }
                }
                qo.MyParas.Add("SKey", keyVal);
                qo.addRightBracket();
            }
            else
            {
                qo.addLeftBracket();
                qo.AddWhere("abc", "all");
                qo.addRightBracket();
            }
            #endregion

            #region 普通属性
            string opkey = ""; // 操作符号。
            foreach (AttrOfSearch attr in attrsOfSearch)
            {
                if (attr.IsHidden)
                {
                    qo.addAnd();
                    qo.addLeftBracket();
                    qo.AddWhere(attr.RefAttrKey, attr.DefaultSymbol, attr.DefaultValRun);
                    qo.addRightBracket();
                    continue;
                }

                if (attr.SymbolEnable == true)
                {
                    opkey = this.GetDDLByKey("DDL_" + attr.Key).SelectedItemStringVal;
                    if (opkey == "all")
                    {
                        continue;
                    }
                }
                else
                {
                    opkey = attr.DefaultSymbol;
                }

                qo.addAnd();
                qo.addLeftBracket();

                if (attr.DefaultVal.Length >= 8)
                {
                    string date = "2005-09-01";
                    try
                    {
                        /* 就可能是年月日。 */
                        string y = this.GetDDLByKey("DDL_" + attr.Key + "_Year").SelectedItemStringVal;
                        string m = this.GetDDLByKey("DDL_" + attr.Key + "_Month").SelectedItemStringVal;
                        string d = this.GetDDLByKey("DDL_" + attr.Key + "_Day").SelectedItemStringVal;
                        date = y + "-" + m + "-" + d;

                        if (opkey == "<=")
                        {
                            DateTime dt = DataType.ParseSysDate2DateTime(date).AddDays(1);
                            date = dt.ToString(DataType.SysDataFormat);
                        }
                    }
                    catch
                    {
                    }

                    qo.AddWhere(attr.RefAttrKey, opkey, date);
                }
                else
                {
                    qo.AddWhere(attr.RefAttrKey, opkey, this.GetTBByID("TB_" + attr.Key).Text);
                }
                qo.addRightBracket();
            }
            #endregion

            #region 外键
            foreach (AttrSearch attr1 in searchAttrs)
            {
                Attr attr = attr1.HisAttr;

                if (attr.MyFieldType == FieldType.RefText)
                {
                    continue;
                }


                DDL ddl = this.GetDDLByKey("DDL_" + attr.Key);
                if (ddl.Items.Count == 0)
                {
                    continue;
                }

                string selectVal = ddl.SelectedItemStringVal;
                if (selectVal == "all")
                {
                    continue;
                }

                if (selectVal == "mvals")
                {
                    UserRegedit sUr = new UserRegedit();
                    sUr.MyPK = WebUser.No + this.EnsName + "_SearchAttrs";
                    sUr.RetrieveFromDBSources();

                    /* 如果是多选值 */
                    string cfgVal = sUr.MVals;
                    AtPara ap     = new AtPara(cfgVal);
                    string instr  = ap.GetValStrByKey(attr.Key);
                    if (instr == null || instr == "")
                    {
                        if (attr.Key == "FK_Dept" || attr.Key == "FK_Unit")
                        {
                            if (attr.Key == "FK_Dept")
                            {
                                selectVal         = WebUser.FK_Dept;
                                ddl.SelectedIndex = 0;
                            }

                            //if (attr.Key == "FK_Unit")
                            //{
                            //    selectVal = WebUser.FK_Unit;
                            //    ddl.SelectedIndex = 0;
                            //}
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        instr = instr.Replace("..", ".");
                        instr = instr.Replace(".", "','");
                        instr = instr.Substring(2);
                        instr = instr.Substring(0, instr.Length - 2);

                        qo.addAnd();
                        qo.addLeftBracket();
                        qo.AddWhereIn(attr.Key, "(" + instr + ")");
                        qo.addRightBracket();
                        continue;
                    }
                }


                qo.addAnd();
                qo.addLeftBracket();

                if (attr.UIBindKey == "BP.Port.Depts" || attr.UIBindKey == "BP.Port.Units")  //判断特殊情况。
                {
                    qo.AddWhere(attr.Key, " LIKE ", selectVal + "%");
                }
                else
                {
                    qo.AddWhere(attr.Key, selectVal);
                }

                //qo.AddWhere(attr.Key,this.GetDDLByKey("DDL_"+attr.Key).SelectedItemStringVal ) ;
                qo.addRightBracket();
            }
            #endregion .

            if (dw != DTSearchWay.None)
            {
                string dtFrom = this.GetTBByID("TB_S_From").Text.Trim();
                string dtTo   = this.GetTBByID("TB_S_To").Text.Trim();
                if (dw == DTSearchWay.ByDate)
                {
                    qo.addAnd();
                    qo.addLeftBracket();
                    qo.SQL = dtKey + " >= '" + dtFrom + " 01:01'";
                    qo.addAnd();
                    qo.SQL = dtKey + " <= '" + dtTo + " 23:59'";
                    qo.addRightBracket();

                    //qo.AddWhere(dtKey, ">=", dtFrom+" 01:01");
                    //qo.addAnd();
                    //qo.AddWhere(dtKey, "<=", dtTo + " 23:59");
                    //qo.addRightBracket();
                }

                if (dw == DTSearchWay.ByDateTime)
                {
                    qo.addAnd();
                    qo.addLeftBracket();
                    qo.SQL = dtKey + " >= '" + dtFrom + "'";
                    qo.addAnd();
                    qo.SQL = dtKey + " <= '" + dtTo + "'";
                    qo.addRightBracket();

                    //qo.addAnd();
                    //qo.addLeftBracket();
                    //qo.AddWhere(dtKey, ">=", dtFrom);
                    //qo.addAnd();
                    //qo.AddWhere(dtKey, "<=", dtTo);
                    //qo.addRightBracket();
                }
            }

            //  throw new Exception(qo.SQL);
            return(qo);
        }
        /// <summary>
        /// 查询方式
        /// </summary>
        /// <param name="isShowKey"></param>
        /// <param name="sw"></param>
        /// <param name="dtSearchKey"></param>
        /// <param name="attrsOfSearch"></param>
        /// <param name="attrsOfFK"></param>
        /// <param name="attrD1"></param>
        /// <param name="page"></param>
        /// <param name="ur"></param>
        public void InitByMapV2(bool isShowKey, DTSearchWay sw, AttrsOfSearch attrsOfSearch, AttrSearchs attrsOfFK, Attrs attrD1, int page, UserRegedit ur)
        {
            int keysNum = 0;

            // 关键字。
            if (isShowKey)
            {
                this.AddLab("Lab_Key", "关键字:&nbsp;");
                TB tb = new TB();
                tb.ID      = "TB_Key";
                tb.Columns = 13;
                this.AddTB(tb);
                keysNum++;
            }
            this.Add("&nbsp;");

            if (sw != DTSearchWay.None)
            {
                Label lab = new Label();
                lab.ID   = "Lab_From";
                lab.Text = "日期从:";
                this.Add(lab);
                TB tbDT = new TB();
                tbDT.ID = "TB_S_From";
                if (sw == DTSearchWay.ByDate)
                {
                    tbDT.ShowType = TBType.Date;
                }
                if (sw == DTSearchWay.ByDateTime)
                {
                    tbDT.ShowType = TBType.DateTime;
                }
                this.Add(tbDT);

                lab      = new Label();
                lab.ID   = "Lab_To";
                lab.Text = "到:";
                this.Add(lab);

                tbDT    = new TB();
                tbDT.ID = "TB_S_To";
                if (sw == DTSearchWay.ByDate)
                {
                    tbDT.ShowType = TBType.Date;
                }
                if (sw == DTSearchWay.ByDateTime)
                {
                    tbDT.ShowType = TBType.DateTime;
                }
                this.Add(tbDT);
            }


            // 非外键属性。
            foreach (AttrOfSearch attr in attrsOfSearch)
            {
                if (attr.IsHidden)
                {
                    continue;
                }

                this.AddLab("Lab_" + attr.Key, attr.Lab);
                keysNum++;

                if (attr.SymbolEnable == true)
                {
                    DDL ddl = new DDL();
                    ddl.ID                 = "DDL_" + attr.Key;
                    ddl.SelfShowType       = DDLShowType.Ens; //  attr.UIDDLShowType;
                    ddl.SelfBindKey        = "BP.Sys.Operators";
                    ddl.SelfEnsRefKey      = "No";
                    ddl.SelfEnsRefKeyText  = "Name";
                    ddl.SelfDefaultVal     = attr.DefaultSymbol;
                    ddl.SelfAddAllLocation = AddAllLocation.None;
                    ddl.SelfIsShowVal      = false; ///不让显示编号
                    //ddl.ID="DDL_"+attr.Key;
                    //ddl.SelfBind();
                    this.AddDDL(ddl);
                    this.GetDDLByKey("DDL_" + attr.Key).SelfBind();
                }

                if (attr.DefaultVal.Length >= 8)
                {
                    DateTime mydt = BP.DA.DataType.ParseSysDate2DateTime(attr.DefaultVal);

                    DDL ddl = new DDL();
                    ddl.ID                 = "DDL_" + attr.Key + "_Year";
                    ddl.SelfShowType       = DDLShowType.Ens;
                    ddl.SelfBindKey        = "BP.Pub.NDs";
                    ddl.SelfEnsRefKey      = "No";
                    ddl.SelfEnsRefKeyText  = "Name";
                    ddl.SelfDefaultVal     = mydt.ToString("yyyy");
                    ddl.SelfAddAllLocation = AddAllLocation.None;
                    ddl.SelfIsShowVal      = false; ///不让显示编号
                    this.AddDDL(ddl);
                    ddl.SelfBind();
                    //ddl.SelfBind();

                    ddl                    = new DDL();
                    ddl.ID                 = "DDL_" + attr.Key + "_Month";
                    ddl.SelfShowType       = DDLShowType.Ens;
                    ddl.SelfBindKey        = "BP.Pub.YFs";
                    ddl.SelfEnsRefKey      = "No";
                    ddl.SelfEnsRefKeyText  = "Name";
                    ddl.SelfDefaultVal     = mydt.ToString("MM");
                    ddl.SelfAddAllLocation = AddAllLocation.None;
                    ddl.SelfIsShowVal      = false; ///不让显示编号
                    //	ddl.SelfBind();
                    this.AddDDL(ddl);
                    ddl.SelfBind();

                    ddl                    = new DDL();
                    ddl.ID                 = "DDL_" + attr.Key + "_Day";
                    ddl.SelfShowType       = DDLShowType.Ens;
                    ddl.SelfBindKey        = "BP.Pub.Days";
                    ddl.SelfEnsRefKey      = "No";
                    ddl.SelfEnsRefKeyText  = "Name";
                    ddl.SelfDefaultVal     = mydt.ToString("dd");
                    ddl.SelfAddAllLocation = AddAllLocation.None;
                    ddl.SelfIsShowVal      = false; ///不让显示编号
                    //ddl.SelfBind();
                    this.AddDDL(ddl);
                    this.GetDDLByKey(ddl.ID).SelfBind();
                }
                else
                {
                    TB tb = new TB();
                    tb.ID      = "TB_" + attr.Key;
                    tb.Text    = attr.DefaultVal;
                    tb.Columns = attr.TBWidth;
                    this.AddTB(tb);
                }
            }

            string ensName = this.Page.Request.QueryString["EnsName"];
            string cfgVal  = "";

            cfgVal = ur.Vals;


            // 外键属性查询。
            bool isfirst = true;

            foreach (AttrSearch attr1 in attrsOfFK)
            {
                Attr attr = attr1.HisAttr;

                if (attr.MyFieldType == FieldType.RefText)
                {
                    continue;
                }

                DDL ddl = new DDL();
                ddl.ID = "DDL_" + attr.Key;
                this.AddDDL(ddl);
                keysNum++;
                //if (keysNum == 3 || keysNum == 6 || keysNum == 9)
                //    this.AddBR("b_" + keysNum);
                if (attr.MyFieldType == FieldType.Enum)
                {
                    this.GetDDLByKey("DDL_" + attr.Key).BindSysEnum(attr.UIBindKey, false, AddAllLocation.TopAndEndWithMVal);
                    this.GetDDLByKey("DDL_" + attr.Key).Items[0].Text = ">>" + attr.Desc;

                    this.GetDDLByKey("DDL_" + attr.Key).Attributes["onclick"] = "DDL_mvals_OnChange(this,'" + ensName + "','" + attr.Key + "')";
                    // this.GetDDLByKey("DDL_" + attr.Key).Attributes["onchange"] = "DDL_mvals_OnChange(this,'" + ur.MyPK + "','" + attr.Key + "')";

                    // ddl.Attributes["onchange"] = "DDL_mvals_OnChange(this,'" + ur.MyPK + "','" + attr.Key + "')";
                }
                else
                {
                    ListItem liMvals = new ListItem("*多项组合..", "mvals");
                    liMvals.Attributes.CssStyle.Add("style", "color:green");
                    liMvals.Attributes.Add("color", "green");
                    liMvals.Attributes.Add("style", "color:green");

                    // liMvals.Attributes.Add("onclick", "alert('sss')");

                    switch (attr.UIBindKey)
                    {
                    case "BP.Port.Depts":
                        ddl.Items.Clear();
                        BP.Port.Depts depts = new BP.Port.Depts();
                        depts.RetrieveAll();
                        foreach (BP.Port.Dept dept in depts)
                        {
                            string space = "";
                            //   space = space.PadLeft(dept.Grade - 1, '-');
                            ListItem li = new ListItem(space + dept.Name, dept.No);
                            this.GetDDLByKey("DDL_" + attr.Key).Items.Add(li);
                        }
                        if (depts.Count > SystemConfig.MaxDDLNum)
                        {
                            this.AddLab("lD", "<a href=\"javascript:onDDLSelectedMore('DDL_" + attr.Key + "', '" + this.EnsName + "', 'BP.Port.Depts', 'No','Name')\" >...</a>");
                        }

                        if (ddl.Items.Count >= 2)
                        {
                            ddl.Items.Add(liMvals);
                        }

                        ddl.Attributes["onchange"] = "DDL_mvals_OnChange(this,'" + ensName + "','" + attr.Key + "')";
                        break;
                    //case "BP.Port.Units":
                    //    ddl.Items.Clear();
                    //    BP.Port.Units units = new BP.Port.Units();
                    //    units.RetrieveAll();
                    //    foreach (BP.Port.Unit unit in units)
                    //    {
                    //        string space = "";
                    //        space = space.PadLeft(unit.No.Length / 2 - 1, '-');
                    //        ListItem li = new ListItem(space + unit.Name, unit.No);
                    //        this.GetDDLByKey("DDL_" + attr.Key).Items.Add(li);
                    //    }
                    //    if (units.Count > SystemConfig.MaxDDLNum)
                    //        this.AddLab("lD", "<a href=\"javascript:onDDLSelectedMore('DDL_" + attr.Key + "', '" + this.EnsName + "', 'BP.Port.Units', 'No','Name')\" >...</a>");

                    //    if (ddl.Items.Count >= 2)
                    //        ddl.Items.Add(liMvals);

                    //    ddl.Attributes["onchange"] = "DDL_mvals_OnChange(this,'" + ensName + "','" + attr.Key + "')";
                    // break;
                    default:
                        ddl.Items.Clear();
                        if (attr.MyDataType == DataType.AppBoolean)
                        {
                            ddl.Items.Add(new ListItem(">>" + attr.Desc, "all"));
                            ddl.Items.Add(new ListItem("是", "1"));
                            ddl.Items.Add(new ListItem("否", "0"));
                            break;
                        }
                        Entities ens = attr.HisFKEns;
                        ens.RetrieveAll();
                        ddl.Items.Add(new ListItem(">>" + attr.Desc, "all"));
                        foreach (Entity en in ens)
                        {
                            ddl.Items.Add(new ListItem(en.GetValStrByKey("Name"), en.GetValStrByKey("No")));
                        }

                        if (ddl.Items.Count >= 2)
                        {
                            ddl.Items.Add(liMvals);
                        }

                        ddl.Attributes["onchange"] = "DDL_mvals_OnChange(this,'" + ensName + "','" + attr.Key + "')";
                        break;
                    }
                }
                if (isfirst)
                {
                    isfirst = false;
                }
            }
            if (_AddSearchBtn)
            {
                this.AddLinkBtn(NamesOfBtn.Search, " 查询 ");
            }
        }