void CreateExamControl(Guid guid) { List <View_HR_Train_QuestionBank> lstBankInfo = _ServiceBasicInfo.GetListQuestionBank(guid); if (lstBankInfo.Count() == 0) { return; } plExam.Controls.Clear(); CE_HR_Train_QuesitonsType quesType = GeneralFunction.StringConvertToEnum <CE_HR_Train_QuesitonsType>(lstBankInfo[0].考题类型); Font font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); Label lbType = new Label(); lbType.AutoSize = true; lbType.Font = font; lbType.Location = new System.Drawing.Point(32, 51); lbType.Size = new System.Drawing.Size(119, 14); lbType.Text = "题目类型:" + quesType.ToString(); plExam.Controls.Add(lbType); Label lbTM = new Label(); lbTM.AutoSize = true; lbTM.Font = font; lbTM.Location = new System.Drawing.Point(32, 93); lbTM.Size = new System.Drawing.Size(49, 14); lbTM.Text = (_IndexGuid + 1).ToString() + ". 题目:"; plExam.Controls.Add(lbTM); Label lbQuestions = new Label(); lbQuestions.Font = font; lbQuestions.Location = new System.Drawing.Point(32, 135); lbQuestions.Size = new System.Drawing.Size(573, 116); lbQuestions.Text = lstBankInfo[0].考题内容; plExam.Controls.Add(lbQuestions); int height = 278; switch (quesType) { case CE_HR_Train_QuesitonsType.判断题: RadioButton rbYes = new RadioButton(); rbYes.AutoSize = true; rbYes.Font = font; rbYes.Location = new System.Drawing.Point(35, height); rbYes.Size = new System.Drawing.Size(95, 18); rbYes.Text = "YES"; plExam.Controls.Add(rbYes); height += 42; RadioButton rbNo = new RadioButton(); rbNo.AutoSize = true; rbNo.Font = font; rbNo.Location = new System.Drawing.Point(35, height); rbNo.Size = new System.Drawing.Size(95, 18); rbNo.TabStop = true; rbNo.Text = "NO"; plExam.Controls.Add(rbNo); break; case CE_HR_Train_QuesitonsType.单选题: for (int i = 0; i < lstBankInfo.Count; i++) { if (i != 0) { height += 42; } RadioButton rbSingle = new RadioButton(); rbSingle.AutoSize = true; rbSingle.Font = font; rbSingle.Location = new System.Drawing.Point(35, height); rbSingle.Size = new System.Drawing.Size(95, 18); rbSingle.Text = lstBankInfo[i].项 + "." + lstBankInfo[i].项内容; plExam.Controls.Add(rbSingle); } break; case CE_HR_Train_QuesitonsType.多选题: for (int i = 0; i < lstBankInfo.Count; i++) { if (i != 0) { height += 42; } CheckBox chbMulit = new CheckBox(); chbMulit.AutoSize = true; chbMulit.Font = font; chbMulit.Location = new System.Drawing.Point(35, height); chbMulit.Size = new System.Drawing.Size(95, 18); chbMulit.Text = lstBankInfo[i].项 + "." + lstBankInfo[i].项内容; plExam.Controls.Add(chbMulit); } break; default: break; } height += 78; Button btnUp = new Button(); btnUp.Font = font; btnUp.Location = new System.Drawing.Point(190, height); btnUp.Size = new System.Drawing.Size(75, 23); btnUp.Text = "上一题"; plExam.Controls.Add(btnUp); Button btnNext = new Button(); btnNext.Font = font; btnNext.Location = new System.Drawing.Point(342, height); btnNext.Size = new System.Drawing.Size(75, 23); if (_IndexGuid + 1 == _ListGuidQuestion.Count) { btnNext.Text = "提交试卷"; } else { btnNext.Text = "下一题"; } plExam.Controls.Add(btnNext); btnNext.Click += new EventHandler(btnNext_Click); btnUp.Click += new EventHandler(btnUp_Click); }
public void InputQuestionsBank(int courseID, DataTable questionsTable) { DepotManagementDataContext ctx = CommentParameter.DepotDataContext; ctx.Connection.Open(); ctx.Transaction = ctx.Connection.BeginTransaction(); try { questionsTable = DataSetHelper.OrderBy(questionsTable, "考题ID,选项"); List <string> lstQuestions = DataSetHelper.ColumnsToList_Distinct(questionsTable, "考题ID"); foreach (string questionsID in lstQuestions) { DataTable tempQuestions = DataSetHelper.SiftDataTable(questionsTable, "考题ID = '" + questionsID + "'"); if (tempQuestions.Rows.Count > 0) { CE_HR_Train_QuesitonsType quesType = GeneralFunction.StringConvertToEnum <CE_HR_Train_QuesitonsType>(tempQuestions.Rows[0]["考题类型"].ToString()); HR_Train_QuestionBank bank = new HR_Train_QuestionBank(); switch (quesType) { case CE_HR_Train_QuesitonsType.判断题: bank.Answer = tempQuestions.Rows[0]["答案"].ToString().ToUpper(); bank.CourseID = courseID; bank.ID = Guid.NewGuid(); bank.Questions = tempQuestions.Rows[0]["考题内容"].ToString(); bank.Type = tempQuestions.Rows[0]["考题类型"].ToString(); ctx.HR_Train_QuestionBank.InsertOnSubmit(bank); break; case CE_HR_Train_QuesitonsType.单选题: case CE_HR_Train_QuesitonsType.多选题: Guid guid = Guid.NewGuid(); bank.Answer = tempQuestions.Rows[0]["答案"].ToString().ToUpper(); bank.CourseID = courseID; bank.ID = guid; bank.Questions = tempQuestions.Rows[0]["考题内容"].ToString(); bank.Type = tempQuestions.Rows[0]["考题类型"].ToString(); ctx.HR_Train_QuestionBank.InsertOnSubmit(bank); ctx.SubmitChanges(); foreach (DataRow dr in tempQuestions.Rows) { HR_Train_QuestionBank_Option option = new HR_Train_QuestionBank_Option(); option.OptionContent = dr["选项内容"].ToString(); option.OptionTag = dr["选项"].ToString().ToUpper(); option.QuestionID = guid; ctx.HR_Train_QuestionBank_Option.InsertOnSubmit(option); } ctx.SubmitChanges(); break; default: break; } } } ctx.SubmitChanges(); ctx.Transaction.Commit(); } catch (Exception ex) { ctx.Transaction.Rollback(); throw new Exception(ex.Message); } }