Exemplo n.º 1
0
    protected void ddl_FieldID_SelectedIndexChanged(object sender, EventArgs e)
    {
        UD_ModelFieldsBLL bll = new UD_ModelFieldsBLL(new Guid(ddl_FieldID.SelectedValue));

        if (bll.Model.RelationType == 1 || bll.Model.RelationType == 2)
        {
            ddl_DisplayMode.Enabled = true;

            //如果关联表是树形结构,则允许设定树表层次
            if (bll.Model.RelationType == 2 && new UD_TableListBLL(bll.Model.RelationTableName).Model.TreeFlag == "Y")
            {
                tbx_TreeLevel.Enabled = true;
            }
            else
            {
                tbx_TreeLevel.Text    = "";
                tbx_TreeLevel.Enabled = false;
            }
        }
        else
        {
            ddl_DisplayMode.Enabled       = false;
            ddl_DisplayMode.SelectedValue = "1";
            tbx_TreeLevel.Text            = "";
            tbx_TreeLevel.Enabled         = false;
        }

        tbx_LabelText.Text = ddl_FieldID.SelectedItem.Text;
    }
    protected void ddl_TableName_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddl_Field.DataSource = UD_ModelFieldsBLL.GetModelList("TableID='" + ddl_TableName.SelectedValue + "'");
        ddl_Field.DataBind();

        ddl_Field.Items.Insert(0, new ListItem("请选择...", Guid.Empty.ToString()));
    }
Exemplo n.º 3
0
 protected void ddl_ChildTable_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (ddl_ChildTable.SelectedValue != "")
     {
         ddl_ChildField.DataSource = UD_ModelFieldsBLL.GetModelList("TableID='" + ddl_ChildTable.SelectedValue + "'");
         ddl_ChildField.DataBind();
     }
 }
Exemplo n.º 4
0
    protected void ddl_TableName_SelectedIndexChanged(object sender, EventArgs e)
    {
        UD_ModelFieldsBLL mf = new UD_ModelFieldsBLL();

        ddl_FieldID.DataSource = mf._GetModelList("TableID='" + ddl_TableName.SelectedValue + "'");
        ddl_FieldID.DataBind();
        ddl_FieldID_SelectedIndexChanged(null, null);
    }
Exemplo n.º 5
0
    protected void bt_AddToDataSet_Click(object sender, EventArgs e)
    {
        IList <Rpt_DataSetFields> datasetfields = new Rpt_DataSetBLL((Guid)ViewState["ID"]).GetFields();
        int maxsortid = 0;

        if (datasetfields.Count > 0)
        {
            maxsortid = datasetfields.Max(p => p.ColumnSortID);
        }

        foreach (ListItem item in cbxl_Fields.Items)
        {
            if (item.Selected)
            {
                Guid fieldid = new Guid(item.Value);

                UD_ModelFields f = new UD_ModelFieldsBLL(fieldid).Model;
                if (f != null)
                {
                    string fieldname = new UD_TableListBLL(f.TableID).Model.ModelClassName + "_" + f.FieldName;
                    if (datasetfields.FirstOrDefault(p => p.FieldName == fieldname) != null)
                    {
                        continue;
                    }

                    maxsortid++;

                    Rpt_DataSetFieldsBLL fieldbll = new Rpt_DataSetFieldsBLL();
                    fieldbll.Model.DataSet        = (Guid)ViewState["ID"];
                    fieldbll.Model.FieldID        = f.ID;
                    fieldbll.Model.FieldName      = fieldname;
                    fieldbll.Model.DisplayName    = f.DisplayName;
                    fieldbll.Model.DataType       = f.DataType;
                    fieldbll.Model.IsComputeField = "N";
                    fieldbll.Model.ColumnSortID   = maxsortid;

                    if (f.RelationType == 1 || f.RelationType == 2)
                    {
                        fieldbll.Model.DisplayMode = 2;
                    }
                    else
                    {
                        fieldbll.Model.DisplayMode = 1;
                    }

                    fieldbll.Model.Description = f.Description;
                    fieldbll.Add();
                }
            }
        }

        BindGrid();
        new Rpt_DataSetBLL((Guid)ViewState["ID"]).ClearCache();
    }
    protected void ddl_TableName_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddl_Field.DataSource = UD_ModelFieldsBLL.GetModelList("TableID='" + ddl_TableName.SelectedValue + "'");
        ddl_Field.DataBind();

        ddl_Field.Items.Insert(0, new ListItem("请选择...", "0"));
        if (_ontableselectedindexchanged != null)
        {
            _ontableselectedindexchanged.Invoke(sender, e);
        }
    }
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        UD_ModelFieldsBLL _modelfieldsbll;
        if (ViewState["ID"] != null)
            _modelfieldsbll = new UD_ModelFieldsBLL((Guid)ViewState["ID"]);
        else
            _modelfieldsbll = new UD_ModelFieldsBLL();
        _modelfieldsbll.Model.TableID = (Guid)ViewState["TableID"];
        _modelfieldsbll.Model.FieldName = tbx_FieldName.Text;
        _modelfieldsbll.Model.DisplayName = tbx_DisplayName.Text;
        _modelfieldsbll.Model.DataType = int.Parse(ddl_DataType.SelectedValue);
        _modelfieldsbll.Model.DataLength = string.IsNullOrEmpty(tbx_Length.Text) ? 0 : int.Parse(tbx_Length.Text);
        _modelfieldsbll.Model.Precision = string.IsNullOrEmpty(tbx_Precision.Text) ? 0 : int.Parse(tbx_Precision.Text);
        _modelfieldsbll.Model.DefaultValue = tbx_DefaultValue.Text;
        _modelfieldsbll.Model.Description = tbx_Description.Text;
        _modelfieldsbll.Model.RelationType = int.Parse(rbl_RelationType.SelectedValue);
        _modelfieldsbll.Model.SearchPageURL = tbx_SearchPageURL.Text;

        if (ddl_RelationTableName.Visible)
        {
            _modelfieldsbll.Model.RelationTableName = ddl_RelationTableName.SelectedValue;
        }
        else
        {
            _modelfieldsbll.Model.RelationTableName = "";
        }
        if (ddl_RelationTextField.Visible)
        {
            _modelfieldsbll.Model.RelationTextField = ddl_RelationTextField.SelectedValue;
        }
        else
        {
            _modelfieldsbll.Model.RelationTextField = "";
        }
        if (ddl_RelationValueField.Visible)
        {
            _modelfieldsbll.Model.RelationValueField = ddl_RelationValueField.SelectedValue;
        }
        else
        {
            _modelfieldsbll.Model.RelationValueField = "";
        }

        _modelfieldsbll.Model.LastUpdateTime = DateTime.Now;

        if (ViewState["ID"] != null)
            _modelfieldsbll.Update();
        else
        {
            _modelfieldsbll.Model.Flag = "N";
            _modelfieldsbll.Add();
        }
        Response.Redirect("ModelFieldList.aspx?TableID=" + ViewState["TableID"].ToString());
    }
    protected void ddl_RelationTableName_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl_RelationTableName.Visible && rbl_RelationType.SelectedValue == "2")
        {
            ddl_RelationTextField.DataSource = UD_ModelFieldsBLL.GetModelList("TableID='" +
                                                                              new UD_TableListBLL(ddl_RelationTableName.SelectedValue).Model.ID.ToString() + "'");
            ddl_RelationTextField.DataBind();

            ddl_RelationValueField.DataSource = ddl_RelationTextField.DataSource;
            ddl_RelationValueField.DataBind();
        }
    }
Exemplo n.º 9
0
        /// <summary>
        /// Get data from the special model
        /// </summary>
        /// <param name="_model"></param>
        public void GetData(IModel _model)
        {
            foreach (object _key in FieldControlsInfo.Keys)
            {
                FieldControlInfo fieldcontrolinfo = (FieldControlInfo)FieldControlsInfo[_key];
                string           fieldname        = fieldcontrolinfo.FieldName;

                if (fieldcontrolinfo.ModelName == _model.ModelName)
                {
                    switch (fieldcontrolinfo.ControlType)
                    {
                    case 1:
                        //_model[fieldname] = ((Label)this.FindControl((string)_key)).Text;
                        break;

                    case 2:
                    case 5:
                        string _textboxvalue = ((TextBox)this.FindControl((string)_key)).Text;
                        _model[fieldname] = _textboxvalue;

                        if (_textboxvalue.Trim() == string.Empty)
                        {
                            //如果文本框的内容为空,则要判断是否是日期型的,如是,则设为1900-01-01
                            UD_ModelFields _modelfield = new UD_ModelFieldsBLL(fieldcontrolinfo.FieldID, true).Model;
                            if (_modelfield.DataType == 4)
                            {
                                _model[fieldname] = "1900-01-01";
                            }
                        }
                        break;

                    case 3:
                        _model[fieldname] = ((DropDownList)this.FindControl((string)_key)).SelectedValue;
                        break;

                    case 4:
                        _model[fieldname] = ((RadioButtonList)this.FindControl((string)_key)).SelectedValue;
                        break;

                    case 6:
                        _model[fieldname] = ((MCSSelectControl)this.FindControl((string)_key)).SelectValue;
                        break;

                    case 7:
                        _model[fieldname] = ((MCSTreeControl)this.FindControl((string)_key)).SelectValue;
                        break;
                    }
                }
            }
        }
    protected void bt_Expand_Click(object sender, EventArgs e)
    {
        Rpt_DataSetFields m = new Rpt_DataSetFieldsBLL((Guid)ViewState["ID"]).Model;
        if (m == null || m.TreeLevel != 0) return;

        UD_ModelFields field = new UD_ModelFieldsBLL(m.FieldID).Model;

        if (field == null) return;

        //如果关联表是树形结构,则允许设定树表层次
        if (field.RelationType == 2 && new UD_TableListBLL(field.RelationTableName).Model.TreeFlag == "Y")
        {
            int maxsortid = 0;
            IList<Rpt_DataSetFields> datasetfields = new Rpt_DataSetBLL((Guid)ViewState["DataSet"]).GetFields();
            if (datasetfields.Count > 0) maxsortid = datasetfields.Max(p => p.ColumnSortID);

            Dictionary<string, Dictionary_Data> levels;
            if (field.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
                levels = DictionaryBLL.GetDicCollections("Addr_OrganizeCityLevel");//关联至管理片区
            else if (field.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity")
                levels = DictionaryBLL.GetDicCollections("Addr_OfficialCityLevel");  //关联至行政城市
            else
                return;

            foreach (string level in levels.Keys)
            {
                string fieldname = m.FieldName + level;
                if (datasetfields.FirstOrDefault(p => p.FieldName == fieldname) == null)
                {
                    maxsortid++;

                    Rpt_DataSetFieldsBLL fieldbll = new Rpt_DataSetFieldsBLL();
                    fieldbll.Model.DataSet = (Guid)ViewState["DataSet"];
                    fieldbll.Model.FieldID = field.ID;
                    fieldbll.Model.FieldName = fieldname;
                    fieldbll.Model.DisplayName = levels[level].Name;
                    fieldbll.Model.DataType = 3;                                  //固定为字符串型
                    fieldbll.Model.IsComputeField = "N";
                    fieldbll.Model.ColumnSortID = maxsortid;
                    fieldbll.Model.DisplayMode = 2;
                    fieldbll.Model.TreeLevel = int.Parse(level);
                    fieldbll.Model.Description = field.Description;
                    fieldbll.Add();
                }
            }
            MessageBox.ShowAndRedirect(this, "展开级别成功!", "Rpt_DataSetFieldsList.aspx?ID=" + ViewState["DataSet"].ToString());
        }
    }
    private void BindDropDown()
    {
        if (ViewState["TableName"] != null)
        {
            IList <UD_TableList> tablelist = UD_TableListBLL.GetModelList("Name='" + ViewState["TableName"].ToString() + "'");

            if (tablelist.Count > 0)
            {
                ViewState["TableID"] = tablelist[0].ID;
                IList <UD_ModelFields> fieldlist = UD_ModelFieldsBLL.GetModelList("Tableid='" + tablelist[0].ID + "'");
                ddl_FieldName.DataSource     = fieldlist;
                ddl_FieldName.DataTextField  = "DisplayName";
                ddl_FieldName.DataValueField = "ID";
                ddl_FieldName.DataBind();
                ddl_FieldName.Items.Insert(0, new ListItem("所有", "0"));
            }
        }
    }
    private void BindData()
    {
        Guid _id = (Guid)ViewState["ID"];
        UD_ModelFieldsBLL _modelfieldsbll = new UD_ModelFieldsBLL(_id);

        lbl_ID.Text                = _modelfieldsbll.Model.ID.ToString();
        tbx_FieldName.Text         = _modelfieldsbll.Model.FieldName;
        tbx_DisplayName.Text       = _modelfieldsbll.Model.DisplayName;
        ddl_DataType.SelectedValue = _modelfieldsbll.Model.DataType.ToString();
        tbx_Length.Text            = _modelfieldsbll.Model.DataLength.ToString();
        if (_modelfieldsbll.Model.Precision != 0)
        {
            tbx_Precision.Text = _modelfieldsbll.Model.Precision.ToString();
        }
        tbx_DefaultValue.Text   = _modelfieldsbll.Model.DefaultValue;
        tbx_Description.Text    = _modelfieldsbll.Model.Description;
        lbl_LastUpdateTime.Text = _modelfieldsbll.Model.LastUpdateTime.ToString();
        if (_modelfieldsbll.Model.RelationType > 0)
        {
            rbl_RelationType.SelectedValue = _modelfieldsbll.Model.RelationType.ToString();
        }
        rbl_RelationType_SelectedIndexChanged(null, null);
        tbx_SearchPageURL.Text = _modelfieldsbll.Model.SearchPageURL;

        if (ddl_RelationTableName != null || ddl_RelationTableName.Items.Count != 0)
        {
            ddl_RelationTableName.SelectedValue = _modelfieldsbll.Model.RelationTableName;
            {
                ddl_RelationTableName_SelectedIndexChanged(null, null);
            }
        }
        if (ddl_RelationTextField != null || ddl_RelationTextField.Items.Count != 0)
        {
            ddl_RelationTextField.SelectedValue = _modelfieldsbll.Model.RelationTextField;
        }
        if (ddl_RelationValueField != null || ddl_RelationValueField.Items.Count != 0)
        {
            ddl_RelationValueField.SelectedValue = _modelfieldsbll.Model.RelationValueField;
        }

        tbx_FieldName.Enabled = false;
        bt_OK.Text            = "修改";
        bt_OK.ForeColor       = System.Drawing.Color.Red;
    }
    protected void bt_AddToDataSet_Click(object sender, EventArgs e)
    {
        IList<Rpt_DataSetFields> datasetfields = new Rpt_DataSetBLL((Guid)ViewState["ID"]).GetFields();
        int maxsortid = 0;
        if (datasetfields.Count > 0) maxsortid = datasetfields.Max(p => p.ColumnSortID);

        foreach (ListItem item in cbxl_Fields.Items)
        {
            if (item.Selected)
            {
                Guid fieldid = new Guid(item.Value);

                UD_ModelFields f = new UD_ModelFieldsBLL(fieldid).Model;
                if (f != null)
                {
                    string fieldname = new UD_TableListBLL(f.TableID).Model.ModelClassName + "_" + f.FieldName;
                    if (datasetfields.FirstOrDefault(p => p.FieldName == fieldname) != null) continue;

                    maxsortid++;

                    Rpt_DataSetFieldsBLL fieldbll = new Rpt_DataSetFieldsBLL();
                    fieldbll.Model.DataSet = (Guid)ViewState["ID"];
                    fieldbll.Model.FieldID = f.ID;
                    fieldbll.Model.FieldName = fieldname;
                    fieldbll.Model.DisplayName = f.DisplayName;
                    fieldbll.Model.DataType = f.DataType;
                    fieldbll.Model.IsComputeField = "N";
                    fieldbll.Model.ColumnSortID = maxsortid;

                    if (f.RelationType == 1 || f.RelationType == 2)
                        fieldbll.Model.DisplayMode = 2;
                    else
                        fieldbll.Model.DisplayMode = 1;

                    fieldbll.Model.Description = f.Description;
                    fieldbll.Add();
                }
            }
        }

        BindGrid();
        new Rpt_DataSetBLL((Guid)ViewState["ID"]).ClearCache();
    }
Exemplo n.º 14
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();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString["TableID"] != null)
            {
                ViewState["TableID"] = new Guid(Request.QueryString["TableID"]);
            }

            if (ViewState["TableID"] == null)
            {
                Response.Redirect("TableList.aspx");
            }
            else
            {
                lbl_TableName.Text = new UD_TableListBLL((Guid)ViewState["TableID"]).Model.Name;
                string CacheKey = "UD_TableList-ModelFields-" + ViewState["TableID"].ToString();
                DataCache.RemoveCache(CacheKey);
                UD_ModelFieldsBLL.Init((Guid)ViewState["TableID"]);
                BindGrid();
            }
        }
    }
    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
        }
    }
