Пример #1
0
        public static List <Technician> getTechnicians()
        {
            HordernsDB         hordensDB   = new HordernsDB(GData.conStr1);
            Table <Technician> technicians = hordensDB.GetTable <Technician>();

            return(technicians.ToList());
        }
Пример #2
0
        // Delete a booking from database
        public static bool deleteBooking(Booking bookingToDelete)
        {
            HordernsDB      hordensDB = new HordernsDB(GData.conStr1);
            Table <Booking> bookings  = hordensDB.GetTable <Booking>();
            var             query     =
                from booking in bookings
                where booking.id == bookingToDelete.id
                select booking;

            if (query.ToList().Count > 0)
            {
                Booking booking = query.ToList()[0];
                hordensDB.bookings.DeleteOnSubmit(booking);
                try
                {
                    hordensDB.SubmitChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return(false);
                }
            }
            return(false);
        }
Пример #3
0
        public static bool deleteTechnician(Technician technicianToDelete)
        {
            HordernsDB         hordensDB   = new HordernsDB(GData.conStr1);
            Table <Technician> technicians = hordensDB.GetTable <Technician>();
            var query =
                from technician in technicians
                where technician.id == technicianToDelete.id
                select technician;

            if (query.ToList().Count > 0)
            {
                Technician technician = query.ToList()[0];
                hordensDB.technicians.DeleteOnSubmit(technician);
                try
                {
                    hordensDB.SubmitChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return(false);
                }
            }
            return(false);
        }
Пример #4
0
        public static List <Customer> getCustomers()
        {
            HordernsDB       hordensDB = new HordernsDB(GData.conStr1);
            Table <Customer> customers = hordensDB.GetTable <Customer>();

            return(customers.ToList());
        }
Пример #5
0
        public static void updateCustomer(Customer customerToUpdate, int id)
        {
            HordernsDB       hordensDB = new HordernsDB(GData.conStr1);
            Table <Customer> customers = hordensDB.GetTable <Customer>();
            var query =
                from customer in customers
                where customer.id == id
                select customer;

            if (query.ToList().Count > 0)
            {
                Customer customer = query.ToList()[0];
                customer.honor    = customerToUpdate.honor;
                customer.name     = customerToUpdate.name;
                customer.address1 = customerToUpdate.address1;
                customer.address2 = customerToUpdate.address2;
                customer.address3 = customerToUpdate.address3;
                customer.postCode = customerToUpdate.postCode;
                customer.email    = customerToUpdate.email;
                customer.tel      = customerToUpdate.tel;

                try
                {
                    hordensDB.SubmitChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Пример #6
0
        // Get all booking from database into Objects
        public static List <Booking> getBookings()
        {
            HordernsDB      hordensDB = new HordernsDB(GData.conStr1);
            Table <Booking> bookings  = hordensDB.GetTable <Booking>();

            return(bookings.ToList());
        }
Пример #7
0
        // Get all job types from database and convert into object
        public static List <JobType> getJobTypes()
        {
            HordernsDB      hordensDB = new HordernsDB(GData.conStr1);
            Table <JobType> jobTypes  = hordensDB.GetTable <JobType>();

            return(jobTypes.ToList());
        }
Пример #8
0
        public static bool updateTechnician(Technician technicianToEdit)
        {
            HordernsDB         hordensDB   = new HordernsDB(GData.conStr1);
            Table <Technician> technicians = hordensDB.GetTable <Technician>();
            var query =
                from technician in technicians
                where technician.id == technicianToEdit.id
                select technician;

            if (query.ToList().Count > 0)
            {
                Technician technician = query.ToList()[0];
                technician.name         = technicianToEdit.name;
                technician.date         = technicianToEdit.date;
                technician.workingHours = technicianToEdit.workingHours;

                try
                {
                    hordensDB.SubmitChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return(false);
                }
            }
            return(false);
        }
Пример #9
0
        // Delete Job Type from database
        public static bool deleteJobType(JobType jobTypeToDelete)
        {
            HordernsDB      hordensDB = new HordernsDB(GData.conStr1);
            Table <JobType> jobTypes  = hordensDB.GetTable <JobType>();
            var             query     =
                from jobType in jobTypes
                where jobType.id == jobTypeToDelete.id
                select jobType;

            if (query.ToList().Count > 0)
            {
                JobType jobType = query.ToList()[0];
                hordensDB.jobTypes.DeleteOnSubmit(jobType);
                try
                {
                    hordensDB.SubmitChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return(false);
                }
            }
            return(false);
        }
Пример #10
0
        // Update Job Type from database
        public static bool updateJobType(JobType jobTypeToEdit)
        {
            HordernsDB      hordensDB = new HordernsDB(GData.conStr1);
            Table <JobType> jobTypes  = hordensDB.GetTable <JobType>();
            var             query     =
                from jobType in jobTypes
                where jobType.id == jobTypeToEdit.id
                select jobType;

            if (query.ToList().Count > 0)
            {
                JobType jobType = query.ToList()[0];
                jobType.typeName   = jobTypeToEdit.typeName;
                jobType.background = jobTypeToEdit.background;

                try
                {
                    hordensDB.SubmitChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return(false);
                }
            }
            return(false);
        }
Пример #11
0
        public static double getHoursOfBookingDate(DateTime date)
        {
            double hours = 0;

            HordernsDB          hordensDB    = new HordernsDB(GData.conStr1);
            Table <BookingDate> bookingDates = hordensDB.GetTable <BookingDate>();
            var query =
                from bookingDate in bookingDates
                where bookingDate.date.Date == date.Date
                select bookingDate;

            if (query.ToList().Count > 0)
            {
                hours = query.ToList()[0].hours;
            }
            return(hours);
            //try
            //{
            //    using (cmd = con.CreateCommand())
            //    {
            //        cmd.CommandText = "SELECT hours FROM BookingDates Where date = @date";
            //        cmd.Parameters.AddWithValue("@date", date.Date);
            //        hours = Convert.ToDouble(cmd.ExecuteScalar());
            //    }
            //}
            //catch (Exception ex)
            //{
            //}
            //return hours;
        }
Пример #12
0
        // Move booking if not finished to next date
        public static void moveBookingToNextDate(Booking bookingToMove, double estimatedTime)
        {
            HordernsDB      hordensDB = new HordernsDB(GData.conStr1);
            Table <Booking> bookings  = hordensDB.GetTable <Booking>();
            var             query     =
                from booking in bookings
                where booking.id == bookingToMove.id
                select booking;

            if (query.ToList().Count > 0)
            {
                Booking booking = new Booking
                {
                    jobNO             = bookingToMove.jobNO,
                    jobType           = bookingToMove.jobType,
                    customerID        = bookingToMove.customerID,
                    servicePlan       = bookingToMove.servicePlan,
                    vehicleMake       = bookingToMove.vehicleMake,
                    vehicleModel      = bookingToMove.vehicleModel,
                    regNo             = bookingToMove.regNo,
                    mileage           = bookingToMove.mileage,
                    loanCar           = bookingToMove.loanCar,
                    timeIn            = bookingToMove.timeIn,
                    timeOut           = bookingToMove.timeOut,
                    bookedBy          = bookingToMove.bookedBy,
                    estimatedTime     = estimatedTime,
                    timeRemaining     = bookingToMove.timeRemaining,
                    insuranceRequired = bookingToMove.insuranceRequired,
                    jobDescription    = bookingToMove.jobDescription,
                    notes             = bookingToMove.notes,
                    bookingDate       = bookingToMove.bookingDate.AddDays(1)
                };
                addBooking(booking);
            }
        }
Пример #13
0
        // Add new booking into sql table
        public static bool addBooking(Booking newBooking)
        {
            HordernsDB hordensDB = new HordernsDB(GData.conStr1);

            hordensDB.bookings.InsertOnSubmit(newBooking);
            try
            {
                hordensDB.SubmitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
        }
Пример #14
0
        // Add new job type into database
        public static bool addJobType(JobType jobType)
        {
            HordernsDB hordensDB = new HordernsDB(GData.conStr1);

            hordensDB.jobTypes.InsertOnSubmit(jobType);
            try
            {
                hordensDB.SubmitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
        }
Пример #15
0
        // Add new technician into database
        public static bool addTechnician(Technician technician)
        {
            HordernsDB hordensDB = new HordernsDB(GData.conStr1);

            hordensDB.technicians.InsertOnSubmit(technician);
            try
            {
                hordensDB.SubmitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
        }
Пример #16
0
        public static int addCustomer(Customer customer)
        {
            HordernsDB hordensDB = new HordernsDB(GData.conStr1);

            hordensDB.customers.InsertOnSubmit(customer);
            try
            {
                hordensDB.SubmitChanges();
                return(customer.id);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(-1);
            }
        }
Пример #17
0
 public static bool CreateDBIfNotExists()
 {
     try
     {
         HordernsDB hordernsDB = new HordernsDB(GData.conStr);
         if (!hordernsDB.DatabaseExists())
         {
             hordernsDB.CreateDatabase();
         }
         return(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
         return(false);
     }
 }
Пример #18
0
        public static string getBookingNote(DateTime date)
        {
            string note = "";

            HordernsDB          hordensDB    = new HordernsDB(GData.conStr1);
            Table <BookingDate> bookingDates = hordensDB.GetTable <BookingDate>();
            var query =
                from bookingDate in bookingDates
                where bookingDate.date.Date == date.Date
                select bookingDate;

            if (query.ToList().Count > 0)
            {
                note = query.ToList()[0].note;
            }
            return(note);
        }
Пример #19
0
        public static bool updateBooking(Booking bookingToEdit)
        {
            HordernsDB      hordensDB = new HordernsDB(GData.conStr1);
            Table <Booking> bookings  = hordensDB.GetTable <Booking>();
            var             query     =
                from booking in bookings
                where booking.id == bookingToEdit.id
                select booking;

            if (query.ToList().Count > 0)
            {
                Booking booking = query.ToList()[0];
                booking.jobNO             = bookingToEdit.jobNO;
                booking.jobType           = bookingToEdit.jobType;
                booking.customerID        = bookingToEdit.customerID;
                booking.servicePlan       = bookingToEdit.servicePlan;
                booking.vehicleMake       = bookingToEdit.vehicleMake;
                booking.vehicleModel      = bookingToEdit.vehicleModel;
                booking.regNo             = bookingToEdit.regNo;
                booking.mileage           = bookingToEdit.mileage;
                booking.loanCar           = bookingToEdit.loanCar;
                booking.timeIn            = bookingToEdit.timeIn;
                booking.timeOut           = bookingToEdit.timeOut;
                booking.bookedBy          = bookingToEdit.bookedBy;
                booking.estimatedTime     = bookingToEdit.estimatedTime;
                booking.insuranceRequired = bookingToEdit.insuranceRequired;
                booking.jobDescription    = bookingToEdit.jobDescription;
                booking.notes             = bookingToEdit.notes;
                try
                {
                    hordensDB.SubmitChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    return(false);
                }
            }
            return(false);
        }
Пример #20
0
        public static void setBookingDates(DateTime date, double hours, string note)
        {
            HordernsDB          hordensDB    = new HordernsDB(GData.conStr1);
            Table <BookingDate> bookingDates = hordensDB.GetTable <BookingDate>();
            var query =
                from bookingDate in bookingDates
                where bookingDate.date.Date == date.Date
                select bookingDate;

            if (query.ToList().Count > 0)
            {
                BookingDate bookingDate = query.ToList()[0];
                bookingDate.hours = hours;
                bookingDate.note  = note;
            }
            else
            {
                BookingDate newBookingDate = new BookingDate
                {
                    date  = date,
                    hours = hours,
                    note  = note
                };
                hordensDB.bookingDates.InsertOnSubmit(newBookingDate);
            }
            try
            {
                hordensDB.SubmitChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            /*try
             * {
             *  using (cmd = con.CreateCommand())
             *  {
             *      cmd.CommandText = "SELECT COUNT(*) FROM BookingDates Where date = @date";
             *      cmd.Parameters.AddWithValue("@date", date.Date);
             *      int count = 0;
             *      count = Convert.ToInt32(cmd.ExecuteScalar());
             *      if (count > 0)
             *      {
             *          cmd.CommandText = "UPDATE BookingDates SET hours=@hours, note=@note Where date=@date";
             *      }
             *      else
             *      {
             *          cmd.CommandText = "INSERT INTO BookingDates (date, hours, note) values (@date, @hours, @note);";
             *      }
             *      cmd.Parameters.Clear();
             *      cmd.Parameters.AddWithValue("@hours", hours);
             *      cmd.Parameters.AddWithValue("@date", date.Date);
             *      cmd.Parameters.AddWithValue("@note", note);
             *      cmd.ExecuteNonQuery();
             *  }
             * }
             * catch (Exception ex)
             * {
             *  MessageBox.Show(ex.ToString());
             * }*/
        }