private void Button1_Click(object sender, EventArgs e) //Confirm button { if (string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(textBox2.Text) || string.IsNullOrWhiteSpace(textBox4.Text) || string.IsNullOrWhiteSpace(textBox5.Text) || string.IsNullOrWhiteSpace(textBox6.Text) || string.IsNullOrWhiteSpace(comboBox3.Text)) { MessageBox.Show("Input Error: Empty Field(s) Detected!" + Environment.NewLine + "Please ensure that all fields are filled. " + Environment.NewLine + "The only field can be left blank is 'Telephone No.'", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (comboBox3.Text != "Male" && comboBox3.Text != "Female") { MessageBox.Show("Input Error: Invalid input(s) Detected!" + Environment.NewLine + "Please ensure that fields 'Gender' are filled with provided items. ", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!Database.CheckUnique("customer", "ic", textBox2.Text)) { MessageBox.Show("Input Error: Duplicate attribute detected!" + Environment.NewLine + "IC number '" + textBox2.Text + "' already exists in customer table.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var customer = new Customer { Name = textBox1.Text, Ic = textBox2.Text, Gender = comboBox3.Text, BirthDate = dateTimePicker1.Value, TelephoneNo = textBox3.Text, HandphoneNo = textBox4.Text, Email = textBox5.Text, Address = textBox6.Text }; customer.Save(); result = customer; var log = new AccessLog { User = Login.Username, Action = "Add", Item = "Customer", ItemId = textBox7.Text, Description = "IC: " + customer.Ic }; log.Insert(); _insertComplete = true; this.Close(); } }
private void Button1_Click(object sender, EventArgs e) { _username = textBox1.Text.ToLower(); string hashedPassword = Security.SHA256Hash(textBox2.Text); List <Employee> item = Employee.Where(string.Format("username = '******'", _username), 0, 1); if (item.Count == 0) { MessageBox.Show("Login Error: Incorrect username. " + Environment.NewLine + "This username does not exists." + Environment.NewLine + "Please double-check and try again.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var emp = item[0]; if (emp.Password == hashedPassword && !emp.IsDisabled()) { var log = new AccessLog { User = _username, Action = "Login", Item = "", ItemId = "" }; log.Insert(); Form1 NextForm = new Form1(); NextForm.Show(); this.Close(); } else { if (emp.IsDisabled()) { MessageBox.Show("Login Error: Account Disabled." + Environment.NewLine + "Your account is suspended." + Environment.NewLine + "Please contact adminstrator for further details.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Login Error: Incorrect password. " + Environment.NewLine + "Please double-check and try again.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void Button6_Click(object sender, EventArgs e) //Save button { if (string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(textBox2.Text) || string.IsNullOrWhiteSpace(textBox4.Text) || string.IsNullOrWhiteSpace(textBox5.Text) || string.IsNullOrWhiteSpace(textBox6.Text) || string.IsNullOrWhiteSpace(comboBox3.Text)) { MessageBox.Show("Input Error: Empty Field(s) Detected!" + Environment.NewLine + "Please ensure that all fields are filled. " + Environment.NewLine + "The only field can be left blank is 'Telephone No.'", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (comboBox3.Text != "Male" && comboBox3.Text != "Female") { MessageBox.Show("Input Error: Invalid input(s) Detected!" + Environment.NewLine + "Please ensure that fields 'Gender' are filled with provided items. ", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!Database.CheckUnique("customer", "ic", textBox2.Text, textBox7.Text)) { MessageBox.Show("Input Error: Duplicate attribute detected!" + Environment.NewLine + "IC number '" + textBox2.Text + "' already exists in customer table.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { var oldCus = new Customer(); oldCus = oldCus.Get(Convert.ToInt32(textBox7.Text)); var customer = new Customer() { Id = Convert.ToInt32(textBox7.Text), Name = textBox1.Text, Ic = textBox2.Text, Gender = comboBox3.Text, BirthDate = dateTimePicker1.Value, TelephoneNo = textBox3.Text, HandphoneNo = textBox4.Text, Email = textBox5.Text, Address = textBox6.Text }; customer.Save(); string updated_attr = ""; if (oldCus.Name != customer.Name) { updated_attr += "; Name: " + oldCus.Name + " to " + customer.Name; } if (oldCus.TelephoneNo != customer.TelephoneNo) { updated_attr += "; Phone No: " + oldCus.TelephoneNo + " to " + customer.TelephoneNo; } if (oldCus.HandphoneNo != customer.HandphoneNo) { updated_attr += "; H/P No: " + oldCus.HandphoneNo + " to " + customer.HandphoneNo; } if (oldCus.Email != customer.Email) { updated_attr += "; Email: " + oldCus.Email + " to " + customer.Email; } if (oldCus.Address != customer.Address) { updated_attr += "; Address: " + oldCus.Address + " to " + customer.Address; } var log = new AccessLog { Action = "Update", Item = "Customer", ItemId = textBox7.Text, User = Login.Username, Description = "IC: " + customer.Ic + updated_attr }; log.Insert(); //Label & Button Settings label2.Show(); //Customer Details label label3.Hide(); //Edit Customer Details label button3.Show(); //Close button button4.Show(); //Edit button button5.Hide(); //Back button button6.Hide(); //Save button LockInputBox(); } }
private void Button1_Click(object sender, EventArgs e) //Confirm button { if (string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(textBox2.Text) || string.IsNullOrWhiteSpace(textBox4.Text) || string.IsNullOrWhiteSpace(textBox5.Text) || string.IsNullOrWhiteSpace(textBox6.Text) || string.IsNullOrWhiteSpace(textBox8.Text) || string.IsNullOrWhiteSpace(textBox9.Text) || string.IsNullOrWhiteSpace(comboBox1.Text) || string.IsNullOrWhiteSpace(comboBox2.Text) || string.IsNullOrWhiteSpace(comboBox3.Text)) { MessageBox.Show("Input Error: Empty Field(s) Detected!" + Environment.NewLine + "Please ensure that all fields are filled. " + Environment.NewLine + "The only field can be left blank is 'Telephone No.'", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!Database.CheckUnique("employee", "ic", textBox2.Text)) { MessageBox.Show("Input Error: Duplicate attribute detected!" + Environment.NewLine + "IC number '" + textBox2.Text + "' already exists in the employee table.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!Database.CheckUnique("employee", "username", textBox8.Text)) { MessageBox.Show("Input Error: Duplicate attribute detected!" + Environment.NewLine + "username '" + textBox8.Text + "' already exists in the employee table.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if ((comboBox3.Text != "Male" && comboBox3.Text != "Female") || (comboBox2.Text != "Staff" && comboBox2.Text != "Manager" && comboBox2.Text != "Owner") || (comboBox1.Text != "Admin" && comboBox1.Text != "Normal")) { MessageBox.Show("Input Error: Invalid input(s) Detected!" + Environment.NewLine + "Please ensure that fields 'Gender', 'Account Permission' and 'Position'" + " are filled with provided items. ", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBox7.Text == "1" && comboBox1.Text != "Admin") { MessageBox.Show("Initialization Error: No Admin Account in Employee Table!" + Environment.NewLine + "You must create an admin account to continue.", "Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string username = textBox8.Text.ToLower(); if (username.Contains("system")) { MessageBox.Show("Input Error: Invalid username." + Environment.NewLine + "Your username cannot contain the word 'system' as it was a reserved word.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _hashedPassword = Security.SHA256Hash(textBox9.Text); if (textBox7.Text == "1") { Database.CreateTable(); } var employee = new Employee { Username = username, Password = _hashedPassword, Permission = comboBox1.Text, Name = textBox1.Text, Ic = textBox2.Text, Gender = comboBox3.Text, Position = comboBox2.Text, Salary = numericUpDown1.Value, BirthDate = dateTimePicker1.Value, TelephoneNo = textBox3.Text, HandphoneNo = textBox4.Text, Email = textBox5.Text, Address = textBox6.Text }; employee.Save(); _insertComplete = true; _setupComplete = true; var log = new AccessLog { Action = "Add", Item = "Employee", ItemId = textBox7.Text, Description = "IC: " + textBox2.Text }; if (textBox7.Text == "1") { log.User = username; log.Insert(); } else { log.User = Login.Username; log.Insert(); } this.Close(); } }
private void Button5_Click(object sender, EventArgs e) //Save button { if (string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(textBox2.Text) || string.IsNullOrWhiteSpace(textBox4.Text) || string.IsNullOrWhiteSpace(textBox5.Text) || string.IsNullOrWhiteSpace(textBox6.Text) || string.IsNullOrWhiteSpace(textBox8.Text) || string.IsNullOrWhiteSpace(comboBox1.Text) || string.IsNullOrWhiteSpace(comboBox2.Text) || string.IsNullOrWhiteSpace(comboBox3.Text)) { MessageBox.Show("Input Error: Empty Field(s) Detected!" + Environment.NewLine + "Please ensure that all fields are filled. " + Environment.NewLine + "The only field can be left blank is 'Telephone No.' and 'Password'.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!Database.CheckUnique("employee", "ic", textBox2.Text, textBox7.Text)) { MessageBox.Show("Input Error: Duplicate attribute detected!" + Environment.NewLine + "IC number '" + textBox2.Text + "' already exists in the employee table.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if ((comboBox3.Text != "Male" && comboBox3.Text != "Female") || (comboBox2.Text != "Staff" && comboBox2.Text != "Manager" && comboBox2.Text != "Owner") || (comboBox1.Text != "Admin" && comboBox1.Text != "Normal")) { MessageBox.Show("Input Error: Invalid input(s) Detected!" + Environment.NewLine + "Please ensure that fields 'Gender', 'Account Permission' and 'Position'" + " are filled with provided items. ", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (!string.IsNullOrWhiteSpace(textBox9.Text)) { _hashedPassword = Security.SHA256Hash(textBox9.Text); } var oldEmp = new Employee(); oldEmp = oldEmp.Get(Convert.ToInt32(textBox7.Text)); var employee = new Employee { Id = Convert.ToInt32(textBox7.Text), Username = textBox8.Text, Password = _hashedPassword, Permission = comboBox1.Text, Name = textBox1.Text, Ic = textBox2.Text, Gender = comboBox3.Text, Position = comboBox2.Text, Salary = numericUpDown1.Value, BirthDate = dateTimePicker1.Value, TelephoneNo = textBox3.Text, HandphoneNo = textBox4.Text, Email = textBox5.Text, Address = textBox6.Text }; employee.Save(); _setupComplete = true; string updatedAttr = ""; if (oldEmp.Name != employee.Name) { updatedAttr += "; Name: " + oldEmp.Name + " to " + employee.Name; } if (oldEmp.TelephoneNo != employee.TelephoneNo) { updatedAttr += "; Phone No: " + oldEmp.TelephoneNo + " to " + employee.TelephoneNo; } if (oldEmp.HandphoneNo != employee.HandphoneNo) { updatedAttr += "; H/P No: " + oldEmp.HandphoneNo + " to " + employee.HandphoneNo; } if (oldEmp.Email != employee.Email) { updatedAttr += "; Email: " + oldEmp.Email + " to " + employee.Email; } if (oldEmp.Address != employee.Address) { updatedAttr += "; Address: " + oldEmp.Address + " to " + employee.Address; } if (oldEmp.Password != employee.Password) { updatedAttr += "; Password changed"; } if (oldEmp.Permission != employee.Permission) { updatedAttr += "; Permission: " + oldEmp.Permission + " to " + employee.Permission; } if (oldEmp.Position != employee.Position) { updatedAttr += "; Position: " + oldEmp.Position + " to " + employee.Position; } if (oldEmp.Salary != employee.Salary) { updatedAttr += "; Salary: " + oldEmp.Salary.ToString() + " to " + employee.Salary.ToString(); } var log = new AccessLog { Action = "Update", Item = "Employee", ItemId = textBox7.Text, User = Login.Username, Description = "IC: " + employee.Ic + updatedAttr }; log.Insert(); if (_setupComplete) { //Label & Button Settings label17.Show(); //Employee Details label label18.Hide(); //Edit Employee Details label button3.Show(); //Close button button4.Show(); //Edit button button5.Hide(); //Save button button6.Hide(); //Back button LockInputBox(); } } }
private void Button3_Click(object sender, EventArgs e) //Export button { string month = dateTimePicker1.Value.ToString("MM"); string longMonth = dateTimePicker1.Value.ToString("MMM"); string fullMonth = dateTimePicker1.Value.ToString("MMMM"); string year = dateTimePicker1.Value.ToString("yyyy"); var result = MessageBox.Show("Do you want to export transactions for " + fullMonth + " " + year + "?\n\n" + "Note:\n1. Exported transactions will be deleted from the database. \n2. If you did not generate the report for " + fullMonth + " " + year + ", please generate and export it first.", "Export Transactions", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { if (dateTimePicker1.Value.Month == DateTime.Now.Month && dateTimePicker1.Value.Year == DateTime.Now.Year) { MessageBox.Show("Export Error: You can't export transactions for this month \n(" + fullMonth + " " + year + ").", "Export Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string defaultFileName = String.Format("EXPORT_TRANSACTIONS_{0}_{1}_{2}", longMonth, year, DateTime.Now.ToString("ddMMyyyy_HHmmss")); string dateCond = String.Format("return_date LIKE '{0}-{1}-%'", year, month); var transactionsList = Transaction.Where(dateCond, 0, 2147483467); if (!transactionsList.Any()) { MessageBox.Show("Error: Empty Record.\nThere are no records in " + fullMonth + " " + year + ".", "Empty Record", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SaveFileDialog sf = new SaveFileDialog { FileName = defaultFileName, Filter = "Excel Workbook (.xlsx) |*.xlsx", Title = "Export Transactions as", FilterIndex = 1 }; if (sf.ShowDialog() == DialogResult.OK) { string savePath = Path.GetDirectoryName(sf.FileName); string fileName = Path.GetFileName(sf.FileName); string saveFile = Path.Combine(savePath, fileName); try { var workbook = new XLWorkbook(); var ws = workbook.AddWorksheet("Transactions"); ws.Cell(1, 1).Value = String.Format("Transactions in {0} {1}", fullMonth, year); ws.Cell(2, 1).InsertTable(transactionsList); DataTable statusTable = new DataTable(); statusTable.Columns.Add("Transaction ID"); statusTable.Columns.Add("Status ID"); foreach (Transaction t in transactionsList) { var statusList = RentalStatus.Where(String.Format("transaction_id = {0}", t.Id), 0, 5); foreach (RentalStatus s in statusList) { statusTable.Rows.Add(s.TransactionId, s.StatusId); } } ws.Cell(ws.LastRowUsed().RowNumber() + 2, 1).InsertTable(statusTable); workbook.SaveAs(saveFile); //Save the file string escapedSaveFile = saveFile.Replace(@"\", @"\\"); var log = new AccessLog() //AccessLog for export { User = Login.Username, Action = "Export", Item = "Transaction", Description = "Month of Transaction Return Date: " + fullMonth + " " + year + "; Path: " + escapedSaveFile }; log.Insert(); foreach (Transaction t in transactionsList) { var statusList = RentalStatus.Where(String.Format("transaction_id = {0}", t.Id), 0, 5); foreach (RentalStatus s in statusList) { s.Delete(); log = new AccessLog() { User = "******", Action = "Delete from database", ItemId = s.TransactionId + ", " + s.StatusId, Item = "Rental Status", Description = "Exported in " + fileName }; log.Insert(); } t.Delete(); log = new AccessLog() { User = "******", Action = "Delete from database", Item = "Transaction", Description = "Month of Transaction Return Date: " + fullMonth + " " + year + "; exported in " + fileName }; log.Insert(); } } catch (Exception exception) { MessageBox.Show(exception.Message); return; } _exportComplete = true; this.Close(); } } }
private void Button2_Click(object sender, EventArgs e) //Save Button { //Select item the dictonary<int (key), string (value)>, which contains the type_name (comboBox1.Text) //In _comboBoxItems, key = type_id, value = type_name var dictValue = from selected in _comboBoxItems where selected.Value.Contains(comboBox1.Text) select selected; //Check if comboBox1.Text was empty or invalid input, //dictValue.Any() determines whether the sequence in dictvalue contains any element if (comboBox1.SelectedIndex < 0 || !dictValue.Any()) { MessageBox.Show("Input Error: Invalid input detected!" + Environment.NewLine + "Please ensure that field 'Locker Type' was filled with provided items. ", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Get the key of the selected item int typeId = Convert.ToInt32(dictValue.First().Key); var cab = new Cabinet { Code = textBox2.Text, Row = Convert.ToInt32(numericUpDown1.Value), Column = Convert.ToInt32(numericUpDown2.Value), TypeID = typeId }; cab.Save(); int latestCabId = cab.Id; var log = new AccessLog { User = Login.Username, Action = "Add", Item = "Cabinet", ItemId = textBox1.Text.ToString(), Description = "Code: " + textBox2.Text }; log.Insert(); _insertComplete = true; for (int i = 1; i <= (cab.Row * cab.Column); i++) { log.ItemId = Locker.CurrentID(); //Auto increment for locker codes var locker = new Locker { Code = String.Format("{0}-{1}", cab.Code, i.ToString("D3")), CabinetID = latestCabId }; locker.Save(); log.User = "******"; log.Action = "Add"; log.Item = "Locker"; log.Description = "Code: " + locker.Code; log.Insert(); } this.Close(); }
private void Button9_Click(object sender, EventArgs e) //Change Locker button { var result = MessageBox.Show("Do you want to change the locker for this rental?", "Change Locker", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { //Check if the rental overdue. If yes, show error message and return. var endDate = selectedRental.StartDate.AddDays(selectedRental.Duration); TimeSpan timeSpan = endDate.Date.Subtract(DateTime.Now.Date); int daysLeft = Convert.ToInt32(timeSpan.Days); if (daysLeft < 0) { MessageBox.Show("Access Error: Rental Overdued." + Environment.NewLine + "You cannot change details for an overdued rental.", "Access Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Assign the old rental data to a temp variable int oldLockerId = selectedRental.LockerID; var oldLocker = new Locker(); oldLocker = oldLocker.Get(oldLockerId); //Open Select Locker Form var ChangeLockerForm = new SelectLockerForm(selectedRental.LockerID); ChangeLockerForm.ShowDialog(); //If cancel select, return. if (!ChangeLockerForm.LockerSelected) { return; } //Get the new selected type, cabinet and locker for the selected locker _typeList = Type.Where(String.Format("id = {0}", ChangeLockerForm.TypeID), 0, 1); _cabinetList = Cabinet.Where(String.Format("id = {0}", ChangeLockerForm.CabinetID), 0, 1); _lockerList = Locker.Where(String.Format("id = {0}", ChangeLockerForm.LockerID), 0, 1); //Assign the new locker into rental, and save access log selectedRental.LockerID = ChangeLockerForm.LockerID; selectedRental.Save(); var log = new AccessLog() { User = Login.Username, Action = "Update", Item = "Rental", ItemId = selectedRental.Id.ToString(), Description = "Locker: " + oldLocker.Code + " to " + _lockerList[0].Code }; log.Insert(); //Release the old locker (status = available) and insert into access log oldLocker.Reset(); log.User = "******"; log.Action = "Update"; log.Item = "Locker"; log.ItemId = oldLocker.Id.ToString(); log.Description = "Code: " + oldLocker.Code + "; Status: Occupied to Available"; log.Insert(); //Check if the old cabinet is full. If yes, set the cabinet to available. var oldCabinet = new Cabinet(); oldCabinet = oldCabinet.Get(oldLocker.CabinetID); if (oldCabinet.IsFull()) { oldCabinet.Restore(); log.User = "******"; log.Action = "Update"; log.Item = "Cabinet"; log.ItemId = oldLocker.CabinetID.ToString(); log.Description = "Code: " + oldCabinet.Code + "; Status: Full to Available"; log.Insert(); } //Set the new locker is occupied, and insert into access log _lockerList[0].Occupied(); log.User = "******"; log.Action = "Update"; log.Item = "Locker"; log.ItemId = selectedRental.LockerID.ToString(); log.Description = "Code: " + _lockerList[0].Code + "; Status: Available to Occupied"; log.Insert(); //Check if the new cabinet full. If yes, set cabinet to full, and insert into access log. var locker = new Locker(); int EmptyLockerNo = locker.Count(String.Format("cabinet_id = {0} AND status = 'Available'", _cabinetList[0].Id)); if (EmptyLockerNo <= 0) { _cabinetList[0].Full(); log.User = "******"; log.Action = "Update"; log.Item = "Cabinet"; log.ItemId = _cabinetList[0].Id.ToString(); log.Description = "Code: " + _cabinetList[0].Code + "; Status: Available to Full"; log.Insert(); } //Change the details in transaction and save in access log var selectedTrans = Transaction.Where(String.Format("rental_id = {0}", selectedRental.Id), 0, 1); selectedTrans[0].LockerID = _lockerList[0].Id; selectedTrans[0].ChangeLocker(); log.User = "******"; log.Action = "Update"; log.Item = "Transaction"; log.ItemId = selectedTrans[0].Id.ToString(); log.Description = "Locker: " + oldLocker.Code + " to " + _lockerList[0].Code; log.Insert(); //Change the locker details in the View Rental Details textBox25.Text = _lockerList[0].Id.ToString(); textBox26.Text = _lockerList[0].Code; textBox27.Text = _cabinetList[0].Code; textBox28.Text = _typeList[0].Name; textBox29.Text = _typeList[0].Rate.ToString("0.00"); } }
private void Button10_Click(object sender, EventArgs e) //Next button { if (numericUpDown9.Value < numericUpDown8.Value) { MessageBox.Show("Input Error: Insufficient Payment." + Environment.NewLine + "Payment amount must be equal or higher than total price.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } numericUpDown10.Value = numericUpDown9.Value - numericUpDown8.Value; button11.Hide(); button10.Hide(); button12.Show(); //Delete Rental Log var log = new AccessLog() { User = Login.Username, Action = "End", Item = "Rental", ItemId = selectedRental.Id.ToString() }; log.Insert(); log = new AccessLog() { User = "******", Action = "Delete from database", Item = "Rental", ItemId = selectedRental.Id.ToString() }; log.Insert(); var transactionItem = Transaction.Where(String.Format("rental_id = {0}", selectedRental.Id), 0, 1); transactionItem[0].ReturnDate = DateTime.Now.Date; transactionItem[0].OverdueTime = _overdueDays; transactionItem[0].Fine = numericUpDown8.Value; transactionItem[0].Save(); log = new AccessLog() { User = "******", Action = "Update", Item = "Transaction", ItemId = transactionItem[0].Id.ToString(), Description = "Return Date: " + transactionItem[0].ReturnDate.ToString("dd-MM-yyyy") + "; Overdue Time: " + _overdueDays + " day; Fine: " + numericUpDown8.Value }; log.Insert(); //Insert transaction return status RentalStatus transReturnStatus = new RentalStatus(); if (_keyLostFineAdded) { transReturnStatus.TransactionId = transactionItem[0].Id; transReturnStatus.StatusId = 3; transReturnStatus.Insert(); log = new AccessLog() { User = "******", Action = "Add", Item = "Rental Status", ItemId = transReturnStatus.TransactionId + ", " + transReturnStatus.StatusId, Description = "Return Status: Key Lost" }; log.Insert(); } if (_lockerDamagedFineAdded) { transReturnStatus.TransactionId = transactionItem[0].Id; transReturnStatus.StatusId = 4; transReturnStatus.Insert(); log = new AccessLog() { User = "******", Action = "Add", Item = "Rental Status", ItemId = transReturnStatus.TransactionId + ", " + transReturnStatus.StatusId, Description = "Return Status: Locker Damaged" }; log.Insert(); } if (checkBox1.Checked) { transReturnStatus.TransactionId = transactionItem[0].Id; transReturnStatus.StatusId = 2; transReturnStatus.Insert(); log = new AccessLog() { User = "******", Action = "Add", Item = "Rental Status", ItemId = transReturnStatus.TransactionId + ", " + transReturnStatus.StatusId, Description = "Return Status: Overdue" }; log.Insert(); } //Release the occupied / overdue locker string lockerStatus = ""; var locker = new Locker(); locker = locker.Get(selectedRental.LockerID); if (locker.IsOverdued()) { lockerStatus = "Overdue"; } else { lockerStatus = "Occupied"; } if (!_keyLostFineAdded && !_lockerDamagedFineAdded) { locker.Reset(); log = new AccessLog() { User = "******", Action = "Update", Item = "Locker", ItemId = locker.Id.ToString(), Description = "Code: " + locker.Code + "; Status: " + lockerStatus + " to Available" }; log.Insert(); //Check is the cabinet full, if yes, set to available var cabinet = new Cabinet(); cabinet = cabinet.Get(locker.CabinetID); if (cabinet.IsFull()) { cabinet.Restore(); log = new AccessLog() { User = "******", Action = "Update", Item = "Cabinet", ItemId = cabinet.Id.ToString(), Description = "Code: " + cabinet.Code + "; Status: Full to Available" }; log.Insert(); } } else { locker.NotAvailable(); string reason = ""; if (_keyLostFineAdded && !_lockerDamagedFineAdded) { reason += "Key Lost"; } else if (!_keyLostFineAdded && _lockerDamagedFineAdded) { reason += "Locker Damaged"; } else { reason += "Key Lost & Locker Damaged"; } log = new AccessLog() { User = "******", Action = "Disable", Item = "Locker", ItemId = locker.Id.ToString(), Description = "Code: " + locker.Code + "; Status: " + lockerStatus + " to Not Available; Reason: " + reason }; log.Insert(); } //Delete the rental selectedRental.Delete(); }
private void Button6_Click(object sender, EventArgs e) //Confirm Payment button { if (numericUpDown4.Value < numericUpDown3.Value) { MessageBox.Show("Input Error: Insufficient Payment." + Environment.NewLine + "Payment amount must be equal or higher than total price.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } numericUpDown5.Value = numericUpDown4.Value - numericUpDown3.Value; button5.Hide(); button6.Hide(); button7.Show(); var rental = new Rental { StartDate = dateTimePicker1.Value, Duration = Convert.ToInt32(numericUpDown2.Value), CustomerID = _customerList[0].Id, LockerID = _lockerList[0].Id, }; rental.Save(); //Insert access_log for rental var log = new AccessLog { User = Login.Username, Action = "Add", Item = "Rental", ItemId = textBox9.Text }; log.Insert(); _insertComplete = true; //Set the locker is occupied, and insert into accesslog _lockerList[0].Occupied(); log.User = "******"; log.Action = "Update"; log.Item = "Locker"; log.ItemId = rental.LockerID.ToString(); log.Description = "Code: " + _lockerList[0].Code + "; Status: Available to Occupied"; log.Insert(); //Check if the cabinet full. If yes, set cabinet to full, and insert into access log. var locker = new Locker(); int emptyLockerNo = locker.Count(String.Format("cabinet_id = {0} AND status = 'Available'", _cabinetList[0].Id)); if (emptyLockerNo <= 0) { _cabinetList[0].Full(); log.User = "******"; log.Action = "Update"; log.Item = "Cabinet"; log.ItemId = _cabinetList[0].Id.ToString(); log.Description = "Code: " + _cabinetList[0].Code + "; Status: Available to Full"; log.Insert(); } //Insert rental details into Transaction var transaction = new Transaction { RentalID = Convert.ToInt32(textBox3.Text), CustomerID = rental.CustomerID, LockerID = rental.LockerID, TypeName = _typeList[0].Name, TypeRate = _typeList[0].Rate, StartDate = rental.StartDate, Duration = rental.Duration, }; transaction.Save(); log = new AccessLog { User = "******", Action = "Add", Item = "Transaction", ItemId = textBox9.Text }; log.Insert(); }
private void Button11_Click(object sender, EventArgs e) //Export button in MDU { string defaultFileName = String.Format("EXPORT_DAYS_REPORT_{0}", dateTimePicker1.Value.ToString("MMM_yyyy")); SaveFileDialog sf = new SaveFileDialog { FileName = defaultFileName, Filter = "Portable Document File (.pdf) |*.pdf|Excel Workbook (.xlsx) |*.xlsx", Title = "Export Report as", FilterIndex = 1 }; if (sf.ShowDialog() == DialogResult.OK) { string savePath = Path.GetDirectoryName(sf.FileName); string fileName = Path.GetFileName(sf.FileName); string saveFile = Path.Combine(savePath, fileName); string imagePath = Path.Combine(savePath, "Chart3.png"); chart3.SaveImage(imagePath, ChartImageFormat.Png); var exportTable = new DataTable(); exportTable = ListViewToTable(exportTable, listView3); switch (sf.FilterIndex) { case 1: { try { Document pdfDocument = new Document(); PdfWriter.GetInstance(pdfDocument, new FileStream(saveFile, FileMode.Create)); pdfDocument.Open(); pdfDocument.AddTitle(label3.Text); Paragraph p = new Paragraph(label3.Text, FontFactory.GetFont("Verdana", 20, 1)); p.Alignment = Element.ALIGN_CENTER; p.SpacingAfter = 30; pdfDocument.Add(p); PdfPTable t = new PdfPTable(3); foreach (ColumnHeader lvch in listView3.Columns) { t.DefaultCell.BackgroundColor = new BaseColor(211, 211, 211); //Set Header Row Colour t.AddCell(lvch.Text); } int rowCount = 0; int maxRow = listView3.Items.Count; foreach (ListViewItem lvi in listView3.Items) { for (int i = 0; i < lvi.SubItems.Count; i++) { t.DefaultCell.BackgroundColor = new BaseColor(255, 255, 255); if (rowCount == maxRow - 1) { t.DefaultCell.BackgroundColor = new BaseColor(230, 230, 230); } t.AddCell(lvi.SubItems[i].Text); } rowCount++; } t.SpacingAfter = 30; pdfDocument.Add(t); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(imagePath); img.Alignment = Element.ALIGN_CENTER; pdfDocument.Add(img); pdfDocument.Close(); } catch (Exception exception) { MessageBox.Show(exception.Message); return; } break; } case 2: { try { var workbook = new XLWorkbook(); var ws = workbook.AddWorksheet("Report"); ws.Cell(1, 1).Value = label3.Text; ws.Cell(2, 1).InsertTable(exportTable); ws.AddPicture(imagePath) .MoveTo(ws.Cell(ws.LastRowUsed().RowNumber() + 2, 1)) .Scale(1.0); workbook.SaveAs(saveFile); } catch (Exception exception) { MessageBox.Show(exception.Message); return; } break; } } string escapedSaveFile = saveFile.Replace(@"\", @"\\"); var log = new AccessLog() { User = Login.Username, Action = "Export", Item = "Sales Report", Description = "Total Usage Days Report for " + dateTimePicker1.Value.ToString("MMM yyyy") + "; Path: " + escapedSaveFile }; log.Insert(); MessageBox.Show("Export file saved sucessfully.", "Export File Saved", MessageBoxButtons.OK); File.Delete(imagePath); } }
private void Button2_Click(object sender, EventArgs e) //Save button { decimal maxOverdueDays; decimal overdueFine; decimal keyLostFine; decimal lockerDamagedFine; maxOverdueDays = numericUpDown1.Value; overdueFine = numericUpDown2.Value; keyLostFine = numericUpDown3.Value; lockerDamagedFine = numericUpDown4.Value; if (!_insertComplete) { var rSetting = new RentalSettings(); rSetting.Name = "Max Overdue Days"; rSetting.SettingValue = maxOverdueDays; rSetting.Save(); rSetting = new RentalSettings(); rSetting.Name = "Overdue Fine"; rSetting.SettingValue = overdueFine; rSetting.Save(); rSetting = new RentalSettings(); rSetting.Name = "Key Lost Fine"; rSetting.SettingValue = keyLostFine; rSetting.Save(); rSetting = new RentalSettings(); rSetting.Name = "Locker Damage Fine"; rSetting.SettingValue = lockerDamagedFine; rSetting.Save(); _insertComplete = true; var log = new AccessLog() { User = Login.Username, Action = "Add", Item = "Rental Settings" }; log.Insert(); this.Close(); } else { int noOfChangedAttr = 0; string updatedAttr = ""; if (_rentalSettingsList[0].SettingValue != maxOverdueDays) { if (noOfChangedAttr == 0) { updatedAttr += "Max Overdue Days: " + Convert.ToInt32(_rentalSettingsList[0].SettingValue).ToString() + " day to " + Convert.ToInt32(maxOverdueDays).ToString() + " day"; } else { updatedAttr += "; Max Overdue Days: " + Convert.ToInt32(_rentalSettingsList[0].SettingValue).ToString() + " day to " + Convert.ToInt32(maxOverdueDays).ToString() + " day"; } _rentalSettingsList[0].SettingValue = maxOverdueDays; _rentalSettingsList[0].Save(); noOfChangedAttr++; } if (_rentalSettingsList[1].SettingValue != overdueFine) { if (noOfChangedAttr == 0) { updatedAttr += "Overdue Fine: " + _rentalSettingsList[1].SettingValue + " to " + overdueFine; } else { updatedAttr += "; Overdue Fine: " + _rentalSettingsList[1].SettingValue + " to " + overdueFine; } _rentalSettingsList[1].SettingValue = overdueFine; _rentalSettingsList[1].Save(); noOfChangedAttr++; } if (_rentalSettingsList[2].SettingValue != keyLostFine) { if (noOfChangedAttr == 0) { updatedAttr += "Key Lost Fine: " + _rentalSettingsList[2].SettingValue + " to " + keyLostFine; } else { updatedAttr += "; Key Lost Fine: " + _rentalSettingsList[2].SettingValue + " to " + keyLostFine; } _rentalSettingsList[2].SettingValue = keyLostFine; _rentalSettingsList[2].Save(); noOfChangedAttr++; } if (_rentalSettingsList[3].SettingValue != lockerDamagedFine) { if (noOfChangedAttr == 0) { updatedAttr += "Locker Damage Fine: " + _rentalSettingsList[3].SettingValue + " to " + lockerDamagedFine; } else { updatedAttr += "; Locker Damage Fine: " + _rentalSettingsList[3].SettingValue + " to " + lockerDamagedFine; } _rentalSettingsList[3].SettingValue = lockerDamagedFine; _rentalSettingsList[3].Save(); noOfChangedAttr++; } var log = new AccessLog() { User = Login.Username, Action = "Update", Item = "Rental Settings", Description = updatedAttr }; log.Insert(); button1.Hide(); button2.Hide(); button3.Show(); button4.Show(); LoadSettingsValue(); LockInput(); } }
private void Button4_Click(object sender, EventArgs e) //Export button { if (DateTime.Compare(dateTimePicker3.Value.Date, dateTimePicker4.Value.Date) > 0) { MessageBox.Show("Input Error: Invalid Date Range" + Environment.NewLine + "Please ensure date in 'From: ' is not later than the date in 'Until: '.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (dateTimePicker3.Value.Date == DateTime.Now || dateTimePicker4.Value.Date == DateTime.Now.Date) { MessageBox.Show("Export Error: Date Today Detected.\n" + "You cannot export access logs for today (" + DateTime.Now.Date.ToString("dd MMMM yyyy") + ").", "Export Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string startDate = dateTimePicker3.Value.ToString("dd-MM-yyyy"); string endDate = dateTimePicker4.Value.ToString("dd-MM-yyyy"); var result = MessageBox.Show("Do you want to export access log from " + startDate + " until " + endDate + "?\n\n" + "Note: Exported access log will be deleted from the database.", "Export Access Log", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { string defaultFileName = String.Format("EXPORT_ACCESS_LOG_{0}_{1}", String.Format("{0}~{1}", startDate, endDate), DateTime.Now.ToString("ddMMyyyy_HHmmss")); string dbStartDate = dateTimePicker3.Value.ToString("yyyy-MM-dd"); string dbEndDate = dateTimePicker4.Value.ToString("yyyy-MM-dd"); string dateCond = String.Format("DATE(log_date) BETWEEN '{0}' AND '{1}'", dbStartDate, dbEndDate); List <AccessLog> logList = AccessLog.Where(dateCond, 0, 2147483647); var workbook = new XLWorkbook(); var ws = workbook.AddWorksheet("AccessLog"); ws.Cell(1, 1).Value = "Access Log"; ws.Cell(2, 1).InsertTable(logList); SaveFileDialog sf = new SaveFileDialog { FileName = defaultFileName, Filter = "Excel Workbook (.xlsx) |*.xlsx", Title = "Export Access Log as", FilterIndex = 1 }; if (sf.ShowDialog() == DialogResult.OK) { string savePath = Path.GetDirectoryName(sf.FileName); string fileName = Path.GetFileName(sf.FileName); string saveFile = Path.Combine(savePath, fileName); try { workbook.SaveAs(saveFile); //Save the file string escapedSaveFile = saveFile.Replace(@"\", @"\\"); var log = new AccessLog() { User = Login.Username, Action = "Export", Item = "Access Log", Description = "Log Date: " + startDate + "~" + endDate + "; Path: " + escapedSaveFile }; log.Insert(); foreach (var item in logList) { log = new AccessLog() { User = "******", Action = "Delete from database", Item = "Access Log", Description = "Exported in " + fileName }; log.Insert(); item.Delete(); } } catch (Exception exception) { MessageBox.Show(exception.Message); return; } _exportComplete = true; this.Close(); } } }
private void Button2_Click(object sender, EventArgs e) //Save button { if (string.IsNullOrWhiteSpace(textBox2.Text)) { MessageBox.Show("Input Error: Empty Field(s) Detected!" + Environment.NewLine + "Please ensure that all fields are filled. ", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (_addNew) { if (!Database.CheckUnique("locker_type", "code", textBox3.Text)) { MessageBox.Show("Input Error: Duplicate attribute detected!" + Environment.NewLine + "Code '" + textBox3.Text + "' already exists in locker_type table.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var item = new Type { Name = textBox2.Text, Code = textBox3.Text, Rate = numericUpDown1.Value }; item.Save(); var log = new AccessLog { User = Login.Username, Action = "Add", Item = "Locker Type", ItemId = textBox1.Text, Description = "Code: " + textBox3.Text }; log.Insert(); _insertComplete = true; } else { var oldType = new Type(); oldType = oldType.Get(Convert.ToInt32(textBox1.Text)); var item = new Type { Id = Convert.ToInt32(textBox1.Text), Name = textBox2.Text, Code = textBox3.Text, Rate = numericUpDown1.Value }; item.Save(); string updatedAttr = ""; if (oldType.Name != item.Name) { updatedAttr += "; Name: " + oldType.Name + " to " + item.Name; } if (oldType.Rate != item.Rate) { updatedAttr += "; Rate: " + oldType.Rate + " to " + item.Rate; } var log = new AccessLog { User = Login.Username, Action = "Update", Item = "Locker Type", ItemId = textBox1.Text, Description = "Code: " + item.Code + updatedAttr }; log.Insert(); } this.Close(); } }