private void FillEntity(int id) { using (kipEntities context = new kipEntities()) { type = context.MVPSTypeSet.Where(b => b.Id == id).SingleOrDefault(); MVPSTypeBox.Text = type.name; } AddButton.Text = "Сохранить"; }
private void AddButton_Click(object sender, EventArgs e) { using (kipEntities context = new kipEntities()) { try { if (MVPSTypeBox.Text == "Введите название типа МВПС") { throw new Exception("Введите коректное название типа МВПС"); } if (type != null) { int key = type.Id; MVPSType freshType = context.MVPSTypeSet.Where(b => b.Id == key).SingleOrDefault(); string str = MVPSTypeBox.Text; if ((freshType.name != str) && (str != "")) { freshType.name = str; context.SaveChanges(); } } else { string str = MVPSTypeBox.Text; if (str != "") { MVPSType freshType = new MVPSType { name = str }; context.MVPSTypeSet.Add(freshType); context.SaveChanges(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Close(); } } }
public static void FillGrid(ListBox list, DataGridView view) { var str = ""; if (list.SelectedItem != null) { str = list.SelectedItem.ToString(); } gridView = view; listBox = list; switch (str) { case "Оборудование": Equipment.FillGrid(view); break; case "Типы оборудования": EquipmentType.FillGrid(view); break; case "Производители": Manufacturer.FillGrid(view); break; case "Типы систем": SystemType.FillGrid(view); break; case "Роли МВПС": MVPSRole.FillGrid(view); break; case "Типы МВПС": MVPSType.FillGrid(view); break; case "МВПС": MVPS.FillGrid(view); break; case "Правила компелктования": EquipmentRule.FillGrid(view); break; case "Замены оборудования": ReplacingLog.FillGrid(view); break; case "Работники": Worker.FillGrid(view); break; case "Должности": Position.FillGrid(view); break; case "График ТО и ТР": Shedule.FillGrid(view); break; case "Журнал проверки/ремонта": ServiceLog.FillGrid(view); break; default: break; } }
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(); } } }