internal static Entity FindRecordByNumber(WordSearchObject searchValues, IOrganizationService crm) { try { var query = new QueryExpression(searchValues.searchentity); query.ColumnSet = new ColumnSet(true); query.Criteria.AddCondition(searchValues.searchnumberfield, ConditionOperator.Equal, searchValues.searchnumber); var results = crm.RetrieveMultiple(query); if (results.Entities.Count == 1) { return(results.Entities[0]); } return(null); } catch (Exception ex) { if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.cannotfindsearch + ex.Message, Resources.ResourceWordNb.documentsinging, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(Resources.ResourceWordEn.cannotfindsearch + ex.Message, Resources.ResourceWordEn.documentsinging, MessageBoxButtons.OK, MessageBoxIcon.Error); } return(null); } }
internal static string GetDefaultSPSiteUrlFromCRMSiteCollectionEntity(WordSearchObject searchValues, IOrganizationService crm) { try { ConditionExpression c = new ConditionExpression("isdefault", ConditionOperator.Equal, true); FilterExpression f = new FilterExpression(LogicalOperator.And); f.Conditions.Add(c); QueryExpression q = new QueryExpression("sharepointsite"); q.Criteria = f; q.ColumnSet = new ColumnSet("sharepointsiteid", "name", "absoluteurl", "relativeurl", "isdefault", "parentsite"); EntityCollection crmSites = crm.RetrieveMultiple(q); if (crmSites.Entities.Count > 0) { Entity defaultSharePointSite = crmSites.Entities[0]; if (defaultSharePointSite.Attributes.Contains("parentsite") && defaultSharePointSite.Attributes.Contains("relativeurl")) { Entity parentSiteOfDefaultSite = crm.Retrieve("sharepointsite", ((EntityReference)defaultSharePointSite["parentsite"]).Id, new ColumnSet(true)); return((string)parentSiteOfDefaultSite["absoluteurl"] + "/" + defaultSharePointSite.GetAttributeValue <string>("relativeurl")); } else { return(defaultSharePointSite.GetAttributeValue <string>("absoluteurl")); } } // no SharePoint Sites defined in CRM if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.spsitenotfound, Resources.ResourceWordNb.datafromcrm, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(Resources.ResourceWordEn.spsitenotfound, Resources.ResourceWordEn.datafromcrm, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("CrmMethods -> GetDefaultSPSite (" + ex.Message + ")", "Getting data from CRM", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } return(null); }
private static void SaveInSP(WordSearchObject searchValues) { try { var crm = WordConnectToCrm.ConnectToMSCRM(); if (crm == null) { return; } var entity = WordHandlerCRM.FindRecordByNumber(searchValues, crm); if (entity == null) { if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.recordnotfound + searchValues.searchnumber + ".", Resources.ResourceWordNb.docsp, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show(Resources.ResourceWordEn.recordnotfound + searchValues.searchnumber + ".", Resources.ResourceWordEn.docsp, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } Save(entity, searchValues, crm); } catch (Exception ex) { if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.cannotsavetosp, Resources.ResourceWordNb.docsp, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show(Resources.ResourceWordEn.cannotsavetosp, Resources.ResourceWordEn.docsp, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
public static void SendDocumentToSP(WordSearchObject searchValues) { try { SaveInSP(searchValues); } catch (Exception ex) { if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.cannotsavetosp + ex.Message, Resources.ResourceWordNb.docsp, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(Resources.ResourceWordNb.cannotsavetosp + ex.Message, Resources.ResourceWordEn.docsp, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public async Task <HttpResponseMessage> SendRequest(WordSearchObject searchValues, Document doc, string pdfName, string orgName, WordCRMConfig crmconfig, IOrganizationService crm) { try { using (var client = new HttpClient()) { using (var content = new MultipartFormDataContent()) { var apiurl = crmconfig.Webapiurl; client.BaseAddress = new Uri(apiurl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/pdf")); StreamReader sr = new StreamReader(doc.Path + "\\" + pdfName); var fileContent = new ByteArrayContent(WordHelpers.ReadToEnd(sr.BaseStream)); var orgname = new NameValueHeaderValue("orgname", orgName); var language = new NameValueHeaderValue("language", searchValues.language.ToString()); var method = new NameValueHeaderValue("method", crmconfig.Wordsigningmethod.ToString()); //pdfName = Convert.ToBase64String(Encoding.UTF8.GetBytes(pdfName)); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = pdfName, Parameters = { orgname, language, method } }; fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); content.Add(fileContent); var response = client.PostAsync("api/SignRequest/PostWord", content).Result; sr.Close(); return(response); } } } catch (Exception ex) { return(new HttpResponseMessage(HttpStatusCode.ExpectationFailed)); } }
internal static void SavePDFInCRM(WordSearchObject searchValues, string docName, string docPath, Guid documentsigningid, IOrganizationService crm) { try { byte[] pdf = File.ReadAllBytes(docPath); string encodedData = Convert.ToBase64String(pdf); Entity Annotation = new Entity("annotation"); Annotation.Attributes["objectid"] = new EntityReference("pp_documentsigning", documentsigningid); Annotation.Attributes["objecttypecode"] = "pp_documentsigning"; Annotation.Attributes["subject"] = "Original: " + docName; Annotation.Attributes["documentbody"] = encodedData; Annotation.Attributes["mimetype"] = @"application/pdf"; if (searchValues.language == 1044) { Annotation.Attributes["notetext"] = Resources.ResourceWordNb.documentsentforsinging; } else { Annotation.Attributes["notetext"] = Resources.ResourceWordEn.documentsentforsinging; } Annotation.Attributes["filename"] = docName + ".pdf"; crm.Create(Annotation); } catch (Exception ex) { if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.cannotcreatenote + ex.Message, Resources.ResourceWordNb.documentsinging, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(Resources.ResourceWordEn.cannotcreatenote + ex.Message, Resources.ResourceWordEn.documentsinging, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
internal static Guid CreatDocumentSigningInCRM(string sdsurl, string docPath, string docName, Entity entity, WordSearchObject searchValues, WordCRMConfig crmconfig, IOrganizationService crm) { try { var parts = sdsurl.Split('='); var taskid = parts.Last(); var requestid = GetRequestId(sdsurl); var saveinsp = crmconfig.Wordsaveinsp; //Create signing package var documentsigning = new Entity("pp_documentsigning"); documentsigning["pp_name"] = "Word dokument: " + docName; documentsigning["pp_requestid"] = requestid; documentsigning["pp_signing"] = new OptionSetValue(crmconfig.Wordsigningmethod); if (saveinsp) { documentsigning["pp_saveindocumentlocation"] = true; } if (entity != null) { var regardingidfield = "pp_" + entity.LogicalName + "id"; documentsigning[regardingidfield] = new EntityReference(entity.LogicalName, entity.Id); } var documentsigningid = crm.Create(documentsigning); //Save doc as note in singing package SavePDFInCRM(searchValues, docName, docPath, documentsigningid, crm); //Create signing task var documenttask = new Entity("pp_signicatdocurl"); documenttask["pp_name"] = taskid; documenttask["pp_sdsurl"] = sdsurl; if (documentsigningid != Guid.Empty) { documenttask["pp_documentsigningid"] = new EntityReference("pp_documentsigning", documentsigningid); } documenttask["statuscode"] = new OptionSetValue(1); var documenttaskid = crm.Create(documenttask); CreateOrAddContact(searchValues.recievermail, documenttaskid, documentsigningid, crm); return(documentsigningid); } catch (Exception ex) { if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.cannotcreateinsignicat + ex.Message, Resources.ResourceWordNb.documentsinging, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(Resources.ResourceWordEn.cannotcreateinsignicat + ex.Message, Resources.ResourceWordEn.documentsinging, MessageBoxButtons.OK, MessageBoxIcon.Error); } return(Guid.Empty); } }
internal static void SendEmail(string sdsurl, string docName, Entity entity, Guid documentsigningid, WordSearchObject searchValues, WordCRMConfig crmconfig, IOrganizationService crm) { try { var linkBtnImg = "https://ppsignicatresources.blob.core.windows.net/signicatlinkbutton/SignicatLinkButton.png"; var emailLogoImg = "https://ppsignicatresources.blob.core.windows.net/signicatlinkbutton/SignicatMailLogo.png"; var url = ""; if (searchValues.language == 1044) { url = "<br/><a href='" + sdsurl + "'><img alt='Click her' src='" + linkBtnImg + "'></a>"; } else { url = "<br/><a href='" + sdsurl + "'><img alt='Click here' src='" + linkBtnImg + "'></a>"; } // Create an e-mail message. Entity email = new Entity("email"); if (crmconfig.Worduser == null) { if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.cannotfindsender); } else { MessageBox.Show(Resources.ResourceWordEn.cannotfindsender); } } if (crmconfig.Worduser != null) { Entity fromParty = new Entity("activityparty"); fromParty["partyid"] = crmconfig.Worduser; var listfrom = new List <Entity>() { fromParty }; email["from"] = new EntityCollection(listfrom); } Entity toParty = new Entity("activityparty"); //if (string.IsNullOrWhiteSpace(searchValues.recievermail) && entity != null) // toParty["partyid"] = new EntityReference(entity.LogicalName, entity.Id); if (!string.IsNullOrWhiteSpace(searchValues.recievermail)) { var reciever = GetCustomerByEmail(searchValues.recievermail, crm); if (reciever != null) { toParty["partyid"] = reciever; } else { toParty["addressused"] = searchValues.recievermail; } var listto = new List <Entity>() { toParty }; email["to"] = new EntityCollection(listto); } var subject = ""; var description = ""; if (searchValues.language == 1044) { subject = Resources.ResourceWordNb.documentsinging + ": " + docName; description = Resources.ResourceWordNb.clicktosign; } else { subject = Resources.ResourceWordEn.documentsinging + ": " + docName; description = Resources.ResourceWordEn.clicktosign; } email["subject"] = subject; email["directioncode"] = true; email["regardingobjectid"] = new EntityReference("pp_documentsigning", documentsigningid); if (description != null) { var newText = "<img src='" + emailLogoImg + "'/><br/>"; //newText += description; newText += url + "<br/><br/><br/>"; newText += "<br/> With Regards / Med vennlig Hilsen<br/>"; newText += crmconfig.Wordusername; email["description"] = newText; } //SendEmailFromTemplate(email, documentsigningid, sdsurl, crm); //return; var _emailId = crm.Create(email); // Use the SendEmail message to send an e-mail message. SendEmailRequest sendEmailreq = new SendEmailRequest { EmailId = _emailId, TrackingToken = "", IssueSend = true }; SendEmailResponse sendEmailresp = (SendEmailResponse)crm.Execute(sendEmailreq); } catch (Exception ex) { if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.emailerror + ex.Message, "Email sending", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(Resources.ResourceWordEn.emailerror + ex.Message, "Email sending", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private static void Save(Entity Entity, WordSearchObject searchValues, IOrganizationService service) { try { var spUsername = ""; //WordHandlerCRM.GetSettingKeyValue(service, "spuser"); var spPassword = ""; //WordHandlerCRM.GetSettingKeyValue(service, "sppassword"); var currentSharePointFolderEntity = GetDocumentLocation(Entity.ToEntityReference(), "regardingobjectid", service); var sharePointUrl = GetDefaultSPSiteUrlFromCRMSiteCollectionEntity(searchValues, service); Document document = Globals.ThisAddIn.Application.ActiveDocument; var fullname = document.Name.Split('.'); var pdfName = fullname[0] + ".pdf"; var fullPath = document.Path + "\\" + pdfName; document.ExportAsFixedFormat( Path.Combine(document.Path, pdfName), WdExportFormat.wdExportFormatPDF, OpenAfterExport: false); HandleRelativeUrl(currentSharePointFolderEntity, service); var urlSplit = folderRelativeUrl.Split('/').ToList(); var listTitle = urlSplit.First(); var folderName = urlSplit[1]; using (ClientContext clientContext = new ClientContext(sharePointUrl)) { SecureString passWord = new SecureString(); foreach (char c in spPassword.ToCharArray()) { passWord.AppendChar(c); } clientContext.Credentials = new SharePointOnlineCredentials(spUsername, passWord); Web web = clientContext.Web; clientContext.Load(web); clientContext.Load(web.Lists); clientContext.ExecuteQuery(); var accountList = web.Lists.GetByTitle(listTitle); clientContext.Load(accountList); clientContext.ExecuteQuery(); var folder = accountList.RootFolder.Folders.GetByUrl(folderName); FileCreationInformation newFile = new FileCreationInformation(); newFile.Content = File.ReadAllBytes(document.Path + "\\" + pdfName); newFile.Url = sharePointUrl + "/" + folderRelativeUrl + pdfName; newFile.Overwrite = true; var uploadFile = folder.Files.Add(newFile); clientContext.ExecuteQuery(); if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.docsavedsp, Resources.ResourceWordNb.docsp, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show(Resources.ResourceWordEn.docsavedsp, Resources.ResourceWordEn.docsp, MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } File.Delete(fullPath); } catch (Exception ex) { if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.cannotfindsetting + ex.Message, Resources.ResourceWordNb.datafromcrm, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(Resources.ResourceWordEn.cannotfindsetting + ex.Message, Resources.ResourceWordEn.datafromcrm, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btnSaveToSP_Click(object sender, RibbonControlEventArgs e) { var account = "accountnumber"; var order = "ordernumber"; var quote = "quotenumber"; var incident = "ticketnumber"; var contract = "contractnumber"; Document document = Globals.ThisAddIn.Application.ActiveDocument; Object start = document.Content.Start; Object end = document.Content.End; var selectedText = Globals.ThisAddIn.Application.ActiveDocument.Range(start, end).Text; selectedText = selectedText.Replace("\r\a", "").Replace("\r", "").Replace("\a", ""); var docText = selectedText.Split(' '); string searchnumber, searchentity, searchnumberfield; searchnumber = searchentity = searchnumberfield = ""; for (int i = 0; i < docText.Length; i++) { if (docText[i].ToLower().Contains(account)) { searchnumber = docText[i + 1]; searchentity = "account"; searchnumberfield = "accountnumber"; break; } if (docText[i].ToLower().Contains(order)) { searchnumber = docText[i + 1]; searchentity = "salesorder"; searchnumberfield = "ordernumber"; break; } if (docText[i].ToLower().Contains(quote)) { searchnumber = docText[i + 1]; searchentity = "quote"; searchnumberfield = "quotenumber"; break; } if (docText[i].ToLower().Contains(incident)) { searchnumber = docText[i + 1]; searchentity = "incident"; searchnumberfield = "ticketnumber"; break; } if (docText[i].ToLower().Contains(contract)) { searchnumber = docText[i + 1]; searchentity = "contract"; searchnumberfield = "contractnumber"; break; } } for (int i = 0; i < docText.Length; i++) { if (docText[i].ToLower().Contains("saveat")) { searchentity = docText[i + 1]; searchnumber = docText[i + 2]; if (searchentity == "account") { searchnumberfield = searchentity + "accountnumber"; } if (searchentity == "salesorder") { searchnumberfield = "ordernumber"; } if (searchentity == "quote") { searchnumberfield = "quotenumber"; } if (searchentity == "incident") { searchnumberfield = "ticketnumber"; } if (searchentity == "contract") { searchnumberfield = "contractnumber"; } break; } } WordSearchObject searchValues = new WordSearchObject(); searchValues.searchentity = searchentity; searchValues.searchnumber = searchnumber; searchValues.searchnumberfield = searchnumberfield; if (string.IsNullOrWhiteSpace(searchentity) || string.IsNullOrWhiteSpace(searchnumber) || string.IsNullOrWhiteSpace(searchnumberfield)) { if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.wordtemplaterror, Resources.ResourceWordNb.documentsinging, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(Resources.ResourceWordEn.wordtemplaterror, Resources.ResourceWordEn.documentsinging, MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } //WordHandlerSP.SendDocumentToSP(searchValues); }
private void buttonSign_Click(object sender, RibbonControlEventArgs e) { try { var crm = WordConnectToCrm.ConnectToMSCRM(); if (crm == null) { return; } WordSearchObject searchValues = new WordSearchObject(); WordCRMConfig crmconfig = WordHandlerCRM.GetCRMConfig(crm); searchValues.language = WordHandlerCRM.RetrieveUserUiLanguageCode(crm, crmconfig.Worduser.Id); var accountfield = (!string.IsNullOrWhiteSpace(crmconfig.AccountNrField)) ? crmconfig.AccountNrField.Split(',') : new[] { "accountnumber" }; var orderfield = (!string.IsNullOrWhiteSpace(crmconfig.OrderNrField)) ? crmconfig.OrderNrField.Split(',') : new[] { "ordernumber" }; var quotefield = (!string.IsNullOrWhiteSpace(crmconfig.QuoteNrField)) ? crmconfig.QuoteNrField.Split(',') : new[] { "quotenumber" }; var incidentfield = (!string.IsNullOrWhiteSpace(crmconfig.IncidentNrField)) ? crmconfig.IncidentNrField.Split(',') : new[] { "ticketnumber" }; var contractfield = (!string.IsNullOrWhiteSpace(crmconfig.ContractNrField)) ? crmconfig.ContractNrField.Split(',') : new[] { "contractnumber" }; var emailfield = (!string.IsNullOrWhiteSpace(crmconfig.EmailField)) ? crmconfig.EmailField.Split(',') : new[] { "recievermailaddress" }; var account = accountfield; // new[] { "accountnumber", "kundenr" }; var order = orderfield; //new[] { "ordernumber", "ordrenummer"}; var quote = quotefield; //new[] { "quotenumber"}; var incident = incidentfield; //new[] { "ticketnumber"}; var contract = contractfield; //new[] { "contractnumber"}; var recievermail = emailfield; //new[] { "recievermailaddress", "e-post" }; Document document = Globals.ThisAddIn.Application.ActiveDocument; //HeaderFooter objHeader = document.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary]; Object start = document.Content.Start; Object end = document.Content.End; //document.Range(ref start, ref end).Select(); var selectedText = Globals.ThisAddIn.Application.ActiveDocument.Range(start, end).Text; //var headerText = objHeader.Range.Text; //headerText = headerText.Replace("\r\a", "").Replace("\r", "").Replace("\a", ""); //var headerTextSplit = headerText.Split(' '); selectedText = selectedText.Replace("\r\a", "").Replace("\r", "").Replace("\a", ""); var docText = selectedText.Split(' '); string searchnumber, searchentity, searchnumberfield, senderfrom, recieverto; searchnumber = searchentity = searchnumberfield = senderfrom = recieverto = ""; for (int i = 0; i < docText.Length; i++) { //if (docText[i].ToLower().Contains(recievermail)) if (recievermail.Any(docText[i].Contains)) { recieverto = docText[i + 1]; } } for (int i = 0; i < docText.Length; i++) { //if (docText[i].ToLower().Contains(account)) if (account.Any(docText[i].Contains)) { searchnumber = docText[i + 1]; searchentity = "account"; searchnumberfield = "accountnumber"; break; } //if (docText[i].ToLower().Contains(order)) if (order.Any(docText[i].Contains)) { searchnumber = docText[i + 1]; searchentity = "salesorder"; searchnumberfield = "ordernumber"; break; } //if (docText[i].ToLower().Contains(quote)) if (quote.Any(docText[i].Contains)) { searchnumber = docText[i + 1]; searchentity = "quote"; searchnumberfield = "quotenumber"; break; } //if (docText[i].ToLower().Contains(incident)) if (incident.Any(docText[i].Contains)) { searchnumber = docText[i + 1]; searchentity = "incident"; searchnumberfield = "ticketnumber"; break; } //if (docText[i].ToLower().Contains(contract)) if (contract.Any(docText[i].Contains)) { searchnumber = docText[i + 1]; searchentity = "contract"; searchnumberfield = "contractnumber"; break; } } for (int i = 0; i < docText.Length; i++) { if (docText[i].ToLower().Contains("saveat")) { searchentity = docText[i + 1]; searchnumber = docText[i + 2]; if (searchentity == "account") { searchnumberfield = searchentity + "accountnumber"; } if (searchentity == "salesorder") { searchnumberfield = "ordernumber"; } if (searchentity == "quote") { searchnumberfield = "quotenumber"; } if (searchentity == "incident") { searchnumberfield = "ticketnumber"; } if (searchentity == "contract") { searchnumberfield = "contractnumber"; } break; } } searchValues.searchentity = searchentity; searchValues.searchnumber = searchnumber; searchValues.searchnumberfield = searchnumberfield; searchValues.recievermail = recieverto; if (string.IsNullOrWhiteSpace(searchentity) || string.IsNullOrWhiteSpace(searchnumber) || string.IsNullOrWhiteSpace(searchnumberfield)) { if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.wordtemplaterror, Resources.ResourceWordNb.documentsinging, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(Resources.ResourceWordEn.wordtemplaterror, Resources.ResourceWordEn.documentsinging, MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } WordHandlerSigning.SendDocumentForSigning(searchValues, crmconfig, crm); } catch (Exception ex) { MessageBox.Show(ex.Message, "Signicat Sign", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
internal static async Task SendDocumentForSigning(WordSearchObject searchValues, WordCRMConfig crmconfig, IOrganizationService crm) { Document document = Globals.ThisAddIn.Application.ActiveDocument; try { var fullname = document.Name.Split('.'); var pdfName = fullname[0] + ".pdf"; var fullPath = document.Path + "\\" + pdfName; if (File.Exists(fullPath)) { File.Delete(fullPath); } document.ExportAsFixedFormat( Path.Combine(document.Path, pdfName), WdExportFormat.wdExportFormatPDF, OpenAfterExport: false); var orgName = ConfigurationManager.AppSettings["OrgName"]; var signicatHandler = new WordHandlerSignicat(); var responseMessage = await signicatHandler.SendRequest(searchValues, document, pdfName, orgName, crmconfig, crm); var stringResult = await responseMessage.Content.ReadAsStringAsync(); var result = stringResult.Split('"'); var sdsurl = result[1]; var entity = WordHandlerCRM.FindRecordByNumber(searchValues, crm); if (entity == null) { if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.recordnotfound + searchValues.searchnumber + Resources.ResourceWordNb.unassociated, Resources.ResourceWordNb.documentsinging, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show(Resources.ResourceWordEn.recordnotfound + searchValues.searchnumber + Resources.ResourceWordEn.unassociated, Resources.ResourceWordEn.documentsinging, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } var documentsigningid = WordHandlerCRM.CreatDocumentSigningInCRM(sdsurl, fullPath, fullname[0], entity, searchValues, crmconfig, crm); if (documentsigningid != Guid.Empty) { WordHandlerCRM.SendEmail(sdsurl, fullname[0], entity, documentsigningid, searchValues, crmconfig, crm); if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.documentsent, Resources.ResourceWordNb.documentsinging, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(Resources.ResourceWordEn.documentsent, Resources.ResourceWordEn.documentsinging, MessageBoxButtons.OK, MessageBoxIcon.Information); } } File.Delete(fullPath); } catch (Exception ex) { if (searchValues.language == 1044) { MessageBox.Show(Resources.ResourceWordNb.cannotcreateinsignicat + ex.Message); } else { MessageBox.Show(Resources.ResourceWordEn.cannotcreateinsignicat + ex.Message); } } }