private async Task <List <AmountSellShow> > AmountSellForShow(List <OrderDetail> orderDetails)
        {
            List <Product> products = await ControlerMethods.GetProductsAsync();

            List <AmountSellShow> amountSellShows = new List <AmountSellShow>();

            foreach (OrderDetail od in orderDetails)
            {
                if (amountSellShows.Exists(x => x.ProductId == od.ProductId))
                {
                    amountSellShows.Where(x => x.ProductId == od.ProductId).FirstOrDefault()
                    .AmountSell += (od.UnitPriceSale - od.UnitPriceSale * Convert.ToDecimal(od.discount)) * od.qty;
                    amountSellShows.Where(x => x.ProductId == od.ProductId).FirstOrDefault()
                    .Qty += od.qty;
                }
                else
                {
                    AmountSellShow amountSell = new AmountSellShow();
                    amountSell.ProductId   = od.ProductId;
                    amountSell.ProductName = products.Where(x => x.ProductId.Equals(od.ProductId)).FirstOrDefault().ProductName;
                    amountSell.AmountSell  = (od.UnitPriceSale - od.UnitPriceSale * Convert.ToDecimal(od.discount)) * od.qty;
                    amountSell.Qty         = od.qty;
                    amountSellShows.Add(amountSell);
                }
            }
            return(amountSellShows);
        }
        private async void btnDeleteAddedProduct_Click(object sender, EventArgs e)
        {
            if (dataQtyProduct.SelectedRows.Count == 1)
            {
                try
                {
                    Product product = (Product)dataQtyProduct.SelectedRows[0].DataBoundItem;
                    await ControlerMethods.DeleteProduct(product);

                    dataQtyProduct.DataSource = await ControlerMethods.GetProductsAsync();
                }
                catch
                {
                    MessageBox.Show("بعد از فروش محصول امکان حذف وجود ندارد میتوانید تعداد محصول را به صفر تغییر دهید    " + "\n",
                                    "خطا",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("لطفا یک سطر را انتخاب نمایید   " + "\n",
                                "خطا",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
        //tab selection change uncompited
        private async void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 2)
            {
                dataQtyProduct.DataSource = await ControlerMethods.GetProductsAsync();

                dataSupliers.DataSource = await ControlerMethods.GetSupliersAsync();

                DataCategory.DataSource = await ControlerMethods.GetCategoryAsync();

                dataSupliers.Columns["SupplierId"].Visible = false;
                DataCategory.Columns["CategoryId"].Visible = false;
                if (comboCat.Items.Count < 1)
                {
                    List <Category> categories = await ControlerMethods.GetCategoryAsync();

                    foreach (Category cat in categories)
                    {
                        comboCat.Items.Add(cat.CategoryName);
                    }
                    List <Suppliers> suppliers = await ControlerMethods.GetSupliersAsync();

                    foreach (Suppliers sup in suppliers)
                    {
                        comboSup.Items.Add(sup.CompanyName);
                    }
                }
            }
            else if (tabControl1.SelectedIndex == 0)
            {
                FrmEmpMain_Load(sender, e);
            }
            else if (tabControl1.SelectedIndex == 3)
            {
                List <SqlParameter> sqlParameters = new List <SqlParameter>();
                sqlParameters.Add(new SqlParameter("date1", dateSumOrder1.Value.Date));
                sqlParameters.Add(new SqlParameter("date2", dateSumOrder2.Value.Date.AddMinutes(1439)));

                dataSumOrders.DataSource = await DataAccessAsync.ExecSPAsync("Sales.dvgSumOrders", sqlParameters);

                dataSumOrders.Columns["sumProfit"].DefaultCellStyle.Format = "#,#";
                dataSumOrders.Columns["sumSell"].DefaultCellStyle.Format   = "#,#";
                dataSumOrders.Columns["sumBuy"].DefaultCellStyle.Format    = "#,#";
                dataSumOrders.Columns["Column1"].HeaderText   = "نام کارمند";
                dataSumOrders.Columns["sumProfit"].HeaderText = "مجموع سود";
                dataSumOrders.Columns["sumBuy"].HeaderText    = "محموع خرید";
                dataSumOrders.Columns["sumSell"].HeaderText   = "مجموع فروش ";
                dataSumOrders.Columns["Column2"].Visible      = false;
            }
            else if (tabControl1.SelectedIndex == 4)
            {
                dgvExistProduct.DataSource = await DataAccessAsync.ExecSPAsync("Production.GetProductByCode");
            }
        }
        //add product available COMPITED
        private async void btnDbAddProduct_Click(object sender, EventArgs e)
        {
            try
            {
                List <Category> categories = await ControlerMethods.GetCategoryAsync();

                List <Suppliers> suppliers = await ControlerMethods.GetSupliersAsync();

                List <Product> products = await ControlerMethods.GetProductsAsync();

                Product product = new Product();
                product.CategoryId     = categories.Where(x => x.CategoryName.Equals(comboCat.Text.ToString())).FirstOrDefault <Category>().CategoryId;
                product.SupplierId     = suppliers.Where(x => x.CompanyName.Equals(comboSup.Text.ToString())).FirstOrDefault <Suppliers>().SupplierId;
                product.ProductName    = txtAddProductName.Text;
                product.ProuductCode   = txtAddProductCode.Text;
                product.Qty            = Convert.ToInt32(txtAddProductQty.Text);
                product.Tax            = Convert.ToInt32(txtAddProductTax.Text) / 100;
                product.UnitPriceBuy   = Convert.ToInt32(txtAddProductBuy.Text);
                product.UnitPriceSales = Convert.ToInt32(txtAddProductSale.Text);
                product.Discount       = Convert.ToDouble(txtAddProductDiscount.Text) / 100;
                FrmEmpMain_Load(sender, e);

                if (products.Where(x => x.ProuductCode.Equals(product.ProuductCode)).Count() > 0)
                {
                    DialogResult dialogResult = MessageBox.Show(String.Format("محصول موجود می باشد آیا مایل به افزودن تعداد وارد شده می باشید  "),
                                                                "اخطار",
                                                                MessageBoxButtons.YesNo,
                                                                MessageBoxIcon.Warning);
                    if (dialogResult == DialogResult.Yes)
                    {
                        await ControlerMethods.CheckAndSetProduct(product);

                        MessageBox.Show(String.Format("با موفقیت ثبت گردید "),
                                        "موفق",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                }
                else
                {
                    await ControlerMethods.CheckAndSetProduct(product);
                }

                dataQtyProduct.DataSource = await ControlerMethods.GetProductsAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show("خطا در هنگام انجام عملایات  " + "\n" + ex.GetBaseException().ToString(),
                                "خطا",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
        // add edited product and update product
        private async void btnAddEditedProduct_Click(object sender, EventArgs e)
        {
            try
            {
                List <Category> categories = await ControlerMethods.GetCategoryAsync();

                List <Suppliers> suppliers = await ControlerMethods.GetSupliersAsync();

                List <Product> products = await ControlerMethods.GetProductsAsync();

                Product product = new Product();
                product.ProductId      = products.Where(x => x.ProuductCode.Equals(txtAddProductCode.Text)).FirstOrDefault <Product>().ProductId;
                product.CategoryId     = categories.Where(x => x.CategoryName.Equals(comboCat.Text.ToString())).FirstOrDefault <Category>().CategoryId;
                product.SupplierId     = suppliers.Where(x => x.CompanyName.Equals(comboSup.Text.ToString())).FirstOrDefault <Suppliers>().SupplierId;
                product.ProductName    = txtAddProductName.Text;
                product.ProuductCode   = txtAddProductCode.Text;
                product.Qty            = Convert.ToInt32(txtAddProductQty.Text);
                product.Tax            = Convert.ToInt32(txtAddProductTax.Text) / 100;
                product.UnitPriceBuy   = Convert.ToInt32(txtAddProductBuy.Text);
                product.UnitPriceSales = Convert.ToInt32(txtAddProductSale.Text);
                product.Discount       = Convert.ToDouble(txtAddProductDiscount.Text) / 100;

                FrmEmpMain_Load(sender, e);
                await ControlerMethods.UpdateProductAsync(product);

                MessageBox.Show(String.Format("با موفقیت ثبت گردید "),
                                "موفق",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                dataQtyProduct.DataSource = await ControlerMethods.GetProductsAsync();

                btnAddEditedProduct.Visible = false;
                btnDbAddProduct.Enabled     = true;
                txtAddProductCode.Enabled   = true;
                txtAddProductName.Text      = "";
                txtAddProductCode.Text      = "";
                txtAddProductQty.Text       = "";
                txtAddProductTax.Text       = "0";
                txtAddProductBuy.Text       = "";
                txtAddProductSale.Text      = "";
                txtAddProductDiscount.Text  = "";
            }
            catch (Exception ex)
            {
                MessageBox.Show("خطا در هنگام انجام عملایات  " + "\n" + ex.GetBaseException().ToString(),
                                "خطا",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
        //btn add product new factor section
        private async void btnAddProduct_Click(object sender, EventArgs e)
        {
            AddProductDetails();
            LoadSoldProductTodata();
            _ProductList = await ControlerMethods.GetProductsAsync();

            lblTotal1.Text     = String.Format("{0:#,#}", ControlerMethods.AmountOfSale(ProductToOrderDetails(_SoldProduct)));
            lblTotalCount.Text = ControlerMethods.TotalOfQty(ProductToOrderDetails(_SoldProduct)).ToString();
            Product temppr = new Product()
            {
                ProductName = "", ProuductCode = "", Qty = 1, Discount = 0, UnitPriceSales = 0
            };

            LoadProductTotxt(temppr);
            txtPackPrice.Text = "0";
        }
        //COMPLITED
        private async void txtAddProductCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                try
                {
                    List <Category> categories = await ControlerMethods.GetCategoryAsync();

                    List <Suppliers> suppliers = await ControlerMethods.GetSupliersAsync();

                    List <Product> products = await ControlerMethods.GetProductsAsync();

                    if (products.Where(x => x.ProuductCode.Equals(txtAddProductCode.Text)).Count() == 1)
                    {
                        DialogResult dialogResult = MessageBox.Show("محصول موجود می باشد \n یک عدد به محصول افزوده شود ؟ ", "توجه", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (dialogResult == DialogResult.Yes)
                        {
                            Product product = (Product)products.Where(x => x.ProuductCode.Equals(txtAddProductCode.Text)).FirstOrDefault <Product>();
                            product.Qty = 1;
                            await ControlerMethods.CheckAndSetProduct(product);

                            dataQtyProduct.DataSource = await ControlerMethods.GetProductsAsync();

                            if (CheckShowDialog.Equals(null))
                            {
                                CheckShowDialog =
                                    MessageBox.Show("هر بار سوال شود ؟", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning).Equals(DialogResult.Yes) ?   true :  false;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("لطفا مقادیر را برسی نمایید  " + "\n" + ex.Message.ToString(),
                                    "خطا",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }
        }
        private async void txtTabAddProductSearch_TextChanged(object sender, EventArgs e)
        {
            List <Product> _ProductListTa2 = await ControlerMethods.GetProductsAsync();

            List <Product> ListProductsTab2 = _ProductList.Where(x => x.ProuductCode.StartsWith(txtTabAddProductSearch.Text.Trim())).ToList <Product>();
            BindingSource  bs = new BindingSource();

            bs.Clear();
            bs.ResetBindings(false);
            if (txtTabAddProductSearch.Text.Equals(""))
            {
                if (_ProductListTa2 != null)
                {
                    bs.DataSource             = ListProductsTab2;
                    dataQtyProduct.DataSource = bs;
                }
            }
            else
            {
                bs.DataSource             = ListProductsTab2;
                dataQtyProduct.DataSource = bs;
            }
        }
        private async void FrmEmpMain_Load(object sender, EventArgs e)
        {
            //add customer info
            Customers customer = await CustCheck();

            txtCustomerCode.Text  = customer.CustId.ToString();
            txtCustomerName.Text  = customer.CompanyName;
            txtCustomerPhone.Text = customer.Phone;
            //load product
            _ProductList = await ControlerMethods.GetProductsAsync();

            ListProducts = await ControlerMethods.GetProductsAsync();

            LoadProductTodata();
            LoadSoldProductTodata();

            //page setings
            btnAddEditedProduct.Visible = false;
            if (!_emp.Title.Equals("admin"))
            {
                if (tabControl1.TabCount > 2)
                {
                    tabControl1.TabPages.Remove(TabAddProductAndCat);
                    tabControl1.TabPages.RemoveAt(2);
                    tabControl1.TabPages.Remove(TabExistProduct);
                }
            }
            else
            {
                if (tabControl1.TabCount < 2)
                {
                    tabControl1.TabPages.Add(TabAddProductAndCat);
                    tabControl1.TabPages.Add(TabManage);
                    tabControl1.TabPages.Add(TabExistProduct);
                }
            }
        }