protected override async Task SaveAsync() { try { var typeManifestation = View.TypeManifestation; var shortName = View.ShortName; var fullName = View.FullName; var additionally = View.Additionally; if (string.IsNullOrWhiteSpace(shortName)) { throw new ArgumentNullException(null, "Вы не ввели краткое наименование причины обращения заказчика!"); } if (string.IsNullOrWhiteSpace(typeManifestation)) { throw new ArgumentNullException(null, "Вы не выбрали тип проявления!"); } using (var context = new DbSSContext()) { if (Identifier != null) { await context.Reason.Where(r => r.ID == (Guid)Identifier).UpdateAsync(r => new ReasonModel { Type = typeManifestation, ShortName = shortName, FullName = GetNullValue(fullName), Additionally = GetNullValue(additionally) }); } else { ReasonModel insertReasonInfo = new ReasonModel { ID = ConsistentGuid.CreateGuid(), Type = typeManifestation, ShortName = shortName, FullName = GetNullValue(fullName), Additionally = GetNullValue(additionally) }; context.Reason.Add(insertReasonInfo); await context.SaveChangesAsync(); Identifier = insertReasonInfo.ID; } } View.Close(); } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { if (_numberNomenclature == null) { throw new ArgumentNullException("_numberNomenclature", "Вы не выбрали работу!"); } if (_workingHourID == null) { throw new ArgumentNullException("_workingHourID", "Вы не выбрали нормочас!"); } var amount = View.Amount; var normOfTime = View.NormOfTime; using (var context = new DbSSContext()) { if (Identifier != null) { await context.Work.Where(w => w.ID == Identifier).UpdateAsync(w => new WorkModel { ID_workingHour = (Guid)_workingHourID, Number_nomenclature = (int)_numberNomenclature, Amount = amount, NormOfTime = normOfTime }); } else { WorkModel insertWorkInfo = new WorkModel { ID = ConsistentGuid.CreateGuid(), ID_reasonCustomer = _reasonCustomerID, ID_workingHour = (Guid)_workingHourID, Number_nomenclature = (int)_numberNomenclature, Amount = amount, NormOfTime = normOfTime }; context.Work.Add(insertWorkInfo); await context.SaveChangesAsync(); Identifier = insertWorkInfo.ID; } } View.Close(); } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { if (_numberNomenclature == null) { throw new ArgumentNullException(null, "Вы не выбрали материал!"); } var amount = View.Amount; var price = View.Price; using (var context = new DbSSContext()) { if (Identifier != null) { await context.Material.Where(w => w.ID == (Guid)Identifier).UpdateAsync(w => new MaterialModel { Number_nomenclature = (int)_numberNomenclature, Amount = amount, Price = price }); } else { MaterialModel insertMaterialInfo = new MaterialModel { ID = ConsistentGuid.CreateGuid(), ID_reasonCustomer = _reasonCustomerID, Number_nomenclature = (int)_numberNomenclature, Amount = amount, Customer = _customer, Price = price }; context.Material.Add(insertMaterialInfo); await context.SaveChangesAsync(); Identifier = insertMaterialInfo.ID; } } View.Close(); } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { var name = View.NameModel; if (_markID == null) { throw new ArgumentNullException(null, "Вы не выбрали модель"); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(null, "Вы не ввели имя модели"); } using (var context = new DbSSContext()) { if (Identifier != null) { await context.Model.Where(m => m.ID == Identifier).UpdateAsync(m => new ModelModel { ID_mark = (Guid)_markID, Name = name }); } else { ModelModel insertModelInfo = new ModelModel { ID = ConsistentGuid.CreateGuid(), ID_mark = (Guid)_markID, Name = name }; context.Model.Add(insertModelInfo); await context.SaveChangesAsync(); Identifier = insertModelInfo.ID; } } View.Close(); } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { if (_reasonID == null) { throw new ArgumentNullException(null, "Вы не выбрали причину обращения заказчика!"); } using (var context = new DbSSContext()) { if (Identifier != null) { Guid id = (Guid)_reasonID; await context.ReasonCustomer.Where(rc => rc.ID == _reasonID).UpdateAsync(rc => new ReasonCustomerModel { ID_reason = id }); } else { ReasonCustomerModel insertReasonCustomerInfo = new ReasonCustomerModel { ID = ConsistentGuid.CreateGuid(), ID_reason = (Guid)_reasonID, Number = _numberApplication }; context.ReasonCustomer.Add(insertReasonCustomerInfo); await context.SaveChangesAsync(); Identifier = insertReasonCustomerInfo.ID; _workJournal.ReasonCustomerID = Identifier; _materialJournal.ReasonCustomerID = Identifier; _materialCustomerJournal.ReasonCustomerID = Identifier; } } if (!openView) { View.Close(); } } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { var number = View.Number; var date = View.Date; if (string.IsNullOrWhiteSpace(number)) { throw new ArgumentNullException(null, "Введите номер доверености"); } using (var context = new DbSSContext()) { if (Identifier != null) { await context.PowerOfAttorney.Where(pa => pa.ID == (Guid)Identifier).UpdateAsync(pa => new PowerOfAttorneyModel { Number = number, Date = date }); } else { PowerOfAttorneyModel insertPowerOfAttorneyInfo = new PowerOfAttorneyModel { ID = ConsistentGuid.CreateGuid(), Number = number, Date = date, ID_contactPerson = _contactPersonID }; context.PowerOfAttorney.Add(insertPowerOfAttorneyInfo); await context.SaveChangesAsync(); Identifier = insertPowerOfAttorneyInfo.ID; } } View.Close(); } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { var name = View.NameWorkingHour; var price = View.Price; if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(null, "Вы не ввели наименование нормочаса!"); } using (var context = new DbSSContext()) { if (Identifier != null) { await context.WorkingHour.Where(w => w.ID == Identifier).UpdateAsync(w => new WorkingHourModel { Name = name, Price = price }); } else { WorkingHourModel insertWorkingHourInfo = new WorkingHourModel { ID = ConsistentGuid.CreateGuid(), Name = name, Price = price }; context.WorkingHour.Add(insertWorkingHourInfo); await context.SaveChangesAsync(); Identifier = insertWorkingHourInfo.ID; } } View.Close(); } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { var shortName = View.ShortName; var fullName = View.FullName; if (string.IsNullOrWhiteSpace(shortName)) { throw new ArgumentNullException(null, "Вы не ввели краткое наименование марки автомобиля"); } using (var context = new DbSSContext()) { if (Identifier != null) { await context.Mark.Where(m => m.ID == (Guid)Identifier).UpdateAsync(m => new MarkModel { ShortName = shortName, FullName = GetNullValue(fullName) }); } else { MarkModel insertMarkInfo = new MarkModel { ID = ConsistentGuid.CreateGuid(), ShortName = shortName, FullName = GetNullValue(fullName) }; context.Mark.Add(insertMarkInfo); await context.SaveChangesAsync(); Identifier = insertMarkInfo.ID; } } View.Close(); } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { var post = View.Post; if (string.IsNullOrWhiteSpace(post)) { throw new ArgumentNullException(null, "Вы не ввели должность сотрудника!"); } using (var context = new DbSSContext()) { if (Identifier != null) { await context.Post.Where(p => p.ID == (Guid)Identifier).UpdateAsync(p => new PostModel { Name = post }); } else { PostModel insertPostInfo = new PostModel { ID = ConsistentGuid.CreateGuid(), Name = post }; context.Post.Add(insertPostInfo); await context.SaveChangesAsync(); Identifier = insertPostInfo.ID; } } View.Close(); } catch (Exception ex) { ShowError(ex.Message); } }
internal override async Task <object> GetInfo() { bool exists = false; try { Guid id = Item.ID; int verificationExists = 0; using (var context = new DbSSContext()) { verificationExists = await context.OptionCustomer.Where(oc => oc.ID_option == id && oc.Number == _numberApplication).CountAsync(); if (verificationExists > 0) { ShowError("Эти коплектация уже находится у заказчика!"); exists = false; } else { context.OptionCustomer.Add(new OptionCustomerModel { ID = ConsistentGuid.CreateGuid(), ID_option = id, Number = _numberApplication }); await context.SaveChangesAsync(); exists = true; } } } catch (Exception ex) { ShowError(ex.Message); } return(exists); }
private async Task SaveUserAsync(string username, string password, bool administrator) { try { using (var context = new DbSSContext()) { if (_userInfo != null) { await context.User.Where(u => u.ID == _userInfo.ID).UpdateAsync(u => new UserModel { Name = username, Password = SHA256.Hash(password), Administrator = administrator }); } else { UserModel insertUserInfo = new UserModel { ID = ConsistentGuid.CreateGuid(), Name = username, Password = SHA256.Hash(password), Administrator = administrator, ID_employee = (Guid)Identifier }; context.User.Add(insertUserInfo); await context.SaveChangesAsync(); _userInfo = insertUserInfo; } } } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { var typeRepair = View.TypeRepair; var number = View.Number; var date = View.Date; var firstControlTime = View.FirstControlTime; var secondControlTime = View.SecondControlTime; var readiness = View.Readiness; var extradition = View.Extradition; var revealed = View.Revealed; var recommendations = View.Recommendations; if (_contractorID == null) { throw new ArgumentNullException(null, "Вы не выбрали контрагента!"); } if (_carID == null) { throw new ArgumentNullException(null, "Вы не выбрали автомобиль!"); } if (_contractPersonID != null && _powerOfAttorneyID == null) { throw new ArgumentNullException(null, "Вы не выбрали доверености контактного лица!"); } if (string.IsNullOrWhiteSpace(typeRepair)) { throw new ArgumentNullException(null, "Вы не выбрали тип ремонта!"); } if (_responsibleID == null) { throw new ArgumentNullException(null, "Вы не выбрали ответственное лицо!"); } using (var context = new DbSSContext()) { if (Identifier != null) { await context.Application.Where(a => a.Number.Equals(number)).UpdateAsync(a => new ApplicationModel { Date = date, FirstControlTime = firstControlTime, SecondControlTime = secondControlTime, Readiness = readiness, Extradition = extradition, Revealed = GetNullValue(revealed), Recommendations = GetNullValue(recommendations), Type = typeRepair, ID_employee = (Guid)_responsibleID, ID_car = (Guid)_carID, ID_powerOfAttorney = _powerOfAttorneyID }); } else { ApplicationModel insertApplicationInfo = new ApplicationModel { Number = number, Date = date, FirstControlTime = firstControlTime, SecondControlTime = secondControlTime, Readiness = readiness, Extradition = extradition, Revealed = GetNullValue(revealed), Recommendations = GetNullValue(recommendations), Type = typeRepair, ID_employee = (Guid)_responsibleID, ID_car = (Guid)_carID, ID_powerOfAttorney = _powerOfAttorneyID }; context.Application.Add(insertApplicationInfo); await context.SaveChangesAsync(); Identifier = insertApplicationInfo.Number; } } if (!openView) { View.Close(); } } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { var view = View.View; var shortName = View.ShortName; var INN = View.INN; var KPP = View.KPP; var OKPO = View.OKPO; var fullName = View.FullName; var phone = View.Phone; var email = View.Email; var address = View.Address; var additionally = View.Additionally; if (string.IsNullOrWhiteSpace(view)) { throw new ArgumentNullException(null, "Вы не выбрали вид контрагента!"); } if (string.IsNullOrWhiteSpace(shortName)) { throw new ArgumentNullException(null, "Вы не ввели краткое наименование контрагента!"); } if (!string.IsNullOrWhiteSpace(INN) && (INN.Length != 10 && INN.Length != 12)) { throw new ArgumentNullException(null, "ИНН должен состоять из 10 или 12 цифр!"); } if (!string.IsNullOrWhiteSpace(KPP) && KPP.Length != 9) { throw new ArgumentNullException(null, "ОКПО должен состоять из 10 цифр!"); } using (var context = new DbSSContext()) { if (Identifier != null) { await context.Contractor.Where(c => c.ID == (Guid)Identifier).UpdateAsync(c => new ContractorModel { View = view, ShortName = shortName, FullName = GetNullValue(fullName), INN = GetNullValue(INN), KPP = GetNullValue(KPP), OKPO = GetNullValue(OKPO), Phone = GetNullValue(phone), Email = GetNullValue(email), Address = GetNullValue(address), Additionally = GetNullValue(additionally) }); } else { Guid id = ConsistentGuid.CreateGuid(); ContractorModel insertContractorInfo = new ContractorModel { ID = id, View = view, ShortName = shortName, FullName = GetNullValue(fullName), INN = GetNullValue(INN), KPP = GetNullValue(KPP), OKPO = GetNullValue(OKPO), Phone = GetNullValue(phone), Email = GetNullValue(email), Address = GetNullValue(address), Additionally = GetNullValue(additionally) }; context.Contractor.Add(insertContractorInfo); await context.SaveChangesAsync(); Identifier = insertContractorInfo.ID; _contactNameJournal.ContractorID = id; _carJournal.ContractorID = id; } } if (!openView) { View.Close(); } } catch (Exception ex) { ShowError(ex.Message); } }
private async Task View_Loading() { try { var main = View.Main; _usersJournal = new EmployeeJournal(main.DGV_Employees, true); _workingHoursJournal = new WorkingHourJournal(main.DGV_WorkingHours); _unitsJournal = new UnitJournal(main.DGV_Unit); _nomenclaturesJournal = new NomenclatureJournal(main.DGV_Nomenclatures); _optionsJournal = new OptionJournal(main.DGV_Options); _reasonsJournal = new ReasonJournal(main.DGV_Reasons); _marksJournal = new MarkJournal(main.DGV_Marks); _modelsJournal = new ModelJournal(main.DGV_Models); _contractorsJournal = new ContractorJournal(main.DGV_Contractors); _applicationsJournal = new ApplicationJournal(main.DGV_Apptications); using (var context = new DbSSContext()) { int countViewСontractor = await context.ViewСontractor.CountAsync(); int countTypeManifestation = await context.TypeManifestation.CountAsync(); int countTypeRepair = await context.TypeRepair.CountAsync(); var countTypeNomenclature = await context.TypeNomenclature.CountAsync(); if (countViewСontractor == 0) { List <ViewСontractorModel> view = new List <ViewСontractorModel>() { new ViewСontractorModel { View = "Юридическое лицо" }, new ViewСontractorModel { View = "Физическое лицо" } }; context.ViewСontractor.AddRange(view); } if (countTypeManifestation == 0) { List <TypeManifestationModel> type = new List <TypeManifestationModel>() { new TypeManifestationModel { Type = "Внешнее" }, new TypeManifestationModel { Type = "Втуреннее" } }; context.TypeManifestation.AddRange(type); } if (countTypeRepair == 0) { List <TypeRepairModel> type = new List <TypeRepairModel>() { new TypeRepairModel { Type = "Гарантийный" }, new TypeRepairModel { Type = "Текущий" } }; context.TypeRepair.AddRange(type); } if (countTypeNomenclature == 0) { List <TypeNomenclatureModel> type = new List <TypeNomenclatureModel>() { new TypeNomenclatureModel { Type = "Товар" }, new TypeNomenclatureModel { Type = "Работа" } }; context.TypeNomenclature.AddRange(type); } await context.SaveChangesAsync(); } await _applicationsJournal.Update(); } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { var code = View.Code; var name = View.NameUnit; var shortName = View.ShortName; if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(null, "Вы не ввели наименование единицы измерения!"); } if (string.IsNullOrWhiteSpace(shortName)) { throw new ArgumentNullException(null, "Вы не ввели краткое наименование единицы измерения!"); } using (var context = new DbSSContext()) { int verihicationCode = context.Unit.Where(u => u.Code == code).Count(); if (Identifier != null) { if (Identifier != code && verihicationCode > 0) { ShowError("Такое код уже существует!"); return; } await context.Unit.Where(u => u.Code == (int)Identifier).UpdateAsync(u => new UnitModel { Code = code, Name = name, ShortName = shortName }); } else { if (verihicationCode > 0) { ShowError("Такое код уже существует!"); return; } UnitModel insertUnitInfo = new UnitModel { Code = code, Name = name, ShortName = shortName }; context.Unit.Add(insertUnitInfo); await context.SaveChangesAsync(); Identifier = insertUnitInfo.Code; } } View.Close(); } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { var VIN = View.VIN; var mileage = View.Mileage; var licensePlate = View.LicensePlate; var numberEngine = View.NumberEngine; var numberChassis = View.NumberChassis; var numberBody = View.NumberBody; var year = View.Year; var price = View.Price; var color = View.Color; if (_modelID == null) { throw new ArgumentNullException(null, "Вы не выбрали модель автомобиля!"); } if (string.IsNullOrWhiteSpace(VIN)) { throw new ArgumentNullException(null, "Вы не до конца ввели VIN автомобиля!"); } using (var context = new DbSSContext()) { if (Identifier != null) { await context.Car.Where(v => v.ID == (Guid)Identifier).UpdateAsync(v => new CarModel { VIN = VIN, ID_model = (Guid)_modelID, Mileage = mileage, LicensePlate = GetNullValue(licensePlate), NumberEngine = GetNullValue(numberEngine), NumberChassis = GetNullValue(numberChassis), NumberBody = GetNullValue(numberBody), Year = year, Price = price, Color = GetNullValue(color), ID_contractor = _contractorID }); } else { CarModel insertCarInfo = new CarModel { ID = ConsistentGuid.CreateGuid(), VIN = VIN, ID_model = (Guid)_modelID, LicensePlate = GetNullValue(licensePlate), NumberEngine = GetNullValue(numberEngine), NumberChassis = GetNullValue(numberChassis), NumberBody = GetNullValue(numberBody), Year = year, Mileage = mileage, Price = price, Color = GetNullValue(color), ID_contractor = _contractorID }; context.Car.Add(insertCarInfo); await context.SaveChangesAsync(); Identifier = insertCarInfo.ID; } } View.Close(); } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { var FFP = View.FFP; var phone = View.Phone; var email = View.Email; var address = View.Address; var additionally = View.Additionally; if (string.IsNullOrWhiteSpace(FFP)) { throw new ArgumentNullException(null, "Вы не ввели имя контактного лица!"); } using (var context = new DbSSContext()) { if (Identifier != null) { await context.ContactPerson.Where(cn => cn.ID == (Guid)Identifier).UpdateAsync(cn => new ContactPersonModel { FFP = FFP, Phone = GetNullValue(phone), Email = GetNullValue(email), Address = GetNullValue(address), Additionally = GetNullValue(additionally) }); } else { Guid id = ConsistentGuid.CreateGuid(); ContactPersonModel insertContactPersonInfo = new ContactPersonModel { ID = id, FFP = FFP, Phone = GetNullValue(phone), Email = GetNullValue(email), Address = GetNullValue(address), Additionally = GetNullValue(additionally), ID_сontractor = _contractorID }; context.ContactPerson.Add(insertContactPersonInfo); await context.SaveChangesAsync(); Identifier = insertContactPersonInfo.ID; _powerOfAttorneyJournal.ContactPersonID = id; } } if (!openView) { View.Close(); } } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { var number = View.Number; var shortName = View.ShortName; var fullName = View.FullName; var type = View.Type; var vendorCode = View.VendorCode; var price = View.Price; var descriprion = View.Descriprion; if (string.IsNullOrWhiteSpace(shortName)) { throw new ArgumentNullException(null, "Вы не ввели краткое наименование номенклатуры!"); } if (_codeUnit == null) { throw new ArgumentNullException(null, "Вы не выбрали единицу измерения номенклатуры!"); } using (var context = new DbSSContext()) { if (Identifier != null) { await context.Nomenclature.Where(n => n.Number == (int)Identifier).UpdateAsync(n => new NomenclatureModel { ShortName = shortName, FullName = GetNullValue(fullName), Type = type, Code_unit = (int)_codeUnit, VendorCode = GetNullValue(vendorCode), Price = price, Descriprion = GetNullValue(descriprion) }); } else { NomenclatureModel insertNomenclatureInfo = new NomenclatureModel() { Number = number, ShortName = shortName, FullName = GetNullValue(fullName), Type = type, Code_unit = (int)_codeUnit, VendorCode = GetNullValue(vendorCode), Price = price, Descriprion = GetNullValue(descriprion) }; context.Nomenclature.Add(insertNomenclatureInfo); await context.SaveChangesAsync(); Identifier = insertNomenclatureInfo.Number; } } View.Close(); } catch (Exception ex) { ShowError(ex.Message); } }
protected override async Task SaveAsync() { try { var FFP = View.FFP; var enterUser = View.EnterUser; var username = View.Username; var password = View.Password; var administrator = View.Administrator; if (string.IsNullOrWhiteSpace(FFP)) { throw new ArgumentNullException(null, "Вы не ввели фамилию, имя и отчество сотрудника!"); } if (_postID == null) { throw new ArgumentNullException(null, "Вы не выбрали должность сотрудника!"); } if (enterUser && string.IsNullOrWhiteSpace(username)) { throw new ArgumentNullException(null, "Вы не ввели имя пользователя!"); } if (enterUser && string.IsNullOrWhiteSpace(password)) { throw new ArgumentNullException(null, "Вы не ввели пароль сотрудника!"); } using (var context = new DbSSContext()) { if (Identifier != null) { await context.Employee.Where(e => e.ID == (Guid)Identifier).UpdateAsync(e => new EmployeeModel { FFP = FFP, ID_post = (Guid)_postID }); } else { EmployeeModel insertEmployeeInfo = new EmployeeModel { ID = ConsistentGuid.CreateGuid(), FFP = FFP, ID_post = (Guid)_postID }; context.Employee.Add(insertEmployeeInfo); await context.SaveChangesAsync(); Identifier = insertEmployeeInfo.ID; } } if (View.EnterUser) { await SaveUserAsync(username, password, administrator); } View.Close(); } catch (Exception ex) { ShowError(ex.Message); } }