/// <summary> /// 更新一条数据 /// </summary> public bool Update(abc.Model.Model.TeacherShift model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update TeacherShift set "); strSql.Append("Color=SQL2012Color,"); strSql.Append("ShiftType=SQL2012ShiftType,"); strSql.Append("ShiftName=SQL2012ShiftName,"); strSql.Append("BeginTime=SQL2012BeginTime,"); strSql.Append("EndTime=SQL2012EndTime,"); strSql.Append("Note=SQL2012Note"); strSql.Append(" where ShiftId=SQL2012ShiftId"); SqlParameter[] parameters = { new SqlParameter("SQL2012Color", SqlDbType.VarChar, 255), new SqlParameter("SQL2012ShiftType", SqlDbType.Int, 4), new SqlParameter("SQL2012ShiftName", SqlDbType.VarChar, 255), new SqlParameter("SQL2012BeginTime", SqlDbType.DateTime), new SqlParameter("SQL2012EndTime", SqlDbType.DateTime), new SqlParameter("SQL2012Note", SqlDbType.VarChar, 500), new SqlParameter("SQL2012ShiftId", SqlDbType.Int, 4) }; parameters[0].Value = model.Color; parameters[1].Value = model.ShiftType; parameters[2].Value = model.ShiftName; parameters[3].Value = model.BeginTime; parameters[4].Value = model.EndTime; parameters[5].Value = model.Note; parameters[6].Value = model.ShiftId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(abc.Model.Model.TeacherShift model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into TeacherShift("); strSql.Append("Color,ShiftType,ShiftName,BeginTime,EndTime,Note)"); strSql.Append(" values ("); strSql.Append("SQL2012Color,SQL2012ShiftType,SQL2012ShiftName,SQL2012BeginTime,SQL2012EndTime,SQL2012Note)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("SQL2012Color", SqlDbType.VarChar, 255), new SqlParameter("SQL2012ShiftType", SqlDbType.Int, 4), new SqlParameter("SQL2012ShiftName", SqlDbType.VarChar, 255), new SqlParameter("SQL2012BeginTime", SqlDbType.DateTime), new SqlParameter("SQL2012EndTime", SqlDbType.DateTime), new SqlParameter("SQL2012Note", SqlDbType.VarChar, 500) }; parameters[0].Value = model.Color; parameters[1].Value = model.ShiftType; parameters[2].Value = model.ShiftName; parameters[3].Value = model.BeginTime; parameters[4].Value = model.EndTime; parameters[5].Value = model.Note; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public abc.Model.Model.TeacherShift DataRowToModel(DataRow row) { abc.Model.Model.TeacherShift model = new abc.Model.Model.TeacherShift(); if (row != null) { if (row["ShiftId"] != null && row["ShiftId"].ToString() != "") { model.ShiftId = int.Parse(row["ShiftId"].ToString()); } if (row["Color"] != null) { model.Color = row["Color"].ToString(); } if (row["ShiftType"] != null && row["ShiftType"].ToString() != "") { model.ShiftType = int.Parse(row["ShiftType"].ToString()); } if (row["ShiftName"] != null) { model.ShiftName = row["ShiftName"].ToString(); } if (row["BeginTime"] != null && row["BeginTime"].ToString() != "") { model.BeginTime = DateTime.Parse(row["BeginTime"].ToString()); } if (row["EndTime"] != null && row["EndTime"].ToString() != "") { model.EndTime = DateTime.Parse(row["EndTime"].ToString()); } if (row["Note"] != null) { model.Note = row["Note"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public abc.Model.Model.TeacherShift GetModel(int ShiftId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ShiftId,Color,ShiftType,ShiftName,BeginTime,EndTime,Note from TeacherShift "); strSql.Append(" where ShiftId=SQL2012ShiftId"); SqlParameter[] parameters = { new SqlParameter("SQL2012ShiftId", SqlDbType.Int, 4) }; parameters[0].Value = ShiftId; abc.Model.Model.TeacherShift model = new abc.Model.Model.TeacherShift(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }