Beispiel #1
0
        public override void SaveForm()
        {
            DaybookModel daybook = (DaybookModel)addDaybookControl.GetFieldValues();

            _daybookService.SaveDaybook(daybook);
            base.SaveForm();
        }
Beispiel #2
0
        public List <DaybookModel> GetDayBooks(DateTime dateTimeStamp)
        {
            List <DaybookModel> dbooks = new List <DaybookModel>();
            var tblJobs = db.tblJobs.Where(j => j.dtFrom == dateTimeStamp).OrderBy(db => db.JobID).ThenBy(db => db.Time).ToList();

            foreach (var job in tblJobs)
            {
                DaybookModel dbookModel = new DaybookModel(job);
                var          customer   = db.tblCustomers.FirstOrDefault(c => c.CustID == dbookModel.CustomerID);
                var          truck      = db.tblTrucks.FirstOrDefault(t => t.Id == dbookModel.TruckId);
                var          trailer    = db.tblTrailers.FirstOrDefault(t => t.Id == dbookModel.TrailerId);

                if (customer != null)
                {
                    dbookModel.Customer = new CustomerModel(customer);
                }
                if (truck != null)
                {
                    dbookModel.Truck = truck.Name;
                }
                if (trailer != null)
                {
                    dbookModel.Trailer = trailer.Name;
                }
                dbooks.Add(dbookModel);
            }

            return(dbooks);
        }
Beispiel #3
0
        public override void EditForm(object id)
        {
            int          daybookId = (int)id;
            DaybookModel job       = daybookId == 0 ? new DaybookModel {
                JobID = 0, dtFrom = DateTime.Now, dtTo = DateTime.Now
            } : _daybookService.GetDayBook(daybookId);

            addDaybookControl.PopulateData(job);
            base.EditForm(id);
        }
Beispiel #4
0
        public List <DaybookModel> GetDayBooks(int type)
        {
            List <DaybookModel> dbooks = new List <DaybookModel>();

            var tblJobs = type == 0 ? db.tblJobs.ToList() : db.tblJobs.Where(j => j.Type == type).ToList();

            foreach (var job in tblJobs)
            {
                DaybookModel dbookModel = new DaybookModel(job);
                var          customer   = db.tblCustomers.FirstOrDefault(c => c.CustID == dbookModel.CustomerID);
                if (customer != null)
                {
                    dbookModel.Customer = new CustomerModel(customer);
                }
                dbooks.Add(dbookModel);
            }

            return(dbooks);
        }
Beispiel #5
0
        public List <DaybookModel> GetInvoices(int customerId, DateTime?dateFrom, DateTime?dateTo, int driverId = 0, int truckId = 0, int trailerId = 0)
        {
            List <DaybookModel> retval = new List <DaybookModel>();

            var invoices = customerId == 0 ? db.tblJobs.ToList() : db.tblJobs.Where(j => j.CustomerID == customerId).ToList();

            if (dateFrom != null && dateFrom != DateTime.MinValue)
            {
                invoices = invoices.Where(j => j.dtFrom >= dateFrom).ToList();
            }
            if (dateFrom != null && dateTo != DateTime.MinValue)
            {
                invoices = invoices.Where(j => j.dtTo <= dateTo).ToList();
            }
            if (driverId != 0)
            {
                invoices = invoices.Where(j => j.DriverID == driverId).ToList();
            }
            if (truckId != 0)
            {
                invoices = invoices.Where(j => j.TruckId == truckId).ToList();
            }
            if (trailerId != 0)
            {
                invoices = invoices.Where(j => j.TrailerId == trailerId).ToList();
            }

            foreach (var invoice in invoices)
            {
                DaybookModel dbookModel = new DaybookModel(invoice);
                var          customer   = db.tblCustomers.FirstOrDefault(c => c.CustID == dbookModel.CustomerID);

                if (customer != null)
                {
                    dbookModel.Customer = new CustomerModel(customer);
                }
                retval.Add(dbookModel);
            }

            //invoices.ForEach(inv => retval.Add(new DaybookModel(inv)));

            return(retval);
        }
Beispiel #6
0
        public override object GetFieldValues()
        {
            int id = this.hdnJobId.Text == string.Empty ? 0 : Convert.ToInt32(this.hdnJobId.Text);

            int    customerid   = (int)((DWTComboBoxItem)cboCustomer.SelectedItem).Value;
            string customerName = (string)((DWTComboBoxItem)cboCustomer.SelectedItem).Text;
            int    driverId     = (int)((DWTComboBoxItem)cboDriver.SelectedItem).Value;
            string driverName   = (string)((DWTComboBoxItem)cboDriver.SelectedItem).Text;
            int    truckId      = (int)((DWTComboBoxItem)cboTruck.SelectedItem).Value;
            int    trailerId    = (int)((DWTComboBoxItem)cboTrailer.SelectedItem).Value;

            string       journey      = ((DWTComboBoxItem)cboJourney.SelectedItem).Text;
            int          type         = cboImportExport.SelectedItem.ToString().ToUpper() == "IMPORT" ? 1 : 2;
            DaybookModel daybookModel = new DaybookModel
            {
                JobID        = id,
                Address      = txtAddress.Text,
                Area         = txtArea.Text,
                BasePrice    = Convert.ToDecimal(txtbasePrice.Text),
                CustomerID   = customerid,
                CustRef      = txtCustomerRef.Text,
                DriverID     = driverId,
                dtFrom       = dateFrom.DateTime,
                dtTo         = dateTo.DateTime,
                Time         = txtTime.Time,
                MiscCode     = txtMiscCode.Text,
                Type         = type,
                InvoiceNo    = txtInvoice.Text,
                JobRef       = txtJobRef.Text,
                Notes        = txtGeneralNotes.Text,
                Journey      = cboJourney.SelectedItem.ToString(),
                CustomerName = customerName,
                DriverName   = driverName,
                IsDuplicate  = chkDulicate.Checked,
                TruckId      = truckId,
                TrailerId    = trailerId,
                PinNumber    = txtPin.Text, UseReturn = chkUseReturn.Checked
            };

            return(daybookModel);
        }
Beispiel #7
0
        public DBResult SaveDaybook(DaybookModel job)
        {
            tblJob tblJob = job.JobID != 0 ? db.tblJobs.FirstOrDefault(j => j.JobID == job.JobID) : new tblJob();

            try
            {
                tblJob.Address      = job.Address;
                tblJob.Area         = job.Area;
                tblJob.BasePrice    = job.BasePrice;
                tblJob.CustomerID   = job.CustomerID;
                tblJob.CustRef      = job.CustRef;
                tblJob.CustomerName = job.CustomerName;
                tblJob.DriverName   = job.DriverName;
                tblJob.dtFrom       = job.dtFrom;
                tblJob.dtTo         = job.dtTo;
                tblJob.Notes        = job.Notes;
                tblJob.Time         = job.Time;
                tblJob.Journey      = job.Journey;
                tblJob.Type         = job.Type;
                tblJob.MiscCode     = job.MiscCode;
                tblJob.TruckId      = job.TruckId;
                tblJob.PinNumber    = job.PinNumber;
                tblJob.TrailerId    = job.TrailerId;
                tblJob.UseReturn    = job.UseReturn;
                tblJob.JobRef       = job.JobRef;
                tblJob.InvoiceNo    = job.InvoiceNo;

                if (job.JobID == 0)
                {
                    tblJob.DriverID = job.DriverID;
                    db.tblJobs.Add(tblJob);
                    if (job.UseReturn)
                    {
                        var dateFrom = Convert.ToDateTime(tblJob.dtFrom).AddDays(1);
                        var dateTo   = Convert.ToDateTime(tblJob.dtTo).AddDays(1);

                        var currentDateUsed = dateFrom;
                        while (currentDateUsed < dateTo)
                        {
                            tblJob retJob = new tblJob();
                            retJob.DriverID     = job.DriverID;
                            retJob.Address      = job.Address;
                            retJob.Area         = job.Area;
                            retJob.BasePrice    = job.BasePrice;
                            retJob.CustomerID   = job.CustomerID;
                            retJob.CustRef      = job.CustRef;
                            retJob.CustomerName = job.CustomerName;
                            retJob.DriverName   = job.DriverName;
                            retJob.dtFrom       = currentDateUsed;
                            retJob.dtTo         = job.dtTo;
                            retJob.Notes        = job.Notes;
                            retJob.Time         = job.Time;
                            retJob.Journey      = job.Journey;
                            retJob.Type         = job.Type;
                            retJob.MiscCode     = dateFrom == dateTo.AddDays(-2) ? string.Format("{0}-RETURNED", job.MiscCode) : job.MiscCode;
                            retJob.TruckId      = job.TruckId;
                            retJob.PinNumber    = job.PinNumber;
                            retJob.TrailerId    = job.TrailerId;
                            retJob.UseReturn    = job.UseReturn;
                            retJob.JobRef       = job.JobRef;
                            retJob.dtFrom       = currentDateUsed;
                            db.tblJobs.Add(retJob);
                            currentDateUsed = currentDateUsed.AddDays(1);
                        }
                    }
                }
                else
                {
                    if (job.IsDuplicate)
                    {
                        if (tblJob.DriverID == job.DriverID)
                        {
                            tblJob.DuplicateOf = job.JobID;
                            var duplicatesFound = db.tblJobs.Count(j => j.DuplicateOf == job.JobID);
                            tblJob.DriverName = string.Format("{0} ({1})", job.DriverName, (duplicatesFound + 2));
                        }

                        tblJob.DriverID = job.DriverID;
                        db.tblJobs.Add(tblJob);
                    }
                }

                db.SaveChanges();
                return(new DBResult {
                    ReturnCode = ReturnCode.Success
                });
            }
            catch (Exception ex)
            {
                return(new DBResult {
                    ReturnCode = ReturnCode.Failed, Message = ex.Message
                });
            }
        }
