public void ImportDataTable(System.Data.DataTable datatable)
        {
            Dictionary <string, ProductionProcess> processlist = new Dictionary <string, ProductionProcess>();

            foreach (DataRow row in datatable.Rows)
            {
                ProcessStep item = new ProcessStep();
                item.ObjectState = Repository.Pattern.Infrastructure.ObjectState.Added;
                ProductionProcess process = null;
                foreach (DataColumn col in datatable.Columns)
                {
                    var sourcefieldname = col.ColumnName;
                    var mapping         = _mappingservice.FindMapping("ProcessStep", sourcefieldname);
                    if (mapping != null && row[sourcefieldname] != DBNull.Value)
                    {
                        if (col.ColumnName == "工序名称")
                        {
                            string name = row[sourcefieldname].ToString();
                            process = this._processservice.Queryable().Where(x => x.Name == name).FirstOrDefault();
                            if (process == null)
                            {
                                if (!processlist.ContainsKey(name))
                                {
                                    process = new ProductionProcess()
                                    {
                                        Name = name
                                    };
                                    process.ObjectState = Repository.Pattern.Infrastructure.ObjectState.Added;
                                    processlist.Add(process.Name, process);
                                }
                                else
                                {
                                    process = processlist[name];
                                }
                            }
                            item.ProductionProcessId = process.Id;
                            item.ProductionProcess   = process;

                            process.ProcessSteps.Add(item);
                        }
                        else
                        {
                            Type         processsteptype = item.GetType();
                            PropertyInfo propertyInfo    = processsteptype.GetProperty(mapping.FieldName);
                            propertyInfo.SetValue(item, Convert.ChangeType(row[sourcefieldname], propertyInfo.PropertyType), null);
                        }
                    }
                }
            }
            this._processservice.InsertGraphRange(processlist.Values);

            //foreach (var item in processlist.Values)
            //    this._processservice.Insert(new ProductionProcess() { Name = item.Name });
            //this._processservice.InsertOrUpdateGraph(item);
        }
        public void ImportDataTable(System.Data.DataTable datatable)
        {
            foreach (DataRow row in datatable.Rows)
            {
                ProductionProcess item = new ProductionProcess();
                foreach (DataColumn col in datatable.Columns)
                {
                    var sourcefieldname = col.ColumnName;
                    var mapping         = _mappingservice.FindMapping("ProductionProcess", sourcefieldname);
                    if (mapping != null && row[sourcefieldname] != DBNull.Value)
                    {
                        Type productionprocesstype = item.GetType();
                        productionprocesstype.GetProperty(mapping.FieldName).SetValue(item, row[sourcefieldname]);
                    }
                }

                this.Insert(item);
            }
        }
        public void ImportDataTable(System.Data.DataTable datatable)
        {
            foreach (DataRow row in datatable.Rows)
            {
                DefectTracking item = new DefectTracking();
                foreach (DataColumn col in datatable.Columns)
                {
                    var sourcefieldname = col.ColumnName;
                    var mapping         = _mappingservice.FindMapping("DefectTracking", sourcefieldname);
                    if (mapping != null && row[sourcefieldname] != DBNull.Value)
                    {
                        Type defecttrackingtype = item.GetType();
                        defecttrackingtype.GetProperty(mapping.FieldName).SetValue(item, row[sourcefieldname]);
                    }
                }

                this.Insert(item);
            }
        }
        public void ImportDataTable(System.Data.DataTable datatable)
        {
            foreach (DataRow row in datatable.Rows)
            {
                WorkProcess item = new WorkProcess();
                foreach (DataColumn col in datatable.Columns)
                {
                    var sourcefieldname = col.ColumnName;
                    var mapping         = _mappingservice.FindMapping("WorkProcess", sourcefieldname);
                    if (mapping != null && row[sourcefieldname] != DBNull.Value)
                    {
                        Type         workprocesstype = item.GetType();
                        PropertyInfo propertyInfo    = workprocesstype.GetProperty(mapping.FieldName);
                        propertyInfo.SetValue(item, Convert.ChangeType(row[sourcefieldname], propertyInfo.PropertyType), null);
                        //workprocesstype.GetProperty(mapping.FieldName).SetValue(item, row[sourcefieldname]);
                    }
                }

                this.Insert(item);
            }
        }
Example #5
0
 public void ImportDataTable(System.Data.DataTable datatable)
 {
     foreach (DataRow row in datatable.Rows)
     {
         SKU item = new SKU();
         foreach (DataColumn col in datatable.Columns)
         {
             var sourcefieldname = col.ColumnName;
             var mapping         = _mappingservice.FindMapping("SKU", sourcefieldname);
             if (mapping != null && row[sourcefieldname] != DBNull.Value)
             {
                 Type skutype = item.GetType();
                 skutype.GetProperty(mapping.FieldName).SetValue(item, row[sourcefieldname]);
             }
         }
         if (Find(item.Sku) == null)
         {
             this.Insert(item);
         }
     }
 }
        public void ImportDataTable(System.Data.DataTable datatable)
        {
            List <BOMComponent> list        = new List <BOMComponent>();
            SKU          sku                = null;
            string       parentsku          = "";
            BOMComponent parentbomComponent = null;

            foreach (DataRow row in datatable.Rows)
            {
                BOMComponent item = new BOMComponent();
                item.ObjectState = Repository.Pattern.Infrastructure.ObjectState.Added;
                foreach (DataColumn col in datatable.Columns)
                {
                    var sourcefieldname = col.ColumnName;
                    var colval          = row[sourcefieldname].ToString();
                    if (sourcefieldname == "组件")
                    {
                        string strsku = row["组件"].ToString().Trim();
                        sku = _iskuservice.Queryable().Where(x => x.Sku == strsku).FirstOrDefault();
                        if (sku == null)
                        {
                            throw new Exception(string.Format("{0}没有维护SKU主数据", strsku));
                        }
                        item.ComponentSKU = sku.Sku;
                        item.SKUId        = sku.Id;
                        item.StockSKU     = sku.Sku;
                        item.SKUGroup     = sku.SKUGroup;
                    }
                    else if (sourcefieldname == "父件")
                    {
                        parentsku = row["父件"].ToString().Trim();
                        if (!string.IsNullOrEmpty(parentsku))
                        {
                            SKU psku = _iskuservice.Queryable().Where(x => x.Sku == parentsku).FirstOrDefault();
                            if (psku == null)
                            {
                                throw new Exception(string.Format("{0}没有维护SKU主数据", parentsku));
                            }
                            parentbomComponent     = list.Where(x => x.ComponentSKU == parentsku).FirstOrDefault();
                            item.ParentComponent   = parentbomComponent;
                            item.ParentComponentId = parentbomComponent.Id;
                        }
                    }
                    else if (sourcefieldname == "生产工序")
                    {
                        var process = _processservice.Queryable().Where(x => x.Name == colval).FirstOrDefault();
                        if (process != null)
                        {
                            item.ProductionProcessId = process.Id;
                        }
                    }
                    else
                    {
                        var mapping = _mappingservice.FindMapping("BOMComponent", sourcefieldname);
                        if (mapping != null && row[sourcefieldname] != DBNull.Value)
                        {
                            Type         bomcomponenttype = item.GetType();
                            PropertyInfo propertyInfo     = bomcomponenttype.GetProperty(mapping.FieldName);
                            propertyInfo.SetValue(item, Convert.ChangeType(row[sourcefieldname], propertyInfo.PropertyType), null);
                            //bomcomponenttype.GetProperty(mapping.FieldName).SetValue(item, row[sourcefieldname]);
                        }
                    }
                }

                list.Add(item);
            }
            this.InsertRange(list);
        }