Ejemplo n.º 1
0
        protected void gvBooks_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName == "Delete")
                {
                    using (deeptiEntities db1 = new deeptiEntities())
                    {
                        //int ncopies = 0;
                        int id = Convert.ToInt32(e.CommandArgument);
                        //var no = (from k in db1.Books where k.Id == id select k.Copies).SingleOrDefault();
                        //ncopies = Convert.ToInt32(no);
                        var copy = from c in db1.Copies where c.BookId == id select c;
                        // List<Copy> cp = copy.ToList();
                        foreach (var cp in copy)
                        {
                            db1.Copies.Remove(cp);
                        }

                        var book = (from b in db1.Books where b.Id == id select b).SingleOrDefault();
                        db1.Books.Remove(book);


                        db1.SaveChanges();
                        BindGrid();
                        lblMessage.Text = "Record deleted !";
                    }
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }
Ejemplo n.º 2
0
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     try
     {
         int id = 0;
         using (deeptiEntities db = new deeptiEntities())
         {
             if (Session["id"] != null)
             {
                 id = Convert.ToInt32(Session["id"].ToString());
             }
             var query = (from r in db.Registrations where r.Id == id select r.Password).FirstOrDefault();
             if (query != null)
             {
                 if (txtOldPwd.Text == query)
                 {
                     var q = (from u in db.Registrations where u.Id == id select u).SingleOrDefault();
                     if (q != null)
                     {
                         q.Password = txtNewPwd.Text;
                         db.SaveChanges();
                         lblMessage.Text = "Password changed successfully! ";
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         lblMessage.Text = ex.Message;
     }
 }
Ejemplo n.º 3
0
        private void bindGrid()

        {
            try
            {
                using (deeptiEntities db = new deeptiEntities())
                {
                    int id = 0;
                    if (Session["id"] != null)
                    {
                        id = Convert.ToInt32(Session["id"]);
                    }

                    var query = (from t in db.Transactions
                                 join b in db.Books on t.BookId equals b.Id where t.MemberId == id
                                 select new { t.BookId, b.BookTitle, b.Category, b.AuthorName, t.MemberId, t.CopyId, t.IssueDate, t.DueDate, t.ReturnDate, t.Fine }).ToList();
                    gvBooks.DataSource = query;
                    gvBooks.DataBind();
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }
Ejemplo n.º 4
0
        protected void txtSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                using (deeptiEntities db = new deeptiEntities())
                {
                    int memberId = 0;
                    int bookId   = Convert.ToInt32(txtBookId.Text);
                    if (Session["id"] != null)
                    {
                        memberId = Convert.ToInt32(Session["id"].ToString());
                    }

                    var query = (from q in db.Transactions where q.BookId == bookId && q.MemberId == memberId select q).FirstOrDefault();
                    if (query != null)
                    {
                        query.ReturnDate = (Convert.ToDateTime(txtReturnDate.Text)).Date;
                        var iDate = (from i in db.Transactions where i.BookId == bookId && i.MemberId == memberId select i.IssueDate).First();
                        if (iDate != null)
                        {
                            txtIssuedDate.Text = iDate.Date.ToString("yyyy-MM-dd");
                        }
                        var DDate = (from d in db.Transactions where d.BookId == bookId && d.MemberId == memberId select d.DueDate).First();
                        if (DDate != null)
                        {
                            txtDueDate.Text = DDate.Date.ToString("yyyy-MM-dd");
                        }
                        int days = (Convert.ToDateTime(txtDueDate.Text) - Convert.ToDateTime(txtReturnDate.Text)).Days;
                        if (days < 0)
                        {
                            query.Fine   = days / 2;
                            txtFine.Text = (days / 2).ToString();
                        }
                        else if (days == 0 || days > 0)
                        {
                            query.Fine   = 0;
                            txtFine.Text = "0";
                        }
                        var copy = (from c in db.Transactions where c.BookId == bookId && c.MemberId == memberId select c.CopyId).First();
                        if (copy != 0)
                        {
                            var cp = (from k in db.Copies where k.Id == copy select k).SingleOrDefault();

                            if (cp != null)
                            {
                                cp.Status = "available";
                            }
                        }
                        db.SaveChanges();

                        lblMessage.Text = "Book returned successfully . Please check your  details!";
                    }
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }
Ejemplo n.º 5
0
        protected void gvBooks_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                int         copy     = 0;
                GridViewRow row      = gvBooks.Rows[e.RowIndex];
                int         id       = Convert.ToInt32(gvBooks.DataKeys[e.RowIndex].Values[0]);
                string      bTitle   = (row.FindControl("txtBookTitle") as TextBox).Text;
                string      category = (row.FindControl("txtCategory") as TextBox).Text;
                string      authName = (row.FindControl("txtAuthName") as TextBox).Text;
                string      copies   = (row.FindControl("txtCopies") as TextBox).Text;
                copy = Convert.ToInt32(copies);

                using (deeptiEntities db = new deeptiEntities())
                {
                    Book bk = (from b in db.Books
                               where b.Id == id
                               select b).SingleOrDefault();
                    bk.BookTitle  = bTitle;
                    bk.Category   = category;
                    bk.AuthorName = authName;
                    bk.Copies     = copy;
                    db.SaveChanges();
                }
                gvBooks.EditIndex = -1;
                this.BindGrid();



                //Label BId = (Label)gvBooks.Rows[e.RowIndex].FindControl("lblId");
                // id = Convert.ToInt32(BId);
                //TextBox BTitle = (TextBox)gvBooks.Rows[e.RowIndex].FindControl("txtBookTitle");
                //TextBox Category = (TextBox)gvBooks.Rows[e.RowIndex].FindControl("txtCategory");
                //TextBox AuthName = (TextBox)gvBooks.Rows[e.RowIndex].FindControl("txtAuthName");
                //TextBox Copies = (TextBox)gvBooks.Rows[e.RowIndex].FindControl("txtCopies");
                //copy = Convert.ToInt32(Copies.Text);
                //using (deeptiEntities db = new deeptiEntities())
                //{
                //    var bookQuery = (from b in db.Books where b.Id == id select b).SingleOrDefault();
                //    if(bookQuery!=null)
                //    {
                //        bookQuery.BookTitle = BTitle.Text;
                //        bookQuery.Category = Category.Text;
                //        bookQuery.AuthorName = AuthName.Text;
                //        bookQuery.Copies = copy ;
                //        db.SaveChanges();
                //        gvBooks.EditIndex = -1;
                //        BindGrid();
                //        lblMessage.Text = "Record updated!";
                //    }
                //}
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }
Ejemplo n.º 6
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                using (deeptiEntities db = new deeptiEntities())
                {
                    string username, password;


                    var uname = (from u in db.Registrations
                                 where u.Email == txtEmail.Text
                                 select u.UserName).SingleOrDefault();
                    if (uname != null)
                    {
                        var pwd = (from u in db.Registrations
                                   where u.Email == txtEmail.Text
                                   select u.Password).SingleOrDefault();
                        if (pwd != null)
                        {
                            username = uname.ToString();
                            password = pwd.ToString();
                            MailMessage mail = new MailMessage();
                            mail.From = new MailAddress("*****@*****.**");
                            mail.To.Add(txtEmail.Text.Trim());
                            mail.Subject    = "Password Recovery";
                            mail.Body       = String.Format("Hi {0}, <br /> <br /> Your Password is {1}. <br/><br/> Thank You,<br/>Admin.", username, password);
                            mail.IsBodyHtml = true;
                            SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
                            // smtp.Host = "smtp.gmail.com";
                            smtp.EnableSsl = true;
                            NetworkCredential nwcred = new NetworkCredential();
                            nwcred.UserName            = "******";
                            nwcred.Password            = "******";
                            smtp.UseDefaultCredentials = true;
                            smtp.Credentials           = nwcred;
                            //smtp.Port = 465;
                            smtp.Send(mail);
                            lblMessage.ForeColor = Color.BlueViolet;
                            lblMessage.Text      = "Password has been sent to your email address!";
                        }
                    }
                    else
                    {
                        lblMessage.ForeColor = Color.Red;
                        lblMessage.Text      = "This Email Address does not match our records!";
                    }
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }
Ejemplo n.º 7
0
        private void BindGrid()
        {
            // using command temporarily creates a context that accesses our database

            using (deeptiEntities db = new deeptiEntities())
            {
                // use LINQ against Books table to have Entity Framework do a SQL query

                var query = from Book in db.Books
                            select Book;
                List <Book> booklist = query.ToList();
                gvBooks.DataSource = booklist;
                gvBooks.DataBind();
            }
        }
Ejemplo n.º 8
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            //System.Web.Security.FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, false);
            using (deeptiEntities db = new deeptiEntities())
            {
                try
                {
                    var rolequery = (from u in db.Registrations
                                     where u.UserName == txtUserName.Text && u.Password == txtPassword.Text
                                     select u.Role).FirstOrDefault();
                    if (rolequery != null)
                    {
                        //if (cbRemember.Checked)
                        //{
                        //    Response.Cookies["UserName"].Value = txtUserName.Text;
                        //    Response.Cookies["Password"].Value = txtPassword.Text;
                        //    Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(15);
                        //    Response.Cookies["Password"].Expires = DateTime.Now.AddDays(15);
                        //}
                        //else
                        //{
                        //    Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
                        //    Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);

                        //}
                        Session["role"] = rolequery.ToString();
                        Session["name"] = txtUserName.Text;
                        var query = (from u in db.Registrations
                                     where u.UserName == txtUserName.Text && u.Password == txtPassword.Text
                                     select u.Id).FirstOrDefault();
                        if (query != 0)
                        {
                            Session["id"] = query.ToString();
                        }
                        FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, cbRemember.Checked);
                    }

                    else
                    {
                        lblMessage.Text = "Invalid Credentials";
                    }
                }
                catch (Exception ex)
                {
                    lblMessage.Text = ex.Message;
                }
            }
        }
Ejemplo n.º 9
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         try
         {
             Label fn = Page.Master.FindControl("lblUserName") as Label;
             if (Session["name"] != null)
             {
                 fn.Text = Session["name"].ToString();
             }
             using (deeptiEntities db = new deeptiEntities())
             {
                 int memberId = 0;
                 if (Session["id"] != null)
                 {
                     memberId = Convert.ToInt32(Session["id"].ToString());
                 }
                 var query = (from u in db.Registrations
                              where u.Id == memberId
                              select new
                 {
                     u.Id,
                     u.FirstName,
                     u.LastName,
                     u.UserName,
                     u.MobileNo,
                     u.RegisteredDate
                 }).FirstOrDefault();
                 if (query != null)
                 {
                     Id.Text        = query.Id.ToString();
                     FirstName.Text = query.FirstName;
                     LastName.Text  = query.LastName;
                     UserName.Text  = query.UserName;
                     MobileNo.Text  = query.MobileNo;
                     RegDate.Text   = query.RegisteredDate.ToString("yyyy-MM-dd hh:mm:ss.fff");
                 }
             }
         }
         catch (Exception ex)
         {
             lblMessage.Text = ex.Message;
         }
     }
 }
