public ActionResult GenerateBarcode() { BarCodeServ.BarCodeSoapClient bc = new BarCodeServ.BarCodeSoapClient(); BarCodeData barCodeData = new BarCodeData(); barCodeData.Height = 125; barCodeData.Width = 225; barCodeData.Angle = 0; barCodeData.Ratio = 5; barCodeData.Module = 0; barCodeData.Left = 25; barCodeData.Top = 0; barCodeData.CheckSum = false; barCodeData.FontName = "Arial"; barCodeData.BarColor = "Black"; barCodeData.BGColor = "White"; barCodeData.FontSize = 10.0f; barCodeData.barcodeOption = BarcodeOption.Both; barCodeData.barcodeType = BarcodeType.Code_2_5_interleaved; barCodeData.checkSumMethod = CheckSumMethod.None; barCodeData.showTextPosition = ShowTextPosition.BottomCenter; barCodeData.BarCodeImageFormat = ImageFormats.PNG; Random r = new Random(); randumNum = r.Next(1000); Byte[] imgBarcode = bc.GenerateBarCode(barCodeData, randumNum.ToString()); MemoryStream memStream = new MemoryStream(imgBarcode); Bitmap bm = new Bitmap(memStream); bm.Save(HttpContext.Response.OutputStream, ImageFormat.Jpeg); System.Drawing.Image image = System.Drawing.Image.FromStream(new System.IO.MemoryStream(imgBarcode)); return(new FileStreamResult(memStream, "image/png")); }
public ActionResult GenerateTicket(FaultModel fm, int pid) { //try //{ string username = Session["username"].ToString(); Account a = new AccountServ.AccountServiceClient().getAccountByUsername(username); int accountID = a.ID; int ticketNum = new FaultsServ.FaultReportLogServiceClient().GenerateTicketNum(); FaultReport checkTicketnum = new FaultsServ.FaultReportLogServiceClient().getTicketNum(ticketNum); if (checkTicketnum == null) { //FaultReport FaultReport fr = new FaultReport(); //fr.ID = new int(); fr.TicketNum = ticketNum; //add barcode BarCodeServ.BarCodeSoapClient bc = new BarCodeServ.BarCodeSoapClient(); BarCodeData barCodeData = new BarCodeData(); barCodeData.Height = 125; barCodeData.Width = 225; barCodeData.Angle = 0; barCodeData.Ratio = 5; barCodeData.Module = 0; barCodeData.Left = 25; barCodeData.Top = 0; barCodeData.CheckSum = false; barCodeData.FontName = "Arial"; barCodeData.BarColor = "Black"; barCodeData.BGColor = "White"; barCodeData.FontSize = 10.0f; barCodeData.barcodeOption = BarcodeOption.Both; barCodeData.barcodeType = BarcodeType.Code_2_5_interleaved; barCodeData.checkSumMethod = CheckSumMethod.None; barCodeData.showTextPosition = ShowTextPosition.BottomCenter; barCodeData.BarCodeImageFormat = ImageFormats.PNG; Byte[] imgBarcode = bc.GenerateBarCode(barCodeData, randumNum.ToString()); MemoryStream memStream = new MemoryStream(imgBarcode); Bitmap bm = new Bitmap(memStream); bm.Save(HttpContext.Response.OutputStream, ImageFormat.Jpeg); System.Drawing.Image image = System.Drawing.Image.FromStream(new System.IO.MemoryStream(imgBarcode)); //end of barcode method fr.Barcode = imgBarcode; fr.ProductID = pid; fr.AccountID = accountID; new FaultsServ.FaultReportLogServiceClient().Create(fr); //FaultLog FaultReport details = new FaultsServ.FaultReportLogServiceClient().getFaultReportIDByAccountIDTicket(accountID, ticketNum); FaultLog fl = new FaultLog(); fl.Status = "Reported"; fl.Description = fm.Description; fl.DateReport = System.DateTime.Now; fl.FaultReportID = details.ID; new FaultsServ.FaultReportLogServiceClient().CreateLog(fl); SendEmailToClient(accountID, image, pid, memStream, Convert.ToInt32(fr.TicketNum)); //SendEmailToClient(accountID, memStream,pid); return(RedirectToAction("Index", "Warranty")); } else { //show error ViewBag.Msg = "An error was encountered during the generation of the ticket"; } return(RedirectToAction("Index", "Warranty")); //} //catch (Exception ex) //{ // TempData["CatchError"] = "An error was encountered. Please try again later"; // return RedirectToAction("Index", "Warranty"); //} }