/// <summary> /// Gets the fulfillment by line from import file. /// </summary> /// <param name="fulfillmentImportLine">The fulfillment import line.</param> /// <returns></returns> /// Erstellt von Joshua Frey, am 27.01.2016 /// <exception cref="NWATException"></exception> private Fulfillment GetFulfillmentByLineFromImportFile(string fulfillmentImportLine) { Fulfillment importFulfillment; // Project_Id|Product_Id|Criterion_Id|Fulfilled|Comment var lineAsArray = fulfillmentImportLine.Split(this._delimiter); int projectId; int productId; int criterionId; bool fulfilled; string comment = CommonMethods.GetNullableStringValueFromString(lineAsArray[4]); try { projectId = Convert.ToInt32(lineAsArray[0]); productId = Convert.ToInt32(lineAsArray[1]); criterionId = Convert.ToInt32(lineAsArray[2]); fulfilled = Convert.ToBoolean(lineAsArray[3]); } catch (FormatException formatException) { throw new NWATException(String.Format("{0}\n\n{1}", formatException, MessageWrongDatatypeInExportedLine("ProjectProduct", fulfillmentImportLine, "int|int|int|bool(\"True\" or \"False\")|string"))); } importFulfillment = new Fulfillment() { Project_Id = projectId, Product_Id = productId, Criterion_Id = criterionId, Fulfilled = fulfilled, Comment = comment }; return importFulfillment; }
/// <summary> /// Allocates the criterion. /// </summary> /// <param name="projectId">The project identifier.</param> /// <param name="projCrit">The proj crit.</param> /// <returns> /// bool if insertions in projectCriterion table and fulfillment table were successful /// </returns> /// Erstellt von Joshua Frey, am 04.01.2016 /// <exception cref="NWATException"></exception> private bool AllocateCriterion(int projectId, ProjectCriterion projCrit) { bool insertionProjectCritionSuccessful = true; bool insertionFulfillmentSuccessful = true; int projCritId = projCrit.Criterion_Id; if (projCritId != 0 && projCrit.Project_Id != 0) { insertionProjectCritionSuccessful = InsertProjectCriterionIntoDb(projCrit); // get all project products for insertion to fulfillment table List<ProjectProduct> allProjectProducts; using (ProjectProductController projProdCont = new ProjectProductController()) { allProjectProducts = projProdCont.GetAllProjectProductsForOneProject(projectId); } // insert criterions into fulfillment table for each product using (FulfillmentController fulfillContr = new FulfillmentController()) { foreach (ProjectProduct projProd in allProjectProducts) { int productId = projProd.Product_Id; // new fulfillment which will be inserted into fulfillment table. // default values for Fulfilled and Comment (false and null) Fulfillment newFulfillment = new Fulfillment() { Project_Id = projectId, Product_Id = productId, Criterion_Id = projCritId, Fulfilled = false, Comment = null }; if (!fulfillContr.InsertFullfillmentInDb(newFulfillment)) { insertionFulfillmentSuccessful = false; throw (new NWATException(CommonMethods.MessageInsertionToFulFillmentTableFailed(productId, projCritId))); } } } } return insertionFulfillmentSuccessful && insertionProjectCritionSuccessful; }
partial void DeleteFulfillment(Fulfillment instance);
/// <summary> /// Handles the Click event of the btn_ProjCritProdFulfSave control. /// </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_ProjCritProdFulfSave_Click(object sender, EventArgs e) { try { if (comboBox_ProjCritProdFulf.SelectedIndex != -1) { using (FulfillmentController fulCont = new FulfillmentController()) { bool saveSucceeded = true; foreach (DataGridViewRow row in dataGridView_ProjCritProdFulf.Rows) { if (CommonMethods.CheckIfForbiddenDelimiterInDb((string)row.Cells["Bemerkung"].Value)) { CommonMethods.MessageForbiddenDelimiterWasFoundInText(); break; } else { Fulfillment fulFi = new Fulfillment(); fulFi.Criterion_Id = (int)row.Cells[0].Value; fulFi.Project_Id = Project.Project_Id; int selectedIndex = comboBox_ProjCritProdFulf.SelectedIndex; Product selectedValue = new Product(); selectedValue = (Product)comboBox_ProjCritProdFulf.SelectedItem; fulFi.Product_Id = selectedValue.Product_Id; fulFi.Comment = (string)row.Cells["Bemerkung"].Value; if ((bool)row.Cells["Erfüllung"].Value == true) { fulFi.Fulfilled = true; } else if ((bool)row.Cells["Erfüllung"].Value == false) { fulFi.Fulfilled = false; } if (!fulCont.UpdateFulfillmentEntry(fulFi)) { saveSucceeded = false; } } } if (saveSucceeded) { MessageBox.Show("Die Änderungen wurden erfolgreich gespeichert."); } else { MessageBox.Show("Beim Speichern ist ein Fehler unterlaufen."); } } } else { MessageBox.Show("Sie müssen ein Produkt auswählen."); } } catch (Exception x) { MessageBox.Show(x.Message); } }
partial void InsertFulfillment(Fulfillment instance);
partial void UpdateFulfillment(Fulfillment instance);
private void detach_Fulfillment(Fulfillment entity) { this.SendPropertyChanging(); entity.Project = null; }
private void detach_Fulfillment(Fulfillment entity) { this.SendPropertyChanging(); entity.Criterion = null; }
private void attach_Fulfillment(Fulfillment entity) { this.SendPropertyChanging(); entity.Project = this; }
/* * Private section */ /// <summary> /// Checks if fulfillments are equal. /// </summary> /// <param name="fulfillmentOne">The fulfillment one.</param> /// <param name="fulfillmentTwo">The fulfillment two.</param> /// <returns> /// bool if fulfillments are equal. /// </returns> /// Erstellt von Joshua Frey, am 29.12.2015 private bool CheckIfEqualFulfillments(Fulfillment fulfillmentOne, Fulfillment fulfillmentTwo) { bool sameProjectId = fulfillmentOne.Project_Id == fulfillmentTwo.Project_Id; bool sameProductId = fulfillmentOne.Product_Id == fulfillmentTwo.Product_Id; bool sameCriterionId = fulfillmentOne.Criterion_Id == fulfillmentTwo.Criterion_Id; bool sameDegreeOfFulfillment = fulfillmentOne.Fulfilled == fulfillmentTwo.Fulfilled; bool sameComment = fulfillmentOne.Comment == fulfillmentTwo.Comment; return sameComment && sameCriterionId && sameDegreeOfFulfillment && sameProductId && sameProjectId; }
/// <summary> /// Updates the fulfillment entry. /// </summary> /// <param name="alteredFulfillment">The altered fulfillment.</param> /// <returns></returns> /// Erstellt von Joshua Frey, am 29.12.2015 /// <exception cref="NWATException"></exception> public bool UpdateFulfillmentEntry(Fulfillment alteredFulfillment) { int projectId = alteredFulfillment.Project_Id; int productId = alteredFulfillment.Product_Id; int criterionId = alteredFulfillment.Criterion_Id; if (alteredFulfillment != null) { Fulfillment fulfillmentFromDb = base.DataContext.Fulfillment.SingleOrDefault(fulfillment => fulfillment.Project_Id == projectId && fulfillment.Product_Id == productId && fulfillment.Criterion_Id == criterionId); fulfillmentFromDb.Fulfilled = alteredFulfillment.Fulfilled; fulfillmentFromDb.Comment = alteredFulfillment.Comment; base.DataContext.SubmitChanges(); } else { throw new NWATException(MessageFulfillmentCouldNotBeSaved()); } Fulfillment newFulfillmentInDb = GetFulfillmentByIds(projectId, productId, criterionId); return CheckIfEqualFulfillments(alteredFulfillment, newFulfillmentInDb); }
/// <summary> /// Inserts the fullfillment in database. /// </summary> /// <param name="projectId">The project identifier.</param> /// <param name="productId">The product identifier.</param> /// <param name="criterionId">The criterion identifier.</param> /// Erstellt von Joshua Frey, am 04.01.2016 /// <exception cref="NWATException"></exception> public bool InsertFullfillmentInDb(Fulfillment fulfillmentToInsert) { int projId = fulfillmentToInsert.Project_Id; int prodId = fulfillmentToInsert.Product_Id; int critId = fulfillmentToInsert.Criterion_Id; if (!CheckIfFulfillmentAlreadyExists(projId, prodId, critId)) { base.DataContext.Fulfillment.InsertOnSubmit(fulfillmentToInsert); base.DataContext.SubmitChanges(); if (CheckIfFulfillmentAlreadyExists(projId, prodId, critId)) return true; else return false; } else { throw new NWATException(MessageFulfillmentEntryAlreadyExists(projId, prodId, critId)); } }
/// <summary> /// Fills the fulfillment table initially. /// </summary> /// <param name="projectId">The project identifier.</param> /// <param name="allProjectProducts">All project products.</param> /// <param name="allProjectCriterions">All project criterions.</param> /// Erstellt von Joshua Frey, am 28.12.2015 /// <exception cref="NWATException"> /// </exception> public void FillFulfillmentTableInitially(int projectId, List<ProjectProduct> allProjectProducts, List<ProjectCriterion> allProjectCriterions) { foreach (ProjectProduct projProd in allProjectProducts) { int productId = projProd.Product_Id; if (allProjectCriterions.Count == 0) { throw new NWATException(MessageGivenParamListIsEmpty("Projektkriterien Liste")); } else if(allProjectProducts.Count == 0) { throw new NWATException(MessageGivenParamListIsEmpty("Projektprodukte Liste")); } else { foreach (ProjectCriterion projCrit in allProjectCriterions) { int criterionId = projCrit.Criterion_Id; Fulfillment insertFulfillment = new Fulfillment() { Project_Id = projectId, Product_Id = productId, Criterion_Id = criterionId, Fulfilled = false, Comment = null }; InsertFullfillmentInDb(insertFulfillment); } } } }