Esempio n. 1
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 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());
        }
    }
    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 bt_Refresh_Click(object sender, EventArgs e)
    {
        Rpt_DataSetBLL bll = new Rpt_DataSetBLL((Guid)ViewState["ID"]);

        bll.ClearCache();

        #region 初始化参数
        Dictionary<string, object> prams = new Dictionary<string, object>();
        foreach (Rpt_DataSetParams p in bll.GetParams())
        {
            object value;
            switch (p.DataType)
            {
                case 1:         //整型(int)
                case 2:         //小数(decimal)
                case 7:         //位(bit)
                    value = 0;
                    break;
                case 3:         //字符串(varchar)
                case 6:         //字符串(nvarchar)
                case 8:         //ntext
                    value = "";
                    break;
                case 4:         //日期(datetime)
                    value = "1900-1-1";
                    break;
                case 5:         //GUID(uniqueidentifier)
                    value = Guid.Empty.ToString();
                    break;
                default:
                    value = "";
                    break;
            }

            prams.Add(p.ParamName, value);
        }
        #endregion

        DateTime t;
        DataTable dt = bll.GetData(prams, false, out t);

        IList<Rpt_DataSetFields> fields = bll.GetFields();

        #region 加入数据集中不包括的列
        foreach (DataColumn column in dt.Columns)
        {
            if (fields.FirstOrDefault(p => p.FieldName == column.ColumnName) == null)
            {
                Rpt_DataSetFieldsBLL field = new Rpt_DataSetFieldsBLL();

                field.Model.DataSet = (Guid)ViewState["ID"];
                field.Model.FieldName = column.ColumnName;
                field.Model.DisplayName = column.ColumnName;
                field.Model.ColumnSortID = column.Ordinal + 1;
                field.Model.DisplayMode = 1;
                field.Model.TreeLevel = 0;
                field.Model.IsComputeField = "N";

                #region 数据类型
                switch (column.DataType.FullName)
                {
                    case "System.Int16":
                    case "System.Int32":
                    case "System.Int64":
                        field.Model.DataType = 1;  //整形
                        break;
                    case "System.String":
                        field.Model.DataType = 3;  //字符串
                        break;
                    case "System.Decimal":
                        field.Model.DataType = 2;  //小数
                        break;
                    case "System.DateTime":
                        field.Model.DataType = 4;  //日期
                        break;
                    case "System.Guid":
                        field.Model.DataType = 5;  //GUID
                        break;
                    default:
                        field.Model.DataType = 3;  //字符串
                        break;
                }
                #endregion

                field.Add();
            }
        }
        #endregion

        #region 删除数据表中不存在的列
        foreach (Rpt_DataSetFields f in fields)
        {
            if (f.IsComputeField == "Y") continue;
            if (!dt.Columns.Contains(f.FieldName))
            {
                new Rpt_DataSetFieldsBLL(f.ID).Delete();
            }
        }
        #endregion

        gv_List.PageIndex = 0;
        BindGrid();
        MessageBox.Show(this, "数据集字段刷新成功!");
    }
    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());
        }
    }
Esempio n. 6
0
    protected void bt_Refresh_Click(object sender, EventArgs e)
    {
        Rpt_DataSetBLL bll = new Rpt_DataSetBLL((Guid)ViewState["ID"]);

        bll.ClearCache();

        #region 初始化参数
        Dictionary <string, object> prams = new Dictionary <string, object>();
        foreach (Rpt_DataSetParams p in bll.GetParams())
        {
            object value;
            switch (p.DataType)
            {
            case 1:             //整型(int)
            case 2:             //小数(decimal)
            case 7:             //位(bit)
                value = 0;
                break;

            case 3:             //字符串(varchar)
            case 6:             //字符串(nvarchar)
            case 8:             //ntext
                value = "";
                break;

            case 4:             //日期(datetime)
                value = "1900-1-1";
                break;

            case 5:             //GUID(uniqueidentifier)
                value = Guid.Empty.ToString();
                break;

            default:
                value = "";
                break;
            }


            prams.Add(p.ParamName, value);
        }
        #endregion

        DateTime  t;
        DataTable dt = bll.GetData(prams, false, out t);

        IList <Rpt_DataSetFields> fields = bll.GetFields();

        #region 加入数据集中不包括的列
        foreach (DataColumn column in dt.Columns)
        {
            if (fields.FirstOrDefault(p => p.FieldName == column.ColumnName) == null)
            {
                Rpt_DataSetFieldsBLL field = new Rpt_DataSetFieldsBLL();

                field.Model.DataSet        = (Guid)ViewState["ID"];
                field.Model.FieldName      = column.ColumnName;
                field.Model.DisplayName    = column.ColumnName;
                field.Model.ColumnSortID   = column.Ordinal + 1;
                field.Model.DisplayMode    = 1;
                field.Model.TreeLevel      = 0;
                field.Model.IsComputeField = "N";

                #region 数据类型
                switch (column.DataType.FullName)
                {
                case "System.Int16":
                case "System.Int32":
                case "System.Int64":
                    field.Model.DataType = 1;      //整形
                    break;

                case "System.String":
                    field.Model.DataType = 3;      //字符串
                    break;

                case "System.Decimal":
                    field.Model.DataType = 2;      //小数
                    break;

                case "System.DateTime":
                    field.Model.DataType = 4;      //日期
                    break;

                case "System.Guid":
                    field.Model.DataType = 5;      //GUID
                    break;

                default:
                    field.Model.DataType = 3;      //字符串
                    break;
                }
                #endregion

                field.Add();
            }
        }
        #endregion


        #region  除数据表中不存在的列
        foreach (Rpt_DataSetFields f in fields)
        {
            if (f.IsComputeField == "Y")
            {
                continue;
            }
            if (!dt.Columns.Contains(f.FieldName))
            {
                new Rpt_DataSetFieldsBLL(f.ID).Delete();
            }
        }
        #endregion

        gv_List.PageIndex = 0;
        BindGrid();
        MessageBox.Show(this, "数据集字段刷新成功!");
    }