Пример #1
0
        public static bool CreateBorrowTransaction(Dictionary <string, string> queries)
        {
            string   RFID      = queries["RFID"];
            long     memberID  = long.Parse(queries["MemberID"]);
            DateTime issueDate = DateTime.Parse(queries["DateIssued"]);
            DateTime dueDate   = DateTime.Parse(queries["DateDue"]);

            SA45Team07B_LibraryEntities context = new SA45Team07B_LibraryEntities();

            RFIDTag rFIDTag = context.RFIDs.Where(x => x.RFID == RFID).First();

            /*This transaction combines three sequences:
             * - create new issue tran in IssueTrans
             * - increment of member's loan qty in Members
             * - change the availability of RFID in RFIDs
             * */
            using (TransactionScope ts = new TransactionScope())
            {
                IssueTran tran = new IssueTran
                {
                    RFID       = RFID,
                    MemberID   = memberID,
                    DateIssued = issueDate,
                    DateDue    = dueDate
                };

                context.IssueTrans.Add(tran);

                Member member = context.Members.Where(x => x.MemberID == memberID).First();
                member.LoanedQty += 1;

                rFIDTag.Availability = "n";

                try
                {
                    context.SaveChanges();
                    ts.Complete();
                }
                catch (Exception e)
                {
                    return(false);
                }
            }

            //After the transaction succeeded, update the trans id in RDIDs
            var query = (from x in context.IssueTrans orderby x.TransactionID descending select x).Take(1);

            rFIDTag.LastTransactionID = query.First().TransactionID;
            context.SaveChanges();
            return(true);
        }
Пример #2
0
        //Save changes
        private void buttonSaveChanges_Click(object sender, EventArgs e)
        {
            SA45Team07B_LibraryEntities context2 = new SA45Team07B_LibraryEntities();
            Member memb = context2.Members.Where(x => x.SchoolID == maskedTextBoxSchoolID.Text).First();

            memb.MemberName       = textBoxMemberName.Text.Trim();
            memb.MemberCategories = context2.MemberCategories.Where(x => x.CategoryName == comboBoxMemberType.SelectedItem.ToString()).FirstOrDefault();
            memb.Faculties        = context2.Faculties.Where(x => x.FacultyName == comboBoxFacultyName.SelectedItem.ToString()).FirstOrDefault();
            memb.ContactNumber    = textBoxContactNumber.Text.Trim();
            memb.Email            = textBoxEmail.Text.ToLower();

            DialogResult dr = MessageBox.Show("Confirm update member?", "Confirmation", MessageBoxButtons.YesNoCancel);

            if (dr == DialogResult.Yes)
            {
                context2.SaveChanges();
                MessageBox.Show(string.Format("Successfully updated Member <<{0}>>.", memb.MemberName));
                Close();
            }
            else if (dr == DialogResult.No)
            {
                DialogResult = 0;
            }
            else if (dr == DialogResult.Cancel)
            {
                DialogResult = 0;
            }
        }
Пример #3
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (this.dtpReturnDate.Value >= this.dtpIssueDate.Value && this.txtbRFID.Text != string.Empty)
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    if (txtbRemarks.Text.Length > 255)
                    {
                        // should no happen as the textbox max length is 255
                        MessageBox.Show("Remarks exceed maximum length.");
                    }
                    else
                    {
                        using (SA45Team07B_LibraryEntities context = new SA45Team07B_LibraryEntities())
                        {
                            RFIDofReturnBook = (from x in context.RFIDs
                                                where x.RFID == RFIDofReturnBook.RFID
                                                select x).First();

                            lastTransaction = (from x in context.IssueTrans
                                               where (x.TransactionID == lastTransaction.TransactionID)
                                               select x).First();

                            borrower = (from x in context.Members
                                        where x.MemberID == lastTransaction.MemberID
                                        select x).First();

                            lastTransaction.DateActualReturned = this.dtpReturnDate.Value;
                            lastTransaction.Status             = "in";
                            lastTransaction.Remarks            = txtbRemarks.Text.ToString();

                            RFIDofReturnBook.Availability = "y";

                            borrower.LoanedQty -= 1;

                            int i = context.SaveChanges();
                            ts.Complete();

                            if (i > 0)
                            {
                                toolStripStatusLabel1.Text = "Return was successful.";
                                txtbRemarks.Text           = string.Empty;
                                ClearTextboxData();
                                this.ActiveControl = txtbRFID;
                            }
                            else
                            {
                                MessageBox.Show("Return was not successful. Please try again.");
                            }
                        }
                    }
                }
            }
            else
            {
                // cannot happen
                MessageBox.Show("Invalid Return Date.");
            }
        }
Пример #4
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            using (SA45Team07B_LibraryEntities context = new SA45Team07B_LibraryEntities())
            {
                newbook.BookID = long.Parse(txtbBkId.Text);
                //assign value for fields not require validation
                newbook.BookTitle = txtbBkTitle.Text.Trim();
                newbook.Author    = txtbAuthor.Text.Trim();
                if (newbook.PublisherValidation(cbxPublisher, epAddBk) && newbook.SubjectNameValidation(cbxSubjectName, epAddBk))
                {
                    newbook.PublisherID = context.Publishers.Where(x => x.PublisherName == cbxPublisher.Text).First().PublisherID.ToString();
                    newbook.SubjectCode = context.BookSubjects.Where(x => x.SubjectName == cbxSubjectName.Text).First().SubjectCode.ToString();
                }

                if (newbook.ISBNValidation(mtbISBN, epAddBk) &&
                    newbook.CallNumValidation(txtbPrice, epAddBk) &&
                    newbook.PriceValidation(txtbPrice, epAddBk))
                {
                    newbook.ISBN       = mtbISBN.Text.Trim();
                    newbook.CallNumber = txtbCallNum.Text.Trim();
                    newbook.Price      = decimal.Parse(txtbPrice.Text.Trim());
                }

                //assign value for fields allow null value
                if (txtbEd.Text.Trim() != string.Empty)
                {
                    newbook.Edition = txtbEd.Text.Trim();
                }
                if (mtbYear.Text.Trim() != string.Empty)
                {
                    if (newbook.YearValidation(mtbYear, epAddBk))
                    {
                        newbook.PublishedYear = mtbYear.Text.Trim();
                    }
                }

                newbook.AddRFID(lbxRFID);
                newbook.TotalCopy = (Int16)newbook.RFIDs.Count();

                //Submission validation
                if (!this.ValidateChildren())
                {
                    MessageBox.Show("Not able to add this book. Please refer to individual error message");
                }
                else if (lbxRFID.Items.Count == 0)
                {
                    epAddBk.SetError(lbxRFID, "Please provide RFID for this book");
                }
                else
                {
                    context.Books.Add(newbook);
                    context.SaveChanges();
                    MessageBox.Show("Book Added");
                    Close();
                }
            }
        }
Пример #5
0
        private void btnSaveChanges_Click(object sender, EventArgs e)
        {
            IssueTran selectedTransaction = null;

            if (dataGridViewTransactionRecords.RowCount != 0)
            {
                long transactionID = Int64.Parse(dataGridViewTransactionRecords.CurrentRow.Cells["TransactionIDColumn"].Value.ToString());

                using (SA45Team07B_LibraryEntities context = new SA45Team07B_LibraryEntities())
                {
                    selectedTransaction = (from x in context.IssueTrans
                                           where x.TransactionID == transactionID
                                           select x).First();

                    if (selectedTransaction != null)
                    {
                        using (TransactionScope ts = new TransactionScope())
                        {
                            if (txtbRemarksOfSelectedTransaction.Text.Length > 255)
                            {
                                // should no happen as the textbox max length is 255
                                MessageBox.Show("Remarks exceed maximum length.");
                            }
                            else
                            {
                                selectedTransaction.Remarks = txtbRemarksOfSelectedTransaction.Text.ToString();
                                int i = context.SaveChanges();
                                ts.Complete();

                                if (i > 0)
                                {
                                    submitSuccessful = true;
                                }
                                else
                                {
                                    submitSuccessful = false;
                                }

                                this.ActiveControl = txtbRemarksOfSelectedTransaction;
                            }
                        }
                    }
                }
            }

            DisplayDGVData();
        }
