Example #1
0
        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            var dlgAddProdus = new FormAddProdus();


            /*
             * Noto: Entity framework este o porcarie
             */
            var oc = ((IObjectContextAdapter)Program.Context).ObjectContext;
            var p  = oc.CreateObject <Produs>();


            p.Vanzator      = Program.Vanzator;
            p.DataDeInceput = DateTime.Now.AddMinutes(5.0);
            p.DataDeSfarsit = DateTime.Now.AddMinutes(10.0);

            dlgAddProdus.Produs = p;

            if (dlgAddProdus.ShowDialog() == DialogResult.OK)
            {
                var prods = Program.Vanzator.Produs;
                prods.Add(dlgAddProdus.Produs);
                // this might throw dbexception
                Program.Context.SaveChanges();

                updateBinding();
            }
            else
            {
                produsBindingSource.CancelEdit();
            }
        }
Example #2
0
        private void produsDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Filtru filtru;

            Enum.TryParse <Filtru>(toolStripComboBox1.ComboBox.SelectedValue.ToString(), out filtru);

            if (filtru == Filtru.Vandute)
            {
                return;
            }

            var row = e.RowIndex;

            var dlgAddProdus = new FormAddProdus();

            dlgAddProdus.Text = "Editare Produs";


            var p = (Produs)produsBindingSource.List[row];

            dlgAddProdus.Produs = p;

            if (dlgAddProdus.ShowDialog() == DialogResult.OK)
            {
                var prods = Program.Vanzator.Produs;
                prods.Add(dlgAddProdus.Produs);
                // this might throw dbexception
                Program.Context.SaveChanges();

                updateBinding();
            }
            else
            {
                produsBindingSource.CancelEdit();
            }
        }