コード例 #1
0
        /// <summary>
        /// Convert Field Value to Law Type
        /// </summary>
        private object ConvertFieldValueIntoLawType(string value, LawFieldTypeBEO fieldType, string format)
        {
            var          isErrorOnConversion = false;
            const string defaultDateFormat   = "ddMMyyyy"; //Currently no format used when data imported through Law Import, So using default format.

            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }
            switch (fieldType)
            {
            case LawFieldTypeBEO.Numeric:
                Int32 numericValue;
                if (Int32.TryParse(value, out numericValue))
                {
                    return(numericValue);
                }
                isErrorOnConversion = true;
                break;

            case LawFieldTypeBEO.DateTime:
                format = (!string.IsNullOrEmpty(format)
                        ? DateTimeUtility.GetLegitimateDateFormat(format)
                        : defaultDateFormat);
                DateTime date;
                DateTime.TryParseExact(value.Replace("/", string.Empty), format.Replace("/", string.Empty), CultureInfo.InvariantCulture, DateTimeStyles.None, out date);
                return(date);

            case LawFieldTypeBEO.String:
                return(value);
            }
            if (isErrorOnConversion)
            {
                throw new EVException().AddUsrMsg("Invalid data, field value not match with Law Field Type.");
            }
            return(null);
        }