private void addItemsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            panelMain.Controls.Clear();
            Add_Items Itadd = new Add_Items();

            Itadd.TopLevel = false;
            Itadd.Visible  = true;
            panelMain.Controls.Add(Itadd);
            Add_Items.tx_brcde.Focus();
        }
        private void btnAddItemAddItem_Click(object sender, EventArgs e)
        {
            //____________________________________________________________________________________________________________

            //____________________________________________________________________________________________________________


            ep_iname.SetError(txtAddItemItemName, "");
            ep_isalePrz.SetError(txtAddItemSalesPrice, "");
            ep_ipuchsPriz.SetError(lbl_p_piz, "");
            ep_isupp.SetError(cbxAddItemSupplier, "");
            ep_ictogry.SetError(cbxAddItemCatogory, "");
            ep_isubCotory.SetError(cbxAddItemSubCatogory, "");
            ep_ibrnd.SetError(cbxAddItemBrande, "");



            string warrty;

            if (cb_warnty.Checked == true)
            {
                string wtyNo = cbx_wrty_number.Text;
                string wtydu = cbx_wrty_duretion.Text;
                warrty = wtyNo + " " + wtydu;
            }
            else
            {
                warrty = "No Warranty";
            }



            try
            {
                if (txtAddItemBarcode.Text != "" || txtAddItemSerial.Text != "")
                {
                    if (txtAddItemItemName.Text != "" && txtAddItemSalesPrice.Text != "" && lbl_p_piz.Text != "" && cbxAddItemCatogory.Text != "" && cbxAddItemSubCatogory.Text != "" && cbxAddItemBrande.Text != "" && cbxAddItemSupplier.Text != "")
                    {
                        if (txtAddItemTaxRate.Text == "")
                        {
                            txtAddItemTaxRate.Text = "0.00";
                        }
                        if (txtAddItemSerial.Text == "")
                        {
                            txtAddItemSerial.Text = txtAddItemBarcode.Text;
                        }
                        //___________________________________________________________________________________________________
                        SqlDataReader srldr = itemdb.select_seril_alrdy(txtAddItemSerial.Text);
                        if (!srldr.Read())
                        {
                            //___________________________________________________________________________________________________
                            if (cb_warnty.Checked == true)
                            {
                                if (cbx_wrty_number.Text != "" && cbx_wrty_duretion.Text != "")
                                {
                                    itemdb.insert(lbl_itemNo.Text, txtAddItemSerial.Text, txtAddItemItemName.Text, Convert.ToDecimal(txtAddItemSalesPrice.Text), Convert.ToDecimal(lbl_p_piz.Text), Convert.ToDecimal(txtAddItemTaxRate.Text), txtAddItemBarcode.Text, cbxAddItemCatogory.Text, cbxAddItemSubCatogory.Text, cbxAddItemBrande.Text, cbxAddItemItemType.Text, cbxAddItemSupplier.Text, warrty, txtAddItemDiscription.Text);
                                    // MessageBox.Show("Item Added");

                                    if (cbx_stok.Text == "")
                                    {
                                        SqlDataReader dr = itemdb.select_to_Qntity(cbxAddItemCatogory.SelectedItem.ToString(), cbxAddItemSubCatogory.SelectedItem.ToString(), cbxAddItemBrande.SelectedItem.ToString());
                                        if (dr.Read())
                                        {
                                            string qt  = dr["Quntity"].ToString();
                                            int    q1  = int.Parse(qt);
                                            int    q2  = q1 + 1;
                                            string qty = q2.ToString();
                                            itemdb.update_Quntity(qty, cbxAddItemCatogory.Text, cbxAddItemSubCatogory.Text, cbxAddItemBrande.Text);
                                            // MessageBox.Show("Quntity Updated");
                                        }
                                        else
                                        {
                                            itemdb.Quntity(txtAddItemItemName.Text, cbxAddItemCatogory.Text, cbxAddItemSubCatogory.Text, cbxAddItemBrande.Text, "1", lbl_p_piz.Text, txtAddItemSalesPrice.Text);
                                            // MessageBox.Show("quntity Added");
                                        }
                                    }


                                    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                                    SqlDataReader stcdr = odr.R_stock_selec(cbx_stok.Text, cbxAddItemSupplier.Text);
                                    if (stcdr.Read())
                                    {
                                        qqty    = ""; q_count = "";
                                        qqty    = stcdr["Quntity"].ToString();
                                        q_count = stcdr["Add_Count"].ToString();

                                        if (q_count != "")
                                        {
                                            if (Convert.ToDouble(qqty) > Convert.ToDouble(q_count))
                                            {
                                                q_count = (Convert.ToDouble(q_count) + 1).ToString();
                                            }
                                        }
                                        else
                                        {
                                            q_count = "1";
                                        }

                                        odr.Update_R_stok_qty(cbx_stok.Text, cbxAddItemSupplier.Text, q_count);
                                        //MessageBox.Show("addddddd");
                                    }



                                    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



                                    if (MessageBox.Show("New Ttem Added Successfuly.", "New Item", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                                    {
                                        SqlDataReader stcdr1 = odr.R_stock_selec(cbx_stok.Text, cbxAddItemSupplier.Text);
                                        if (stcdr1.Read())
                                        {
                                            lbl_a_qty.Text   = stcdr1["Quntity"].ToString();
                                            lbl_add_qty.Text = stcdr1["Add_Count"].ToString();
                                        }
                                        //____________________________________________________________________________________
                                        if (lbl_a_qty.Text == lbl_add_qty.Text)
                                        {
                                            Main.p1.Controls.Clear();
                                            Add_Items d1 = new Add_Items();
                                            d1.TopLevel = false;
                                            d1.Visible  = true;
                                            Main.p1.Controls.Add(d1);
                                        }
                                        else
                                        {
                                            //==================================================From Item Table==========================================================//
                                            string rNo = itemdb.Itemno();
                                            if (rNo.Equals("") || rNo == null)
                                            {
                                                iNo = 001000;
                                            }
                                            else
                                            {
                                                iNo = Convert.ToInt32(rNo);
                                                iNo = iNo + 1;
                                                //MessageBox.Show(iNo.ToString());
                                            }

                                            //==============================================================================================================================//

                                            string rcNo = itemdb.getCusno();
                                            if (rcNo.Equals("") || rcNo == null)
                                            {
                                                cNo = 001000;
                                            }
                                            else
                                            {
                                                cNo = Convert.ToInt32(rcNo);
                                                cNo = cNo + 1;
                                                //MessageBox.Show(cNo.ToString());
                                            }



                                            int[] numbers = new[] { iNo, cNo };

                                            int max = numbers.Max();

                                            lbl_itemNo.Text = Convert.ToString(max);


                                            txtAddItemBarcode.Clear();
                                            txtAddItemSerial.Clear();
                                            txtAddItemBarcode.Focus();
                                        }
                                        //_____________________________________________________________________________________
                                    }
                                }

                                else
                                {
                                    ep_wanty.SetError(cbx_wrty_duretion, "Complete warranty");
                                }
                            }

                            else
                            {
                                if (txtAddItemTaxRate.Text == "")
                                {
                                    txtAddItemTaxRate.Text = "0.00";
                                }
                                if (txtAddItemSerial.Text == "")
                                {
                                    txtAddItemSerial.Text = txtAddItemBarcode.Text;
                                }

                                itemdb.insert(lbl_itemNo.Text, txtAddItemSerial.Text, txtAddItemItemName.Text, Convert.ToDecimal(txtAddItemSalesPrice.Text), Convert.ToDecimal(lbl_p_piz.Text), Convert.ToDecimal(txtAddItemTaxRate.Text), txtAddItemBarcode.Text, cbxAddItemCatogory.Text, cbxAddItemSubCatogory.Text, cbxAddItemBrande.Text, cbxAddItemItemType.Text, cbxAddItemSupplier.Text, warrty, txtAddItemDiscription.Text);
                                // MessageBox.Show("Item Added");

                                if (cbx_stok.Text == "")
                                {
                                    SqlDataReader dr = itemdb.select_to_Qntity(cbxAddItemCatogory.SelectedItem.ToString(), cbxAddItemSubCatogory.SelectedItem.ToString(), cbxAddItemBrande.SelectedItem.ToString());
                                    if (dr.Read())
                                    {
                                        string qt  = dr["Quntity"].ToString();
                                        int    q1  = int.Parse(qt);
                                        int    q2  = q1 + 1;
                                        string qty = q2.ToString();
                                        itemdb.update_Quntity(qty, cbxAddItemCatogory.Text, cbxAddItemSubCatogory.Text, cbxAddItemBrande.Text);
                                        // MessageBox.Show("Quntity Updated");
                                    }
                                    else
                                    {
                                        itemdb.Quntity(txtAddItemItemName.Text, cbxAddItemCatogory.Text, cbxAddItemSubCatogory.Text, cbxAddItemBrande.Text, "1", lbl_p_piz.Text, txtAddItemSalesPrice.Text);
                                        // MessageBox.Show("quntity Added");
                                    }
                                }


                                //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                                SqlDataReader stcdr = odr.R_stock_selec(cbx_stok.Text, cbxAddItemSupplier.Text);
                                if (stcdr.Read())
                                {
                                    qqty    = ""; q_count = "";
                                    qqty    = stcdr["Quntity"].ToString();
                                    q_count = stcdr["Add_Count"].ToString();

                                    if (q_count != "")
                                    {
                                        if (Convert.ToDouble(qqty) > Convert.ToDouble(q_count))
                                        {
                                            q_count = (Convert.ToDouble(q_count) + 1).ToString();
                                        }
                                    }
                                    else
                                    {
                                        q_count = "1";
                                    }

                                    odr.Update_R_stok_qty(cbx_stok.Text, cbxAddItemSupplier.Text, q_count);
                                    //MessageBox.Show("addddddd");
                                }



                                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



                                if (MessageBox.Show("New Ttem Added Successfuly.", "New Item", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                                {
                                    SqlDataReader stcdr1 = odr.R_stock_selec(cbx_stok.Text, cbxAddItemSupplier.Text);
                                    if (stcdr1.Read())
                                    {
                                        lbl_a_qty.Text   = stcdr1["Quntity"].ToString();
                                        lbl_add_qty.Text = stcdr1["Add_Count"].ToString();
                                    }

                                    //____________________________________________________________________________________
                                    if (lbl_a_qty.Text == lbl_add_qty.Text)
                                    {
                                        Main.p1.Controls.Clear();
                                        Add_Items d1 = new Add_Items();
                                        d1.TopLevel = false;
                                        d1.Visible  = true;
                                        Main.p1.Controls.Add(d1);
                                    }
                                    else
                                    {
                                        //==================================================From Item Table==========================================================//
                                        string rNo = itemdb.Itemno();
                                        if (rNo.Equals("") || rNo == null)
                                        {
                                            iNo = 001000;
                                        }
                                        else
                                        {
                                            iNo = Convert.ToInt32(rNo);
                                            iNo = iNo + 1;
                                            //MessageBox.Show(iNo.ToString());
                                        }

                                        //==============================================================================================================================//

                                        string rcNo = itemdb.getCusno();
                                        if (rcNo.Equals("") || rcNo == null)
                                        {
                                            cNo = 001000;
                                        }
                                        else
                                        {
                                            cNo = Convert.ToInt32(rcNo);
                                            cNo = cNo + 1;
                                            //MessageBox.Show(cNo.ToString());
                                        }



                                        int[] numbers = new[] { iNo, cNo };

                                        int max = numbers.Max();

                                        lbl_itemNo.Text = Convert.ToString(max);


                                        txtAddItemBarcode.Clear();
                                        txtAddItemSerial.Clear();
                                        txtAddItemBarcode.Focus();
                                    }
                                    //_____________________________________________________________________________________



                                    ////-----------------clear all textbox.text-----------------------
                                    //Action<Control.ControlCollection> func = null;

                                    //func = (controls) =>
                                    //{
                                    //    foreach (Control control in controls)
                                    //        if (control is TextBox)
                                    //            (control as TextBox).Clear();
                                    //        else
                                    //            func(control.Controls);
                                    //};
                                    //func(Controls);



                                    //Main.p1.Controls.Clear();
                                    //Add_Items d1 = new Add_Items();
                                    //d1.TopLevel = false;
                                    //d1.Visible = true;
                                    //Main.p1.Controls.Add(d1);
                                }
                            }
                        }
                        else
                        {
                            toolTip_check.Show("Serial number alrady in Stok", lbl_tp, 1500);
                        }
                    }
                    else
                    {
                        if (txtAddItemItemName.Text == "")
                        {
                            ep_iname.SetError(txtAddItemItemName, "Enter Item name");
                        }

                        if (txtAddItemSalesPrice.Text == "")
                        {
                            ep_isalePrz.SetError(txtAddItemSalesPrice, "Enter Item Sales Price");
                        }

                        if (lbl_p_piz.Text == "")
                        {
                            ep_ipuchsPriz.SetError(lbl_p_piz, "Enter Item Purchas Price");
                        }

                        if (cbxAddItemSupplier.Text == "")
                        {
                            ep_isupp.SetError(cbxAddItemSupplier, "Choose Supplier name");
                        }

                        if (cbxAddItemCatogory.Text == "")
                        {
                            ep_ictogry.SetError(cbxAddItemCatogory, "Choose Item Catogary");
                        }

                        if (cbxAddItemSubCatogory.Text == "")
                        {
                            ep_isubCotory.SetError(cbxAddItemSubCatogory, "Choose Item sub Catogary");
                        }

                        if (cbxAddItemBrande.Text == "")
                        {
                            ep_ibrnd.SetError(cbxAddItemBrande, "Choose Item Brande");
                        }


                        tp_required.Show("Fill Require fileds", btnAddItemAddItem, 5000);
                    }
                }
                else
                {
                    tp_seril_barcobe.Show("Must Enter Serial or Barcode For Iditify Items", lbl_tp, 4000);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }