Ejemplo n.º 1
0
        public void GenerateSurvey(DbContext dbContext, SurveyType receivedSurveytype)
        {
            m_ModelFactory = new ModelFactory();
            categories     = new List <Category>();
            gfactors       = new List <GFactor>();

            dpoints         = new List <Dangerpoint>();
            questions       = new List <Question>();
            questionHelpers = new List <QuestionHelper>();
            dpointsHelpers  = new List <DPointsHelper>();
            gfactorHelpers  = new List <GFactorHelper>();
            categoryHelpers = new List <CategoryHelper>();


            var myAL = new ArrayList();
            WordprocessingDocument doc;

            //using (WordprocessingDocument doc = WordprocessingDocument.Open("checkliste.docx", false))
            if (receivedSurveytype.SurveyTypeDocx == null)
            {
                doc = WordprocessingDocument.Open("..\\OpenResKit.Danger\\Resources\\checkliste.docx", false);
            }
            else
            {
                File.WriteAllBytes(Path.GetTempPath() + receivedSurveytype.SurveyTypeDocx.Name, receivedSurveytype.SurveyTypeDocx.DocumentSource.BinarySource);

                doc = WordprocessingDocument.Open(Path.GetTempPath() + receivedSurveytype.SurveyTypeDocx.Name, false);
                Console.WriteLine("Versuche neuen Fragebogen zu parsen");
            }
            // Pfad zum Ressourcen Ordner
            {
                //es wird der MainDocumentPart geholt, welcher das eigenliche worddokument mit allen Referenzen darstellt
                var mainPart = doc.MainDocumentPart;

                //der reine Inhalt ist dann im Dokument
                var document = mainPart.Document;

                // hier holen wir uns die Tabellen
                var tables = document.Descendants <Table>();

                foreach (var tbl in tables)
                {
                    //var tabledesc = tbl.Descendants<TableDescription>();
                    //tabledesc.ToList().ForEach((dc) => Console.WriteLine(dc.InnerText));

                    //hier holen wir uns alle Zeilen
                    var rows = tbl.Descendants <TableRow>();


                    foreach (var tblrw in rows)
                    {
                        //und nun holen wir und die Zellen
                        var cells = tblrw.Descendants <TableCell>();


                        //Inhalt von Zellen einer Zeile ausgeben
                        //test - inhalt der zellen ausgeben
                        var arrContent = new ArrayList();

                        foreach (var tc in cells.ToList())
                        {
                            var myArr = new ArrayList();
                            foreach (var tcc in tc.ToList())
                            {
                                if (tcc.InnerText != "")
                                {
                                    myArr.Add(tcc.InnerText);
                                }
                            }

                            if (myArr.Count > 1)
                            {
                                arrContent.Add(myArr);
                            }
                            else if (myArr.Count == 1)
                            {
                                arrContent.Add(myArr[0]);
                            }
                        }

                        myAL.Add(arrContent);

                        //endtest
                        //cells.ToList().ForEach((tc) => Console.Write(tc.InnerText + " | "));
                        //PrintArray(myAL, 0);
                    } //forech2
                }     //freach1

                //var st = m_ModelFactory.CreateSurveytype(name);
                //dbContext.Set<OpenResKit.Danger.Models.Surveytype>().Add(st);

                //Gfactor gf = new Gfactor();
                var myarray = getArray(myAL);
                var catid   = 0;

                //Speichern in die DB
                var newzeile = new ArrayList();
                var catcount = 1;
                foreach (var zeile in myarray)
                {
                    // GFactor curline = (GFactor)zeile;
                    var clh = (GFHelper)zeile;

                    var curcat = (Category)clh.category;


                    if (catid != clh.category.Id)
                    {
                        catid = clh.category.Id;
                        //var ct = new OpenResKit.Danger.Models.Category { Name = clh.category.Name };

                        var ct2 = new CategoryHelper
                        {
                            Name = clh.category.Name,
                            id   = catid.ToString()
                        };

                        /*m_ModelFactory.CreateCategory(clh.category.Name,st)*/

                        //sqlKategorie = ("insert into category (catid, catname) VALUES (" + curline.category.id + ",'" + curline.category.name + "');");
                        catcount = 1;
                        //Console.WriteLine("Category dazu"+ct.Name+ct.Id);
                        //categories.Add(ct);
                        categoryHelpers.Add(ct2);

                        // dbContext.Set<OpenResKit.Danger.Models.Category>().Add(ct);
                    }

                    var catidtext = catid.ToString() + "." + catcount.ToString();

                    var gfa = new GFactorHelper
                    {
                        /*Cat = categoryHelpers.Last(),*/ Name = clh.gfactor,
                        Number = catidtext,
                        CatId  = catid.ToString()
                    };
                    //m_ModelFactory.CreateGFactor(clh.gfactor, catidtext, categories.Last());

                    gfactorHelpers.Add(gfa);
                    //var gfa = m_ModelFactory.CreateGFactor(clh.id,clh.gfactor,catidtext,curcat);
                    //dbContext.Set<OpenResKit.Danger.Models.GFactor>().Add(gfa);
                    // Console.WriteLine("GFactor dazu"+gfa.Name+gfa.Id);

                    catcount++;

                    foreach (var curquestion in clh.arrQuestion)
                    {
                        //string checkq = frage.ToString();
                        //if(checkq.EndsWith("Sichtkontrolle:") || checkq.EndsWith("Befragung:") || checkq.EndsWith("Messung:")){

                        //    curline.arrFrage.Remove(checkq);
                        //    continue;
                        //}
                        //var tempgfactor = m_ModelFactory.CreateGFactor(clh.id, clh.gfactor, catidtext, curcat);
                        //var quest = m_ModelFactory.CreateQuestion(questid, curquestion.ToString(), tempgfactor);

                        var quest = new QuestionHelper
                        {
                            Name = curquestion.ToString(),
                            GFID = catidtext
                        }; /*m_ModelFactory.CreateQuestion(curquestion.ToString(), gfactorHelpers.Last());*/
                        questionHelpers.Add(quest);

                        //dbContext.Set<OpenResKit.Danger.Models.Question>().Add(quest);
                        //Console.WriteLine(" Question dazu "+quest.QuestionName+quest.Id);
                        //dbContext.SaveChanges();
                    } //ende foreach2

                    foreach (var curdpoint in clh.arrDpoints)
                    {
                        var dpoint = new DPointsHelper
                        {
                            Name = curdpoint.ToString(),
                            GFID = catidtext
                        };
                        dpointsHelpers.Add(dpoint);
                    }
                } //ende foreach

                //Console.ReadLine();
            } //ende using wordprocess


            //var categoriesForSurveytype = new List<Category>();

            foreach (var categoryHelper in categoryHelpers)
            {
                var gfactorsForCategory = new List <GFactor>();

                var gfactorHelperI = gfactorHelpers.Where(g1 => g1.CatId == categoryHelper.id);

                foreach (var gfactorHelper in gfactorHelperI)
                {
                    var questionForGFactor = new List <Question>();
                    var dpointForGFactor   = new List <Dangerpoint>();
                    var dpointHelperI      = dpointsHelpers.Where(d1 => d1.GFID == gfactorHelper.Number);
                    var questionHelperI    = questionHelpers.Where(q1 => q1.GFID == gfactorHelper.Number);

                    foreach (var dpointHelper in dpointHelperI)
                    {
                        var dpoint = m_ModelFactory.CreateDpoint(dpointHelper.Name);
                        //    dbContext.Set<Dangerpoints>()
                        //    .Add(dpoint);

                        dpointForGFactor.Add(dpoint);
                    }

                    foreach (var questionHelper in questionHelperI)
                    {
                        var question = m_ModelFactory.CreateQuestion(questionHelper.Name);
                        //     dbContext.Set<Question>()
                        //     .Add(question);

                        questionForGFactor.Add(question);
                    }


                    var gfactor = m_ModelFactory.CreateGFactor(gfactorHelper.Name, gfactorHelper.Number, questionForGFactor, dpointForGFactor);
                    // dbContext.Set<GFactor>()
                    // .Add(gfactor);

                    gfactorsForCategory.Add(gfactor);
                }

                var category = m_ModelFactory.CreateCategory(categoryHelper.Name, gfactorsForCategory);
                // dbContext.Set<Category>()
                //  .Add(category);
                if (receivedSurveytype.Categories == null)
                {
                    receivedSurveytype.Categories = new Collection <Category>();
                }
                receivedSurveytype.Categories.Add(category);
            }


            dbContext.SaveChanges();
            Console.WriteLine("Fragebogen hinzugefügt");
        } //ende main
Ejemplo n.º 2
0
        public void GenerateSurvey(DbContext dbContext, Surveytype receivedSurveytype)
        {
            m_ModelFactory = new ModelFactory();
              categories = new List<Category>();
              gfactors = new List<GFactor>();

              dpoints = new List<Dangerpoint>();
              questions = new List<Question>();
              questionHelpers = new List<QuestionHelper>();
              dpointsHelpers = new List<DPointsHelper>();
              gfactorHelpers = new List<GFactorHelper>();
              categoryHelpers = new List<CategoryHelper>();

              var myAL = new ArrayList();
              WordprocessingDocument doc;
              //using (WordprocessingDocument doc = WordprocessingDocument.Open("checkliste.docx", false))
              if (receivedSurveytype.SurveyTypeDocx == null)
              {
            doc = WordprocessingDocument.Open("..\\OpenResKit.Danger\\Resources\\checkliste.docx", false);
              }
              else {
              File.WriteAllBytes(Path.GetTempPath() + receivedSurveytype.SurveyTypeDocx.Name, receivedSurveytype.SurveyTypeDocx.DocumentSource.BinarySource);

              doc = WordprocessingDocument.Open(Path.GetTempPath() + receivedSurveytype.SurveyTypeDocx.Name, false);
            Console.WriteLine("Versuche neuen Fragebogen zu parsen");
              }
              // Pfad zum Ressourcen Ordner
              {

            //es wird der MainDocumentPart geholt, welcher das eigenliche worddokument mit allen Referenzen darstellt
            var mainPart = doc.MainDocumentPart;

            //der reine Inhalt ist dann im Dokument
            var document = mainPart.Document;

            // hier holen wir uns die Tabellen
            var tables = document.Descendants<Table>();

            foreach (var tbl in tables)
            {
              //var tabledesc = tbl.Descendants<TableDescription>();
              //tabledesc.ToList().ForEach((dc) => Console.WriteLine(dc.InnerText));

              //hier holen wir uns alle Zeilen
              var rows = tbl.Descendants<TableRow>();

              foreach (var tblrw in rows)
              {

            //und nun holen wir und die Zellen
            var cells = tblrw.Descendants<TableCell>();

            //Inhalt von Zellen einer Zeile ausgeben
            //test - inhalt der zellen ausgeben
            var arrContent = new ArrayList();

            foreach (var tc in cells.ToList())
            {
              var myArr = new ArrayList();
              foreach (var tcc in tc.ToList())
              {
                if (tcc.InnerText != "")
                {
                  myArr.Add(tcc.InnerText);
                }

              }

              if (myArr.Count > 1)
              {
                arrContent.Add(myArr);
              }
              else if (myArr.Count == 1)
              {
                arrContent.Add(myArr[0]);
              }
            }

            myAL.Add(arrContent);

            //endtest
            //cells.ToList().ForEach((tc) => Console.Write(tc.InnerText + " | "));
            //PrintArray(myAL, 0);

              } //forech2

            } //freach1

            //var st = m_ModelFactory.CreateSurveytype(name);
            //dbContext.Set<OpenResKit.Danger.Models.Surveytype>().Add(st);

            //Gfactor gf = new Gfactor();
            var myarray = getArray(myAL);
            var catid = 0;

            //Speichern in die DB
            var newzeile = new ArrayList();
            var catcount = 1;
            foreach (var zeile in myarray)
            {
              // GFactor curline = (GFactor)zeile;
              var clh = (GFHelper) zeile;

              var curcat = (Category) clh.category;

              if (catid != clh.category.Id)
              {
            catid = clh.category.Id;
            //var ct = new OpenResKit.Danger.Models.Category { Name = clh.category.Name };

            var ct2 = new CategoryHelper
            {
              Name = clh.category.Name,
              id = catid.ToString()
            };

            /*m_ModelFactory.CreateCategory(clh.category.Name,st)*/

            //sqlKategorie = ("insert into category (catid, catname) VALUES (" + curline.category.id + ",'" + curline.category.name + "');");
            catcount = 1;
            //Console.WriteLine("Category dazu"+ct.Name+ct.Id);
            //categories.Add(ct);
            categoryHelpers.Add(ct2);

            // dbContext.Set<OpenResKit.Danger.Models.Category>().Add(ct);
              }

              var catidtext = catid.ToString() + "." + catcount.ToString();

              var gfa = new GFactorHelper
              {
            /*Cat = categoryHelpers.Last(),*/ Name = clh.gfactor,
            Number = catidtext,
            CatId = catid.ToString()
              };
              //m_ModelFactory.CreateGFactor(clh.gfactor, catidtext, categories.Last());

              gfactorHelpers.Add(gfa);
              //var gfa = m_ModelFactory.CreateGFactor(clh.id,clh.gfactor,catidtext,curcat);
              //dbContext.Set<OpenResKit.Danger.Models.GFactor>().Add(gfa);
              // Console.WriteLine("GFactor dazu"+gfa.Name+gfa.Id);

              catcount++;

              foreach (var curquestion in clh.arrQuestion)
              {
            //string checkq = frage.ToString();
            //if(checkq.EndsWith("Sichtkontrolle:") || checkq.EndsWith("Befragung:") || checkq.EndsWith("Messung:")){

            //    curline.arrFrage.Remove(checkq);
            //    continue;
            //}
            //var tempgfactor = m_ModelFactory.CreateGFactor(clh.id, clh.gfactor, catidtext, curcat);
            //var quest = m_ModelFactory.CreateQuestion(questid, curquestion.ToString(), tempgfactor);

            var quest = new QuestionHelper
            {
              Name = curquestion.ToString(),
              GFID = catidtext
            }; /*m_ModelFactory.CreateQuestion(curquestion.ToString(), gfactorHelpers.Last());*/
            questionHelpers.Add(quest);

            //dbContext.Set<OpenResKit.Danger.Models.Question>().Add(quest);
            //Console.WriteLine(" Question dazu "+quest.QuestionName+quest.Id);
            //dbContext.SaveChanges();
              } //ende foreach2

              foreach (var curdpoint in clh.arrDpoints)
              {
            var dpoint = new DPointsHelper
            {
              Name = curdpoint.ToString(),
              GFID = catidtext
            };
            dpointsHelpers.Add(dpoint);
              }
            } //ende foreach

            //Console.ReadLine();
              } //ende using wordprocess

              //var categoriesForSurveytype = new List<Category>();

              foreach (var categoryHelper in categoryHelpers)
              {
            var gfactorsForCategory = new List<GFactor>();

            var gfactorHelperI = gfactorHelpers.Where(g1 => g1.CatId == categoryHelper.id);

            foreach (var gfactorHelper in gfactorHelperI)
            {
              var questionForGFactor = new List<Question>();
              var dpointForGFactor = new List<Dangerpoint>();
              var dpointHelperI = dpointsHelpers.Where(d1 => d1.GFID == gfactorHelper.Number);
              var questionHelperI = questionHelpers.Where(q1 => q1.GFID == gfactorHelper.Number);

              foreach (var dpointHelper in dpointHelperI)
              {
            var dpoint = m_ModelFactory.CreateDpoint(dpointHelper.Name);
            //    dbContext.Set<Dangerpoints>()
              //    .Add(dpoint);

            dpointForGFactor.Add(dpoint);
              }

              foreach (var questionHelper in questionHelperI)
              {
            var question = m_ModelFactory.CreateQuestion(questionHelper.Name);
               //     dbContext.Set<Question>()
             //     .Add(question);

            questionForGFactor.Add(question);
              }

              var gfactor = m_ModelFactory.CreateGFactor(gfactorHelper.Name, gfactorHelper.Number, questionForGFactor, dpointForGFactor);
             // dbContext.Set<GFactor>()
               // .Add(gfactor);

              gfactorsForCategory.Add(gfactor);
            }

            var category = m_ModelFactory.CreateCategory(categoryHelper.Name, gfactorsForCategory);
               // dbContext.Set<Category>()
            //  .Add(category);
            if (receivedSurveytype.Categories == null)
            {
              receivedSurveytype.Categories = new Collection<Category>();
            }
               receivedSurveytype.Categories.Add(category);
              }

              dbContext.SaveChanges();
              Console.WriteLine("Fragebogen hinzugefügt");
        }