// Show booking grid with booking list from SQL Table
        public void showBookings()
        {
            workingHours_Txt.Text = DatabaseControl.getHoursOfBookingDate(dateTimePicker1.Value.Date).ToString();
            note_Txt.Text         = DatabaseControl.getBookingNote(dateTimePicker1.Value.Date);
            double        workingHours = DatabaseControl.getHoursOfBookingDate(dateTimePicker1.Value.Date);
            BindingSource bs           = new BindingSource();

            GData.bookings  = DatabaseControl.getBookings();
            GData.customers = DatabaseControl.getCustomers();
            List <Booking> bookings = GData.bookings.Where(b => b.bookingDate.Date == dateTimePicker1.Value.Date).ToList();

            foreach (Booking booking in bookings)
            {
                //booking.estimatedTime = booking.timeOut - booking.timeIn;
                booking.timeRemaining = workingHours - booking.estimatedTime;
                workingHours         -= booking.estimatedTime;
            }
            bs.DataSource = bookings.Select(b => new FilteredBooking()
            {
                id             = b.id,
                jobNO          = b.jobNO,
                jobType        = b.jobType,
                customerName   = GData.customers.Where(c => c.id == b.customerID).ToList()[0].name,
                vehicleModel   = b.vehicleModel,
                regNo          = b.regNo,
                bookedBy       = b.bookedBy,
                loanCar        = b.loanCar,
                jobDescription = b.jobDescription,
                timeRemaining  = b.timeRemaining,
                timeIn         = b.timeIn,
                timeOut        = b.timeOut,
                bookingDate    = b.bookingDate
            }).ToList();
            dataGridView1.DataSource = bs;
        }
Exemple #2
0
        private void connect_Bt_Click(object sender, EventArgs e)
        {
            GData.hostAddress = hostAddress_Txt.Text;
            if (GData.hostAddress == "")
            {
                MessageBox.Show("Please input Host Address");
                hostAddress_Txt.Focus();
                return;
            }

            GData.userID = user_Txt.Text;
            if (GData.userID == "")
            {
                MessageBox.Show("Please input User ID");
                user_Txt.Focus();
                return;
            }

            GData.password = password_Txt.Text;
            GData.port     = port_Txt.Text;

            GData.conStr = "Data Source=" + GData.hostAddress + "\\SQLEXPRESS," + GData.port +
                           ";Network Library=DBMSSOCN;User ID=" + GData.userID + ";Password="******"Data Source=" + GData.hostAddress + "\\SQLEXPRESS," + GData.port +
                            ";Network Library=DBMSSOCN;;Initial Catalog=HordernsDB;User ID=" + GData.userID + ";Password="******"Data Source=" + Info.hostAddress +
            //    ";Integrated Security=SSPI;Initial Catalog=" + Info.database + ";";

            // Connect to Database and get data of Booking, JobType, and Technicians
            if (DatabaseControl.CreateDBIfNotExists())
            {
                GData.bookings    = DatabaseControl.getBookings();
                GData.jobTypes    = DatabaseControl.getJobTypes();
                GData.technicians = DatabaseControl.getTechnicians();
                GData.customers   = DatabaseControl.getCustomers();
                UIControl.mainForm.Show();
                this.Hide();
            }
        }
