private void BtnRemove_Click(object sender, RoutedEventArgs e) { if (datagrid.SelectedIndex < 11 && datagrid.SelectedIndex >= 0) { products[datagrid.SelectedIndex] = new Product("Empty", 0, -1, 0); } datagrid.ItemsSource = null; datagrid.ItemsSource = products; AddWindow.Serialize(products); }
private void BtnAdd_Click(object sender, RoutedEventArgs e) { int pricePerHour = 0, hour = 0, square = 0; if (int.TryParse(txtboxPricePerHour.Text, out pricePerHour) && int.TryParse(txtboxHour.Text, out hour) && int.TryParse(txtboxSquare.Text, out square) && pricePerHour > 0 && hour > 0 && square > 0 && txtboxName.Text != null) { for (int i = 0; i < 10; i++) { if (products[i].Name == "Empty") { Product prod = new Product(); prod.Hours = Convert.ToDouble(txtboxHour.Text); prod.Name = txtboxName.Text; prod.PricePerHour = Convert.ToDouble(txtboxPricePerHour.Text); prod.Square = Convert.ToDouble(txtboxSquare.Text); prod.Date = DateTime.Now; products[i] = prod; int profit; using (FileStream fs = new FileStream("profit.DAT", FileMode.OpenOrCreate)) { using (StreamReader sr = new StreamReader(fs)) { profit = sr.Read(); } } using (FileStream fs = new FileStream("profit.DAT", FileMode.Create)) { using (StreamWriter sr = new StreamWriter(fs)) { sr.Write(profit + prod.PricePerHour * prod.Hours); } } AddWindow.Serialize(products); this.DialogResult = true; this.Close(); break; } } } }
private void BtnEdit_Click(object sender, RoutedEventArgs e) { int pricePerHour = 0, hour = 0, square = 0; if (int.TryParse(txtboxPricePerHour.Text, out pricePerHour) && int.TryParse(txtboxHour.Text, out hour) && int.TryParse(txtboxSquare.Text, out square) && pricePerHour > 0 && hour > 0 && square > 0 && txtboxName.Text != null ) { if (products[index].Name != "Empty") { Product prod = new Product(); prod.Hours = Convert.ToDouble(txtboxHour.Text); prod.Name = txtboxName.Text; prod.PricePerHour = Convert.ToDouble(txtboxPricePerHour.Text); prod.Square = Convert.ToDouble(txtboxSquare.Text); prod.Date = DateTime.Now; products[index] = prod; } AddWindow.Serialize(products); } else { MessageBox.Show("error"); this.Close(); return; } this.DialogResult = true; this.Close(); }