private static void FindFactor(ref PreferencesRow p, ref ExamsListRow ls) { ExamsRow[] arr = ls.GetExamsRows(); double sumPoint = arr.Sum(o => o.QuestionsRow.Weight); double factor = Convert.ToDouble(p.Points); factor /= (sumPoint); p.Factor = factor; arr = null; }
private static void doOneEncriptExam(ref PreferencesRow p, ref ExamsListRow ls, out IList <string[]> questionAnswer, string password) { IEnumerable <DB.ExamsRow> join = ls.GetExamsRows(); string[] ClaveWQID = null; ClaveWQID = makeQAs(ref join, ref p, out questionAnswer); ls.LQuestion = ClaveWQID[1]; // question weight string string LAnswer = ClaveWQID[0]; //clave verdadera sin encriptar string QIDString = ClaveWQID[2]; //secuencia de preguntas, importante guardar ls.CLAnswer = Rsx.Encryption.AESThenHMAC.SimpleEncryptWithPassword(LAnswer, password, null); //encripta ls.CQIDString = Rsx.Encryption.AESThenHMAC.SimpleEncryptWithPassword(QIDString, password, null); //encripta }
public ExamsListRow AddExam(ref PreferencesRow p) { ExamsListRow ls = ExamsList.NewExamsListRow(); ExamsList.AddExamsListRow(ls); Guid g = Guid.NewGuid(); ls.PID = p.PID; ////MAKES THE DOC FILE ls.GUID = g.ToString().Replace("-", null);//.Split('-')[4]; ls.Time = DateTime.Now; ls.Class = p.Class; return(ls); }
private static object MakeDOC(ref ExamsListRow ls, ref IList <string[]> questionAnswer, string filepathAux, string title, bool showAnswer, string pass) { W.Document doc = openDocApp(filepathAux); string Intro = "Recorte el Cupón"; // W.Document doc = ExamMain.MakeWord(ref destFile, ref w); //makes the word file makeExamIntro(ref doc, filepathAux + JPG_EXT, Intro, title); makeExamCoupon(ref doc, filepathAux + JPG_EXT, ref ls, showAnswer, pass); makeExamFileBody(ref questionAnswer, ref doc); // Application.DoEvents(); //save word doc.Save(); return(doc); }
private void doOneDocExam(ref PreferencesRow p, ref ExamsListRow ls, ref IList <string[]> questionAnswer) { string filepathAux = examsPath + model + ls.GUID; string CryptoGUID = Rsx.Encryption.AESThenHMAC.SimpleEncryptWithPassword(ls.GUID, inter.Password, null); // string jpgQRCodeFile = filepathAux + JPG_EXT; Image img = Tools.CreateQRCode(CryptoGUID, qrSise); img.Save(filepathAux + JPG_EXT); img.Dispose(); // string destFile = filepathAux + WORD_EXT; ///MAKE WORD DOCUMENT /// File.Copy(templateFile, filepathAux + WORD_EXT); string title = p.Title + " (" + p.Class + ")"; bool showAnswer = p.showAnswer; string pass = inter.Password; object doc = Generator.MakeDOC(ref ls, ref questionAnswer, filepathAux, title, showAnswer, pass); inter.Status = Resources.ExamenCreado; bool close = true; bool quit = true; Generator.MakePDF(ref doc, close, quit); Byte[] rtf = IO.ReadFileBytes(filepathAux + PDF_EXT); ls.ExamFile = rtf; //salva una copia del archivo PDF en el servidor SQL DB.TAM.ExamsListTableAdapter.Update(ls); inter.Status = Resources.ExamenCreadoPDF; File.Delete(filepathAux + PDF_EXT); File.Delete(filepathAux + WORD_EXT); File.Delete(filepathAux + JPG_EXT); }
public void DoExams() { PreferencesRow p = inter.IBS.CurrentPreference; inter.IBS.Working = true; updatePreferenceAndClone(ref p); inter.IBS.Working = false; inter.IBS.LogPref.Position = inter.IBS.LogPref.Find(inter.IdB.Preferences.PIDColumn.ColumnName, p.PID); inter.IBS.Working = true; inter.Status = "Empezando..."; FillClassDataBase(p.Class); // inter.IBS.LogPref.MoveFirst(); //select item to clone Application.DoEvents(); inter.ProgressHandler?.Invoke(p.Models, EventArgs.Empty); int mod = 0; //models for (mod = 0; mod < p.Models; mod++) { inter.IdB.Exams.Clear(); inter.ProgressHandler?.Invoke(0, EventArgs.Empty); ExamsListRow ls = doOneExam(ref p); if (ls == null) { continue; } inter.ProgressHandler?.Invoke(0, EventArgs.Empty); Generator.FindFactor(ref p, ref ls); ////ENCRIPTAMIENTOOOOOOO inter.Status = "Procesando examen..."; IList <string[]> questionAnswer; doOneEncriptExam(ref p, ref ls, out questionAnswer, inter.Password); //SAVE COPY OF TABLE in EXAMLIST Generator.MakeTableBytes(ref ls, examsPath); DB.TAM.ExamsListTableAdapter.Update(inter.IdB.ExamsList); inter.ProgressHandler?.Invoke(0, EventArgs.Empty); inter.Status = Resources.Creando + "el examen " + ls.GUID; doOneDocExam(ref p, ref ls, ref questionAnswer); inter.Status = "Examen generado"; inter.ProgressHandler?.Invoke(0, EventArgs.Empty); } Generator.MakeTableBytes(ref p, examsPath); int count = p.GetExamsListRows().Count(); if (count != 0) { inter.Status = count + " Modelos generados"; } DB.TAM.PreferencesTableAdapter.Update(p); inter.IdB.Exams.Clear(); inter.IBS.Working = false; }
/// <summary> /// MAIN FILE FOR GENERATING AN EXAM /// </summary> /// <param name="p"></param> private ExamsListRow doOneExam(ref PreferencesRow p) { inter.Status = Resources.Creando + inter.IdB.Questions.Count + Resources.PregAleatorias; Func <DB.QuestionsRow, bool> selector = x => { bool?ok = x.TopicsRow?.UseIt; if (ok == null) { ok = false; } return((bool)ok); }; ///RANDOMNIZE RAW QUESTIONS IEnumerable <DB.QuestionsRow> questions = inter.IdB.Questions.Where(selector).ToArray(); //toma todas las preguntas if (questions.Count() == 0) { inter.Status = "No hay preguntas seleccionadas"; return(null); } int times = 3; questions = Tools.RandomnizeStringsTimes(questions, times); IList <ExamsRow> exams = new List <ExamsRow>(); //todas las preguntas randomnizadas seran guardadas primero en esta lista foreach (QuestionsRow q in questions) { ExamsRow er = inter.IdB.Exams.NewExamsRow(); //crea rows pero no los metas en la tabla er.QID = q.QID; //dales el id de la pregunta exams.Add(er); //agregalos a la lista } inter.Status = Resources.Filtrando; IEnumerable <ExamsRow> join = weightThem(ref p, ref exams); //not re-ordered // preguntas seleccionadas y filtradas Application.DoEvents(); inter.Status = Resources.OrderAleatorio; // de las preguntas del examen ya pesadas (filtradaS) join = Tools.RandomnizeStringsTimes(join, times); inter.Status = Resources.Seleccionando + join.Count() + Resources.PregAleatorias; Application.DoEvents(); foreach (ExamsRow ex in join) { inter.IdB.Exams.AddExamsRow(ex); //agregalas a la tabla para salvarlas DB.QuestionsRow q = ex.QuestionsRow; IEnumerable <AnswersRow> answ = q.GetAnswersRows(); ///RANDOMIZE RAW ASWERS answ = Tools.RandomnizeStringsTimes(answ, times); //CREATE EXAM QUESTION CODE! AIDSTRING string code = CreateExamQuestionCode(ref answ); ex.AIDString = code; ExamsRow auxiliar = ex; MakeTableBytes(ref auxiliar, examsPath); } DB.TAM.ExamsTableAdapter.Update(inter.IdB.Exams); Application.DoEvents(); ExamsListRow ls = inter.IdB.AddExam(ref p); // Image img = Tools.CreateQRCode(ls.GUID, qrSizeDB); ls.QRCode = Tools.imageToByteArray(img); DB.TAM.ExamsListTableAdapter.Update(inter.IdB.ExamsList); Application.DoEvents(); //este orden es importante foreach (DB.ExamsRow re in join) { re.EID = ls.EID; //ahora asocia las preguntas a cada examen generado } DB.TAM.ExamsTableAdapter.Update(inter.IdB.Exams); Application.DoEvents(); return(ls); }
private static void MakeTableBytes <T>(ref T l, string examPath) { Type tipo = l.GetType(); byte[] arr2 = null; // string afile = string.Empty; if (tipo.Equals(typeof(ExamsListRow))) { ExamsListRow ls = l as ExamsListRow; IEnumerable <ExamsRow> rows = ls.GetExamsRows(); ExamsDataTable exdt = new ExamsDataTable(); foreach (var item in rows) { exdt.ImportRow(item); } // afile = ExasmPath + ls.EID.ToString(); arr2 = Tables.MakeDTBytes(ref exdt, examPath); ls.EData = arr2; } else if (tipo.Equals(typeof(ExamsRow))) { //SAVE COPY OF TABLE ExamsRow ex = l as ExamsRow; QuestionsRow q = ex.QuestionsRow; // afile = ExasmPath + ex.QID.ToString(); IEnumerable<DB.QuestionsRow> shortQlist = // new List<DB.QuestionsRow>(); ((IList<DB.QuestionsRow>)shortQlist).Add(ex.QuestionsRow); QuestionsDataTable qdt = new QuestionsDataTable(); qdt.ImportRow(q); byte[] qarray = Tables.MakeDTBytes(ref qdt, examPath); ex.QData = qarray; Dumb.FD(ref qdt); AnswersDataTable adt = new AnswersDataTable(); IEnumerable <AnswersRow> answ = q.GetAnswersRows(); foreach (var item in answ) { adt.ImportRow(item); } // afile = ExasmPath + ex.QueToString() + ".xml"; arr2 = Tables.MakeDTBytes(ref adt, examPath); ex.AData = arr2; Dumb.FD(ref adt); } else if (tipo.Equals(typeof(PreferencesRow))) { PreferencesRow p = l as PreferencesRow; //SAVE A COPY OF EXAMS LISTS IEnumerable <DB.ExamsListRow> rows = p.GetExamsListRows(); ExamsListDataTable dt = new ExamsListDataTable(); foreach (var item in rows) { dt.ImportRow(item); } // afile = ExasmPath + p.PID.ToString() + ".xml"; arr2 = Tables.MakeDTBytes(ref dt, examPath); p.ELData = arr2; Dumb.FD(ref dt); } }
private static void makeExamCoupon(ref W.Document doc, string qrCodeJPG, ref ExamsListRow ls, bool showAnswer, string password) { string text = string.Empty; W.Range aux = null; aux = doc.Paragraphs.Last.Range; text = "\n\n\n"; text += Resources.CortaCupon; // text += "\n\n\n"; aux.Text = text; aux.set_Style(W.WdBuiltinStyle.wdStyleFooter); aux.InsertParagraphAfter(); doc.Paragraphs.Add(aux); aux = doc.Paragraphs.Last.Range; object lastRange = aux; aux.InlineShapes.AddPicture(qrCodeJPG, ref roObj, ref roObj, ref lastRange); aux.InlineShapes.AddPicture(ID_FILE, ref roObj, ref roObj, ref lastRange); aux.set_Style(W.WdBuiltinStyle.wdStyleTitle); aux.InsertParagraphAfter(); doc.Paragraphs.Add(aux); aux = doc.Paragraphs.Last.Range; int cuadros = ls.GetExamsRows().Count(); text = string.Empty; text += Resources.ExamenRespuesta; text += " "; string ahorcado = string.Empty; int j = 0; for (int i = 0; i < cuadros; i++) { ahorcado += "__ "; j++; if (j == 5) { ahorcado += "-"; j = 0; } } text += ahorcado; text += "\n\n"; text += Resources.ExamenRespuesta; text += " "; string ahorcadoNr = string.Empty; j = 0; for (int i = 0; i < cuadros; i++) { int cuenta = i + 1; ahorcadoNr += cuenta.ToString(); ahorcadoNr += " "; if (cuenta < 10) { ahorcadoNr += " "; } j++; if (j == 5) { ahorcadoNr += "-"; j = 0; } } text += ahorcadoNr; if (showAnswer) { text += "\n\n"; text += Resources.ExamenRespuestaCorrecta; text += "\t"; text += Rsx.Encryption.AESThenHMAC.SimpleDecryptWithPassword(ls.CLAnswer, password, 0); text += "\n\n"; text += "Encriptada como:\t"; text += ls.CLAnswer; text += "\n\n"; text += "Examen modelo:\t"; text += ls.GUID; // text += "\n\n"; text += "Encriptado como:\t"; text += ; } aux.Text = text; aux.set_Style(W.WdBuiltinStyle.wdStyleFooter); /// ESTA ES LA CLAVE!!! aux.InsertParagraphAfter(); doc.Paragraphs.Add(aux); }
internal void PopulateExamQuestions(ref ExamsListRow r) { // DB.TAM.ExamsTableAdapter.FillByEID(dt, r.EID); //now find the examsTablewith questions and answers for the EXAM (list) // if (!r.NeedsExams) return; // string eid = ExasmPath + r.EID.ToString() + ".xml"; this.Preferences.Clear(); this.Preferences.ImportRow(r.PreferencesRow); this.Class.Clear(); this.Class.ImportRow(r.PreferencesRow.ClassRow); this.AYear.Clear(); this.AYear.ImportRow(r.PreferencesRow.AYearRow); Environment.SpecialFolder dir = Environment.SpecialFolder.InternetCache; string cache = Environment.GetFolderPath(dir) + "\\"; byte[] auxiliar; auxiliar = r.EData; ExamsDataTable dt2 = new ExamsDataTable(); Rsx.Dumb.Tables.ReadDTBytes(cache, ref auxiliar, ref dt2); this.Exams.Clear(); this.Exams.Merge(dt2); Rsx.Dumb.Dumb.FD(ref dt2); this.ExamsList.Clear(); this.ExamsList.ImportRow(r); r = this.ExamsList.First(); // if (r.NeedsExams) return; this.Questions.Clear(); IEnumerable <ExamsRow> rows = r.GetExamsRows(); foreach (var item in rows) { auxiliar = item.QData; QuestionsDataTable qdt = new QuestionsDataTable(); Rsx.Dumb.Tables.ReadDTBytes(cache, ref auxiliar, ref qdt); this.Questions.Merge(qdt); Rsx.Dumb.Dumb.FD(ref qdt); } this.Answers.Clear(); // IEnumerable<ExamsRow> rows = r.GetExamsRows(); foreach (var item in rows) { auxiliar = item.AData; AnswersDataTable adt = new AnswersDataTable(); Rsx.Dumb.Tables.ReadDTBytes(cache, ref auxiliar, ref adt); this.Answers.Merge(adt); Rsx.Dumb.Dumb.FD(ref adt); } this.AcceptChanges(); }