Ejemplo n.º 1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            FileInfo fileInfo = new FileInfo(DATAPATH);

            if (fileInfo.Exists)
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Store));
                using (FileStream fs = new FileStream(DATAPATH, FileMode.Open, FileAccess.Read))
                {
                    store = (Store)serializer.Deserialize(fs);
                }
            }
            else
            {
                GroceryGoods bread   = new GroceryGoods("Bread", new DateTime(2019, 7, 3), new DateTime(2019, 7, 6), new DateTime(2019, 7, 4), 15, 5);
                GroceryGoods sausage = new GroceryGoods("Sausage", new DateTime(2019, 7, 3), new DateTime(2019, 9, 6), new DateTime(2019, 7, 4), 90, 25);
                GroceryGoods beer    = new GroceryGoods("Beer", new DateTime(2019, 7, 3), new DateTime(2020, 9, 6), new DateTime(2019, 7, 4), 50, 5);

                store.StoreGoods.Add(bread);
                store.StoreGoods.Add(sausage);
                store.StoreGoods.Add(beer);
            }

            dataGridView1.Rows.Add(store.StoreGoods.Count);

            if (store.StoreGoods.Count > 0)
            {
                selectedRow = 0;
                FillForm();
            }

            comboBoxSortOrder.DataSource = Enum.GetValues(typeof(StoreSortMode));
        }
Ejemplo n.º 2
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            string errorText     = "";
            double purchasePrice = 0;
            double markup        = 0;

            try
            {
                purchasePrice = Convert.ToDouble(textBoxPurchasePrice.Text);
            }
            catch (Exception)
            {
                errorText += "Не верное значение закупочной стоимости!\n";
            }

            try
            {
                markup = Convert.ToDouble(textBoxMarkup.Text);
            }
            catch (Exception)
            {
                errorText += "Не верное значение наценки!\n";
            }

            if (errorText != "")
            {
                MessageBox.Show(errorText, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            GroceryGoods newGoods = new GroceryGoods(
                textBoxTitle.Text,
                dateTimePickerProdDate.Value,
                dateTimePickerExpDate.Value,
                dateTimePickerPurchaseDate.Value,
                checkBoxDateOfSale.Checked ? DateTime.MinValue : dateTimePickerDateOfSale.Value,
                purchasePrice,
                markup
                );

            store.StoreGoods.Add(newGoods);
            dataGridView1.Rows.Add(1);
        }