private void submitBed_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                p.textboxWard.Text    = this.comboboxChooseWard.SelectedItem.ToString();
                p.textboxBed.Text     = this.comboboxChooseBed.SelectedItem.ToString();
                p.textboxBedType.Text = this.check();

                string          Query      = "update bed set pat_contact_no='" + contact + "',bed_status='" + "Occupied" + "' where bed_no='" + comboboxChooseBed.SelectedItem.ToString() + "';";
                MySqlCommand    MyCommand4 = new MySqlCommand(Query, conn);
                MySqlDataReader MyReader4;
                MyReader4 = MyCommand4.ExecuteReader();
                while (MyReader4.Read())
                {
                    name = MyReader4.GetString(0);
                    comboboxChooseBed.Items.Add(name);
                }
                MyReader4.Close();
                this.Close();
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message.ToString());
            }
        }
Example #2
0
        private void btnorder_Click(object sender, EventArgs e)
        {
            string rand = RandomUtil.GetRandomString();

            try
            {
                //This is my connection string i have assigned the database file address path
                string MyConnection4 = "datasource=127.0.0.1;port=3306;username=root;password=;database=supermarket";
                //This is my update query in which i am taking input from the user through windows forms and update the record.
                string Query4 = "update sale set recipt_status =1 where recipt_status=0;";
                //This is  MySqlConnection here i have created the object and pass my connection string.
                MySqlConnection MyConn4    = new MySqlConnection(MyConnection4);
                MySqlCommand    MyCommand4 = new MySqlCommand(Query4, MyConn4);
                MySqlDataReader MyReader4;
                MyConn4.Open();
                MyReader4 = MyCommand4.ExecuteReader();
                while (MyReader4.Read())
                {
                }
                MyConn4.Close();//Connection closed here
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            clearData();
            MessageBox.Show("Thanks you");
        }
Example #3
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string          Query     = "insert into admitted_patient values('" + patient_name.Text + "','" + patient_age.Text + "','" + patient_contact_no.Text + "','" + comboboxBloodGroup.SelectedItem.ToString() + "','" + patient_address.Text + "','" + comboboxDisease.SelectedItem.ToString() + "','" + comboboxDoctorName.SelectedItem.ToString() + "','" + docId + "','" + textboxDoctorDept.Text + "','" + time_of_admission.Text + "','" + this.textboxWard.Text + "', '" + "Admitted" + "');";
                MySqlCommand    MyCommand = new MySqlCommand(Query, conn);
                MySqlDataReader MyReader;
                MyReader = MyCommand.ExecuteReader();
                MyReader.Close();

                string          Query1     = "DROP TABLE ward_bed;";
                MySqlCommand    MyCommand1 = new MySqlCommand(Query1, conn);
                MySqlDataReader MyReader1;
                MyReader1 = MyCommand1.ExecuteReader();
                MyReader1.Close();

                string          Query2     = "CREATE TABLE ward_bed AS SELECT ward.ward_name,bed.pat_contact_no,bed.bed_no,bed.bed_type,bed.bed_cost,bed.bed_status FROM ward,bed WHERE ward.ward_id=bed.ward_id;";
                MySqlCommand    MyCommand2 = new MySqlCommand(Query2, conn);
                MySqlDataReader MyReader2;
                MyReader2 = MyCommand2.ExecuteReader();
                MyReader2.Close();

                string          Query3     = "DROP TABLE allocate_patient_bed;";
                MySqlCommand    MyCommand3 = new MySqlCommand(Query3, conn);
                MySqlDataReader MyReader3;
                MyReader3 = MyCommand3.ExecuteReader();
                MyReader3.Close();

                string          Query4     = "CREATE TABLE allocate_patient_bed AS SELECT admitted_patient.patient_name,admitted_patient.patient_age,admitted_patient.patient_contact_no,ward_bed.ward_name,ward_bed.bed_no,ward_bed.bed_type,ward_bed.bed_cost,ward_bed.bed_status FROM admitted_patient,ward_bed WHERE admitted_patient.patient_contact_no=ward_bed.pat_contact_no AND admitted_patient.ward_name=ward_bed.ward_name;";
                MySqlCommand    MyCommand4 = new MySqlCommand(Query4, conn);
                MySqlDataReader MyReader4;
                MyReader4 = MyCommand4.ExecuteReader();
                MyReader4.Close();


                MessageBox.Show("Patient Addmitted!");

                patient_name.Text = ""; patient_address.Text = ""; patient_age.Text = ""; patient_contact_no.Text = "";
                comboboxBloodGroup.Items.Clear(); comboboxDoctorName.Items.Clear(); comboboxDisease.Items.Clear();
                textboxBed.Text = ""; textboxBedType.Text = ""; textboxWard.Text = ""; textboxDoctorDept.Text = "";
                load_blood_group(); load_disease(); load_doctor_name();

                patient_name.IsEnabled       = false; patient_address.IsEnabled = false; patient_age.IsEnabled = false; patient_contact_no.IsEnabled = false;
                comboboxBloodGroup.IsEnabled = false; comboboxDoctorName.IsEnabled = false; comboboxDisease.IsEnabled = false;
                textboxBed.IsEnabled         = false; textboxBedType.IsEnabled = false; textboxWard.IsEnabled = false; textboxDoctorDept.IsEnabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #4
0
        private void comboBoxDisc4_SelectedIndexChanged(object sender, EventArgs e)
        {
            string          Conexao    = "SERVER=localhost;" + "DATABASE=Scholendar;" + "UID=root;";
            MySqlConnection connection = new MySqlConnection(Conexao);

            connection.Open();
            string          disciplina4 = comboBoxDisc4.SelectedItem.ToString();
            string          query4      = "select * from Disciplina where Disciplina = '" + disciplina4 + "' ";
            MySqlCommand    MyCommand4  = new MySqlCommand(query4, connection);
            MySqlDataReader MyReader4;

            MyReader4 = MyCommand4.ExecuteReader();
            while (MyReader4.Read())
            {
                textBoxIDDisc4.Text = MyReader4["ID_Disciplina"].ToString();
            }
            connection.Close();
        }
 private void comboboxChooseWard_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     comboboxChooseBed.Items.Clear();
     try
     {
         string          text       = comboboxChooseWard.SelectedItem.ToString();
         string          Query      = "select bed_no from ward_bed where ward_name='" + text + "' and bed_status='" + "Free" + "' and bed_type='" + check().ToString() + "';";
         MySqlCommand    MyCommand4 = new MySqlCommand(Query, conn);
         MySqlDataReader MyReader4;
         MyReader4 = MyCommand4.ExecuteReader();
         while (MyReader4.Read())
         {
             name = MyReader4.GetString(0);
             comboboxChooseBed.Items.Add(name);
         }
         MyReader4.Close();
     }
     catch
     { }
     this.comboboxChooseBed.IsEnabled = true;
     radiobtnNormal.IsEnabled         = false;
     radiobtnVIP.IsEnabled            = false;
 }
