private void button_Prod_Search_Click(object sender, EventArgs e)//Product Search
        {
            ProductTableDataContext p = new ProductTableDataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Study\Sem 8\OOP2 (C#)\Final\Project\FinalTermProject v2.0\FinalTermProject\FinalTermProject\Admindata.mdf;Integrated Security=True;Connect Timeout=30");

            try
            {
                var x = from a in p.Products
                        where a.Id == int.Parse(textBox_Prod_Search.Text) || a.Name.Equals(textBox_Prod_Search.Text)
                        select a;

                {
                    label_Prod_Name.Text  = x.FirstOrDefault().Name;
                    label_Bill_1.Text     = x.First().Name;
                    text_pID.Text         = x.First().Id.ToString();
                    textBox_Pd_Id.Text    = x.First().Id.ToString();
                    text_Pd_Name.Text     = x.First().Name;
                    text_Pd_Quantity.Text = x.First().Quantity.ToString();
                    text_Pd_Price.Text    = x.First().Price.ToString();


                    button_Purchase.Visible = true;
                    pictureBox2.Visible     = true;

                    dataGrid_Purchase.DataSource = x.ToList();
                }
            }
            catch
            {
                MessageBox.Show("Not Found!");
            }
        }
        private void button8_Click(object sender, EventArgs e)//UPDATE PRODUCT Button
        {
            ProductTableDataContext p = new ProductTableDataContext(strCon);

            if (textBox_Pd_Id.Text != "")
            {
                try
                {
                    var x = from a in p.Products
                            where a.Id == int.Parse(textBox_Pd_Id.Text)
                            select a;

                    x.First().Id       = int.Parse(textBox_Pd_Id.Text);
                    x.First().Name     = text_Pd_Name.Text;
                    x.First().Quantity = Double.Parse(text_Pd_Quantity.Text);
                    x.First().Price    = Double.Parse(text_Pd_Price.Text);

                    p.SubmitChanges();
                    dataGrid_Purchase.DataSource = x.ToList();

                    MessageBox.Show("Update Successful!");
                }
                catch
                {
                    MessageBox.Show("Invalid Entry!");
                }
            }
            else
            {
                MessageBox.Show("Input ID First!");
            }
        }
        private void button9_Click(object sender, EventArgs e)//BILL Button (BILL SECTION)
        {
            ProductTableDataContext p = new ProductTableDataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Study\Sem 8\OOP2 (C#)\Final\Project\FinalTermProject v2.0\FinalTermProject\FinalTermProject\Admindata.mdf;Integrated Security=True;Connect Timeout=30");



            try
            {
                for (int i = 0; i < dataGridView_Bill.Rows.Count; i++)
                {
                    total += Double.Parse(dataGridView_Bill.Rows[i].Cells["PrdAmount"].Value.ToString());
                }


                labelAmnt.Text = total.ToString();

                MessageBox.Show("Your Bill : " + total + "TK");

                var x = from a in p.Products
                        where a.Id == int.Parse(text_pID.Text)
                        select a;

                {
                    x.First().Quantity -= Double.Parse(text_Quantity.Text);

                    p.SubmitChanges();
                    dataGrid_Purchase.DataSource = x.ToList();
                }
            }
            catch
            {
                MessageBox.Show("Unsuccessful!");
            }
        }
        private void button6_Click(object sender, EventArgs e)//ADD PRODUCT Button
        {
            ProductTableDataContext p = new ProductTableDataContext(strCon);

            try
            {
                Product pd = new Product
                {
                    Id       = int.Parse(textBox_Pd_Id.Text),
                    Name     = text_Pd_Name.Text,
                    Quantity = Double.Parse(text_Pd_Quantity.Text),
                    Price    = Double.Parse(text_Pd_Price.Text)
                };

                p.Products.InsertOnSubmit(pd);
                p.SubmitChanges();
                dataGrid_Purchase.DataSource = p.Products.ToList();

                MessageBox.Show("Success!");
            }
            catch
            {
                MessageBox.Show("Error!");
            }
        }
        private void text_Quantity_TextChanged(object sender, EventArgs e)//QUANTITY Textbox (BILL SECTION)
        {
            if (text_Quantity.Equals(null) || text_Quantity.Text.Any())
            {
                try
                {
                    ProductTableDataContext p = new ProductTableDataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Study\Sem 8\OOP2 (C#)\Final\Project\FinalTermProject v2.0\FinalTermProject\FinalTermProject\Admindata.mdf;Integrated Security=True;Connect Timeout=30");

                    quantity = int.Parse(text_Quantity.Text);

                    var x = from a in p.Products
                            where a.Id == int.Parse(text_pID.Text)
                            select a;


                    textBox_Rate.Text = x.First().Price.ToString();
                    labelAmount.Text  = ((x.First().Price) * quantity).ToString();



                    p.SubmitChanges();
                }
                catch
                {
                    MessageBox.Show("Invalid Entry!");
                }
            }
        }
        private void button6_Click(object sender, EventArgs e)//ADD PRODUCT Button
        {
            ProductTableDataContext p = new ProductTableDataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Study\Sem 8\OOP2 (C#)\Final\Project\FinalTermProject v2.0\FinalTermProject\FinalTermProject\Admindata.mdf;Integrated Security=True;Connect Timeout=30");

            try
            {
                Product pd = new Product
                {
                    Id       = int.Parse(textBox_Pd_Id.Text),
                    Name     = text_Pd_Name.Text,
                    Quantity = Double.Parse(text_Pd_Quantity.Text),
                    Price    = Double.Parse(text_Pd_Price.Text)
                };

                p.Products.InsertOnSubmit(pd);
                p.SubmitChanges();
                dataGrid_Purchase.DataSource = p.Products.ToList();

                MessageBox.Show("Success!");
            }
            catch
            {
                MessageBox.Show("Error!");
            }
        }
        private void button8_Click(object sender, EventArgs e)//UPDATE PRODUCT Button
        {
            ProductTableDataContext p = new ProductTableDataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Study\Sem 8\OOP2 (C#)\Final\Project\FinalTermProject v2.0\FinalTermProject\FinalTermProject\Admindata.mdf;Integrated Security=True;Connect Timeout=30");

            if (textBox_Pd_Id.Text != "")
            {
                try
                {
                    var x = from a in p.Products
                            where a.Id == int.Parse(textBox_Pd_Id.Text)
                            select a;

                    x.First().Id       = int.Parse(textBox_Pd_Id.Text);
                    x.First().Name     = text_Pd_Name.Text;
                    x.First().Quantity = Double.Parse(text_Pd_Quantity.Text);
                    x.First().Price    = Double.Parse(text_Pd_Price.Text);

                    p.SubmitChanges();
                    dataGrid_Purchase.DataSource = x.ToList();

                    MessageBox.Show("Update Successful!");
                }
                catch
                {
                    MessageBox.Show("Invalid Entry!");
                }
            }
            else
            {
                MessageBox.Show("Input ID First!");
            }
        }
        private void text_Quantity_TextChanged(object sender, EventArgs e)//QUANTITY Textbox (BILL SECTION)
        {
            if (text_Quantity.Equals(null) || text_Quantity.Text.Any())
            {
                try
                {
                    ProductTableDataContext p = new ProductTableDataContext(strCon);

                    quantity = int.Parse(text_Quantity.Text);

                    var x = from a in p.Products
                            where a.Id == int.Parse(text_pID.Text)
                            select a;


                    textBox_Rate.Text = x.First().Price.ToString();
                    labelAmount.Text  = ((x.First().Price) * quantity).ToString();



                    p.SubmitChanges();
                }
                catch
                {
                    MessageBox.Show("Invalid Entry!");
                }
            }
        }
        private void button_Prod_Search_Click(object sender, EventArgs e)//Product Search
        {
            ProductTableDataContext p = new ProductTableDataContext(strCon);

            try
            {
                var x = from a in p.Products
                        where a.Id == int.Parse(textBox_Prod_Search.Text) || a.Name.Equals(textBox_Prod_Search.Text)
                        select a;

                {
                    label_Prod_Name.Text  = x.FirstOrDefault().Name;
                    label_Bill_1.Text     = x.First().Name;
                    text_pID.Text         = x.First().Id.ToString();
                    textBox_Pd_Id.Text    = x.First().Id.ToString();
                    text_Pd_Name.Text     = x.First().Name;
                    text_Pd_Quantity.Text = x.First().Quantity.ToString();
                    text_Pd_Price.Text    = x.First().Price.ToString();


                    button_Purchase.Visible = true;
                    pictureBox2.Visible     = true;

                    dataGrid_Purchase.DataSource = x.ToList();
                }
            }
            catch
            {
                MessageBox.Show("Not Found!");
            }
        }
        private void button9_Click(object sender, EventArgs e)//BILL Button (BILL SECTION)
        {
            ProductTableDataContext p = new ProductTableDataContext(strCon);



            try
            {
                for (int i = 0; i < dataGridView_Bill.Rows.Count; i++)
                {
                    total += Double.Parse(dataGridView_Bill.Rows[i].Cells["PrdAmount"].Value.ToString());
                }


                labelAmnt.Text = total.ToString();

                MessageBox.Show("Your Bill : " + total + "TK");

                var x = from a in p.Products
                        where a.Id == int.Parse(text_pID.Text)
                        select a;

                {
                    x.First().Quantity -= Double.Parse(text_Quantity.Text);

                    p.SubmitChanges();
                    dataGrid_Purchase.DataSource = x.ToList();
                }
            }
            catch
            {
                MessageBox.Show("Unsuccessful!");
            }
        }
        //-----------------------------------END OF UPDATE INFO-----------------------------------------



        //-----------------------------------PURCHASE PRODUCT-----------------------------------------

        private void b4_Click(object sender, EventArgs e)//PRODUCT PURCHASE Button
        {
            ProductTableDataContext pd = new ProductTableDataContext(strCon);

            dataGrid_Purchase.DataSource = pd.Products.ToList();

            panel_Mem_Info.Visible         = false;
            panel_Purchase_Product.Visible = true;
            panel_Home.Visible             = false;
            panel_AddMem.Visible           = false;
            panel_Update_Member.Visible    = false;
            panel_Admin.Visible            = false;
        }
        //-----------------------------------END OF UPDATE INFO-----------------------------------------



        //-----------------------------------PURCHASE PRODUCT-----------------------------------------

        private void b4_Click(object sender, EventArgs e)//PRODUCT PURCHASE Button
        {
            ProductTableDataContext pd = new ProductTableDataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Study\Sem 8\OOP2 (C#)\Final\Project\FinalTermProject v2.0\FinalTermProject\FinalTermProject\Admindata.mdf;Integrated Security=True;Connect Timeout=30");

            dataGrid_Purchase.DataSource = pd.Products.ToList();

            panel_Mem_Info.Visible         = false;
            panel_Purchase_Product.Visible = true;
            panel_Home.Visible             = false;
            panel_AddMem.Visible           = false;
            panel_Update_Member.Visible    = false;
            panel_Admin.Visible            = false;
        }
        private void buttonRefresh_P_Click(object sender, EventArgs e) //REFRESH PRODUCT Button
        {
            ProductTableDataContext pd = new ProductTableDataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Study\Sem 8\OOP2 (C#)\Final\Project\FinalTermProject v2.0\FinalTermProject\FinalTermProject\Admindata.mdf;Integrated Security=True;Connect Timeout=30");

            dataGrid_Purchase.DataSource = pd.Products.ToList();
            textBox_Prod_Search.Text     = "";
            pictureBox2.Visible          = false;
            label_Prod_Name.Text         = "";
            button_Purchase.Visible      = false;
            textBox_Pd_Id.Text           = "";
            text_Pd_Name.Text            = "";
            text_Pd_Quantity.Text        = "";
            text_Pd_Price.Text           = "";
        }
        private void buttonRefresh_P_Click(object sender, EventArgs e) //REFRESH PRODUCT Button
        {
            ProductTableDataContext pd = new ProductTableDataContext(strCon);

            dataGrid_Purchase.DataSource = pd.Products.ToList();
            textBox_Prod_Search.Text     = "";
            pictureBox2.Visible          = false;
            label_Prod_Name.Text         = "";
            button_Purchase.Visible      = false;
            textBox_Pd_Id.Text           = "";
            text_Pd_Name.Text            = "";
            text_Pd_Quantity.Text        = "";
            text_Pd_Price.Text           = "";
        }
        //-----------------------------------END OF PURCHASE PRODUCT-----------------------------------------



        //----------------------------------------BILL SECTION-----------------------------------------------

        private void text_pID_TextChanged(object sender, EventArgs e)//PRODUCT ID (BILL SECTION)
        {
            if (text_pID.Equals(null) || text_pID.Text.Any())
            {
                ProductTableDataContext p = new ProductTableDataContext(strCon);
                try
                {
                    var x = from a in p.Products
                            where a.Id == int.Parse(text_pID.Text)
                            select a;

                    {
                        label_Bill_1.Text  = x.FirstOrDefault().Name;
                        textBox_Rate.Text  = x.First().Price.ToString();
                        text_Quantity.Text = "";
                    }
                }
                catch
                {
                    MessageBox.Show("Please insert a valid product ID");
                }
            }
        }
        //-----------------------------------END OF PURCHASE PRODUCT-----------------------------------------



        //----------------------------------------BILL SECTION-----------------------------------------------

        private void text_pID_TextChanged(object sender, EventArgs e)//PRODUCT ID (BILL SECTION)
        {
            if (text_pID.Equals(null) || text_pID.Text.Any())
            {
                ProductTableDataContext p = new ProductTableDataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Study\Sem 8\OOP2 (C#)\Final\Project\FinalTermProject v2.0\FinalTermProject\FinalTermProject\Admindata.mdf;Integrated Security=True;Connect Timeout=30");
                try
                {
                    var x = from a in p.Products
                            where a.Id == int.Parse(text_pID.Text)
                            select a;

                    {
                        label_Bill_1.Text  = x.FirstOrDefault().Name;
                        textBox_Rate.Text  = x.First().Price.ToString();
                        text_Quantity.Text = "";
                    }
                }
                catch
                {
                    MessageBox.Show("Please insert a valid product ID");
                }
            }
        }
        private void button2_Click_1(object sender, EventArgs e) //ADD Items (BILL SECTIOIN)
        {
            ProductTableDataContext p = new ProductTableDataContext(strCon);

            var x = from a in p.Products
                    where a.Id == int.Parse(text_pID.Text)
                    select a;

            if (text_Quantity.Text == "" || int.Parse(text_Quantity.Text) == 0 || textBox_Rate.Equals(null))
            {
                MessageBox.Show("Please input quantity!");
            }
            else
            {
                try
                {
                    if (x.First().Quantity >= int.Parse(text_Quantity.Text))
                    {
                        string s = ((x.First().Price) * quantity).ToString();

                        labelAmount.Text = s;

                        dataGridView_Bill.Rows.Add(text_pID.Text, x.First().Name, textBox_Rate.Text, text_Quantity.Text, s);
                    }

                    else
                    {
                        MessageBox.Show("Stock Out!");
                    }
                }
                catch
                {
                    MessageBox.Show("Error!");
                }
            }
        }
        private void button2_Click_1(object sender, EventArgs e) //ADD Items (BILL SECTIOIN)
        {
            ProductTableDataContext p = new ProductTableDataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Study\Sem 8\OOP2 (C#)\Final\Project\FinalTermProject v2.0\FinalTermProject\FinalTermProject\Admindata.mdf;Integrated Security=True;Connect Timeout=30");

            var x = from a in p.Products
                    where a.Id == int.Parse(text_pID.Text)
                    select a;

            if (text_Quantity.Text == "" || int.Parse(text_Quantity.Text) == 0 || textBox_Rate.Equals(null))
            {
                MessageBox.Show("Please input quantity!");
            }
            else
            {
                try
                {
                    if (x.First().Quantity >= int.Parse(text_Quantity.Text))
                    {
                        string s = ((x.First().Price) * quantity).ToString();

                        labelAmount.Text = s;

                        dataGridView_Bill.Rows.Add(text_pID.Text, x.First().Name, textBox_Rate.Text, text_Quantity.Text, s);
                    }

                    else
                    {
                        MessageBox.Show("Stock Out!");
                    }
                }
                catch
                {
                    MessageBox.Show("Error!");
                }
            }
        }