예제 #1
0
        public void CarLeft(object carId)
        {
            using (var context = new AutoShopEntities())
            {
                if (carId != null)
                {
                    var car = context.Cars.FirstOrDefault(x => x.VIN == (string)carId);

                    if (car.Jobs.Any(job => job.Finished == false))
                    {
                        MessageBox.Show("Automobilis turi neuzbaigtu darbu");
                    }
                    else
                    {
                        car.Arrived = false;

                        foreach (Job job in car.Jobs)
                        {
                            job.Employees.Clear();
                        }

                        context.Jobs.RemoveRange(car.Jobs);
                        context.SaveChanges();
                    }
                }
            }
        }
예제 #2
0
        public void AddNewClient(bool isPerson, string s1, string s2, string address, string telephone)
        {
            var client = new Client
            {
                Adress    = address,
                Telephone = telephone
            };

            if (isPerson)
            {
                var person = new Person
                {
                    Id      = client.Id,
                    Name    = s1,
                    Surname = s2
                };
                client.Person = person;
            }
            else
            {
                var company = new Company
                {
                    Id   = client.Id,
                    Name = s1,
                    Code = s2
                };
                client.Company = company;
            }

            using (var context = new AutoShopEntities())
            {
                context.Clients.Add(client);
                context.SaveChanges();
            }
        }
예제 #3
0
        public void PopulateListBoxClients(bool selectedClientPerson, ListBox listBoxClients)
        {
            if (selectedClientPerson)
            {
                using (var context = new AutoShopEntities())
                {
                    var results = (from c in context.People
                                   select new { Id = c.Id, Row = c.Name + " " + c.Surname }).ToList();

                    listBoxClients.DataSource    = results;
                    listBoxClients.DisplayMember = "Row";
                    listBoxClients.ValueMember   = "Id";
                }
            }
            else
            {
                using (var context = new AutoShopEntities())
                {
                    var results = (from c in context.Companies
                                   select new { Id = c.Id, Row = c.Name + " " + c.Code }).ToList();

                    listBoxClients.DataSource    = results;
                    listBoxClients.DisplayMember = "Row";
                    listBoxClients.ValueMember   = "Id";
                }
            }
        }
예제 #4
0
        public void DeleteJob(object jobId)
        {
            using (var context = new AutoShopEntities())
            {
                if (jobId != null)
                {
                    var job = context.Jobs.FirstOrDefault(x => x.Id == (int)jobId);
                    job.Employees.Clear();
                    context.Jobs.Remove(job);
                    context.SaveChanges();
                }
            }

            /*
             * using (var context = new AutoShopEntities())
             *          {
             *                  if (jobId != null)
             *                  {
             *                          var job = context.Jobs.FirstOrDefault(x => x.Id == (int)jobId);
             *
             *                          context.Jobs.Remove(job);
             *                          context.SaveChanges();
             *                  }
             *          }
             */
        }
예제 #5
0
 public Company findCompany(int id)
 {
     using (var context = new AutoShopEntities())
     {
         Company result = context.Companies.FirstOrDefault(x => x.Id == id);
         return(result);
     }
 }
예제 #6
0
 public Person findPerson(int id)
 {
     using (var context = new AutoShopEntities())
     {
         Person result = context.People.FirstOrDefault(x => x.Id == id);
         return(result);
     }
 }
예제 #7
0
 public Client findClient(int id)
 {
     using (var context = new AutoShopEntities())
     {
         Client result = context.Clients.FirstOrDefault(x => x.Id == id);
         return(result);
     }
 }
예제 #8
0
 public void updateCompany(int id, String name, String code)
 {
     using (var context = new AutoShopEntities())
     {
         Company result = context.Companies.FirstOrDefault(x => x.Id == id);
         result.Name = name;
         result.Code = code;
         context.SaveChanges();
     }
 }
예제 #9
0
 public void updatePerson(int id, String name, String surname)
 {
     using (var context = new AutoShopEntities())
     {
         Person result = context.People.FirstOrDefault(x => x.Id == id);
         result.Name    = name;
         result.Surname = surname;
         context.SaveChanges();
     }
 }
예제 #10
0
 public void updateClient(int id, String address, String phone)
 {
     using (var context = new AutoShopEntities())
     {
         Client result = context.Clients.FirstOrDefault(x => x.Id == id);
         result.Adress    = address;
         result.Telephone = phone;
         context.SaveChanges();
     }
 }