Ejemplo n.º 10
0
 private void BindGrid()
 {
     try
     {
         using (deeptiEntities db = new deeptiEntities())
         {
             var query = from reg in db.Registrations
                         select reg;
             List <Registration> memberlist = query.ToList();
             gvUsers.DataSource = memberlist;
             gvUsers.DataBind();
         }
     }
     catch (Exception ex)
     {
         lblMessage.Text = ex.Message;
     }
 }
Ejemplo n.º 11
0
 private void BindGrid()
 {
     try
     {
         using (deeptiEntities db = new deeptiEntities())
         {
             var trans = (from t in db.Transactions
                          join b in db.Books on t.BookId equals b.Id
                          select new { t.BookId, b.BookTitle, b.Category, b.AuthorName, t.MemberId, t.CopyId, t.IssueDate, t.DueDate, t.ReturnDate, t.Fine }).ToList();
             gvTransactions.DataSource = trans;
             gvTransactions.DataBind();
         }
     }
     catch (Exception ex)
     {
         lblMessage.Text = ex.Message;
     }
 }
Ejemplo n.º 12
0
        private void bindGrid()
        {
            try
            {
                using (deeptiEntities db = new deeptiEntities())
                {
                    if (txtAuthorName.Text == "" && txtBookId.Text == "" && txtBookTitle.Text == "" && txtCategory.Text == "")
                    {
                        var         q        = from b in db.Books select b;
                        List <Book> bookList = q.ToList();
                        gvBooks.DataSource = bookList;
                        gvBooks.DataBind();
                    }
                    else
                    {
                        int id = 0;
                        if (txtBookId.Text == "")
                        {
                            id = 0;
                        }
                        else
                        {
                            id = Convert.ToInt32(txtBookId.Text);
                        }
                        var search = (from b in db.Books
                                      where b.AuthorName == txtAuthorName.Text || b.BookTitle == txtBookTitle.Text || b.Category == txtCategory.Text || b.Id == id
                                      select b).ToList();
                        gvBooks.DataSource = search;
                        gvBooks.DataBind();

                        //IQueryable<Book> books = db.Books;
                        //if(!string.IsNullOrEmpty(txtAuthorName.Text))
                        //{
                        //    books = books.where(b => b.AuthorName.Contains(txtAuthorName.Text));
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }
Ejemplo n.º 13
0
 protected void gvUsers_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     try
     {
         if (e.CommandName == "Delete")
         {
             using (deeptiEntities db1 = new deeptiEntities())
             {
                 int id   = Convert.ToInt32(e.CommandArgument);
                 var user = (from u in db1.Registrations where u.Id == id select u).FirstOrDefault();
                 db1.Registrations.Remove(user);
                 db1.SaveChanges();
                 BindGrid();
             }
         }
     }
     catch (Exception ex)
     {
         lblMessage.Text = ex.Message;
     }
 }
Ejemplo n.º 14
0
        protected void txtSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                using (deeptiEntities db = new deeptiEntities())
                {
                    int bookId = Convert.ToInt32(txtBookId.Text);

                    var copy = from p in db.Copies where p.BookId == bookId select p;
                    var cid  = from c in db.Copies where c.BookId == bookId select c.Id;
                    var s    = copy.FirstOrDefault();
                    if (s != null)
                    {
                        s.Status = "Unavailable";
                    }

                    var trans = new Transaction();

                    trans.BookId = bookId;
                    if (Session["id"] != null)
                    {
                        trans.MemberId = Convert.ToInt32(Session["id"].ToString());
                    }
                    trans.CopyId    = Convert.ToInt32(cid.First());
                    trans.IssueDate = Convert.ToDateTime(DateTime.Now.Date);
                    DateTime due = trans.IssueDate.AddDays(21);
                    trans.DueDate = due;
                    // adding the transactoin to db collection
                    db.Transactions.Add(trans);
                    // telling the db to save the changes
                    db.SaveChanges();
                    lblMessage.Text = "Book has been issued  and due date is " + due.ToString("d");
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }
Ejemplo n.º 15
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            try
            {
                // using command temporarily creates a context that accesses our database
                // creating an object of the object context "deeptiEntities"
                using (deeptiEntities db = new deeptiEntities())
                {
                    //creating an object of the Registration class

                    Registration objreg = new Registration();

                    // set values to the db columns

                    objreg.FirstName      = txtFirstName.Text;
                    objreg.LastName       = txtLastName.Text;
                    objreg.UserName       = txtUserName.Text;
                    objreg.Password       = txtPassword.Text;
                    objreg.MobileNo       = txtMobileNo.Text;
                    objreg.RegisteredDate = DateTime.Now;
                    objreg.Email          = txtEmail.Text;
                    objreg.Role           = ddlRole.SelectedItem.Text;

                    // add registration object to the registrations collection in the object context

                    db.Registrations.Add(objreg);

                    //call savechanges method to insert the record into table

                    db.SaveChanges();
                    lblMessage.Text = " You have registered successfully!";
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }
Ejemplo n.º 16
0
        protected void txtSubmit_Click(object sender, EventArgs e)
        {
            // using command temporarily creates a context that accesses our database
            using (deeptiEntities db = new deeptiEntities())
            {
                Book objBook = new Book
                {
                    AuthorName = txtAuthorName.Text,
                    BookTitle  = txtBookTitle.Text,
                    Category   = txtCategory.Text,
                    Copies     = Convert.ToInt32(txtCopies.Text)
                };

                db.Books.Add(objBook);
                db.SaveChanges();
                var query = from b in db.Books where b.BookTitle == txtBookTitle.Text & b.AuthorName == txtAuthorName.Text select b.Id;
                var c     = query.SingleOrDefault();
                if (c != 0)
                {
                    for (int i = 0; i < Convert.ToInt32(txtCopies.Text); i++)
                    {
                        Copy objCopy = new Copy
                        {
                            BookId = c,
                            Status = "available"
                        };
                        db.Copies.Add(objCopy);
                    }
                }


                db.SaveChanges();

                lblMessage.Text = " Book added successfully !";
            }
        }