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