/// <summary> /// 制造一个课程对象 /// </summary> /// <returns></returns> private Course CreateACourse() { Course course = new Course((string)dgvCourses.SelectedRows[0].Cells["courseNumber"].Value); course.Name = (string)dgvCourses.SelectedRows[0].Cells["courseName"].Value; course.Message = (string)dgvCourses.SelectedRows[0].Cells["courseMessage"].Value; return course; }
/// <summary> /// 增加一条数据 /// </summary> public static bool AddCourse(Course model) { int number; SqlConnection conn = new SqlConnection(connStr); conn.Open(); SqlCommand cmd = null; StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Courses("); strSql.Append("Course_Number,Course_Name,Course_Message)"); strSql.Append(" values ("); strSql.Append("@Course_Number,@Course_Name,@Course_Message)"); SqlParameter[] parameters = { new SqlParameter("@Course_Number", SqlDbType.NVarChar,20), new SqlParameter("@Course_Name", SqlDbType.NVarChar,20), new SqlParameter("@Course_Message", SqlDbType.Text)}; parameters[0].Value = model.Number; parameters[1].Value = model.Name; parameters[2].Value = model.Message; cmd = new SqlCommand(strSql.ToString(), conn); foreach (SqlParameter para in parameters) { cmd.Parameters.Add(para); } number = (int)cmd.ExecuteNonQuery(); conn.Close(); if (number == 0) { return false; } else { return true; } }
private Stack<Thread> threadStack; //所有线程栈 #endregion Fields #region Constructors /// <summary> /// 主界面构造函数 /// </summary> public MainMenu() { InitializeComponent(); threadStack = new Stack<Thread>(); startServe = false; ThreadPool.SetMaxThreads(10, 10); recentCourse = DBHelper.GetCourseList()[0]; this.Shown += new System.EventHandler(this.MainLayer_Shown); this.btnStartServe.Click += new System.EventHandler(this.btnStartServe_Click); this.btnImportList.Click += new EventHandler(btnImportList_Click); this.学生编辑ToolStripMenuItem.Click += new System.EventHandler(this.学生编辑ToolStripMenuItem_Click); this.课程编辑ToolStripMenuItem.Click += new System.EventHandler(this.课程编辑ToolStripMenuItem_Click); this.当前课程ToolStripMenuItem.Click += new System.EventHandler(this.当前课程ToolStripMenuItem_Click); this.签到记录ToolStripMenuItem.Click += new System.EventHandler(this.签到记录ToolStripMenuItem_Click); }
/// <summary> /// 获得数据列表 /// </summary> public static List<Course> GetCourseList() { SqlConnection conn = new SqlConnection(connStr); conn.Open(); SqlDataReader sqlDataReader = null; List<Course> courseList = new List<Course>(); StringBuilder strSql = new StringBuilder(); strSql.Append("select Course_Number,Course_Name,Course_Message "); strSql.Append(" FROM Courses "); //if (strWhere.Trim() != "") //{ // strSql.Append(" where " + strWhere); //} SqlCommand cmd = new SqlCommand(strSql.ToString(), conn); sqlDataReader = cmd.ExecuteReader(); while (sqlDataReader.Read()) { //循环读出所有学生 Course course = new Course((string)sqlDataReader["Course_Number"]); course.Name = (string)sqlDataReader["Course_Name"]; course.Message = (string)sqlDataReader["Course_Message"]; courseList.Add(course); //加入学生集合 } conn.Close(); return courseList; }
/// <summary> /// 操作recentCourseMenu传来的值 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SendValue(object sender, EventArgs e) { recentCourse = sender as Course; }
/// <summary> /// 制造一个课程对象 /// </summary> /// <returns></returns> private Course CreateACourse() { Course course = new Course(txtCourseNumber.Text); course.Name = txtCourseName.Text; course.Message = txtCourseMessage.Text; return course; }