private void lstTables_SelectedIndexChanged(object sender, EventArgs e) { //string dbPath = Variables.NewFilePath; try { myDB = dbE.OpenDatabase(Variables.NewFilePath); } catch (Exception ex) { //MessageBox.Show("Error openning database! \n" + // "File path: " + dbPath + "\n" + ex, // "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); errorMsgDB(ex.ToString()); return; } //show tables fields if (lstTables.SelectedIndices.Count <= 0) { return; } int intselectedindex = lstTables.SelectedIndices[0]; if (intselectedindex < 0) { return; } string tblName = lstTables.Text; gridTblFld.Rows.Clear(); int i = 0; //show table info try { TableDef myTable = myDB.TableDefs[tblName]; foreach (Field fldExtItem in ((Fields)myTable.Fields)) { gridTblFld.Rows.Add(1); gridTblFld.Rows[i].Cells[0].Value = fldExtItem.Name.ToString(); gridTblFld.Rows[i].Cells[1].Value = TableField.decodeFldType(fldExtItem.Type); gridTblFld.Rows[i].Cells[2].Value = fldExtItem.Size.ToString(); i++; } } catch (Exception ex) { //MessageBox.Show("Error reading database! \n" + // "File path: " + Variables.NewFilePath + "\n" + ex, // "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); errorMsgDB(ex.ToString()); return; } }
private void lstViewOpenTbl_SelectedIndexChanged(object sender, EventArgs e) { if (lstViewOpenTbl.SelectedIndices.Count <= 0) { return; } int intselectedindex = lstViewOpenTbl.SelectedIndices[0]; if (intselectedindex < 0) { return; } string tblName = lstViewOpenTbl.Items[intselectedindex].Text; gridOpenTblView.Rows.Clear(); int i = 0; //show table info try { TableDef myTable = myDB.TableDefs[tblName]; foreach (Field fldExtItem in ((Fields)myTable.Fields)) { gridOpenTblView.Rows.Add(1); gridOpenTblView.Rows[i].Cells[0].Value = fldExtItem.Name.ToString(); gridOpenTblView.Rows[i].Cells[1].Value = TableField.decodeFldType(fldExtItem.Type); gridOpenTblView.Rows[i].Cells[2].Value = fldExtItem.Size.ToString(); i++; } } catch (Exception ex) { MessageBox.Show("Error reading database! \n" + ex); return; } }
private void btnClose_Click(object sender, EventArgs e) //save and close { //saveTable button pressed - lets check the new table name and proceed: bool isTableNameUniqe = true; bool isFldCreated = false; newTableName = txtTblName.Text.Trim(); if (!Validator.isValidName(newTableName)) { txtTblName.Focus(); return; } //verify if any fields existing: if (fliItemList.Count == 0) { MessageBox.Show("There is not fields in this new table found!" + "\nSorry we can not create a table with no fields!" + "\nPlease add a field or Cancel creation process!", "Warning new Table", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //Table name verification if existing try { foreach (TableDef myTable in myDB.TableDefs) { if (myTable.Attributes == 0) { if (myTable.Name.ToUpper() == newTableName.ToUpper()) { MessageBox.Show("Can\'t create the new table! " + "\nTable : " + myTable.Name + "\nAlready existing!"); gridFields.Rows.Clear(); int i = 0; foreach (Field fldExtItem in ((Fields)myTable.Fields)) { gridFields.Rows.Add(1); gridFields.Rows[i].Cells[0].Value = fldExtItem.Name.ToString(); gridFields.Rows[i].Cells[1].Value = TableField.decodeFldType(fldExtItem.Type); gridFields.Rows[i].Cells[2].Value = fldExtItem.Size.ToString(); i++; } isTableNameUniqe = false; Variables.NewTableName = ""; grpNewTblCreate.Enabled = false; } } } if (isTableNameUniqe) { Variables.NewTableName = newTableName; //creating table object myTb = myDB.CreateTableDef(newTableName); foreach (TableField field in fliItemList) { isFldCreated = createTblField(field); //create field } myDB.TableDefs.Append(myTb); //adding table to the DataBase grpNewTblCreate.Enabled = true; } } catch (Exception ex) { MessageBox.Show("Error reading database! \n" + ex); return; } myDB.Close(); this.Close(); }
private void getTableStructure(string dbPath) { string message = ""; dbe = new DBEngine(); try { myDB = dbe.OpenDatabase(dbPath); } catch (Exception ex) { MessageBox.Show("Error openning database! \n" + ex.Message + "\n" + ex.HResult.ToString()); try { myDB.Close(); } catch (Exception exx) { MessageBox.Show("Error openning database! \n" + exx.Message + "\n" + exx.HResult.ToString()); } this.Close(); return; } message = message + ("Database Name: " + myDB.Name); try { foreach (TableDef myTable in myDB.TableDefs) { if (myTable.Attributes == 0) { lstDBStruc.Items.Add("Table : " + myTable.Name); foreach (Field fldExtItem in ((Fields)myTable.Fields)) { lstDBStruc.Items.Add("\t-Field: " + fldExtItem.Name + "\tsize: " + fldExtItem.Size + "\ttype: " + TableField.decodeFldType(fldExtItem.Type)); } //DisplayNameAttribute all the indexes (the fields that are indexed) foreach (Index idxItem in myTable.Indexes) { lstDBStruc.Items.Add("\t\t-Index: " + idxItem.Name); foreach (Field fldItem in ((IndexFields)idxItem.Fields)) { lstDBStruc.Items.Add("\t\t\t-IndexedField: " + (fldItem.Name)); } } } } } catch (Exception ex) { MessageBox.Show("Error reading database! \n" + ex); return; } try //Reading DB relations schemas { foreach (Relation myRel in myDB.Relations) { if (myRel.Attributes == 0) { lstDBStruc.Items.Add("Relation: " + myRel.Name); lstDBStruc.Items.Add("\t- Primary Table: " + myRel.Table); lstDBStruc.Items.Add("\t- Foreign Table: " + myRel.ForeignTable); foreach (Field myFl in myRel.Fields) { lstDBStruc.Items.Add("\t\t- Primary Field: " + myFl.Name); lstDBStruc.Items.Add("\t\t- Foreign Field: " + myFl.ForeignName); } } } } catch (Exception ex) { MessageBox.Show("Error reading database relations! \n" + ex); return; } }