Example #6
0
        private void send_btn_Click(object sender, EventArgs e)
        {
            try
            {
                MySqlConnection connection = new MySqlConnection(Connec);
                connection.Open();

                string          query   = @"SELECT user_id FROM  internal_communication_4.users 
                               WHERE user_name = " + login_form.user_name + " ";
                MySqlCommand    command = new MySqlCommand(query, connection);
                MySqlDataReader MyReader2;
                MyReader2 = command.ExecuteReader();
                while (MyReader2.Read())
                {
                    user_id_messages = Convert.ToInt32(MyReader2.GetString(0));
                }

                connection.Close();


                MySqlConnection connection3 = new MySqlConnection(Connec);
                connection3.Open();

                string          query3   = @"SELECT Project_project_id FROM  internal_communication_4.subjects 
                               WHERE subject_id = " + subj_id_lbl.Text + " ";
                MySqlCommand    command3 = new MySqlCommand(query3, connection3);
                MySqlDataReader MyReader4;
                MyReader4 = command3.ExecuteReader();
                while (MyReader4.Read())
                {
                    project_id = Convert.ToInt32(MyReader4.GetString(0));
                }

                connection3.Close();
            }

            catch
            {
                MessageBox.Show("error in data integrity");
            }

            try
            {
                Message_class mes = new Message_class();
                mes.Message_content = input_txtbx.Text;
                mes.Subject_id      = Convert.ToInt32(subj_id_lbl.Text);
                mes.User_id         = user_id_messages;
                mes.Project_id      = project_id;
                mes.Message_posting = DateTime.Now;

                MySqlConnection connection2 = new MySqlConnection(Connec);
                connection2.Open();

                MySqlCommand command2 = connection2.CreateCommand();
                command2.CommandText = @"INSERT INTO internal_communication_4.messages
                                                (user_user_id,subjects_subject_id,subjects_Project_project_id,message_content, message_posting) 
                                     VALUES( @user_user_id,  @subjects_subject_id, @subjects_Project_project_id, @message_content, @message_posting)";
                command2.Parameters.AddWithValue("@user_user_id", mes.User_id);
                command2.Parameters.AddWithValue("@subjects_subject_id", mes.Subject_id);
                command2.Parameters.AddWithValue("@subjects_Project_project_id", mes.Project_id);
                command2.Parameters.AddWithValue("@message_content", mes.Message_content);
                command2.Parameters.AddWithValue("@message_posting", mes.Message_posting);
                command2.ExecuteNonQuery();

                connection2.Close();

                message_lstbx.Items.Add(mes.Showmessage());
            }

            catch
            {
                MessageBox.Show("could not add message");
            }
        }
