Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtTitle.Text.Length < 1 && ((txtEmail.Text.Length < 5) || (mtxtMN.Text.Length < 8)))
            {
                MessageBox.Show("Requires at least a valid name and contact");
            }
            else
            {
                SA45TEAM01ALibraryEntities context = new SA45TEAM01ALibraryEntities();
                User newUser = new User();
                using (TransactionScope ts = new TransactionScope())
                {
                    newUser.Name     = txtTitle.Text;
                    newUser.Email    = txtEmail.Text;
                    newUser.Phone_no = int.Parse(mtxtMN.Text);
                    newUser.Category = cmbMemType.Text;

                    context.Users.Add(newUser);
                    context.SaveChanges();
                    ts.Complete();
                }

                Messages A = new Messages();
                A.SaveMessage();
                txtTitle.Clear();
                txtEmail.Clear();
                mtxtMN.Clear();
            }
        }
Exemplo n.º 2
0
        private void Save_Click(object sender, EventArgs e)
        {
            newAuthor = txtAuthor.Text;
            newTitle  = txtAuthor.Text;
            newYP     = Convert.ToInt32(cmbYear.SelectedText);
            newGenre  = txtGenre.Text;
            newLG     = txtLanguage.Text;
            newISBN   = txbISBN.Text;

            int a = int.Parse(mtxtBID.Text);
            SA45TEAM01ALibraryEntities d = new SA45TEAM01ALibraryEntities();
            booklist b = d.booklists.Where(x => x.Book_ID == a).First();

            if ((b.Author != newAuthor) || (b.Title != newTitle) || (b.Year_of_Publication != newYP) || (b.Category != newGenre) || (b.Language != newLG) || (b.ISBN != newISBN))
            {
                b.Author = newAuthor;
                b.Title  = newTitle;
                b.Year_of_Publication = newYP;
                b.Category            = newGenre;
                b.Language            = newLG;
                b.ISBN = newISBN;
                d.SaveChanges();

                Messages A = new Messages();
                A.SaveMessage();
            }
            else
            {
                MessageBox.Show("Please make edits in order to Save or click Cancel to Return to Books Menu");
            }
        }
        private void btnDel_Click(object sender, EventArgs e)
        {
            string       qq2    = mtextUID.Text.TrimStart(new Char[] { '0' });
            DialogResult result = MessageBox.Show("Confirm Delete?", "Warning!", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                SA45TEAM01ALibraryEntities context = new SA45TEAM01ALibraryEntities();
                User a = context.Users.Where(x => x.User_ID.ToString() == qq2).FirstOrDefault();

                using (TransactionScope ts = new TransactionScope())
                {
                    a.Status = "Inactive";
                    context.SaveChanges();
                    ts.Complete();
                }

                btnSearch.Visible          = true;
                mtextUID.Text              = String.Empty;
                mtextUID.BackColor         = System.Drawing.SystemColors.Window;
                mtextUID.ReadOnly          = false;
                lblName.Visible            = false;
                lblEmail.Visible           = false;
                lblPN.Visible              = false;
                txtName.Visible            = false;
                txtEmail.Visible           = false;
                mtextPN.Visible            = false;
                btnDel.Visible             = false;
                btnClear.Visible           = false;
                toolStripStatusLabel1.Text = "Input User_ID and click Search";

                Messages A = new Messages();
                A.SaveMessage();
            }
        }
        private void newDataPlease()
        {
            SA45TEAM01ALibraryEntities c = new SA45TEAM01ALibraryEntities();
            var q = from x in c.booklists select new { x.ISBN, x.Title, x.Book_ID, x.Language, x.Category, x.Author, x.Year_of_Publication };

            dataGridView1.DataSource = q.ToList();
        }
Exemplo n.º 5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (getSInputs() > 0)
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    SA45TEAM01ALibraryEntities c = new SA45TEAM01ALibraryEntities();
                    booklist a = new booklist();
                    a.ISBN                = txtTitle.Text.ToString();
                    a.Title               = txtTitle.Text.ToString();
                    a.Language            = txtLanguage.Text.ToString();
                    a.Category            = txtGenre.Text.ToString();
                    a.Author              = txtAuthor.Text.ToString();
                    a.Year_of_Publication = Convert.ToInt32(cmbYear.SelectedText);//Convert.ToInt32(cmbYear.Text);
                    c.booklists.Add(a);
                    c.SaveChanges();
                    ts.Complete();
                }

                Messages A = new Messages();
                A.SaveMessage();
            }
            else
            {
                MessageBox.Show("Please Add in Relevant info before Adding new Books");
            }
        }
        private void btnRefresh_click()
        {
            SA45TEAM01ALibraryEntities context = new SA45TEAM01ALibraryEntities();
            var q = context.Users.Where(x => x.Status != "Inactive").Select(x => new { x.User_ID, x.Name, x.Email, x.Phone_no, x.Book_due, x.Category, x.Status });

            dataGridView1.DataSource = q.ToList();
        }
        private void ViewMembers_Load(object sender, EventArgs e)
        {
            SA45TEAM01ALibraryEntities context = new SA45TEAM01ALibraryEntities();
            var q = context.Users.Where(x => x.Status != "Inactive").Select(x => new { x.User_ID, x.Name, x.Email, x.Phone_no, x.Book_due, x.Category, x.Status });

            dataGridView1.DataSource = q.ToList();
        }
Exemplo n.º 8
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            int rV = 0;

            foreach (DataGridViewRow dg in dataGridView1.Rows)
            {
                if (Convert.ToBoolean(dg.Cells[0].Value) == true)
                {
                    rV++;
                }
            }
            if (rV > 0 && (txtName.Text.Length > 0))
            {
                DialogResult result = new DialogResult();
                result = MessageBox.Show("Proceed with borrowing?", "Borrowing books", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    SA45TEAM01ALibraryEntities context = new SA45TEAM01ALibraryEntities();

                    using (TransactionScope ts = new TransactionScope())
                    {
                        foreach (DataGridViewRow dgRow in dataGridView1.Rows)
                        {
                            if (dgRow.Cells[0].Value != null)
                            {
                                int selected1  = Convert.ToInt32(dgRow.Cells[3].Value.ToString());
                                int newIssueID = context.Issue_Details.Select(x => x.Issue_ID).Max() + 1;

                                Issue_Details id = new Issue_Details();
                                id.Issue_ID      = newIssueID;
                                id.Issue_Date    = DateTime.Today.ToString();
                                id.Due_Date      = DateTime.Today.AddDays(20).ToString();
                                id.Book_ID       = selected1;
                                id.User_ID       = Convert.ToInt32(txtID.Text.ToString());
                                id.Rental_Status = "OUT";
                                id.Return_Date   = null;

                                context.Issue_Details.Add(id);
                                string uid = txtID.Text;
                                User   m   = context.Users.Where(x => x.User_ID.ToString() == uid).First();
                                m.Book_due++;
                                context.SaveChanges();
                            }
                        }
                        ts.Complete();
                    }
                    FormBorrow();
                }
            }
            else if (rV > 0)
            {
                MessageBox.Show("Please input a valid user id");
            }
            else
            {
                MessageBox.Show("Please select checkboxes for books to borrow");
            }
        }
