Esempio n. 1
0
        public static bool CopyTable(DataTable src, DataTable dst)
        {
            if (src == null || dst == null)
            {
                return(false);
            }

            if (dst.Columns.Count <= 0)
            {
                CopyTableSchema(src, dst);
            }

            CopyTablePageInfo(src, dst);

            if (dst.TableName.Equals(""))
            {
                dst.TableName = src.TableName;
            }

            dst.Clear();
            TableUtil.StopConstraint(dst);
            try
            {
                dst.BeginLoadData();
                dst.ReadXml(new StringReader(TableToXml(src)));
            }
            finally
            {
                TableUtil.StartConstraint(dst);
                dst.EndLoadData();
            }
            dst.AcceptChanges();

            return(true);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public static void BindMaskedTextBox(MaskedTextBox box, DataColumn column)
        {
            if (box == null || column == null)
            {
                return;
            }

            BindingSource bs = GetBindingSource(column.Table);

            if (bs != null)
            {
                box.DataBindings.Add("Text", bs, column.ColumnName);
            }

            box.Tag    = column;
            box.Leave -= new EventHandler(ControlLeave);
            box.Leave += new EventHandler(ControlLeave);

            RuleColumn rc = TableUtil.GetRuleColumn(column);

            if (rc != null)
            {
                box.Mask = rc.Mask;
            }

            box.Text = "";
        }
Esempio n. 4
0
        public static void BindComboBox(ComboBox box, DataColumn column)
        {
            if (box == null || column == null)
            {
                return;
            }

            BindingSource bs = GetBindingSource(column.Table);

            if (bs != null)
            {
                box.DataBindings.Add("SelectedValue", bs, column.ColumnName);
            }

            box.Tag    = column;
            box.Leave -= new EventHandler(ControlLeave);
            box.Leave += new EventHandler(ControlLeave);

            RuleColumn rcolumn = TableUtil.GetRuleColumn(column);

            if (rcolumn != null)
            {
                InitComboBox(box, rcolumn);
            }
            else
            {
                box.ValueMember   = column.ColumnName;
                box.DisplayMember = column.ColumnName;
                box.Text          = "";
            }
        }
Esempio n. 5
0
        public static void BindControls(Control container, DataTable table, bool searchChildren, string alias)
        {
            if (container == null || table == null)
            {
                return;
            }

            DataColumnCollection columns = table.Columns;

            if (columns != null && columns.Count > 0)
            {
                ResetLabels(container, alias);

                Control[]  ctrls;
                DataColumn column;
                RuleColumn rc;
                int        editIndex;
                for (int i = 0; i < columns.Count; i++)
                {
                    column = columns[i];
                    rc     = TableUtil.GetRuleColumn(column);

                    if (rc != null && !rc.EditCtrlVision)
                    {
                        continue;
                    }

                    editIndex = (rc != null ? rc.EditIndex : i + 1);

                    ctrls = FindControls(container, "label", alias, editIndex, column.ColumnName, searchChildren);
                    if (ctrls != null && ctrls.Length > 0)
                    {
                        foreach (Control ctrl in ctrls)
                        {
                            ctrl.Text = column.Caption + ":";
                        }
                    }

                    ctrls = FindControls(container, "commonEditBox,textBox,checkBox,comboBox,dateTimePicker,richTextBox,pictureBox", alias, editIndex, column.ColumnName, searchChildren);
                    if (ctrls != null && ctrls.Length > 0)
                    {
                        foreach (Control ctrl in ctrls)
                        {
                            BindControl(ctrl, column);
                        }
                    }
                }

                ctrls = FindControls(container, "dataGridView", alias, 1, table.TableName, searchChildren);
                if (ctrls != null && ctrls.Length > 0)
                {
                    foreach (Control ctrl in ctrls)
                    {
                        InitDataGridViewColumns(ctrl as DataGridView, table);
                    }
                }
            }
        }
Esempio n. 6
0
        public static void MoveNextPage(DataTable table)
        {
            PageManager pm = TableUtil.GetPageManager(table);

            if (pm != null)
            {
                pm.MoveNextPage();
            }
        }
Esempio n. 7
0
        public static void CopyTablePageInfo(DataTable src, DataTable dst)
        {
            PageManager pm = TableUtil.GetPageManager(dst);

            if (pm != null)
            {
                pm.SetPageInfo(TableUtil.GetPageInfo(src));
            }
        }
Esempio n. 8
0
        public static bool QueryTable(DataTable table, string parameter)
        {
            PageManager pm = TableUtil.GetPageManager(table);

            if (pm != null)
            {
                return(pm.LoadData(parameter));
            }
            else
            {
                return(false);
            }
        }
Esempio n. 9
0
        public static bool MoveToPage(DataTable table, int page)
        {
            PageManager pm = TableUtil.GetPageManager(table);

            if (pm != null)
            {
                return(pm.MoveToPage(page));
            }
            else
            {
                return(false);
            }
        }
Esempio n. 10
0
        public static bool RefreshTable(DataTable table)
        {
            PageManager pm = TableUtil.GetPageManager(table);

            if (pm != null)
            {
                return(pm.RefreshData());
            }
            else
            {
                return(false);
            }
        }
Esempio n. 11
0
        public static void BindDateTimePicker(DateTimePicker picker, DataColumn column)
        {
            if (picker == null || column == null || !column.DataType.ToString().Equals("System.DateTime"))
            {
                return;
            }

            BindingSource bs = GetBindingSource(column.Table);

            if (bs != null)
            {
                picker.DataBindings.Add("Text", bs, column.ColumnName);
            }

            picker.Tag    = column;
            picker.Leave -= new EventHandler(ControlLeave);
            picker.Leave += new EventHandler(ControlLeave);

            if (picker.CustomFormat == null || picker.CustomFormat.Equals(""))
            {
                RuleColumn rcolumn = TableUtil.GetRuleColumn(column);
                if (rcolumn != null)
                {
                    switch (rcolumn.DataType)
                    {
                    case DataTypes.dtDateTime:
                        picker.CustomFormat = "yyyy-MM-dd HH:mm:ss";
                        break;

                    case DataTypes.dtDate:
                        picker.CustomFormat = "yyyy-MM-dd";
                        break;

                    case DataTypes.dtTime:
                        picker.CustomFormat = "HH:mm:ss";
                        break;

                    default:
                        return;
                    }
                    picker.Format = DateTimePickerFormat.Custom;
                }
            }
        }
Esempio n. 12
0
        public static DataTable BuildTable(string tablename, string data, int offset, int length)
        {
            string    tableType, pageInfo, curData = data;
            DataTable table = null;

            int index = curData.IndexOf("<DataTable Name=");

            if (index >= 0)
            {
                string td = curData.Remove(0, index + 16);
                if (tablename.Equals(""))
                {
                    index     = td.IndexOf(" Type=");
                    tablename = td.Substring(0, index);
                }

                table = new DataTable(tablename);

                index     = td.IndexOf(" Type=");
                curData   = td.Remove(0, index + 6);
                index     = curData.IndexOf(">");
                tableType = curData.Substring(0, index).Trim();

                index    = curData.IndexOf("<Page>");
                td       = curData.Remove(0, index + 6);
                index    = td.IndexOf("</Page>");
                pageInfo = td.Substring(0, index);
                //table.SetPageInfo(pageInfo);
                TableUtil.SetPageInfo(table, pageInfo);

                if (tableType.Equals("STR"))
                {
                    FillTableFromStr(table, td, offset, length);
                }
                else if (tableType.Equals("XML"))
                {
                    index   = td.IndexOf("<XMLData>");
                    curData = td.Remove(0, index + 9);
                    index   = curData.IndexOf("</XMLData>");
                    //JDOMUtil.fillTableFromXml(table, curData.Substring(0,index), offset, length);
                }
            }
            return(table);
        }
Esempio n. 13
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);
            }
        }
