예제 #1
0
 protected virtual void OnValidateSetAutoIncrement(bool value)
 {
     if (value == true && this.Table != null && this.Table.Rows.Count > 0 && CremaDataTypeUtility.CanUseAutoIncrement(this.DataType) == false)
     {
         throw new ArgumentException($"{this.DataType.GetTypeName()} 은 {nameof(AutoIncrement)}가 지원되지 않는 타입입니다.");
     }
 }
예제 #2
0
 private object GetDefaultValue(ColumnInfo columnInfo)
 {
     if (columnInfo.DefaultValue != null && CremaDataTypeUtility.IsBaseType(columnInfo.DataType) == true)
     {
         var type = CremaDataTypeUtility.GetType(columnInfo.DataType);
         return(CremaConvert.ChangeType(columnInfo.DefaultValue, type));
     }
     return(columnInfo.DefaultValue);
 }
예제 #3
0
 private void ValidateConstructor(string columnName, Type dataType)
 {
     if (string.IsNullOrEmpty(columnName) == false)
     {
         CremaDataColumn.ValidateColumnName(columnName);
     }
     if (CremaDataTypeUtility.IsBaseType(dataType) == false)
     {
         throw new ArgumentException(string.Format(Resources.Exception_TypeCannotBeUsed_Format, dataType.Name), nameof(dataType));
     }
 }
예제 #4
0
 protected virtual void OnValidateAddColumn(string columnName, Type type)
 {
     this.OnValidateAddColumn(columnName);
     if (type == null)
     {
         throw new ArgumentNullException(nameof(type));
     }
     if (CremaDataTypeUtility.IsBaseType(type) == false)
     {
         throw new ArgumentException(string.Format(Resources.Exception_TypeCannotBeUsed_Format, type.Name), nameof(type));
     }
 }
예제 #5
0
 private static void ValidateChangeType(object value, Type dataType)
 {
     if (value == null)
     {
         throw new ArgumentNullException(nameof(value));
     }
     if (dataType == null)
     {
         throw new ArgumentNullException(nameof(dataType));
     }
     if (CremaDataTypeUtility.IsBaseType(dataType) == false)
     {
         throw new ArgumentException(string.Format(Resources.Exception_TypeCannotBeUsed_Format, dataType.Name), nameof(dataType));
     }
 }
예제 #6
0
 private void ValidateConstructor(string attributeName, Type dataType)
 {
     if (string.IsNullOrEmpty(attributeName) == false)
     {
         InternalAttribute.ValidateAttributeName(attributeName);
     }
     if (dataType == null)
     {
         throw new ArgumentNullException(nameof(dataType));
     }
     if (CremaDataTypeUtility.IsBaseType(dataType) == false)
     {
         throw new ArgumentException(string.Format(Resources.Exception_TypeCannotBeUsed_Format, dataType.Name), nameof(dataType));
     }
 }
예제 #7
0
        protected virtual void OnValidateSetDataTypeName(string value)
        {
            var dataSet = this.Table?.DataSet;

            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (value is string == false)
            {
                throw new ArgumentException(nameof(value));
            }

            if (dataSet == null && CremaDataTypeUtility.IsBaseType(value) == false)
            {
                if (NameValidator.VerifyItemPath(value) == false)
                {
                    throw new ArgumentException(string.Format(Resources.Exception_TypeCannotBeUsed_Format, value), nameof(value));
                }
            }
            if (CremaDataTypeUtility.IsBaseType(value) == true)
            {
                this.OnValidateSetDataType(CremaDataTypeUtility.GetType(value));
            }

            if (dataSet != null && CremaDataTypeUtility.IsBaseType(value) == false)
            {
                if (NameValidator.VerifyItemPath(value) == false)
                {
                    if (InternalDataSet.ContainsType(this.Table?.DataSet, value) == false)
                    {
                        throw new ArgumentException(string.Format(Resources.Exception_TypeCannotBeUsed_Format, value), nameof(value));
                    }
                    var dataType = InternalDataSet.GetType(this.Table?.DataSet, value);
                    this.OnValidateSetCremaType(dataType);
                }
                else
                {
                    var itemName = new ItemName(value);
                    if (InternalDataSet.ContainsType(this.Table?.DataSet, itemName.Name, itemName.CategoryPath) == false)
                    {
                        throw new ArgumentException(string.Format(Resources.Exception_TypeCannotBeUsed_Format, value), nameof(value));
                    }
                    var dataType = InternalDataSet.GetType(this.Table?.DataSet, itemName.Name, itemName.CategoryPath);
                    this.OnValidateSetCremaType(dataType);
                }
            }
        }
예제 #8
0
 public override void EndLoadData()
 {
     base.EndLoadData();
     if (this.autoIncrements != null)
     {
         for (var i = 0; i < this.autoIncrements.Length; i++)
         {
             var column = this.Columns[i];
             if (this.autoIncrements[i] == false || CremaDataTypeUtility.CanUseAutoIncrement(column.DataType) == false || column.DefaultValue != DBNull.Value)
             {
                 continue;
             }
             column.AutoIncrement = true;
         }
         this.autoIncrements = null;
     }
 }
