public FileResult Avatar(Guid UID, int?Width) { var cover = db.UserProfiles.FirstOrDefault(x => x.UserID == UID); FileStreamResult result; if (cover == null || cover.Avatar == null || UID == new Guid()) { var fs = new FileStream(Server.MapPath("/content/noimage.jpg"), FileMode.Open, FileAccess.Read); result = new FileStreamResult(fs, "image/jpg"); } else { try { var ms = new MemoryStream(cover.Avatar.ToArray()); ms.Seek(0L, SeekOrigin.Begin); var bmpIn = new Bitmap(ms); ImageFormat loFormat = bmpIn.RawFormat; Bitmap bmpOut = bmpIn.CreateThumbnail(Width ?? 64, Width ?? 64, true); ms.Close(); var res = new MemoryStream(); bmpOut.Save(res, loFormat); res.Seek(0L, SeekOrigin.Begin); result = new FileStreamResult(res, MIMETypeWrapper.GetMIME(loFormat.ToString())); } catch (Exception) { var fs = new FileStream(Server.MapPath("/content/anon.jpg"), FileMode.Open, FileAccess.Read); result = new FileStreamResult(fs, "image/jpg"); } } return(result); }
public FileResult Flag(int ID, int?width) { var cached = HttpRuntime.Cache.Get(string.Format("Flag_{0}_{1}", ID, width)); if (cached is byte[]) { return(new FileStreamResult(new MemoryStream((byte[])cached), MIMETypeWrapper.GetMIME("jpeg"))); } var cover = db.Languages.First(x => x.ID == ID); FileStreamResult result; if (cover == null || cover.Icon == null) { var fs = new FileStream(Server.MapPath("/Content/nopic.gif"), FileMode.Open, FileAccess.Read); result = new FileStreamResult(fs, "image/gif"); } else { var ms = new MemoryStream(cover.Icon.ToArray()); ms.Seek(0L, SeekOrigin.Begin); var bmpIn = new Bitmap(ms); ImageFormat loFormat = bmpIn.RawFormat; Bitmap bmpOut = bmpIn.CreateThumbnail(width ?? cover.getProperWidth(cover.Width), cover.getProperHeight(width ?? cover.Width), false); ms.Close(); var res = new MemoryStream(); bmpOut.Save(res, loFormat); res.Seek(0L, SeekOrigin.Begin); HttpRuntime.Cache.Insert(string.Format("Flag_{0}_{1}", ID, width), res.ToArray(), null, DateTime.Now.AddDays(1D), Cache.NoSlidingExpiration); result = new FileStreamResult(res, MIMETypeWrapper.GetMIME(loFormat.ToString())); } return(result); }
public ActionResult Index(string url1, string url2, string url3, string url4, string url5, string url6, string url7, string url8, string url9, string url10, string url11, string url12, string url13, string url14, string url15, int?book, int?page) { if (AccessHelper.Repository.ContainsKey("Refreshed")) { AccessHelper.Repository.Remove("Refreshed"); } var path = new List <string> { url1, url2, url3, url4, url5, url6, url7, url8, url9, url10, url11, url12, url13, url14, url15 }; var jnp = "~/" + string.Join("/", path.Where(x => !x.IsNullOrEmpty()).ToList()); var mapped = Server.MapPath(jnp); if (System.IO.File.Exists(mapped) && Path.GetExtension(mapped) != ".cshtml") { return(File(mapped, MIMETypeWrapper.GetMIME(Path.GetExtension(mapped)))); } var info = CommonPageInfo.InitFromQueryParams(path.Where(x => !x.IsNullOrEmpty()).ToList()); AccessHelper.CurrentPageInfo = info; ViewBag.CommonInfo = info; return(View(info)); }
protected static bool Send(string sendTo, string sendFrom, string sendSubject, string sendMessage, List <string> attachments, List <KeyValuePair <string, MemoryStream> > memAttaches, out string result) { try { bool bTest = sendTo.IsMailAdress(); if (bTest == false) { result = "Неправильно указан адрес: " + sendTo; return(false); } var message = new MailMessage( sendFrom, sendTo, sendSubject, sendMessage); message.IsBodyHtml = true; message.BodyEncoding = Encoding.UTF8; foreach (string attach in attachments) { var attached = new Attachment(attach, MediaTypeNames.Application.Octet); //attached.NameEncoding = Encoding.UTF8; message.Attachments.Add(attached); } foreach (var pair in memAttaches) { pair.Value.Position = 0; var attached = new Attachment(pair.Value, pair.Key, MIMETypeWrapper.GetMIME(Path.GetExtension(pair.Key).Substring(1))); //attached.NameEncoding = Encoding.UTF8; message.Attachments.Add(attached); } // create smtp client at mail server location var client = new SmtpClient(SiteSetting.Get <string>("SMTP")); if (SiteSetting.Get <Int32>("SMTPPort") > 0) { client.Port = SiteSetting.Get <Int32>("SMTPPort"); } if (SiteSetting.Get <string>("SMTPLogin").IsNullOrEmpty() || SiteSetting.Get <string>("SMTPPass").IsNullOrEmpty()) { client.UseDefaultCredentials = true; } else { client.Credentials = new NetworkCredential(SiteSetting.Get <string>("SMTPLogin"), SiteSetting.Get <string>("SMTPPass")); } client.Send(message); result = ""; return(true); } catch (Exception ex) { result = ex.Message; return(false); } }
public ActionResult XLS(string List) { var stream = new MemoryStream(); var workbook = new HSSFWorkbook(); var ids = List.Split <int>(";"); var orders = DB.Orders.Where(x => ids.Contains(x.ID) && x.Shop != null && x.Shop.Owner == CurrentUser.ShopOwnerID).ToList(); foreach (var order in orders) { var worksheet = workbook.CreateSheet("Заказ №" + order.OrderNumberOrID.Replace("[", "@").Replace("]", "@")); var header = worksheet.CreateRow(0); header.CreateCell(0).SetCellValue("Информация о заказе:"); header = worksheet.CreateRow(1); header.CreateCell(0).SetCellValue("Номер заказа"); header.CreateCell(1).SetCellValue(order.OrderNumberOrID); header = worksheet.CreateRow(2); header.CreateCell(0).SetCellValue("Статус заказа"); header.CreateCell(1).SetCellValue(order.StatusText); header = worksheet.CreateRow(3); header.CreateCell(0).SetCellValue("Пометка \"Важный\""); header.CreateCell(1).SetCellValue(order.IsImportant.ToYesNoStatus()); header = worksheet.CreateRow(4); header.CreateCell(0).SetCellValue("Дата создания"); header.CreateCell(1).SetCellValue(order.CreateDate.ToString("dd.MM.yyyy HH:mm:ss")); header = worksheet.CreateRow(5); header.CreateCell(0).SetCellValue("Комментарий"); header.CreateCell(1).SetCellValue(order.Warning); header = worksheet.CreateRow(6); header.CreateCell(0).SetCellValue(""); if (order.Consumer != null) { header = worksheet.CreateRow(7); header.CreateCell(0).SetCellValue("Информация о покупателе:"); header = worksheet.CreateRow(8); header.CreateCell(0).SetCellValue("ФИО"); header.CreateCell(1).SetCellValue(order.Consumer.FullName); header = worksheet.CreateRow(9); header.CreateCell(0).SetCellValue("Телефон"); header.CreateCell(1).SetCellValue(order.Consumer.Phone); header = worksheet.CreateRow(10); header.CreateCell(0).SetCellValue(""); } if (order.OrderedProducts.Any()) { header = worksheet.CreateRow(11); header.CreateCell(0).SetCellValue("Заказанные товары:"); header = worksheet.CreateRow(12); header.CreateCell(0).SetCellValue("Название"); header.CreateCell(1).SetCellValue("Артикул"); header.CreateCell(2).SetCellValue("Цена"); header.CreateCell(3).SetCellValue("Количество"); header.CreateCell(4).SetCellValue("Вес"); int index = 5; foreach (var ch in order.CharList) { header.CreateCell(index).SetCellValue(ch.Name); index++; } int msi = 13; foreach (var product in order.OrderedProducts) { header = worksheet.CreateRow(msi); header.CreateCell(0).SetCellValue(product.Product.Name); header.CreateCell(1).SetCellValue(product.Product.Article); header.CreateCell(2).SetCellValue(product.Price.ToString()); header.CreateCell(3).SetCellValue(product.Amount); header.CreateCell(4).SetCellValue(product.Product.Weight.ToString()); index = 5; foreach (var ch in order.CharList) { header.CreateCell(index) .SetCellValue(product.ProductChars.Any(x => x.Name == ch.Name) ? product.ProductChars.First(x => x.Name == ch.Name).Value : ""); index++; } msi++; } } } workbook.Write(stream); return(File(stream.ToArray(), MIMETypeWrapper.GetMIME("xls"), "Order_" + List.Trim(';').Replace(";", "_") + ".xls")); }
public ActionResult Torg12(string List) { var stream = new MemoryStream(); var ids = List.Split <int>(";"); var orders = DB.Orders.Where(x => ids.Contains(x.ID) && x.Shop != null && x.Shop.Owner == CurrentUser.ShopOwnerID).ToList(); var workbook = new HSSFWorkbook(); using (var fs = new FileStream(Server.MapPath("~/Content/TORG12.xls"), FileMode.Open)) { var example = new HSSFWorkbook(fs); int index = 0; foreach (var order in orders) { var sheet = (HSSFSheet)example.GetSheetAt(0); sheet.CopyTo(workbook, "Заказ №" + order.OrderNumberOrID.Replace("'", "").Replace("[", "@").Replace("]", "@"), true, false); var copied = (HSSFSheet)workbook.GetSheetAt(index); copied.GetRow(2).GetCell(1).SetCellValue(order.Requisites); copied.GetRow(9).GetCell(3).SetCellValue(order.Requisites); copied.GetRow(7).GetCell(3).SetCellValue(order.Receiver); copied.GetRow(11).GetCell(3).SetCellValue(order.Receiver); copied.GetRow(3).GetCell(37).SetCellValue(order.Shop.GetSetting("OKPO")); copied.GetRow(8).GetCell(37).SetCellValue(order.Shop.GetSetting("OKPO")); copied.GetRow(16).GetCell(10).SetCellValue(order.OrderNumberOrID); copied.GetRow(16).GetCell(14).SetCellValue(DateTime.Now.ToString("dd.MM.yyyy")); if (order.OrderedProducts.Count > 1) { for (int i = 1; i < order.OrderedProducts.Count; i++) { copied.GetRow(22).CopyRowTo(23); } } int oi = 0; foreach (var product in order.OrderedProducts) { var row = copied.GetRow(22 + oi); row.GetCell(1).SetCellValue(oi + 1); row.GetCell(2).SetCellValue(product.Product.Name); row.GetCell(6).SetCellValue(product.Product.Article); row.GetCell(7).SetCellValue(product.Product.AmountUnitName); row.GetCell(11).SetCellValue(product.Product.UnitCode); row.GetCell(21).SetCellValue(product.Amount); row.GetCell(23).SetCellValue((product.PriceWithoutNDS).ToString("f2")); row.GetCell(25).SetCellValue((product.PriceWithoutNDS * product.Amount).ToString("f2")); row.GetCell(30).SetCellValue("18%"); row.GetCell(33).SetCellValue((product.NDS * product.Amount).ToString("f2")); row.GetCell(36).SetCellValue((product.Price * product.Amount).ToString("f2")); oi++; } var rws1 = copied.GetRow(22 + oi); var rws2 = copied.GetRow(22 + oi + 1); rws1.GetCell(21).SetCellValue(order.OrderedProducts.Sum(x => x.Amount)); rws2.GetCell(21).SetCellValue(order.OrderedProducts.Sum(x => x.Amount)); rws1.GetCell(23).SetCellValue("X"); rws2.GetCell(23).SetCellValue("X"); rws1.GetCell(25).SetCellValue(order.OrderedProducts.Sum(x => x.Amount * x.PriceWithoutNDS).ToString("f2")); rws2.GetCell(25).SetCellValue(order.OrderedProducts.Sum(x => x.Amount * x.PriceWithoutNDS).ToString("f2")); rws1.GetCell(30).SetCellValue("X"); rws2.GetCell(30).SetCellValue("X"); rws1.GetCell(33).SetCellValue(order.OrderedProducts.Sum(x => x.Amount * x.NDS).ToString("f2")); rws2.GetCell(33).SetCellValue(order.OrderedProducts.Sum(x => x.Amount * x.NDS).ToString("f2")); rws1.GetCell(36).SetCellValue(order.OrderedProducts.Sum(x => x.Amount * x.Price).ToString("f2")); rws2.GetCell(36).SetCellValue(order.OrderedProducts.Sum(x => x.Amount * x.Price).ToString("f2")); copied.GetRow(22 + oi + 3) .GetCell(5) .SetCellValue(Russian.ToString(order.OrderedProducts.Count, Gender.Masculine)); var all = order.OrderedProducts.Sum(x => x.Price * x.Amount); var allStr = Russian.ToString((int)all, Gender.Masculine, true) + " рублей " + ((int)((all - (int)all) * 100)).ToString("d2") + " копеек"; copied.GetRow(22 + oi + 13) .GetCell(1) .SetCellValue(allStr); index++; } workbook.Write(stream); } return(File(stream.ToArray(), MIMETypeWrapper.GetMIME("xls"), "Torg12_" + List.Trim(';').Replace(";", "_") + ".xls")); }