1
0

FrmBookListViewer.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace BooksManageSystem
  10. {
  11. public partial class FrmBookListViewer : Form
  12. {
  13. public FrmBookListViewer()
  14. {
  15. InitializeComponent();
  16. }
  17. DBcon con = new DBcon();
  18. private void FrmBookListViewer_Load(object sender, EventArgs e)
  19. {
  20. var dic = con.BookListALL();
  21. foreach (KeyValuePair<int,string> item in dic)
  22. {
  23. ListViewItem li = new ListViewItem(item.Value);
  24. li.Tag = item.Key;
  25. this.listView1.Items.Add(li);
  26. }
  27. }
  28. private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  29. {
  30. if (this.listView1.SelectedItems.Count>0)
  31. {
  32. int bklid = (int)this.listView1.SelectedItems[0].Tag;
  33. var list = con.GetBookListFromBookListID(bklid);
  34. this.BookList = list;
  35. this.listBox1.Items.Clear();
  36. this.listBox1.Items.AddRange(tos(list).ToArray());
  37. }
  38. }
  39. private List<string> tos(List<Book> list)
  40. {
  41. List<string> s = new List<string>();
  42. foreach (var item in list)
  43. {
  44. s.Add(item.BookName);
  45. }
  46. return s;
  47. }
  48. public List<Book> BookList { get; set; }
  49. private void button1_Click(object sender, EventArgs e)
  50. {
  51. this.DialogResult = System.Windows.Forms.DialogResult.OK;
  52. }
  53. private void button2_Click(object sender, EventArgs e)
  54. {
  55. if (this.listView1.SelectedItems.Count > 0)
  56. {
  57. int bklid = (int)this.listView1.SelectedItems[0].Tag;
  58. var c = con.RemoveBookListByBookListID(bklid);
  59. if (c>0)
  60. {
  61. this.listView1.SelectedItems[0].Remove();
  62. MessageBox.Show("成功删除一个书单!");
  63. }
  64. else
  65. {
  66. MessageBox.Show("删除失败!");
  67. }
  68. }
  69. }
  70. }
  71. }