示例#1
0
    protected void btnInvoiceSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            decimal amount    = 0;
            decimal vatper    = 0;
            decimal incamount = 0;
            decimal subamount = 0;
            int     inVat     = 0;

            invoiceEntity.Description  = txtDescription.Text;
            invoiceEntity.Amount       = Convert.ToDecimal(txtAmount.Text);
            invoiceEntity.InvoiceDate  = System.DateTime.Now.ToShortDateString();
            invoiceEntity.VatInclusive = Convert.ToInt32(chkVatInclusive.Checked);
            invoiceEntity.ClientSRNO   = ViewState["SRNO"].ToString();
            string serviceno = ViewState["SRNO"].ToString();

            amount = Convert.ToDecimal(txtAmount.Text);
            inVat  = Convert.ToInt32(chkVatInclusive.Checked);
            if (inVat == 0)
            {
                incamount = Math.Round(amount, 2);
                vatper    = Math.Round((amount * Convert.ToDecimal(0.15)) + vatper, 2);
                subamount = Math.Round(amount + vatper, 2);
            }
            else
            {
                incamount = Math.Round((amount / Convert.ToDecimal(1.15)), 2);
                vatper    = Math.Round((amount - incamount), 2);
                subamount = Math.Round((incamount + vatper), 2);
            }
            totalamount = subamount;
            invoiceEntity.TotalAmount = totalamount;
            int Result = invoiceBL.InsertInvoice(invoiceEntity);
            if (Result > 0)
            {
                lblTitle.Text      = "Thank You";
                lblTitle.ForeColor = System.Drawing.Color.Green;
                message.ForeColor  = System.Drawing.Color.Green;
                message.Text       = "Invoice Generated Successfully";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
                ClearControls();
                DataSet ds = new DataSet();
                ds = invoiceBL.GetClientSRDataPdf(ViewState["SRNO"].ToString());
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    emailid = ds.Tables[0].Rows[0]["EmailID"].ToString();
                }

                DataSet ds1 = new DataSet();
                ds1 = invoiceBL.GetInvoiceNum();
                if (ds1.Tables.Count > 0 && ds1.Tables[0].Rows.Count > 0)
                {
                    invoicenum = ds1.Tables[0].Rows[0]["InvoiceNum"].ToString();
                }

                SendMail(emailid, invoicenum, serviceno);
                string srno1           = ViewState["SRNO"].ToString();
                int    status1         = 6;
                int    res1            = serviceRequestBL.UpdateServiceStatus(status1, srno1);
                string invAmountStatus = "Not Yet Received";
                int    result1         = invoicePaymentBL.UpdateAmountStatus(invAmountStatus, invoicenum);
            }
        }
        catch
        {
            lblTitle.Text      = "Warning!";
            lblTitle.ForeColor = System.Drawing.Color.Red;
            message.ForeColor  = System.Drawing.Color.Red;
            message.Text       = "Sorry,Something went wrong, please contact administrator";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
        }
    }