private void toolStripMenuItemconnect_Click(object sender, EventArgs e) { if (labelselectedproj.Text != "") { greenapple.Properties.Settings.Default.server = toolStripTextBoxserver.Text; greenapple.Properties.Settings.Default.database = toolStripTextBoxdatabase.Text; greenapple.Properties.Settings.Default.user = toolStripTextBoxuser.Text; greenapple.Properties.Settings.Default.password = toolStripTextBoxpassword.Text; greenapple.Properties.Settings.Default.Save(); //get the names of all the tables of the database into a Datatable DataTable dat = new Connectoperations().showDatabaseTables(); //a loop to put items in the table into the listview int i = 1; listView1.Items.Clear(); foreach (DataRow row in dat.Rows) { //an instance of a lisviewitem ListViewItem lv = new ListViewItem((i++).ToString()); lv.SubItems.Add(row[0].ToString()); //add the lisviewitem to listview1 listView1.Items.Add(lv); //table controls } loadRelations(); } else { MessageBox.Show("Select a Project"); } string path = ""; path = Directory.GetCurrentDirectory() + "\\" + myproject.selectedProject + "\\" + myproject.selectedProject + "\\controls.xml"; DataSet ds = new DataSet(); try { tableControls.Clear(); ds.ReadXml(path); foreach (DataTable tab in ds.Tables) { ClassTableControls ctc = new ClassTableControls(); ctc.controls = new List<string>(); foreach (DataRow row in tab.Rows) { string controlName = row[0].ToString(); ctc.controls.Add(controlName); ctc.tablename = tab.TableName; } tableControls.Add(ctc); } } catch { } }
void saveToControlList() { ClassTableControls ctc = new ClassTableControls(); ctc.controls = new List<string>(); ctc.tablename = myproject.selectedTable; int i = 0; foreach (DataGridViewRow row in dataGridView1.Rows) { int rowcount = dataGridView1.Rows.Count - 1; if (i < rowcount) { string control = row.DataGridView[6, i].Value.ToString(); ctc.controls.Add(control); } i++; } //loop to check if the table is present for (int x = 0; x < tableControls.Count; x++) { if (tableControls[x].tablename == ctc.tablename) { //table already exist so remove it before adding tableControls.Remove(tableControls[x]); } } //table doesnt exist so lets party and add it tableControls.Add(ctc); }