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 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."); } }