private void AddButton_Click(object sender, EventArgs e) { using (kipEntities context = new kipEntities()) { try { CheckFields(); if (manufacturer != null) { int key = manufacturer.Id; Manufacturer freshMan = context.ManufacturerSet.Where(b => b.Id == key).SingleOrDefault(); string str = ManufacturerNameBox.Text; if ((freshMan.name != str) && (str != "")) { freshMan.name = str; } if ((ManufacturerAddressBox.Text != "") && (ManufacturerAddressBox.Text != freshMan.address)) { freshMan.address = ManufacturerAddressBox.Text; } if ((ManufacturerPhoneBox.Text != "") && (ManufacturerPhoneBox.Text != freshMan.phone)) { freshMan.phone = ManufacturerPhoneBox.Text; } if ((ManufacturerEmailBox.Text != "") && (ManufacturerEmailBox.Text != freshMan.email)) { freshMan.email = ManufacturerEmailBox.Text; } context.SaveChanges(); } else { CheckFields(); string str = ManufacturerNameBox.Text; if (str != "") { Manufacturer freshMan = new Manufacturer { name = str, address = ManufacturerAddressBox.Text, phone = ManufacturerPhoneBox.Text, email = ManufacturerEmailBox.Text, }; context.ManufacturerSet.Add(freshMan); context.SaveChanges(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Close(); } } }
private void AddButton_Click(object sender, EventArgs e) { using (kipEntities context = new kipEntities()) { try { if (SystemTypeNameBox.Text == "Введите название системы") { throw new Exception("Введите коректное название системы"); } if (SystemTypeDescriptionBox.Text == "Введите описание системы") { throw new Exception("Введите коректное описание системы"); } if (type != null) { int key = type.Id; SystemType freshSysType = context.SystemTypeSet.Where(b => b.Id == key).SingleOrDefault(); string str = SystemTypeNameBox.Text; if (str != "") { if (str != freshSysType.name) { freshSysType.name = str; } if (SystemTypeDescriptionBox.Text != freshSysType.description) { freshSysType.description = SystemTypeDescriptionBox.Text; } context.SaveChanges(); } } else { string str = SystemTypeNameBox.Text; if (str != "") { SystemType freshSysType = new SystemType { name = str, description = SystemTypeDescriptionBox.Text }; context.SystemTypeSet.Add(freshSysType); context.SaveChanges(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Close(); } } }
private void MvpsGrid_CellDoubleClick(Object sender, DataGridViewCellEventArgs e) { if (CheckAllSelected() && !CheckEmpty()) { using (kipEntities context = new kipEntities()) { Guid id = Guid.Parse(mvpsGrid[0, e.RowIndex].Value.ToString()); Equipment equipment = context.EquipmentSet.Where(b => b.Id == id).SingleOrDefault(); DialogResult result = MessageBox.Show("Нажмите \"Да\", если блок снимается по неисправности. Если блок снимается по другой причине - нажмите \"Нет\"", "Снимаем " + equipment.EquipmentType.name + " № " + equipment.number, MessageBoxButtons.YesNoCancel); MVPS mvps = context.MVPSSet.Where(b => b.Id == mvpsGuid).SingleOrDefault(); equipment.isFree = true; mvps.Equipment.Remove(equipment); context.SaveChanges(); switch (result) { case DialogResult.Yes: equipment.isWorking = false; equipment.isFree = true; mvps.Equipment.Remove(equipment); if (worker != null) { OutGuid = equipment.Id; input = Microsoft.VisualBasic.Interaction.InputBox("Введите комментарий к замене", "Замена оборудования", "По сроку.", -1, -1); } context.SaveChanges(); break; case DialogResult.No: equipment.isFree = true; mvps.Equipment.Remove(equipment); if (worker != null) { OutGuid = equipment.Id; input = Microsoft.VisualBasic.Interaction.InputBox("Введите комментарий к замене", "Замена оборудования", "По сроку.", -1, -1); } context.SaveChanges(); break; case DialogResult.Cancel: break; } } FillGrid(); } }
public static void DoRepairOrCheck(Worker worker, List <string> descriptions, bool isRepair_) { int i = 0; foreach (var item in Items.GetItems) { using (kipEntities context = new kipEntities()) { Guid guid = Guid.Parse(item.Block.Id); var eq = context.EquipmentSet.Where(b => b.Id == guid).SingleOrDefault(); var performer = context.WorkerSet.Where(b => b.Id == worker.Id).SingleOrDefault(); if (eq == null) { throw new Exception("Не найден блок с идентификатором " + guid.ToString()); } else { eq.isWorking = true; eq.serviceDate = DateTime.Today.Date; var service = new ServiceLog { date = DateTime.Now, description = descriptions[i++], Equipment = eq, isRepair = isRepair_, Performer = performer }; context.ServiceLogSet.Add(service); eq.ServiceLog.Add(service); context.SaveChanges(); } } } }
private void PictureBox1_Click(object sender, EventArgs e) { ///ToDo: не пускать этот код в продакшн using (kipEntities context = new kipEntities()) { Worker worker = context.WorkerSet.Include("Position").Where(b => b.PersonnelNumber == 11179474).SingleOrDefault(); if (worker == null) { Position pos = context.PositionSet.Where(b => b.name == "Администратор").SingleOrDefault(); if (pos == null) { pos = new Position { name = "Администратор", }; context.PositionSet.Add(pos); } worker = new Worker { Position = pos, Name = "Тестовый", Family = "Профиль", Patronymic = "Администатора", PersonnelNumber = 11100000, PinCodeHash = "" }; context.WorkerSet.Add(worker); context.SaveChanges(); } var position = worker.Position.Id; GetNextForm(position, worker); } }
private void AddButton_Click(object sender, EventArgs e) { using (kipEntities context = new kipEntities()) { try { if (MVPSRoleBox.Text == "Введите название роли МВПС") { throw new Exception("Введите коректное название роли МВПС"); } if (role != null) { int key = role.Id; MVPSRole freshRole = context.MVPSRoleSet.Where(b => b.Id == key).SingleOrDefault(); string str = MVPSRoleBox.Text; if ((freshRole.name != str) && (str != "")) { freshRole.name = str; context.SaveChanges(); } } else { string str = MVPSRoleBox.Text; if (str != "") { MVPSRole freshRole = new MVPSRole { name = str }; context.MVPSRoleSet.Add(freshRole); context.SaveChanges(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Close(); } } }
private void EquipmentGrid_CellDoubleClick(Object sender, DataGridViewCellEventArgs e) { if (CheckAllSelected() && CheckEmpty()) { if (equipmentGrid[0, e.RowIndex].Value.ToString() != "") { using (kipEntities context = new kipEntities()) { Guid id = Guid.Parse(equipmentGrid[0, e.RowIndex].Value.ToString()); Equipment equipment = context.EquipmentSet.Where(b => b.Id == id).SingleOrDefault(); MVPS mvps = context.MVPSSet.Where(b => b.Id == mvpsGuid).SingleOrDefault(); equipment.isFree = false; mvps.Equipment.Add(equipment); if (worker != null) { if (OutGuid.Equals(Guid.Empty)) { throw new Exception("Не найдена начатая замена. Если вы не снимали соотвествующее оборудование - обратитесь к мастеру или администратору"); } else { Replacing(context, equipment.Id, OutGuid, mvps, input); } } context.SaveChanges(); } FillGrid(); } } else { MessageBox.Show("Что-то пошло не так, возможно вы пытаетесь установить блок на занятую позицию."); } }
private void RemoveFromShed(int v) { using (kipEntities context = new kipEntities()) { var shedule = context.SheduleSet.Where(b => b.date == dateTimePicker1.Value.Date).SingleOrDefault(); if (shedule == null) { shedule = new Shedule() { date = dateTimePicker1.Value.Date, }; context.SheduleSet.Add(shedule); } var strings = DayMVPSList.Items[v].ToString().Split(' '); var repairOrMaintenance = strings[0]; var type = strings[1]; var series = strings[2]; var mvps = context.MVPSSet.Where(b => b.series == series && b.MVPSType.name == type).First(); if (repairOrMaintenance == "ТО3") { shedule.MVPS_Maintenance.Remove(mvps); } else if (repairOrMaintenance == "ТР1") { shedule.MVPS_Repair.Remove(mvps); } context.SaveChanges(); FillTable(); } }
private void AddToShed(bool isRepair) { CheckFields(); { using (kipEntities context = new kipEntities()) { var shedule = context.SheduleSet.Where(b => b.date == dateTimePicker1.Value.Date).SingleOrDefault(); if (shedule == null) { shedule = new Shedule() { date = dateTimePicker1.Value.Date, }; context.SheduleSet.Add(shedule); } var strings = MVPSSeriesBox.SelectedItem.ToString().Split(' '); var type = strings[0]; var series = strings[1]; var mvps = context.MVPSSet.Where(b => b.series == series && b.MVPSType.name == type).First(); if (isRepair) { shedule.MVPS_Repair.Add(mvps); } else { shedule.MVPS_Maintenance.Add(mvps); } context.SaveChanges(); FillTable(); FillList(); } } }
private void AddButton_Click(object sender, EventArgs e) { using (kipEntities context = new kipEntities()) { try { CheckFields(); int _sysTypeId = sysTypeId[SysTypeBox.SelectedIndex]; int _manufactId = manufactId[ManufactBox.SelectedIndex]; var sysType = context.SystemTypeSet.Where(b => b.Id == _sysTypeId).SingleOrDefault(); var manf = context.ManufacturerSet.Where(b => b.Id == _manufactId).SingleOrDefault(); bool hasVerf = int.TryParse(VerificationPeriodBox.Text, out int verf); bool hasServ = int.TryParse(ServicePeriodBox.Text, out int serv); if (!hasServ) { throw new Exception("Введите срок проверки"); } if (type == null) { type = new EquipmentType { name = NameBox.Text, description = DescriptionBox.Text, SystemType = sysType, Manufacturer = manf, verfPeriod = verf, servicePeriod = serv }; context.EquipmentTypeSet.Add(type); } else { int key = type.Id; EquipmentType freshEqType = context.EquipmentTypeSet.Where(b => b.Id == key).SingleOrDefault(); if (freshEqType.name != NameBox.Text) { freshEqType.name = NameBox.Text; } if (freshEqType.description != DescriptionBox.Text) { freshEqType.description = DescriptionBox.Text; } if (freshEqType.SystemType != sysType) { freshEqType.SystemType = sysType; } if (freshEqType.Manufacturer != manf) { freshEqType.Manufacturer = manf; } if (freshEqType.servicePeriod != serv) { freshEqType.servicePeriod = serv; } if (freshEqType.verfPeriod != verf) { freshEqType.verfPeriod = verf; } } context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } //type = null; sysTypeId.Clear(); manufactId.Clear(); Close(); }
private void AddButton_Click(object sender, EventArgs e) { using (kipEntities context = new kipEntities()) { try { int _roleId = roleId[MVPSRoleBox_.SelectedIndex]; int _typeId = typeId[MVPSTypeBox_.SelectedIndex]; var role = context.MVPSRoleSet.Where(b => b.Id == _roleId).SingleOrDefault(); var type = context.MVPSTypeSet.Where(b => b.Id == _typeId).SingleOrDefault(); List <EquipmentType> eqList = new List <EquipmentType>(); foreach (int k in InRuleEqId) { var equipmentTypes = context.EquipmentTypeSet.Where(b => b.Id == k).SingleOrDefault(); eqList.Add(equipmentTypes); } if (rule == null) { context.EquipmentRuleSet.Add(new EquipmentRule { MVPSRole = role, MVPSType = type, EquipmentType = eqList }); } else { int key = rule.Id; EquipmentRule freshRule = context.EquipmentRuleSet.Where(b => b.Id == key).SingleOrDefault(); if (freshRule.MVPSRole != role) { freshRule.MVPSRole = role; } if (freshRule.MVPSType != type) { freshRule.MVPSType = type; } if (freshRule.EquipmentType != eqList) { freshRule.EquipmentType = eqList; } } context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } rule = null; sysTypeId.Clear(); roleId.Clear(); typeId.Clear(); eqTypeId.Clear(); InRuleEqId.Clear(); Close(); }
private void AddButton_Click(object sender, EventArgs e) { using (kipEntities context = new kipEntities()) { try { if (!ChechFields()) { throw new Exception("Все поля обязательны к заполнению. Заполните их."); } string pos = PositionBox.Items[PositionBox.SelectedIndex].ToString(); if (worker != null) { Worker freshWorker = context.WorkerSet.Where(b => b.Id == worker.Id).SingleOrDefault(); if (freshWorker.Name != NameBox.Text) { freshWorker.Name = NameBox.Text; } if (freshWorker.Family != FamilyBox.Text) { freshWorker.Family = FamilyBox.Text; } if (freshWorker.Patronymic != PatronymicBox.Text) { freshWorker.Patronymic = PatronymicBox.Text; } if (freshWorker.PersonnelNumber != int.Parse(PersonnelNumberBox.Text)) { freshWorker.PersonnelNumber = int.Parse(PersonnelNumberBox.Text); } if (freshWorker.Position.name != pos) { Position position = context.PositionSet.Where(b => Name == pos).SingleOrDefault(); freshWorker.Position = position; } context.SaveChanges(); } else { Position position = context.PositionSet.Where(b => b.name == pos).SingleOrDefault(); SHA1 sha = new SHA1CryptoServiceProvider(); var buffer = Encoding.Unicode.GetBytes("0000"); byte[] result = sha.ComputeHash(buffer); string hash = Convert.ToBase64String(result); worker = new Worker { Name = NameBox.Text, Family = FamilyBox.Text, Patronymic = PatronymicBox.Text, PersonnelNumber = int.Parse(PersonnelNumberBox.Text), Position = position, PinCodeHash = hash }; context.WorkerSet.Add(worker); context.SaveChanges(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Close(); } } }
private void AddButton_Click(object sender, EventArgs e) { Guid guid = mVPS == null? Guid.Empty : mVPS.Id; using (kipEntities context = new kipEntities()) { try { CheckFields(); if (mVPS != null) { int typeId = typeIds[TypeBox.SelectedIndex]; int roleId = roleIds[RoleBox.SelectedIndex]; int ruleId = currentRules[RuleBox.SelectedIndex].Id; MVPSType type = context.MVPSTypeSet.Where(b => b.Id == typeId).SingleOrDefault(); MVPSRole role = context.MVPSRoleSet.Where(b => b.Id == roleId).SingleOrDefault(); EquipmentRule rule = context.EquipmentRuleSet.Where(b => b.Id == ruleId).SingleOrDefault(); MVPS mVPS = context.MVPSSet.Where(b => b.Id == guid).SingleOrDefault(); if (mVPS.MVPSRole.Id != role.Id) { mVPS.MVPSRole = role; } if (mVPS.MVPSType.Id != type.Id) { mVPS.MVPSType = type; } if (mVPS.number != NumberBox.Text) { mVPS.number = NumberBox.Text; } if (mVPS.series != SeriesBox.Text) { mVPS.series = SeriesBox.Text; } if (mVPS.EquipmentRule.Id != rule.Id) { mVPS.EquipmentRule = rule; } context.SaveChanges(); } else { int typeId = typeIds[TypeBox.SelectedIndex]; int roleId = roleIds[RoleBox.SelectedIndex]; int ruleId = currentRules[RuleBox.SelectedIndex].Id; MVPSType type = context.MVPSTypeSet.Where(b => b.Id == typeId).SingleOrDefault(); MVPSRole role = context.MVPSRoleSet.Where(b => b.Id == roleId).SingleOrDefault(); EquipmentRule rule = context.EquipmentRuleSet.Where(b => b.Id == ruleId).SingleOrDefault(); mVPS = new MVPS { Id = Guid.Parse(IdBox.Text), number = NumberBox.Text, series = SeriesBox.Text, MVPSType = type, MVPSRole = role, EquipmentRule = rule }; context.MVPSSet.Add(mVPS); context.SaveChanges(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { roleIds.Clear(); typeIds.Clear(); currentRules.Clear(); Close(); } } }
private void AddButton_Click(object sender, EventArgs e) { using (kipEntities context = new kipEntities()) { try { CheckFields(); int typeId = typeIds[TypeBox.SelectedIndex]; var type = context.EquipmentTypeSet.Where(b => b.Id == typeId).SingleOrDefault(); DateTime dateTimeRepair = DateTime.Parse(RepairDate.Text); DateTime dateTimeService = DateTime.Parse(ServiceDate.Text); //DateTime dateTimeVerification = DateTime.Parse(VerificationDate.Text); DateTime?VerificationDate; DateTime?TerminationDate; bool hasDate = DateTime.TryParse(this.VerificationDate.Text, out DateTime term); if (hasDate) { VerificationDate = term; } else { VerificationDate = null; } hasDate = DateTime.TryParse(this.TerminationDate.Text, out term); if (hasDate) { TerminationDate = term; } else { TerminationDate = null; } if (this.VerificationDate.Enabled) { if (!DateTime.TryParse(this.VerificationDate.Text, out DateTime time)) { throw new Exception("Введена некорректная дата в поле даты поверки. Введите дату вида - дд.мм.гг"); } } if (eq != null) { Guid id = eq.Id; Equipment equipment = context.EquipmentSet.Where(b => b.Id == id).SingleOrDefault(); if (equipment.EquipmentType.Id != typeId) { equipment.EquipmentType = type; } if (equipment.number != NumberBox.Text) { equipment.number = NumberBox.Text; } if (equipment.repairDate != dateTimeRepair) { equipment.repairDate = dateTimeRepair; } if (equipment.serviceDate != dateTimeService) { equipment.serviceDate = dateTimeService; } if (equipment.nextVerificationDate != VerificationDate) { equipment.nextVerificationDate = VerificationDate; } if (equipment.termDate != TerminationDate) { equipment.termDate = TerminationDate; } if (equipment.isWorking != IsWorking.Checked) { equipment.isWorking = IsWorking.Checked; } if (equipment.isFree != IsFree.Checked) { equipment.isFree = IsFree.Checked; } context.SaveChanges(); } else { eq = new Equipment { Id = Guid.Parse(IdBox.Text), EquipmentType = type, number = NumberBox.Text, repairDate = dateTimeRepair, serviceDate = dateTimeService, nextVerificationDate = VerificationDate, termDate = TerminationDate, isWorking = IsWorking.Checked, isFree = IsFree.Checked }; context.EquipmentSet.Add(eq); context.SaveChanges(); } Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }