//Podsumowanie odpowiedzi. public void showSubmitForm() { treeView1.Visible = false; treeView1.Nodes.Clear(); SubmitForm f = new SubmitForm(); List <DbQuestion> answers = new List <DbQuestion>(); answers = getAnswers(); List <CheckedQuestion> cq = new List <CheckedQuestion>(); StringBuilder s = new StringBuilder(); foreach (var q in list) { CheckedQuestion checkedQ = new CheckedQuestion(); checkedQ.OK = true; // Startujemy od tego, że nie ma błednych odpowiedzi :) checkedQ.ID = q.ID; checkedQ.Question = q; checkedQ.Answer = answers.Where(b => b.ID == q.ID).FirstOrDefault(); if (checkedQ.Answer != null) { string[] tabQ; string[] tabA; switch (checkedQ.Question.Type) { case 5: tabQ = new string[] { q.A == "" ? null : q.A, q.B == "" ? null : q.B }; tabA = new string[] { checkedQ.Answer.A, checkedQ.Answer.B }; break; case 6: tabQ = new string[] { q.B == "" ? null : q.B }; tabA = new string[] { checkedQ.Answer.B }; break; case 7: tabQ = new string[] { q.A == "" ? null : String.Join("", q.A.ToUpper().Split(' ')).Replace("\r", "").Replace("\n", "") }; tabA = new string[] { String.Join("", checkedQ.Answer.A.ToUpper().Split(' ')).Replace("\r", "").Replace("\n", "") }; break; default: tabQ = new string[] { q.A == ""? null: q.A, q.B == ""? null: q.B, q.C == ""? null: q.C, q.D == ""? null: q.D, q.E == ""? null: q.E, q.F == ""? null: q.F, q.G == ""? null: q.G, q.H == ""? null: q.H }; tabA = new string[] { checkedQ.Answer.A == ""? null: checkedQ.Answer.A, checkedQ.Answer.B == ""? null: checkedQ.Answer.B, checkedQ.Answer.C == ""? null: checkedQ.Answer.C, checkedQ.Answer.D == ""? null: checkedQ.Answer.D, checkedQ.Answer.E == ""? null: checkedQ.Answer.E, checkedQ.Answer.F == ""? null: checkedQ.Answer.F, checkedQ.Answer.G == ""? null: checkedQ.Answer.G, checkedQ.Answer.H == ""? null: checkedQ.Answer.H }; break; } // Sprawdza czy odpowiedź OK. for (int i = 0; i < tabQ.Length; i++) { if (tabQ[i] != tabA[i]) { checkedQ.OK = false; // Jeśli któryś się nie zgadza to false i przerywa szukanie. break; } } } else { checkedQ.OK = null; // Nie udzielono odpowiedzi. } cq.Add(checkedQ); } // Tworzymy raport na podstawie listy przeanalizowanych pytań i odpowiedzi. for (int i = 0; i < cq.Count; i++) { s.AppendLine(cq[i].GetHtml()); } decimal okCount = cq.Where(a => a.OK == true).Count(); decimal notOkCount = cq.Where(a => a.OK == false).Count(); decimal allCount = cq.Count(); int okPercentOfAll = (int)Math.Floor(allCount != 0 ? (okCount / allCount) * 100 : 0); int okPercentOfAnwsered = (int)Math.Floor((okCount + notOkCount) != 0 ? (okCount / (okCount + notOkCount)) * 100 : 0); cq.Clear(); list.Clear(); answers.Clear(); StringBuilder html = new StringBuilder(); html.Append(" <div style = 'font-family: verdana;'> ") .Append(" <h3 style='color: black'><u>").Append(" ").Append(DateTime.Now.ToLongDateString()) .Append(" ").Append(DateTime.Now.ToShortTimeString()).Append("</br>").Append("</br>") .Append("Odpowiedziano na : ").Append((okCount + notOkCount)).Append(" pytań").Append("</br>") .Append("Ilość prawidłowych odpowiedzi to: ").Append(okCount).Append(" na ").Append(allCount).Append(" możliwych").Append("</br>") .Append("Ilosć procentowa z całości to: ").Append(okPercentOfAll).Append(" %").Append("</br>") .Append("Ilosć procentowa z pytan na które odpowiedziano to: ").Append(okPercentOfAnwsered).Append(" %").Append("</br>") .Append("</u></h3>").Append(s.ToString()) .Append(" </div>"); s.Clear(); f.webBrowser1.DocumentText = html.ToString(); f.MdiParent = this; f.Dock = DockStyle.Fill; f.Show(); closeAllChildren(); }
private void ExportQuestionsToHtml(string mainTemplatePath, string questionTemplatePath) { string style = ""; string script = ""; string mainTemplate = ""; if (File.Exists("HTML/Style.css")) { style = style + File.ReadAllText("HTML/Style.css"); } if (File.Exists("HTML/bootstrap.css")) { style = style + File.ReadAllText("HTML/bootstrap.css"); } if (File.Exists("HTML/bootstrap-theme.css")) { style = style + File.ReadAllText("HTML/bootstrap-theme.css"); } if (File.Exists("HTML/jquery.js")) { script = script + File.ReadAllText("HTML/jquery.js"); } if (File.Exists("HTML/jquery.js")) { script = script + File.ReadAllText("HTML/bootstrap.js"); } if (File.Exists("HTML/bootstrap.js")) { script = script + File.ReadAllText("HTML/Script.js"); } if (treeView1.Nodes.Count == 0) { MessageBox.Show("Najpierw pobierz pytania które chcesz eksportować.", "Trochę tu pusto..."); return; } DialogResult dialog = saveFileDialog2.ShowDialog(); if (dialog == DialogResult.OK) { try { File.Delete(saveFileDialog2.FileName); } catch (Exception) { MessageBox.Show("Nie udało się eksportować do wskazanego pliku. Jest aktualnie używany przez inny proces. \nSpróbuj ponownie uruchomić aplikację.", "Uwaga!!!"); return; } try { StringBuilder s = new StringBuilder(); if (File.Exists(mainTemplatePath)) { mainTemplate = File.ReadAllText(mainTemplatePath); } mainTemplate = mainTemplate.Replace("+[style]+", " <style>\n" + style + "</style> "); mainTemplate = mainTemplate.Replace("+[script]+", " <script>\n" + script + "</script> "); mainTemplate = mainTemplate.Replace("+[date]+", DateTime.Now.ToShortDateString()); //s.AppendLine(mainTemplate); foreach (var q in list) { string template = ""; if (File.Exists(questionTemplatePath)) { template = File.ReadAllText(questionTemplatePath); } CheckedQuestion cq = new CheckedQuestion(); q.question = q.question.ReplaceApostropheToSymbol(); cq.Question = q; if (template.Length > 0) { q.question = q.question.Replace("border=\"1\"", "class='table table-bordered'"); template = template.Replace("+[description]+", "Pytanie " + q.ID.ToString()); template = template.Replace("+[ID]+", q.ID.ToString()); template = template.Replace("+[question]+", q.QType != 2 ? q.question : imageHtml(q.ImageText, false)); template = template.Replace("+[options]+", q.Type == 4 ? "Opcje do wyboru</br> " + cq.GetOptionsToHtmlList() : ""); template = template.Replace("+[answer]+", cq.GetGoodAnswerHTML()); } else { template = cq.GetHtmlWithStyle(); } s.AppendLine(template); } mainTemplate = mainTemplate.Replace("+[body]+", s.ToString()); if (!String.IsNullOrEmpty(saveFileDialog2.FileName) && !String.IsNullOrEmpty(mainTemplate)) { try { File.WriteAllText(saveFileDialog2.FileName, mainTemplate, Encoding.GetEncoding("iso-8859-2")); MessageBox.Show("Zapisano"); } catch (Exception) { MessageBox.Show("Nie udało się zapisać"); } } } catch (Exception) { MessageBox.Show("Nie udało się zapisać"); } } }
private void QuestionForm_Load(object sender, EventArgs e) { int qn = getQuestionNumber(); checkButtons(getId(qn)); DbQuestion answer = parent.GetAnswer(qn); panel1.Size = new System.Drawing.Size(this.Size.Width - 130, this.Size.Height - 170); switch (questionType) { case 1: if (answer != null) { type1.q = answer; } Controls.Add(type1); type1.Location = new Point(105, panel1.Size.Height + 35); type1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; if (exam) { type1.Leave += new System.EventHandler(this.type1_Leave); } break; case 2: if (answer != null) { type2.q = answer; } Controls.Add(type2); type2.Location = new Point(105, panel1.Size.Height + 35); type2.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; type2.TabIndex = 1; if (exam) { type2.Leave += new System.EventHandler(this.type2_Leave); } break; case 3: if (answer != null) { type3.q = answer; } Controls.Add(type3); type3.Location = new Point(105, panel1.Size.Height + 35); type3.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; //type3.TabIndex = 1; if (exam) { type3.Leave += new System.EventHandler(this.type3_Leave); } break; case 4: panel1.Size = new System.Drawing.Size(this.Size.Width - 130, this.Size.Height - 200); type4q.Location = new Point(105, panel1.Size.Height + 35); if (answer != null) { type4q.q = answer; type4q.h = parent.list.Where(a => a.ID == qn).Select(a => a.H).FirstOrDefault(); } else { type4q.h = parent.list.Where(a => a.ID == qn).Select(a => a.H).FirstOrDefault(); } type4q.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; if (exam) { type4q.Leave += new System.EventHandler(this.type4q_Leave); } Controls.Add(type4q); break; case 5: panel1.Size = new System.Drawing.Size(this.Size.Width - 130, this.Size.Height - 200); type5q.Location = new Point(105, panel1.Size.Height + 35); if (answer != null) { type5q.q = answer; type5q.h = parent.list.Where(a => a.ID == qn).Select(a => a.H).FirstOrDefault(); type5q.a = parent.list.Where(a => a.ID == qn).Select(a => a.A).FirstOrDefault(); type5q.b = parent.list.Where(a => a.ID == qn).Select(a => a.B).FirstOrDefault(); } else { type5q.h = parent.list.Where(a => a.ID == qn).Select(a => a.H).FirstOrDefault(); type5q.a = parent.list.Where(a => a.ID == qn).Select(a => a.A).FirstOrDefault(); type5q.b = parent.list.Where(a => a.ID == qn).Select(a => a.B).FirstOrDefault(); } type5q.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; if (exam) { type5q.Leave += new System.EventHandler(this.type5q_Leave); } Controls.Add(type5q); break; case 6: panel1.Size = new System.Drawing.Size(this.Size.Width - 130, this.Size.Height - 200); type6.Location = new Point(105, panel1.Size.Height + 35); if (answer != null) { type6.q = answer; type6.h = parent.list.Where(a => a.ID == qn).Select(a => a.H).FirstOrDefault(); type6.a = parent.list.Where(a => a.ID == qn).Select(a => a.A).FirstOrDefault(); type6.b = parent.list.Where(a => a.ID == qn).Select(a => a.B).FirstOrDefault(); } else { type6.h = parent.list.Where(a => a.ID == qn).Select(a => a.H).FirstOrDefault(); type6.a = parent.list.Where(a => a.ID == qn).Select(a => a.A).FirstOrDefault(); type6.b = parent.list.Where(a => a.ID == qn).Select(a => a.B).FirstOrDefault(); } type6.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; if (exam) { type6.Leave += new System.EventHandler(this.type6_Leave); } Controls.Add(type6); break; case 7: if (answer != null) { type7.q = answer; } Controls.Add(type7); type7.Location = new Point(105, panel1.Size.Height + 35); type7.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; type7.TabIndex = 1; if (exam) { type7.Leave += new System.EventHandler(this.type7_Leave); } break; default: break; } CheckedQuestion c = new CheckedQuestion(); c.Question = parent.list.Where(a => a.ID == qn).FirstOrDefault(); //if(parent.list.Where(a=>a.ID==qn).Select(a=>a.QType).FirstOrDefault()==2) // enableBtns(false); //else // enableBtns(true); goodAnwser = c.GetGoodAnwser(); }