Exemple #3
0
        private void save_Btn_Click(object sender, EventArgs e)
        {
            // Check if Job NO is not empty
            if (jobNO_Txt.Text == "")
            {
                MessageBox.Show("Job No can not be empty. Please input!");
                jobNO_Txt.Focus();
                return;
            }
            // Check if a job No already exists in the database
            GData.bookings = DatabaseControl.getBookings();
            var list = GData.bookings.Where(b => b.jobNO == jobNO_Txt.Text).ToList();

            if (list.Count > 0)
            {
                MessageBox.Show("The booking with Job No. " + jobNO_Txt.Text + " already exists! Please input another Job No.");
                jobNO_Txt.Focus();
                return;
            }

            // Check if Job NO is not empty
            if (jobType_Cmb.Text == "")
            {
                MessageBox.Show("Job Type can not be empty. Please input!");
                jobType_Cmb.Focus();
                return;
            }
            // Check if a Customer filed is not empty
            if (customerName_Txt.Text == "")
            {
                MessageBox.Show("Customer field can not be empty. Please input!");
                customerName_Txt.Focus();
                return;
            }
            // Check if an Address filed is not empty.
            if (address1_Txt.Text == "")
            {
                MessageBox.Show("Address field can not be empty. Please input!");
                address1_Txt.Focus();
                return;
            }
            if (address2_Txt.Text == "")
            {
                MessageBox.Show("Address field can not be empty. Please input!");
                address2_Txt.Focus();
                return;
            }
            if (address3_Txt.Text == "")
            {
                MessageBox.Show("Address field can not be empty. Please input!");
                address3_Txt.Focus();
                return;
            }
            // Check if an Post Code filed is not empty.
            if (postCode_Txt.Text == "")
            {
                MessageBox.Show("Post Code can not be empty. Please input!");
                postCode_Txt.Focus();
                return;
            }
            // Check if an email filed is not empty.
            if (email_Txt.Text == "")
            {
                MessageBox.Show("Email field can not be empty. Please input!");
                email_Txt.Focus();
                return;
            }
            // Check if an Tel filed is not empty.
            if (tel_Txt.Text == "")
            {
                MessageBox.Show("Tel field can not be empty. Please input!");
                tel_Txt.Focus();
                return;
            }
            // Check if an Vehicle Model filed is not empty.
            if (vehicleModel_Txt.Text == "")
            {
                MessageBox.Show("Vehicle Model field can not be empty. Please input!");
                vehicleModel_Txt.Focus();
                return;
            }
            // Check if an Vehicle Reg.No filed is not empty.
            if (vehicleRegNo_Txt.Text == "")
            {
                MessageBox.Show("Vehicle Reg.NO field can not be empty. Please input!");
                vehicleRegNo_Txt.Focus();
                return;
            }
            // Check if an Booked By filed is not empty.
            if (bookedBy_Txt.Text == "")
            {
                MessageBox.Show("Booked By field can not be empty. Please input!");
                bookedBy_Txt.Focus();
                return;
            }
            // Check if an Job Description filed is not empty.
            if (jobDescription_Txt.Text == "")
            {
                MessageBox.Show("Work Title field can not be empty. Please input!");
                jobDescription_Txt.Focus();
                return;
            }

            // Compare Time in and Time Out
            if (timeIn_Dtp.Value.Hour * 60 + timeIn_Dtp.Value.Minute > timeOut_Dtp.Value.Hour * 60 + timeOut_Dtp.Value.Minute)
            {
                MessageBox.Show("Time in should be less than Time Out!");
                timeIn_Dtp.Focus();
                return;
            }

            int customerId = 0;

            customer = new Customer
            {
                honor    = honor_Cmb.Text,
                name     = customerName_Txt.Text,
                address1 = address1_Txt.Text,
                address2 = address2_Txt.Text,
                address3 = address3_Txt.Text,
                postCode = postCode_Txt.Text,
                email    = email_Txt.Text,
                tel      = tel_Txt.Text
            };
            if (existingCustomer_Cmb.SelectedIndex == 0)
            {
                customerId = DatabaseControl.addCustomer(customer);
                updateCustomers();
                UIControl.editBookingForm.updateCustomers();
            }
            else
            {
                customerId = GData.customers[existingCustomer_Cmb.SelectedIndex - 1].id;
                DatabaseControl.updateCustomer(customer, customerId);
            }
            double estimatedTime = Convert.ToDouble(estimatedTime_Txt.Text);
            double timeRemaining = DatabaseControl.getHoursOfBookingDate(DateTime.Now.Date) - estimatedTime;

            if (timeRemaining < 0)
            {
                timeRemaining = 0;
            }
            var newBooking = new Booking
            {
                jobNO             = jobNO_Txt.Text,
                jobType           = jobType_Cmb.Text,
                customerID        = customerId,
                servicePlan       = servicePlan_Cmb.Text,
                vehicleMake       = vehicleMake_Txt.Text,
                vehicleModel      = vehicleModel_Txt.Text,
                regNo             = vehicleRegNo_Txt.Text,
                mileage           = Convert.ToDouble(mileage_Txt.Text),
                loanCar           = loanCar_Cmb.Text,
                timeIn            = timeIn_Dtp.Value,
                timeOut           = timeOut_Dtp.Value,
                bookedBy          = bookedBy_Txt.Text,
                estimatedTime     = estimatedTime,
                timeRemaining     = timeRemaining,
                insuranceRequired = insurance_Cmb.Text,
                jobDescription    = jobDescription_Txt.Text,
                notes             = notes_Txt.Text,
                bookingDate       = newBookingDate
            };

            //if (newBooking.timeRemaining > 0)
            //{
            //    var newBookingToNextDay = new Booking
            //    {
            //        jobNO = jobNO_Txt.Text,
            //        jobType = jobType_Cmb.Text,
            //        customerID = customerId,
            //        servicePlan = servicePlan_Cmb.Text,
            //        vehicleMake = vehicleMake_Txt.Text,
            //        vehicleModel = vehicleModel_Txt.Text,
            //        regNo = vehicleRegNo_Txt.Text,
            //        mileage = Convert.ToDouble(mileage_Txt.Text),
            //        loanCar = loanCar_Cmb.Text,
            //        timeIn = timeIn_Dtp.Value,
            //        timeOut = timeOut_Dtp.Value,
            //        bookedBy = bookedBy_Txt.Text,
            //        estimatedTime = newBooking.timeRemaining,
            //        timeRemaining = DatabaseControl.getHoursOfBookingDate(DateTime.Now.Date) - newBooking.timeRemaining,
            //        insuranceRequired = insurance_Cmb.Text,
            //        jobDescription = jobDescription_Txt.Text,
            //        notes = notes_Txt.Text,
            //        bookingDate = newBookingDate.AddDays(1)
            //    };
            //    foreach (DateTime dt in GData.blackoutDates)
            //    {
            //        if (dt.Date == newBookingToNextDay.bookingDate.Date)
            //        {
            //            newBookingToNextDay.bookingDate.AddDays(1);
            //            break;
            //        }
            //    }
            //    if (newBookingToNextDay.bookingDate.DayOfWeek == DayOfWeek.Sunday)
            //    {
            //        newBookingToNextDay.bookingDate.AddDays(1);
            //    }
            //    if (DatabaseControl.addBooking(newBooking) && DatabaseControl.addBooking(newBookingToNextDay))
            //    {
            //        MessageBox.Show("New booking has been added succesfully!");
            //        UIControl.bookingGridForm.showBookings();
            //        clearFields();
            //    }
            //}
            //else
            //{
            if (DatabaseControl.addBooking(newBooking))
            {
                MessageBox.Show("New booking has been added succesfully!");
                UIControl.bookingGridForm.showBookings();
                clearFields();
            }
            //}
        }