コード例 #1
0
 private void AddCredite_Load(object sender, EventArgs e)
 {
     using (DepoziteDbContext db = new DepoziteDbContext())
     {
         Lbl_name.Text = db.People.ToList().Last().Name;
     }
 }
コード例 #2
0
        private void AllPersonForm_Load(object sender, EventArgs e)
        {
            using (DepoziteDbContext db = new DepoziteDbContext())
            {
                var People  = db.People.ToList();
                var Credits = db.Credits.ToList();

                var newPerson = People.GroupJoin(Credits, p => p.Id, c => c.Person_Id, (person, credits) => new
                {
                    PersonName          = person.Name,
                    PersonSurname       = person.Surname,
                    PersonPasportNumber = person.PasportNumber,
                    SumAmount           = credits.Sum(x => x.Amount),
                });


                int index = 0;
                foreach (var person in newPerson)
                {
                    Dgw_AllPerson.Rows.Add();
                    Dgw_AllPerson.Rows[index].Cells[0].Value = person.PersonName;
                    Dgw_AllPerson.Rows[index].Cells[1].Value = person.PersonSurname;
                    Dgw_AllPerson.Rows[index].Cells[2].Value = person.PersonPasportNumber;
                    Dgw_AllPerson.Rows[index].Cells[3].Value = person.SumAmount;

                    index++;
                }
            }
        }
コード例 #3
0
 private void Btn_Save_Click(object sender, EventArgs e)
 {
     using (DepoziteDbContext db = new DepoziteDbContext())
     {
         decimal amount;
         Decimal.TryParse(Txb_Price.Text, out amount);
         if (amount != 0)
         {
             db.Credits.Add(new Credit()
             {
                 Amount       = amount,
                 OpenDatetime = Dtp_CrediteDate.Value,
                 Person_Id    = db.People.ToList().Last().Id,
             });
             db.SaveChanges();
         }
     }
 }
コード例 #4
0
        private void Btn_Save_Click(object sender, EventArgs e)
        {
            using (DepoziteDbContext db = new DepoziteDbContext())
            {
                try
                {
                    db.People.Add(new Person()
                    {
                        Name          = Txb_Name.Text,
                        Surname       = Txb_Surname.Text,
                        PasportNumber = Txb_PasportNumber.Text
                    });

                    db.SaveChanges();

                    new AddCredite().ShowDialog();
                }
                catch (DbEntityValidationException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }