protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { #region InvoiceMaster.. _invmstr.InvoiceNo = (lblPrefix.Text + txtInvoiceNo.Text.Trim()); _invmstr.CompanyId = Convert.ToInt16(Session["CompanyId"]); _invmstr.CreatedDate = Convert.ToDateTime(txtDate.Text); _invmstr.CustomerName = txtCustName.Text.Trim(); _invmstr.Address = txtCustAddress.Text.Trim(); _invmstr.PhoneNo = Convert.ToDouble(txtCustMobile.Text.Trim()); _invmstr.EmailId = txtCustEmail.Text.Trim(); _invmstr.SubTotalAmount = Convert.ToDouble(lblSubTotal.Text); if (ddlTax1.SelectedItem.Text == "Select") { _invmstr.TaxName1 = ""; } else { _invmstr.TaxName1 = ddlTax1.SelectedItem.Text; } _invmstr.TaxRate1 = Convert.ToDouble(lblTax1.Text); if (ddlTax2.SelectedItem.Text == "Select") { _invmstr.TaxName2 = ""; } else { _invmstr.TaxName2 = ddlTax2.SelectedItem.Text; } _invmstr.TaxRate2 = Convert.ToDouble(lblTax2.Text); _invmstr.DiscountRate = Convert.ToDouble(txtDiscount.Text); _invmstr.AdditionCharge = Convert.ToDouble(txtAddCharge.Text); _invmstr.NetAmount = Convert.ToDouble(lblTotalPrice.Text); _invmstr.Comment = txtComment.Text.Trim(); _invmstr.SalePersonName = txtSalePerson.Text.Trim(); _invmstr.PaymentStatus = Convert.ToInt16(ddlPaymentStatus.SelectedItem.Value); _invmstr.LastUpdateDate = Convert.ToDateTime(DateTime.Now); #endregion int flag1 = _obj.Add_InvoiceMaster(_invmstr); if (flag1 == 0) { ViewState["InvoiceId"] = Convert.ToString(_sobj.LastInvoiceId()); } else { ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('You have not Successfully InvoiceMaster..')</script>"); return; } #region InvoiceDetails.. int r = 0, l = _dtTemp.Rows.Count; for (r = 0; r < l; r++) { _invdtl.InvoiceId = Convert.ToInt16(ViewState["InvoiceId"]); _invdtl.ItemName = _dtTemp.Rows[r][0].ToString(); _invdtl.ItemDesc = _dtTemp.Rows[r][1].ToString(); _invdtl.UnitRate = Convert.ToDouble(_dtTemp.Rows[r][2]); _invdtl.Quantity = Convert.ToInt16(_dtTemp.Rows[r][3]); if (Convert.ToString(_dtTemp.Rows[r][4]) == "True") { _invdtl.IsTaxable = 1; } else { _invdtl.IsTaxable = 0; } _invdtl.Amount = Convert.ToDouble(_dtTemp.Rows[r][5]); int flag2 = _obj.Add_InvoiceDetail(_invdtl); if (flag2 == 1) { ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('You have not Successfully InvoiceDetail..')</script>"); return; } } #endregion #region InvoicePayment.. if (ddlPaymentStatus.SelectedItem.Text == "Paid") { _invpay.InvoiceId = Convert.ToInt16(ViewState["InvoiceId"]); _invpay.PaidAmount = Convert.ToDouble(lblTotalPrice.Text); _invpay.PaymentDate = Convert.ToDateTime(txtDate.Text); _invpay.PaymentMethod = ddlPaymentMethod.SelectedItem.Text; _invpay.CardNo = txtCardNo.Text.Trim(); _invpay.Comment = txtComment.Text.Trim(); int flag3 = _obj.Add_InvoicePayment(_invpay); if (flag3 == 0) { Response.Redirect("~/companyadmin/InvoiceView.aspx?index=" + ViewState["InvoiceId"] + "&Chk=0"); } else { ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('You have not Successfully InvoicePayment..')</script>"); return; } } else { Response.Redirect("~/companyadmin/InvoiceView.aspx?index=" + ViewState["InvoiceId"] + "&Chk=0"); } #endregion } }