void BenXeToBenXeModel(BenXe itemfrom, BenXeModel itemto) { itemto.Id = itemfrom.Id; itemto.TenBenXe = itemfrom.TenBenXe; itemto.DiaChiId = itemfrom.DiaChiId; itemto.HienThi = itemfrom.HienThi; itemto.PictureId = itemfrom.PictureId; itemto.PictureUrl = _pictureService.GetPictureUrl(itemfrom.PictureId); itemto.MoTa = itemfrom.MoTa; var diachi = _diachiService.GetById(itemfrom.DiaChiId); if (diachi != null) { string strhuyen = ""; if (diachi.QuanHuyenID > 0) { var quanhuyen = _diachiService.GetQuanHuyenById(diachi.QuanHuyenID.GetValueOrDefault(0)); if (quanhuyen != null) { strhuyen = "- " + quanhuyen.Ten + " "; } } itemto.DiaChiText = string.Format("{0} {1}- {2}", diachi.DiaChi1, strhuyen, diachi.Province.Name); } }
public ActionResult SuaNhaXe(NhaXeModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.QLNhaXe)) { return(AccessDeniedView()); } var nhaxe = _nhaxeService.GetNhaXeById(model.Id); if (nhaxe == null || nhaxe.isDelete) { //No manufacturer found with the specified id return(RedirectToAction("ListNhaXe")); } if (ModelState.IsValid) { int prevLogoID = nhaxe.LogoID; int prevAnhDaiDienID = nhaxe.AnhDaiDienID; //diachi.Id = nhaxe.DiaChiID; nhaxe = model.ToEntity(nhaxe); _nhaxeService.UpdateNhaXe(nhaxe); var diachi = _diachiService.GetById(nhaxe.DiaChiID); diachi = model.ThongTinDiaChi.ToEntity(diachi); diachi.Id = nhaxe.DiaChiID; _diachiService.Update(diachi); //delete an old picture (if deleted or updated) if (prevLogoID > 0 && prevLogoID != nhaxe.LogoID) { var prevPicture = _pictureService.GetPictureById(prevLogoID); if (prevPicture != null) { _pictureService.DeletePicture(prevPicture); } } if (prevAnhDaiDienID > 0 && prevAnhDaiDienID != nhaxe.AnhDaiDienID) { var prevPicture = _pictureService.GetPictureById(prevAnhDaiDienID); if (prevPicture != null) { _pictureService.DeletePicture(prevPicture); } } if (continueEditing) { //selected tab SaveSelectedTabIndex(); return(RedirectToAction("SuaNhaXe", nhaxe.Id)); } return(RedirectToAction("ListNhaXe")); } return(View(model)); }
/// <summary> /// Print orders to PDF /// </summary> /// <param name="stream">Stream</param> /// <param name="orders">Orders</param> /// <param name="languageId">Language identifier; 0 to use a language used when placing an order</param> public virtual void PrintOrdersToPdf(Stream stream, PhoiVe _phoive, int languageId = 0) { if (stream == null) { throw new ArgumentNullException("stream"); } if (_phoive == null) { throw new ArgumentNullException("Không có vé"); } //get thong tin nguon ve var order = _orderService.GetOrderById(_phoive.OrderId); if (order == null) { throw new ArgumentNullException("Không có đơn hàng"); } var nguonvexe = _hanhtrinhService.GetNguonVeXeById(_phoive.NguonVeXeId); if (nguonvexe.ParentId > 0) { nguonvexe = _hanhtrinhService.GetNguonVeXeById(_phoive.NguonVeXeConId); } //get thong tin nha xe var nhaxe = _nhaxeService.GetNhaXeById(nguonvexe.NhaXeId); var diachi = _diachiService.GetById(nhaxe.DiaChiID); //get thong tin xe xuan ben var xexuatbenInfo = _nhaxeService.GetHistoryXeXuatBenByNguonVeId(nguonvexe.Id, _phoive.NgayDi); var TenXe = ""; var BienSo = ""; if (xexuatbenInfo != null) { var xeInfo = _xeinfoService.GetXeInfoById(xexuatbenInfo.XeVanChuyenId.GetValueOrDefault(0)); TenXe = xeInfo.TenXe; BienSo = xeInfo.BienSo; } //logo var logoPicture = _pictureService.GetPictureById(nhaxe.LogoID); var logoExists = logoPicture != null; var doc = new Document(); var pdfWriter = PdfWriter.GetInstance(doc, stream); doc.Open(); //fonts var titleFont = GetFont(); titleFont.Size = BaseFont.SUPERSCRIPT_SIZE; //font ten nha xe var TenNhaXe = GetFont(); TenNhaXe.SetStyle("initial"); //font thong tin var InfoFont = GetFont(); InfoFont.Size = 14; var font = GetFont(); font.Size = 13; var pdfSettingsByStore = _settingContext.LoadSetting <PdfSettings>(order.StoreId); var lang = _workContext.WorkingLanguage; //header float[] widths = { 3, 7 }; var HeaderVeIn = new PdfPTable(widths); HeaderVeIn.DefaultCell.Border = Rectangle.NO_BORDER; if (logoExists) { var logoFilePath = _pictureService.GetThumbLocalPath(logoPicture, 0, false); var logo = Image.GetInstance(logoFilePath); logo.ScaleToFit(200, 100); PdfPCell CellLeft = new PdfPCell(logo); CellLeft.Border = Rectangle.NO_BORDER; CellLeft.FixedHeight = 80f; HeaderVeIn.AddCell(CellLeft); } PdfPCell CellRight = new PdfPCell(); CellRight.Border = Rectangle.NO_BORDER; var ParaTenNhaXe = new Paragraph(string.Format(_localizationService.GetResource("PDFInvoice.TenNhaXe", lang.Id), nhaxe.TenNhaXe), font); ParaTenNhaXe.Alignment = Element.ALIGN_RIGHT; CellRight.AddElement(ParaTenNhaXe); var ParaDiaChi = new Paragraph(string.Format(_localizationService.GetResource("PDFInvoice.DiaChiNhXe", lang.Id), diachi.DiaChi1 + " " + diachi.DiaChi2), font); ParaDiaChi.Alignment = Element.ALIGN_RIGHT; CellRight.AddElement(ParaDiaChi); var ParaSdt = new Paragraph(string.Format(_localizationService.GetResource("PDFInvoice.SDTNhaXe", lang.Id), nhaxe.DienThoai), font); ParaSdt.Alignment = Element.ALIGN_RIGHT; CellRight.AddElement(ParaSdt); HeaderVeIn.AddCell(CellRight); doc.Add(HeaderVeIn); doc.Add(new Paragraph("")); doc.Add(new Paragraph("")); //add line var line = new iTextSharp.text.pdf.draw.LineSeparator(0, 100, BaseColor.GRAY, Element.ALIGN_CENTER, 1); doc.Add(new Chunk(line)); //content Paragraph vexekhach = new Paragraph(_localizationService.GetResource("PDFInvoice.VeXeKhach", lang.Id), titleFont); vexekhach.Alignment = Element.ALIGN_CENTER; doc.Add(vexekhach); doc.Add(new Paragraph("")); doc.Add(new Paragraph("")); var Table1 = new PdfPTable(2); float[] widthTable1 = new float[] { 1f, 2f }; Table1.SetWidths(widthTable1); Table1.RunDirection = GetDirection(lang); Table1.DefaultCell.Border = Rectangle.NO_BORDER; Table1.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.Tuyen", lang.Id), font)); Table1.AddCell(new Paragraph(nguonvexe.TenDiemDon + " -- " + nguonvexe.TenDiemDen, InfoFont)); Table1.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.GiaVe", lang.Id), font)); Table1.AddCell(new Paragraph(nguonvexe.LichTrinhInfo.GiaVeToanTuyen.ToString() + " VNĐ", InfoFont)); doc.Add(Table1); //add ghe,xe var Table2 = new PdfPTable(4); float[] widthTable2 = new float[] { 1f, 2f, 1f, 2f }; Table2.SetWidths(widthTable2); Table2.RunDirection = GetDirection(lang); Table2.DefaultCell.Border = Rectangle.NO_BORDER; Table2.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.SoXe", lang.Id), font)); Table2.AddCell(new Paragraph(TenXe + "/" + BienSo, InfoFont)); Table2.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.SoGhe", lang.Id), font)); Table2.AddCell(new Paragraph(_phoive.sodoghexequytac.Val + " ( Tầng" + _phoive.sodoghexequytac.Tang + ")", InfoFont)); doc.Add(Table2); //add thoi gian khoi hanh var Table3 = new PdfPTable(4); float[] widthTable3 = new float[] { 2f, 1f, 1f, 2f }; Table3.SetWidths(widthTable3); Table3.RunDirection = GetDirection(lang); Table3.DefaultCell.Border = Rectangle.NO_BORDER; Table3.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.ThoiGianDi", lang.Id), font)); Table3.AddCell(new Paragraph(nguonvexe.ThoiGianDi.ToString("HH:mm"), InfoFont)); Table3.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.NgayDi", lang.Id), font)); Table3.AddCell(new Paragraph(_phoive.NgayDi.ToString("dd/MM/yyyy"), InfoFont)); doc.Add(Table3); //add footer var FooterNgayBan = new Paragraph("Ngày " + DateTime.Now.Day + " tháng " + DateTime.Now.Month + " năm " + DateTime.Now.Year, font); FooterNgayBan.Alignment = Element.ALIGN_RIGHT; var FooterNguoiBanTitle = new Paragraph("Người bán vé", font); FooterNguoiBanTitle.Alignment = Element.ALIGN_RIGHT; var firtname = _workContext.CurrentCustomer.GetAttribute <string>(SystemCustomerAttributeNames.FirstName); var lastname = _workContext.CurrentCustomer.GetAttribute <string>(SystemCustomerAttributeNames.LastName); var FooterTenNguoiBan = new Paragraph(firtname + " " + lastname, font); FooterTenNguoiBan.Alignment = Element.ALIGN_RIGHT; var Table4 = new PdfPTable(1); Table4.DefaultCell.Border = Rectangle.NO_BORDER; PdfPCell CellFooter = new PdfPCell(); CellFooter.Border = Rectangle.NO_BORDER; CellFooter.AddElement(FooterNgayBan); CellFooter.AddElement(FooterNguoiBanTitle); CellFooter.AddElement(FooterTenNguoiBan); Table4.AddCell(CellFooter); doc.Add(Table4); doc.Add(new Paragraph(" ")); doc.NewPage(); doc.Close(); }