private void button1_Click(object sender, EventArgs e) { if (val == 1) { //Citire date client String q, FN, LN, Gr = "01"; int CNP; FN = Convert.ToString(textBox1.Text); LN = Convert.ToString(textBox2.Text); CNP = Convert.ToInt32(textBox3.Text); if (radioButton1.Checked == false && radioButton2.Checked == false && radioButton3.Checked == false && radioButton4.Checked == false) { MessageBox.Show("Check blood type"); } else if (radioButton1.Checked == true) { Gr = Convert.ToString(radioButton1.Text); } else if (radioButton2.Checked == true) { Gr = Convert.ToString(radioButton2.Text); } else if (radioButton3.Checked == true) { Gr = Convert.ToString(radioButton3.Text); } else { Gr = Convert.ToString(radioButton4.Text); } //Verificare existenta client SqlConnection con = new SqlConnection(init); con.Open(); q = "Select CNP from Info_Client where CNP =" + CNP; SqlCommand cmd = new SqlCommand(q, con); SqlDataReader read = cmd.ExecuteReader(); if (read.Read()) { con.Close(); MessageBox.Show("Client already in DataBase"); } else { con.Close(); con.Open(); q = "insert into Info_Client(CNP, Nume, Prenume, Grupa_sanguina) values('" + CNP + "', '" + FN.ToUpper() + "', '" + LN.ToUpper() + "', '" + Gr + "')"; cmd = new SqlCommand(q, con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Done!"); } label1.Hide(); label2.Hide(); label3.Hide(); label4.Hide(); textBox1.Text = null; textBox2.Text = null; textBox3.Text = null; textBox1.Hide(); textBox2.Hide(); textBox3.Hide(); radioButton1.Hide(); radioButton2.Hide(); radioButton3.Hide(); radioButton4.Hide(); button1.Hide(); radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; } if (val == 2) { String q, CNP; CNP = Convert.ToString(textBox1.Text); CNPMaster = Convert.ToString(textBox1.Text); SqlConnection con = new SqlConnection(init); con.Open(); q = "Select * from Info_Client where CNP =" + CNP; SqlCommand cmd = new SqlCommand(q, con); SqlDataReader read = cmd.ExecuteReader(); if (read.Read()) { label1.Text = "First name"; label2.Text = "Last name"; label3.Text = "CNP"; label4.Text = "Blood type"; button1.Text = "Execute"; textBox1.Text = read["Nume"].ToString(); textBox2.Text = read["Prenume"].ToString(); textBox3.Text = read["CNP"].ToString(); textBox3.ReadOnly = true; label2.Show(); label3.Show(); textBox2.Show(); textBox3.Show(); radioButton1.Show(); radioButton2.Show(); radioButton3.Show(); radioButton4.Show(); comboBox1.Show(); if (read["Grupa_sanguina"].ToString().Equals("01")) { radioButton1.Checked = true; } else if (read["Grupa_sanguina"].ToString().Equals("A2")) { radioButton2.Checked = true; } else if (read["Grupa_sanguina"].ToString().Equals("B3")) { radioButton3.Checked = true; } else { radioButton4.Checked = true; } con.Close(); radioButton1.Enabled = false; radioButton2.Enabled = false; radioButton3.Enabled = false; radioButton4.Enabled = false; val = 3; } else { MessageBox.Show("Client not found"); con.Close(); textBox1.Text = null; } } if (val == 3) { if (comboBox1.Text.ToString().Equals("Delete")) { String q, CNP; CNP = Convert.ToString(textBox3.Text); SqlConnection con = new SqlConnection(init); con.Open(); q = "Delete from Info_Client where CNP =" + CNP; SqlCommand cmd = new SqlCommand(q, con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Done!"); label1.Hide(); label2.Hide(); label3.Hide(); label4.Hide(); textBox1.Text = null; textBox2.Text = null; textBox3.Text = null; textBox1.Hide(); textBox2.Hide(); textBox3.Hide(); radioButton1.Hide(); radioButton2.Hide(); radioButton3.Hide(); radioButton4.Hide(); comboBox1.Hide(); button1.Hide(); radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; } if (comboBox1.Text.ToString().Equals("Modify")) { String q, FN, LN, Gr = "01", CNP; SqlConnection con = new SqlConnection(init); con.Open(); FN = Convert.ToString(textBox1.Text); LN = Convert.ToString(textBox2.Text); CNP = Convert.ToString(textBox3.Text); if (radioButton1.Checked == false && radioButton2.Checked == false && radioButton3.Checked == false && radioButton4.Checked == false) { MessageBox.Show("Check blood type"); } else if (radioButton1.Checked == true) { Gr = Convert.ToString(radioButton1.Text); } else if (radioButton2.Checked == true) { Gr = Convert.ToString(radioButton2.Text); } else if (radioButton3.Checked == true) { Gr = Convert.ToString(radioButton3.Text); } else { Gr = Convert.ToString(radioButton4.Text); } q = "update Info_Client set Nume='" + FN.ToUpper() + "',Prenume='" + LN.ToUpper() + "',Grupa_sanguina='" + Gr + "' where CNP='" + CNP + "'"; SqlCommand cmd = new SqlCommand(q, con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("Done!"); label1.Hide(); label2.Hide(); label3.Hide(); label4.Hide(); textBox1.Text = null; textBox2.Text = null; textBox3.Text = null; textBox1.Hide(); textBox2.Hide(); textBox3.Hide(); radioButton1.Hide(); radioButton2.Hide(); radioButton3.Hide(); radioButton4.Hide(); comboBox1.Hide(); button1.Hide(); radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; } if (comboBox1.Text.ToString().Equals("New Appointment")) { Form4 f4 = new Form4(); this.Hide(); f4.ShowDialog(); this.Show(); label1.Hide(); label2.Hide(); label3.Hide(); label4.Hide(); textBox1.Text = null; textBox2.Text = null; textBox3.Text = null; textBox1.Hide(); textBox2.Hide(); textBox3.Hide(); radioButton1.Hide(); radioButton2.Hide(); radioButton3.Hide(); radioButton4.Hide(); button1.Hide(); radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; comboBox1.Hide(); } if (comboBox1.Text.ToString().Equals("Delete Future Appointment")) { if (listBox1.SelectedItem != null) { String q; string[] tokens = listBox1.SelectedItem.ToString().Split(' '); q = "delete from Consultatie where Data='" + tokens[0] + "' and Ora='" + tokens[1] + "' and CNP='" + CNPMaster + "'"; SqlConnection con = new SqlConnection(init); con.Open(); SqlCommand cmd = new SqlCommand(q, con); cmd.ExecuteNonQuery(); con.Close(); listBox1.Items.Clear(); con.Open(); q = "select C.Data, C.Ora, I.Nume, I.Prenume from Consultatie C join Info_Stomatolog I on C.ID_Stomatolog=I.ID_Stomatolog and C.CNP='" + CNPMaster + "' and (C.Data>GETDATE() or (C.Data=GETDATE() and C.Ora>(SELECT CONVERT(TIME,GETDATE()))))"; cmd = new SqlCommand(q, con); SqlDataReader read = cmd.ExecuteReader(); while (read.Read()) { listBox1.Items.Add(read["Data"].ToString().Substring(0, read["Data"].ToString().IndexOf(' ')) + " " + read["Ora"].ToString().Substring(0, 5) + " " + read["Nume"].ToString() + " " + read["Prenume"].ToString()); } con.Close(); } } if (comboBox1.Text.ToString().Equals("Complete Appointment")) { if (listBox1.SelectedIndex != -1) { Form5 f5 = new Form5(); Consult = listBox1.SelectedItem.ToString(); this.Hide(); f5.ShowDialog(); this.Show(); } } if (comboBox1.Text.ToString().Equals("Bill Appointment")) { if (listBox1.SelectedIndex != -1) { Consult = listBox1.SelectedItem.ToString(); Form6 f6 = new Form6(); this.Hide(); f6.ShowDialog(); this.Show(); } } } }