Esempio n. 1
0
        // 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);
            }
        }