//Заменить в проекте private void itemReplace_Click(object sender, EventArgs e) { string connectionNumber; using (frmInputBox frm = new frmInputBox(_project, 2 /*замена*/)) { if (frm.ShowDialog() == DialogResult.OK) { connectionNumber = frm.GetTxtValue; ProjectEquipment pe = EquipServices.ReplaceProjectCbr(_project, connectionNumber, bs_Cbr.Current as CurrentBreaker); bs_CbrPrj.DataSource = EquipServices.GetProjectCbr(_project, false); if (EquipServices.GetCbrAnalog(pe, bs_Cbr.Current as CurrentBreaker)) { AnalogDataSourceLoad(DefaultForeColor, bs_CbrAn.Count.ToString()); } else { AnalogDataSourceLoad(Color.Red, "не найдено"); } } else { return; } } }
//открепить аналоги оборудования от проекта public List <ProjectEquipment> DisattachAnalog(ProjectEquipment pe, Project project, bool justAnalog) { using (DataEntities db = new DataEntities()) { if (!justAnalog) { var sql = from pean in db.ProjectEquipments where pean.IdNote == pe.IdNote && pean.Analog == true select pean; if (sql != null) { foreach (ProjectEquipment peq in sql) { db.ProjectEquipments.Attach(peq); db.ProjectEquipments.Remove(peq); } } } else { db.ProjectEquipments.Attach(pe); db.ProjectEquipments.Remove(pe); } db.SaveChanges(); return(GetAllEquipCbr(project, true)); } }
//подбор аналогов 2.0 public bool GetCbrAnalog(ProjectEquipment pe, CurrentBreaker cbr) { using (DataEntities db = new DataEntities()) { var listAnalog = from cban in db.CurrentBreakers where cban.IdDisCurrent == cbr.IdDisCurrent && cban.IdCbCurrent == cbr.IdCbCurrent && cban.IdIcuValue == cbr.IdIcuValue && cban.IdDisType == cbr.IdDisType && cban.IdPoleNumber == cbr.IdPoleNumber select cban; if (listAnalog.Count() > 1) { foreach (CurrentBreaker c in listAnalog) { ProjectEquipment newpe = new ProjectEquipment(); if (c.Id != cbr.Id) //исключить текущий выключатель из подбора аналогов { if (pe.IdProjectNumber != null) { newpe.IdProjectNumber = pe.IdProjectNumber; } newpe.IdCbr = c.Id; newpe.Analog = true; newpe.IdNote = pe.IdNote; db.ProjectEquipments.Add(newpe); } } db.SaveChanges(); return(true); } else { ProjectEquipment notAnalog = new ProjectEquipment(); if (pe.IdProjectNumber != null) { notAnalog.IdProjectNumber = pe.IdProjectNumber; } notAnalog.IdCbr = 4354; // нет аналога notAnalog.Analog = true; notAnalog.IdNote = pe.IdNote; db.ProjectEquipments.Add(notAnalog); db.SaveChanges(); return(false); } } }
//обновить таблицу обозначений оборудования public List <EquipNote> UpdateTable(ProjectEquipment pe, string newText) { using (DataEntities db = new DataEntities()) { EquipNote note = (from pn in db.EquipNotes where pn.Id == pe.IdNote select pn).SingleOrDefault(); note.Text = newText; db.EquipNotes.Attach(note); db.Entry(note).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(db.EquipNotes.ToList()); } }
//добавление выключателя в проект private void InsertCbr(string connectionNumber) { ProjectEquipment pe = EquipServices.AttachCbr(_project, bs_Cbr.Current as CurrentBreaker, connectionNumber); bs_CbrPrj.DataSource = EquipServices.GetProjectCbr(_project, false); bs_CbrEquip.DataSource = EquipServices.GetAllEquipCbr(_project, false); bs_EquipNote.DataSource = EquipServices.GetAllProjectNote(); if (EquipServices.GetCbrAnalog(pe, bs_Cbr.Current as CurrentBreaker)) { AnalogDataSourceLoad(DefaultForeColor, string.Empty); } else { AnalogDataSourceLoad(Color.Red, "не найдено"); } }
//добавить контактор в проект public ProjectEquipment AttachContactor(Project project, Contactor cont, string note) { using (DataEntities db = new DataEntities()) { ProjectEquipment pe = new ProjectEquipment(); if (project.IdNumber != 0) { pe.IdProjectNumber = project.IdNumber; } pe.IdCont = cont.Id; pe.Analog = false; db.ProjectEquipments.Add(pe); db.SaveChanges(); return(pe); } }
//открепить основное оборудование от проекта public List <ProjectEquipment> DisattachBase(ProjectEquipment pe, Project project) { using (DataEntities db = new DataEntities()) { var notes = from pn in db.EquipNotes where pn.Id == pe.IdNote select pn; foreach (EquipNote note in notes) { db.EquipNotes.Attach(note); db.EquipNotes.Remove(note); } db.ProjectEquipments.Attach(pe); db.ProjectEquipments.Remove(pe); db.SaveChanges(); return(GetAllEquipCbr(project, false)); } }
//добавить выключатель в проект public ProjectEquipment AttachCbr(Project project, CurrentBreaker cbr, string connectionNumber) { using (DataEntities db = new DataEntities()) { ProjectEquipment pe = new ProjectEquipment(); if (project.IdNumber != 0) { pe.IdProjectNumber = project.IdNumber; pe.IdNote = InsertProjectNote(cbr, project, connectionNumber); } else { pe.IdNote = InsertProjectNote(cbr, null, connectionNumber); } pe.IdCbr = cbr.Id; pe.Analog = false; db.ProjectEquipments.Add(pe); db.SaveChanges(); return(pe); } }
//открепить аналоги оборудования от проекта public static List <ProjectEquipment> DisattachAnalog(ProjectEquipment pe, Project project, bool justAnalog) { return(equipobj.DisattachAnalog(pe, project, justAnalog)); }
//открепить оборудование от проекта public static List <ProjectEquipment> DisattachBase(ProjectEquipment pe, Project project) { return(equipobj.DisattachBase(pe, project)); }
//обновить таблицу оборудования public static List <EquipNote> UpdateTable(ProjectEquipment pe, string newText) { return(equipobj.UpdateTable(pe, newText)); }
//подбор аналогов 2.0 public static bool GetCbrAnalog(ProjectEquipment pe, CurrentBreaker cbr) { return(equipobj.GetCbrAnalog(pe, cbr)); }
//добавление контактора в проект private void InsertCnt(string connectionNumber) { ProjectEquipment pe = EquipServices.AttachContactor(_project, bs_Cont.Current as Contactor, connectionNumber); bs_ContPrj.DataSource = EquipServices.GetAllProjectCont(_project, false); }