Esempio n. 1
0
        private void BtnAddItem_Click(object sender, RoutedEventArgs e)
        {
            bool flag = false;

            for (int i = 0; i < 10; i++)
            {
                if (products[i].Name == "Empty")
                {
                    flag = true;
                }
            }

            if (flag == false)
            {
                MessageBox.Show("All cell's are locked");
            }
            else
            {
                AddWindow window = new AddWindow(products);
                if (window.ShowDialog().Value == true)
                {
                    XmlSerializer xml = new XmlSerializer(typeof(Product[]));
                    using (FileStream fs = new FileStream("Products.xml", FileMode.Open))
                    {
                        products = (Product[])xml.Deserialize(fs);
                    }
                }
            }
            datagrid.ItemsSource = null;
            datagrid.ItemsSource = products;
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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;
                    }
                }
            }
        }
Esempio n. 4
0
        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();
        }