Example #1
0
        private void btn_Edit_Click(object sender, EventArgs e)
        {
            _mode = 2;
            string name = "";

            using (UserContext db = new UserContext(Settings.constr))
            {
                name = db.CalculationTypes.FirstOrDefault(x => x.ID == currentTypeID).Name;
            }

            CalculationTypeName f = new CalculationTypeName(name, 2);

            if (f.ShowDialog(this) == DialogResult.OK)
            {
                using (UserContext db = new UserContext(Settings.constr))
                {
                    var type = db.CalculationTypes.FirstOrDefault(x => x.ID == currentTypeID);
                    type.Name = f.result;
                    db.CalculationTypes.Attach(type);
                    var entry = db.Entry(type);
                    entry.Property(x => x.Name).IsModified = true;
                    db.SaveChanges();
                }
                LoadTypes();
                Init();
            }
        }
Example #2
0
        private void btn_Add_Click(object sender, EventArgs e)
        {
            _mode = 1;
            CalculationTypeName f = new CalculationTypeName("", 1);

            if (f.ShowDialog(this) == DialogResult.OK)
            {
                using (UserContext db = new UserContext(Settings.constr))
                {
                    db.CalculationTypes.Add(new CalculationType {
                        Name = f.result
                    });
                    db.SaveChanges();
                }
                LoadTypes();
                Init();
            }
        }