private void fillGrid(String query, int i) { dc.openCon(); SqlDataAdapter da = dc.selectTable(query); DataTable dt = new DataTable(); da.Fill(dt); if (i == 1) { metroGrid1.DataSource = dt; DataGridViewButtonColumn col = new DataGridViewButtonColumn(); col.UseColumnTextForButtonValue = true; col.Text = "Delete"; col.Name = "deleteUsr"; metroGrid1.Columns.Add(col); dc.closeCon(); } else { metroGrid2.DataSource = dt; DataGridViewButtonColumn col = new DataGridViewButtonColumn(); col.UseColumnTextForButtonValue = true; col.Text = "Delete"; col.Name = "deleteUsr"; metroGrid2.Columns.Add(col); dc.closeCon(); } }
private void metroButton3_Click(object sender, EventArgs e) { if (!((DateTime.Compare(Convert.ToDateTime(metroDateTime1.Text), DateTime.Now) < 0) || (String.IsNullOrEmpty(metroTextBox2.Text) || (String.IsNullOrEmpty(metroTextBox13.Text) || (String.IsNullOrEmpty(metroTextBox3.Text)))))) { String fd = metroDateTime1.Value.ToString("yyyy-MM-dd"); DataCon dc1 = new DataCon(); SqlDataReader dr = dc1.execSelect("SELECT staff_id from users where access_level like '" + metroTextBox13.Text + "'"); List <String> rec = new List <string>(); try { while (dr.Read()) { rec.Add((String)dr[0]); //MessageBox.Show("Read :Line"); } }catch (Exception ex2) { MessageBox.Show(ex2.Message); } dc1.closeCon(); for (int i = 0; i < rec.Count; i++) { String command = "INSERT INTO notification VALUES ('" + fd + "',GETDATE(), '" + metroTextBox2.Text + "','" + metroTextBox3.Text + "','" + rec[i] + "')"; new DataCon().execInsert(command); MessageBox.Show("Added"); fillGrid("SELECT * FROM notification", 1, 1); } } else { MessageBox.Show("Empty or Invalid fields. Please Correct and try again!"); } }
private void metroButton5_Click(object sender, EventArgs e) { String command = "RESTORE DATABASE bisdb FROM DISK ='" + metroTextBox1.Text + "' WITH REPLACE"; DataCon dc4 = new DataCon(); dc4.openCon(); SqlCommand cmd = new SqlCommand(command, dc4.getCon()); dc4.closeCon(); dc4.dispCon(); MessageBox.Show("SuccessFully Restored"); }
private void metroButton12_Click(object sender, EventArgs e) { if (!((DateTime.Compare(Convert.ToDateTime(metroDateTime1.Text), DateTime.Now) < 0) || (String.IsNullOrEmpty(metroTextBox2.Text) || (String.IsNullOrEmpty(metroTextBox13.Text) || (String.IsNullOrEmpty(metroTextBox3.Text) || (String.IsNullOrEmpty(metroTextBox12.Text))))))) { String fd = metroDateTime1.Value.ToString("yyyy-MM-dd"); DataCon d3 = new DataCon(); DataCon dc1 = new DataCon(); SqlDataReader dr = dc1.execSelect("SELECT staff_id from users where access_level like '" + metroTextBox13.Text + "'"); List <String> rec = new List <string>(); try { while (dr.Read()) { rec.Add((String)dr[0]); // MessageBox.Show("Read :Line"); } } catch (Exception ex2) { MessageBox.Show(ex2.Message); } dc1.closeCon(); for (int i = 0; i < rec.Count; i++) { String command = "UPDATE notification set date = '" + fd + "', subject = '" + metroTextBox2.Text + "', message = '" + metroTextBox3.Text + "', staff_id = '" + rec[i] + "' WHERE nid = '" + System.Convert.ToInt32(metroTextBox12.Text) + "'"; new DataCon().execInsert(command); MessageBox.Show("Updated"); } fillGrid("SELECT * from notification", 1, 1); } else { MessageBox.Show("Invalid or incomplete fields. Please complete and try agian."); } }
private void metroButton4_Click(object sender, EventArgs e) { if (!((String.IsNullOrEmpty(metroTextBox4.Text) || (String.IsNullOrEmpty(metroTextBox5.Text))))) { sql = "BACKUP DATABASE bisdb TO DISK ='" + metroTextBox4.Text + "\\bisdb-" + metroTextBox5.Text + ".bak'"; cmd = new SqlCommand(sql, dc.getCon()); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } dc.closeCon(); dc.dispCon(); MessageBox.Show("Successfully Backed up!"); } else { MessageBox.Show("one or more empty fields. You cannot leave them blank!"); } }