private void LoadRentalData(Rental item, bool rentalEnd) { rentalSettingsList = RentalSettings.All(0, 10); selectedRental = item; //Rental textBox31.Text = item.Id.ToString(); textBox32.Text = item.StartDate.ToString("dd-MM-yyyy"); var endDate = item.StartDate.AddDays(item.Duration); textBox33.Text = endDate.ToString("dd-MM-yyyy"); textBox34.Text = item.Duration.ToString(); //Customer var customer = new Customer(); customer = customer.Get(item.CustomerID); textBox35.Text = customer.Id.ToString(); textBox36.Text = customer.Name; textBox37.Text = customer.Ic; //Locker var locker = new Locker(); var cabinet = new Cabinet(); var type = new Type(); locker = locker.Get(item.LockerID); cabinet = cabinet.Get(locker.CabinetID); type = type.Get(cabinet.TypeID); textBox38.Text = locker.Id.ToString(); textBox39.Text = locker.Code; textBox40.Text = cabinet.Code; textBox41.Text = type.Name; //Additional Payment TimeSpan timeSpan = endDate.Date.Subtract(DateTime.Now.Date); int daysLeft = Convert.ToInt32(timeSpan.Days); if (daysLeft >= 0) { _overdueDays = 0; } else { _overdueDays = -daysLeft; _totalFine = _totalFine + rentalSettingsList[1].SettingValue + (type.Rate * _overdueDays); numericUpDown8.Value = _totalFine; checkBox1.Checked = true; //Assign Overdue Check Box as Ticked } textBox43.Text = _overdueDays.ToString(); }
public RentalSettings Get(int id) { RentalSettings item = null; string query = String.Format("SELECT * FROM {0} WHERE id = {1}", TableName, id); MySqlCommand cmd = new MySqlCommand(query, Database.Connection); MySqlDataReader dataReader = cmd.ExecuteReader(); if (dataReader.Read()) { item = new RentalSettings(dataReader); } dataReader.Close(); return(item); }
public RentalSettingsForm(bool setting_done) { InitializeComponent(); _insertComplete = setting_done; if (!_insertComplete) { button3.Hide(); button4.Hide(); } else { button1.Hide(); button2.Hide(); _rentalSettingsList = RentalSettings.All(0, 10); LoadSettingsValue(); LockInput(); } }
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(); } }