예제 #11
0
 public List <dynamic> getClients(String str)
 {
     using (var context = new AutoShopEntities())
     {
         var result = (from cl in context.Clients
                       where cl.Person.Surname.Contains(str) || cl.Person.Name.Contains(str) || cl.Company.Name.Contains(str)
                       select new { Name = cl.Person.Name + " " + cl.Person.Surname + cl.Company.Name, Id = cl.Id }).ToList <dynamic>();
         return(result);
     }
 }
예제 #12
0
 public List <dynamic> getEmployees(String str)
 {
     using (var context = new AutoShopEntities())
     {
         var result = (from emp in context.Employees
                       where emp.Surname.Contains(str) || emp.Name.Contains(str)
                       select new { Name = emp.Name + " " + emp.Surname, Id = emp.Id }).ToList <dynamic>();
         return(result);
     }
 }
예제 #13
0
 public List <dynamic> getAllJobs(String str)
 {
     using (var context = new AutoShopEntities())
     {
         var result = (from job in context.Jobs
                       where job.Service.Name.Contains(str)
                       select new { Name = job.Service.Name + " Baigtas: " + job.Finished.ToString() + " " + job.Car.Make + " " + job.Car.Model, Id = job.Id }).ToList <dynamic>();
         return(result);
     }
 }
예제 #14
0
 public List <dynamic> getJobEmployees(int id)
 {
     using (var context = new AutoShopEntities())
     {
         var result = (from emp in context.Employees
                       where emp.Jobs.Any(x => x.Id == id)
                       select new { Name = emp.Name + " " + emp.Surname, Id = emp.Id }).ToList <dynamic>();
         return(result);
     }
 }
예제 #15
0
 public List <dynamic> getCars(String str)
 {
     using (var context = new AutoShopEntities())
     {
         var result = (from car in context.Cars
                       where car.Model.Contains(str) || car.Make.Contains(str) || car.VIN.Contains(str) || car.NumberPlate.Contains(str)
                       select new { Name = car.Model + " " + car.Make + " " + car.NumberPlate, Id = car.VIN }).ToList <dynamic>();
         return(result);
     }
 }
예제 #16
0
 public List <dynamic> getJobs(String vin)
 {
     using (var context = new AutoShopEntities())
     {
         var result = (from job in context.Jobs
                       where job.Car_VIN == vin
                       select new { Name = job.Service.Name + " Baigtas: " + job.Finished.ToString(), Id = job.Id }).ToList <dynamic>();
         return(result);
     }
 }
예제 #17
0
 public List <dynamic> getServices(String str)
 {
     using (var context = new AutoShopEntities())
     {
         var result = (from serv in context.Services
                       where serv.Name.Contains(str)
                       select new { Name = serv.Name + " Price: " + serv.Price, Id = serv.Id }).ToList <dynamic>();
         return(result);
     }
 }
예제 #18
0
        public void PopulateListBoxEmployees(ListBox listBoxEmployees)
        {
            using (var context = new AutoShopEntities())
            {
                var results = (from c in context.Employees
                               select new { Id = c.Id, Row = c.Id + "  " + c.Name + "    " + c.Surname }).ToList();

                listBoxEmployees.DataSource    = results;
                listBoxEmployees.DisplayMember = "Row";
                listBoxEmployees.ValueMember   = "Id";
            }
        }
예제 #19
0
        public void CarArrived(object carId)
        {
            using (var context = new AutoShopEntities())
            {
                if (carId != null)
                {
                    var car = context.Cars.FirstOrDefault(x => x.VIN == (string)carId);
                    car.Arrived = true;

                    context.SaveChanges();
                }
            }
        }
예제 #20
0
        public void FinishJob(object jobId)
        {
            using (var context = new AutoShopEntities())
            {
                if (jobId != null)
                {
                    var job = context.Jobs.FirstOrDefault(x => x.Id == (int)jobId);
                    job.Finished = true;

                    context.SaveChanges();
                }
            }
        }
예제 #21
0
        public void PopulateTopClients(ListBox listBoxTopClients)
        {
            using (var context = new AutoShopEntities())
            {
                var results = (from c in context.People
                               orderby c.Client.Cars.Count() descending
                               select new { Id = c.Id, Row = c.Name + "    " + c.Surname + "  " + c.Client.Cars.Count() }).ToList().Take(5);

                listBoxTopClients.DataSource    = results.ToList();
                listBoxTopClients.DisplayMember = "Row";
                listBoxTopClients.ValueMember   = "Id";
            }
        }
예제 #22
0
        public void PopulateListBoxClientCars(int clientId, ListBox listBoxClientCars)
        {
            using (var context = new AutoShopEntities())
            {
                var results = (from c in context.Cars
                               where c.Client_Id == clientId
                               select new { VIN = c.VIN, NumberPlate = c.NumberPlate, Row = c.NumberPlate + "    " + c.VIN }).ToList();

                listBoxClientCars.DataSource    = results;
                listBoxClientCars.DisplayMember = "Row";
                listBoxClientCars.ValueMember   = "VIN";
            }
        }
