Нет описания

article.cs 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. using System;
  2. using System.Data;
  3. using System.Text;
  4. using System.Reflection;
  5. using System.Collections.Generic;
  6. using System.Data.SqlClient;
  7. using CallCenterApi.DB;
  8. namespace CallCenterApi.DAL
  9. {
  10. /// <summary>
  11. /// 数据访问类:文章内容
  12. /// </summary>
  13. public partial class article
  14. {
  15. private string databaseprefix; //数据库表名前缀
  16. public article(string _databaseprefix = "dt_")
  17. {
  18. databaseprefix = _databaseprefix;
  19. }
  20. #region 基本方法================================
  21. /// <summary>
  22. /// 是否存在该记录
  23. /// </summary>
  24. public bool Exists(int article_id)
  25. {
  26. StringBuilder strSql = new StringBuilder();
  27. strSql.Append("select count(1) from " + databaseprefix + "channel_article_goods");
  28. strSql.Append(" where id=@article_id");
  29. SqlParameter[] parameters = {
  30. new SqlParameter("@article_id", SqlDbType.Int,4)};
  31. parameters[0].Value = article_id;
  32. return DbHelperSQL.Exists(strSql.ToString(), parameters);
  33. }
  34. /// <summary>
  35. /// 是否存在该记录
  36. /// </summary>
  37. public bool Exists(string call_index)
  38. {
  39. StringBuilder strSql = new StringBuilder();
  40. strSql.Append("select count(1) from " + databaseprefix + "channel_article_goods");
  41. strSql.Append(" where call_index=@call_index");
  42. SqlParameter[] parameters = {
  43. new SqlParameter("@call_index", SqlDbType.NVarChar,50)};
  44. parameters[0].Value = call_index;
  45. return DbHelperSQL.Exists(strSql.ToString(), parameters);
  46. }
  47. /// <summary>
  48. /// 增加一条数据
  49. /// </summary>
  50. public int Add(Model.article model)
  51. {
  52. ////查询频道名称
  53. //string channelName = new DAL.site_channel(databaseprefix).GetChannelName(model.channel_id);
  54. //if (channelName.Length == 0)
  55. //{
  56. // return 0;
  57. //}
  58. using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
  59. {
  60. conn.Open();
  61. using (SqlTransaction trans = conn.BeginTransaction())
  62. {
  63. try
  64. {
  65. #region 添加主表数据====================
  66. StringBuilder strSql = new StringBuilder();
  67. StringBuilder str1 = new StringBuilder();//数据字段
  68. StringBuilder str2 = new StringBuilder();//数据参数
  69. //利用反射获得属性的所有公共属性
  70. PropertyInfo[] pros = model.GetType().GetProperties();
  71. List<SqlParameter> paras = new List<SqlParameter>();
  72. strSql.Append("insert into " + databaseprefix + "dt_channel_article_goods" + "(");
  73. //主表字段信息
  74. foreach (PropertyInfo pi in pros)
  75. {
  76. //如果不是主键或List<T>则追加sql字符串
  77. if (!pi.Name.Equals("id") && !pi.Name.Equals("fields") && !typeof(System.Collections.IList).IsAssignableFrom(pi.PropertyType))
  78. {
  79. //判断属性值是否为空
  80. if (pi.GetValue(model, null) != null)
  81. {
  82. str1.Append(pi.Name + ",");//拼接字段
  83. str2.Append("@" + pi.Name + ",");//声明参数
  84. paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null)));//对参数赋值
  85. }
  86. }
  87. }
  88. //扩展字段信息
  89. //foreach (KeyValuePair<string, string> kvp in model.fields)
  90. //{
  91. // str1.Append(kvp.Key + ",");//拼接字段
  92. // str2.Append("@" + kvp.Key + ",");//声明参数
  93. // paras.Add(new SqlParameter("@" + kvp.Key, kvp.Value));//对参数赋值
  94. //}
  95. strSql.Append(str1.ToString().Trim(','));
  96. strSql.Append(") values (");
  97. strSql.Append(str2.ToString().Trim(','));
  98. strSql.Append(") ");
  99. strSql.Append(";select @@IDENTITY;");
  100. object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), paras.ToArray());//带事务
  101. model.id = Convert.ToInt32(obj);//插入后赋值
  102. #endregion
  103. #region 添加图片相册====================
  104. //if (model.albums != null)
  105. //{
  106. // new DAL.article_albums(databaseprefix).Add(conn, trans, model.albums, model.channel_id, model.id);
  107. //}
  108. #endregion
  109. #region 添加内容附件====================
  110. //if (model.attach != null)
  111. //{
  112. // new DAL.article_attach(databaseprefix).Add(conn, trans, model.attach, model.channel_id, model.id);
  113. //}
  114. #endregion
  115. #region 添加用户组价格==================
  116. //if (model.group_price != null)
  117. //{
  118. // foreach (Model.user_group_price modelt in model.group_price)
  119. // {
  120. // new DAL.user_group_price(databaseprefix).Add(conn, trans, modelt, model.channel_id, model.id);
  121. // }
  122. //}
  123. #endregion
  124. #region 添加Tags标签====================
  125. //if (model.tags != null && model.tags.Trim().Length > 0)
  126. //{
  127. // string[] tagsArr = model.tags.Trim().Split(',');
  128. // if (tagsArr.Length > 0)
  129. // {
  130. // foreach (string tagsStr in tagsArr)
  131. // {
  132. // new DAL.article_tags(databaseprefix).Update(conn, trans, tagsStr, model.channel_id, model.id);
  133. // }
  134. // }
  135. //}
  136. #endregion
  137. trans.Commit();
  138. }
  139. catch
  140. {
  141. trans.Rollback();
  142. return 0;
  143. }
  144. }
  145. }
  146. return model.id;
  147. }
  148. /// <summary>
  149. /// 更新一条数据
  150. /// </summary>
  151. public bool Update(Model.article model)
  152. {
  153. //查询频道名称
  154. //string channelName = new DAL.site_channel(databaseprefix).GetChannelName(model.channel_id);
  155. //if (channelName.Length == 0)
  156. //{
  157. // return false;
  158. //}
  159. using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
  160. {
  161. conn.Open();
  162. using (SqlTransaction trans = conn.BeginTransaction())
  163. {
  164. try
  165. {
  166. #region 修改主表数据==========================
  167. StringBuilder strSql = new StringBuilder();
  168. StringBuilder str1 = new StringBuilder();
  169. //利用反射获得属性的所有公共属性
  170. PropertyInfo[] pros = model.GetType().GetProperties();
  171. List<SqlParameter> paras = new List<SqlParameter>();
  172. strSql.Append("update " + databaseprefix + "dt_channel_article_goods set ");
  173. //主表字段信息
  174. foreach (PropertyInfo pi in pros)
  175. {
  176. //如果不是主键或List<T>则追加sql字符串
  177. if (!pi.Name.Equals("id") && !pi.Name.Equals("fields") && !typeof(System.Collections.IList).IsAssignableFrom(pi.PropertyType))
  178. {
  179. //判断属性值是否为空
  180. if (pi.GetValue(model, null) != null)
  181. {
  182. str1.Append(pi.Name + "=@" + pi.Name + ",");//声明参数
  183. paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null)));//对参数赋值
  184. }
  185. }
  186. }
  187. //扩展字段信息
  188. //foreach (KeyValuePair<string, string> kvp in model.fields)
  189. //{
  190. // str1.Append(kvp.Key + "=@" + kvp.Key + ",");//声明参数
  191. // paras.Add(new SqlParameter("@" + kvp.Key, kvp.Value));//对参数赋值
  192. //}
  193. strSql.Append(str1.ToString().Trim(','));
  194. strSql.Append(" where id=@id");
  195. paras.Add(new SqlParameter("@id", model.id));
  196. DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), paras.ToArray());
  197. #endregion
  198. //#region 修改图片相册==========================
  199. ////删除/添加/修改相册图片
  200. //new DAL.article_albums(databaseprefix).Update(conn, trans, model.albums, model.channel_id, model.id);
  201. //#endregion
  202. //#region 修改内容附件==========================
  203. ////删除/添加/修改附件
  204. //new DAL.article_attach(databaseprefix).Update(conn, trans, model.attach, model.channel_id, model.id);
  205. //#endregion
  206. //#region 修改用户组价格========================
  207. ////删除旧用户组价格
  208. //new DAL.user_group_price(databaseprefix).Delete(conn, trans, model.channel_id, model.id);
  209. ////添加用户组价格
  210. //if (model.group_price != null)
  211. //{
  212. // foreach (Model.user_group_price modelt in model.group_price)
  213. // {
  214. // new DAL.user_group_price(databaseprefix).Add(conn, trans, modelt, model.channel_id, model.id);
  215. // }
  216. //}
  217. //#endregion
  218. //#region 修改Tags标签==========================
  219. //删除已有的Tags标签关系
  220. //new DAL.article_tags(databaseprefix).Delete(conn, trans, model.channel_id, model.id);
  221. ////添加添加标签
  222. //if (model.tags != null && model.tags.Trim().Length > 0)
  223. //{
  224. // string[] tagsArr = model.tags.Trim().Split(',');
  225. // if (tagsArr.Length > 0)
  226. // {
  227. // foreach (string tagsStr in tagsArr)
  228. // {
  229. // new DAL.article_tags(databaseprefix).Update(conn, trans, tagsStr, model.channel_id, model.id);
  230. // }
  231. // }
  232. //}
  233. // #endregion
  234. trans.Commit();
  235. }
  236. catch
  237. {
  238. trans.Rollback();
  239. return false;
  240. }
  241. }
  242. }
  243. return true;
  244. }
  245. /// <summary>
  246. /// 删除一条数据
  247. /// </summary>
  248. public bool Delete(int article_id)
  249. {
  250. ////取得相册MODEL
  251. //List<Model.article_albums> albumsList = new DAL.article_albums(databaseprefix).GetList(channel_id, article_id);
  252. ////取得附件MODEL
  253. //List<Model.article_attach> attachList = new DAL.article_attach(databaseprefix).GetList(channel_id, article_id);
  254. ////删除图片相册
  255. //StringBuilder strSql2 = new StringBuilder();
  256. //strSql2.Append("delete from " + databaseprefix + "article_albums");
  257. //strSql2.Append(" where article_id=@article_id");
  258. //SqlParameter[] parameters2 = {
  259. // new SqlParameter("@article_id", SqlDbType.Int,4)};
  260. //parameters2[0].Value = article_id;
  261. List<CommandInfo> sqllist = new List<CommandInfo>();
  262. //CommandInfo cmd = new CommandInfo(strSql2.ToString(), parameters2);
  263. //sqllist.Add(cmd);
  264. ////删除附件
  265. //StringBuilder strSql3 = new StringBuilder();
  266. //strSql3.Append("delete from " + databaseprefix + "article_attach");
  267. //strSql3.Append(" where channel_id=@channel_id and article_id=@article_id");
  268. //SqlParameter[] parameters3 = {
  269. // new SqlParameter("@channel_id", SqlDbType.Int,4),
  270. // new SqlParameter("@article_id", SqlDbType.Int,4)};
  271. //parameters3[0].Value = channel_id;
  272. //parameters3[1].Value = article_id;
  273. //cmd = new CommandInfo(strSql3.ToString(), parameters3);
  274. //sqllist.Add(cmd);
  275. ////删除用户组价格
  276. //StringBuilder strSql4 = new StringBuilder();
  277. //strSql4.Append("delete from " + databaseprefix + "user_group_price");
  278. //strSql4.Append(" where channel_id=@channel_id and article_id=@article_id");
  279. //SqlParameter[] parameters4 = {
  280. // new SqlParameter("@channel_id", SqlDbType.Int,4),
  281. // new SqlParameter("@article_id", SqlDbType.Int,4)};
  282. //parameters4[0].Value = channel_id;
  283. //parameters4[1].Value = article_id;
  284. //cmd = new CommandInfo(strSql4.ToString(), parameters4);
  285. //sqllist.Add(cmd);
  286. ////删除Tags标签关系
  287. //StringBuilder strSql7 = new StringBuilder();
  288. //strSql7.Append("delete from " + databaseprefix + "article_tags_relation");
  289. //strSql7.Append(" where channel_id=@channel_id and article_id=@article_id");
  290. //SqlParameter[] parameters7 = {
  291. // new SqlParameter("@channel_id", SqlDbType.Int,4),
  292. // new SqlParameter("@article_id", SqlDbType.Int,4)};
  293. //parameters7[0].Value = channel_id;
  294. //parameters7[1].Value = article_id;
  295. //cmd = new CommandInfo(strSql7.ToString(), parameters7);
  296. //sqllist.Add(cmd);
  297. ////删除评论
  298. //StringBuilder strSql8 = new StringBuilder();
  299. //strSql8.Append("delete from " + databaseprefix + "article_comment");
  300. //strSql8.Append(" where channel_id=@channel_id and article_id=@article_id ");
  301. //SqlParameter[] parameters8 = {
  302. // new SqlParameter("@channel_id", SqlDbType.Int,4),
  303. // new SqlParameter("@article_id", SqlDbType.Int,4)};
  304. //parameters8[0].Value = channel_id;
  305. //parameters8[1].Value = article_id;
  306. //cmd = new CommandInfo(strSql8.ToString(), parameters8);
  307. //sqllist.Add(cmd);
  308. //删除主表
  309. StringBuilder strSql = new StringBuilder();
  310. strSql.Append("delete from " + databaseprefix + "channel_article_goods");
  311. strSql.Append(" where id=@id");
  312. SqlParameter[] parameters = {
  313. new SqlParameter("@id", SqlDbType.Int,4)};
  314. parameters[0].Value = article_id;
  315. var cmd = new CommandInfo(strSql.ToString(), parameters);
  316. sqllist.Add(cmd);
  317. int rowsAffected = DbHelperSQL.ExecuteSqlTran(sqllist);
  318. if (rowsAffected > 0)
  319. {
  320. //new DAL.article_albums(databaseprefix).DeleteFile(albumsList); //删除图片
  321. //new DAL.article_attach(databaseprefix).DeleteFile(attachList); //删除附件
  322. return true;
  323. }
  324. else
  325. {
  326. return false;
  327. }
  328. }
  329. /// <summary>
  330. /// 删除一条数据
  331. /// </summary>
  332. public bool DeleteBatch(string where)
  333. {
  334. StringBuilder strSql = new StringBuilder();
  335. strSql.Append("delete from " + databaseprefix + "channel_article_goods");
  336. if (!string.IsNullOrWhiteSpace(where))
  337. {
  338. strSql.Append(" where ");
  339. strSql.Append(where);
  340. }
  341. int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString());
  342. if (rowsAffected > 0)
  343. return true;
  344. return false;
  345. }
  346. /// <summary>
  347. /// 得到一个对象实体
  348. /// </summary>
  349. public Model.article GetModel(int article_id)
  350. {
  351. StringBuilder strSql = new StringBuilder();
  352. strSql.Append("select top 1 product.*,c.title as categorytitle from " + databaseprefix + "channel_article_goods as product left join dt_article_category as c on c.id=product.category_id ");
  353. strSql.Append(" where product.id=@id");
  354. SqlParameter[] parameters = {
  355. new SqlParameter("@id", SqlDbType.Int,4)};
  356. parameters[0].Value = article_id;
  357. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  358. if (ds.Tables[0].Rows.Count > 0)
  359. {
  360. return DataRowToModel(ds.Tables[0].Rows[0]);
  361. }
  362. else
  363. {
  364. return null;
  365. }
  366. }
  367. /// <summary>
  368. /// 得到一个对象实体
  369. /// </summary>
  370. public Model.article GetModel(string call_index)
  371. {
  372. StringBuilder strSql = new StringBuilder();
  373. strSql.Append("select top 1 * from " + databaseprefix + "channel_article_goods");
  374. strSql.Append(" where call_index=@call_index");
  375. SqlParameter[] parameters = {
  376. new SqlParameter("@call_index", SqlDbType.NVarChar,50)};
  377. parameters[0].Value = call_index;
  378. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  379. if (ds.Tables[0].Rows.Count > 0)
  380. {
  381. return DataRowToModel(ds.Tables[0].Rows[0]);
  382. }
  383. else
  384. {
  385. return null;
  386. }
  387. }
  388. /// <summary>
  389. /// 获得前几行数据
  390. /// </summary>
  391. public DataSet GetList(int Top, string strWhere, string filedOrder)
  392. {
  393. StringBuilder strSql = new StringBuilder();
  394. strSql.Append("select ");
  395. if (Top > 0)
  396. {
  397. strSql.Append(" top " + Top.ToString());
  398. }
  399. strSql.Append(" * ");
  400. strSql.Append(" FROM " + databaseprefix + "channel_article_goods");
  401. if (strWhere.Trim() != "")
  402. {
  403. strSql.Append(" where " + strWhere);
  404. }
  405. strSql.Append(" order by " + filedOrder);
  406. return DbHelperSQL.Query(strSql.ToString());
  407. }
  408. #region 私有方法================================
  409. /// <summary>
  410. /// 将对象转换为实体
  411. /// </summary>
  412. private Model.article DataRowToModel(DataRow row)
  413. {
  414. Model.article model = new Model.article();//主表字段
  415. if (row != null)
  416. {
  417. #region 主表信息======================
  418. //利用反射获得属性的所有公共属性
  419. Type modelType = model.GetType();
  420. for (int i = 0; i < row.Table.Columns.Count; i++)
  421. {
  422. PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
  423. if (proInfo != null && row[i] != DBNull.Value)
  424. {
  425. //用索引值设置属性值
  426. proInfo.SetValue(model, row[i], null);
  427. }
  428. }
  429. #endregion
  430. #region 扩展字段信息===================
  431. //Dictionary<string, string> fieldDic = new DAL.article_attribute_field(databaseprefix).GetFields(model.channel_id);//扩展字段字典
  432. //for (int i = 0; i < row.Table.Columns.Count; i++)
  433. //{
  434. // if (fieldDic.ContainsKey(row.Table.Columns[i].ColumnName) && row[i] != null)
  435. // {
  436. // fieldDic[row.Table.Columns[i].ColumnName] = row[i].ToString();
  437. // }
  438. //}
  439. //model.fields = fieldDic;
  440. #endregion
  441. //相册信息
  442. //model.albums = new DAL.article_albums(databaseprefix).GetList(model.channel_id, model.id);
  443. ////附件信息
  444. //model.attach = new DAL.article_attach(databaseprefix).GetList(model.channel_id, model.id);
  445. ////用户组价格
  446. //model.group_price = new DAL.user_group_price(databaseprefix).GetList(model.channel_id, model.id);
  447. }
  448. return model;
  449. }
  450. #endregion
  451. #region 扩展方法================================
  452. /// <summary>
  453. /// 是否存在标题
  454. /// </summary>
  455. public bool ExistsTitle(string title)
  456. {
  457. StringBuilder strSql = new StringBuilder();
  458. strSql.Append("select count(1) from " + databaseprefix + "channel_article_goods");
  459. strSql.Append(" where title=@title");
  460. SqlParameter[] parameters = {
  461. new SqlParameter("@title", SqlDbType.VarChar,200)};
  462. parameters[0].Value = title;
  463. return DbHelperSQL.Exists(strSql.ToString(), parameters);
  464. }
  465. /// <summary>
  466. /// 是否存在标题
  467. /// </summary>
  468. public bool ExistsTitle(int category_id, string title)
  469. {
  470. StringBuilder strSql = new StringBuilder();
  471. strSql.Append("select count(1) from " + databaseprefix + "channel_article_goods");
  472. strSql.Append(" where category_id=@category_id and title=@title");
  473. SqlParameter[] parameters = {
  474. new SqlParameter("@category_id", SqlDbType.Int,4),
  475. new SqlParameter("@title", SqlDbType.VarChar,200)}
  476. ;
  477. parameters[0].Value = category_id;
  478. parameters[1].Value = title;
  479. return DbHelperSQL.Exists(strSql.ToString(), parameters);
  480. }
  481. /// <summary>
  482. /// 返回信息标题
  483. /// </summary>
  484. public string GetTitle(int article_id)
  485. {
  486. StringBuilder strSql = new StringBuilder();
  487. strSql.Append("select top 1 title from " + databaseprefix + "channel_article_goods");
  488. strSql.Append(" where id=" + article_id);
  489. string title = Convert.ToString(DbHelperSQL.GetSingle(strSql.ToString()));
  490. if (string.IsNullOrEmpty(title))
  491. {
  492. return string.Empty;
  493. }
  494. return title;
  495. }
  496. /// <summary>
  497. /// 返回信息内容
  498. /// </summary>
  499. public string GetContent(int article_id)
  500. {
  501. StringBuilder strSql = new StringBuilder();
  502. strSql.Append("select top 1 content from " + databaseprefix + "channel_article_goods");
  503. strSql.Append(" where id=" + article_id);
  504. string content = Convert.ToString(DbHelperSQL.GetSingle(strSql.ToString()));
  505. if (string.IsNullOrEmpty(content))
  506. {
  507. return string.Empty;
  508. }
  509. return content;
  510. }
  511. /// <summary>
  512. /// 返回信息内容
  513. /// </summary>
  514. public string GetContent(string call_index)
  515. {
  516. StringBuilder strSql = new StringBuilder();
  517. strSql.Append("select top 1 content from " + databaseprefix + "channel_article_goods");
  518. strSql.Append(" where call_index=@call_index");
  519. SqlParameter[] parameters = {
  520. new SqlParameter("@call_index", SqlDbType.NVarChar,50)};
  521. parameters[0].Value = call_index;
  522. string content = Convert.ToString(DbHelperSQL.GetSingle(strSql.ToString(), parameters));
  523. if (string.IsNullOrEmpty(content))
  524. {
  525. return string.Empty;
  526. }
  527. return content;
  528. }
  529. /// <summary>
  530. /// 返回信息封面图
  531. /// </summary>
  532. public string GetImgUrl(int article_id)
  533. {
  534. StringBuilder strSql = new StringBuilder();
  535. strSql.Append("select top 1 img_url from " + databaseprefix + "channel_article_goods");
  536. strSql.Append(" where id=" + article_id);
  537. string imgsrc = Convert.ToString(DbHelperSQL.GetSingle(strSql.ToString()));
  538. if (string.IsNullOrEmpty(imgsrc))
  539. {
  540. return string.Empty;
  541. }
  542. return imgsrc;
  543. }
  544. /// <summary>
  545. /// 获取阅读次数
  546. /// </summary>
  547. public int GetClick(int article_id)
  548. {
  549. StringBuilder strSql = new StringBuilder();
  550. strSql.Append("select top 1 click from " + databaseprefix + "channel_article_goods");
  551. strSql.Append(" where id=" + article_id);
  552. string str = Convert.ToString(DbHelperSQL.GetSingle(strSql.ToString()));
  553. if (string.IsNullOrEmpty(str))
  554. {
  555. return 0;
  556. }
  557. return Convert.ToInt32(str);
  558. }
  559. /// <summary>
  560. /// 返回数据总数
  561. /// </summary>
  562. public int GetCount(string strWhere)
  563. {
  564. StringBuilder strSql = new StringBuilder();
  565. strSql.Append("select count(*) as H ");
  566. strSql.Append(" from " + databaseprefix + "channel_article_goods");
  567. if (strWhere.Trim() != "")
  568. {
  569. strSql.Append(" where " + strWhere);
  570. }
  571. return Convert.ToInt32(DbHelperSQL.GetSingle(strSql.ToString()));
  572. }
  573. /// <summary>
  574. /// 返回商品库存数量
  575. /// </summary>
  576. public int GetStockQuantity(int article_id)
  577. {
  578. StringBuilder strSql = new StringBuilder();
  579. strSql.Append("select top 1 stock_quantity ");
  580. strSql.Append(" from " + databaseprefix + "channel_article_goods");
  581. strSql.Append(" where id=" + article_id);
  582. return Convert.ToInt32(DbHelperSQL.GetSingle(strSql.ToString()));
  583. }
  584. /// <summary>
  585. /// 修改一列数据
  586. /// </summary>
  587. public bool UpdateField(int id, string strValue)
  588. {
  589. StringBuilder strSql = new StringBuilder();
  590. strSql.Append("update " + databaseprefix + "channel_article_goods set " + strValue);
  591. strSql.Append(" where id=" + id);
  592. return DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
  593. }
  594. #endregion
  595. }
  596. }
  597. #endregion