/// <summary> /// 生成有数据的DataGridView /// </summary> /// <param name="orderNum"></param> /// <param name="batch"></param> /// <param name="customerName"></param> /// <param name="locationName"></param> /// <returns></returns> private static DataGridView StructureDataForBackOrder(string orderNum, string batch, out string customerName, out string locationName, out string patientInfo) { DataGridView forback = StructureForBackOrder(); customerName = string.Empty; locationName = string.Empty; patientInfo = string.Empty; if (!string.IsNullOrEmpty(orderNum) && !string.IsNullOrEmpty(batch)) { SortedList condition = new SortedList(); condition.Add(1, orderNum); condition.Add(2, batch); condition.Add(3, orderNum); condition.Add(4, batch); CnasRemotCall reCnasRemotCall = new CnasRemotCall(); string testDataSql = reCnasRemotCall.RemotInterface.CheckSelectData("hcs_work_specialset_info-sec002", condition); DataTable data = reCnasRemotCall.RemotInterface.SelectData("hcs_work_specialset_info-sec002", condition); if (data != null && data.Rows.Count > 0) { customerName = Convert.ToString(data.Rows[0]["cu_name"]); locationName = Convert.ToString(data.Rows[0]["u_uname"]); Dictionary <string, string> dicInstrument = GetSetInstrumentTypeItem(string.Empty); Dictionary <string, string> dicChildInstrument = GetInstrumentChildTypeItem(); for (int i = 0; i < data.Rows.Count; i++) { int index = forback.Rows.Add(); string str_codeType = Convert.ToString(data.Rows[i]["codeType"]); string str_c_codeType = Convert.ToString(data.Rows[i]["base_ca_type"]); forback.Rows[index].Cells["o_id"].Value = forback.RowCount; //forback.Rows[index].Cells["o_cu_name"].Value = customerName; //forback.Rows[index].Cells["o_u_uname"].Value = locationName; forback.Rows[index].Cells["o_ca_name"].Value = data.Rows[i]["base_ca_name"]; //base_ca_name forback.Rows[index].Cells["o_codeType"].Value = GetEnumInstrumentTypeName(str_codeType, str_c_codeType, dicInstrument, dicChildInstrument); forback.Rows[index].Cells["o_num"].Value = data.Rows[i]["instrument_count"]; forback.Rows[index].Cells["o_remark"].Value = data.Rows[i]["remark"]; } } if (BarCodeHelper.IsOrderOutSet(orderNum)) { condition.Clear(); condition.Add(1, orderNum); condition.Add(2, batch); string personSQL = reCnasRemotCall.RemotInterface.CheckSelectData("HCS_person_info_sec001", condition); DataTable personData = reCnasRemotCall.RemotInterface.SelectData("HCS_person_info_sec001", condition); if (personData != null && personData.Rows.Count > 0) { patientInfo = string.Format("病人姓名:{0} 住 院 号:{1}", Convert.ToString(personData.Rows[0]["p_name"]), Convert.ToString(personData.Rows[0]["p_Number"])); } } } return(forback); }
/// <summary> /// 打印订单详情 /// </summary> /// <param name="orderNum">订单号</param> /// <param name="batch">订单批次</param> /// <param name="printType">打印模板</param> public static void OrderPrint(string orderNum, string batch, string printXml) { //订单详情 string customerName, locationName, orderName, instrumentCount, setCount, patientInfo; DataGridView dgv_orderDetail = StructureOrderDetailDgv(orderNum, batch, out customerName, out locationName, out orderName, out setCount, out instrumentCount, out patientInfo); string thingCount = string.Empty; if (BarCodeHelper.IsOrderOutSet(orderNum)) { thingCount = string.Format("物品数量:{0}件", instrumentCount); orderName = string.Format("外来器械包名:{0}", orderName); } else { thingCount = string.Format("器械包数量: {0}个 物品数量:{1}件", setCount, instrumentCount); orderName = string.Format("订单名称: {0}", orderName); } PrintHelper.Instance.Print_DataGridView(dgv_orderDetail, printXml, orderNum, new string[] { customerName, locationName, orderName, thingCount, patientInfo }); }
/// <summary> /// 构造订单详情dgv /// </summary> /// <param name="orderNum">订单号</param> /// <param name="batch">批次号</param> /// <param name="customerName">客户名称</param> /// <param name="locationName">使用地点</param> /// <returns></returns> private static DataGridView StructureOrderDetailDgv(string orderNum, string batch, out string customerName, out string locationName, out string setName, out string setCount, out string instrumentCount, out string patientInfo) { customerName = string.Empty; locationName = string.Empty; setName = string.Empty; patientInfo = string.Empty; DataGridView dgv_orderDetail = new DataGridView(); dgv_orderDetail.AllowUserToAddRows = false; DataGridViewTextBoxColumn o_id = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn o_ca_name = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn o_codeType = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn o_num = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn o_remark = new DataGridViewTextBoxColumn(); dgv_orderDetail.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { o_id, o_ca_name, o_codeType, o_num, o_remark, }); // // 序号o_id // o_id.HeaderText = " 序号"; o_id.Name = "o_id"; // // 器械名称o_ca_name // o_ca_name.HeaderText = "品名"; o_ca_name.Name = "o_ca_name"; // // 类型 o_codeType // o_codeType.HeaderText = "类型"; o_codeType.Name = "o_codeType"; // // 数量o_num // o_num.HeaderText = "数量"; o_num.Name = "o_num"; // // 备注o_remark // o_remark.HeaderText = "备注"; o_remark.Name = "o_remark"; int setNum = 0; int instrumentNum = 0; if (!string.IsNullOrEmpty(orderNum) && !string.IsNullOrEmpty(batch)) { SortedList condition = new SortedList(); condition.Add(1, orderNum); condition.Add(2, batch); condition.Add(3, orderNum); condition.Add(4, batch); CnasRemotCall reCnasRemotCall = new CnasRemotCall(); string testDataSql = reCnasRemotCall.RemotInterface.CheckSelectData("hcs_work_specialset_info-sec002", condition); DataTable data = reCnasRemotCall.RemotInterface.SelectData("hcs_work_specialset_info-sec002", condition); if (data != null && data.Rows.Count > 0) { customerName = Convert.ToString(data.Rows[0]["cu_name"]); locationName = Convert.ToString(data.Rows[0]["u_uname"]); setName = Convert.ToString(data.Rows[0]["ca_name"]); Dictionary <string, string> dicInstrument = GetSetInstrumentTypeItem(string.Empty); Dictionary <string, string> dicChildInstrument = GetInstrumentChildTypeItem(); for (int i = 0; i < data.Rows.Count; i++) { int index = dgv_orderDetail.Rows.Add(); string str_codeType = Convert.ToString(data.Rows[i]["codeType"]); string str_c_codeType = Convert.ToString(data.Rows[i]["base_ca_type"]); dgv_orderDetail.Rows[index].Cells["o_id"].Value = index + 1; dgv_orderDetail.Rows[index].Cells["o_ca_name"].Value = data.Rows[i]["base_ca_name"]; //base_ca_name dgv_orderDetail.Rows[index].Cells["o_codeType"].Value = GetEnumInstrumentTypeName(str_codeType, str_c_codeType, dicInstrument, dicChildInstrument); dgv_orderDetail.Rows[index].Cells["o_num"].Value = Convert.ToString(data.Rows[i]["instrument_count"]); dgv_orderDetail.Rows[index].Cells["o_remark"].Value = data.Rows[i]["remark"]; int number = 0; int.TryParse(Convert.ToString(data.Rows[i]["instrument_count"]), out number); if (str_codeType == "2") { setNum += number; } else { instrumentNum += number; } } } if (BarCodeHelper.IsOrderOutSet(orderNum)) { condition.Clear(); condition.Add(1, orderNum); condition.Add(2, batch); string personSQL = reCnasRemotCall.RemotInterface.CheckSelectData("HCS_person_info_sec001", condition); DataTable personData = reCnasRemotCall.RemotInterface.SelectData("HCS_person_info_sec001", condition); if (personData != null && personData.Rows.Count > 0) { patientInfo = string.Format("病人姓名:{0} 住 院 号:{1}", Convert.ToString(personData.Rows[0]["p_name"]), Convert.ToString(personData.Rows[0]["p_Number"])); } } } setCount = setNum.ToString(); instrumentCount = instrumentNum.ToString(); return(dgv_orderDetail); }
private void PrintDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { int tmpWidth, i; int tmpTop = e.MarginBounds.Top; int tmpLeft = e.MarginBounds.Left; try { double pageWidth = e.PageBounds.Width - e.MarginBounds.Left * 2; if (pageWidth < 0) { MessageBox.Show(PromptMessageXmlHelper.Instance.GetPromptMessage("printlist", EnumPromptMessage.warning), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); _printPreviewDialog.Close(); return; } // Before starting first page, it saves Width & Height of Headers and CoulmnType if (PageNo == 1) { foreach (DataGridViewColumn GridCol in dgv.Columns) { if (!GridCol.Visible) { ColumnWidths.Add(GridCol.Name, 0); continue; } // Skip if the current column not selected if (!SelectedColumns.Contains(GridCol.HeaderText)) { continue; } // Detemining whether the columns are fitted to page or not. if (FitToPageWidth) { ; if (pageWidth < TotalWidth) { tmpWidth = (int)(Math.Floor((double)((double)GridCol.Width / (double)TotalWidth * (double)pageWidth))); } else { tmpWidth = (int)(Math.Floor((double)((double)GridCol.Width / (double)TotalWidth * (double)TotalWidth * ((double)e.MarginBounds.Width / (double)TotalWidth)))); } } else { if (pageWidth < TotalWidth) { tmpWidth = (int)(Math.Floor((double)((double)GridCol.Width / (double)TotalWidth * (double)pageWidth))); } else { tmpWidth = GridCol.Width; } } HeaderHeight = (int)(e.Graphics.MeasureString(GridCol.HeaderText, GridCol.InheritedStyle.Font, tmpWidth).Height) + 20; // Save width & height of headres and ColumnType ColumnLefts.Add(tmpLeft); ColumnWidths.Add(GridCol.Name, tmpWidth); ColumnTypes.Add(GridCol.GetType()); tmpLeft += tmpWidth; } } // Printing Current Page, Row by Row while (RowPos <= dgv.Rows.Count - 1) { DataGridViewRow GridRow = dgv.Rows[RowPos]; if (GridRow.IsNewRow || (!PrintAllRows && !GridRow.Selected)) { RowPos++; continue; } // CellHeight = GridRow.Height; if (tmpTop + CellHeight >= e.MarginBounds.Height + e.MarginBounds.Top) { DrawFooter(e, RowsPerPage); NewPage = true; PageNo++; e.HasMorePages = true; return; } else { Font font = new Font(dgv.Font, FontStyle.Bold); if (NewPage) { tmpTop = e.MarginBounds.Top; // Draw Header //这里开始渲染标题 SizeF titleSize = e.Graphics.MeasureString(PrintTitle, TitleFont, e.MarginBounds.Width); e.Graphics.DrawString(PrintTitle, TitleFont, FontColor, (int)((pageWidth + e.MarginBounds.Left * 2 - titleSize.Width) / 2), e.MarginBounds.Top - titleSize.Height); int topH = 0; // 用于记录BarCode有传入的情况下,记录高度 Size barCodeSize = new Size(300, 80); if (!string.IsNullOrEmpty(barCodeValue)) { //渲染出BarCode在界面上 Image barImage = BarCodeHelper.GetBarcodeImage(barCodeValue, barCodeValue, 300, 80); barCodeSize = barImage.Size; e.Graphics.DrawImage(barImage, (int)((pageWidth + e.MarginBounds.Left * 2 - barCodeSize.Width) / 2), tmpTop, barCodeSize.Width, barCodeSize.Height); tmpTop += barCodeSize.Height; } if (PageNo == 1) { //显示内容部分 if (!string.IsNullOrEmpty(PrintContent)) { SizeF contentSize = e.Graphics.MeasureString(PrintContent, ConFont, e.MarginBounds.Width); e.Graphics.DrawString(PrintContent, ConFont, ConFontColor, e.MarginBounds.Left - 18, tmpTop); tmpTop += (int)contentSize.Height; } } string printTime = string.Format("时间:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm")); SizeF timeSize = e.Graphics.MeasureString(printTime, ConFont, e.MarginBounds.Width); e.Graphics.DrawString(printTime, ConFont, ConFontColor, (int)(pageWidth + e.MarginBounds.Left * 2 - e.MarginBounds.Left - timeSize.Width - 10), tmpTop); tmpTop += (int)timeSize.Height; // Draw Columns i = 0; foreach (DataGridViewColumn GridCol in dgv.Columns) { if (!GridCol.Visible) { continue; } if (!SelectedColumns.Contains(GridCol.HeaderText)) { continue; } e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), new Rectangle((int)ColumnLefts[i], tmpTop, (int)ColumnWidths[GridCol.Name], HeaderHeight)); e.Graphics.DrawRectangle(Pens.Black, new Rectangle((int)ColumnLefts[i], tmpTop, (int)ColumnWidths[GridCol.Name], HeaderHeight)); e.Graphics.DrawString(GridCol.HeaderText, DgvFont, new SolidBrush(GridCol.InheritedStyle.ForeColor), new RectangleF((int)ColumnLefts[i], tmpTop, (int)ColumnWidths[GridCol.Name], HeaderHeight), StrFormat); i++; } NewPage = false; tmpTop += HeaderHeight; } // Draw Columns Contents i = 0; foreach (DataGridViewCell Cel in GridRow.Cells) { if (!Cel.OwningColumn.Visible) { continue; } if (!SelectedColumns.Contains(Cel.OwningColumn.HeaderText)) { continue; } int j = 0; foreach (DataGridViewCell cel in GridRow.Cells) { SizeF maxSize = new SizeF((int)ColumnWidths[cel.OwningColumn.Name], CellHeight); string celValue = cel.Value != null?cel.Value.ToString() : ""; SizeF celSize = e.Graphics.MeasureString(celValue, DgvFont, e.MarginBounds.Width); double celHeight = celSize.Height * Math.Ceiling((double)(celSize.Width / maxSize.Width)); if (maxSize.Height < Math.Ceiling(celHeight) && !double.IsInfinity(celHeight)) { maxSize = new SizeF(maxSize.Width, (float)Math.Ceiling(celHeight)); CellHeight = (int)maxSize.Height + 10; } j++; } string cellValue = Cel.Value != null?Cel.Value.ToString() : ""; // For the TextBox Column if (((Type)ColumnTypes[i]).Name == "DataGridViewTextBoxColumn" || ((Type)ColumnTypes[i]).Name == "DataGridViewLinkColumn") { e.Graphics.DrawString(cellValue, DgvFont, new SolidBrush(Cel.InheritedStyle.ForeColor), new RectangleF((int)ColumnLefts[i], (float)tmpTop, (int)ColumnWidths[Cel.OwningColumn.Name], (int)CellHeight), StrFormat); } // For the Button Column else if (((Type)ColumnTypes[i]).Name == "DataGridViewButtonColumn") { CellButton.Text = cellValue; CellButton.Size = new Size((int)ColumnWidths[Cel.OwningColumn.Name], (int)CellHeight); Bitmap bmp = new Bitmap(CellButton.Width, CellButton.Height); CellButton.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height)); e.Graphics.DrawImage(bmp, new Point((int)ColumnLefts[i], tmpTop)); } // For the CheckBox Column else if (((Type)ColumnTypes[i]).Name == "DataGridViewCheckBoxColumn") { CellCheckBox.Size = new Size(14, 14); CellCheckBox.Checked = (bool)Boolean.Parse(cellValue); Bitmap bmp = new Bitmap((int)ColumnWidths[Cel.OwningColumn.Name], CellHeight); Graphics tmpGraphics = Graphics.FromImage(bmp); tmpGraphics.FillRectangle(Brushes.White, new Rectangle(0, 0, bmp.Width, bmp.Height)); CellCheckBox.DrawToBitmap(bmp, new Rectangle((int)((bmp.Width - CellCheckBox.Width) / 2), (int)((bmp.Height - CellCheckBox.Height) / 2), CellCheckBox.Width, CellCheckBox.Height)); e.Graphics.DrawImage(bmp, new Point((int)ColumnLefts[i], tmpTop)); } // For the ComboBox Column else if (((Type)ColumnTypes[i]).Name == "DataGridViewComboBoxColumn") { CellComboBox.Size = new Size((int)ColumnWidths[Cel.OwningColumn.Name], (int)CellHeight); Bitmap bmp = new Bitmap(CellComboBox.Width, (int)CellHeight); CellComboBox.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height)); e.Graphics.DrawImage(bmp, new Point((int)ColumnLefts[i], tmpTop)); e.Graphics.DrawString(cellValue, Cel.InheritedStyle.Font, new SolidBrush(Cel.InheritedStyle.ForeColor), new RectangleF((int)ColumnLefts[i] + 1, tmpTop, (int)ColumnWidths[Cel.OwningColumn.Name] - 16, CellHeight), StrFormatComboBox); } // For the Image Column else if (((Type)ColumnTypes[i]).Name == "DataGridViewImageColumn") { Rectangle CelSize = new Rectangle((int)ColumnLefts[i], tmpTop, (int)ColumnWidths[Cel.OwningColumn.Name], CellHeight); Size ImgSize = ((Image)(Cel.FormattedValue)).Size; e.Graphics.DrawImage((Image)Cel.FormattedValue, new Rectangle((int)ColumnLefts[i] + (int)((CelSize.Width - ImgSize.Width) / 2), tmpTop + (int)((CelSize.Height - ImgSize.Height) / 2), ((Image)(Cel.FormattedValue)).Width, ((Image)(Cel.FormattedValue)).Height)); } // For the Decimal else if (((Type)ColumnTypes[i]).Name == "DataGridViewDecimalColumn") { e.Graphics.DrawString(cellValue, DgvFont, new SolidBrush(Color.Black), new RectangleF((int)ColumnLefts[i], (float)tmpTop, (int)ColumnWidths[Cel.OwningColumn.Name], (int)CellHeight), StrFormat); } // Drawing Cells Borders e.Graphics.DrawRectangle(Pens.Black, new Rectangle((int)ColumnLefts[i], tmpTop, (int)ColumnWidths[Cel.OwningColumn.Name], (int)CellHeight)); i++; } tmpTop += CellHeight; } RowPos++; // For the first page it calculates Rows per Page if (PageNo == 1) { RowsPerPage++; } } if (RowsPerPage == 0) { return; } // Write Footer (Page Number) DrawFooter(e, RowsPerPage); e.HasMorePages = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }