Beispiel #1
0
 private string GetRelateTextByValue(UD_ModelFields field, string value)
 {
     if (field.RelationType == 1)
     {
         //关联字典表
         return(DictionaryBLL.GetDicCollections(field.RelationTableName, false)[value].Name);
     }
     else if (field.RelationType == 2)
     {
         //关联实体表
         return(TreeTableBLL.GetRelationTableDataValue(field.RelationTableName, field.RelationValueField, field.RelationTextField, value));
     }
     else
     {
         return(value);
     }
 }
Beispiel #2
0
    protected void ddl_TableName_SelectedIndexChanged(object sender, EventArgs e)
    {
        IList <UD_ModelFields> fields = UD_ModelFieldsBLL.GetModelList("TableID='" + ddl_TableName.SelectedValue + "'");

        foreach (Rpt_DataSetFields f in new Rpt_DataSetBLL((Guid)ViewState["ID"]).GetFields())
        {
            UD_ModelFields field = fields.FirstOrDefault(p => p.ID == f.FieldID);
            if (field != null)
            {
                UD_TableList table = new UD_TableListBLL(field.RelationTableName).Model;
                if (field.RelationType == 2 && table != null && table.TreeFlag == "Y")
                {
                    continue;
                }

                fields.Remove(field);
            }
        }

        cbxl_Fields.DataSource = fields;
        cbxl_Fields.DataBind();
    }
        /// <summary>
        /// 用IList(IModel)数据源来绑定GridView
        /// </summary>
        /// <param name="m"></param>
        public void BindGrid <T>(IList <T> source)
        {
            this.DataSource = source;
            this.DataBind();

            if (source.Count == 0)
            {
                return;
            }

            IList <UD_TableList> _tables = new UD_TableListBLL()._GetModelList("ModelName='" + ((IModel)source[0]).ModelName + "'");

            if (_tables.Count == 0)
            {
                return;
            }
            UD_TableList table = _tables[0];

            IList <UD_ModelFields> fields = new UD_TableListBLL(table.ID).GetModelFields();

            for (int i = 0; i < Columns.Count; i++)
            {
                DataControlField column = Columns[i];

                if (column.GetType().Name == "BoundField")
                {
                    BoundField field = (BoundField)column;
                    if (!column.Visible)
                    {
                        continue;
                    }

                    IList <UD_ModelFields> _models = UD_ModelFieldsBLL.GetModelList("TableID='" + table.ID.ToString() + "' AND FieldName='" + field.DataField + "'");
                    if (_models.Count == 0)
                    {
                        continue;
                    }
                    UD_ModelFields model = _models[0];

                    switch (model.RelationType)
                    {
                    case 1:         //关联字典表
                        foreach (GridViewRow row in Rows)
                        {
                            Dictionary <string, Dictionary_Data> dic = DictionaryBLL.GetDicCollections(model.RelationTableName, false);
                            row.Cells[i].Text = dic.ContainsKey(row.Cells[i].Text) ? dic[row.Cells[i].Text].Name : "";
                        }
                        break;

                    case 2:         //关联实体表
                        foreach (GridViewRow row in Rows)
                        {
                            row.Cells[i].Text = TreeTableBLL.GetRelationTableDataValue(model.RelationTableName, model.RelationValueField, model.RelationTextField, row.Cells[i].Text);
                        }
                        break;
                    }

                    if (model.DataType == 4)  //日期型
                    {
                        foreach (GridViewRow row in Rows)
                        {
                            if (row.Cells[i].Text.StartsWith("1900-01-01"))
                            {
                                row.Cells[i].Text = "";
                            }
                        }
                    }
                }
            }
        }
    protected void btn_addsearch_Click(object sender, EventArgs e)
    {
        if (ddl_Field.SelectedValue == "0")
        {
            return;
        }
        //添加条件
        ListItem lt = new ListItem();

        #region 条件选择
        UD_TableList table = new UD_TableListBLL(new Guid(ddl_TableName.SelectedValue), true).Model;
        if (table == null)
        {
            return;
        }

        UD_ModelFields modelfield = null;
        try
        {
            modelfield = new UD_ModelFieldsBLL(new Guid(ddl_Field.SelectedValue), true).Model;
        }
        catch { }

        if (modelfield == null)
        {
            //自定义字段
            lt.Text  = ddl_Field.SelectedItem.Text + " " + ddl_op.SelectedItem.Text + " ('" + tbx_searchvalue.Text + "')";
            lt.Value = ddl_Field.SelectedValue + " " + ddl_op.SelectedItem.Value + " '" + tbx_searchvalue.Text + "'";
        }
        else
        {
            string fielddisplayname = table.DisplayName + "." + modelfield.DisplayName;
            string fieldfullname    = "";

            if (modelfield.Flag == "Y")
            {
                fieldfullname = table.Name + "." + modelfield.FieldName;        //实体字段
            }
            else
            {
                fieldfullname = "MCS_SYS.dbo.UF_Spilt(" + table.Name + ".ExtPropertys,'|'," + modelfield.Position.ToString() + ")";
            }


            if (ddl_op.SelectedValue == "NOTNULL")
            {
                lt.Text  = fielddisplayname + " 不为空";
                lt.Value = " ISNULL(" + fieldfullname + ",'')<>'' ";
                lbx_search.Items.Add(lt);
                return;
            }
            if (ddl_op.SelectedValue == "ISNULL")
            {
                lt.Text  = fielddisplayname + " 为空";
                lt.Value = " ISNULL(" + fieldfullname + ",'')='' ";
                lbx_search.Items.Add(lt);
                return;
            }

            switch (modelfield.RelationType)
            {
            case 1:
                #region 字典关联
                if (cbl_SearchValue.SelectedIndex != -1)
                {
                    lt.Text  = fielddisplayname + " 包含 ( ";
                    lt.Value = fieldfullname + " IN ( ";
                    foreach (ListItem item in cbl_SearchValue.Items)
                    {
                        if (item.Selected)
                        {
                            lt.Text  += item.Text + ",";
                            lt.Value += "'" + item.Value + "',";
                        }
                    }
                    lt.Text   = lt.Text.Substring(0, lt.Text.Length - 1);
                    lt.Value  = lt.Value.Substring(0, lt.Value.Length - 1);
                    lt.Text  += ")";
                    lt.Value += ")";
                }
                break;

                #endregion
            case 2:
                #region 实体表关联
                lt.Text  = fielddisplayname + " 为  ";
                lt.Value = fieldfullname + " =  ";
                if (!string.IsNullOrEmpty(modelfield.SearchPageURL))
                {
                    //通过查询控件查询
                    lt.Text  += MCSSelectControl1.SelectText;
                    lt.Value += "'" + MCSSelectControl1.SelectValue + "'";
                }
                else if (new UD_TableListBLL(modelfield.RelationTableName).Model.TreeFlag == "Y")
                {
                    #region 通过树形结构查询
                    if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity" || modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity")
                    {
                        if (ddl_TreeLevel.SelectedValue == "0")
                        {
                            lt.Text += MCSTreeControl1.SelectText;
                            lt.Value = fieldfullname + " = " + MCSTreeControl1.SelectValue;
                        }
                        else if (ddl_TreeLevel.SelectedValue == "100")
                        {
                            //所属于
                            lt.Text = fielddisplayname + " " + ddl_TreeLevel.SelectedItem.Text + " " + MCSTreeControl1.SelectText;

                            lt.Value = fieldfullname + " IN  (";
                            DataTable dt = TreeTableBLL.GetAllChildByNodes(modelfield.RelationTableName, "ID", "SuperID", MCSTreeControl1.SelectValue);
                            foreach (DataRow dr in dt.Rows)
                            {
                                lt.Value += "'" + dr[0].ToString() + "',";
                            }
                            lt.Value += "'" + MCSTreeControl1.SelectValue + "')";
                        }
                    }
                    else
                    {
                        lt.Text += MCSTreeControl1.SelectText;
                        lt.Value = fieldfullname + " IN  (";
                        DataTable dt = TreeTableBLL.GetAllChildByNodes(modelfield.RelationTableName, "ID", "SuperID", MCSTreeControl1.SelectValue);
                        foreach (DataRow dr in dt.Rows)
                        {
                            lt.Value += "'" + dr[0].ToString() + "',";
                        }
                        lt.Value += "'" + MCSTreeControl1.SelectValue + "')";
                    }
                    #endregion
                }
                else
                {
                    #region 其他关联方式的实体表
                    if (cbl_SearchValue.SelectedIndex != -1)
                    {
                        lt.Text  = fielddisplayname + " 包含 ( ";
                        lt.Value = fieldfullname + " IN ( ";
                        foreach (ListItem item in cbl_SearchValue.Items)
                        {
                            if (item.Selected)
                            {
                                lt.Text  += item.Text + ",";
                                lt.Value += "'" + item.Value + "',";
                            }
                        }
                        lt.Text   = lt.Text.Substring(0, lt.Text.Length - 1);
                        lt.Value  = lt.Value.Substring(0, lt.Value.Length - 1);
                        lt.Text  += ")";
                        lt.Value += ")";
                    }
                    #endregion
                }
                break;

                #endregion
            default:
                #region 非关联字段
                lt.Text  = fielddisplayname + " " + ddl_op.SelectedItem.Text + " ('" + tbx_searchvalue.Text + "')";
                lt.Value = fieldfullname + " =  ";
                if (ddl_op.SelectedValue == "StartWith")
                {
                    lt.Value = fieldfullname + " " + "Like" + " '" + tbx_searchvalue.Text + "%'";
                }
                else if (ddl_op.SelectedValue == "NotStartWith")
                {
                    lt.Value = fieldfullname + " " + "Not Like" + " '" + tbx_searchvalue.Text + "%'";
                }
                else if (ddl_op.SelectedValue != "like")
                {
                    if (modelfield.DataType == 4)            //日期(datetime)
                    {
                        lt.Value = "CONVERT(DATETIME,CONVERT(VARCHAR,CONVERT(DATETIME," + fieldfullname + "),111))" + " " + ddl_op.SelectedItem.Value + " '" + tbx_searchvalue.Text + "'";
                    }
                    else
                    {
                        lt.Value = fieldfullname + " " + ddl_op.SelectedItem.Value + " '" + tbx_searchvalue.Text + "'";
                    }
                }
                else
                {
                    lt.Value = fieldfullname + " " + ddl_op.SelectedItem.Value + " '%" + tbx_searchvalue.Text + "%'";
                }
                break;
                #endregion
            }
        }
        #endregion

        if (!string.IsNullOrEmpty(lt.Text))
        {
            lbx_search.Items.Add(lt);
        }
    }
    protected void ddl_op_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl_op.SelectedValue == "NOTNULL" || ddl_op.SelectedValue == "ISNULL")
        {
            tbx_searchvalue.Visible   = false;
            cbl_SearchValue.Visible   = false;
            ddl_TreeLevel.Visible     = false;
            MCSSelectControl1.Visible = false;
            MCSTreeControl1.Visible   = false;
        }
        else
        {
            #region 条件选择
            UD_ModelFields modelfield = null;
            try
            {
                modelfield = new UD_ModelFieldsBLL(new Guid(ddl_Field.SelectedValue), true).Model;
            }
            catch { }

            if (modelfield == null)
            {
                tbx_searchvalue.Visible = true;
                return;
            }
            else
            {
                switch (modelfield.RelationType)
                {
                case 1:
                    //字典关联
                    cbl_SearchValue.Visible = true;
                    break;

                case 2:
                    //实体表关联
                    if (!string.IsNullOrEmpty(modelfield.SearchPageURL))
                    {
                        //通过查询控件查询
                        MCSSelectControl1.Visible = true;
                    }
                    else if (new UD_TableListBLL(modelfield.RelationTableName).Model.TreeFlag == "Y")
                    {
                        MCSTreeControl1.Visible = true;
                        if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity" ||
                            modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity")
                        {
                            ddl_TreeLevel.Visible = true;
                        }
                    }
                    else
                    {
                        //其他关联方式的实体表
                        cbl_SearchValue.Visible = true;
                    }
                    break;

                default:
                    //非关联字段
                    tbx_searchvalue.Visible = true;
                    break;
                }
            }
            #endregion
        }
    }
    protected void ddl_Field_SelectedIndexChanged(object sender, EventArgs e)
    {
        tbx_searchvalue.Text = "";
        tbx_searchvalue.Attributes["onfocus"] = "";
        cbl_SearchValue.Items.Clear();
        ddl_op.Items.Clear();
        ddl_TreeLevel.Visible = false;

        tbx_searchvalue.Visible   = false;
        cbl_SearchValue.Visible   = false;
        MCSSelectControl1.Visible = false;
        MCSTreeControl1.Visible   = false;

        #region 条件选择
        UD_ModelFields modelfield = null;
        try
        {
            modelfield = new UD_ModelFieldsBLL(new Guid(ddl_Field.SelectedValue), true).Model;
        }
        catch { }

        if (modelfield == null)
        {
            #region 外部自定义条件
            ddl_op.Items.Add(new ListItem("等于", "="));
            ddl_op.Items.Add(new ListItem("大于", ">"));
            ddl_op.Items.Add(new ListItem("大于等于", ">="));
            ddl_op.Items.Add(new ListItem("小于", "<"));
            ddl_op.Items.Add(new ListItem("小于等于", "<="));
            ddl_op.Items.Add(new ListItem("不等于", "<>"));
            tbx_searchvalue.Visible = true;
            #endregion
        }
        else
        {
            switch (modelfield.RelationType)
            {
            case 1:
                #region 字典关联
                cbl_SearchValue.DataTextField  = "Value";
                cbl_SearchValue.DataValueField = "Key";
                cbl_SearchValue.DataSource     = DictionaryBLL.GetDicCollections(modelfield.RelationTableName);
                cbl_SearchValue.DataBind();
                cbl_SearchValue.Visible = true;
                ddl_op.Items.Insert(0, new ListItem("值", "SELECTITEM"));
                break;

                #endregion
            case 2:
                #region 实体表关联
                if (!string.IsNullOrEmpty(modelfield.SearchPageURL))
                {
                    //通过查询控件查询
                    MCSSelectControl1.PageUrl = modelfield.SearchPageURL;
                    MCSSelectControl1.Visible = true;
                }
                else if (new UD_TableListBLL(modelfield.RelationTableName).Model.TreeFlag == "Y")
                {
                    if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
                    {
                        #region 如果为管理片区字段,则取员工所能管辖的片区
                        Org_StaffBLL staff = new Org_StaffBLL((int)System.Web.HttpContext.Current.Session["UserID"]);
                        MCSTreeControl1.DataSource = staff.GetStaffOrganizeCity();

                        if (MCSTreeControl1.DataSource.Select("ID = 1").Length > 0 || staff.Model.OrganizeCity == 0)
                        {
                            MCSTreeControl1.RootValue   = "0";
                            MCSTreeControl1.SelectValue = "0";
                        }
                        else
                        {
                            MCSTreeControl1.RootValue   = new Addr_OrganizeCityBLL(staff.Model.OrganizeCity).Model.SuperID.ToString();
                            MCSTreeControl1.SelectValue = staff.Model.OrganizeCity.ToString();
                        }
                        #endregion
                    }
                    else
                    {
                        //通过树形结构查询
                        MCSTreeControl1.DataSource  = null;
                        MCSTreeControl1.TableName   = modelfield.RelationTableName;
                        MCSTreeControl1.RootValue   = "0";
                        MCSTreeControl1.SelectValue = "0";
                    }
                    MCSTreeControl1.DataBind();
                    MCSTreeControl1.Visible = true;

                    #region 如果是管理片区或行政城市,可以选择指定的树形级别
                    if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
                    {
                        ddl_TreeLevel.Items.Clear();
                        ddl_TreeLevel.Items.Insert(0, new ListItem("所属于", "100"));
                        ddl_TreeLevel.Items.Insert(1, new ListItem("当前值", "0"));
                        ddl_TreeLevel.Visible = true;
                    }
                    else if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity")
                    {
                        ddl_TreeLevel.Items.Clear();
                        ddl_TreeLevel.Items.Insert(0, new ListItem("所属于", "100"));
                        ddl_TreeLevel.Items.Insert(1, new ListItem("当前值", "0"));
                        ddl_TreeLevel.Visible = true;
                    }
                    #endregion
                }
                else
                {
                    //其他关联方式的实体表
                    cbl_SearchValue.DataTextField  = "Value";
                    cbl_SearchValue.DataValueField = "Key";
                    cbl_SearchValue.DataSource     = TreeTableBLL.GetRelationTableSourceData(modelfield.RelationTableName, modelfield.RelationValueField, modelfield.RelationTextField);
                    cbl_SearchValue.DataBind();
                    cbl_SearchValue.Visible = true;
                }
                ddl_op.Items.Insert(0, new ListItem("值", "SELECTITEM"));
                break;

                #endregion
            default:
                #region 非关联字段
                switch (modelfield.DataType)
                {
                case 1:             //整型(int)
                case 2:             //小数(decimal)
                    ddl_op.Items.Add(new ListItem("等于", "="));
                    ddl_op.Items.Add(new ListItem("大于", ">"));
                    ddl_op.Items.Add(new ListItem("大于等于", ">="));
                    ddl_op.Items.Add(new ListItem("小于", "<"));
                    ddl_op.Items.Add(new ListItem("小于等于", "<="));
                    ddl_op.Items.Add(new ListItem("不等于", "<>"));
                    break;

                case 3:             //字符串(varchar)
                case 6:             //字符串(nvarchar)
                case 8:             //ntext
                    ddl_op.Items.Add(new ListItem("等于", "="));
                    ddl_op.Items.Add(new ListItem("相似", "like"));
                    ddl_op.Items.Add(new ListItem("起始于", "StartWith"));
                    ddl_op.Items.Add(new ListItem("不起始于", "NotStartWith"));
                    break;

                case 4:             //日期(datetime)
                    ddl_op.Items.Add(new ListItem("等于", "="));
                    ddl_op.Items.Add(new ListItem("大于等于", ">="));
                    ddl_op.Items.Add(new ListItem("小于等于", "<="));
                    ddl_op.Visible = true;

                    tbx_searchvalue.Attributes["onfocus"] = "setday(this)";
                    break;

                case 5:             //GUID(uniqueidentifier)
                case 7:             //bit
                    ddl_op.Items.Add(new ListItem("等于", "="));
                    ddl_op.Items.Add(new ListItem("不等于", "<>"));
                    break;
                }
                tbx_searchvalue.Visible = true;
                break;
                #endregion
            }

            ddl_op.Items.Add(new ListItem("不为空", "NOTNULL"));
            ddl_op.Items.Add(new ListItem("为空", "ISNULL"));
        }
        #endregion
        ddl_op.SelectedIndex = 0;
    }