Ejemplo n.º 1
0
        public static CheckResult ValidateSave(DSModel db, CompanyModel model)
        {
            CheckResult res = new CheckResult(model);
            if (string.IsNullOrWhiteSpace(model.CompanyName))
                res.AddError("Please enter a Company Name!", model.GetName(p => p.CompanyName));
            if (model.CompanyCode != string.Empty)
            {
                var check = db.Companies.Where(c => c.CompanyCode == model.CompanyCode && c.CompanyID != model.CompanyID).FirstOrDefault();
                if (check != null)
                    res.AddError("Another company already uses this Company Code! Use Peek or leave blank to autogenerate!", model.GetName(p => p.CompanyCode));
            }
            if (model.TrainingTime < 0m)
                res.AddError("Traning time cannot be negative number!", model.GetName(p => p.TrainingTime));

            var groups = model.Locations.GroupBy(l => l.LocationCode).ToList();
            if (groups.Any(g => g.Count() > 1))
            {
                var gr = groups.Where(g => g.Count() > 1).FirstOrDefault();
                res.AddError(string.Format("Duplicate location codes! Code: {0}", gr.FirstOrDefault().LocationCode));
            }
            return res;
        }
        private static void InsertCompany(DSModel db, KeyBinder key, CompanyModel model)
        {
            Company poco = new Company();
            poco.CompanyID = model.CompanyID;
            poco.CompanyName = model.CompanyName;
            if (model.CompanyCode == string.Empty)
                poco.CompanyCode = "C" + CompanyRepository.PeekCompanyCode(db, "C");
            else
                poco.CompanyCode = model.CompanyCode;
            poco.CompanyAddress1 = model.CompanyAddress1;
            poco.CompanyAddress2 = model.CompanyAddress2;
            poco.CompanyCity = model.CompanyCity;
            poco.CompanyState = model.CompanyState;
            poco.CompanyPostCode = model.CompanyPostCode;
            poco.CompanyContactName = model.CompanyContactName;
            poco.CompanyFax = model.CompanyFax;
            poco.CompanyPhone = model.CompanyPhone;
            poco.CompanyEmail = model.CompanyEmail;
            poco.LunchTime = model.LunchTime;
            poco.TrainingTime = model.TrainingTime;
            poco.IsEnabled = model.IsEnabled;

            foreach (var loc in model.Locations)
            {
                Location l = LocationRepository.SaveLocation(db, key, loc, poco);
                poco.Locations.Add(l);
                key.AddKey(l, loc, loc.GetName(p => p.LocationID));
                key.AddKey(poco, loc, loc.GetName(p => p.CompanyID));
            }

            db.Add(poco);

            key.AddKey(poco, model, model.GetName(p => p.CompanyID));
        }
        private void BindModel(CompanyModel model)
        {
            BindingSource bsModel = new BindingSource();
            bsModel.DataSource = model;

            CompanyName.DataBindings.Add("EditValue", bsModel, model.GetName(p => p.CompanyName), true, DataSourceUpdateMode.OnPropertyChanged);
            CompanyCode.DataBindings.Add("EditValue", bsModel, model.GetName(p => p.CompanyCode), true, DataSourceUpdateMode.OnPropertyChanged);
            CompanyAddress1.DataBindings.Add("EditValue", bsModel, model.GetName(p => p.CompanyAddress1), true, DataSourceUpdateMode.OnPropertyChanged);
            CompanyAddress2.DataBindings.Add("EditValue", bsModel, model.GetName(p => p.CompanyAddress2), true, DataSourceUpdateMode.OnPropertyChanged);
            CompanyCity.DataBindings.Add("EditValue", bsModel, model.GetName(p => p.CompanyCity), true, DataSourceUpdateMode.OnPropertyChanged);
            CompanyState.DataBindings.Add("EditValue", bsModel, model.GetName(p => p.CompanyState), true, DataSourceUpdateMode.OnPropertyChanged);
            CompanyPostCode.DataBindings.Add("EditValue", bsModel, model.GetName(p => p.CompanyPostCode), true, DataSourceUpdateMode.OnPropertyChanged);
            CompanyContactName.DataBindings.Add("EditValue", bsModel, model.GetName(p => p.CompanyContactName), true, DataSourceUpdateMode.OnPropertyChanged);
            CompanyFax.DataBindings.Add("EditValue", bsModel, model.GetName(p => p.CompanyFax), true, DataSourceUpdateMode.OnPropertyChanged);
            CompanyPhone.DataBindings.Add("EditValue", bsModel, model.GetName(p => p.CompanyPhone), true, DataSourceUpdateMode.OnPropertyChanged);
            CompanyEmail.DataBindings.Add("EditValue", bsModel, model.GetName(p => p.CompanyEmail), true, DataSourceUpdateMode.OnPropertyChanged);
            LunchTime.DataBindings.Add("EditValue", bsModel, model.GetName(p => p.LunchTime), true, DataSourceUpdateMode.OnPropertyChanged);
            TrainingTime.DataBindings.Add("EditValue", bsModel, model.GetName(p => p.TrainingTime), true, DataSourceUpdateMode.OnPropertyChanged);
            IsEnabled.DataBindings.Add("Checked", bsModel, model.GetName(p => p.IsEnabled), true, DataSourceUpdateMode.OnPropertyChanged);

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

            BindingSource bsLicenseRates = new BindingSource();
            bsLicenseRates.DataSource = this.Manager.LicensePayRates;
            gridControlLicense.DataSource = bsLicenseRates;

            BindingSource bsInvoiceRates = new BindingSource();
            bsInvoiceRates.DataSource = this.Manager.InvoicePayRates;
            gridControlInvoice.DataSource = bsInvoiceRates;
        }