예제 #1
0
            public bool AddColumn(int column_index, string column_name, string column_system_type, bool column_require)
            {
                bool result = false;

                if (_columns != null)
                {
                    if (!_columns.Contains(column_name))
                    {
                        ImportColumn _column = new ImportColumn(column_index, column_name, column_system_type);
                        if (_column != null)
                        {
                            _column.IsColumnRequire = column_require;
                            _columns.Add(column_name, _column);
                            result = true;
                        }
                    }
                }
                else
                {
                    ImportColumn _column = ((ImportColumn)_columns[column_name]);
                    if (_column != null)
                    {
                        _column.ColumnIndex = column_index;
                        _column.ColumnName = column_name;
                        _column.ColumnSystemType = column_system_type;
                        result = true;
                    }
                }

                return result;
            }
예제 #2
0
            private string CheckValue(ref DataRow data_row, ref ImportColumn import_column, string value, ref string error_desc)
            {
                error_desc = string.Empty;

                string result = "";
                if (_import_table != null)
                {
                    ImportLog _log = _import_table.GetLog();
                    if ((import_column != null) && (_log != null))
                    {
                        if ((value.Length == 0) && (import_column.IsColumnRequire))
                        {
                            _log.Add(ref data_row, ImportLog.ErrorType.Error, _import_table.GetSheetName(), GetAssetPath(), GetAssetValue("SerialNumber"), import_column.ColumnName, "", "Value can't be empty.");
                        }
                        else
                        {
                            string _system_type = import_column.ColumnSystemType;

                            if (value.Length > 0)
                            {
                                switch (_system_type)
                                {
                                    case "System.Int16":
                                        try
                                        {
                                            Int16 _int16_value = Int16.Parse(value);
                                            result = value;
                                        }
                                        catch
                                        {
                                            if (import_column.IsColumnRequire)
                                                _log.Add(ref data_row, ImportLog.ErrorType.Error, _import_table.GetSheetName(), GetAssetPath(), GetAssetValue("SerialNumber"), import_column.ColumnName, value, "Required value can't convert to integer(Int16) value.");
                                            else
                                                _log.Add(ref data_row, ImportLog.ErrorType.Warning, _import_table.GetSheetName(), GetAssetPath(), GetAssetValue("SerialNumber"), import_column.ColumnName, value, "Value can't convert to integer(Int16) value.");
                                        };
                                        break;
                                    case "System.Int32":
                                        try
                                        {
                                            Int32 _int32_value = Int32.Parse(value);
                                            result = value;
                                        }
                                        catch
                                        {
                                            if (import_column.IsColumnRequire)
                                                _log.Add(ref data_row, ImportLog.ErrorType.Error, _import_table.GetSheetName(), GetAssetPath(), GetAssetValue("SerialNumber"), import_column.ColumnName, value, "Required value can't convert to integer(Int32) value.");
                                            else
                                                _log.Add(ref data_row, ImportLog.ErrorType.Warning, _import_table.GetSheetName(), GetAssetPath(), GetAssetValue("SerialNumber"), import_column.ColumnName, value, "Value can't convert to integer(Int32) value.");
                                        };
                                        break;
                                    case "System.Byte":
                                        try
                                        {
                                            Byte _int8_value = Byte.Parse(value);
                                            result = value;
                                        }
                                        catch
                                        {
                                            if (import_column.IsColumnRequire)
                                                _log.Add(ref data_row, ImportLog.ErrorType.Error, _import_table.GetSheetName(), GetAssetPath(), GetAssetValue("SerialNumber"), import_column.ColumnName, value, "Required value can't convert to integer(Int8) value.");
                                            else
                                                _log.Add(ref data_row, ImportLog.ErrorType.Warning, _import_table.GetSheetName(), GetAssetPath(), GetAssetValue("SerialNumber"), import_column.ColumnName, value, "Value can't convert to integer(Int8) value.");
                                        };
                                        break;
                                    case "System.Decimal":
                                        try
                                        {
                                            Decimal _decimal_value = Decimal.Parse(value);
                                            result = value;
                                        }
                                        catch
                                        {
                                            if (import_column.IsColumnRequire)
                                                _log.Add(ref data_row, ImportLog.ErrorType.Error, _import_table.GetSheetName(), GetAssetPath(), GetAssetValue("SerialNumber"), import_column.ColumnName, value, "Required value can't convert to decimal value.");
                                            else
                                                _log.Add(ref data_row, ImportLog.ErrorType.Warning, _import_table.GetSheetName(), GetAssetPath(), GetAssetValue("SerialNumber"), import_column.ColumnName, value, "Value can't convert to decimal value.");
                                        };
                                        break;
                                    case "System.String":
                                        result = value;
                                        break;
                                    case "System.Enum":
                                        result = value;
                                        if (value.Length > 0)
                                        {
                                            string _enums = import_column.ColumnEnumeration;
                                            if (_enums.Length > 0)
                                            {
                                                AssetTypeProperty _custom_property = new AssetTypeProperty();
                                                if (_custom_property != null)
                                                {
                                                    _custom_property.Enumeration = _enums;
                                                    string[] _array = _custom_property.EnumerationArray;
                                                    if (_array != null)
                                                    {
                                                        bool _is_exist = false;
                                                        for (int _array_index = 0; _array_index < _array.Length; _array_index++)
                                                        {
                                                            if (value == _array[_array_index])
                                                            {
                                                                _is_exist = true;
                                                                break;
                                                            };
                                                        };

                                                        if (!_is_exist)
                                                        {
                                                            error_desc = "value not exist in enumeration set.";
                                                            result = "";
                                                            //Now, supported auto creation undefined enum values.
                                                            //_log.Add(ref data_row, ImportLog.ErrorType.Warning, _import_table.GetSheetName(), GetAssetPath(), GetAssetValue("SerialNumber"), import_column.ColumnName, value, "Value not exist in enumeration set.");
                                                        };
                                                    };
                                                };
                                            };
                                        };
                                        break;
                                    case "System.DateTime":
                                        try
                                        {
                                            DateTime _datetime_value = DateTime.Parse(value);
                                            result = Functions.FormatSQLShortDateTime(_datetime_value);
                                            //result = value;
                                        }
                                        catch
                                        {
                                            if (import_column.IsColumnRequire)
                                                _log.Add(ref data_row, ImportLog.ErrorType.Error, _import_table.GetSheetName(), GetAssetPath(), GetAssetValue("SerialNumber"), import_column.ColumnName, value, "Required value can't convert to datetime value.");
                                            else
                                                _log.Add(ref data_row, ImportLog.ErrorType.Warning, _import_table.GetSheetName(), GetAssetPath(), GetAssetValue("SerialNumber"), import_column.ColumnName, value, "Value can't convert to datetime value.");
                                        };
                                        break;
                                };
                            };
                        };
                    };
                };

                return result;
            }
