1
0

FrmLOGViewer.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace BooksManageSystem
  10. {
  11. public partial class FrmLOGViewer : Form
  12. {
  13. List<OPLOG> list;
  14. DBcon con;
  15. public FrmLOGViewer( List<OPLOG> l)
  16. {
  17. InitializeComponent();
  18. this.list = l;
  19. con = new DBcon();
  20. }
  21. private void FrmLOGViewer_Load(object sender, EventArgs e)
  22. {
  23. foreach (var item in list)
  24. {
  25. ListViewItem ii = new ListViewItem(item.BookID.ToString());
  26. ii.SubItems.Add(item.BookName);
  27. ii.SubItems.Add(item.op.ToString());
  28. ii.SubItems.Add(item.OPCount.ToString());
  29. ii.SubItems.Add(item.AfterOPCount.ToString());
  30. ii.SubItems.Add(item.OPdatetime.ToString());
  31. ii.SubItems.Add(item.oper);
  32. ii.Tag = item;
  33. listView1.Items.Add(ii);
  34. }
  35. }
  36. private void menu_outExcel_Click(object sender, EventArgs e)
  37. {
  38. var sfd = new SaveFileDialog();
  39. sfd.Filter = "Excel File(*.xlsx)|*.xlsx";
  40. if (sfd.ShowDialog()== System.Windows.Forms.DialogResult.OK)
  41. {
  42. if (File.Exists(sfd.FileName))
  43. {
  44. File.Delete(sfd.FileName);
  45. }
  46. using (OfficeOpenXml.ExcelPackage ep = new OfficeOpenXml.ExcelPackage(new FileInfo(sfd.FileName)))
  47. {
  48. var sheet = ep.Workbook.Worksheets.Add("变更记录");
  49. sheet.Cells[1, 1].Value = "书名";
  50. sheet.Cells[1, 2].Value = "变更操作";
  51. sheet.Cells[1, 3].Value = "变更数量";
  52. sheet.Cells[1, 4].Value = "变更后数量";
  53. sheet.Cells[1, 5].Value = "变更时间";
  54. sheet.Cells[1, 6].Value = "备注";
  55. int r = 1;
  56. foreach (var item in this.list)
  57. {
  58. sheet.Cells[++r, 1].Value = item.BookName;
  59. sheet.Cells[r, 2].Value = item.op.ToString();
  60. sheet.Cells[r, 3].Value = item.OPCount;
  61. sheet.Cells[r, 4].Value = item.AfterOPCount;
  62. sheet.Cells[r, 5].Value = item.OPdatetime;
  63. sheet.Cells[r, 6].Value = item.oper;
  64. }
  65. sheet.Cells["A:G"].AutoFitColumns();
  66. sheet.Cells["A1:G1"].Style.Font.Bold = true;
  67. sheet.Cells["E:E"].Style.Numberformat.Format = "yyyy-mm-dd";
  68. ep.Save();
  69. MessageBox.Show("已保存!","成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
  70. }
  71. }
  72. }
  73. private void menu_edit_Click(object sender, EventArgs e)
  74. {
  75. Edit_OP_LOG();
  76. }
  77. private void Edit_OP_LOG()
  78. {
  79. if (listView1.SelectedItems.Count == 1)
  80. {
  81. OPLOG log = listView1.SelectedItems[0].Tag as OPLOG;
  82. var eop = new FrmEditOP(log);
  83. if (eop.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  84. {
  85. if (con.ModifyOPLog(log.OPID, eop.DateOP, eop.Operator) > 0)
  86. {
  87. listView1.SelectedItems[0].SubItems[5].Text = eop.DateOP.ToString("yyyy-MM-dd HH:mm:ss");
  88. listView1.SelectedItems[0].SubItems[6].Text = eop.Operator;
  89. }
  90. else
  91. {
  92. MessageBox.Show("修改失败!");
  93. }
  94. }
  95. }
  96. else
  97. {
  98. MessageBox.Show("请选择一项进行修改");
  99. }
  100. }
  101. private void menu_del_Click(object sender, EventArgs e)
  102. {
  103. Del_OP_LOG();
  104. }
  105. private void Del_OP_LOG()
  106. {
  107. if (listView1.SelectedItems.Count == 1)
  108. {
  109. OPLOG log = listView1.SelectedItems[0].Tag as OPLOG;
  110. string op = string.Empty;
  111. if (log.op == EnumOP.购 || log.op == EnumOP.还)
  112. {
  113. op = "减少";
  114. }
  115. else if (log.op == EnumOP.领 || log.op == EnumOP.售)
  116. {
  117. op = "增加";
  118. }
  119. string message = "删除本记录会使《" + log.BookName + "》的数量" + op + log.OPCount.ToString() + "。本操作不可撤销。确认删除?";
  120. var res = MessageBox.Show(message, "确认删除本条记录?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
  121. if (res == System.Windows.Forms.DialogResult.Yes)
  122. {
  123. if (con.UndoOPByOPID(log.OPID) > 0)
  124. {
  125. listView1.Items.Remove(listView1.SelectedItems[0]);
  126. listView1.Update();
  127. //MessageBox.Show("删除成功");
  128. }
  129. }
  130. else if (res == System.Windows.Forms.DialogResult.No)
  131. {
  132. }
  133. else if (res == System.Windows.Forms.DialogResult.Cancel)
  134. {
  135. }
  136. }
  137. else
  138. {
  139. MessageBox.Show("请选择一项进行修改");
  140. }
  141. }
  142. private void cMenu_Del_oplog_Click(object sender, EventArgs e)
  143. {
  144. Del_OP_LOG();
  145. }
  146. private void cMenu_Edit_oplog_Click(object sender, EventArgs e)
  147. {
  148. Edit_OP_LOG();
  149. }
  150. }
  151. }