예제 #23
0
        public void PopulateListBoxJobs(string carVIN, ListBox listBoxCarJobs)
        {
            using (var context = new AutoShopEntities())
            {
                var results = (from c in context.Jobs
                               where c.Car_VIN == carVIN
                               select new { Id = c.Id, Row = c.Service.Name + "    " + c.Hours + "   " + c.Finished }).ToList();

                listBoxCarJobs.DataSource    = results;
                listBoxCarJobs.DisplayMember = "Row";
                listBoxCarJobs.ValueMember   = "Id";
            }
        }
예제 #24
0
        public void AddEmployeeToJob(object employeeId, object jobId)
        {
            using (var context = new AutoShopEntities())
            {
                var employee = context.Employees.FirstOrDefault(x => x.Id == (int)employeeId);
                if (jobId != null)
                {
                    var job = context.Jobs.FirstOrDefault(x => x.Id == (int)jobId);

                    job.Employees.Add(employee);

                    context.SaveChanges();
                }
            }
        }
예제 #25
0
 public bool isPerson(int id)
 {
     using (var context = new AutoShopEntities())
     {
         Person pers = context.People.FirstOrDefault(x => x.Id == id);
         if (pers != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
예제 #26
0
        public void AddNewService(string name, string price, string hours)
        {
            var service = new Service
            {
                Name          = name,
                Price         = double.Parse(price),
                Default_hours = double.Parse(hours)
            };

            using (var context = new AutoShopEntities())
            {
                context.Services.Add(service);
                context.SaveChanges();
            }
        }
예제 #27
0
 public bool isCompany(int id)
 {
     using (var context = new AutoShopEntities())
     {
         Company comp = context.Companies.FirstOrDefault(x => x.Id == id);
         if (comp != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
예제 #28
0
        public void AddJobToCar(int serviceId, string carVin)
        {
            using (var context = new AutoShopEntities())
            {
                double hours = (from c in context.Services
                                where c.Id == serviceId
                                select c.Default_hours).FirstOrDefault();

                var job = new Job
                {
                    Service_Id = serviceId,
                    Car_VIN    = carVin,
                    Start      = System.DateTime.Now,
                    Hours      = hours,
                    Finished   = false
                };

                context.Jobs.Add(job);
                context.SaveChanges();
            }
        }
예제 #29
0
        public void AddNewCar(string carVIN, string plate, string make, string model, string run, string engine, string year, int clientId)
        {
            var car = new Car
            {
                VIN         = carVIN,
                NumberPlate = plate,
                Make        = make,
                Model       = model,
                Run         = int.Parse(run),
                Engine      = engine,
                Year        = int.Parse(year)
            };

            car.Client_Id = clientId;

            using (var context = new AutoShopEntities())
            {
                context.Cars.Add(car);
                context.SaveChanges();
            }
        }
예제 #30
0
        /*
         *      public void PopulateListBoxJobEmployees(ListBox listBoxJobEmployees, ListBox listBoxCarJobs)
         *      {
         *              using (var context = new AutoShopEntities())
         *              {
         *                      if (listBoxCarJobs.SelectedValue != null)
         *                      {
         *                              var results = (from e in context.Employees
         *                                                         where e.Jobs.Any(j => j.Id == (int)listBoxCarJobs.SelectedValue)
         *                                                         select new { Id = e.Id, Row = e.Name + " " + e.Surname }).ToList();
         *
         *                              listBoxJobEmployees.DataSource = results;
         *                              listBoxJobEmployees.DisplayMember = "Row";
         *                              listBoxJobEmployees.ValueMember = "Id";
         *                      }
         *              }
         *      }
         */
        public void addData(object element)
        {
            Type type = element.GetType();

            using (var context = new AutoShopEntities())
            {
                if (type == typeof(Service))
                {
                    context.Services.Add((Service)element);
                }
                if (type == typeof(Car))
                {
                    context.Cars.Add((Car)element);
                }
                if (type == typeof(Employee))
                {
                    context.Employees.Add((Employee)element);
                }
                if (type == typeof(Job))
                {
                    context.Jobs.Add((Job)element);
                }
                if (type == typeof(Client))
                {
                    context.Clients.Add((Client)element);
                }
                if (type == typeof(Company))
                {
                    context.Companies.Add((Company)element);
                }
                if (type == typeof(Person))
                {
                    context.People.Add((Person)element);
                }
                context.SaveChanges();
            }
        }