Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Add addForm = new Add();

            addForm.numericUpDown2.Value = (int)DateTime.Now.Year;
            DialogResult result = addForm.ShowDialog(this);


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

            People people = new People();

            people.Name     = addForm.textBox1.Text;
            people.LastName = addForm.textBox2.Text;
            people.Day      = (int)addForm.numericUpDown1.Value;
            people.Year     = (int)addForm.numericUpDown2.Value;
            db.Peoples.Add(people);
            db.SaveChanges();
            dataGridView1.DataSource = null;
            dataGridView1.Update();
            db.Peoples.Load();
            dataGridView1.DataSource = db.Peoples.AsNoTracking().ToList();
            dataGridView1.Refresh();
        }
Exemplo n.º 2
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                int  DaysRegain;
                int  index     = dataGridView1.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                HolyDay       peoplday   = _db.HolyDays.FirstOrDefault(c => c.Id == id);
                People        people     = _db.Peoples.FirstOrDefault(c => c.Id == peoplday.Peopleid);
                BindingSource DatedbOne  = new BindingSource();
                var           DatedbOneK = from w in _db.HolyDays.Local
                                           where (w.Peopleid == _Id)
                                           select w;

                if (peoplday.IndexDate == true)
                {
                    MessageBox.Show("it is used");
                }
                else
                {
                    // holydayn.SecontDate.Subtract(holydayn.FirstDate).Days
                    DaysRegain = peoplday.People.Day + peoplday.SecontDate.Subtract(peoplday.FirstDate).Days;
                    people.Day = DaysRegain;
                    _db.HolyDays.Remove(peoplday);

                    _db.SaveChanges();

                    DatedbOneK = from w in _db.HolyDays.Local
                                 where (w.Peopleid == _Id)
                                 select w;

                    var qieryAsList = new BindingList <HolyDay>(DatedbOneK.ToList());
                    DatedbOne.DataSource     = qieryAsList;
                    dataGridView1.DataSource = DatedbOne;

                    dataGridView1.Update();
                    dataGridView1.Refresh();
                }
            }
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            Add          addForm = new Add();
            DialogResult result  = addForm.ShowDialog(this);

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

            people.Name     = addForm.textBox1.Text;
            people.LastName = addForm.textBox2.Text;
            people.Day      = (int)addForm.numericUpDown1.Value;
            db.Peoples.Add(people);
            db.SaveChanges();
            MessageBox.Show("New person");
        }
Exemplo n.º 4
0
        private void btnAddnewPerson(object sender, EventArgs e)
        {
            Add          addForm = new Add();
            DialogResult result  = addForm.ShowDialog(this);

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

            people.Id       = Guid.NewGuid();
            people.Name     = addForm.textBox1.Text;
            people.LastName = addForm.textBox2.Text;
            people.Day      = (int)addForm.numericUpDown1.Value;
            people.Year     = (int)addForm.numericUpDown2.Value;
            db.Workers.Add(people);
            db.SaveChanges();
            evenstb();
        }
Exemplo n.º 5
0
        private void btnDeleteDate(object sender, EventArgs e)
        {
            int DaysRegain;

            Guid id = SearcId();

            if (id == Form1.IdError)
            {
                return;
            }
            Vacation      peoplday   = _db.Vacations.FirstOrDefault(c => c.Id == id);
            Person        people     = _db.Workers.FirstOrDefault(c => c.Id == peoplday.Peopleid);
            BindingSource DatedbOne  = new BindingSource();
            var           DatedbOneK = from w in _db.Vacations
                                       where (w.Peopleid == _Id)
                                       select w;

            if (peoplday.IndexDate == true)
            {
                MessageBox.Show("it is used");
            }
            else
            {
                // holydayn.SecontDate.Subtract(holydayn.FirstDate).Days
                DaysRegain = peoplday.People.Day + peoplday.SecontDate.Subtract(peoplday.FirstDate).Days;
                people.Day = DaysRegain;
                _db.Vacations.Remove(peoplday);

                _db.SaveChanges();

                DatedbOneK = from w in _db.Vacations
                             where (w.Peopleid == _Id)
                             select w;

                var qieryAsList = new BindingList <Vacation>(DatedbOneK.ToList());
                DatedbOne.DataSource     = qieryAsList;
                dataGridView1.DataSource = DatedbOne;
                dataGridView1.Update();
                dataGridView1.Refresh();
            }
        }