| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- using Newtonsoft.Json.Linq;
- using PTMedicalInsurance.Business;
- using PTMedicalInsurance.Common;
- using PTMedicalInsurance.FormSetter;
- using PTMedicalInsurance.Helper;
- using PTMedicalInsurance.Variables;
- using Sunny.UI;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Xml.Serialization;
- namespace PTMedicalInsurance.Forms
- {
- public partial class PreAndInProcessAnalysisLogQueryForm : Form
- {
- private PreAndInProcessAnalysisLogService logService = new PreAndInProcessAnalysisLogService();
- private GridViewSetter grdSetter = new GridViewSetter();
-
- public PreAndInProcessAnalysisLogQueryForm()
- {
- InitializeComponent();
- }
- private void PreAndInProcessAnalysisLogQueryForm_Load(object sender, EventArgs e)
- {
- try
- {
- // 初始化日期范围
- dtpStartDate.Value = DateTime.Now.AddDays(-7);
- dtpEndDate.Value = DateTime.Now;
-
- // 设置界面样式
- this.StartPosition = FormStartPosition.CenterParent;
-
- // 初始化表格列
- InitializeDataGridViewColumns();
- }
- catch (Exception ex)
- {
- MessageBox.Show($"初始化界面失败: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void InitializeDataGridViewColumns()
- {
- dgvLogs.Columns.Clear();
-
- // 添加列定义
- var columns = new[]
- {
- new { HeaderText = "日期", DataPropertyName = "InfDate", Width = 150 },
- new { HeaderText = "时间", DataPropertyName = "InfTime", Width = 150 },
- new { HeaderText = "科室", DataPropertyName = "DeptName", Width = 120 },
- new { HeaderText = "操作员", DataPropertyName = "OpterName", Width = 100 },
- new { HeaderText = "病人姓名", DataPropertyName = "PatnName", Width = 100 },
- new { HeaderText = "项目名称", DataPropertyName = "ItemName", Width = 150 },
- new { HeaderText = "违规分类", DataPropertyName = "VolaBhvrType", Width = 100 },
- new { HeaderText = "限制类型", DataPropertyName = "WarnType", Width = 100 },
- new { HeaderText = "后续操作", DataPropertyName = "DspoWay", Width = 100 },
- new { HeaderText = "数量", DataPropertyName = "Quantity", Width = 80 },
- new { HeaderText = "金额", DataPropertyName = "Amount", Width = 100 },
- new { HeaderText = "交易代码", DataPropertyName = "TradeCode", Width = 80 },
- new { HeaderText = "触发场景", DataPropertyName = "TriggerScene", Width = 80 },
- new { HeaderText = "违规规则", DataPropertyName = "RuleName", Width = 150 },
- new { HeaderText = "违规金额", DataPropertyName = "VolaAmt", Width = 100 }
- };
-
- foreach (var col in columns)
- {
- DataGridViewColumn newColumn = new DataGridViewTextBoxColumn();
- newColumn.HeaderText = col.HeaderText;
- newColumn.DataPropertyName = col.DataPropertyName;
- newColumn.Width = col.Width;
- dgvLogs.Columns.Add(newColumn);
- }
-
- dgvLogs.AutoGenerateColumns = false;
- }
- private void btnQuery_Click(object sender, EventArgs e)
- {
- try
- {
- Cursor = Cursors.WaitCursor;
- btnQuery.Enabled = false;
-
- // 获取查询条件
- string startDate = dtpStartDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string endDate = dtpEndDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
- string operatorName = txtOperatorName.Text.Trim();
- string patientName = txtPatientName.Text.Trim();
- string itemName = txtItemName.Text.Trim();
-
- // 调用查询服务
- string errMsg;
- DataTable dt = logService.QueryLogs(startDate, endDate, operatorName, patientName, itemName, out errMsg);
-
- if (dt == null)
- {
- if (!string.IsNullOrEmpty(errMsg))
- {
- MessageBox.Show($"查询失败: {errMsg}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else
- {
- MessageBox.Show("查询失败,请稍后重试", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- dgvLogs.DataSource = null;
- lblRecordCount.Text = "查询结果:0 条记录";
- return;
- }
-
- // 显示查询结果
- dgvLogs.DataSource = dt;
- lblRecordCount.Text = $"查询结果:{dt.Rows.Count} 条记录";
-
- // 计算合计金额
- CalculateTotals(dt);
- }
- catch (Exception ex)
- {
- MessageBox.Show($"查询异常: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally
- {
- Cursor = Cursors.Default;
- btnQuery.Enabled = true;
- }
- }
- private void CalculateTotals(DataTable dt)
- {
- try
- {
- decimal totalAmount = 0;
- decimal totalViolationAmount = 0;
- int totalRecords = dt.Rows.Count;
-
- foreach (DataRow row in dt.Rows)
- {
- // 计算总金额
- if (row["Amount"] != DBNull.Value && decimal.TryParse(row["Amount"].ToString(), out decimal amount))
- {
- totalAmount += amount;
- }
-
- // 计算违规金额
- if (row["ViolationAmount"] != DBNull.Value && decimal.TryParse(row["ViolationAmount"].ToString(), out decimal violationAmount))
- {
- totalViolationAmount += violationAmount;
- }
- }
-
- lblTotalAmount.Text = $"总金额:{totalAmount:F2} 元";
- lblTotalViolationAmount.Text = $"违规金额:{totalViolationAmount:F2} 元";
- lblRecordCount.Text = $"查询结果:{totalRecords} 条记录";
- }
- catch (Exception ex)
- {
- Global.writeLog($"计算合计金额异常: {ex.Message}");
- }
- }
- private void btnExport_Click(object sender, EventArgs e)
- {
- try
- {
- if (dgvLogs.DataSource == null)
- {
- MessageBox.Show("请先查询数据再进行导出", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
-
- DataTable dt = (DataTable)dgvLogs.DataSource;
- if (dt.Rows.Count == 0)
- {
- MessageBox.Show("没有数据可以导出", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
-
- // 弹出保存文件对话框
- SaveFileDialog saveFileDialog = new SaveFileDialog();
- saveFileDialog.Filter = "Excel文件 (*.xlsx)|*.xlsx|Excel文件 (*.xls)|*.xls|所有文件 (*.*)|*.*";
- saveFileDialog.FilterIndex = 1;
- saveFileDialog.RestoreDirectory = true;
- saveFileDialog.FileName = $"事前事中分析日志_{DateTime.Now:yyyyMMddHHmmss}";
-
- if (saveFileDialog.ShowDialog() == DialogResult.OK)
- {
- Cursor = Cursors.WaitCursor;
- btnExport.Enabled = false;
-
- try
- {
- //// 导出到Excel
- //string fileName = ExportToExcel.DataTabletoExcel(dt, saveFileDialog.FileName);
-
- //if (!string.IsNullOrEmpty(fileName))
- //{
- // MessageBox.Show($"数据已成功导出到:{fileName}", "导出成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
-
- // // 更新导出状态
- // UpdateExportStatus(dt);
- //}
- //else
- //{
- // MessageBox.Show("导出失败,请稍后重试", "导出失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
- //}
- // 导出到Excel
- ExportToExcel.ExportDataGridViewToExcel(dgvLogs, saveFileDialog.FileName);
- MessageBox.Show($"数据已成功导出到:{saveFileDialog.FileName}", "导出成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- catch (Exception ex)
- {
- MessageBox.Show($"导出异常: {ex.Message}", "导出失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally
- {
- Cursor = Cursors.Default;
- btnExport.Enabled = true;
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show($"导出异常: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void UpdateExportStatus(DataTable dt)
- {
- try
- {
- // 这里可以实现更新数据库中的导出状态
- // 例如:标记已导出的记录
- Global.writeLog($"已导出 {dt.Rows.Count} 条日志记录");
-
- // 在实际项目中,这里应该调用服务更新数据库中的导出状态
- // logService.UpdateExportStatus(logIds, DateTime.Now, Global.user.Name);
- }
- catch (Exception ex)
- {
- Global.writeLog($"更新导出状态异常: {ex.Message}");
- }
- }
- private void btnClear_Click(object sender, EventArgs e)
- {
- // 清空查询条件
- txtOperatorName.Text = "";
- txtPatientName.Text = "";
- txtItemName.Text = "";
- }
- private void dgvLogs_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
- {
- // 可以在这里实现查看详细信息的逻辑
- // 例如:点击某行时显示详细信息
- var selectedRow = dgvLogs.Rows[e.RowIndex];
- string logId = selectedRow.Cells["ID"]?.Value?.ToString();
-
- if (!string.IsNullOrEmpty(logId))
- {
- // 可以在这里显示详细信息对话框
- // ShowLogDetailDialog(logId);
- }
- }
- }
- catch (Exception ex)
- {
- Global.writeLog($"点击表格单元格异常: {ex.Message}");
- }
- }
- private void btnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- }
- }
|