Form1.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Data.OleDb;
  9. //using NPOI.SS.UserModel;
  10. using System.IO;
  11. namespace BooksManageSystem
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. DBcon con = new DBcon();
  20. List<Book> booklist;
  21. private void Form1_Load(object sender, EventArgs e)
  22. {
  23. reload();
  24. }
  25. private void reload()
  26. {
  27. try
  28. {
  29. booklist = new DBcon().GetBookList();
  30. fillListView(booklist);
  31. }
  32. catch (Exception err)
  33. {
  34. MessageBox.Show(err.Message + "请确保数据库文件和程序在同一个目录。");
  35. }
  36. }
  37. private void fillListView(List<Book> list)
  38. {
  39. listView1.Items.Clear();
  40. listView1.BeginUpdate();
  41. foreach (var item in list)
  42. {
  43. ListViewItem i = new ListViewItem(item.BookID.ToString());
  44. i.SubItems.Add(item.BookName);
  45. i.SubItems.Add(item.Price.ToString());
  46. i.SubItems.Add(item.OrderPrice.ToString());
  47. i.SubItems.Add(item.Count.ToString());
  48. i.SubItems.Add(item.IsStuBook?"YES":"NO");
  49. i.Tag = item;
  50. if (item.IsStuBook&& item.Count<10)
  51. {
  52. i.ForeColor = Color.Firebrick;
  53. }
  54. listView1.Items.Add(i);
  55. }
  56. listView1.EndUpdate();
  57. }
  58. private void menu_BUYBOOK_Click(object sender, EventArgs e)
  59. {
  60. BUY_BookList();
  61. }
  62. private void menu_RETURNBOOK_Click(object sender, EventArgs e)
  63. {
  64. RETURN_BOOK();
  65. }
  66. private void menu_SELLBOOK_Click(object sender, EventArgs e)
  67. {
  68. SELL_BOOK();
  69. }
  70. private void menu_LINGQU_Click(object sender, EventArgs e)
  71. {
  72. LINGQU_BOOK();
  73. }
  74. private void menu_BookLOG_Click(object sender, EventArgs e)
  75. {
  76. if (listView1.SelectedItems.Count > 1)
  77. {
  78. MessageBox.Show("只能选择一种书!");
  79. return;
  80. }
  81. if (listView1.SelectedItems.Count == 1)
  82. {
  83. var list =con.GetOPLogByID((listView1.SelectedItems[0].Tag as Book).BookID);
  84. new FrmLOGViewer(list).ShowDialog();
  85. }
  86. }
  87. private void menu_All_bookLOG_Click(object sender, EventArgs e)
  88. {
  89. new FrmLOGViewer(con.GetOPLogALL()).ShowDialog();
  90. }
  91. private void menu_exportBookList_Click(object sender, EventArgs e)
  92. {
  93. var list = con.GetBookList();
  94. StringBuilder sb = new StringBuilder();
  95. sb.AppendLine("编号\t书名\t定价\t购入价\t库存+\t学生用书");
  96. foreach (Book item in list)
  97. {
  98. sb.AppendLine(item.BookID + "\t" + item.BookName + "\t" + item.Price + "\t" + item.OrderPrice + "\t" + item.Count + "\t" + (item.IsStuBook?"YES":"NO"));
  99. }
  100. try
  101. {
  102. var fDia = new SaveFileDialog();
  103. fDia.Filter = "txt files (*.txt)|*.txt";
  104. if (fDia.ShowDialog()== DialogResult.OK)
  105. {
  106. System.IO.File.WriteAllText(fDia.FileName, sb.ToString(), Encoding.Default);
  107. MessageBox.Show("如需要Excel在Excel中操作,请全选并复制粘贴到Excel中。");
  108. System.Diagnostics.Process.Start(fDia.FileName);
  109. }
  110. }
  111. catch (Exception err)
  112. {
  113. MessageBox.Show(err.Message);
  114. }
  115. }
  116. void output()
  117. {
  118. //NPOI.HSSF.UserModel.HSSFWorkbook wb = new NPOI.HSSF.UserModel.HSSFWorkbook();
  119. //ISheet oSheet = wb.CreateSheet("leibieo");
  120. //var row = oSheet.CreateRow(1);
  121. //row.CreateCell(1).SetCellValue("编号");
  122. //row.CreateCell(2).SetCellValue("书名");
  123. //row.CreateCell(3).SetCellValue("定价");
  124. //row.CreateCell(4).SetCellValue("购入价");
  125. //row.CreateCell(5).SetCellValue("库存");
  126. //row.CreateCell(6).SetCellValue("学生用书");
  127. //var list = con.GetBookList();
  128. //int n = 2;
  129. //foreach (Book item in list)
  130. //{
  131. // row = oSheet.CreateRow(n++);
  132. // row.CreateCell(1).SetCellValue(item.BookID);
  133. // row.CreateCell(2).SetCellValue(item.BookName);
  134. // row.CreateCell(3).SetCellValue(item.Price);
  135. // row.CreateCell(4).SetCellValue(item.OrderPrice);
  136. // row.CreateCell(5).SetCellValue(item.Count);
  137. // row.CreateCell(6).SetCellValue(item.IsStuBook);
  138. //}
  139. //FileStream fs = new FileStream(@"abc.xlsx", FileMode.Create);
  140. //wb.Write(fs);
  141. //fs.Close();
  142. }
  143. void outputExcelBookList()
  144. {
  145. string fn;
  146. var fDia = new SaveFileDialog();
  147. fDia.Filter = "Excel files (*.xlsx)|*.xlsx";
  148. if (fDia.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  149. {
  150. fn = fDia.FileName;
  151. }
  152. else
  153. {
  154. return;
  155. }
  156. var file = new FileInfo(fn);
  157. if (File.Exists(file.FullName))
  158. {
  159. file.Delete();
  160. }
  161. OfficeOpenXml.ExcelPackage ep = new OfficeOpenXml.ExcelPackage(file) ;
  162. var sheet = ep.Workbook.Worksheets.Add("库存列表");
  163. var list = con.GetBookList();
  164. int r =1;
  165. int c=1;
  166. sheet.Cells[r, c].Value = "编号";
  167. sheet.Cells[r, ++c].Value = "书名";
  168. sheet.Cells[r, ++c].Value = "定价";
  169. sheet.Cells[r, ++c].Value = "购入价";
  170. sheet.Cells[r, ++c].Value = "库存";
  171. sheet.Cells[r, ++c].Value = "学生用书";
  172. foreach (Book item in list)
  173. {
  174. c = 1;
  175. sheet.Cells[++r, c++].Value = item.BookID;
  176. sheet.Cells[r, c++].Value = item.BookName;
  177. sheet.Cells[r, c++].Value = item.Price;
  178. sheet.Cells[r, c++].Value = item.OrderPrice;
  179. sheet.Cells[r, c++].Value = item.Count;
  180. sheet.Cells[r, c++].Value = item.IsStuBook;
  181. }
  182. sheet.Cells["1:1"].Style.Font.Bold = true;
  183. sheet.Cells["A:F"].AutoFitColumns();
  184. //Console.WriteLine(sheet.Cells["1:1"].End.Row.ToString());
  185. ep.Save();
  186. ep.Dispose();
  187. }
  188. void outputExcelSellList(DateTime start,DateTime end)
  189. {//编号, 书名 , 定价, 数量, 备注信息 , 小计
  190. var fDia = new SaveFileDialog();
  191. fDia.Filter = "Excel files (*.xlsx)|*.xlsx";
  192. if (fDia.ShowDialog()== System.Windows.Forms.DialogResult.OK)
  193. {
  194. if (File.Exists(fDia.FileName))
  195. {
  196. File.Delete(fDia.FileName);
  197. }
  198. }
  199. else
  200. {
  201. return;
  202. }
  203. var dt =con.GetSellList(start,end);
  204. using (OfficeOpenXml.ExcelPackage ep = new OfficeOpenXml.ExcelPackage())
  205. {
  206. var sheet = ep.Workbook.Worksheets.Add("Table1");
  207. for (int i = 0; i < dt.Columns.Count; i++)
  208. {
  209. sheet.Cells[1, i + 1].Value = dt.Columns[i].ColumnName;
  210. }
  211. int row = 1;
  212. foreach (DataRow r in dt.Rows)
  213. {
  214. row++;
  215. for (int i = 0; i < dt.Columns.Count; i++)
  216. {
  217. sheet.Cells[row, i + 1].Value = r[i];
  218. }
  219. }
  220. sheet.Cells["A:G"].AutoFitColumns();
  221. sheet.Cells["A1:G1"].Style.Font.Bold = true;
  222. sheet.Cells["E:E"].Style.Numberformat.Format = "yyyy-mm-dd";
  223. ep.SaveAs(new FileInfo(fDia.FileName));
  224. }
  225. }
  226. void outputExcelOutGiveList(DateTime start, DateTime end)
  227. {//编号, 书名 , 定价, 数量, 备注信息 , 小计
  228. var fDia = new SaveFileDialog();
  229. fDia.Filter = "Excel files (*.xlsx)|*.xlsx";
  230. if (fDia.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  231. {
  232. if (File.Exists(fDia.FileName))
  233. {
  234. File.Delete(fDia.FileName);
  235. }
  236. }
  237. else
  238. {
  239. return;
  240. }
  241. var dt = con.GetHandOutList(start, end);
  242. using (OfficeOpenXml.ExcelPackage ep = new OfficeOpenXml.ExcelPackage())
  243. {
  244. var sheet = ep.Workbook.Worksheets.Add("Table1");
  245. for (int i = 0; i < dt.Columns.Count; i++)
  246. {
  247. sheet.Cells[1, i + 1].Value = dt.Columns[i].ColumnName;
  248. }
  249. int row = 1;
  250. foreach (DataRow r in dt.Rows)
  251. {
  252. row++;
  253. for (int i = 0; i < dt.Columns.Count; i++)
  254. {
  255. sheet.Cells[row, i + 1].Value = r[i];
  256. }
  257. }
  258. sheet.Cells["A:G"].AutoFitColumns();
  259. sheet.Cells["A1:G1"].Style.Font.Bold = true;
  260. sheet.Cells["E:E"].Style.Numberformat.Format = "yyyy-mm-dd";
  261. ep.SaveAs(new FileInfo(fDia.FileName));
  262. }
  263. }
  264. private void menu_newBook_Click(object sender, EventArgs e)
  265. {
  266. var ok= new FrmAddNewBook(null).ShowDialog();
  267. if (ok== System.Windows.Forms.DialogResult.OK)
  268. {
  269. reload();
  270. }
  271. }
  272. private void txt_Search_KeyPress(object sender, KeyPressEventArgs e)
  273. {
  274. if (e.KeyChar==13)
  275. {
  276. var list =con.GetBookListByName(txt_Search.Text.Trim());
  277. fillListView(list);
  278. e.Handled = true;
  279. }
  280. }
  281. private void menu_ExcelOutBookList_Click(object sender, EventArgs e)
  282. {
  283. outputExcelBookList();
  284. }
  285. private void menu_TotalSell_Click(object sender, EventArgs e)
  286. {
  287. FrmOutputSellList olist = new FrmOutputSellList();
  288. if (olist.ShowDialog()== System.Windows.Forms.DialogResult.OK)
  289. {
  290. outputExcelSellList(olist.Start, olist.End);
  291. }
  292. }
  293. private void menu_TotalOut_Click(object sender, EventArgs e)
  294. {
  295. FrmOutputSellList olist = new FrmOutputSellList();
  296. if (olist.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  297. {
  298. outputExcelOutGiveList(olist.Start, olist.End);
  299. }
  300. }
  301. private void menu_init_Click(object sender, EventArgs e)
  302. {
  303. new FrmClearDB().ShowDialog();
  304. }
  305. private void menu_ModifyBook_Click(object sender, EventArgs e)
  306. {
  307. if (listView1.SelectedItems.Count == 1)
  308. {
  309. var ok = new FrmAddNewBook(listView1.SelectedItems[0].Tag as Book).ShowDialog();
  310. if (ok== System.Windows.Forms.DialogResult.OK)
  311. {
  312. reload();
  313. }
  314. }
  315. else
  316. {
  317. MessageBox.Show("需要选择一项进行修改!");
  318. }
  319. }
  320. private void menu_About_Click(object sender, EventArgs e)
  321. {
  322. new FrmAbout().ShowDialog();
  323. //MessageBox.Show("H为Grace定制的图书管理!\r\n\r\n 2014年4月12日", "Grace的图书管理", MessageBoxButtons.OK, MessageBoxIcon.Information);
  324. }
  325. private void Form1_SizeChanged(object sender, EventArgs e)
  326. {
  327. //pl_ListView.Size = new Size(pl_ListView.Size.Width, this.Size.Height - he);
  328. listView1.Size = new Size(this.Size.Width - listView1.Location.X - 25 , this.Size.Height - listView1.Location.Y - 45);
  329. }
  330. private void menu_BigList_Click(object sender, EventArgs e)
  331. {
  332. try
  333. {
  334. new FrmBigListViewer().ShowDialog();
  335. }
  336. catch (Exception err)
  337. {
  338. MessageBox.Show(err.Message);
  339. }
  340. }
  341. #region 书籍变更逻辑
  342. void BUY_BOOK()
  343. {
  344. if (listView1.SelectedItems.Count != 1)
  345. {
  346. MessageBox.Show("请先选择需要操作的书籍!(能且只能选择一种书籍)");
  347. return;
  348. }
  349. if (listView1.SelectedItems.Count == 1)
  350. {
  351. var frm = new frmChange(listView1.SelectedItems[0].Tag as Book, EnumOP.购);
  352. if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  353. {
  354. try
  355. {
  356. int after = con.PurchaseBook(frm.BookID, frm.BookChangeCount, frm.NoteTag, frm.OPDateTime,0);
  357. listView1.SelectedItems[0].SubItems[4].Text = after.ToString();
  358. MessageBox.Show("变更成功!","成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
  359. }
  360. catch (Exception err)
  361. {
  362. MessageBox.Show("变更失败:" + err.Message);
  363. }
  364. }
  365. }
  366. }
  367. void RETURN_BOOK()
  368. {
  369. if (listView1.SelectedItems.Count != 1)
  370. {
  371. MessageBox.Show("请先选择需要操作的书籍!(能且只能选择一种书籍)");
  372. return;
  373. }
  374. if (listView1.SelectedItems.Count == 1)
  375. {
  376. var frm = new frmChange(listView1.SelectedItems[0].Tag as Book, EnumOP.还);
  377. if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  378. {
  379. try
  380. {
  381. int after = con.ReturnBookByID(frm.BookID, frm.BookChangeCount, frm.NoteTag, frm.OPDateTime);
  382. listView1.SelectedItems[0].SubItems[4].Text = after.ToString();
  383. MessageBox.Show("变更成功!","成功!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  384. }
  385. catch (Exception err)
  386. {
  387. MessageBox.Show("变更失败:" + err.Message);
  388. }
  389. }
  390. }
  391. }
  392. void SELL_BOOK()
  393. {
  394. if (listView1.SelectedItems.Count != 1)
  395. {
  396. MessageBox.Show("请先选择需要操作的书籍!(能且只能选择一种书籍)");
  397. return;
  398. }
  399. if (listView1.SelectedItems.Count == 1)
  400. {
  401. var frm = new frmChange(listView1.SelectedItems[0].Tag as Book, EnumOP.售);
  402. if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  403. {
  404. try
  405. {
  406. int after = con.SellBookByID(frm.BookID, frm.BookChangeCount, frm.NoteTag, frm.OPDateTime);
  407. listView1.SelectedItems[0].SubItems[4].Text = after.ToString();
  408. MessageBox.Show("变更成功!", "成功!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  409. }
  410. catch (Exception err)
  411. {
  412. MessageBox.Show("变更失败:" + err.Message);
  413. }
  414. }
  415. }
  416. }
  417. void LINGQU_BOOK()
  418. {
  419. if (listView1.SelectedItems.Count != 1)
  420. {
  421. MessageBox.Show("请先选择需要操作的书籍!(能且只能选择一种书籍)");
  422. return;
  423. }
  424. if (listView1.SelectedItems.Count == 1)
  425. {
  426. var frm = new frmChange(listView1.SelectedItems[0].Tag as Book, EnumOP.领);
  427. if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  428. {
  429. try
  430. {
  431. int after = con.Lingqu(frm.BookID, frm.BookChangeCount, frm.NoteTag, frm.OPDateTime);
  432. listView1.SelectedItems[0].SubItems[4].Text = after.ToString();
  433. MessageBox.Show("变更成功!","成功!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  434. }
  435. catch (Exception err)
  436. {
  437. MessageBox.Show("变更失败:" + err.Message);
  438. }
  439. }
  440. }
  441. }
  442. void BUY_BookList()
  443. {
  444. try
  445. {
  446. if (booklist==null)
  447. {
  448. booklist = con.GetBookList();
  449. }
  450. var maker = new FrmBookListMaker(booklist,"购买-列表编辑器","确认购买");
  451. if (maker.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  452. {
  453. //maker.BookListToBuy.Values.Count;
  454. int i = 0;
  455. foreach (var item in maker.BookListToOperate.Values)
  456. {
  457. i = i + item;
  458. }
  459. int bid = con.Blist(i, maker.OperTime);
  460. foreach (KeyValuePair<Book, int> item in maker.BookListToOperate)
  461. {
  462. con.PurchaseBook(item.Key.BookID, item.Value, maker.NoteTag, maker.OperTime, bid);
  463. }
  464. reload();
  465. MessageBox.Show("购买成功!","成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
  466. }
  467. }
  468. catch (Exception err)
  469. {
  470. MessageBox.Show("操作失败,错误消息:" + err.Message);
  471. }
  472. }
  473. void Lingqu_Booklist()
  474. {
  475. try
  476. {
  477. if (booklist == null)
  478. {
  479. booklist = con.GetBookList();
  480. }
  481. var maker = new FrmBookListMaker(booklist, "领取-列表编辑器", "确认领取");
  482. if (maker.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  483. {
  484. int i = 0;
  485. foreach (var item in maker.BookListToOperate.Values)
  486. {
  487. i = i + item;
  488. }
  489. foreach (KeyValuePair<Book, int> item in maker.BookListToOperate)
  490. {
  491. con.Lingqu(item.Key.BookID, item.Value, maker.NoteTag, maker.OperTime);
  492. }
  493. reload();
  494. MessageBox.Show("领取成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
  495. }
  496. }
  497. catch (Exception err)
  498. {
  499. MessageBox.Show("操作失败,错误消息:" + err.Message);
  500. }
  501. }
  502. void out_sell_BookList()
  503. {
  504. try
  505. {
  506. if (booklist == null)
  507. {
  508. booklist = con.GetBookList();
  509. }
  510. var maker = new FrmBookListMaker(booklist, "销售-列表编辑器", "确认售书");
  511. if (maker.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  512. {
  513. int i = 0;
  514. foreach (var item in maker.BookListToOperate.Values)
  515. {
  516. i = i + item;
  517. }
  518. foreach (KeyValuePair<Book, int> item in maker.BookListToOperate)
  519. {
  520. con.SellBookByID(item.Key.BookID, item.Value, maker.NoteTag, maker.OperTime);
  521. }
  522. reload();
  523. MessageBox.Show("售书成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
  524. }
  525. }
  526. catch (Exception err)
  527. {
  528. MessageBox.Show("操作失败,错误消息:" + err.Message);
  529. }
  530. }
  531. #endregion
  532. #region ButtonCalls
  533. private void btn_ShowAll_Click(object sender, EventArgs e)
  534. {
  535. reload();
  536. }
  537. private void btn_Search_Click(object sender, EventArgs e)
  538. {
  539. var list = con.GetBookListByName(txt_Search.Text.Trim());
  540. fillListView(list);
  541. }
  542. private void btn_in_Return_Click(object sender, EventArgs e)
  543. {
  544. RETURN_BOOK();
  545. }
  546. private void btn_out_Sell_Click(object sender, EventArgs e)
  547. {
  548. SELL_BOOK();
  549. }
  550. private void btn_out_Give_Click(object sender, EventArgs e)
  551. {
  552. LINGQU_BOOK();
  553. }
  554. private void btn_OPLOGALL_Click(object sender, EventArgs e)
  555. {
  556. new FrmLOGViewer(con.GetOPLogALL()).ShowDialog();
  557. }
  558. private void btn_in_Buy_Click(object sender, EventArgs e)
  559. {
  560. BUY_BookList();
  561. }
  562. private void btn_BuyListQuery_Click(object sender, EventArgs e)
  563. {
  564. try
  565. {
  566. new FrmBigListViewer().ShowDialog();
  567. }
  568. catch (Exception err)
  569. {
  570. MessageBox.Show(err.Message);
  571. }
  572. }
  573. private void btn_out_Sell_List_Click(object sender, EventArgs e)
  574. {
  575. out_sell_BookList();
  576. }
  577. private void btn_out_Give_booklist_Click(object sender, EventArgs e)
  578. {
  579. Lingqu_Booklist();
  580. }
  581. #endregion
  582. #region 升级
  583. private void toolStripMenuItem1_Click(object sender, EventArgs e)
  584. {
  585. try
  586. {
  587. DBHelper.ExecuteNonQuery(@"Alter TABLE OPERATE ADD COLUMN BID INT");
  588. DBHelper.ExecuteNonQuery(@"CREATE TABLE BLIST(BID INT NOT NULL IDENTITY(1,1),BCOUNT INT NOT NULL,BDATE DATETIME NOT NULL)");
  589. MessageBox.Show("升级成功!");
  590. }
  591. catch (Exception)
  592. {
  593. MessageBox.Show("升级失败,可能已经升级过了。");
  594. }
  595. }
  596. private void toolStripMenuItem2_Click(object sender, EventArgs e)
  597. {
  598. try
  599. {
  600. //DBHelper.ExecuteNonQuery(@"Alter TABLE OPERATE ADD COLUMN BID INT");
  601. DBHelper.ExecuteNonQuery(@"CREATE TABLE BOOKLIST(LID INT NOT NULL IDENTITY(1,1),BOOKSID TEXT NOT NULL,TAG TEXT NOT NULL)");
  602. MessageBox.Show("升级成功!");
  603. }
  604. catch (Exception)
  605. {
  606. MessageBox.Show("升级失败,可能已经升级过了。");
  607. }
  608. }
  609. #endregion
  610. private void button1_Click(object sender, EventArgs e)
  611. {
  612. MessageBox.Show(DateTime.Now.ToString());
  613. //测试函数
  614. using (OleDbCommand comm = new OleDbCommand(@"select books_count from books where id = @id"))
  615. {
  616. comm.Parameters.AddWithValue("@id", 1);
  617. MessageBox.Show("id参数:" + DBHelper.ExecuteScalar(comm).ToString());
  618. }
  619. using (OleDbCommand comm = new OleDbCommand(@"update books set books_count = @ccount where id = @id"))
  620. {
  621. comm.Parameters.AddWithValue("@ccount", 999);
  622. comm.Parameters.AddWithValue("@id", 1);
  623. MessageBox.Show("id参数、数量参数:" + DBHelper.ExecuteNonQuery(comm).ToString());
  624. }
  625. 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)"))
  626. {
  627. comm.Parameters.AddWithValue("@id", 1);
  628. comm.Parameters.AddWithValue("@op", (int)EnumOP.领);
  629. comm.Parameters.AddWithValue("@op_date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  630. comm.Parameters.AddWithValue("@op_count", 99);
  631. comm.Parameters.AddWithValue("@opertor", "Hansi");
  632. comm.Parameters.AddWithValue("@after_op_count", 22);
  633. //insert into operate (op_book_no,op,op_date,op_count,operator,after_op_count) values (?,?,?,?,?,?)
  634. //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)
  635. //INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)
  636. MessageBox.Show("多个参数,包含时间: 成功!" + DBHelper.ExecuteNonQuery(comm).ToString());
  637. }
  638. //MessageBox.Show(con.TestCon());
  639. }
  640. }
  641. }