Exemplo n.º 1
0
        private string ToXML(ITableAdaptor dataTableAdaptor, int id,string tab)
        {
            var sb = new StringBuilder();
            DataTable dataTable =  dataTableAdaptor.GetTable();
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                if (id > -1)
                {
                    int currentId;
                    int.TryParse(dataTable.Rows[i].ItemArray[0].ToString(), out currentId);
                    if (currentId != id)
                    {
                        continue;
                    }
                }
                for (int j = 0; j < dataTable.Columns.Count; j++)
                {
                    if (j>0 && dataTable.Columns[j].DataType == typeof (decimal))
                    {
                        sb.Append(tab+"<" + dataTable.Columns[j].ColumnName + ">\n");
                
                        object objo =
                            dataTableAdaptor.GetItem().UnderlyingSystemType.GetProperty(
                                dataTable.Columns[j].ColumnName);
                        if (objo != null)
                        {
                            ITableAdaptor dataTableAdaptorChild =
                                new MySqlTableAdaptor(((PropertyInfo) objo).PropertyType);
                            int idToFind;
                            int.TryParse(dataTable.Rows[i].ItemArray[j].ToString(), out idToFind);
                            string childXml = ToXML(dataTableAdaptorChild, idToFind,tab+"\t");
                            sb.Append(childXml);

                        }
                        sb.Append(tab+"</" + dataTable.Columns[j].ColumnName + ">\n");
                    }
                    else
                    {
                        sb.Append(tab+"<" + dataTable.Columns[j].ColumnName + ">" + dataTable.Rows[i].ItemArray[j] + "</" + dataTable.Columns[j].ColumnName + ">\n");
                
                    }
                }
            }

            string result = sb.ToString();
            return result;
        }
Exemplo n.º 2
0
        public Form1(Type tableType)
        {
            InitializeComponent();
            this.bindingSource1.DataSource = tableType.GetType();
            bindingSource1.DataSourceChanged += bindingSource1_DataSourceChanged;
            System.Type yy = tableType.GetType();
            this.Text = tableType.Name+"s";
            dataTableAdaptor = new MySqlTableAdaptor(tableType);
            dataTable = dataTableAdaptor.GetTable();
            
            dataGridView1.Columns.Clear();
            int position = 3;

            this.tabPage2.SuspendLayout();
            this.tabPage3.SuspendLayout();
            
            for (int i = 1; i < dataTable.Columns.Count; i++)
            {
                DataGridViewColumn dataGridViewColumn = new DataGridViewColumn();
                DataGridViewCell dataGridViewCell = null;
                if (dataTable.Columns[i].DataType == typeof(decimal))
                {
                    dataGridViewCell = new FormatedBindCell();
                    //((FormatedBindCell)dataGridViewCell).InitializecatTableAdaptor(dataTableAdaptor);
                }
                else
                {
                    dataGridViewCell = new DataGridViewTextBoxCell();
                }
                dataGridViewColumn.DataPropertyName = dataTable.Columns[i].ColumnName;
                dataGridViewColumn.HeaderText = dataTable.Columns[i].ColumnName;
                dataGridViewColumn.CellTemplate = dataGridViewCell;
                dataGridViewColumn.Name = dataTable.Columns[i].ColumnName;
                dataGridView1.Columns.Add(dataGridViewColumn);



                if (dataTable.Columns[i].DataType == typeof(decimal))
                {

                    DataWraper dataWrapper = null;
                    object objo = ((Type)dataTableAdaptor.GetItem()).UnderlyingSystemType.GetProperty(dataTable.Columns[i].ColumnName);
                    if (objo != null)
                    {
                        dataWrapper = new DataWraper(((PropertyInfo)objo).PropertyType, bindingSource1, errorProvider1);//.MemberType.GetType();
                        dataGridViewColumn.Tag = new MySqlTableAdaptor(((PropertyInfo)objo).PropertyType);
                    
                    dataWrapper.Location = new System.Drawing.Point(6, position);
                    tabPage2.Controls.Add(dataWrapper);
                    }
                }
                else
                {
                    Button button1 = new Button();
                    Button button2 = new Button();
                    TextBox textBox1 = new TextBox();
                    Label label1 = new Label();

                    label1.AutoSize = true;
                    label1.Location = new System.Drawing.Point(6, position + 6);
                    label1.Name = dataTable.Columns[i].ColumnName + "Label";
                    label1.Size = new System.Drawing.Size(46, 13);
                    label1.TabIndex = 0;
                    label1.Text = dataTable.Columns[i].ColumnName; ;
                    // 
                    // textBox1
                    // 
                    textBox1.Location = new System.Drawing.Point(80, position + 3);
                    textBox1.Name = dataTable.Columns[i].ColumnName + "TextBox";
                    textBox1.Size = new System.Drawing.Size(111, 20);
                    textBox1.TabIndex = 1;
                    textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", bindingSource1, dataTable.Columns[i].ColumnName));
                    this.tabPage2.Controls.Add(textBox1);
                    this.tabPage2.Controls.Add(label1);
                }

                SimulationBand dataSimulator = null;
                dataSimulator = new SimulationBand();

                dataSimulator.Location = new System.Drawing.Point(6, position * 5);
                dataSimulator.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            
                tabPage3.Controls.Add(dataSimulator);

                position += 28;
            }


            this.tabPage2.ResumeLayout(false);
            this.tabPage2.PerformLayout();

            this.tabPage3.ResumeLayout(false);
            this.tabPage3.PerformLayout();

            bindingSource1.DataSource = dataTable;
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.ReadOnly = true;
            dataGridView1.DataSource = bindingSource1;

            
            this.tabControl1.DrawMode =
                    TabDrawMode.OwnerDrawFixed;
            this.tabControl1.DrawItem +=
                new DrawItemEventHandler(PageTab_DrawItem);
            this.tabControl1.Selecting +=
                new TabControlCancelEventHandler(PageTab_Selecting);
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

            dataGridView1.DoubleClick += new System.EventHandler(dataGridView1_DoubleClick);
            dataGridView1.SelectionChanged += new EventHandler(dataGridView1_SelectionChanged);
            dataTable.ColumnChanged += new DataColumnChangeEventHandler(HELP_ColumnChanged);
            //dataGridView1.Columns[1]..Format += new ConvertEventHandler(Form1_Format);
        }