Exemple #1
0
        // datagridview1 cell value changed event. Creates an object to store the index of cell, and data.
        // stores the data in the Table class.
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            string primaryKey = null;
            string colType    = null;

            List <PrimaryKey> primaryKeys = ts.PrimaryKeyList;
            List <UniqueKey>  uniqueKeys  = ts.UniqueKeyList;

            try
            {
                object objId   = dataGridView1.Rows[e.RowIndex].Cells[0].Value;
                object objName = dataGridView1.Columns[e.ColumnIndex].Name;
                object value   = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;

                int    id   = Convert.ToInt32(objId);
                string name = objName.ToString();

                string schema    = treeView1.SelectedNode.Parent.Name;
                string tableName = treeView1.SelectedNode.Text;

                //TODO: There is an issue with the way the primary key is determined for different tables it works or doesn't work.
                foreach (PrimaryKey pk in primaryKeys)
                {
                    if (pk.TableName == tableName)
                    {
                        // this may only work for my specific database to dtermine the primaryKey.
                        // it works because primaryKey the correct columnName for the primaryKey always seems to be the first one returned by GetSchema("IndexInfo")
                        if (primaryKey == null)
                        {
                            primaryKey = pk.FieldName;
                        }
                    }
                }

                foreach (Columns c in cols)
                {
                    if (c.TableName == tableName && c.FieldName == name)
                    {
                        colType = c.ColumnType;
                    }
                }

                CellChange change = new CellChange(id, name, value, schema, tableName, primaryKey, colType);
                t.AddChange(change);

                //MessageBox.Show("colindex" + e.ColumnIndex.ToString());
                //MessageBox.Show("rowindex" + e.RowIndex.ToString());
                //MessageBox.Show("Column Name: " + dataGridView1.Columns[e.ColumnIndex].Name);
                //MessageBox.Show("New Value:  " + dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
                //MessageBox.Show("Primary Key ID# " + dataGridView1.Rows[e.RowIndex].Cells[0].Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #2
0
 public void AddChange(CellChange change) // add a cell to be changed to the changes list
 {
     changes.Add(change);
 }