private void checkBox1_CheckedChanged(object sender, EventArgs e) { Guid id = SearcId(); if (id == MainForm.IdError) { return; } Vacation peoplday = EFVacations.FindById(c => c.Id == id); if (peoplday == null) { return; } peoplday.IndexDate = true; EFVacations.Update(peoplday); }
public ShowVacation(Guid Id) { InitializeComponent(); _Id = Id; if (EFVacations.Count(i => i.Peopleid == _Id) < 1) { MessageBox.Show("Don`t have weekend"); } else { BindingSource DatedbOne = new BindingSource(); var DatedbOneK = EFVacations.Get(i => i.Peopleid == _Id); personOfweekend = EFVacations.FindById(i => i.Peopleid == _Id); if (personOfweekend == null) { return; } checkBox1.Checked = personOfweekend.IndexDate; var qieryAsList = new BindingList <Vacation>(DatedbOneK.ToList()); DatedbOne.DataSource = qieryAsList; dataGridViewVacations.DataSource = DatedbOne; } this.dataGridViewVacations.RowPrePaint += new DataGridViewRowPrePaintEventHandler(this.PaintRows); }
private void btnDeleteDate(object sender, EventArgs e) { Guid id = SearcId(); if (id == Form1.IdError) { return; } Vacation peoplday = vacations.FindById(c => c.Id == id); Person people = workers.FindById(c => c.Id == peoplday.Peopleid); BindingSource DatedbOne = new BindingSource(); var DatedbOneK = vacations.Get(i => i.Peopleid == _Id); if (peoplday.IndexDate == true) { MessageBox.Show("it is used"); } else { // holydayn.SecontDate.Subtract(holydayn.FirstDate).Days int DaysRegain = peoplday.Days; people.Day = DaysRegain; workers.Update(people); //_db.Vacations.Remove(peoplday); vacations.Remove(peoplday); _db.SaveChanges(); DatedbOneK = vacations.Get(i => i.Peopleid == _Id); var qieryAsList = new BindingList <Vacation>(DatedbOneK.ToList()); DatedbOne.DataSource = qieryAsList; dataGridView1.DataSource = DatedbOne; dataGridView1.Update(); dataGridView1.Refresh(); } }
public void btnAddVacation(object sender, EventArgs e) { workers = new EFGenericRepository <Person>(new WorkerContext()); vacations = new EFGenericRepository <Vacation>(new WorkerContext()); Vacation holydayn = new Vacation(); Guid id = SearcId(); if (id == IdError) { return; } //db.Workers.AsNoTracking(); // db.Workers.Load(); Person person = workers.FindById(i => i.Id == id); if (person == null) { return; } // db.Entry(person).Reload(); // db.Entry(person).State = EntityState.Modified; // holydayn.People = db.Peoples.AsNoTracking().ToList().FirstOrDefault(i=>i.Id==id); holydayn.Peopleid = person.Id; AddHol addHolForm = new AddHol(person.Day - 1); DateTime date = new DateTime(person.Year, 1, 1); if (person.Day < 1) { MessageBox.Show("don`t have weekend!!!"); return; } addHolForm.dateTimePicker1.Value = date; int Daysu = person.Day; DialogResult result = addHolForm.ShowDialog(this); holydayn.Id = Guid.NewGuid(); holydayn.FirstDate = addHolForm.dateTimePicker1.Value; DateTime CountDate = addHolForm.dateTimePicker1.Value; holydayn.IndexDate = false; holydayn.SecontDate = addHolForm.dateTimePicker2.Value; if (result == DialogResult.Cancel) { return; } int IndexDay = Daysu; for (DateTime i = addHolForm.dateTimePicker1.Value; i <= addHolForm.dateTimePicker2.Value;) { if (i.DayOfWeek != DayOfWeek.Sunday && i.DayOfWeek != DayOfWeek.Saturday && !AuditDate(i)) { IndexDay--; } i = i.AddDays(1); } Daysu = IndexDay; holydayn.TeamName = person.TeamName; holydayn.Days = person.Day - IndexDay; person.Day = Daysu; if (CountTeam(person.TeamName) - CountWeekend(holydayn.FirstDate, holydayn.SecontDate, person.TeamName) <= 1) { MessageBox.Show("Date busy"); return; } vacations.Create(holydayn); workers.Update(person); // db.Vacations.Add(holydayn); addHolForm.Close(); //db.SaveChanges(); evenstb(); }
private void BtnOk(object sender, EventArgs e) { workers = new EFGenericRepository <Person>(new WorkerContext()); Guid id = Id; Person person = workers.FindById(i => i.Id == id); if (person == null) { return; } Vacation holydayn = new Vacation(); holydayn.Peopleid = person.Id; DateTime date = new DateTime(person.Year, 1, 1); if (person.Days < 1) { MessageBox.Show("don`t have weekend!!!"); return; } Team team = EFTeams.FindById(i => i.TeamName == person.Team.TeamName); if (team == null) { return; } int Daysu = person.Days; //DialogResult result = addHolForm.ShowDialog(this); holydayn.Id = Guid.NewGuid(); holydayn.FirstDate = dateTimePickerFirstDate.Value; DateTime CountDate = dateTimePickerFirstDate.Value; holydayn.IndexDate = false; holydayn.SecontDate = dateTimePickerSecondDate.Value; if ((CountTeam(person.Team.TeamName) - CountWeekend(holydayn.FirstDate, holydayn.SecontDate, person.Team.TeamName) <= team.MinNumberWorkers) && team.MinNumberWorkers != 0) { MessageBox.Show("Date busy"); return; } int CountDaysHolyDays = 0; int IndexDay = 0; for (DateTime i = dateTimePickerFirstDate.Value.Date; i <= dateTimePickerSecondDate.Value.Date;) { if (i.DayOfWeek == DayOfWeek.Sunday || i.DayOfWeek == DayOfWeek.Saturday || AuditDate(i)) { IndexDay++; CountDaysHolyDays--; } CountDaysHolyDays++; i = i.AddDays(1); } holydayn.TeamName = person.Team.TeamName; holydayn.Days = CountDaysHolyDays; Daysu = person.Days - CountDaysHolyDays; person.Days = Daysu; if (CountTeam(person.Team.TeamName) - CountWeekend(holydayn.FirstDate, holydayn.SecontDate, person.Team.TeamName) <= team.MinNumberWorkers && team.MinNumberWorkers != 0) { MessageBox.Show("Date busy"); return; } this.GetVacation = holydayn; this.PersonGet = person; workers.Update(person); }