Esempio n. 1
0
        public void ImportDataTable(System.Data.DataTable datatable)
        {
            foreach (DataRow row in datatable.Rows)
            {
                CodeItem item    = new CodeItem();
                var      mapping = _mappingservice.Queryable().Where(x => x.EntitySetName == "CodeItem" && x.IsEnabled == true).ToList();

                foreach (var field in mapping)
                {
                    var defval    = field.DefaultValue;
                    var contation = datatable.Columns.Contains((field.SourceFieldName == null ? "" : field.SourceFieldName));
                    if (contation && row[field.SourceFieldName] != DBNull.Value)
                    {
                        Type         codeitemtype = item.GetType();
                        PropertyInfo propertyInfo = codeitemtype.GetProperty(field.FieldName);
                        propertyInfo.SetValue(item, Convert.ChangeType(row[field.SourceFieldName], propertyInfo.PropertyType), null);
                    }
                    else if (!string.IsNullOrEmpty(defval))
                    {
                        Type         codeitemtype = item.GetType();
                        PropertyInfo propertyInfo = codeitemtype.GetProperty(field.FieldName);
                        if (defval.ToLower() == "now" && propertyInfo.PropertyType == typeof(DateTime))
                        {
                            propertyInfo.SetValue(item, Convert.ChangeType(DateTime.Now, propertyInfo.PropertyType), null);
                        }
                        else
                        {
                            propertyInfo.SetValue(item, Convert.ChangeType(defval, propertyInfo.PropertyType), null);
                        }
                    }
                }

                this.Insert(item);
            }
        }
Esempio n. 2
0
        public void ImportDataTable(System.Data.DataTable datatable)
        {
            foreach (DataRow row in datatable.Rows)
            {
                PgaSku item    = new PgaSku();
                var    mapping = _mappingservice.Queryable().Where(x => x.EntitySetName == "PgaSku").ToList();

                foreach (var field in mapping)
                {
                    var defval    = field.DefaultValue;
                    var contation = datatable.Columns.Contains((field.SourceFieldName == null ? "" : field.SourceFieldName));
                    if (contation && row[field.SourceFieldName] != DBNull.Value)
                    {
                        Type         pgaskutype   = item.GetType();
                        PropertyInfo propertyInfo = pgaskutype.GetProperty(field.FieldName);
                        propertyInfo.SetValue(item, Convert.ChangeType(row[field.SourceFieldName], propertyInfo.PropertyType), null);
                    }
                    else if (!string.IsNullOrEmpty(defval))
                    {
                        Type         pgaskutype   = item.GetType();
                        PropertyInfo propertyInfo = pgaskutype.GetProperty(field.FieldName);
                        propertyInfo.SetValue(item, Convert.ChangeType(defval, propertyInfo.PropertyType), null);
                    }
                }

                this.Insert(item);
            }
        }
Esempio n. 3
0
        public void ImportDataTable(System.Data.DataTable datatable)
        {
            foreach (DataRow row in datatable.Rows)
            {
                var item          = new MenuItem();
                var mapping       = _mappingservice.Queryable().Where(x => x.EntitySetName == "MenuItem" && ((x.IsEnabled == true) || (x.IsEnabled == false && !(x.DefaultValue == null || x.DefaultValue.Equals(string.Empty))))).ToList();
                var requiredfield = mapping.Where(x => x.IsRequired == true).FirstOrDefault()?.SourceFieldName;
                if (requiredfield != null && !row.IsNull(requiredfield) && row[requiredfield] != DBNull.Value && Convert.ToString(row[requiredfield]).Trim() != string.Empty)
                {
                    foreach (var field in mapping)
                    {
                        var defval    = field.DefaultValue;
                        var contation = datatable.Columns.Contains((field.SourceFieldName == null ? "" : field.SourceFieldName));
                        if (contation && !row.IsNull(field.SourceFieldName) && row[field.SourceFieldName] != DBNull.Value && row[field.SourceFieldName].ToString() != string.Empty)
                        {
                            var menuitemtype = item.GetType();
                            var propertyInfo = menuitemtype.GetProperty(field.FieldName);
                            //关联外键查询获取Id
                            switch (field.FieldName)
                            {
                            case "ParentId":
                                var title    = row[field.SourceFieldName].ToString();
                                var parentid = getParentIdByTitle(title);
                                propertyInfo.SetValue(item, Convert.ChangeType(parentid, propertyInfo.PropertyType), null);
                                break;

                            default:
                                var safetype  = Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType;
                                var safeValue = (row[field.SourceFieldName] == null) ? null : Convert.ChangeType(row[field.SourceFieldName], safetype);
                                propertyInfo.SetValue(item, safeValue, null);
                                break;
                            }
                        }
                        else if (!string.IsNullOrEmpty(defval))
                        {
                            var          menuitemtype = item.GetType();
                            PropertyInfo propertyInfo = menuitemtype.GetProperty(field.FieldName);
                            if (defval.ToLower() == "now" && propertyInfo.PropertyType == typeof(DateTime))
                            {
                                propertyInfo.SetValue(item, Convert.ChangeType(DateTime.Now, propertyInfo.PropertyType), null);
                            }
                            else
                            {
                                var safetype  = Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType;
                                var safeValue = Convert.ChangeType(defval, safetype);
                                propertyInfo.SetValue(item, safeValue, null);
                            }
                        }
                    }
                    Insert(item);
                }
            }
        }
Esempio n. 4
0
        public void ImportDataTable(System.Data.DataTable datatable)
        {
            foreach (DataRow row in datatable.Rows)
            {
                Employee item          = new Employee();
                var      mapping       = _mappingservice.Queryable().Where(x => x.EntitySetName == "Employee" && ((x.IsEnabled == true) || (x.IsEnabled == false && !(x.DefaultValue == null || x.DefaultValue.Equals(string.Empty))))).ToList();
                var      requiredfield = mapping.Where(x => x.IsRequired == true).FirstOrDefault()?.SourceFieldName;
                if (requiredfield != null && !row.IsNull(requiredfield) && row[requiredfield] != DBNull.Value && Convert.ToString(row[requiredfield]).Trim() != string.Empty)
                {
                    foreach (var field in mapping)
                    {
                        var defval    = field.DefaultValue;
                        var contation = datatable.Columns.Contains((field.SourceFieldName == null ? "" : field.SourceFieldName));
                        if (contation && !row.IsNull(field.SourceFieldName) && row[field.SourceFieldName] != DBNull.Value)
                        {
                            Type         employeetype = item.GetType();
                            PropertyInfo propertyInfo = employeetype.GetProperty(field.FieldName);
                            switch (field.FieldName)
                            {
                            case "CompanyId":
                                var name      = row[field.SourceFieldName].ToString();
                                var companyid = this.getCompanyIdByName(name);
                                propertyInfo.SetValue(item, Convert.ChangeType(companyid, propertyInfo.PropertyType), null);
                                break;

                            default:
                                propertyInfo.SetValue(item, Convert.ChangeType(row[field.SourceFieldName], propertyInfo.PropertyType), null);
                                break;
                            }
                        }
                        else if (!string.IsNullOrEmpty(defval))
                        {
                            Type         employeetype = item.GetType();
                            PropertyInfo propertyInfo = employeetype.GetProperty(field.FieldName);
                            if (defval.ToLower() == "now" && propertyInfo.PropertyType == typeof(DateTime))
                            {
                                propertyInfo.SetValue(item, Convert.ChangeType(DateTime.Now, propertyInfo.PropertyType), null);
                            }
                            else
                            {
                                propertyInfo.SetValue(item, Convert.ChangeType(defval, propertyInfo.PropertyType), null);
                            }
                        }
                    }
                    this.Insert(item);
                }
            }
        }
Esempio n. 5
0
        public void ImportDataTable(System.Data.DataTable datatable)
        {
            var batchId = "K" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "001";

            foreach (DataRow row in datatable.Rows)
            {
                PgaKitting item    = new PgaKitting();
                var        mapping = _mappingservice.Queryable().Where(x => x.EntitySetName == "PgaKitting").ToList();
                item.KittingId = batchId;
                foreach (var field in mapping)
                {
                    var defval    = field.DefaultValue;
                    var contation = datatable.Columns.Contains((field.SourceFieldName == null ? "" : field.SourceFieldName));
                    if (contation && row[field.SourceFieldName] != DBNull.Value)
                    {
                        Type         pgakittingtype = item.GetType();
                        PropertyInfo propertyInfo   = pgakittingtype.GetProperty(field.FieldName);
                        propertyInfo.SetValue(item, Convert.ChangeType(row[field.SourceFieldName], propertyInfo.PropertyType), null);
                    }
                    else if (!string.IsNullOrEmpty(defval))
                    {
                        Type         pgakittingtype = item.GetType();
                        PropertyInfo propertyInfo   = pgakittingtype.GetProperty(field.FieldName);
                        if (defval.ToLower() == "now" && propertyInfo.PropertyType == typeof(DateTime))
                        {
                            propertyInfo.SetValue(item, Convert.ChangeType(DateTime.Now, propertyInfo.PropertyType), null);
                        }
                        else
                        {
                            propertyInfo.SetValue(item, Convert.ChangeType(defval, propertyInfo.PropertyType), null);
                        }
                    }
                }

                this.Insert(item);
            }
        }