private static void InsertDriver(DSModel db, KeyBinder key, DriverModel model)
        {
            Driver poco = new Driver();
            if (model.DriverCode == string.Empty)
                poco.DriverCode = "D" + DriverRepository.PeekDriverCode(db, "D");
            else
                poco.DriverCode = model.DriverCode;
            poco.FirstName = model.FirstName;
            poco.SecondName = model.SecondName;
            poco.LastName = model.LastName;
            poco.DateOfBirth = model.DateOfBirth;
            poco.DateOfHire = model.DateOfHire;
            poco.CellPhone = model.CellPhone;
            poco.EmergencyPhone = model.EmergencyPhone;
            poco.Email = model.Email;
            poco.PayRateOverride = model.PayRateOverride;
            poco.IsEnabled = model.IsEnabled;
            foreach (var l in model.Locations)
            {
                poco.LocationsDrivers.Add(
                    new LocationsDriver()
                    {
                        LocationID = l.LocationID,
                        Driver = poco,
                        TravelPay = l.TravelPay
                    });
                key.AddKey(poco, l, poco.GetName(p => p.DriverID));
            }
            db.Add(poco);

            key.AddKey(poco, model, poco.GetName(p => p.DriverID));
        }
Пример #2
0
        public static CheckResult ValidateSave(DSModel db, DriverModel model)
        {
            CheckResult res = new CheckResult(model);
            if (string.IsNullOrWhiteSpace(model.FirstName))
                res.AddError("Please enter a First Name of the driver!", model.GetName(p => p.FirstName));
            if (string.IsNullOrWhiteSpace(model.SecondName))
                res.AddWarning("Missing Second Name of the driver!", model.GetName(p => p.SecondName));
            if (string.IsNullOrWhiteSpace(model.LastName))
                res.AddError("Please enter a Last Name of the driver!", model.GetName(p => p.LastName));
            //if (model.LicenseID == 0)
            //    res.AddError("Please select a license!", model.GetName(p => p.LicenseID));
            //if (!model.LicenseExpirationDate.HasValue)
            //    res.AddError("Please enter a license expiration date", model.GetName(p => p.LicenseExpirationDate));
            if (model.PayRateOverride < 0.0m)
                res.AddError("Please enter a positive number for Pay Rate Override!", model.GetName(p => p.PayRateOverride));
            if (model.DriverCode != string.Empty)
            {
                var check = db.Drivers.Where(d => d.DriverCode == model.DriverCode && d.DriverID != model.DriverID).FirstOrDefault();
                if (check != null)
                    res.AddError("Another driver already uses this Driver Code! Use Peek or leave blank to autogenerate!", model.GetName(p => p.DriverCode));
            }
            foreach (var l in model.Locations)
            {
                if (l.LocationID == 0)
                    res.AddError("Please choose a Location for hte travel pay!", "LocationID");
                if (l.TravelPay == 0.0m)
                    res.AddError("Please enter a positive non-zero number for Travel Pay!", "TravelPay");
            }

            return res;
        }
        public static DriverModel GetDriver(DSModel db, uint driverID)
        {
            if (db == null)
                throw new ArgumentNullException("db");

            var poco = db.Drivers.Where(d => d.DriverID == driverID).FirstOrDefault();
            if (poco == null)
                return null;

            DriverModel mod = new DriverModel();
            mod.DriverID = poco.DriverID;
            mod.DriverCode = poco.DriverCode;
            mod.FirstName = poco.FirstName;
            mod.SecondName = poco.SecondName;
            mod.LastName = poco.LastName;
            mod.DateOfBirth = poco.DateOfBirth;
            mod.DateOfHire = poco.DateOfHire;
            mod.CellPhone = poco.CellPhone;
            mod.EmergencyPhone = poco.EmergencyPhone;
            mod.Email = poco.Email;
            mod.PayRateOverride = poco.PayRateOverride;
            mod.IsEnabled = poco.IsEnabled;
            mod.IsChanged = false;
            mod.Locations = poco.LocationsDrivers.Select(q => new LocationDriverModel() { LocationDriverID = q.LocationDriverID, CompanyID = q.Location.CompanyID, DriverID = q.DriverID, LocationID = q.LocationID, TravelPay = q.TravelPay, IsChanged = false }).ToList();

            return mod;
        }
        private void BindModel(DriverModel mod)
        {
            BindingSource bsModel = new BindingSource();
            bsModel.DataSource = mod;

            DriverCode.DataBindings.Add("EditValue", bsModel, mod.GetName(p => p.DriverCode), true, DataSourceUpdateMode.OnPropertyChanged);
            FirstName.DataBindings.Add("EditValue", bsModel, mod.GetName(p => p.FirstName), true, DataSourceUpdateMode.OnPropertyChanged);
            SecondName.DataBindings.Add("EditValue", bsModel, mod.GetName(p => p.SecondName), true, DataSourceUpdateMode.OnPropertyChanged);
            LastName.DataBindings.Add("EditValue", bsModel, mod.GetName(p => p.LastName), true, DataSourceUpdateMode.OnPropertyChanged);
            DateOfBirth.DataBindings.Add("EditValue", bsModel, mod.GetName(p => p.DateOfBirth), true, DataSourceUpdateMode.OnPropertyChanged);
            DateOfHire.DataBindings.Add("EditValue", bsModel, mod.GetName(p => p.DateOfHire), true, DataSourceUpdateMode.OnPropertyChanged);
            CellPhone.DataBindings.Add("EditValue", bsModel, mod.GetName(p => p.CellPhone), true, DataSourceUpdateMode.OnPropertyChanged);
            EmergencyPhone.DataBindings.Add("EditValue", bsModel, mod.GetName(p => p.EmergencyPhone), true, DataSourceUpdateMode.OnPropertyChanged);
            Email.DataBindings.Add("EditValue", bsModel, mod.GetName(p => p.Email), true, DataSourceUpdateMode.OnPropertyChanged);
            //LicenseID.DataBindings.Add("EditValue", bsModel, mod.GetName(p => p.LicenseID), true, DataSourceUpdateMode.OnPropertyChanged);
            //LicenseExpirationDate.DataBindings.Add("EditValue", bsModel, mod.GetName(p => p.LicenseExpirationDate), true, DataSourceUpdateMode.OnPropertyChanged);
            PayRateOverride.DataBindings.Add("EditValue", bsModel, mod.GetName(p => p.PayRateOverride), true, DataSourceUpdateMode.OnPropertyChanged);
            IsEnabled.DataBindings.Add("Checked", bsModel, mod.GetName(p => p.IsEnabled), true, DataSourceUpdateMode.OnPropertyChanged);

            BindingSource bsLocations = new BindingSource();
            bsLocations.DataSource = mod.Locations;
            gridControlLocations.DataSource = bsLocations;

            FileBlobCreationInfoModel info = new FileBlobCreationInfoModel();
            info.DriverID = this.Manager.ActiveModel.DriverID;
            var manager = FileBlobManager.Create(info);
            xu_Files.Load(manager);

            var driverLicensesManager = DriverLicenseCatalogManager.Create(this.Manager.ActiveModel.DriverID);
            xu_DriverLicenses.LoadManager(driverLicensesManager);
        }
        public static void SaveDriver(DSModel db, KeyBinder key, DriverModel model)
        {
            if (db == null)
                throw new ArgumentNullException("db");
            if (key == null)
                throw new ArgumentNullException("key");
            if (model == null)
                throw new ArgumentNullException("model");

            if (model.DriverID == 0)
                InsertDriver(db, key, model);
            else
                UpdateDriver(db, key, model);
        }
Пример #6
0
        public CheckResult DeleteDriver(DriverModel model)
        {
            try
            {
                using (var db = DB.GetContext())
                {
                    var check = DriverValidator.ValidateDelete(db, model);
                    if (check.Failed)
                        return check;

                    DriverRepository.DeleteDriver(db, model);
                    db.SaveChanges();
                    return check;
                }
            }
            catch (Exception ex)
            {
                CheckResult res = new CheckResult();
                res.AddError("The following driver has records in the database and cannot be deleted!", "DriverID");
                return res;
            }
        }
Пример #7
0
        public CheckResult SaveDriver(DriverModel model)
        {
            try
            {
                using (var db = DB.GetContext())
                {
                    var check = DriverValidator.ValidateSave(db, model);
                    if (check.Failed)
                        return check;

                    KeyBinder key = new KeyBinder();
                    DriverRepository.SaveDriver(db, key, model);
                    db.SaveChanges();
                    key.BindKeys();
                    model.IsChanged = false;
                    return check;
                }
            }
            catch (Exception ex)
            {
                return new CheckResult(ex);
            }
        }
Пример #8
0
 public static CheckResult ValidateDelete(DSModel db, DriverModel model)
 {
     return new CheckResult(model);
 }
Пример #9
0
 private DriverManager(DSModel db, DriverModel model)
     : base(db)
 {
     this.ActiveModel = model;
 }
Пример #10
0
 public static DriverManager CreateEdit(DriverModel driver)
 {
     return new DriverManager(DB.GetContext(), driver);
 }
Пример #11
0
        public static void DeleteDriver(DSModel db, DriverModel model)
        {
            if (db == null)
                throw new ArgumentNullException("db");

            if (model.DriverID != 0)
            {
                var poco = db.Drivers.Where(d => d.DriverID == model.DriverID).FirstOrDefault();
                if (poco != null)
                    db.Delete(poco);
            }
        }
Пример #12
0
        private static void UpdateDriver(DSModel db, KeyBinder key, DriverModel model)
        {
            var poco = db.Drivers.Where(d => d.DriverID == model.DriverID).FirstOrDefault();
            if (poco == null)
                throw new ArgumentException("No driver with this ID!");

            poco.DriverCode = model.DriverCode;
            poco.FirstName = model.FirstName;
            poco.SecondName = model.SecondName;
            poco.LastName = model.LastName;
            poco.DateOfBirth = model.DateOfBirth;
            poco.DateOfHire = model.DateOfHire;
            poco.CellPhone = model.CellPhone;
            poco.EmergencyPhone = model.EmergencyPhone;
            poco.Email = model.Email;
            poco.PayRateOverride = model.PayRateOverride;
            poco.IsEnabled = model.IsEnabled;

            foreach (var l in poco.LocationsDrivers.ToList())
            {
                db.Delete(l);
                poco.LocationsDrivers.Remove(l);
            }
            db.FlushChanges();
            foreach (var l in model.Locations)
            {
                poco.LocationsDrivers.Add(
                    new LocationsDriver()
                    {
                        LocationID = l.LocationID,
                        DriverID = l.DriverID,
                        TravelPay = l.TravelPay
                    });
            }
        }