예제 #1
0
 public static void Print(CMS_OrderModels modelOrder, string path)
 {
     try
     {
         PrintFromHTML(modelOrder, path);
     }
     catch (Exception ex) { };
 }
예제 #2
0
 public ActionResult LoadOrderDetail(string OrderID)
 {
     try
     {
         var model = new CMS_OrderModels();
         model = _facOrder.GetDetailOrder(OrderID);
         return(PartialView("_OrderDetail", model));
     }
     catch (Exception ex)
     {
         NSLog.Logger.Error("GetOrderDetail", ex);
         return(new HttpStatusCodeResult(400, ex.Message));
     }
 }
예제 #3
0
        public void PrintManual(CMS_OrderModels modelOrder)
        {
            //PdfDocument document = new PdfDocument();
            //document.Info.Author = "Quang Tran TP";
            //document.Info.Keywords = "Lamode";

            //PdfPage page = document.AddPage();
            //page.Size = PageSize.A4;

            //// Obtain an XGraphics object to render to
            //XGraphics gfx = XGraphics.FromPdfPage(page);

            //// Create a font
            //double fontHeight = 36;
            //XFont font = new XFont("Times New Roman", fontHeight, XFontStyle.BoldItalic);

            //// Get the centre of the page
            //double y = page.Height / 2;
            //int lineCount = 0;
            //double linePadding = 10;

            //// Create a rectangle to draw the text in and draw in it
            //XRect rect = new XRect(0, y, page.Width, fontHeight);
            //gfx.DrawString("Hello, World! ", font,
            //               XBrushes.Black, rect, XStringFormats.Center);
            //lineCount++;
            //y += fontHeight;

            //rect = new XRect(0, y, page.Width, fontHeight);
            //gfx.DrawString("This is not" +
            //    " auto-wrap when the edge of the page is reached",
            //               font, XBrushes.Black,
            //               rect, XStringFormats.TopLeft);
            //lineCount++;
            //y += fontHeight;

            //double topY = y - (lineCount * fontHeight) - linePadding;

            //// Draw a line below the text
            //gfx.DrawLine(XPens.Black, 0, y, page.Width, y + linePadding);

            //// Draw a line above the text
            //gfx.DrawLine(XPens.Black, 0, topY, page.Width, topY);

            //// Save and show the document
            //document.Save("C:\\Users\\NoName\\Desktop\\a.pdf");
            //Process.Start("C:\\Users\\NoName\\Desktop\\a.pdf");
        }
