Пример #1
0
 protected void btnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         int         c_id     = Convert.ToInt32(Session["company_id"]);
         string      vendor   = ddlVendor.SelectedItem.Text.Trim();
         string      SON      = txtSONo.Text.Trim();
         string      date     = txtdate.Text.Trim();
         string      pname    = ddlproduct.SelectedItem.Text.Trim();
         string      quantity = txtquantity.Text.Trim();
         string      price    = txtprice.Text.Trim();
         string      discount = txtdiscount.Text.Trim();
         int         p_id     = Convert.ToInt32(ddlproduct.SelectedValue);
         Tax_percent t        = new Tax_percent();
         t.company_id = c_id;
         t.product_id = p_id;
         t.All(t);
         int    tax_id         = t.tax_id;
         int    unit_id        = t.unit_id;
         string unit_name      = t.unit_name;
         string tax_percentage = t.tax_percentage;
         int    batch_id       = t.batch_id;
         ViewState["b_id"] = batch_id;
         string    batch_name  = t.batch_name;
         int       product_id  = Convert.ToInt32(ddlproduct.SelectedValue);
         decimal   SubTotal    = Convert.ToInt32(txtquantity.Text) * Convert.ToInt32(txtprice.Text);
         decimal   a           = SubTotal / 100;
         decimal   discountamt = a * decimal.Parse(discount);
         decimal   tax_amount  = a * decimal.Parse(tax_percentage);
         DataTable dt          = (DataTable)Session["table"];
         dt.Rows.Add(1, p_id, batch_id, unit_id, tax_id, SubTotal, discountamt, tax_amount, price, quantity, pname, unit_name, batch_name, tax_percentage);
         Session["table"]          = dt;
         gvSalesdetails.DataSource = dt;
         gvSalesdetails.DataBind();
         clr();
         txtBalanceAmt.Enabled = true;
         txtGivenAmt.Enabled   = true;
         calculation(SubTotal, tax_amount, discountamt);
     }
     catch (Exception ex)
     {
         ErrorLog.saveerror(ex);
     }
 }
Пример #2
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                int    c_id     = Convert.ToInt32(Session["company_id"]);
                string vendor   = ddlVendor.SelectedItem.Text.Trim();
                string SON      = txtSONo.Text.Trim();
                string date     = txtdate.Text.Trim();
                string pname    = ddlproduct.SelectedItem.Text.Trim();
                string quantity = txtquantity.Text.Trim();
                string price    = txtprice.Text.Trim();
                string discount = txtdiscount.Text.Trim();
                int    p_id     = Convert.ToInt32(ddlproduct.SelectedValue);
                if (discount == "" || discount == null)
                {
                    discount = "0";
                }
                Tax_percent t = new Tax_percent();
                t.company_id = c_id;
                t.product_id = p_id;
                t.All(t);
                int     tax_id         = t.tax_id;
                int     unit_id        = t.unit_id;
                string  unit_name      = t.unit_name;
                string  tax_percentage = t.tax_percentage;
                int     batch_id       = t.batch_id;
                string  batch_name     = t.batch_name;
                int     product_id     = Convert.ToInt32(ddlproduct.SelectedValue);
                decimal SubTotal       = Convert.ToDecimal(txtquantity.Text) * Convert.ToDecimal(txtprice.Text);
                decimal a           = SubTotal / 100;
                decimal discountamt = a * Convert.ToDecimal(discount);
                decimal tax_amount  = a * Convert.ToDecimal(tax_percentage);

                decimal   subtot          = Convert.ToDecimal(ViewState["subtot"]) - SubTotal;
                decimal   taxamount       = Convert.ToDecimal(ViewState["taxamount"]) - Convert.ToDecimal(tax_amount);
                decimal   discount_amount = Convert.ToDecimal(ViewState["dis"]) - discountamt;
                decimal   qty             = Convert.ToDecimal(ViewState["qtybefore"]) - Convert.ToDecimal(txtquantity.Text);
                DataTable dt = Session["table"] as DataTable;
                if (ViewState["id2"] != null)
                {
                    int row = Convert.ToInt32(ViewState["id"]);
                    dt.Rows[row][0]  = ViewState["id2"];
                    dt.Rows[row][1]  = ViewState["id2"];
                    dt.Rows[row][2]  = ddlproduct.SelectedValue;
                    dt.Rows[row][3]  = batch_id;
                    dt.Rows[row][4]  = unit_id;
                    dt.Rows[row][5]  = tax_id;
                    dt.Rows[row][6]  = subtot;
                    dt.Rows[row][7]  = discount_amount;
                    dt.Rows[row][8]  = taxamount;
                    dt.Rows[row][9]  = txtprice.Text.Trim();
                    dt.Rows[row][10] = qty;
                    dt.Rows[row][11] = pname;
                    dt.Rows[row][12] = unit_name;
                    dt.Rows[row][13] = batch_name;
                    dt.Rows[row][14] = tax_percentage;
                }
                gvSalesdetails.DataSource = dt;
                gvSalesdetails.DataBind();
                clr();
                updatecal();
                calculation(subtot, taxamount, discount_amount);
                //btnAdd.Visible = true;
                btnUpdate.Visible = false;
                giventotalcal(Convert.ToDecimal(lblGrandTotal.Text), Convert.ToDecimal(txtGivenAmt.Text));
            }
            catch (Exception ex)
            {
                ErrorLog.saveerror(ex);
            }
        }