PreAndInProcessAnalysisLogQueryForm.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Business;
  3. using PTMedicalInsurance.Common;
  4. using PTMedicalInsurance.FormSetter;
  5. using PTMedicalInsurance.Helper;
  6. using PTMedicalInsurance.Variables;
  7. using Sunny.UI;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows.Forms;
  17. using System.Xml.Serialization;
  18. namespace PTMedicalInsurance.Forms
  19. {
  20. public partial class PreAndInProcessAnalysisLogQueryForm : Form
  21. {
  22. private PreAndInProcessAnalysisLogService logService = new PreAndInProcessAnalysisLogService();
  23. private GridViewSetter grdSetter = new GridViewSetter();
  24. public PreAndInProcessAnalysisLogQueryForm()
  25. {
  26. InitializeComponent();
  27. }
  28. private void PreAndInProcessAnalysisLogQueryForm_Load(object sender, EventArgs e)
  29. {
  30. try
  31. {
  32. // 初始化日期范围
  33. dtpStartDate.Value = DateTime.Now.AddDays(-7);
  34. dtpEndDate.Value = DateTime.Now;
  35. // 设置界面样式
  36. this.StartPosition = FormStartPosition.CenterParent;
  37. // 初始化表格列
  38. InitializeDataGridViewColumns();
  39. }
  40. catch (Exception ex)
  41. {
  42. MessageBox.Show($"初始化界面失败: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  43. }
  44. }
  45. private void InitializeDataGridViewColumns()
  46. {
  47. dgvLogs.Columns.Clear();
  48. // 添加列定义
  49. var columns = new[]
  50. {
  51. new { HeaderText = "日期", DataPropertyName = "InfDate", Width = 150 },
  52. new { HeaderText = "时间", DataPropertyName = "InfTime", Width = 150 },
  53. new { HeaderText = "科室", DataPropertyName = "DeptName", Width = 120 },
  54. new { HeaderText = "操作员", DataPropertyName = "OpterName", Width = 100 },
  55. new { HeaderText = "病人姓名", DataPropertyName = "PatnName", Width = 100 },
  56. new { HeaderText = "项目名称", DataPropertyName = "ItemName", Width = 150 },
  57. new { HeaderText = "违规分类", DataPropertyName = "VolaBhvrType", Width = 100 },
  58. new { HeaderText = "限制类型", DataPropertyName = "WarnType", Width = 100 },
  59. new { HeaderText = "后续操作", DataPropertyName = "DspoWay", Width = 100 },
  60. new { HeaderText = "数量", DataPropertyName = "Quantity", Width = 80 },
  61. new { HeaderText = "金额", DataPropertyName = "Amount", Width = 100 },
  62. new { HeaderText = "交易代码", DataPropertyName = "TradeCode", Width = 80 },
  63. new { HeaderText = "触发场景", DataPropertyName = "TriggerScene", Width = 80 },
  64. new { HeaderText = "违规规则", DataPropertyName = "RuleName", Width = 150 },
  65. new { HeaderText = "违规金额", DataPropertyName = "VolaAmt", Width = 100 }
  66. };
  67. foreach (var col in columns)
  68. {
  69. DataGridViewColumn newColumn = new DataGridViewTextBoxColumn();
  70. newColumn.HeaderText = col.HeaderText;
  71. newColumn.DataPropertyName = col.DataPropertyName;
  72. newColumn.Width = col.Width;
  73. dgvLogs.Columns.Add(newColumn);
  74. }
  75. dgvLogs.AutoGenerateColumns = false;
  76. }
  77. private void btnQuery_Click(object sender, EventArgs e)
  78. {
  79. try
  80. {
  81. Cursor = Cursors.WaitCursor;
  82. btnQuery.Enabled = false;
  83. // 获取查询条件
  84. string startDate = dtpStartDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  85. string endDate = dtpEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  86. string operatorName = txtOperatorName.Text.Trim();
  87. string patientName = txtPatientName.Text.Trim();
  88. string itemName = txtItemName.Text.Trim();
  89. // 调用查询服务
  90. string errMsg;
  91. DataTable dt = logService.QueryLogs(startDate, endDate, operatorName, patientName, itemName, out errMsg);
  92. if (dt == null)
  93. {
  94. if (!string.IsNullOrEmpty(errMsg))
  95. {
  96. MessageBox.Show($"查询失败: {errMsg}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  97. }
  98. else
  99. {
  100. MessageBox.Show("查询失败,请稍后重试", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  101. }
  102. dgvLogs.DataSource = null;
  103. lblRecordCount.Text = "查询结果:0 条记录";
  104. return;
  105. }
  106. // 显示查询结果
  107. dgvLogs.DataSource = dt;
  108. lblRecordCount.Text = $"查询结果:{dt.Rows.Count} 条记录";
  109. // 计算合计金额
  110. CalculateTotals(dt);
  111. }
  112. catch (Exception ex)
  113. {
  114. MessageBox.Show($"查询异常: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  115. }
  116. finally
  117. {
  118. Cursor = Cursors.Default;
  119. btnQuery.Enabled = true;
  120. }
  121. }
  122. private void CalculateTotals(DataTable dt)
  123. {
  124. try
  125. {
  126. decimal totalAmount = 0;
  127. decimal totalViolationAmount = 0;
  128. int totalRecords = dt.Rows.Count;
  129. foreach (DataRow row in dt.Rows)
  130. {
  131. // 计算总金额
  132. if (row["Amount"] != DBNull.Value && decimal.TryParse(row["Amount"].ToString(), out decimal amount))
  133. {
  134. totalAmount += amount;
  135. }
  136. // 计算违规金额
  137. if (row["ViolationAmount"] != DBNull.Value && decimal.TryParse(row["ViolationAmount"].ToString(), out decimal violationAmount))
  138. {
  139. totalViolationAmount += violationAmount;
  140. }
  141. }
  142. lblTotalAmount.Text = $"总金额:{totalAmount:F2} 元";
  143. lblTotalViolationAmount.Text = $"违规金额:{totalViolationAmount:F2} 元";
  144. lblRecordCount.Text = $"查询结果:{totalRecords} 条记录";
  145. }
  146. catch (Exception ex)
  147. {
  148. Global.writeLog($"计算合计金额异常: {ex.Message}");
  149. }
  150. }
  151. private void btnExport_Click(object sender, EventArgs e)
  152. {
  153. try
  154. {
  155. if (dgvLogs.DataSource == null)
  156. {
  157. MessageBox.Show("请先查询数据再进行导出", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  158. return;
  159. }
  160. DataTable dt = (DataTable)dgvLogs.DataSource;
  161. if (dt.Rows.Count == 0)
  162. {
  163. MessageBox.Show("没有数据可以导出", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  164. return;
  165. }
  166. // 弹出保存文件对话框
  167. SaveFileDialog saveFileDialog = new SaveFileDialog();
  168. saveFileDialog.Filter = "Excel文件 (*.xlsx)|*.xlsx|Excel文件 (*.xls)|*.xls|所有文件 (*.*)|*.*";
  169. saveFileDialog.FilterIndex = 1;
  170. saveFileDialog.RestoreDirectory = true;
  171. saveFileDialog.FileName = $"事前事中分析日志_{DateTime.Now:yyyyMMddHHmmss}";
  172. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  173. {
  174. Cursor = Cursors.WaitCursor;
  175. btnExport.Enabled = false;
  176. try
  177. {
  178. //// 导出到Excel
  179. //string fileName = ExportToExcel.DataTabletoExcel(dt, saveFileDialog.FileName);
  180. //if (!string.IsNullOrEmpty(fileName))
  181. //{
  182. // MessageBox.Show($"数据已成功导出到:{fileName}", "导出成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
  183. // // 更新导出状态
  184. // UpdateExportStatus(dt);
  185. //}
  186. //else
  187. //{
  188. // MessageBox.Show("导出失败,请稍后重试", "导出失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
  189. //}
  190. // 导出到Excel
  191. ExportToExcel.ExportDataGridViewToExcel(dgvLogs, saveFileDialog.FileName);
  192. MessageBox.Show($"数据已成功导出到:{saveFileDialog.FileName}", "导出成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
  193. }
  194. catch (Exception ex)
  195. {
  196. MessageBox.Show($"导出异常: {ex.Message}", "导出失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
  197. }
  198. finally
  199. {
  200. Cursor = Cursors.Default;
  201. btnExport.Enabled = true;
  202. }
  203. }
  204. }
  205. catch (Exception ex)
  206. {
  207. MessageBox.Show($"导出异常: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
  208. }
  209. }
  210. private void UpdateExportStatus(DataTable dt)
  211. {
  212. try
  213. {
  214. // 这里可以实现更新数据库中的导出状态
  215. // 例如:标记已导出的记录
  216. Global.writeLog($"已导出 {dt.Rows.Count} 条日志记录");
  217. // 在实际项目中,这里应该调用服务更新数据库中的导出状态
  218. // logService.UpdateExportStatus(logIds, DateTime.Now, Global.user.Name);
  219. }
  220. catch (Exception ex)
  221. {
  222. Global.writeLog($"更新导出状态异常: {ex.Message}");
  223. }
  224. }
  225. private void btnClear_Click(object sender, EventArgs e)
  226. {
  227. // 清空查询条件
  228. txtOperatorName.Text = "";
  229. txtPatientName.Text = "";
  230. txtItemName.Text = "";
  231. }
  232. private void dgvLogs_CellClick(object sender, DataGridViewCellEventArgs e)
  233. {
  234. try
  235. {
  236. if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
  237. {
  238. // 可以在这里实现查看详细信息的逻辑
  239. // 例如:点击某行时显示详细信息
  240. var selectedRow = dgvLogs.Rows[e.RowIndex];
  241. string logId = selectedRow.Cells["ID"]?.Value?.ToString();
  242. if (!string.IsNullOrEmpty(logId))
  243. {
  244. // 可以在这里显示详细信息对话框
  245. // ShowLogDetailDialog(logId);
  246. }
  247. }
  248. }
  249. catch (Exception ex)
  250. {
  251. Global.writeLog($"点击表格单元格异常: {ex.Message}");
  252. }
  253. }
  254. private void btnClose_Click(object sender, EventArgs e)
  255. {
  256. this.Close();
  257. }
  258. }
  259. }