2023-08-16 22:32:16 +08:00

1826 lines
84 KiB
C#

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 frmFactDrugNew : OfficeForm
{
public static object valueTime;
public int currentTabIndex = 2;
public bool isCVhageAllSapDose = false;
public int DrugTypeId;
public DateTime? ClickTime;
#region
int x = 0;
/// <summary>
/// 修改加药委托
/// </summary>
public delegate void DrugsParamHandler();
/// <summary>
/// 修改加药事件
/// </summary>
public event DrugsParamHandler DrugsParam;
/// <summary>
/// 手术记录
/// </summary>
public DrawGraph.OperationRecord _record;
/// <summary>
/// 图表控件
/// </summary>
public ZedGraphControl zgcAnaesRecord;
/// <summary>
/// 选择项编号
/// </summary>
public int _itemId;
public DataGridView _dataGridView;
private int _lineNumber;
#endregion
public frmFactDrugNew()
{
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 frmFactDrugNew_Load(object sender, EventArgs e)
{
buttonX1.Text = "";
SetDGVNotSort();
Initial();
FullALLDGV();
tabDrugs.SelectedTabIndex = currentTabIndex;
_dataGridView = dgvDrugsSZ;
BindAnaesthesiaEvents();
dgvYP.Visible = false;
dgvYP.AutoGenerateColumns = false;
if (PublicMethod.OperatorNo == "admin" || PublicMethod.RoleName.Contains("常用药品"))
{
btnTypeManager.Visible = true;
}
}
private void SetDGVNotSort()
{
for (int i = 0; i < this.dgvDrugsYD.Columns.Count; i++)
{
dgvDrugsYD.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}
for (int i = 0; i < this.dgvDrugsSQ.Columns.Count; i++)
{
dgvDrugsSQ.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}
for (int i = 0; i < dgvDrugsSZ.Columns.Count; i++)
{
dgvDrugsSZ.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
}
for (int i = 0; i < dgvDrugsSH.Columns.Count; i++)
{
dgvDrugsSH.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);
dgv.CellDoubleClick -= Dgv_CellDoubleClick;
dgv.CellDoubleClick += Dgv_CellDoubleClick;
}
private void Dgv_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
//if (_dataGridView.CurrentCell.ColumnIndex == 3)
//{
// frmPrescriptionDocument document = new frmPrescriptionDocument();
// document._operationRecord = _record;
// document.CurrentRow = _dataGridView.CurrentRow;
// document.ShowDialog();
//}
}
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 = "" });
}
}
int page = 0;
int currpage = 0;
DataTable drugdt;
Panel panelleftsel;
private void FullCommonlyDrugs(DataTable dt, Panel panelleft)
{
if (panelleft.Controls != null) panelleft.Controls.Clear();
if (dt.Rows.Count == 18 || dt.Rows.Count == 36 || dt.Rows.Count == 54)
page = (dt.Rows.Count / 18);
else
page = (dt.Rows.Count / 18) + 1;
currpage = 1;
drugdt = dt;
int y = -28;
if (page > 1)
{
Panel paneltab = new Panel();
paneltab.AutoScroll = true;
paneltab.BackColor = Color.White;
paneltab.Dock = DockStyle.Top;
paneltab.Height = 36;
panelleft.Controls.Add(paneltab);
int x = -28;
y = 8;
for (int i = 1; i <= page; i++)
{
ButtonX lb = new ButtonX();
lb.Text = i.ToString().Trim();
lb.Size = new System.Drawing.Size(30, 30);
lb.Font = new System.Drawing.Font("微软雅黑", 11f, FontStyle.Bold);
lb.Parent = paneltab;
if (i == 1)
lb.TextColor = System.Drawing.Color.Black;
x += 34;
lb.Location = new Point(x, 3);
lb.Click += Lb1_Click;
paneltab.Controls.Add(lb);
}
}
Panel panel = new Panel();
panel.AutoScroll = true;
panel.BackColor = Color.White;
panel.Dock = DockStyle.Fill;
panelleft.Controls.Add(panel);
panelleftsel = panel;
LoadDrugsMethod(y);
}
private void Lb1_Click(object sender, EventArgs e)
{
ButtonX button = (ButtonX)sender;
currpage = int.Parse(button.Text);
foreach (Control item in button.Parent.Controls)
{
if (item is ButtonX)
{
if (((ButtonX)item).Text == currpage.ToString())
((ButtonX)item).TextColor = System.Drawing.Color.Black;
else
((ButtonX)item).TextColor = System.Drawing.Color.White;
}
}
panelleftsel.Controls.Clear();
int y = 8;
LoadDrugsMethod(y);
}
private void LoadDrugsMethod(int y)
{
int row = (currpage - 1) * 18;
for (int i = 0; i < 18; i++)
{
if (row + i >= drugdt.Rows.Count) break;
int usedose = 0;
ButtonX lb = new ButtonX();
lb.Text = drugdt.Rows[row + i]["Name"].ToString().Trim() + " " + drugdt.Rows[row + i]["Stand"].ToString().Trim();
lb.Tag = drugdt.Rows[row + i]["Id"].ToString();
lb.Font = new System.Drawing.Font("微软雅黑", 9.5f, FontStyle.Bold);
if (drugdt.Rows[row + i]["UseDose1"].ToString() != "")
usedose++;
if (drugdt.Rows[row + i]["UseDose2"].ToString() != "")
usedose++;
if (drugdt.Rows[row + i]["UseDose3"].ToString() != "")
usedose++;
lb.Size = new System.Drawing.Size(panelleftsel.Width - (usedose * 43) - 8, 30);
lb.Cursor = Cursors.Hand;
lb.ColorTable = eButtonColor.Orange;// Flat;
lb.BackColor = Color.SkyBlue;
lb.TextAlignment = eButtonTextAlignment.Left;
lb.Parent = panelleftsel;
lb.TextColor = System.Drawing.Color.Black;
y += 32;
lb.Location = new Point(4, y);
lb.Click += new EventHandler(lb_Click);
int count = 0;
if (drugdt.Rows[row + i]["UseDose1"].ToString() != "")
{
ButtonX lb1 = new ButtonX();
lb1.Text = drugdt.Rows[row + i]["UseDose1"].ToString().Trim();
lb1.Tag = drugdt.Rows[row + i]["Id"].ToString();
//设定位置
lb1.Size = new System.Drawing.Size(38, 30);
lb1.Location = new Point(lb.Width + 8, y);
lb1.Font = new System.Drawing.Font("微软雅黑", 9f);
lb1.Cursor = Cursors.Hand;
lb1.ColorTable = eButtonColor.Orange;
lb1.BackColor = Color.SkyBlue;
lb1.TextAlignment = eButtonTextAlignment.Left;
lb1.Parent = panelleftsel;
lb1.TextColor = System.Drawing.Color.Black;
lb1.Click += new EventHandler(lb_Click);
panelleftsel.Controls.Add(lb1);
count++;
}
if (drugdt.Rows[row + i]["UseDose2"].ToString() != "")
{
ButtonX lb2 = new ButtonX();
lb2.Text = drugdt.Rows[row + i]["UseDose2"].ToString().Trim();
lb2.Tag = drugdt.Rows[row + i]["Id"].ToString();
//设定位置
lb2.Size = new System.Drawing.Size(38, 30);
lb2.Location = new Point((43 * count) + 8 + lb.Width, y);
lb2.Font = new System.Drawing.Font("微软雅黑", 9f);
lb2.Cursor = Cursors.Hand;
lb2.ColorTable = eButtonColor.Orange;
lb2.BackColor = Color.SkyBlue;
lb2.TextAlignment = eButtonTextAlignment.Left;
lb2.Parent = panelleftsel;
lb2.TextColor = System.Drawing.Color.Black;
lb2.Click += new EventHandler(lb_Click);
panelleftsel.Controls.Add(lb2);
count++;
}
if (drugdt.Rows[row + i]["UseDose3"].ToString() != "")
{
ButtonX lb3 = new ButtonX();
lb3.Text = drugdt.Rows[row + i]["UseDose3"].ToString().Trim();
lb3.Tag = drugdt.Rows[row + i]["Id"].ToString();
//设定位置
lb3.Size = new System.Drawing.Size(38, 30);
lb3.Location = new Point((43 * count) + 8 + lb.Width, y);
lb3.Font = new System.Drawing.Font("微软雅黑", 9f);
lb3.Cursor = Cursors.Hand;
lb3.ColorTable = eButtonColor.Orange;
lb3.BackColor = Color.SkyBlue;
lb3.TextAlignment = eButtonTextAlignment.Left;
lb3.Parent = panelleftsel;
lb3.TextColor = System.Drawing.Color.Black;
lb3.Click += new EventHandler(lb_Click);
panelleftsel.Controls.Add(lb3);
}
panelleftsel.Controls.Add(lb);
}
}
void lb_Click(object sender, EventArgs e)
{
ButtonX send = sender as ButtonX;
Drugs drug = BDrugs.SelectSingle(int.Parse(send.Tag.ToString()));
DataGridViewRow dr = new DataGridViewRow();
dr.CreateCells(_dataGridView);
dr.Cells[0].Value = imageList1.Images[1];
dr.Cells[2].Value = drug.DrugKind;
dr.Cells[3].Tag = drug.Id;
dr.Cells[3].Value = drug.Name;
dr.Cells[4].Value = drug.Remark;
dr.Cells[5].Value = drug.Channel;
if (tabDrugs.SelectedTab.Name == "P3") dr.Cells[5].Value = "泵入";
if (dr.Cells[2].Value.ToString() == "血液制品")
{
dr.Cells[12].ReadOnly = false;//血型
}
else
{
dr.Cells[12].ReadOnly = true;//血型
}
if (send.Text != "")
{
double outValue = 0;
if (double.TryParse(send.Text, out outValue))
{
dr.Cells[10].Value = outValue;
}
}
dr.Cells[11].Value = drug.DosageUnit.Trim();
//开始时间默认手术当天日期
dr.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);
dr.Cells[14].Value = begindate;
}
if (_lineNumber > 0)
{
dr.Cells[1].Value = " ...";
dr.Cells[1].Tag = _dataGridView.Rows[_lineNumber].Cells[1].Tag;
try
{
dr.Cells[14].Value = _dataGridView.Rows[_lineNumber - 1].Cells[14].Value;
}
catch (Exception)
{
}
_dataGridView.Rows.RemoveAt(_lineNumber);
_dataGridView.Rows.Insert(_lineNumber, dr);
_lineNumber = 0;
}
else
{
dr.Cells[1].Value = "主";
if (_dataGridView.Rows.Count != 0 && _dataGridView.Rows[_dataGridView.Rows.Count - 1].Cells[3].EditedFormattedValue.ToString() == "")
{
_dataGridView.Rows.Insert(_dataGridView.Rows.Count - 1, dr);
}
else
{
_dataGridView.Rows.Add(dr);
}
if (dr.Cells[5].EditedFormattedValue.ToString() == "吸入")
{
dr.Cells[7].Value = "%";//备注名称
_dataGridView.CurrentCell = dr.Cells[6];
_dataGridView.BeginEdit(true);
}
else if (dr.Cells[10].EditedFormattedValue.ToString() == "")
{
_dataGridView.CurrentCell = dr.Cells[10];
_dataGridView.BeginEdit(true);
}
}
}
/// <summary>
/// 向DataGridView填充入量数据
/// </summary>
private void FullDrugsData(List<FactDrug> 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();
}
//for (int i = 0; i < dgvDrugsSQ.Columns.Count; i++)
//{
// dgvDrugsSQ.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
//}
}
}
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 = Math.Round(item.DrugEndTime.Subtract(item.DrugBeginTime).TotalMinutes, 0) + "分";//结束时间
}
_dataGridView.Rows[index].Cells[18].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";
if (ClickTime != null)
_dataGridView.Rows[e.RowIndex].Cells[14].Value = ClickTime.Value.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;//结束时间
_dataGridView.CurrentRow.Cells[17].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;
}
double min = Math.Round(DateTime.Parse(_dataGridView.CurrentCell.Value.ToString()).Subtract(DateTime.Parse(_dataGridView.CurrentRow.Cells[14].EditedFormattedValue.ToString())).TotalMinutes, 0);
if (min > 0)
{
_dataGridView.CurrentRow.Cells[17].Value = min + "分";//结束时间
}
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 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() == "")
if (_dataGridView.CurrentRow.Cells[3].EditedFormattedValue.ToString() == "氧气")
_dataGridView.CurrentRow.Cells[9].Value = "L/min";
else _dataGridView.CurrentRow.Cells[9].Value = "ml/h";
//_dataGridView.CurrentRow.Cells[11].Value = null;
}
else if (e.ColumnIndex == 6)
{
if (_dataGridView.CurrentCell == null || _dataGridView.CurrentRow.Cells[6].EditedFormattedValue.ToString() == "") return;
if (_dataGridView.CurrentRow.Cells[7].EditedFormattedValue.ToString() == "") _dataGridView.CurrentRow.Cells[7].Value = "%";
}
else if (e.ColumnIndex == 14 || e.ColumnIndex == 16)
{
if (_dataGridView.CurrentRow == null) return;
if (_dataGridView.CurrentRow.Cells[14].EditedFormattedValue.ToString() != "" && _dataGridView.CurrentRow.Cells[16].EditedFormattedValue.ToString() != "")//持续
{
double min = Math.Round(DateTime.Parse(_dataGridView.CurrentRow.Cells[16].EditedFormattedValue.ToString()).Subtract(DateTime.Parse(_dataGridView.CurrentRow.Cells[14].EditedFormattedValue.ToString())).TotalMinutes, 0);
if (min > 0)
{
_dataGridView.CurrentRow.Cells[17].Value = min + "分";//结束时间
}
}
}
}
/// <summary>
/// 当前单元格内容发生改变时,将改变提交
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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<FactDrug> 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;
case 3:
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<FactDrug> 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[18].Value != null)
drugsR.Access = dr.Cells[18].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(dgvDrugsSQ, 1)) Save(dgvDrugsSQ, 0);
else return;
if (SaveValid(dgvDrugsSZ, 2)) Save(dgvDrugsSZ, 1);
else return;
if (SaveValid(dgvDrugsSH, 3)) Save(dgvDrugsSH, 2);
else return;
if (SaveValid(dgvDrugsYD, 0)) Save(dgvDrugsYD, 3);
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()
{
_record.FactDrugList.Sort(new FactDrugComparer());
foreach (BasicDictionary bd in ControlExtension._drugEffectList)
{
if (bd.Name == "麻醉诱导用药")
{
List<FactDrug> sList = _record.FactDrugList.Where(p => p.GiveDrugType == bd.Name).ToList();
_dataGridView = dgvDrugsYD;
SetDGVEvent(_dataGridView);
//dgvDrugs_RowsAdded(null, null);
FullDrugsData(sList);
}
else if (bd.Name == "麻醉前用药")
{
List<FactDrug> sList = _record.FactDrugList.Where(p => p.GiveDrugType == bd.Name).ToList();
_dataGridView = dgvDrugsSQ;
SetDGVEvent(_dataGridView);
//dgvDrugs_RowsAdded(null, null);
FullDrugsData(sList);
}
else if (bd.Name == "术中加药")
{
List<FactDrug> sList = _record.FactDrugList.Where(p => p.GiveDrugType == bd.Name).ToList();
_dataGridView = dgvDrugsSZ;
SetDGVEvent(_dataGridView);
//dgvDrugs_RowsAdded(null, null);
FullDrugsData(sList);
}
else if (bd.Name == "术后镇痛药")
{
List<FactDrug> sList = _record.FactDrugList.Where(p => p.GiveDrugType == bd.Name).ToList();
_dataGridView = dgvDrugsSH;
SetDGVEvent(_dataGridView);
//dgvDrugs_RowsAdded(null, null);
FullDrugsData(sList);
}
}
}
private void frmFactDrugNew_Paint(object sender, PaintEventArgs e)
{
this.HorizontalScroll.Value = x;
}
private void frmFactDrugNew_Scroll(object sender, ScrollEventArgs e)
{
x = this.HorizontalScroll.Value;
}
private void tabDrugs_SelectedTabChanged(object sender, SuperTabStripSelectedTabChangedEventArgs e)
{
DataTable dt = new DataTable();
_dataGridView = dgvDrugsSQ;
if (tabDrugs.SelectedTab.Name == "P1")
{
_dataGridView = dgvDrugsSQ;
}
else if (tabDrugs.SelectedTab.Name == "P2")
{
_dataGridView = dgvDrugsSZ;
}
else if (tabDrugs.SelectedTab.Name == "P3")
{
_dataGridView = dgvDrugsSH;
}
else if (tabDrugs.SelectedTab.Name == "P0")
{
_dataGridView = dgvDrugsYD;
}
_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);
}
}
}
SuperTabItem Superitem;
private void superTabControl1_SelectedTabChanged(object sender, SuperTabStripSelectedTabChangedEventArgs e)
{
if (Superitem != null && Superitem == TabSelDrugs.SelectedTab) return;
Panel panel = null;
DataTable dt = new DataTable();
Superitem = TabSelDrugs.SelectedTab;
if (Superitem.Tag != null && Superitem.Tag.ToString() != "")
{
panel = (SuperTabControlPanel)Superitem.AttachedControl;
dt = BDrugs.GetDrugsByIds(Superitem.Tag.ToString());
}
FullCommonlyDrugs(dt, panel);
}
private void frmFactDrugNew_FormClosing(object sender, FormClosingEventArgs e)
{
//List<FactDrug> UpdateRecordList = GetDrugsList();
//if (UpdateRecordList.Count > 0)
//{
// DialogResult dialogResult = MessageBox.Show("记录尚未保存,是否保存当前记录?", "系统提示", MessageBoxButtons.YesNo);
// if (dialogResult == DialogResult.Yes)
// {
// btnSave_Click(null, null);
// }
//}
//this.Hide();
//e.Cancel = true;
}
private void buttonX1_Click(object sender, EventArgs e)
{
if (buttonX1.Text == "全部显示")
{
buttonX1.Text = "分类显示";
}
else
{
buttonX1.Text = "全部显示";
}
FullALLDGV();
tabDrugs_SelectedTabChanged(null, null);
}
SuperTabControl stc = new SuperTabControl();
private void BindAnaesthesiaEvents()
{
try
{
for (int i = TabSelDrugs.Tabs.Count - 1; i >= 0; i--)
{
TabSelDrugs.Tabs.RemoveAt(i);
}
List<AnaesthesiaEvents> AnaesthesiaList = BAnaesthesiaEvents.Select(" IsAutomatic=1 and IsValid=1 ", null, RecursiveType.None, 0);
foreach (AnaesthesiaEvents item in AnaesthesiaList)
{
string Name = "";
char[] separatedCharacters = item.Name.ToCharArray();
for (int i = 0; i < separatedCharacters.Length; i++)
{
Name += separatedCharacters[i] + "\n";
}
SuperTabItem spt = stc.CreateTab(Name);
spt.Tag = item.TheEventsId;
spt.SymbolColor = Color.White;
SuperTabControlPanel superTabControlPanel = new SuperTabControlPanel();
superTabControlPanel.Dock = System.Windows.Forms.DockStyle.Fill;
superTabControlPanel.CanvasColor = Color.White;
superTabControlPanel.TabItem = spt;
spt.AttachedControl = superTabControlPanel;
TabSelDrugs.Controls.Add(superTabControlPanel);
TabSelDrugs.Tabs.Add(spt);
}
TabSelDrugs.FixedTabSize = new Size(30, 65);
this.TabSelDrugs.SelectedTabChanged += new System.EventHandler<DevComponents.DotNetBar.SuperTabStripSelectedTabChangedEventArgs>(this.superTabControl1_SelectedTabChanged);
TabSelDrugs.SelectedTab = TabSelDrugs.Tabs[0] as SuperTabItem;
superTabControl1_SelectedTabChanged(null, null);
}
catch (Exception ex)
{
PublicMethod.WriteLog(ex);
}
}
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;
}
}
}
private void txtQuery_Click(object sender, EventArgs e)
{
TextBoxX box = sender as TextBoxX;
box.Text = "";
}
#region 2020-2-27 GZ
/// <summary>
/// 获取DataGridView回车事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
}
/// <summary>
/// 药品名称单元格字符串改变事件(根据输入查询药品)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
}
}
/// <summary>
/// 药品名称单元格按键事件(判断输入上下箭头并处理)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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];
}
}
}
/// <summary>
/// 判断剂量鼠标事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void dgvTxt_PreviewKeyDownEvent(object sender, PreviewKeyDownEventArgs e)
{
////常用默认剂量小于2不做操作
}
///<summary>
///获取单元格的位置并显示面板
///</summary>
///<param name="pnl"></param>
///<param name="cell"></param>
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 = TabSelDrugs.Width + rec.X;
pnl.Visible = true;
}
//定位当前行索引
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() != "")
{
//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[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["Channel"].Value.ToString() == "吸入")
_dataGridView.CurrentRow.Cells[7].Value = "%";//备注名称
else
_dataGridView.CurrentRow.Cells[11].Value = dgvYP.Rows[index].Cells["DoseUnit"].Value.ToString().Trim(); ;//备注名称
// 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;
}
index = 0;
dgvYP.Visible = false;
AddNewNullRows();
if (dgvYP.Rows[index].Cells["Channel"].Value.ToString() == "吸入")
_dataGridView.CurrentCell = _dataGridView.CurrentRow.Cells[6];
else
_dataGridView.CurrentCell = _dataGridView.CurrentRow.Cells[10];
_dataGridView.BeginEdit(false);
}
}
/// <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;
}
}
/// <summary>
/// 使用药品表单元格失去焦点
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
}
/// <summary>
/// 重写父类捕获键盘点击事件
/// </summary>
/// <param name="msg"></param>
/// <param name="keyData"></param>
/// <returns></returns>
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
{
dgvDrugs_KeyDown(_dataGridView, new KeyEventArgs(keyData));
return true;
}
else
{
return false;
}
}
/// <summary>
/// 选择剂量列表点击鼠标时向使用药品列表填写剂量数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
//}
}
/// <summary>
/// 选择剂量列表点击上下键时移动及定位光标
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
// }
//}
}
/// <summary>
/// 选择剂量列表回车时向使用药品列表添加剂量数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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;
// }
//}
}
/// <summary>
/// 选择剂量列表回车时先定位行索引
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgvDosage_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
//if (e.KeyCode == Keys.Enter)
//{
// index = dgvDosage.CurrentRow.Index;
//}
}
#endregion
private void btnTypeManager_Click(object sender, EventArgs e)
{
frmAnaesthesiaEvents fae = new frmAnaesthesiaEvents();
fae.Type = 1;
fae.ShowDialog();
BindAnaesthesiaEvents();
//TabSelDrugs.SelectedTab = AnesTab;
}
}
public class DataGridViewComboEditBoxColumn : DataGridViewComboBoxColumn
{
public DataGridViewComboEditBoxColumn()
{
DataGridViewComboEditBoxCell obj = new DataGridViewComboEditBoxCell();
this.CellTemplate = obj;
}
}
//要加入的类
public class DataGridViewComboEditBoxCell : DataGridViewComboBoxCell
{
public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
ComboBox comboBox = (ComboBox)base.DataGridView.EditingControl;
if (comboBox != null)
{
comboBox.DropDownStyle = ComboBoxStyle.DropDown;
comboBox.AutoCompleteMode = AutoCompleteMode.Suggest;
comboBox.Validating += new CancelEventHandler(comboBox_Validating);
}
}
void comboBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
DataGridViewComboBoxEditingControl cbo = (DataGridViewComboBoxEditingControl)sender;
if (cbo.Text.Trim() == string.Empty) return;
DataGridView grid = cbo.EditingControlDataGridView;
if (grid.CurrentCell.ColumnIndex != 4 && grid.CurrentCell.ColumnIndex != 6) return;
object value = cbo.Text;
// Add value to list if not there
if (cbo.Items.IndexOf(value) == -1)
{
DataGridViewComboBoxCell cboCol = (DataGridViewComboBoxCell)grid.CurrentCell;
// Must add to both the current combobox as well as the template, to avoid duplicate entries
cbo.Items.Add(value);
cboCol.Items.Add(value);
grid.CurrentCell.Value = value;
}
}
}
}