Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                BLAddInvoice blAddCl = new BLAddInvoice();
                txtDtInvce.Text = System.DateTime.Now.ToShortDateString();
                if ((HttpContext.Current.Session["LoginId"]) == null)
                {
                    Response.Redirect("~/Login.aspx");
                }
                Session["SelectProject"] = 0;
                if (Page.IsPostBack)
                {
                    Session["dtgetselectedRecords"] = null;
                }
                SqlDataReader dr = blAddCl.getClientInvce();
                if (dr.HasRows == true)
                {
                    while (dr.Read())
                        drpdwnClientNm.Items.Add(dr.GetString(0));
                    drpdwnClientNm.Items.Insert(0, new ListItem("--Select--", "-1"));
                    dr.Close();
                }

                if (!Page.IsPostBack)
                {
                    if (Request.QueryString["Id"] == "1")
                    {
                        clnm = Session["ClNm"].ToString();
                        drpdwnClientNm.SelectedValue = clnm;
                        txtAddInvce.Text = Session["Add"].ToString();
                        txtPanNo.Text = Session["PAN"].ToString();
                        txtBillNo.Text = Session["BillNo"].ToString();
                        string amt = txtAmtAddInvce.Text.ToString();
                        Session["TotalAmount"] = amt;
                        string ClientName = drpdwnClientNm.SelectedValue.ToString();
                        Session["ClientName"] = ClientName;
                    }
                    DataTable dt = Session["dtgetselectedRecords"] as DataTable;
                    double amt1 = Convert.ToDouble(Session["amt"]);

                    if (dt != null)
                    {
                        GdVwAddInvce.DataSource = dt;
                        GdVwAddInvce.DataBind();
                    }
                    if (dt != null)
                    {
                        double amtNew = 0.0;
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            amtNew += double.Parse(dt.Rows[i].Field<string>(4));
                        }
                        Session["addedamt"] = amtNew.ToString();
                        txtAmtAddInvce.Text = amtNew.ToString();
                    }

                    SelAllCheckbox();

                    if (Request.QueryString["InvoiceId"] != null)
                    {
                        InvoiceId = int.Parse(Request.QueryString["InvoiceId"]);
                        Session["InvoiceId"] = InvoiceId;
                        SqlDataReader drgetInv = blAddCl.getInvoiceForUpdate(InvoiceId);

                        if (drgetInv.HasRows == true)
                        {
                            while (drgetInv.Read())
                            {
                                DateTime indate = drgetInv.GetDateTime(2);
                                txtDtInvce.Text = indate.ToString("dd/MM/yyyy");
                                int ClId = drgetInv.GetInt32(3);
                                Session["ClId"] = ClId.ToString();
                                drpdwnClientNm.SelectedValue = Session["ClientName"].ToString();
                                GetClientInfo();
                                txtAmtAddInvce.Text = drgetInv.GetDecimal(4).ToString();
                                txtBillNo.Text = Session["InvoiceNo"].ToString();
                                txtRemrk.Text = drgetInv.GetString(7);
                                if (drgetInv.GetInt32(9) == 1)
                                    chkbxisDel.Checked = true;
                                else
                                    chkbxisDel.Checked = false;
                                if (drgetInv.GetInt32(10) == 1)
                                    chkbxAppInv.Checked = true;
                                else
                                    chkbxAppInv.Checked = false;
                            }
                            drgetInv.Close();
                        }
                        DataTable dtgetInvDet = blAddCl.GetInvoiceDetailForUpdate(InvoiceId);
                        GdVwAddInvce.DataSource = dtgetInvDet;
                        GdVwAddInvce.DataBind();
                        Session["dtgetselectedRecordsUpdate"] = dtgetInvDet;
                        SelAllCheckbox();
                    }
                }
                else
                {
                    lblCatchError.Text = "";
                    lblSelProjectMessage.Text = "";
                    lblResult.Text = "";
                }
                //if (!Page.IsPostBack)
                //{
                //    if (Request.QueryString["InvoiceId"] != null)
                //    {
                //        InvoiceId = int.Parse(Request.QueryString["InvoiceId"]);
                //        Session["InvoiceId"] = InvoiceId;
                //        SqlDataReader drgetInv = blAddCl.getInvoiceForUpdate(InvoiceId);

                //        //SqlDataReader dr = blAddCl.getClientInvce();
                //        //if (dr.HasRows == true)
                //        //{
                //        //    while (dr.Read())
                //        //        drpdwnClientNm.Items.Add(dr.GetString(0));
                //        //    drpdwnClientNm.Items.Insert(0, new ListItem("--Select--", "-1"));
                //        //    dr.Close();
                //        //}
                //        if (Request.QueryString["Id"] == "1")
                //        {
                //            clnm = Session["ClNm"].ToString();
                //            drpdwnClientNm.SelectedValue = clnm;
                //            txtAddInvce.Text = Session["Add"].ToString();
                //            txtPanNo.Text = Session["PAN"].ToString();
                //            txtBillNo.Text = Session["BillNo"].ToString();
                //            string amt = txtAmtAddInvce.Text.ToString();
                //            Session["TotalAmount"] = amt;
                //            string ClientName = drpdwnClientNm.SelectedValue.ToString();
                //            Session["ClientName"] = ClientName;
                //        }
                //        DataTable dt = Session["dtgetselectedRecords"] as DataTable;
                //        double amt1 = Convert.ToDouble(Session["amt"]);

                //        if (dt != null)
                //        {
                //            GdVwAddInvce.DataSource = dt;
                //            GdVwAddInvce.DataBind();

                //            double amtNew = 0.0;
                //            for (int i = 0; i < dt.Rows.Count; i++)
                //            {
                //                amtNew += double.Parse(dt.Rows[i].Field<string>(4));
                //            }
                //            Session["addedamt"] = amtNew.ToString();
                //            txtAmtAddInvce.Text = amtNew.ToString();
                //        }

                //        if (drgetInv.HasRows == true)
                //        {
                //            while (drgetInv.Read())
                //            {
                //                DateTime indate = drgetInv.GetDateTime(2);
                //                txtDtInvce.Text = indate.ToString("dd/MM/yyyy");
                //                int ClId = drgetInv.GetInt32(3);
                //                Session["ClId"] = ClId.ToString();
                //                drpdwnClientNm.SelectedValue = Session["ClientName"].ToString();
                //                GetClientInfo();
                //                txtAmtAddInvce.Text = drgetInv.GetDecimal(4).ToString();
                //                txtBillNo.Text = Session["InvoiceNo"].ToString();
                //                txtRemrk.Text = drgetInv.GetString(7);
                //                if (drgetInv.GetInt32(9) == 1)
                //                    chkbxisDel.Checked = true;
                //                else
                //                    chkbxisDel.Checked = false;
                //                if (drgetInv.GetInt32(10) == 1)
                //                    chkbxAppInv.Checked = true;
                //                else
                //                    chkbxAppInv.Checked = false;
                //            }
                //            drgetInv.Close();
                //        }
                //        DataTable dtgetInvDet = blAddCl.GetInvoiceDetailForUpdate(InvoiceId);
                //        GdVwAddInvce.DataSource = dtgetInvDet;
                //        GdVwAddInvce.DataBind();
                //        Session["dtgetselectedRecordsUpdate"] = dtgetInvDet;
                //    }
                //    SelAllCheckbox();
                //}
                //else
                //{
                //    //Session["dtgetselectedRecords"] = null;
                //    lblCatchError.Text = "";
                //    lblSelProjectMessage.Text = "";
                //    lblResult.Text = "";
                //}
            }
            catch (Exception ex)
            {
                lblCatchError.Text = ex.Message.ToString();
            }
        }