public List <T_Task_Course> GetList() { //连接C:\Users\lenovo\Desktop\taskmanager\TaskManager\DAL\MyClass\DALT_Event_MyTask.cs SqlConnection co = new SqlConnection(); co.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dataConnection"]; co.Open(); //读取 SqlCommand cm = new SqlCommand(); cm.CommandText = "select * from T_Task_Course;"; //发送 cm.Connection = co; //接收 SqlDataReader dr = cm.ExecuteReader(); List <TaskManager.Model.T_Task_Course> lst = new List <TaskManager.Model.T_Task_Course>(); while (dr.Read()) { TaskManager.Model.T_Task_Course course = new TaskManager.Model.T_Task_Course(); course.ClassId = Convert.ToInt32(dr["ClassId"]); course.CourseId = Convert.ToString(dr["CourseId"]); course.Id = Convert.ToInt32(dr["Id"]); course.Name = Convert.ToString(dr["Name"]); course.StuId = Convert.ToInt32(dr["StuId"]); course.TeaId = Convert.ToInt32(dr["TeaId"]); course.Type = Convert.ToInt32(dr["Type"]); lst.Add(course); } dr.Close(); co.Close(); return(lst); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(TaskManager.Model.T_Task_Course model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_Task_Course set "); strSql.Append("CourseId=@CourseId,"); strSql.Append("Name=@Name,"); strSql.Append("Type=@Type,"); strSql.Append("ClassId=@ClassId,"); strSql.Append("TeaId=@TeaId,"); strSql.Append("StuId=@StuId"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@CourseId", SqlDbType.NVarChar, 20), new SqlParameter("@Name", SqlDbType.NVarChar, 20), new SqlParameter("@Type", SqlDbType.Int, 4), new SqlParameter("@ClassId", SqlDbType.Int, 4), new SqlParameter("@TeaId", SqlDbType.Int, 4), new SqlParameter("@StuId", SqlDbType.Int, 4), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.CourseId; parameters[1].Value = model.Name; parameters[2].Value = model.Type; parameters[3].Value = model.ClassId; parameters[4].Value = model.TeaId; parameters[5].Value = model.StuId; parameters[6].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public TaskManager.Model.T_Task_Course DataRowToModel(DataRow row) { TaskManager.Model.T_Task_Course model = new TaskManager.Model.T_Task_Course(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["CourseId"] != null) { model.CourseId = row["CourseId"].ToString(); } if (row["Name"] != null) { model.Name = row["Name"].ToString(); } if (row["Type"] != null && row["Type"].ToString() != "") { model.Type = int.Parse(row["Type"].ToString()); } if (row["ClassId"] != null && row["ClassId"].ToString() != "") { model.ClassId = int.Parse(row["ClassId"].ToString()); } if (row["TeaId"] != null && row["TeaId"].ToString() != "") { model.TeaId = int.Parse(row["TeaId"].ToString()); } if (row["StuId"] != null && row["StuId"].ToString() != "") { model.StuId = int.Parse(row["StuId"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(TaskManager.Model.T_Task_Course model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_Task_Course("); strSql.Append("CourseId,Name,Type,ClassId,TeaId,StuId)"); strSql.Append(" values ("); strSql.Append("@CourseId,@Name,@Type,@ClassId,@TeaId,@StuId)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@CourseId", SqlDbType.NVarChar, 20), new SqlParameter("@Name", SqlDbType.NVarChar, 20), new SqlParameter("@Type", SqlDbType.Int, 4), new SqlParameter("@ClassId", SqlDbType.Int, 4), new SqlParameter("@TeaId", SqlDbType.Int, 4), new SqlParameter("@StuId", SqlDbType.Int, 4) }; parameters[0].Value = model.CourseId; parameters[1].Value = model.Name; parameters[2].Value = model.Type; parameters[3].Value = model.ClassId; parameters[4].Value = model.TeaId; parameters[5].Value = model.StuId; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public TaskManager.Model.T_Task_Course GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,CourseId,Name,Type,ClassId,TeaId,StuId from T_Task_Course "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; TaskManager.Model.T_Task_Course model = new TaskManager.Model.T_Task_Course(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }