Ejemplo n.º 1
0
        public void InsertOrUpdateFileImportRow(FileImportRowModel row)
        {
            FileImportRow tempRow = null;

            if (row.Id != 0)
            {
                tempRow = db.FindFileImportRow(row.CompanyId, row.UserId, row.Id);
                if (tempRow == null)
                {
                    row.Id = 0;
                }
            }
            if (row.Id == 0)
            {
                // New row
                tempRow = new FileImportRow {
                    CompanyId  = row.CompanyId,
                    UserId     = row.UserId,
                    ProductId  = row.ProductId,
                    SupplierId = row.SupplierId
                };
                db.InsertOrUpdateFileImportRow(tempRow);
                row.Id = tempRow.Id;

                foreach (var field in row.Fields)
                {
                    var tempField = new FileImportField {
                        CompanyId       = row.CompanyId,
                        FileImportRowId = tempRow.Id,
                        Value           = field.Value
                    };
                    db.InsertOrUpdateFileImportField(tempField, false);
                }
                db.SaveChanges();
            }
            else
            {
                // Update existing row
                tempRow.ErrorMessage = row.ErrorMessage;
                tempRow.ProductId    = row.ProductId;
                tempRow.SupplierId   = row.SupplierId;
                db.InsertOrUpdateFileImportRow(tempRow);

                int fldNo = 0;
                foreach (var field in tempRow.FileImportFields)
                {
                    field.Value = row.Fields[fldNo].Value;
                    fldNo++;
                }
                db.InsertOrUpdateFileImportRow(tempRow);
            }
        }
Ejemplo n.º 2
0
        private FileImportField getField(FileImportRow row, string fieldName)
        {
            FileImportField result = null;
            var             fields = row.FileImportFields.Cast <FileImportField>().ToList();

            int idx = findField(row, fieldName);

            if (idx != -1)
            {
                result = fields[idx];
            }
            return(result);
        }
Ejemplo n.º 3
0
        private FileImportField getField(FileImportRow row, string fieldName)
        {
            FileImportField result = null;
            var             fields = row.FileImportFields.Cast <FileImportField>().ToList();

            for (int i = 0; i < _headings.Count(); i++)
            {
                if (_headings[i].ToLower() == fieldName.ToLower())
                {
                    result = fields[i];
                    i      = _headings.Count();
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        public Error ValidateOrders(CompanyModel company, UserModel user, List <string> headings,
                                    string dateFormat)
        {
            var error = new Error();

            _headings = headings;

            int rowNum      = 1,
                customerIdx = -1,
                countryIdx  = -1,
                locationIdx = -1,
                dwoIdx      = -1,
                dwcIdx      = -1,
                brandCatIdx = -1,
                productIdx  = -1;

            foreach (var row in db.FindFileImportRows(company.Id, user.Id)
                     .Skip(1)                      // Skip first record (headers)
                     .ToList())
            {
                if (rowNum == 1)
                {
                    customerIdx = findField(row, "CustomerName");
                    countryIdx  = findField(row, "ShipCountry");
                    locationIdx = findField(row, "LocationId");
                    dwoIdx      = findField(row, "DeliveryWindowOpen");
                    dwcIdx      = findField(row, "DeliveryWindowClose");

                    brandCatIdx = findField(row, "BrandCategory");
                    productIdx  = findField(row, "ItemNumber");

                    rowNum++;
                }

                var fields = row.FileImportFields.Cast <FileImportField>().ToList();

                FileImportField customer = null;
                if (customerIdx >= 0)
                {
                    customer = fields[customerIdx];
                }
                FileImportField country = null;
                if (countryIdx >= 0)
                {
                    country = fields[countryIdx];
                }
                FileImportField location = null;
                if (locationIdx >= 0)
                {
                    location = fields[locationIdx];
                }
                FileImportField dwo = null;
                if (dwoIdx >= 0)
                {
                    dwo = fields[dwoIdx];
                }
                FileImportField dwc = null;
                if (dwcIdx >= 0)
                {
                    dwc = fields[dwcIdx];
                }
                FileImportField brandCat = null;
                if (brandCatIdx >= 0)
                {
                    brandCat = fields[brandCatIdx];
                }
                FileImportField product = null;
                if (productIdx >= 0)
                {
                    product = fields[productIdx];
                }

                if (customer != null && !string.IsNullOrEmpty(customer.Value.Trim()))
                {
                    // Find the customer
                    var cust = db.FindCustomer(company.Id, customer.Value);
                    if (cust == null)
                    {
                        row.ErrorMessage = "Customer '" + customer.Value + "' not found!";
                    }
                    else
                    {
                        row.CustomerId = cust.Id;

                        if (country == null || db.FindCountry(country.Value) == null)
                        {
                            row.ErrorMessage = "Country '" + (country == null ? "" : country.Value) + "' not found!";
                        }
                        else if (location == null || db.FindLocation(company.Id, location.Value) == null)
                        {
                            row.ErrorMessage = "Ship From Location '" + (location == null ? "" : location.Value) + "' not found!";
                        }
                        else if (dwo == null || !string.IsNullOrEmpty(dwo.Value) && !dwo.Value.IsValidDate(dateFormat))
                        {
                            row.ErrorMessage = "Invalid Delivery Window Open Date '" + (dwo == null ? "" : dwo.Value) + "' !";
                        }
                        else if (dwc == null || !string.IsNullOrEmpty(dwc.Value) && !dwc.Value.IsValidDate(dateFormat))
                        {
                            row.ErrorMessage = "Invalid Delivery Window Close Date '" + (dwc == null ? "" : dwc.Value) + "' !";
                        }
                        else if (brandCat == null || db.FindBrandCategory(company.Id, brandCat.Value) == null)
                        {
                            row.ErrorMessage = "Brand Category '" + (brandCat == null ? "" : brandCat.Value) + "' not found!";
                        }
                        else if (product == null)
                        {
                            row.ErrorMessage = "Item Number '" + (product == null ? "" : product.Value) + "' not found!";
                        }
                        else
                        {
                            var prod = db.FindProduct(product.Value);
                            if (prod == null)
                            {
                                row.ErrorMessage = "Item Number '" + (product == null ? "" : product.Value) + "' not found!";
                            }
                            else
                            {
                                row.ProductId  = prod.Id;
                                row.SupplierId = prod.PrimarySupplierId;

                                row.ErrorMessage = "";
                            }
                        }
                    }
                }
                else
                {
                    row.ErrorMessage = "Invalid Customer! Please ensure that a Customer column is selected or a valid customer name supplied";
                }

                db.InsertOrUpdateFileImportRow(row);

                if (!string.IsNullOrEmpty(row.ErrorMessage))
                {
                    error.SetError(EvolutionResources.errImportErrorsFound);
                }
            }

            return(error);
        }