private void RefreshDataGrid() { FileStream file = File.OpenRead(_fileName); dgvCandyBoxes.Rows.Clear(); while (file.Length != file.Position) { CandyBox candyBox = CandyBox.GetNextFromStream(file); AddRowToDataGrid(candyBox); } file.Close(); }
private void buttonAdd_Click(object sender, EventArgs e) { double weight = 0, cost = 0; var checkFields = textBoxNameCandyBox.Text != "" && textBoxProducerCandyBox.Text != "" && double.TryParse(textBoxCostCandyBox.Text, out cost) && double.TryParse(textBoxWeight.Text, out weight); if (checkFields) { var candyBox = new CandyBox(textBoxNameCandyBox.Text, weight, cost, textBoxProducerCandyBox.Text, pickerIssueDate.Value, (int)numericShelfTimeCandyBox.Value); OnAddCandyBox(candyBox); Close(); } else { MessageBox.Show(this, "Проверьте корректность входных значений!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void AddRowToDataGrid(CandyBox candyBox) { dgvCandyBoxes.Rows.Add(candyBox.Name, candyBox.Weight, candyBox.Cost, candyBox.Producer, candyBox.IssueDate.ToShortDateString(), candyBox.ShelfLife); }