206 lines
8.4 KiB
C#
206 lines
8.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Linq;
|
|
using Datalib.Linq;
|
|
using Datalib.EntityClasses;
|
|
using Datalib.FactoryClasses;
|
|
using Datalib.HelperClasses;
|
|
using DocumentFormat.OpenXml;
|
|
using DocumentFormat.OpenXml.Packaging;
|
|
using DocumentFormat.OpenXml.Validation;
|
|
using OpenXmlPowerTools;
|
|
|
|
namespace Omega.Forms
|
|
{
|
|
public partial class frmCreateQuiz : Omega.BasicForms.frmCommon
|
|
{
|
|
public List<TblQuizEntity> QuizList = new List<TblQuizEntity>();
|
|
public frmCreateQuiz()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void frmCreateQuiz_Load(object sender, EventArgs e)
|
|
{
|
|
LinqMetaData meta = new LinqMetaData(adapter);
|
|
var temps = meta.TblQuizTemplate.OrderBy(m => m.TrainingTypeId);
|
|
this.QuizTemplate.Properties.DataSource = temps;
|
|
LinqMetaData Meta = new LinqMetaData(adapter);
|
|
this.repoQuizTemplate.DataSource = Meta.TblQuizTemplate;
|
|
}
|
|
|
|
private void Create_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
// Get Template
|
|
string QuizTemplateID = this.QuizTemplate.EditValue.ToString();
|
|
string QuizCode = this.QuizCode.Text;
|
|
LinqMetaData meta = new LinqMetaData(adapter);
|
|
var CurQuizTempate = meta.TblQuizTemplate.Where(m => m.QuizTemplateId == QuizTemplateID).FirstOrDefault();
|
|
var CurQuizTemplateDetail = meta.TblQuizTemplateDetail.Where(m => m.QuizTemplateId == QuizTemplateID).ToList<TblQuizTemplateDetailEntity>();
|
|
TblQuizEntity CurrQuiz = new TblQuizEntity(Guid.NewGuid().ToString("N"));
|
|
CurrQuiz.QuizName = this.QuizName.Text;
|
|
CurrQuiz.QuizTime = Convert.ToInt16(this.QuizTime.EditValue);
|
|
CurrQuiz.QuizYear = Convert.ToInt16(this.QuizYear.EditValue);
|
|
CurrQuiz.QuizTemplateId = QuizTemplateID;
|
|
CurrQuiz.QuizCode = QuizCode;
|
|
EntityCollection<TblQuizQuestionEntity> QuizQuestions = CurrQuiz.TblQuizQuestions;
|
|
|
|
List<string> ExclusiveQuestions = new List<string>();
|
|
|
|
switch(SettingInfo.Exclusive)
|
|
{
|
|
case "1":
|
|
ExclusiveQuestions = (from q in meta.TblQuizQuestion where (q.TrainingTypeId == CurQuizTempate.TrainingTypeId) select q.QuestionId).ToList<string>();
|
|
|
|
break;
|
|
case "2":
|
|
|
|
ExclusiveQuestions = (from q in meta.TblQuizQuestion where (q.QuizTemplateId == CurQuizTempate.QuizTemplateId) select q.QuestionId).ToList<string>();
|
|
|
|
break;
|
|
case "3":
|
|
ExclusiveQuestions = (from q in meta.TblQuizQuestion select q.QuestionId).ToList<string>();
|
|
break;
|
|
}
|
|
|
|
|
|
foreach (var QuizDetail in CurQuizTemplateDetail)
|
|
{
|
|
|
|
int QuestionNum = (int)QuizDetail.QuestionNum;
|
|
string SubjectID = QuizDetail.SubjectId;
|
|
string Level = QuizDetail.Level;
|
|
string Difficulty = QuizDetail.Difficulty;
|
|
string FieldID = QuizDetail.FieldId;
|
|
List<Quiz> Questions;
|
|
if (QuizDetail.Difficulty == "A")
|
|
{
|
|
|
|
if(QuizDetail.Level=="A")
|
|
{
|
|
Questions = (from q in meta.TblQuestion
|
|
where (q.Exclusive != true && q.SubjectId == SubjectID && q.FieldId == FieldID && !(from o in ExclusiveQuestions select o).Contains(q.QuestionId))
|
|
select new Quiz { QuestionId = q.QuestionId, Order = 0 }).ToList();
|
|
}
|
|
else
|
|
{
|
|
Questions = (from q in meta.TblQuestion
|
|
where (q.Exclusive != true && q.SubjectId == SubjectID && q.FieldId == FieldID && q.Level == Level && !(from o in ExclusiveQuestions select o).Contains(q.QuestionId))
|
|
select new Quiz { QuestionId = q.QuestionId, Order = 0 }).ToList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
{
|
|
|
|
if (QuizDetail.Level == "A")
|
|
{
|
|
Questions = (from q in meta.TblQuestion
|
|
where (q.Exclusive != true && q.SubjectId == SubjectID && q.FieldId == FieldID && q.Difficulty == Difficulty && !(from o in ExclusiveQuestions select o).Contains(q.QuestionId))
|
|
select new Quiz { QuestionId = q.QuestionId, Order = 0 }).ToList();
|
|
|
|
} else
|
|
{
|
|
Questions = (from q in meta.TblQuestion
|
|
where (q.Exclusive != true && q.SubjectId == SubjectID && q.FieldId == FieldID && q.Difficulty == Difficulty && q.Level == Level && !(from o in ExclusiveQuestions select o).Contains(q.QuestionId))
|
|
select new Quiz { QuestionId = q.QuestionId, Order = 0 }).ToList();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Questions.Count < QuestionNum + SettingInfo.MinQuestionNum -1)
|
|
{
|
|
|
|
frmWarning frm = new frmWarning();
|
|
frm.RestQuestionNum.Text = Questions.Count.ToString();
|
|
frm.QuizTemplateDetai = QuizDetail;
|
|
frm.LoadData();
|
|
frm.ShowDialog();
|
|
}
|
|
|
|
Random rnd = new Random();
|
|
|
|
foreach (var q in Questions)
|
|
{
|
|
q.Order = rnd.Next(1, 1000);
|
|
}
|
|
|
|
|
|
foreach (var m in Questions.OrderBy(m => m.Order).Take(QuestionNum))
|
|
{
|
|
TblQuizQuestionEntity QuizQuestion = QuizQuestions.AddNew();
|
|
QuizQuestion.UniqueId = Guid.NewGuid().ToString("N");
|
|
QuizQuestion.QuestionId = m.QuestionId;
|
|
QuizQuestion.QuizTemplateId = QuizTemplateID;
|
|
QuizQuestion.TrainingTypeId = CurQuizTempate.TrainingTypeId;
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
adapter.SaveEntity(CurrQuiz, true, true);
|
|
QuizList.Add(CurrQuiz);
|
|
|
|
grdQuiz.DataSource = null;
|
|
|
|
grdQuiz.DataSource = QuizList;
|
|
|
|
}
|
|
|
|
private void Print_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
this.progressPanel.Visible = true;
|
|
List<Source> sources = new List<Source>();
|
|
LinqMetaData meta = new LinqMetaData(adapter);
|
|
this.progressPanel.Visible = false;
|
|
if (QuizList.Count > 0)
|
|
{
|
|
TblQuizEntity CurrQuiz = (TblQuizEntity)QuizList[this.BindingContext[QuizList].Position];
|
|
Utilities.PrintQuiz(CurrQuiz);
|
|
|
|
}
|
|
this.progressPanel.Visible = false;
|
|
|
|
}
|
|
|
|
|
|
private void QuizTemplate_EditValueChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
LinqMetaData meta = new LinqMetaData(adapter);
|
|
string QuizTemplateId = this.QuizTemplate.EditValue.ToString();
|
|
string QuizTemplateCode = meta.TblQuizTemplate.Where(m => m.QuizTemplateId == QuizTemplateId).FirstOrDefault().QuizTemplateCode;
|
|
this.QuizCode.Text = QuizTemplateCode + "-" + this.QuizYear.Text;
|
|
}
|
|
|
|
private void CloseForm_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void PrintAnswer_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
|
{
|
|
this.progressPanel.Visible = true;
|
|
List<Source> sources = new List<Source>();
|
|
LinqMetaData meta = new LinqMetaData(adapter);
|
|
this.progressPanel.Visible = false;
|
|
if (QuizList.Count > 0)
|
|
{
|
|
TblQuizEntity CurrQuiz = (TblQuizEntity)QuizList[this.BindingContext[QuizList].Position];
|
|
Utilities.PrintQuizAnswer(CurrQuiz);
|
|
|
|
}
|
|
this.progressPanel.Visible = false;
|
|
}
|
|
}
|
|
} |