private void button3_Click(object sender, EventArgs e) { Insert insert = new Insert(); this.Hide(); insert.Show(); }
private void button1_Click(object sender, EventArgs e) { KeyValue keyValue = new KeyValue(); KeyValue kvuk = new KeyValue(); KeyValue kvfknew = new KeyValue(); string tableName = comboBox2.SelectedItem.ToString(); string databaseName = comboBox1.SelectedItem.ToString(); foreach (Control control in this.Controls) { if (control.GetType().Name == "TextBox") { List<PrimaryKey> pkeys = DataLayer.Configuration.GetPrimaryKey(tableName); if (pkeys.Count(x => x.Key == control.Name) > 0) { bool exists = DataLayer.DataAccess.CheckRestriction(databaseName, tableName, control.Text); if (!exists) { MessageBox.Show("The primary key " + control.Name + " already exists!"); return; } } List<UniqueKey> ukeys = DataLayer.Configuration.GetUniqueKeys(tableName); if (ukeys.Count(x => x.Key == control.Name) > 0) { bool exists = DataLayer.DataAccess.CheckRestriction(databaseName, tableName, "uk", control.Text); if (exists) { MessageBox.Show("The unique key " + control.Name + " already exists!"); return; } } List<ForeignKey> fkeys = DataLayer.Configuration.GetForeignKeys(tableName); if (fkeys != null && fkeys.Count(x => x.Key == control.Name) > 0) { ForeignKey fkey = fkeys.FirstOrDefault(x => x.Key == control.Name); bool exists = DataLayer.DataAccess.CheckRestriction(databaseName, fkey, control.Text); if (!exists) { MessageBox.Show("The foreign key " + control.Name + " : " + control.Text + " does not exists!"); return; } } if (pkeys.Count(x => x.Key == control.Name) > 0) { keyValue.key += control.Text; keyValue.key += "#"; } else { keyValue.value += control.Text; keyValue.value += "#"; } if (ukeys.Count(x => x.Key == control.Name) > 0) { kvuk.key += control.Text; kvuk.key += "#"; } else if (pkeys.Count(x => x.Key == control.Name) > 0 && ukeys.Count > 0) { kvuk.value += control.Text; kvuk.value += "#"; } if (fkeys != null && fkeys.Count(x => x.Key == control.Name) > 0 && fkeys.Count > 0) { kvfknew.key += control.Text; } else if (pkeys.Count(x => x.Key == control.Name) > 0) { kvfknew.value = control.Text; } } } if (!string.IsNullOrEmpty(keyValue.key)) { keyValue.key = keyValue.key.Remove(keyValue.key.Length - 1, 1); } if (keyValue.value != null && keyValue.value.Length > 0) { keyValue.value = keyValue.value.Remove(keyValue.value.Length - 1, 1); } if (!string.IsNullOrEmpty(kvuk.key)) { kvuk.key = kvuk.key.Remove(kvuk.key.Length - 1, 1); } if (kvuk.value != null && kvuk.value.Length > 0) { kvuk.value = kvuk.value.Remove(kvuk.value.Length - 1, 1); } DataLayer.DataAccess.InsertInTable(comboBox1.SelectedItem.ToString(), tableName, keyValue); if (kvuk.key != null) DataLayer.DataAccess.InsertInTable(comboBox1.SelectedItem.ToString(), tableName + "uk", kvuk); if (kvfknew.key != null) DataLayer.DataAccess.UpdateExistingFK(databaseName, tableName, kvfknew); // DataLayer.DataAccess.InsertInTable(comboBox1.SelectedItem.ToString(), tableName + "fk", kvfk); MessageBox.Show("Value added successfully !"); Insert insert = new Insert(); this.Dispose(); insert.Show(); }
private void button1_Click(object sender, EventArgs e) { KeyValue keyValue = new KeyValue(); KeyValue kvuk = new KeyValue(); KeyValue kvfknew = new KeyValue(); string tableName = comboBox2.SelectedItem.ToString(); string databaseName = comboBox1.SelectedItem.ToString(); foreach (Control control in this.Controls) { if (control.GetType().Name == "TextBox") { List <PrimaryKey> pkeys = DataLayer.Configuration.GetPrimaryKey(tableName); if (pkeys.Count(x => x.Key == control.Name) > 0) { bool exists = DataLayer.DataAccess.CheckRestriction(databaseName, tableName, control.Text); if (!exists) { MessageBox.Show("The primary key " + control.Name + " already exists!"); return; } } List <UniqueKey> ukeys = DataLayer.Configuration.GetUniqueKeys(tableName); if (ukeys.Count(x => x.Key == control.Name) > 0) { bool exists = DataLayer.DataAccess.CheckRestriction(databaseName, tableName, "uk", control.Text); if (exists) { MessageBox.Show("The unique key " + control.Name + " already exists!"); return; } } List <ForeignKey> fkeys = DataLayer.Configuration.GetForeignKeys(tableName); if (fkeys != null && fkeys.Count(x => x.Key == control.Name) > 0) { ForeignKey fkey = fkeys.FirstOrDefault(x => x.Key == control.Name); bool exists = DataLayer.DataAccess.CheckRestriction(databaseName, fkey, control.Text); if (!exists) { MessageBox.Show("The foreign key " + control.Name + " : " + control.Text + " does not exists!"); return; } } if (pkeys.Count(x => x.Key == control.Name) > 0) { keyValue.key += control.Text; keyValue.key += "#"; } else { keyValue.value += control.Text; keyValue.value += "#"; } if (ukeys.Count(x => x.Key == control.Name) > 0) { kvuk.key += control.Text; kvuk.key += "#"; } else if (pkeys.Count(x => x.Key == control.Name) > 0 && ukeys.Count > 0) { kvuk.value += control.Text; kvuk.value += "#"; } if (fkeys != null && fkeys.Count(x => x.Key == control.Name) > 0 && fkeys.Count > 0) { kvfknew.key += control.Text; } else if (pkeys.Count(x => x.Key == control.Name) > 0) { kvfknew.value = control.Text; } } } if (!string.IsNullOrEmpty(keyValue.key)) { keyValue.key = keyValue.key.Remove(keyValue.key.Length - 1, 1); } if (keyValue.value != null && keyValue.value.Length > 0) { keyValue.value = keyValue.value.Remove(keyValue.value.Length - 1, 1); } if (!string.IsNullOrEmpty(kvuk.key)) { kvuk.key = kvuk.key.Remove(kvuk.key.Length - 1, 1); } if (kvuk.value != null && kvuk.value.Length > 0) { kvuk.value = kvuk.value.Remove(kvuk.value.Length - 1, 1); } DataLayer.DataAccess.InsertInTable(comboBox1.SelectedItem.ToString(), tableName, keyValue); if (kvuk.key != null) { DataLayer.DataAccess.InsertInTable(comboBox1.SelectedItem.ToString(), tableName + "uk", kvuk); } if (kvfknew.key != null) { DataLayer.DataAccess.UpdateExistingFK(databaseName, tableName, kvfknew); } // DataLayer.DataAccess.InsertInTable(comboBox1.SelectedItem.ToString(), tableName + "fk", kvfk); MessageBox.Show("Value added successfully !"); Insert insert = new Insert(); this.Dispose(); insert.Show(); }