381 lines
16 KiB
C#
381 lines
16 KiB
C#
using AIMS.OperationAanesthesia;
|
|
using AIMSBLL;
|
|
using AIMSDAL;
|
|
using AIMSExtension;
|
|
using AIMSModel;
|
|
using DCSoftDotfuscate;
|
|
using DevComponents.Editors;
|
|
using Microsoft.Office.Interop.Excel;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace AIMS.OperationAfter.UI
|
|
{
|
|
public partial class frmOperationCharg5 : Form
|
|
{
|
|
|
|
System.Data.DataTable operationApplys;
|
|
public string FeeType = "麻醉";
|
|
public List<FeesRecordReport> upHisDrugs;
|
|
public string DataGridViewPath = "";
|
|
public SysConfig exportConfig;
|
|
|
|
public frmOperationCharg5()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void frmOperationDruggCheck_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
dtpOpeTime.Value = DateTime.Now;
|
|
dtpEnd.Value = dtpOpeTime.Value;
|
|
DataGridViewPath = GetControlPath(dgvDrugs);
|
|
exportConfig = BSysConfig.SelectSingle(" Note='" + DataGridViewPath + "'", null, RecursiveType.None, 0);
|
|
|
|
if (exportConfig != null)
|
|
ConfigDataGridView(exportConfig);
|
|
|
|
if (upHisDrugs != null && upHisDrugs.Count > 0)
|
|
{
|
|
dtpOpeTime.Value = upHisDrugs[0].EndTime.Value;
|
|
}
|
|
}
|
|
catch (Exception exp)
|
|
{
|
|
PublicMethod.WriteLog(exp);
|
|
}
|
|
}
|
|
|
|
private void btnOK_Click(object sender, EventArgs e)
|
|
{
|
|
//if (comboBoxExType.Text == "") return;
|
|
//if (cnoDrugName.Text == "") return;
|
|
string beginTime = Convert.ToDateTime(dtpOpeTime.Value).ToString("yyyy-MM-dd 00:00:00");
|
|
string endTime = Convert.ToDateTime(dtpEnd.Value).ToString("yyyy-MM-dd 23:59:59");
|
|
string sql = string.Format(" ExecTime>='{0}' and ExecTime<'{1}'", beginTime, endTime);
|
|
if (comboBoxExType.SelectedItem != null)
|
|
{
|
|
ComboItem chargitem = comboBoxExType.SelectedItem as ComboItem;
|
|
sql += " and (FeeTypeId = '" + chargitem.Value + "' ) ";
|
|
}
|
|
if (cnoDrugName.SelectedItem != null)
|
|
{
|
|
ComboItem chargitem = cnoDrugName.SelectedItem as ComboItem;
|
|
sql += " and (ChargName = '" + chargitem.Value + "' ) ";
|
|
}
|
|
if (FeeType != "")
|
|
{
|
|
sql += " and (FeeType = '" + FeeType + "' ) ";
|
|
}
|
|
operationApplys = BFeesRecordReport.GetUpListByWhere3(sql);
|
|
dgvDrugs.DataSource = operationApplys;
|
|
if (exportConfig != null)
|
|
ConfigDataGridView(exportConfig);
|
|
}
|
|
|
|
private void toolStripButton10_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 表格配置
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void tsbSettingDGV_Click(object sender, EventArgs e)
|
|
{
|
|
}
|
|
private static string GetControlPath(Control control)
|
|
{
|
|
StringBuilder controlPathStringBuilder = new StringBuilder();
|
|
controlPathStringBuilder.Append(control.Name);
|
|
while (control.Parent != null)
|
|
{
|
|
control = control.Parent;
|
|
controlPathStringBuilder.Append("." + control.Name);
|
|
}
|
|
return controlPathStringBuilder.ToString();
|
|
}
|
|
public ExportConfig dataGridViewSetting;
|
|
private void ConfigDataGridView(SysConfig exportConfig)
|
|
{
|
|
try
|
|
{
|
|
dataGridViewSetting = JsonConvert.DeserializeObject<ExportConfig>(exportConfig.Value);
|
|
foreach (DataGridViewColumn column in dgvDrugs.Columns)
|
|
{
|
|
foreach (var item in dataGridViewSetting.Exports)
|
|
{
|
|
if (column.Name == "Id")
|
|
{
|
|
column.Visible = false;
|
|
}
|
|
else if (column.Name == item.Name)
|
|
{
|
|
column.Visible = item.IsVisible;
|
|
column.Width = item.Width;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
PublicMethod.WriteLog(ex);
|
|
}
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
KillAllExcel();
|
|
ExprotExcel2();
|
|
}
|
|
private Microsoft.Office.Interop.Excel.Application myExcel = null;
|
|
private void ExprotExcel2(bool isPrint = false)
|
|
{
|
|
//自定义表头
|
|
string title = "麻醉、精一药品注射剂使用、及残余液处理登记表";
|
|
|
|
//是否横向
|
|
bool xlLandscape = true;
|
|
if (dataGridViewSetting != null && dataGridViewSetting.Landscape == false) xlLandscape = false;
|
|
//主体字体大小
|
|
int BodySize = 9;
|
|
if (dataGridViewSetting != null && dataGridViewSetting.FontSize > 0) BodySize = dataGridViewSetting.FontSize;
|
|
|
|
myExcel = new Microsoft.Office.Interop.Excel.Application();
|
|
this.Cursor = Cursors.WaitCursor;
|
|
//保存文化环境
|
|
System.Globalization.CultureInfo CurrentCI = System.Threading.Thread.CurrentThread.CurrentCulture;
|
|
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
|
|
|
|
Workbook workbookData = myExcel.Workbooks.Add(Missing.Value);
|
|
Worksheet xlSheet = (Microsoft.Office.Interop.Excel.Worksheet)workbookData.Worksheets[1];
|
|
|
|
xlSheet.Name = title;
|
|
|
|
if (isPrint == false)
|
|
myExcel.Visible = true;
|
|
|
|
myExcel.Cells[1, 1] = title;//默认的就是在sheet1里面的。
|
|
string DrugName = "科室:麻醉科";
|
|
myExcel.Cells[2, 1] = DrugName;//默认的就是在sheet1里面的。
|
|
int startIndex = 3;
|
|
|
|
WorksheetClass wsClass = new WorksheetClass();
|
|
|
|
Dictionary<int, string> Columns = new Dictionary<int, string>();
|
|
//填充标题
|
|
for (int i = 0; i < dgvDrugs.Columns.Count; i++)
|
|
{
|
|
if (dataGridViewSetting != null)
|
|
{
|
|
foreach (var item in dataGridViewSetting.Exports)
|
|
{
|
|
if (dgvDrugs.Columns[i].Name == item.Name)
|
|
{
|
|
if (item.IsPrint == true)
|
|
{
|
|
Columns.Add(i, dgvDrugs.Columns[i].HeaderText);
|
|
continue;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (dgvDrugs.Columns[i].Visible == true)
|
|
Columns.Add(i, dgvDrugs.Columns[i].HeaderText);
|
|
}
|
|
}
|
|
|
|
List<KeyValuePair<int, string>> ColumnsStr = Columns.ToList();
|
|
|
|
for (int i = 0; i < ColumnsStr.Count; i++)
|
|
{
|
|
myExcel.Cells[startIndex, i + 1] = ColumnsStr[i].Value;
|
|
if (dataGridViewSetting != null)
|
|
{
|
|
foreach (var item in dataGridViewSetting.Exports)
|
|
{
|
|
if (ColumnsStr[i].Value == item.Text)
|
|
{
|
|
xlSheet.get_Range(xlSheet.Cells[startIndex, i + 1], xlSheet.Cells[startIndex, i + 1]).ColumnWidth = item.PrintWidth;//列宽
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
xlSheet.get_Range(xlSheet.Cells[startIndex, i + 1], xlSheet.Cells[startIndex, i + 1]).ColumnWidth = 5;//列宽
|
|
}
|
|
}
|
|
//获得数据表的值
|
|
int RowCount = dgvDrugs.Rows.Count;
|
|
int colCount = ColumnsStr.Count;
|
|
//设置填充单元格样式
|
|
xlSheet.get_Range(xlSheet.Cells[startIndex, 1], xlSheet.Cells[RowCount + startIndex, colCount]).Borders.LineStyle = XlLineStyle.xlContinuous;//边框的样式
|
|
object[,] objData = new object[RowCount, colCount];
|
|
|
|
//将DataTable里的值填充到对象数组中
|
|
for (int i = 0; i < RowCount; i++)
|
|
{
|
|
for (int j = 0; j < colCount; j++)
|
|
{
|
|
if (dgvDrugs.Columns[ColumnsStr[j].Key].Name == "序号" || dgvDrugs.Columns[ColumnsStr[j].Key].Name == "ApplyId")
|
|
objData[i, j] = i + 1;
|
|
else if (dgvDrugs.Rows[i].Cells[ColumnsStr[j].Key].Value != null)
|
|
objData[i, j] = dgvDrugs.Rows[i].Cells[ColumnsStr[j].Key].Value.ToString().Trim();
|
|
}
|
|
System.Windows.Forms.Application.DoEvents();
|
|
}
|
|
|
|
//将对象数组的值赋值给Excel
|
|
Range range = xlSheet.get_Range(xlSheet.Cells[4, 1], xlSheet.Cells[RowCount + startIndex, colCount]);
|
|
range.NumberFormat = "@";
|
|
range.Value2 = objData;
|
|
range.RowHeight = 19;
|
|
//xlSheet.get_Range(xlSheet.Cells[2, 1], xlSheet.Cells[RowCount + 2, colCount]).Font.Size = BodySize;//字体大小
|
|
|
|
//设置主标题单元格的样式
|
|
xlSheet.get_Range(xlSheet.Cells[1, 1], xlSheet.Cells[1, colCount]).MergeCells = true;//合并单元格
|
|
xlSheet.get_Range(xlSheet.Cells[1, 1], xlSheet.Cells[1, colCount]).HorizontalAlignment = XlHAlign.xlHAlignCenter;//水平对齐方式
|
|
xlSheet.get_Range(xlSheet.Cells[1, 1], xlSheet.Cells[1, colCount]).VerticalAlignment = XlVAlign.xlVAlignCenter;//垂直对齐方式
|
|
xlSheet.get_Range(xlSheet.Cells[1, 1], xlSheet.Cells[1, colCount]).Font.Bold = true;//字体加粗
|
|
xlSheet.get_Range(xlSheet.Cells[1, 1], xlSheet.Cells[1, colCount]).Font.ColorIndex = 0;//字体颜色
|
|
//xlSheet.get_Range(xlSheet.Cells[1, 1], xlSheet.Cells[1, colCount]).Font.Italic = true;//是否斜体
|
|
xlSheet.get_Range(xlSheet.Cells[1, 1], xlSheet.Cells[1, colCount]).Font.Size = 20;//字体大小
|
|
//xlSheet.get_Range(xlSheet.Cells[1, 1], xlSheet.Cells[2, colCount]).Borders.LineStyle = XlLineStyle.xlContinuous;//边框样式
|
|
xlSheet.get_Range(xlSheet.Cells[1, 1], xlSheet.Cells[1, colCount]).RowHeight = 33.75;//行高
|
|
|
|
xlSheet.get_Range(xlSheet.Cells[2, 1], xlSheet.Cells[2, colCount]).MergeCells = true;//合并单元格
|
|
|
|
//设置标题单元格样式
|
|
xlSheet.get_Range(xlSheet.Cells[2, 1], xlSheet.Cells[startIndex, colCount]).RowHeight = 21;//行高
|
|
|
|
if (xlLandscape == true)
|
|
xlSheet.PageSetup.Orientation = XlPageOrientation.xlLandscape;//页面方向为横向
|
|
//复苏文化环境
|
|
System.Threading.Thread.CurrentThread.CurrentCulture = CurrentCI;
|
|
try
|
|
{
|
|
if (isPrint == true)
|
|
xlSheet.PrintOutEx();
|
|
//myExcel.Save(@"D:a.xls");
|
|
//myExcel.Quit();
|
|
this.Cursor = Cursors.Default;
|
|
//MessageBox.Show("导出成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
|
|
}
|
|
finally
|
|
{
|
|
if (isPrint == true)
|
|
{
|
|
//释放资源
|
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);
|
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbookData);
|
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(range);
|
|
System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel);
|
|
GC.Collect();
|
|
range = null;
|
|
xlSheet = null;
|
|
workbookData = null;
|
|
myExcel = null;
|
|
KillAllExcel();
|
|
}
|
|
}
|
|
}
|
|
private void KillAllExcel()
|
|
{
|
|
List<Process> excelProcess = GetExcelProcesses();
|
|
for (int i = 0; i < excelProcess.Count; i++)
|
|
{
|
|
excelProcess[i].Kill();
|
|
}
|
|
}
|
|
private List<Process> GetExcelProcesses()
|
|
{
|
|
Process[] processes = Process.GetProcesses();
|
|
List<Process> excelProcesses = new List<Process>();
|
|
|
|
for (int i = 0; i < processes.Length; i++)
|
|
{
|
|
if (processes[i].ProcessName.ToUpper() == "EXCEL")
|
|
excelProcesses.Add(processes[i]);
|
|
}
|
|
|
|
return excelProcesses;
|
|
}
|
|
|
|
private void cboRoom_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
System.Data.DataTable table = BFeesRecordReport.GetDrugByType(comboBoxExType.Text);
|
|
cnoDrugName.Items.Clear();
|
|
for (int i = 0; i < table.Rows.Count; i++)
|
|
{
|
|
ComboItem item = new ComboItem();
|
|
item.Text = table.Rows[i][0].ToString();
|
|
item.Value = table.Rows[i][0].ToString();
|
|
cnoDrugName.Items.Add(item);
|
|
}
|
|
}
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (comboBoxExType.Text == "") return;
|
|
if (cnoDrugName.Text == "") return;
|
|
foreach (DataGridViewRow item in dgvDrugs.Rows)
|
|
{
|
|
string feerid = item.Cells[0].EditedFormattedValue.ToString();
|
|
FeesRecord report = BFeesRecord.SelectSingle(Convert.ToInt32(feerid));
|
|
report.InsureNO = item.Cells[6].EditedFormattedValue.ToString();
|
|
report.Extend5 = item.Cells[12].EditedFormattedValue.ToString();
|
|
report.Conclusion = item.Cells[10].EditedFormattedValue.ToString();
|
|
report.IsInsure = item.Cells[9].EditedFormattedValue.ToString();
|
|
//report.LimitDrug = item.Cells[2].EditedFormattedValue.ToString();
|
|
BFeesRecord.Update(report);
|
|
}
|
|
MessageBox.Show("保存成功!", "系统提示");
|
|
}
|
|
|
|
private void dgvDrugs_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
|
|
{
|
|
//隔行换色
|
|
this.dgvDrugs.RowsDefaultCellStyle.BackColor = Color.White;//设置背景为白色
|
|
this.dgvDrugs.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(212)))), ((int)(((byte)(222)))), (((int)(((byte)242)))));//青色
|
|
}
|
|
|
|
private void dgvDrugs_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
DialogResult dialog = MessageBox.Show("是否批量填写数据?", "系统提示", MessageBoxButtons.YesNo);
|
|
if (dialog == DialogResult.Yes)
|
|
{
|
|
string batchNo = dgvDrugs.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString();
|
|
for (int i = 0; i < dgvDrugs.Rows.Count; i++)
|
|
{
|
|
dgvDrugs.Rows[i].Cells[e.ColumnIndex].Value = batchNo;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void toolStripButton2_Click(object sender, EventArgs e)
|
|
{
|
|
frmExportConfig formDataGridViewConfig = new frmExportConfig(dgvDrugs, exportConfig, DataGridViewPath, this.Text);
|
|
if (formDataGridViewConfig.ShowDialog() == DialogResult.OK)
|
|
{
|
|
exportConfig = formDataGridViewConfig.exportConfig;
|
|
ConfigDataGridView(formDataGridViewConfig.exportConfig);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|