Пример #6
0
        //Add for Add Publisher
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            SA45Team07B_LibraryEntities context2 = new SA45Team07B_LibraryEntities();
            Publisher pb             = new Publisher();
            var       matchingRecord = context2.Publishers.Where(x => x.PublisherID == textBoxPublisherID.Text.Trim()).FirstOrDefault();

            if (matchingRecord != null)
            {
                errorProviderPublisherID.SetError(textBoxPublisherID, "Member already exists.");
            }
            else
            {
                pb.PublisherID = textBoxPublisherID.Text.Trim();

                pb.PublisherName = textBoxPublisherName.Text.Trim();
                if (comboBoxCountry.SelectedItem != null && (comboBoxCountry.SelectedItem.ToString() != "Not Applicable"))
                {
                    pb.Country = comboBoxCountry.SelectedItem.ToString();
                }
                else
                {
                    pb.Country = "";
                }

                DialogResult dr = MessageBox.Show("Confirm add new publisher?", "Confirmation", MessageBoxButtons.YesNoCancel);
                if (dr == DialogResult.Yes)
                {
                    context2.Publishers.Add(pb);
                    context2.SaveChanges();
                    MessageBox.Show(string.Format("Successfully added Publisher <<{0}>>.", pb.PublisherName));
                    SA45Team07B_LibraryEntities context = new SA45Team07B_LibraryEntities();
                    var query = from x in context.Publishers select new { x.PublisherID, x.PublisherName, x.Country };
                    dataGridViewPublishers.DataSource = query.ToList();
                }
                else if (dr == DialogResult.No)
                {
                    DialogResult = 0;
                }
                else if (dr == DialogResult.Cancel)
                {
                    DialogResult = 0;
                }
            }
        }
Пример #7
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //Submission validation
            if (!this.ValidateChildren() || lbxRFID.Items.Count == 0)
            {
                MessageBox.Show("Not able to modify this book. Please refer to individual error message");
            }
            else
            {
                //trim the lbox into list<string> newRFID and add to this book

                List <string> newRFID = new List <string>();

                foreach (var item in lbxRFID.Items)
                {
                    newRFID.Add(item.ToString());
                }
                newRFID.RemoveRange(0, bookFound.RFIDs.Count());
                bookModified.AddRFID(newRFID);


                using (SA45Team07B_LibraryEntities context = new SA45Team07B_LibraryEntities())
                {
                    Book bookToBeModified = context.Books.Where(x => x.BookID == bookFound.BookID).First();
                    bookToBeModified.ISBN          = bookModified.ISBN;
                    bookToBeModified.BookTitle     = bookModified.BookTitle;
                    bookToBeModified.BookSubjects  = context.BookSubjects.Where(x => x.SubjectName == cbxSubjectName.Text).First();
                    bookToBeModified.CallNumber    = bookModified.CallNumber;
                    bookToBeModified.Author        = txtbAuthor.Text.Trim(); //Author not require validation
                    bookToBeModified.PublisherID   = context.Publishers.Where(x => x.PublisherName == cbxPublisher.Text).First().PublisherID.ToString();
                    bookToBeModified.Price         = bookModified.Price;
                    bookToBeModified.Edition       = bookModified.Edition;
                    bookToBeModified.PublishedYear = bookModified.PublishedYear;

                    bookToBeModified.RFIDs = bookModified.RFIDs;

                    bookToBeModified.TotalCopy = (Int16)bookToBeModified.RFIDs.Count();
                    context.SaveChanges();
                    MessageBox.Show("Saved");
                    Close();
                }
            }
        }
