protected override bool ValidateRow(ImportRow row) { ValidateDouble(row[GetColumnByValue(Fields.NumeroLinea.Value)], "NUMERO_LINEA"); ValidateDouble(row[GetColumnByValue(Fields.Imei.Value)], "SIM"); return(true); }
protected Data GetLogiclinkData(Entities entity, ImportRow row) { var data = new Data { Entity = (int)entity }; foreach (var field in GetMappingFields()) { if (field.LogiclinkEntity != entity) { continue; } var value = row[GetColumnByValue(field.Value)]; if (value == string.Empty) { value = GetDefaultByValue(field.Value); if (value == string.Empty) { continue; } } if (field.LogiclinkProperty == 0) { value = string.Format("{0}=\"{1}\"", field.Name, value); } data.Add(field.LogiclinkProperty, value); } return(data); }
/// <summary> /// Replace the Pattern text by double clicking on a row (outside fields). /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FilesList_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (this.listbow_FilesList.SelectedItem != null) { ImportRow row = (ImportRow)this.listbow_FilesList.SelectedItem; this.textbox_Pattern.Text = row.Filename; } }
public override Product Find(ImportRow row) { // search by employee id first if (row.Has(ProductColumnMappingTargets.ProductId)) { return(Products.FindByProductId((string)row[ProductColumnMappingTargets.ProductId])); } row.AddProblem("Import contains no ProductId."); return(null); }
private void SaveAttribute <TPropType>(ImportRow <Customer> row, string key, TPropType value) { if (row.IsTransient) { return; } if (row.IsNew || value != null) { _genericAttributeService.SaveAttribute(row.Entity.Id, key, _attributeKeyGroup, value); } }
protected override bool ValidateRow(ImportRow row) { ValidateInt32(row[GetColumnByValue(Fields.Costo.Value)], "COSTO"); ValidateInt32(row[GetColumnByValue(Fields.VidaUtil.Value)], "VIDA_UTIL"); ValidateDouble(row[GetColumnByValue(Fields.Capacidad.Value)], "CAPACIDAD"); ValidateDouble(row[GetColumnByValue(Fields.Rendimiento.Value)], "RENDIMIENTO"); ValidateInt32(row[GetColumnByValue(Fields.Codigo.Value)], "CODE"); ValidateEmpty(row[GetColumnByValue(Fields.Marca.Value)], "PARENTI06"); ValidateEmpty(row[GetColumnByValue(Fields.Descripcion.Value)], "DESCRIPCION"); return(true); }
public override void Apply(Transaction p, ImportRow r) { for (var i = 0; i < r.Layout.Length; i++) { var value = r.Values[i]; var target = r.Layout[i]; switch (target) { case PointsColumnMappingTargets.Amount: p.Amount = (int)value; break; } } }
public override Product Create(ImportRow row) { var pid = (string)row[ProductColumnMappingTargets.ProductId]; return(new Product { Document = new Document { Id = Document.For <Product>(pid) }, ProductId = pid, Enabled = false, }); }
private static ComicBookInventory ProcessOneComicBook( ImportRow row ) { return(new ComicBookInventory() { // Id = row.ItemGuid, IssueNumber = row.IssueNumber, Title = row.Title, Description = row.Description, Flag = row.Flag, DatePublished = row.DatePublished, }); }
private static ImportRow NewImportRow(List <Check> researchChecks, CheckViewModel resolvedCheck, string disposition) { ImportRow importRow = new ImportRow { RecordID = resolvedCheck.RecordID, InterviewRecordID = resolvedCheck.InterviewRecordID }; PrepopulateImportRow(researchChecks, importRow); PopulateImportRow(resolvedCheck, importRow); return(importRow); }
private static void PrepopulateImportRow(List <Check> researchChecks, ImportRow importRow) { List <Check> rChecks = researchChecks.FindAll(r => r.RecordID == importRow.RecordID && r.InterviewRecordID == importRow.InterviewRecordID).ToList(); foreach (Check resolvedCheck in rChecks) { CheckViewModel cvm = new CheckViewModel(); cvm.Num = resolvedCheck.Num; cvm.Disposition = resolvedCheck.Disposition; cvm.Service = resolvedCheck.Service; PopulateImportRow(cvm, importRow); } }
public void InsertImportRow(ImportRow ImportRowObj) { TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "Start Call: InsertImportRow"); SQLiteCommand cmd; cmd = new SQLiteCommand(WDBSQLiteObj.conn); cmd.CommandText = @"INSERT INTO `ImportView` (`Username`, `Date_Time`, `FileSize`, `FileName`, `FileHash`, `Status`, `Message`) VALUES ( ?, ?, ?, ?, ?, ?, ?)"; var Username = cmd.CreateParameter(); Username.Value = ImportRowObj.Username; cmd.Parameters.Add(Username); var Date_Time = cmd.CreateParameter(); Date_Time.Value = ImportRowObj.DateTime; cmd.Parameters.Add(Date_Time); var FileSize = cmd.CreateParameter(); FileSize.Value = ImportRowObj.FileSize; cmd.Parameters.Add(FileSize); var FileName = cmd.CreateParameter(); FileName.Value = ImportRowObj.FileName; cmd.Parameters.Add(FileName); var FileHash = cmd.CreateParameter(); FileHash.Value = ImportRowObj.FileHash; cmd.Parameters.Add(FileHash); var Status = cmd.CreateParameter(); Status.Value = ImportRowObj.Status; cmd.Parameters.Add(Status); var Message = cmd.CreateParameter(); Message.Value = ImportRowObj.Message; cmd.Parameters.Add(Message); TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "cmd.ExecuteNonQuery(): " + cmd.ExecuteNonQuery().ToString()); cmd.Dispose(); TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "End Call: InsertImportRow"); }
public override User Create(ImportRow row) { // use either employee id or login, and add digits after login to create a unique id string id = null; if (row.Has(UserColumnMappingTargets.EmployeeId)) { id = Document.For <User>((string)row[UserColumnMappingTargets.EmployeeId]); var dupe = Users.TryGet(id); if (null != dupe) { row.Problems.Add("There is already an employee with this EmployeeId, '" + id + "'."); return(null); } } else if (row.Has(UserColumnMappingTargets.Login)) { id = Document.For <User>((string)row[UserColumnMappingTargets.EmployeeId]); var dupe = Users.TryGet(id); while (null != dupe) { if (id.Length > 2 && char.IsDigit(id[id.Length - 1]) && '-' == id[id.Length - 2]) { id = id.Substring(id.Length - 1) + (int.Parse(id[id.Length - 1].ToString()) + 1); } else { id += "-1"; } dupe = Users.TryGet(id); } } else { row.Problems.Add("Row has neither EmployeeId nor Login."); } return(new User { Document = new Document { Id = id }, EmployeeId = (string)row[UserColumnMappingTargets.EmployeeId], Login = (string)row[UserColumnMappingTargets.Login], State = UserState.Registered, }); }
private void UpsertRole(ImportRow <Customer> row, CustomerRole role, string roleSystemName, bool value) { if (role != null) { var hasRole = row.Entity.CustomerRoles.Any(x => x.SystemName == roleSystemName); if (value && !hasRole) { row.Entity.CustomerRoles.Add(role); } else if (!value && hasRole) { row.Entity.CustomerRoles.Remove(role); } } }
public override void ValidateRow(ImportRow row) { // employee id is required if its on the sheet. if (row.Has(UserColumnMappingTargets.EmployeeId) && String.IsNullOrEmpty((string)row[UserColumnMappingTargets.EmployeeId])) { row.AddProblem("Row has an empty EmployeeId column. EmployeeId is an optional column, but if part of the upload sheet, it must be filled."); } // login is also required if on the sheet if (row.Has(UserColumnMappingTargets.Login) && String.IsNullOrEmpty((string)row[UserColumnMappingTargets.Login])) { row.AddProblem("Row has an empty Login value. Login is a required field."); } }
private static ImportRow BuildDomainRowFromFile(Utils utils, string time, string url, string timeTaken) { var row = new ImportRow { DateImported = DateTime.Now, Time = Convert.ToDateTime(time), URL = url, IsComparable = utils.IsComparable(url) }; if (double.TryParse(timeTaken, out var number)) { row.TimeTaken = number; } return(row); }
public override User Find(ImportRow row) { // search by employee id first if (row.Has(UserColumnMappingTargets.EmployeeId)) { return(Users.FindUserByEmployeeId((string)row[UserColumnMappingTargets.EmployeeId])); } // search by login next if (row.Has(UserColumnMappingTargets.Login)) { return(Users.FindUserByLogin((string)row[UserColumnMappingTargets.Login])); } row.AddProblem("Import contains neither EmployeeId nor Login."); return(null); }
private void uiFileImport_Click(object sender, RoutedEventArgs e) { XMLimporter window = new XMLimporter(); string filename = window.filename; FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read); IExcelDataReader excelReader; if (System.IO.Path.GetExtension(filename).ToUpper() == ".XLS") { //1.1 Reading from a binary Excel file ('97-2003 format; *.xls) excelReader = ExcelReaderFactory.CreateBinaryReader(stream); } else { //1.2 Reading from a OpenXml Excel file (2007 format; *.xlsx) excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); } DataSet result = excelReader.AsDataSet(); int rowsMax = result.Tables[0].Rows.Count; int colsMax = result.Tables[0].Columns.Count; List <ImportRow> noveStavke = new List <ImportRow>(); for (int i = 0; i < rowsMax; i++) { if (!string.IsNullOrWhiteSpace(result.Tables[0].Rows[i][0].ToString())) { double parseContainer = 0; ImportRow newInput = new ImportRow(); newInput.Stavka = result.Tables[0].Rows[i][0].ToString(); newInput.Opis = result.Tables[0].Rows[i][1].ToString(); newInput.InvKod = result.Tables[0].Rows[i][2].ToString(); newInput.Ulaz = Double.TryParse(result.Tables[0].Rows[i][3].ToString(), out parseContainer) ? parseContainer : 0; //if parsable, use. else is 0 newInput.Rabat = Double.TryParse(result.Tables[0].Rows[i][4].ToString(), out parseContainer) ? parseContainer : 0; newInput.Izlaz = Double.TryParse(result.Tables[0].Rows[i][5].ToString(), out parseContainer) ? parseContainer : 0; newInput.Dobavljac = result.Tables[0].Rows[i][6].ToString(); newInput.Komentari = result.Tables[0].Rows[i][7].ToString(); noveStavke.Add(newInput); } } uiImportDataGrid.ItemsSource = noveStavke; excelReader.Close(); }
protected override bool ValidateRow(ImportRow row) { if (IsMapped(Fields.Latitud.Value) && IsMapped(Fields.Longitud.Value)) { ValidateDouble(row[GetColumnByValue(Fields.Latitud.Value)], "LATITUD"); ValidateDouble(row[GetColumnByValue(Fields.Longitud.Value)], "LONGITUD"); } ValidateEmpty(GetColumnByValue(Fields.Codigo.Value), "CODE"); if (IsMapped(Fields.Descripcion.Value)) { ValidateEmpty(GetColumnByValue(Fields.Descripcion.Value), "DESCRIPTION"); } //if (IsMapped(Fields.TipoGeoRef.Value)) ValidateEmpty(GetColumnByValue(Fields.TipoGeoRef.Value), "Entities", "PARENTI10"); return(true); }
public void UpdateImportRow(ImportRow ImportRowObj) { TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "Start Call: UpdateImportRow"); SQLiteCommand cmd; cmd = new SQLiteCommand(WDBSQLiteObj.conn); cmd.CommandText = @"UPDATE `ImportView` SET `ImportID` = ?, `ImportTitle` = ?, `Status` = ?, `Message` = ? WHERE `FileHash` = ?"; var ImportIDParm = cmd.CreateParameter(); ImportIDParm.Value = ImportRowObj.ImportID; cmd.Parameters.Add(ImportIDParm); var ImportTitleParm = cmd.CreateParameter(); ImportTitleParm.Value = ImportRowObj.ImportTitle; cmd.Parameters.Add(ImportTitleParm); var StatusParm = cmd.CreateParameter(); StatusParm.Value = ImportRowObj.Status; cmd.Parameters.Add(StatusParm); var MessageParm = cmd.CreateParameter(); MessageParm.Value = ImportRowObj.Message; cmd.Parameters.Add(MessageParm); var FileHashParm = cmd.CreateParameter(); FileHashParm.Value = ImportRowObj.FileHash.ToUpper(); cmd.Parameters.Add(FileHashParm); TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "cmd.ExecuteNonQuery(): " + cmd.ExecuteNonQuery().ToString()); cmd.Dispose(); TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "End Call: UpdateImportRow"); }
protected override bool ValidateRow(ImportRow row) { ValidateDouble(GetValue(row, Fields.Cantidad.Value), "CANTIDAD"); if (CurrentImportMode == Modes.EssoCard) { ValidateDouble(GetValue(row, Fields.Valor.Value), "VALOR"); } else { ValidateDouble(GetValue(row, Fields.ImporteTotal.Value), "IMPORTE_TOTAL"); ValidateDouble(GetValue(row, Fields.ImporteUnitario.Value), "IMPORTE_UNITARIO"); if (IsMapped(Fields.Vehiculo.Value) || HasDefault(Fields.Vehiculo.Value)) { ValidateDouble(GetValue(row, Fields.KmDeclarados.Value), "KM_REC"); } } return(true); }
private static ImportRow NewImportRow(Check resolvedCheck, string disposition) { ImportRow importRow = new ImportRow { RecordID = resolvedCheck.RecordID, InterviewRecordID = resolvedCheck.InterviewRecordID, LBVDCheckNum = (resolvedCheck.Service.Equals("LBVD") ? resolvedCheck.Num : 0), LBVDCheckDisposition = (resolvedCheck.Service.Equals("LBVD") ? disposition : ""), TIDCheckNum = (resolvedCheck.Service.Equals("TID") ? resolvedCheck.Num : 0), TIDCheckDisposition = (resolvedCheck.Service.Equals("TID") ? disposition : ""), TDLCheckNum = (resolvedCheck.Service.Equals("TDL") ? resolvedCheck.Num : 0), TDLCheckDisposition = (resolvedCheck.Service.Equals("TDL") ? disposition : ""), MBVDCheckNum = (resolvedCheck.Service.Equals("MBVD") ? resolvedCheck.Num : 0), MBVDCheckDisposition = (resolvedCheck.Service.Equals("MBVD") ? disposition : ""), SDCheckNum = (resolvedCheck.Service.Equals("SD") ? resolvedCheck.Num : 0), SDCheckDisposition = (resolvedCheck.Service.Equals("SD") ? disposition : "") }; return(importRow); }
public override void ValidateRow(ImportRow row) { // product id is required if (String.IsNullOrEmpty((string)row[ProductColumnMappingTargets.ProductId])) { row.AddProblem("Row has an empty ProductId column. ProductId is a required field."); } // name is also required if on the sheet if (String.IsNullOrEmpty((string)row[ProductColumnMappingTargets.Name])) { row.AddProblem("Row has an empty name value. Name is a required field."); } var cost = (decimal?)row[ProductColumnMappingTargets.Cost]; if (!cost.HasValue) { row.AddProblem("Row has no cost value. Cost is a required field."); } }
public List <ImportRow> GetImportRows() { TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "Start Call: GetImportRows"); string ImportID; SQLiteCommand cmd; SQLiteDataReader reader; List <ImportRow> ImportRows = new List <ImportRow>(); cmd = new SQLiteCommand(WDBSQLiteObj.conn); cmd.CommandText = @"SELECT * FROM `ImportView`"; reader = cmd.ExecuteReader(); while (reader.Read()) { ImportRow ImportRowObj = new ImportRow(); if (reader["ImportID"].ToString() == "") { ImportID = "0"; } else { ImportID = reader["ImportID"].ToString(); } TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "ImportID For IntParse: " + ImportID); ImportRowObj.ImportID = Int32.Parse(ImportID); ImportRowObj.Username = reader["Username"].ToString(); ImportRowObj.ImportTitle = reader["ImportTitle"].ToString(); ImportRowObj.DateTime = reader["Date_Time"].ToString(); ImportRowObj.FileSize = reader["FileSize"].ToString(); ImportRowObj.FileName = reader["FileName"].ToString(); ImportRowObj.FileHash = reader["FileHash"].ToString(); ImportRowObj.Status = reader["Status"].ToString(); ImportRowObj.Message = reader["Message"].ToString(); ImportRows.Add(ImportRowObj); } TraceLogObj.WriteToLog(_ThreadName, ObjectName, GetCurrentMethod(), "End Call: GetImportRows"); return(ImportRows); }
private static void ValidateImportRow(ImportRow row, ModelStateDictionary modelState) { if (string.IsNullOrEmpty(row.IssueNumber)) { AddModelError( modelState, "Issue Number cannot be left blank", row.RowNumber ); } if (string.IsNullOrEmpty(row.Title)) { AddModelError( modelState, "Title cannot be left blank", row.RowNumber ); } if (string.IsNullOrEmpty(row.Description)) { AddModelError( modelState, "Description cannot be left blank", row.RowNumber ); } if (row.DatePublished > DateTimeOffset.Now) { AddModelError( modelState, "Date Published must be a past date", row.RowNumber ); } }
public override void Apply(Product p, ImportRow r) { var features = new List <string>(); var images = new List <string>(); // select the option that this row refers, or use the default option // creates the named option if it does not exist. var optionName = (string)r[ProductColumnMappingTargets.OptionName] ?? ""; if (null == p.Options) { p.Options = new List <ProductOption>(); } var option = p.Options.FirstOrDefault(x => x.Name == optionName); if (null == option) { option = new ProductOption { Name = optionName, }; p.Options.Add(option); } // select the product source or use a default source var vendorName = (string)r[ProductColumnMappingTargets.Vendor] ?? ""; if (null == option.Sources) { option.Sources = new List <ProductSource>(); } var source = String.IsNullOrEmpty(vendorName) ? option.Sources.FirstOrDefault(x => x.Vendor == null) : option.Sources.FirstOrDefault(x => null != x.Vendor && x.Vendor.Value.Name == vendorName); if (null == source) { source = new ProductSource { Pricing = new ProductPricing(), Stock = new ProductStock(), Vendor = null, }; if (!String.IsNullOrEmpty(vendorName)) { var vendor = Vendors.FindVendorByName(vendorName); if (null == vendor) { vendor = new Vendor { Document = new Document() { Id = Document.For <Vendor>(vendorName.ToSlug()) }, Name = vendorName, }; Vendors.Save(vendor); source.Vendor = Reference.To(vendor); } } option.Sources.Add(source); } var pricing = source.Pricing ?? (source.Pricing = new ProductPricing()); var stock = source.Stock ?? (source.Stock = new ProductStock()); for (var i = 0; i < r.Layout.Length; i++) { var value = r.Values[i]; var target = r.Layout[i]; switch (target) { case ProductColumnMappingTargets.Enabled: p.Set(x => x.Enabled, (bool)value); break; case ProductColumnMappingTargets.Category: p.Set(x => x.Category, (Product.ParseCategory((string)value))); break; case ProductColumnMappingTargets.Name: p.Set(x => x.Name, (string)value); break; case ProductColumnMappingTargets.Manufacturer: p.Set(x => x.Manufacturer, (string)value); break; case ProductColumnMappingTargets.Brand: p.Set(x => x.Brand, (string)value); break; case ProductColumnMappingTargets.Description: p.Set(x => x.Description, (string)value); break; case ProductColumnMappingTargets.Details: p.Set(x => x.Details, (string)value); break; case ProductColumnMappingTargets.Warranty: p.Set(x => x.Warranty, (string)value); break; case ProductColumnMappingTargets.CountryOfOrigin: p.Set(x => x.CountryOfOrigin, (string)value); break; case ProductColumnMappingTargets.Model: p.Model = ((string)value); break; case ProductColumnMappingTargets.LeadTime: stock.Leadtime = (string)value; break; case ProductColumnMappingTargets.Feature: features.Add((string)value); break; case ProductColumnMappingTargets.Sku: p.Set(x => x.Sku, (string)value); break; case ProductColumnMappingTargets.Upc: p.Set(x => x.Upc, (string)value); break; case ProductColumnMappingTargets.PackageL: (p.PackageDimensions ?? (p.PackageDimensions = new ProductDimensions())).Length = (decimal?)value; break; case ProductColumnMappingTargets.PackageW: (p.PackageDimensions ?? (p.PackageDimensions = new ProductDimensions())).Width = (decimal?)value; break; case ProductColumnMappingTargets.PackageH: (p.PackageDimensions ?? (p.PackageDimensions = new ProductDimensions())).Height = (decimal?)value; break; case ProductColumnMappingTargets.PackageWeight: (p.PackageDimensions ?? (p.PackageDimensions = new ProductDimensions())).Weight = (decimal?)value; break; case ProductColumnMappingTargets.ProductL: (p.ProductDimensions ?? (p.ProductDimensions = new ProductDimensions())).Length = (decimal?)value; break; case ProductColumnMappingTargets.ProductW: (p.ProductDimensions ?? (p.ProductDimensions = new ProductDimensions())).Width = (decimal?)value; break; case ProductColumnMappingTargets.ProductH: (p.ProductDimensions ?? (p.ProductDimensions = new ProductDimensions())).Height = (decimal?)value; break; case ProductColumnMappingTargets.ProductWeight: (p.ProductDimensions ?? (p.ProductDimensions = new ProductDimensions())).Weight = (decimal?)value; break; case ProductColumnMappingTargets.Image: images.Add((string)value); break; case ProductColumnMappingTargets.SourceAdded: source.Added = (DateTime?)value; break; case ProductColumnMappingTargets.SourceUpdated: source.Updated = (DateTime?)value; break; case ProductColumnMappingTargets.Msrp: pricing.Msrp = (decimal?)value; break; case ProductColumnMappingTargets.Cost: pricing.Cost = ((decimal?)value).Value; break; case ProductColumnMappingTargets.ShippingFee: pricing.ShippingFee = (decimal?)value; break; case ProductColumnMappingTargets.ShippingCost: pricing.ShippingCost = (decimal?)value; break; case ProductColumnMappingTargets.OptionSku: option.Sku = (string)value; break; case ProductColumnMappingTargets.VendorPrice: pricing.Cost = ((decimal?)value) ?? 0; break; } } if (features.Count > 0) { p.Set(x => x.Features, features.Where(x => !String.IsNullOrWhiteSpace(x)).ToArray()); } if (images.Count > 0) { p.Set(x => x.Images, images.Where(x => !String.IsNullOrWhiteSpace(x)).ToArray()); } }
private static void PopulateImportRow(CheckViewModel resolvedCheck, ImportRow importRow) { switch (resolvedCheck.Service) { case "LBVD": importRow.LBVDCheckNum = resolvedCheck.Num; importRow.LBVDCheckDisposition = resolvedCheck.Disposition; break; case "LBVD2": importRow.LBVDCheckNum2 = resolvedCheck.Num; importRow.LBVDCheck2Disposition = resolvedCheck.Disposition; break; case "LBVD3": importRow.LBVDCheckNum3 = resolvedCheck.Num; importRow.LBVDCheck3Disposition = resolvedCheck.Disposition; break; case "TID": importRow.TIDCheckNum = resolvedCheck.Num; importRow.TIDCheckDisposition = resolvedCheck.Disposition; break; case "TID2": importRow.TIDCheckNum2 = resolvedCheck.Num; importRow.TIDCheck2Disposition = resolvedCheck.Disposition; break; case "TID3": importRow.TIDCheckNum3 = resolvedCheck.Num; importRow.TIDCheck3Disposition = resolvedCheck.Disposition; break; case "TDL": importRow.TDLCheckNum = resolvedCheck.Num; importRow.TDLCheckDisposition = resolvedCheck.Disposition; break; case "TDL2": importRow.TDLCheckNum2 = resolvedCheck.Num; importRow.TDLCheck2Disposition = resolvedCheck.Disposition; break; case "TDL3": importRow.TDLCheckNum3 = resolvedCheck.Num; importRow.TDLCheck3Disposition = resolvedCheck.Disposition; break; case "MBVD": importRow.MBVDCheckNum = resolvedCheck.Num; importRow.MBVDCheckDisposition = resolvedCheck.Disposition; break; case "MBVD2": importRow.MBVDCheckNum2 = resolvedCheck.Num; importRow.MBVDCheck2Disposition = resolvedCheck.Disposition; break; case "MBVD3": importRow.MBVDCheckNum3 = resolvedCheck.Num; importRow.MBVDCheck3Disposition = resolvedCheck.Disposition; break; // Supporting documents /* * case "SD1": * importRow.SDCheckNum1 = resolvedCheck.Num; * importRow.SDCheckDisposition = resolvedCheck.Disposition; * break; * * case "SD2": * importRow.SDCheckNum2 = resolvedCheck.Num; * importRow.SDCheckDisposition2 = resolvedCheck.Disposition; * break; * * case "SD3": * importRow.SDCheckNum3 = resolvedCheck.Num; * importRow.SDCheckDisposition3 = resolvedCheck.Disposition; * break; */ } }
private static void UpdateExistingImportRow(CheckViewModel resolvedCheck, string disposition, ImportRow irow) { int checkNum = resolvedCheck.Num; switch (resolvedCheck.Service) { case "LBVD": if (irow.LBVDCheckNum == 0) { irow.LBVDCheckNum = checkNum; irow.LBVDCheckDisposition = disposition; } break; case "LBVD2": if (irow.LBVDCheckNum2 == 0) { irow.LBVDCheckNum2 = checkNum; irow.LBVDCheck2Disposition = disposition; } break; case "LBVD3": if (irow.LBVDCheckNum3 == 0) { irow.LBVDCheckNum3 = checkNum; irow.LBVDCheck3Disposition = disposition; } break; case "TID": if (irow.TIDCheckNum == 0) { irow.TIDCheckNum = checkNum; irow.TIDCheckDisposition = disposition; } break; case "TID2": if (irow.TIDCheckNum2 == 0) { irow.TIDCheckNum2 = checkNum; irow.TIDCheck2Disposition = disposition; } break; case "TID3": if (irow.TIDCheckNum3 == 0) { irow.TIDCheckNum3 = checkNum; irow.TIDCheck3Disposition = disposition; } break; case "TDL": if (irow.TDLCheckNum == 0) { irow.TDLCheckNum = checkNum; irow.TDLCheckDisposition = disposition; } break; case "TDL2": if (irow.TDLCheckNum2 == 0) { irow.TDLCheckNum2 = checkNum; irow.TDLCheck2Disposition = disposition; } break; case "TDL3": if (irow.TDLCheckNum3 == 0) { irow.TDLCheckNum3 = checkNum; irow.TDLCheck3Disposition = disposition; } break; case "MBVD": if (irow.MBVDCheckNum == 0) { irow.MBVDCheckNum = checkNum; irow.MBVDCheckDisposition = disposition; } break; case "MBVD2": if (irow.MBVDCheckNum2 == 0) { irow.MBVDCheckNum2 = checkNum; irow.MBVDCheck2Disposition = disposition; } break; case "MBVD3": if (irow.MBVDCheckNum3 == 0) { irow.MBVDCheckNum3 = checkNum; irow.MBVDCheck3Disposition = disposition; } break; // Supporting Documents /* * case "SD1": * if (irow.SDCheckNum1 == 0) * { * irow.SDCheckNum1 = checkNum; * irow.SDCheckDisposition2 = disposition; * } * break; * case "SD2": * if (irow.SDCheckNum2 == 0) * { * irow.SDCheckNum2 = checkNum; * irow.SDCheckDisposition2 = disposition; * } * break; * case "SD3": * if (irow.SDCheckNum3 == 0) * { * irow.SDCheckNum3 = checkNum; * irow.SDCheckDisposition3 = disposition; * } * break; */ default: break; } }
/// <summary> /// Gets the Client association from the loaded clientAssociations and a row's Categories/Associations (if there is one). /// It used the DataCategory.ClientName to find the Client. /// </summary> /// <param name="clientAssociations">The loaded clientAssociations</param> /// <param name="row">The row's categories/values.</param> private static Client GetClientAssociation(IEnumerable<Client> clientAssociations, ImportRow row) { //Get the client association var clientNameCell = row.GetCell(DataCategory.ClientName); if (clientNameCell == null) throw ImportRowTools.Exception("Client not set", row); var associatedClient = clientAssociations.FirstOrDefault(ca => ca.Name == clientNameCell.Value); if (associatedClient == null) throw ImportRowTools.Exception(String.Format("Could not find Client '{0}'", clientNameCell.Value), row); return associatedClient; }
/// <summary> /// Gets the Location association from the loaded locationAssociations. /// It uses the DataCategory.LocationLatitude and DataCategory.LocationLongitude to find the location. /// </summary> /// <param name="locationAssociations">The loaded location associations.</param> /// <param name="importRow">The row's categories/values.</param> /// <returns></returns> private static Location GetLocationAssociation(IEnumerable<Location> locationAssociations, ImportRow importRow) { Location associatedLocation = null; var locationLatitude = importRow.GetCell(DataCategory.LocationLatitude); var locationLongitude = importRow.GetCell(DataCategory.LocationLongitude); if (locationLatitude == null) throw ImportRowTools.Exception("Latitude not set", importRow); if (locationLongitude == null) throw ImportRowTools.Exception("Longitude not set", importRow); associatedLocation = //compare first 6 decimals locationAssociations.FirstOrDefault( c => ToSixDecimals(c.Latitude.ToString()) == ToSixDecimals(locationLatitude.Value) && ToSixDecimals(c.Longitude.ToString()) == ToSixDecimals(locationLongitude.Value)); if (associatedLocation == null) throw ImportRowTools.Exception( String.Format("Could not find Location with latitude '{0}', longitude '{1}'", locationLatitude, locationLongitude), importRow); return associatedLocation; }
private void SaveAttribute <TPropType>(ImportRow <Customer> row, string key) { SaveAttribute(row, key, row.GetDataValue <TPropType>(key)); }
/// <summary> /// Gets the Region association from the loaded regionAssociations and a row's Categories/Associations (if there is one). /// It used the DataCategory.RegionName to find the Region. /// </summary> /// <param name="regionAssociations">The loaded region associations</param> /// <param name="row">The row's categories/values.</param> private static Region GetRegionAssociation(IEnumerable<Region> regionAssociations, ImportRow row) { var regionNameCell = row.GetCell(DataCategory.RegionName); if (regionNameCell == null || string.IsNullOrEmpty(regionNameCell.Value)) return null; var region = regionAssociations.First(ca => ca.Name == regionNameCell.Value); return region; }
private void ImportAddress( string fieldPrefix, ImportRow <Customer> row, ImportExecuteContext context, Dictionary <string, int> allCountries, Dictionary <Tuple <int, string>, int> allStateProvinces) { // last name is mandatory for an address to be imported or updated if (!row.HasDataValue(fieldPrefix + "LastName")) { return; } var address = new Address { CreatedOnUtc = UtcNow }; var childRow = new ImportRow <Address>(row.Segmenter, row.DataRow, row.Position); childRow.Initialize(address, row.EntityDisplayName); childRow.SetProperty(context.Result, fieldPrefix + "LastName", x => x.LastName); childRow.SetProperty(context.Result, fieldPrefix + "FirstName", x => x.FirstName); childRow.SetProperty(context.Result, fieldPrefix + "Email", x => x.Email); childRow.SetProperty(context.Result, fieldPrefix + "Company", x => x.Company); childRow.SetProperty(context.Result, fieldPrefix + "City", x => x.City); childRow.SetProperty(context.Result, fieldPrefix + "Address1", x => x.Address1); childRow.SetProperty(context.Result, fieldPrefix + "Address2", x => x.Address2); childRow.SetProperty(context.Result, fieldPrefix + "ZipPostalCode", x => x.ZipPostalCode); childRow.SetProperty(context.Result, fieldPrefix + "PhoneNumber", x => x.PhoneNumber); childRow.SetProperty(context.Result, fieldPrefix + "FaxNumber", x => x.FaxNumber); childRow.SetProperty(context.Result, fieldPrefix + "CountryId", x => x.CountryId); if (childRow.Entity.CountryId == null) { // try with country code childRow.SetProperty(context.Result, fieldPrefix + "CountryCode", x => x.CountryId, converter: (val, ci) => CountryCodeToId(allCountries, val.ToString())); } var countryId = childRow.Entity.CountryId; if (countryId.HasValue) { childRow.SetProperty(context.Result, fieldPrefix + "StateProvinceId", x => x.StateProvinceId); if (childRow.Entity.StateProvinceId == null) { // try with state abbreviation childRow.SetProperty(context.Result, fieldPrefix + "StateAbbreviation", x => x.StateProvinceId, converter: (val, ci) => StateAbbreviationToId(allStateProvinces, countryId, val.ToString())); } } if (!childRow.IsDirty) { // Not one single property could be set. Get out! return; } var appliedAddress = row.Entity.Addresses.FindAddress(address); if (appliedAddress == null) { appliedAddress = address; row.Entity.Addresses.Add(appliedAddress); } if (fieldPrefix == "BillingAddress.") { row.Entity.BillingAddress = appliedAddress; } else if (fieldPrefix == "ShippingAddress.") { row.Entity.ShippingAddress = appliedAddress; } _customerRepository.Update(row.Entity); }
//Use the idea from http://www.codeproject.com/KB/database/CsvReader.aspx by Sebastien Lorion public static bool ImportOHLCV_CSV(string csvFileName, char delimiter, common.dateTimeLibs.DateTimeFormats dataDateFormat, string stockExchangeForNewCode, CultureInfo culture, data.baseDS.priceDataDataTable priceDataTbl, ImportRow ImportRowFunc, OnUpdatePriceData onUpdateDataFunc, OnEndImportPriceData onEndImportFunc) { libs.importStat myImportStat = new libs.importStat(); myImportStat.Reset(); myImportStat.dateFormat = dataDateFormat; myImportStat.culture = culture; data.baseDS.stockCodeDataTable stockCodeTbl = new data.baseDS.stockCodeDataTable(); data.baseDS.priceDataRow priceDataRow; DataRowView[] foundRows; application.DbAccess.LoadData(stockCodeTbl, AppTypes.CommonStatus.Enable); DataView stockCodeView = new DataView(stockCodeTbl); stockCodeView.Sort = stockCodeTbl.codeColumn.ColumnName; bool fCanceled = false; DateTime lastPriceDate = common.Consts.constNullDate; importOHLCV data; // open the file "data.csv" which is a CSV file with headers using (CsvReader csv = new CsvReader(new StreamReader(csvFileName), true, delimiter)) { // missing fields will not throw an exception, // but will instead be treated as if there was a null value csv.MissingFieldAction = MissingFieldAction.ReplaceByNull; int fieldCount = csv.FieldCount; if (fieldCount < 7) return false; while (csv.ReadNextRecord()) { Application.DoEvents(); myImportStat.dataCount++; data = ImportRowFunc(csv, myImportStat); if (myImportStat.cancel) { fCanceled = true; break; } if (data == null) { myImportStat.errorCount++; continue; } //Assume that all price must be valid if (data.Open <= 0 || data.High <= 0 || data.Low <= 0 || data.Close <= 0) continue; foundRows = stockCodeView.FindRows(data.code); if (foundRows.Length == 0) { //Try to add new stock code libs.AddNewCode(data.code, stockExchangeForNewCode, stockCodeTbl); application.DbAccess.UpdateData(stockCodeTbl); } // Ignore all data that was in database //if (!foundLastPriceDate) //{ // lastPriceDate = libs.FindLastPriceDate(data.code); // foundLastPriceDate = true; //} if (lastPriceDate != common.Consts.constNullDate && data.dateTime <= lastPriceDate) { continue; } if (priceDataTbl.FindBystockCodeonDate(data.code, data.dateTime) != null) { myImportStat.errorCount++; continue; } myImportStat.updateCount++; priceDataRow = priceDataTbl.NewpriceDataRow(); commonClass.AppLibs.InitData(priceDataRow); priceDataRow.stockCode = data.code; priceDataRow.onDate = data.dateTime; //Try to fix some error in data priceDataRow.openPrice = (decimal)data.Open; priceDataRow.highPrice = (decimal)data.High; priceDataRow.lowPrice = (decimal)data.Low; priceDataRow.closePrice = (decimal)data.Close; priceDataRow.volume = (decimal)data.Volume; priceDataTbl.AddpriceDataRow(priceDataRow); if (onUpdateDataFunc != null) onUpdateDataFunc(priceDataRow, myImportStat); } } if (fCanceled) { priceDataTbl.Clear(); return false; } if (onEndImportFunc != null) onEndImportFunc(priceDataTbl); return true; }