Exemplo n.º 1
0
        private void createToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            CrOrder      orderCr = new CrOrder();
            DialogResult result  = orderCr.ShowDialog(this);

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

            Order order = new Order();

            order.ProductId  = Convert.ToInt32(orderCr.comboBox1.SelectedItem);
            order.EmployeeId = Convert.ToInt32(orderCr.comboBox2.SelectedItem);
            order.ClientId   = Convert.ToInt32(orderCr.comboBox3.SelectedItem);
            try
            {
                order.DateOfEnd     = Convert.ToDateTime(orderCr.textBox1.Text);
                order.DateOfExecute = Convert.ToDateTime(orderCr.textBox2.Text);
            }
            catch (FormatException f)
            {
                MessageBox.Show("Check! Date Format: DD.MM.YYYY.");
                return;
            }
            db.Orders.Add(order);
            db.SaveChanges();
            MessageBox.Show("New order is added!");
        }
Exemplo n.º 2
0
        private void updateToolStripMenuItem3_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;
                }

                Order order = db.Orders.Find(id);

                CrOrder orderCr = new CrOrder();

                orderCr.comboBox1.SelectedItem = Convert.ToString(order.ProductId);
                orderCr.comboBox2.SelectedItem = Convert.ToString(order.EmployeeId);
                orderCr.comboBox3.SelectedItem = Convert.ToString(order.ClientId);
                orderCr.textBox1.Text          = Convert.ToString(order.DateOfEnd);
                orderCr.textBox2.Text          = Convert.ToString(order.DateOfExecute);

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

                order.ProductId     = Convert.ToInt32(orderCr.comboBox1.SelectedItem);
                order.EmployeeId    = Convert.ToInt32(orderCr.comboBox2.SelectedItem);
                order.ClientId      = Convert.ToInt32(orderCr.comboBox3.SelectedItem);
                order.DateOfEnd     = Convert.ToDateTime(orderCr.textBox1.Text);
                order.DateOfExecute = Convert.ToDateTime(orderCr.textBox2.Text);

                db.SaveChanges();
                dataGridView1.Refresh(); // обновляем грид
                MessageBox.Show("Order is updated!");
            }
            catch (Exception outOfRange)
            {
                MessageBox.Show("Inconsistent operation !");
            }
        }