public ItemsPage() { InitializeComponent(); NavigationPage.SetHasBackButton(this, false); lblPersianDate.Text = SandoghcheController.GetPersianDate(null); lblUser.Text = Application.Current.Properties["userRollName"].ToString() + " : " + Application.Current.Properties["FullName"].ToString(); }
public ReportPage() { InitializeComponent(); NavigationPage.SetHasBackButton(this, false); lblPersianDate.Text = SandoghcheController.GetPersianDate(null); lblUser.Text = Application.Current.Properties["userRollName"].ToString() + " : " + Application.Current.Properties["FullName"].ToString(); pkrReceiptType.Items.Add("روش پرداخت : همه"); pkrReceiptType.Items.Add("نقدی"); pkrReceiptType.Items.Add("اعتباری"); pkrReceiptType.SelectedIndex = 0; userRoll = Application.Current.Properties["userRollName"].ToString(); switch (userRoll) { case "مدیر ارشد": { isEdited.IsVisible = true; isDeleted.IsVisible = true; lblIsEdited.IsVisible = true; lblIsDeleted.IsVisible = true; } break; case "مدیر": { isEdited.IsVisible = true; isDeleted.IsVisible = true; lblIsEdited.IsVisible = true; lblIsDeleted.IsVisible = true; } break; case "صندوقدار": { isEdited.IsVisible = false; isDeleted.IsVisible = false; lblIsEdited.IsVisible = false; lblIsDeleted.IsVisible = false; } break; case "میزبان": { isEdited.IsVisible = false; isDeleted.IsVisible = false; lblIsEdited.IsVisible = false; lblIsDeleted.IsVisible = false; } break; default: break; } }
public InvoicePage(int ClientId, string ClientName) { InitializeComponent(); NavigationPage.SetHasBackButton(this, false); lblPersianDate.Text = SandoghcheController.GetPersianDate(null); lblClient.Text = "انتخاب مشتری : " + ClientName; lblClientId.Text = ClientId.ToString(); clientName = ClientName; order = new Order(); }
public SettingsPage() { InitializeComponent(); NavigationPage.SetHasBackButton(this, false); lblPersianDate.Text = SandoghcheController.GetPersianDate(null); lblUser.Text = Application.Current.Properties["userRollName"].ToString() + " : " + Application.Current.Properties["FullName"].ToString(); var userRoll = Application.Current.Properties["userRollName"].ToString(); switch (userRoll) { case "مدیر ارشد": { UserSettings.Content.IsVisible = true; } break; case "مدیر": { UserSettings.Content.IsVisible = true; } break; case "صندوقدار": { UserSettings.Content.IsVisible = false; } break; case "میزبان": { UserSettings.Content.IsVisible = false; } break; default: break; } }
async private void btnShare_Clicked(object sender, EventArgs e) { var s = sender as Xamarin.Forms.Button; var selectedOrder = s.BindingContext; var orderModel = (OrderDetailForSearchViewModel)selectedOrder; int orderId = orderModel.OrderId; var order = await SandoghcheController.GetConnection().Table <Order>().FirstOrDefaultAsync(o => o.OrderId == orderId); order.OrderDetails = await SandoghcheController.GetConnection().Table <OrderDetail>().Where(od => od.OrderId == orderModel.OrderId).ToListAsync(); var products = await SandoghcheController.GetConnection().Table <Product>().ToListAsync(); var client = await SandoghcheController.GetConnection().Table <Client>().FirstOrDefaultAsync(c => c.ClientId == order.ClientId); int rownum = 0; foreach (var item in order.OrderDetails) { rownum++; item.ProductText = products.FirstOrDefault(p => p.ProductId == item.ProductId).ProductText; item.RowNumber = rownum; } List <orderDetailViewModel> orderDetails = new List <orderDetailViewModel>(); foreach (var item in order.OrderDetails) { orderDetails.Add(new orderDetailViewModel { RowNumber = item.RowNumber, ProductText = item.ProductText, Number = item.Number, Price = item.Price, TotalPrice = item.TotalPrice }); } PdfDocument doc = new PdfDocument(); doc.PageSettings.Size = new Syncfusion.Drawing.SizeF(300, 800); PdfMargins margins = new PdfMargins(); margins.All = 10; doc.PageSettings.Margins = margins; PdfPage page = doc.Pages.Add(); PdfGraphics graphics = page.Graphics; //var test = GetType().GetTypeInfo().Assembly.GetManifestResourceNames(); Stream fontStream = typeof(EditPage).GetTypeInfo().Assembly.GetManifestResourceStream("Sandoghche.Images.IRANSans(FaNum).ttf"); PdfFont font = new PdfTrueTypeFont(fontStream, 10); PdfStringFormat format = new PdfStringFormat(); format.TextDirection = PdfTextDirection.RightToLeft; format.Alignment = PdfTextAlignment.Center; PdfStringFormat format2 = new PdfStringFormat(); format2.TextDirection = PdfTextDirection.RightToLeft; format2.Alignment = PdfTextAlignment.Right; PdfStringFormat format3 = new PdfStringFormat(); format3.TextDirection = PdfTextDirection.RightToLeft; format3.Alignment = PdfTextAlignment.Left; graphics.DrawString(client.ClientName, font, PdfBrushes.Black, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format); graphics.DrawString("فاکتور فروش", font, PdfBrushes.Black, new RectangleF(0, 20, page.GetClientSize().Width, page.GetClientSize().Height), format); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, 40), new PointF(300, 40)); graphics.DrawString("تاریخ :" + SandoghcheController.GetPersianDate(Convert.ToDateTime(order.DateCreated)), font, PdfBrushes.Black, new RectangleF(0, 42, page.GetClientSize().Width, page.GetClientSize().Height), format); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, 60), new PointF(300, 60)); graphics.DrawString("ردیف عنوان تعداد قیمت واحد قیمت کل ", font, PdfBrushes.Black, new RectangleF(0, 60, page.GetClientSize().Width, page.GetClientSize().Height), format); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, 75), new PointF(300, 75)); string source = ""; int length = 5; string result = source.PadRight(length).Substring(0, length); int height = 75; foreach (var item in order.OrderDetails) { string rowNumber = item.RowNumber.ToString().PadLeft(5).Substring(0, 5); string productText = item.ProductText.PadRight(20).Substring(0, 20); string Number = item.Number.ToString().PadLeft(5).Substring(0, 5); string Price = item.Price.ToString().PadLeft(12).Substring(0, 12); string TotalPrice = item.TotalPrice.ToString().PadLeft(12).Substring(0, 12); graphics.DrawString(rowNumber, font, PdfBrushes.Black, 285, height, format2); graphics.DrawString(productText, font, PdfBrushes.Black, 255, height, format2); graphics.DrawString(Number, font, PdfBrushes.Black, 130, height, format2); graphics.DrawString(Price, font, PdfBrushes.Black, 110, height, format2); graphics.DrawString(TotalPrice, font, PdfBrushes.Black, 55, height, format2); height += 15; graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(300, height)); productText = ""; } graphics.DrawString("مالیات : " + (order.Tax1 + order.Tax2).ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height)); height += 15; graphics.DrawString("سرویس : " + order.TotalServiceFee.ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height)); height += 15; graphics.DrawString("پیک : " + order.DeliveryFee.ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height)); height += 15; graphics.DrawString("تخفیف : " + order.TotalDiscount.ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height)); height += 15; graphics.DrawString("توضیحات : " + order.Comment, font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height)); height += 15; graphics.DrawString("جمع کل : " + order.FinalPayment.ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(300, height)); MemoryStream stream = new MemoryStream(); doc.Save(stream); byte[] test = stream.ToArray(); doc.Close(true); var fn = order.OrderId.ToString() + ".pdf"; var file = Path.Combine(FileSystem.CacheDirectory, fn); File.WriteAllBytes(file, test); await Share.RequestAsync(new ShareFileRequest { Title = "فاکتور فروش", File = new ShareFile(file) }); // await Xamarin.Forms.DependencyService.Get<ISave>().Save(order.OrderId.ToString(), "application/pdf", stream); }
public async void PrintUWpAsync(Order order, string receiptType, string ClientName) { #region Grid Print Document Grid Receipt = new Grid { Width = 300 }; #region Main Grid Definition Receipt.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30, GridUnitType.Pixel) }); Receipt.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30, GridUnitType.Pixel) }); Receipt.RowDefinitions.Add(new RowDefinition { Height = new GridLength(50, GridUnitType.Pixel) }); Receipt.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); Receipt.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30, GridUnitType.Pixel) }); Receipt.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30, GridUnitType.Pixel) }); Receipt.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30, GridUnitType.Pixel) }); Receipt.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30, GridUnitType.Pixel) }); Receipt.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30, GridUnitType.Pixel) }); Receipt.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30, GridUnitType.Pixel) }); Receipt.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30, GridUnitType.Pixel) }); Receipt.RowDefinitions.Add(new RowDefinition { Height = new GridLength(30, GridUnitType.Pixel) }); Receipt.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(300, GridUnitType.Pixel) }); #endregion #region Store Name TextBlock StoreName = new TextBlock { Foreground = new SolidColorBrush(Windows.UI.Colors.Black), Text = ClientName, FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, FontSize = 18, FontWeight = Windows.UI.Text.FontWeights.Bold }; #endregion Receipt.Children.Add(StoreName); Grid.SetRow(StoreName, 0); #region ReceiptType TextBlock ReceiptType = new TextBlock { Foreground = new SolidColorBrush(Windows.UI.Colors.Black), Text = receiptType, FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, FontSize = 15, FontWeight = Windows.UI.Text.FontWeights.Bold }; #endregion Receipt.Children.Add(ReceiptType); Grid.SetRow(ReceiptType, 1); StackPanel row2 = new StackPanel(); #region ReceiptNumber ,User,Date,Time Grid ReceiptNumber = new Grid { Background = new SolidColorBrush(Windows.UI.Colors.LightGray) }; ReceiptNumber.RowDefinitions.Add(new RowDefinition { Height = new GridLength(25, GridUnitType.Pixel) }); ReceiptNumber.RowDefinitions.Add(new RowDefinition { Height = new GridLength(25, GridUnitType.Pixel) }); ReceiptNumber.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(150, GridUnitType.Pixel) }); ReceiptNumber.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(150, GridUnitType.Pixel) }); TextBlock User = new TextBlock { Foreground = new SolidColorBrush(Windows.UI.Colors.Black), Text = "کاربر : مدیر", FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; ReceiptNumber.Children.Add(User); Grid.SetRow(User, 0); Grid.SetColumn(User, 0); TextBlock ReceiptNum = new TextBlock { Foreground = new SolidColorBrush(Windows.UI.Colors.Black), Text = "شماره : " + order.ReceiptNumber, FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, FontSize = 15, FontWeight = Windows.UI.Text.FontWeights.Bold }; ReceiptNumber.Children.Add(ReceiptNum); Grid.SetRow(ReceiptNum, 0); Grid.SetColumn(ReceiptNum, 1); TextBlock Time = new TextBlock { Foreground = new SolidColorBrush(Windows.UI.Colors.Black), Text = "ساعت :" + Convert.ToDateTime(order.DateCreated).ToString("HH:mm:ss"), FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; ReceiptNumber.Children.Add(Time); Grid.SetRow(Time, 1); Grid.SetColumn(Time, 0); TextBlock Date = new TextBlock { Foreground = new SolidColorBrush(Windows.UI.Colors.Black), Text = SandoghcheController.GetPersianDate(Convert.ToDateTime(order.DateCreated)), FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; ReceiptNumber.Children.Add(Date); Grid.SetRow(Date, 1); Grid.SetColumn(Date, 1); #endregion row2.Children.Add(ReceiptNumber); Receipt.Children.Add(row2); Grid.SetRow(row2, 2); StackPanel row3 = new StackPanel { HorizontalAlignment = HorizontalAlignment.Right, Width = 300 }; #region Order Detail Header StackPanel PanelHeader = new StackPanel { Orientation = Orientation.Horizontal }; Grid Header = new Grid { Width = 300 }; Header.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(60, GridUnitType.Pixel) }); Header.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(60, GridUnitType.Pixel) }); Header.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(40, GridUnitType.Pixel) }); Header.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); Header.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(40, GridUnitType.Pixel) }); TextBlock TotalPriceHeader = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center, Text = "قیمت کل", FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), Foreground = new SolidColorBrush(Windows.UI.Colors.Black) }; Header.Children.Add(TotalPriceHeader); Grid.SetColumn(TotalPriceHeader, 0); TextBlock PriceHeader = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center, Text = "قیمت", FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), Foreground = new SolidColorBrush(Windows.UI.Colors.Black) }; Header.Children.Add(PriceHeader); Grid.SetColumn(PriceHeader, 1); TextBlock NumberHeader = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center, Text = "تعداد", FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), Foreground = new SolidColorBrush(Windows.UI.Colors.Black) }; Header.Children.Add(NumberHeader); Grid.SetColumn(NumberHeader, 2); TextBlock ProductTextHeader = new TextBlock { HorizontalAlignment = HorizontalAlignment.Right, Text = "عنوان", FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), Foreground = new SolidColorBrush(Windows.UI.Colors.Black) }; Header.Children.Add(ProductTextHeader); Grid.SetColumn(ProductTextHeader, 3); TextBlock RowNumberHeader = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center, Text = "ردیف", FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), Foreground = new SolidColorBrush(Windows.UI.Colors.Black) }; Header.Children.Add(RowNumberHeader); Grid.SetColumn(RowNumberHeader, 4); PanelHeader.Children.Add(Header); #endregion //GridView ProductGridviewContent = new GridView(); // StackPanel OrderDetailPanel = new StackPanel { Orientation = Orientation.Vertical }; #region Order Detail Content StackPanel PanelContent = new StackPanel { Orientation = Orientation.Vertical }; Grid Contents = new Grid { Width = 300 }; ListView lstContents = new ListView(); Contents.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(60, GridUnitType.Pixel) }); Contents.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(60, GridUnitType.Pixel) }); Contents.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(40, GridUnitType.Pixel) }); Contents.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); Contents.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(40, GridUnitType.Pixel) }); for (int i = 0; i < order.OrderDetails.Count; i++) //Add 36 columns { RowDefinition row = new RowDefinition(); row.Height = new GridLength(40, GridUnitType.Pixel); Contents.RowDefinitions.Add(row); } for (int rowIndex = 0; rowIndex < order.OrderDetails.Count; rowIndex++) { TextBlock TotalPriceContent = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center, Text = order.OrderDetails[rowIndex].TotalPrice.ToString(), FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), Foreground = new SolidColorBrush(Windows.UI.Colors.Black) }; Contents.Children.Add(TotalPriceContent); Grid.SetColumn(TotalPriceContent, 0); Grid.SetRow(TotalPriceContent, rowIndex); TextBlock PriceContent = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center, Text = order.OrderDetails[rowIndex].Price.ToString(), FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), Foreground = new SolidColorBrush(Windows.UI.Colors.Black) }; Contents.Children.Add(PriceContent); Grid.SetColumn(PriceContent, 1); Grid.SetRow(PriceContent, rowIndex); TextBlock NumberContent = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center, Text = order.OrderDetails[rowIndex].Number.ToString(), FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), Foreground = new SolidColorBrush(Windows.UI.Colors.Black) }; Contents.Children.Add(NumberContent); Grid.SetColumn(NumberContent, 2); Grid.SetRow(NumberContent, rowIndex); TextBlock ProductTextContent = new TextBlock { HorizontalAlignment = HorizontalAlignment.Right, Text = order.OrderDetails[rowIndex].ProductText, FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), Foreground = new SolidColorBrush(Windows.UI.Colors.Black) }; Contents.Children.Add(ProductTextContent); Grid.SetColumn(ProductTextContent, 3); Grid.SetRow(ProductTextContent, rowIndex); TextBlock RowNumberContent = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center, Text = order.OrderDetails[rowIndex].RowNumber.ToString(), FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), Foreground = new SolidColorBrush(Windows.UI.Colors.Black) }; Contents.Children.Add(RowNumberContent); Grid.SetColumn(RowNumberContent, 4); Grid.SetRow(RowNumberContent, rowIndex); } PanelContent.Children.Add(Contents); #endregion row3.Children.Add(PanelHeader); row3.Children.Add(PanelContent); Receipt.Children.Add(row3); Grid.SetRow(row3, 3); int rowCounter = 3; #region Tax1 TextBlock Tax1 = new TextBlock { Foreground = new SolidColorBrush(Windows.UI.Colors.Black), Text = " مالیات اول : " + order.Tax1Percent.ToString() + " % " + order.Tax1.ToString(), FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, FontSize = 15, FontWeight = Windows.UI.Text.FontWeights.Bold }; #endregion if (order.Tax1 != 0) { rowCounter++; Receipt.Children.Add(Tax1); Grid.SetRow(Tax1, rowCounter); } #region Tax2 TextBlock Tax2 = new TextBlock { Foreground = new SolidColorBrush(Windows.UI.Colors.Black), Text = " مالیات دوم : " + order.Tax2Percent.ToString() + " % " + order.Tax2.ToString(), FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, FontSize = 15, FontWeight = Windows.UI.Text.FontWeights.Bold }; #endregion if (order.Tax2 != 0) { rowCounter++; Receipt.Children.Add(Tax2); Grid.SetRow(Tax2, rowCounter); } #region Delivery TextBlock Delivery = new TextBlock { Foreground = new SolidColorBrush(Windows.UI.Colors.Black), Text = " پیک : " + order.DeliveryFee.ToString(), FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, FontSize = 15, FontWeight = Windows.UI.Text.FontWeights.Bold }; #endregion if (order.DeliveryFee != 0) { rowCounter++; Receipt.Children.Add(Delivery); Grid.SetRow(Delivery, rowCounter); } #region Service TextBlock Service = new TextBlock { Foreground = new SolidColorBrush(Windows.UI.Colors.Black), Text = " سرویس : " + order.ServicePercent.ToString() + " % " + order.TotalServiceFee.ToString(), FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, FontSize = 15, FontWeight = Windows.UI.Text.FontWeights.Bold }; #endregion if (order.TotalServiceFee != 0) { rowCounter++; Receipt.Children.Add(Service); Grid.SetRow(Service, rowCounter); } #region Discount TextBlock Discount = new TextBlock { Foreground = new SolidColorBrush(Windows.UI.Colors.Black), Text = " تخفیف : " + order.DiscountPercent.ToString() + " % " + order.TotalDiscount.ToString(), FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, FontSize = 15, FontWeight = Windows.UI.Text.FontWeights.Bold }; #endregion if (order.TotalDiscount != 0) { rowCounter++; Receipt.Children.Add(Discount); Grid.SetRow(Discount, rowCounter); } #region Final Payment TextBlock FinalPayment = new TextBlock { Foreground = new SolidColorBrush(Windows.UI.Colors.Black), Text = "مجموع : " + order.FinalPayment.ToString(), FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, FontSize = 15, FontWeight = Windows.UI.Text.FontWeights.Bold }; #endregion if (order.FinalPayment != 0) { rowCounter++; Receipt.Children.Add(FinalPayment); Grid.SetRow(FinalPayment, rowCounter); } #region Note TextBlock Note = new TextBlock { Foreground = new SolidColorBrush(Windows.UI.Colors.Black), Text = " توضیحات : " + order.Comment, FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, FontSize = 15, FontWeight = Windows.UI.Text.FontWeights.Bold }; #endregion if (!string.IsNullOrEmpty(order.Comment)) { rowCounter++; Receipt.Children.Add(Note); Grid.SetRow(Note, rowCounter); } #region sandoghchr.net TextBlock Sandoghche = new TextBlock { Foreground = new SolidColorBrush(Windows.UI.Colors.Black), Text = "www.sandoghche.net", FontFamily = new FontFamily("IRANSansMobile(FaNum).ttf#IRANSansMobile(FaNum)"), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, FontSize = 15, FontWeight = Windows.UI.Text.FontWeights.Bold }; #endregion Receipt.Children.Add(Sandoghche); Grid.SetRow(Sandoghche, rowCounter + 1); testPanel.Children.Add(Receipt); #endregion if (PrintDoc != null) { printDoc.GetPreviewPage -= PrintDoc_GetPreviewPage; printDoc.Paginate -= PrintDoc_Paginate; printDoc.AddPages -= PrintDoc_AddPages; } this.printDoc = new PrintDocument(); try { printDoc.GetPreviewPage += PrintDoc_GetPreviewPage; printDoc.Paginate += PrintDoc_Paginate; printDoc.AddPages += PrintDoc_AddPages; bool showprint = await PrintManager.ShowPrintUIAsync(); } catch (Exception e) { Debug.WriteLine(e.ToString()); } PrintDoc = null; PrintManager printmgr = PrintManager.GetForCurrentView(); printmgr.PrintTaskRequested -= Printmgr_PrintTaskRequested; GC.Collect(); }
protected override async void OnAppearing() { if (ForHistory) { EditedOrder = await SandoghcheController.GetConnection().Table <EditedOrdersLogs>().FirstOrDefaultAsync(o => o.EditedLogId == EditedLogId); btnSaveInvoiceUpdate.IsVisible = false; btnPrintInvoiceUpdate.IsVisible = false; btnCreditInvoiceUpdate.IsVisible = false; btnDeleteOrder.IsVisible = false; var client = await SandoghcheController.GetConnection().Table <Client>().FirstOrDefaultAsync(c => c.ClientId == EditedOrder.ClientId); var EditedOrderDetail = await SandoghcheController.GetConnection().Table <EditedOrderDetailsLogs>().Where(d => d.EditedLogId == EditedLogId).ToListAsync(); var products = await SandoghcheController.GetConnection().Table <Product>().ToListAsync(); ClientName = client.ClientName; EditedOrder.EditedOrderDetailsLogs = EditedOrderDetail; lblOrderId.Text = EditedOrder.OrderId.ToString(); lblReceipNumber.Text = EditedOrder.ReceiptNumber.ToString(); lblPersianDate.Text = SandoghcheController.GetPersianDate(Convert.ToDateTime(EditedOrder.DateCreated)); lblClient.Text = client.ClientName; lblFinalPayment.Text = EditedOrder.FinalPayment.ToString(); lblDelivery.Text = EditedOrder.DeliveryFee.ToString(); lblDiscount.Text = EditedOrder.TotalDiscount.ToString(); lblService.Text = EditedOrder.TotalServiceFee.ToString(); lblTax.Text = (EditedOrder.Tax1 + EditedOrder.Tax2).ToString(); lblTotalPrice.Text = EditedOrder.TotalPrice.ToString(); int rowNumber = 1; foreach (var item in EditedOrderDetail) { item.ProductText = products.FirstOrDefault(p => p.ProductId == item.ProductId).ProductText; item.RowNumber = rowNumber; item.isEnabled = false; rowNumber++; } ProductsDataGrid.ItemsSource = EditedOrderDetail; } else { order = await SandoghcheController.GetConnection().Table <Order>().FirstOrDefaultAsync(o => o.OrderId == OrderId); if (order.isDeleted) { btnSaveInvoiceUpdate.IsVisible = false; btnPrintInvoiceUpdate.IsVisible = false; btnCreditInvoiceUpdate.IsVisible = false; btnDeleteOrder.IsVisible = false; } else { btnSaveInvoiceUpdate.IsVisible = true; btnPrintInvoiceUpdate.IsVisible = true; btnCreditInvoiceUpdate.IsVisible = true; btnDeleteOrder.IsVisible = true; } if (order.PaymentType == 1 || order.isDeleted) { btnSaveInvoiceUpdate.IsVisible = false; btnPrintInvoiceUpdate.IsVisible = false; } else { btnSaveInvoiceUpdate.IsVisible = true; btnPrintInvoiceUpdate.IsVisible = true; } var client = await SandoghcheController.GetConnection().Table <Client>().FirstOrDefaultAsync(c => c.ClientId == order.ClientId); var orderDetail = await SandoghcheController.GetConnection().Table <OrderDetail>().Where(d => d.OrderId == order.OrderId).ToListAsync(); var products = await SandoghcheController.GetConnection().Table <Product>().ToListAsync(); order.OrderDetails = orderDetail; ClientName = client.ClientName; await getSetting(); lblOrderId.Text = order.OrderId.ToString(); lblReceipNumber.Text = order.ReceiptNumber.ToString(); lblPersianDate.Text = SandoghcheController.GetPersianDate(Convert.ToDateTime(order.DateCreated)); lblClient.Text = client.ClientName; lblFinalPayment.Text = order.FinalPayment.ToString(); lblDelivery.Text = order.DeliveryFee.ToString(); lblDiscount.Text = order.TotalDiscount.ToString(); lblService.Text = order.TotalServiceFee.ToString(); lblTax.Text = (order.Tax1 + order.Tax2).ToString(); lblTotalPrice.Text = order.TotalPrice.ToString(); int rowNumber = 1; foreach (var item in orderDetail) { item.ProductText = products.FirstOrDefault(p => p.ProductId == item.ProductId).ProductText; item.RowNumber = rowNumber; rowNumber++; } await getCategories(); ProductsDataGrid.ItemsSource = orderDetail; await ClientCreditStatus(order.ClientId.ToString()); var EditAlloweTime = Convert.ToDateTime(order.DateCreated).AddMinutes(EditDelayTime); if (DateTime.Now > EditAlloweTime) { btnSaveInvoiceUpdate.IsVisible = false; btnPrintInvoiceUpdate.IsVisible = false; btnCreditInvoiceUpdate.IsVisible = false; await DisplayAlert("خطا", "زمان ویرایش به اتمام رسیده است", "باشه"); } } base.OnAppearing(); }
async private void PrintInvoice_Tapped(object sender, EventArgs e) { order.PaymentType = 0; double finalPayment = Convert.ToDouble(lblFinalPayment.Text); if (finalPayment == 0) { await DisplayAlert("صدور فاکتور", "فاکتور به مبلغ صفر نمیتواتد در سیستم ثبت گردد", "باشه"); } else { await SandoghcheController._connection.InsertAsync(order); await SandoghcheController._connection.InsertAllAsync(order.OrderDetails); await SandoghcheController._connection.UpdateWithChildrenAsync(order); await UpdateProductsAmount(); if (Device.RuntimePlatform == Device.iOS) { //iOS stuff } else if (Device.RuntimePlatform == Device.Android) { PdfDocument doc = new PdfDocument(); doc.PageSettings.Size = new Syncfusion.Drawing.SizeF(300, 800); PdfMargins margins = new PdfMargins(); margins.All = 10; doc.PageSettings.Margins = margins; PdfPage page = doc.Pages.Add(); PdfGraphics graphics = page.Graphics; //var test = GetType().GetTypeInfo().Assembly.GetManifestResourceNames(); Stream fontStream = typeof(EditPage).GetTypeInfo().Assembly.GetManifestResourceStream("Sandoghche.Images.IRANSans(FaNum).ttf"); PdfFont font = new PdfTrueTypeFont(fontStream, 10); PdfStringFormat format = new PdfStringFormat(); format.TextDirection = PdfTextDirection.RightToLeft; format.Alignment = PdfTextAlignment.Center; PdfStringFormat format2 = new PdfStringFormat(); format2.TextDirection = PdfTextDirection.RightToLeft; format2.Alignment = PdfTextAlignment.Right; PdfStringFormat format3 = new PdfStringFormat(); format3.TextDirection = PdfTextDirection.RightToLeft; format3.Alignment = PdfTextAlignment.Left; graphics.DrawString(lblClient.Text, font, PdfBrushes.Black, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format); graphics.DrawString("فاکتور فروش", font, PdfBrushes.Black, new RectangleF(0, 20, page.GetClientSize().Width, page.GetClientSize().Height), format); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, 40), new PointF(300, 40)); graphics.DrawString("تاریخ :" + SandoghcheController.GetPersianDate(Convert.ToDateTime(order.DateCreated)), font, PdfBrushes.Black, new RectangleF(0, 42, page.GetClientSize().Width, page.GetClientSize().Height), format); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, 60), new PointF(300, 60)); graphics.DrawString("ردیف عنوان تعداد قیمت واحد قیمت کل ", font, PdfBrushes.Black, new RectangleF(0, 60, page.GetClientSize().Width, page.GetClientSize().Height), format); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, 75), new PointF(300, 75)); string source = ""; int length = 5; string result = source.PadRight(length).Substring(0, length); int height = 75; foreach (var item in order.OrderDetails) { string rowNumber = item.RowNumber.ToString().PadLeft(5).Substring(0, 5); string productText = item.ProductText.PadRight(20).Substring(0, 20); string Number = item.Number.ToString().PadLeft(5).Substring(0, 5); string Price = item.Price.ToString().PadLeft(12).Substring(0, 12); string TotalPrice = item.TotalPrice.ToString().PadLeft(12).Substring(0, 12); graphics.DrawString(rowNumber, font, PdfBrushes.Black, 285, height, format2); graphics.DrawString(productText, font, PdfBrushes.Black, 255, height, format2); graphics.DrawString(Number, font, PdfBrushes.Black, 130, height, format2); graphics.DrawString(Price, font, PdfBrushes.Black, 110, height, format2); graphics.DrawString(TotalPrice, font, PdfBrushes.Black, 55, height, format2); height += 15; graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(300, height)); productText = ""; } graphics.DrawString("مالیات : " + (order.Tax1 + order.Tax2).ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height)); height += 15; graphics.DrawString("سرویس : " + order.TotalServiceFee.ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height)); height += 15; graphics.DrawString("پیک : " + order.DeliveryFee.ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height)); height += 15; graphics.DrawString("تخفیف : " + order.TotalDiscount.ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height)); height += 15; graphics.DrawString("توضیحات : " + order.Comment, font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height)); height += 15; graphics.DrawString("جمع کل : " + order.FinalPayment.ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3); graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(300, height)); MemoryStream stream = new MemoryStream(); doc.Save(stream); byte[] test = stream.ToArray(); doc.Close(true); DependencyService.Get <IPrintPdf>().PrintPdf(test, order.OrderId); } else if (Device.RuntimePlatform == Device.UWP) { DependencyService.Get <IPrint>().Print(order, "فاکتور فروش", clientName); } await setOrderNumber(); await setReceiptNumber(); lblTax.Text = "0"; lblDiscount.Text = "0"; lblService.Text = "0"; lblTax.Text = "0"; lblFinalPayment.Text = "0"; lblTotalPrice.Text = "0"; lblDelivery.Text = "0"; ProductsDataGrid.ItemsSource = null; lstProducts.ItemsSource = null; await getCategories(); order = new Order(); } }