public string getQR(QRModel qr) { qr.timestamp = (DateTime.Now - DateTime.Parse("1970-01-01 00:00:00")).TotalMilliseconds; requestModel req = new requestModel() { pId = System.Configuration.ConfigurationManager.ConnectionStrings["pid"].ConnectionString, encryptContent = AESHelper.AESEncrypt(JsonConvert.SerializeObject(qr)) }; try { string res = HttpWebResponseUtility.CreatePostDataResponse(System.Configuration.ConfigurationManager.ConnectionStrings["url"].ConnectionString + System.Configuration.ConfigurationManager.ConnectionStrings["getqr"].ConnectionString, JsonConvert.SerializeObject(req)); responseModel response = JsonConvert.DeserializeObject <responseModel>(res); if (response.status.Equals("success")) { return(response.qr_image); } else { throw new Exception(response.message); } } catch (Exception ex) { return(null); } }
public void Test() { var tx_info = new RefundRequest_TX_INFO() { MONEY = "0.01", ORDER = "105000148164313190228144018226" }; var refundRequest = new RefundRequest() { REQUEST_SN = QRModel.CreateREQUEST_SN(), CUST_ID = QRModel.MERCHANTID, USER_ID = "105000148164313-001", PASSWORD = "******", LANGUAGE = "CN", TX_CODE = "5W1004", SIGNCERT = "1111", SIGN_INFO = "1111", TX_INFO = tx_info }; string request = XmlHelper.SerializeToXmlStr(refundRequest, false); string returstr = HttpClientUtil.HttpPost("http://localhost:2582/pay/ccb/notice", request, "text/xml"); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("ORDERID", "123123"); dic.Add("POSID", "456456"); string data = string.Empty; foreach (string key in dic.Keys) { data += key + "=" + dic[key] + "&"; } string payStr = HttpClientUtil.HttpPost("http://localhost:2582/pay/ccb/notice", data.Trim('&')); //提交网银网关地址 }
public IHttpActionResult Post(byte[] raw) { try { QRModel data = QRModel.FromArray(Serializer.FromByteArray <object[]>(raw)); if (!IsAuthorizedDevice(data)) { return(Unauthorized()); } List <Guest> all = db.Guest.ToList(); Guest guest = all.FirstOrDefault(g => g.Keynum.SequenceEqual(data.GetKeynum())); if (guest != null) { guest.IsConfirmed = true; db.SaveChanges(); } } catch (Exception) { return(NotFound()); } return(Ok()); }
private void OnCreateQR(object p) { if (this.SelectedElection == null || BallotId == Guid.Empty || string.IsNullOrEmpty(ElectionModels.Misc.Utils.StripSpaces(SSN))) { return; } string encryptedstring = ElectionModels.Misc.Utils.Encrypt(this.BallotId.ToString("n"), ElectionModels.Misc.Utils.StripSpaces(this.SSN)); //string decryptedBallotId = ElectionModels.Misc.Utils.Decrypt(encryptedstring, this.SSN); QRModel qrModel = new QRModel() { ElectionId = this.SelectedElection.Id, Registration = Registration, BirthYear = BirthYear, EncryptedBallotId = encryptedstring }; //string code = string.Format("{0}|{1}|{2}|{3}", this.SelectedElection.Id, Registration, BirthYear, encryptedstring); string code = JsonConvert.SerializeObject(qrModel); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); System.Drawing.Bitmap qrCodeImage = qrCode.GetGraphic(40); QRImage = qrCodeImage.ToBitmapImage(); }
/// <summary> /// 退款申请 /// </summary> public string Refund(string OrderId) { var tx_info = new RefundRequest_TX_INFO() { MONEY = "0.01", ORDER = OrderId }; var refundRequest = new RefundRequest() { REQUEST_SN = QRModel.CreateREQUEST_SN(), CUST_ID = QRModel.MERCHANTID, USER_ID = "001", PASSWORD = "******", LANGUAGE = "CN", TX_CODE = "5W1004", TX_INFO = tx_info }; string request = "<?xml version=\"1.0\" encoding=\"GB2312\" standalone=\"yes\" ?>" + XmlHelper.SerializeToXmlStr(refundRequest, true); int port = 9010; string host = "192.168.30.168";//服务器端ip地址 IPAddress ip = IPAddress.Parse(host); IPEndPoint ipe = new IPEndPoint(ip, port); Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); clientSocket.Connect(ipe); //send message<?xml version='1.0' encoding='GB2312' standalone='yes' ?> //string sendStr = "<TX><REQUEST_SN>19022818202467701</REQUEST_SN><CUST_ID>105000148164313</CUST_ID><USER_ID>105000148164313-001</USER_ID><PASSWORD>jlkj2019</PASSWORD><TX_CODE>5W1004</TX_CODE><LANGUAGE>CN</LANGUAGE><TX_INFO><MONEY>0.01</MONEY><ORDER>105000148164313190228121021514</ORDER></TX_INFO><SIGN_INFO></SIGN_INFO><SIGNCERT></SIGNCERT></TX>"; byte[] sendBytes = Encoding.Default.GetBytes(request); clientSocket.Send(sendBytes); //receive message string recStr = ""; byte[] recBytes = new byte[4096]; int bytes = clientSocket.Receive(recBytes, recBytes.Length, 0); recStr += Encoding.Default.GetString(recBytes, 0, bytes); Console.WriteLine(recStr); clientSocket.Close(); // string returstr = HttpClientUtil.HttpPost("https://192.168.30.168:9010", request, "text/xml"); //退款返回数据 //var RETURN_CODE = XmlHelper.GetNodeValue(returstr, XmlHelper.XmlType.String, "RETURN_CODE"); // if (RETURN_CODE.RETURN_CODE.Equals("000000")) //{ // //交易成功todo //} //var refundResponse = XmlHelper.XmlDeserialize<RefundResponse>(returstr); //if (refundResponse.RETURN_CODE.Equals("000000")) //{ // //交易成功todo //} return(""); }
// GET: ItemsHires/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ItemsHire itemsHire = db.ItemsHires.Find(id); if (itemsHire == null) { return(HttpNotFound()); } QRModel qr = new QRModel(); QRCodeGenerator ObjQr = new QRCodeGenerator(); //TempData["fullurl"] = HttpContext.Request.Url.AbsoluteUri; //qr.Message = TempData["fullurl"].ToString(); qr.Message = Request.Url.ToString(); QRCodeData qrCodeData = ObjQr.CreateQrCode(qr.Message, QRCodeGenerator.ECCLevel.Q); Bitmap bitMap = new QRCode(qrCodeData).GetGraphic(20); using (MemoryStream ms = new MemoryStream()) { bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] byteImage = ms.ToArray(); ViewBag.Url = "data:image/png;base64," + Convert.ToBase64String(byteImage); ms.Position = 0; } return(View(itemsHire)); }
void GenerateQR() { var writer = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new EncodingOptions { Height = 600, Width = 600 } }; //for prototyping purposes, we just declared the subscription id, //subscription id should come from database. string subscription_id = "12345"; QRModel qr = new QRModel(); qr.subscription_id = subscription_id; qr.datetime = DateTime.Now.ToString(); var jsonObj = JsonConvert.SerializeObject(qr); var bitmap = writer.Write(jsonObj); qrImage.SetImageBitmap(bitmap); }
private bool IsAuthorizedDevice(QRModel data) { if (data.UserID == null || data.UserID.Length == 0) { return(false); } return(db.Registration.Any(r => r.deviceID == data.UserID)); }
public ActionResult Index(QRModel model) { QRService objService = new QRService(); QRModel objModel = new QRModel(); List <ExamTranModel> lstShedule = new List <ExamTranModel>(); lstShedule = objService.getExamShedule(Convert.ToInt32(model.EID)); if (lstShedule.Count() > 0) { int stdID = Convert.ToInt32(lstShedule[0].StdID); var lstStud = Dbcontext.StudentMasters.Where(m => m.StdID == stdID).ToList(); foreach (var i in lstShedule) { foreach (var st in lstStud) { var std = Dbcontext.StandardMasters.Where(m => m.StdID == st.StdID).SingleOrDefault(); var sub = Dbcontext.SubjectMasters.Where(m => m.SubID == i.SubID).SingleOrDefault(); string code = "Registration# : " + st.Prefix + "" + st.StudID + ",Roll No. : " + st.RollNo + ",Name : " + st.FirstName + ' ' + st.MiddleName + ' ' + st.LastName + ",Subject : " + sub.Subject + ",Standard : " + std.Standard; QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q); System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image(); imgBarCode.Height = 150; imgBarCode.Width = 150; using (Bitmap bitMap = qrCode.GetGraphic(20)) { using (MemoryStream ms = new MemoryStream()) { bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] byteImage = ms.ToArray(); imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage); model.QRCodeImage = byteImage; } //plBarCode.Controls.Add(imgBarCode); model.QRCode = Convert.ToString(imgBarCode.ImageUrl); model.StudID = st.StudID; model.SubID = i.SubID; model.ETID = i.ETID; model.SchoolID = i.SchoolID; model.EID = i.EID; objService.Insert(model); } } } return(RedirectToAction("Print", new { @SchoolID = model.SchoolID, @StdID = model.StdID })); } else { TempData["AMsg"] = "QR Code not Generated! First you should to arrange shedule."; return(RedirectToAction("Index")); } }
public ActionResult Logout() { QRModel k = Session[Statics.Visitorkey] as QRModel; IEnumerable <Guest> r = db.Guest.ToList().Where(g => g.Keynum.SequenceEqual(k.GetKeynum())); db.Guest.RemoveRange(r); db.SaveChanges(); Session[Statics.Visitorkey] = null; return(RedirectToActionPermanent("Index")); }
private QRModel SortDataMain(string perfix, List <QRModel> qrListString) { var SelectedData = new QRModel { DataType = qrListString.Find(it => it.DataType == $"{perfix}")?.DataType ?? "", DataLength = qrListString.Find(it => it.DataType == $"{perfix}")?.DataLength ?? "", Data = qrListString.Find(it => it.DataType == $"{perfix}")?.Data ?? "", }; return(SelectedData); }
public ActionResult Print(int SchoolID, int StdID) { QRService objService = new QRService(); List <QRModel> lstQR = new List <QRModel>(); QRModel objModel = new QRModel(); lstQR = objService.getQRBySChoolNStd(SchoolID, StdID); objModel.ListQR = new List <QRModel>(); objModel.ListQR.AddRange(lstQR); return(View(objModel)); }
private QRModel SortDataSubField(string Conditionperfix1, string Conditionperfix2, List <QRModel> qrListString) { var SelectedData = new QRModel { DataType = qrListString.Find(it => it.DataType == $"{Conditionperfix1}" || it.DataType == $"{Conditionperfix2}")?.DataType ?? "", DataLength = qrListString.Find(it => it.DataType == $"{Conditionperfix1}" || it.DataType == $"{Conditionperfix2}")?.DataLength ?? "", Data = qrListString.Find(it => it.DataType == $"{Conditionperfix1}" || it.DataType == $"{Conditionperfix2}")?.Data ?? "", }; return(SelectedData); }
public int Insert(QRModel model) { try { Mapper.CreateMap <QRModel, QRCodeMaster>(); QRCodeMaster objUser = Mapper.Map <QRCodeMaster>(model); Dbcontext.QRCodeMasters.Add(objUser); return(Dbcontext.SaveChanges()); } catch (Exception ex) { throw ex; } }
public ActionResult Index() { // Check if session has qr data stored if (!(Session[Statics.Visitorkey] is QRModel qrInfo) || (DateTime.UtcNow - qrInfo.Created).TotalSeconds > 30) { // If qr data is missing or timed out, create a new guest Guest g = db.Guest.Add(new Guest()); db.SaveChanges(); qrInfo = new QRModel(g.Keynum, g.Visited, ""); Session[Statics.Visitorkey] = qrInfo; } return(View()); }
public ResponseModel CreateQR() { var context = _httpContextAccessor.HttpContext; var createqr = new QRModel(); var res = new ResponseModel() { Status = "200", Message = "", }; try { createqr.Command = "CONNECTTOTRX"; createqr.ServerAddress = "h2673771.stratoserver.net"; createqr.Port = 80; createqr.URLPart = "webservicestx"; var x = _userService.GetUser(context.User.Identity.Name); if (x != null) { createqr.User = x.UserName; createqr.EncryptionKey = x.Token; } var textboxQR = (createqr.Command + ":" + createqr.ServerAddress + ":" + createqr.Port + "/" + createqr.URLPart + "|" + createqr.EncryptionKey + "|" + createqr.User); QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(textboxQR.ToString(), QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(20); var bitmapBytes = BitmapToBytes(qrCodeImage); //Convert bitmap into a byte array string base64String = Convert.ToBase64String(bitmapBytes); res.Data = base64String; //tra data kieu responsemodel return(res); } catch (Exception ex) { res.Status = "500"; res.Message = ex.Message; } return(res); }
public IHttpActionResult GenerateQrCode() { var qrPayload = new QRModel { ServerConfig = "104.215.180.104", DomainCode = "dgn5", UserId = "utl009" }; var jsonString = JsonConvert.SerializeObject(qrPayload); using (var qrGenerator = new QRCodeGenerator()) { using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(jsonString, QRCodeGenerator.ECCLevel.Q, forceUtf8: true)) { using (QRCode qrCode = new QRCode(qrCodeData)) { using (Bitmap bitMap = qrCode.GetGraphic(20, Color.Black, Color.White, new Bitmap(HttpContext.Current.Server.MapPath(@"~/App_Data/HR-One-logo.png")), 16)) { var folderPath = HttpContext.Current.Server.MapPath(@"~/QRImage/"); var fileName = "myQr1" + DateTime.Now.ToString("yyyy-mm-dd") + ".png"; var imagePath = folderPath + fileName; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } // bitMap.Save(imagePath); using (var ms = new MemoryStream()) { bitMap.Save(ms, ImageFormat.Png); File.WriteAllBytes(imagePath, ms.ToArray()); } } } } } return(Ok()); }
private static void GetSubInfo(string QRSub, string Basetype) { var Type = QRSub.Substring(0, 2); var dataLength = QRSub.Substring(2, 2); var dataString = QRSub.Substring(4, int.Parse(dataLength)); var result = new QRModel { DataType = $"{Basetype}_{Type}", DataLength = dataLength, Data = dataString }; Result.Add(result); var count = Type.Length + dataLength.Length + dataString.Length; var newQRString = QRSub.Remove(0, count); if (newQRString.Length > 0) { GetSubInfo(newQRString, Basetype); } }
public ActionResult Index() { QRService objService = new QRService(); QRModel objModel = new QRModel(); List <QRModel> lstQR = new List <QRModel>(); CommonService objCService = new CommonService(); int did = 0; int acid = 0; if (Session["DID"] != null) { did = Convert.ToInt32(Session["DID"].ToString()); acid = Convert.ToInt32(Session["ACID"].ToString()); } lstQR = objService.getQR(); objModel.ListQR = new List <QRModel>(); objModel.ListQR.AddRange(lstQR); List <SchoolModel> lstSchool = new List <SchoolModel>(); lstSchool = objCService.getActiveSchool(did); objModel.ListSchool = new List <SchoolModel>(); objModel.ListSchool.AddRange(lstSchool); List <StandardModel> lstStd = new List <StandardModel>(); lstStd = objCService.getActiveStd(); objModel.ListStd = new List <StandardModel>(); objModel.ListStd.AddRange(lstStd); List <ExamModel> lstExam = new List <ExamModel>(); lstExam = objCService.getActiveExam(); objModel.ListExam = new List <ExamModel>(); objModel.ListExam.AddRange(lstExam); return(View(objModel)); }
public List <QRModel> GetInfo(string QRBase) { var Type = QRBase.Substring(0, 2); var dataLength = QRBase.Substring(2, 2); var dataString = QRBase.Substring(4, int.Parse(dataLength)); var result = new QRModel { DataType = Type, DataLength = dataLength, Data = dataString }; if (Sublist.Contains(Type)) { var subHeader = new QRModel { DataType = Type, DataLength = dataLength }; Result.Add(subHeader); GetSubInfo(dataString, Type); } else { Result.Add(result); } var count = Type.Length + dataLength.Length + dataString.Length; var newQRString = QRBase.Remove(0, count); if (newQRString.Length > 0) { GetInfo(newQRString); } return(Result); }
public QRScanPage() { InitializeComponent(); ViewModel = new QRModel(viewfinderBrush); DataContext = ViewModel; }
/// <summary> /// 聚合扫码只能上送2或3 /// </summary> /// <param name="RETURNTYPE"></param> public string PAY(int RETURNTYPE = 3) { string ORDERID = QRModel.CreateOrderId(); string PAYMENT = "0.01"; string CURCODE = "01"; string TXCODE = "530550"; string REMARK1 = ""; string REMARK2 = ""; string TIMEOUT = ""; //MAC字段参与摘要运算的字符串及其顺序 System.Text.StringBuilder tmp = new StringBuilder(); tmp.Append("MERCHANTID="); tmp.Append(QRModel.MERCHANTID); tmp.Append("&POSID="); tmp.Append(QRModel.POSID); tmp.Append("&BRANCHID="); tmp.Append(QRModel.BRANCHID); tmp.Append("&ORDERID="); tmp.Append(ORDERID); tmp.Append("&PAYMENT="); tmp.Append(PAYMENT); tmp.Append("&CURCODE="); tmp.Append(CURCODE); tmp.Append("&TXCODE="); tmp.Append(TXCODE); tmp.Append("&REMARK1="); tmp.Append(REMARK1); tmp.Append("&REMARK2="); tmp.Append(REMARK2); tmp.Append("&RETURNTYPE="); tmp.Append(RETURNTYPE); tmp.Append("&TIMEOUT="); tmp.Append(TIMEOUT); tmp.Append("&PUB="); tmp.Append(QRModel.PUB32TR2); //提交的参数 Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("CCB_IBSVersion", "V6"); dic.Add("MERCHANTID", QRModel.MERCHANTID); dic.Add("POSID", QRModel.POSID); dic.Add("BRANCHID", QRModel.BRANCHID); dic.Add("ORDERID", ORDERID); dic.Add("PAYMENT", PAYMENT); dic.Add("CURCODE", CURCODE); dic.Add("TXCODE", TXCODE); dic.Add("REMARK1", REMARK1); dic.Add("REMARK2", REMARK2); dic.Add("RETURNTYPE", RETURNTYPE.ToString()); dic.Add("TIMEOUT", TIMEOUT); dic.Add("MAC", MD5.GetMD5Str(tmp.ToString())); string data = string.Empty; foreach (string key in dic.Keys) { data += key + "=" + dic[key] + "&"; } string payStr = HttpClientUtil.HttpPost(QRModel.BankURL, data.Trim('&')); //提交网银网关地址 //2 直接返回带二维码的网页 if (RETURNTYPE == 2) { return(payStr); } var payData = JsonConvert.DeserializeObject <PayResData>(payStr); var qrurlStr = HttpClientUtil.HttpGet(payData.PAYURL); var qrurlData = JsonConvert.DeserializeObject <PayResData>(qrurlStr); qrurlData.QRURL = HttpUtility.UrlDecode(qrurlData.QRURL);//浏览器直接打开地址 return(qrurlData.QRURL); }
public ActionResult ActionQrCode(QRModel qr) { QRCodeGenerator ObjQr = new QRCodeGenerator(); qr.Message = Request.Url.ToString(); QRCodeData qrCodeData = ObjQr.CreateQrCode(qr.Message, QRCodeGenerator.ECCLevel.Q); Bitmap bitMap = new QRCode(qrCodeData).GetGraphic(20); using (MemoryStream ms = new MemoryStream()) { bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] byteImage = ms.ToArray(); ViewBag.Url = "data:image/png;base64," + Convert.ToBase64String(byteImage); ms.Position = 0; try { // start of working email SmtpClient client = new SmtpClient("smtp.sendgrid.net"); client.Port = 25; client.Host = "smtp.sendgrid.net"; client.Timeout = 10000; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; client.UseDefaultCredentials = false; var key = Environment.GetEnvironmentVariable("apikey"); client.Credentials = new NetworkCredential("apikey", key /*, user, password*/); System.Net.Mail.Attachment attachment; attachment = new System.Net.Mail.Attachment(ms, "order.png"); MailMessage msz = new MailMessage("*****@*****.**", "*****@*****.**") { From = new MailAddress(ConfigurationManager.AppSettings["Email"].ToString()), Subject = "Order QR From GOLDPRIDE For " + "Joshua" /*Name.ToUpper()*/, IsBodyHtml = true, Body = " Good Day : " + "Joshua" /*Name.ToUpper()*/ + " " + "MAdurai" /*SName.ToUpper()*/ + ", Please find attached QR Code for ease of collection : " }; msz.Attachments.Add(attachment); client.Send(msz); ModelState.Clear(); // end } catch { } } return(View()); //return RedirectToAction("ActionQrCode", "QrGenerate"); }
public ActionResult BarCode(int id, QRModel model) { ExamService objService = new ExamService(); ExamModel objModel = new ExamModel(); int did = 0; int acid = 0; if (Session["DID"] != null) { did = Convert.ToInt32(Session["DID"].ToString()); acid = Convert.ToInt32(Session["ACID"].ToString()); } var lstExam = Dbcontext.ExamMasters.Where(m => m.EID == id).SingleOrDefault(); var lstQRCode = Dbcontext.QRCodeMasters.Where(m => m.EID == id).ToList(); if (lstQRCode.Count > 0) { return(RedirectToAction("PrintQRCode", new { @SchoolID = lstExam.SchoolID, @StdID = lstExam.StdID })); } else { if (lstExam != null) { var lstStud = Dbcontext.StudentMasters.Where(m => m.StdID == lstExam.StdID && m.DID == did && m.ACID == acid && m.SchoolID == lstExam.SchoolID).ToList(); foreach (var st in lstStud) { var std = Dbcontext.StandardMasters.Where(m => m.StdID == st.StdID).SingleOrDefault(); List <SubjectModel> lstSub = new List <SubjectModel>(); lstSub = objService.getSubjectByStud(st.StudID); //var sub = Dbcontext.SubjectMasters.Where(m => m.SubID == i.SubID).SingleOrDefault(); foreach (var sub in lstSub) { string barCode = Convert.ToString(st.StudID + "-" + lstExam.EID + "-" + sub.SubID); System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image(); using (Bitmap bitMap = new Bitmap(barCode.Length * 40, 80)) { using (Graphics graphics = Graphics.FromImage(bitMap)) { Font oFont = new Font("IDAutomationHC39M", 16); PointF point = new PointF(2f, 2f); SolidBrush blackBrush = new SolidBrush(Color.Black); SolidBrush whiteBrush = new SolidBrush(Color.White); graphics.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height); graphics.DrawString("*" + barCode + "*", oFont, blackBrush, point); } using (MemoryStream ms = new MemoryStream()) { bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] byteImage = ms.ToArray(); Convert.ToBase64String(byteImage); imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage); model.QRCodeImage = byteImage; } //plBarCode.Controls.Add(imgBarCode); model.QRCode = Convert.ToString(imgBarCode.ImageUrl); model.StudID = st.StudID; model.SubID = sub.SubID; model.SchoolID = st.SchoolID; model.EID = id; model.StdID = st.StdID; objService.Insert(model); } //string code = Convert.ToString(st.StudID + "-" + lstExam.EID + "-" + sub.SubID); ////string code = "Registration# : " + st.Prefix + "" + st.StudID + ",Roll No. : " + st.RollNo + ",Name : " + st.FirstName + ' ' + st.MiddleName + ' ' + st.LastName + ",Subject : " + sub.Subject + ",Standard : " + std.Standard; //QRCodeGenerator qrGenerator = new QRCodeGenerator(); //QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q); //System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image(); //imgBarCode.Height = 150; //imgBarCode.Width = 150; //using (Bitmap bitMap = qrCode.GetGraphic(20)) //{ // using (MemoryStream ms = new MemoryStream()) // { // bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); // byte[] byteImage = ms.ToArray(); // imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage); // model.QRCodeImage = byteImage; // } // //plBarCode.Controls.Add(imgBarCode); // model.QRCode = Convert.ToString(imgBarCode.ImageUrl); // model.StudID = st.StudID; // model.SubID = sub.SubID; // model.SchoolID = st.SchoolID; // model.EID = id; // model.StdID = st.StdID; // objService.Insert(model); //} } } return(RedirectToAction("PrintQRCode", new { @SchoolID = lstExam.SchoolID, @StdID = lstExam.StdID })); } else { TempData["AMsg"] = "Bar Code not Generated!"; return(RedirectToAction("Index")); } } //return RedirectToAction("Print", new { @SchoolID = model.SchoolID, @StdID = model.StdID }); }
public ActionResult QRCode(int id, QRModel model) { ExamService objService = new ExamService(); ExamModel objModel = new ExamModel(); int did = 0; int acid = 0; if (Session["DID"] != null) { did = Convert.ToInt32(Session["DID"].ToString()); acid = Convert.ToInt32(Session["ACID"].ToString()); } var lstExam = Dbcontext.ExamMasters.Where(m => m.EID == id).SingleOrDefault(); var lstQRCode = Dbcontext.QRCodeMasters.Where(m => m.EID == id).ToList(); if (lstQRCode.Count > 0) { return(RedirectToAction("PrintQRCode", new { @SchoolID = lstExam.SchoolID, @StdID = lstExam.StdID })); } else { if (lstExam != null) { var lstStud = Dbcontext.StudentMasters.Where(m => m.StdID == lstExam.StdID && m.DID == did && m.ACID == acid && m.SchoolID == lstExam.SchoolID).ToList(); foreach (var st in lstStud) { var std = Dbcontext.StandardMasters.Where(m => m.StdID == st.StdID).SingleOrDefault(); List <SubjectModel> lstSub = new List <SubjectModel>(); lstSub = objService.getSubjectByStud(st.StudID); //var sub = Dbcontext.SubjectMasters.Where(m => m.SubID == i.SubID).SingleOrDefault(); foreach (var sub in lstSub) { string code = Convert.ToString(st.StudID + "-" + lstExam.EID + "-" + sub.SubID); //string code = "Registration# : " + st.Prefix + "" + st.StudID + ",Roll No. : " + st.RollNo + ",Name : " + st.FirstName + ' ' + st.MiddleName + ' ' + st.LastName + ",Subject : " + sub.Subject + ",Standard : " + std.Standard; QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q); System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image(); imgBarCode.Height = 150; imgBarCode.Width = 150; using (Bitmap bitMap = qrCode.GetGraphic(20)) { using (MemoryStream ms = new MemoryStream()) { bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] byteImage = ms.ToArray(); imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage); model.QRCodeImage = byteImage; } //plBarCode.Controls.Add(imgBarCode); model.QRCode = Convert.ToString(imgBarCode.ImageUrl); model.StudID = st.StudID; model.SubID = sub.SubID; model.SchoolID = st.SchoolID; model.EID = id; model.StdID = st.StdID; objService.Insert(model); } } } return(RedirectToAction("PrintQRCode", new { @SchoolID = lstExam.SchoolID, @StdID = lstExam.StdID })); } else { TempData["AMsg"] = "QR Code not Generated!"; return(RedirectToAction("Index")); } } //return RedirectToAction("Print", new { @SchoolID = model.SchoolID, @StdID = model.StdID }); }
public async Task <ActionResult> ProcessOrderAsync(FormCollection frc) { ApplicationDbContext db = new ApplicationDbContext(); var Delivery = (from x in db.Maps where x.Email == User.Identity.Name orderby x.Id descending select x.Distance).First().ToString(); var order = (from i in db.Orders where i.Email == User.Identity.Name orderby i.OrderID descending select i).First(); // string cos = Delivery.Distance; var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); ApplicationUser currentUser = UserManager.FindById(User.Identity.GetUserId()); string ID = currentUser.Id; string Email = currentUser.Email; string Name = currentUser.Name; string SName = currentUser.Surname; byte[] Sign = currentUser.MySignature; //var Delivery = (from i in db.Maps // select i).Last(); List <Cart> lstCart = (List <Cart>)Session[strCart]; //Models.Order ord = new Models.Order(); //string a = ord.CollDate.ToString(); //1.savw the order into order table //var order = new Models.Order() //{ // MySignature = Sign, // CustomerName = frc["cusName"], // Surname = frc["cusSurname"], // CustomerPhone = frc["cusPhone"], // Email = frc["cusEmail"], // //CollDate = Convert.ToDateTime(frc["colDate"]).ToShortDateString(), // CollDate = Convert.ToDateTime(frc["collDate"]).ToShortDateString(), // OrderDate = DateTime.Now, // PaymentType = "PayPal", // //ExpectedReturnDate = Convert.ToDateTime(frc["collDate"]).AddDays(2).ToString("dd/MM/yyyy") // ExpectedReturnDate = Convert.ToDateTime(frc["collDate"]).Date.AddDays(2) // //Status = "Processing" // }; // db.Orders.Add(order); //string ReturnDate = ""; //ReturnDate = Convert.ToDateTime(order.CollDate).AddDays(3).ToString(/*"dd/MM/yyyy"*/); OrderDetail orderDetail = new OrderDetail(); //2. save the order detail into the Order detail table List <string> productName = new List <string>(); List <int> productId = new List <int>(); List <int> productQuantity = new List <int>(); List <decimal> productPrice = new List <decimal>(); List <string> distance = new List <string>(); //List<decimal> deposit = new List<decimal>(); List <Cart> temp = (List <Cart>)Session["Cart"]; //var deposit = String.Format("{0:C}", temp.Sum(x => x.Quantity * x.ItemsHire.Price / 2)); var total = String.Format("{0:C}", (temp.Sum(x => x.Quantity * x.ItemsHire.Price) + temp.Sum(x => x.Quantity * x.ItemsHire.Price / 2)) /* + Delivery.ToString()*//* + Delivery.Distance.ToString()*/); foreach (Cart cart in lstCart) { orderDetail.OrderID = order.OrderID; orderDetail.ProductName = cart.ItemsHire.ProductName; orderDetail.ProductID = cart.ItemsHire.ProductID; orderDetail.Quantity = cart.Quantity; orderDetail.Price = cart.ItemsHire.Price; //orderDetail.Distance = Delivery.ToString(); orderDetail.Deposit = temp.Sum(x => x.Quantity * x.ItemsHire.Price / 2); orderDetail.Total = temp.Sum(x => x.Quantity * x.ItemsHire.Price /* + Convert.ToDecimal(Delivery)*/) + orderDetail.Deposit /* + Convert.ToDecimal(Delivery.Distance.ToString())*/; productName.Add(cart.ItemsHire.ProductName); productQuantity.Add(cart.Quantity); productPrice.Add(cart.ItemsHire.Price); //deposit.Add(orderDetail.Deposit); db.OrderDetails.Add(orderDetail); ItemsHire prod = (from p in db.ItemsHires where p.ProductID == orderDetail.ProductID select p).Single(); prod.Quantity -= orderDetail.Quantity; db.SaveChanges(); } try { ViewBag.Orders = db.Orders.ToList().FindAll(x => x.OrderID == order.OrderID); MemoryStream memoryStream = new MemoryStream(); StringBuilder status = new StringBuilder(""); var doc = new Document(PageSize.A4, 10, 10, 10, 10); PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream); var titleFont = FontFactory.GetFont("Arial", 12, Font.BOLD); var titleFontBlue = FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLUE); var boldTableFont = FontFactory.GetFont("Arial", 8, Font.BOLD); var bodyFont = FontFactory.GetFont("Arial", 8, Font.NORMAL); var EmailFont = FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLUE); BaseColor TabelHeaderBackGroundColor = WebColors.GetRGBColor("#EEEEEE"); // doc.SetWidths(headers); Rectangle pageSize = writer.PageSize; doc.Open(); PdfPTable header = new PdfPTable(3); header.HorizontalAlignment = 0; header.WidthPercentage = 100; header.SetWidths(new float[] { 100f, 320f, 100f }); header.DefaultCell.Border = Rectangle.NO_BORDER; iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(HttpContext.Server.MapPath("~/Content/Images/GP_BLUE.jpg")); //var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Content/Images/GP_BLUE.jpg")); logo.ScaleToFit(100, 100); { PdfPCell pdfCelllogo = new PdfPCell(logo); pdfCelllogo.Border = Rectangle.NO_BORDER; pdfCelllogo.BorderColorBottom = new BaseColor(System.Drawing.Color.Black); pdfCelllogo.BorderWidthBottom = 1f; header.AddCell(pdfCelllogo); } { PdfPCell middlecell = new PdfPCell(); middlecell.Border = Rectangle.NO_BORDER; middlecell.BorderColorBottom = new BaseColor(System.Drawing.Color.Black); middlecell.BorderWidthBottom = 1f; header.AddCell(middlecell); } { PdfPTable nested = new PdfPTable(1); nested.DefaultCell.Border = Rectangle.NO_BORDER; PdfPCell nextPostCell1 = new PdfPCell(new Phrase("Gold Pride", titleFont)); nextPostCell1.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell1); PdfPCell nextPostCell2 = new PdfPCell(new Phrase("90 street, Durban, SA,", bodyFont)); nextPostCell2.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell2); PdfPCell nextPostCell3 = new PdfPCell(new Phrase("(082) 0798501", bodyFont)); nextPostCell3.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell3); PdfPCell nextPostCell4 = new PdfPCell(new Phrase("*****@*****.**", EmailFont)); nextPostCell4.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell4); nested.AddCell(""); PdfPCell nesthousing = new PdfPCell(nested); nesthousing.Border = Rectangle.NO_BORDER; nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black); nesthousing.BorderWidthBottom = 1f; nesthousing.Rowspan = 5; nesthousing.PaddingBottom = 10f; header.AddCell(nesthousing); } PdfPTable Invoicetable = new PdfPTable(3); Invoicetable.HorizontalAlignment = 0; Invoicetable.WidthPercentage = 100; Invoicetable.SetWidths(new float[] { 100f, 320f, 100f }); // then set the column's __relative__ widths Invoicetable.DefaultCell.Border = Rectangle.NO_BORDER; { PdfPTable nested = new PdfPTable(1); nested.DefaultCell.Border = Rectangle.NO_BORDER; PdfPCell nextPostCell1 = new PdfPCell(new Phrase("INVOICE TO:", bodyFont)); nextPostCell1.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell1); PdfPCell nextPostCell2 = new PdfPCell(new Phrase(" " + Name, bodyFont)); nextPostCell2.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell2); PdfPCell nextPostCell3 = new PdfPCell(new Phrase("" + order.CollDate, bodyFont)); nextPostCell3.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell3); PdfPCell nextPostCell4 = new PdfPCell(new Phrase(" " + Email, EmailFont)); nextPostCell4.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell4); nested.AddCell(""); PdfPCell nesthousing = new PdfPCell(nested); nesthousing.Border = Rectangle.NO_BORDER; //nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black); //nesthousing.BorderWidthBottom = 1f; nesthousing.Rowspan = 5; nesthousing.PaddingBottom = 10f; Invoicetable.AddCell(nesthousing); } { PdfPCell middlecell = new PdfPCell(); middlecell.Border = Rectangle.NO_BORDER; //middlecell.BorderColorBottom = new BaseColor(System.Drawing.Color.Black); //middlecell.BorderWidthBottom = 1f; Invoicetable.AddCell(middlecell); } { PdfPTable nested = new PdfPTable(1); nested.DefaultCell.Border = Rectangle.NO_BORDER; PdfPCell nextPostCell1 = new PdfPCell(new Phrase("Invoice Number: " + order.OrderID, titleFontBlue)); nextPostCell1.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell1); PdfPCell nextPostCell2 = new PdfPCell(new Phrase("Date of Invoice: " + order.OrderDate.ToString("dd/MM/yyyy HH:mm:ss"), bodyFont)); nextPostCell2.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell2); PdfPCell nextPostCell3 = new PdfPCell(new Phrase("Pick Up Date: " + order.CollDate.ToShortDateString(), bodyFont)); nextPostCell3.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell3); PdfPCell nextPostCell4 = new PdfPCell(new Phrase("Return Date: " + order.ExpectedReturnDate.ToShortDateString(), bodyFont)); nextPostCell4.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell4); //PdfPCell nextPostCell5 = new PdfPCell(new Phrase(" Hire Period: " , bodyFont)); //nextPostCell5.Border = Rectangle.NO_BORDER; //nested.AddCell(nextPostCell5); PdfPCell nextPostCell5 = new PdfPCell(new Phrase("Collection Status: " + order.PickUp, bodyFont)); nextPostCell5.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell5); PdfPCell nextPostCell6 = new PdfPCell(new Phrase("Collectors Name: " + order.CustomerName, bodyFont)); nextPostCell6.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell6); //PdfPCell nextPostCell6 = new PdfPCell(new Phrase("Collectors Address" + order.CustomerName, bodyFont)); //nextPostCell5.Border = Rectangle.NO_BORDER; //nested.AddCell(nextPostCell6); PdfPCell nextPostCell7 = new PdfPCell(new Phrase("Collectors Number: " + "\n" + order.CustomerPhone, bodyFont)); nextPostCell7.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell7); PdfPCell nextPostCell8 = new PdfPCell(new Phrase("Payment Mehtod: " + "PayFast", bodyFont)); nextPostCell8.Border = Rectangle.NO_BORDER; nested.AddCell(nextPostCell8); nested.AddCell(""); PdfPCell nesthousing = new PdfPCell(nested); nesthousing.Border = Rectangle.NO_BORDER; //nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black); //nesthousing.BorderWidthBottom = 1f; nesthousing.Rowspan = 5; nesthousing.PaddingBottom = 10f; Invoicetable.AddCell(nesthousing); } doc.Add(header); Invoicetable.PaddingTop = 10f; doc.Add(Invoicetable); #region Items Table //Create body table PdfPTable itemTable = new PdfPTable(5); itemTable.HorizontalAlignment = 0; itemTable.WidthPercentage = 100; itemTable.SetWidths(new float[] { 5, 40, 10, 20, 25 }); // then set the column's __relative__ widths itemTable.SpacingAfter = 40; itemTable.DefaultCell.Border = Rectangle.BOX; PdfPCell cell1 = new PdfPCell(new Phrase("PROD ID", boldTableFont)); cell1.BackgroundColor = TabelHeaderBackGroundColor; cell1.HorizontalAlignment = Element.ALIGN_CENTER; itemTable.AddCell(cell1); PdfPCell cell2 = new PdfPCell(new Phrase("PRODUCT NAME", boldTableFont)); cell2.BackgroundColor = TabelHeaderBackGroundColor; cell2.HorizontalAlignment = 1; itemTable.AddCell(cell2); PdfPCell cell3 = new PdfPCell(new Phrase("QUANTITY", boldTableFont)); cell3.BackgroundColor = TabelHeaderBackGroundColor; cell3.HorizontalAlignment = Element.ALIGN_CENTER; itemTable.AddCell(cell3); PdfPCell cell4 = new PdfPCell(new Phrase("UNIT AMOUNT", boldTableFont)); cell4.BackgroundColor = TabelHeaderBackGroundColor; cell4.HorizontalAlignment = Element.ALIGN_CENTER; itemTable.AddCell(cell4); //PdfPCell cell5 = new PdfPCell(new Phrase("Delivery Cost", boldTableFont)); //cell5.BackgroundColor = TabelHeaderBackGroundColor; //cell5.HorizontalAlignment = Element.ALIGN_CENTER; //itemTable.AddCell(cell5); PdfPCell cell5 = new PdfPCell(new Phrase("TOTAL", boldTableFont)); cell5.BackgroundColor = TabelHeaderBackGroundColor; cell5.HorizontalAlignment = Element.ALIGN_CENTER; itemTable.AddCell(cell5); foreach (Cart cart in lstCart) { orderDetail.OrderID = order.OrderID; orderDetail.ProductName = cart.ItemsHire.ProductName; orderDetail.ProductID = cart.ItemsHire.ProductID; orderDetail.Quantity = cart.Quantity; orderDetail.Price = cart.ItemsHire.Price; orderDetail.SubTotal = cart.Quantity * cart.ItemsHire.Price; orderDetail.Deposit = temp.Sum(x => x.Quantity * x.ItemsHire.Price / 2); orderDetail.Total = orderDetail.SubTotal + orderDetail.Deposit + Convert.ToDecimal(Delivery) /*temp.Sum(x => x.Quantity * cart.ItemsHire.Price)*//* + Convert.ToDecimal(Delivery) + orderDetail.Deposit*/; PdfPCell numberCell = new PdfPCell(new Phrase("" + orderDetail.ProductID, bodyFont)); numberCell.HorizontalAlignment = 1; numberCell.PaddingLeft = 10f; numberCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; itemTable.AddCell(numberCell); var _phrase = new Phrase(); _phrase.Add(new Chunk(" " + orderDetail.ProductName, bodyFont)); PdfPCell descCell = new PdfPCell(_phrase); descCell.HorizontalAlignment = 0; descCell.PaddingLeft = 10f; descCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; itemTable.AddCell(descCell); PdfPCell qtyCell = new PdfPCell(new Phrase(" " + orderDetail.Quantity, bodyFont)); qtyCell.HorizontalAlignment = 1; qtyCell.PaddingLeft = 10f; qtyCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; itemTable.AddCell(qtyCell); PdfPCell amountCell = new PdfPCell(new Phrase(" " + orderDetail.Price, bodyFont)); amountCell.HorizontalAlignment = 1; amountCell.PaddingLeft = 10f; amountCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; itemTable.AddCell(amountCell); //PdfPCell deliveryamtCell = new PdfPCell(new Phrase("240 " /*+ Delivery*/, bodyFont)); //deliveryamtCell.HorizontalAlignment = 1; //deliveryamtCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; //itemTable.AddCell(deliveryamtCell); PdfPCell totalamtCell = new PdfPCell(new Phrase(" " + orderDetail.SubTotal, bodyFont)); totalamtCell.HorizontalAlignment = 1; totalamtCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; itemTable.AddCell(totalamtCell); } //Delivery start PdfPCell deliveryCell = new PdfPCell(new Phrase("")); deliveryCell.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER; itemTable.AddCell(deliveryCell); PdfPCell deliveryCell2 = new PdfPCell(new Phrase("")); deliveryCell2.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER; itemTable.AddCell(deliveryCell2); PdfPCell deliveryCell3 = new PdfPCell(new Phrase("")); deliveryCell3.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER; itemTable.AddCell(deliveryCell3); PdfPCell DeliveryCell = new PdfPCell(new Phrase("Delivery", boldTableFont)); DeliveryCell.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER; DeliveryCell.HorizontalAlignment = 1; itemTable.AddCell(DeliveryCell); PdfPCell DelCell = new PdfPCell(new Phrase("$" + Delivery, boldTableFont)); DelCell.HorizontalAlignment = 1; itemTable.AddCell(DelCell); //Delivery End //Deposit start PdfPCell depCell = new PdfPCell(new Phrase("")); depCell.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER; itemTable.AddCell(depCell); PdfPCell depCell2 = new PdfPCell(new Phrase("")); depCell2.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER; itemTable.AddCell(depCell2); PdfPCell depCell3 = new PdfPCell(new Phrase("")); depCell3.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER; itemTable.AddCell(depCell3); PdfPCell depCelll = new PdfPCell(new Phrase("Deposit", boldTableFont)); depCelll.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER; depCelll.HorizontalAlignment = 1; itemTable.AddCell(depCelll); PdfPCell depCell4 = new PdfPCell(new Phrase("$" + orderDetail.Deposit, boldTableFont)); depCell4.HorizontalAlignment = 1; itemTable.AddCell(depCell4); //Deposit End // Table footer PdfPCell totalAmtCell1 = new PdfPCell(new Phrase("")); totalAmtCell1.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER; itemTable.AddCell(totalAmtCell1); PdfPCell totalAmtCell2 = new PdfPCell(new Phrase("")); totalAmtCell2.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER; itemTable.AddCell(totalAmtCell2); PdfPCell totalAmtCell3 = new PdfPCell(new Phrase("")); totalAmtCell3.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER; itemTable.AddCell(totalAmtCell3); PdfPCell totalAmtStrCell = new PdfPCell(new Phrase("Total Amount", boldTableFont)); totalAmtStrCell.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER; totalAmtStrCell.HorizontalAlignment = 1; itemTable.AddCell(totalAmtStrCell); PdfPCell totalAmtCell = new PdfPCell(new Phrase("$" + orderDetail.Total, boldTableFont)); totalAmtCell.HorizontalAlignment = 1; itemTable.AddCell(totalAmtCell); PdfPCell cell = new PdfPCell(new Phrase("Thank You For Your Support", bodyFont)); cell.Colspan = 5; cell.HorizontalAlignment = 1; itemTable.AddCell(cell); doc.Add(itemTable); #endregion PdfContentByte cb = new PdfContentByte(writer); BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, true); cb = new PdfContentByte(writer); cb = writer.DirectContent; cb.BeginText(); cb.SetFontAndSize(bf, 8); cb.SetTextMatrix(pageSize.GetLeft(120), 20); cb.ShowText("Invoice was created on a computer and is valid without the signature and seal. "); cb.EndText(); //Move the pointer and draw line to separate footer section from rest of page cb.MoveTo(40, doc.PageSize.GetBottom(50)); cb.LineTo(doc.PageSize.Width - 40, doc.PageSize.GetBottom(50)); cb.Stroke(); //PdfContentByte content = writer.DirectContent; //Rectangle rectangle = new Rectangle(doc.PageSize); //rectangle.Left += doc.LeftMargin; //rectangle.Right -= doc.RightMargin; //rectangle.Top -= doc.TopMargin; //rectangle.Bottom += doc.BottomMargin; //content.SetColorStroke(GrayColor.BLACK); //content.Rectangle(rectangle.Left, rectangle.Bottom, rectangle.Width, rectangle.Height); //content.Stroke(); writer.CloseStream = false; doc.Close(); memoryStream.Position = 0; QRModel qr = new QRModel(); QRCodeGenerator ObjQr = new QRCodeGenerator(); qr.Message = "https://2020grp26.azurewebsites.net/Order/Details/" + order.OrderID; QRCodeData qrCodeData = ObjQr.CreateQrCode(qr.Message, QRCodeGenerator.ECCLevel.Q); System.Drawing.Bitmap bitMap = new QRCode(qrCodeData).GetGraphic(20); using (MemoryStream ms = new MemoryStream()) { bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] byteImage = ms.ToArray(); ViewBag.Url = "data:image/png;base64," + Convert.ToBase64String(byteImage); ms.Position = 0; // start of working email SmtpClient client = new SmtpClient("smtp.sendgrid.net"); client.Port = 25; client.Host = "smtp.sendgrid.net"; client.Timeout = 10000; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; client.UseDefaultCredentials = false; var key = Environment.GetEnvironmentVariable("apikey"); client.Credentials = new NetworkCredential("apikey", key /*, user, password*/); System.Net.Mail.Attachment attachment; System.Net.Mail.Attachment attach; attachment = new System.Net.Mail.Attachment(memoryStream, "order.pdf"); attach = new System.Net.Mail.Attachment(ms, "order.png"); MailMessage msz = new MailMessage(Email, Email) { From = new MailAddress(ConfigurationManager.AppSettings["Email"].ToString()), Subject = "order Details for " + Name.ToUpper(), IsBodyHtml = true, Body = " Good Day : " + Name.ToUpper() + ", Please find attached order information for order ID : " + order.OrderID, }; msz.Attachments.Add(attachment); msz.Attachments.Add(attach); client.Send(msz); ModelState.Clear(); // end //var at = new SendGrid.Helpers.Mail.Attachment(memoryStream, "Order.pdf"); //msz.Attachments.Add(new System.Net.Mail.Attachment(memoryStream, "order.pdf")); // msz.AddAttachment(Server.MapPath("")); //SmtpClient smtp = new SmtpClient(); // var response = client.SendMailAsync(msz); //client.SendAsync(msz, null); // smtp.SendAsync(msz); } } catch (Exception ex) { ModelState.Clear(); ViewBag.Message = $"sorry we are facing a problem{ex.Message}"; } //3. Remove shopping cart session Session.Remove(strCart); return(RedirectToAction("Index", "Home")); }