private void buttonRecordConfirm_Click(object sender, EventArgs e) { string category = comboRecordCategory.Text; int expireDays; int ammount; int points; try { expireDays = Convert.ToInt32(boxRecordExpire.Text); errorProvider.Clear(); } catch { errorProvider.SetError(boxRecordExpire, "Field must contains number"); return; } try { ammount = Convert.ToInt32(boxRecordAmmount.Text); errorProvider.Clear(); } catch { errorProvider.SetError(boxRecordAmmount, "Field must contains number"); return; } try { points = Convert.ToInt32(boxRecordPoints.Text); errorProvider.Clear(); } catch { errorProvider.SetError(boxRecordPoints, "Field must contains number"); return; } //vytvorit novy zaznam Record record = new Record(); record.Ammount = ammount; record.PointsTaken = points; record.DateOfEntry = DateTime.Now; record.ExpireDate = record.DateOfEntry.AddDays(expireDays); if (checkBoxPaid.Checked) { record.PaidDate = DateTime.Now; } else { record.PaidDate = null; } record.driverID = driverID; record.employeeID = manager.login; record.fineTypeID = (int)comboRecordCategory.SelectedValue; RecordDataMapper.Save(record); if (record.PointsTaken > 0) { //odebrat body ridici Driver driver = DriverDataMapper.FindByID(record.driverID); driver.SubtractPoints(record.PointsTaken); DriverDataMapper.Update(driver); if (driver.PointsLessThenZero()) { string message = "Body ridice <= 0. Odebrat RP"; MessageBox.Show(message, "Upozornění", MessageBoxButtons.OK); } } this.Owner.Refresh(); this.Close(); }
public IActionResult AutomatickeVytvoreni(string SPZ, int speed, bool isInCity) { Vehicle vehicle = VehicleDataMapper.FindBySPZ(SPZ); if (vehicle == null) { return(RedirectToAction("Index", "Home")); } Driver driver = DriverDataMapper.FindByID(vehicle.driverID); Record record = new Record(); record.Ammount = 0; record.DateOfEntry = DateTime.Now; record.PaidDate = null; record.ExpireDate = record.DateOfEntry.AddDays(30); record.driverID = driver.ID; record.PointsTaken = 0; record.employeeID = 1; record.fineTypeID = 6; if (speed < 10 && isInCity == true) { record.Ammount = 500; record.PointsTaken = 0; } else if (speed >= 10 && speed < 30 && isInCity == true) { record.Ammount = 2000; record.PointsTaken = 1; } else if (speed >= 30 && isInCity == true) { record.Ammount = 5000; record.PointsTaken = 3; } else if (speed < 10 && isInCity == false) { record.Ammount = 500; record.PointsTaken = 0; } else if (speed >= 10 && speed < 30 && isInCity == false) { record.Ammount = 2000; record.PointsTaken = 2; } else if (speed >= 30 && isInCity == false) { record.Ammount = 5000; record.PointsTaken = 4; } RecordDataMapper.Save(record); driver.RemainingPoints -= record.PointsTaken; if (driver.RemainingPoints <= 0) { driver.State = false; ViewBag.driverState = false; } DriverDataMapper.Update(driver); return(RedirectToAction("Login", "Home")); }