您目前尚未登陆,请选择【登陆】或【注册
首页->影音视频->燕赵宽频点播系统V1.0源码>>DAL/Films.cs>>代码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:燕赵宽频点播系统V1.0源码


当前文件路径:hevod/DAL/Films.cs 文件类型
普通视图
		            
1using System; 2using System.Data; 3using System.Data.OleDb; 4using System.Configuration; 5 6//该源码下载自www.51aspx.com(51aspx.com) 7 8namespace DAL 9{ 10 /// <summary> 11 /// films 12 /// </summary> 13 public class Films 14 { 15 public DBConn dbConn = new DBConn(); 16 17 /// <summary> 18 /// 添加film 19 /// </summary> 20 public bool AddFilm(Model.Films modelFilms) 21 { 22 bool isOK = false; 23 string sql = "insert into films (name,pathId,iscommend,director,players,typeId,fromCountry,intro,url,num,format,pdate) values" 24 + "('" + modelFilms.Name + "'," + modelFilms.PathId + "," + modelFilms.IsCommend + ",'" + modelFilms.Director + "','" + modelFilms.Players + "'," + modelFilms.TypeId + ",'" + modelFilms.FromCountry + "','" + modelFilms.Intro + "','" + modelFilms.Url + "'," + modelFilms.Num + ",'" + modelFilms.Format + "','" + DateTime.Now + "')"; 25 26 OleDbCommand cmd = new OleDbCommand(sql, dbConn.conn); 27 try 28 { 29 dbConn.Open(); 30 if (cmd.ExecuteNonQuery() > 0) 31 isOK = true; 32 } 33 catch (OleDbException ex) 34 { 35 throw ex; 36 } 37 catch (Exception ex) 38 { 39 throw ex; 40 } 41 finally 42 { 43 dbConn.Close(); 44 } 45 return isOK; 46 } 47 48 /// <summary> 49 /// 更新film 50 /// </summary> 51 public bool UpdateFilm(int id, Model.Films modelFilm) 52 { 53 bool isOK = false; 54 string sql = "update films set name='" + modelFilm.Name + "',pathId=" + modelFilm.PathId + ",iscommend=" + modelFilm.IsCommend + ",director='" + modelFilm.Director + "',players='" + modelFilm.Players + "',typeId=" + modelFilm.TypeId + ",fromCountry=" + modelFilm.FromCountry + ",intro='" + modelFilm.Intro + "',url='" + modelFilm.Url + "',num=" + modelFilm.Num + ",format='" + modelFilm.Format + "',pdate='" + modelFilm.PDate + "' where id=" + id; 55 OleDbCommand cmd = new OleDbCommand(sql, dbConn.conn); 56 try 57 { 58 dbConn.Open(); 59 if (cmd.ExecuteNonQuery() > 0) 60 isOK = true; 61 } 62 catch (OleDbException ex) 63 { 64 throw ex; 65 } 66 catch (Exception ex) 67 { 68 throw ex; 69 } 70 finally 71 { 72 dbConn.Close(); 73 } 74 return isOK; 75 } 76 77 /// <summary> 78 /// 增加点击率 79 /// </summary> 80 /// <param name="id"></param> 81 public void AddHit(int id) 82 { 83 string sql = "update films set hits=hits+1 where id="+id.ToString(); 84 OleDbCommand cmd = new OleDbCommand(sql, dbConn.conn); 85 try 86 { 87 dbConn.Open(); 88 cmd.ExecuteNonQuery(); 89 } 90 catch (Exception ex) 91 { 92 throw ex; 93 } 94 finally 95 { 96 dbConn.Close(); 97 } 98 } 99 100 /// <summary> 101 /// 删除film 102 /// </summary> 103 /// <param name="id">film id</param> 104 /// <returns>bool</returns> 105 public bool DelFilm(int id) 106 { 107 bool isOK = false; 108 string sql = "delete from films where id=" + id; 109 OleDbCommand cmd = new OleDbCommand(sql, dbConn.conn); 110 try 111 { 112 dbConn.Open(); 113 if (cmd.ExecuteNonQuery() > 0) 114 isOK = true; 115 } 116 catch (OleDbException ex) 117 { 118 throw ex; 119 } 120 finally 121 { 122 dbConn.Close(); 123 } 124 return isOK; 125 } 126 /// <summary> 127 /// 修改film的推荐,如果是推荐则改为不推荐,若不推荐改为推荐 128 /// </summary> 129 public bool ModifyFilmCommend(int id, bool isCommend) 130 { 131 bool isOK = false; 132 string sql = "update films set isCommend=" + isCommend + " where id=" + id; 133 OleDbCommand cmd = new OleDbCommand(sql, dbConn.conn); 134 try 135 { 136 dbConn.Open(); 137 if (cmd.ExecuteNonQuery() > 0) 138 isOK = true; 139 } 140 catch (Exception ex) 141 { 142 throw ex; 143 } 144 finally 145 { 146 dbConn.Close(); 147 } 148 return isOK; 149 } 150 151 152 /// <summary> 153 /// 取得films列表,并根据字段进行排序 154 /// </summary> 155 /// <param name="typeId">栏目id(0则不分类别)</param> 156 /// <param name="byCondition">排序字段(0则无条件)</param> 157 /// <param name="iCount">返回记录数(0则返回全部)</param> 158 /// <returns></returns> 159 public DataSet GetFilmsBy(int typeId, string Condition,int iCount) 160 { 161 162 string strTop=""; 163 string strTypeId=""; 164 string strCondition="id desc"; 165 166 if(iCount>1) 167 { 168 strTop="top "+iCount.ToString(); 169 } 170 if(typeId>1) 171 { 172 strTypeId="where typeId="+typeId.ToString(); 173 } 174 if(Condition.Trim()!="0") 175 { 176 strCondition=Condition; 177 } 178 179 string sql = "select " + strTop + " id,name,fromCountry,director,players,isCommend,num,hits,pathId,typeId,pDate from films " + strTypeId + " order by " + strCondition + ""; 180 181 OleDbCommand cmd = new OleDbCommand(sql, dbConn.conn); 182 OleDbDataAdapter da = new OleDbDataAdapter(cmd); 183 DataSet ds = null; 184 try 185 { 186 dbConn.Open(); 187 ds = new DataSet(); 188 da.Fill(ds); 189 190 } 191 catch (OleDbException ex) 192 { 193 throw ex; 194 } 195 catch (Exception ex) 196 { 197 throw ex; 198 } 199 finally 200 { 201 dbConn.Close(); 202 } 203 return ds; 204 } 205 206 /// <summary> 207 /// 对电影进行分页(这里用sql效率比较高) 208 /// </summary> 209 /// <param name="myPageSize">每页显示的条数</param> 210 /// <param name="myPageIndex">读取第几页</param> 211 /// <param name="typeId">类别Id</param> 212 /// <returns></returns> 213 public DataSet PageFilms(int myPageSize,int myPageIndex,int typeId) 214 { 215 string condition = "typeID>0"; 216 if (typeId>0) 217 condition = "typeID=" + typeId.ToString(); 218 219 string sql = "select top "+myPageSize+" id,name,fromCountry,director,players, hits, typeId,pDate from films where "+condition+" order by id DESC "; 220 221 //如果当前页码不为0 222 if (myPageIndex > 1) 223 //效率太低,所以改用下面的语句 224 // sql = "select top " + myPageSize + " id,name,fromCountry,director,players, hits, typeId,pDate from films where id not in (select top " + (myPageSize - 1) * myPageIndex + " id from films order by id DESC) order by id DESC"; 225 sql = "select top " + myPageSize + " id,name,fromCountry,director,players, hits, typeId,pDate from films where id < (Select Min(id) from(select top " + (myPageSize - 1) * myPageIndex + " id from films order by id DESC) as T) and "+condition+" order by id DESC"; 226 227 OleDbCommand cmd = new OleDbCommand(sql,dbConn.conn); 228 OleDbDataAdapter da = new OleDbDataAdapter(cmd); 229 DataSet ds = null; 230 try 231 { 232 dbConn.Open(); 233 ds = new DataSet(); 234 da.Fill(ds); 235 } 236 catch (Exception ex) 237 { 238 throw ex; 239 } 240 finally 241 { 242 dbConn.Close(); 243 } 244 return ds; 245 } 246 247 /// <summary> 248 /// 根据关键字显示搜索结果并分页 249 /// </summary> 250 /// <param name="myPageSize">每页显示条数</param> 251 /// <param name="myPageIndex">当前页码</param> 252 /// <param name="searchType">搜索类型(name或players)</param> 253 /// <param name="keyWord">搜索关键字</param> 254 /// <returns></returns> 255 public DataSet PageSearchFilms(int myPageSize, int myPageIndex, string searchType,string keyWord) 256 { 257 string sql = "select top " + myPageSize + " id,name,fromCountry,director,players, hits, typeId,pDate from films where "+searchType+" like '%"+keyWord+"%' order by id DESC "; 258 259 //如果当前页码不为0 260 if (myPageIndex > 1) 261 sql = "select top " + myPageSize +