예제 #9
0
        protected virtual void OnValidateSetDataType(Type value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (CremaDataTypeUtility.IsBaseType(value) == false)
            {
                throw new ArgumentException(string.Format(Resources.Exception_TypeCannotBeUsed_Format, value.Name), nameof(value));
            }
            if (this.Table != null && this.Table.Rows.Count > 0 && this.AutoIncrement == true && CremaDataTypeUtility.CanUseAutoIncrement(value) == false)
            {
                throw new ArgumentException($"AutoIncrement 를 사용중인 열에서 '{value.GetTypeName()}' 타입은 사용할 수 없습니다.");
            }

            var index = 0;

            if (this.Table != null)
            {
                foreach (DataRow item in this.Table.Rows)
                {
                    var field = item[this];
                    if (field == DBNull.Value)
                    {
                        continue;
                    }
                    if (CremaConvert.VerifyChangeType(field, value) == false)
                    {
                        throw new FormatException($"{index}번째 값 \"{field}\"은(는) {value.GetTypeName()} 타입으로 변환할 수 없습니다.");
                    }
                    index++;
                }
            }

            if (this.DefaultValue != DBNull.Value && CremaConvert.VerifyChangeType(this.DefaultValue, value) == false)
            {
                throw new FormatException($"기본값 \"{this.DefaultValue}\"은(는) {value.GetTypeName()} 타입으로 변환할 수 없습니다.");
            }
        }
예제 #10
0
        public static void ValidateSetDataTypeName(InternalDataSet dataSet, string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (value is string == false)
            {
                throw new ArgumentException(nameof(value));
            }

            if (dataSet == null && CremaDataTypeUtility.IsBaseType(value) == false)
            {
                if (NameValidator.VerifyItemPath(value) == false)
                {
                    throw new ArgumentException(string.Format(Resources.Exception_TypeCannotBeUsed_Format, value), nameof(value));
                }
            }

            if (dataSet != null && CremaDataTypeUtility.IsBaseType(value) == false)
            {
                if (NameValidator.VerifyItemPath(value) == false)
                {
                    if (InternalDataSet.ContainsType(dataSet, value) == false)
                    {
                        throw new ArgumentException(string.Format(Resources.Exception_TypeCannotBeUsed_Format, value), nameof(value));
                    }
                }
                else
                {
                    var itemName = new ItemName(value);
                    if (InternalDataSet.ContainsType(dataSet, itemName.Name, itemName.CategoryPath) == false)
                    {
                        throw new ArgumentException(string.Format(Resources.Exception_TypeCannotBeUsed_Format, value), nameof(value));
                    }
                }
            }
        }
예제 #11
0
        public static bool VerifyChangeType(object value, Type dataType)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (dataType == null)
            {
                throw new ArgumentNullException(nameof(dataType));
            }
            if (CremaDataTypeUtility.IsBaseType(dataType) == false)
            {
                throw new ArgumentException(string.Format(Resources.Exception_TypeCannotBeUsed_Format, dataType.Name), nameof(dataType));
            }

            if (value.GetType() == dataType)
            {
                return(true);
            }

            var textValue = string.Empty;

            if (value is DateTime)
            {
                textValue = ((DateTime)value).ToOADate().ToString();
            }
            else if (value is TimeSpan)
            {
                textValue = ((TimeSpan)value).Ticks.ToString();
            }
            else if (value is float)
            {
                textValue = ((float)value).ToString("R");
            }
            else if (value is double)
            {
                textValue = ((double)value).ToString("R");
            }
            else
            {
                textValue = value.ToString();
            }

            if (dataType == typeof(bool))
            {
                return(bool.TryParse(textValue, out bool v));
            }
            else if (dataType == typeof(float))
            {
                return(float.TryParse(textValue, out float v));
            }
            else if (dataType == typeof(double))
            {
                return(double.TryParse(textValue, out double v));
            }
            else if (dataType == typeof(sbyte))
            {
                return(sbyte.TryParse(textValue, out sbyte v));
            }
            else if (dataType == typeof(byte))
            {
                return(byte.TryParse(textValue, out byte v));
            }
            else if (dataType == typeof(short))
            {
                return(short.TryParse(textValue, out short v));
            }
            else if (dataType == typeof(ushort))
            {
                return(ushort.TryParse(textValue, out ushort v));
            }
            else if (dataType == typeof(int))
            {
                return(int.TryParse(textValue, out int v));
            }
            else if (dataType == typeof(uint))
            {
                return(uint.TryParse(textValue, out uint v));
            }
            else if (dataType == typeof(long))
            {
                return(long.TryParse(textValue, out long v));
            }
            else if (dataType == typeof(ulong))
            {
                return(ulong.TryParse(textValue, out ulong v));
            }
            else if (dataType == typeof(DateTime))
            {
                try
                {
                    if (double.TryParse(textValue, out double l) == true)
                    {
                        DateTime.FromOADate(l);
                        return(true);
                    }
                    return(DateTime.TryParse(textValue, out DateTime s));
                }
                catch
                {
                    return(false);
                }
            }
            else if (dataType == typeof(TimeSpan))
            {
                try
                {
                    if (double.TryParse(textValue, out double l) == true)
                    {
                        if (l == TimeSpan.MinValue.TotalSeconds || l == TimeSpan.MaxValue.TotalSeconds)
                        {
                            return(true);
                        }
                        TimeSpan.FromSeconds(l);
                        return(true);
                    }
                    return(TimeSpan.TryParse(textValue, out TimeSpan s));
                }
                catch
                {
                    return(false);
                }
            }
            else if (dataType == typeof(Guid))
            {
                return(Guid.TryParse(textValue, out Guid v));
            }

            return(true);
        }