/// <summary> /// This method creates a dynamic FlowDocument. You can add anything to this /// FlowDocument that you would like to send to the printer /// </summary> /// <returns></returns> private FlowDocument CreateFlowDocument() { // Create a FlowDocument FlowDocument doc = new FlowDocument(); // Set Margin doc.PagePadding = new Thickness(0); //doc.PagePadding = new Thickness(5, 10, 5, 10); // Set PageHeight and PageWidth to "Auto". doc.PageHeight = Double.NaN; doc.PageWidth = 290; //// Specify minimum page sizes. //doc.MinPageWidth = 680.0; //doc.MinPageHeight = 480.0; ////Specify maximum page sizes. //doc.MaxPageWidth = 1024.0; //doc.MaxPageHeight = 768.0; // Create a Section Section sec = new Section(); //// Create first Paragraph //Paragraph p1 = new Paragraph(); //// Create and add a new Bold, Italic and Underline //Bold bld = new Bold(); //bld.Inlines.Add(new Run("First Paragraph")); //Italic italicBld = new Italic(); //italicBld.Inlines.Add(bld); //Underline underlineItalicBld = new Underline(); //underlineItalicBld.Inlines.Add(italicBld); //// Add Bold, Italic, Underline to Paragraph //p1.Inlines.Add(underlineItalicBld); // Template Data for print OrderForPrint order = new OrderForPrint() { No = "ORD0000001", Table = 1, Date = DateTime.Now, Casher = "Luong Nhat Duy", Customer = "Luu Duc Trung", CustomerPay = 500 }; //// Add Paragraph to Section //sec.Blocks.Add(p1); // Add Section to FlowDocument doc.Blocks.Add(sec); //doc.PageWidth = 100; return(doc); }
private void Generate_HeadText(BlockUIContainer blkHeadText, OrderForPrint order) { // Main stackPanel in Head Text StackPanel stpHeadText = new StackPanel(); StackPanel stpTime = new StackPanel() { Orientation = Orientation.Horizontal, Margin = new Thickness(0, 0, 0, 10) }; TextBlock tbDate = new TextBlock() { Text = order.Date.ToShortDateString(), Width = 120, VerticalAlignment = VerticalAlignment.Stretch, TextAlignment = TextAlignment.Left, FontFamily = new FontFamily("Century Gothic"), FontSize = 18, FontWeight = FontWeights.UltraBold, }; TextBlock tbTime = new TextBlock() { Text = order.Date.ToShortTimeString(), Width = 150, VerticalAlignment = VerticalAlignment.Stretch, TextAlignment = TextAlignment.Right, FontFamily = new FontFamily("Century Gothic"), FontSize = 18, FontWeight = FontWeights.UltraBold, }; stpTime.Children.Add(tbDate); stpTime.Children.Add(tbTime); StackPanel stpTableNumber = new StackPanel() { Orientation = Orientation.Horizontal }; TextBlock tbTableNumberLabel = new TextBlock() { Text = "Table: ", FontFamily = new FontFamily("Century Gothic"), FontSize = 18, FontWeight = FontWeights.UltraBold, }; TextBlock tbTableNumber = new TextBlock() { Text = order.Table.ToString(), FontFamily = new FontFamily("Century Gothic"), FontSize = 18, Width = 30, FontWeight = FontWeights.UltraBold, }; TextBlock tbPaxLable = new TextBlock() { Text = "Pax: ", FontFamily = new FontFamily("Century Gothic"), FontSize = 18, Width = 40, Margin = new Thickness(95, 0, 0, 0), FontWeight = FontWeights.UltraBold, }; TextBlock tbPaxValue = new TextBlock() { Text = order.Pax.ToString(), FontFamily = new FontFamily("Century Gothic"), FontSize = 18, Width = 35, TextAlignment = TextAlignment.Right, FontWeight = FontWeights.UltraBold, }; stpTableNumber.Children.Add(tbTableNumberLabel); stpTableNumber.Children.Add(tbTableNumber); stpTableNumber.Children.Add(tbPaxLable); stpTableNumber.Children.Add(tbPaxValue); StackPanel stpPageName = new StackPanel(); TextBlock tbPageName = new TextBlock() { Text = "BAR", HorizontalAlignment = HorizontalAlignment.Center, FontSize = 20, Margin = new Thickness(0, 10, 0, 0), FontFamily = new FontFamily("Century Gothic"), FontWeight = FontWeights.UltraBold, }; stpPageName.Children.Add(tbPageName); stpHeadText.Children.Add(stpTime); stpHeadText.Children.Add(stpTableNumber); stpHeadText.Children.Add(stpPageName); blkHeadText.Child = stpHeadText; }
/// <summary> /// Create the summary section of Receipt /// </summary> /// <param name="blkTableText"></param> /// <param name="order">the order data for filling the receip</param> /// <param name="moneyUnit"></param> private void Generate_SummaryText(BlockUIContainer blkSummaryText, OrderForPrint order, string moneyUnit) { StackPanel stpSummary = new StackPanel() { Orientation = Orientation.Vertical }; // Sale Value StackPanel stpSaleValue = new StackPanel() { Orientation = Orientation.Horizontal }; TextBlock tbSaleValueLable = new TextBlock() { Text = "Sale Value:", FontFamily = new FontFamily("Century Gothic"), FontSize = 12, FontWeight = FontWeights.UltraBold, Margin = new Thickness(90, 0, 0, 0), Width = 120 }; TextBlock tbSaleValueValue = new TextBlock() { Text = String.Format("{0:0.000}", order.SaleValue), FontFamily = new FontFamily("Century Gothic"), FontSize = 11, Width = 60, TextAlignment = TextAlignment.Right }; stpSaleValue.Children.Add(tbSaleValueLable); stpSaleValue.Children.Add(tbSaleValueValue); // Service Charge StackPanel stpSVC = new StackPanel() { Orientation = Orientation.Horizontal }; TextBlock tbSVCLable = new TextBlock() { Text = "SVC (5%):", FontFamily = new FontFamily("Century Gothic"), FontSize = 12, FontWeight = FontWeights.UltraBold, Margin = new Thickness(90, 0, 0, 0), Width = 120 }; TextBlock tbSVCValue = new TextBlock() { Text = String.Format("{0:0.000}", order.Svc), FontFamily = new FontFamily("Century Gothic"), FontSize = 11, Width = 60, TextAlignment = TextAlignment.Right }; stpSVC.Children.Add(tbSVCLable); stpSVC.Children.Add(tbSVCValue); // VAT StackPanel stpVAT = new StackPanel() { Orientation = Orientation.Horizontal }; TextBlock tbVATLable = new TextBlock() { Text = "VAT (10%):", FontFamily = new FontFamily("Century Gothic"), FontSize = 12, FontWeight = FontWeights.UltraBold, Margin = new Thickness(90, 0, 0, 0), Width = 120 }; TextBlock tbVATValue = new TextBlock() { Text = String.Format("{0:0.000}", order.Vat), FontFamily = new FontFamily("Century Gothic"), FontSize = 11, Width = 60, TextAlignment = TextAlignment.Right }; stpVAT.Children.Add(tbVATLable); stpVAT.Children.Add(tbVATValue); // Total Price StackPanel stpTotalPrice = new StackPanel() { Orientation = Orientation.Horizontal }; TextBlock tbTotalPriceLable = new TextBlock() { Text = "Total Amount " + "(" + moneyUnit + "):", FontFamily = new FontFamily("Century Gothic"), FontSize = 12, FontWeight = FontWeights.UltraBold, Margin = new Thickness(90, 0, 0, 0), Width = 120 }; TextBlock tbTotalPriceValue = new TextBlock() { Text = String.Format("{0:0.000}", order.TotalPrice), FontFamily = new FontFamily("Century Gothic"), FontSize = 11, Width = 60, TextAlignment = TextAlignment.Right }; stpTotalPrice.Children.Add(tbTotalPriceLable); stpTotalPrice.Children.Add(tbTotalPriceValue); // Customer Pay StackPanel stpCustomerPay = new StackPanel() { Orientation = Orientation.Horizontal }; TextBlock tbCustomerPayLable = new TextBlock() { Text = "Customer Pay:", FontFamily = new FontFamily("Century Gothic"), FontSize = 12, FontWeight = FontWeights.UltraBold, Margin = new Thickness(90, 0, 0, 0), Width = 120 }; TextBlock tbCustomerPayValue = new TextBlock() { Text = String.Format("{0:0.000}", order.CustomerPay), FontFamily = new FontFamily("Century Gothic"), FontSize = 11, Width = 60, TextAlignment = TextAlignment.Right }; stpCustomerPay.Children.Add(tbCustomerPayLable); stpCustomerPay.Children.Add(tbCustomerPayValue); // Pay Back StackPanel stpPayBack = new StackPanel() { Orientation = Orientation.Horizontal }; TextBlock tbPayBackLable = new TextBlock() { Text = "Change:", FontFamily = new FontFamily("Century Gothic"), FontSize = 12, FontWeight = FontWeights.UltraBold, Margin = new Thickness(90, 0, 0, 0), Width = 120 }; TextBlock tbPayBackValue = new TextBlock() { Text = String.Format("{0:0.000}", order.PayBack), FontFamily = new FontFamily("Century Gothic"), FontSize = 11, Width = 60, TextAlignment = TextAlignment.Right }; stpPayBack.Children.Add(tbPayBackLable); stpPayBack.Children.Add(tbPayBackValue); stpSummary.Children.Add(stpSaleValue); stpSummary.Children.Add(stpSVC); stpSummary.Children.Add(stpVAT); stpSummary.Children.Add(stpTotalPrice); stpSummary.Children.Add(stpCustomerPay); stpSummary.Children.Add(stpPayBack); blkSummaryText.Child = stpSummary; }