예제 #3
0
 /// <summary>
 /// Check trùng dữ liệu
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="entitiesInFile">thực thể được build từ Excel</param>
 /// <param name="entity">Thực thể</param>
 /// <param name="cellValue">Giá trị của cell lấy từ file Excel</param>
 /// <param name="importColumn">Thông tin cột import được lấy trong database</param>
 /// CreatedBy: NVMANH (15/05/2020)
 protected virtual void CheckDuplicateData <T>(List <T> entitiesInFile, T entity, object cellValue, ImportColumn importColumn) where T : BaseEntity
 {
     // Validate: kiểm tra trùng dữ liệu trong File Excel:
     if (importColumn.ColumnInsert == "CitizenIdentityNo" && cellValue != null)
     {
         var itemDuplicate = entitiesInFile.Where(item => item.GetType().GetProperty("CitizenIdentityNo").GetValue(item).ToString() == cellValue.ToString()).FirstOrDefault();
         if (itemDuplicate != null)
         {
             entity.GetType().GetProperty("ImportValidState").SetValue(entity, ImportValidState.DuplicateInFile);
             entity.ImportValidError.Add(string.Format(Resources.Error_ImportDataDuplicateInFile, itemDuplicate.GetType().GetProperty("FullName").GetValue(itemDuplicate).ToString()));
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Xử lý dữ liệu liên quan đến ngày/ tháng
        /// </summary>
        /// <param name="entity">Thực thế sẽ import vào Db</param>
        /// <param name="cellValue">Giá trị của cell</param>
        /// <param name="type">Kiểu dữ liệu</param>
        /// <param name="importColumn">Thông tin cột import được khai báo trong Db</param>
        /// <returns>giá trị ngày tháng được chuyển đổi tương ứng</returns>
        /// CreatedBy: NVMANH (25/05/2020)
        protected virtual DateTime?GetProcessDateTimeValue <T>(T entity, object cellValue, Type type, ImportColumn importColumn = null) where T : BaseEntity
        {
            DateTime?dateReturn = null;

            if (cellValue.GetType() == typeof(double))
            {
                return(DateTime.FromOADate((double)cellValue));
            }
            var dateString = cellValue.ToString();
            // Ngày tháng phải nhập theo định dạng (ngày/tháng/năm):
            // VD hợp lệ: [25.04.2017] [02.04.2017] [2.4.2017] [25/04/2017] [5/12/2017] [15/2/2017] [25-04-2017]  [6-10-2017]  [16-5-2017] [09/26/2000 12:00:00 AM]  [09/26/2000 12:00:00 PM]
            Regex dateValidRegex         = new Regex(@"^([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0]?[1-9]|[1][0-2])[./-]([0-9]{4}|[0-9]{2})$");
            Regex dateValidRegexWithTime = new Regex(@"^([0]?[1-9]|[1][0-2])[/]([0]?[1-9]|[1|2][0-9]|[3][0|1])[/]([0-9]{4}|[0-9]{2}) ([0]|[1])([0-9])[:]([0]|[1])([0-9])[:]([0]|[1])([0-9]) ([AM]|[PM])$");

            if (dateValidRegex.IsMatch(dateString))
            {
                var dateSplit = dateString.Split(new string[] { "/", ".", "-" }, StringSplitOptions.None);
                var day       = int.Parse(dateSplit[0]);
                var month     = int.Parse(dateSplit[1]);
                var year      = int.Parse(dateSplit[2]);
                dateReturn = new DateTime(year, month, day);
            }
            else if (dateValidRegexWithTime.IsMatch(dateString))
            {
                dateReturn = DateTime.Parse(dateString);
            }
            else if (DateTime.TryParse(cellValue.ToString(), out DateTime dateTime) == true)
            {
                dateReturn = dateTime;
            }
            else
            {
                entity.ImportValidState = ImportValidState.Invalid;
                entity.ImportValidError.Add(string.Format("Thông tin [{0}] không đúng định dạng.", importColumn.ColumnTitle));
            }
            return(dateReturn);
        }
예제 #5
0
        /// <summary>
        /// Xử lý dữ liệu với các cột được khai báo property có tham chiếu tới 1 table
        /// </summary>
        /// <param name="objectReferenceName">Tên bảng trong CSDL được tham chiếu đến</param>
        /// <param name="cellValue">Giá trị của cell</param>
        /// CreatedBy: NVMANH (12/12/2020)
        protected virtual void ProcessCellValueByDataTypeWhenTableReference <T>(dynamic entity, ref object cellValue, ImportColumn importColumn) where T : BaseEntity
        {
            var    value = cellValue.ToString().Trim();
            var    objectReferenceName = importColumn.ObjectReferenceName;
            var    columnInsert        = importColumn.ColumnInsert;
            object objectReference     = null;

            switch (objectReferenceName)
            {
            case "Nationality":
                var nationality = Nationalities.Where(n => n.NationalityName == value.ToString().Trim()).FirstOrDefault();
                if (nationality == null)
                {
                    cellValue = null;
                }
                else
                {
                    objectReference = nationality;
                    //var nationalityPropertyByColumnInsert = typeof(Nationality).GetProperty(columnInsert);
                    //if (nationalityPropertyByColumnInsert != null)
                    //    cellValue = nationalityPropertyByColumnInsert.GetValue(nationality);
                    SetCellValueByColumnInsertWhenTableReference(nationality, columnInsert, ref cellValue);
                    var nationalityIdProperty   = entity.GetType().GetProperty("NationalityId");
                    var nationalityCodeProperty = entity.GetType().GetProperty("NationalityCode");
                    var nationalityNameProperty = entity.GetType().GetProperty("NationalityName");

                    if (nationalityCodeProperty != null)
                    {
                        nationalityCodeProperty.SetValue(entity, nationality.NationalityCode);
                    }

                    if (nationalityNameProperty != null)
                    {
                        nationalityNameProperty.SetValue(entity, nationality.NationalityName);
                    }

                    if (nationalityIdProperty != null)
                    {
                        nationalityIdProperty.SetValue(entity, nationality.NationalityId);
                    }
                }
                break;

            case "Relation":
                var relation = Relations.Where(n => n.RelationName == value.ToString().Trim()).FirstOrDefault();
                if (relation == null)
                {
                    cellValue = null;
                }
                else
                {
                    objectReference = relation;
                    SetCellValueByColumnInsertWhenTableReference(relation, columnInsert, ref cellValue);

                    var relationIdProperty   = entity.GetType().GetProperty("RelationId");
                    var relationCodeProperty = entity.GetType().GetProperty("RelationCode");
                    var relationNameProperty = entity.GetType().GetProperty("RelationName");

                    if (relationIdProperty != null)
                    {
                        relationIdProperty.SetValue(entity, relation.RelationId);
                    }

                    if (relationCodeProperty != null)
                    {
                        relationCodeProperty.SetValue(entity, relation.RelationCode);
                    }

                    if (relationNameProperty != null)
                    {
                        relationNameProperty.SetValue(entity, relation.RelationName);
                    }
                }

                break;

            case "Ethnic":
                var ethnic = Ethnics.Where(n => n.EthnicName == value.ToString().Trim()).FirstOrDefault();
                if (ethnic == null)
                {
                    cellValue = null;
                }
                else
                {
                    objectReference = ethnic;
                    SetCellValueByColumnInsertWhenTableReference(ethnic, columnInsert, ref cellValue);

                    var ethnicIdProperty   = entity.GetType().GetProperty("EthnicId");
                    var ethnicCodeProperty = entity.GetType().GetProperty("EthnicCode");
                    var ethnicNameProperty = entity.GetType().GetProperty("EthnicName");

                    if (ethnicIdProperty != null)
                    {
                        ethnicIdProperty.SetValue(entity, ethnic.EthnicId);
                    }

                    if (ethnicCodeProperty != null)
                    {
                        ethnicCodeProperty.SetValue(entity, ethnic.EthnicCode);
                    }

                    if (ethnicNameProperty != null)
                    {
                        ethnicNameProperty.SetValue(entity, ethnic.EthnicName);
                    }
                }
                break;

            case "Position":
                var position = Positions.Where(n => n.PositionName.ToLower() == value.ToString().Trim().ToLower()).FirstOrDefault();
                // Nếu không có vị trí tương ứng thì thực hiện thêm mới vị trí này:
                if (position == null)
                {
                    position = new Position()
                    {
                        PositionId     = Guid.NewGuid(),
                        PositionName   = cellValue.ToString(),
                        OrganizationId = _importRepository.GetCurrentOrganization().OrganizationId,
                    };
                    // Thêm vào danh sách các vị trí sẽ thêm mới:
                    _newPossitons.Add(position);
                }

                objectReference = position;
                SetCellValueByColumnInsertWhenTableReference(position, columnInsert, ref cellValue);
                var positionIdProperty   = entity.GetType().GetProperty("PositionId");
                var positionCodeProperty = entity.GetType().GetProperty("PositionCode");

                if (positionIdProperty != null)
                {
                    positionIdProperty.SetValue(entity, position.PositionId);
                }

                if (positionCodeProperty != null)
                {
                    positionCodeProperty.SetValue(entity, position.PositionCode);
                }

                break;

            default:
                var listData         = _importRepository.GetListObjectByTableName(objectReferenceName).Result;
                var iDPropertyName   = String.Format("{0}Id", objectReferenceName);
                var namePropertyName = String.Format("{0}Name", objectReferenceName);
                var codePropertyName = String.Format("{0}Code", objectReferenceName);
                if (listData != null && listData.First().GetType().GetProperty(namePropertyName) != null)
                {
                    List <object> objectReferences = new List <object>();
                    // Tìm chính xác:
                    objectReference = listData.Where(e => e.GetType().GetProperty(namePropertyName).GetValue(e, null).ToString().ToLower() == value.ToLower()).FirstOrDefault();
                    // Tìm gần đúng:
                    if (objectReference == null)
                    {
                        objectReference = listData.Where(e =>
                                                         RemoveDiacritics(e.GetType().GetProperty(namePropertyName).GetValue(e, null).ToString()).Contains(RemoveDiacritics(value)) ||
                                                         RemoveDiacritics(value).Contains(RemoveDiacritics(e.GetType().GetProperty(namePropertyName).GetValue(e, null).ToString())))
                                          .FirstOrDefault();
                    }

                    if (objectReference == null)
                    {
                        (entity as BaseEntity).ImportValidState = ImportValidState.Invalid;
                        (entity as BaseEntity).ImportValidError.Add(String.Format(@"Thông tin [{0}] ('{1}') nhập trên tệp không tồn tại trên hệ thống.", importColumn.ColumnTitle, value));
                        return;
                    }
                    SetCellValueByColumnInsertWhenTableReference(objectReference, columnInsert, ref cellValue);

                    var idProperty   = typeof(T).GetProperty(iDPropertyName);
                    var codeProperty = typeof(T).GetProperty(codePropertyName);
                    var nameProperty = typeof(T).GetProperty(namePropertyName);

                    if (idProperty != null)
                    {
                        idProperty.SetValue(entity, objectReference.GetType().GetProperty(iDPropertyName).GetValue(objectReference));
                    }

                    if (codeProperty != null)
                    {
                        codeProperty.SetValue(entity, objectReference.GetType().GetProperty(codePropertyName).GetValue(objectReference));
                    }

                    if (nameProperty != null)
                    {
                        nameProperty.SetValue(entity, objectReference.GetType().GetProperty(namePropertyName).GetValue(objectReference));
                    }
                }
                break;
            }
            CustomAfterSetCellValueByColumnInsertWhenTableReference(entity, objectReference, columnInsert, ref cellValue);
        }
예제 #6
0
        /// <summary>
        /// Thực hiện xử lý giá trị của cell theo từng loại dữ liệu được khai báo
        /// </summary>
        /// <typeparam name="T">Type của thực thể (bắt buộc class của thực thể phải kế thừa class Base Entity)</typeparam>
        /// <param name="dataType">Kiểu dữ liệu (string, số, enum...) được khai báo trong cơ sở dữ liệu</param>
        /// <param name="cellValue">Giá trị lấy từ ô nhập trong File Excel</param>
        /// <param name="entity">Thực thể sẽ gán các giá trị từ cell sau khi xử lý xong</param>
        /// <param name="importColumnTemplate">Thông tin cột nhập khẩu được khai báo trong Database</param>
        /// CreatedBy: NVMANH (25/05/2020)
        protected virtual void ProcessCellValueByDataType <T>(DataType dataType, ref object cellValue, dynamic entity, ImportColumn importColumnTemplate) where T : BaseEntity
        {
            switch (dataType)
            {
            case DataType.Boolean:
                if (cellValue.ToString().ToLower() == "có")
                {
                    cellValue = 1;
                }
                else
                {
                    cellValue = 0;
                }
                break;

            // Xử lý nếu kiểu dữ liệu khai báo là kiểu Enum:
            case DataType.Enum:
                var enumName = importColumnTemplate.ObjectReferenceName;     // Enum khai báo trong Database
                // Kiểm tra xem có Enum nào có tên như được khai báo hay không, nếu không khai báo thì bỏ qua:
                // -> Nếu có thì thực hiện Lấy key từ Resource -> sau đó lấy giá trị và gán lại Property tương ứng"
                var enumNameStringContains = string.Format("MISA.ImportDemo.Core.Enumeration.{0}", enumName);
                var enumType = Type.GetType(enumNameStringContains);
                if (enumType == null)
                {
                    return;
                }

                // 1. Lấy key từ Resource:
                var resourceStringKeyContains = string.Format("Enum_{0}", enumName);
                var resourceKey = _enumUtility.GetResourceNameByValue(cellValue.ToString(), resourceStringKeyContains);
                // Nếu không có resource có giá trị tương ứng thì cảnh báo lỗi:
                if (resourceKey == null)
                {
                    entity.ImportValidError.Add(string.Format("Thông tin [{0}] nhập không chính xác.", importColumnTemplate.ColumnTitle));
                    return;
                }

                // 2. -> sau đó lấy giá trị và gán lại Property tương ứng"
                var enumKey   = resourceKey.Replace(resourceStringKeyContains + "_", string.Empty);
                var enumValue = (int)Enum.Parse(enumType, enumKey);
                cellValue = enumValue;
                CustomAfterSetCellValueByColumnInsertWhenEnumReference(entity, enumType, importColumnTemplate.ColumnInsert, ref cellValue);
                break;

            case DataType.ReferenceTable:
                ProcessCellValueByDataTypeWhenTableReference <T>(entity, ref cellValue, importColumnTemplate);
                break;

            default:
                if (importColumnTemplate.ColumnInsert == null)
                {
                    return;
                }

                // Nếu không có property tương ứng với cột mapping đã khai báo -> bỏ qua và duyệt cell tiếp theo
                var property = entity.GetType().GetProperty(importColumnTemplate.ColumnInsert);
                if (property == null)
                {
                    return;
                }

                var propertyType = property.PropertyType;
                entity.HasPropertyValueImport = true;
                if (cellValue == null || cellValue is DBNull)
                {
                    break;
                }
                else
                {
                    if (propertyType == typeof(string))
                    {
                        cellValue = cellValue.ToString().Trim();
                        if (importColumnTemplate.ColumnInsert == "FullName")
                        {
                            var fullNames = new List <string>(cellValue.ToString().Split(" "));
                            var count     = fullNames.Count();
                            var firstName = string.Empty;
                            var lastName  = fullNames[count - 1].ToString();
                            fullNames.RemoveAt(count - 1);
                            foreach (var item in fullNames)
                            {
                                firstName = string.Format("{0} {1}", firstName, item);
                            }
                            var fNameProperty    = entity.GetType().GetProperty("FirstName");
                            var lastNameProperty = entity.GetType().GetProperty("LastName");
                            if (fNameProperty != null)
                            {
                                fNameProperty.SetValue(entity, firstName.Trim());
                            }
                            if (lastNameProperty != null)
                            {
                                lastNameProperty.SetValue(entity, lastName.Trim());
                            }
                        }
                    }
                    else if (propertyType == typeof(ulong) || propertyType == typeof(ulong?))
                    {
                        cellValue = Convert.ToUInt64(cellValue.ToString() == "Có" ? 1 : 0);
                    }
                    else if (propertyType == typeof(Decimal) || propertyType == typeof(Decimal?))
                    {
                        cellValue = Convert.ToDecimal(cellValue);
                    }
                    else if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?))
                    {
                        cellValue = GetProcessDateTimeValue(entity, cellValue, propertyType, importColumnTemplate);
                    }
                    else
                    {
                        cellValue = Convert.ChangeType(cellValue, Nullable.GetUnderlyingType(propertyType));
                    }
                }
                break;
            }
        }
예제 #7
0
 /// <summary>
 /// Check trùng dữ liệu trong File Excel và trong database, dựa vào số chứng minh thư
 /// </summary>
 /// <typeparam name="T">Generic Type</typeparam>
 /// <param name="entitiesInFile">Danh sách các đối tượng được build từ tệp nhập khẩu</param>
 /// <param name="entity">thực thể hiện tại</param>
 /// <param name="cellValue">Giá trị nhập trong ô excel đang đọc</param>
 /// <param name="importColumn">Thông tin cột nhập khẩu (tiêu đề cột, kiểu giá trị....)</param>
 /// CreatedBy: NVMANH (19/06/2020)
 protected override void CheckDuplicateData <T>(List <T> entitiesInFile, T entity, object cellValue, ImportColumn importColumn)
 {
     if (entity is Employee)
     {
         var newEmployee = entity as Employee;
         // Validate: kiểm tra trùng dữ liệu trong File Excel và trong Database: check theo số CMTND
         if (importColumn.ColumnInsert == "CitizenIdentityNo" && cellValue != null)
         {
             var citizenIndentityNo = cellValue.ToString().Trim();
             // Check trong File
             var itemDuplicate = entitiesInFile.Where(item => (item.GetType().GetProperty("CitizenIdentityNo").GetValue(item) ?? string.Empty).ToString() == citizenIndentityNo).FirstOrDefault();
             if (itemDuplicate != null)
             {
                 entity.ImportValidState        = ImportValidState.DuplicateInFile;
                 itemDuplicate.ImportValidState = ImportValidState.DuplicateInFile;
                 entity.ImportValidError.Add(string.Format(Resources.Error_ImportDataDuplicateInFile, entity.GetType().GetProperty("FullName").GetValue(entity).ToString()));
                 itemDuplicate.ImportValidError.Add(string.Format(Resources.Error_ImportDataDuplicateInFile, itemDuplicate.GetType().GetProperty("FullName").GetValue(itemDuplicate).ToString()));
             }
             // Check trong Db:
             var itemDuplicateInDb = EntitiesFromDatabase.Where(item => (item.GetType().GetProperty("CitizenIdentityNo").GetValue(item) ?? string.Empty).ToString() == citizenIndentityNo).Cast <T>().FirstOrDefault();
             if (itemDuplicateInDb != null)
             {
                 entity.ImportValidState            = ImportValidState.DuplicateInDb;
                 newEmployee.EmployeeId             = (Guid)itemDuplicateInDb.GetType().GetProperty("EmployeeId").GetValue(itemDuplicateInDb);
                 itemDuplicateInDb.ImportValidState = ImportValidState.DuplicateInFile;
                 entity.ImportValidError.Add(string.Format(Resources.Error_ImportDataDuplicateInDatabase, entity.GetType().GetProperty("FullName").GetValue(entity).ToString()));
                 itemDuplicateInDb.ImportValidError.Add(string.Format(Resources.Error_ImportDataDuplicateInDatabase, itemDuplicateInDb.GetType().GetProperty("FullName").GetValue(itemDuplicateInDb).ToString()));
             }
         }
     }
     else
     {
         base.CheckDuplicateData(entitiesInFile, entity, cellValue, importColumn);
     }
 }
예제 #8
0
        /// <summary>
        /// Xử lý dữ liệu liên quan đến ngày/ tháng
        /// </summary>
        /// <param name="entity">Thực thế sẽ import vào Db</param>
        /// <param name="cellValue">Giá trị của cell</param>
        /// <param name="type">Kiểu dữ liệu</param>
        /// <param name="importColumn">Thông tin cột import được khai báo trong Db</param>
        /// <returns>giá trị ngày tháng được chuyển đổi tương ứng</returns>
        /// CreatedBy: NVMANH (25/05/2020)
        protected override DateTime?GetProcessDateTimeValue <T>(T entity, object cellValue, Type type, ImportColumn importColumn = null)
        {
            if (entity is EmployeeFamily && importColumn.ColumnInsert == "DateOfBirth")
            {
                var      empFamily          = entity as EmployeeFamily;
                var      dateDisplaySetting = (DateDisplaySetting)empFamily.DobdisplaySetting;
                DateTime?dateOfBirth        = null;
                var      dateString         = cellValue.ToString();
                switch (dateDisplaySetting)
                {
                case DateDisplaySetting.mmyyyy:
                    Regex dateValidRegex = new Regex(@"^([0]?[1-9]|[1][0-2])[./-]([0-9]{4})$");
                    if (dateValidRegex.IsMatch(dateString))
                    {
                        var dateSplit = dateString.Split(new string[] { "/", ".", "-" }, StringSplitOptions.None);
                        var month     = int.Parse(dateSplit[0]);
                        var year      = int.Parse(dateSplit[1]);
                        dateOfBirth = new DateTime(year, month, 1);
                    }
                    else
                    {
                        dateOfBirth = base.GetProcessDateTimeValue(entity, cellValue, type, importColumn);
                        //entity.ImportValidState = ImportValidState.Invalid;
                        //entity.ImportValidError.Add(string.Format("Thông tin [{0}] không đúng định dạng.", importColumn.ColumnTitle));
                    }
                    break;

                case DateDisplaySetting.yyyy:
                    Regex yearValidRegex = new Regex(@"^([0-9]{4})$");
                    if (yearValidRegex.IsMatch(dateString))
                    {
                        var year = int.Parse(dateString);
                        dateOfBirth = new DateTime(year, 1, 1);
                    }
                    else
                    {
                        dateOfBirth = base.GetProcessDateTimeValue(entity, cellValue, type, importColumn);
                        //entity.ImportValidState = ImportValidState.Invalid;
                        //entity.ImportValidError.Add(string.Format("Thông tin [{0}] không đúng định dạng.", importColumn.ColumnTitle));
                    }
                    break;

                default:
                    dateOfBirth = base.GetProcessDateTimeValue(entity, cellValue, type, importColumn);
                    break;
                }
                return(dateOfBirth);
            }
            else
            {
                return(base.GetProcessDateTimeValue(entity, cellValue, type, importColumn));
            }
        }
예제 #9
0
        /// <summary>
        /// Xử lý đặc thù với các thông tin lấy trên tệp nhập khẩu ở dạng lựa chọn thông tin ở 1 danh mục trong database
        /// </summary>
        /// <typeparam name="T">kiểu của thực thể đang build</typeparam>
        /// <param name="entity">thực thể</param>
        /// <param name="cellValue">giá trị của cell đọc được trên tệp</param>
        /// <param name="importColumn">thông tin cột nhập khẩu hiện tại được khai báo trong databse</param>
        /// OverriderBy: NVMANH (15/12/2020)
        protected override void ProcessCellValueByDataTypeWhenTableReference <T>(object entity, ref object cellValue, ImportColumn importColumn)
        {
            var value = cellValue;

            if (importColumn.ObjectReferenceName == "ParticipationForm" && entity is Employee)
            {
                //var listData = _importRepository.GetListObjectByTableName("ParticipationForm").Result.Cast<ParticipationForm>().ToList();
                //var par = listData.Where(e => e.Rate == decimal.Parse(value.ToString().Replace(",","."))).FirstOrDefault();
                //if (par == null)
                //    return;
                //(entity as Employee).ParticipationFormId = par.ParticipationFormId;
                //(entity as Employee).ParticipationFormName = par.ParticipationFormName;
            }
            else
            {
                base.ProcessCellValueByDataTypeWhenTableReference <T>(entity, ref cellValue, importColumn);
            }
        }