private void btnCreateDocu_Click(object sender, EventArgs e) { if (txt_titleDocu.Text != "") { dbCommand("", "createDocuTitle", "insert into document_table(title) values ('" + txt_titleDocu.Text + "')"); dbCommand("", "getDocuId", "select id from document_table where title ='" + txt_titleDocu.Text + "'"); txt_titleDocu.Text = ""; docuForm manageDocu = new docuForm(); manageDocu.Show(); } else { MessageBox.Show("Fill all the blanks."); } }
public void dbCommand(string module, string specialAction, string qry) { try { conn = new MySqlConnection(cs); conn.Open(); query = conn.CreateCommand(); query.CommandText = qry; if (module == "" && specialAction == "addUser") { adapt = new MySqlDataAdapter(query); dataTable = new DataTable(); adapt.Fill(dataTable); if (dataTable.Rows[0][0].ToString() == "0") { query = conn.CreateCommand(); query.CommandText = "insert into account_table(username,password,full_name,type) values (@username,@password,@full_name,@type)"; query.Parameters.AddWithValue("@username", txt_regUsername.Text); query.Parameters.AddWithValue("@password", txt_regPassword.Text); query.Parameters.AddWithValue("@full_name", txt_regFullName.Text); query.Parameters.AddWithValue("@type", cmb_regType.Text); query.ExecuteNonQuery(); dbCommandLogs(Session.FullName.ToString() + " added new account."); MessageBox.Show("Account successfully added!"); clearRegTextBox(); query = conn.CreateCommand(); query.CommandText = "select id as 'ID', username as 'Username', full_name as 'Full Name', type as 'Type' from account_table where id != '" + Session.Id + "'"; adapt = new MySqlDataAdapter(query); setData = new DataSet(); adapt.Fill(setData); dg_accounts.DataSource = setData.Tables[0].DefaultView; } else { MessageBox.Show("Account Exist"); clearRegTextBox(); } } else if (module == "" && specialAction == "viewUser") { query = conn.CreateCommand(); query.CommandText = "select id as 'ID', username as 'Username', full_name as 'Full Name', type as 'Type' from account_table where id != '" + Session.Id + "'"; adapt = new MySqlDataAdapter(query); setData = new DataSet(); adapt.Fill(setData); dg_accounts.DataSource = setData.Tables[0].DefaultView; } else if (module == "" && specialAction == "deleteUser") { query.ExecuteNonQuery(); MessageBox.Show("Successfully deleted."); dbCommandLogs(Session.FullName.ToString() + " has been successfully deleted an account."); } else if (module == "" && specialAction == "updateUser") { query.Parameters.AddWithValue("@username", txt_regUsername.Text); query.Parameters.AddWithValue("@full_name", txt_regFullName.Text); query.Parameters.AddWithValue("@password", txt_regPassword.Text); query.Parameters.AddWithValue("@type", cmb_regType.Text); query.ExecuteNonQuery(); MessageBox.Show("Account has been updated!"); dbCommandLogs(Session.FullName.ToString() + " has been successfully updated an account."); } else if (module == "" && specialAction == "showLogs") { adapt = new MySqlDataAdapter(query); setData = new DataSet(); adapt.Fill(setData); dt_logs.DataSource = setData.Tables[0].DefaultView; } else if (module == "" && specialAction == "showDocu") { adapt = new MySqlDataAdapter(query); setData = new DataSet(); adapt.Fill(setData); dt_docu.DataSource = setData.Tables[0].DefaultView; } else if (module == "" && specialAction == "showDocuGuest") { adapt = new MySqlDataAdapter(query); setData = new DataSet(); adapt.Fill(setData); gf = new Guest_frm(); gf.docuFormGuest(setData.Tables[0].DefaultView); } else if (module == "" && specialAction == "searchDocuGuest") { adapt = new MySqlDataAdapter(query); setData = new DataSet(); adapt.Fill(setData); gf = new Guest_frm(); gf.loadGuestBySearch(setData.Tables[0].DefaultView); } else if (module == "" && specialAction == "createDocuTitle") { query.ExecuteNonQuery(); } else if (module == "" && specialAction == "getDocuId") { adapt = new MySqlDataAdapter(query); dataTable = new DataTable(); adapt.Fill(dataTable); document.Id = Convert.ToInt32(dataTable.Rows[0][0].ToString()); document.Title = txt_titleDocu.Text; } else if (module == "" && specialAction == "addDocu") { query.ExecuteNonQuery(); } else if (module == "" && specialAction == "showArea") { adapt = new MySqlDataAdapter(query); setData = new DataSet(); adapt.Fill(setData); df = new docuForm(); df.docuFormGet(setData.Tables[0].DefaultView); //dg.DataSource = setData.Tables[0].DefaultView; df.Show(); } else if (module == "" && specialAction == "getArea") { adapt = new MySqlDataAdapter(query); setData = new DataSet(); adapt.Fill(setData); df = new docuForm(); df.docuFormGet(setData.Tables[0].DefaultView); //dg.DataSource = setData.Tables[0].DefaultView; df.Hide(); } else if (module == "" && specialAction == "deleteArea") { query.ExecuteNonQuery(); } else if (module == "" && specialAction == "deleteDocu") { query.ExecuteNonQuery(); } else if (module == "" && specialAction == "deleteArea") { query.ExecuteNonQuery(); } else if (module == "" && specialAction == "updateArea") { query.ExecuteNonQuery(); } else if (module == "" && specialAction == "importArea") { query.ExecuteNonQuery(); } else if (module == "" && specialAction == "searchDocuByTitle") { adapt = new MySqlDataAdapter(query); setData = new DataSet(); adapt.Fill(setData); dt_docu.DataSource = setData.Tables[0].DefaultView; } else if (module == "" && specialAction == "searchDocuGuest") { adapt = new MySqlDataAdapter(query); setData = new DataSet(); adapt.Fill(setData); gf = new Guest_frm(); gf.loadGuestBySearch(setData.Tables[0].DefaultView); //dt_docu.DataSource = setData.Tables[0].DefaultView; } } catch (Exception ex) { Console.WriteLine("Error:", ex.ToString()); MessageBox.Show("Error:" + ex.ToString()); } finally { if (conn != null) { conn.Close(); } } }