Пример #8
0
        //Add for Add Member
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            SA45Team07B_LibraryEntities context2 = new SA45Team07B_LibraryEntities();

            Member newMember = new Member();

            newMember.SchoolID   = maskedTextBoxSchoolID.Text.ToUpper();
            newMember.MemberName = textBoxMemberName.Text.Trim();

            MemberCategories cat = new MemberCategories();

            cat = context2.MemberCategories.Where(x => x.CategoryName == comboBoxMemberType.SelectedItem.ToString()).FirstOrDefault();
            newMember.MemberCategories = cat;

            Faculty fac = new Faculty();

            fac = context2.Faculties.Where(x => x.FacultyName == comboBoxFacultyName.SelectedItem.ToString()).FirstOrDefault();
            newMember.Faculties = fac;

            newMember.ContactNumber = textBoxContactNumber.Text.Trim();
            newMember.Email         = textBoxEmail.Text.ToLower().Trim();
            newMember.Discontinued  = "N";
            newMember.LoanedQty     = 0;

            DialogResult dr = MessageBox.Show("Confirm add new member?", "Confirmation", MessageBoxButtons.YesNoCancel);

            if (dr == DialogResult.Yes)
            {
                context2.Members.Add(newMember);
                context2.SaveChanges();
                MessageBox.Show(string.Format("Successfully added <<{0}>>.", newMember.MemberName));
                Close();
            }
            else if (dr == DialogResult.No)
            {
                DialogResult = 0;
            }
            else if (dr == DialogResult.Cancel)
            {
                DialogResult = 0;
            }
        }
Пример #9
0
        public static void MakeRFIDAdjusment(string RFID, bool discontinued, string remarks)
        {
            SA45Team07B_LibraryEntities context = new SA45Team07B_LibraryEntities();

            RFIDTag tag = context.RFIDs.Where(x => x.RFID == RFID).First();

            tag.Discontinued = discontinued ? "y" : "n";

            StockAdjustment adj = new StockAdjustment
            {
                RFID         = RFID,
                DateAdjusted = DateTime.Now,
                QtyAdjusted  = discontinued ? (short)-1 : (short)1,
                Remarks      = remarks
            };

            context.StockAdjustments.Add(adj);

            context.SaveChanges();
        }
Пример #10
0
        //Save Changes for Modify Publisher
        private void buttonSaveChanges_Click(object sender, EventArgs e)
        {
            SA45Team07B_LibraryEntities context2 = new SA45Team07B_LibraryEntities();
            Publisher pb = new Publisher();

            pb = context2.Publishers.Where(x => x.PublisherID == textBoxModPublisherID.Text).First();
            pb.PublisherName = textBoxModPublisherName.Text.Trim();
            if (comboBoxModCountry.SelectedItem != null && (comboBoxModCountry.SelectedItem.ToString() != "Not Applicable"))
            {
                pb.Country = comboBoxModCountry.SelectedItem.ToString();
            }
            else
            {
                pb.Country = "";
            }

            DialogResult dr = MessageBox.Show("Confirm update?", "Confirmation", MessageBoxButtons.YesNoCancel);

            if (dr == DialogResult.Yes)
            {
                context2.SaveChanges();
                MessageBox.Show(string.Format("Successfully updated <<{0}>>.", pb.PublisherName));
                toolStripStatusLabel1.Text = "Publisher list updated.";
                SA45Team07B_LibraryEntities context = new SA45Team07B_LibraryEntities();
                var query = from x in context.Publishers select new { x.PublisherID, x.PublisherName, x.Country };
                dataGridViewPublishers.DataSource = query.ToList();
            }
            else if (dr == DialogResult.No)
            {
                DialogResult = 0;
            }
            else if (dr == DialogResult.Cancel)
            {
                DialogResult = 0;
            }
        }