public void CheckIvoiceDetail() { try { listData = TakeDataList(); if (listData != null) { SendEmail(listData); } else { Log.AddLog("Выборка не дала результат"); } } catch (Exception ex) { Log.AddLog(ex.Message); } }
public List <ExchangeRateDTO> DownloadRatesFile() { try { string now = DateTime.UtcNow.Date.ToString("dd'/'MM'/'yyyy"); string url = String.Format(@"http://www.cbr.ru/scripts/XML_daily.asp?date_req={0}", now); string xml; Log.AddLog("Try download currency"); using (var webClient = new WebClient()) { xml = webClient.DownloadString(url); } XDocument doc = XDocument.Parse(xml); string date = doc.Element("ValCurs").Attribute("Date").Value; List <ExchangeRateDTO> rates = (from i in doc.Element("ValCurs").Elements("Valute") where i.Element("CharCode").Value == "USD" || i.Element("CharCode").Value == "EUR" || i.Element("CharCode").Value == "UZS" select new ExchangeRateDTO { IsoCode = i.Element("CharCode").Value, Nominal = i.Element("Nominal").Value, ExchangeValue = i.Element("Value").Value, RelevanceDate = date }).ToList(); return(rates); } catch (Exception ex) { Log.AddLog(string.Format("Somethink is wrong in ParceXML: {0}", ex.Message)); return(null); } }
public void CheckTasksItem() { try { using (var orgContext = new OrganizationServiceContext(this.service)) { var PrelistData = (from i in orgContext.CreateQuery <Task>() where i.ScheduledEnd >= DateTime.Today.AddDays(-1).ToUniversalTime() && i.ScheduledEnd <= DateTime.Today.AddDays(1).ToUniversalTime() select i).ToList(); var validTask = PrelistData.Where(x => x.Subject.Contains("подходит срок очередного платежа, требуется выставить счет заказчику") && x.RegardingObjectId.LogicalName == "invoice"); if (validTask.Count() == 0) { return; } foreach (var item in validTask) { Email unloadEmail = new Email(); unloadEmail.Subject = string.Format("По Договору {0} подходит срок очередного платежа", item.RegardingObjectId.Name); string link = string.Format(@"<a href=https://crm.softline.az/SoftlineInternationalLtd/userdefined/edit.aspx?etc=1090&id=%7b{0}%7d>{1}</a></span></u></i></p>", item.RegardingObjectId.Id.ToString(), item.RegardingObjectId.Name); unloadEmail.Description = string.Format(@"<div id=':14b' class='Am Al editable LW-avf' hidefocus='true' aria-label='Текст повідомлення' g_editable='true' role='textbox' contenteditable='true' tabindex='1' style='direction: ltr; min-height: 306px;' itacorner='6,7:1,1,0,0'><div>Уважаемый коллега, </div><div><br></div><div>по Договору {0} подходит срок очередного платежа, требуется выставить счет заказчику. <br></div><div><br></div><div>Заказ - {1}<br></div></div>" , item.RegardingObjectId.Name, link); unloadEmail.DirectionCode = true; SystemUser user = (SystemUser)service.Retrieve(SystemUser.EntityLogicalName, item.OwnerId.Id, new ColumnSet("internalemailaddress")); if (user.InternalEMailAddress == null) { Log.AddLog(string.Format("Адрес Електроной почты отсутствует... ({0})", item.OwnerId.Name)); continue; } var activity1 = new ActivityParty { AddressUsed = user.InternalEMailAddress }; var activity2 = new ActivityParty { AddressUsed = @"*****@*****.**" }; unloadEmail.Cc = new[] { activity2 }; unloadEmail.To = new[] { activity1 }; Guid createdEmailId = service.Create(unloadEmail); var sendEmailreq = new SendEmailRequest { EmailId = createdEmailId, TrackingToken = "", IssueSend = true }; try { service.Execute(sendEmailreq); } catch (Exception ex) { Log.AddLog(ex.Message); } } } } catch (Exception ex) { Log.AddLog(ex.Message); } }
public void UpdateCurrency() { try { var XmlDataList = new ParsingXML().DownloadRatesFile(); var XmlDataListNational = new ParsingXML().getNationCurrency(); if (XmlDataList == null) { Log.AddLog("Second attempt"); XmlDataList = new ParsingXML().DownloadRatesFile(); if (XmlDataList == null) { Log.AddLog("Bad Second attempt"); return; } } if (XmlDataListNational == null) { Log.AddLog("Second attempt /2"); XmlDataListNational = new ParsingXML().getNationCurrency(); if (XmlDataListNational == null) { Log.AddLog("Bad Second attempt /2"); return; } } DateTime date = Convert.ToDateTime(XmlDataList.First().RelevanceDate); decimal USD, EUR, UZS, USDNational, EURNational, RUBNational; USD = Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("USD")).ExchangeValue) / Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("USD")).Nominal); EUR = Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("EUR")).ExchangeValue) / Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("EUR")).Nominal); UZS = Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("UZS")).ExchangeValue) / Convert.ToDecimal(XmlDataList.Find(x => x.IsoCode.Contains("UZS")).Nominal); USDNational = Convert.ToDecimal(XmlDataListNational.Find(y => y.IsoCode.Contains("USD")).ExchangeValue); EURNational = Convert.ToDecimal(XmlDataListNational.Find(y => y.IsoCode.Contains("EUR")).ExchangeValue); RUBNational = Convert.ToDecimal(XmlDataListNational.Find(y => y.IsoCode.Contains("RUB")).ExchangeValue); if (FindAndDeactivateEntity(date)) { var newRateUSD = new sl_ExchangeRate() { sl_RelevanceDate = date, sl_TransactionCurrencyId = ToTransactionCurrency("USD", decimal.One), sl_ExchangeRate1 = decimal.One, new_national_currency = decimal.One }; service.Create(newRateUSD); var newRateEUR = new sl_ExchangeRate() { sl_RelevanceDate = date, sl_TransactionCurrencyId = ToTransactionCurrency("EUR", EUR / USD), sl_ExchangeRate1 = EUR / USD, new_national_currency = EURNational }; service.Create(newRateEUR); var newRateUZS = new sl_ExchangeRate() { sl_RelevanceDate = date, sl_TransactionCurrencyId = ToTransactionCurrency("UZS", UZS / USD), sl_ExchangeRate1 = UZS / USD, new_national_currency = USDNational }; service.Create(newRateUZS); var newRateRUB = new sl_ExchangeRate() { sl_RelevanceDate = date, sl_TransactionCurrencyId = ToTransactionCurrency("RUB", decimal.One / USD), sl_ExchangeRate1 = decimal.One / USD, new_national_currency = RUBNational }; service.Create(newRateRUB); } else { Log.AddLog("All Currency is correct"); } } catch (Exception ex) { Log.AddLog(string.Format("Somethink is wrong in WorkClass: {0}", ex.Message)); } }