예제 #4
0
        public JsonResult getDetail(string id)
        {
            var model = new CMS_OrderModels();

            try
            {
                model = _fac.GetDetailOrder(id);

                if (model != null)
                {
                    model.sCreatedDate = model.CreatedDate.ToString("dd/MM/yyyy hh:mm tt");
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("getDetail_Order:", ex);
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
예제 #5
0
        public static void PrintFromHTML(CMS_OrderModels modelOrder, string path)
        {
            var body = CommonHelper.CreateBodyMail(modelOrder);

            HtmlToPdf converter = new HtmlToPdf();

            converter.Options.PdfPageSize   = PdfPageSize.A5;
            converter.Options.WebPageWidth  = 650;
            converter.Options.WebPageHeight = 0;

            // convert the url to pdf
            SelectPdf.PdfDocument doc = converter.ConvertHtmlString(body);

            // save pdf document
            doc.Save(path);

            // close pdf document
            doc.Close();
        }
예제 #6
0
        public ActionResult Print(string Id)
        {
            var model       = new CMS_OrderModels();
            var pathReceipt = Commons._PublicImages + "Receipt/" + Id + ".pdf";

            try
            {
                model = _fac.GetDetailOrder(Id);
                if (model != null)
                {
                    model.sCreatedDate = model.CreatedDate.ToString("dd/MM/yyyy hh:mm tt");
                }

                var path = Server.MapPath("~/Uploads/Receipt/" + model.Id + ".pdf");
                PrintHelper.Print(model, path);
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("getDetail_Order:", ex);
            }
            return(Redirect(pathReceipt));

            //return View("Print", model);
        }
예제 #7
0
        public static string CreateBodyMail(CMS_OrderModels model)
        {
            string body = string.Empty;

            try
            {
                body += "<div class='payment-order'  style = 'margin: 50px 50px 50px 50px;'>";
                body += "<h3 style  = 'text-align: center'>Mã đơn hàng: <b style='color: #ff0000;'>#" + model.OrderNo + "</b></h3>";
                body += "<p><b>Ngày đặt:</b> <i>" + model.CreatedDate.ToString("dd/MM/yyyy hh:mm tt") + "</i></p>";
                body += "<p><b>Tên khách hàng:</b> <i>" + model.CustomerName + "</i></p>";
                body += "<p><b>Số điện thoại:</b> <i>" + model.Phone + "</i></p>";
                body += "<p><b>Email:</b> <i>" + model.Email + "</i></p>";
                body += "<p><b>Địa chỉ:</b> <i>" + model.Address + "</i></p>";
                body += "<h1 class='page-heading' style= 'font-size: 16px;color: #958457;margin-bottom: 5px;'>Thông tin đơn hàng</h1>";
                body += "<table class='table' style='width: 100%;margin-bottom: 20px;max-width: 100%;border-collapse: collapse;border-spacing: 0;'>";
                body += "<thead style='background-color: #a0ca50 !important;color:#FFF'>";
                body += "<tr>";
                body += "<th style='padding: 15px;vertical-align: bottom;border-bottom: 2px solid #e7ecf1;line-height: 1.42857;'>STT</th>";
                body += "<th style='padding: 15px;vertical-align: bottom;border-bottom: 2px solid #e7ecf1;line-height: 1.42857;'>SẢN PHẨM</th>";
                body += "<th style='padding: 15px;vertical-align: bottom;border-bottom: 2px solid #e7ecf1;line-height: 1.42857;'>GIÁ</th>";
                body += "<th style='padding: 15px;vertical-align: bottom;border-bottom: 2px solid #e7ecf1;line-height: 1.42857;'>SL</th>";
                body += "<th style='padding: 15px;vertical-align: bottom;border-bottom: 2px solid #e7ecf1;line-height: 1.42857;'>T.TIỀN</th>";
                body += "</tr>";
                body += "</thead>";
                body += " <tbody>";
                if (model.Items != null && model.Items.Any())
                {
                    var Index = 1;
                    foreach (var item in model.Items)
                    {
                        body += "<tr>";
                        body += " <td style='padding: 8px;line-height: 1.42857;vertical-align: top;border-top: 1px solid #e7ecf1;text-align:center;'>" + Index + "</td>";
                        body += "<td style='padding: 8px;line-height: 1.42857;vertical-align: top;border-top: 1px solid #e7ecf1;text-align:left;'>";
                        body += "<span>" + item.ProductName + "</span>";
                        body += " <p class='note'></p>";
                        body += "</td>";
                        body += "<td style='padding: 8px;line-height: 1.42857;vertical-align: top;border-top: 1px solid #e7ecf1;text-align:center;'>" + item.Price.ToString("#,0") + "đ</td>";
                        body += "<td style='padding: 8px;line-height: 1.42857;vertical-align: top;border-top: 1px solid #e7ecf1;text-align:center;'>" + item.Quantity + "</td>";
                        body += "<td style='padding: 8px;line-height: 1.42857;vertical-align: top;border-top: 1px solid #e7ecf1;text-align:right;'>" + item.TotalPrice.ToString("#,0") + "đ</td>";
                        body += "</tr>";
                        Index = Index + 1;
                    }
                }
                body += "</tbody>";
                body += "<tfoot>";
                body += "<tr>";
                body += "<td colspan='4' class='label-payment' style='text-transform: uppercase;padding: 8px;line-height: 1.42857;vertical-align: top;border-top: 1px solid #e7ecf1;text-align: right;!important;'><b>Thành tiền</b></td>";
                body += "<td class='total-payment text-center' style='color: #ff0000;border-top: 1px solid #e7ecf1; padding: 8px; text-align:right'>" + model.SubTotal.Value.ToString("#,0") + "đ</td>";
                body += "</tr>";

                if (model.TotalDiscount > 0)
                {
                    body += "<tr>";
                    body += "<td colspan='4' class='label-payment' style='text-transform: uppercase;padding: 8px;line-height: 1.42857;vertical-align: top;border-top: 1px solid #e7ecf1;text-align: right;!important;'><b>Khuyến mãi</b></td>";
                    body += "<td class='total-payment text-center' style='color: #ff0000;border-top: 1px solid #e7ecf1; padding: 8px; text-align:right'>" + model.TotalDiscount.Value.ToString("#,0") + "đ</td>";
                    body += "</tr>";
                }

                if (model.TotalBill != model.SubTotal)
                {
                    body += "<tr>";
                    body += "<td colspan='4' class='label-payment' style='text-transform: uppercase;padding: 8px;line-height: 1.42857;vertical-align: top;border-top: 1px solid #e7ecf1;text-align: right;!important;'><b>Tiền cần thanh toán</b></td>";
                    body += "<td class='total-payment' style='color: #ff0000;border-top: 1px solid #e7ecf1; padding: 8px; text-align:right'>" + model.TotalBill.Value.ToString("#,0") + "đ</td>";
                    body += "</tr>";
                }

                body += "</tfoot>";
                body += "</table>";
                body += "<p><b>Địa chỉ:</b> <i>181 / 29 Âu Dương Lân, P.2, Q.8, HCM</i></p>";
                body += "<p><b>Số điện thoại:</b> <i>(+84) 0993.5555.99</i></p>";
                body += "<p><b>Facebook:</b> <i>fb.com/LamodeHomeSpa</i></p>";
                body += "<p style='color: #ff0000;border-top: 1px solid #e7ecf1;text-align:center'><i>Lamode xin cảm ơn quý khách đã tin tưởng và ủng hộ!</i></p>";
                body += "<div style = 'margin: auto; width: 50%'>";
                body += "<img class='img1' src='https://lamodehome.com/Images/LogoFull.png' alt='logo' style = 'display: block; margin - left: auto; margin - right: auto;'/>";
                body += "</div>";
                body += "<br clear=\"all\">";
                body += "</div>";
            }
            catch (Exception ex) { }

            return(body);
        }
예제 #8
0
        public ActionResult CheckOut(CMS_CheckOutModels model)
        {
            try
            {
                var _Orders = GetListOrderCookie();
                NSLog.Logger.Info("List Order Cookie", JsonConvert.SerializeObject(_Orders));
                if (_Orders != null && _Orders.Any())
                {
                    var ItemIds = _Orders.Select(x => x.ItemId).ToList();
                    var data    = _fac.GetList().Where(o => ItemIds.Contains(o.Id))
                                  .Select(o => new CMS_ItemModels
                    {
                        Price       = o.ProductPrice,
                        ProductID   = o.Id,
                        ProductName = o.ProductName,
                        Quantity    = o.Quantity
                    }).ToList();
                    if (data != null && data.Any())
                    {
                        data.ForEach(o =>
                        {
                            var item     = _Orders.FirstOrDefault(z => z.ItemId.Equals(o.ProductID));
                            o.Quantity   = item.Quantity;
                            o.TotalPrice = Convert.ToDouble(o.Price * item.Quantity);
                        });
                        model.ListItem = data;

                        model.TotalPrice    = data.Sum(o => o.TotalPrice);
                        model.SubTotalPrice = data.Sum(o => o.TotalPrice);

                        if (!string.IsNullOrEmpty(model.DiscountID))
                        {
                            model.ListItem.Add(new CMS_ItemModels
                            {
                                DiscountID    = model.DiscountID,
                                DiscountType  = model.DiscountType,
                                DiscountValue = model.DiscountValue
                            });

                            if (model.DiscountType == (byte)CMS_Common.Commons.EValueType.Percent)
                            {
                                model.TotalDiscount = CommonHelper.RoundingOption4(model.TotalPrice * (model.DiscountValue / 100));
                            }
                            else
                            {
                                model.TotalDiscount = model.DiscountValue;
                            }
                            model.TotalPrice = CommonHelper.RoundingOption4(model.TotalPrice - model.TotalDiscount);
                        }
                    }
                    var OrderId = string.Empty;
                    var result  = _facOrder.CreateOrder(model, ref OrderId);
                    if (result)
                    {
                        //get info order
                        if (!string.IsNullOrEmpty(OrderId))
                        {
                            var modelOrder = new CMS_OrderModels();
                            modelOrder = _facOrder.GetDetailOrder(OrderId);
                            //body mail
                            var body    = CommonHelper.CreateBodyMail(modelOrder);
                            var subject = "[V/v đơn hàng " + modelOrder.OrderNo + "]";
                            //Send to admin
                            CommonHelper.SendContentMail(ConfigurationManager.AppSettings["LamodeMail"], body, "", subject, "", "");
                            //Send to customer
                            CommonHelper.SendContentMail(modelOrder.Email, body, "", subject, "", "");
                        }
                        HttpCookie currentUserCookie = HttpContext.Request.Cookies["cms-order"];
                        HttpContext.Response.Cookies.Remove("cms-order");
                        currentUserCookie.Expires = DateTime.Now.AddDays(-10);
                        currentUserCookie.Value   = null;
                        HttpContext.Response.SetCookie(currentUserCookie);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        model.IsError = true;
                    }
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("CheckOut", ex);
            }
            return(View(model));
        }
예제 #9
0
        public CMS_OrderModels GetDetailOrder(string OrderId)
        {
            var data = new CMS_OrderModels();

            try
            {
                NSLog.Logger.Info("GetDetailOrder_Request : ", OrderId);
                using (var db = new CMS_Context())
                {
                    data = db.CMS_Order.GroupJoin(db.CMS_OrderDetail, o => o.ID, d => d.OrderID, (o, d) => new { o, d })
                           .GroupJoin(db.CMS_Customer, o => o.o.CustomerID, c => c.ID, (o, c) => new { o = o.o, d = o.d, c })
                           .Where(o => o.o.ID.Equals(OrderId))
                           .Select(r => new CMS_OrderModels
                    {
                        CreatedDate   = r.o.CreatedDate,
                        CustomerId    = r.o.CustomerID,
                        CustomerName  = string.IsNullOrEmpty(r.o.CustomerID) ? "" : r.c.Select(x => x.FirstName + " " + x.LastName).FirstOrDefault(),
                        OrderNo       = r.o.OrderNo,
                        Id            = r.o.ID,
                        Phone         = string.IsNullOrEmpty(r.o.CustomerID) ? "" : r.c.Select(x => x.Phone).FirstOrDefault(),
                        TotalBill     = r.o.TotalBill,
                        SubTotal      = r.o.SubTotal,
                        TotalDiscount = r.o.TotalDiscount,
                        City          = string.IsNullOrEmpty(r.o.CustomerID) ? "" : r.c.Select(x => x.HomeCity).FirstOrDefault(),
                        Country       = string.IsNullOrEmpty(r.o.CustomerID) ? "" : r.c.Select(x => x.HomeCountry).FirstOrDefault(),
                        Email         = string.IsNullOrEmpty(r.o.CustomerID) ? "" : r.c.Select(x => x.Email).FirstOrDefault(),
                        PostCode      = string.IsNullOrEmpty(r.o.CustomerID) ? "" : r.c.Select(x => x.HomeZipCode).FirstOrDefault(),
                        Description   = r.d.Select(x => x.Description).FirstOrDefault(),
                        Address       = string.IsNullOrEmpty(r.o.CustomerID) ? "" : r.c.Select(x => x.HomeStreet).FirstOrDefault(),
                        Items         = r.d.Select(x => new CMS_ItemModels
                        {
                            Price         = x.Price.HasValue ? x.Price.Value : 0,
                            ProductID     = x.ProductID,
                            ProductName   = x.CMS_Products.Name,
                            Quantity      = x.Quantity.HasValue ? (double)x.Quantity.Value : 0,
                            TotalPrice    = (x.Price.Value * (double)x.Quantity.Value),
                            DiscountID    = x.DiscountID,
                            DiscountType  = x.DiscountType,
                            DiscountValue = (float)x.DiscountValue,
                            Description   = x.Description,
                            EmployeeID    = x.EmployeeID,
                            EmployeeName  = x.CMS_Employees != null ? x.CMS_Employees.Name : "",
                        }).ToList()
                    }).FirstOrDefault();

                    //var listEmployeeID = data.Items.Select(o => o.EmployeeID).ToList();
                    //var listEmp = db.CMS_Employee.Where(o => listEmployeeID.Contains(o.ID)).ToList();
                    //data.Items.ForEach(o =>
                    //{
                    //    o.EmployeeName = listEmp.Where(e => e.ID == o.EmployeeID).Select(e => e.Name).FirstOrDefault();
                    //});

                    NSLog.Logger.Info("GetDetailOrder_Response : ", data);
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("GetDetailOrder :", ex);
            }
            return(data);
        }