/// <summary> /// Handles the Click event of the btn_CritCreate control. /// Holt die Einträge aus den Textboxen, überprüft diese auf unerlaubte Sonderzeichen und speichert das neue Kriterium ab /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> /// Erstellt von Veit Berg, am 27.01.16 private void btn_CritCreate_Click(object sender, EventArgs e) { //try{ String Name = textBox_CritNameCreate.Text; String Desc = textBox_CritDescCreate.Text; if (CommonMethods.ChreckIfStringIsEmpty(Name) || CommonMethods.ChreckIfStringIsEmpty(Desc)) { MessageBox.Show(CommonMethods.MessageTextIsEmpty()); } else { if (CommonMethods.CheckIfForbiddenDelimiterInDb(Name) || CommonMethods.CheckIfForbiddenDelimiterInDb(Desc)) { MessageBox.Show(CommonMethods.MessageForbiddenDelimiterWasFoundInText()); } else { Criterion Crit = new Criterion { Name = Name, Description = Desc }; this.critCont.InsertCriterionIntoDb(Crit); this.Close(); } } //} //catch (Exception x) //{ // MessageBox.Show(x.Message); //} }
/// <summary> /// Gets the criterion by line from import file. /// </summary> /// <param name="criterionImportLine">The criterion import line.</param> /// <returns></returns> /// Erstellt von Joshua Frey, am 15.01.2016 private Criterion GetCriterionByLineFromImportFile(string criterionImportLine) { Criterion importCriterion; // Criterion_Id|Name|Description var lineAsArray = criterionImportLine.Split(this._delimiter); int criterionId; try { criterionId = Convert.ToInt32(lineAsArray[0]); } catch (FormatException formatException) { throw new NWATException(String.Format("{0}\n\n{1}", formatException, MessageWrongDatatypeInExportedLine("Criterion", criterionImportLine, "int|string|string"))); } importCriterion = new Criterion() { Criterion_Id = criterionId, Name = lineAsArray[1], Description = lineAsArray[2] }; return importCriterion; }
/* * Private Section */ /// <summary> /// Checks if equal criterions. /// </summary> /// <param name="critOne">The crit one.</param> /// <param name="critTwo">The crit two.</param> /// <returns> /// bool if given criterions have equal properties /// </returns> /// Erstellt von Joshua Frey, am 14.12.2015 private bool CheckIfEqualCriterions(Criterion critOne, Criterion critTwo) { bool equalName = critOne.Name == critTwo.Name; bool equalDescription = critOne.Description == critTwo.Description; return equalName && equalDescription; }
/// <summary> /// Return messages if all child project criterions should be deallocated. /// </summary> /// <param name="projectCriterionChildren">The project criterion children.</param> /// <param name="deleteCriterion">The delete criterion.</param> /// <returns></returns> /// Erstellt von Joshua Frey, am 13.01.2016 private string MessageDeleteAllChildProjectCriterions(List<ProjectCriterion> projectCriterionChildren, Criterion deleteCriterion) { string begin = String.Format("Das Kriterium {0} (Id={1}) hat folgende Projektkriterien als untergeordnete Kriterien:\n\n", deleteCriterion.Name, deleteCriterion.Criterion_Id); string projectCriterionChildrenListAsString = ""; foreach (ProjectCriterion projCrit in projectCriterionChildren) { projectCriterionChildrenListAsString += String.Format(" - Projekt: {0} (Id={1})\n Kindkriterium: {2} (Id={3})\n\n", projCrit.Project.Name, projCrit.Project_Id, projCrit.Criterion.Name, projCrit.Criterion_Id); } string end = "\nWenn Sie das Kriterium löschen, entkoppeln sie auch alle \n"+ "untergeordneten Kriterien und deren untergeordneten Kriterien usw. \n"+ "von allen betroffenen Projekten. \n" + "Sind Sie sich sicher, dass Sie das Kriterium löschen wollen?"; return begin + projectCriterionChildrenListAsString + end; }
/// <summary> /// Updates the criterion in database. /// </summary> /// <param name="alteredCriterion">The altered criterion.</param> /// <returns> /// bool if update of criterion was successful /// </returns> /// Erstellt von Joshua Frey, am 14.12.2015 /// <exception cref="NWATException"> /// Das Kriterium mit dem Namen -Kriteriumname- existiert bereits in einem anderen Datensatz in der Datenbank. /// or /// Das Kriterium konnte nicht in der Datenbank gespeichert werden. /// Bitte überprüfen Sie das übergebene Kriterium Objekt. /// or /// Das Criterion Object besitzt keine ID. Bitte überprüfen Sie das übergebene Object /// </exception> public bool UpdateCriterionInDb(Criterion alteredCriterion) { if (!CheckIfCriterionHasAnId(alteredCriterion)) throw (new NWATException(MessageCriterionHasNoId())); int criterionId = alteredCriterion.Criterion_Id; Criterion critToUpdateFromDb = base.DataContext.Criterion.SingleOrDefault(crit=>crit.Criterion_Id==criterionId); if (critToUpdateFromDb != null) { string newCriterionName = alteredCriterion.Name; if (!CheckIfCriterionNameAlreadyExists(newCriterionName, criterionId)) { critToUpdateFromDb.Name = alteredCriterion.Name; critToUpdateFromDb.Description = alteredCriterion.Description; } else { throw (new NWATException(MessageCriterionAlreadyExists(newCriterionName))); } } else { throw (new NWATException(MessageCriterionDoesNotExist(criterionId) + "\n" + MessageCriterionCouldNotBeSavedEmptyObject())); } base.DataContext.SubmitChanges(); Criterion alteredCriterionFromDb = GetCriterionById(criterionId); return CheckIfEqualCriterions(alteredCriterion, alteredCriterionFromDb); }
/// <summary> /// Checks if product has an identifier. /// </summary> /// <param name="prod">The product.</param> /// <returns> /// bool if Criterion has an id and it differs zero /// </returns> /// Erstellt von Joshua Frey, am 15.12.2015 private bool CheckIfCriterionHasAnId(Criterion crit) { if (crit.Criterion_Id == 0) return false; else return true; }
/// <summary> /// Inserts the criterion into database. /// </summary> /// <param name="newCriterion">The new criterion.</param> /// <returns> /// bool if insert of new criterion was successfull. /// </returns> /// Erstellt von Joshua Frey, am 14.12.2015 /// <exception cref="NWATException"> /// </exception> public bool InsertCriterionIntoDb(Criterion newCriterion) { if (newCriterion != null) { // if insert Id is != 0 then this criterion will be imported at the index of insertId bool willBeImported = newCriterion.Criterion_Id != 0; string newCriterionName = newCriterion.Name; if (!CheckIfCriterionNameAlreadyExists(newCriterionName)) { if (willBeImported) { if (CheckIfCriterionIdAlreadyExists(newCriterion.Criterion_Id)) { throw (new NWATException(MessageCriterionIdAlreadyExists(newCriterion.Criterion_Id))); } else { base.DataContext.Criterion.InsertOnSubmit(newCriterion); base.DataContext.SubmitChanges(); } } else { using (CurrentMasterDataIdsController masterDataIdsContr = new CurrentMasterDataIdsController()) { CurrentMasterDataIds masterDataIdsSet = masterDataIdsContr.GetCurrentMasterDataIds(); int currentCritId = masterDataIdsSet.CurrentCriterionId; // if you inserted a criterion manually and forgot to adjust the currentCriterionId it will // increment to the free place and will use new id to insert new criterion while (GetCriterionById(currentCritId) != null) { masterDataIdsContr.incrementCurrentCriterionId(); currentCritId = masterDataIdsSet.CurrentCriterionId; } newCriterion.Criterion_Id = currentCritId; base.DataContext.Criterion.InsertOnSubmit(newCriterion); base.DataContext.SubmitChanges(); masterDataIdsContr.incrementCurrentCriterionId(); } } } else { throw (new NWATException((MessageCriterionAlreadyExists(newCriterionName)))); } } else { throw (new NWATException(MessageCriterionCouldNotBeSavedEmptyObject())); } Criterion newCriterionFromDb = (from crit in base.DataContext.Criterion where crit.Name == newCriterion.Name && crit.Description == newCriterion.Description select crit).FirstOrDefault(); return CheckIfEqualCriterions(newCriterion, newCriterionFromDb); }
/// <summary> /// Imports the criterion into database. /// </summary> /// <param name="importCriterion">The import criterion.</param> /// <returns></returns> /// Erstellt von Joshua Frey, am 26.01.2016 public bool ImportCriterionIntoDb(Criterion importCriterion) { return InsertCriterionIntoDb(importCriterion); }
partial void DeleteCriterion(Criterion instance);
partial void UpdateCriterion(Criterion instance);
partial void InsertCriterion(Criterion instance);