private void toolStripButton1_Click(object sender, EventArgs e) // Borrow button { if (textBox2.Text == "") // validate: check for no selected customer { MessageBox.Show("No customer account selected"); } else if (dataGridView1.DataSource == null) // validate: check for no selected books { MessageBox.Show("No books are selected for borrowing"); } else { try { Boolean IssueSucess = false; using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { // update IssueTrans IssueTran IT = new IssueTran(); IT.CustomerID = Convert.ToInt32(textBox1.Text); context.IssueTrans.Add(IT); context.SaveChanges(); // update booklist and BookIssued foreach (BookList b in bL) { b.Loaned++; BookIssued BI = new BookIssued(); BI.TransactionNo = IT.TransactionNo; BI.ISBN = b.ISBN; BI.BookTitle = b.BookTitle; BI.DateBorrow = DateTime.Now.Date; BI.DateDue = DateTime.Now.Date.AddDays(14); context.BookIssueds.Add(BI); BorrowSucessfulMessage += string.Format("{0}\t\t{1}\n", b.BookTitle.PadRight(20).Substring(0, 20), BI.DateDue); } context.SaveChanges(); ts.Complete(); MessageBox.Show(BorrowSucessfulMessage); IssueSucess = true; } if (IssueSucess) { new TransReceiptForm().ShowDialog(); } this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void toolStripButton2_Click(object sender, EventArgs e) { String SelectedISBN; String SelectedTitle; // Get the Selected Row, if any if (dataGridView1.SelectedRows.Count != 0) { // Get the selected Row (There's only one) SelectedISBN = dataGridView1.SelectedRows[0].Cells["ISBNColumn"].Value.ToString(); SelectedTitle = dataGridView1.SelectedRows[0].Cells["TitleColumn"].Value.ToString(); } else { MessageBox.Show("Please Search a Book First"); return; } DueTran dd = new DueTran(); dd.CustomerID = Int32.Parse(textBox1.Text); dd.DueAmount = 100; dd.Remarks = "You lost one book. So You have to pay $100."; context.DueTrans.Add(dd); BookList booklist; string returnbook1 = dataGridView1.CurrentRow.Cells[0].Value.ToString(); var qq = from x in context.BookLists where x.ISBN == returnbook1 select x; booklist = qq.ToList().First(); booklist.Loaned--; booklist.TotalStock--; var dateupdate = from x in context.BookIssueds where x.ISBN == returnbook1 select x; BookIssued bi = dateupdate.First(); bi.DateActualReturn = DateTime.Now; context.SaveChanges(); MessageBox.Show("We record U lost one book."); refresh(); }
private void toolStripButton1_Click(object sender, EventArgs e) { BookIssued bookissue; BookList blist; DueTran dtran; String SelectedISBN; String SelectedTitle; // Get the Selected Row, if any if (dataGridView1.SelectedRows.Count != 0) { // Get the selected Row (There's only one) SelectedISBN = dataGridView1.SelectedRows[0].Cells["ISBNColumn"].Value.ToString(); SelectedTitle = dataGridView1.SelectedRows[0].Cells["TitleColumn"].Value.ToString(); } else { MessageBox.Show("Please Search a Book First"); return; } //Assign bookissue to the selected book in datagrid view string returnbook = dataGridView1.CurrentRow.Cells[0].Value.ToString(); var selectedISBN = from x in context.BookIssueds where x.ISBN == returnbook select x; bookissue = selectedISBN.First(); //Over Due Date if (bookissue.DateDue < DateTime.Now) { var duetranupdate = from x in context.DueTrans where x.CustomerID.ToString() == textBox1.Text select x; dtran = duetranupdate.First(); int payamount = 0; dtran.CustomerID = Int32.Parse(textBox1.Text); bookissue.DateActualReturn = DateTime.Now; TimeSpan noofDue = (DateTime.Now) - bookissue.DateDue; double noofDay = noofDue.TotalDays; //TimeSpan duedate = DateTime.Today - bookissue.DateDue; //MessageBox.Show(duedate.ToString()); int overdate = (int)noofDay; if (overdate > 1) { payamount = overdate; dtran.DueAmount = payamount; } dtran.Remarks = "Find new; You are " + noofDay + "day late."; context.DueTrans.Add(dtran); var dateupdate = from x in context.BookIssueds where x.ISBN == returnbook select x; BookIssued bi = dateupdate.First(); bi.DateActualReturn = DateTime.Now; MessageBox.Show("You are " + overdate + "days over due date!.. Pay Amount is: $" + payamount + "!"); context.SaveChanges(); refresh(); } else { string returnbook1 = dataGridView1.CurrentRow.Cells[0].Value.ToString(); var q = from x in context.BookLists where x.ISBN == returnbook1 select x; blist = q.ToList().First(); blist.Loaned--; var dateupdate = from x in context.BookIssueds where x.ISBN == returnbook1 select x; BookIssued bi = dateupdate.First(); bi.DateActualReturn = DateTime.Now; context.SaveChanges(); MessageBox.Show("Thank You for Returning Your Book."); refresh(); } }