private void buttonGpSave_Click(object sender, EventArgs e) { try { var gpMapper = new GpMapper(); var gp = gpMapper.SelectGp(_gpId); if (gp.Date.AddHours(1) > DateTime.Now) { labelError.Text = @"Výsledky nelze vložit, protože neuběhla nejméně 1 hodina od startu. "; return; } var classificationMapper = new ClassificationMapper(); foreach (DataGridViewRow row in dataGridView1.Rows) { if (ReferenceEquals(row.Cells["Position"].Value, "")) { continue; } var driver = (int)row.Cells["ID"].Value; var position = (int?)row.Cells["Position"].Value; var classification = classificationMapper.SelectGpDriver(_gpId, driver); if (position == null || position == 0) { continue; } if (classification == null) { classificationMapper.Insert(_gpId, driver, (int)position); } else { classificationMapper.Edit(_gpId, driver, (int)position); } } } catch (Exception exception) { Console.WriteLine(exception); throw; } Close(); }
public ActionResult Detail(int id) { var gpMapper = new GpMapper(); Gp gp = gpMapper.SelectGp(id); gp.State = States.FindForGp(gp); ViewBag.Name = gp.Name; gpMapper.GetPrevNextDriver(id, out int?prev, out int?next); ViewBag.Prev = prev; ViewBag.Next = next; ViewBag.IfGp = User.Identity.IsAuthenticated && ButtonEnable.GpEdit(gp.UserId, new UsersMapper().SelectUser(User.Identity.Name)); return(View(gp)); }
public bool OpenRecord(object primaryKey) { if (primaryKey == null) { return(false); } var idGp = (int)primaryKey; var gpMapper = new GpMapper(); var classificationMapper = new ClassificationMapper(); var gp = gpMapper.SelectGp(idGp); var drivers = new DriversMapper().SelectAll(); var bindingList = new BindingList <Drivers>(drivers); dataGridView1.AutoGenerateColumns = false; dataGridView1.Rows.Clear(); foreach (var driver in bindingList) { var rowIndex = dataGridView1.Rows.Add(); var row = dataGridView1.Rows[rowIndex]; row.Cells["Position"].Value = classificationMapper.SelectGpDriver(gp.Id, driver.Id); row.Cells["LastName"].Value = driver.LastName; row.Cells["FirstName"].Value = driver.FirstName; row.Cells["ID"].Value = driver.Id; } if (classificationMapper.SelectGpCount(gp.Id) == 0) { labelError.Text = @"Výsledky pro tuto GP ještě neexistují."; } else { labelError.Text = ""; } labelHeader.Text = @"Zobrazení výsledků GP - " + gp.Name; Text = labelHeader.Text; _gpId = idGp; gpMapper.GetPrevNextDriver(_gpId, out _prevId, out _nextId); buttonGpEdit.Visible = ButtonEnable.TeamsEdit(gp.UserId, new UsersMapper().SelectUser(Logged.CurrentUser.UserRole)); return(true); }
public ActionResult Classifications(int id) { var gpMapper = new GpMapper(); var gp = gpMapper.SelectGp(id); ViewBag.Name = gp.Name; gpMapper.GetPrevNextDriver(id, out int?prev, out int?next); ViewBag.Prev = prev; ViewBag.Next = next; ViewBag.Id = id; Dictionary <int, Classification> classifications = new ClassificationMapper().SelectAll(id); ViewBag.IfGp = User.Identity.IsAuthenticated && ButtonEnable.GpEdit(gp.UserId, new UsersMapper().SelectUser(User.Identity.Name)); return(View(classifications)); }
public ActionResult Edit(int id) { GpMapper gpMapper = new GpMapper(); Gp gp = gpMapper.SelectGp(id); if (!(User.IsInRole("Admin") || ButtonEnable.TeamsEdit(gp.UserId, new UsersMapper().SelectUser(User.Identity.Name)))) { return(RedirectToAction("Detail", "Drivers", new { id = id })); } gp.State = States.FindForGp(gp); ViewBag.tName = gp.Name; ViewBag.States = new StatesMapper().SelectAll(); ((Collection <States>)ViewBag.States).Insert(0, new States().EmptyState()); return(View(gp)); }
public bool OpenRecord(object primaryKey) { if (primaryKey == null) { return(false); } var idDriver = (int)primaryKey; var driverMapper = new GpMapper(); var gp = driverMapper.SelectGp(idDriver); labelNameEdit.Text = gp.Name; labelCircuitEdit.Text = gp.Circuit; if (gp.Date != null) { labelDateEdit.Text = ((DateTime)gp.Date).ToString("dd/MM/yyyy"); } if (gp.Lenght != null) { labelLenghtEdit.Text = gp.Lenght.ToString(); } if (gp.Laps != null) { labelLapsEdit.Text = gp.Laps.ToString(); } gp.State = States.FindForGp(gp); var state = new StatesMapper().SelectState(gp.State.Id); labelStateEdit.Text = state.Name; labelHeader.Text = @"Výpis GP - " + gp.Name; Text = labelHeader.Text; _gpId = gp.Id; driverMapper.GetPrevNextDriver(_gpId, out _prevId, out _nextId); buttonGpEdit.Visible = ButtonEnable.TeamsEdit(gp.UserId, new UsersMapper().SelectUser(Logged.CurrentUser.UserRole)); return(true); }
public ActionResult ClassificationsEdit(int id) { GpMapper gpMapper = new GpMapper(); Gp gp = gpMapper.SelectGp(id); if (!(User.IsInRole("Admin") || ButtonEnable.GpEdit(gp.UserId, new UsersMapper().SelectUser(User.Identity.Name)))) { return(RedirectToAction("Classifications", "Gp", new { id = id })); } gp.State = States.FindForGp(gp); ViewBag.Name = gp.Name; ViewBag.Id = id; ViewBag.Points = new PointsMapper().SelectAll(); ViewBag.Classifications = new ClassificationMapper().SelectAll(id); return(View(new DriversMapper().SelectAll())); }
public bool OpenRecord(object primaryKey) { try { if (primaryKey == null) { return(false); } _gpId = (int)primaryKey; var gpMapper = new GpMapper(); var classificationMapper = new ClassificationMapper(); var results = classificationMapper.SelectAll(_gpId); var gp = gpMapper.SelectGp(_gpId); var drivers = new DriversMapper().SelectAll(); var positions = new PointsMapper().SelectAll(); var bindingList = new BindingList <Drivers>(drivers); dataGridView1.AutoGenerateColumns = false; dataGridView1.Rows.Clear(); foreach (var driver in bindingList) { var rowIndex = dataGridView1.Rows.Add(); var row = dataGridView1.Rows[rowIndex]; row.Cells["Position"].ValueType = typeof(int); ((DataGridViewComboBoxCell)row.Cells["Position"]).Items.Insert(0, ""); foreach (var position in positions) { ((DataGridViewComboBoxCell)row.Cells["Position"]).Items.Insert(position.Position, position.Position); } try { if (results.ContainsKey(driver.Id)) { row.Cells["Position"].Value = results[driver.Id].Position; } } catch { // ignored } row.Cells["LastName"].Value = driver.LastName; row.Cells["FirstName"].Value = driver.FirstName; row.Cells["ID"].Value = driver.Id; } labelError.Text = ""; if (results.Count == 0) { labelError.Text += @"Výsledky pro tuto GP ještě neexistují. "; } if (gp.Date.AddHours(1) > DateTime.Now) { labelError.Text += @"Výsledky lze uložit nejdříve 1 hodinu po startu GP. "; } labelHeader.Text = @"Úprava výsledků GP - " + gp.Name; Text = labelHeader.Text; } catch (Exception e) { Console.WriteLine(e); throw; } return(true); }