注释习惯
#region File Header & Copyright Notice /* * Copyright (C) 2014XXXXXX */ #endregion using System; using System.Threading; using System.Windows.Forms; using System.ServiceModel; using System.ComponentModel; using Constant; using Model; using OES.Teacher; using Tool; namespace OES { /// <summary> /// This class is used for login. /// </summary> public partial class FormLogin : Form { #region Field private log4net.ILog log = log4net.LogManager.GetLogger(EqualsConst.GetLoggerName); public User user = null; #endregion #region Constructor public FormLogin() { InitializeComponent(); } #endregion #region Private Method /// <summary> /// The processing of btnSubmit. /// </summary> /// <param name="sender">The source object of event.</param> /// <param name="e">The parameter of event.</param> private void BtnSubmit_Click(object sender, EventArgs e) { UserBllService.UserBllClient userBll = new UserBllService.UserBllClient(); if (String.IsNullOrWhiteSpace(this.txtUsername.Text)) { this.lblLoginResult.Text = Constant.UserException.UserNameIsNull; } else if (String.IsNullOrWhiteSpace(this.txtPassword.Text)) { this.lblLoginResult.Text = Constant.UserException.PasswordIsNull; } else { string userName = CheckForParameter.ReplaceSqlChar(this.txtUsername.Text.Trim()); string password = CheckForParameter.ReplaceSqlChar(this.txtPassword.Text.Trim()); try { BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += new DoWorkEventHandler( delegate { user = userBll.RetrieveUserByUserName(userName); }); bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler( delegate(object obj, RunWorkerCompletedEventArgs arg) { if (arg.Error == null) { if (null != user && user.Password.Equals(MD5Tool.MD5Tostring(password), StringComparison.InvariantCultureIgnoreCase)) { this.DialogResult = DialogResult.OK; } else { this.lblLoginResult.Text = UserException.LoginedFailed; } } else { log.Error(arg.Error); MessageBox.Show(UIException.ConnectionWithWCFFail); } }); bw.RunWorkerAsync(); } catch (FaultException<MyExceptionContainer> myException) { log.Error(myException.Message, myException); } catch (FaultException faultException) { log.Error(faultException.Message, faultException); } catch (Exception exception) { log.Error(exception.Message, exception); } } } /// <summary> /// The processing of close the form. /// </summary> /// <param name="sender">The source object of event.</param> /// <param name="e">The parameter of event.</param> private void BtnCancel_Click(object sender, EventArgs e) { this.Close(); this.Dispose(); } #endregion } }
using System.Collections; using System.Collections.Generic; using Model; using Constant; namespace Dal { /// <summary> /// This interface id defined for exam's functions. /// </summary> public interface IExamDal { #region Return List /// <summary> /// Gets exam list when first load in take exam. /// </summary> /// <param name="order">Judge get the exam is finished or not. 0 equals finished ohter equals unfinished.</param> /// <returns>Return list of exam</returns> IList<Exam> RetrieveExamList(string userName, int order); /// <summary> /// Gets the list of finished exam. /// </summary> /// <param name="userName">The user's name.</param> /// <param name="isFinished">The exam is finished or not.</param> /// <param name="keyWord">The search of finished exam key word.</param> /// <returns>Returns finished exam list.<ExamFinshed></returns> IList<ExamFinished> RetrieveFinishedExamList(string userName, bool isFinished, string keyWord); /// <summary> /// Gets QuestionID list for taking exmaing. /// </summary> /// <param name="examId">The exam's id.</param> /// <returns>Returns the question's id list of the exam.</returns> ArrayList RetrieveQuestionIdList(int examId); /// <summary> /// Gets exams by examName key words. /// </summary> /// <param name="keyWork">The key work.</param> /// <returns>Return exam list.</returns> IList<Exam> RetrieveUnFinishedExamListByKeyWord(string userName, string keyWork); /// <summary> /// Retrieves exam result. /// </summary> /// <returns>Returns examreport list.</returns> IList<ExamReport> RetrieveExamReportList(Page page); /// <summary> /// Retrieves score by exam id for paging. /// </summary> /// <see cref="Model.Page"/> /// <param name="examId">The id of exam.</param> /// <returns>Returns the score list.</returns> IList<Score> RetrieveDetailExamScore(Page page, int examId); /// <summary> /// Retrieve score list by exam's id. /// </summary> /// <param name="examId">The exam's id.</param> /// <returns>Returns the list of score.</returns> IList<Score> RetrieveScoreByExamId(int examId); #endregion #region Returns Model /// <summary> /// Gets the question by question id. /// </summary> /// <param name="questionID">The id of the question.</param> /// <returns>Returns question model.</returns> Question RetrieveQuestionById(int questionId); /// <summary> /// Gets the exam model by exam id. /// </summary> /// <param name="examId">The id of exam.</param> /// <returns>Return exam model.</returns> Exam RetrieveExamByExamId(int examId); /// <summary> /// Gets score by userName and examId. /// </summary> /// <param name="userName">The user's name.</param> /// <param name="examId">The exam's id.</param> /// <returns>Score</returns> Score RetrieveScoreByUserNameAndExamId(string userName, int examId); #endregion #region Void /// <summary> /// Records the exam information when user loads exam testing. /// </summary> /// <see cref="Model.Score"/> int InsertIntoScore(Score score); /// <summary> /// Submits the answer and record use's answer and update score. /// </summary> /// <see cref="Model.RecordAnswer"/> /// <see cref="Model.Score"/> int SubmitExam(RecordAnswer recordAnswer, Score score); /// <summary> /// Updates the score information of exam when user click finished button. /// </summary> /// <see cref="Model.Score"/> /// <returns>Returns score model.</returns> int SubmitFinishedExam(Score score); /// <summary> /// Submits the exam by system when role loaded. /// </summary> /// <param name="userName">The user's name.</param> int SubmitOutTimeExamByUser(string userName, string roleType); /// <summary> /// Updates score table of currentExamPaperQuestionID column. /// </summary> /// <see cref="Model.Score"/> /// <returns>Return the influence number.</returns> int UpdateScoreByTimer(Score score); #endregion #region Returns Bool /// <summary> /// Judges the exam is out time or not. /// </summary> /// <param name="userName">The user's name.</param> /// <param name="examId">The exam's id.</param> /// <returns>Returns a bool result about the exam is out time or not.</returns> bool IsExamOutTime(string userName, int examId); #endregion } }
namespace Dal { /// <summary> /// This class is provided to implement <c>IExamDal</c> methods. /// </summary> public class ExamDal : IExamDal { #region Returns List /// <summary> /// Gets exam list when first loaded in take exam. /// </summary> /// <param name="order">Judge get the exam is finished or not. 0 equals finished ohter equals unfinished.</param> /// <returns>Return exam list.</returns> public IList<Exam> RetrieveExamList(string userName, int order) { IList<Exam> examList = null; try { string sqlText = null; if (order == 0) { sqlText = SqlText.RetrieveUNFinishedExam; } else { sqlText = SqlText.RetrieveToDoExam; } SqlParameter[] prams = new SqlParameter[] { new SqlParameter("@userName", userName), }; SqlDataReader sqlDataReader = SqlHelper.ExecureReader(sqlText, prams); examList = new List<Exam>(); Exam exam = null; while (sqlDataReader.Read()) { exam = new Exam(); exam.ExamId = (int)sqlDataReader["exam_id"]; exam.Name = sqlDataReader["name"].ToString(); exam.SingleQuestionScore = (int)sqlDataReader["single_question_score"]; exam.Quantity = (int)sqlDataReader["quantity"]; exam.TotalScore = (int)sqlDataReader["total_score"]; exam.Duration = (int)sqlDataReader["duration"]; exam.Description = sqlDataReader["description"].ToString(); exam.PassScore = (int)sqlDataReader["pass_score"]; examList.Add(exam); } SqlHelper.CloseSqlDataReader(sqlDataReader); } catch (SqlException ex) { throw new ExamException(ExamException.RetrieveExamList,ex); } return examList; }