private void FileReader() { pathStock = Directory.GetCurrentDirectory() + "/stock.txt"; pathHistory = Directory.GetCurrentDirectory() + "/history.txt"; using (BinaryReader reader = new BinaryReader(File.Open(pathStock, FileMode.OpenOrCreate))) { while (reader.PeekChar() > -1) { Item tempItem = new Item(); tempItem.Name = reader.ReadString(); tempItem.Count = reader.ReadInt32(); items.Add(tempItem); } } using (BinaryReader reader = new BinaryReader(File.Open(pathHistory, FileMode.OpenOrCreate))) { while (reader.PeekChar() > -1) { Item tempItem = new Item(); tempItem.Name = reader.ReadString(); tempItem.Count = reader.ReadInt32(); ItemForHistory tempHistory = new ItemForHistory(); tempHistory.Item = tempItem; int tempYear = reader.ReadInt32(); int tempMonth = reader.ReadInt32(); int tempDay = reader.ReadInt32(); int tempHour = reader.ReadInt32(); int tempMinute = reader.ReadInt32(); int tempSecond = reader.ReadInt32(); DateTime tempDate = new DateTime(tempYear, tempMonth, tempDay, tempHour, tempMinute, tempSecond); tempHistory.Date = tempDate; tempHistory.ChangeInQuantity = reader.ReadInt32(); itemForHistory.Add(tempHistory); } } }
private void FinishButtonClick(object sender, RoutedEventArgs e) { bool isFound = false; if (operationComboBox.SelectedIndex == 0) { int countTemp = 0; try { int.TryParse(countTextBox.Text, out countTemp); } catch { MessageBox.Show("Поле 'Кол-во' должно содержать только цифры"); } for (int i = 0; i < items.Count; i++) { if (items[i].Name == nameItemTextBox.Text) { items[i].Count += countTemp; ItemForHistory temp = new ItemForHistory(items[i], DateTime.Now, countTemp); itemForHistory.Add(temp); isFound = true; } } if (isFound == false) { Item temp = new Item(Guid.NewGuid(), nameItemTextBox.Text, countTemp); ItemForHistory tempHistory = new ItemForHistory(temp, DateTime.Now, countTemp); itemForHistory.Add(tempHistory); items.Add(temp); } } else if (operationComboBox.SelectedIndex == 1) { int countTemp = 0; try { int.TryParse(countTextBox.Text, out countTemp); } catch { MessageBox.Show("Поле 'Кол-во' должно содержать только цифры"); } for (int i = 0; i < items.Count; i++) { if (items[i].Name == nameItemTextBox.Text) { items[i].Count -= countTemp; ItemForHistory temp = new ItemForHistory(items[i], DateTime.Now, (countTemp - (countTemp * 2))); itemForHistory.Add(temp); isFound = true; } } if (isFound == false) { Item temp = new Item(Guid.NewGuid(), nameItemTextBox.Text, (countTemp - (countTemp * 2))); ItemForHistory tempHistory = new ItemForHistory(temp, DateTime.Now, (countTemp - (countTemp * 2))); itemForHistory.Add(tempHistory); items.Add(temp); } } operationWindow.Close(); }