Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("Please insert Vendor Name");
            }

            else if (numericUpDown1.Value == 0)
            {
                MessageBox.Show("Please insert quantity");
            }
            else
            {
                DataSet ds = new DataSet();
                ds = _sqlSetup.GetData("select Name from Vendor where Name = '" + textBox1.Text + "'", false, null);
                if (ds != null)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        string cmd;
                        if (textBox2.Text == "")
                        {
                            cmd = "insert into MedicineReceived(idMedicine, RecvdDate, ExpiryDate, QtyRcvd, idVendor) values" +
                                  "(" + InventoryView.SetID + ", '" + dateTimePicker2.Value.ToShortDateString() + "', '" + dateTimePicker1.Value.ToShortDateString() + "', " + numericUpDown1.Value + ",(Select idVendor from Vendor where Name like '" + textBox1.Text + "'))";
                        }
                        else
                        {
                            cmd = "insert into MedicineReceived(idMedicine, RecvdDate, ExpiryDate, Comments, QtyRcvd, idVendor) values" +
                                  "(" + InventoryView.SetID + ",'" + dateTimePicker2.Value.ToShortDateString() + "', '" + dateTimePicker1.Value.ToShortDateString() + "', '" +
                                  textBox2.Text + "', " + numericUpDown1.Value + ",(Select idVendor from Vendor where Name like '" + textBox1.Text + "'))";
                        }

                        int insert = _sqlSetup.SetData(cmd, false, null);


                        int update = _sqlSetup.SetData("Update Medicine Set Quantity = Quantity + ((Select PcsPerPack from Medicine where idMedicine = " +
                                                       InventoryView.SetID + ") * " + numericUpDown1.Value +
                                                       " ) where idMedicine = " + InventoryView.SetID + " ", false, null);

                        MessageBox.Show("Stock Updated.");
                        this.RefreshDgv();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("The vendor does not exist.");
                    }
                }
            }
        }
 private void button1_Click_1(object sender, EventArgs e)
 {
     if (textBox1.Text == "")
     {
         MessageBox.Show("Please insert vendor's name.");
     }
     else
     {
         DataSet ds = new DataSet();
         ds = _sqlSetup.GetData("select Name from Vendor where Name = '" + textBox1.Text + "'", false, null);
         if (ds != null)
         {
             if (ds.Tables[0].Rows.Count > 0)
             {
                 MessageBox.Show("This vendor already exists.");
             }
             else
             {
                 int insert = _sqlSetup.SetData("Insert into Vendor(idVendor, Name) values " +
                                                "((Select Top 1 idVendor from Vendor order by idVendor desc) +1,'"
                                                + textBox1.Text + "')", false, null);
                 MessageBox.Show("Vendor Added.");
                 this.Close();
                 AddMedicineStock fm = new AddMedicineStock();
                 fm.Show();
             }
         }
     }
 }
