public void delete(object sender, EventArgs e) { try { if (!checkView()) { throw new Exception(); } DbInterface.open(); lblStatus.Text = "Begin Query"; string tab = tab_table[tabControl1.SelectedTab]; string query = DELETE.query[tab]; Dictionary <string, string> args = getArgs(UPDATE, tab); lblStatus.Text = "Querying"; DbInterface.Query(query, args); lblStatus.Text = "Query Successful"; DbInterface.close(); int row = view.dataGridView1.CurrentCell.RowIndex; read(tabControl1.SelectedTab, null); view.dataGridView1.CurrentCell = view.dataGridView1.Rows[row].Cells[0]; if (row != 0) { view.dataGridView1[0, 0].Selected = false; } view.dataGridView1_CellClick(null, new DataGridViewCellEventArgs(0, row)); } catch (Exception ex) { DbInterface.close(); lblStatus.Text = "Query failed"; } }
public void create(object sender, EventArgs e) { try { if (!checkView()) { throw new Exception(); } DbInterface.open(); lblStatus.Text = "Begin Query"; string tab = tab_table[tabControl1.SelectedTab]; string query = CREATE.query[tab]; Dictionary <string, string> args = getArgs(UPDATE, tab); lblStatus.Text = "Querying"; DbInterface.Query(query, args); lblStatus.Text = "Query Successful"; DbInterface.close(); read(tabControl1.SelectedTab, null); } catch (Exception ex) { DbInterface.close(); lblStatus.Text = "Query failed"; } }
public static bool attemp_login(string uname, string pass) { DbInterface.open(); Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("@uname", uname); args.Add("@pass", pass); string[][] count = DbInterface.returnQuery(" SELECT * FROM user WHERE username = @uname AND password = @pass ", args); if (count.Length > 0) { isAllowedLogin = true; } else { isAllowedLogin = false; } DbInterface.close(); return(isAllowedLogin); }
private void read(object sender, EventArgs e) { try { if (!checkView()) { throw new Exception(); } tab_action[tabControl1.SelectedTab](); DbInterface.open(); lblStatus.Text = "Begin Query"; string tab = tab_table[tabControl1.SelectedTab]; string query = READ.query[tab]; lblStatus.Text = "Querying"; string[][] data = DbInterface.returnQuery(query); lblStatus.Text = "Query Successful"; lblStatus.Text = "get table data"; DbInterface.close(); DbInterface.open(); string[] column = DbInterface.getColumn(tab); lblStatus.Text = "Populating table"; DataTable dt = new DataTable(); foreach (string s in column) { dt.Columns.Add(new DataColumn(s)); } foreach (string[] s in data) { dt.Rows.Add(s); } view.dataGridView1.DataSource = dt; foreach (DataGridViewColumn c in view.dataGridView1.Columns) { c.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } DbInterface.close(); } catch (Exception ex) { DbInterface.close(); lblStatus.Text = "Query Failed"; } }