Beispiel #8
0
        public override void PopulateData(object data)
        {
            DaybookModel currentData = (DaybookModel)data;

            var customers = _customerService.GetCustomers();
            var drivers   = _driverService.GetDrivers();

            journeys = _journeyService.GetJourneys();
            var trucks   = _driverService.GetTrucks();
            var trailers = _driverService.GetTrailers();


            cboCustomer.Items.Clear();
            cboDriver.Items.Clear();
            cboJourney.Items.Clear();
            cboTrailer.Items.Clear();
            cboTruck.Items.Clear();


            this.txtCustomerRef.Text  = string.Empty;
            this.txtAddress.Text      = string.Empty;
            this.txtbasePrice.Text    = string.Empty;
            this.txtArea.Text         = string.Empty;
            this.txtGeneralNotes.Text = string.Empty;
            this.txtMiscCode.Text     = string.Empty;
            this.txtInvoice.Text      = string.Empty;
            this.txtTime.Text         = string.Empty;
            this.txtJobRef.Text       = string.Empty;
            this.chkDulicate.Checked  = currentData.IsDuplicate;
            this.chkUseReturn.Checked = currentData.UseReturn;

            int index = 1;

            DWTComboBoxItem journeyItem = new DWTComboBoxItem {
                Text = "Select Journey", Value = 0
            };

            cboJourney.Items.Add(journeyItem);

            int selectedJourneyIndex = 0;

            foreach (var journey in journeys)
            {
                journeyItem = new DWTComboBoxItem {
                    Text = journey.Journey, Value = journey.ID
                };
                cboJourney.Items.Add(journeyItem);

                if (journey.Journey == currentData.Journey)
                {
                    selectedJourneyIndex = index;
                }
                index++;
            }

            int             importExport = Convert.ToInt32(currentData.Type) == 1 ? 0 : 1;
            DWTComboBoxItem customerItem = new DWTComboBoxItem {
                Text = "Select Customer", Value = 0
            };

            cboCustomer.Items.Add(customerItem);


            index = 1;
            int selectedCustomerIndex = 0;

            foreach (var customer in customers)
            {
                customerItem = new DWTComboBoxItem {
                    Text = customer.Name, Value = customer.CustID
                };
                cboCustomer.Items.Add(customerItem);
                if (customer.CustID == currentData.CustomerID)
                {
                    selectedCustomerIndex = index;
                }
                index++;
            }

            DWTComboBoxItem driverItem = new DWTComboBoxItem {
                Text = "Select Driver", Value = 0
            };

            cboDriver.Items.Add(driverItem);

            index = 1;
            int selectedDriverIndex = 0;

            foreach (var driver in drivers)
            {
                driverItem = new DWTComboBoxItem {
                    Text = string.Format("{0} {1}", driver.Name, driver.Surname), Value = driver.DriverID
                };
                cboDriver.Items.Add(driverItem);
                if (driver.DriverID == currentData.DriverID)
                {
                    selectedDriverIndex = index;
                }
                index++;
            }

            DWTComboBoxItem truckItem = new DWTComboBoxItem {
                Text = "Select Truck", Value = 0
            };

            cboTruck.Items.Add(truckItem);

            index = 1;
            int selectedTruckIndex = 0;

            foreach (var truck in trucks)
            {
                truckItem = new DWTComboBoxItem {
                    Text = string.Format("{0}-{1}", truck.Name, truck.TruckNumber), Value = truck.Id
                };
                cboTruck.Items.Add(truckItem);

                if (truck.Id == currentData.TruckId)
                {
                    selectedTruckIndex = index;
                }
                index++;
            }

            DWTComboBoxItem trailerItem = new DWTComboBoxItem {
                Text = "Select Trailer", Value = 0
            };

            cboTrailer.Items.Add(trailerItem);

            index = 1;
            int selectedTrailerIndex = 0;

            foreach (var trailer in trailers)
            {
                trailerItem = new DWTComboBoxItem {
                    Text = string.Format("{0}-{1}", trailer.Name, trailer.TrailerName), Value = trailer.Id
                };
                cboTrailer.Items.Add(trailerItem);

                if (trailer.Id == currentData.TrailerId)
                {
                    selectedTrailerIndex = index;
                }
                index++;
            }

            this.txtCustomerRef.Text  = currentData.CustRef;
            this.txtAddress.Text      = currentData.Address;
            this.txtbasePrice.Text    = currentData.BasePrice.ToString();
            this.txtArea.Text         = currentData.Area;
            this.txtGeneralNotes.Text = currentData.Notes;
            this.txtMiscCode.Text     = currentData.MiscCode;
            this.txtInvoice.Text      = currentData.InvoiceNo;

            TimeSpan timeSpan = currentData.Time != null?Convert.ToDateTime(currentData.Time).TimeOfDay : DateTime.Now.TimeOfDay;

            this.txtTime.EditValue = Utilities.ConvertTo12HourFormat(timeSpan);


            this.cboCustomer.SelectedIndex = selectedCustomerIndex;
            this.cboDriver.SelectedIndex   = selectedDriverIndex;
            this.cboTruck.SelectedIndex    = selectedTruckIndex;
            this.cboTrailer.SelectedIndex  = selectedTrailerIndex;

            if (cboJourney.Items.Count > 0 && selectedJourneyIndex < cboJourney.Items.Count)
            {
                this.cboJourney.SelectedIndex = selectedJourneyIndex;
            }

            if (cboImportExport.Items.Count > 0)
            {
                this.cboImportExport.SelectedIndex = importExport;
            }

            this.txtJobRef.Text    = currentData.JobRef;
            this.hdnJobId.Text     = currentData.JobID.ToString();
            this.dateFrom.DateTime = Convert.ToDateTime(currentData.dtFrom);
            this.dateTo.DateTime   = Convert.ToDateTime(currentData.dtTo);
            this.txtPin.Text       = currentData.PinNumber;



            var addresses = _dayBookService.GetAdresses();

            AutoCompleteStringCollection addressSuggestions = new AutoCompleteStringCollection();

            addresses.ForEach(add => addressSuggestions.Add(add));
            txtAddress.AutoCompleteCustomSource = addressSuggestions;
            txtAddress.AutoCompleteMode         = AutoCompleteMode.Suggest;
            txtAddress.AutoCompleteSource       = AutoCompleteSource.CustomSource;
        }