private void Apply_Click(object sender, RoutedEventArgs e) { #if DEBUG List <string> titleList = new List <string>(); List <string> contentList = new List <string>(); foreach (var item in Histories) { titleList.Add(item.Title); contentList.Add(item.Description); } IExcel excel = ExcelFactory.GetExcel(); excel.SaveHistory(CharToIntColumnName(ConfigExcelFormat.TitleColumn), CharToIntColumnName(ConfigExcelFormat.ContentColumn), titleList, contentList); #endif }
private void Refresh_Click(object sender, RoutedEventArgs e) { Histories = new ObservableCollection <HistoryGridModel>(); List <string> titleList = new List <string>(); List <string> contentList = new List <string>(); var instance = ExcelFactory.GetExcel(); instance.ReadHistory(CharToIntColumnName(ConfigExcelFormat.TitleColumn), CharToIntColumnName(ConfigExcelFormat.ContentColumn), titleList, contentList); for (int i = 0; i < titleList.Count; i++) { Histories.Add(new HistoryGridModel() { Title = titleList[i], Description = contentList[i] }); } ((System.Windows.Controls.Grid) this.Parent).Children.Add(new UserControlHistory()); }
private void Bt_Apply_Click(object sender, RoutedEventArgs e) { if (System.IO.File.Exists(TB_Excel_Path.Text)) { try { using (FileStream fs = File.OpenRead(TB_Excel_Path.Text)) { } } catch (IOException) { MessageBox.Show("The file is opened by another application"); return; } var instance = ExcelFactory.GetExcel(); instance.GetPath(TB_Excel_Path.Text); } else { try { if (!Directory.Exists(TB_Work_Path.Text)) { Directory.CreateDirectory(TB_Work_Path.Text); } } catch { Error_Info.Content = "Please enter the correct work path"; return; } if (!(System.IO.Path.GetExtension(TB_Excel_Path.Text) == ".xlsx")) { Error_Info.Content = "The Excel Path is not a valid Excel file"; return; } try { var instance = ExcelFactory.GetExcel(); instance.GetPath(TB_Excel_Path.Text); } catch (DirectoryNotFoundException err) { Error_Info.Content = $"Can't create excel at {TB_Excel_Path.Text}, {err.Message}"; return; } catch (NotSupportedException err) { Error_Info.Content = $"The format for path is invalid, {err.Message}"; return; } catch (Exception err) { Error_Info.Content = $"{err.Message}"; return; } } try { if (!Directory.Exists(TB_Work_Path.Text)) { Directory.CreateDirectory(TB_Work_Path.Text); } WorkPath.DefalutWorkPath = TB_Work_Path.Text; } catch { Error_Info.Content = "Please enter the correct work path"; return; } this.Close(); }