Ejemplo n.º 3
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();

            ds = _sqlSetup.GetData("select Name from Medicine where Name like '" + textBox4.Text + "'", false, null);
            if (ds != null)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (numericUpDown1.Value == 0)
                    {
                        MessageBox.Show("The Quantity must be greater than 0");
                    }
                    else
                    {
                        DataSet ds1 = new DataSet();
                        ds1 = _sqlSetup.GetData("Select * from Appointment_has_Medicine", false, null);
                        if (ds1 != null)
                        {
                            if (ds1.Tables[0].Rows.Count > 0)
                            {
                                int insert = _sqlSetup.SetData("Insert into Appointment_has_Medicine(idAppMed, idMedicine,idAppointment, QtyIssued, Date)  values " +
                                                               "((Select Top 1 idAppMed from Appointment_has_Medicine order by idAppMed desc) +1,(select idMedicine from Medicine where Name like '"
                                                               + textBox4.Text + "' and Type = (Select idType from Type where Name like '" + comboBox1.Text + "')), (Select idAppointment from Appointment where idAppointment = " + ConsultationForm.appt.ToString() + " and Date = '" +
                                                               ConsultationForm.date + "'), " + numericUpDown1.Value + ", (Select Date from Appointment where idAppointment = " + ConsultationForm.appt.ToString() + " and Date = '" +
                                                               ConsultationForm.date + "'))", false, null);
                            }
                            else
                            {
                                int insert = _sqlSetup.SetData("Insert into Appointment_has_Medicine(idAppMed, idMedicine, idAppointment, QtyIssued, Date)  values(1, (select idMedicine from Medicine where Name like '"
                                                               + textBox4.Text + "' and Type = (Select idType from Type where Name like '" + comboBox1.Text + "')), (Select idAppointment from Appointment where idAppointment = " + ConsultationForm.appt.ToString() + " and Date = '" +
                                                               ConsultationForm.date + "'), " + numericUpDown1.Value + ", (Select Date from Appointment where idAppointment = " + ConsultationForm.appt.ToString() + " and Date = '" +
                                                               ConsultationForm.date + "'))", false, null);

                                MessageBox.Show("Dosage Added");
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please enter a valid medicine from the options available");
                }
            }
            DisplayData();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                AppMed = Convert.ToInt32(row.Cells[1].Value.ToString());
                bool    isSelected = Convert.ToBoolean(row.Cells[0].Value);
                DataSet ds         = new DataSet();
                ds = _sqlSetup.GetData("Select * from Appointment_has_Medicine where idAppMed = " + AppMed + " and issued = 1", false, null);
                if (ds != null)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        MessageBox.Show(row.Cells[2].Value.ToString() + " has already been issued.");
                    }
                    else if (isSelected && ds.Tables[0].Rows.Count == 0)
                    {
                        DataSet ds2 = new DataSet();
                        ds2 = _sqlSetup.GetData("Select * from Medicine where Name like '" + row.Cells[2].Value.ToString() + "'and Quantity -" +
                                                Convert.ToInt32(row.Cells[3].Value.ToString()) + "> 0", false, null);
                        if (ds2 != null)
                        {
                            if (ds2.Tables[0].Rows.Count > 0)
                            {
                                int update = _sqlSetup.SetData("Update Medicine Set Quantity = Quantity -" +
                                                               Convert.ToInt32(row.Cells[3].Value.ToString()) +
                                                               " where idMedicine = (Select idMedicine from Medicine where Name like '"
                                                               + row.Cells[2].Value.ToString() + "')", false, null);


                                int update2 = _sqlSetup.SetData("Update Appointment_has_Medicine Set issued = 1 where idAppMed = " + AppMed + "", false, null);
                                MessageBox.Show("Medicine has been issued.");
                                this.Close();
                            }

                            else
                            {
                                MessageBox.Show("Not enough quantity in stock for " + dataGridView1.CurrentRow.Cells[2].Value.ToString());
                            }
                        }
                    }
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            double pv;

            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || textBox7.Text == "" || textBox8.Text == "")
            {
                MessageBox.Show("Invalid! Please enter all the information to proceed.");
            }
            else
            {
                if (!(Double.TryParse(textBox4.Text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out pv)) || !(Double.TryParse(textBox6.Text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out pv)) || !(Double.TryParse(textBox5.Text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out pv)))
                {
                    MessageBox.Show("Phone Number , CNIC, and age must only be integer values.");
                }

                else
                {
                    if (!(textBox5.TextLength == 11))
                    {
                        MessageBox.Show("Phone No. must be 11 digits.");
                    }

                    else
                    {
                        if (!(textBox4.TextLength == 13))
                        {
                            MessageBox.Show("CNIC must be 13 digits.");
                        }

                        else if (textBox4.TextLength == 13)
                        {
                            DataSet ds = new DataSet();
                            ds = _sqlSetup.GetData("select Name from City where Name = '" + textBox7.Text + "'", false, null);
                            if (ds != null)
                            {
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    int update = _sqlSetup.SetData("Update Patient set idCity = (select idCity from City where Name like '" + textBox7.Text + "'), FatherOrHusband = '" + textBox3.Text + "', Age = " + Convert.ToInt32(textBox6.Text) + ", CNIC = '" + textBox4.Text + "', Address = '" + textBox8.Text + "', Cell_No = '" + textBox5.Text + "' where Patient.Name = '" + textBox2.Text + "' and Patient.MR_No = " + Convert.ToInt32(textBox1.Text), false, null);
                                    MessageBox.Show("Patient details updated! Please click the Close button to exit.");
                                }
                                else
                                {
                                    MessageBox.Show("Please enter a valid city from the options available");
                                }
                            }
                        }
                    }
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            double pv;

            //when no details are mentioned and save is pressed
            if (comboBox1.Text == "" && comboBox2.Text == "" && textBox9.Text == "" && textBox8.Text == "" && textBox7.Text == "" && textBox6.Text == "" && textBox5.Text == "" && textBox1.Text == "" && textBox4.Text == "")
            {
                MessageBox.Show("Please enter details to proceed.");
            }
            //when only vitals are being filled out
            else if (textBox1.Text == "" && textBox4.Text == "")
            {
                if (Double.TryParse(comboBox1.Text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out pv) && Double.TryParse(textBox9.Text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out pv) && Double.TryParse(textBox8.Text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out pv))
                {
                    int update = _sqlSetup.SetData("Update Appointment set Heightf = " + Convert.ToDouble(comboBox1.Text) + ", Heighti = " + Convert.ToDouble(comboBox2.Text) + ", Weight = " + Convert.ToDouble(textBox9.Text) + ", Temp = " + Convert.ToDouble(textBox8.Text) + ", BP = '" + textBox7.Text + "', Pulse = '" + textBox6.Text + "', RespRate = '" + textBox5.Text + "' where idDoctors in (select idDoctors from Doctors where Name like '" + ConsultationForm.doc + "') and MR_No = " + DoctorView.MR.ToString() + " and Date = '" + ConsultationForm.date + "' and idAppointment = " + ConsultationForm.appt.ToString(), false, null);
                    MessageBox.Show("Changes saved!");
                }
                else
                {
                    MessageBox.Show("Height, Weight and Temp must be numbers");
                }
            }
            //when consulting doctors enters all data
            else
            {
                if (Double.TryParse(comboBox1.Text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out pv) && Double.TryParse(textBox9.Text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out pv) && Double.TryParse(textBox8.Text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out pv))
                {
                    int update2 = _sqlSetup.SetData("Update Appointment set Investigation = '" + textBox4.Text + "', PresentComplaints = '" + textBox1.Text + "', Heightf = " + Convert.ToDouble(comboBox1.Text) + ", Heighti = " + Convert.ToDouble(comboBox2.Text) + ", Weight = " + Convert.ToDouble(textBox9.Text) + ", Temp = " + Convert.ToDouble(textBox8.Text) + ", BP = '" + textBox7.Text + "', Pulse = '" + textBox6.Text + "', RespRate = '" + textBox5.Text + "' where idDoctors in (select idDoctors from Doctors where Name like '" + ConsultationForm.doc + "') and MR_No = " + DoctorView.MR.ToString() + " and Date = '" + ConsultationForm.date + "' and idAppointment = " + ConsultationForm.appt.ToString(), false, null);
                    MessageBox.Show("Changes saved!");
                }
                else
                {
                    MessageBox.Show("Height, Weight and Temp must be numbers");
                }
            }
        }
