AIMS/AIMSControls/OperationAfter/frmOperationCharg.cs
2023-08-16 22:32:16 +08:00

403 lines
15 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AIMSBLL;
using AIMSExtension;
using AIMSModel;
using DrawGraph;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AIMS.OperationAfter.UI
{
public partial class frmOperationCharg : Form
{
public string FeeType = "麻醉";
public frmOperationCharg()
{
InitializeComponent();
}
private void frmOperationChargCheck2_Load(object sender, EventArgs e)
{
try
{
dgvYP.AutoGenerateColumns = false;
//DataGridViewSettingManager.GetInstance().AttachDataGridView(dgvtEMPOperationInfos);
//if (PublicMethod.Operator.RoleRef.Name != "系统管理员")
//{
// tsbSettingDGV.Visible = false;
// label2.Visible = false;
//}
this.txtPatName.TextChanged += new System.EventHandler(this.txtPatName_TextChanged);
this.txtPatName.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.dgvTextYP_PreviewKeyDownEvent);
this.txtPatCaseNO.TextChanged += new System.EventHandler(this.txtPatCaseNO_TextChanged);
this.txtPatCaseNO.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.dgvTextYP_PreviewKeyDownEvent);
//rdoZQ.Checked = true;
Role role = BRole.SelectSingle(PublicMethod.RoleId);
if (role.RoleName.Contains("麻") || role.Id == 1)
{
radioButton1.Checked = true;
}
else
{
radioButton1.Checked = false;
}
}
catch (Exception exp)
{
PublicMethod.WriteLog(exp);
}
}
private void btnOK_Click(object sender, EventArgs e)
{
if (txtPatCaseNO.Text != "" || txtPatName.Text != "")
{
DataTable dt = BOperationRecord.GetOpeIdByNoName(txtPatCaseNO.Text.Trim(), txtPatName.Text.Trim());
if (dt != null && dt.Rows.Count > 0)
{
int OpeID = int.Parse(dt.Rows[0]["id"].ToString());
dgvYP.Visible = false;
dgvtEMPOperationInfos.Rows.Clear();
lblName.Text = "";
lblInHospitalNo.Text = "";
label1.Text = "";
label4.Text = "";
lblName.Text = dt.Rows[0]["PatientName"].ToString();
lblInHospitalNo.Text = dt.Rows[0]["MdrecNo"].ToString();
if (dt.Rows[0]["OperationBeginTime"].ToString() != "")
{
label1.Text = dt.Rows[0]["OperationBeginTime"].ToString();
}
SetChargDetalie(OpeID.ToString());
SetChargDrugLbl();
}
}
}
private void LoadSelectDate(DataGridViewRow dr)
{
int OpeID = int.Parse(dr.Cells["id"].EditedFormattedValue.ToString());
dgvYP.Visible = false;
dgvtEMPOperationInfos.Rows.Clear();
lblName.Text = "";
lblInHospitalNo.Text = "";
label1.Text = "";
label4.Text = "";
lblName.Text = dr.Cells["DrugName"].EditedFormattedValue.ToString();
lblInHospitalNo.Text = dr.Cells["TypeName"].EditedFormattedValue.ToString();
label1.Text = dr.Cells["InRoomTime"].EditedFormattedValue.ToString();
SetChargDetalie(OpeID.ToString());
//if (FeeType == "麻醉")
//{
// OperationRecord _pauoperationRecord = BOperationRecord.SelectSingle(" ParentId=" + OpeID, null, RecursiveType.None, 0);
// if (_pauoperationRecord != null)
// {
// SetChargDetalie(_pauoperationRecord);
// }
//}
SetChargDrugLbl();
}
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)
{
//DataGridViewSettingManager.GetInstance().ShowConfigUI(dgvtEMPOperationInfos);
//dgvtEMPOperationInfos.AllowUserToAddRows = false;
}
private void button1_Click(object sender, EventArgs e)
{
if (dgvtEMPOperationInfos.Rows.Count < 0 || dgvtEMPOperationInfos.Rows.Count < 1)
{
MessageBox.Show("没有记录请查询到数据后再导出数据到Excel");
return;
}
//DataGridViewToExcel.DataToExcel(dgvtEMPOperationInfos);
}
private void SetChargDetalie(string _operationRecordId)
{
try
{
IList<FeesRecord> frees = BFeesRecord.Select("FeeType='" + FeeType + "' and OperationRecordId=" + _operationRecordId, null);
foreach (var item in frees)
{
int index = dgvtEMPOperationInfos.Rows.Add();
dgvtEMPOperationInfos.Rows[index].Cells["DId"].Value = item.Id;// 编号
dgvtEMPOperationInfos.Rows[index].Cells["code"].Value = item.BillCode;
dgvtEMPOperationInfos.Rows[index].Cells["type"].Value = item.FeeTypeId;
dgvtEMPOperationInfos.Rows[index].Cells["Doctor"].Value = item.BillingWork;
dgvtEMPOperationInfos.Rows[index].Cells["name"].Value = item.ChargName;
dgvtEMPOperationInfos.Rows[index].Cells["spec"].Value = item.ChargSpec;
dgvtEMPOperationInfos.Rows[index].Cells["unit"].Value = item.Unit;
dgvtEMPOperationInfos.Rows[index].Cells["qty"].Value = item.FeeNum;
dgvtEMPOperationInfos.Rows[index].Cells["price"].Value = item.UnitPrice;
dgvtEMPOperationInfos.Rows[index].Cells["pageno"].Value = item.ChargePrice;
dgvtEMPOperationInfos.Rows[index].Cells["ordersn"].Value = item.ExecWork;
dgvtEMPOperationInfos.Rows[index].Cells["coftime"].Value = item.ExecTime;
}
}
catch (Exception ex)
{
PublicMethod.WriteLog(ex);
}
}
private void SetChargDrugLbl()
{
int chargCount = 0;
double chargValue = 0;
foreach (DataGridViewRow item in dgvtEMPOperationInfos.Rows)
{
if (item.Cells["qty"].EditedFormattedValue.ToString() != "" && item.Cells["price"].EditedFormattedValue.ToString() != "" && item.Cells["name"].EditedFormattedValue.ToString() != "")
{
double res = 0;
if (double.TryParse(item.Cells["qty"].EditedFormattedValue.ToString(), out res))
{
double price = double.Parse(item.Cells["price"].Value.ToString());
chargCount++;
double rowprice = res * price;
chargValue += rowprice;
}
}
}
if (chargCount > 0)
{
label4.Text = string.Format(" {0}元 项目:{1}条", chargValue, chargCount);
}
else
{
label4.Text = "";
}
}
public int maxOrder = 0;
private void dgvtEMPOperationInfos_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
SolidBrush b = new SolidBrush(dgvtEMPOperationInfos.RowHeadersDefaultCellStyle.ForeColor);
e.Graphics.DrawString((maxOrder + e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), this.dgvtEMPOperationInfos.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
}
private void rdoZQ_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
FeeType = "麻醉";
}
else
{
FeeType = "护士";
}
}
private void txtPatCaseNO_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (dgvYP.Visible == false)
{
//btnOK_Click(null, null);
}
else
{
LoadSelectDate(dgvYP.Rows[0]);
txtPatCaseNO.Text = dgvYP.Rows[0].Cells[1].EditedFormattedValue.ToString();
dgvYP.Visible = false;
}
}
}
private void txtPatCaseNO_TextChanged(object sender, EventArgs e)
{
//显示并定位药品选择列表
if (dgvYP.Visible == false)
{
dgvYP.Visible = true;
}
//药品名称单元格为空时,隐藏选择药品列表,否则为选择药品列表加载数据
if (txtPatCaseNO.Text == "")
{
dgvYP.Visible = false;
}
else
{
string str = txtPatCaseNO.Text.Trim();
DataTable dt = BOperationRecord.GetOpesByNo(txtPatCaseNO.Text.Trim());
dgvYP.DataSource = dt;
}
}
private void txtPatName_TextChanged(object sender, EventArgs e)
{
//显示并定位药品选择列表
if (dgvYP.Visible == false)
{
dgvYP.Visible = true;
}
//药品名称单元格为空时,隐藏选择药品列表,否则为选择药品列表加载数据
if (txtPatName.Text == "")
{
dgvYP.Visible = false;
}
else
{
string str = txtPatName.Text.Trim();
DataTable dt = BOperationRecord.GetOpesByName(txtPatName.Text.Trim());
dgvYP.DataSource = dt;
}
}
/// <summary>
/// 药品名称单元格按键事件(判断输入上下箭头并处理)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void dgvTextYP_PreviewKeyDownEvent(object sender, PreviewKeyDownEventArgs e)
{
//药品名称单元格为空时,返回
//显示并定位选择药品列表
if (dgvYP.Visible == false)
{
dgvYP.Visible = true;
}
//判断按下上下键时,选择药品列表获得焦点并定位光标
if (e.KeyCode == Keys.Up)
{
dgvYP.Focus();
dgvYP.Rows[dgvYP.Rows.Count - 1].Selected = true;
dgvYP.CurrentCell = dgvYP.Rows[dgvYP.Rows.Count - 1].Cells[2];
}
if (e.KeyCode == Keys.Down)
{
if (dgvYP.Rows.Count > 0)
{
dgvYP.Focus();
dgvYP.Rows[1].Selected = true;
dgvYP.CurrentCell = dgvYP.Rows[1].Cells[2];
}
}
}
//定位当前行索引
int index = 0;
/// <summary>
/// 向药品表添加数据
/// </summary>
/// <param name="e"></param>
private void SetYPContent(DataGridViewCellEventArgs e)
{
if (e != null)
{
index = e.RowIndex;
}
if (dgvYP.Rows[index].Cells["DrugName"].EditedFormattedValue.ToString() != "")
{
this.txtPatName.TextChanged -= new System.EventHandler(this.txtPatName_TextChanged);
this.txtPatName.PreviewKeyDown -= new System.Windows.Forms.PreviewKeyDownEventHandler(this.dgvTextYP_PreviewKeyDownEvent);
this.txtPatCaseNO.TextChanged -= new System.EventHandler(this.txtPatCaseNO_TextChanged);
this.txtPatCaseNO.PreviewKeyDown -= new System.Windows.Forms.PreviewKeyDownEventHandler(this.dgvTextYP_PreviewKeyDownEvent);
LoadSelectDate(dgvYP.Rows[index]);
txtPatCaseNO.Text = dgvYP.Rows[index].Cells[1].EditedFormattedValue.ToString();
dgvYP.Visible = false;
this.txtPatName.TextChanged += new System.EventHandler(this.txtPatName_TextChanged);
this.txtPatName.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.dgvTextYP_PreviewKeyDownEvent);
this.txtPatCaseNO.TextChanged += new System.EventHandler(this.txtPatCaseNO_TextChanged);
this.txtPatCaseNO.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.dgvTextYP_PreviewKeyDownEvent);
}
}
/// <summary>
/// 鼠标点击选择药品列表时,向使用药品表添加数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgvYP_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
SetYPContent(e);
}
}
/// <summary>
/// 选择药品列表上点击上下键定位并移动光标
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgvYP_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Down)
{
if (dgvYP.CurrentRow.Index == dgvYP.Rows.Count - 1)
{
e.Handled = true;
dgvYP.CurrentCell = dgvYP.Rows[0].Cells[3];
dgvYP.Rows[0].Selected = true;
}
}
if (e.KeyCode == Keys.Up)
{
if (dgvYP.CurrentRow.Index == 0)
{
e.Handled = true;
dgvYP.CurrentCell = dgvYP.Rows[dgvYP.Rows.Count - 1].Cells[3];
dgvYP.Rows[dgvYP.Rows.Count - 1].Selected = true;
}
}
}
/// <summary>
/// 选择药品列表点击回车键向使用药品列表添加数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgvYP_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar.ToString() == "\r")
{
if (dgvYP.SelectedRows.Count > 0)
{
SetYPContent(null);
}
}
}
/// <summary>
/// 选择药品列表点击回车时先定位当前行的索引
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgvYP_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
index = dgvYP.CurrentRow.Index;
}
}
private void txtPatCaseNO_Click(object sender, EventArgs e)
{
txtPatCaseNO.Text = "";
txtPatName.Text = "";
}
}
}