Exemplo n.º 17
0
        private string GenarateSelectSQL(out Dictionary <string, Rpt_DataSetFields> dicTreeColumnList)
        {
            string _sqlstring     = "";
            string _selectstr     = "SELECT ";
            string _fromstr       = "";
            string _selectfromstr = "";           //字段如果是关联时,临时生成的from sql

            dicTreeColumnList = new Dictionary <string, Rpt_DataSetFields>();

            if (_m.CommandType != 3)
            {
                return("");
            }

            #region create the select string
            IList <Rpt_DataSetFields> _fields = this.GetFields();

            foreach (Rpt_DataSetFields _field in _fields)
            {
                if (_field.IsComputeField == "Y")
                {
                    _selectstr += _field.Expression + " AS " + _field.FieldName + ",";
                }
                else
                {
                    UD_ModelFields _modelfield = new UD_ModelFieldsBLL(_field.FieldID, true).Model;
                    UD_TableList   _tablemodel = new UD_TableListBLL(_modelfield.TableID, true).Model;

                    string _fieldfullname = _tablemodel.ModelClassName + "_" + _modelfield.FieldName;

                    #region 判断字段关联类型,决定如果创建SQL
                    switch (_modelfield.RelationType)
                    {
                    case 1:                          //Relation to dic
                        if (_field.DisplayMode == 1) //Bound the id value of the field
                        {
                            if (_modelfield.Flag == "Y")
                            {
                                _selectstr += _tablemodel.Name + "." + _modelfield.FieldName + " AS " + _fieldfullname + ",";
                            }
                            else    //扩展字段
                            {
                                _selectstr += "MCS_SYS.[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," +
                                              _modelfield.Position.ToString() + ") AS " + _fieldfullname + ",";
                            }
                        }
                        else    //Bound the text value of the field
                        {
                            //计算出关联字典表的别名"_vname"
                            string _vname = "V_Dictionary_Data" + "_" + _modelfield.FieldName;
                            if (_modelfield.Flag == "Y")
                            {
                                _selectstr     += _vname + ".Name" + " AS " + _fieldfullname + ",";
                                _selectfromstr += " left join V_Dictionary_Data AS " + _vname + " ON " + _tablemodel.Name + "." + _modelfield.FieldName + "=" + _vname + ".Code AND " + _vname + ".TableName='" + _modelfield.RelationTableName + "' ";
                            }
                            else    //扩展字段
                            {
                                _selectstr     += _vname + ".Name" + " AS " + _fieldfullname + ",";
                                _selectfromstr += " left join V_Dictionary_Data AS " + _vname + " ON MCS_SYS.[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") =" + _vname + ".Code AND " + _vname + ".TableName='" + _modelfield.RelationTableName + "' ";
                            }
                        }
                        break;

                    case 2:    //Relation to model table
                        if (_field.TreeLevel > 0 && new UD_TableListBLL(_modelfield.RelationTableName).Model.TreeFlag == "Y")
                        {
                            #region 字段关联到树形结构表,且要显示上层父结点信息
                            _fieldfullname += _field.TreeLevel.ToString();

                            if (_modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
                            {
                                string tmpfieldname = "";
                                if (_modelfield.Flag == "Y")
                                {
                                    tmpfieldname = _tablemodel.Name + "." + _modelfield.FieldName;
                                }
                                else    //扩展字段
                                {
                                    tmpfieldname = "[MCS_SYS].[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ")";
                                }

                                if (_field.DisplayMode == 1)
                                {
                                    _selectstr += "[MCS_SYS].[dbo].[UF_GetSuperOrganizeCityByLevel02](" + tmpfieldname + "," + _field.TreeLevel.ToString() + ")" + " AS " + _fieldfullname + ",";
                                }
                                else
                                {
                                    _selectstr += "[MCS_SYS].[dbo].[UF_GetSuperOrganizeCityNameByLevel02](" + tmpfieldname + "," + _field.TreeLevel.ToString() + ")" + " AS " + _fieldfullname + ",";
                                }
                            }
                            else if (_modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
                            {
                                string tmpfieldname = "";
                                if (_modelfield.Flag == "Y")
                                {
                                    tmpfieldname = _tablemodel.Name + "." + _modelfield.FieldName;
                                }
                                else    //扩展字段
                                {
                                    tmpfieldname = "[MCS_SYS].[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ")";
                                }

                                if (_field.DisplayMode == 1)
                                {
                                    _selectstr += "[MCS_SYS].[dbo].[UF_GetSuperOfficialCityByLevel02](" + tmpfieldname + "," + _field.TreeLevel.ToString() + ")" + " AS " + _fieldfullname + ",";
                                }
                                else
                                {
                                    _selectstr += "[MCS_SYS].[dbo].[UF_GetSuperOfficialCityNameByLevel02](" + tmpfieldname + "," + _field.TreeLevel.ToString() + ")" + " AS " + _fieldfullname + ",";
                                }
                            }
                            else
                            {
                                if (_modelfield.Flag == "Y")
                                {
                                    _selectstr += _tablemodel.Name + "." + _modelfield.FieldName + " AS " + _fieldfullname + ",";
                                }
                                else    //扩展字段
                                {
                                    _selectstr += "MCS_SYS.[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") AS " + _fieldfullname + ",";
                                }

                                dicTreeColumnList.Add(_fieldfullname, _field);
                            }
                            #endregion
                        }
                        else
                        {
                            #region  需关联到树形结构表
                            if (_field.DisplayMode == 1)    //Bound the id value of the field
                            {
                                if (_modelfield.Flag == "Y")
                                {
                                    _selectstr += _tablemodel.Name + "." + _modelfield.FieldName + " AS " + _fieldfullname + ",";
                                }
                                else    //扩展字段
                                {
                                    _selectstr += "MCS_SYS.[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") AS " + _fieldfullname + ",";
                                }
                            }
                            else    //Bound the text value of the field
                            {
                                #region 计算出关联表的别名"_vname"
                                string _vname = "";
                                int    pos    = _modelfield.RelationTableName.LastIndexOf('.');
                                if (pos >= 0)
                                {
                                    _vname = _modelfield.RelationTableName.Substring(pos + 1) + "_" + _modelfield.FieldName;
                                }
                                else
                                {
                                    _vname = _modelfield.RelationTableName + "_" + _modelfield.FieldName;
                                }
                                #endregion

                                if (_modelfield.Flag == "Y")
                                {
                                    _selectstr     += _vname + "." + _modelfield.RelationTextField + " AS " + _fieldfullname + ",";
                                    _selectfromstr += " left join " + _modelfield.RelationTableName + " AS " + _vname + " ON " + _tablemodel.Name + "." + _modelfield.FieldName + "=" + _vname + "." + _modelfield.RelationValueField;
                                }
                                else    //扩展字段
                                {
                                    _selectstr     += _vname + "." + _modelfield.RelationTextField + " AS " + _fieldfullname + ",";
                                    _selectfromstr += " left join " + _modelfield.RelationTableName + " AS " + _vname + " ON MCS_SYS.[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") =" + _vname + "." + _modelfield.RelationValueField;
                                }
                            }
                            #endregion
                        }

                        break;

                    default:    //No relation
                        if (_modelfield.Flag == "Y")
                        {
                            _selectstr += _tablemodel.Name + "." + _modelfield.FieldName + " AS " + _fieldfullname + ",";
                        }
                        else
                        {
                            _selectstr += "MCS_SYS.[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") AS " + _fieldfullname + ",";
                        }
                        break;
                    }
                    #endregion
                }
            }
            _selectstr = _selectstr.Substring(0, _selectstr.Length - 1);


            #endregion

            #region create the from string of sql
            IList <Rpt_DataSetTableRelations> _tablerelations = this.GetTableRelations();
            IList <Rpt_DataSetTables>         _tables         = this.GetTables();
            if (_tables.Count == 1 || _tablerelations.Count == 0)
            {
                _fromstr = " FROM " + new UD_TableListBLL(_tables[0].TableID, true).Model.Name;
            }
            else
            {
                foreach (Rpt_DataSetTableRelations _tablerelation in _tablerelations)
                {
                    string _parenttablename = new UD_TableListBLL(_tablerelation.ParentTableID, true).Model.Name;
                    string _childtablename  = new UD_TableListBLL(_tablerelation.ChildTableID, true).Model.Name;

                    UD_ModelFields _parentfield = new UD_ModelFieldsBLL(_tablerelation.ParentFieldID, true).Model;
                    UD_ModelFields _childfield  = new UD_ModelFieldsBLL(_tablerelation.ChildFieldID, true).Model;

                    if (_tablerelation.JoinMode == "")
                    {
                        _tablerelation.JoinMode = "LEFT JOIN";
                    }

                    if (_fromstr == "")
                    {
                        _fromstr = " FROM " + _parenttablename + " ";
                    }

                    _fromstr += " " + _tablerelation.JoinMode + " " + _childtablename + " ON ";

                    if (_parentfield.Flag == "Y" && _childfield.Flag == "Y")
                    {
                        _fromstr += _parenttablename + ".[" + _parentfield.FieldName + "] = " + _childtablename + ".[" + _childfield.FieldName + "] ";
                    }
                    else
                    {
                        //关联字段中,有一个字段为扩展字段
                        if (_parentfield.Flag == "Y")
                        {
                            _fromstr += "CONVERT(VarChar," + _parenttablename + "." + _parentfield.FieldName + ")";
                        }
                        else
                        {
                            _fromstr += "MCS_SYS.[dbo].[UF_Spilt](" + _parenttablename + ".ExtPropertys,'|'," + _parentfield.Position.ToString() + ")";
                        }

                        _fromstr += " = ";

                        if (_childfield.Flag == "Y")
                        {
                            _fromstr += "CONVERT(VarChar," + _childtablename + "." + _childfield.FieldName + ")";
                        }
                        else
                        {
                            _fromstr += "MCS_SYS.[dbo].[UF_Spilt](" + _childtablename + ".ExtPropertys,'|'," + _childfield.Position.ToString() + ")";
                        }
                    }

                    if (_tablerelation.RelationCondition != "")
                    {
                        _fromstr += " AND " + _tablerelation.RelationCondition + " ";
                    }
                }
            }

            if (_selectfromstr != "")
            {
                _fromstr += _selectfromstr;
            }

            _sqlstring = _selectstr + _fromstr;
            #endregion

            if (_m.ConditionSQL != "")
            {
                _sqlstring += " WHERE " + _m.ConditionSQL;
            }

            if (_m.OrderString != "")
            {
                _sqlstring += " ORDER BY " + _m.OrderString;
            }

            return(_sqlstring);
        }
    protected void bt_Expand_Click(object sender, EventArgs e)
    {
        Rpt_DataSetFields m = new Rpt_DataSetFieldsBLL((Guid)ViewState["ID"]).Model;

        if (m == null || m.TreeLevel != 0)
        {
            return;
        }

        UD_ModelFields field = new UD_ModelFieldsBLL(m.FieldID).Model;

        if (field == null)
        {
            return;
        }

        //如果关联表是树形结构,则允许设定树表层次
        if (field.RelationType == 2 && new UD_TableListBLL(field.RelationTableName).Model.TreeFlag == "Y")
        {
            int maxsortid = 0;
            IList <Rpt_DataSetFields> datasetfields = new Rpt_DataSetBLL((Guid)ViewState["DataSet"]).GetFields();
            if (datasetfields.Count > 0)
            {
                maxsortid = datasetfields.Max(p => p.ColumnSortID);
            }

            Dictionary <string, Dictionary_Data> levels;
            if (field.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
            {
                levels = DictionaryBLL.GetDicCollections("Addr_OrganizeCityLevel");//关联至管理片区
            }
            else if (field.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity")
            {
                levels = DictionaryBLL.GetDicCollections("Addr_OfficialCityLevel");  //关联至行政城市
            }
            else
            {
                return;
            }

            foreach (string level in levels.Keys)
            {
                string fieldname = m.FieldName + level;
                if (datasetfields.FirstOrDefault(p => p.FieldName == fieldname) == null)
                {
                    maxsortid++;

                    Rpt_DataSetFieldsBLL fieldbll = new Rpt_DataSetFieldsBLL();
                    fieldbll.Model.DataSet        = (Guid)ViewState["DataSet"];
                    fieldbll.Model.FieldID        = field.ID;
                    fieldbll.Model.FieldName      = fieldname;
                    fieldbll.Model.DisplayName    = levels[level].Name;
                    fieldbll.Model.DataType       = 3;                            //固定为字符串型
                    fieldbll.Model.IsComputeField = "N";
                    fieldbll.Model.ColumnSortID   = maxsortid;
                    fieldbll.Model.DisplayMode    = 2;
                    fieldbll.Model.TreeLevel      = int.Parse(level);
                    fieldbll.Model.Description    = field.Description;
                    fieldbll.Add();
                }
            }
            MessageBox.ShowAndRedirect(this, "展开级别成功!", "Rpt_DataSetFieldsList.aspx?ID=" + ViewState["DataSet"].ToString());
        }
    }
    private void BindData()
    {
        Rpt_DataSetFieldsBLL _bll = new Rpt_DataSetFieldsBLL((Guid)ViewState["ID"]);

        ViewState["DataSet"] = _bll.Model.DataSet;

        ddl_IsComputeField.SelectedValue = _bll.Model.IsComputeField;
        ddl_IsComputeField_SelectedIndexChanged(null, null);
        tbx_Expression.Text = _bll.Model.Expression;

        if (_bll.Model.FieldID != Guid.Empty)
        {
            #region 设置关联字段界面控件属性
            UD_ModelFields field = new UD_ModelFieldsBLL(_bll.Model.FieldID).Model;
            if (field == null)
            {
                return;
            }

            if (field.RelationType == 1 || field.RelationType == 2)
            {
                ddl_DisplayMode.Enabled = true;

                //如果关联表是树形结构,则允许设定树表层次
                if (field.RelationType == 2 && new UD_TableListBLL(field.RelationTableName).Model.TreeFlag == "Y")
                {
                    tbx_TreeLevel.Enabled = true;
                    if (_bll.Model.TreeLevel == 0 && (field.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity" ||
                                                      field.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity"))
                    {
                        bt_Expand.Visible = true;  //如果字段关联于管理片区或行政城市,显示"展开层级"按钮
                    }
                }
                else
                {
                    tbx_TreeLevel.Text    = "";
                    tbx_TreeLevel.Enabled = false;
                }
            }
            else
            {
                ddl_DisplayMode.Enabled       = false;
                ddl_DisplayMode.SelectedValue = "1";
                tbx_TreeLevel.Text            = "";
                tbx_TreeLevel.Enabled         = false;
            }
            #endregion
        }

        tbx_FieldName.Text         = _bll.Model.FieldName;
        tbx_DisplayName.Text       = _bll.Model.DisplayName;
        ddl_DataType.SelectedValue = _bll.Model.DataType.ToString();
        tbx_Description.Text       = _bll.Model.Description;

        tbx_SortID.Text               = _bll.Model.ColumnSortID.ToString();
        tbx_TreeLevel.Text            = _bll.Model.TreeLevel.ToString();
        ddl_DisplayMode.SelectedValue = _bll.Model.DisplayMode.ToString();

        tbx_FieldName.Enabled      = false;
        ddl_IsComputeField.Enabled = false;


        bt_OK.Text      = "修 改";
        bt_OK.ForeColor = System.Drawing.Color.Red;

        if ((int)ViewState["DataSet_CommandType"] == 1 || (int)ViewState["DataSet_CommandType"] == 2)
        {
            tbx_FieldName.Visible = true;

            ddl_DisplayMode.Enabled = false;
            tbx_TreeLevel.Enabled   = false;

            if (_bll.Model.IsComputeField != "Y")
            {
                bt_Delete.Visible = false;
            }
        }
    }
    protected void ddl_Field_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddl_op.Items.Clear();
        ddl_op.Visible = false;
        ddl_TreeLevel.Visible = false;

        #region 操作符选择
        UD_ModelFields modelfield = new UD_ModelFieldsBLL(new Guid(ddl_Field.SelectedValue), true).Model;
        if (modelfield == null)
        {
            btn_addsearch.Enabled = false;
            return;
        }
        btn_addsearch.Enabled = true;

        switch (modelfield.RelationType)
        {
            case 1:
                //字典关联
                break;
            case 2:
                //实体表关联
                #region 如果是管理片区或行政城市,可以选择指定的树形级别
                if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
                {
                    ddl_TreeLevel.DataSource = DictionaryBLL.GetDicCollections("Addr_OrganizeCityLevel");
                    ddl_TreeLevel.DataBind();
                    ddl_TreeLevel.Items.Insert(0, new ListItem("当前级别", "0"));
                    ddl_TreeLevel.Items.Insert(1, new ListItem("所属于", "100"));
                    ddl_TreeLevel.Visible = true;
                }
                else if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity")
                {
                    ddl_TreeLevel.DataSource = DictionaryBLL.GetDicCollections("Addr_OfficialCityLevel");
                    ddl_TreeLevel.DataBind();
                    ddl_TreeLevel.Items.Insert(0, new ListItem("当前级别", "0"));
                    ddl_TreeLevel.Items.Insert(1, new ListItem("所属于", "100"));
                    ddl_TreeLevel.Visible = true;
                }
                #endregion
                break;
            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"));
                        break;
                    case 4:     //日期(datetime)
                        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.Visible = true;

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

        rbl_ValueFrom_SelectedIndexChanged(null, null);
    }
Exemplo n.º 21
0
        /// <summary>
        /// Init the components of the panel through the special pageid
        /// </summary>
        private void InitComponents()
        {
            HtmlTable T_Content = new HtmlTable();
            T_Content.CellPadding = 0;
            T_Content.CellSpacing = 0;
            T_Content.Width = "100%";
            T_Content.Border = 0;
            T_Content.ID = "T_Content_" + ID;
            this.Controls.Add(T_Content);

            UD_DetailViewBLL _DetailViewBll = new UD_DetailViewBLL(DetailViewCode, true);

            IList<UD_Panel> _panellist = _DetailViewBll.GetDetailPanels();
            Hashtable _htFieldControlsInfo = new Hashtable();

            foreach (UD_Panel _panelmodel in _panellist)
            {
                HtmlTableRow tr_panel = new HtmlTableRow();//Create one TableRow for a panel
                tr_panel.ID = _panelmodel.Code;
                if (_panelmodel.Enable.ToUpper() == "N")
                    tr_panel.Visible = false;
                HtmlTableCell tc_panel = new HtmlTableCell();
                string _tablestytle = _panelmodel.TableStyle;
                string[] _tablestyles = _panelmodel.TableStyle.Split(new char[] { ',' });

                if (_tablestyles.Length < 3)
                    _tablestyles = ("tabForm,dataLabel,dataField").Split(new char[] { ',' });

                #region The title of the panel
                if (_panelmodel.Name != "")
                {
                    HtmlTable tb_panel_title = new HtmlTable();
                    tb_panel_title.CellPadding = 0;
                    tb_panel_title.CellSpacing = 0;
                    tb_panel_title.Width = "100%";
                    tb_panel_title.Height = "28px";
                    tb_panel_title.Border = 0;
                    tb_panel_title.Attributes["class"] = "h3Row";
                    HtmlTableRow tr_panel_title = new HtmlTableRow();
                    HtmlTableCell tc_panel_title = new HtmlTableCell();
                    tc_panel_title.InnerHtml = "<h3>" + _panelmodel.Name + "</h3>";
                    tr_panel_title.Cells.Add(tc_panel_title);
                    tb_panel_title.Rows.Add(tr_panel_title);
                    tc_panel.Controls.Add(tb_panel_title);
                }
                #endregion

                #region The content of the panel
                IList<UD_Panel_ModelFields> fields = new UD_PanelBLL(_panelmodel.ID, true).GetModelFields();

                int FieldCount = _panelmodel.FieldCount;

                HtmlTable tb_panel_content = new HtmlTable();
                tb_panel_content.Width = "100%";
                tb_panel_content.Attributes["class"] = _tablestyles[0];
                int i = 0;
                foreach (UD_Panel_ModelFields _panel_modelfields in fields)
                {
                    if (_panel_modelfields.Visible == "N") continue;

                    UD_ModelFields _modelfieldsmodel = new UD_ModelFieldsBLL(_panel_modelfields.FieldID, true).Model;
                    UD_TableList _tablemodel = new UD_TableListBLL(_modelfieldsmodel.TableID, true).Model;

                    #region 判断该控件是否已存在
                    if (_htFieldControlsInfo.Contains(_tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName)) continue;
                    #endregion

                    #region 判断是否要增加新行
                    HtmlTableRow tr_panel_detail;
                    if (i >= FieldCount || i == 0)
                    {
                        tr_panel_detail = new HtmlTableRow();
                        tb_panel_content.Rows.Add(tr_panel_detail);
                        i = 0;
                    }
                    else
                    {
                        tr_panel_detail = tb_panel_content.Rows[tb_panel_content.Rows.Count - 1];
                    }
                    #endregion

                    #region 增加Label Cell
                    HtmlTableCell tc_displayname = new HtmlTableCell();
                    tc_displayname.Attributes["Class"] = _tablestyles[1];
                    tc_displayname.InnerText = string.IsNullOrEmpty(_panel_modelfields.LabelText) ?
                        _modelfieldsmodel.DisplayName : _panel_modelfields.LabelText;
                    if (tc_displayname.InnerText.Length <= 6)
                        tc_displayname.Attributes["Style"] = "width: 80px; height: 18px;";
                    else
                        tc_displayname.Attributes["Style"] = "width: 100px; height: 18px;";
                    tc_displayname.Attributes["nowrap"] = "nowrap";
                    tr_panel_detail.Cells.Add(tc_displayname);
                    #endregion

                    #region 增加Field Cell
                    HtmlTableCell tc_control = new HtmlTableCell();
                    tc_control.Attributes["Class"] = _tablestyles[2];
                    if (_panel_modelfields.ColSpan > 0)
                    {
                        if (i + _panel_modelfields.ColSpan <= FieldCount)
                        {
                            tc_control.ColSpan = 2 * _panel_modelfields.ColSpan - 1;
                            i = i + _panel_modelfields.ColSpan;
                        }
                        else
                        {
                            tc_control.ColSpan = 2 * (FieldCount - i) - 1;
                            i = 0;
                        }

                    }
                    else
                    {
                        i++;
                    }

                    WebControl control = null;

                    int RelationType = _modelfieldsmodel.RelationType;
                    string RelationTableName = _modelfieldsmodel.RelationTableName;
                    string RelationValueField = _modelfieldsmodel.RelationValueField;
                    string RelationTextField = _modelfieldsmodel.RelationTextField;

                    #region 根据控件类型生成相应的控件
                    switch (_panel_modelfields.ControlType)
                    {
                        case 1://Label
                            control = new Label();
                            break;
                        case 2://TextBox
                            control = new TextBox();
                            if (_modelfieldsmodel.DataType == 4)
                            {
                                control.Attributes["onfocus"] = "WdatePicker();";
                            }
                            break;
                        case 3://DropDownList
                            control = new DropDownList();
                            if (RelationType == 1)//Relation to the dictionary
                            {
                                ((DropDownList)control).DataSource = DictionaryBLL.GetDicCollections(RelationTableName, true);
                            }
                            else if (RelationType == 2)//Relation to the model table
                            {
                                ((DropDownList)control).DataSource = TreeTableBLL.GetRelationTableSourceData(RelationTableName, RelationValueField, RelationTextField);
                            }
                            else
                                break;

                            ((DropDownList)control).DataTextField = "Value";
                            ((DropDownList)control).DataValueField = "Key";
                            ((DropDownList)control).DataBind();
                            if (_modelfieldsmodel.DataType != 5)
                                ((DropDownList)control).Items.Insert(0, new ListItem("请选择...", "0"));
                            else
                                ((DropDownList)control).Items.Insert(0, new ListItem("请选择...", Guid.Empty.ToString()));
                            break;
                        case 4://RadioButtonList
                            control = new RadioButtonList();
                            if (RelationType == 1)//Relation to the dictionary
                            {
                                ((RadioButtonList)control).DataSource = DictionaryBLL.GetDicCollections(RelationTableName, true);
                            }
                            else if (RelationType == 2)//Relation to the model table
                            {
                                ((RadioButtonList)control).DataSource = TreeTableBLL.GetRelationTableSourceData(RelationTableName, RelationValueField, RelationTextField);
                            }
                            else
                                break;

                            ((RadioButtonList)control).RepeatColumns = 6;
                            ((RadioButtonList)control).RepeatDirection = RepeatDirection.Horizontal;
                            ((RadioButtonList)control).DataTextField = "Value";
                            ((RadioButtonList)control).DataValueField = "Key";
                            ((RadioButtonList)control).DataBind();
                            if (((RadioButtonList)control).Items.Count != 0) ((RadioButtonList)control).SelectedIndex = 0;
                            break;
                        case 5://MutiLinesTextBox
                            control = new TextBox();
                            ((TextBox)control).TextMode = TextBoxMode.MultiLine;
                            if (_panel_modelfields.ControlHeight > 0) ((TextBox)control).Height = new Unit(_panel_modelfields.ControlHeight);
                            break;
                        case 6://TextBox supports search
                            control = new MCSSelectControl();
                            if (RelationType == 2)//Relation to the model table
                            {
                                control.ID = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName;

                                if (_panel_modelfields.SearchPageURL != "")
                                    ((MCSSelectControl)control).PageUrl = _panel_modelfields.SearchPageURL;
                                else if (_modelfieldsmodel.SearchPageURL != "")
                                    ((MCSSelectControl)control).PageUrl = _modelfieldsmodel.SearchPageURL;
                            }
                            break;
                        case 7://MCSTreeControl

                            control = new MCSTreeControl();

                            if (RelationType == 2)//Relation to the model table
                            {
                                control.ID = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName;

                                if (_modelfieldsmodel.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
                                {
                                    #region 如果为管理片区字段,则取所能管辖的片区
                                    if (System.Web.HttpContext.Current.Session["AccountType"] == null ||
                                    (int)System.Web.HttpContext.Current.Session["AccountType"] == 1)
                                    {
                                        //员工
                                        Org_StaffBLL staff = new Org_StaffBLL((int)System.Web.HttpContext.Current.Session["UserID"]);
                                        ((MCSTreeControl)control).DataSource = staff.GetStaffOrganizeCity();
                                        ((MCSTreeControl)control).IDColumnName = "ID";
                                        ((MCSTreeControl)control).NameColumnName = "Name";
                                        ((MCSTreeControl)control).ParentColumnName = "SuperID";

                                        if (((MCSTreeControl)control).DataSource.Select("ID = 1").Length > 0 || staff.Model.OrganizeCity == 0)
                                        {
                                            ((MCSTreeControl)control).RootValue = "0";
                                            if (!Page.IsPostBack) ((MCSTreeControl)control).SelectValue = "0";
                                        }
                                        else
                                        {
                                            ((MCSTreeControl)control).RootValue = new Addr_OrganizeCityBLL(staff.Model.OrganizeCity).Model.SuperID.ToString();
                                            if (!Page.IsPostBack) ((MCSTreeControl)control).SelectValue = staff.Model.OrganizeCity.ToString();
                                        }
                                    }
                                    else if ((int)System.Web.HttpContext.Current.Session["AccountType"] == 2 &&
                                     System.Web.HttpContext.Current.Session["OrganizeCity"] != null)
                                    {
                                        //商业客户

                                        int city = (int)System.Web.HttpContext.Current.Session["OrganizeCity"];
                                        Addr_OrganizeCityBLL citybll = new Addr_OrganizeCityBLL(city);
                                        ((MCSTreeControl)control).DataSource = citybll.GetAllChildNodeIncludeSelf();
                                        ((MCSTreeControl)control).RootValue = citybll.Model.SuperID.ToString();
                                        ((MCSTreeControl)control).IDColumnName = "ID";
                                        ((MCSTreeControl)control).NameColumnName = "Name";
                                        ((MCSTreeControl)control).ParentColumnName = "SuperID";

                                        if (!Page.IsPostBack) ((MCSTreeControl)control).SelectValue = city.ToString();
                                    }
                                    #endregion
                                }
                                else if (_modelfieldsmodel.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity")
                                {
                                    ((MCSTreeControl)control).TableName = "MCS_SYS.dbo.Addr_OfficialCity";
                                    ((MCSTreeControl)control).IDColumnName = "ID";
                                    ((MCSTreeControl)control).NameColumnName = "Name";
                                    ((MCSTreeControl)control).ParentColumnName = "SuperID";
                                    ((MCSTreeControl)control).RootValue = "0";
                                    if (!Page.IsPostBack) ((MCSTreeControl)control).SelectValue = "0";
                                }
                                else
                                {
                                    ((MCSTreeControl)control).TableName = RelationTableName;
                                    ((MCSTreeControl)control).IDColumnName = RelationValueField;
                                    ((MCSTreeControl)control).NameColumnName = RelationTextField;
                                    ((MCSTreeControl)control).ParentColumnName = "SuperID";
                                }
                            }
                            break;
                    }
                    #endregion

                    control.ID = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName;
                    control.Enabled = _panel_modelfields.Enable.ToUpper() == "Y";

                    if (_panel_modelfields.ControlWidth > 0) control.Width = _panel_modelfields.ControlWidth;

                    tc_control.Controls.Add(control);

                    #region 如果是文本框时,加上输入验证控件
                    if (_panel_modelfields.IsRequireField == "Y")
                    {
                        Label lbl_reqinfo = new Label();
                        lbl_reqinfo.Text = "&nbsp;&nbsp;*";
                        lbl_reqinfo.ForeColor = System.Drawing.Color.Red;
                        tc_control.Controls.Add(lbl_reqinfo);
                    }

                    if (_panel_modelfields.ControlType == 2 || _panel_modelfields.ControlType == 5)
                    {
                        if (_panel_modelfields.IsRequireField == "Y")
                        {
                            RequiredFieldValidator _requiredfieldvalidator = new RequiredFieldValidator();
                            _requiredfieldvalidator.ControlToValidate = control.ID;
                            _requiredfieldvalidator.Display = ValidatorDisplay.Dynamic;
                            _requiredfieldvalidator.ErrorMessage = "必填";
                            _requiredfieldvalidator.ForeColor = System.Drawing.Color.Red;
                            _requiredfieldvalidator.ValidationGroup = _validationgroup;

                            tc_control.Controls.Add(_requiredfieldvalidator);
                        }

                        if (_panel_modelfields.RegularExpression != "")
                        {
                            RegularExpressionValidator _regularexpressionvalidator = new RegularExpressionValidator();
                            _regularexpressionvalidator.ControlToValidate = control.ID;
                            _regularexpressionvalidator.ErrorMessage = "数据格式不正确";
                            _regularexpressionvalidator.ForeColor = System.Drawing.Color.Red;
                            _regularexpressionvalidator.ValidationExpression = _panel_modelfields.RegularExpression;
                            _regularexpressionvalidator.ValidationGroup = ValidationGroup;
                            _regularexpressionvalidator.Display = ValidatorDisplay.Dynamic;
                            tc_control.Controls.Add(_regularexpressionvalidator);
                        }
                        else
                        {
                            if (_modelfieldsmodel.DataType == 1 || _modelfieldsmodel.DataType == 2 || _modelfieldsmodel.DataType == 4)        //非varchar 字符串
                            {
                                CompareValidator _comparevalidator = new CompareValidator();
                                _comparevalidator.ControlToValidate = control.ID;
                                _comparevalidator.Operator = ValidationCompareOperator.DataTypeCheck;
                                _comparevalidator.Display = ValidatorDisplay.Dynamic;
                                _comparevalidator.ForeColor = System.Drawing.Color.Red;
                                _comparevalidator.ValidationGroup = _validationgroup;

                                if (_modelfieldsmodel.DataType == 1)//int
                                {
                                    _comparevalidator.Type = ValidationDataType.Integer;
                                    _comparevalidator.ErrorMessage = "应为整数";

                                }
                                if (_modelfieldsmodel.DataType == 2)//decimal
                                {
                                    _comparevalidator.Type = ValidationDataType.Double;
                                    _comparevalidator.ErrorMessage = "应为数字";
                                }
                                if (_modelfieldsmodel.DataType == 4)//datetime
                                {
                                    _comparevalidator.Type = ValidationDataType.Date;
                                    _comparevalidator.ErrorMessage = "日期格式不正确";
                                }
                                tc_control.Controls.Add(_comparevalidator);
                            }
                        }
                    }
                    #endregion

                    if (!string.IsNullOrEmpty(_panel_modelfields.Description))
                    {
                        Label lb = new Label();
                        lb.Text = "  " + _panel_modelfields.Description;
                        tc_control.Controls.Add(lb);
                    }

                    tr_panel_detail.Cells.Add(tc_control);
                    #endregion

                    #region 将控件记录到字段控件HashTable中
                    FieldControlInfo fieldcontrolinfo = new FieldControlInfo();

                    fieldcontrolinfo.FieldID = _modelfieldsmodel.ID;
                    fieldcontrolinfo.FieldName = _modelfieldsmodel.FieldName;
                    fieldcontrolinfo.ModelName = _tablemodel.ModelClassName;
                    fieldcontrolinfo.ControlType = _panel_modelfields.ControlType;
                    fieldcontrolinfo.ControlName = control.ID;
                    fieldcontrolinfo.DisplayMode = _panel_modelfields.DisplayMode;
                    fieldcontrolinfo.Panel_Field_ID = _panel_modelfields.ID;
                    _htFieldControlsInfo.Add(fieldcontrolinfo.ControlName, fieldcontrolinfo);
                    #endregion
                }
                #endregion

                tc_panel.Controls.Add(tb_panel_content);
                tr_panel.Cells.Add(tc_panel);
                T_Content.Rows.Add(tr_panel);
            }
            ViewState["FieldControlsInfo"] = _htFieldControlsInfo;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Bind data to the control from the special model
        /// </summary>
        /// <param name="_model"></param>
        public void BindData(IModel _model)
        {
            if (_model == null || _model["ID"] == string.Empty)
            {
                return;
            }

            foreach (object _key in FieldControlsInfo.Keys)
            {
                FieldControlInfo fieldcontrolinfo = (FieldControlInfo)FieldControlsInfo[_key];
                string fieldname = fieldcontrolinfo.FieldName;

                if (fieldcontrolinfo.ModelName == _model.ModelName)
                {
                    try
                    {
                        UD_Panel_ModelFields _panelfield = new UD_Panel_ModelFieldsBLL(fieldcontrolinfo.Panel_Field_ID, true).Model;
                        UD_ModelFields _modelfield = new UD_ModelFieldsBLL(fieldcontrolinfo.FieldID, true).Model;
                        string _formatstring = _panelfield.FormatString;

                        switch (fieldcontrolinfo.ControlType)
                        {
                            case 1: //Label控件
                                //判断是否显示关联表的文本值
                                if (fieldcontrolinfo.DisplayMode == 1)
                                {
                                    if (_modelfield.DataType == 1)
                                        ((Label)this.FindControl((string)_key)).Text = int.Parse(_model[fieldname]).ToString(_formatstring);
                                    else if (_modelfield.DataType == 2)
                                        ((Label)this.FindControl((string)_key)).Text = decimal.Parse(_model[fieldname]).ToString(_formatstring);
                                    else if (_modelfield.DataType == 4)
                                    {
                                        if (DateTime.Parse(_model[fieldname]) != new DateTime(1900, 1, 1))
                                            ((Label)this.FindControl((string)_key)).Text = DateTime.Parse(_model[fieldname]).ToString(_formatstring);
                                    }
                                    else
                                        ((Label)this.FindControl((string)_key)).Text = _model[fieldname];

                                }
                                else
                                {
                                    if (_panelfield.TreeLevel > 0 && new UD_TableListBLL(_modelfield.RelationTableName).Model.TreeFlag == "Y")
                                    {
                                        #region 字段关联到树形结构表,且要显示上层父结点信息
                                        int value = 0;
                                        if (int.TryParse(_model[fieldname], out value))
                                        {
                                            if (_panelfield.TreeLevel == 100)
                                            {
                                                //显示全路径
                                                ((Label)this.FindControl((string)_key)).Text = TreeTableBLL.GetFullPathName(_modelfield.RelationTableName, value);
                                            }
                                            else
                                            {
                                                //显示父级
                                                ((Label)this.FindControl((string)_key)).Text = TreeTableBLL.GetSuperNameByLevel(_modelfield.RelationTableName, value, _panelfield.TreeLevel);
                                            }
                                        }
                                        #endregion
                                    }
                                    else
                                    {
                                        ((Label)this.FindControl((string)_key)).Text = GetRelateTextByValue(_modelfield, _model[fieldname]);
                                    }
                                }
                                break;
                            case 2: //TextBox
                            case 5: //MultiRowTextBox
                                if (_modelfield.DataType == 1)
                                    ((TextBox)this.FindControl((string)_key)).Text = int.Parse(_model[fieldname]).ToString(_formatstring);
                                else if (_modelfield.DataType == 2)
                                    ((TextBox)this.FindControl((string)_key)).Text = decimal.Parse(_model[fieldname]).ToString(_formatstring);
                                else if (_modelfield.DataType == 4)
                                {
                                    if (DateTime.Parse(_model[fieldname]) != new DateTime(1900, 1, 1))
                                        ((TextBox)this.FindControl((string)_key)).Text = DateTime.Parse(_model[fieldname]).ToString(_formatstring);
                                }
                                else
                                    ((TextBox)this.FindControl((string)_key)).Text = _model[fieldname];
                                break;
                            case 3: //DropDownList
                                if (_model[fieldname] != "") ((DropDownList)this.FindControl((string)_key)).SelectedValue = _model[fieldname];
                                break;
                            case 4: //RadioButtonList
                                if (_model[fieldname] != "") ((RadioButtonList)this.FindControl((string)_key)).SelectedValue = _model[fieldname];
                                break;
                            case 6: //带选择功能的控件
                                if (_model[fieldname] != "")
                                {
                                    ((MCSSelectControl)this.FindControl((string)_key)).SelectValue = _model[fieldname];
                                    ((MCSSelectControl)this.FindControl((string)_key)).SelectText = GetRelateTextByValue(_modelfield, _model[fieldname]);
                                }
                                break;
                            case 7: //树形选择控件
                                if (_model[fieldname] != "") ((MCSTreeControl)this.FindControl((string)_key)).SelectValue = _model[fieldname];
                                break;
                        }
                    }
                    catch { }
                }
            }
        }
    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 = new UD_ModelFieldsBLL(new Guid(ddl_Field.SelectedValue), true).Model;
        if (modelfield == null)
        {
            return;
        }

        //字段全称
        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 (rbl_ValueFrom.SelectedValue == "M")
        {
            #region 从手工设定中取值
            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")
                    {
                        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 = "MCS_SYS.dbo.UF_IsChildOrganizeCity(" + MCSTreeControl1.SelectValue + "," + fieldfullname + ") = 0";
                        }
                        else
                        {
                            //指定级别上级
                            lt.Text  = fielddisplayname + " 的 " + ddl_TreeLevel.SelectedItem.Text + " 为 " + MCSTreeControl1.SelectText;
                            lt.Value = "MCS_SYS.dbo.UF_GetSuperOrganizeCityByLevel02(" + fieldfullname + "," + ddl_TreeLevel.SelectedValue + ") = " + MCSTreeControl1.SelectValue;
                        }
                    }
                    else if (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 = "MCS_SYS.dbo.UF_IsChildOfficialCityCity(" + MCSTreeControl1.SelectValue + "," + fieldfullname + ") = 0";
                        }
                        else
                        {
                            //指定级别上级
                            lt.Text  = fielddisplayname + " 的 " + ddl_TreeLevel.SelectedItem.Text + " 为 " + MCSTreeControl1.SelectText;
                            lt.Value = "MCS_SYS.dbo.UF_GetSuperOfficialCityByLevel02(" + fieldfullname + "," + ddl_TreeLevel.SelectedValue + ") = " + 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 != "like")
                {
                    if (tbx_searchvalue.Text.StartsWith("@"))
                    {
                        lt.Value = fieldfullname + " " + 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
        }
        else
        {
            #region 从参数中取值
            switch (modelfield.RelationType)
            {
            case 1:
                #region 字典关联
                lt.Text  = fielddisplayname + " = " + ddl_Param.SelectedValue;
                lt.Value = fieldfullname + " = " + ddl_Param.SelectedValue;
                #endregion
                break;

            case 2:
                #region 实体表关联
                lt.Text  = fielddisplayname + " 为  ";
                lt.Value = fieldfullname + " =  ";
                if (ddl_TreeLevel.Visible)
                {
                    #region 管理片区及行政城市选项
                    if (ddl_TreeLevel.SelectedValue == "0")
                    {
                        //当前级
                        lt.Text += ddl_Param.SelectedValue;
                        lt.Value = fieldfullname + " = " + ddl_Param.SelectedValue;
                    }
                    else if (ddl_TreeLevel.SelectedValue == "100")
                    {
                        //所属于
                        lt.Text = fielddisplayname + " " + ddl_TreeLevel.SelectedItem.Text + " " + ddl_Param.SelectedValue;

                        if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
                        {
                            lt.Value = "MCS_SYS.dbo.UF_IsChildOrganizeCity(" + ddl_Param.SelectedValue + "," + fieldfullname + ") = 0";
                        }
                        else if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity")
                        {
                            lt.Value = "MCS_SYS.dbo.UF_IsChildOfficialCityCity(" + ddl_Param.SelectedValue + "," + fieldfullname + ") = 0";
                        }
                    }
                    else
                    {
                        lt.Text = fielddisplayname + " 的 " + ddl_TreeLevel.SelectedItem.Text + " 为 " + ddl_Param.SelectedValue;

                        //指定级别上级
                        if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
                        {
                            lt.Value = "MCS_SYS.dbo.UF_GetSuperOrganizeCityByLevel02(" + fieldfullname + "," + ddl_TreeLevel.SelectedValue + ") = " + ddl_Param.SelectedValue;
                        }
                        else if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity")
                        {
                            lt.Value = "MCS_SYS.dbo.UF_GetSuperOfficialCityByLevel02(" + fieldfullname + "," + ddl_TreeLevel.SelectedValue + ") = " + ddl_Param.SelectedValue;
                        }
                    }
                    #endregion
                }
                else
                {
                    lt.Text += ddl_Param.SelectedValue;
                    lt.Value = fieldfullname + " = " + ddl_Param.SelectedValue;
                }
                break;

                #endregion
            default:
                #region 非关联字段
                lt.Text  = fielddisplayname + " " + ddl_op.SelectedItem.Text + " (" + ddl_Param.SelectedValue + ")";
                lt.Value = fieldfullname + " =  ";
                if (ddl_op.SelectedValue != "like")
                {
                    lt.Value = fieldfullname + " " + ddl_op.SelectedItem.Value + ddl_Param.SelectedValue;
                }
                else
                {
                    lt.Value = fieldfullname + " LIKE '%'+" + ddl_Param.SelectedValue + "+'%'";
                }
                break;
                #endregion
            }
            #endregion
        }
        #endregion

        if (!string.IsNullOrEmpty(lt.Text))
        {
            lbx_search.Items.Add(lt);
        }
    }
    protected void ddl_Field_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddl_op.Items.Clear();
        ddl_op.Visible        = false;
        ddl_TreeLevel.Visible = false;

        #region 操作符选择
        UD_ModelFields modelfield = new UD_ModelFieldsBLL(new Guid(ddl_Field.SelectedValue), true).Model;
        if (modelfield == null)
        {
            btn_addsearch.Enabled = false;
            return;
        }
        btn_addsearch.Enabled = true;

        switch (modelfield.RelationType)
        {
        case 1:
            //字典关联
            break;

        case 2:
            //实体表关联
            #region 如果是管理片区或行政城市,可以选择指定的树形级别
            if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
            {
                ddl_TreeLevel.DataSource = DictionaryBLL.GetDicCollections("Addr_OrganizeCityLevel");
                ddl_TreeLevel.DataBind();
                ddl_TreeLevel.Items.Insert(0, new ListItem("当前级别", "0"));
                ddl_TreeLevel.Items.Insert(1, new ListItem("所属于", "100"));
                ddl_TreeLevel.Visible = true;
            }
            else if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity")
            {
                ddl_TreeLevel.DataSource = DictionaryBLL.GetDicCollections("Addr_OfficialCityLevel");
                ddl_TreeLevel.DataBind();
                ddl_TreeLevel.Items.Insert(0, new ListItem("当前级别", "0"));
                ddl_TreeLevel.Items.Insert(1, new ListItem("所属于", "100"));
                ddl_TreeLevel.Visible = true;
            }
            #endregion
            break;

        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"));
                break;

            case 4:             //日期(datetime)
                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.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;
            }
            ddl_op.SelectedIndex = 0;
            ddl_op.Visible       = true;
            #endregion
            break;
        }
        #endregion

        rbl_ValueFrom_SelectedIndexChanged(null, null);
    }
Exemplo n.º 25
0
        /// <summary>
        /// Init the components of the panel through the special pageid
        /// </summary>
        private void InitComponents()
        {
            HtmlTable T_Content = new HtmlTable();

            T_Content.CellPadding = 0;
            T_Content.CellSpacing = 0;
            T_Content.Width       = "100%";
            T_Content.Border      = 0;
            T_Content.ID          = "T_Content_" + ID;
            this.Controls.Add(T_Content);


            UD_DetailViewBLL _DetailViewBll = new UD_DetailViewBLL(DetailViewCode, true);

            IList <UD_Panel> _panellist           = _DetailViewBll.GetDetailPanels();
            Hashtable        _htFieldControlsInfo = new Hashtable();

            foreach (UD_Panel _panelmodel in _panellist)
            {
                HtmlTableRow tr_panel = new HtmlTableRow();//Create one TableRow for a panel
                tr_panel.ID = _panelmodel.Code;
                if (_panelmodel.Enable.ToUpper() == "N")
                {
                    tr_panel.Visible = false;
                }
                HtmlTableCell tc_panel     = new HtmlTableCell();
                string        _tablestytle = _panelmodel.TableStyle;
                string[]      _tablestyles = _panelmodel.TableStyle.Split(new char[] { ',' });

                if (_tablestyles.Length < 3)
                {
                    _tablestyles = ("tabForm,dataLabel,dataField").Split(new char[] { ',' });
                }

                #region The title of the panel
                if (_panelmodel.Name != "")
                {
                    HtmlTable tb_panel_title = new HtmlTable();
                    tb_panel_title.CellPadding         = 0;
                    tb_panel_title.CellSpacing         = 0;
                    tb_panel_title.Width               = "100%";
                    tb_panel_title.Height              = "28px";
                    tb_panel_title.Border              = 0;
                    tb_panel_title.Attributes["class"] = "h3Row";
                    HtmlTableRow  tr_panel_title = new HtmlTableRow();
                    HtmlTableCell tc_panel_title = new HtmlTableCell();
                    tc_panel_title.InnerHtml = "<h3>" + _panelmodel.Name + "</h3>";
                    tr_panel_title.Cells.Add(tc_panel_title);
                    tb_panel_title.Rows.Add(tr_panel_title);
                    tc_panel.Controls.Add(tb_panel_title);
                }
                #endregion

                #region The content of the panel
                IList <UD_Panel_ModelFields> fields = new UD_PanelBLL(_panelmodel.ID, true).GetModelFields();

                int FieldCount = _panelmodel.FieldCount;

                HtmlTable tb_panel_content = new HtmlTable();
                tb_panel_content.Width = "100%";
                tb_panel_content.Attributes["class"] = _tablestyles[0];
                int i = 0;
                foreach (UD_Panel_ModelFields _panel_modelfields in fields)
                {
                    if (_panel_modelfields.Visible == "N")
                    {
                        continue;
                    }

                    UD_ModelFields _modelfieldsmodel = new UD_ModelFieldsBLL(_panel_modelfields.FieldID, true).Model;
                    UD_TableList   _tablemodel       = new UD_TableListBLL(_modelfieldsmodel.TableID, true).Model;

                    #region 判断该控件是否已存在
                    if (_htFieldControlsInfo.Contains(_tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName))
                    {
                        continue;
                    }
                    #endregion

                    #region 判断是否要增加新行
                    HtmlTableRow tr_panel_detail;
                    if (i >= FieldCount || i == 0)
                    {
                        tr_panel_detail = new HtmlTableRow();
                        tb_panel_content.Rows.Add(tr_panel_detail);
                        i = 0;
                    }
                    else
                    {
                        tr_panel_detail = tb_panel_content.Rows[tb_panel_content.Rows.Count - 1];
                    }
                    #endregion

                    #region 增加Label Cell
                    HtmlTableCell tc_displayname = new HtmlTableCell();
                    tc_displayname.Attributes["Class"] = _tablestyles[1];
                    tc_displayname.InnerText           = string.IsNullOrEmpty(_panel_modelfields.LabelText) ?
                                                         _modelfieldsmodel.DisplayName : _panel_modelfields.LabelText;
                    if (tc_displayname.InnerText.Length <= 6)
                    {
                        tc_displayname.Attributes["Style"] = "width: 80px; height: 18px;";
                    }
                    else
                    {
                        tc_displayname.Attributes["Style"] = "width: 100px; height: 18px;";
                    }
                    tc_displayname.Attributes["nowrap"] = "nowrap";
                    tr_panel_detail.Cells.Add(tc_displayname);
                    #endregion

                    #region 增加Field Cell
                    HtmlTableCell tc_control = new HtmlTableCell();
                    tc_control.Attributes["Class"] = _tablestyles[2];
                    if (_panel_modelfields.ColSpan > 0)
                    {
                        if (i + _panel_modelfields.ColSpan <= FieldCount)
                        {
                            tc_control.ColSpan = 2 * _panel_modelfields.ColSpan - 1;
                            i = i + _panel_modelfields.ColSpan;
                        }
                        else
                        {
                            tc_control.ColSpan = 2 * (FieldCount - i) - 1;
                            i = 0;
                        }
                    }
                    else
                    {
                        i++;
                    }

                    WebControl control = null;

                    int    RelationType       = _modelfieldsmodel.RelationType;
                    string RelationTableName  = _modelfieldsmodel.RelationTableName;
                    string RelationValueField = _modelfieldsmodel.RelationValueField;
                    string RelationTextField  = _modelfieldsmodel.RelationTextField;

                    #region 根据控件类型生成相应的控件
                    switch (_panel_modelfields.ControlType)
                    {
                    case 1:    //Label
                        control = new Label();
                        break;

                    case 2:    //TextBox
                        control = new TextBox();
                        if (_modelfieldsmodel.DataType == 4)
                        {
                            control.Attributes["onfocus"] = "WdatePicker();";
                        }
                        break;

                    case 3:                    //DropDownList
                        control = new DropDownList();
                        if (RelationType == 1) //Relation to the dictionary
                        {
                            ((DropDownList)control).DataSource = DictionaryBLL.GetDicCollections(RelationTableName, true);
                        }
                        else if (RelationType == 2)    //Relation to the model table
                        {
                            ((DropDownList)control).DataSource = TreeTableBLL.GetRelationTableSourceData(RelationTableName, RelationValueField, RelationTextField);
                        }
                        else
                        {
                            break;
                        }

                        ((DropDownList)control).DataTextField  = "Value";
                        ((DropDownList)control).DataValueField = "Key";
                        ((DropDownList)control).DataBind();
                        if (_modelfieldsmodel.DataType != 5)
                        {
                            ((DropDownList)control).Items.Insert(0, new ListItem("请选择...", "0"));
                        }
                        else
                        {
                            ((DropDownList)control).Items.Insert(0, new ListItem("请选择...", Guid.Empty.ToString()));
                        }
                        break;

                    case 4:                    //RadioButtonList
                        control = new RadioButtonList();
                        if (RelationType == 1) //Relation to the dictionary
                        {
                            ((RadioButtonList)control).DataSource = DictionaryBLL.GetDicCollections(RelationTableName, true);
                        }
                        else if (RelationType == 2)    //Relation to the model table
                        {
                            ((RadioButtonList)control).DataSource = TreeTableBLL.GetRelationTableSourceData(RelationTableName, RelationValueField, RelationTextField);
                        }
                        else
                        {
                            break;
                        }

                        ((RadioButtonList)control).RepeatColumns   = 6;
                        ((RadioButtonList)control).RepeatDirection = RepeatDirection.Horizontal;
                        ((RadioButtonList)control).DataTextField   = "Value";
                        ((RadioButtonList)control).DataValueField  = "Key";
                        ((RadioButtonList)control).DataBind();
                        if (((RadioButtonList)control).Items.Count != 0)
                        {
                            ((RadioButtonList)control).SelectedIndex = 0;
                        }
                        break;

                    case 5:    //MutiLinesTextBox
                        control = new TextBox();
                        ((TextBox)control).TextMode = TextBoxMode.MultiLine;
                        if (_panel_modelfields.ControlHeight > 0)
                        {
                            ((TextBox)control).Height = new Unit(_panel_modelfields.ControlHeight);
                        }
                        break;

                    case 6:                    //TextBox supports search
                        control = new MCSSelectControl();
                        if (RelationType == 2) //Relation to the model table
                        {
                            control.ID = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName;

                            if (_panel_modelfields.SearchPageURL != "")
                            {
                                ((MCSSelectControl)control).PageUrl = _panel_modelfields.SearchPageURL;
                            }
                            else if (_modelfieldsmodel.SearchPageURL != "")
                            {
                                ((MCSSelectControl)control).PageUrl = _modelfieldsmodel.SearchPageURL;
                            }
                        }
                        break;

                    case 7:    //MCSTreeControl

                        control = new MCSTreeControl();


                        if (RelationType == 2)    //Relation to the model table
                        {
                            control.ID = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName;

                            if (_modelfieldsmodel.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
                            {
                                #region 如果为管理片区字段,则取所能管辖的片区
                                if (System.Web.HttpContext.Current.Session["AccountType"] == null ||
                                    (int)System.Web.HttpContext.Current.Session["AccountType"] == 1)
                                {
                                    //员工
                                    Org_StaffBLL staff = new Org_StaffBLL((int)System.Web.HttpContext.Current.Session["UserID"]);
                                    ((MCSTreeControl)control).DataSource       = staff.GetStaffOrganizeCity();
                                    ((MCSTreeControl)control).IDColumnName     = "ID";
                                    ((MCSTreeControl)control).NameColumnName   = "Name";
                                    ((MCSTreeControl)control).ParentColumnName = "SuperID";

                                    if (((MCSTreeControl)control).DataSource.Select("ID = 1").Length > 0 || staff.Model.OrganizeCity == 0)
                                    {
                                        ((MCSTreeControl)control).RootValue = "0";
                                        if (!Page.IsPostBack)
                                        {
                                            ((MCSTreeControl)control).SelectValue = "0";
                                        }
                                    }
                                    else
                                    {
                                        ((MCSTreeControl)control).RootValue = new Addr_OrganizeCityBLL(staff.Model.OrganizeCity).Model.SuperID.ToString();
                                        if (!Page.IsPostBack)
                                        {
                                            ((MCSTreeControl)control).SelectValue = staff.Model.OrganizeCity.ToString();
                                        }
                                    }
                                }
                                else if ((int)System.Web.HttpContext.Current.Session["AccountType"] == 2 &&
                                         System.Web.HttpContext.Current.Session["OrganizeCity"] != null)
                                {
                                    //商业客户

                                    int city = (int)System.Web.HttpContext.Current.Session["OrganizeCity"];
                                    Addr_OrganizeCityBLL citybll = new Addr_OrganizeCityBLL(city);
                                    ((MCSTreeControl)control).DataSource       = citybll.GetAllChildNodeIncludeSelf();
                                    ((MCSTreeControl)control).RootValue        = citybll.Model.SuperID.ToString();
                                    ((MCSTreeControl)control).IDColumnName     = "ID";
                                    ((MCSTreeControl)control).NameColumnName   = "Name";
                                    ((MCSTreeControl)control).ParentColumnName = "SuperID";

                                    if (!Page.IsPostBack)
                                    {
                                        ((MCSTreeControl)control).SelectValue = city.ToString();
                                    }
                                }
                                #endregion
                            }
                            else if (_modelfieldsmodel.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity")
                            {
                                ((MCSTreeControl)control).TableName        = "MCS_SYS.dbo.Addr_OfficialCity";
                                ((MCSTreeControl)control).IDColumnName     = "ID";
                                ((MCSTreeControl)control).NameColumnName   = "Name";
                                ((MCSTreeControl)control).ParentColumnName = "SuperID";
                                ((MCSTreeControl)control).RootValue        = "0";
                                if (!Page.IsPostBack)
                                {
                                    ((MCSTreeControl)control).SelectValue = "0";
                                }
                            }
                            else
                            {
                                ((MCSTreeControl)control).TableName        = RelationTableName;
                                ((MCSTreeControl)control).IDColumnName     = RelationValueField;
                                ((MCSTreeControl)control).NameColumnName   = RelationTextField;
                                ((MCSTreeControl)control).ParentColumnName = "SuperID";
                            }
                        }
                        break;
                    }
                    #endregion

                    control.ID      = _tablemodel.ModelClassName + "_" + _modelfieldsmodel.FieldName;
                    control.Enabled = _panel_modelfields.Enable.ToUpper() == "Y";

                    if (_panel_modelfields.ControlWidth > 0)
                    {
                        control.Width = _panel_modelfields.ControlWidth;
                    }

                    tc_control.Controls.Add(control);

                    #region 如果是文本框时,加上输入验证控件
                    if (_panel_modelfields.IsRequireField == "Y")
                    {
                        Label lbl_reqinfo = new Label();
                        lbl_reqinfo.Text      = "&nbsp;&nbsp;*";
                        lbl_reqinfo.ForeColor = System.Drawing.Color.Red;
                        tc_control.Controls.Add(lbl_reqinfo);
                    }

                    if (_panel_modelfields.ControlType == 2 || _panel_modelfields.ControlType == 5)
                    {
                        if (_panel_modelfields.IsRequireField == "Y")
                        {
                            RequiredFieldValidator _requiredfieldvalidator = new RequiredFieldValidator();
                            _requiredfieldvalidator.ControlToValidate = control.ID;
                            _requiredfieldvalidator.Display           = ValidatorDisplay.Dynamic;
                            _requiredfieldvalidator.ErrorMessage      = "必填";
                            _requiredfieldvalidator.ForeColor         = System.Drawing.Color.Red;
                            _requiredfieldvalidator.ValidationGroup   = _validationgroup;

                            tc_control.Controls.Add(_requiredfieldvalidator);
                        }

                        if (_panel_modelfields.RegularExpression != "")
                        {
                            RegularExpressionValidator _regularexpressionvalidator = new RegularExpressionValidator();
                            _regularexpressionvalidator.ControlToValidate    = control.ID;
                            _regularexpressionvalidator.ErrorMessage         = "数据格式不正确";
                            _regularexpressionvalidator.ForeColor            = System.Drawing.Color.Red;
                            _regularexpressionvalidator.ValidationExpression = _panel_modelfields.RegularExpression;
                            _regularexpressionvalidator.ValidationGroup      = ValidationGroup;
                            _regularexpressionvalidator.Display = ValidatorDisplay.Dynamic;
                            tc_control.Controls.Add(_regularexpressionvalidator);
                        }
                        else
                        {
                            if (_modelfieldsmodel.DataType == 1 || _modelfieldsmodel.DataType == 2 || _modelfieldsmodel.DataType == 4)        //非varchar 字符串
                            {
                                CompareValidator _comparevalidator = new CompareValidator();
                                _comparevalidator.ControlToValidate = control.ID;
                                _comparevalidator.Operator          = ValidationCompareOperator.DataTypeCheck;
                                _comparevalidator.Display           = ValidatorDisplay.Dynamic;
                                _comparevalidator.ForeColor         = System.Drawing.Color.Red;
                                _comparevalidator.ValidationGroup   = _validationgroup;

                                if (_modelfieldsmodel.DataType == 1)//int
                                {
                                    _comparevalidator.Type         = ValidationDataType.Integer;
                                    _comparevalidator.ErrorMessage = "应为整数";
                                }
                                if (_modelfieldsmodel.DataType == 2)//decimal
                                {
                                    _comparevalidator.Type         = ValidationDataType.Double;
                                    _comparevalidator.ErrorMessage = "应为数字";
                                }
                                if (_modelfieldsmodel.DataType == 4)//datetime
                                {
                                    _comparevalidator.Type         = ValidationDataType.Date;
                                    _comparevalidator.ErrorMessage = "日期格式不正确";
                                }
                                tc_control.Controls.Add(_comparevalidator);
                            }
                        }
                    }
                    #endregion

                    if (!string.IsNullOrEmpty(_panel_modelfields.Description))
                    {
                        Label lb = new Label();
                        lb.Text = "  " + _panel_modelfields.Description;
                        tc_control.Controls.Add(lb);
                    }

                    tr_panel_detail.Cells.Add(tc_control);
                    #endregion

                    #region 将控件记录到字段控件HashTable中
                    FieldControlInfo fieldcontrolinfo = new FieldControlInfo();

                    fieldcontrolinfo.FieldID        = _modelfieldsmodel.ID;
                    fieldcontrolinfo.FieldName      = _modelfieldsmodel.FieldName;
                    fieldcontrolinfo.ModelName      = _tablemodel.ModelClassName;
                    fieldcontrolinfo.ControlType    = _panel_modelfields.ControlType;
                    fieldcontrolinfo.ControlName    = control.ID;
                    fieldcontrolinfo.DisplayMode    = _panel_modelfields.DisplayMode;
                    fieldcontrolinfo.Panel_Field_ID = _panel_modelfields.ID;
                    _htFieldControlsInfo.Add(fieldcontrolinfo.ControlName, fieldcontrolinfo);
                    #endregion
                }
                #endregion

                tc_panel.Controls.Add(tb_panel_content);
                tr_panel.Cells.Add(tc_panel);
                T_Content.Rows.Add(tr_panel);
            }
            ViewState["FieldControlsInfo"] = _htFieldControlsInfo;
        }
Exemplo n.º 26
0
        /// <summary>
        /// Bind data to the control from the special model
        /// </summary>
        /// <param name="_model"></param>
        public void BindData(IModel _model)
        {
            if (_model == null || _model["ID"] == string.Empty)
            {
                return;
            }

            foreach (object _key in FieldControlsInfo.Keys)
            {
                FieldControlInfo fieldcontrolinfo = (FieldControlInfo)FieldControlsInfo[_key];
                string           fieldname        = fieldcontrolinfo.FieldName;

                if (fieldcontrolinfo.ModelName == _model.ModelName)
                {
                    try
                    {
                        UD_Panel_ModelFields _panelfield = new UD_Panel_ModelFieldsBLL(fieldcontrolinfo.Panel_Field_ID, true).Model;
                        UD_ModelFields       _modelfield = new UD_ModelFieldsBLL(fieldcontrolinfo.FieldID, true).Model;
                        string _formatstring             = _panelfield.FormatString;

                        switch (fieldcontrolinfo.ControlType)
                        {
                        case 1:     //Label控件
                            //判断是否显示关联表的文本值
                            if (fieldcontrolinfo.DisplayMode == 1)
                            {
                                if (_modelfield.DataType == 1)
                                {
                                    ((Label)this.FindControl((string)_key)).Text = int.Parse(_model[fieldname]).ToString(_formatstring);
                                }
                                else if (_modelfield.DataType == 2)
                                {
                                    ((Label)this.FindControl((string)_key)).Text = decimal.Parse(_model[fieldname]).ToString(_formatstring);
                                }
                                else if (_modelfield.DataType == 4)
                                {
                                    if (DateTime.Parse(_model[fieldname]) != new DateTime(1900, 1, 1))
                                    {
                                        ((Label)this.FindControl((string)_key)).Text = DateTime.Parse(_model[fieldname]).ToString(_formatstring);
                                    }
                                }
                                else
                                {
                                    ((Label)this.FindControl((string)_key)).Text = _model[fieldname];
                                }
                            }
                            else
                            {
                                if (_panelfield.TreeLevel > 0 && new UD_TableListBLL(_modelfield.RelationTableName).Model.TreeFlag == "Y")
                                {
                                    #region 字段关联到树形结构表,且要显示上层父结点信息
                                    int value = 0;
                                    if (int.TryParse(_model[fieldname], out value))
                                    {
                                        if (_panelfield.TreeLevel == 100)
                                        {
                                            //显示全路径
                                            ((Label)this.FindControl((string)_key)).Text = TreeTableBLL.GetFullPathName(_modelfield.RelationTableName, value);
                                        }
                                        else
                                        {
                                            //显示父级
                                            ((Label)this.FindControl((string)_key)).Text = TreeTableBLL.GetSuperNameByLevel(_modelfield.RelationTableName, value, _panelfield.TreeLevel);
                                        }
                                    }
                                    #endregion
                                }
                                else
                                {
                                    ((Label)this.FindControl((string)_key)).Text = GetRelateTextByValue(_modelfield, _model[fieldname]);
                                }
                            }
                            break;

                        case 2:     //TextBox
                        case 5:     //MultiRowTextBox
                            if (_modelfield.DataType == 1)
                            {
                                ((TextBox)this.FindControl((string)_key)).Text = int.Parse(_model[fieldname]).ToString(_formatstring);
                            }
                            else if (_modelfield.DataType == 2)
                            {
                                ((TextBox)this.FindControl((string)_key)).Text = decimal.Parse(_model[fieldname]).ToString(_formatstring);
                            }
                            else if (_modelfield.DataType == 4)
                            {
                                if (DateTime.Parse(_model[fieldname]) != new DateTime(1900, 1, 1))
                                {
                                    ((TextBox)this.FindControl((string)_key)).Text = DateTime.Parse(_model[fieldname]).ToString(_formatstring);
                                }
                            }
                            else
                            {
                                ((TextBox)this.FindControl((string)_key)).Text = _model[fieldname];
                            }
                            break;

                        case 3:     //DropDownList
                            if (_model[fieldname] != "")
                            {
                                ((DropDownList)this.FindControl((string)_key)).SelectedValue = _model[fieldname];
                            }
                            break;

                        case 4:     //RadioButtonList
                            if (_model[fieldname] != "")
                            {
                                ((RadioButtonList)this.FindControl((string)_key)).SelectedValue = _model[fieldname];
                            }
                            break;

                        case 6:     //带选择功能的控件
                            if (_model[fieldname] != "")
                            {
                                ((MCSSelectControl)this.FindControl((string)_key)).SelectValue = _model[fieldname];
                                ((MCSSelectControl)this.FindControl((string)_key)).SelectText  = GetRelateTextByValue(_modelfield, _model[fieldname]);
                            }
                            break;

                        case 7:     //树形选择控件
                            if (_model[fieldname] != "")
                            {
                                ((MCSTreeControl)this.FindControl((string)_key)).SelectValue = _model[fieldname];
                            }
                            break;
                        }
                    }
                    catch { }
                }
            }
        }
    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);
    }
Exemplo n.º 28
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="UserName">用户名</param>
        /// <param name="EncryptPassword">加密后的登录密码</param>
        /// <param name="DeviceCode">设备识别号</param>
        /// <param name="AuthKey">输出:授权码</param>
        /// <param name="ExtParams">扩展登录参数Json格式,包括AppCode、AppVersion、DeviceModel、DeviceOS、OSVersion、NetworkType
        /// 如:{"AppCode":"YSLRMAPP","AppVersion":43,"DeviceModel":"SM-G7108V","DeviceOS":"Android","OSVersion":"4.3","NetworkType":"ChinaMobile TD-SCDMA"}
        /// </param>
        /// <returns>0:登录成功
        /// -1001:用户名或密码错误,登录失败
        /// -1002:未能获取到对称加密密钥
        /// -1003:设备号未在可登录的列表中登记
        /// -1004:当前用户不允许从该设备号登录
        /// -1005:登录失败
        /// -1009:APP版本过低必须更新
        /// </returns>
        public static int Login(string UserName, string EncryptPassword, string DeviceCode, string ExtParams, out string AuthKey)
        {
            LogWriter.WriteLog("UserLogin.LoginEx2:UserName="******",EncryptPassword="******",DeviceCode=" + DeviceCode + ",ExtParams=" + ExtParams);
            AuthKey = "";

            Hashtable hs = string.IsNullOrEmpty(ExtParams) ? new Hashtable() : JsonConvert.DeserializeObject <Hashtable>(ExtParams);

            #region 判断是否符合最新版本要求
            if (hs["AppCode"] != null)
            {
                int MinAppVersion = 0;
                if (hs["AppCode"].ToString() == "PBMSAPP")
                {
                    MinAppVersion = ConfigHelper.GetConfigInt("MinAppVersion");
                }
                else if (hs["AppCode"].ToString() == "PBMSAPP-iOS")
                {
                    MinAppVersion = ConfigHelper.GetConfigInt("MinAppVersion-iOS");
                }

                if (MinAppVersion > 0 && hs["AppVersion"] != null)
                {
                    int AppVersion = 0;
                    if (int.TryParse(hs["AppVersion"].ToString(), out AppVersion) && AppVersion < MinAppVersion)
                    {
                        LogWriter.WriteLog("UserLogin.LoginEx2: AppVersion too lower! UserName="******",DeviceCode=" + DeviceCode + ",AppVersion=" + AppVersion.ToString());
                        return(-1009);       //APP版本过低必须更新
                    }
                }
            }

            #endregion

            #region 组织登录扩展属性
            string ExtPropertys = "";
            try
            {
                IList <UD_TableList> tables = UD_TableListBLL.GetModelList("Name='MCS_SYS.dbo.User_Online'");
                if (tables.Count > 0)
                {
                    IList <UD_ModelFields> models = UD_ModelFieldsBLL.GetModelList("Tableid='" + tables[0].ID.ToString() + "' AND Flag='N'");
                    foreach (UD_ModelFields item in models.OrderBy(p => p.Position))
                    {
                        if (hs.ContainsKey(item.FieldName))
                        {
                            ExtPropertys += hs[item.FieldName].ToString();
                        }
                        ExtPropertys += "|";
                    }
                }
            }
            catch { }
            #endregion

            string         cachekey = "EBMIF_DeviceCryptKey-" + DeviceCode;
            DeviceCryptKey key      = null;

            #region 从数据库中加载保存的密钥
            if (key == null)
            {
                string _keystr = "";
                if (UserBLL.AppCryptKey_LoadKey(DeviceCode, out _keystr) == 0 && !string.IsNullOrEmpty(_keystr))
                {
                    try
                    {
                        key = JsonConvert.DeserializeObject <DeviceCryptKey>(_keystr);
                        if (key != null)
                        {
                            DataCache.SetCache(cachekey, key, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration);
                        }
                    }
                    catch { }
                }
            }
            #endregion

            int    ret      = 0;
            string Password = EncryptPassword;
            if (key == null)
            {
                LogWriter.WriteLog("UserLogin.LoginEx: Get DeviceCrytKey Null! UserName="******",DeviceCode=" + DeviceCode);
                return(-1002);  //未能获取到对称加密密钥
            }
            else
            {
                ret = AESProvider.DecryptText(EncryptPassword, key.AESKey, key.AESIV, out Password);
                if (ret < 0)
                {
                    LogWriter.WriteLog("UserLogin.LoginEx! AESProvider.DecryptText Ret=" + ret.ToString() + ",DeviceCode=" + DeviceCode +
                                       ",EncryptPassword="******",AESKey=" + key.AESKey + ",AESIV=" + key.AESIV);
                    return(-1002);
                }
            }

            ret = userlogin(UserName, Password, DeviceCode, ExtPropertys, out AuthKey);

            if (ConfigHelper.GetConfigBool("DebugMode") && key != null)
            {
                LogWriter.WriteLog("UserLogin.LoginEx:Login Return ret=" + ret.ToString() + ",DeviceCode=" + DeviceCode
                                   + ",AESKey=" + key.AESKey + ",AESIV=" + key.AESIV + ",AuthKey=" + AuthKey);
            }

            switch (ret)
            {
            case -1003:
                //设备号未在可登录的列表中登记
                return(-1003);

            case -3:
            case -5:
            case -10:
                //当前用户不允许从该设备号登录
                return(-1004);

            case -2:
            case -11:
            case -12:
            case -13:
                //用户名或密码错误,登录失败
                return(-1001);

            case 1:
                //登录成功
                return(0);

            default:
                //登录失败
                return(-1005);
            }
        }
    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;
    }
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        Rpt_DataSetFieldsBLL _bll;

        if ((Guid)ViewState["ID"] != Guid.Empty)
            _bll = new Rpt_DataSetFieldsBLL((Guid)ViewState["ID"]);
        else
            _bll = new Rpt_DataSetFieldsBLL();

        _bll.Model.DataSet = (Guid)ViewState["DataSet"];

        _bll.Model.FieldName = tbx_FieldName.Text;
        _bll.Model.DisplayName = tbx_DisplayName.Text;
        _bll.Model.DataType = int.Parse(ddl_DataType.SelectedValue);
        _bll.Model.Description = tbx_Description.Text;

        if (ddl_IsComputeField.SelectedValue == "Y")
        {
            _bll.Model.IsComputeField = "Y";
            _bll.Model.Expression = tbx_Expression.Text.Trim();
            if (_bll.Model.Expression == "")
            {
                tbx_Expression.Focus();
                MessageBox.Show(this, "请正确录入计算列的表达式!");
                return;
            }
        }
        else
        {
            _bll.Model.IsComputeField = "N";
            _bll.Model.Expression = "";
        }

        if (tbx_SortID.Text != "") _bll.Model.ColumnSortID = int.Parse(tbx_SortID.Text);
        _bll.Model.DisplayMode = int.Parse(ddl_DisplayMode.SelectedValue);

        #region 树形字段有指定层次时,重设字段名
        //要与查询条件生成的字段要一致,以便支持多同一树形字段多列显示
        if (tbx_TreeLevel.Enabled)
        {
            UD_ModelFields f = new UD_ModelFieldsBLL(_bll.Model.FieldID).Model;

            if (new UD_TableListBLL(f.RelationTableName).Model.TreeFlag == "Y")
            {

                int level = 0;
                int.TryParse(tbx_TreeLevel.Text, out level);
                _bll.Model.TreeLevel = level;

                UD_TableList t = new UD_TableListBLL(f.TableID).Model;
                if (level > 0)
                    _bll.Model.FieldName = t.ModelClassName + "_" + f.FieldName + level.ToString();
                else
                    _bll.Model.FieldName = t.ModelClassName + "_" + f.FieldName;
            }
        }
        #endregion

        if (Rpt_DataSetFieldsBLL.GetModelList("DataSet='" + _bll.Model.DataSet.ToString() + "' AND FieldName='" +
               _bll.Model.FieldName + "' AND ID <>'" + _bll.Model.ID.ToString() + "'").Count > 0)
        {
            MessageBox.Show(this, "对不起,字段名已重复,请更改字段名称!");
            return;
        }

        if ((Guid)ViewState["ID"] != Guid.Empty)
        {
            _bll.Update();
        }
        else
        {
            _bll.Add();
        }
        new Rpt_DataSetBLL((Guid)ViewState["DataSet"]).ClearCache();

        Response.Redirect("Rpt_DataSetFieldsList.aspx?ID=" + ViewState["DataSet"].ToString());
    }
    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
        }
    }
Exemplo n.º 32
0
        /// <summary>
        /// Get data from the special model
        /// </summary>
        /// <param name="_model"></param>
        public void GetData(IModel _model)
        {
            foreach (object _key in FieldControlsInfo.Keys)
            {
                FieldControlInfo fieldcontrolinfo = (FieldControlInfo)FieldControlsInfo[_key];
                string fieldname = fieldcontrolinfo.FieldName;

                if (fieldcontrolinfo.ModelName == _model.ModelName)
                {
                    switch (fieldcontrolinfo.ControlType)
                    {
                        case 1:
                            //_model[fieldname] = ((Label)this.FindControl((string)_key)).Text;
                            break;
                        case 2:
                        case 5:
                            string _textboxvalue = ((TextBox)this.FindControl((string)_key)).Text;
                            _model[fieldname] = _textboxvalue;

                            if (_textboxvalue.Trim() == string.Empty)
                            {
                                //如果文本框的内容为空,则要判断是否是日期型的,如是,则设为1900-01-01
                                UD_ModelFields _modelfield = new UD_ModelFieldsBLL(fieldcontrolinfo.FieldID, true).Model;
                                if (_modelfield.DataType == 4) _model[fieldname] = "1900-01-01";
                            }
                            break;
                        case 3:
                            _model[fieldname] = ((DropDownList)this.FindControl((string)_key)).SelectedValue;
                            break;
                        case 4:
                            _model[fieldname] = ((RadioButtonList)this.FindControl((string)_key)).SelectedValue;
                            break;
                        case 6:
                            _model[fieldname] = ((MCSSelectControl)this.FindControl((string)_key)).SelectValue;
                            break;
                        case 7:
                            _model[fieldname] = ((MCSTreeControl)this.FindControl((string)_key)).SelectValue;
                            break;
                    }
                }
            }
        }
Exemplo n.º 33
0
        /// <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 = new UD_ModelFieldsBLL(new Guid(ddl_Field.SelectedValue), true).Model;
        if (modelfield == null) return;

        //字段全称
        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 (rbl_ValueFrom.SelectedValue == "M")
        {
            #region 从手工设定中取值
            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")
                        {
                            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 = "MCS_SYS.dbo.UF_IsChildOrganizeCity(" + MCSTreeControl1.SelectValue + "," + fieldfullname + ") = 0";
                            }
                            else
                            {
                                //指定级别上级
                                lt.Text = fielddisplayname + " 的 " + ddl_TreeLevel.SelectedItem.Text + " 为 " + MCSTreeControl1.SelectText;
                                lt.Value = "MCS_SYS.dbo.UF_GetSuperOrganizeCityByLevel02(" + fieldfullname + "," + ddl_TreeLevel.SelectedValue + ") = " + MCSTreeControl1.SelectValue;
                            }
                        }
                        else if (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 = "MCS_SYS.dbo.UF_IsChildOfficialCityCity(" + MCSTreeControl1.SelectValue + "," + fieldfullname + ") = 0";
                            }
                            else
                            {
                                //指定级别上级
                                lt.Text = fielddisplayname + " 的 " + ddl_TreeLevel.SelectedItem.Text + " 为 " + MCSTreeControl1.SelectText;
                                lt.Value = "MCS_SYS.dbo.UF_GetSuperOfficialCityByLevel02(" + fieldfullname + "," + ddl_TreeLevel.SelectedValue + ") = " + 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 != "like")
                    {
                        if (tbx_searchvalue.Text.StartsWith("@"))
                            lt.Value = fieldfullname + " " + 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
        }
        else
        {
            #region 从参数中取值
            switch (modelfield.RelationType)
            {
                case 1:
                    #region 字典关联
                    lt.Text = fielddisplayname + " = " + ddl_Param.SelectedValue;
                    lt.Value = fieldfullname + " = " + ddl_Param.SelectedValue;
                    #endregion
                    break;
                case 2:
                    #region 实体表关联
                    lt.Text = fielddisplayname + " 为  ";
                    lt.Value = fieldfullname + " =  ";
                    if (ddl_TreeLevel.Visible)
                    {
                        #region 管理片区及行政城市选项
                        if (ddl_TreeLevel.SelectedValue == "0")
                        {
                            //当前级
                            lt.Text += ddl_Param.SelectedValue;
                            lt.Value = fieldfullname + " = " + ddl_Param.SelectedValue;
                        }
                        else if (ddl_TreeLevel.SelectedValue == "100")
                        {
                            //所属于
                            lt.Text = fielddisplayname + " " + ddl_TreeLevel.SelectedItem.Text + " " + ddl_Param.SelectedValue;

                            if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
                            {
                                lt.Value = "MCS_SYS.dbo.UF_IsChildOrganizeCity(" + ddl_Param.SelectedValue + "," + fieldfullname + ") = 0";
                            }
                            else if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity")
                            {
                                lt.Value = "MCS_SYS.dbo.UF_IsChildOfficialCityCity(" + ddl_Param.SelectedValue + "," + fieldfullname + ") = 0";
                            }
                        }
                        else
                        {
                            lt.Text = fielddisplayname + " 的 " + ddl_TreeLevel.SelectedItem.Text + " 为 " + ddl_Param.SelectedValue;

                            //指定级别上级
                            if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity")
                            {
                                lt.Value = "MCS_SYS.dbo.UF_GetSuperOrganizeCityByLevel02(" + fieldfullname + "," + ddl_TreeLevel.SelectedValue + ") = " + ddl_Param.SelectedValue;
                            }
                            else if (modelfield.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity")
                            {
                                lt.Value = "MCS_SYS.dbo.UF_GetSuperOfficialCityByLevel02(" + fieldfullname + "," + ddl_TreeLevel.SelectedValue + ") = " + ddl_Param.SelectedValue;
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        lt.Text += ddl_Param.SelectedValue;
                        lt.Value = fieldfullname + " = " + ddl_Param.SelectedValue;
                    }
                    break;
                    #endregion
                default:
                    #region 非关联字段
                    lt.Text = fielddisplayname + " " + ddl_op.SelectedItem.Text + " (" + ddl_Param.SelectedValue + ")";
                    lt.Value = fieldfullname + " =  ";
                    if (ddl_op.SelectedValue != "like")
                        lt.Value = fieldfullname + " " + ddl_op.SelectedItem.Value + ddl_Param.SelectedValue;
                    else
                        lt.Value = fieldfullname + " LIKE '%'+" + ddl_Param.SelectedValue + "+'%'";
                    break;
                    #endregion
            }
            #endregion

        }
        #endregion

        if (!string.IsNullOrEmpty(lt.Text)) lbx_search.Items.Add(lt);
    }
    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"] = "WdatePicker()";
                            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;
    }
    protected void rbl_ValueFrom_SelectedIndexChanged(object sender, EventArgs e)
    {
        tbx_searchvalue.Text = "";
        tbx_searchvalue.Attributes["onfocus"] = "";
        cbl_SearchValue.Items.Clear();

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

        if (rbl_ValueFrom.SelectedValue == "M")
        {
            #region 条件选择
            UD_ModelFields modelfield = new UD_ModelFieldsBLL(new Guid(ddl_Field.SelectedValue), true).Model;
            if (modelfield == null) return;

            switch (modelfield.RelationType)
            {
                case 1:
                    //字典关联
                    cbl_SearchValue.DataTextField = "Value";
                    cbl_SearchValue.DataValueField = "Key";
                    cbl_SearchValue.DataSource = DictionaryBLL.GetDicCollections(modelfield.RelationTableName);
                    cbl_SearchValue.DataBind();
                    cbl_SearchValue.Visible = true;
                    break;
                case 2:
                    //实体表关联
                    if (!string.IsNullOrEmpty(modelfield.SearchPageURL))
                    {
                        //通过查询控件查询
                        MCSSelectControl1.PageUrl = modelfield.SearchPageURL;
                        MCSSelectControl1.Visible = true;
                    }
                    else if (new UD_TableListBLL(modelfield.RelationTableName).Model.TreeFlag == "Y")
                    {
                        MCSTreeControl1.DataSource = null;
                        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.TableName = modelfield.RelationTableName;
                            MCSTreeControl1.RootValue = "0";
                            MCSTreeControl1.SelectValue = "0";
                        }
                        MCSTreeControl1.DataBind();
                        MCSTreeControl1.Visible = true;
                    }
                    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;
                    }
                    break;
                default:
                    //非关联字段
                    tbx_searchvalue.Visible = true;
                    break;
            }

            #endregion
        }
        else
        {
            ddl_Param.Visible = true;
        }
    }
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        UD_ModelFieldsBLL _modelfieldsbll;

        if (ViewState["ID"] != null)
        {
            _modelfieldsbll = new UD_ModelFieldsBLL((Guid)ViewState["ID"]);
        }
        else
        {
            _modelfieldsbll = new UD_ModelFieldsBLL();
        }
        _modelfieldsbll.Model.TableID       = (Guid)ViewState["TableID"];
        _modelfieldsbll.Model.FieldName     = tbx_FieldName.Text;
        _modelfieldsbll.Model.DisplayName   = tbx_DisplayName.Text;
        _modelfieldsbll.Model.DataType      = int.Parse(ddl_DataType.SelectedValue);
        _modelfieldsbll.Model.DataLength    = string.IsNullOrEmpty(tbx_Length.Text) ? 0 : int.Parse(tbx_Length.Text);
        _modelfieldsbll.Model.Precision     = string.IsNullOrEmpty(tbx_Precision.Text) ? 0 : int.Parse(tbx_Precision.Text);
        _modelfieldsbll.Model.DefaultValue  = tbx_DefaultValue.Text;
        _modelfieldsbll.Model.Description   = tbx_Description.Text;
        _modelfieldsbll.Model.RelationType  = int.Parse(rbl_RelationType.SelectedValue);
        _modelfieldsbll.Model.SearchPageURL = tbx_SearchPageURL.Text;

        if (ddl_RelationTableName.Visible)
        {
            _modelfieldsbll.Model.RelationTableName = ddl_RelationTableName.SelectedValue;
        }
        else
        {
            _modelfieldsbll.Model.RelationTableName = "";
        }
        if (ddl_RelationTextField.Visible)
        {
            _modelfieldsbll.Model.RelationTextField = ddl_RelationTextField.SelectedValue;
        }
        else
        {
            _modelfieldsbll.Model.RelationTextField = "";
        }
        if (ddl_RelationValueField.Visible)
        {
            _modelfieldsbll.Model.RelationValueField = ddl_RelationValueField.SelectedValue;
        }
        else
        {
            _modelfieldsbll.Model.RelationValueField = "";
        }

        _modelfieldsbll.Model.LastUpdateTime = DateTime.Now;

        if (ViewState["ID"] != null)
        {
            _modelfieldsbll.Update();
        }
        else
        {
            _modelfieldsbll.Model.Flag = "N";
            _modelfieldsbll.Add();
        }
        Response.Redirect("ModelFieldList.aspx?TableID=" + ViewState["TableID"].ToString());
    }
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        Rpt_DataSetFieldsBLL _bll;

        if ((Guid)ViewState["ID"] != Guid.Empty)
        {
            _bll = new Rpt_DataSetFieldsBLL((Guid)ViewState["ID"]);
        }
        else
        {
            _bll = new Rpt_DataSetFieldsBLL();
        }

        _bll.Model.DataSet = (Guid)ViewState["DataSet"];

        _bll.Model.FieldName   = tbx_FieldName.Text;
        _bll.Model.DisplayName = tbx_DisplayName.Text;
        _bll.Model.DataType    = int.Parse(ddl_DataType.SelectedValue);
        _bll.Model.Description = tbx_Description.Text;

        if (ddl_IsComputeField.SelectedValue == "Y")
        {
            _bll.Model.IsComputeField = "Y";
            _bll.Model.Expression     = tbx_Expression.Text.Trim();
            if (_bll.Model.Expression == "")
            {
                tbx_Expression.Focus();
                MessageBox.Show(this, "请正确录入计算列的表达式!");
                return;
            }
        }
        else
        {
            _bll.Model.IsComputeField = "N";
            _bll.Model.Expression     = "";
        }

        if (tbx_SortID.Text != "")
        {
            _bll.Model.ColumnSortID = int.Parse(tbx_SortID.Text);
        }
        _bll.Model.DisplayMode = int.Parse(ddl_DisplayMode.SelectedValue);

        #region 树形字段有指定层次时,重设字段名
        //要与查询条件生成的字段要一致,以便支持多同一树形字段多列显示
        if (tbx_TreeLevel.Enabled)
        {
            UD_ModelFields f = new UD_ModelFieldsBLL(_bll.Model.FieldID).Model;

            if (new UD_TableListBLL(f.RelationTableName).Model.TreeFlag == "Y")
            {
                int level = 0;
                int.TryParse(tbx_TreeLevel.Text, out level);
                _bll.Model.TreeLevel = level;

                UD_TableList t = new UD_TableListBLL(f.TableID).Model;
                if (level > 0)
                {
                    _bll.Model.FieldName = t.ModelClassName + "_" + f.FieldName + level.ToString();
                }
                else
                {
                    _bll.Model.FieldName = t.ModelClassName + "_" + f.FieldName;
                }
            }
        }
        #endregion

        if (Rpt_DataSetFieldsBLL.GetModelList("DataSet='" + _bll.Model.DataSet.ToString() + "' AND FieldName='" +
                                              _bll.Model.FieldName + "' AND ID <>'" + _bll.Model.ID.ToString() + "'").Count > 0)
        {
            MessageBox.Show(this, "对不起,字段名已重复,请更改字段名称!");
            return;
        }

        if ((Guid)ViewState["ID"] != Guid.Empty)
        {
            _bll.Update();
        }
        else
        {
            _bll.Add();
        }
        new Rpt_DataSetBLL((Guid)ViewState["DataSet"]).ClearCache();

        Response.Redirect("Rpt_DataSetFieldsList.aspx?ID=" + ViewState["DataSet"].ToString());
    }
    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_TableName_SelectedIndexChanged(object sender, EventArgs e)
    {
        UD_ModelFieldsBLL mf = new UD_ModelFieldsBLL();

        ddl_FieldID.DataSource = mf._GetModelList("TableID='" + ddl_TableName.SelectedValue + "'");
        ddl_FieldID.DataBind();
        ddl_FieldID_SelectedIndexChanged(null, null);
    }
    private void BindData()
    {
        Guid _id = (Guid)ViewState["ID"];
        UD_ModelFieldsBLL _modelfieldsbll = new UD_ModelFieldsBLL(_id);
        lbl_ID.Text = _modelfieldsbll.Model.ID.ToString();
        tbx_FieldName.Text = _modelfieldsbll.Model.FieldName;
        tbx_DisplayName.Text = _modelfieldsbll.Model.DisplayName;
        ddl_DataType.SelectedValue = _modelfieldsbll.Model.DataType.ToString();
        tbx_Length.Text = _modelfieldsbll.Model.DataLength.ToString();
        if (_modelfieldsbll.Model.Precision != 0) tbx_Precision.Text = _modelfieldsbll.Model.Precision.ToString();
        tbx_DefaultValue.Text = _modelfieldsbll.Model.DefaultValue;
        tbx_Description.Text = _modelfieldsbll.Model.Description;
        lbl_LastUpdateTime.Text = _modelfieldsbll.Model.LastUpdateTime.ToString();
        if (_modelfieldsbll.Model.RelationType > 0)
            rbl_RelationType.SelectedValue = _modelfieldsbll.Model.RelationType.ToString();
        rbl_RelationType_SelectedIndexChanged(null, null);
        tbx_SearchPageURL.Text = _modelfieldsbll.Model.SearchPageURL;

        if (ddl_RelationTableName != null || ddl_RelationTableName.Items.Count != 0)
        {
            ddl_RelationTableName.SelectedValue = _modelfieldsbll.Model.RelationTableName;
            {
                ddl_RelationTableName_SelectedIndexChanged(null, null);
            }
        }
        if (ddl_RelationTextField != null || ddl_RelationTextField.Items.Count != 0)
        {
            ddl_RelationTextField.SelectedValue = _modelfieldsbll.Model.RelationTextField;
        }
        if (ddl_RelationValueField != null || ddl_RelationValueField.Items.Count != 0)
        {
            ddl_RelationValueField.SelectedValue = _modelfieldsbll.Model.RelationValueField;
        }

        tbx_FieldName.Enabled = false;
        bt_OK.Text = "修改";
        bt_OK.ForeColor = System.Drawing.Color.Red;
    }
    protected void rbl_ValueFrom_SelectedIndexChanged(object sender, EventArgs e)
    {
        tbx_searchvalue.Text = "";
        tbx_searchvalue.Attributes["onfocus"] = "";
        cbl_SearchValue.Items.Clear();

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

        if (rbl_ValueFrom.SelectedValue == "M")
        {
            #region 条件选择
            UD_ModelFields modelfield = new UD_ModelFieldsBLL(new Guid(ddl_Field.SelectedValue), true).Model;
            if (modelfield == null)
            {
                return;
            }

            switch (modelfield.RelationType)
            {
            case 1:
                //字典关联
                cbl_SearchValue.DataTextField  = "Value";
                cbl_SearchValue.DataValueField = "Key";
                cbl_SearchValue.DataSource     = DictionaryBLL.GetDicCollections(modelfield.RelationTableName);
                cbl_SearchValue.DataBind();
                cbl_SearchValue.Visible = true;
                break;

            case 2:
                //实体表关联
                if (!string.IsNullOrEmpty(modelfield.SearchPageURL))
                {
                    //通过查询控件查询
                    MCSSelectControl1.PageUrl = modelfield.SearchPageURL;
                    MCSSelectControl1.Visible = true;
                }
                else if (new UD_TableListBLL(modelfield.RelationTableName).Model.TreeFlag == "Y")
                {
                    MCSTreeControl1.DataSource = null;
                    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.TableName   = modelfield.RelationTableName;
                        MCSTreeControl1.RootValue   = "0";
                        MCSTreeControl1.SelectValue = "0";
                    }
                    MCSTreeControl1.DataBind();
                    MCSTreeControl1.Visible = true;
                }
                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;
                }
                break;

            default:
                //非关联字段
                tbx_searchvalue.Visible = true;
                break;
            }

            #endregion
        }
        else
        {
            ddl_Param.Visible = true;
        }
    }
    protected void ddl_FieldID_SelectedIndexChanged(object sender, EventArgs e)
    {
        UD_ModelFieldsBLL bll = new UD_ModelFieldsBLL(new Guid(ddl_FieldID.SelectedValue));
        if (bll.Model.RelationType == 1 || bll.Model.RelationType == 2)
        {
            ddl_DisplayMode.Enabled = true;

            //如果关联表是树形结构,则允许设定树表层次
            if (bll.Model.RelationType == 2 && new UD_TableListBLL(bll.Model.RelationTableName).Model.TreeFlag == "Y")
                tbx_TreeLevel.Enabled = true;
            else
            {
                tbx_TreeLevel.Text = "";
                tbx_TreeLevel.Enabled = false;
            }
        }
        else
        {
            ddl_DisplayMode.Enabled = false;
            ddl_DisplayMode.SelectedValue = "1";
            tbx_TreeLevel.Text = "";
            tbx_TreeLevel.Enabled = false;
        }

        tbx_LabelText.Text = ddl_FieldID.SelectedItem.Text;
    }