Esempio n. 14
0
        public static void BindCheckBox(CheckBox box, DataColumn column)
        {
            if (box == null || column == null || !column.DataType.ToString().Equals("System.Boolean"))
            {
                return;
            }

            BindingSource bs = GetBindingSource(column.Table);

            if (bs != null)
            {
                box.DataBindings.Add("Checked", bs, column.ColumnName);
            }

            box.Tag    = column;
            box.Leave -= new EventHandler(ControlLeave);
            box.Leave += new EventHandler(ControlLeave);

            if (box.Name.Equals("") || box.Name.StartsWith("checkBox"))
            {
                RuleColumn rcolumn = TableUtil.GetRuleColumn(column);
                if (rcolumn != null)
                {
                    box.Text = rcolumn.Label;

                    string    labelname = box.Name.Replace("checkBox", "label");
                    Control[] ctrls     = box.Parent is CommonEditBox?box.Parent.Parent.Controls.Find(labelname, false) : box.Parent.Controls.Find(labelname, false);

                    if (ctrls.Length > 0)
                    {
                        ctrls[0].Text = "";
                    }
                }
            }

            box.Checked = false;
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
        public static void InitDataGridViewColumns(DataGridView grid, DataTable table)
        {
            if (grid == null || table == null)
            {
                return;
            }

            //if (grid.Columns.Count > 0)
            //    grid.Columns.Clear();

            if (grid.Columns.Count == 0)
            {
                grid.EditingControlShowing -= new DataGridViewEditingControlShowingEventHandler(DataGridViewEditingControlShowing);
                grid.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(DataGridViewEditingControlShowing);

                DataRule dr = TableUtil.GetDataRule(table);
                if (dr != null)
                {
                    DataColumnCollection columns = table.Columns;
                    if (columns.Count > 0)
                    {
                        DataGridViewColumn gcolumn;
                        RuleColumn         rcolumn;
                        foreach (DataColumn column in columns)
                        {
                            rcolumn = TableUtil.GetRuleColumn(column);
                            if (rcolumn != null)
                            {
                                gcolumn = CreateDataGridViewColumn(rcolumn);
                                grid.Columns.Add(gcolumn);
                            }
                            else
                            {
                                InitDataGridViewColumns(grid, dr);
                                break;
                            }
                        }
                    }
                    else
                    {
                        InitDataGridViewColumns(grid, dr);
                    }
                }
                else if (table.Columns.Count > 0)
                {
                    DataGridViewColumn gcolumn;

                    foreach (DataColumn column in table.Columns)
                    {
                        if (TableUtil.StrProperty(column, "Visible").Equals("0"))
                        {
                            continue;
                        }

                        gcolumn = null;

                        string datatype = column.DataType.ToString();

                        if (datatype.Equals("System.Boolean"))
                        {
                            gcolumn              = new DataGridViewCheckBoxColumn();
                            gcolumn.Width        = column.MaxLength > 50 ? column.MaxLength : 50;
                            gcolumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                        }
                        else if (datatype.Equals("System.DateTime"))
                        {
                            gcolumn              = new CalendarColumn("yyyy-MM-dd HH:mm:ss");
                            gcolumn.Width        = 130;
                            gcolumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                        }
                        else
                        {
                            string mapInfo = TableUtil.StrProperty(column, "MapInfo");
                            if (!mapInfo.Equals(""))
                            {
                                DataMap dm = SystemContext.MapManager.FromMapInfo(mapInfo);
                                if (dm != null)
                                {
                                    DataTable mtable = dm.GetMapTable(null);
                                    if (mtable != null && mtable.Rows.Count > 0)
                                    {
                                        gcolumn = new DataGridViewComboBoxColumn();
                                        DataGridViewComboBoxCell combboxcell = gcolumn.CellTemplate as DataGridViewComboBoxCell;
                                        if (combboxcell != null)
                                        {
                                            combboxcell.DataSource    = mtable;
                                            combboxcell.ValueMember   = "Key";
                                            combboxcell.DisplayMember = "Value";
                                        }
                                    }
                                }
                            }

                            if (gcolumn == null)
                            {
                                gcolumn              = new DataGridViewTextBoxColumn();
                                gcolumn.Width        = column.MaxLength > 100 ? column.MaxLength : 100;
                                gcolumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                            }
                        }

                        gcolumn.Name             = column.ColumnName;
                        gcolumn.HeaderText       = column.Caption;
                        gcolumn.DataPropertyName = column.ColumnName;

                        //gcolumn.Width = column.MaxLength;
                        //gcolumn.Width = column.MaxLength > 100 ? column.MaxLength : 100;

                        //gcolumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;

                        grid.Columns.Add(gcolumn);
                    }
                }

                grid.AutoGenerateColumns = false;
                grid.DataSource          = GetBindingSource(table);
            }
            else
            {
                DataColumn column;
                string     mapInfo;
                foreach (DataGridViewColumn gcolumn in grid.Columns)
                {
                    column = table.Columns[gcolumn.DataPropertyName];
                    if (column != null)
                    {
                        mapInfo = TableUtil.StrProperty(column, "MapInfo");
                        if (!mapInfo.Equals(""))
                        {
                            DataMap dm = SystemContext.MapManager.FromMapInfo(mapInfo);
                            if (dm != null)
                            {
                                DataTable mtable = dm.GetMapTable(null);
                                if (mtable != null && mtable.Rows.Count > 0)
                                {
                                    DataGridViewComboBoxCell combboxcell = gcolumn.CellTemplate as DataGridViewComboBoxCell;
                                    if (combboxcell != null)
                                    {
                                        combboxcell.DataSource    = mtable;
                                        combboxcell.ValueMember   = "Key";
                                        combboxcell.DisplayMember = "Value";
                                    }
                                }
                            }
                        }
                    }
                }

                grid.AutoGenerateColumns = false;
                grid.DataSource          = GetBindingSource(table);
            }

            grid.CellLeave -= new DataGridViewCellEventHandler(DataGridView_CellLeave);
            grid.CellLeave += new DataGridViewCellEventHandler(DataGridView_CellLeave);
        }
Esempio n. 17
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);
            }
        }
