/// <summary> /// 更新一条数据 /// </summary> public bool Update(ITCastOCSS.Model.Teaching model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Teaching set "); strSql.Append("TID=@TID,"); strSql.Append("CID=@CID,"); strSql.Append("Week=@Week,"); strSql.Append("Timeperiod=@Timeperiod,"); strSql.Append("Place=@Place,"); strSql.Append("MaxNum=@MaxNum,"); strSql.Append("ActualNum=@ActualNum"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@TID", SqlDbType.Int, 4), new SqlParameter("@CID", SqlDbType.Int, 4), new SqlParameter("@Week", SqlDbType.NVarChar, 20), new SqlParameter("@Timeperiod", SqlDbType.NVarChar, 20), new SqlParameter("@Place", SqlDbType.NVarChar, 20), new SqlParameter("@MaxNum", SqlDbType.Int, 4), new SqlParameter("@ActualNum", SqlDbType.Int, 4), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.TID; parameters[1].Value = model.CID; parameters[2].Value = model.Week; parameters[3].Value = model.Timeperiod; parameters[4].Value = model.Place; parameters[5].Value = model.MaxNum; parameters[6].Value = model.ActualNum; parameters[7].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ITCastOCSS.Model.Teaching DataRowToModel(DataRow row) { ITCastOCSS.Model.Teaching model = new ITCastOCSS.Model.Teaching(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["TID"] != null && row["TID"].ToString() != "") { model.TID = int.Parse(row["TID"].ToString()); } if (row["CID"] != null && row["CID"].ToString() != "") { model.CID = int.Parse(row["CID"].ToString()); } if (row["Week"] != null) { model.Week = row["Week"].ToString(); } if (row["Timeperiod"] != null) { model.Timeperiod = row["Timeperiod"].ToString(); } if (row["Place"] != null) { model.Place = row["Place"].ToString(); } if (row["MaxNum"] != null && row["MaxNum"].ToString() != "") { model.MaxNum = int.Parse(row["MaxNum"].ToString()); } if (row["ActualNum"] != null && row["ActualNum"].ToString() != "") { model.ActualNum = int.Parse(row["ActualNum"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(ITCastOCSS.Model.Teaching model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Teaching("); strSql.Append("TID,CID,Week,Timeperiod,Place,MaxNum,ActualNum)"); strSql.Append(" values ("); strSql.Append("@TID,@CID,@Week,@Timeperiod,@Place,@MaxNum,@ActualNum)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@TID", SqlDbType.Int, 4), new SqlParameter("@CID", SqlDbType.Int, 4), new SqlParameter("@Week", SqlDbType.NVarChar, 20), new SqlParameter("@Timeperiod", SqlDbType.NVarChar, 20), new SqlParameter("@Place", SqlDbType.NVarChar, 20), new SqlParameter("@MaxNum", SqlDbType.Int, 4), new SqlParameter("@ActualNum", SqlDbType.Int, 4) }; parameters[0].Value = model.TID; parameters[1].Value = model.CID; parameters[2].Value = model.Week; parameters[3].Value = model.Timeperiod; parameters[4].Value = model.Place; parameters[5].Value = model.MaxNum; parameters[6].Value = model.ActualNum; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ITCastOCSS.Model.Teaching GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,TID,CID,Week,Timeperiod,Place,MaxNum,ActualNum from Teaching "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; ITCastOCSS.Model.Teaching model = new ITCastOCSS.Model.Teaching(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }