/// <summary> /// Automaticlly saves workbook because it has to work on two files at once public static void UpdateTraining(TrainingModel training, int year, int month, int position, string folderPath, string clientName) { var workbookHandler = new _WorkbookHandler(folderPath, clientName); var workbook = workbookHandler.getWorkbook(year); var worksheetHandler = new _WorksheetHandler(workbook, month.ToString()); var startingRow = new TableReader().GetTableStart(worksheetHandler.Worksheet, position); DeleteTraining(worksheetHandler.Worksheet, position); workbook.Save(); var tbMaker = new TableMaker(worksheetHandler.Worksheet); List <string[]> exerciesesData = new List <string[]>(); foreach (ExerciseModel exercise in training.Exercises) { exerciesesData.Add(new string[] { exercise.Name, exercise.Weight.ToString(), exercise.Sets.ToString(), exercise.Reps.ToString(), exercise.ExerciseVolume.ToString(), exercise.Type }); } //Insert table in place of update one if same worksheet //Otherwise create one in a different one after deleting it in the starting position if (training.TrainingDay.Year == year && training.TrainingDay.Month == month) { tbMaker.InsertTable(startingRow, new string[] { "Exercise", "Weight", "Sets", "Reps", "Volume", "Type" }, training.TrainingDay.Date, exerciesesData); } else { workbook = workbookHandler.getWorkbook(training.TrainingDay.Date); worksheetHandler.Workbook = workbook; worksheetHandler.SheetName = training.TrainingDay.Month.ToString(); worksheetHandler.GetOrCreateWorksheet(); tbMaker = new TableMaker(worksheetHandler.Worksheet); tbMaker.CreateTable(new string[] { "Exercise", "Weight", "Sets", "Reps", "Volume", "Type" }, training.TrainingDay.Date, exerciesesData); } workbook.Save(); }
private void Save() { var workbook = workbookHandler.getWorkbook(CurrentlySelectedTrainingDay.Year); if (SelectedTrainingDay != TrainingDays[TrainingDays.Count() - 1]) { MessageBoxResult result = MessageBox.Show("Do you want to update this training session?", "Update", MessageBoxButton.YesNo); if (result == MessageBoxResult.No) { return; } TrainingDataMapper.UpdateTraining(new TrainingModel(CurrentlySelectedTrainingDay, ExerciseList.ToList()), SelectedTrainingYear, SelectedTrainingMonth, TrainingPositionInMonth + 1, folderPath, "kk"); MessageBox.Show("A training has been updated"); } else { MessageBoxResult result = MessageBox.Show("Do you want to create new training session?", "Create", MessageBoxButton.YesNo); if (result == MessageBoxResult.No) { return; } TrainingDataMapper.AddTraining(new TrainingModel(CurrentlySelectedTrainingDay, ExerciseList.ToList()), workbook); TrainingYears = TrainingDataMapper.GetTrainingYears(folderPath, "kk"); MessageBox.Show("A new training has been saved"); workbook.Save(); } }
private void LoadData() { workbookHandler = new _WorkbookHandler(folderPath, clientName); var workbook = workbookHandler.getWorkbook(); worksheetHandler = new _WorksheetHandler(workbook, DateTime.Now.Month.ToString()); TrainingYears = TrainingDataMapper.GetTrainingYears(folderPath, clientName); SelectedTrainingYear = TrainingYears[0]; TrainingMonths = TrainingDataMapper.GetTrainingMonths(workbookHandler.getWorkbook(SelectedTrainingYear)); SelectedTrainingMonth = TrainingMonths[0]; TrainingDays = TrainingList.Select(t => t.TrainingDay).ToList(); SelectedTrainingDay = TrainingDays[0]; ExerciseList = new ObservableCollection <ExerciseModel>(TrainingList[TrainingPositionInMonth].Exercises); CurrentlySelectedTrainingDay = DateTime.Now; }
public static List <TrainingModel> GetAllTrainings(string folderPath, string clientName) { var wbHandler = new _WorkbookHandler(folderPath, clientName); List <TrainingModel> allTrainings = new List <TrainingModel>(); foreach (int trainingYear in GetTrainingYears(folderPath, clientName)) { allTrainings.AddRange(GetYearTrainings(wbHandler.getWorkbook(trainingYear))); } return(allTrainings); }
public static void ReadToConsole() { var workbookHandler = new _WorkbookHandler(@"C:\Users\RAMAND\Desktop\c#_trainingTracker", "NewClient"); using (var workbook = workbookHandler.getWorkbook()) { var worksheet = WorksheetChecker.GetOrCreateWorksheet(workbook, "New"); var lastRowUsed = worksheet.LastRowUsed() != null?worksheet.LastRowUsed().RowNumber() : 1; for (int i = 1; i <= lastRowUsed; i++) { Console.WriteLine(); ReadRowToConsole(worksheet, i); } } }
static void Main(string[] args) { #region TxtWriteRead string baseText; using (StreamReader fileReader = new StreamReader(@"C:\Users\RAMAND\Desktop\c#_trainingTracker\training1.txt")) { baseText = fileReader.ReadToEnd(); } using (StreamWriter file = new StreamWriter(@"C:\Users\RAMAND\Desktop\c#_trainingTracker\training1.txt")) { file.WriteLine("abcdef"); } #endregion #region XLground /*using (var workbook = new XLWorkbook()) * { #region Writing to XL * var worksheet = workbook.Worksheets.Add("Sample Sheet"); * worksheet.Cell("A1").Value = "Hello World!"; * worksheet.Cell("B5").Value = "llo World!gdsg"; * worksheet.Cell("C3").FormulaA1 = "=MID(B5, 7, 5)"; * worksheet.Columns("A", "D").AdjustToContents(); * workbook.SaveAs(@"C:\Users\RAMAND\Desktop\c#_trainingTracker\trainingX.xlsx"); #endregion * #region Reading from XL * var newWorksheet = workbook.Worksheet("Sample Sheet"); * Console.WriteLine($"{newWorksheet.Cell("C3").Value}"); #endregion * * }*/ //WorksheetChecker.CheckWorksheets(); //var TM = new TableMaker(); //TM.CreateTable(); //SheetReader.ReadToConsole(); //SheetReader.ReadDates(); #endregion var folderPath = @"C:\Users\RAMAND\Desktop\c#_trainingTracker"; var workbookHandler = new _WorkbookHandler(folderPath, "MP"); var workbook = workbookHandler.getWorkbook(); var worksheetHandler = new _WorksheetHandler(workbook, DateTime.Now.AddMonths(0).Month.ToString()); worksheetHandler.Worksheet.Clear(); var tableMaker = new TableMaker(workbook, worksheetHandler.Worksheet); var tableReader = new TableReader(); List <string[]> tableRows = new List <string[]>(); tableRows.Add(new string[] { "BP", "100", "10", "10", "10000", "HPush" }); tableRows.Add(new string[] { "Cable Row", "100", "10", "10", "10000", "HPull" }); tableRows.Add(new string[] { "OHP", "100", "10", "10", "10000", "VPush" }); tableMaker.CreateTable(new string[] { "Exercise", "Weight", "Sets", "Reps", "Volume", "Type" }, null, tableRows); TrainingDataMapper.AddTraining(new TrainingModel(DateTime.Now), workbook); List <ExerciseModel> exerciseList = new List <ExerciseModel>(); exerciseList.Add(new ExerciseModel("A", 1, 1, 1)); exerciseList.Add(new ExerciseModel("B", 2, 2, 2)); exerciseList.Add(new ExerciseModel("C", 3, 3, 3)); TrainingModel training = new TrainingModel(DateTime.Now.AddDays(1), exerciseList); //tableMaker.InsertTable(tableReader.GetTableStart(worksheetHandler.Worksheet, 7), new string[] { "Exercise", "Weight", "Sets", "Reps", "Volume", "Type" }, null, tableRows); TrainingDataMapper.UpdateTraining(training, workbook, 2); TrainingDataMapper.DeleteTraining(worksheetHandler.Worksheet, 1); //TrainingDataMapper.GetAllTrainings(folderPath, "kk"); //var trg = TrainingDataMapper.GetTraining(worksheetHandler.Worksheet, 1); //worksheetHandler.SheetName = "3"; //var trgs = TrainingDataMapper.GetMonthTrainings(worksheetHandler.Worksheet); //var yTrgs = TrainingDataMapper.GetYearTrainings(workbook); //TrainingDataMapper.DeleteTraining(worksheetHandler.Worksheet, 28); worksheetHandler.Adjust(); workbook.Save(); Console.WriteLine("Finished"); }