using AIMSBLL;
using AIMSExtension;
using AIMSModel;
using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Controls;
using DrawGraph;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace AIMS.PublicUI.UI
{
public partial class frmFactSpeedyDrug : OfficeForm
{
public static object valueTime;
public int currentTabIndex = 1;
public bool isCVhageAllSapDose = false;
public int DrugTypeId;
public DateTime ClickTime;
#region 公共成员
int x = 0;
///
/// 修改加药委托
///
public delegate void DrugsParamHandler();
///
/// 修改加药事件
///
public event DrugsParamHandler DrugsParam;
///
/// 手术记录
///
public DrawGraph.OperationRecord _record;
///
/// 选中记录
///
public List factDrugs;
///
/// 图表控件
///
public ZedGraphControl zgcAnaesRecord;
///
/// 选择项编号
///
public int _itemId;
public DataGridView _dataGridView;
private int _lineNumber;
#endregion
public frmFactSpeedyDrug()
{
InitializeComponent();
if (PublicMethod.HospitalName.Contains("漳浦天福"))
{
this.dataGridViewTextBoxColumn8.HeaderText = "位置";
this.dataGridViewTextBoxColumn8.Items.AddRange(new object[] {
"",
"上",
"下"});
}
else
{
this.dataGridViewTextBoxColumn8.HeaderText = "通路";
this.dataGridViewTextBoxColumn8.Items.AddRange(new object[] {
"",
"1",
"2",
"3",
"4"});
}
}
private void frmFactDrugNew2_Load(object sender, EventArgs e)
{
try
{
if (factDrugs == null) factDrugs = new List();
SetDGVNotSort();
Initial();
FullALLDGV();
tabDrugs.SelectedTabIndex = currentTabIndex;
_dataGridView = dgvDrugsSZ;
dgvYP.Visible = false;
dgvYP.AutoGenerateColumns = false;
}
catch (Exception ex)
{
PublicMethod.WriteLog(ex);
}
}
private void SetDGVNotSort()
{
for (int i = 0; i < dgvDrugsSZ.Columns.Count; i++)
{
dgvDrugsSZ.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}
}
private void SetDGVEvent(DataGridView dgv)
{
dgv.CellClick -= new DataGridViewCellEventHandler(dgvDrugs_CellClick);
dgv.CellContentClick -= new DataGridViewCellEventHandler(dgvDrugs_CellContentClick);
dgv.CellValueChanged -= new DataGridViewCellEventHandler(dgvDrugs_CellValueChanged);
dgv.CurrentCellDirtyStateChanged -= new EventHandler(dgvDrugs_CurrentCellDirtyStateChanged);
dgv.EditingControlShowing -= new DataGridViewEditingControlShowingEventHandler(dgvDrugs_EditingControlShowing);
dgv.CellEndEdit -= Dgv_CellEndEdit;
dgv.RowsAdded -= new DataGridViewRowsAddedEventHandler(dgvDrugs_RowsAdded);
dgv.CellClick += new DataGridViewCellEventHandler(dgvDrugs_CellClick);
dgv.CellContentClick += new DataGridViewCellEventHandler(dgvDrugs_CellContentClick);
dgv.CellValueChanged += new DataGridViewCellEventHandler(dgvDrugs_CellValueChanged);
dgv.CurrentCellDirtyStateChanged += new EventHandler(dgvDrugs_CurrentCellDirtyStateChanged);
dgv.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dgvDrugs_EditingControlShowing);
dgv.CellEndEdit += Dgv_CellEndEdit;
dgv.RowsAdded += new DataGridViewRowsAddedEventHandler(dgvDrugs_RowsAdded);
dgv.CellLeave -= new DataGridViewCellEventHandler(dgvDrugs_CellLeave);
dgv.CellLeave += new DataGridViewCellEventHandler(dgvDrugs_CellLeave);
dgv.KeyDown -= new System.Windows.Forms.KeyEventHandler(dgvDrugs_KeyDown);
dgv.KeyDown += new System.Windows.Forms.KeyEventHandler(dgvDrugs_KeyDown);
}
private void Dgv_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 6)
{
_dataGridView.CurrentCell.Tag = _dataGridView.CurrentCell.EditedFormattedValue.ToString();
}
}
private void Initial()
{
if (ControlExtension._channelList == null)
{
ControlExtension._channelList = BBasicDictionary.GetBasicDictionaryByName("用药途径", "asc").SubItem;
ControlExtension._channelList.Insert(0, new BasicDictionary() { Id = -1, Name = "" });
ControlExtension._drugEffectList = BBasicDictionary.GetBasicDictionaryByName("加药方式").SubItem;
ControlExtension._drugEffectList.Insert(0, new BasicDictionary() { Id = -1, Name = "" });
ControlExtension._dUnitList = BBasicDictionary.GetBasicDictionaryByName("给药单位").SubItem;
ControlExtension._dUnitList.Insert(0, new BasicDictionary() { Id = -1, Name = "" });
ControlExtension._bloodTypeList = BBasicDictionary.GetBasicDictionaryByName("血型").SubItem;
ControlExtension._bloodTypeList.Insert(0, new BasicDictionary() { Id = -1, Name = "" });
ControlExtension._VelocityUnit = BBasicDictionary.GetBasicDictionaryByName("速度单位").SubItem;
ControlExtension._VelocityUnit.Insert(0, new BasicDictionary() { Id = -1, Name = "" });
ControlExtension._DensityUnit = BBasicDictionary.GetBasicDictionaryByName("浓度单位").SubItem;
ControlExtension._DensityUnit.Insert(0, new BasicDictionary() { Id = -1, Name = "" });
}
}
///
/// 向DataGridView填充入量数据
///
private void FullDrugsData(List list)
{
if (list != null)
{
//添加入量
if (list.Count > 0)
{
_dataGridView.Rows.Clear();
foreach (FactDrug item in list)
{
if (item.ParentId > 0) continue;
SetDGV(item);
foreach (FactDrug sItem in list)
{
if (sItem.ParentId == item.Id)
{
SetDGV(sItem);
}
}
}
}
else
{
_dataGridView.Rows.Clear();
}
}
}
public int zhuid = 0;
private void SetDGV(FactDrug item)
{
int index = _dataGridView.Rows.Add();
_dataGridView.Rows[index].Tag = item.Id;
if (item.ParentId == 0)
{
_dataGridView.Rows[index].Cells[1].Value = "主";
_dataGridView.Rows[index].Cells[0].Value = imageList1.Images[0];
zhuid = _dataGridView.Rows[index].Index;
}
else
{
_dataGridView.Rows[index].Cells[1].Value = " ...";
if (zhuid != 0) _dataGridView.Rows[index].Cells[1].Tag = zhuid;
_dataGridView.Rows[index].Cells[0].Value = imageList1.Images[1];
}
_dataGridView.Rows[index].Cells[2].Tag = item.DrugId;//药品编号
_dataGridView.Rows[index].Cells[2].Value = BDrugs.SelectSingle(item.DrugId).DrugKind;//药品编号
_dataGridView.Rows[index].Cells[3].Value = item.DrugName;//药品名称
_dataGridView.Rows[index].Cells[3].Tag = item.DrugId;//药品名称编号
_dataGridView.Rows[index].Cells[5].Value = item.DrugChannel;//途径
_dataGridView.Rows[index].Cells[4].Value = item.Remark;//备注
if (item.Dosage != 0)
_dataGridView.Rows[index].Cells[10].Value = (double)item.Dosage;//剂量
_dataGridView.Rows[index].Cells[11].Value = item.DosageUnit;//剂量单位
if (item.BloodType != null && item.BloodType != "")
_dataGridView.Rows[index].Cells[12].Value = item.BloodType;//血型
if (item.Density != 0)
_dataGridView.Rows[index].Cells[6].Value = (double)item.Density;//浓度
if (item.DensityUnit != null && item.DensityUnit != "")
_dataGridView.Rows[index].Cells[7].Value = item.DensityUnit;//浓度单位
if (item.Velocity != "")
_dataGridView.Rows[index].Cells[8].Value = item.Velocity;//速度
if (item.VelocityUnit != null && item.VelocityUnit != "")
_dataGridView.Rows[index].Cells[9].Value = item.VelocityUnit;//速度单位
if (Convert.ToDateTime(item.DrugBeginTime).ToString().Length > 0)
{
_dataGridView.Rows[index].Cells[14].Value = Convert.ToDateTime(item.DrugBeginTime);//开始时间
}
if (item.IsContinue > 0)
{
_dataGridView.Rows[index].Cells[15].Value = "-->";//持续
}
if (item.DrugEndTime.ToString("yyyy-MM-dd HH:mm") != item.DrugBeginTime.ToString("yyyy-MM-dd HH:mm"))
{
_dataGridView.Rows[index].Cells[16].Value = Convert.ToDateTime(item.DrugEndTime);//结束时间
}
_dataGridView.Rows[index].Cells[17].Value = item.Access;
}
private void dgvDrugs_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
//if (e.ColumnIndex == 0)
//{
// DataGridViewImageColumn dc = new DataGridViewImageColumn(true);
// dc.Image = imageList1.Images[0];
// e.Value = dc.Image;
//}
}
private void dgvDrugs_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
try
{
if (e.RowIndex >= 0)
{
int parentId = Convert.ToInt32(_dataGridView.CurrentRow.Tag);
if (_dataGridView.Rows[e.RowIndex].Cells[1].Value != null)
{
if (e.ColumnIndex == 0 && _dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString() == "主")
{
DataGridViewRow dr = new DataGridViewRow();
dr.CreateCells(_dataGridView);
dr.Cells[1].Value = " ...";
//dr.Cells[1].Tag = parentId;
dr.Cells[1].Tag = _dataGridView.CurrentRow.Index;
dr.Cells[0].Value = imageList1.Images[1];
_lineNumber = e.RowIndex + 1;
while (_dataGridView.Rows[_lineNumber].Cells[1].Value.ToString() == " ...")
{
_lineNumber++;
}
_dataGridView.Rows.Insert(_lineNumber, dr);
}
if (e.ColumnIndex == 1)
{
DataGridViewRow dr = new DataGridViewRow();
dr.CreateCells(_dataGridView);
dr.Cells[1].Value = _dataGridView.Rows[e.RowIndex].Cells[1].Value;
if (dr.Cells[1].Value.ToString().Trim() != "...")
{
dr.Cells[0].Value = imageList1.Images[0];
_lineNumber = _dataGridView.Rows.Count - 1;//追加药添加到最后一行
}
else
{
dr.Cells[0].Value = imageList1.Images[1];
_lineNumber = e.RowIndex + 1;
}
dr.Cells[4].Value = _dataGridView.Rows[e.RowIndex].Cells[4].Value;
dr.Cells[1].Tag = _dataGridView.Rows[e.RowIndex].Cells[1].Tag;
dr.Cells[2].Value = _dataGridView.Rows[e.RowIndex].Cells[2].Value;
dr.Cells[2].Tag = _dataGridView.Rows[e.RowIndex].Cells[2].Tag;
dr.Cells[3].Value = _dataGridView.Rows[e.RowIndex].Cells[3].Value;//药品名称
dr.Cells[3].Tag = _dataGridView.Rows[e.RowIndex].Cells[3].Tag;//药品名称
dr.Cells[5].Value = _dataGridView.Rows[e.RowIndex].Cells[5].Value;//途径
dr.Cells[11].Value = _dataGridView.Rows[e.RowIndex].Cells[11].Value;//剂量单位
dr.Cells[6].Value = _dataGridView.Rows[e.RowIndex].Cells[6].Value;//浓度
dr.Cells[6].Tag = _dataGridView.Rows[e.RowIndex].Cells[6].Value;//浓度
dr.Cells[7].Value = _dataGridView.Rows[e.RowIndex].Cells[7].Value;//浓度单位
dr.Cells[8].Value = _dataGridView.Rows[e.RowIndex].Cells[8].Value;//速度
dr.Cells[9].Value = _dataGridView.Rows[e.RowIndex].Cells[9].Value;//速度单位
dr.Cells[10].Value = _dataGridView.Rows[e.RowIndex].Cells[10].Value;//剂量
DateTime starttime = DateTime.Now;
try
{
if (_dataGridView.Rows[e.RowIndex].Cells[16].Value != null && _dataGridView.Rows[e.RowIndex].Cells[16].Value.ToString() != "")
{
DateTime time = DateTime.Parse(_dataGridView.Rows[e.RowIndex].Cells[16].Value.ToString());
starttime = time;
dr.Cells[15].Value = "-->";
}
else if (_dataGridView.Rows[e.RowIndex].Cells[14].Value != null && _dataGridView.Rows[e.RowIndex].Cells[14].Value.ToString() != "")
{
DateTime time = DateTime.Parse(_dataGridView.Rows[e.RowIndex].Cells[14].Value.ToString());
starttime = time;
}
}
catch (Exception)
{
starttime = DateTime.Now;
}
dr.Cells[14].Value = starttime;//开始时间
_dataGridView.Rows.Insert(_lineNumber, dr);
if (_dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString() != " ..." && _dataGridView.Rows[e.RowIndex + 1].Cells[1].Value.ToString() == " ...")
{
DataGridViewRow drc = new DataGridViewRow();
drc.CreateCells(_dataGridView);
drc.Cells[1].Value = _dataGridView.Rows[e.RowIndex + 1].Cells[1].Value;
drc.Cells[0].Value = imageList1.Images[1];
_lineNumber = _dataGridView.Rows.Count - 1;//追加药添加到最后一行
drc.Cells[4].Value = _dataGridView.Rows[e.RowIndex + 1].Cells[4].Value;
drc.Cells[1].Tag = dr.Index;
drc.Cells[2].Value = _dataGridView.Rows[e.RowIndex + 1].Cells[2].Value;
drc.Cells[2].Tag = _dataGridView.Rows[e.RowIndex + 1].Cells[2].Tag;
drc.Cells[3].Value = _dataGridView.Rows[e.RowIndex + 1].Cells[3].Value;//药品名称
drc.Cells[3].Tag = _dataGridView.Rows[e.RowIndex + 1].Cells[3].Tag;//药品名称
drc.Cells[5].Value = _dataGridView.Rows[e.RowIndex + 1].Cells[5].Value;//途径
drc.Cells[11].Value = _dataGridView.Rows[e.RowIndex + 1].Cells[11].Value;//剂量单位
drc.Cells[6].Value = _dataGridView.Rows[e.RowIndex + 1].Cells[6].Value;//浓度
drc.Cells[6].Tag = _dataGridView.Rows[e.RowIndex + 1].Cells[6].Tag;//浓度
drc.Cells[7].Value = _dataGridView.Rows[e.RowIndex + 1].Cells[7].Value;//浓度单位
drc.Cells[8].Value = _dataGridView.Rows[e.RowIndex + 1].Cells[8].Value;//速度
drc.Cells[9].Value = _dataGridView.Rows[e.RowIndex + 1].Cells[9].Value;//速度单位
drc.Cells[10].Value = _dataGridView.Rows[e.RowIndex + 1].Cells[10].Value;//剂量
drc.Cells[14].Value = starttime;//开始时间
drc.Cells[15].Value = dr.Cells[15].Value;
_dataGridView.Rows.Insert(_lineNumber, drc);
}
}
}
}
}
catch (Exception exp)
{
PublicMethod.WriteLog(exp);
}
}
private void dgvDrugs_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
DataGridViewComboBoxCell channelCell;
DataGridViewComboBoxCell dUnitCell;
DataGridViewComboBoxCell drugEffectCell;
DataGridViewComboBoxCell BloodTypeCell;
DataGridViewComboBoxCell DensityUnit;
DataGridViewComboBoxCell VelocityUnit;
if (e == null)
{
channelCell = _dataGridView.Rows[0].Cells[5] as DataGridViewComboBoxCell;//途径
DensityUnit = _dataGridView.Rows[0].Cells[7] as DataGridViewComboBoxCell;//浓度单位
dUnitCell = _dataGridView.Rows[0].Cells[11] as DataGridViewComboBoxCell;//剂量单位
drugEffectCell = _dataGridView.Rows[0].Cells[13] as DataGridViewComboBoxCell;//速度
BloodTypeCell = _dataGridView.Rows[0].Cells[12] as DataGridViewComboBoxCell;//血型
VelocityUnit = _dataGridView.Rows[0].Cells[9] as DataGridViewComboBoxCell;//速度单位
_dataGridView.Rows[0].Cells[0].Value = imageList1.Images[0];
}
else
{
channelCell = _dataGridView.Rows[e.RowIndex].Cells[5] as DataGridViewComboBoxCell;//途径
DensityUnit = _dataGridView.Rows[e.RowIndex].Cells[7] as DataGridViewComboBoxCell;//浓度单位
dUnitCell = _dataGridView.Rows[e.RowIndex].Cells[11] as DataGridViewComboBoxCell;//剂量单位
drugEffectCell = _dataGridView.Rows[e.RowIndex].Cells[13] as DataGridViewComboBoxCell;//速度
BloodTypeCell = _dataGridView.Rows[e.RowIndex].Cells[12] as DataGridViewComboBoxCell;//血型
VelocityUnit = _dataGridView.Rows[e.RowIndex].Cells[9] as DataGridViewComboBoxCell;//速度单位
_dataGridView.Rows[e.RowIndex].Cells[0].Value = imageList1.Images[0];
}
channelCell.DataSource = ControlExtension._channelList;
channelCell.DisplayMember = "Name";
channelCell.ValueMember = "Name";
dUnitCell.DataSource = ControlExtension._dUnitList;
dUnitCell.DisplayMember = "Name";
dUnitCell.ValueMember = "Name";
drugEffectCell.DataSource = ControlExtension._drugEffectList;
drugEffectCell.DisplayMember = "Name";
drugEffectCell.ValueMember = "Id";
DensityUnit.DataSource = ControlExtension._DensityUnit;
DensityUnit.DisplayMember = "Name";
DensityUnit.ValueMember = "Id";
BloodTypeCell.DataSource = ControlExtension._bloodTypeList;
BloodTypeCell.DisplayMember = "Name";
BloodTypeCell.ValueMember = "Id";
VelocityUnit.DataSource = ControlExtension._VelocityUnit;
VelocityUnit.DisplayMember = "Name";
VelocityUnit.ValueMember = "Id";
_dataGridView.Rows[e.RowIndex].Cells[14].Value = ClickTime.ToString("yyyy-MM-dd HH:mm");
}
private void dgvDrugs_CellClick(object sender, DataGridViewCellEventArgs e)
{
//点击开始时间时显示时间
if (_dataGridView.CurrentCell != null)
{
_dataGridView.BeginEdit(true);
//点击Sign列时显示持续事件标记
if (_dataGridView.CurrentCell.ColumnIndex == 15)
{
if (_dataGridView.CurrentCell.EditedFormattedValue.ToString() == "" && _dataGridView.CurrentRow.Cells[14].EditedFormattedValue.ToString() != "")
{
_dataGridView.CurrentCell.Value = "-->";
//SendKeys.Send("{Tab}");
btnSave.Focus();
}
else
{
_dataGridView.CurrentCell.Value = "";
_dataGridView.CurrentRow.Cells[16].Value = null;//结束时间
btnSave.Focus();
}
}
//点击结束时间时判断是否持续事件,并显示时间
else if (_dataGridView.CurrentCell.ColumnIndex == 16)
{
if (_dataGridView.CurrentRow.Cells[15].EditedFormattedValue.ToString() != "" && _dataGridView.CurrentCell.EditedFormattedValue.ToString() == "")//持续
{
_dataGridView.CurrentCell.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm");//默认当前时间‘
TimeSpan tsp = DateTime.Now - _record.InRoomTime.Value;
if (tsp.TotalHours > 12)
{
DateTime begindate = new DateTime(_record.InRoomTime.Value.Year, _record.InRoomTime.Value.Month, _record.InRoomTime.Value.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
if (begindate > _record.InRoomTime.Value)
{
begindate = DateTime.Now;
}
_dataGridView.CurrentCell.Value = begindate;
}
btnSave.Focus();
}
}
else if (_dataGridView.CurrentCell.ColumnIndex == 18)
{
if (_dataGridView.CurrentRow.Cells[18].FormattedValue.ToString() == "")
{
_dataGridView.CurrentRow.Cells[18].Value = "下";
btnSave.Focus();
}
else
{
_dataGridView.CurrentRow.Cells[18].Value = "";
btnSave.Focus();
}
}
}
}
private bool ValidTimeTxt(string dgvTimeTxt, ref string message)
{
bool k = true;
if (dgvTimeTxt == "")
{
return k;
}
if (!dgvTimeTxt.Contains("-") || !dgvTimeTxt.Contains(":") || !dgvTimeTxt.Contains(" "))
{
return false;
}
if (dgvTimeTxt.IndexOf("-") < 1 || dgvTimeTxt.IndexOf(":") < 1 || dgvTimeTxt.IndexOf(" ") < 1)
{
return false;
}
try
{
string[] ym = dgvTimeTxt.Split(' ');
string[] sym = ym[0].Split('-');
string[] hm = ym[1].Split(':');
int month = Convert.ToInt16(sym[0]);
int day = Convert.ToInt16(sym[1]);
int hh = Convert.ToInt16(hm[0]);
int mm = Convert.ToInt16(hm[1]);
if (month > 12 || month < 0)
{
k = false;
message = "请填写正确的月份(1-12)";
}
if (day > 31 || day < 0)
{
k = false;
message = "请填写正确的日期(1-31)";
}
if (hh > 23 || hh < 0)
{
k = false;
message = "请填写正确的小时(0-23)";
}
if (mm > 59 || hh < 0)
{
k = false;
message = "请填写正确的小时(0-59)";
}
}
catch
{
k = false;
}
return k;
}
private void dgvDrugs_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (_dataGridView == null) return;
//判断如果事件名称列内容发生变化时(输入关键字),设置显示查询结果的控件的位置及内容
if (e.ColumnIndex == 8)
{
if (_dataGridView.CurrentCell == null || _dataGridView.CurrentRow.Cells[8].EditedFormattedValue.ToString() == "") return;
if (_dataGridView.CurrentRow.Cells[9].EditedFormattedValue.ToString() == "") _dataGridView.CurrentRow.Cells[9].Value = 85;
_dataGridView.CurrentRow.Cells[11].Value = null;
}
}
///
/// 当前单元格内容发生改变时,将改变提交
///
///
///
private void dgvDrugs_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (_dataGridView.IsCurrentCellDirty)
{
_dataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
try
{
if (_dataGridView.CurrentRow != null)
{
string objectName = _dataGridView.CurrentRow.Cells[3].EditedFormattedValue.ToString();
if (_dataGridView.CurrentRow.Tag != null)
{
int id = Convert.ToInt32(_dataGridView.CurrentRow.Tag);
///删除子药
List ers = _record.FactDrugList.Where(b => b.ParentId == id).ToList();
if (ers.Count > 0)
{
MessageBox.Show("请先删除子药 再进行删除!", "系统提示");
return;
}
FactDrug er = _record.FactDrugList.Where(b => b.Id == id).ToList()[0];
if (zgcAnaesRecord != null)
{
er.clearAddObj(zgcAnaesRecord);
er.clearIm(zgcAnaesRecord);
}
BFactDrug.Delete(er);
_record.FactDrugList.Remove(er);
_dataGridView.Rows.Remove(_dataGridView.CurrentRow);
_lineNumber = 0;
//FullALLDGV();
//tabDrugs_SelectedTabChanged(null, null);
if (DrugsParam != null) DrugsParam();
//if (_dataGridView.Rows.Count == 0 || _dataGridView.Rows[_dataGridView.Rows.Count - 1].Cells[3].Value != null)
//AddNewNullRows();
}
else
{
if (_dataGridView.CurrentRow.Cells[3].Value != null)//药品名称
{
_dataGridView.Rows.Remove(_dataGridView.CurrentRow);
_lineNumber = 0;
//if (_dataGridView.Rows.Count == 0 || _dataGridView.Rows[_dataGridView.Rows.Count - 1].Cells[3].Value != null)
// AddNewNullRows();
}
}
}
}
catch (Exception ex)
{
PublicMethod.WriteLog(ex);
}
}
private bool SaveValid(DataGridView _dataGridView, int index)
{
if (_dataGridView.Rows.Count < 1) return true;
foreach (DataGridViewRow dr in _dataGridView.Rows)
{
if (dr.Cells[3].EditedFormattedValue.ToString() != "")//药品名称
{
if (dr.Cells[2].EditedFormattedValue.ToString() == "")
{
MessageBox.Show("保存失败!\n\r" + "输入的入量:" + dr.Cells[3].EditedFormattedValue.ToString() + "错误,请按照正确方式选择入量!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);//药品名称
_dataGridView.CurrentCell = dr.Cells[3];//药品名称
_dataGridView.BeginEdit(true);
dr.Cells[3].Value = "";//药品名称
tabDrugs.SelectedTabIndex = index;
return false;
}
if (dr.Cells[5].EditedFormattedValue.ToString() == "")//途径
{
MessageBox.Show("保存失败!\n\r" + "请输入:" + dr.Cells[2].EditedFormattedValue.ToString() + ":" + dr.Cells[3].EditedFormattedValue.ToString() + "的途径!", "系统提示");//药品名称
_dataGridView.CurrentCell = dr.Cells[5];//途径
_dataGridView.BeginEdit(true);
tabDrugs.SelectedTabIndex = index;
return false;
}
if (dr.Cells[12].EditedFormattedValue.ToString() == "" && dr.Cells[2].EditedFormattedValue.ToString() == "血液制品")//血型
{
MessageBox.Show("保存失败!\n\r" + "请输入:" + dr.Cells[2].EditedFormattedValue.ToString() + ":" + dr.Cells[3].EditedFormattedValue.ToString() + "的血型!", "系统提示");//药品名称
_dataGridView.CurrentCell = dr.Cells[12];//血型
_dataGridView.BeginEdit(true);
tabDrugs.SelectedTabIndex = index;
return false;
}
if (dr.Cells[14].EditedFormattedValue.ToString() == "")//开始时间
{
MessageBox.Show("保存失败!\n\r" + "请输入:" + dr.Cells[2].EditedFormattedValue.ToString() + ":" + dr.Cells[3].EditedFormattedValue.ToString() + "的开始时间!", "系统提示");//药品名称
_dataGridView.CurrentCell = dr.Cells[14];//开始时间
_dataGridView.BeginEdit(true);
tabDrugs.SelectedTabIndex = index;
return false;
}
else
{
DateTime DrugBeginTime = Convert.ToDateTime(dr.Cells[14].Value.ToString());
if (DrugBeginTime > DateTime.Now.AddHours(5))
{
MessageBox.Show("保存失败!\n\r 用药开始时间不能大于当前时间5个小时 请检查!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);//药品名称
_dataGridView.CurrentCell = dr.Cells[14];//开始时间
_dataGridView.BeginEdit(true);
tabDrugs.SelectedTabIndex = index;
return false;
}
}
if (dr.Cells[14].EditedFormattedValue.ToString() != "" && dr.Cells[15].EditedFormattedValue.ToString() != "" && dr.Cells[16].EditedFormattedValue.ToString() != "")//开始时间
{
DateTime DrugBeginTime = Convert.ToDateTime(dr.Cells[14].Value.ToString());
DateTime endTime = Convert.ToDateTime(dr.Cells[16].Value.ToString());
if (endTime < DrugBeginTime)
{
MessageBox.Show("保存失败!\n\r" + dr.Cells[3].EditedFormattedValue.ToString() + ": 结束时间:" + dr.Cells[16].EditedFormattedValue.ToString() + " 小于开始时间:" + dr.Cells[14].EditedFormattedValue.ToString() + " 请检查!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);//药品名称
_dataGridView.CurrentCell = dr.Cells[16];//开始时间
_dataGridView.BeginEdit(true);
tabDrugs.SelectedTabIndex = index;
return false;
}
if (endTime > DateTime.Now.AddHours(5))
{
MessageBox.Show("保存失败!\n\r 用药结束时间不能大于当前时间5个小时 请检查!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);//药品名称
_dataGridView.CurrentCell = dr.Cells[16];//开始时间
_dataGridView.BeginEdit(true);
tabDrugs.SelectedTabIndex = index;
return false;
}
}
}
}
return true;
}
private void Save(DataGridView _dataGridView, int index)
{
try
{
if (_dataGridView.Rows.Count < 1) return;
string drugEffect = string.Empty;
switch (index)
{
case 0:
drugEffect = "麻醉前用药";
break;
case 1:
drugEffect = "术中加药";
break;
case 2:
drugEffect = "术后镇痛药";
break;
}
int second = 0;
foreach (DataGridViewRow dr in _dataGridView.Rows)
{
if (dr.Cells[3].Value == null || dr.Cells[3].Value.ToString() == "")//药品名称
continue;
//实例化FactDrug对象
FactDrug drugsR = new FactDrug();
drugsR.PatientId = _record.PatientId.Value;
drugsR.DrugId = Convert.ToInt32(dr.Cells[3].Tag);//药品名称
if (drugsR.DrugId == 0)//药品名称
continue;
if (dr.Cells[1].Value.ToString() == " ..." && dr.Cells[1].Tag != null)
{
drugsR.ParentId = Convert.ToInt32(_dataGridView.Rows[int.Parse(dr.Cells[1].Tag.ToString())].Tag);
List drs = _record.FactDrugList.Where(a => a.Id == drugsR.ParentId).ToList();
if (drs == null || drs.Count <= 0)
continue;
}
else
{
drugsR.ParentId = 0;
}
drugsR.DrugKind = dr.Cells[2].EditedFormattedValue.ToString();//药品名称
drugsR.DrugName = dr.Cells[3].EditedFormattedValue.ToString();//药品名称
drugsR.DrugChannel = dr.Cells[5].EditedFormattedValue.ToString();//途径
if (dr.Cells[10].EditedFormattedValue.ToString() != "")//剂量
{
drugsR.Dosage = Convert.ToDecimal(dr.Cells[10].EditedFormattedValue.ToString());//剂量
}
drugsR.DosageUnit = dr.Cells[11].EditedFormattedValue.ToString();//剂量单位
if (dr.Cells[6].EditedFormattedValue.ToString() != "")
{
drugsR.Density = Convert.ToDecimal(dr.Cells[6].EditedFormattedValue.ToString());//浓度
}
else
{
drugsR.Density = 0;
}
drugsR.DensityUnit = dr.Cells[7].EditedFormattedValue.ToString();//浓度单位
if (dr.Cells[8].EditedFormattedValue.ToString() != "")
{
drugsR.Velocity = dr.Cells[8].EditedFormattedValue.ToString();//速度
}
else
{
drugsR.Velocity = "";
}
drugsR.VelocityUnit = dr.Cells[9].EditedFormattedValue.ToString();//速度单位
drugsR.BloodType = dr.Cells[12].EditedFormattedValue.ToString();//血型
drugsR.GiveDrugType = drugEffect;
if (dr.Cells[4].EditedFormattedValue.ToString() != "")//备注
drugsR.Remark = dr.Cells[4].EditedFormattedValue.ToString();
else
drugsR.Remark = "";
if (dr.Cells[14].EditedFormattedValue.ToString() != "")//开始时间
{
drugsR.DrugBeginTime = Convert.ToDateTime(dr.Cells[14].Value.ToString());
if (!drugsR.DrugName.Contains("氧气"))
{
second++;
drugsR.DrugBeginTime = drugsR.DrugBeginTime.AddSeconds(second);
if (second > 5) second = 1;
}
}
drugsR.IsContinue = dr.Cells[15].EditedFormattedValue.ToString() != "" ? 1 : 0;//持续
if (drugsR.IsContinue == 1)
{
DateTime endTime = drugsR.DrugBeginTime;
if (dr.Cells[16].EditedFormattedValue.ToString() != "") endTime = Convert.ToDateTime(dr.Cells[16].Value.ToString());
drugsR.DrugEndTime = endTime;//结束时间
}
else
{
drugsR.DrugEndTime = drugsR.DrugBeginTime;
}
drugsR.OperatorNo = PublicMethod.OperatorNo;
drugsR.OperatorName = PublicMethod.OperatorName;
drugsR.OperateDate = DateTime.Now;
drugsR.DrugTypeId = DrugTypeId;
if (dr.Cells[17].Value != null)
drugsR.Access = dr.Cells[17].Value.ToString();
else
drugsR.Access = "";
if (dr.Tag == null)
{
drugsR.Id = BFactDrug.Insert(drugsR);
dr.Tag = drugsR.Id;
_record.FactDrugList.Add(drugsR);
}
else
{
drugsR.Id = Convert.ToInt32(dr.Tag);
//将修改的事件保存到集合
foreach (FactDrug FactDrug in _record.FactDrugList)
{
if (FactDrug.Id == drugsR.Id && equelDrugs(FactDrug, drugsR) == false)
{
if (drugsR.ParentId == 0) drugsR.ParentId = FactDrug.ParentId;
if (zgcAnaesRecord != null)
{
FactDrug.clearAddObj(zgcAnaesRecord);
FactDrug.clearIm(zgcAnaesRecord);
}
_record.FactDrugList.Remove(FactDrug);
_record.FactDrugList.Add(drugsR);
BFactDrug.Update(drugsR);
break;
}
}
dr.Tag = drugsR.Id;
}
}
}
catch (Exception exp)
{
PublicMethod.WriteLog(exp);
}
}
public bool equelDrugs(FactDrug oldDrug, FactDrug newDrug)
{
bool b = true;
if (oldDrug.DrugName != newDrug.DrugName) b = false;
if (oldDrug.Remark != newDrug.Remark) b = false;
if (oldDrug.Dosage != newDrug.Dosage) b = false;
if (oldDrug.Velocity != newDrug.Velocity) b = false;
if (oldDrug.Density != newDrug.Density) b = false;
if (oldDrug.DosageUnit != newDrug.DosageUnit) b = false;
if (oldDrug.VelocityUnit != newDrug.VelocityUnit) b = false;
if (oldDrug.DensityUnit != newDrug.DensityUnit) b = false;
if (oldDrug.BloodType != newDrug.BloodType) b = false;
if (oldDrug.DrugChannel != newDrug.DrugChannel) b = false;
if (oldDrug.Access != newDrug.Access) b = false;
if (oldDrug.DrugBeginTime != null && newDrug.DrugBeginTime != null && oldDrug.DrugBeginTime.ToString("yyyy-MM-dd HH:mm") != newDrug.DrugBeginTime.ToString("yyyy-MM-dd HH:mm")) b = false;
if (oldDrug.IsContinue != newDrug.IsContinue) b = false;
if (oldDrug.DrugEndTime != newDrug.DrugEndTime && oldDrug.DrugEndTime.ToString("HH:mm") != newDrug.DrugEndTime.ToString("HH:mm")) b = false;
return b;
}
private void btnSave_Click(object sender, EventArgs e)
{
try
{
btnSave.Focus();
if (SaveValid(dgvDrugsSZ, 1)) Save(dgvDrugsSZ, 1);
else return;
new frmMessageBox().Show();
if (DrugsParam != null) DrugsParam();
}
catch (Exception exp)
{
PublicMethod.WriteLog(exp);
}
}
#region DataGridView数字单元格验证 GZ
public DataGridViewTextBoxEditingControl dgvTxt = null; // 声明 一个文本 CellEdit
public DataGridViewTextBoxEditingControl dgvTxtName = null; // 声明 一个文本 CellEdit
public DataGridViewTextBoxEditingControl dgvVensity = null; // 声明 一个文本 CellEdit
//public DataGridViewTextBoxEditingControl dgvDensity = null; // 声明 一个文本 CellEdit
public DataGridViewTextBoxEditingControl dgvTextYP = null; // 声明 一个文本 CellEdit
private void dgvDrugs_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
//判断类型
if (_dataGridView.CurrentCell != null && _dataGridView.CurrentCell.ColumnIndex != 6)
{
if (e.Control.GetType().Equals(typeof(DevComponents.DotNetBar.Controls.DataGridViewDateTimeInputEditingControl)))
{
((DevComponents.DotNetBar.Controls.DataGridViewDateTimeInputEditingControl)e.Control).DateTimeSelectorVisibility = DevComponents.Editors.DateTimeAdv.eDateTimeSelectorVisibility.DateSelector;
}
else if (dgvTxt != null)
{
dgvTxt.KeyPress -= new KeyPressEventHandler(dgvTxt_KeyPress); // 绑定事件
}
if (_dataGridView.CurrentCell.ColumnIndex == 3)
{
dgvTextYP = (DataGridViewTextBoxEditingControl)e.Control; // 得到单元格
dgvTextYP.KeyPress -= new KeyPressEventHandler(dgvTxtName_KeyPress); // 绑定事件
dgvTextYP.KeyPress += new KeyPressEventHandler(dgvTxtName_KeyPress); // 绑定事件
dgvTextYP.TextChanged -= new EventHandler(dgvTextYP_TextChanged);
dgvTextYP.TextChanged += new EventHandler(dgvTextYP_TextChanged);
dgvTextYP.PreviewKeyDown -= new PreviewKeyDownEventHandler(dgvTextYP_PreviewKeyDownEvent);
dgvTextYP.PreviewKeyDown += new PreviewKeyDownEventHandler(dgvTextYP_PreviewKeyDownEvent);
}
if (_dataGridView.CurrentCell.ColumnIndex == 10)
{
dgvTxt = (DataGridViewTextBoxEditingControl)e.Control; // 得到单元格
dgvTxt.KeyPress -= new KeyPressEventHandler(dgvTxt_KeyPress); // 绑定事件
dgvTxt.KeyPress += new KeyPressEventHandler(dgvTxt_KeyPress); // 绑定事件
dgvTxt.PreviewKeyDown -= new PreviewKeyDownEventHandler(dgvTxt_PreviewKeyDownEvent);
dgvTxt.PreviewKeyDown += new PreviewKeyDownEventHandler(dgvTxt_PreviewKeyDownEvent);
}
if (_dataGridView.CurrentCell.ColumnIndex == 6)
{
dgvVensity = (DataGridViewTextBoxEditingControl)e.Control; // 得到单元格
dgvVensity.KeyPress -= new KeyPressEventHandler(dgvTxt_KeyPress); // 绑定事件
dgvVensity.KeyPress += new KeyPressEventHandler(dgvTxt_KeyPress); // 绑定事件
}
//if (_dataGridView.CurrentCell.ColumnIndex == 8)
//{
// dgvDensity = (DataGridViewTextBoxEditingControl)e.Control; // 得到单元格
// dgvDensity.KeyPress -= new KeyPressEventHandler(dgvTxt_KeyPress); // 绑定事件
// dgvDensity.KeyPress += new KeyPressEventHandler(dgvTxt_KeyPress); // 绑定事件
//}
}
}
void dgvTxtName_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 34 || e.KeyChar == 39 || e.KeyChar == 47 || e.KeyChar == 44 || e.KeyChar == 58 || e.KeyChar == 59 || e.KeyChar == 60 || e.KeyChar == 62 || e.KeyChar == 63 || e.KeyChar == 91 || e.KeyChar == 92 || e.KeyChar == 93 || e.KeyChar == 123 || e.KeyChar == 124 || e.KeyChar == 125)
{
e.Handled = true;
}
}
void dgvTxt_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar < 48 || e.KeyChar > 57)
{
if (e.KeyChar != 46 && e.KeyChar != 8 && e.KeyChar != 13)
{
e.Handled = true;
}
}
TextBox tb = sender as TextBox;
if (e.KeyChar == 46)
{
int n = tb.Text.LastIndexOf(".");
if (n > 0) e.Handled = true;
}
}
#endregion
private void FullALLDGV()
{
factDrugs.Sort(new FactDrugComparer());
_dataGridView = dgvDrugsSZ;
SetDGVEvent(_dataGridView);
FullDrugsData(factDrugs);
tabDrugs_SelectedTabChanged(null, null);
}
private void frmFactDrugNew2_Paint(object sender, PaintEventArgs e)
{
this.HorizontalScroll.Value = x;
}
private void frmFactDrugNew2_Scroll(object sender, ScrollEventArgs e)
{
x = this.HorizontalScroll.Value;
}
private void tabDrugs_SelectedTabChanged(object sender, SuperTabStripSelectedTabChangedEventArgs e)
{
_dataGridView = dgvDrugsSZ;
_dataGridView.Columns[1].ReadOnly = true;
_dataGridView.Columns[2].ReadOnly = true;
//20200226 增加空行
AddNewNullRows();
_dataGridView.CurrentCell = _dataGridView.Rows[_dataGridView.Rows.Count - 1].Cells[3];
_dataGridView.BeginEdit(true);
if (dgvYP.Visible == true)
{
dgvYP.Visible = false;
}
}
private void AddNewNullRows()
{
if (_dataGridView.Rows.Count == 0)
{
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(_dataGridView);
row.Cells[0].Value = imageList1.Images[1];
row.Cells[1].Value = "主";
if (tabDrugs.SelectedTab.Name == "P3") row.Cells[5].Value = "泵入";
_dataGridView.Rows.Add(row);
}
else
{
if (_dataGridView.Rows[_dataGridView.Rows.Count - 1].Cells[3].EditedFormattedValue.ToString() != "")
{
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(_dataGridView);
row.Cells[0].Value = imageList1.Images[1];
row.Cells[1].Value = "主";
if (tabDrugs.SelectedTab.Name == "P3") row.Cells[5].Value = "泵入";
_dataGridView.Rows.Add(row);
}
}
}
private void frmFactDrugNew2_FormClosing(object sender, FormClosingEventArgs e)
{
}
private void dgvDrugs_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
if (e.Exception.Message == "DataGridViewComboBoxCell 值无效。")
{
try
{
object value = _dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
if (!((DataGridViewComboBoxCell)_dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex]).Items.Contains(value))
{
((DataGridViewComboBoxCell)_dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex]).Items.Add(value);
e.ThrowException = false;
}
}
catch (Exception)
{
e.ThrowException = false;
}
}
}
#region 2020-2-27 优化药品输入 GZ
///
/// 获取DataGridView回车事件
///
///
///
private void dgvDrugs_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Enter)
{
e.Handled = true;
//药品名称单元格回车时判断并填充药品信息
if (_dataGridView.CurrentCell.ColumnIndex == 3)
{
if (_dataGridView.CurrentRow.Cells[3].EditedFormattedValue.ToString() == "")
{
return;
}
SetYPContent(null);
}
//剂量单元格回车时填写剂量并将光标移到到下一行的药品名称单元格
else if (_dataGridView.CurrentCell.ColumnIndex == 10)
{
if (_dataGridView.CurrentRow.Cells[10].EditedFormattedValue.ToString() == "")
{
return;
}
//_dataGridView.CurrentCell.Value = dgvDosage.Rows[index].Cells[0].Value.ToString();
index = 0;
//dgvDosage.Visible = false;
_dataGridView.CurrentCell = _dataGridView.Rows[_dataGridView.CurrentCell.RowIndex + 1].Cells[3];
_dataGridView.BeginEdit(true);
}
}
}
///
/// 药品名称单元格字符串改变事件(根据输入查询药品)
///
///
///
void dgvTextYP_TextChanged(object sender, EventArgs e)
{
//显示并定位药品选择列表
if (dgvYP.Visible == false)
{
dgvYP.Visible = true;
GetControlPosition(dgvYP, _dataGridView.CurrentCell);
}
//药品名称单元格为空时,隐藏选择药品列表,否则为选择药品列表加载数据
if (dgvTextYP.Text == "")
{
dgvYP.Visible = false;
}
else
{
string str = dgvTextYP.Text.Trim();
DataTable dt = BDrugs.GetAllDrugsByCondition(str);
dgvYP.DataSource = dt;
}
}
///
/// 药品名称单元格按键事件(判断输入上下箭头并处理)
///
///
///
void dgvTextYP_PreviewKeyDownEvent(object sender, PreviewKeyDownEventArgs e)
{
//药品名称单元格为空时,返回
if (_dataGridView.CurrentCell.EditedFormattedValue.ToString() == "")
{
return;
}
//显示并定位选择药品列表
if (dgvYP.Visible == false)
{
dgvYP.Visible = true;
GetControlPosition(dgvYP, _dataGridView.CurrentCell);
}
//判断按下上下键时,选择药品列表获得焦点并定位光标
if (e.KeyCode == Keys.Up)
{
dgvYP.Focus();
dgvYP.Rows[dgvYP.Rows.Count - 1].Selected = true;
dgvYP.CurrentCell = dgvYP.Rows[dgvYP.Rows.Count - 1].Cells[3];
}
if (e.KeyCode == Keys.Down)
{
if (dgvYP.Rows.Count > 0)
{
dgvYP.Focus();
dgvYP.Rows[1].Selected = true;
dgvYP.CurrentCell = dgvYP.Rows[1].Cells[3];
}
}
}
///
/// 判断剂量鼠标事件
///
///
///
void dgvTxt_PreviewKeyDownEvent(object sender, PreviewKeyDownEventArgs e)
{
////常用默认剂量小于2不做操作
}
///
///获取单元格的位置并显示面板
///
///
///
private void GetControlPosition(Control pnl, DataGridViewCell cell)
{
Rectangle rec = _dataGridView.GetCellDisplayRectangle(cell.ColumnIndex, cell.RowIndex, false);
if (_dataGridView.Height - rec.Y - rec.Height - pnl.Height > 0)
{
pnl.Top = rec.Y + rec.Height + panel2.Height + 40;
}
else
{
pnl.Top = rec.Y - pnl.Height + panel2.Height + 40;
}
pnl.Left = rec.X;//TabSelDrugs.Width +
pnl.Visible = true;
}
//定位当前行索引
int index = 0;
///
/// 向药品表添加数据
///
///
private void SetYPContent(DataGridViewCellEventArgs e)
{
if (e != null)
{
index = e.RowIndex;
}
if (dgvYP.Rows[index].Cells["DrugName"].EditedFormattedValue.ToString() != "")
{
//dgvDosage.Rows.Clear();
_dataGridView.CurrentRow.Cells[2].Value = dgvYP.Rows[index].Cells["TypeName"].Value.ToString();
_dataGridView.CurrentRow.Cells[3].Tag = int.Parse(dgvYP.Rows[index].Cells["id"].Value.ToString());
_dataGridView.CurrentRow.Cells[3].Value = dgvYP.Rows[index].Cells["DrugName"].Value.ToString();//药品名称
_dataGridView.CurrentRow.Cells[11].Value = dgvYP.Rows[index].Cells["DoseUnit"].Value.ToString().Trim(); ;//备注名称
_dataGridView.CurrentRow.Cells[4].Value = dgvYP.Rows[index].Cells["Remark"].Value.ToString();
_dataGridView.CurrentRow.Cells[5].Value = dgvYP.Rows[index].Cells["Channel"].Value.ToString();
if (_dataGridView.CurrentRow.Cells[2].Value.ToString() == "血液制品")
{
_dataGridView.CurrentRow.Cells[12].ReadOnly = false;//血型
}
else
{
_dataGridView.CurrentRow.Cells[12].ReadOnly = true;//血型
}
// if (dgvYP.Rows[index].Cells["DosageUnit"].Value.ToString() != "")
//{
// _dataGridView.CurrentRow.Cells[11].Value = BBasicDictionary.GetDrugsUntiIdByUnitName(dgvYP.Rows[index].Cells["DosageUnit"].Value.ToString().Trim());
//}
//开始时间默认手术当天日期
_dataGridView.CurrentRow.Cells[14].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm");//默认当前时间‘
TimeSpan tsp = DateTime.Now - _record.InRoomTime.Value;
if (tsp.TotalHours > 12)
{
DateTime begindate = new DateTime(_record.InRoomTime.Value.Year, _record.InRoomTime.Value.Month, _record.InRoomTime.Value.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
_dataGridView.CurrentRow.Cells[14].Value = begindate;
}
if (tabDrugs.SelectedTab.Name == "P3") _dataGridView.CurrentRow.Cells[5].Value = "泵入";
index = 0;
dgvYP.Visible = false;
AddNewNullRows();
_dataGridView.CurrentCell = _dataGridView.CurrentRow.Cells[10];
_dataGridView.BeginEdit(false);
}
}
///
/// 鼠标点击选择药品列表时,向使用药品表添加数据
///
///
///
private void dgvYP_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
SetYPContent(e);
}
}
///
/// 选择药品列表上点击上下键定位并移动光标
///
///
///
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;
}
}
}
///
/// 选择药品列表点击回车键向使用药品列表添加数据
///
///
///
private void dgvYP_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar.ToString() == "\r")
{
if (dgvYP.SelectedRows.Count > 0)
{
SetYPContent(null);
}
}
}
///
/// 选择药品列表点击回车时先定位当前行的索引
///
///
///
private void dgvYP_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
index = dgvYP.CurrentRow.Index;
}
}
///
/// 使用药品表单元格失去焦点
///
///
///
private void dgvDrugs_CellLeave(object sender, DataGridViewCellEventArgs e)
{
//药品名称失去焦点时注销药品名称单元格的事件
if (e.ColumnIndex == 3)
{
if (dgvTextYP != null)
{
dgvTextYP.TextChanged -= new EventHandler(dgvTextYP_TextChanged);
dgvTextYP.PreviewKeyDown -= new PreviewKeyDownEventHandler(dgvTextYP_PreviewKeyDownEvent);
dgvTextYP.KeyPress -= new KeyPressEventHandler(dgvTxtName_KeyPress);
}
}
//剂量失去焦点时注销剂量单元格的事件
if (e.ColumnIndex == 10)
{
if (dgvTxt != null)
{
dgvTxt.KeyPress -= new KeyPressEventHandler(dgvTxt_KeyPress);
dgvTxt.PreviewKeyDown -= new PreviewKeyDownEventHandler(dgvTxt_PreviewKeyDownEvent);
}
}
}
///
/// 重写父类捕获键盘点击事件
///
///
///
///
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
{
dgvDrugs_KeyDown(_dataGridView, new KeyEventArgs(keyData));
return true;
}
else
{
return false;
}
}
///
/// 选择剂量列表点击鼠标时向使用药品列表填写剂量数据
///
///
///
private void dgvDosage_CellClick(object sender, DataGridViewCellEventArgs e)
{
//if (e.RowIndex >= 0)
//{
// _dataGridView.CurrentCell.Value = dgvDosage.Rows[e.RowIndex].Cells[0].Value.ToString();
// index = 0;
// dgvDosage.Visible = false;
//}
}
///
/// 选择剂量列表点击上下键时移动及定位光标
///
///
///
private void dgvDosage_KeyDown(object sender, KeyEventArgs e)
{
//if (e.KeyCode == Keys.Down)
//{
// if (dgvDosage.CurrentRow.Index == dgvDosage.Rows.Count - 1)
// {
// e.Handled = true;
// dgvDosage.CurrentCell = dgvDosage.Rows[0].Cells[0];
// dgvDosage.Rows[0].Selected = true;
// }
//}
//if (e.KeyCode == Keys.Up)
//{
// if (dgvDosage.CurrentRow.Index == 0)
// {
// e.Handled = true;
// dgvDosage.CurrentCell = dgvDosage.Rows[dgvDosage.Rows.Count - 1].Cells[0];
// dgvDosage.Rows[dgvDosage.Rows.Count - 1].Selected = true;
// }
//}
}
///
/// 选择剂量列表回车时向使用药品列表添加剂量数据
///
///
///
private void dgvDosage_KeyPress(object sender, KeyPressEventArgs e)
{
//if (e.KeyChar.ToString() == "\r")
//{
// if (dgvDosage.SelectedRows.Count > 0)
// {
// _dataGridView.CurrentCell.Value = dgvDosage.Rows[index].Cells[0].Value.ToString();
// index = 0;
// dgvDosage.Visible = false;
// }
//}
}
///
/// 选择剂量列表回车时先定位行索引
///
///
///
private void dgvDosage_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
//if (e.KeyCode == Keys.Enter)
//{
// index = dgvDosage.CurrentRow.Index;
//}
}
#endregion
}
}