1
0

DBcon.cs 25 KB

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