Exemplo n.º 9
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string qq2 = mtextUID.Text.TrimStart(new Char[] { '0' });

            if (qq2.Length < 1)
            {
                MessageBox.Show("Please input a valid ID");
            }
            else
            {
                SA45TEAM01ALibraryEntities context = new SA45TEAM01ALibraryEntities();
                string q = "";
                try
                {
                    q = context.Users.Where(x => x.User_ID.ToString() == qq2).Where(x => x.Status != "Inactive").Select(x => x.Name).First();
                }
                catch (Exception)
                {
                    MessageBox.Show("Invalid ID. Please try again.");
                    mtextUID.Text = String.Empty;
                }
                if (q.Length < 1)
                {
                }
                else
                {
                    btnSearch.Visible          = false;
                    mtextUID.BackColor         = System.Drawing.SystemColors.ScrollBar;
                    mtextUID.ReadOnly          = true;
                    lblName.Visible            = true;
                    lblEmail.Visible           = true;
                    lblPN.Visible              = true;
                    lblCat.Visible             = true;
                    txtName.Visible            = true;
                    txtEmail.Visible           = true;
                    mtextPN.Visible            = true;
                    cboxCat.Visible            = true;
                    btnSave.Visible            = true;
                    btnClear.Visible           = true;
                    toolStripStatusLabel1.Text = "Click Save to Confirm, Cancel to Close Screen";

                    txtName.Text = q;
                    string q1 = context.Users.Where(x => x.User_ID.ToString() == qq2).Select(x => x.Email).First();
                    txtEmail.Text = q1;
                    int?q2 = context.Users.Where(x => x.User_ID.ToString() == qq2).Select(x => x.Phone_no).First();
                    mtextPN.Text = q2.ToString();
                    string q3 = context.Users.Where(x => x.User_ID.ToString() == qq2).Select(x => x.Category).First();
                    cboxCat.Text = q3;
                }
            }
        }
Exemplo n.º 10
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            //SA45TEAM01ALibraryEntities d = new SA45TEAM01ALibraryEntities();

            //int a = int.Parse(Book_ID);
            //booklist b = d.booklists.Where(x => x.Book_ID == a).First();
            //b.Disposed = "Yes";
            //d.SaveChanges();
            //MessageBox.Show("Deleted Successfully");

            int rV = 0;

            foreach (DataGridViewRow dg in dataGridView1.Rows)
            {
                if (Convert.ToBoolean(dg.Cells[0].Value) == true)
                {
                    rV++;
                }
            }
            if (rV > 0)
            {
                DialogResult dr = MessageBox.Show("Confirm Deletion for these row(s)?", "Warning!", MessageBoxButtons.YesNo);
                if (dr == DialogResult.Yes)
                {
                    SA45TEAM01ALibraryEntities context = new SA45TEAM01ALibraryEntities();
                    foreach (DataGridViewRow dg in dataGridView1.Rows)
                    {
                        if (Convert.ToBoolean(dg.Cells[0].Value) == true)
                        {
                            int      x2 = Convert.ToInt32(dg.Cells[3].Value);
                            var      q  = context.booklists.Where(x => x.Book_ID == x2).FirstOrDefault();
                            booklist A  = q;
                            using (TransactionScope ts = new TransactionScope())
                            {
                                q.Disposed = "Yes";
                                context.SaveChanges();
                                ts.Complete();
                            }
                        }
                    }
                    Messages newM = new Messages();
                    newM.SaveMessage();
                    newDataPlease();
                }
            }
            else
            {
                MessageBox.Show("Please select checkbox(es) to delete first");
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int rV = 0;

            foreach (DataGridViewRow dg in dataGridView1.Rows)
            {
                if (Convert.ToBoolean(dg.Cells[0].Value) == true)
                {
                    rV++;
                }
            }
            if (rV > 0)
            {
                DialogResult dr = MessageBox.Show("Confirm Deletion for these row(s)?", "Warning!", MessageBoxButtons.YesNo);
                if (dr == DialogResult.Yes)
                {
                    SA45TEAM01ALibraryEntities context = new SA45TEAM01ALibraryEntities();
                    foreach (DataGridViewRow dg in dataGridView1.Rows)
                    {
                        if (Convert.ToBoolean(dg.Cells[0].Value) == true)
                        {
                            int  x2 = Convert.ToInt32(dg.Cells[1].Value);
                            var  q  = context.Users.Where(x => x.User_ID == x2).FirstOrDefault();
                            User A  = q;
                            using (TransactionScope ts = new TransactionScope())
                            {
                                q.Status = "Inactive";
                                context.SaveChanges();
                                ts.Complete();
                            }
                        }
                    }
                    Messages newM = new Messages();
                    newM.SaveMessage();
                    btnRefresh_click();
                }
            }
            else
            {
                this.Hide();
                var newDMForm = new DeleteMember();
                newDMForm.Closed += (s, args) => this.Close();
                newDMForm.Show();
            }
        }
Exemplo n.º 12
0
        private void Search_Click(object sender, EventArgs e)
        {
            SA45TEAM01ALibraryEntities d = new SA45TEAM01ALibraryEntities();

            try
            {
                int a   = int.Parse(mtxtBID.Text);
                var qty = from x in d.booklists where x.Book_ID == a select x;

                string isbn   = qty.Single().ISBN;
                string title  = qty.Single().Title;
                int    bookid = qty.Single().Book_ID;
                string lang   = qty.Single().Language;
                string categ  = qty.Single().Category;
                string author = qty.Single().Author;
                int?   yop    = qty.Single().Year_of_Publication;

                txtTitle.Text    = title;
                txtAuthor.Text   = author;
                cmbYear.Text     = yop.ToString();
                txtGenre.Text    = categ;
                txtLanguage.Text = lang;
                txbISBN.Text     = isbn;

                panelTB.Visible  = true;
                panelBTN.Visible = true;
            }
            catch (Exception)
            {
                MessageBox.Show("Invalid ID entered");
            }
            if (txtTitle.Text.Length > 0)
            {
                mtxtBID.Enabled = false;
            }
        }
Exemplo n.º 13
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string qq2 = mtextUID.Text.TrimStart(new Char[] { '0' });

            if (txtName.Text.Length < 1)
            {
                MessageBox.Show("Please Enter a valid name");
            }
            else
            {
                SA45TEAM01ALibraryEntities context = new SA45TEAM01ALibraryEntities();
                User a = context.Users.Where(x => x.User_ID.ToString() == qq2).FirstOrDefault();
                newName  = txtName.Text;
                newEmail = txtEmail.Text;
                newCat   = cboxCat.Text;
                newPN    = Convert.ToInt32(mtextPN.Text);
                string q  = context.Users.Where(x => x.User_ID.ToString() == qq2).Select(x => x.Name).First();
                string q1 = context.Users.Where(x => x.User_ID.ToString() == qq2).Select(x => x.Email).First();
                int?   q2 = context.Users.Where(x => x.User_ID.ToString() == qq2).Select(x => x.Phone_no).First();
                string q3 = context.Users.Where(x => x.User_ID.ToString() == qq2).Select(x => x.Category).First();

                using (TransactionScope ts = new TransactionScope())
                {
                    if (newName != q)
                    {
                        a.Name = newName;
                    }
                    if (newPN != q2)
                    {
                        a.Phone_no = newPN;
                    }
                    if (newEmail != q1)
                    {
                        a.Email = newEmail;
                    }
                    if (newCat != q3)
                    {
                        a.Category = newCat;
                    }

                    context.SaveChanges();
                    ts.Complete();
                }

                btnSearch.Visible          = true;
                mtextUID.Text              = String.Empty;
                mtextUID.BackColor         = System.Drawing.SystemColors.Window;
                mtextUID.ReadOnly          = false;
                lblName.Visible            = false;
                lblEmail.Visible           = false;
                lblPN.Visible              = false;
                lblCat.Visible             = false;
                txtName.Visible            = false;
                txtEmail.Visible           = false;
                mtextPN.Visible            = false;
                cboxCat.Visible            = false;
                btnSave.Visible            = false;
                btnClear.Visible           = false;
                toolStripStatusLabel1.Text = "Input User_ID and click Search";

                Messages A = new Messages();
                A.SaveMessage();
            }
        }