예제 #1
0
        private bool ValidateRFID()
        {
            if (txtbRFID.Text == "")
            {
                errorProvider.SetError(txtbRFID, "Empty field");
                return(false);
            }

            if (txtbRFID.Text.Length < 9)
            {
                errorProvider.SetError(txtbRFID, "Wrong RFID format");
                return(false);
            }

            borrowRFIDTag = DataService.GetRFIDTag(txtbRFID.Text);

            if (borrowRFIDTag == null)
            {
                errorProvider.SetError(txtbRFID, "No record found");
                return(false);
            }

            errorProvider.SetError(txtbRFID, "");
            return(true);
        }
예제 #2
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.");
            }
        }
예제 #3
0
 private void BorrowForm_Load(object sender, EventArgs e)
 {
     dpDateIssued.Value   = DateTime.Today;
     dpDateDue.Value      = DateTime.Today;
     dpDateIssued.MaxDate = DateTime.Today;
     borrower             = null;
     borrowRFIDTag        = null;
 }
예제 #4
0
        public static bool GetRFIDDiscontinueStatus(string RFID)
        {
            SA45Team07B_LibraryEntities context = new SA45Team07B_LibraryEntities();

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

            return(tag.Discontinued == "y" ? true : false);
        }
예제 #5
0
 public void AddRFID(List <string> rfidList)
 {
     foreach (var rfid in rfidList)
     {
         RFIDTag newrifd = new RFIDTag();
         newrifd.RFID   = rfid;
         newrifd.BookID = this.BookID;
         this.RFIDs.Add(newrifd);
     }
 }
예제 #6
0
 public void AddRFID(ListBox lbox)
 {
     foreach (var item in lbox.Items)
     {
         RFIDTag newrifd = new RFIDTag();
         newrifd.RFID   = item.ToString();
         newrifd.BookID = this.BookID;
         this.RFIDs.Add(newrifd);
     }
 }
예제 #7
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);
        }
예제 #8
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;
                }
            }
        }
예제 #9
0
        public static RFIDTag GetRFIDTag(string RFID)
        {
            SA45Team07B_LibraryEntities context = new SA45Team07B_LibraryEntities();

            try
            {
                RFIDTag tag = context.RFIDs.Where(x => x.RFID == RFID).First();
                return(tag);
            }
            catch (InvalidOperationException e)
            {
                return(null);
            }
        }
예제 #10
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);
            }
        }
예제 #11
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            using (SA45Team07B_LibraryEntities context = new SA45Team07B_LibraryEntities())
            {
                string selectedRFID = dataGridViewBookList.CurrentRow.Cells["RFIDColumn"].Value.ToString();

                // tag can never be null since this button is disable when there is no selected row
                this.tagFound = (from x in context.RFIDs
                                 where x.RFID == selectedRFID
                                 select x).First();

                this.bookFound            = RFIDFound.Books;
                this.tagsOfBookFound      = BookFound.RFIDs.ToList();
                this.subjectOfBookFound   = BookFound.BookSubjects;
                this.publisherOfBookFound = BookFound.Publishers;
            }

            this.DialogResult = DialogResult.OK;
        }
예제 #12
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();
        }