private void createExamFile_Click(object sender, EventArgs e) { var invalid = Questions.Any(q => q.Score == 0); if (invalid) { lblMessage.ForeColor = Color.Red; lblMessage.Text = "نمره برخی سوالها وارد نشده است"; return; } Exam exam = new Exam(); exam.Id = Guid.NewGuid().ToString(); var st = faDatePicker1.SelectedDateTime; if (st.HasValue) { var s = st.Value.ToUniversalTime(); st = PersianDateConverter.ToMiladi(s); st = new DateTime(s.Year, s.Month, s.Day, int.Parse(comboStartHour.Text), int.Parse(comboStartMinute.Text), 0); } exam.StartTime = st; exam.Time = new TimeSpan(int.Parse(comboHour.Text), int.Parse(comboMinute.Text), 0); exam.ExamName = txtName.Text; exam.PasswordForExamTime = txtPassword.Text; exam.PasswordForEvaluationTime = txtEPass.Text; int i = 0; foreach (var q in Questions) { exam.AddQuestion(q, i++); } IFormatter formatter = new BinaryFormatter(); SaveFileDialog save = new SaveFileDialog(); save.Filter = "آزمون پرسان(*.pex)|*.pex"; if (save.ShowDialog() == DialogResult.OK) { FileStream fileStream = new FileStream(save.FileName, FileMode.Create, FileAccess.Write, FileShare.None); //MemoryStream ms = new MemoryStream(); RijndaelManaged rmCrypto = new RijndaelManaged(); byte[] key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 }; byte[] iv = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 }; //Create a CryptoStream, pass it the NetworkStream, and encrypt //it with the Rijndael class. CryptoStream cryptStream = new CryptoStream(fileStream, rmCrypto.CreateEncryptor(key, iv), CryptoStreamMode.Write); formatter.Serialize(cryptStream, exam); cryptStream.Close(); fileStream.Close(); } }
private void btnSearch_Click(object sender, EventArgs e) { searchExpr = txtSearchExpr.Text; lessonName = lessonsComboBox1.Text; fromDate = fdpFrom.SelectedDateTime == null ? (DateTime?)null : PersianDateConverter.ToMiladi(fdpFrom.SelectedDateTime); toDate = fdpTo.SelectedDateTime == null ? (DateTime?)null : PersianDateConverter.ToMiladi(fdpTo.SelectedDateTime); tags = tagsBox1.Tags; flpLongQuestions.Controls.Clear(); flpMultiOptionsQuestions.Controls.Clear(); flpPracticalQuestions.Controls.Clear(); flpPuzzleQuestions.Controls.Clear(); flpShortQuestions.Controls.Clear(); flpTFQuestions.Controls.Clear(); search(); }
public void search() { if (toDate != null) { toDate.Value.AddHours(-1 * toDate.Value.Hour).AddHours(24); } System.Diagnostics.Debug.WriteLine(PersianDateConverter.ToMiladi(fdpTo.SelectedDateTime).Year); using (var db = new irQmDbContext()) { IQuestion[] questions = null; FlowLayoutPanel target = null; switch (tabControl1.SelectedIndex) { case 0: questions = db.MultiChoicesQuestions.Where(q => (string.IsNullOrWhiteSpace(lessonName) ? true : q.LessonName == lessonName) && (fromDate != null ? q.RegisterTime >= fromDate : true) && (toDate != null ? q.RegisterTime <= toDate : true) && tags.All(tg => db.TagInMultichoices.Any(t => t.QuestionId == q.Id && t.Tag.Value == tg)) && richContains(q.Face, searchExpr)).Include(q => q.Options).Include(q => q.Tags).ToArray(); target = flpMultiOptionsQuestions; break; case 1: questions = db.TFQuestions.Where(q => (string.IsNullOrWhiteSpace(lessonName) ? true : q.LessonName == lessonName) && (fromDate != null ? q.RegisterTime >= fromDate : true) && (toDate != null ? q.RegisterTime <= toDate : true) && tags.All(tg => db.TagInTfQuestion.Any(t => t.QuestionId == q.Id && t.Tag.Value == tg)) && richContains(q.Face, searchExpr)).Include(q => q.Tags).ToArray(); target = flpTFQuestions; break; case 2: questions = db.PuzzleQuestions.Where(q => (string.IsNullOrWhiteSpace(lessonName) ? true : q.LessonName == lessonName) && (fromDate != null ? q.RegisterTime >= fromDate : true) && (toDate != null ? q.RegisterTime <= toDate : true) && tags.All(tg => db.TagInPuzzle.Any(t => t.QuestionId == q.Id && t.Tag.Value == tg)) && richContains(q.Face, searchExpr)).Include(q => q.Pairs).Include(q => q.Tags).ToArray(); target = flpPuzzleQuestions; break; case 3: questions = db.ShortAnswerQustions.Where(q => (string.IsNullOrWhiteSpace(lessonName) ? true : q.LessonName == lessonName) && (fromDate != null ? q.RegisterTime >= fromDate : true) && (toDate != null ? q.RegisterTime <= toDate : true) && tags.All(tg => db.TagInShortAnswer.Any(t => t.QuestionId == q.Id && t.Tag.Value == tg)) && richContains(q.Face, searchExpr)).Include(q => q.Answer).Include(q => q.Tags).ToArray(); target = flpShortQuestions; break; case 4: questions = db.LongAnswerQuestions.Where(q => (string.IsNullOrWhiteSpace(lessonName) ? true : q.LessonName == lessonName) && (fromDate != null ? q.RegisterTime >= fromDate : true) && (toDate != null ? q.RegisterTime <= toDate : true) && tags.All(tg => db.TagInLongAnswer.Any(t => t.QuestionId == q.Id && t.Tag.Value == tg)) && richContains(q.Face, searchExpr)).Include(q => q.Tags).ToArray(); target = flpLongQuestions; break; case 5: questions = db.PracticalQuestions.Where(q => (string.IsNullOrWhiteSpace(lessonName) ? true : q.LessonName == lessonName) && (fromDate != null ? q.RegisterTime >= fromDate : true) && (toDate != null ? q.RegisterTime <= toDate : true) && tags.All(tg => db.TagInPractical.Any(t => t.QuestionId == q.Id && t.Tag.Value == tg)) && richContains(q.Face, searchExpr)).Include(q => q.Tags).Include(q => q.CheckList).ToArray(); target = flpPracticalQuestions; break; case 6: return; } int i = 1; target.Controls.Clear(); foreach (var q in questions.OrderBy(q => q.Face)) { var qitem = new UCQuestionListItem(q, q.RegisterTime.ToLocalTime().ToPrettyTime(), i); qitem.Width = multiTabPage.Width - 50; qitem.RightToLeft = RightToLeft.Yes; qitem.Anchor = AnchorStyles.Right | AnchorStyles.Left; qitem.Resize += (s, ev) => { qitem.MaximumSize = new Size(Width - 50, 0); }; qitem.Removed += Qitem_Removed; qitem.CheckedChange += Qitem_CheckedChange; qitem.Name = q.Id; if (selectedQuestions.Contains(q)) { qitem.Checked = true; } target.Controls.Add(qitem); qitem.QuestionEdited += Qitem_QuestionEdited; list.Add(qitem); i++; } } }