private void ButtonPrint_Click(object sender, RoutedEventArgs e) { PrintDialog printDlg = new PrintDialog(); printDlg.PrintVisual(DataGridReport, "ToursReport"); }
public void Button_Click(object sender, RoutedEventArgs e) { if (IsPrint) { PrintDialog pDialog1 = new PrintDialog(); pDialog1.PrintVisual(GridPrint, "非会员消费打印"); DialogResult = true; this.Close(); return; } dynamic d = GridPrint.DataContext; decimal dCash = Convert.ToDecimal(txtCash.Text); decimal dChange = Convert.ToDecimal(txtChange.Text); if (dCash - dChange < d.Amount) { throw new ArgumentException("收的钱应不小于消费金额"); } using (TransactionScope transaction = new TransactionScope()) { DXInfo.Models.Consume consume = new DXInfo.Models.Consume(); consume.Sum = d.Sum; consume.Voucher = d.Voucher; consume.PayVoucher = d.PayVoucher; consume.Amount = d.Amount; consume.CreateDate = d.CreateDate; consume.DeptId = d.DeptId; consume.UserId = d.UserId; consume.Cash = dCash; consume.Change = dChange; consume.ConsumeType = 1; consume.PayType = d.PayType; consume.Discount = 100; consume.DeskNo = txtDeskNo.Text; uow.Consume.Add(consume); DXInfo.Models.Bills bill = new DXInfo.Models.Bills(); bill.Sum = d.Sum; bill.Voucher = d.Voucher; bill.Amount = d.Amount; bill.BillType = "NoMemberConsumeWindow"; bill.CreateDate = d.CreateDate; bill.DeptName = d.DeptName; bill.FullName = d.FullName; bill.PayTypeName = d.PayTypeName; bill.Cash = dCash; bill.Change = dChange; bill.DeskNo = txtDeskNo.Text; uow.Bills.Add(bill); uow.Commit(); foreach (var si in d.lSelInv) { DXInfo.Models.ConsumeList cl = new DXInfo.Models.ConsumeList(); cl.Amount = si.Amount; cl.Consume = consume.Id; cl.CreateDate = d.CreateDate; cl.Cup = si.Cup; cl.DeptId = d.DeptId; cl.Inventory = si.Id; cl.Price = si.SalePrice; cl.Quantity = si.Quantity; cl.UserId = d.UserId; uow.ConsumeList.Add(cl); DXInfo.Models.BillInvLists bl = new DXInfo.Models.BillInvLists(); bl.Amount = si.Amount; bl.Bill = bill.Id; bl.CupType = si.CupType; bl.Name = si.Name; bl.Quantity = si.Quantity; bl.SalePrice = si.SalePrice; bl.Tastes = si.Tastes; uow.BillInvLists.Add(bl); if (si.lTastes.Count > 0) { uow.Commit(); foreach (var lt in si.lTastes) { DXInfo.Models.ConsumeTastes ct = new DXInfo.Models.ConsumeTastes(); ct.ConsumeList = cl.Id; ct.Taste = lt.Id; uow.ConsumeTastes.Add(ct); } } } uow.Commit(); transaction.Complete(); } PrintDialog pDialog = new PrintDialog(); pDialog.PrintVisual(GridPrint, "非会员消费打印"); DialogResult = true; this.Close(); }
private void Bntprint_Click(object sender, RoutedEventArgs e) { PrintDialog printDlg = new PrintDialog(); printDlg.PrintVisual(dgGrade, "Grid Printing."); }
private void BTImprimer_Click(object sender, RoutedEventArgs e) { PrintDialog printDlg = new PrintDialog(); printDlg.PrintVisual(DataGridFournisseur, "Liste des fournisseurs"); }
private void OnPrintVisualClick(object sender, RoutedEventArgs e) { var printDlg = new PrintDialog(); printDlg.PrintVisual(this, "Main Window"); }
private void btnImprimer_Click(object sender, RoutedEventArgs e) { PrintDialog printDlg = new PrintDialog(); printDlg.PrintVisual(DataGridClient, "Liste des clients"); }
private void CtlMenuPrint_Click(object sender, RoutedEventArgs e) { var printDlg = new PrintDialog(); printDlg.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4); printDlg.PrintTicket.PageOrientation = PageOrientation.Landscape; RenderData(true, true, true); if (printDlg.ShowDialog() == true) { FrameworkElement visual = CtlMainContent; var capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket); double scaleX = capabilities.PageImageableArea.ExtentWidth / visual.ActualWidth; double scaleY = 1; // capabilities.PageImageableArea.ExtentHeight / visual.ActualHeight; double scale = Math.Min(scaleX, scaleY); var headerHeight = CtlParametersHeader.ActualHeight + CtlPageInfo.ActualHeight; //var parameterHeight = (CtlParameters.Children[0] as FrameworkElement).ActualHeight + (CtlParameters.Children[0] as UserControl).Margin.Top * 2; var parametersCount = CtlParameters.Children.Count; //var parametersPerPage = -1 + (int)((capabilities.PageImageableArea.ExtentHeight - headerHeight * scaleX) / (parameterHeight * scaleX)); //var pagesCount = (int)Math.Ceiling(parametersCount / (double)parametersPerPage); //for (int page = 0; page < pagesCount; ++page) int page = 0; int parameterIndex = 0; while (true) { int toPrint = 0; double pageHeight = headerHeight; for (int n = 0; n < parameterIndex; ++n) { var parameter = CtlParameters.Children[n]; parameter.Visibility = Visibility.Collapsed; } for (int n = parameterIndex; n < CtlParameters.Children.Count; ++n) { var parameter = CtlParameters.Children[n]; parameter.Visibility = Visibility.Visible; } int i = parameterIndex; for (; i < CtlParameters.Children.Count; ++i) { var parameter = CtlParameters.Children[i]; var parameterHeight = (parameter as FrameworkElement).ActualHeight + (parameter as UserControl).Margin.Top * 2; pageHeight += parameterHeight; if (pageHeight < capabilities.PageImageableArea.ExtentWidth - parameterHeight) { //parameter.Visibility = Visibility.Visible; ++toPrint; } else { break; } } for (int n = i; n < CtlParameters.Children.Count; ++n) { var parameter = CtlParameters.Children[n]; parameter.Visibility = Visibility.Collapsed; } parameterIndex = i; if (toPrint > 0) { //CtlPageInfo.Text = $"Страница: {page + 1}/{pagesCount}. Параметров: {toPrint}/{parametersCount}. Дата {DateTime.Now.ToString("dd MMM yyyy")}."; visual.LayoutTransform = null; visual.UpdateLayout(); visual.LayoutTransform = new ScaleTransform(scale, scale); var sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight); visual.Measure(sz); visual.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz)); //printDlg.PrintVisual(visual, $"Medical parameters. Page {page + 1}/{pagesCount}."); printDlg.PrintVisual(visual, $"Medical parameters. Page {page + 1}."); } else { break; } } for (int i = 0; i < CtlParameters.Children.Count; ++i) { CtlParameters.Children[i].Visibility = Visibility.Visible; } visual.LayoutTransform = null; visual.UpdateLayout(); } }
private void Button_Click(object sender, RoutedEventArgs e) { PrintDialog print = new PrintDialog(); print.PrintVisual(otch, ""); }
private void FileCmdExecuted(object sender, ExecutedRoutedEventArgs e) { RoutedCommand rc = e.Command as RoutedCommand; if (rc == null) { return; } switch (rc.Name) { case "Open": OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = WpfDemoHelperMethods.CreateDialogFilter(true); if (dlg.ShowDialog().Value) { this.AnnotationViewer.Open(dlg.FileName, 0, null); } break; case "SaveAs": SaveFileDialog save = new SaveFileDialog(); save.Filter = "JPEG (*.jpg)|*.jpg|TIFF (*.tif)|*.tif|PDF (*.pdf)|*.pdf"; if (save.ShowDialog().Value) { if (save.FilterIndex == 1) { SaveImage(save.FileName, new JpegEncoder()); } else if (save.FilterIndex == 2) { SaveImage(save.FileName, new TiffEncoder()); } else { if (AtalaImage.Edition == LicenseEdition.Document) { SaveImage(save.FileName, new PdfEncoder()); SavePdfAnnotations(save.FileName); } else { MessageBox.Show("A 'DotImage Document Imaging' license is required to save as PDF.", "License Required", MessageBoxButton.OK, MessageBoxImage.Information); } } } break; case "Print": PrintDialog pdlg = new PrintDialog(); if (pdlg.ShowDialog().Value) { PageMediaSize sz = pdlg.PrintTicket.PageMediaSize; pdlg.PrintVisual(this.AnnotationViewer.CreateVisual(new Size(sz.Width.HasValue ? sz.Width.Value : 0, sz.Height.HasValue ? sz.Height.Value : 0), _printScaleMode, new Thickness(10)), "WPF Annotation Printing"); } break; } }
private void print_btn_Click(object sender, RoutedEventArgs e) { PrintDialog pd = new PrintDialog(); pd.PrintVisual(this, "Plan Metrics Report"); }
//挂号 private void BtnRegister_Click(object sender, RoutedEventArgs e) { List <Control> con_list1 = new List <Control>() { txtRid, txtKid, txtOtherFei, cboIdType, cboSectionRoom, dtpRegisterTime, dtpSeeDoctorTime, cboDoctor, txtGuaHaoFei, txtName, txtAddress, cboCultrue, txtIdcardNo, txtPhone, cboWork, txtAge, cboNation, txtPostcode, rdoBoy, rdoGirl, rdoMarriageYes, rdoMarriageNo, dtpBirthday }; foreach (Control item in con_list1) { if (item is TextBox) { if (((TextBox)item).Text == "") { var p = new Tip("请填写完整信息!"); p.ShowDialog(); return; } } else if (item is ComboBox) { if (((ComboBox)item).Text == "") { var p = new Tip("请填写完整信息!"); p.ShowDialog(); return; } } else if (item is DatePicker) { if (((DatePicker)item).Text == "") { var p = new Tip("请填写完整信息!"); p.ShowDialog(); return; } } else { //if(((RadioButton)item).IsChecked == false) //{ // var p = new Tip("请填写完整信息!"); // p.ShowDialog(); // return; //} } } Register r = new Register { Rid = txtRid.Text, KId = int.Parse(txtKid.Text), IdType = cboIdType.Text, SectionRoom = cboSectionRoom.Text + "", Doctor = cboDoctor.Text, GuaDanFei = int.Parse(txtGuaHaoFei.Text), OtherFei = int.Parse(txtOtherFei.Text), ReristerTime = dtpRegisterTime.Text, SeeDoctorTime = dtpSeeDoctorTime.Text }; string s = new UsersBLL().RegisterRew(r); var t = new Tip(s); t.ShowDialog(); if (printList.IsChecked == true && s == "挂号成功") { PrintDialog dialog = new PrintDialog(); if (dialog.ShowDialog() == true) { dialog.PrintVisual(groupBox1, "打印挂号单"); } } }
/// <summary> /// The print to printer. /// </summary> /// <param name="canvas1"> /// The canvas 1. /// </param> /// <param name="canvas2"> /// The canvas 2. /// </param> /// <param name="canvas3"> /// The canvas 3. /// </param> /// <param name="canvas4"> /// The canvas 4. /// </param> /// <returns> /// The <see cref="BitmapSource"/>. /// </returns> public static BitmapSource PrintToPrinter(Canvas canvas1, Canvas canvas2, Canvas canvas3, Canvas canvas4) { var rtb1 = new RenderTargetBitmap( (int)Math.Round(canvas1.ActualWidth, 0), (int)Math.Round(canvas1.ActualHeight, 0), 96.0, 96.0, PixelFormats.Pbgra32); ModifyPosition(canvas1); rtb1.Render(canvas1); ModifyPositionBack(canvas1); var pixels1 = new byte[rtb1.PixelWidth * rtb1.PixelHeight * rtb1.Format.BitsPerPixel / 8]; rtb1.CopyPixels(pixels1, (rtb1.PixelWidth * rtb1.Format.BitsPerPixel) / 8, 0); var rtb2 = new RenderTargetBitmap( (int)Math.Round(canvas2.ActualWidth, 0), (int)Math.Round(canvas2.ActualHeight, 0), 96.0, 96.0, PixelFormats.Pbgra32); ModifyPosition(canvas2); rtb2.Render(canvas2); ModifyPositionBack(canvas2); var pixels2 = new byte[rtb2.PixelWidth * rtb2.PixelHeight * rtb2.Format.BitsPerPixel / 8]; rtb2.CopyPixels(pixels2, (rtb2.PixelWidth * rtb2.Format.BitsPerPixel) / 8, 0); var rtb3 = new RenderTargetBitmap( (int)Math.Round(canvas3.ActualWidth, 0), (int)Math.Round(canvas3.ActualHeight, 0), 96.0, 96.0, PixelFormats.Pbgra32); ModifyPosition(canvas3); rtb3.Render(canvas3); ModifyPositionBack(canvas3); var pixels3 = new byte[rtb3.PixelWidth * rtb3.PixelHeight * rtb3.Format.BitsPerPixel / 8]; rtb3.CopyPixels(pixels3, (rtb3.PixelWidth * rtb3.Format.BitsPerPixel) / 8, 0); var rtb4 = new RenderTargetBitmap( (int)Math.Round(canvas4.ActualWidth, 0), (int)Math.Round(canvas4.ActualHeight, 0), 96.0, 96.0, PixelFormats.Pbgra32); ModifyPosition(canvas4); rtb4.Render(canvas4); ModifyPositionBack(canvas4); var pixels4 = new byte[rtb4.PixelWidth * rtb4.PixelHeight * rtb4.Format.BitsPerPixel / 8]; rtb4.CopyPixels(pixels4, (rtb4.PixelWidth * rtb4.Format.BitsPerPixel) / 8, 0); var wb = new WriteableBitmap( rtb1.PixelWidth + rtb2.PixelWidth, rtb1.PixelHeight + rtb3.PixelHeight, 96.0, 96.0, PixelFormats.Pbgra32, null); wb.WritePixels( new Int32Rect(0, 0, rtb1.PixelWidth, rtb1.PixelHeight), pixels1, (rtb1.PixelWidth * rtb1.Format.BitsPerPixel) / 8, 0); wb.WritePixels( new Int32Rect(rtb1.PixelWidth, 0, rtb2.PixelWidth, rtb2.PixelHeight), pixels2, (rtb2.PixelWidth * rtb2.Format.BitsPerPixel) / 8, 0); wb.WritePixels( new Int32Rect(0, rtb1.PixelHeight, rtb3.PixelWidth, rtb3.PixelHeight), pixels3, (rtb3.PixelWidth * rtb3.Format.BitsPerPixel) / 8, 0); wb.WritePixels( new Int32Rect(rtb3.PixelWidth, rtb2.PixelHeight, rtb4.PixelWidth, rtb4.PixelHeight), pixels4, (rtb4.PixelWidth * rtb4.Format.BitsPerPixel) / 8, 0); var d = new PrintDialog(); if (d.ShowDialog() == true) { var img = new Image(); var b = new Border(); b.Padding = new Thickness(1 * 96.0 / 2.54); b.Child = img; img.Source = wb; b.Measure(new Size(d.PrintableAreaWidth, d.PrintableAreaHeight)); b.Arrange(new Rect(new Point(0, 0), new Size(d.PrintableAreaWidth, d.PrintableAreaHeight))); d.PrintVisual(b, "Print canvases"); } return(wb); }
void PrintOnClick(object sender, RoutedEventArgs args) { PrintDialog dlg = new PrintDialog(); if ((bool)dlg.ShowDialog().GetValueOrDefault()) { // Create Grid panel. Grid grid = new Grid(); // Define five auto-sized rows and columns. for (int i = 0; i < 5; i++) { ColumnDefinition coldef = new ColumnDefinition(); coldef.Width = GridLength.Auto; grid.ColumnDefinitions.Add(coldef); RowDefinition rowdef = new RowDefinition(); rowdef.Height = GridLength.Auto; grid.RowDefinitions.Add(rowdef); } // Give the Grid a gradient brush. grid.Background = new LinearGradientBrush(Colors.Gray, Colors.White, new Point(0, 0), new Point(1, 1)); // Every program needs a bit of randomness. Random rand = new Random(); // Fill the Grid with 25 buttons. for (int i = 0; i < 25; i++) { Button btn = new Button(); btn.FontSize = 12 + rand.Next(8); btn.Content = "Button No. " + (i + 1); btn.HorizontalAlignment = HorizontalAlignment.Center; btn.VerticalAlignment = VerticalAlignment.Center; btn.Margin = new Thickness(6); grid.Children.Add(btn); Grid.SetRow(btn, i % 5); Grid.SetColumn(btn, i / 5); } // Size the Grid. grid.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); Size sizeGrid = grid.DesiredSize; // Determine point for centering Grid on page. Point ptGrid = new Point((dlg.PrintableAreaWidth - sizeGrid.Width) / 2, (dlg.PrintableAreaHeight - sizeGrid.Height) / 2); // Layout pass. grid.Arrange(new Rect(ptGrid, sizeGrid)); // Now print it. dlg.PrintVisual(grid, Title); } }
private void Button_Click(object sender, RoutedEventArgs e) { if (IsPrint) { PrintDialog pDialog1 = new PrintDialog(); pDialog1.PrintVisual(GridPrint, "会员积分兑换打印"); DialogResult = true; this.Close(); return; } dynamic d = GridPrint.DataContext; using (TransactionScope transaction = new TransactionScope()) { DXInfo.Models.Consume consume = new DXInfo.Models.Consume(); consume.Card = d.Id; consume.Sum = d.Amount; consume.Discount = 100; consume.Amount = d.Amount; consume.Balance = d.Balance; consume.CreateDate = d.CreateDate; consume.DeptId = d.DeptId; consume.LastBalance = d.LastBalance; consume.UserId = d.UserId; consume.ConsumeType = 2; uow.Consume.Add(consume); DXInfo.Models.Bills bill = new DXInfo.Models.Bills(); bill.Amount = d.Amount; bill.Balance = d.Balance; bill.BillType = "PointsExchangeWindow"; bill.CardNo = d.CardNo; bill.CreateDate = d.CreateDate; bill.DeptName = d.DeptName; bill.FullName = d.FullName; bill.LastBalance = d.LastBalance; bill.MemberName = d.MemberName; uow.Bills.Add(bill); uow.Commit(); Guid cid = d.Id; var p = uow.CardPoints.GetAll().Where(w => w.Card == cid); decimal dkp = 0; foreach (DXInfo.Models.CardPoints cp in p) { if (cp.Point > d.Amount - dkp) { dkp = d.Amount; cp.Point = cp.Point - d.Amount; break; } else { dkp += cp.Point; cp.Point = 0; } } foreach (var si in d.lSelInv) { DXInfo.Models.ConsumeList cl = new DXInfo.Models.ConsumeList(); cl.Amount = si.Amount; cl.Consume = consume.Id; cl.CreateDate = d.CreateDate; cl.Cup = si.Cup; cl.DeptId = d.DeptId; cl.Inventory = si.Id; cl.Price = si.SalePoint; cl.Quantity = si.Quantity; cl.UserId = d.UserId; uow.ConsumeList.Add(cl); DXInfo.Models.BillInvLists bl = new DXInfo.Models.BillInvLists(); bl.Amount = si.Amount; bl.Bill = bill.Id; bl.CupType = si.CupType; bl.Name = si.Name; bl.Quantity = si.Quantity; bl.SalePrice = si.SalePoint; bl.Tastes = si.Tastes; uow.BillInvLists.Add(bl); if (si.lTastes.Count > 0) { uow.Commit(); foreach (var lt in si.lTastes) { DXInfo.Models.ConsumeTastes ct = new DXInfo.Models.ConsumeTastes(); ct.ConsumeList = cl.Id; ct.Taste = lt.Id; uow.ConsumeTastes.Add(ct); } } } uow.Commit(); transaction.Complete(); } PrintDialog pDialog = new PrintDialog(); pDialog.PrintVisual(GridPrint, "会员积分兑换打印"); DialogResult = true; this.Close(); }
public OrderMenuForm(OrderMenuList orderMenuList, string TableNumber) { InitializeComponent(); ordermenu = orderMenuList; var ItemCOL = OrderMenu.Items; SolveCoder(); int CountComboItem = 0; foreach (TextBlock tblkcombo in comboBox.Items) { if (tblkcombo.Text.Contains(TableNumber)) { break; } CountComboItem++; } comboBox.SelectionChanged += ComboBox_SelectionChanged; comboBox.SelectedIndex = CountComboItem; ListBox PrintBox = new Printform().Content as ListBox; string Uid = OrderMenu.Uid = DateTime.Now.ToString("HHmmssMMdd"); TextBlock tbnbk = new TextBlock(); tbnbk.FontSize = 16; tbnbk.Text = "桌號 : " + (comboBox.SelectedItem as TextBlock).Text + " " + Uid + OrderCode.ToString("D2"); //MessageBox.Show(tbnbk.Text); PrintBox.Items.Add(tbnbk); int Amount = 0; foreach (myItem x in orderMenuList.GetItems()) { x.vblk2text = new Viewbox(); TextBlock textblk = new TextBlock(); textblk.FontSize = 18; x.ck.Height = 24; x.ck.Children.Add(x.vblk2text); x.vblk2text.Child = textblk; x.vblk2text.PreviewMouseLeftButtonUp += previewMouseLeftButtonUP; if (x.Count != 1) { textblk.Text = x.IName + "*" + x.Count; } else { textblk.Text = x.IName; } ItemCOL.Insert(ItemCOL.Count - 1, x); Amount += x.Count * x.Price; TextBlock tbnlk = new TextBlock(); tbnlk.Text = x.IName + "(" + x.Price + ")" + "*" + x.Count; tbnlk.FontSize = 20; PrintBox.Items.Add(tbnlk); if (GlobalInfo.isItemSpecial(x.IName)) { continue; } bool isContain = false; foreach (var cg in GlobalInfo.TotalOrderListBox.Items) { try { if ((cg as CountGrid).linkItem.IName.Equals(x.IName)) { isContain = true; (cg as CountGrid).KindCount += x.Count; break; } } catch { } } if (!isContain) { GlobalInfo.TotalOrderListBox.Items.Add(new CountGrid(x)); } } TextBlock tbAmount = new TextBlock(); tbAmount.Text = "總價 : " + Amount.ToString(); tbAmount.FontSize = 24; tbAmount.HorizontalAlignment = HorizontalAlignment.Right; PrintBox.Items.Add(tbAmount); PrintDialog pd = new PrintDialog(); pd.PrintVisual(PrintBox, OrderMenu.Uid); //InitialStatusListBox = SerializeObj.DeepCopy<ListBox>(OrderMenu); StatusSteps = new List <myItem>(); }
private void btnPrint_Click(object sender, RoutedEventArgs e) { PrintDialog dialog = new PrintDialog(); dialog.PrintVisual(borderMeasure, "mesure"); }
//打印 private void btPrint_Click(object sender, RoutedEventArgs e) { Cursor = Cursors.Wait; if (lvList.Items.Count > 0) { Drug[] ds = lvList.ItemsSource as Drug[]; PrintDialog pd = new PrintDialog(); DrawingVisual dv = new DrawingVisual(); using (DrawingContext dc = dv.RenderOpen()) { double space_X = 20; double space_Y = 10; double size_G = 16; double size_L = 14; double wide_Col = 40; //标题 FormattedText title = new FormattedText("加药清单-" + DateTime.Now.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Microsoft YaHei"), size_G, Brushes.Black); dc.DrawText(title, new Point((pd.PrintableAreaWidth - title.Width) / 2, space_Y));//居中 space_Y += title.Height; //横线 dc.DrawLine(new Pen(Brushes.Black, 1), new Point(space_X, space_Y), new Point(pd.PrintableAreaWidth - space_X, space_Y)); //列标题 FormattedText col_1 = new FormattedText("缺药", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Microsoft YaHei"), size_L, Brushes.Black); dc.DrawText(col_1, new Point(space_X + (wide_Col - col_1.Width) / 2, space_Y)); FormattedText col_2 = new FormattedText("名称/规格/厂家", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Microsoft YaHei"), size_L, Brushes.Black); dc.DrawText(col_2, new Point(space_X + wide_Col + 10, space_Y)); //3条竖线 dc.DrawLine(new Pen(Brushes.Black, 1), new Point(space_X, space_Y), new Point(space_X, space_Y + col_2.Height)); dc.DrawLine(new Pen(Brushes.Black, 1), new Point(space_X + wide_Col, space_Y), new Point(space_X + wide_Col, space_Y + col_2.Height)); dc.DrawLine(new Pen(Brushes.Black, 1), new Point(pd.PrintableAreaWidth - space_X, space_Y), new Point(pd.PrintableAreaWidth - space_X, space_Y + col_2.Height)); space_Y += col_2.Height; //横线 dc.DrawLine(new Pen(Brushes.Black, 1), new Point(space_X, space_Y), new Point(pd.PrintableAreaWidth - space_X, space_Y)); //循环 foreach (Drug d in ds) { //名称 FormattedText name = new FormattedText(d.DrugName, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Microsoft YaHei"), size_L, Brushes.Black); dc.DrawText(name, new Point(space_X + wide_Col + 10, space_Y)); dc.DrawLine(new Pen(Brushes.Black, 1), new Point(space_X + wide_Col, space_Y), new Point(pd.PrintableAreaWidth - space_X, space_Y)); //规格 FormattedText spec = new FormattedText(d.DrugSpec, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Microsoft YaHei"), size_L, Brushes.Black); dc.DrawText(spec, new Point(space_X + wide_Col + 10, space_Y + name.Height)); dc.DrawLine(new Pen(Brushes.Black, 1), new Point(space_X + wide_Col, space_Y + name.Height), new Point(pd.PrintableAreaWidth - space_X, space_Y + name.Height)); //厂家 FormattedText fac = new FormattedText(d.DrugFactory, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Microsoft YaHei"), size_L, Brushes.Black); dc.DrawText(fac, new Point(space_X + wide_Col + 10, space_Y + name.Height * 2)); dc.DrawLine(new Pen(Brushes.Black, 1), new Point(space_X + wide_Col, space_Y + name.Height * 2), new Point(pd.PrintableAreaWidth - space_X, space_Y + name.Height * 2)); //缺药 FormattedText num = new FormattedText(d.Short.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Microsoft YaHei"), 30, Brushes.Black); dc.DrawText(num, new Point(space_X + (wide_Col - num.Width) / 2, space_Y + (name.Height * 3 - num.Height) / 2)); //三条竖线 dc.DrawLine(new Pen(Brushes.Black, 1), new Point(space_X, space_Y), new Point(space_X, space_Y + name.Height * 3)); dc.DrawLine(new Pen(Brushes.Black, 1), new Point(space_X + wide_Col, space_Y), new Point(space_X + wide_Col, space_Y + name.Height * 3)); dc.DrawLine(new Pen(Brushes.Black, 1), new Point(pd.PrintableAreaWidth - space_X, space_Y), new Point(pd.PrintableAreaWidth - space_X, space_Y + name.Height * 3)); //横线 dc.DrawLine(new Pen(Brushes.Black, 1), new Point(space_X, space_Y + name.Height * 3), new Point(pd.PrintableAreaWidth - space_X, space_Y + name.Height * 3)); space_Y += name.Height * 3; } //空白 FormattedText n = new FormattedText(".", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Microsoft YaHei"), size_L, Brushes.Black); dc.DrawText(n, new Point(space_X, space_Y + n.Height)); dc.DrawText(n, new Point(space_X, space_Y + n.Height * 2)); } pd.PrintVisual(dv, ""); } Cursor = null; }
public static void printReportNew(Order order) { Family f = Family.GetFamilyByID(order.FamilyID.Value); TextBlock tb = new TextBlock(); tb.FontFamily = new System.Windows.Media.FontFamily("Arial"); tb.Inlines.Add(new Bold(new Run("جمعية الإحسان الخيرية التنموية بحلب"))); tb.Inlines.Add(new LineBreak()); tb.Inlines.Add(new LineBreak()); tb.Inlines.Add(new Run("التاريخ " + order.Date.Value.ToString("dd/MM/yyyy hh:mm"))); tb.Inlines.Add(new LineBreak()); tb.Inlines.Add(new Run("المسلم " + User.GetUserNameByID(order.LastUserID))); tb.Inlines.Add(new LineBreak()); tb.Inlines.Add(new Run("رمز العائلة " + f.FamilyCode)); tb.Inlines.Add(new LineBreak()); tb.Inlines.Add(new Run("اسم العائلة " + f.FamilyName)); tb.Inlines.Add(new LineBreak()); if (order.NextOrderDate.HasValue) { tb.Inlines.Add(new Run("الاستلام القادم " + order.NextOrderDate.Value.ToString("dd-MM-yyyy"))); tb.Inlines.Add(new LineBreak()); } tb.Inlines.Add(new Underline(new Run("المواد المسلّمة :"))); tb.Inlines.Add(new LineBreak()); // Add some Bold text to the paragraph for (int i = 0; i < order.OIs.Count; i++) { var x = order.OIs[i].Item; tb.Inlines.Add(new Run(x.Source + " " + x.Name + "\t (" + order.OIs[i].Quantity + ")")); tb.Inlines.Add(new LineBreak()); } tb.Margin = new Thickness(5, 2, 5, 2); tb.FontSize = 12; Grid g = new Grid(); g.FlowDirection = FlowDirection.RightToLeft; g.Children.Add(tb); // Create the print dialog object and set options PrintDialog pDialog = new PrintDialog(); pDialog.PageRangeSelection = PageRangeSelection.AllPages; pDialog.UserPageRangeEnabled = true; pDialog.PrintQueue = System.Printing.LocalPrintServer.GetDefaultPrintQueue(); pDialog.PrintTicket = pDialog.PrintQueue.DefaultPrintTicket; pDialog.PrintTicket.PageScalingFactor = 1; System.Printing.PrintCapabilities capabilities = null; try { capabilities = pDialog.PrintQueue.GetPrintCapabilities(pDialog.PrintTicket); } catch { capabilities = null; } Viewbox vb = new Viewbox(); vb.Child = g; System.Windows.Size sz = new System.Windows.Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight); vb.MinWidth = 1; vb.MinHeight = 1; vb.Measure(sz); vb.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz)); double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / vb.ActualWidth, capabilities.PageImageableArea.ExtentHeight / vb.ActualHeight); vb.LayoutTransform = new ScaleTransform(scale, scale); pDialog.PrintVisual(vb, "MyViewBox"); }
private void Print_Click(object sender, RoutedEventArgs e) { var printDLG = new PrintDialog(); var arrayOfModels = new Model.TextModel[] { new Model.TextModel(numTextBox.Text, 590, 120), new Model.TextModel(day.Text, 195, 140), new Model.TextModel(month.Text, 280, 140), new Model.TextModel(year.Text, 380, 140), new Model.TextModel(carBrand.Text, 240, 240), new Model.TextModel(licensePlate.Text, 330, 260), new Model.TextModel(driver.Text, 180, 280), new Model.TextModel(certificate.Text, 230, 310), new Model.TextModel(persNum.Text, 890, 275), new Model.TextModel(departure.Text, 190, 513), new Model.TextModel(returns.Text, 190, 535), new Model.TextModel(orderBySome.Text, 150, 650), //new Model.TextModel(workType.Text, 0, 0), //new Model.TextModel(dispatcherSign.Text, 0, 0), //new Model.TextModel(mechanicSign.Text, 0, 0), //new Model.TextModel(driverSign.Text, 0, 0), //new Model.TextModel(passedDriver.Text, 0, 0), //new Model.TextModel(acceptedMech.Text, 0, 0) }; var arrayOfTextBlocks = new TextBlock[arrayOfModels.Length]; if (printDLG.ShowDialog() == true) { try { var index = 0; foreach (var item in arrayOfModels) { var textBlock = new TextBlock(); textBlock.Inlines.Add(item.Content); textBlock.Margin = new Thickness(item.Xposition, item.YPosition, 0, 0); var pageSize = new Size(printDLG.PrintableAreaWidth, printDLG.PrintableAreaHeight); textBlock.Measure(pageSize); textBlock.Arrange(new Rect(item.Xposition, item.YPosition, pageSize.Width, pageSize.Height)); arrayOfTextBlocks[index] = textBlock; index++; } var tempGrid = new Grid(); foreach (var item in arrayOfTextBlocks) { tempGrid.Children.Add(item); } printDLG.PrintVisual(tempGrid, "Visual element printing (VS)"); } catch (Exception exception) { MessageBox.Show($"ОШИБКА: {exception.Message}. Свяжитесь с разработчиком!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } } }
internal static void printReportA6(Order o) { try { if (o.Type < 3) { var uc = LoadTemplate(Path.Combine(Environment.CurrentDirectory, "VoucherReportTemplate.xaml")) as UserControl; uc.DataContext = o; (uc.FindName("Items") as ItemsControl).ItemsSource = from x in o.OIs select new { ItemName = x.Item.Name, Quantity = x.Quantity, StandardUnit = x.Item.StandardUnit }; (uc.FindName("txtTag") as TextBlock).Text = "1/1"; (uc.FindName("txtHeader") as TextBlock).Text = Properties.Settings.Default.VoucherHeaderText; (uc.FindName("grdFamily") as Grid).Visibility = Visibility.Collapsed; (uc.FindName("grdOrder") as Grid).Visibility = Visibility.Visible; var img = uc.FindName("img") as Image; BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(Properties.Settings.Default.AssociationLogoPath, UriKind.RelativeOrAbsolute); bitmap.EndInit(); img.Source = bitmap; // Create the print dialog object and set options PrintDialog pDialog = new PrintDialog(); pDialog.PageRangeSelection = PageRangeSelection.AllPages; pDialog.UserPageRangeEnabled = true; pDialog.PrintQueue = System.Printing.LocalPrintServer.GetDefaultPrintQueue(); pDialog.PrintTicket = pDialog.PrintQueue.DefaultPrintTicket; pDialog.PrintTicket.PageScalingFactor = 1; System.Printing.PrintCapabilities capabilities = null; try { capabilities = pDialog.PrintQueue.GetPrintCapabilities(pDialog.PrintTicket); } catch { capabilities = null; } Viewbox vb = new Viewbox(); vb.Child = uc; System.Windows.Size sz = new Size(520, 380); vb.MinWidth = 1; vb.MinHeight = 1; vb.Measure(sz); vb.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz)); double scale = 1; vb.LayoutTransform = new ScaleTransform(scale, scale); pDialog.PrintVisual(vb, "MyViewBox"); } else if (o.Type == 3) { var dtVoucherCriteria = BaseDataBase._Tabling($@"select IsNull(GroupID,-1) GroupID,Item.Name ItemName, Quantity, StandardUnit from (select ItemID, Quantity from Order_Item where OrderID = {o.Id}) t1 inner join Item on t1.ItemID = item.Id left outer join VoucherCriteria t2 on t1.ItemID = t2.ItemID"); if (dtVoucherCriteria != null && dtVoucherCriteria.Rows.Count > 0) { List <DataTable> subTables = dtVoucherCriteria.AsEnumerable().GroupBy(row => row.Field <int>("GroupID")).Select(g => g.CopyToDataTable()).ToList(); if (subTables.Count > 1) { MyMessageBox.Show("ستم طباعة " + subTables.Count + " وصل"); } var dt = BaseDataBase._Tabling($@"select OrderCode Id,[Order].Barcode, dbo.GetInventory(InventoryID) InventoryName,dbo.fn_getSectorByOrderID([Order].Id) Sector, Family.FamilyID FamilyCode, case when FatherName is not null then FatherName else (case when MotherName is not null then MotherName else FamilyName end) end as FatherName, case when FatherPID is not null then FatherPID else (case when MotherPID is not null then MotherPID else 'لايوجد رقم وطني' end) end as PID, NextOrderDate, Date, Users.Name Presenter from [Order] inner join Family on [Order].Id = {o.Id} and Family.FamilyID = [Order].FamilyID inner join Users on Users.Id = [Order].LastUserID left outer join (select FirstName + ' ' + IsNUll(LastName,'') FatherName ,PID FatherPID, FamilyID from Parent where Gender like N'ذكر') x on x.FamilyID = [Order].FamilyID left outer join (select FirstName + ' ' + IsNUll(LastName,'') MotherName ,PID MotherPID, FamilyID from Parent where Gender like N'أنثى') y on y.FamilyID = [Order].FamilyID"); for (int i = 0; i < subTables.Count; i++) { var uc = LoadTemplate(Path.Combine(Environment.CurrentDirectory, "VoucherReportTemplate.xaml")) as UserControl; uc.DataContext = null; uc.DataContext = dt.DefaultView; (uc.FindName("Items") as ItemsControl).ItemsSource = subTables[i].DefaultView; (uc.FindName("txtTag") as TextBlock).Text = (i + 1) + "/" + subTables.Count; (uc.FindName("txtHeader") as TextBlock).Text = Properties.Settings.Default.VoucherHeaderText; var img = uc.FindName("img") as Image; BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(Properties.Settings.Default.AssociationLogoPath, UriKind.RelativeOrAbsolute); bitmap.EndInit(); img.Source = bitmap; // Create the print dialog object and set options PrintDialog pDialog = new PrintDialog(); pDialog.PageRangeSelection = PageRangeSelection.AllPages; pDialog.UserPageRangeEnabled = true; pDialog.PrintQueue = System.Printing.LocalPrintServer.GetDefaultPrintQueue(); pDialog.PrintTicket = pDialog.PrintQueue.DefaultPrintTicket; pDialog.PrintTicket.PageScalingFactor = 1; System.Printing.PrintCapabilities capabilities = null; try { capabilities = pDialog.PrintQueue.GetPrintCapabilities(pDialog.PrintTicket); } catch { capabilities = null; } Viewbox vb = new Viewbox(); vb.Child = uc; System.Windows.Size sz = new Size(520, 380); vb.MinWidth = 1; vb.MinHeight = 1; vb.Measure(sz); vb.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz)); double scale = 1; vb.LayoutTransform = new ScaleTransform(scale, scale); pDialog.PrintVisual(vb, "MyViewBox"); } } } else { var dtVoucherCriteria = BaseDataBase._Tabling($@"select IsNull(GroupID,-1) GroupID,Item.Name ItemName, Quantity, StandardUnit from (select ItemID, Quantity from Order_Item where OrderID = {o.Id}) t1 inner join Item on t1.ItemID = item.Id left outer join VoucherCriteria t2 on t1.ItemID = t2.ItemID"); if (dtVoucherCriteria != null && dtVoucherCriteria.Rows.Count > 0) { List <DataTable> subTables = dtVoucherCriteria.AsEnumerable().GroupBy(row => row.Field <int>("GroupID")).Select(g => g.CopyToDataTable()).ToList(); if (subTables.Count > 1) { MyMessageBox.Show("ستم طباعة " + subTables.Count + " وصل"); } var dt = BaseDataBase._Tabling($@"select OrderCode Id,[Order].Barcode, dbo.GetInventory(InventoryID) InventoryName,'عائلة خاصة' Sector, SpecialFamily.Id FamilyCode, SpecialFamily.Name FatherName, PID, Date, Users.Name Presenter from [Order] inner join SpecialFamily on [Order].Id = {o.Id} and SpecialFamily.Id = [Order].SpecialFamilyID inner join Users on Users.Id = [Order].LastUserID"); for (int i = 0; i < subTables.Count; i++) { var uc = LoadTemplate(Path.Combine(Environment.CurrentDirectory, "VoucherReportTemplate.xaml")) as UserControl; uc.DataContext = null; uc.DataContext = dt; (uc.FindName("Items") as ItemsControl).ItemsSource = subTables[i].DefaultView; (uc.FindName("txtTag") as TextBlock).Text = (i + 1) + "/" + subTables.Count; (uc.FindName("txtHeader") as TextBlock).Text = Properties.Settings.Default.VoucherHeaderText; //(uc.FindName("Items") as ItemsControl).ItemsSource = from x in o.OIs select new { ItemName = x.Item.Name, Quantity = x.Quantity, StandardUnit = x.Item.StandardUnit }; //(uc.FindName("txtTag") as TextBlock).Text = "1/1"; var img = uc.FindName("img") as Image; BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(Properties.Settings.Default.AssociationLogoPath, UriKind.RelativeOrAbsolute); bitmap.EndInit(); img.Source = bitmap; // Create the print dialog object and set options PrintDialog pDialog = new PrintDialog(); pDialog.PageRangeSelection = PageRangeSelection.AllPages; pDialog.UserPageRangeEnabled = true; pDialog.PrintQueue = System.Printing.LocalPrintServer.GetDefaultPrintQueue(); pDialog.PrintTicket = pDialog.PrintQueue.DefaultPrintTicket; pDialog.PrintTicket.PageScalingFactor = 1; System.Printing.PrintCapabilities capabilities = null; try { capabilities = pDialog.PrintQueue.GetPrintCapabilities(pDialog.PrintTicket); } catch { capabilities = null; } Viewbox vb = new Viewbox(); vb.Child = uc; System.Windows.Size sz = new Size(520, 380); vb.MinWidth = 1; vb.MinHeight = 1; vb.Measure(sz); vb.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz)); double scale = 1; vb.LayoutTransform = new ScaleTransform(scale, scale); pDialog.PrintVisual(vb, "MyViewBox"); } } } } catch (Exception ex) { MyMessageBox.Show(ex.Message); } }
private void BTImprimer_Click(object sender, RoutedEventArgs e) { PrintDialog printDlg = new PrintDialog(); printDlg.PrintVisual(DataGridArticle, "Liste des produits"); }
internal static void printInvoiceA6(Invoice i, int Type) { try { var uc = LoadTemplate(Path.Combine(Environment.CurrentDirectory, "InvoiceReportTemplate.xaml")) as UserControl; (uc.FindName("txtHeader") as TextBlock).Text = Properties.Settings.Default.VoucherHeaderText; var img = uc.FindName("img") as Image; BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(Properties.Settings.Default.AssociationLogoPath, UriKind.RelativeOrAbsolute); bitmap.EndInit(); img.Source = bitmap; if (Type == 1) { uc.DataContext = BaseDataBase._Tabling($@"select Description, Barcode, TotalValue, Serial, Receiver, ReceiverPID, dbo.GetUserByID(LastUserID) UserName, CreateDate, (select Name from Account where ID = {i.Transitions[0].LeftAccount.Id.Value}) SponsorName from Invoice where Id = {i.ID.Value}"); (uc.FindName("grdSponsor") as Grid).Visibility = Visibility.Visible; } else if (Type == 2) { var dv = BaseDataBase._Tabling($@"select Description, Barcode, TotalValue, Serial, Receiver, ReceiverPID, dbo.GetUserByID(LastUserID) UserName, CreateDate from Invoice where Id = {i.ID.Value}"); (uc.FindName("icOrphans") as ItemsControl).ItemsSource = BaseDataBase._Tabling($@"select FirstName + ' ' + ISNULL(LastName,'') OrphanName, orphan.Type, Value, Sponsor.Name SponsorName from orphan inner join Account on Account.Type >= 2 and OwnerID = OrphanID inner join Transition on InvoiceID = {i.ID.Value} and Account.Id = RightAccount inner join (select * from Sponsorship where ID in (select Max(ID) from Sponsorship group by OrphanID)) Sponsorship on Sponsorship.OrphanID = Orphan.OrphanID inner join AvailableSponsorship on AvailableSponsorship.Id = Sponsorship.AvailableSponsorshipID inner join Sponsor on AvailableSponsorship.SponsorID = Sponsor.SponsorID").DefaultView; uc.DataContext = dv; (uc.FindName("grdOrphan") as Grid).Visibility = Visibility.Visible; var w = new ToWord(decimal.Parse(dv.Rows[0]["TotalValue"].ToString()), new CurrencyInfo(CurrencyInfo.Currencies.Syria)); (uc.FindName("TotalValueWord") as TextBlock).Text = w.ConvertToArabic(); } // Create the print dialog object and set options PrintDialog pDialog = new PrintDialog(); pDialog.PageRangeSelection = PageRangeSelection.AllPages; pDialog.UserPageRangeEnabled = true; pDialog.PrintQueue = System.Printing.LocalPrintServer.GetDefaultPrintQueue(); pDialog.PrintTicket = pDialog.PrintQueue.DefaultPrintTicket; pDialog.PrintTicket.PageScalingFactor = 1; System.Printing.PrintCapabilities capabilities = null; try { capabilities = pDialog.PrintQueue.GetPrintCapabilities(pDialog.PrintTicket); } catch { capabilities = null; } Viewbox vb = new Viewbox(); vb.Child = uc; System.Windows.Size sz = new Size(520, 380); vb.MinWidth = 1; vb.MinHeight = 1; vb.Measure(sz); vb.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz)); double scale = 1; vb.LayoutTransform = new ScaleTransform(scale, scale); pDialog.PrintVisual(vb, "MyViewBox"); } catch (Exception ex) { MyMessageBox.Show(ex.Message); } }
private void btnPrint_Click(object sender, System.Windows.RoutedEventArgs e) { PrintDialog printDlg = new PrintDialog(); printDlg.PrintVisual(dtgLaporan, "Riwayat Transaksi Penjualan Pulsa"); }
public static void printReport(Order order, BitmapImage bi) { try { Family f = Family.GetFamilyByID(order.FamilyID.Value); Paragraph paragraph3 = new Paragraph(); paragraph3.FlowDirection = FlowDirection.RightToLeft; paragraph3.Inlines.Add(new Bold(new Run(Properties.Settings.Default.VoucherHeaderText))); paragraph3.Inlines.Add(new LineBreak()); paragraph3.Inlines.Add(new LineBreak()); paragraph3.Inlines.Add(new Run("التاريخ " + order.Date.Value.ToString("dd/MM/yyyy hh:mm"))); paragraph3.Inlines.Add(new LineBreak()); paragraph3.Inlines.Add(new Run("المسلم " + User.GetUserNameByID(order.LastUserID))); paragraph3.Inlines.Add(new LineBreak()); paragraph3.Inlines.Add(new Run("رمز العائلة " + f.FamilyCode)); paragraph3.Inlines.Add(new LineBreak()); paragraph3.Inlines.Add(new Run("اسم العائلة " + f.FamilyName)); paragraph3.Inlines.Add(new LineBreak()); if (order.NextOrderDate.HasValue) { paragraph3.Inlines.Add(new Run("الاستلام القادم " + order.NextOrderDate.Value.ToString("dd-MM-yyyy"))); paragraph3.Inlines.Add(new LineBreak()); } paragraph3.Inlines.Add(new Underline(new Run("المواد المسلّمة :"))); paragraph3.Inlines.Add(new LineBreak()); for (int i = 0; i < order.OIs.Count; i++) { var x = order.OIs[i].Item; paragraph3.Inlines.Add(new Run(x.Source + " " + x.Name + "\t (" + order.OIs[i].Quantity + ")")); paragraph3.Inlines.Add(new LineBreak()); } paragraph3.FontFamily = new FontFamily("Arial"); paragraph3.FontSize = 16; FlowDocumentScrollViewer temp = new FlowDocumentScrollViewer(); temp.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled; FlowDocument myFlowDocument = new FlowDocument(); temp.FlowDirection = FlowDirection.RightToLeft; myFlowDocument.FlowDirection = FlowDirection.RightToLeft; paragraph3.FlowDirection = FlowDirection.RightToLeft; paragraph3.Inlines.Add(new Underline(new Run("بصمة المستلم"))); myFlowDocument.Blocks.Add(paragraph3); // myFlowDocument.Blocks.Add(paragraph4); myFlowDocument.Blocks.Add(new BlockUIContainer(new Image() { Source = bi, Height = 100, Stretch = Stretch.Uniform })); FlowDocumentReader myFlowDocumentReader = new FlowDocumentReader(); myFlowDocumentReader.Document = myFlowDocument; myFlowDocumentReader.FlowDirection = FlowDirection.RightToLeft; temp.Document = myFlowDocument; temp.FlowDirection = FlowDirection.RightToLeft; temp.HorizontalAlignment = HorizontalAlignment.Center; temp.Width = 250; temp.Height = 285 + (order.OIs.Count * 21); PrintDialog pDialog = new PrintDialog(); pDialog.PageRangeSelection = PageRangeSelection.AllPages; pDialog.UserPageRangeEnabled = true; pDialog.PrintQueue = System.Printing.LocalPrintServer.GetDefaultPrintQueue(); pDialog.PrintTicket = pDialog.PrintQueue.DefaultPrintTicket; pDialog.PrintTicket.PageScalingFactor = 1; Rect printableArea = GetPrintableArea(pDialog); Viewbox viewBox = new Viewbox { Child = temp }; printableArea.Height = 285 + (order.OIs.Count * 21); printableArea.Width = 250; viewBox.Measure(printableArea.Size); viewBox.Arrange(printableArea); pDialog.PrintVisual(viewBox, "Letter Canvas"); } catch (Exception ex) { MyMessageBox.Show(ex.Message); } }
private void btnPrint_Click(object sender, RoutedEventArgs e) { PrintDialog printDlg = new PrintDialog(); printDlg.PrintVisual(gridStudentCard, "Grid Printing."); }
private void btImprimir_Click(object sender, RoutedEventArgs e) { PrintDialog printDlg = new PrintDialog(); printDlg.PrintVisual(impressao, "Impressão Grid."); }
///<summary> /// Prints the content of the App's MainWindow. The logic is that if the content is not visual but IInputElement /// we will try to let it handle the command first. If it does not handle the print command we will get the corresponding /// visual in the visual tree and use that to print. ///</summary> private static void OnCommandPrint(object sender, ExecutedRoutedEventArgs e) { #if !DONOTREFPRINTINGASMMETA RootBrowserWindow rbw = sender as RootBrowserWindow; Invariant.Assert(rbw != null); if (!rbw._isPrintingFromRBW) { Visual vis = rbw.Content as Visual; if (vis == null) { // If the content is not Visual but IInputElement, try to let it handle the command first. // This is for the document scenario. Printing a document is different from printing a visual. // Printing a visual is to print how it is rendered on screen. Printing a doc prints the full // doc inculding the part that is not visible. There might be other functionalities that are // specific for document. FlowDocument's viewer knows how to print the doc. IInputElement target = rbw.Content as IInputElement; if (target != null) { // CanExecute will bubble up. If nobody between the content and rbw can handle it, // It would call back on RBW again. Use _isPrintingFromRBW to prevent the loop. rbw._isPrintingFromRBW = true; try { if (ApplicationCommands.Print.CanExecute(null, target)) { ApplicationCommands.Print.Execute(null, target); return; } } finally { rbw._isPrintingFromRBW = false; } } } // Let the user choose a printer and set print options. PrintDialog printDlg = new PrintDialog(); // If the user pressed the OK button on the print dialog, we proceed if (printDlg.ShowDialog() == true) { string printJobDescription = GetPrintJobDescription(App.MainWindow); // If the root is not visual and does not know how to print itself, we find the // corresponding visual and use that to print. if (vis == null) { INavigatorImpl navigator = rbw as INavigatorImpl; Invariant.Assert(navigator != null); vis = navigator.FindRootViewer(); Invariant.Assert(vis != null); } // Area we can print to for the chosen printer Rect imageableRect = GetImageableRect(printDlg); // We print Visuals aligned with the top/left corner of the printable area. // We do not attempt to print very large Visuals across multiple pages. // Any portion that doesn't fit on a single page will get cropped by the // print system. // Used to draw our visual into another visual for printing purposes VisualBrush visualBrush = new VisualBrush(vis); visualBrush.Stretch = Stretch.None; // Visual we will print - containing a rectangle the size of our // original Visual but offset into the printable area DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext context = drawingVisual.RenderOpen(); context.DrawRectangle(visualBrush, null, new Rect(imageableRect.X, imageableRect.Y, vis.VisualDescendantBounds.Width, vis.VisualDescendantBounds.Height)); context.Close(); printDlg.PrintVisual(drawingVisual, printJobDescription); } } #endif // DONOTREFPRINTINGASMMETA }
private void Button_Click(object sender, RoutedEventArgs e) { if (IsPrint) { PrintDialog pDialog1 = new PrintDialog(); pDialog1.PrintVisual(GridPrint, "会员卡消费打印"); DialogResult = true; this.Close(); return; } dynamic d = GridPrint.DataContext; if (d.Amount > 0) { StringBuilder sb = new StringBuilder(33); sb.Append(d.CardNo); int value = Convert.ToInt32(d.Amount * 100); int st = CardRef.CoolerConsumeCard(sb, value); if (st != 0) { MessageBox.Show(CardRef.GetStr(st)); return; } } using (TransactionScope transaction = new TransactionScope()) { DXInfo.Models.Consume consume = new DXInfo.Models.Consume(); consume.Sum = d.Sum; consume.Voucher = d.Voucher; consume.PayVoucher = d.PayVoucher; consume.Discount = d.Discount; consume.Card = d.Id; consume.Amount = d.Amount; consume.Balance = d.Balance; consume.CreateDate = d.CreateDate; consume.DeptId = d.DeptId; consume.LastBalance = d.LastBalance; consume.Point = d.Point; consume.UserId = d.UserId; consume.Point = d.Point; consume.ConsumeType = 0; consume.DeskNo = txtDeskNo.Text; uow.Consume.Add(consume); DXInfo.Models.Bills bill = new DXInfo.Models.Bills(); bill.Sum = d.Sum; bill.Voucher = d.Voucher; bill.Discount = d.Discount; bill.Amount = d.Amount; bill.Balance = d.Balance; bill.BillType = "CardConsumeWindow"; bill.CardNo = d.CardNo; bill.CreateDate = d.CreateDate; bill.DeptName = d.DeptName; bill.FullName = d.FullName; bill.LastBalance = d.LastBalance; bill.MemberName = d.MemberName; bill.DeskNo = txtDeskNo.Text; uow.Bills.Add(bill); uow.Commit(); Guid CardId = d.Id; DXInfo.Models.Cards card = uow.Cards.GetById(CardId);//.Where(w => w.Id == CardId).FirstOrDefault(); if (card == null) { throw new ArgumentException("卡信息未找到"); } card.Balance = d.Balance; if (d.CardDonateInventory != null && d.CardDonateInventory.Count > 0) { foreach (var cdi in d.CardDonateInventory) { DXInfo.Models.ConsumeDonateInv cdonate = new DXInfo.Models.ConsumeDonateInv(); cdonate.Consume = consume.Id; cdonate.Inventory = cdi.Id; uow.ConsumeDonateInv.Add(cdonate); Guid gInvId = cdi.Id; var cdi1 = uow.CardDonateInventory.GetAll().Where(w => w.Inventory == gInvId).Where(w => w.CardId == CardId).FirstOrDefault(); if (cdi1 != null) { cdi1.IsValidate = false; } DXInfo.Models.BillDonateInvLists bd = new DXInfo.Models.BillDonateInvLists(); bd.Bill = bill.Id; bd.InvName = cdi.Name; uow.BillDonateInvLists.Add(bd); } } foreach (var si in d.lSelInv) { DXInfo.Models.ConsumeList cl = new DXInfo.Models.ConsumeList(); cl.Amount = si.Amount; cl.Consume = consume.Id; cl.CreateDate = d.CreateDate; cl.Cup = si.Cup; cl.DeptId = d.DeptId; cl.Inventory = si.Id; cl.Price = si.SalePrice; cl.Quantity = si.Quantity; cl.UserId = d.UserId; uow.ConsumeList.Add(cl); DXInfo.Models.BillInvLists bl = new DXInfo.Models.BillInvLists(); bl.Amount = si.Amount; bl.Bill = bill.Id; bl.CupType = si.CupType; bl.Name = si.Name; bl.Quantity = si.Quantity; bl.SalePrice = si.SalePrice; bl.Tastes = si.Tastes; uow.BillInvLists.Add(bl); if (si.lTastes.Count > 0) { uow.Commit(); foreach (var lt in si.lTastes) { DXInfo.Models.ConsumeTastes ct = new DXInfo.Models.ConsumeTastes(); ct.ConsumeList = cl.Id; ct.Taste = lt.Id; uow.ConsumeTastes.Add(ct); } } } if (d.Point > 0) { var cps = uow.CardPoints.GetAll().Where(w => w.Card == CardId).Where(w => w.PointType == 0).FirstOrDefault(); if (cps != null) { cps.Point = cps.Point + d.Point; } else { DXInfo.Models.CardPoints cp = new DXInfo.Models.CardPoints(); cp.Card = d.Id; cp.CreateDate = d.CreateDate; cp.DeptId = d.DeptId; cp.Point = d.Point; cp.PointType = 0; cp.UserId = d.UserId; uow.CardPoints.Add(cp); } } uow.Commit(); transaction.Complete(); } PrintDialog pDialog = new PrintDialog(); pDialog.PrintVisual(GridPrint, "会员卡消费打印"); DialogResult = true; this.Close(); }
private void ClientPrint() { foreach (Turn t in client.turns) { if (t.Id == client.user.TurnId) { t.Enabled = client.user.turnEnabled; } } string timeToPrint = "00:00:00"; if (client.user.StatusTime.IndexOf(".") > -1) { timeToPrint = client.user.StatusTime.Substring(0, client.user.StatusTime.IndexOf(".") - 3); } else { timeToPrint = client.user.StatusTime.Substring(0, client.user.StatusTime.Length - 3); } if (client.IsComPrinter) { // PRINT TO SERIAL (COM-PORT) try { // generate string string dataToPrint = CP866 + FONT_A + "------------------------" + CR + CR + CR + FONT_B_DH_DW_B + "Ваш номер в очереди:" + CR + CR + FONT_A_DH_DW_B + " " + client.user.TurnPrefix + " " + client.user.Index + CR + CR + CR + FONT_B_DH_DW_B + client.user.TurnLine + CR + CR + CR + FONT_A_DH_DW + "КЛИЕНТ-ID: " + client.user.Id + CR + CR + CR + FONT_B_DH_DW_B + "ВРЕМЯ: " + timeToPrint + CR + CR + CR + FONT_B_DH_DW_B + " СОХРАНЯЙТЕ ТАЛОН!" + CR + CR + CR + "------------------------" + CR + CR + CR + CR + CUT; // create serial if null if (client.Serial == null) { client.Serial = new System.IO.Ports.SerialPort(client.ComPort, client.ComBaudRate); client.Serial.WriteTimeout = 500; } // connect serial client.Serial.Open(); // write to serial client.Serial.Write(dataToPrint); // close serial client.Serial.Close(); System.Threading.Thread.Sleep(2000); } catch (Exception ex) { client.LogAdd(ex.Message); } finally { if (client.Serial.IsOpen) { client.Serial.Close(); } } } else { // MANUAL PRINT foPrintTemplate = new PrintTemplate(); foPrintTemplate.laId.Content = client.user.Id; foPrintTemplate.laNumber.Content = client.user.TurnPrefix + client.user.Index; foPrintTemplate.laTime.Content = timeToPrint; foPrintTemplate.lbInfos.ItemsSource = client.user.Infos; foPrintTemplate.tbTurnName.Text = client.user.TurnLine; foPrintTemplate.RefreshSize(); foPrintTemplate.Show(); System.Threading.Thread.Sleep(2000); // Увеличить вывод в 5 раз PrintDialog printDialog = new PrintDialog(); foPrintTemplate.grMain.LayoutTransform = new ScaleTransform(5, 5); // Напечатать элемент printDialog.PrintVisual(foPrintTemplate.grMain, "Печать чека" + client.user.TurnPrefix + client.user.Index); // Удалить трансформацию и снова сделать элемент видимым foPrintTemplate.grMain.LayoutTransform = null; foPrintTemplate.Hide(); } ResetButtons(); client.user = new User(); }
private void Button_Click_3(object sender, RoutedEventArgs e) { DocumentDescription doc = DocsList.SelectedItem as DocumentDescription; if (doc == null) { return; } if (DataGroups == null) { return; } PrintDialog pd = new PrintDialog(); if (doc.PrintOrientation.ToLower() == "landscape") { pd.PrintTicket.PageOrientation = PageOrientation.Landscape; } else { pd.PrintTicket.PageOrientation = PageOrientation.Portrait; } pd.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4); if (pd.ShowDialog() ?? false) { if (doc.PrintOrientation.ToLower() == "landscape") { pd.PrintTicket.PageOrientation = PageOrientation.Landscape; } else { pd.PrintTicket.PageOrientation = PageOrientation.Portrait; } pd.PrintTicket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4); MessageBox.Show("Kérem helyezze be a nyomtatványt " + doc.PrintOrientation + " tájolással. \nHa kész, nyomja meg az OK gombot.", "Dokumentum tájolás", MessageBoxButton.OK, MessageBoxImage.Information); PrintQueue pq = pd.PrintQueue; PrintCapabilities pc = pq.GetPrintCapabilities(); DrawingVisual vis = new DrawingVisual(); DrawingContext dc = vis.RenderOpen(); string prn = pq.Name; PrinterSettings ps; if (Printers.ContainsKey(prn)) { ps = Printers[prn]; } else { ps = Printers["Default"]; } double stx = ps.XOffset + (pc.OrientedPageMediaWidth ?? 870) / 2; double dsty = ps.YOffset + pc.PageImageableArea.OriginHeight; double defaultFontSize = 14; double mmphi = 0.254; foreach (KeyValuePair <string, DataGroup> kvp in DataGroups) { StringDataGroup sdg = kvp.Value as StringDataGroup; if (sdg != null) { string s = sdg.TbString ?? ""; FormattedText ft = new FormattedText(s, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(sdg.FontName), defaultFontSize * sdg.FontScale, new SolidColorBrush(Colors.Black)); double sty = dsty - ft.Baseline; dc.DrawText(ft, new Point(stx + sdg.PrintPosition.X / mmphi, sty + sdg.PrintPosition.Y / mmphi));//*/ } CheckDataGroup cdg = kvp.Value as CheckDataGroup; if (cdg != null) { if (cdg.Checked) { string s = cdg.CheckString ?? "X"; FormattedText ft = new FormattedText(s, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(cdg.FontName), defaultFontSize * cdg.FontScale, new SolidColorBrush(Colors.Black)); double sty = dsty - ft.Baseline; dc.DrawText(ft, new Point(stx + cdg.PrintPosition.X / mmphi, sty + cdg.PrintPosition.Y / mmphi));//*/ } } } dc.Close(); pd.PrintVisual(vis, doc.Name); } }