Esempio n. 18
0
 public static void BindControls(Control container, DataTable table, bool searchChildren)
 {
     BindControls(container, table, searchChildren, TableUtil.GetBindAlias(table));
 }
Esempio n. 19
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");
            }
        }
Esempio n. 20
0
        private static void FillTableData(DataTable table, string body, int offset, int length)
        {
            string            colFlag = "<F", curColFlag, curRow, curCol, curBody = body;
            DataRowCollection datarows = table.Rows;
            DataRow           row      = null;

            DataColumnCollection columns = table.Columns;
            DataColumn           column;
            int sdpDataType = 0;

            int index, subindex;

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

            table.Clear();
            if (offset < 0)
            {
                offset = 0;
            }
            if (length < 0)
            {
                length = rows.Length - offset;
            }

            int limit = offset + length >= rows.Length ? rows.Length : offset + length;

            for (int i = 0; i < length; i++)
            {
                if (offset + i >= limit)
                {
                    break;
                }

                curRow = rows[offset + i];
                if (curRow.Equals(""))
                {
                    continue;
                }
                curRow = StrUtil.ReplaceStr(curRow, SignConstant.RowReplace, SignConstant.RowSign);

                row = table.NewRow();
                for (int j = 0; j < columns.Count; 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(""))
                        {
                            curCol      = StrUtil.ReplaceStr(curCol, SignConstant.FieldReplace, SignConstant.FieldSign);
                            column      = columns[j];
                            sdpDataType = TableUtil.IntProperty(column, "SDPDataType");

                            if (sdpDataType == 0)
                            {
                                sdpDataType = DataTypes.ToDataType(column.DataType);
                            }

                            switch (sdpDataType)
                            {
                            case DataTypes.dtBLOB:
                                row[j] = BCUtil.Decode(curCol);
                                break;

                            case DataTypes.dtCLOB:
                                row[j] = StrUtil.FromByteArray(BCUtil.Decode(curCol));
                                break;

                            case DataTypes.dtXMLType:
                                row[j] = StrUtil.FromByteArray(BCUtil.Decode(curCol));
                                break;

                            case DataTypes.dtBoolean:
                                row[j] = curCol.Equals("1") ? true : false;
                                break;

                            //case DataTypes.dtDateTime:
                            //    row[j] = Convert.ToDateTime(curCol);
                            //    break;
                            //case DataTypes.dtDate:
                            //    row[j] = Convert.ToDateTime(curCol);
                            //    break;
                            //case DataTypes.dtTime:
                            //    row[j] = Convert.ToDateTime(curCol);
                            //    break;
                            default:
                                row[j] = curCol;
                                break;
                            }
                        }
                    }
                }
                datarows.Add(row);
            }
            if (length > 0)
            {
                table.AcceptChanges();
            }
        }