DBcon.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Text;
  5. using System.Data.OleDb;
  6. namespace BooksManageSystem
  7. {
  8. internal class DBcon
  9. {
  10. #region 书籍列表
  11. private DataTable _dal_getBookList()
  12. {
  13. using (OleDbCommand comm = new OleDbCommand(@"select * from books"))
  14. {
  15. return DBHelper.ExecuteDataTable(comm);
  16. }
  17. }
  18. private DataTable _dal_getBookListByName(string name)
  19. {
  20. using (OleDbCommand comm = new OleDbCommand(@"select * from books where bookname like '%" + name + "%'"))
  21. {
  22. return DBHelper.ExecuteDataTable(comm);
  23. }
  24. }
  25. private DataTable _dal_getOneBookByID(int id)
  26. {
  27. using (OleDbCommand comm = new OleDbCommand(@"select * from books where ID =" + id ))
  28. {
  29. return DBHelper.ExecuteDataTable(comm);
  30. }
  31. }
  32. private List<Book> _ToModuleBookList(DataTable dt)
  33. {
  34. List<Book> list = new List<Book>();
  35. foreach (DataRow item in dt.Rows)
  36. {
  37. int id = int.Parse(item[0].ToString());//id
  38. string name = item[1].ToString();//name
  39. double price = double.Parse(item[2].ToString());//price
  40. double order_Price = double.Parse(item[3].ToString());//order_Price
  41. int cout = int.Parse(item[4].ToString());//count
  42. bool isStu = bool.Parse(item[5].ToString());
  43. Book b = new Book(id, name, price, order_Price, cout, isStu);
  44. list.Add(b);
  45. }
  46. return list;
  47. }
  48. public List<Book> GetBookList()
  49. {
  50. return _ToModuleBookList(_dal_getBookList());
  51. }
  52. public List<Book> GetBookListByName(string bkname)
  53. {
  54. return _ToModuleBookList(_dal_getBookListByName(bkname));
  55. }
  56. public Book GetOneBookByID(int id)
  57. {
  58. var list = _ToModuleBookList(_dal_getOneBookByID(id));
  59. if (list.Count==1)
  60. {
  61. return list[0];
  62. }
  63. else
  64. {
  65. return null;
  66. }
  67. }
  68. private int _dal_addNewBook(string bkname,double price,double orderprice, int count,bool studentBook )
  69. {
  70. using (OleDbCommand comm = new OleDbCommand(@"insert into books(bookname,price,order_price,books_count,IS_STUDENTBOOK)values('" + bkname + "'," + price + "," + orderprice + "," + count + "," + studentBook +")"))
  71. {
  72. return DBHelper.ExecuteNonQuery(comm);
  73. }
  74. }
  75. private int _dal_ModifyBook(int id, string bookname, double price, double orderprice, int count, bool studentBook)
  76. {
  77. using (OleDbCommand comm = new OleDbCommand(@"update books set bookname='" + bookname + "',price="+ price +",order_price=" + orderprice+ ",books_count=" + count +",IS_STUDENTBOOK=" + studentBook + " where id=" + id))
  78. {
  79. return DBHelper.ExecuteNonQuery(comm);
  80. }
  81. }
  82. public int AddNewBook(string bookname,double price,double orderprice,int count,bool studentBook)
  83. {
  84. return _dal_addNewBook(bookname, price, orderprice, count,studentBook);
  85. }
  86. public int ModifyBook(int id, string bookname, double price, double orderprice, int count, bool studentBook)
  87. {
  88. return _dal_ModifyBook(id, bookname, price, orderprice, count, studentBook);
  89. }
  90. #endregion
  91. #region 变更数量操作
  92. /// <summary>
  93. ///
  94. /// </summary>
  95. /// <param name="id"></param>
  96. /// <param name="count"></param>
  97. /// <param name="opertor"></param>
  98. /// <param name="time"></param>
  99. /// <returns>返回变更后的数量</returns>
  100. public int SellBookByID(int id,int count,string opertor,DateTime time)
  101. {
  102. int c = queryCountByID(id);
  103. if (c < count)
  104. {
  105. throw new Exception("没有足够数量的书可供售出!");
  106. }
  107. using (OleDbCommand comm = new OleDbCommand(@"update books set books_count = " + (c - count).ToString() + " where id = " + id.ToString() ))
  108. {
  109. DBHelper.ExecuteNonQuery(comm);
  110. }
  111. using (OleDbCommand comm = new OleDbCommand(@"insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count) values
  112. (" + id + "," + ((int)EnumOP.售).ToString() + ",'" + time.ToString() + "'," + count.ToString() + ",'" + opertor + "'," + (c - count) + ")"))
  113. {
  114. //INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
  115. DBHelper.ExecuteNonQuery(comm);
  116. return c - count;
  117. }
  118. }
  119. /// <summary>
  120. ///
  121. /// </summary>
  122. /// <param name="id"></param>
  123. /// <param name="count"></param>
  124. /// <param name="opertor"></param>
  125. /// <param name="time"></param>
  126. /// <returns>返回变更后的数量</returns>
  127. public int Lingqu(int id, int count, string opertor, DateTime time)
  128. {
  129. int c = queryCountByID(id);
  130. if (c < count)
  131. {
  132. throw new Exception("没有足够数量的书可供领取!");
  133. }
  134. using (OleDbCommand comm = new OleDbCommand(@"update books set books_count = " + (c - count).ToString() + " where id = " + id.ToString()))
  135. {
  136. DBHelper.ExecuteNonQuery(comm);
  137. }
  138. using (OleDbCommand comm = new OleDbCommand(@"insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count) values (@id,@op,@op_date,@op_count,@opertor,@after_op_count)"))
  139. {
  140. comm.Parameters.AddWithValue("@id", (uint)id);
  141. comm.Parameters.AddWithValue("@op", (int)EnumOP.领);
  142. comm.Parameters.AddWithValue("@op_date", time.ToString());
  143. comm.Parameters.AddWithValue("@op_count", count);
  144. comm.Parameters.AddWithValue("@opertor", opertor);
  145. comm.Parameters.AddWithValue("@after_op_count", c - count);
  146. //insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count) values (?,?,?,?,?,?)
  147. //insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count) values (1,2,'2018/2/6 10:48:09',1,'afsdf',1)
  148. //INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
  149. DBHelper.ExecuteNonQuery(comm);
  150. return c - count;
  151. }
  152. }
  153. /// <summary>
  154. ///
  155. /// </summary>
  156. /// <param name="id"></param>
  157. /// <param name="count"></param>
  158. /// <param name="oper"></param>
  159. /// <param name="time"></param>
  160. /// <returns>返回变更后的数量</returns>
  161. public int PurchaseBook(int id, int count, string oper, DateTime time, int bid)
  162. {
  163. int c = queryCountByID(id);
  164. using (OleDbCommand comm = new OleDbCommand(@"update books set books_count = " + (c + count).ToString() + " where id = " + id.ToString()))
  165. {
  166. DBHelper.ExecuteNonQuery(comm);
  167. }
  168. if (bid==0)
  169. {
  170. using (OleDbCommand comm = new OleDbCommand(@"insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count) values
  171. (" + id + "," + ((int)EnumOP.购).ToString() + ",'" + time.ToString() + "'," + count.ToString() + ",'" + oper + "'," + (c + count) + ")"))
  172. {
  173. //INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
  174. DBHelper.ExecuteNonQuery(comm);
  175. return c + count;
  176. }
  177. }
  178. else
  179. {
  180. using (OleDbCommand comm = new OleDbCommand(@"insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count,bid) values
  181. (" + id + "," + ((int)EnumOP.购).ToString() + ",'" + time.ToString() + "'," + count.ToString() + ",'" + oper + "'," + (c + count) + "," + bid + ")"))
  182. {
  183. //INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
  184. DBHelper.ExecuteNonQuery(comm);
  185. return c + count;
  186. }
  187. }
  188. }
  189. /// <summary>
  190. /// 返回BID
  191. /// </summary>
  192. /// <param name="totalcount"></param>
  193. /// <param name="time"></param>
  194. /// <returns></returns>
  195. public int Blist(int totalcount, DateTime time)
  196. {
  197. using (OleDbCommand comm = new OleDbCommand(@"insert into blist (bcount,bdate) values(" + totalcount + ",'" + time.ToString() + "')"))
  198. {
  199. DBHelper.ExecuteNonQuery(comm);
  200. }
  201. using (OleDbCommand comm = new OleDbCommand(@"SELECT MAX(BID) AS id FROM BLIST"))
  202. {
  203. var o = DBHelper.ExecuteScalar(comm);
  204. return Convert.ToInt32(o);
  205. }
  206. }
  207. /// <summary>
  208. ///
  209. /// </summary>
  210. /// <param name="id"></param>
  211. /// <param name="count"></param>
  212. /// <param name="oper"></param>
  213. /// <param name="time"></param>
  214. /// <returns>返回变更后的数量</returns>
  215. public int ReturnBookByID(int id, int count, string oper, DateTime time)
  216. {
  217. int c = queryCountByID(id);
  218. using (OleDbCommand comm = new OleDbCommand(@"update books set books_count = " + (c + count).ToString() + " where id = " + id.ToString()))
  219. {
  220. DBHelper.ExecuteNonQuery(comm);
  221. }
  222. using (OleDbCommand comm = new OleDbCommand(@"insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count) values
  223. (" + id + "," + ((int)EnumOP.还).ToString() + ",'" + time.ToString() + "'," + count.ToString() + ",'" + oper + "'," + (c + count) + ")"))
  224. {
  225. //INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
  226. DBHelper.ExecuteNonQuery(comm);
  227. return c + count;
  228. }
  229. }
  230. #endregion
  231. #region 分操作
  232. //查询书的数量OK
  233. private int queryCountByID(int id )
  234. {
  235. using (OleDbCommand comm = new OleDbCommand(@"select books_count from books where id = " + id))
  236. {
  237. return Convert.ToInt32(DBHelper.ExecuteScalar(comm));
  238. }
  239. }
  240. //Untest
  241. private int queryIDByName(string bookname)
  242. {
  243. using (OleDbCommand comm = new OleDbCommand(@"select id from books where bookname = '" + bookname + "'"))
  244. {
  245. return Convert.ToInt32(DBHelper.ExecuteScalar(comm));
  246. }
  247. }
  248. #endregion
  249. #region 操作记录
  250. private DataTable _dal_getOPLOGByBookID(int id)
  251. {
  252. using (OleDbCommand comm = new OleDbCommand(@"SELECT top 1000 BOOKS.ID,BOOKS.BOOKNAME, OPERATE.OP, OPERATE.OP_DATE, OPERATE.OP_COUNT,after_op_count, OPERATE.OPERATOR,OPERATE.ID
  253. FROM (BOOKS INNER JOIN OPERATE ON BOOKS.ID = OPERATE.OP_BOOK_NO)
  254. WHERE (OPERATE.OP_BOOK_NO = " + id + @")
  255. ORDER BY OPERATE.OP_DATE DESC"))
  256. {
  257. return DBHelper.ExecuteDataTable(comm);
  258. }
  259. }
  260. private DataTable _dal_getOPLOGByBID(int Bid)
  261. {
  262. using (OleDbCommand comm = new OleDbCommand(@"SELECT top 1000 BOOKS.ID,BOOKS.BOOKNAME, OPERATE.OP, OPERATE.OP_DATE, OPERATE.OP_COUNT,after_op_count, OPERATE.OPERATOR,OPERATE.ID
  263. FROM (BOOKS INNER JOIN OPERATE ON BOOKS.ID = OPERATE.OP_BOOK_NO)
  264. WHERE (OPERATE.BID = " + Bid + @")
  265. ORDER BY OPERATE.OP_DATE DESC"))
  266. {
  267. return DBHelper.ExecuteDataTable(comm);
  268. }
  269. }
  270. private DataTable _dal_getOPLOGALL()
  271. {
  272. using (OleDbCommand comm = new OleDbCommand(@"SELECT TOP 1000 BOOKS.ID,BOOKS.BOOKNAME, OPERATE.OP, OPERATE.OP_DATE, OPERATE.OP_COUNT,after_op_count, OPERATE.OPERATOR,OPERATE.ID
  273. FROM (BOOKS INNER JOIN OPERATE ON BOOKS.ID = OPERATE.OP_BOOK_NO)
  274. ORDER BY OPERATE.OP_DATE DESC"))
  275. {
  276. return DBHelper.ExecuteDataTable(comm);
  277. }
  278. }
  279. private int _dal_ModifyOPLogByOPID(int opid, DateTime dt, string oper)
  280. {
  281. using (OleDbCommand comm = new OleDbCommand(@"update operate set OP_DATE=Cdate('"+dt.ToString("yyyy-MM-dd HH:mm:ss")+"'),operator = '"+oper+"' where id = " + opid))
  282. {
  283. return DBHelper.ExecuteNonQuery(comm);
  284. }
  285. }
  286. private List<OPLOG> _ToModuleSellList(DataTable dt)
  287. {
  288. List<OPLOG> list = new List<OPLOG>();
  289. foreach (DataRow item in dt.Rows)
  290. {
  291. int bkid = int.Parse(item[0].ToString());
  292. string bkname = item[1].ToString();
  293. EnumOP op = (EnumOP)Enum.Parse(typeof(EnumOP), item[2].ToString());
  294. DateTime opdate = DateTime.Parse(item[3].ToString());
  295. int cout = int.Parse(item[4].ToString());
  296. int afcount = int.Parse(item[5].ToString());
  297. string oper = item[6].ToString();
  298. int opid = int.Parse(item[7].ToString());
  299. OPLOG oplog = new OPLOG()
  300. {
  301. BookID = bkid,
  302. BookName = bkname,
  303. op = op,
  304. OPdatetime = opdate,
  305. OPCount = cout,
  306. AfterOPCount = afcount,
  307. oper = oper,
  308. OPID = opid
  309. };
  310. list.Add(oplog);
  311. }
  312. return list;
  313. }
  314. public List<OPLOG> GetOPLogByID(int id)
  315. {
  316. return _ToModuleSellList(_dal_getOPLOGByBookID(id));
  317. }
  318. public List<OPLOG> GetOPLogByBID(int bid)
  319. {
  320. return _ToModuleSellList(_dal_getOPLOGByBID(bid));
  321. }
  322. public List<OPLOG> GetOPLogALL()
  323. {
  324. return _ToModuleSellList(_dal_getOPLOGALL());
  325. }
  326. /// <summary>
  327. /// 修改操作记录
  328. /// </summary>
  329. /// <param name="opid"></param>
  330. /// <param name="dt"></param>
  331. /// <param name="oper"></param>
  332. /// <returns></returns>
  333. public int ModifyOPLog(int opid,DateTime dt,string oper)
  334. {
  335. return _dal_ModifyOPLogByOPID(opid, dt, oper);
  336. }
  337. /// <summary>
  338. /// 撤销操作记录
  339. /// </summary>
  340. /// <param name="opid"></param>
  341. /// <returns></returns>
  342. public int UndoOPByOPID(int opid)
  343. {
  344. using (OleDbCommand comm = new OleDbCommand(@"SELECT BOOKS.ID, BOOKS.BOOKNAME, OPERATE.OP, OPERATE.OP_DATE, OPERATE.OP_COUNT, OPERATE.AFTER_OP_COUNT, OPERATE.OPERATOR, OPERATE.ID AS OPID
  345. FROM (BOOKS INNER JOIN OPERATE ON BOOKS.ID = OPERATE.OP_BOOK_NO)
  346. WHERE (OPERATE.ID = " + opid + ")"))
  347. {
  348. var dt = DBHelper.ExecuteDataTable(comm);
  349. var oplogList = _ToModuleSellList(dt);
  350. if (oplogList.Count == 0)
  351. {
  352. return 0;
  353. }
  354. var oplog = oplogList[0];
  355. if (oplog.op == EnumOP.购 || oplog.op == EnumOP.还)
  356. {
  357. int c = queryCountByID(oplog.BookID);
  358. using (OleDbCommand comm2 = new OleDbCommand(@"update books set books_count = " + (c - oplog.OPCount).ToString() + " where id = " + oplog.BookID))
  359. {
  360. DBHelper.ExecuteNonQuery("delete from operate where ID = " + opid);
  361. return DBHelper.ExecuteNonQuery(comm2);
  362. }
  363. }
  364. if (oplog.op == EnumOP.领 || oplog.op == EnumOP.售)
  365. {
  366. int c = queryCountByID(oplog.BookID);
  367. using (OleDbCommand comm2 = new OleDbCommand(@"update books set books_count = " + (c + oplog.OPCount).ToString() + " where id = " + oplog.BookID))
  368. {
  369. DBHelper.ExecuteNonQuery("delete from operate where ID = " + opid);
  370. return DBHelper.ExecuteNonQuery(comm2);
  371. }
  372. }
  373. return 0;
  374. }
  375. }
  376. #endregion
  377. #region 销售统计
  378. private int _dal_getTotalSell()
  379. {
  380. using (OleDbCommand comm= new OleDbCommand(@"SELECT SUM(BOOKS.PRICE * OPERATE.OP_COUNT) AS Total
  381. FROM (BOOKS INNER JOIN OPERATE ON BOOKS.ID = OPERATE.OP_BOOK_NO)
  382. WHERE (OPERATE.OP = 1)"))
  383. {
  384. return Convert.ToInt32(DBHelper.ExecuteScalar(comm));
  385. }
  386. }
  387. private int GetTotalSell()
  388. {
  389. return _dal_getTotalSell();
  390. }
  391. private DataTable _dal_getSellList(DateTime dt_start, DateTime dt_end)
  392. {
  393. int year = DateTime.Now.Year;
  394. using (OleDbCommand comm = new OleDbCommand(@"SELECT BOOKS.ID AS 编号, BOOKS.BOOKNAME AS 书名, BOOKS.PRICE AS 定价, OPERATE.OP_COUNT AS 数量,
  395. OPERATE.OP_DATE AS 销售时间, OPERATE.OPERATOR AS 备注信息,
  396. BOOKS.PRICE * OPERATE.OP_COUNT AS 小计
  397. FROM (BOOKS INNER JOIN
  398. OPERATE ON BOOKS.ID = OPERATE.OP_BOOK_NO)
  399. WHERE (OPERATE.OP = 1) AND (OPERATE.OP_DATE > CDATE('" + dt_start.ToString("yyyy-MM-dd HH:mm:ss") + "')) and (OPERATE.OP_DATE < CDATE('" + dt_end.ToString("yyyy-MM-dd HH:mm:ss") + "'))"))
  400. {
  401. return DBHelper.ExecuteDataTable(comm);
  402. }
  403. }
  404. public DataTable GetSellList(DateTime start,DateTime end)
  405. {
  406. return _dal_getSellList(start,end);
  407. }
  408. /// <summary>
  409. /// 领取导出
  410. /// </summary>
  411. /// <param name="dt_start"></param>
  412. /// <param name="dt_end"></param>
  413. /// <returns></returns>
  414. public DataTable GetHandOutList(DateTime dt_start, DateTime dt_end)
  415. {
  416. int year = DateTime.Now.Year;
  417. using (OleDbCommand comm = new OleDbCommand(@"SELECT BOOKS.ID AS 编号, BOOKS.BOOKNAME AS 书名, BOOKS.PRICE AS 定价, OPERATE.OP_COUNT AS 数量,
  418. OPERATE.OP_DATE AS 领取时间, OPERATE.OPERATOR AS 备注信息,
  419. BOOKS.PRICE * OPERATE.OP_COUNT AS 小计
  420. FROM (BOOKS INNER JOIN
  421. OPERATE ON BOOKS.ID = OPERATE.OP_BOOK_NO)
  422. WHERE (OPERATE.OP = 2) AND (OPERATE.OP_DATE > CDATE('" + dt_start.ToString("yyyy-MM-dd HH:mm:ss") + "')) and (OPERATE.OP_DATE < CDATE('" + dt_end.ToString("yyyy-MM-dd HH:mm:ss") + "'))"))
  423. {
  424. return DBHelper.ExecuteDataTable(comm);
  425. }
  426. }
  427. #endregion
  428. #region ClearAll
  429. public bool ClearDataBase()
  430. {
  431. try
  432. {
  433. DBHelper.ExecuteNonQuery(@"delete * from operate");
  434. DBHelper.ExecuteNonQuery(@"delete * from books");
  435. DBHelper.ExecuteNonQuery(@"delete * from blist");
  436. DBHelper.ExecuteNonQuery(@"alter table operate alter column ID counter(1,1)");
  437. DBHelper.ExecuteNonQuery(@"alter table books alter column ID counter(1,1)");
  438. DBHelper.ExecuteNonQuery(@"alter table blist alter column BID counter(1,1)");
  439. return true;
  440. }
  441. catch (Exception)
  442. {
  443. return false;
  444. }
  445. }
  446. #endregion
  447. #region 批量购入记录
  448. private DataTable _dal_getBlist()
  449. {
  450. string command = "select * from blist";
  451. using (OleDbCommand comm = new OleDbCommand(command))
  452. {
  453. return DBHelper.ExecuteDataTable(comm);
  454. }
  455. }
  456. private List<BuyList> _ToModuleBuyList(DataTable dt)
  457. {
  458. List<BuyList> blist = new List<BuyList>();
  459. foreach (DataRow item in dt.Rows)
  460. {
  461. BuyList bl = new BuyList();
  462. bl.BID = int.Parse(item[0].ToString());
  463. bl.Count = int.Parse(item[1].ToString());
  464. bl.BuyDate = DateTime.Parse(item[2].ToString());
  465. blist.Add(bl);
  466. }
  467. return blist;
  468. }
  469. public List<BuyList> GetAllBuyList()
  470. {
  471. return _ToModuleBuyList(_dal_getBlist());
  472. }
  473. #endregion
  474. #region 书列表操作 针对表Booklist
  475. /// <summary>
  476. /// 获取书的列表的列表
  477. /// </summary>
  478. /// <returns></returns>
  479. public Dictionary<int, string> BookListALL()
  480. {
  481. return _ToModuleBookListList(_dal_getBookListList());
  482. }
  483. private DataTable _dal_getBookListList()
  484. {
  485. using (OleDbCommand comm = new OleDbCommand("select * from booklist"))
  486. {
  487. return DBHelper.ExecuteDataTable(comm);
  488. }
  489. }
  490. private Dictionary<int, string> _ToModuleBookListList(DataTable dt)
  491. {
  492. Dictionary<int, string> dic = new Dictionary<int, string>();
  493. foreach (DataRow item in dt.Rows)
  494. {
  495. int i = int.Parse(item[0].ToString());
  496. string s = item[2].ToString();
  497. dic.Add(i, s);
  498. }
  499. return dic;
  500. }
  501. public List<Book> GetBookListFromBookListID(int id)
  502. {
  503. List<Book> list = new List<Book>();
  504. string s = DBHelper.ExecuteScalar(new OleDbCommand("select booksid from booklist where lid = " + id)).ToString();
  505. var ids = s.Split(',');
  506. for (int i = 0; i < ids.Length; i++)
  507. {
  508. var bk = this.GetOneBookByID(int.Parse(ids[i]));
  509. list.Add(bk);
  510. }
  511. return list;
  512. }
  513. public int SaveBookList(List<Book> bklst,string tag)
  514. {
  515. //insert into books(bookname,price,order_price,books_count,IS_STUDENTBOOK)values('" + bkname + "'," + price + "," + orderprice + "," + count + "," + studentBook +")"))
  516. StringBuilder bkids = new StringBuilder();
  517. for (int i = 0; i < bklst.Count; i++)
  518. {
  519. if (bkids.Length==0)
  520. {
  521. bkids.Append(bklst[i].BookID);
  522. }
  523. else
  524. {
  525. bkids.Append("," + bklst[i].BookID);
  526. }
  527. }
  528. using (OleDbCommand comm = new OleDbCommand("insert into booklist(booksid,tag)values('"+ bkids.ToString() +"','" + tag + "' )"))
  529. {
  530. return DBHelper.ExecuteNonQuery(comm);
  531. }
  532. }
  533. public int RemoveBookListByBookListID(int id)
  534. {
  535. return DBHelper.ExecuteNonQuery(new OleDbCommand("delete from booklist where lid = " + id));
  536. }
  537. #endregion
  538. }
  539. }