コード例 #1
0
        public static BindingSource GetBindingSource(DataColumn column)
        {
            if (column == null)
            {
                return(null);
            }

            BindingSource bs = TableUtil.GetProperty(column, BINDINGSOURCE) as BindingSource;

            if (bs == null)
            {
                lock (column)
                {
                    bs = TableUtil.GetProperty(column, BINDINGSOURCE) as BindingSource;
                    if (bs == null)
                    {
                        bs            = new BindingSource();
                        bs.DataSource = column.Table.AsDataView();
                        bs.DataMember = column.ColumnName;
                        TableUtil.SetProperty(column, BINDINGSOURCE, bs);
                    }
                }
            }
            return(bs);
        }
コード例 #2
0
        public static bool InitTableSchemaFromSql(DataTable table, string sql, string paramvalue, string pageinfo, string dsname, string alias)
        {
            if (table == null || sql == null || sql.Equals(""))
            {
                return(false);
            }

            DataServices.OpenSql(table, sql, paramvalue, pageinfo, dsname);

            try
            {
                TableUtil.SetProperty(table, SysConstant.scSQL, sql);
                TableUtil.SetProperty(table, SysConstant.scParamValue, paramvalue);
                TableUtil.SetProperty(table, SysConstant.scBindAlias, alias);
                TableUtil.SetProperty(table, SysConstant.scPageManager, new PageManager(table));
                TableUtil.SetProperty(table, SysConstant.scPrimaryKey, "");

                DataColumn column;
                RuleColumn rcolumn;
                int        count = table.Columns.Count;
                for (int i = 0; i < count; i++)
                {
                    column = table.Columns[i];

                    rcolumn          = RuleColumn.FromDataColumn(column);
                    rcolumn.WhereOpt = "n";

                    TableUtil.SetProperty(column, SysConstant.scRuleColumn, rcolumn);
                }

                return(true);
            }
            catch (Exception e)
            {
                throw new Exception("SDP-ST02 填充元数据出错:" + e.Message);
            }
        }
コード例 #3
0
        public static BindingSource GetBindingSource(DataTable table)
        {
            if (table == null)
            {
                return(null);
            }

            BindingSource bs = TableUtil.GetProperty(table, BINDINGSOURCE) as BindingSource;

            if (bs == null)
            {
                lock (table)
                {
                    bs = TableUtil.GetProperty(table, BINDINGSOURCE) as BindingSource;
                    if (bs == null)
                    {
                        bs            = new BindingSource();
                        bs.DataSource = table.AsDataView();
                        TableUtil.SetProperty(table, BINDINGSOURCE, bs);
                    }
                }
            }
            return(bs);
        }
コード例 #4
0
        private static void FillTableMetaData(DataTable table, string head)
        {
            string     colFlag = "<F", curColFlag, curRow, curCol, curHead = head;
            DataColumn column = null;
            int        index, subindex;

            string[] rows = StrUtil.GetParamList(head, "<R>");

            bool hasPK = false;

            table.Columns.Clear();
            int count = rows.Length;

            for (int i = 0; i < count; i++)
            {
                curRow = rows[i];

                if (curRow.Equals(""))
                {
                    continue;
                }

                column = null;
                for (int j = 0; j < 5; j++)
                {
                    curColFlag = colFlag + Convert.ToString(j) + ">";
                    index      = curRow.IndexOf(curColFlag);
                    if (index > 0)
                    {
                        curCol   = curRow.Substring(0, index);
                        subindex = curRow.Length - index - curColFlag.Length;
                        curRow   = curRow.Substring(index + curColFlag.Length, subindex);
                        if (!curCol.Equals(""))
                        {
                            switch (j)
                            {
                            case 0:
                                column = new DataColumn(curCol);
                                break;

                            case 1:
                                column.Caption = curCol;
                                break;

                            case 2:
                                TableUtil.SetProperty(column, "SDPDataType", curCol);
                                column.DataType = DataTypes.ToType(Convert.ToInt32(curCol));
                                break;

                            case 3:
                                if (column.DataType.ToString().Equals("System.String"))
                                {
                                    column.MaxLength = Convert.ToInt32(curCol);
                                }
                                break;

                            case 4:
                                TableUtil.SetProperty(column, "PK", curCol);
                                hasPK = true;
                                break;
                            }
                        }
                    }
                }

                if (column != null)
                {
                    table.Columns.Add(column);
                }
            }
            if (hasPK)
            {
                TableUtil.SetProperty(table, "HasPK", hasPK ? "1" : "0");
            }
        }
コード例 #5
0
        public static bool InitTableSchemaFromDataRule(DataTable table, DataRule dr, string alias)
        {
            if (table == null || dr == null)
            {
                return(false);
            }

            try
            {
                DataTable ruletable = dr.GetFieldRule();
                if (ruletable == null)
                {
                    return(false);
                }

                DataRule olddr = TableUtil.GetDataRule(table);
                if (olddr != null)
                {
                    table.TableNewRow   -= new DataTableNewRowEventHandler(olddr.OnTableNewRow);
                    table.ColumnChanged -= new DataColumnChangeEventHandler(olddr.OnColumnChanged);
                }

                table.TableNewRow   += new DataTableNewRowEventHandler(dr.OnTableNewRow);
                table.ColumnChanged += new DataColumnChangeEventHandler(dr.OnColumnChanged);

                table.TableName = dr.RuleName;

                TableUtil.SetProperty(table, SysConstant.scDataRule, dr);
                TableUtil.SetProperty(table, SysConstant.scBindAlias, alias);
                TableUtil.SetProperty(table, SysConstant.scPageManager, new PageManager(table));

                DataColumnCollection columns = table.Columns;
                DataColumn           column;
                RuleColumn           rulecolumn;

                DataRowCollection rows = ruletable.Rows;

                if (columns.Count > 0)
                {
                    if (table.Rows.Count > 0)
                    {
                        table.Rows.Clear();
                    }

                    columns.Clear();
                }

                for (int i = 0; i < rows.Count; i++)
                {
                    rulecolumn = RuleColumn.FromDataRow(rows[i]);

                    column = new DataColumn(rulecolumn.ColumnName);

                    TableUtil.SetProperty(column, SysConstant.scRuleColumn, rulecolumn);

                    column.Caption = rulecolumn.Label;

                    column.DataType = DataTypes.ToType(rulecolumn.DataType);

                    if (rulecolumn.DataType == DataTypes.dtString)
                    {
                        column.MaxLength = rulecolumn.Size;
                    }

                    if (rulecolumn.HasDefValue)
                    {
                        column.AllowDBNull = rulecolumn.IsNullable;
                    }

                    columns.Add(column);
                }
                return(true);
            }
            catch (Exception e)
            {
                throw new Exception("SDP-ST02 填充元数据出错:" + e.Message);
            }
        }