Ejemplo n.º 1
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (dgvData.SelectedCells.Count > 0)
            {
                fCountersAdd add             = new fCountersAdd();
                Counters     counter         = context.Counters.Find(dgvData.SelectedCells[0].Value);
                var          typeContersList = from TypesOfCounters in context.TypesOfCounters select TypesOfCounters;
                add.cbTypeCounter.DataSource    = typeContersList.ToList();
                add.cbTypeCounter.ValueMember   = "IdType";
                add.cbTypeCounter.DisplayMember = "Description";
                add.cbTypeCounter.SelectedValue = counter.TypeCounter;

                var housesList = from Houses in context.Houses select Houses;
                add.cbNumberHouse.DataSource    = housesList.ToList();
                add.cbNumberHouse.ValueMember   = "IdHouse";
                add.cbNumberHouse.DisplayMember = "NumberHouse";
                add.cbNumberHouse.SelectedIndex = counter.House;

                add.nudInformation.Value = counter.Information;

                DialogResult result = add.ShowDialog();
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                counter.TypeCounter = (int)add.cbTypeCounter.SelectedValue;
                counter.House       = (int)add.cbNumberHouse.SelectedValue;
                counter.Information = (int)add.nudInformation.Value;
                context.SaveChanges();
                MessageBox.Show("Изменения сохранены");
                LoadData();
            }
        }
Ejemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            fCountersAdd add             = new fCountersAdd();
            var          typeContersList = from TypesOfCounters in context.TypesOfCounters select TypesOfCounters;

            add.cbTypeCounter.DataSource    = typeContersList.ToList();
            add.cbTypeCounter.ValueMember   = "IdType";
            add.cbTypeCounter.DisplayMember = "Description";
            add.cbTypeCounter.SelectedIndex = -1;

            var housesList = from Houses in context.Houses select Houses;

            add.cbNumberHouse.DataSource    = housesList.ToList();
            add.cbNumberHouse.ValueMember   = "IdHouse";
            add.cbNumberHouse.DisplayMember = "NumberHouse";
            add.cbNumberHouse.SelectedIndex = -1;

            DialogResult result = add.ShowDialog();

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

            counter.TypeCounter = (int)add.cbTypeCounter.SelectedValue;
            counter.House       = (int)add.cbNumberHouse.SelectedValue;
            counter.Information = (int)add.nudInformation.Value;
            context.Counters.Add(counter);
            context.SaveChanges();
            MessageBox.Show("Успешное добавление");
            LoadData();
        }