using JJMediSys.cs; using JJServer; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; namespace JJMediSys { public partial class DataHistory : Form { public DataHistory() { InitializeComponent(); } public string Recp = ""; private void DataHistory_Load(object sender, EventArgs e) { gridView1.OptionsBehavior.Editable = false; gridView1.OptionsView.ShowIndicator = false;// 显示最左边空白列 //dateStart.Properties.ReadOnly = true; //dateEnd.Properties.ReadOnly = true; dateStart.DateTime = DateTime.Now; dateEnd.DateTime = DateTime.Now; PanelAction.Visible = false; RadioZX.Checked = true; Recp = ConfigFileReader.GetValue("/configuration/appSettings/add[@key='RecpFormat']"); } private void BSearch_Click(object sender, EventArgs e) { DoSearch(); } public void DoSearch() { try { string TJ = ""; if (TextSearhItemID.Text.Length > 0) { TJ = " and Barcode ='" + TextSearhItemID.Text + "'"; } else if (TextSearhCardNo.Text.Length > 0) { TJ = " and PatID ='" + TextSearhCardNo.Text + "'"; } else if (TextSearhName.Text.Length > 0) { TJ = " and PatName ='" + TextSearhName.Text + "'"; } if (TextCAOZY.Text.Length > 0) { TJ = TJ+" and PrinterDev ='" + TextCAOZY.Text + "'"; } string Key = "DBExcTime"; if (RadioKD.Checked) Key = "OprTime"; string sql = "select * from trans_history where " + Key + " >'" + dateStart.DateTime.Date.ToString("yyyy-MM-dd") + "' and " + Key + " <='" + dateEnd.DateTime.Date.AddDays(1).ToString("yyyy-MM-dd") + "'" + TJ; MainForm.logger.Info("Mysql sql=" + sql); DataSet dataSet = DoDBMySql.Query(sql); BindingSource bindingSource = new BindingSource(); bindingSource.DataSource = dataSet; bindingSource.DataMember = "ds"; // 将 BindingSource 绑定到 GridControl gridControl1.DataSource = bindingSource; gridControl1.RefreshDataSource(); gridView1.RefreshData(); LabNote.Text = $"共检索到: {gridView1.DataRowCount} 条记录"; } catch(Exception e) { MessageBox.Show(e.Message); } } private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) { if (e.Column.Name == "Tuble") { var v = e.CellValue; if (v != null) { e.Appearance.BackColor = Color.FromName(MZCY.GetColorInfo(v.ToString(), false)); } } if (e.Column.Name == "ItemDetails1") { var v = e.CellValue; } } private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) { if (e.Column.FieldName == "ItemStatus") { if (e.Value != null) { string zsStatus = MZCY.TransItemStatus(e.Value.ToString()); e.DisplayText = zsStatus; } } } private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e) { if (e.Column != null && e.Column.FieldName == "ItemName") { string detailes = gridView1.GetRowCellValue(e.RowHandle, "ItemsDetails").ToString(); ItemsShowBox itemsShowBox = new ItemsShowBox(detailes); itemsShowBox.Show(); } } private void bPrint_Click(object sender, EventArgs e) { if (gridView1.SelectedRowsCount <= 0) { MessageBox.Show("请先选择需要打印的试管"); return; } bool ItemStatusExp = false; //项目状态异常 需要进行提示 int[] selectedRowHandles = gridView1.GetSelectedRows(); // 遍历选中的行 PatientDatail patientDatail = new PatientDatail(); Patient_Info CurPatientInfo = new Patient_Info(); patientDatail.PatientInfo = CurPatientInfo; List jyDatas = new List(); List orginDatas = new List(); foreach (int rowHandle in selectedRowHandles) { // 检查行是否有效 if (rowHandle >= 0 && rowHandle < gridView1.DataRowCount) { // 获取行数据 object dataRow = gridView1.GetDataRow(rowHandle); string PatID = gridView1.GetRowCellValue(rowHandle, "PatID").ToString(); string PatName = gridView1.GetRowCellValue(rowHandle, "PatName").ToString(); string PatAge = gridView1.GetRowCellValue(rowHandle, "PatAge").ToString(); string PatSex = gridView1.GetRowCellValue(rowHandle, "PatSex").ToString(); if (CurPatientInfo.CardNo == null) { CurPatientInfo.CardNo = PatID; CurPatientInfo.Name = PatName; CurPatientInfo.Sex = PatSex; CurPatientInfo.Age = PatAge; } else if(CurPatientInfo.CardNo!= PatID) { MessageBox.Show("所选试管不属于同一个患者,请确认后重试"); return; } string Barcode = gridView1.GetRowCellValue(rowHandle, "Barcode").ToString(); string Tuble = gridView1.GetRowCellValue(rowHandle, "Tuble").ToString(); string ItemName = gridView1.GetRowCellValue(rowHandle, "ItemName").ToString(); string ItemCount = gridView1.GetRowCellValue(rowHandle, "ItemCount").ToString(); string ItemType = gridView1.GetRowCellValue(rowHandle, "ItemType").ToString(); string DoDept = gridView1.GetRowCellValue(rowHandle, "DoDept").ToString(); string OprDept = gridView1.GetRowCellValue(rowHandle, "OprDept").ToString(); string OprTime = gridView1.GetRowCellValue(rowHandle, "OprTime").ToString(); string PrintTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string ItemStatus = gridView1.GetRowCellValue(rowHandle, "ItemStatus").ToString(); ; string ItemsDetails = gridView1.GetRowCellValue(rowHandle, "ItemsDetails").ToString(); if (!ItemStatus.Equals("未打印")) { ItemStatusExp = true; } jyData mjyData = new jyData(); mjyData.sgname = Tuble; mjyData.Barcode = Barcode; mjyData.itemInfo = ItemName; var variables = new Dictionary { { "pictureBox1", Barcode }, { "Barcode", Barcode }, { "ItemInfo", ItemName }, { "CardNo", PatID }, { "ItemType", ItemType }, { "OprTime", DateTime.Now.ToString("yyyy-MM-dd") }, { "OprDept", OprDept }, { "DoDept", DoDept }, { "Tuble", Tuble }, { "patSex", PatSex }, { "patName", PatName } }; string bqxx = Regex.Replace(Recp, @"\{(\w+)\}", match => { string variableName = match.Groups[1].Value; return variables.ContainsKey(variableName) ? variables[variableName] : match.Value; }); //string bqxx = "B060010255050|" + mjyData.Barcode + "@TB18320020080040|L^" + Tuble + "@TB18110060220040|L^" + mjyData.Barcode + "@TB18032090400040|L^" + CurPatientInfo.Name + " " + CurPatientInfo.Sex + " " + OprDept + " " + DoDept + "@TB18032120400040|L^" + DateTime.Now.ToString("yyyy-MM-dd") + " " + ItemType + " " + CurPatientInfo.CardNo + "@TB18032150400080|L^" + mjyData.itemInfo; if (!RecpOnly.Checked) { mjyData.sgxx = bqxx; if (MZCY.CanDispense(mjyData.sgname)) { mjyData.bqtype = 1; } else { mjyData.bqtype = 2; } } else { mjyData.sgxx = bqxx; mjyData.bqtype = 2; } jyDatas.Add(mjyData); OrginData orginData = new OrginData(); orginData.PatID = CurPatientInfo.CardNo; orginData.PatName = CurPatientInfo.Name; orginData.PatAge = CurPatientInfo.Age; orginData.PatSex = CurPatientInfo.Sex; orginData.Barcode = Barcode; orginData.Tuble = Tuble; orginData.ItemName = ItemName; orginData.ItemCount = ItemCount; orginData.ItemType = ItemType; orginData.DoDept = DoDept; orginData.OprDept = OprDept; orginData.OprTime = OprTime; orginData.PrintTime = PrintTime; orginData.ItemStatus = "1"; orginData.ItemsDetails = ItemsDetails; orginData.PrinterDev = Login.nurseDeskInfo.NurseName; orginDatas.Add(orginData); patientDatail.ItemCount++; } } patientDatail.jyDatas = jyDatas; patientDatail.OrginDatas = orginDatas; if ( ItemStatusExp) { DialogResult dialogResult = MessageBox.Show("所选项目部分状态异常,是否确认打印?", "提示", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.No) return; } SystemSet.systemSet.myServer.ParseData(patientDatail); //foreach (OrginData orginData in patientDatail.OrginDatas) //{ // DoDBMySql.connectionString = Login.SqlConnect; // string sql = "Insert into trans_history(PatID,PatName,PatAge,PatSex,Barcode,Tuble ,ItemName ,ItemCount,ItemType ,DoDept ,OprDept ,OprTime,PrintTime,ItemStatus,ItemsDetails,PrinterDev)values('" + orginData.PatID + "','" + orginData.PatName + "','" + orginData.PatAge + "','" + orginData.PatSex + "','" + orginData.Barcode + "','" + orginData.Tuble + "','" + orginData.ItemName + "','" + orginData.ItemCount + "','" + orginData.ItemType + "','" + orginData.DoDept + "','" + orginData.OprDept + "','" + orginData.OprTime + "','" + orginData.PrintTime + "','" + orginData.ItemStatus + "','" + orginData.ItemsDetails + "','" + orginData.PrinterDev + "') ON DUPLICATE KEY UPDATE Tuble = VALUES(Tuble),ItemName = VALUES(ItemName),ItemCount = VALUES(ItemCount),ItemType = VALUES(ItemType),OprTime = VALUES(OprTime),OprDept = VALUES(OprDept),DoDept = VALUES(DoDept),PrintTime = VALUES(PrintTime),ItemStatus = VALUES(ItemStatus),ItemsDetails = VALUES(ItemsDetails),PrinterDev = VALUES(PrinterDev)"; // int Ret = DoDBMySql.ExecuteSql(sql); //} } private void bDistory_Click(object sender, EventArgs e) { try { if (gridView1.SelectedRowsCount <= 0) { MessageBox.Show("请先选择需要作废的试管"); return; } DialogResult dialogResult = MessageBox.Show($"即将作废选中的{gridView1.SelectedRowsCount}根试管", "警告", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.No) return; int[] selectedRowHandles = gridView1.GetSelectedRows(); // 遍历选中的行 List IDs = new List(); foreach (int rowHandle in selectedRowHandles) { // 检查行是否有效 if (rowHandle >= 0 && rowHandle < gridView1.DataRowCount) { // 获取行数据 object dataRow = gridView1.GetDataRow(rowHandle); IDs.Add(gridView1.GetRowCellValue(rowHandle, "ID").ToString()); } } if (IDs.Count > 0) { string TJ = ""; foreach (string str in IDs) { if (TJ == "") { TJ = "'" + str + "'"; } else { TJ = TJ + ",'" + str + "'"; } } string sql = "Update trans_history Set ItemStatus='0', PrintTime=NULL ,PrinterDev='' where ID in(" + TJ + ")"; MainForm.logger.Info("Mysql sql=" + sql); int Ret = DoDBMySql.ExecuteSql(sql); } DoSearch(); } catch(Exception err) { MessageBox.Show(err.Message); } } private void gridView1_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e) { if(gridView1.SelectedRowsCount<=0) { PanelAction.Visible = false; } else { PanelAction.Visible = true; } } private void gridView1_DoubleClick(object sender, EventArgs e) { if (gridView1.RowCount > 0 && gridView1.FocusedColumn != null && gridView1.FocusedRowHandle >= 0) { string data = gridView1.GetFocusedRowCellDisplayText(gridView1.FocusedColumn); if (!String.IsNullOrEmpty(data)) Clipboard.SetText(data, TextDataFormat.Text); } } private void groupBox1_Enter(object sender, EventArgs e) { } private void label4_Click(object sender, EventArgs e) { } private void TextCAOZY_TextChanged(object sender, EventArgs e) { } private void 时间设置_Enter(object sender, EventArgs e) { } private void RadioZX_CheckedChanged(object sender, EventArgs e) { } private void RadioKD_CheckedChanged(object sender, EventArgs e) { } private void dateStart_EditValueChanged(object sender, EventArgs e) { } private void label16_Click(object sender, EventArgs e) { } private void dateEnd_EditValueChanged(object sender, EventArgs e) { } private void label3_Click(object sender, EventArgs e) { } private void TextSearhName_TextChanged(object sender, EventArgs e) { } private void label2_Click(object sender, EventArgs e) { } private void TextSearhItemID_TextChanged(object sender, EventArgs e) { } private void label15_Click(object sender, EventArgs e) { } private void label1_Click(object sender, EventArgs e) { } private void TextSearhCardNo_TextChanged(object sender, EventArgs e) { } private void panel1_Paint(object sender, PaintEventArgs e) { } private void panel2_Paint(object sender, PaintEventArgs e) { } private void LabNote_Click(object sender, EventArgs e) { } private void gridControl1_Click(object sender, EventArgs e) { } private void RecpOnly_CheckedChanged(object sender, EventArgs e) { } private void PanelAction_Paint(object sender, PaintEventArgs e) { } private void PicClear1_Click(object sender, EventArgs e) { TextSearhCardNo.Clear(); } private void PicClear2_Click(object sender, EventArgs e) { TextSearhName.Clear(); } private void PicClear3_Click(object sender, EventArgs e) { TextSearhItemID.Clear(); } private void PicClear4_Click(object sender, EventArgs e) { TextCAOZY.Clear(); } } }