Example #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string MyConnection2 = "datasource=localhost;port=3306;username=root;password=9490";
                //get curr location before updating and check it from the set....

                string           Query1     = "select current_location from world.transport where paid_id= " + this.textBox1.Text + ";";
                MySqlConnection  MyConn2    = new MySqlConnection(MyConnection2);
                MySqlCommand     MyCommand2 = new MySqlCommand(Query1, MyConn2);
                MySqlDataAdapter adapt      = new MySqlDataAdapter(MyCommand2);
                DataTable        ds         = new DataTable();
                adapt.Fill(ds);
                string   prev_loc = ds.Rows[0][0].ToString();
                string   next_loc = this.textBox2.Text;
                string[] South    = { "Chennai", "Manipal", "Mangalore", "Udupi", "Goa", "Hyderabad" };
                string[] North    = { "Mumbai", "Delhi", "Ahemdabad", "Agra", "Goa" };
                MessageBox.Show("Previous Location: " + prev_loc + "  Current Location: " + next_loc);

                //Final location check
                string           Query3     = "select drop_location from world.delivery where paid_id= " + this.textBox1.Text + ";";
                MySqlConnection  MyConn3    = new MySqlConnection(MyConnection2);
                MySqlCommand     MyCommand3 = new MySqlCommand(Query3, MyConn3);
                MySqlDataAdapter adapt1     = new MySqlDataAdapter(MyCommand3);
                DataTable        dt         = new DataTable();
                adapt1.Fill(dt);
                string final_loc = ds.Rows[0][0].ToString();

                if (final_loc == next_loc)
                {
                    this.Hide();
                    Form1 f1 = new Form1();
                    MessageBox.Show("The Location has been reached.");
                }

                if (South.Contains(prev_loc) && South.Contains(next_loc))
                {
                    try
                    {
                        string          Query      = "Update world.transport set current_location = '" + this.textBox2.Text + "' where paid_id = " + this.textBox1.Text;
                        MySqlConnection MyConn7    = new MySqlConnection(MyConnection2);
                        MySqlCommand    MyCommand7 = new MySqlCommand(Query, MyConn7);
                        MySqlDataReader MyReader3;
                        MyConn7.Open();
                        MyReader3 = MyCommand7.ExecuteReader();     // Here our query will be executed and data saved into the database.
                        MessageBox.Show("Note: Updated the current location");
                        while (MyReader3.Read())
                        {
                        }
                        MyConn3.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

                //Previous UPDATE ROUTE

                /* try
                 * {
                 * MessageBox.Show("FIRST ELSE");
                 *       string Query = "select * from world.path_finder where paid_id ="+this.textBox1.Text;
                 *       MySqlConnection MyConn6 = new MySqlConnection(MyConnection2);
                 *       MySqlCommand MyCommand6 = new MySqlCommand(Query, MyConn6);
                 *       MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
                 *       MyAdapter.SelectCommand = MyCommand6;
                 *       DataTable dTable = new DataTable();
                 *       MyAdapter.Fill(dTable);
                 *       dataGridView1.DataSource = dTable;
                 *       //MyConn2.Close();
                 *
                 *   }
                 *   catch (Exception ex)
                 *   {
                 *       MessageBox.Show(ex.Message);
                 *   }
                 *   //BACKTRACKING SHOW ROUTE IN GRID.*/

                if (North.Contains(prev_loc) && North.Contains(next_loc))
                {
                    try
                    {
                        string          Query      = "Update world.transport set current_location= '" + this.textBox2.Text + "' where paid_id=" + this.textBox1.Text;
                        MySqlConnection MyConn4    = new MySqlConnection(MyConnection2);
                        MySqlCommand    MyCommand4 = new MySqlCommand(Query, MyConn4);
                        MySqlDataReader MyReader4;
                        MyConn4.Open();
                        MyReader4 = MyCommand4.ExecuteReader();     // Here our query will be executed and data saved into the database.
                        MessageBox.Show("Note: Updated the current location");
                        while (MyReader4.Read())
                        {
                        }
                        MyConn4.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                try
                {
                    string Query2 = "select * from world.path_finder where paid_id =" + this.textBox1.Text;

                    MySqlConnection  MyConn5    = new MySqlConnection(MyConnection2);
                    MySqlCommand     MyCommand5 = new MySqlCommand(Query2, MyConn5);
                    MySqlDataAdapter MyAdapter1 = new MySqlDataAdapter();
                    MyAdapter1.SelectCommand = MyCommand5;
                    DataTable dTable1 = new DataTable();
                    MyAdapter1.Fill(dTable1);
                    dataGridView2.DataSource = dTable1;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); }
        }
Example #8
0
        private void button2_Click(object sender, EventArgs e)
        {
            string sql        = null;
            string nome       = textBoxnome.Text;
            string email      = textBoxEmail.Text;
            string telemovel  = textBoxTel.Text;
            string dn         = textBoxDN.Text;
            string utilizador = textBoxUtilizador.Text;
            string hex        = textBoxHex.Text;
            string dec        = textBoxDec.Text;

            string connetionString = null;

            connetionString = "Server=localhost;Database=Scholendar;Uid=root";
            MySqlConnection  cnn;
            MySqlDataAdapter adapter = new MySqlDataAdapter();

            cnn = new MySqlConnection(connetionString);

            if (comboBox1.SelectedItem.ToString() == "EE")
            {
                //ClearTxt();
                if (string.IsNullOrEmpty(textBoxEmail.Text) || string.IsNullOrEmpty(textBoxnome.Text) || string.IsNullOrEmpty(textBoxTel.Text) || string.IsNullOrEmpty(textBoxUtilizador.Text))
                {
                    MessageBox.Show("Preencha todos os campos!");
                }
                else
                {
                    sql = "insert into EE (Nome, Email, Telemovel, Utilizador, Pass) values('" + nome + "', '" + email + "', '" + telemovel + "', '" + utilizador + "' , 'EE123A' )";
                    try
                    {
                        cnn.Open();
                        adapter.InsertCommand = new MySqlCommand(sql, cnn);
                        adapter.InsertCommand.ExecuteNonQuery();
                        MessageBox.Show("Encarregado de Educação Inserido!");
                        ClearTxt();
                        comboBoxEE.Items.Clear();
                        FillcomboboxEE();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                    finally
                    {
                        cnn.Close();
                    }
                }
            }
            else if (comboBox1.SelectedItem.ToString() == "Aluno")
            {
                //ClearTxt();
                if (string.IsNullOrEmpty(textBoxEmail.Text) || string.IsNullOrEmpty(textBoxnome.Text) || string.IsNullOrEmpty(textBoxTel.Text) || string.IsNullOrEmpty(textBoxUtilizador.Text) || string.IsNullOrEmpty(textBoxDN.Text) || string.IsNullOrEmpty(textBoxDec.Text) || string.IsNullOrEmpty(textBoxHex.Text) || comboBoxTurma.SelectedItem == null || comboBoxEE.SelectedItem == null)
                {
                    MessageBox.Show("Preencha todos os campos!");
                }
                else
                {
                    try
                    {
                        cnn.Open();
                        string          turma      = comboBoxTurma.SelectedItem.ToString();
                        string          Query3     = "select * from Turma where Turma ='" + turma + "'";
                        MySqlCommand    MyCommand3 = new MySqlCommand(Query3, cnn);
                        MySqlDataReader MyReader3;
                        MyReader3 = MyCommand3.ExecuteReader();
                        while (MyReader3.Read())
                        {
                            textBoxIDTurma.Text = MyReader3["ID_Turma"].ToString();
                        }
                        cnn.Close();

                        cnn.Open();
                        string          aluno      = comboBoxEE.SelectedItem.ToString();
                        string          QueryA     = "select * from EE where Nome ='" + aluno + "'";
                        MySqlCommand    MyCommand4 = new MySqlCommand(QueryA, cnn);
                        MySqlDataReader MyReader4;
                        MyReader4 = MyCommand4.ExecuteReader();
                        while (MyReader4.Read())
                        {
                            textBoxAluno.Text = MyReader4["ID_EE"].ToString();
                        }
                        cnn.Close();

                        cnn.Open();
                        string IDTurma = textBoxIDTurma.Text;
                        string ID_EE   = textBoxAluno.Text;
                        sql = "insert into Aluno (Nome, Email, Telemovel, Utilizador,DataDeNascimento,Hex,De,Pass,ID_Turma, ID_EE) values('" + nome + "', '" + email + "', '" + telemovel + "', '" + utilizador + "', '" + dn + "', '" + hex + "', '" + dec + "' , 'Aluno123A', '" + IDTurma + "' , '" + ID_EE + "' )";
                        adapter.InsertCommand = new MySqlCommand(sql, cnn);
                        adapter.InsertCommand.ExecuteNonQuery();
                        MessageBox.Show("Aluno Inserido!");
                        ClearTxt();
                        comboBoxEE.SelectedItem    = null;
                        comboBoxTurma.SelectedItem = null;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                    finally
                    {
                        cnn.Clone();
                    }
                }
            }
            else if (comboBox1.SelectedItem.ToString() == "Professor")
            {
                if (string.IsNullOrEmpty(textBoxEmail.Text) || string.IsNullOrEmpty(textBoxnome.Text) || string.IsNullOrEmpty(textBoxTel.Text) || string.IsNullOrEmpty(textBoxUtilizador.Text) || string.IsNullOrEmpty(textBoxDec.Text) || string.IsNullOrEmpty(textBoxHex.Text) || comboBoxDisc.SelectedItem == null)
                {
                    MessageBox.Show("Preencha todos os campos!");
                }
                else
                {
                    try
                    {
                        cnn.Open();
                        sql = "insert into Professor (Nome, Email, Telemovel, Utilizador, Pass, Hex, De) values('" + nome + "', '" + email + "', '" + telemovel + "', '" + utilizador + "', 'Prof123A' , '" + hex + "', '" + dec + "')";
                        adapter.InsertCommand = new MySqlCommand(sql, cnn);
                        adapter.InsertCommand.ExecuteNonQuery();
                        MessageBox.Show("Professor Inserido!");

                        cnn.Close();

                        cnn.Open();
                        string          professor = textBoxnome.Text;
                        string          query     = "select * from Professor where nome = '" + professor + "' ";
                        MySqlCommand    MyCommand = new MySqlCommand(query, cnn);
                        MySqlDataReader MyReader;
                        MyReader = MyCommand.ExecuteReader();
                        while (MyReader.Read())
                        {
                            textBoxIDProf.Text = MyReader["ID_Professor"].ToString();
                        }
                        cnn.Close();

                        string Disc1     = textBoxIDDisc.Text;
                        string Disc2     = textBoxIDDisc2.Text;
                        string Disc3     = textBoxIDDisc3.Text;
                        string Disc4     = textBoxIDDisc4.Text;
                        string Professor = textBoxIDProf.Text;

                        cnn.Open();
                        string query2 = "insert into Prof_Disc values ('" + Disc1 + "', '" + Professor + "')";
                        adapter.InsertCommand = new MySqlCommand(query2, cnn);
                        adapter.InsertCommand.ExecuteNonQuery();
                        cnn.Close();

                        if (comboBoxDisc2.SelectedItem != null)
                        {
                            cnn.Open();
                            string query3 = "insert into Prof_Disc values('" + Disc2 + "', '" + Professor + "')";
                            adapter.InsertCommand = new MySqlCommand(query3, cnn);
                            adapter.InsertCommand.ExecuteNonQuery();
                            cnn.Close();
                            if (comboBoxDisc3.SelectedItem != null)
                            {
                                cnn.Open();
                                string query4 = "insert into Prof_Disc values('" + Disc3 + "', '" + Professor + "')";
                                adapter.InsertCommand = new MySqlCommand(query4, cnn);
                                adapter.InsertCommand.ExecuteNonQuery();
                                cnn.Close();
                                if (comboBoxDisc4.SelectedItem != null)
                                {
                                    cnn.Open();
                                    string query5 = "insert into Prof_Disc values('" + Disc4 + "', '" + Professor + "')";
                                    adapter.InsertCommand = new MySqlCommand(query5, cnn);
                                    adapter.InsertCommand.ExecuteNonQuery();
                                    cnn.Close();
                                }
                            }
                        }


                        ClearTxt();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                    finally
                    {
                        cnn.Close();
                    }
                }
            }
            else if (comboBox1.SelectedItem.ToString() == "Admin")
            {
                if (string.IsNullOrEmpty(textBoxEmail.Text) || string.IsNullOrEmpty(textBoxnome.Text) || string.IsNullOrEmpty(textBoxTel.Text) || string.IsNullOrEmpty(textBoxUtilizador.Text) || string.IsNullOrEmpty(textBoxDec.Text) || string.IsNullOrEmpty(textBoxHex.Text))
                {
                    MessageBox.Show("Preencha todos os campos!");
                }
                else
                {
                    try
                    {
                        cnn.Close();
                        cnn.Open();
                        sql = "insert into Admin (Nome, Email, Telemovel, Utilizador, Pass, Hex, De) values('" + nome + "', '" + email + "', '" + telemovel + "', '" + utilizador + "', 'adm123' , '" + hex + "', '" + dec + "')";
                        adapter.InsertCommand = new MySqlCommand(sql, cnn);
                        adapter.InsertCommand.ExecuteNonQuery();
                        MessageBox.Show("Admin Inserido!");
                        ClearTxt();
                        cnn.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                    finally
                    {
                        cnn.Close();
                    }
                }
            }
        }
Example #9
0
        private void btnAddmore_Click(object sender, EventArgs e)
        {
            int   p_code = int.Parse(txtCode.Text);
            int   p_qty  = int.Parse(txtQty.Text);
            float p_unitPrice;
            int   p_stock_id, p_stock_qty;

            //find stock record by barcode
            try
            {
                //This is my connection string i have assigned the database file address path
                string MyConnection2 = "datasource=127.0.0.1;port=3306;username=root;password=;database=supermarket";
                //This is my insert query in which i am taking input from the user through windows forms
                string Query = "Select * from stock where barcode= '" + p_code + "'";
                //This is  MySqlConnection here i have created the object and pass my connection string.
                MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
                //This is command class which will handle the query and connection object.
                MySqlCommand    MyCommand2 = new MySqlCommand(Query, MyConn2);
                MySqlDataReader MyReader2;
                MyConn2.Open();
                MyReader2 = MyCommand2.ExecuteReader();     // Here our query will be executed and data saved into the database.
                while (MyReader2.Read())
                {
                    p_unitPrice = float.Parse(MyReader2.GetString(3));
                    p_stock_id  = int.Parse(MyReader2.GetString(0));
                    p_stock_qty = int.Parse(MyReader2.GetString(5));
                    int   new_stock_qty = p_stock_qty - p_qty;
                    float amount        = p_qty * p_unitPrice;

                    //remove qty from stock
                    try
                    {
                        //This is my connection string i have assigned the database file address path
                        string MyConnection4 = "datasource=127.0.0.1;port=3306;username=root;password=;database=supermarket";
                        //This is my update query in which i am taking input from the user through windows forms and update the record.
                        string Query4 = "update stock set total_qty='" + new_stock_qty + "' where barcode='" + p_code + "';";
                        //This is  MySqlConnection here i have created the object and pass my connection string.
                        MySqlConnection MyConn4    = new MySqlConnection(MyConnection4);
                        MySqlCommand    MyCommand4 = new MySqlCommand(Query4, MyConn4);
                        MySqlDataReader MyReader4;
                        MyConn4.Open();
                        MyReader4 = MyCommand4.ExecuteReader();
                        while (MyReader4.Read())
                        {
                        }
                        MyConn4.Close();//Connection closed here
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }



                    //insert sale record

                    try
                    {
                        //This is my connection string i have assigned the database file address path
                        string MyConnection3 = "datasource=127.0.0.1;port=3306;username=root;password=;database=supermarket";
                        //This is my insert query in which i am taking input from the user through windows forms
                        string Query3 = "insert into `sale` (stock_id,qty,amount) values('" + p_stock_id + "','" + p_qty + "','" + amount + "');";
                        //This is  MySqlConnection here i have created the object and pass my connection string.
                        MySqlConnection MyConn3 = new MySqlConnection(MyConnection3);
                        //This is command class which will handle the query and connection object.
                        MySqlCommand    MyCommand3 = new MySqlCommand(Query3, MyConn3);
                        MySqlDataReader MyReader3;
                        MyConn3.Open();
                        MyReader3 = MyCommand3.ExecuteReader();     // Here our query will be executed and data saved into the database.

                        while (MyReader3.Read())
                        {
                        }

                        MyConn3.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                MyConn2.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            updateData();
        }
        private void btnReleasePatient_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string          Query     = "insert into release_patient values('" + txtPatientName.Text + "','" + txtPatientAge.Text + "','" + txtContactNo.Text + "','" + txtPatientAddress.Text + "','" + txtDisease.Text + "','" + txtDocName.Text + "','" + txtDateOfAdmit.Text + "','" + txtDateOfRelease.Text + "','" + txtDays.Text + "','" + txtMedicineCost.Text + "','" + txtTestCost.Text + "', '" + txtBedCost.Text + "', '" + txtTotalCost.Text + "');";
                MySqlCommand    MyCommand = new MySqlCommand(Query, conn);
                MySqlDataReader MyReader;
                MyReader = MyCommand.ExecuteReader();
                MyReader.Close();
                MessageBox.Show("Patient Released!");

                string          Query1     = "update admitted_patient set checked_status='" + "Released" + "' where patient_contact_no='" + txtContactNo.Text + "';";
                MySqlCommand    MyCommand1 = new MySqlCommand(Query1, conn);
                MySqlDataReader MyReader1;
                MyReader1 = MyCommand1.ExecuteReader();
                MyReader1.Close();


                //These 3 block codes are responsible for free-ing the bed.
                string          Query2     = "update bed set pat_contact_no='" + "" + "', bed_status='" + "Free" + "' where pat_contact_no='" + txtContactNo.Text + "';";
                MySqlCommand    MyCommand2 = new MySqlCommand(Query2, conn);
                MySqlDataReader MyReader2;
                MyReader2 = MyCommand2.ExecuteReader();
                MyReader2.Close();

                //SELECT ward.ward_name,bed.pat_contact_no, bed.bed_no,bed.bed_type ,bed.bed_cost, bed.bed_status FROM ward,bed WHERE ward.ward_id = bed.ward_id

                string          Query3     = "DROP TABLE ward_bed;";
                MySqlCommand    MyCommand3 = new MySqlCommand(Query3, conn);
                MySqlDataReader MyReader3;
                MyReader3 = MyCommand3.ExecuteReader();
                MyReader3.Close();

                string          Query4     = "CREATE TABLE ward_bed AS SELECT ward.ward_name,bed.pat_contact_no, bed.bed_no,bed.bed_type ,bed.bed_cost, bed.bed_status FROM ward,bed WHERE ward.ward_id = bed.ward_id;";
                MySqlCommand    MyCommand4 = new MySqlCommand(Query4, conn);
                MySqlDataReader MyReader4;
                MyReader4 = MyCommand4.ExecuteReader();
                MyReader4.Close();


                string          Query5     = "DROP TABLE user.allocate_patient_bed;";
                MySqlCommand    MyCommand5 = new MySqlCommand(Query5, conn);
                MySqlDataReader MyReader5;
                MyReader5 = MyCommand5.ExecuteReader();
                MyReader5.Close();

                string          Query6     = "CREATE TABLE allocate_patient_bed AS SELECT admitted_patient.patient_name,admitted_patient.patient_age,admitted_patient.patient_contact_no,ward_bed.ward_name,ward_bed.bed_no,ward_bed.bed_type,ward_bed.bed_cost,ward_bed.bed_status FROM admitted_patient,ward_bed WHERE admitted_patient.patient_contact_no=ward_bed.pat_contact_no AND admitted_patient.ward_name=ward_bed.ward_name;";
                MySqlCommand    MyCommand6 = new MySqlCommand(Query6, conn);
                MySqlDataReader MyReader6;
                MyReader6 = MyCommand6.ExecuteReader();
                MyReader6.Close();

                txtContactNo.Text           = ""; txtPatientAge.Text = ""; txtPatientAddress.Text = ""; txtDateOfRelease.Text = "";
                txtPatientName.Text         = ""; txtDisease.Text = ""; txtDocName.Text = ""; txtDateOfAdmit.Text = "";
                txtMedicineCost.Text        = ""; txtBedCost.Text = ""; txtTestCost.Text = ""; txtTotalCost.Text = ""; txtDays.Text = "";
                btnReleasePatient.IsEnabled = false;

                /*string Query5 = "select quantity,days from user.admitted_medicine where product_name='" + comboboxMedicineName.SelectedItem + "';";
                 * MySqlCommand MyCommand5 = new MySqlCommand(Query5, conn);
                 * MySqlDataReader MyReader5;
                 * MyReader5 = MyCommand5.ExecuteReader();
                 * while (MyReader5.Read())
                 * {
                 *  string medquantyty = MyReader5.GetString(0);
                 *  x = Int32.Parse(medquantyty);
                 *  string c = this.quantity.Text;
                 *  y = Int32.Parse(c);
                 *
                 *  x = x - y;
                 * }
                 * MyReader5.Close();
                 *
                 * string Query6 = "update user.supplier set quantity='" + x.ToString() + "' where product_name='" + comboboxMedicineName.SelectedItem + "' ;";
                 * MySqlCommand MyCommand6 = new MySqlCommand(Query6, conn);
                 * MySqlDataReader MyReader6;
                 * MyReader6 = MyCommand6.ExecuteReader();
                 * MyReader6.Close();*/
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }