Beispiel #1
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.");
            }
        }
Beispiel #2
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);
        }
Beispiel #3
0
        private void ValidatetxtbRFID()
        {
            using (SA45Team07B_LibraryEntities context = new SA45Team07B_LibraryEntities())
            {
                string inputRFID = txtbRFID.Text.ToString();

                this.RFIDofReturnBook = (from x in context.RFIDs
                                         where x.RFID == inputRFID
                                         select x).FirstOrDefault();

                if (RFIDofReturnBook != null)
                {
                    this.returnBook = RFIDofReturnBook.Books;

                    lastTransaction = (from x in context.IssueTrans
                                       where x.TransactionID == RFIDofReturnBook.LastTransactionID
                                       select x).FirstOrDefault();

                    if (lastTransaction == null)
                    {
                        ClearTextboxData();
                        MessageBox.Show("No last transaction record.");
                    }
                    else if (lastTransaction.Status == "in")
                    {
                        ClearTextboxData();
                        MessageBox.Show("No active transaction record.");
                    }
                    else
                    {
                        borrower           = lastTransaction.Members;
                        borrowerMemberType = borrower.MemberCategories;
                        borrowerFaculty    = borrower.Faculties;

                        DisplayTextboxData();

                        errorProviderForRFID.SetError(txtbRFID, "");
                        toolStripStatusLabel1.Text = "1 record is found.";
                        btnSubmit.Enabled          = true;
                    }
                }
                else
                {
                    errorProviderForRFID.SetError(txtbRFID, "Invalid RFID");
                    toolStripStatusLabel1.Text = "Invalid RFID";
                    ClearTextboxData();
                    btnSubmit.Enabled = false;
                }
            }
        }
Beispiel #4
0
        //true means "in"
        public static bool CheckRFIDAvailability(string RFID)
        {
            SA45Team07B_LibraryEntities context = new SA45Team07B_LibraryEntities();
            RFIDTag   tag     = context.RFIDs.Where(x => x.RFID == RFID).First();
            long?     transID = tag.LastTransactionID;
            IssueTran trans   = context.IssueTrans.Where(x => x.TransactionID == transID).First();

            if (trans.Status == "out")
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        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();
        }