public static string GetFormattedValue(CustomParamValue cpv) { if (cpv == null) { return(null); } var cp = cpv.Cp; if (cp == null) { return(null); } var value = cpv.CPVValue; if (!string.IsNullOrEmpty(cp.ObjectlookupCode_R)) { return(LookupHelper.GetDispalyMemberValue(cp.ObjectlookupCode_R, value)); } var fieldType = GetValueType(cpv); if (fieldType == null) { return(value); } var type = fieldType.GetNonNullableType(); var existsFormat = !string.IsNullOrEmpty(cp.CustomParamFormat); if (type == typeof(DateTime)) { var dtvalue = new StringToDateTimeConverter().Convert(value, null, GetDateTimeFormat(), Thread.CurrentThread.CurrentCulture) as DateTime?; if (dtvalue.HasValue) { return(existsFormat ? dtvalue.Value.ToString(cp.CustomParamFormat) : dtvalue.Value.ToShortDateString()); } return(null); } if (type.IsPrimitive || type == typeof(decimal)) { var nvalue = new StringToNumericConverter().Convert(value, null, fieldType, Thread.CurrentThread.CurrentCulture); if (nvalue != null) { return(existsFormat ? string.Format("{0}:" + cp.CustomParamFormat, nvalue) : nvalue.ToString()); } return(null); } return(value); }
public void StringToDateTimeOffsetConverter_ConvertConvertBackStringDateTest() { var dateConverter = new StringToDateTimeConverter(); var testDate = new DateTime(2020, 12, 12, 5, 50, 00); //Passing a DateTime to the Convert() method var dateConverted = (String)dateConverter.Convert(testDate, null, null, null); //Validates that the conversion from DateTime to String was successful Assert.IsNotNull(dateConverted); Assert.AreEqual(dateConverted.GetType(), typeof(String)); Assert.AreEqual(dateConverted.ToString(), "December 12, 2020 5:50 AM"); //Passing a string with a specific data format to the ConvertBack() method var dateContertedBack = (DateTime)dateConverter.ConvertBack("December 12, 2020 5:50 AM", null, null, null); //Validates that the conversion from String to DateTime was successful Assert.IsNotNull(dateContertedBack); Assert.AreEqual(dateContertedBack.GetType(), typeof(DateTime)); Assert.AreEqual(dateContertedBack.ToString(DefaultDateFormat), testDate.ToString(DefaultDateFormat)); }
public void SetUp() { _converter = new StringToDateTimeConverter(); }
private void Calc() { var cpv = _billOperation2Contract.Operation2ContractCpvL; if (cpv != null) { var formulaDate = cpv.FirstOrDefault(p => p != null && p.CustomParamCode.EqIgnoreCase("BillO2CCalcFDateL2")); var formulaDateStr = formulaDate != null && _dateTimeFormats != null ? formulaDate.CPVValue : string.Empty; var formulaCount = cpv.FirstOrDefault(p => p != null && p.CustomParamCode.EqIgnoreCase("BillO2CCalcFCountL2")); var formulaCountStr = formulaCount != null ? formulaCount.CPVValue : string.Empty; var formulaFactor = cpv.FirstOrDefault(p => p != null && p.CustomParamCode.EqIgnoreCase("BillO2CCalcFFactorL2")); var formulaFactorStr = formulaFactor != null ? formulaFactor.CPVValue : string.Empty; var formulaSumm = cpv.FirstOrDefault(p => p != null && p.CustomParamCode.EqIgnoreCase("BillO2CCalcFSummL2")); var formulaSummStr = formulaSumm != null ? formulaSumm.CPVValue : string.Empty; var engine = new CalcEngine.CalcEngine { DataContext = Source }; //дата DateTime?date; if (!formulaDateStr.IsNullOrEmptyAfterTrim()) { var culture = System.Threading.Thread.CurrentThread.CurrentCulture; try { date = new StringToDateTimeConverter().Convert(engine.Evaluate(formulaDateStr), null, _dateTimeFormats, culture) as DateTime?; } catch (Exception) { date = null; } } else { date = _defaltCalcDate; } //цена double price = 0; if (date.HasValue) { using (var mgrTariff = IoC.Instance.Resolve <IBaseManager <BillTariff> >()) { var filter = string.Format( "operation2contractid_r = {0} and TO_DATE('{1}','YYYY.MM.DD') >= tariffdatefrom and TO_DATE('{1}','YYYY.MM.DD') < tariffdatetill", Source.Operation2ContractID, ((DateTime)date).ToString("yyyy.MM.dd")); var values = mgrTariff.GetFiltered(filter).ToArray(); if (values.Length == 1) { price = values[0].Value; } } } engine.Variables.Add("PRICE", price); //кол-во double count; if (!formulaCountStr.IsNullOrEmptyAfterTrim()) { try { if (!double.TryParse(engine.Evaluate(formulaCountStr).ToString(), out count)) { count = 0; } } catch (Exception) { count = 0; } } else { count = DefaultCalcCount; } Source.WorkActDetailCount = count; //коэффициент double factor; if (!formulaFactorStr.IsNullOrEmptyAfterTrim()) { try { if (!double.TryParse(engine.Evaluate(formulaFactorStr).ToString(), out factor)) { factor = 0; } } catch (Exception) { factor = 0; } } else { factor = DefaultCalcFactor; } Source.WorkActDetailMulti = factor; //сумма if (!Source.IsEnabledTotalSum) { double summ = 0; if (!formulaSummStr.IsNullOrEmptyAfterTrim()) { try { if (!double.TryParse(engine.Evaluate(formulaSummStr).ToString(), out summ)) { summ = 0; } } catch (Exception) { summ = 0; } } Source.WorkActDetailTotalSum = summ; } } }
/// <summary> /// Parses a CalDav response XML into a list of CalDavElements. /// </summary> /// <param name="ResponseXmlDoc">XML to parse.</param> /// <returns>All CalDavElements contained in the Xml.</returns> public static List <CalDavElement> Parse(XmlDocument ResponseXmlDoc) { List <CalDavElement> allElements = new List <CalDavElement>(); if (ResponseXmlDoc.DocumentElement != null) { foreach (XmlNode xnode in ResponseXmlDoc.DocumentElement) { CalDavElement myElement = new CalDavElement(); if (xnode.SelectSingleNode("*[local-name()='href']") != null) { myElement.Url = xnode.SelectSingleNode("*[local-name()='href']").InnerText; } if (xnode.SelectSingleNode("*[local-name()='propstat']/*[local-name()='prop']/*[local-name()='getetag']") != null) { myElement.ETag = xnode.SelectSingleNode("*[local-name()='propstat']/*[local-name()='prop']/*[local-name()='getetag']").InnerText; } if (xnode.SelectSingleNode("*[local-name()='propstat']/*[local-name()='prop']/*[local-name()='calendar-data']") != null) { string[] parameters = xnode.SelectSingleNode("*[local-name()='propstat']/*[local-name()='prop']/*[local-name()='calendar-data']").InnerText.Split(new char[] { '\n' }); foreach (var item in parameters) { string[] specificParameter = item.Split(new char[] { ':' }, 2); if (specificParameter[0].ToUpper().StartsWith("UID") && specificParameter[1] != null) { myElement.Guid = specificParameter[1]; } if (specificParameter[0].ToUpper().StartsWith("SUMMARY") && specificParameter[1] != null) { myElement.Summary = specificParameter[1]; } if (specificParameter[0].ToUpper().StartsWith("DESCRIPTION") && specificParameter[1] != null) { myElement.Description = specificParameter[1]; } if (specificParameter[0].ToUpper().StartsWith("LAST-MODIFIED") && specificParameter[1] != null) { myElement.LastModified = StringToDateTimeConverter.Convert(specificParameter[1], -CaldavConnector.LASTMODIFIED_DATE_OFFSET); } if (specificParameter[0].ToUpper().StartsWith("LOCATION") && specificParameter[1] != null) { myElement.Location = specificParameter[1]; } if (specificParameter[0].ToUpper().StartsWith("DTSTART") && specificParameter[1] != null) { if (specificParameter[1].Contains("T")) { myElement.AllDayEvent = false; } else { myElement.AllDayEvent = true; } myElement.Start = StringToDateTimeConverter.Convert(specificParameter[1]); } if (specificParameter[0].ToUpper().StartsWith("DTEND") && specificParameter[1] != null) { myElement.End = StringToDateTimeConverter.Convert(specificParameter[1]); } } } allElements.Add(myElement); } } return(allElements); }
public IEnumerable <LoanInformation> Read(string file) { using (var doc = SpreadsheetDocument.Open(file, false)) { var workbookPart = doc.WorkbookPart; var worksheetPart = workbookPart.WorksheetParts.First(); var reader = OpenXmlReader.Create(worksheetPart); bool isFirst = true; while (reader.Read()) { if (reader.ElementType == typeof(Row)) { if (reader.IsEndElement) { continue; } if (isFirst) { isFirst = false; continue; } var children = reader.LoadCurrentElement().ChildElements; var loan = new LoanInformation(); foreach (Cell child in children.Where(x => x is Cell)) { var columnReference = Regex.Replace(child.CellReference.ToString(), @"[\d]", string.Empty); var cellContent = child.InnerText; switch (columnReference) { case "A": loan.Id = cellContent; continue; case "B": loan.IssueDate = StringToDateTimeConverter.Convert(cellContent); continue; case "C": loan.ClosingDate = StringToDateTimeConverter.Convert(cellContent); continue; case "D": loan.ListingDate = StringToDateTimeConverter.Convert(cellContent); continue; case "E": loan.Country = cellContent; continue; case "F": loan.LoanOriginator = cellContent; continue; case "G": loan.MintosRating = cellContent; continue; case "H": loan.LoanType = cellContent; continue; case "I": loan.LoanRate = Convert.ToDecimal(cellContent); continue; case "J": loan.Term = Convert.ToUInt16(cellContent); continue; case "K": loan.Collateral = YesNoToBooleanConverter.Convert(cellContent); continue; case "L": loan.InitialLtv = Convert.ToDecimal(cellContent); continue; case "M": loan.Ltv = Convert.ToDecimal(cellContent); continue; case "N": loan.LoanStatus = cellContent; continue; case "O": loan.BuybackReason = cellContent; continue; case "P": loan.InitialLoanAmount = Convert.ToDecimal(cellContent); continue; case "Q": loan.RemainingLoanAmount = Convert.ToDecimal(cellContent); continue; case "R": loan.Currency = cellContent; continue; case "S": loan.Buyback = YesNoToBooleanConverter.Convert(cellContent); continue; default: throw new ArgumentOutOfRangeException(nameof(columnReference)); } } yield return(loan); } } } }