Exemplo n.º 1
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            int purchaseId = Convert.ToInt32(hdnPurchaseId.Value);
            //lblcheckDoubleError.Text = string.Empty;
            int     productId       = Convert.ToInt32(ddlproduct.SelectedValue);
            decimal enteredQuantity = Convert.ToDecimal(txtquantity.Text);

            try
            {
                //Get Original price, Tax and discount happened during Purchase
                var productDetails = context.sp_GetPurchaseDetailsById(purchaseId).ToList();
                if (productDetails != null)
                {
                    var oneproductDetail = productDetails.Where(w => w.product_id == productId);
                    if (!Convert.ToBoolean(ValidateQuantity(enteredQuantity, productId, purchaseId)[0]))
                    {
                        decimal subTotal         = Convert.ToDecimal(txtquantity.Text) * Convert.ToDecimal(oneproductDetail.FirstOrDefault().purchase_rate);
                        decimal a                = subTotal / 100;
                        decimal discount_percent = (Convert.ToDecimal(oneproductDetail.FirstOrDefault().dicount_amt) * 100) / Convert.ToDecimal(oneproductDetail.FirstOrDefault().amount);
                        decimal discountamt      = a * Convert.ToDecimal(discount_percent.ToString("0.##"));
                        decimal tax_amount       = a * Convert.ToDecimal(oneproductDetail.FirstOrDefault().tax_percentage);

                        clr();
                        calculation(subTotal, tax_amount, discountamt);
                        txtPaidAmt.Enabled = true;

                        DataTable tbl = (DataTable)ViewState["Details"];

                        tbl.Rows.Add(oneproductDetail.FirstOrDefault().purchasedetails_id, productId, oneproductDetail.FirstOrDefault().batch_id, oneproductDetail.FirstOrDefault().unit_id,
                                     oneproductDetail.FirstOrDefault().tax_id, subTotal, discountamt, tax_amount, oneproductDetail.FirstOrDefault().purchase_rate, enteredQuantity,
                                     oneproductDetail.FirstOrDefault().product_name, oneproductDetail.FirstOrDefault().unit_name, oneproductDetail.FirstOrDefault().batch_name,
                                     oneproductDetail.FirstOrDefault().tax_percentage);
                        ViewState["Details"] = tbl;
                        this.BindGrid();
                        ddlproduct.Items.FindByValue(productId.ToString()).Enabled = false;
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLog.saveerror(ex);
            }
        }