protected void OnPropertyChanged(string prop) { if (prop == "Id") { HoursWeekly = Fun.GetCleanerHours(Id, DateTime.Now); } if (PropertyChanged != null) { try { using (var db = new PodaciContext()) { db.Update(this); db.SaveChanges(); } } catch (Exception ex) { MessageBox.Show("Cleaner Update Error: " + ex.Message); } PropertyChanged(this, new PropertyChangedEventArgs(prop)); } }
public static int spremi_preko(ShipmentItem d) { try { using (var db = new PodaciContext()) { ShipmentItem temp = db.ShipmentItems.Include("Shipment").FirstOrDefault(x => x.Barcode == d.Barcode); if (temp != null) { d.Id = temp.Id; d.ShipmentId = temp.ShipmentId; d.Shipment.Id = temp.Shipment.Id; db.Set <ShipmentItem>().AddOrUpdate(d); db.Set <Shipment>().AddOrUpdate(d.Shipment); //db.Entry(d).State = EntityState.Modified; spremi_dodatno(db); return(1); } } return(-1); } catch (Exception ee) { return(-1); } }
protected override void OnClosing(CancelEventArgs e) { Fun.overWorked(model.CleaningJobs); foreach (var cj in model.CleaningJobs) { if (repeatJobs.ContainsKey(cj.Id) && cj.RepeatJobId != null) { if (cj.changed) { OnlyThisShiftDlg dlg = new OnlyThisShiftDlg(); if (dlg.ShowDialog() == true) { cj.RepeatJob = null; cj.RepeatJobId = null; using (var db = new PodaciContext()) { db.Update(cj); db.SaveChanges(); } } else { Fun.setRepeatingJobs(repeatJobs[cj.Id], cj); } } } } }
public ExtraServicesWin(int CleaningJobId) { InitializeComponent(); using (var db = new PodaciContext()) { var cj = db.CleaningJobs.Include(x => x.ServiceJobs).FirstOrDefault(x => x.Id == CleaningJobId); if (cj != null) { model.CleaningJob = cj; } var serviceJobs = cj.ServiceJobs?.ToList(); if (serviceJobs != null && serviceJobs.Count > 0) { model.Service1Id = serviceJobs[0].ServiceId; } if (serviceJobs != null && serviceJobs.Count > 1) { model.Service2Id = serviceJobs[1].ServiceId; } if (serviceJobs != null && serviceJobs.Count > 2) { model.Service3Id = serviceJobs[2].ServiceId; } if (serviceJobs != null && serviceJobs.Count > 3) { model.Service4Id = serviceJobs[3].ServiceId; } } this.DataContext = model; }
private void setLocations(int _id) { try { if (Client != null) { Locations = new Dictionary <int, string> { { 0, Client.Address }, { 1, Client.Address2 }, { 2, Client.Address3 }, { 3, Client.Address4 } } } ; else if (_id != 0) { using (var db = new PodaciContext()) { if (db.Clients.Any()) { var c = db.Clients.FirstOrDefault(x => x.Id == _id); Locations = new Dictionary <int, string> { { 0, c.Address }, { 1, c.Address2 }, { 2, c.Address3 }, { 3, c.Address4 } }; } } } } catch (Exception ex) { MessageBox.Show("setLocations Error: " + ex.Message); } }
public static double GetCleanerHours(int CleanerId, DateTime date) { double HoursWeekly = 0; using (var db = new PodaciContext()) { var year = date.Year; var week = getWeek(date); var jobs = db.CleaningJobs .Include(x => x.Team) .ThenInclude(y => y.CleanerTeams) .Where(x => (x.CleanerId == CleanerId || x.Team.CleanerTeams.Any(y => y.CleanerId == CleanerId)) && x.Week == week && x.Date.Year == year).ToList(); var hours = jobs?.Select(x => x.NoOfHours); if (hours != null && hours.Count() > 0) { foreach (var hour in jobs.Select(x => x.NoOfHours)) { HoursWeekly += hour; } } } return(HoursWeekly); }
public static void otvori(string reception_number, ShipmentItem d, List <bool> povrat) { try { using (var db = new PodaciContext()) { ShipmentItem temp = db.ShipmentItems.Include("Shipment").FirstOrDefault(x => x.Barcode == reception_number); if (temp != null) // ovo dole se radi jer funkcija CRUD.otvori briše referencu na ShipmentItem(d) { var props = temp.GetType().GetProperties(); foreach (var prop in props) { string s = prop.PropertyType.Name; if (prop.PropertyType.Name != "ObservableCollection`1") { prop.SetValue(d, prop.GetValue(temp, null)); } } povrat.Add(true); } } } catch { MessageBox.Show("Greška kod otvaranja"); } }
public MainWindow() { System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); InitializeComponent(); this.Title = "Cleaning Records ver. " + fvi.FileVersion; mainGrid.IsEnabled = false; using (var db = new PodaciContext()) { var rjobs = db.RepeatJobs.Include(x => x.CleaningJobs); foreach (var rjob in rjobs) { var date = DateTime.Now.Date; var cj = rjob.CleaningJobs.FirstOrDefault(x => x.Date.Date == date); if (cj != null) { Fun.setRepeatingJobs(rjob.Id, cj); } } } mainGrid.IsEnabled = true; CalendarUserControl x2 = new CalendarUserControl(); x2.Visibility = Visibility.Collapsed; DisplayGrid.Children.Add(x2); }
private void getCleaningJobs(PodaciContext db) { var cj = db.CleaningJobs .Include(x => x.RepeatJob) .Include(x => x.Team) .ThenInclude(y => y.CleanerTeams) .Where(x => x.ClientId == ClientObject.Id && x.Date.Year == ClientObject.Year && x.Date.Month == ClientObject.Month && ((ClientObject.Cleaner != null && ClientObject.Cleaner != 0) ? ClientObject.Cleaner == x.CleanerId || x.Team.CleanerTeams.Any(y => y.CleanerId == ClientObject.Cleaner) : true) && ((ClientObject.Status != null && ClientObject.Status != -1) ? ClientObject.Status == x.JobStatus : true) && ((ClientObject.Service != null && ClientObject.Service != 0) ? ClientObject.Service == x.ServiceId : true)); repeatJobs.Clear(); foreach (var c in cj) { c.Team = null; if (c.RepeatJobId != null) { repeatJobs.Add(c.Id, (int)c.RepeatJobId); } } ClientObject.CleaningJobs = new ObservableCollection <CleaningJob>(cj); dataGrid.ItemsSource = ClientObject.CleaningJobs; }
public CalendarEditWin(int?CleaningJobId = null, DateTime?date = null) { InitializeComponent(); if (CleaningJobId != null) { using (var db = new PodaciContext()) { model.CleaningJobs = new ObservableCollection <CleaningJob>( db.CleaningJobs .Include(x => x.RepeatJob) .Where(x => x.Id == CleaningJobId) ); dataGrid.ItemsSource = model.CleaningJobs; Date = model.CleaningJobs.FirstOrDefault()?.Date; } } else if (date != null) { Date = date; using (var db = new PodaciContext()) { model.CleaningJobs = new ObservableCollection <CleaningJob>(db.CleaningJobs.Include(x => x.RepeatJob).Where(x => x.Date.Date == date.Value.Date)); dataGrid.ItemsSource = model.CleaningJobs; } } foreach (var cj in model.CleaningJobs) { if (cj.RepeatJobId != null) { repeatJobs.Add(cj.Id, (int)cj.RepeatJobId); } } }
private void Add_Click(object sender, RoutedEventArgs e) { using (var db = new PodaciContext()) { var service = db.Add(new Service()).Entity; db.SaveChanges(); model.Services.Add(service); } }
private void Print_Click(object sender, RoutedEventArgs e) { var month = calendars[TabsMain.SelectedIndex].DisplayStartDate.Month; var year = calendars[TabsMain.SelectedIndex].DisplayStartDate.Year; var pdf = new GeneratePDF(); using (var db = new PodaciContext()) pdf.Create(month, year, models[TabsMain.SelectedIndex].CleanerId, db); }
private void Add_Click(object sender, RoutedEventArgs e) { using (var db = new PodaciContext()) { var client = db.Add(new Client()).Entity; db.SaveChanges(); Clients.Clients.Add(client); } }
public CleanerUserControl() { InitializeComponent(); using (var db = new PodaciContext()) { Cleaners.Cleaners = new ObservableCollection <Cleaner>(db.Cleaners); dataGrid.ItemsSource = Cleaners.Cleaners; } }
public ServicesUserControl() { InitializeComponent(); using (var db = new PodaciContext()) { model.Services = new ObservableCollection <Service>(db.Services); dataGrid.ItemsSource = model.Services; } }
public ClientsList() { using (var db = new PodaciContext()) { var Clients = db.Clients; foreach (var client in Clients) { this.Add(client.Id, client.Name + " " + client.Surname); } } }
private void Add_Click(object sender, RoutedEventArgs e) { using (var db = new PodaciContext()) { var clean = db.Add(new CleaningJob { ClientId = 1, Date = Date ?? DateTime.Now }).Entity; db.SaveChanges(); model.CleaningJobs.Add(clean); } }
private void Add_Click(object sender, RoutedEventArgs e) { using (var db = new PodaciContext()) { var team = db.Add(new Team()).Entity; team.CleanerTeams = new ObservableCollection <CleanerTeam>(); db.SaveChanges(); Teams.Teams.Add(new TeamsHelper { Team = team }); } }
private void copyDB(PodaciContext db) { using (var db2 = new CleaningRecords.DAL.Models.OldModels.PodaciContext()) { var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new DAL.Mappings.MappingProfile()); }); IMapper m = mappingConfig.CreateMapper(); if (db2.Cleaners.Any() && !db.Cleaners.Any()) { var Cleaners = m.Map <List <CleaningRecords.DAL.Models.Cleaner> >(db2.Cleaners); db.AddRange(Cleaners); } if (db2.Clients.Any() && !db.Clients.Any()) { var Clients = m.Map <List <CleaningRecords.DAL.Models.Client> >(db2.Clients); db.AddRange(Clients); } if (db2.Teams.Any() && !db.Teams.Any()) { var Teams = m.Map <List <CleaningRecords.DAL.Models.Team> >(db2.Teams.Include(x => x.CleanerTeams)); db.AddRange(Teams); } if (db2.Services.Any() && !db.Services.Any()) { var Services = m.Map <List <CleaningRecords.DAL.Models.Service> >(db2.Services); db.AddRange(Services); } if (db2.RepeatJobs.Any() && !db.RepeatJobs.Any()) { var RepeatJobs = m.Map <List <CleaningRecords.DAL.Models.RepeatJob> >(db2.RepeatJobs); db.AddRange(RepeatJobs); } if (db2.CleaningJobs.Any() && !db.CleaningJobs.Any()) { var CleaningJobs = m.Map <List <CleaningRecords.DAL.Models.CleaningJob> >(db2.CleaningJobs); db.AddRange(CleaningJobs); } db.SaveChanges(); } }
public CleanerEditWin(int _cleanerId) { InitializeComponent(); using (var db = new PodaciContext()) { Cleaner = db.Cleaners .FirstOrDefault(x => x.Id == _cleanerId); this.DataContext = Cleaner; } }
private void Window_Loaded(object sender, RoutedEventArgs e) { comboBox1.Focus(); using (var db = new PodaciContext()) { var query = from b in db.ShipmentItems select b.Barcode; svi_projekti = new List <string>(query); } comboBox1.ItemsSource = svi_projekti; }
private void OK_Click(object sender, RoutedEventArgs e) { if (model.RepeatFrequency != 0 && !model.days.Contains(true)) { MessageBox.Show("Repeating day has to be selected!"); return; } using (var db = new PodaciContext()) { if (model.RepeatFrequency == 0) { if (model.Id != 0) { model.AllDays = 0; db.Update(model); db.SaveChanges(); } } else { model.daysToAllDays(); if (cleaningJob.RepeatJobId == null) { var RepeatJob = db.Add(model); db.SaveChanges(); cleaningJob.RepeatJobId = RepeatJob?.Entity?.Id; db.Update(cleaningJob); db.SaveChanges(); } else { db.Update(model); db.SaveChanges(); } } //if (model.days[startDay] == false && cleanJob.Repeating != 0) //{ // var jobs = db.CleaningJobs.Where(x => x.Id != cleanJob.Id && x.ClientId == cleanJob.ClientId && x.Date >= cleanJob.Date && x.Repeating == cleanJob.Repeating); // foreach (var job in jobs) // db.CleaningJobs.Remove(job); //} } Fun.setRepeatingJobs(cleaningJob.RepeatJobId ?? model.Id, cleaningJob); Ok = true; Close(); }
public CleanersList() { using (var db = new PodaciContext()) { this.Add(0, null); var Cleaners = db.Cleaners; if (Cleaners != null && Cleaners.Any()) { foreach (var cleaner in Cleaners) { this.Add(cleaner.Id, cleaner.Name + " " + cleaner.Surname); } } } }
public ServicesListWithAll() { using (var db = new PodaciContext()) { this.Add(0, "All services"); var Services = db.Services; if (Services != null && Services.Any()) { foreach (var service in Services) { this.Add(service.Id, service.Name); } } } }
public ClientEditWin(int ClientId) { InitializeComponent(); using (var db = new PodaciContext()) { ClientObject = db.Clients .FirstOrDefault(x => x.Id == ClientId); getCleaningJobs(db); ClientObject.setMonthsYears(); ClientObject.setLocations(); this.DataContext = ClientObject; } }
public TeamsList() { using (var db = new PodaciContext()) { this.Add(0, null); var Teams = db.Teams; if (Teams != null && Teams.Any()) { foreach (var team in Teams) { this.Add(team.Id, team.Name); } } } }
public void Create(int month, int year, int?_CleanerId, PodaciContext _db) { if (_CleanerId == null || _CleanerId == 0) { MessageBox.Show("Cleaner not selected!"); return; } CleanerId = (int)_CleanerId; db = _db; var cleaner = db.Cleaners.FirstOrDefault(x => x.Id == CleanerId); if (cleaner == null) { return; } // Create a temporary file Directory.CreateDirectory("PDFs"); string filename = String.Format($"{cleaner.Name}_{cleaner.Surname}_{month}_{year}_{Guid.NewGuid().ToString("D").ToUpper()}.pdf"); var s_document = new PdfDocument(); s_document.Info.Title = $"{cleaner.Name}_{cleaner.Surname} schedule"; s_document.Info.Author = "Sven Ivic"; s_document.Info.Subject = $"Calendar for {cleaner.Name}_{cleaner.Surname}"; s_document.Info.Keywords = $"{cleaner.Name}_{cleaner.Surname} Calendar"; // Create demonstration pages var page = s_document.AddPage(); page.Orientation = PdfSharp.PageOrientation.Landscape; XGraphics gfx = XGraphics.FromPdfPage(page); DrawLine(gfx, month, year); // Save the s_document... s_document.Save("PDFs\\" + filename); // ...and start a viewer //Process.Start(filename); try { System.Diagnostics.Process.Start(Environment.GetEnvironmentVariable("WINDIR") + @"\explorer.exe", Directory.GetCurrentDirectory() + "\\PDFs"); } catch (Exception ex) { } }
public TeamsWithAllList() { using (var db = new PodaciContext()) { this.Add(0, "All Teams"); this.Add(-1, "No Teams"); var Teams = db.Teams; if (Teams != null && Teams.Any()) { foreach (var team in Teams) { this.Add(team.Id, team.Name); } } } }
private static string OverworkHelper(int CleanerId, CleaningJob job) { var HoursWeekly = GetCleanerHours(CleanerId, job.Date); if (HoursWeekly >= 18) { using (var db = new PodaciContext()) { var cleaner = db.Cleaners.FirstOrDefault(x => x.Id == CleanerId); MessageBox.Show($"Warning! {cleaner?.Name} {cleaner?.Surname} has {HoursWeekly} hours a week (on week {job.Week})!", "Possible cleaner over worked!", MessageBoxButton.OK, MessageBoxImage.Warning); return(CleanerId + "," + job.Week); } } return(null); }
private void Add_Click(object sender, RoutedEventArgs e) { using (var db = new PodaciContext()) { var cleaner = db.Add(new Cleaner { Monday = true, Tuesday = true, Wednesday = true, Thursday = true, Friday = true, Saturday = true, Sunday = true, NotAvailableStart = DateTime.Now, NotAvailableEnd = DateTime.Now, NotAvailableStart2 = DateTime.Now, NotAvailableEnd2 = DateTime.Now, HolidayStart = DateTime.Now, HolidayEnd = DateTime.Now, HolidayStart2 = DateTime.Now, HolidayEnd2 = DateTime.Now }).Entity; db.SaveChanges(); Cleaners.Cleaners.Add(cleaner); } }