using AIMSBLL; using AIMSExtension; using AIMSModel; using DevComponents.DotNetBar; using DevComponents.DotNetBar.Controls; using DrawGraph; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Windows.Forms; namespace AIMS.PublicUI.UI { public partial class frmDrugSel : OfficeForm { public static object valueTime; public int currentTabIndex = 1; public bool isCVhageAllSapDose = false; public int DrugTypeId; public bool IsLoad; public string loadString; #region 公共成员 int x = 0; /// /// 手术记录 /// public List FactDrugList; /// /// 剂量单位集合 /// public List _dUnitList; /// /// 选择项编号 /// public int _itemId; public DataGridView _dataGridView; private int _lineNumber; #endregion public frmDrugSel() { InitializeComponent(); } private void frmDrugSel_Load(object sender, EventArgs e) { SetDGVNotSort(); Initial(); FactDrugList = new List(); FullALLDGV(); tabDrugs.SelectedTabIndex = currentTabIndex; _dataGridView = dgvDrugsSZ; BindAnaesthesiaEvents(); dgvYP.Visible = false; dgvYP.AutoGenerateColumns = false; AddNewNullRows(); } 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); dgv.CellDoubleClick -= Dgv_CellDoubleClick; dgv.CellDoubleClick += Dgv_CellDoubleClick; } private void Dgv_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { } private void Dgv_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 6) { _dataGridView.CurrentCell.Tag = _dataGridView.CurrentCell.EditedFormattedValue.ToString(); } } private void Initial() { _dUnitList = BBasicDictionary.GetBasicDictionaryByName("包装单位").SubItem; _dUnitList.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]["Price"].ToString().Trim(); lb.Tag = drugdt.Rows[row + i]["Id"].ToString(); lb.Font = new System.Drawing.Font("微软雅黑", 9.5f, FontStyle.Bold); 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); panelleftsel.Controls.Add(lb); } } string SelectedTab = ""; void lb_Click(object sender, EventArgs e) { ButtonX send = sender as ButtonX; DataGridViewRow dr = new DataGridViewRow(); dr.CreateCells(_dataGridView); dr.Cells[0].Value = imageList1.Images[1]; dr.Cells[2].Value = ""; if (SelectedTab == "药品") { Drugs drug = BDrugs.SelectSingle(int.Parse(send.Tag.ToString())); dr.Cells[3].Tag = drug.Id; dr.Cells[3].Value = drug.Name; dr.Cells[4].Value = drug.Price; dr.Cells[6].Value = drug.Unit; dr.Cells[7].Value = drug.ZFBL; //if (drug.Name == "吸入用七氟烷") // dr.Cells[6].Value = "ml"; //else // dr.Cells[6].Value = "支"; //if (drug.Name == "复方右旋糖酐40注射液" || drug.Name == "地佐辛注射液" || drug.Name == "注射用尼可地尔" || drug.Name == "盐酸甲氧明注射液" || drug.Name == "盐酸阿扎司琼氯化钠注射液") // dr.Cells[7].Value = "100%"; //else // dr.Cells[7].Value = "10%"; } else { Charges drug = BCharges.SelectSingle(int.Parse(send.Tag.ToString())); dr.Cells[3].Tag = drug.Id; dr.Cells[3].Value = drug.Name; dr.Cells[4].Value = drug.Price; dr.Cells[6].Value = drug.Unit; dr.Cells[7].Value = drug.ZFBL; //if (drug.Name == "电子注药泵ZZB-II-150") // dr.Cells[7].Value = "100%"; //else // dr.Cells[7].Value = "50%"; } if (_lineNumber > 0) { dr.Cells[1].Value = " ..."; dr.Cells[1].Tag = _dataGridView.Rows[_lineNumber].Cells[1].Tag; _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); } } } /// /// 向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[14].Value != null && _dataGridView.Rows[e.RowIndex].Cells[14].Value.ToString() != "") { DateTime time = DateTime.Parse(_dataGridView.Rows[e.RowIndex].Cells[14].Value.ToString()); starttime = new DateTime(time.Year, time.Month, time.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0); } } 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;//开始时间 _dataGridView.Rows.Insert(_lineNumber, drc); } } } } } catch (Exception exp) { PublicMethod.WriteLog(exp); } } private void dgvDrugs_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { DataGridViewComboBoxCell dUnitCell; if (e == null) { dUnitCell = _dataGridView.Rows[0].Cells[6] as DataGridViewComboBoxCell;//剂量单位 } else { dUnitCell = _dataGridView.Rows[e.RowIndex].Cells[6] as DataGridViewComboBoxCell;//剂量单位 } dUnitCell.DataSource = _dUnitList; dUnitCell.DisplayMember = "Name"; dUnitCell.ValueMember = "Name"; } 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(); } } //点击结束时间时判断是否持续事件,并显示时间 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");//默认当前时间‘ _dataGridView.CurrentCell.Value = DateTime.Now; 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); _dataGridView.Rows.Remove(_dataGridView.CurrentRow); _lineNumber = 0; FullALLDGV(); tabDrugs_SelectedTabChanged(null, null); } else { if (_dataGridView.CurrentRow.Cells[3].Value != null || _dataGridView.CurrentRow.Cells[1].Value != null)//药品名称 { _dataGridView.Rows.Remove(_dataGridView.CurrentRow); _lineNumber = 0; } } } } catch (Exception ex) { PublicMethod.WriteLog(ex); } } private void Save(DataGridView _dataGridView, int index) { try { if (_dataGridView.Rows.Count < 1) return; string drugEffect = string.Empty; foreach (DataGridViewRow dr in _dataGridView.Rows) { if (dr.Cells[3].Value == null || dr.Cells[3].Value.ToString() == "")//药品名称 continue; //实例化FactDrug对象 FactDrug drugsR = new FactDrug(); drugsR.DrugId = Convert.ToInt32(dr.Cells[3].Tag);//药品名称 if (drugsR.DrugId == 0)//药品名称 continue; drugsR.ParentId = 0; drugsR.DrugKind = dr.Cells[2].EditedFormattedValue.ToString();//药品名称 drugsR.DrugName = dr.Cells[3].EditedFormattedValue.ToString();//药品名称 drugsR.Dosage = Convert.ToDecimal(dr.Cells[4].EditedFormattedValue.ToString()); drugsR.DrugKind = dr.Cells[5].EditedFormattedValue.ToString();//途径 drugsR.DosageUnit = dr.Cells[6].EditedFormattedValue.ToString();//剂量单位 drugsR.DensityUnit = dr.Cells[7].EditedFormattedValue.ToString();//比例 if (dr.Tag == null) { //drugsR.Id = BFactDrug.Insert(drugsR); //dr.Tag = drugsR.Id; FactDrugList.Add(drugsR); } else { drugsR.Id = Convert.ToInt32(dr.Tag); //将修改的事件保存到集合 foreach (FactDrug FactDrug in FactDrugList) { if (FactDrug.Id == drugsR.Id && equelDrugs(FactDrug, drugsR) == false) { if (drugsR.ParentId == 0) drugsR.ParentId = FactDrug.ParentId; FactDrugList.Remove(FactDrug); 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(); Save(dgvDrugsSZ, 1); this.Close(); } 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() { _dataGridView = dgvDrugsSZ; SetDGVEvent(_dataGridView); FullDrugsData(FactDrugList); } private void frmDrugSel_Paint(object sender, PaintEventArgs e) { this.HorizontalScroll.Value = x; } private void frmDrugSel_Scroll(object sender, ScrollEventArgs e) { x = this.HorizontalScroll.Value; } private void tabDrugs_SelectedTabChanged(object sender, SuperTabStripSelectedTabChangedEventArgs e) { DataTable dt = new DataTable(); _dataGridView = dgvDrugsSZ; if (tabDrugs.SelectedTab.Name == "P2") { _dataGridView = dgvDrugsSZ; } _dataGridView.Columns[1].ReadOnly = true; _dataGridView.Columns[2].ReadOnly = true; 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 = "主"; _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 = "主"; _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; AnaesthesiaEvents spt = Superitem.Tag as AnaesthesiaEvents; if (spt != null) { SelectedTab = spt.Remark; if (SelectedTab == "药品") { panel = (SuperTabControlPanel)Superitem.AttachedControl; dt = BDrugs.GetDrugsByIds(spt.TheEventsId.ToString()); } else { panel = (SuperTabControlPanel)Superitem.AttachedControl; dt = BCharges.GetDrugsByIds(spt.TheEventsId.ToString()); } } FullCommonlyDrugs(dt, panel); } private void frmDrugSel_FormClosing(object sender, FormClosingEventArgs e) { } SuperTabControl stc = new SuperTabControl(); private void BindAnaesthesiaEvents() { try { for (int i = TabSelDrugs.Tabs.Count - 1; i >= 0; i--) { TabSelDrugs.Tabs.RemoveAt(i); } List AnaesthesiaList = BAnaesthesiaEvents.Select(" IsAutomatic=3 and IsValid=1 ", null, RecursiveType.None, 0); foreach (AnaesthesiaEvents item in AnaesthesiaList) { SuperTabItem spt = stc.CreateTab(item.Name); spt.Tag = item; spt.SymbolColor = Color.White; SuperTabControlPanel superTabControlPanel = new SuperTabControlPanel(); superTabControlPanel.Dock = System.Windows.Forms.DockStyle.Fill; superTabControlPanel.CanvasColor = Color.White; TabSelDrugs.Controls.Add(superTabControlPanel); TabSelDrugs.Tabs.Add(spt); superTabControlPanel.TabItem = spt; spt.AttachedControl = superTabControlPanel; } this.TabSelDrugs.SelectedTabChanged += new System.EventHandler(this.superTabControl1_SelectedTabChanged); TabSelDrugs.SelectedTab = TabSelDrugs.Tabs[0] as SuperTabItem; if (IsLoad == true) { foreach (var item in AnaesthesiaList) { if (!loadString.Contains(item.Name)) continue; if (item.Remark == "药品") { DataTable dt = BDrugs.GetDrugsByIds(item.TheEventsId.ToString()); SelectedTab = "药品"; foreach (DataRow dr in dt.Rows) { ButtonX button = new ButtonX(); button.Tag = dr["Id"].ToString(); lb_Click(button, null); } } else { DataTable dt = BCharges.GetDrugsByIds(item.TheEventsId.ToString()); SelectedTab = "耗材"; foreach (DataRow dr in dt.Rows) { ButtonX button = new ButtonX(); button.Tag = dr["Id"].ToString(); lb_Click(button, null); } } } } } catch (Exception ex) { PublicMethod.WriteLog(ex); } superTabControl1_SelectedTabChanged(null, null); } 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 = ""; } /// /// 获取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 = TabSelDrugs.Width + rec.X; 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[4].Value = dgvYP.Rows[index].Cells["Price"].Value.ToString(); //_dataGridView.CurrentRow.Cells[5].Value = 1; _dataGridView.CurrentRow.Cells[6].Value = dgvYP.Rows[index].Cells["Unit"].Value.ToString(); _dataGridView.CurrentRow.Cells[7].Value = dgvYP.Rows[index].Cells["ZFBL"].Value.ToString(); index = 0; dgvYP.Visible = false; AddNewNullRows(); _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) { } /// /// 选择剂量列表回车时向使用药品列表添加剂量数据 /// /// /// private void dgvDosage_KeyPress(object sender, KeyPressEventArgs e) { } /// /// 选择剂量列表回车时先定位行索引 /// /// /// private void dgvDosage_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { } private void btnTypeManager_Click(object sender, EventArgs e) { frmAnaesthesiaEvents fae = new frmAnaesthesiaEvents(); fae.Type = 3; fae.ShowDialog(); BindAnaesthesiaEvents(); } } }