Exemplo n.º 1
0
        private void updateToolStripMenuItem6_Click(object sender, EventArgs e)
        {
            try
            {
                int index = dataGridView1.SelectedRows[0].Index;
                int id    = 0;

                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }
                Supply   sup   = db.Supplies.Find(id);
                CrSupply supCr = new CrSupply();

                supCr.comboBox1.SelectedItem = Convert.ToString(sup.ProviderId);
                supCr.textBox1.Text          = Convert.ToString(sup.deliveryDate);
                DialogResult result = supCr.ShowDialog(this);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                sup.ProviderId   = Convert.ToInt32(supCr.comboBox1.SelectedItem);
                sup.deliveryDate = Convert.ToDateTime(supCr.textBox1.Text);
                db.SaveChanges();
                dataGridView1.Refresh(); // обновляем грид
                MessageBox.Show("Supply is updated!");
            }
            catch (Exception outOfRange)
            {
                MessageBox.Show("Inconsistent operation !");
            }
        }
Exemplo n.º 2
0
        private void createToolStripMenuItem5_Click(object sender, EventArgs e)
        {
            CrSupply     supCr  = new CrSupply();
            DialogResult result = supCr.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            Supply sup = new Supply();

            sup.ProviderId = Convert.ToInt32(supCr.comboBox1.SelectedItem);
            try
            {
                sup.deliveryDate = Convert.ToDateTime(supCr.textBox1.Text);
            }

            catch (FormatException f)
            {
                MessageBox.Show("Check! Date Format: DD.MM.YYYY. ");
                return;
            }

            db.Supplies.Add(sup);
            db.SaveChanges();
            MessageBox.Show("New supply is added!");
        }