public string CreateImage(string json, string absolutepath) { //declare random object to create last 2 characters of filename Random r = new Random(); //use combination of date and random 2 digit number to create a unique photo id string fileName = DateTime.Now.ToBinary().ToString() + r.Next(10, 100).ToString() + ".png"; //remove any - signs fileName = fileName.Replace("-", ""); //create converer SignatureToImage converter = new SignatureToImage(); converter.CanvasHeight = 200; converter.CanvasWidth = 600; //convert image Bitmap image = converter.SigJsonToImage(json); //save image image.Save(absolutepath + fileName); //split string at application root string[] components = absolutepath.Split(new string[] { "\\SDFC", "\\wwwroot" }, StringSplitOptions.None); //return relative path return(components[components.Length - 1] + fileName); }
public ActionResult Index(WorkOrderLog input, Guid crewId, bool isComplete) { using (var context = new WorkOrderContext()) { var workOrder = context.WorkOrders.Include(w => w.WorkOrderLogs).First(w => w.Id == input.WorkOrderId); workOrder.IsComplete = isComplete; var signatureValue = Request.Form["Signature"]; if (!string.IsNullOrEmpty(signatureValue)) { var signature = JsonConvert.DeserializeObject <Signature>(signatureValue); var converter = new SignatureToImage(); var image = converter.SigJsonToImage(signatureValue); } if (!workOrder.WorkOrderLogs.Any()) { input.Date = DateTime.Now; workOrder.WorkOrderLogs.Add(input); } else { var log = workOrder.WorkOrderLogs.First(); log.Date = DateTime.Now; log.Notes = input.Notes; } context.SaveChanges(); return(RedirectToAction("Index", new { crewId = crewId })); } }
public void ProcessRequest(HttpContext context) { //take JSON string and convert to png string jsonStr = context.Request.Form["json"]; SignatureToImage sit = new SignatureToImage(); #region set the width and height (IMPORTANT!!) try { sit.CanvasWidth = Convert.ToInt32(context.Request.Form["width"]); } catch { sit.CanvasWidth = 200; } try { sit.CanvasHeight = Convert.ToInt32(context.Request.Form["height"]); } catch { sit.CanvasHeight = 60; } #endregion try { string result = string.Empty; Bitmap bitmapImg = sit.SigJsonToImage(jsonStr); string directoryName = string.Empty; string fileName = "signature.png"; string filePath = FileUtility.EnsurePath(ref directoryName, ref fileName); //string pngStr = string.Empty; using (MemoryStream ms = new MemoryStream()) { bitmapImg.Save(ms, System.Drawing.Imaging.ImageFormat.Png); //byte[] pngBin = new byte[ms.Length]; //pngBin = ms.ToArray(); //pngStr = "data:image/png;base64," + Convert.ToBase64String(pngBin); using (Stream fileStream = FileUtility.Open(filePath, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { this.CopyStream(ms, fileStream); } } result = "<collection><object><fields><field name='FileName'><value>" + HttpUtility.HtmlEncode(fileName) + "</value></field><field name='FilePath'><value>" + HttpUtility.HtmlEncode(filePath) + "</value></field><field name='FileRequestData'><value></value></field></fields></object></collection>"; context.Response.ContentType = "text/xml"; context.Response.Write(result); } catch (Exception ex) { context.Response.ContentType = "text/plain"; context.Response.ClearContent(); Logging.LogException(ex, string.Format("Error getting image: {0}", ex.ToString()), false, true); context.Response.Write("Error getting signature"); } }
public JsonResult SignConsignmentContract(long id, string sellerSignature) { try { Consignment consignment = InvoiceRepository.GetConsignment(id); ConsignmentContract consignmentContract = InvoiceRepository.GetConsignmentContract(id); if (consignment == null || consignmentContract == null || consignmentContract.StatusID != (int)Consts.ConsignmentContractStatus.Unsigned || consignment.User_ID != AppHelper.CurrentUser.ID) { throw new Exception("Error occurred during the process of signing the document. Please reload page and try again"); } if (string.IsNullOrWhiteSpace(sellerSignature)) { throw new Exception("Draw signature as first."); } Specialist specialist = InvoiceRepository.GetSpecialist(consignment.Specialist_ID.GetValueOrDefault(-1)); if (specialist == null) { throw new Exception("Error occurred during the process of signing the document. Please contact us."); } string lelandsSignaturePath = AppHelper.SignatureImagesOnDisk(string.Format("userSignature{0}.png", specialist.User_ID)); FileInfo fileInfo = new FileInfo(lelandsSignaturePath); if (!fileInfo.Exists) { throw new Exception("Error occurred during the process of signing the document. Please contact us."); } SignatureToImage signature = new SignatureToImage(); Bitmap signatureImage = signature.SigJsonToImage(sellerSignature); string sellerSignaturePath = AppHelper.ConsignmentContractOnDisk(consignment.ID, consignmentContract.FileName.ToLower().Replace(".pdf", ".png")); fileInfo = new FileInfo(sellerSignaturePath); if (fileInfo.Exists) { fileInfo.Delete(); } signatureImage.Save(sellerSignaturePath); Address lelandsAddress = new Address { FirstName = "Lelands.com", LastName = Consts.SiteEmail, Address_1 = Consts.CompanyAddress, City = Consts.CompanyCity, State = Consts.CompanyState, Zip = Consts.CompanyZip, HomePhone = Consts.CompanyPhone, WorkPhone = Consts.CompanyFax }; User consignor = UserRepository.GetUser(consignment.User_ID, true); Address consignorAddress = Address.GetAddress(UserRepository.GetAddressCard(consignor.Billing_AddressCard_ID.GetValueOrDefault(0), true)); PdfReports.ConsignmentContract(AppHelper.ConsignmentContractOnDisk(consignment.ID, consignmentContract.FileName), AppHelper.PublicImagesOnDisk("logo.png"), string.Empty, Consts.CompanyTitleName, string.Empty, lelandsAddress, lelandsSignaturePath, consignorAddress, consignor.Email, sellerSignaturePath, DateTime.Now, InvoiceRepository.GetConsignmentDetailsByConsignmentID(id), consignmentContract.ContractText); consignmentContract.StatusID = (int)Consts.ConsignmentContractStatus.Signed; InvoiceRepository.UpdateConsignmentContract(consignmentContract); } catch (Exception exc) { return(JSON(new { success = false, exc.Message })); } return(JSON(new { success = true })); }
//UpdateUserForm public object UpdateUserForm(string user, ModelStateDictionary ModelState, string newSignature) { long user_id = 0; try { JavaScriptSerializer serializer = new JavaScriptSerializer(); UserRegistration usr = serializer.Deserialize <UserRegistration>(user); if (!AppHelper.CurrentUser.IsRoot && AppHelper.CurrentUser.ID != usr.ID && (usr.UserType == (byte)Consts.UserTypes.Admin || usr.UserType == (byte)Consts.UserTypes.Root)) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't create/update this user.")); } usr.ConfirmPassword = usr.Password; usr.ConfirmEmail = usr.Email; if (usr.UserType == (byte)Consts.UserTypes.Buyer || usr.UserType == (byte)Consts.UserTypes.HouseBidder) { usr.CommissionRate = CommissionRate.DefaultCommission; } if (usr.UserType == (byte)Consts.UserTypes.Seller || usr.UserType == (byte)Consts.UserTypes.SellerBuyer) { usr.IsPostCards = true; } usr.ValidateWithoutConfim(ModelState); if (ModelState.IsValid) { if (!UpdateUser(usr)) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "The user's information wasn't saved.")); } user_id = usr.ID; if (!string.IsNullOrWhiteSpace(newSignature)) { SignatureToImage signature = new SignatureToImage(); Bitmap signatureImage = signature.SigJsonToImage(newSignature); string filePath = DiffMethods.SignatureImagesOnDisk(string.Format("userSignature{0}.png", usr.ID)); FileInfo fileInfo = new FileInfo(filePath); if (fileInfo.Exists) { fileInfo.Delete(); } signatureImage.Save(filePath); } } else { ModelState.Remove("user"); if (usr.BillingLikeShipping) { KeyValuePair <string, ModelState>[] res = (from M in ModelState where M.Key.Contains("Shipping") select M).ToArray(); if (res.Count() > 0) { foreach (KeyValuePair <string, ModelState> r in res) { ModelState.Remove(r); } } } var errors = (from M in ModelState select new { field = M.Key, message = M.Value.Errors.FirstOrDefault().ErrorMessage }).ToArray(); return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "Please correct the errors and try again.", errors)); } } catch (Exception ex) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message)); } return(new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS, "", user_id)); }
private void CreateSignatureBitmap(Agreement agreement, SignatureToImage sigToImage, string signatureUrl) { var bitmap = sigToImage.SigJsonToImage(agreement.Signature); var targetPath = Server.MapPath(signatureUrl); bitmap.Save(targetPath, ImageFormat.Gif); }
private string CreateSignature(Agreement agreement) { var sigToImage = new SignatureToImage() { CanvasWidth = 200, CanvasHeight = 120 }; var signatureUrl = "~/Output/Signatures/" + agreement.UniqueId + ".gif"; CreateSignatureBitmap(agreement, sigToImage, signatureUrl); signatureUrl = Url.Content(signatureUrl); agreement.Signature = signatureUrl; return signatureUrl; }
public void ProcessRequest(HttpContext context) { #region Get image in PNG format //take JSON string and convert to png string jsonStr = context.Request.Form["json"]; SignatureToImage sit = new SignatureToImage(); #region set the width and height (IMPORTANT!!) try { sit.CanvasWidth = Convert.ToInt32(context.Request.Form["width"]); } catch { sit.CanvasWidth = 200; } try { sit.CanvasHeight = Convert.ToInt32(context.Request.Form["height"]); } catch { sit.CanvasHeight = 60; } #endregion Bitmap bitmapImg = sit.SigJsonToImage(jsonStr); string pngStr = string.Empty; using (MemoryStream ms = new MemoryStream()) { bitmapImg.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] pngBin = new byte[ms.Length]; pngBin = ms.ToArray(); pngStr = "data:image/png;base64," + Convert.ToBase64String(pngBin); } #endregion #region save to smartobject and return the new obj ID SCSMOC.SmartObjectClientServer smoSvr = new SCSMOC.SmartObjectClientServer(); try { smoSvr.CreateConnection(); smoSvr.Connection.Open(GetSMOConnStr()); SCSMOC.SmartObject smoObj = smoSvr.GetSmartObject("DigitalSignature"); smoObj.Properties["Signature"].Value = pngStr; smoObj.Properties["FormURL"].Value = context.Request.Form["url"]; smoObj.Properties["UserFQN"].Value = context.Request.Form["fqn"]; smoObj.Properties["Date"].Value = DateTime.Now.ToString(); smoObj.MethodToExecute = "Create"; smoObj = smoSvr.ExecuteScalar(smoObj); context.Response.Write(smoObj.Properties["ID"].Value.ToString()); } finally { if (smoSvr.Connection != null && smoSvr.Connection.IsConnected) { smoSvr.Connection.Dispose(); } } #endregion }