Ejemplo n.º 7
0
        private void button4_Click(object sender, EventArgs e)
        {
            SetID = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            int insert = _sqlSetup.SetData("Begin Transaction Delete from MedicineReceived where idMedicine = " +
                                           SetID + " Delete from Appointment_has_Medicine where idMedicine = " + SetID + " Delete from Medicine where idMedicine = "
                                           + SetID + " Commit", false, null);

            MessageBox.Show("Medicine Deleted");

            DataSet ds = new DataSet();

            ds = _sqlSetup.GetData("Select idMedicine, Medicine.Name as 'Medicine', Quantity, Type.Name AS 'Type' from Medicine join Type on Medicine.Type = Type.idType Where Medicine.Name like '" + textBox1.Text + "%'", false, null);
            if (ds != null)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    dataGridView1.DataSource = ds.Tables[0];
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            double pv;

            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || textBox7.Text == "" || (radioButton1.Checked == false && radioButton2.Checked == false))
            {
                MessageBox.Show("Invalid! Please enter all the information to proceed.");
            }
            else
            {
                if (Double.TryParse(textBox3.Text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out pv) && Double.TryParse(textBox4.Text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out pv) && Double.TryParse(textBox6.Text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out pv) && textBox4.TextLength == 11 && textBox3.TextLength == 13)
                {
                    DataSet ds = new DataSet();
                    ds = _sqlSetup.GetData("select Name from City where Name = '" + textBox7.Text + "'", false, null);
                    if (ds != null)
                    {
                        if (!(ds.Tables[0].Rows.Count > 0))
                        {
                            MessageBox.Show("Please enter a valid city from the options available");
                        }
                        else
                        {
                            DataSet ds2 = new DataSet();
                            ds2 = _sqlSetup.GetData("Select top 1 MR_No from Patient", false, null);
                            if (ds2 != null)
                            {
                                if (!(ds2.Tables[0].Rows.Count > 0))
                                {
                                    int insert = _sqlSetup.SetData("Set Identity_insert Patient ON insert into Patient (MR_No, idCity, Name, FatherOrHusband, Age, CNIC, Address, Cell_No) values (" +
                                                                   "1, (select idCity from City where Name like '" + textBox7.Text + "'), '" + textBox1.Text + "', '" + textBox2.Text + "', " + Convert.ToInt32(textBox6.Text) + ", '" + textBox3.Text + "', '" + textBox5.Text + "', '" + textBox4.Text + "')", false, null);
                                }
                                else
                                {
                                    int insert = _sqlSetup.SetData("Set Identity_insert Patient ON insert into Patient (MR_No, idCity, Name, FatherOrHusband, Age, CNIC, Address, Cell_No) values (" +
                                                                   "(Select top 1 MR_No from Patient order by MR_No desc) + 1, (select idCity from City where Name like '" + textBox7.Text + "'), '" + textBox1.Text + "', '" + textBox2.Text + "', " + Convert.ToInt32(textBox6.Text) + ", '" + textBox3.Text + "', '" + textBox5.Text + "', '" + textBox4.Text + "')", false, null);
                                }
                            }

                            DataSet ds4 = new DataSet();
                            ds4 = _sqlSetup.GetData("Select top 1 idAppointment from Appointment where Date = '" + dateTimePicker2.Value.Date + "' order by idAppointment desc", false, null);
                            if (ds4 != null)
                            {
                                if (ds4.Tables[0].Rows.Count > 0) //if an appointment exists for that date
                                {
                                    DataSet ds6 = new DataSet();
                                    ds6 = _sqlSetup.GetData("select Name from Doctors where Name = '" + textBox8.Text + "'", false, null);
                                    if (ds6 != null)
                                    {
                                        if (ds6.Tables[0].Rows.Count > 0)     //if the doctor is correct
                                        {
                                            if (radioButton1.Checked == true) //if it is a consultation
                                            {
                                                int insert4 = _sqlSetup.SetData("insert into Appointment (idAppointment, idDoctors, MR_No, Date, Time, isSurgery)  values " +
                                                                                "((Select top 1 idAppointment from Appointment where Date = '" + dateTimePicker2.Value.Date + "'order by idAppointment desc) +1," +
                                                                                " (select idDoctors from Doctors where Name like '" + textBox8.Text + "'), (select TOP 1 MR_No from Patient order by MR_No desc), '" + dateTimePicker2.Value.Date + "', '" + dateTimePicker3.Value.ToLongTimeString() + "', 0)", false, null);

                                                MessageBox.Show("Patient added and Appointment Scheduled!");
                                                this.Close();
                                            }
                                            else if (radioButton2.Checked == true)
                                            {
                                                int insert4 = _sqlSetup.SetData("insert into Appointment (idAppointment, idDoctors, MR_No, Date, Time, isSurgery)  values " +
                                                                                "((Select top 1 idAppointment from Appointment where Date = '" + dateTimePicker2.Value.Date + "'order by idAppointment desc) +1," +
                                                                                " (select idDoctors from Doctors where Name like '" + textBox8.Text + "'), (select TOP 1 MR_No from Patient order by MR_No desc), '" + dateTimePicker2.Value.Date + "', '" + dateTimePicker3.Value.ToLongTimeString() + "', 1)", false, null);

                                                MessageBox.Show("Patient added and Appointment Scheduled!");
                                                this.Close();
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Please enter a valid doctor from the options available");
                                        }
                                    }
                                }


                                else
                                {
                                    DataSet ds5 = new DataSet();
                                    ds5 = _sqlSetup.GetData("select Name from Doctors where Name = '" + textBox8.Text + "'", false, null);
                                    if (ds5 != null)
                                    {
                                        if (ds5.Tables[0].Rows.Count > 0)
                                        {
                                            if (radioButton1.Checked == true)
                                            {
                                                int insert3 = _sqlSetup.SetData("insert into Appointment (idAppointment, idDoctors, MR_No, Date, Time, isSurgery) values (1, (select idDoctors from Doctors where Name like '" + textBox8.Text + "'), (select TOP 1 MR_No from Patient order by MR_No desc), '" + dateTimePicker2.Value.Date + "', '" + dateTimePicker3.Value.ToLongTimeString() + "', 0)", false, null);
                                                MessageBox.Show("Patient added and Appointment Scheduled!");
                                                this.Close();
                                            }
                                            else if (radioButton2.Checked == true)
                                            {
                                                int insert3 = _sqlSetup.SetData("insert into Appointment (idAppointment, idDoctors, MR_No, Date, Time, isSurgery) values (1, (select idDoctors from Doctors where Name like '" + textBox8.Text + "'), (select TOP 1 MR_No from Patient order by MR_No desc), '" + dateTimePicker2.Value.Date + "',  '" + dateTimePicker3.Value.ToLongTimeString() + "', 1)", false, null);
                                                MessageBox.Show("Patient added and Appointment Scheduled!");
                                                this.Close();
                                            }
                                        }

                                        else
                                        {
                                            MessageBox.Show("Please enter a valid doctor from the options available");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("CNIC must have 13 digits, Phone Number must have 11 digits. Age, CNIC and Phone Number must only be numeric.");
                }
            }
        }
        private void Reg_Click_1(object sender, EventArgs e)
        {
            if (uname.Text == "" || pass.Text == "" || cpass.Text == "")
            {
                MessageBox.Show("Incomplete Information!");
            }
            else if (pass.Text.Length < 8)
            {
                MessageBox.Show("Password needs more characters");
            }
            else if (pass.Text != cpass.Text)
            {
                MessageBox.Show("Passwords don't match");
            }

            else
            {
                DataSet ds = new DataSet();
                ds = _sqlSetup.GetData("select username from Users where username ='******'", false, null);
                if (ds != null)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        MessageBox.Show("A user already exists with these credentials. Please enter a different username and password.");
                    }
                    else
                    {
                        string command;

                        if (radioButton1.Checked == true)
                        {
                            command = "Insert into dbo.Users(username,pw,isDoctor,isReceptionist,isPharmacist,isAdmin) " +
                                      "values( '" + uname.Text + "', '" + pass.Text + "', 0,0,1,0)";
                            int update = _sqlSetup.SetData(command, false, null);
                            MessageBox.Show("User Details Added!");
                            this.Close();
                        }
                        else if (radioButton2.Checked == true)
                        {
                            command = "Insert into dbo.Users(username,pw,isDoctor,isReceptionist,isPharmacist,isAdmin) " +
                                      "values( '" + uname.Text + "', '" + pass.Text + "',  0,1,0,0)";
                            int update = _sqlSetup.SetData(command, false, null);
                            MessageBox.Show("User Details Added!");
                            this.Close();
                        }

                        else if (radioButton3.Checked == true)
                        {
                            command = "Insert into dbo.Users(username,pw,isDoctor,isReceptionist,isPharmacist,isAdmin) " +
                                      "values( '" + uname.Text + "', '" + pass.Text + "',  0,0,0,1)";
                            int update = _sqlSetup.SetData(command, false, null);
                            MessageBox.Show("User Details Added!");
                            this.Close();
                        }
                        else if (radioButton4.Checked == true)
                        {
                            command = "Insert into dbo.Users(username,pw,isDoctor,isReceptionist,isPharmacist,isAdmin) " +
                                      "values( '" + uname.Text + "', '" + pass.Text + "', 1,0,0,0)";

                            int add    = _sqlSetup.SetData("Insert into dbo.Doctors(Name) values('" + uname.Text + "')", false, null);
                            int update = _sqlSetup.SetData(command, false, null);
                            MessageBox.Show("User Details Added!");
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("Please select your position!");
                        }
                    }
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("Invalid! Please enter all the information to proceed.");
            }


            else
            {
                if (textBox3.Enabled == true && textBox3.Text == "")
                {
                    MessageBox.Show("Invalid! Please enter all the information to proceed.");
                }

                else
                {
                    double pv;


                    if (textBox3.Enabled == true && !(Double.TryParse(textBox3.Text, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CurrentCulture, out pv)))
                    {
                        MessageBox.Show("Quantity has to be an integer only.");
                    }

                    else
                    {
                        DataSet ds = new DataSet();
                        ds = _sqlSetup.GetData("Select * from Medicine where Name like '" + textBox1.Text + "' and Type = (Select idType from Type " +
                                               "where Name like '" + comboBox1.Text + "')", false, null);
                        if (ds != null)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                MessageBox.Show("This medicine already exists.");
                            }
                        }


                        else
                        {
                            if (textBox3.Text == "")
                            {
                                int insert = _sqlSetup.SetData("Set Identity_insert Medicine ON Insert into Medicine(idMedicine, Name, GenericChemName, Quantity, PcsPerPack, Type) values (((Select Top 1 idMedicine from Medicine order by idMedicine desc)+1), '" +
                                                               textBox1.Text + "', '" + textBox2.Text + "' , 0 ,  0 , (Select idType from Type where Name like '" + comboBox1.Text + "')) ", false, null);
                                MessageBox.Show("Medicine Added.");
                                this.Close();
                                InventoryView newfrm = new InventoryView();
                                newfrm.Show();
                            }
                            else
                            {
                                int insert = _sqlSetup.SetData("Set Identity_insert Medicine ON Insert into Medicine(idMedicine, Name, GenericChemName, Quantity, PcsPerPack, Type) values (((Select Top 1 idMedicine from Medicine order by idMedicine desc)+1), '" +
                                                               textBox1.Text + "', '" + textBox2.Text + "' , 0 , '" + textBox3.Text + "' , (Select idType from Type where Name like '" + comboBox1.Text + "')) ", false, null);
                                MessageBox.Show("Medicine Added.");
                                this.Close();
                                InventoryView newfrm = new InventoryView();
                                newfrm.Show();
                            }
                        }
                    }
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox3.Text == "" || (radioButton1.Checked == false && radioButton2.Checked == false))
            {
                MessageBox.Show("Invalid! Please enter all the information to proceed.");
            }
            else
            {
                DataSet ds = new DataSet();
                ds = _sqlSetup.GetData("Select top 1 idAppointment from Appointment where Date = '" +
                                       dateTimePicker1.Value.Date + "' order by idAppointment desc", false, null);
                if (ds != null)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        DataSet ds1 = new DataSet();
                        ds1 = _sqlSetup.GetData("select Name from Doctors where Name = '" + textBox3.Text + "'", false, null);
                        if (ds1 != null)
                        {
                            if (ds1.Tables[0].Rows.Count > 0)
                            {
                                if (radioButton1.Checked == true)
                                {
                                    int insert = _sqlSetup.SetData("insert into Appointment (idAppointment, idDoctors, MR_No, Date, Time, " +
                                                                   "isSurgery) values ((Select top 1 idAppointment from Appointment where Date = '" + dateTimePicker1.Value.Date + "' order by idAppointment desc) +1 , " +
                                                                   "(select idDoctors from Doctors where Name like '" + textBox3.Text + "'), " +
                                                                   "(select MR_No from Patient where MR_No = " + Convert.ToInt32(textBox2.Text) + "),'" + dateTimePicker1.Value.Date +
                                                                   "','" + dateTimePicker2.Value.ToLongTimeString() + "', 0)", false, null);


                                    MessageBox.Show("Appointment Scheduled!");
                                    this.Close();
                                }
                                else if (radioButton2.Checked == true)
                                {
                                    int insert = _sqlSetup.SetData("insert into Appointment (idAppointment, idDoctors, MR_No, Date, Time, " +
                                                                   "isSurgery) values ((Select top 1 idAppointment from Appointment where Date = '" + dateTimePicker1.Value.Date + "' order by idAppointment desc) +1 , " +
                                                                   "(select idDoctors from Doctors where Name like '" + textBox3.Text + "'), " +
                                                                   "(select MR_No from Patient where MR_No = " + Convert.ToInt32(textBox2.Text) + "),'" + dateTimePicker1.Value.Date +
                                                                   "','" + dateTimePicker2.Value.ToLongTimeString() + "', 1)", false, null);

                                    MessageBox.Show("Appointment Scheduled!");
                                    this.Close();
                                }
                            }
                            else
                            {
                                MessageBox.Show("Please enter a valid doctor from the options available");
                            }
                        }
                    }
                    else
                    {
                        DataSet ds2 = new DataSet();
                        ds2 = _sqlSetup.GetData("select Name from Doctors where Name = '" + textBox3.Text + "'  ", false, null);
                        if (ds2 != null)
                        {
                            if (ds2.Tables[0].Rows.Count > 0)
                            {
                                if (radioButton1.Checked == true)
                                {
                                    int insert = _sqlSetup.SetData("insert into Appointment (idAppointment, idDoctors, MR_No, Date, Time, " +
                                                                   "isSurgery) values (1, (select idDoctors from Doctors where Name like '" + textBox3.Text + "'), " +
                                                                   "(select MR_No from Patient where MR_No = " + Convert.ToInt32(textBox2.Text) + "),'" + dateTimePicker1.Value.Date +
                                                                   "','" + dateTimePicker2.Value.ToLongTimeString() + "', 0)", false, null);
                                    MessageBox.Show("Appointment Scheduled!");
                                    this.Close();
                                }
                                else if (radioButton2.Checked == true)
                                {
                                    int insert = _sqlSetup.SetData("insert into Appointment (idAppointment, idDoctors, MR_No, Date, Time, " +
                                                                   "isSurgery) values (1, (select idDoctors from Doctors where Name like '" + textBox3.Text + "'), " +
                                                                   "(select MR_No from Patient where MR_No = " + Convert.ToInt32(textBox2.Text) + "), '" + dateTimePicker1.Value.Date +
                                                                   "','" + dateTimePicker2.Value.ToLongTimeString() + "', 1)", false, null);
                                    MessageBox.Show("Appointment Scheduled!");
                                    this.Close();
                                }
                            }

                            else
                            {
                                MessageBox.Show("Please enter a valid doctor from the options available");
                            }
                        }
                    }
                }
            }
        }