private void borrowReceiptToolStripMenuItem_Click(object sender, EventArgs e) { if (i == 1) { BorrowReceiptForm bore = new BorrowReceiptForm(); bore.Show(); } else { MessageBox.Show("Please login!"); } }
//Confirm for Borrow Book private void btnConfirm_Click(object sender, EventArgs e) { //Program written by Thett Oo Eain //Testing TextBoxes are blank, Due date and borrow date. if (txtBookID.Text == "" || maskedTxtMemberID.Text == "" || maskedTxtMemberID.Text.Length < 5 || txtAvailableToBorrow.Text == "" || txtTotalStock.Text == "") { MessageBox.Show("Type Carefully and Check Aagin!"); } else { int BDay = dateTimePickerBorrowDate.Value.Day; int DDay = dateTimePickerDueDate.Value.Day; int BMonth = dateTimePickerBorrowDate.Value.Month; int DMonth = dateTimePickerDueDate.Value.Month; int BYear = dateTimePickerBorrowDate.Value.Year; int DYear = dateTimePickerDueDate.Value.Year; if ((BYear < DYear && BMonth < DMonth)) { if (Convert.ToInt32(txtAvailableToBorrow.Text) > 0 && Convert.ToInt32(txtTotalStock.Text) > 0) { con = new SqlConnection(str); SqlCommand cmdInsertIssueTran = new SqlCommand(); cmdInsertIssueTran.Connection = con; cmdInsertIssueTran.CommandText = "Insert into IssueTran(MemberID, BookID, BorrowedStatus, DateIssue, DueDate) values(@MemberID, @BookID, 'OUT', @DateIssue, @DueDate)"; SqlParameter pMemberID = new SqlParameter("@MemberID", SqlDbType.NVarChar, 10); SqlParameter pBookID = new SqlParameter("@BookID", SqlDbType.Int); SqlParameter pDateIssue = new SqlParameter("@DateIssue", SqlDbType.DateTime); SqlParameter pDueDate = new SqlParameter("@DueDate", SqlDbType.DateTime); SqlParameter[] pArr = new SqlParameter[] { pMemberID, pBookID, pDateIssue, pDueDate }; cmdInsertIssueTran.Parameters.AddRange(pArr); SqlCommand cmdUpdateBook = new SqlCommand(); cmdUpdateBook.Connection = con; cmdUpdateBook.CommandText = "update Books set NumberBorrowed= NumberBorrowed+1 where BookID=@BookID1"; SqlParameter pBookID2 = new SqlParameter("@BookID1", SqlDbType.Int); cmdUpdateBook.Parameters.Add(pBookID2); using (TransactionScope ts = new TransactionScope()) { con.Open(); pMemberID.Value = maskedTxtMemberID.Text; pBookID.Value = Convert.ToInt16(txtBookID.Text); pDateIssue.Value = dateTimePickerBorrowDate.Value; pDueDate.Value = dateTimePickerDueDate.Value; pBookID2.Value = Convert.ToInt16(txtBookID.Text); cmdInsertIssueTran.ExecuteNonQuery(); cmdUpdateBook.ExecuteNonQuery(); ts.Complete(); } con.Close(); BorrowReceiptForm bowform = new BorrowReceiptForm(); bowform.Show(); MessageBox.Show("Borrow Successful"); //BorrowReceiptForm bowform = new BorrowReceiptForm(); //bowform.Show(); ClearText(); } else { MessageBox.Show("Not Available"); ClearText(); } } else if ((BMonth < DMonth && BDay < DDay) || (BMonth < DMonth && BDay > DDay) || (BMonth == DMonth && BDay < DDay)) { if (Convert.ToInt32(txtAvailableToBorrow.Text) > 0 && Convert.ToInt32(txtTotalStock.Text) > 0) { con = new SqlConnection(str); SqlCommand cmdInsertIssueTran = new SqlCommand(); cmdInsertIssueTran.Connection = con; cmdInsertIssueTran.CommandText = "Insert into IssueTran(MemberID, BookID, BorrowedStatus, DateIssue, DueDate) values(@MemberID, @BookID, 'OUT', @DateIssue, @DueDate)"; SqlParameter pMemberID = new SqlParameter("@MemberID", SqlDbType.NVarChar, 10); SqlParameter pBookID = new SqlParameter("@BookID", SqlDbType.Int); SqlParameter pDateIssue = new SqlParameter("@DateIssue", SqlDbType.DateTime); SqlParameter pDueDate = new SqlParameter("@DueDate", SqlDbType.DateTime); SqlParameter[] pArr = new SqlParameter[] { pMemberID, pBookID, pDateIssue, pDueDate }; cmdInsertIssueTran.Parameters.AddRange(pArr); SqlCommand cmdUpdateBook = new SqlCommand(); cmdUpdateBook.Connection = con; cmdUpdateBook.CommandText = "update Books set NumberBorrowed= NumberBorrowed+1 where BookID=@BookID1"; SqlParameter pBookID2 = new SqlParameter("@BookID1", SqlDbType.Int); cmdUpdateBook.Parameters.Add(pBookID2); using (TransactionScope ts = new TransactionScope()) { con.Open(); pMemberID.Value = maskedTxtMemberID.Text; pBookID.Value = Convert.ToInt16(txtBookID.Text); pDateIssue.Value = dateTimePickerBorrowDate.Value; pDueDate.Value = dateTimePickerDueDate.Value; pBookID2.Value = Convert.ToInt16(txtBookID.Text); cmdInsertIssueTran.ExecuteNonQuery(); cmdUpdateBook.ExecuteNonQuery(); ts.Complete(); } con.Close(); MessageBox.Show("Borrow Successful"); BorrowReceiptForm bowform = new BorrowReceiptForm(); bowform.Show(); ClearText(); } else { MessageBox.Show("Not Available"); ClearText(); } } else { MessageBox.Show("Your Due Date should be greater than the Borrow Date. "); ClearText(); } } }