Exemple #1
0
 static public RestaurantInfoManager getInstance()
 {
     if (_instance == null)
     {
         _instance = new RestaurantInfoManager();
     }
     return(_instance);
 }
Exemple #2
0
        public void exportBillAsPdf(string path, Order order)
        {
            if (order == null)
            {
                return;
            }
            try {
                FileStream fs = new FileStream(path + "\\Order" + order.OrderId.ToString() + ".pdf", FileMode.Create);

                Document document = new Document(PageSize.A4, 25, 25, 30, 30);

                PdfWriter writer = PdfWriter.GetInstance(document, fs);
                document.Open();

                string orderStr = "Nhà hàng: " + RestaurantInfoManager.getInstance().Info.Name;
                orderStr += "\n" + "Số điện thoại: " + RestaurantInfoManager.getInstance().Info.Phone;
                orderStr += "\n" + "Địa chỉ: " + RestaurantInfoManager.getInstance().Info.Address;
                orderStr += "\n" + "Thời điểm: " + DateTime.Now.ToString("H:mm:ss  dd/MM/yyyy");

                orderStr += "\n\n" + "             Hóa đơn bán hàng ";
                foreach (FoodWithOrder foodWithOrder in order.FoodWithOrders)
                {
                    string strFoodName  = foodWithOrder.Food.FoodId + "-" + foodWithOrder.Food.Name;
                    string strQuantity  = foodWithOrder.Quantities.ToString();
                    string strFoodPrice = "x  " + UtilFuction.formatMoney(foodWithOrder.Food.Price);
                    orderStr += "\n"
                                + strFoodName + UtilFuction.getSpacesFromQuantityChar(50, strFoodName)
                                + strQuantity + UtilFuction.getSpacesFromQuantityChar(10, strQuantity)
                                + strFoodPrice + UtilFuction.getSpacesFromQuantityChar(10, strFoodPrice);
                }
                string totalStr = "TỔNG CỘNG: ";
                orderStr += "\n\n" + totalStr + UtilFuction.getSpacesFromQuantityChar(70, totalStr) + UtilFuction.formatMoney(order.BillMoney);

                orderStr += "\n\n\n Nếu quý khách có nhu cầu xuất hóa đơn, \n xin liên hệ với chúng tôi trong ngày.";

                iTextSharp.text.Font font = null;
                try {
                    var vini = BaseFont.CreateFont("c:/windows/fonts/aachenb.ttf", BaseFont.IDENTITY_H, true);
                    font = new iTextSharp.text.Font(vini, 14);
                } catch (Exception ex) {
                }
                if (font != null)
                {
                    document.Add(new Paragraph(18, orderStr, font));
                }
                else
                {
                    document.Add(new Paragraph(16, orderStr, font));
                }

                document.Close();
                fs.Close();
            } catch (Exception ex) {
            }
        }
        public void exportBillAsPdf(string path, Order order)
        {
            if (order == null)
            {
                return;
            }
            try {
                FileStream fs = new FileStream(path + "\\Order" + order.OrderId.ToString() + ".pdf", FileMode.Create);

                Document document = new Document(PageSize.A4, 25, 25, 30, 30);

                PdfWriter writer = PdfWriter.GetInstance(document, fs);
                document.Open();

                string orderStr = "Nhà hàng: " + RestaurantInfoManager.getInstance().Info.Name;
                orderStr += "\n" + "Số điện thoại: " + RestaurantInfoManager.getInstance().Info.Phone;
                orderStr += "\n" + "Địa chỉ: " + RestaurantInfoManager.getInstance().Info.Address;
                orderStr += "\n" + "Thời điểm: " + DateTime.Now.ToString("H:mm:ss  dd/MM/yyyy");

                orderStr += "\n\n" + "             Hóa đơn bán hàng ";
                var index = 1;
                foreach (FoodWithOrder foodWithOrder in order.FoodWithOrders)
                {
                    string strFoodName  = index + "-" + foodWithOrder.Food.Name;
                    string strQuantity  = foodWithOrder.Quantities.ToString();
                    string strFoodPrice = "x  " + UtilFuction.formatMoney(foodWithOrder.Food.Price);
                    orderStr += "\n"
                                + strFoodName + UtilFuction.getSpacesFromQuantityChar(50, strFoodName)
                                + strQuantity + UtilFuction.getSpacesFromQuantityChar(10, strQuantity)
                                + strFoodPrice + UtilFuction.getSpacesFromQuantityChar(10, strFoodPrice);
                    index++;
                }
                orderStr += "\n ========================================================================";
                string totalStr = "TỔNG CỘNG: ";
                orderStr += "\n\n" + totalStr + UtilFuction.getSpacesFromQuantityChar(70, totalStr) + UtilFuction.formatMoney(order.BillMoney);

                //orderStr += "\n\n\n Nếu quý khách có nhu cầu xuất hóa đơn, \n xin liên hệ với chúng tôi trong ngày.";

                string appFolderPath      = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                iTextSharp.text.Font font = null;
                try {
                    string fontPath = Path.Combine(Directory.GetParent(appFolderPath).Parent.FullName, "Resource/Font/VT323-Regular.ttf");
                    var    vini     = BaseFont.CreateFont(fontPath, BaseFont.IDENTITY_H, true);
                    font = new iTextSharp.text.Font(vini, 14);
                } catch (Exception ex) {
                }
                if (font != null)
                {
                    document.Add(new Paragraph(18, orderStr, font));
                }
                else
                {
                    document.Add(new Paragraph(16, orderStr, font));
                }

                document.Close();
                fs.Close();
            } catch (Exception ex) {
                Console.Write(ex.Message);
            }
        }