/// <summary> /// Load info from excell sheet and fill in any missing fields with db data /// </summary> public void LoadExcelInfo() { WorkbookReader workbookReader = new WorkbookReader(); OpenFileDialog dialog = new OpenFileDialog { Filter = "Excel files|*.xls; *.xlsx" }; if (dialog.ShowDialog() != true) { return; } CheckColumnHeaders(dialog.FileName); try { this.ProgressCheck = "Loading Data from excel sheet..."; this.LoadedItems = this.ItemService.LoadExcelItems("Update", dialog.FileName); this.LoadItemCount = LoadedItems.Count; this.ButtonVisibility = "False"; LoadItemWorker.DoWork += LoadItemWorker_DoWork; LoadItemWorker.ProgressChanged += LoadItemWorker_ProgressChanged; LoadItemWorker.RunWorkerCompleted += LoadItemWorker_RunWorkerCompleted; LoadItemWorker.WorkerReportsProgress = true; LoadItemWorker.RunWorkerAsync(); } catch (Exception ex) { ErrorLog.LogError("Odin was unable to load the additional information for the excel items.", ex.ToString()); } }
/// <summary> /// Constructs the Find Item View Model /// </summary> /// <param name="type"></param> /// <param name="itemService"></param> /// <param name="workbookReader"></param> public FindItemViewModel(string type, ItemService itemService, WorkbookReader workbookReader) { this.BackgroundWorker = new BackgroundWorker(); this.ItemService = itemService ?? throw new ArgumentNullException("itemService"); this.WorkbookReader = workbookReader ?? throw new ArgumentNullException("workbookReader"); this.UpdateType = type; this.SearchByFields = SetSearchByFields(); this.Title = type + " Items"; this.ItemIdSearchOrder = 0; this.DescriptionIdSearchOrder = 0; }
public void ImportItemList() { OpenFileDialog dialogue = new OpenFileDialog(); dialogue.Filter = "Excel files|*.xls; *.xlsx"; WorkbookReader workbookReader = new WorkbookReader(); if (dialogue.ShowDialog() != true) { return; } this.ItemIds = workbookReader.RetrieveIds(dialogue.FileName); }
public static void WireUp() { ErrorLog.CreateFolder(); try { ConnectionManager connectionManager = new ConnectionManager(Odin.Properties.Settings.Default.DbServerName, Odin.Properties.Settings.Default.DbName); // ConnectionManager connectionManager = new ConnectionManager(@"(local)\SQLExpress", "Odin"); // connectionManager.SetUseTrustedConnection(true); connectionManager.SetUseTrustedConnection(false); connectionManager.SetPassword(Odin.Properties.Settings.Default.DbPassword); LogServiceFactory logServiceFactory = new LogServiceFactory("Odin"); OdinContextFactory = new OdinContextFactory(connectionManager, logServiceFactory); OdinContext context = OdinContextFactory.CreateContext(); if (!context.Database.Exists()) { DbSettingsView window = new DbSettingsView() { DataContext = new DbSettingsViewModel() }; window.ShowDialog(); OdinContextFactory.CreateContext(); } WorkbookReader = new WorkbookReader(); ItemRepository = new ItemRepository(OdinContextFactory); OptionRepository = new OptionRepository(OdinContextFactory); RequestRepository = new RequestRepository(OdinContextFactory); TemplateRepository = new TemplateRepository(OdinContextFactory); ItemService = new ItemService(WorkbookReader, ItemRepository, TemplateRepository); OptionService = new OptionService(OptionRepository, RequestRepository); ExcelService = new ExcelService(false, ItemService, OptionService, TemplateRepository, RequestRepository); EmailService = new EmailService(OptionService); } catch (Exception e) { // MessageBox.Show(e.ToString()); ErrorLog.LogError("Odin encountered an error with the database.", e.ToString()); Environment.Exit(1); } }
/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public MainViewModel() { var path = Path.Combine(Environment.CurrentDirectory, "DeckMatchups.xlsx"); var reader = new WorkbookReader(path); var matchups = reader.GetAllMatchups(); var calc = new EloCalculator(); calc.Calculate(matchups); var decklist = new List <Deck>(); decklist.AddRange(matchups.Select(m => m.DeckA).Distinct()); decklist.AddRange(matchups.Where(m => !decklist.Contains(m.DeckB)).Select(m => m.DeckB).Distinct()); _allDecks = decklist; Decks = _allDecks; Filter = new DeckFilter(); Filter.FilterChangedEvent += OnFilterChanged; }
public TableRowService() { WorkbookReader = new WorkbookReader(); Results = new ObservableCollection <KeyValuePair <string, string> >(); }
static void RunOptions(Options options) { if (!Directory.Exists(options.InputDir)) { return; } LogHandler logHandler = new LogHandler((type, id, msg) => { string msgType = "Info"; Color color = Color.White; if (type == LogType.Error) { msgType = "Error"; color = Color.Red; } else if (type == LogType.Warning) { msgType = "Warning"; color = Color.Yellow; } Colorful.Console.WriteLine($"[{msgType}] [{id}] {msg}", color); }); WorkbookReader reader = new WorkbookReader(logHandler); TypeContext context = new TypeContext(); context.Add(typeof(LogHandler), logHandler); Workbook[] workbooks = reader.ReadExcelFromDir(options.InputDir); if (workbooks != null && workbooks.Length > 0) { foreach (var workbook in workbooks) { string dir = $"{options.OutputDir}/{workbook.Name}"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } bool result = workbook.Verify(context); if (result) { for (int i = 0; i < workbook.SheetCount; ++i) { Sheet sheet = workbook.GetSheeetByIndex(i); if (options.Format == OutputFormat.Json) { JsonWriter.WriteTo(sheet, dir); } else if (options.Format == OutputFormat.Ndb) { NdbWriter.WriteTo(sheet, dir); } else if (options.Format == OutputFormat.Lua) { LuaWriter.WriteTo(sheet, dir); } } } } } context.Clear(); }