/// <summary>
        /// Initializes a new instance of the <see cref="ProjectExporter"/> class.
        /// </summary>
        /// <param name="projectIdToExport">The project identifier to export.</param>
        /// <param name="exportDirectoryPath">The export file path.</param>
        /// Erstellt von Joshua Frey, am 13.01.2016
        public ProjectExporter(int projectIdToExport, string exportDirectoryPath)
        {
            // initialize db controller
            ExportProjectController = new ProjectController();
            ExportCriterionController = new CriterionController();
            ExportProductController = new ProductController();
            ExportProjectCriterionController = new ProjectCriterionController();
            ExportProjectProductController = new ProjectProductController();
            ExportFulfillmentController = new FulfillmentController();

            this.ExportFilePaths = new List<string>();

            ProjectId = projectIdToExport;
            ProjectName = ExportProjectController.GetProjectById(projectIdToExport).Name;
            Timestamp = CommonMethods.GetTimestamp();

            ExportFilePath = exportDirectoryPath;

            FileBaseName = String.Format(@"{0}\{1}_Project_{2}", ExportFilePath, Timestamp, ProjectName);

            string logFilePath = this.FileBaseName + ".log";
            this.ExportFilePaths.Add(logFilePath);

            // Create Logfile
            this.ArchiveLogWriter = new LogWriter(logFilePath, "Archivierungslog");
        }
        //Konstruktor - Werden ProjectId und ProductId als Parameter übergeben
        public FulfillmentForEachProductPrinter(int projectId, int productId)
        {
            this.ProjCritContr = new ProjectCriterionController();
             ProjectController projCont = new ProjectController();
             this.Project = projCont.GetProjectById(projectId);

             this.ProjProduct = new ProductController();
             ProductController projProdController = new ProductController();
             this.Product = projProdController.GetProductById(productId);

             this.FulFillContr = new FulfillmentController();
             FulfillmentController fulCont = new FulfillmentController();
             this.FulfillmentForEachProduct = fulCont.GetAllFulfillmentsForSingleProduct(projectId, productId);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectImporter"/> class.
        /// </summary>
        /// <param name="archiveFilePath">The archive file path.</param>
        /// Erstellt von Joshua Frey, am 13.01.2016
        public ProjectImporter(string archiveFilePath)
        {
            // initialize db controller
            ImportProjectController = new ProjectController();
            ImportCriterionController = new CriterionController();
            ImportProductController = new ProductController();
            ImportProjectCriterionController = new ProjectCriterionController();
            ImportProjectProductController = new ProjectProductController();
            ImportFulfillmentController = new FulfillmentController();
            this.ZipArchiveFilePath = archiveFilePath;

            this.ImportFilesDirectory = CreateImportDirectory();

            // Create Logfile
            string logFilePath = this.ImportFilesDirectory + @"\Import.log";
            this.ImportLogWriter = new LogWriter(logFilePath, "Import Log");
        }
Example #4
0
        /// <summary>
        /// Allocates the product.
        /// </summary>
        /// <param name="projectId">The project identifier.</param>
        /// <param name="projProd">The proj product.</param>
        /// <returns>
        /// boolean, if allocation to ProjectProduct and Fulfillment table was successful
        /// </returns>
        /// Erstellt von Joshua Frey, am 12.01.2016
        /// <exception cref="NWATException"></exception>
        private bool AllocateProduct(int projectId, ProjectProduct projProd)
        {
            bool insertionProjectProductSuccessful = true;
            bool insertionFulfillmentSuccessful    = true;

            int productId = projProd.Product_Id;

            if (productId != 0 && projProd.Project_Id != 0)
            {
                insertionProjectProductSuccessful = InsertProjectProductIntoDb(projProd);

                // get all project criterions to create new fulfillment entries
                List <ProjectCriterion> allProjectCriterions;
                using (ProjectCriterionController projCritCont = new ProjectCriterionController())
                {
                    allProjectCriterions = projCritCont.GetAllProjectCriterionsForOneProject(projectId);
                }

                // create fulfillment entry for this product and each project criterion
                using (FulfillmentController fulfillCont = new FulfillmentController())
                {
                    foreach (ProjectCriterion projCrit in allProjectCriterions)
                    {
                        int criterionId = projCrit.Criterion_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 = criterionId,
                            Fulfilled    = false,
                            Comment      = null
                        };

                        if (!fulfillCont.InsertFullfillmentInDb(newFulfillment))
                        {
                            insertionFulfillmentSuccessful = false;
                            throw (new NWATException(CommonMethods.MessageInsertionToFulFillmentTableFailed(productId, criterionId)));
                        }
                    }
                }
            }
            return(insertionFulfillmentSuccessful && insertionProjectProductSuccessful);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectImporter"/> class.
        /// </summary>
        /// <param name="archiveFilePath">The archive file path.</param>
        /// Erstellt von Joshua Frey, am 13.01.2016
        public ProjectImporter(string archiveFilePath)
        {
            // initialize db controller
            ImportProjectController          = new ProjectController();
            ImportCriterionController        = new CriterionController();
            ImportProductController          = new ProductController();
            ImportProjectCriterionController = new ProjectCriterionController();
            ImportProjectProductController   = new ProjectProductController();
            ImportFulfillmentController      = new FulfillmentController();
            this.ZipArchiveFilePath          = archiveFilePath;

            this.ImportFilesDirectory = CreateImportDirectory();

            // Create Logfile
            string logFilePath = this.ImportFilesDirectory + @"\Import.log";

            this.ImportLogWriter = new LogWriter(logFilePath, "Import Log");
        }
Example #6
0
        /*
         * Private section
         */


        /// <summary>
        /// Deallocates the product from project and deletes all allocated fulfillment entries
        /// </summary>
        /// <param name="projectId">The project identifier.</param>
        /// <param name="productToDeallocate">The product to deallocate.</param>
        /// <returns>
        /// boolean, if deallocation was successful and all allocated fulfillment entries were delted successfully
        /// </returns>
        /// Erstellt von Joshua Frey, am 12.01.2016
        private bool DeallocateProductFromProject(int projectId, ProjectProduct productToDeallocate)
        {
            bool   fulfillmentDeletionSuccessful;
            int    idOfProductToDeallocate   = productToDeallocate.Product_Id;
            string nameOfProductToDeallocate = productToDeallocate.Product.Name;

            using (FulfillmentController fulfillContr = new FulfillmentController())
            {
                fulfillmentDeletionSuccessful = fulfillContr.DeleteAllFulfillmentsForOneProductInOneProject(projectId, idOfProductToDeallocate);
            }

            if (fulfillmentDeletionSuccessful && DeleteProjectProductFromDb(projectId, idOfProductToDeallocate))
            {
                return(true);
            }
            else
            {
                MessageBox.Show(String.Format(@"Bei dem Entkoppeln des Produkts {0} ist ein Fehler aufgetreten."), nameOfProductToDeallocate);
                return(false);
            }
        }
        /// <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;
        }
        /// <summary>
        /// Deallocates the criterion and all child criterions from project. This includes the entries in the fulfillment table
        /// </summary>
        /// <param name="projectId">The project identifier.</param>
        /// <param name="projCrit">The proj crit.</param>
        /// <returns></returns>
        /// Erstellt von Joshua Frey, am 04.01.2016
        public bool DeallocateCriterionAndAllChildCriterions(int projectId, ProjectCriterion projCrit, bool forceDeallocationOfChildren)
        {
            int projectCriterionId = projCrit.Criterion_Id;
            // checks if criterion has any children criterion (is a parent criterion)
            List<ProjectCriterion> eventualChildCriterions = GetChildCriterionsByParentId(projectId, projectCriterionId);
            bool deletionPermitted = true;
            if (eventualChildCriterions.Count > 0)
            {
                string decisionMessage = MessageUserDecisionOfDeallocatingAllChildCriterions(projCrit, eventualChildCriterions);
                const string caption = "Kriterienentkopplung";

                // only ask user if children should be deallocated when forceDeallocationOfChildre = false
                if (!forceDeallocationOfChildren)
                {
                    var result = MessageBox.Show(decisionMessage, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (result == DialogResult.No)
                    {
                        deletionPermitted = false;
                    }
                }

                if (deletionPermitted)
                {
                    foreach (ProjectCriterion childProjCrit in eventualChildCriterions)
                    {
                        deletionPermitted = DeallocateCriterionAndAllChildCriterions(projectId, childProjCrit, forceDeallocationOfChildren);
                    }
                }
            }
            string projCritName = projCrit.Criterion.Name;
            if (deletionPermitted)
            {
                // delete all fulfillment entries which point to this project criterion
                bool fulfillmentDeletionSuccessfull;
                using (FulfillmentController fulfillmentContr = new FulfillmentController())
                {
                    fulfillmentDeletionSuccessfull = fulfillmentContr.DeleteAllFulfillmentsForOneCriterionInOneProject(projectId, projCrit.Criterion_Id);
                }

                if (fulfillmentDeletionSuccessfull && DeleteProjectCriterionFromDb(projectId, projectCriterionId))
                {
                    if (!forceDeallocationOfChildren)
                    {
                        MessageBox.Show("Das Kriterium " + projCritName + " wurde erfolgreich vom Projekt entkoppelt.");
                    }

                    return true;
                }
                else
                {
                    MessageBox.Show("Bei dem Löschvorgang ist ein Fehler aufgetreten.");
                    return false;
                }
            }
            else
            {
                MessageBox.Show("Löschen von " + projCritName + " konnte nicht durchgeführt werden, weil ein Löschvorgang vom Benutzer abgelehnt wurde.");
                return false;
            }
        }
        /// <summary>
        /// Handles the SelectedIndexChanged event of the comboBox_ProjCritProdFulf 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 comboBox_ProjCritProdFulf_SelectedIndexChanged(object sender, EventArgs e)
        {
            try{
            if (formloaded > 2)
            {
                Product selectedValue = new Product();
                ComboBox cmb = (ComboBox)sender;
                int selectedIndex = cmb.SelectedIndex;
                if (cmb.SelectedIndex > -1)
                {
                    selectedValue = (Product)cmb.SelectedValue;

                    if (selectedValue != null)
                    {
                        using (FulfillmentController fuFiCont = new FulfillmentController())
                        {
                            int i = 0;
                            var projProdFulf = fuFiCont.GetAllFulfillmentsForSingleProduct(PID, selectedValue.Product_Id);

                            foreach (Fulfillment singleProjProdFulf in projProdFulf)
                            {
                                int row = i;
                                bool selected = singleProjProdFulf.Fulfilled;
                                String note = singleProjProdFulf.Comment;
                                dataGridView_ProjCritProdFulf.Rows[row].Cells["Erfüllung"].Value = selected;
                                dataGridView_ProjCritProdFulf.Rows[row].Cells["Bemerkung"].Value = note;
                                i++;
                            }
                        }
                    }
                }
            }
            formloaded++;
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message);
            }
        }
        /// <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);
            }
        }
        /// <summary>
        /// Eigentliche Print Methode um Pdf zu befüllen
        /// </summary>
        /// 
        /// Erstellt von Adrian Glasnek
        private void PrintCriterionStructure(ref PdfPTable CritTable, List<ProjectProduct> productsInTable)
        {
            FulfillmentController fufiCont = new FulfillmentController();
            List<Fulfillment> fufiList = fufiCont.GetAllFulfillmentsForOneProject(this.Project.Project_Id);

            //Übergebene Liste von Methode "GetSortedCriterionStructure()" in Liste sortedProjectCriterionStructure schreiben
            List<ProjectCriterion> sortedProjectCriterionStructure = this.ProjCritContr.GetSortedCriterionStructure(this.Project.Project_Id);

            // Generische Liste - Dictionary Wertepaar vom Typ int - Schlüssel und Wert
            Dictionary<int, int> enumerations = new Dictionary<int, int>() { { 1, 0 } };

            //Foreach-Schleife druckt sortierte Kriterien auf das Pdf Dokument
            foreach (ProjectCriterion projectCriterion in SortedProjectCriterionStructure)
            {
                //Definieren der intend Variable um die richtige "Einrückung" auf dem Pdf Dokument erzielen zu können
                int layer = projectCriterion.Layer_Depth;
                int factor = 25;
                int intend;
                intend = layer * factor;

                //Aufzählunszahlen für die Kriterienstruktur in einen string schreiben
                string enumeration = GetEnumerationForCriterion(ref enumerations, layer);

                //Schriftgröße der angezeigten Kriterienstruktur bestimmen
                Font CritStructFont = FontFactory.GetFont("Arial", 10);
                Font numbers = FontFactory.GetFont("Arial_BOLD", 7, Font.NORMAL);

                //Paragraph der die Zellen befüllt
                string CritsEnumeration = "[" + enumeration + "]" + " " + projectCriterion.Criterion.Description.ToString();

                Paragraph para = new Paragraph(CritsEnumeration, CritStructFont);
                //Einrückungsfaktor, das zugehörige Kriterien untereinander stehen
                para.IndentationLeft = intend;
                //Neue Tabellenzelle in der die Kriterienbeschreibung reingeschrieben wird
                PdfPCell Crits = new PdfPCell();
                //Der Zelle den Paragraphen übergeben
                Crits.AddElement(para);
                //Anzeigen von Linien im Pdf
                Crits.Border = 1;

                //Die Kriterienstruktur den zellen hinzufügen
                CritTable.AddCell(Crits);
                CritTable.AddCell(" ");
                if (projectCriterion.Weighting_Cardinal <= 0)
                {
                    CritTable.AddCell(new Paragraph("-", CritStructFont));
                }
                else
                {
                    CritTable.AddCell(new Paragraph("x", CritStructFont));
                }

                foreach (ProjectProduct projprod in productsInTable)
                {

                    //try catch Anweisung um Fehler abzufangen. Fehler: Für das Produkt sind keine oder nicht alle Erfülungen in der DB hinterlegt
                    try
                    {
                        //Abfrage der Erfüllungen
                        Fulfillment fulfillForThisProdAndThisCrit = fufiList.Single(
                                fufi => fufi.Project_Id == projectCriterion.Project_Id &&
                                        fufi.Product_Id == projprod.Product_Id &&
                                        fufi.Criterion_Id == projectCriterion.Criterion.Criterion_Id);

                        //Wenn ein Kriterium erfüllt ist wird ein x gesetzt ansonsten ein -
                        if (fulfillForThisProdAndThisCrit.Fulfilled == true)
                        {
                            CritTable.AddCell(new Paragraph("x", CritStructFont));
                        }
                        else
                        {
                            CritTable.AddCell(new Paragraph("-", CritStructFont));
                        }
                    }

                    catch
                    {
                        throw new ApplicationException("Warnung!\n Nicht für alle Produkte des Projekts sind Erfüllungen hinterlegt! Bitte überprüfen Sie Ihre Eingaben! ");
                    }

                }
            }
        }
        /*
         * Private section
         */
        /// <summary>
        /// Deallocates the product from project and deletes all allocated fulfillment entries
        /// </summary>
        /// <param name="projectId">The project identifier.</param>
        /// <param name="productToDeallocate">The product to deallocate.</param>
        /// <returns>
        /// boolean, if deallocation was successful and all allocated fulfillment entries were delted successfully
        /// </returns>
        /// Erstellt von Joshua Frey, am 12.01.2016
        private bool DeallocateProductFromProject(int projectId, ProjectProduct productToDeallocate)
        {
            bool fulfillmentDeletionSuccessful;
            int idOfProductToDeallocate = productToDeallocate.Product_Id;
            string nameOfProductToDeallocate = productToDeallocate.Product.Name;
            using (FulfillmentController fulfillContr = new FulfillmentController())
            {
                fulfillmentDeletionSuccessful = fulfillContr.DeleteAllFulfillmentsForOneProductInOneProject(projectId, idOfProductToDeallocate);
            }

            if (fulfillmentDeletionSuccessful && DeleteProjectProductFromDb(projectId, idOfProductToDeallocate))
            {
                return true;
            }
            else
            {
                MessageBox.Show(String.Format(@"Bei dem Entkoppeln des Produkts {0} ist ein Fehler aufgetreten."), nameOfProductToDeallocate);
                return false;
            }
        }
        /// <summary>
        /// Deallocates the criterion and all child criterions from project. This includes the entries in the fulfillment table
        /// </summary>
        /// <param name="projectId">The project identifier.</param>
        /// <param name="projCrit">The proj crit.</param>
        /// <returns></returns>
        /// Erstellt von Joshua Frey, am 04.01.2016
        public bool DeallocateCriterionAndAllChildCriterions(int projectId, ProjectCriterion projCrit, bool forceDeallocationOfChildren)
        {
            int projectCriterionId = projCrit.Criterion_Id;
            // checks if criterion has any children criterion (is a parent criterion)
            List <ProjectCriterion> eventualChildCriterions = GetChildCriterionsByParentId(projectId, projectCriterionId);
            bool deletionPermitted = true;

            if (eventualChildCriterions.Count > 0)
            {
                string       decisionMessage = MessageUserDecisionOfDeallocatingAllChildCriterions(projCrit, eventualChildCriterions);
                const string caption         = "Kriterienentkopplung";

                // only ask user if children should be deallocated when forceDeallocationOfChildre = false
                if (!forceDeallocationOfChildren)
                {
                    var result = MessageBox.Show(decisionMessage, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (result == DialogResult.No)
                    {
                        deletionPermitted = false;
                    }
                }

                if (deletionPermitted)
                {
                    foreach (ProjectCriterion childProjCrit in eventualChildCriterions)
                    {
                        deletionPermitted = DeallocateCriterionAndAllChildCriterions(projectId, childProjCrit, forceDeallocationOfChildren);
                    }
                }
            }
            string projCritName = projCrit.Criterion.Name;

            if (deletionPermitted)
            {
                // delete all fulfillment entries which point to this project criterion
                bool fulfillmentDeletionSuccessfull;
                using (FulfillmentController fulfillmentContr = new FulfillmentController())
                {
                    fulfillmentDeletionSuccessfull = fulfillmentContr.DeleteAllFulfillmentsForOneCriterionInOneProject(projectId, projCrit.Criterion_Id);
                }

                if (fulfillmentDeletionSuccessfull && DeleteProjectCriterionFromDb(projectId, projectCriterionId))
                {
                    if (!forceDeallocationOfChildren)
                    {
                        MessageBox.Show("Das Kriterium " + projCritName + " wurde erfolgreich vom Projekt entkoppelt.");
                    }

                    return(true);
                }
                else
                {
                    MessageBox.Show("Bei dem Löschvorgang ist ein Fehler aufgetreten.");
                    return(false);
                }
            }
            else
            {
                MessageBox.Show("Löschen von " + projCritName + " konnte nicht durchgeführt werden, weil ein Löschvorgang vom Benutzer abgelehnt wurde.");
                return(false);
            }
        }