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); }
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."); } }
private void BorrowForm_Load(object sender, EventArgs e) { dpDateIssued.Value = DateTime.Today; dpDateDue.Value = DateTime.Today; dpDateIssued.MaxDate = DateTime.Today; borrower = null; borrowRFIDTag = null; }
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); }
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); } }
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); } }
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); }
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; } } }
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); } }
//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 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; }
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(); }