Exemplo n.º 44
0
        private void CreateSqlString()
        {
            string _sqlstring = "";
            string _selectstr = "SELECT ";
            string _fromstr   = "";
            string _tmpfrom   = "";         //字段如果是关联时,临时生成的from sql

            #region create the select string
            UD_PanelBLL _panelbll = new UD_PanelBLL(PanelCode, true);
            if (_panelbll.Model == null)
            {
                throw new Exception("Panel:" + PanelCode + ",未能找到该Code对应的Panel,Code无效!");
            }

            Dictionary <string, UD_Panel_ModelFields> dicTreeColumnList = new Dictionary <string, UD_Panel_ModelFields>();
            IList <UD_Panel_ModelFields> _panel_modelfieldsmodels       = _panelbll.GetModelFields();
            OrderFields = _panelbll.Model.DefaultSortFields;

            if (_panel_modelfieldsmodels.Count == 0)
            {
                //未定义Panel字段
                ViewState["SqlString"] = "";
                return;
            }

            if (!string.IsNullOrEmpty(_panelbll.Model.Description))
            {
                string[] _array = _panelbll.Model.Description.Split(new char[] { '|' }, StringSplitOptions.None);
                if (_array.Length >= 2)
                {
                    ViewState["DBConnectString"] = _array[1];
                }
            }

            foreach (UD_Panel_ModelFields _panel_modelfields in _panel_modelfieldsmodels)
            {
                UD_ModelFields _modelfield = new UD_ModelFieldsBLL(_panel_modelfields.FieldID, true).Model;
                UD_TableList   _tablemodel = new UD_TableListBLL(_modelfield.TableID, true).Model;


                string _fieldfullname = _tablemodel.ModelClassName + "_" + _modelfield.FieldName;

                #region 判断字段关联类型,决定如果创建SQL
                switch (_modelfield.RelationType)
                {
                case 1:                                      //Relation to dic
                    if (_panel_modelfields.DisplayMode == 1) //Bound the id value of the field
                    {
                        if (_modelfield.Flag == "Y")
                        {
                            _selectstr += _tablemodel.Name + "." + _modelfield.FieldName + " AS " + _fieldfullname + ",";
                        }
                        else    //扩展字段
                        {
                            _selectstr += "[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," +
                                          _modelfield.Position.ToString() + ") AS " + _fieldfullname + ",";
                        }
                    }
                    else    //Bound the text value of the field
                    {
                        //计算出关联字典表的别名"_vname"
                        string _vname = "V_Dictionary_Data" + "_" + _modelfield.FieldName;
                        if (_modelfield.Flag == "Y")
                        {
                            _selectstr += _vname + ".Name" + " AS " + _fieldfullname + ",";
                            _tmpfrom   += " left join V_Dictionary_Data AS " + _vname + " ON " + _tablemodel.Name + "." + _modelfield.FieldName + "=" + _vname + ".Code AND " + _vname + ".TableName='" + _modelfield.RelationTableName + "' ";
                        }
                        else    //扩展字段
                        {
                            _selectstr += _vname + ".Name" + " AS " + _fieldfullname + ",";
                            _tmpfrom   += " left join V_Dictionary_Data AS " + _vname + " ON [dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") =" + _vname + ".Code AND " + _vname + ".TableName='" + _modelfield.RelationTableName + "' ";
                        }
                    }
                    break;

                case 2:    //Relation to model table
                    if (_panel_modelfields.TreeLevel > 0 && new UD_TableListBLL(_modelfield.RelationTableName).Model.TreeFlag == "Y")
                    {
                        #region 字段关联到树形结构表,且要显示上层父结点信息
                        _fieldfullname += _panel_modelfields.TreeLevel.ToString();
                        if (_modelfield.Flag == "Y")
                        {
                            _selectstr += _tablemodel.Name + "." + _modelfield.FieldName + " AS " + _fieldfullname + ",";
                        }
                        else    //扩展字段
                        {
                            _selectstr += "[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") AS " + _fieldfullname + ",";
                        }

                        dicTreeColumnList.Add(_fieldfullname, _panel_modelfields);
                        #endregion

                        #region 注释
                        //if (param.TreeLevel == 100 && param.DisplayMode == 2)
                        //{
                        //    //显示字段路径全称
                        //    if (_modelfield.Flag == "Y")
                        //        _selectstr += "[dbo].[Exuf_TreeTable_GetFullName]('" + _modelfield.RelationTableName + "'," + _tablemodel.Name + "." + _modelfield.FieldName + ",1) AS " + _fieldfullname + ",";
                        //    else//扩展字段
                        //        _selectstr += "[dbo].[Exuf_TreeTable_GetFullName]('" + _modelfield.RelationTableName + "'," + "[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + "),0) AS " + _fieldfullname + ",";
                        //}
                        //else
                        //{
                        //    _fieldfullname += param.TreeLevel.ToString();
                        //    if (param.DisplayMode == 1)//Bound the id value of the field
                        //    {
                        //        if (_modelfield.Flag == "Y")
                        //            _selectstr += "[dbo].[Exuf_TreeTable_GetSuperIDByLevel]('" + _modelfield.RelationTableName + "'," + _tablemodel.Name + "." + _modelfield.FieldName + "," + param.TreeLevel.ToString() + ") AS " + _fieldfullname + ",";
                        //        else//扩展字段
                        //        {
                        //            _selectstr += "[dbo].[Exuf_TreeTable_GetSuperIDByLevel]('" + _modelfield.RelationTableName + "'," + "[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ")," + param.TreeLevel.ToString() + ") AS " + _fieldfullname + ",";
                        //        }
                        //    }
                        //    else//Bound the text value of the field
                        //    {
                        //        if (_modelfield.Flag == "Y")
                        //            _selectstr += "[dbo].[Exuf_TreeTable_GetSuperNameByLevel]('" + _modelfield.RelationTableName + "'," + _tablemodel.Name + "." + _modelfield.FieldName + "," + param.TreeLevel.ToString() + ") AS " + _fieldfullname + ",";
                        //        else//扩展字段
                        //            _selectstr += "[dbo].[Exuf_TreeTable_GetSuperNameByLevel]('" + _modelfield.RelationTableName + "'," + "[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ")," + param.TreeLevel.ToString() + ") AS " + _fieldfullname + ",";
                        //    }
                        //}
                        #endregion
                    }
                    else
                    {
                        #region  需关联到树形结构表
                        if (_panel_modelfields.DisplayMode == 1)    //Bound the id value of the field
                        {
                            if (_modelfield.Flag == "Y")
                            {
                                _selectstr += _tablemodel.Name + "." + _modelfield.FieldName + " AS " + _fieldfullname + ",";
                            }
                            else    //扩展字段
                            {
                                _selectstr += "[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") AS " + _fieldfullname + ",";
                            }
                        }
                        else    //Bound the text value of the field
                        {
                            #region 计算出关联表的别名"_vname"
                            string _vname = "";
                            int    pos    = _modelfield.RelationTableName.LastIndexOf('.');
                            if (pos >= 0)
                            {
                                _vname = _modelfield.RelationTableName.Substring(pos + 1) + "_" + _modelfield.FieldName;
                            }
                            else
                            {
                                _vname = _modelfield.RelationTableName + "_" + _modelfield.FieldName;
                            }
                            #endregion

                            if (_modelfield.Flag == "Y")
                            {
                                _selectstr += _vname + "." + _modelfield.RelationTextField + " AS " + _fieldfullname + ",";
                                _tmpfrom   += " left join " + _modelfield.RelationTableName + " AS " + _vname + " ON " + _tablemodel.Name + "." + _modelfield.FieldName + "=" + _vname + "." + _modelfield.RelationValueField;
                            }
                            else    //扩展字段
                            {
                                _selectstr += _vname + "." + _modelfield.RelationTextField + " AS " + _fieldfullname + ",";
                                _tmpfrom   += " left join " + _modelfield.RelationTableName + " AS " + _vname + " ON [dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") =" + _vname + "." + _modelfield.RelationValueField;
                            }
                        }
                        #endregion
                    }

                    break;

                default:    //No relation
                    if (_modelfield.Flag == "Y")
                    {
                        _selectstr += _tablemodel.Name + "." + _modelfield.FieldName + " AS " + _fieldfullname + ",";
                    }
                    else
                    {
                        _selectstr += "[dbo].[UF_Spilt](" + _tablemodel.Name + ".ExtPropertys,'|'," + _modelfield.Position.ToString() + ") AS " + _fieldfullname + ",";
                    }
                    break;
                }
                #endregion

                //Add a bound field to the gridview according to the selected field
                BoundField _boundfield = new BoundField();
                _boundfield.HeaderText     = string.IsNullOrEmpty(_panel_modelfields.LabelText) ? _modelfield.DisplayName : _panel_modelfields.LabelText;
                _boundfield.DataField      = _fieldfullname;
                _boundfield.SortExpression = _fieldfullname;

                if (!_panel_modelfields.FormatString.StartsWith("{0:"))
                {
                    _boundfield.DataFormatString = "{0:" + _panel_modelfields.FormatString + "}";
                }
                else
                {
                    _boundfield.DataFormatString = _panel_modelfields.FormatString;
                }
                //_boundfield.Visible = _panel_modelfieldsmodel.Visible == "Y";

                if (_panel_modelfields.Visible == "Y")
                {
                    if (_panel_modelfields.SortID - 1 > Columns.Count)
                    {
                        Columns.Add(_boundfield);
                    }
                    else
                    {
                        Columns.Insert(_panel_modelfields.SortID - 1, _boundfield);
                    }
                }
            }
            _selectstr = _selectstr.Substring(0, _selectstr.Length - 1);
            #endregion

            #region create the from string of sql
            IList <UD_Panel_TableRelation> _panel_tablerelations = _panelbll.GetTableRelations();
            if (_panel_tablerelations.Count == 0)
            {
                IList <UD_Panel_Table> _panel_tables = _panelbll.GetPanelTables();

                if (_panel_tables.Count == 0)
                {
                    throw new Exception("Panel:" + PanelCode + "在定义中未包括包含的表信息!");
                }

                _fromstr = " FROM " + new UD_TableListBLL(_panel_tables[0].TableID, true).Model.Name;
            }
            else
            {
                foreach (UD_Panel_TableRelation _panel_tablerelation in _panel_tablerelations)
                {
                    string         _parenttablename = new UD_TableListBLL(_panel_tablerelation.ParentTableID, true).Model.Name;
                    string         _childtablename  = new UD_TableListBLL(_panel_tablerelation.ChildTableID, true).Model.Name;
                    UD_ModelFields _parentfield     = new UD_ModelFieldsBLL(_panel_tablerelation.ParentFieldID, true).Model;
                    UD_ModelFields _childfield      = new UD_ModelFieldsBLL(_panel_tablerelation.ChildFieldID, true).Model;
                    if (_panel_tablerelation.JoinMode == "")
                    {
                        _panel_tablerelation.JoinMode = "LEFT JOIN";
                    }

                    if (_fromstr == "")
                    {
                        _fromstr = " FROM " + _parenttablename + " ";
                    }

                    if (_parentfield.Flag == "Y" && _childfield.Flag == "Y")
                    {
                        _fromstr += " " + _panel_tablerelation.JoinMode + " " + _childtablename + " ON " + _parenttablename + "." + _parentfield.FieldName + "=" + _childtablename + "." + _childfield.FieldName + " ";
                    }
                    else
                    {
                        _fromstr += " " + _panel_tablerelation.JoinMode + " " + _childtablename + " ON ";

                        if (_parentfield.Flag == "Y")
                        {
                            _fromstr += "CONVERT(VarChar," + _parenttablename + "." + _parentfield.FieldName + ")";
                        }
                        else
                        {
                            _fromstr += "[dbo].[UF_Spilt](" + _parenttablename + ".ExtPropertys,'|'," +
                                        new UD_ModelFieldsBLL(_panel_tablerelation.ParentFieldID, true).Model.Position + ")";
                        }

                        _fromstr += " = ";

                        if (_childfield.Flag == "Y")
                        {
                            _fromstr += "CONVERT(VarChar," + _childtablename + "." + _childfield.FieldName + ")";
                        }
                        else
                        {
                            _fromstr += "[dbo].[UF_Spilt](" + _childtablename + ".ExtPropertys,'|'," +
                                        new UD_ModelFieldsBLL(_panel_tablerelation.ChildFieldID, true).Model.Position + ")";
                        }
                    }
                    if (_panel_tablerelation.RelationCondition != "")
                    {
                        _fromstr += " AND " + _panel_tablerelation.RelationCondition + " ";
                    }
                }
            }

            if (_tmpfrom != "")
            {
                _fromstr += _tmpfrom;
            }

            _sqlstring = _selectstr + _fromstr;
            #endregion

            ViewState["SqlString"]  = _sqlstring;
            ViewState["TreeColumn"] = dicTreeColumnList;
        }
    private void BindData()
    {
        Rpt_DataSetFieldsBLL _bll = new Rpt_DataSetFieldsBLL((Guid)ViewState["ID"]);

        ViewState["DataSet"] = _bll.Model.DataSet;

        ddl_IsComputeField.SelectedValue = _bll.Model.IsComputeField;
        ddl_IsComputeField_SelectedIndexChanged(null, null);
        tbx_Expression.Text = _bll.Model.Expression;

        if (_bll.Model.FieldID != Guid.Empty)
        {
            #region 设置关联字段界面控件属性
            UD_ModelFields field = new UD_ModelFieldsBLL(_bll.Model.FieldID).Model;
            if (field == null) return;

            if (field.RelationType == 1 || field.RelationType == 2)
            {
                ddl_DisplayMode.Enabled = true;

                //如果关联表是树形结构,则允许设定树表层次
                if (field.RelationType == 2 && new UD_TableListBLL(field.RelationTableName).Model.TreeFlag == "Y")
                {
                    tbx_TreeLevel.Enabled = true;
                    if (_bll.Model.TreeLevel == 0 && (field.RelationTableName == "MCS_SYS.dbo.Addr_OrganizeCity" ||
                        field.RelationTableName == "MCS_SYS.dbo.Addr_OfficialCity"))
                    {
                        bt_Expand.Visible = true;  //如果字段关联于管理片区或行政城市,显示"展开层级"按钮
                    }
                }
                else
                {
                    tbx_TreeLevel.Text = "";
                    tbx_TreeLevel.Enabled = false;
                }
            }
            else
            {
                ddl_DisplayMode.Enabled = false;
                ddl_DisplayMode.SelectedValue = "1";
                tbx_TreeLevel.Text = "";
                tbx_TreeLevel.Enabled = false;
            }
            #endregion
        }

        tbx_FieldName.Text = _bll.Model.FieldName;
        tbx_DisplayName.Text = _bll.Model.DisplayName;
        ddl_DataType.SelectedValue = _bll.Model.DataType.ToString();
        tbx_Description.Text = _bll.Model.Description;

        tbx_SortID.Text = _bll.Model.ColumnSortID.ToString();
        tbx_TreeLevel.Text = _bll.Model.TreeLevel.ToString();
        ddl_DisplayMode.SelectedValue = _bll.Model.DisplayMode.ToString();

        tbx_FieldName.Enabled = false;
        ddl_IsComputeField.Enabled = false;

        bt_OK.Text = "修 改";
        bt_OK.ForeColor = System.Drawing.Color.Red;

        if ((int)ViewState["DataSet_CommandType"] == 1 || (int)ViewState["DataSet_CommandType"] == 2)
        {
            tbx_FieldName.Visible = true;

            ddl_DisplayMode.Enabled = false;
            tbx_TreeLevel.Enabled = false;

            if (_bll.Model.IsComputeField != "Y") bt_Delete.Visible = false;
        }
    }