protected void btn_update_Click(object sender, EventArgs e)
        {
            db = new THFinanceEntities();
            int id = Convert.ToInt32(lbl_id.Text);


            tbl_borrower tbl = (from c in db.tbl_borrower
                                where c.borrowerId.Equals(id)
                                select c).Single();

            tbl.borrowerId          = Convert.ToInt32(lbl_id.Text);
            tbl.borrowerName        = txt_barrowername.Text;
            tbl.borrowerFatherName  = txt_barrowerfathername.Text;
            tbl.BorrowerDesignation = txt_barrowerdesignation.Text;
            tbl.borrowerAddress     = txt_barroweraddresseee.Text;
            tbl.borrowerPhone       = txt_barrowerphone.Text;
            Stream fs  = txt_prooffile.PostedFile.InputStream;
            Stream fs2 = txt_photo.PostedFile.InputStream;

            BinaryReader br  = new BinaryReader(fs);
            BinaryReader br2 = new BinaryReader(fs2);

            Byte[] bytes  = br.ReadBytes((Int32)fs.Length);
            Byte[] bytes2 = br2.ReadBytes((Int32)fs.Length);
            tbl.borrowerproof = bytes;

            // txt_prooffile.PostedFile.SaveAs(Server.MapPath("~/Uploads") + tbl.borrowerproof);
            tbl.borrowerproofType = txt_proof.Value;
            tbl.createdby         = Convert.ToInt32(Session["UserID"]);
            tbl.createdDate       = DateTime.Now;
            tbl.borrowerPhoto     = bytes2;
            // txt_photo.PostedFile.SaveAs(Server.MapPath("~/Uploads") + tbl.borrowerPhoto);
            if (tbl != null)
            {
                //  db.tbl_borrower.Add(q);
                db.SaveChanges();
                loadgrid();
            }
        }
        protected void btn_login_Click(object sender, EventArgs e)
        {
            try
            {
                if (Page.IsValid)
                {
                    using (THFinanceEntities db = new THFinanceEntities())
                    {
                        var q = (from s in db.tbl_borrower
                                 select s).ToList();
                        tbl_borrower tbl = new tbl_borrower();
                        tbl.borrowerName        = txt_barrowername.Text;
                        tbl.borrowerFatherName  = txt_barrowerfathername.Text;
                        tbl.BorrowerDesignation = txt_barrowerdesignation.Text;
                        tbl.borrowerAddress     = txt_barroweraddresseee.Text;
                        tbl.borrowerPhone       = txt_barrowerphone.Text;
                        Stream fs  = txt_prooffile.PostedFile.InputStream;
                        Stream fs2 = txt_photo.PostedFile.InputStream;
                        //int fileSize = (txt_prooffile.PostedFile.ContentLength / 1024);
                        //Stream ipStream = txt_prooffile.PostedFile.InputStream;
                        //using (var image = System.Drawing.Image.FromStream(ipStream))
                        //{
                        //    float w = image.PhysicalDimension.Width;
                        //    float h = image.PhysicalDimension.Height;
                        //}
                        //if (fileSize<(2 * 1024))
                        //{
                        //   // PanelError.Visible = true;
                        //    lblError.Text = "Filesize of image is too large. Maximum file size permitted is " + 5 + "MB";
                        //    lblError.Visible = true;
                        //    return;
                        //}

                        BinaryReader br     = new BinaryReader(fs);
                        BinaryReader br2    = new BinaryReader(fs2);
                        Byte[]       bytes  = br.ReadBytes((Int32)fs.Length);
                        Byte[]       bytes2 = br2.ReadBytes((Int32)fs.Length);
                        tbl.borrowerproof = bytes;
                        // txt_prooffile.PostedFile.SaveAs(Server.MapPath("~/Uploads") + tbl.borrowerproof);
                        tbl.borrowerproofType = txt_proof.Value;
                        tbl.createdby         = Convert.ToInt32(Session["UserID"]);
                        tbl.createdDate       = DateTime.Now;
                        tbl.borrowerPhoto     = bytes2;
                        if (q.Count == 0)
                        {
                            db.tbl_borrower.Add(tbl);
                            db.SaveChanges();
                            Response.Write("<script>alert('Sucessfully Saved')</script>");
                            clearfields();
                            return;
                        }
                        else
                        {
                            for (int i = 0; i <= q.Count; i++)
                            {
                                string prev          = q[i].borrowerName;
                                string present       = txt_barrowername.Text;
                                string mobileprev    = q[i].borrowerPhone;
                                string mobilepresent = txt_barrowerphone.Text;
                                if (present == prev || mobileprev == mobilepresent)
                                {
                                    Response.Write("<script>alert('please check mobile or  valid borrower Name')</script>");
                                    return;
                                }

                                //else
                                //{
                                //    db.tbl_borrower.Add(tbl);
                                //    db.SaveChanges();
                                //    Response.Write("<script>alert('Sucessfully Saved')</script>");
                                //    clearfields();
                                //    return;
                                //}
                            }
                        }

                        //txt_photo.PostedFile.SaveAs(Server.MapPath("~/Uploads") + tbl.borrowerPhoto);
                        db.tbl_borrower.Add(tbl);
                        db.SaveChanges();
                        Response.Write("<script>alert('Sucessfully Saved')</script>");
                        clearfields();
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('Sucessfully not Saved')</script>");
                throw ex;
            }
        }