private void cmdGenerate_Click(object sender, EventArgs e) { foreach (DataGridViewRow aRow in dgvColumns.Rows) { MappingGeneratorDataItem mgdi = (MappingGeneratorDataItem)aRow.Cells["colMappingGeneratorItem"].Value; data_mapping_field _workingObject = new data_mapping_field(); if ((!mgdi.Exists) && (mgdi.Map_Field)) { // Create a mapping field _workingObject = new data_mapping_field(); _workingObject.table_name = mgdi.Table_Name; _workingObject.field_name = mgdi.Field_Name; _workingObject.field_type = mgdi.Field_Type; _workingObject.Save(); } else if (mgdi.Exists && !mgdi.Map_Field) { // Remove a mapping field _workingObject = mgdi.ExistingMapping; _workingObject.Delete(); } } MessageBox.Show(this, "The requested changes have been processed.", "Operation Complete"); Close(); }
public frmGenerateMappings() { InitializeComponent(); _existingFields = new List <data_mapping_field>(); _workingObject = new data_mapping_field(); _generatedFields = new List <MappingGeneratorDataItem>(); MappingGeneratorDataItem _workingItem; // Get existing data mappings DataTable allFields = _workingObject.Search(_workingObject.SearchSQL + " ORDER BY table_name, field_name"); foreach (DataRow aRow in allFields.Rows) { _workingObject = new data_mapping_field(); _workingObject.Load(aRow); _existingFields.Add(_workingObject); } for (int i = 0; i < 4; i++) { string tableName; switch (i) { case 0: tableName = "claims"; break; case 1: tableName = "companies"; break; case 2: tableName = "company_contact_info"; break; case 3: tableName = "procedures"; break; default: throw new Exception("Unitialized table in generate mappings."); } // Retrieve column information // Use Connection object for the DataAdapter to retrieve all tables from selected Database DataTable columnsTable = _workingObject.Search("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + tableName + "' ORDER BY Column_Name"); foreach (DataRow aColumn in columnsTable.Rows) { _workingItem = new MappingGeneratorDataItem(); _workingItem.Table_Name = tableName; _workingItem.Field_Name = aColumn["Column_Name"].ToString(); _workingItem.Field_Type = aColumn["Data_Type"].ToString(); _workingItem.ExistingMapping = _existingFields.Find(delegate(data_mapping_field dmf) { return((dmf.table_name == _workingItem.Table_Name) && (dmf.field_name == _workingItem.Field_Name)); }); _workingItem.Exists = _workingItem.ExistingMapping != null; _workingItem.Map_Field = _workingItem.Exists; _generatedFields.Add(_workingItem); } } }