//write record to record.txt public void WriteRecordToFile() { StreamWriter streamWriter = new StreamWriter(RECORD_FILE_NAME); foreach (Record record in _records) { streamWriter.Write(record.Date.ToString(DATE_FORMAT + " ")); streamWriter.Write(_categoryModel.GetCategoryIndex(record.Category) + " "); streamWriter.WriteLine(record.Amount.ToString()); } streamWriter.Close(); }
//select a record public void SelectRecord(int recordIndex) { RecordIndex = recordIndex; if (recordIndex >= 0) { IsSelectionMode = true; IsAddEnable = false; IsModifyEnable = true; IsDeleteEnable = true; IsCancelEnable = true; ErrorProviderMessage = String.Empty; Record record = _recordModel.Records[recordIndex]; CategoryIndex = _categoryModel.GetCategoryIndex(record.Category); SetAmountAndIncome(record); RecordDate = record.Date; } else { InitializeState(); } RaiseUpdateEvent(); }
//get category index from category name public int GetCategoryIndex(Category category) { return(_categoryModel.GetCategoryIndex(category)); }
public void TestGetCategoryIndex() { CategoryModel categoryModel = new CategoryModel(); Category categoryMovie = new Category(CATEGORY_NAME_MOVIE); Category categoryWork = new Category(CATEGORY_NAME_WORK); categoryModel.AddCategory(categoryMovie); categoryModel.AddCategory(categoryWork); Assert.AreEqual(0, categoryModel.GetCategoryIndex(categoryMovie)); Assert.AreEqual(1, categoryModel.GetCategoryIndex(categoryWork)); }