Example #1
0
        protected void btnSvPrvInv_Click(object sender, EventArgs e)
        {
            int ClId = 0;

            try
            {
                // Session["InvoiceId"] = null;
                int mode = 0, Invoiceid = 0;
                BLAddInvoice blgetIn = new BLAddInvoice();
                SqlDataReader dr = blgetIn.GetInvoiceId1();
                if (dr.HasRows)
                {
                    dr.Read();
                    Invoiceid = dr.GetInt32(0);
                    dr.Close();
                }
                Invoiceid++;
                string InvoiceNo = Session["BillNo"] + Invoiceid.ToString();
                DateTime date = Convert.ToDateTime(txtDtInvce.Text);
                ClId = Convert.ToInt32(Session["ClId"]);
                decimal amt = decimal.Parse(txtAmtAddInvce.Text);
                decimal OtherChrge = Convert.ToDecimal(0);
                decimal TotAmt = Convert.ToDecimal(txtAmtAddInvce.Text);
                string remark = txtRemrk.Text;
                string status = "In Process";
                int isdel = 0;
                if (chkbxisDel.Checked)
                    isdel = 1;
                else
                    isdel = 0;
                int app = 0;
                if (chkbxAppInv.Checked)
                    app = 1;
                else
                    app = 0;
                if (GdVwAddInvce.Rows.Count == 0)
                {
                    lblSelProjectMessage.Text = "Please Select At Least One Project";
                }
                else
                {
                    fillSelUnselectedProjects();
                    int InvId;
                    if (Session["InvoiceId"] != null)
                    {
                        InvoiceNo = txtBillNo.Text;
                        InvId = int.Parse(Session["InvoiceId"].ToString());
                        mode = 1;

                        if (dtSelProject.Rows.Count == 0)
                        {
                            lblSelProjectMessage.Text = "Please Select At Least One Project";
                        }
                        else
                        {
                            blgetIn.AddInvoice(InvId, InvoiceNo, date, ClId, amt, OtherChrge, TotAmt, remark, status, isdel, app, mode);
                            SaveProjectDetail(InvId, mode);
                            HiddenFieldInvoiceId.Value = Convert.ToString(InvId);
                            lblResult.Visible = true;
                            lblResult.Text = "Invoice Details are Updated Successfully";
                            //ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", "Invoice.aspx?InvoiceID=" + InvId));
                            Generate_Invoice_and_Annexure();
                            //Session["InvoiceId"] = null;
                            clearfilelds();
                        }
                    }
                    else
                    {
                        if (dtSelProject.Rows.Count == 0)
                        {
                            lblSelProjectMessage.Text = "please select atleast one project";
                        }
                        else
                        {
                            blgetIn.AddInvoice(Invoiceid, InvoiceNo, date, ClId, amt, OtherChrge, TotAmt, remark, status, isdel, app, mode);
                            SaveProjectDetail(Invoiceid, mode);
                            HiddenFieldInvoiceId.Value = Convert.ToString(Invoiceid);
                            lblResult.Visible = true;
                            lblResult.Text = "Invoice Details are Added Successfully";
                            //ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", "Invoice.aspx?InvoiceID=" + Invoiceid));
                            Generate_Invoice_and_Annexure();
                            clearfilelds();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lblCatchError.Text = ex.Message.ToString();
            }
            string amount = txtAmtAddInvce.Text;
            decimal TotAmt1 = Convert.ToDecimal(txtAmtAddInvce.Text);
        }