private void SpouseSibGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SpouseSibling SelectedSib = ((SpouseSibling)SpouseSibGrid.SelectedItem);

            if (SelectedSib != null)
            {
                ChildName.Text = SelectedSib.Name.ToString();
                Phone.Text     = SelectedSib.Phone.ToString();
            }
        }
        private void DeleteBtn_Click(object sender, RoutedEventArgs e)
        {
            SpouseSibling SelectedSib = ((SpouseSibling)SpouseSibGrid.SelectedItem);


            if (SelectedSib != null)
            {
                _context.Entry(SelectedSib).State = System.Data.Entity.EntityState.Deleted;
                _context.SaveChanges();
                Clear();
                refreshBtn_Click();
            }
        }
        private void EditBtn_Click(object sender, RoutedEventArgs e)
        {
            SpouseSibling SelectedSib = ((SpouseSibling)SpouseSibGrid.SelectedItem);

            if (SelectedSib != null)
            {
                SelectedSib.Name  = ChildName.Text.Trim();
                SelectedSib.Phone = Convert.ToInt64(Phone.Text);

                _context.Entry(SelectedSib).State = System.Data.Entity.EntityState.Modified;
                _context.SaveChanges();
                refreshBtn_Click();
                Clear();
            }
        }
Esempio n. 4
0
        private void ReportBtn_Click(object sender, RoutedEventArgs e)
        {
            if (Fundamental.IsChecked.GetValueOrDefault() == true)
            {
                Member Descised = ((Member)MemGrid.SelectedItem);
                if (Descised != null)
                {
                    try
                    {
                        _context.Losses.Add(Loss);
                        _context.Entry(Descised).State = System.Data.Entity.EntityState.Deleted;
                        //Descised.Children = _context.Childs.Where(c => c.ParentId == Descised.Id).ToList();
                        //Descised.Siblings = _context.Siblings.Where(c => c.ParentId == Descised.Id).ToList();
                        //Descised.SpouseSiblings = _context.SpouseSiblings.Where(c => c.ParentId == Descised.Id).ToList();
                        //foreach (var child in Descised.Children)
                        //{
                        //    _context.Entry(child).State = EntityState.Modified;

                        //}
                        //foreach (var child in Descised.Siblings)
                        //{
                        //    _context.Entry(child).State = EntityState.Modified;
                        //}
                        //foreach (var child in Descised.SpouseSiblings)
                        //{
                        //    _context.Entry(child).State = EntityState.Modified;
                        //}
                        //Spouse spo = _context.spouses.FirstOrDefault(s => s.ParentId == Descised.Id);
                        //if(spo != null)
                        //{
                        //_context.Entry(spo).State = EntityState.Modified;
                        //}
                        _context.SaveChanges();
                    }
                    catch (Exception msg)
                    {
                        Console.WriteLine(msg.Message);
                    }
                }
            }
            long Type = Convert.ToInt64(LossType.SelectedIndex);

            if (Type == 1)
            {
                Child Descised = (Child)(AliveFamilyMembers.SelectedItem);
                Loss.Description = Description.Text.Trim();
                Member Selected = ((Member)MemGrid.SelectedItem);
                Loss.ParentId  = Selected.Id;
                Loss.PaidMoney = PayChild;
                Edir.Capital  -= PayChild;
                if (Edir.Capital < 0)
                {
                    ErrorMessage er = new ErrorMessage();
                    er.MessageText.Text = "Can not provide such amount";
                    er.Show();
                    Loss.PaidMoney = -1 * Edir.Capital;
                    Edir.Capital   = 0;
                }
                Loss.Date = Convert.ToDateTime(DateOfDeath.Text);
                _context.Losses.Add(Loss);
                _context.Entry(Descised).State = System.Data.Entity.EntityState.Deleted;
                _context.Entry(Edir).State     = System.Data.Entity.EntityState.Modified;
                _context.SaveChanges();
                Condolence();
            }
            else if (Type == 0)
            {
                Member Selected = ((Member)MemGrid.SelectedItem);
                Spouse Descised = _context.spouses.FirstOrDefault(s => s.ParentId == Selected.Id);
                Loss.Description = Description.Text.Trim();
                if (Edir.Capital - PaySpou < 0)
                {
                    ErrorMessage er = new ErrorMessage();
                    er.MessageText.Text = "Can not provide such amount";
                    er.Show();
                    Loss.PaidMoney = Edir.Capital;
                    Edir.Capital   = 0;
                }
                else
                {
                    Edir.Capital  -= PaySpou;
                    Loss.PaidMoney = PaySpou;
                }
                Loss.ParentId = Selected.Id;
                Loss.Date     = Convert.ToDateTime(DateOfDeath.Text);
                _context.Losses.Add(Loss);
                _context.Entry(Descised).State = System.Data.Entity.EntityState.Deleted;
                _context.SaveChanges();
                _context.Entry(Edir).State = System.Data.Entity.EntityState.Modified;
                _context.SaveChanges();

                Condolence();
            }
            else if (Type == 2)
            {
                Sibling Descised = (Sibling)(AliveFamilyMembers.SelectedItem);
                Loss.Description = Description.Text.Trim();
                Member Selected = ((Member)MemGrid.SelectedItem);
                if (Edir.Capital - PaySib < 0)
                {
                    ErrorMessage er = new ErrorMessage();
                    er.MessageText.Text = "Can not provide such amount";
                    er.Show();
                    Loss.PaidMoney = Edir.Capital;
                    Edir.Capital   = 0;
                }
                else
                {
                    Loss.PaidMoney = PaySib;
                    Edir.Capital  -= PaySib;
                }

                Loss.ParentId = Selected.Id;
                Loss.Date     = Convert.ToDateTime(DateOfDeath.Text);
                _context.Losses.Add(Loss);
                _context.Entry(Descised).State = System.Data.Entity.EntityState.Deleted;
                _context.Entry(Edir).State     = System.Data.Entity.EntityState.Modified;
                _context.SaveChanges();

                Condolence();
            }
            else if (Type == 3)
            {
                SpouseSibling Descised = (SpouseSibling)(AliveFamilyMembers.SelectedItem);
                Loss.Description = Description.Text.Trim();
                Member Selected = ((Member)MemGrid.SelectedItem);
                if (Edir.Capital - PaySib < 0)
                {
                    ErrorMessage er = new ErrorMessage();
                    er.MessageText.Text = "Can not provide such amount";
                    er.Show();
                    Loss.PaidMoney = Edir.Capital;
                    Edir.Capital   = 0;
                }
                else
                {
                    Loss.PaidMoney = PaySib;
                    Edir.Capital  -= PaySib;
                }

                Loss.ParentId = Selected.Id;
                Loss.Date     = Convert.ToDateTime(DateOfDeath.Text);
                _context.Losses.Add(Loss);
                _context.Entry(Edir).State     = System.Data.Entity.EntityState.Modified;
                _context.Entry(Descised).State = System.Data.Entity.EntityState.Deleted;
                _context.SaveChanges();
                Condolence();
            }
            else if (Type == 4)
            {
                Loss.Description = Description.Text.Trim();
                Member Selected = ((Member)MemGrid.SelectedItem);
                if (Edir.Capital - PayParents < 0)
                {
                    ErrorMessage er = new ErrorMessage();
                    er.MessageText.Text = "Can not provide such amount";
                    er.Show();
                    Loss.PaidMoney = Edir.Capital;
                    Edir.Capital   = 0;
                }
                else
                {
                    Edir.Capital  -= PayParents;
                    Loss.PaidMoney = PayParents;
                }

                Loss.ParentId = Selected.Id;
                Loss.Date     = Convert.ToDateTime(DateOfDeath.Text);
                _context.Entry(Edir).State = System.Data.Entity.EntityState.Modified;
                _context.Losses.Add(Loss);
                _context.SaveChanges();
                Condolence();
            }
        }