protected void GridViewGroup_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row   = GridViewGroup.Rows[e.RowIndex];
            int         id    = Convert.ToInt32(((TextBox)(row.Cells[1].Controls[0])).Text);
            Group       group = _db.Groups.Where(f => f.Id == id).FirstOrDefault();

            group.GroupName       = e.NewValues["GroupName"].ToString();
            group.StaffId         = int.Parse(e.NewValues["StaffId"].ToString());
            group.CountOfChildren = int.Parse(e.NewValues["CountOfChildren"].ToString());
            group.YearOfCreation  = int.Parse(e.NewValues["YearOfCreating"].ToString());
            group.GroupType_Id    = int.Parse(e.NewValues["TypeId"].ToString());
            _db.SaveChanges();
            GridViewGroup.EditIndex = -1;

            ShowData(strFindGroup);
        }
        protected void GridViewStaff_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row   = GridViewStaff.Rows[e.RowIndex];
            int         id    = Convert.ToInt32(((TextBox)(row.Cells[1].Controls[0])).Text);
            Staff       staff = _db.Staffs.Where(f => f.Id == id).FirstOrDefault();

            staff.FullName   = e.NewValues["FullName"].ToString();
            staff.Adress     = e.NewValues["Adress"].ToString();
            staff.Phone      = Convert.ToInt32(e.NewValues["Phone"].ToString());
            staff.PositionId = int.Parse(e.NewValues["PositionId"].ToString());
            staff.Info       = e.NewValues["Info"].ToString();
            staff.Reward     = e.NewValues["Reward"].ToString();
            _db.SaveChanges();
            GridViewStaff.EditIndex = -1;

            ShowData(strFindStaff);
        }
Exemple #3
0
        public void SetCredentials()
        {
            CredentialsForServer.Login      = Login;
            CredentialsForServer.Password   = Password;
            CredentialsForServer.DataSource = DataSource;
            CredentialsForServer.DataBase   = DataBase;

            try
            {
                using (KindergartenContext db = new KindergartenContext())
                {
                    db.Database.Migrate();
                    if (db.Users.ToList().Count() == 0 && db.Employees.ToList().Count() == 0)
                    {
                        db.Employees.Add(new Employee {
                            Name = "Администратор", Lastname = "Администратор"
                        });
                        db.SaveChanges();
                        db.Users.Add(new User {
                            Login = "******", Password = "******", LevelAccess = 1, EmployeeId = db.Employees.Local.First().Id
                        });
                        db.SaveChanges();
                    }

                    if (db.Menus.ToList().Count() == 0)
                    {
                        db.Menus.Add(new Menu {
                            Name = "Меню 1"
                        });
                        db.SaveChanges();
                    }

                    MessageBox.Show("Подключение успешно создано!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка! " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private async void ChangeGroupType()
        {
            ChangeGroupTypeCommand.NotifyCanExecute(false);
            var groupType = await Task.Run(() =>
            {
                var context     = new KindergartenContext();
                var group       = context.Groups.First(g => g.Id == CurrentGroup.Id);
                group.GroupType = SelectedGroupType | (CurrentGroup.GroupType & Groups.Finished); // save Finished flag
                context.SaveChanges();
                return(group.GroupType);
            });

            Pipe.SetParameter("group_type_result", groupType);
            ChangeGroupTypeCommand.NotifyCanExecute(true);
            Finish();
        }
Exemple #5
0
        private async void AddGroup(Group group)
        {
            if (!group.IsValid())
            {
                return;
            }

            AddGroupCommand.NotifyCanExecute(false);
            await Task.Run(() =>
            {
                var context = new KindergartenContext();
                context.Groups.Add(group);
                context.SaveChanges();
            });

            AddGroupCommand.NotifyCanExecute(true);
            Pipe.SetParameter("added_group_result", group);
            Finish();
        }
        private async void AddTarif(Tarif tarif)
        {
            if (!tarif.IsValid())
            {
                return;
            }

            AddTarifCommand.NotifyCanExecute(false);
            await Task.Run(() =>
            {
                var context = new KindergartenContext();
                context.Tarifs.Add(tarif);
                context.SaveChanges();
            });

            AddTarifCommand.NotifyCanExecute(true);

            Pipe.SetParameter("tarif_result", tarif);
            Finish();
        }
Exemple #7
0
        private async void Save()
        {
            if (CurrentGroup == SelectedGroup)
            {
                return;
            }

            SaveCommand.NotifyCanExecute(false);

            await Task.Run(() =>
            {
                var context   = new KindergartenContext();
                var child     = context.Children.First(c => c.Id == _currentChild.Id);
                child.GroupId = SelectedGroup.Id;

                context.SaveChanges();
            });

            SaveCommand.NotifyCanExecute(true);
            Pipe.SetParameter("saved_group_result", SelectedGroup);
            Finish();
        }
Exemple #8
0
        private void AddExpense()
        {
            if (MoneyExpense <= 0)
            {
                return;
            }

            var expense = new Expense
            {
                ExpenseType = (ExpenseType)this["SelectedExpenseType"],
                Money       = MoneyExpense,
                Description = DescriptionExpense
            };

            var context = new KindergartenContext();

            context.Expenses.Add(expense);
            context.SaveChanges();
            App.Logger.Trace("New expense added");

            Pipe.SetParameter("added_expense", expense);
            Finish();
        }
Exemple #9
0
 public void Insert(T entity)
 {
     entity.NotNull();
     Entities.Add(entity);
     _context.SaveChanges();
 }
        private async void AddChild(Child child)
        {
            if (!child.IsValid())
            {
                MessageBox.Show("Не все поля заполнены/пункты выбраны", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            var now = DateTime.Now;

            if (ChildAdditionDate > now)
            {
                MessageBox.Show("Ввод будущей даты добавления запрещён", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (child.BirthDate > ChildAdditionDate)
            {
                MessageBox.Show("Дата рождения должна быть меньше даты добавления", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (SelectedOther == null && SelectedMother == null && SelectedFather == null)
            {
                MessageBox.Show("Должен быть выбран хотя бы один из родителей либо иной представитель", "Некорректный выбор", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (BroughtParent == Parents.Father && SelectedFather == null ||
                BroughtParent == Parents.Mother && SelectedMother == null ||
                BroughtParent == Parents.Other && SelectedOther == null)
            {
                MessageBox.Show("Выберите существующего родителя");
                return;
            }
            AddChildCommand.NotifyCanExecute(false);

            ParentChild broghtParent    = null;
            EnterChild  enterChild      = null;
            bool        needAddPayments = StartedToPayFromAdditionDate;
            await Task.Run(() =>
            {
                string imageFileName = null;
                try
                {
                    if (_imageUri != null)
                    {
                        var savePath           = Path.Combine(Settings.AppFilePaths.ChildImages, CommonHelper.GetUniqueString());
                        imageFileName          = ImageUtil.SaveImage(_imageUri, savePath);
                        child.Person.PhotoPath = Path.GetFileName(imageFileName);
                    }

                    // groups and tarifs (in OnLoaded) are from other context
                    child.GroupId = child.Group.Id;
                    child.Group   = null;
                    child.TarifId = child.Tarif.Id;
                    enterChild    = new EnterChild {
                        Child = child, EnterDate = ChildAdditionDate
                    };
                    child.LastEnterChild = enterChild;

                    var context = new KindergartenContext();

                    if (needAddPayments)
                    {
                        // to no debt range add

                        if (now.Year != ChildAdditionDate.Year && now.Month != ChildAdditionDate.Month)
                        {
                            // 1) the first fictitious payment for start range
                            context.MonthlyPayments.Add(new MonthlyPayment
                            {
                                ChildId             = child.Id,
                                PaymentDate         = ChildAdditionDate,
                                MoneyPaymentByTarif = 0, // 0 - because to make no debt
                            });
                        }

                        // 2) the second fictitious payment for end range
                        context.MonthlyPayments.Add(new MonthlyPayment
                        {
                            ChildId = child.Id, PaymentDate = now, MoneyPaymentByTarif = child.Tarif.MonthlyPayment, DebtAfterPaying = InitialDebt,
                        });
                    }
                    child.Tarif = null;

                    context.EnterChildren.Add(enterChild);

                    if (SelectedFather != null)
                    {
                        var parentChild = new ParentChild {
                            Child = child, ParentId = SelectedFather.Id, ParentType = Parents.Father
                        };
                        context.ParentChildren.Add(parentChild);
                        if (BroughtParent == Parents.Father)
                        {
                            broghtParent = parentChild;
                        }
                    }
                    if (SelectedMother != null)
                    {
                        var parentChild = new ParentChild {
                            Child = child, ParentId = SelectedMother.Id, ParentType = Parents.Mother
                        };
                        context.ParentChildren.Add(parentChild);
                        if (BroughtParent == Parents.Mother)
                        {
                            broghtParent = parentChild;
                        }
                    }
                    if (SelectedOther != null)
                    {
                        var parentChild = new ParentChild {
                            Child = child, ParentId = SelectedOther.Id, ParentType = Parents.Other, ParentTypeText = OtherParentText
                        };
                        context.ParentChildren.Add(parentChild);
                        if (BroughtParent == Parents.Other)
                        {
                            broghtParent = parentChild;
                        }
                    }
                    context.SaveChanges();
                    App.Logger.Debug("Child added");
                }
                catch
                {
                    if (imageFileName != null)
                    {
                        File.Delete(imageFileName);
                    }
                    throw;
                }
            });

            Pipe.SetParameter("saved_child_result", child);
            Pipe.SetParameter("brought_parent", broghtParent);
            Pipe.SetParameter("enter", enterChild);
            // ReSharper disable once RedundantExplicitArraySize
            var parents = new ParentChild[3]
            {
                new ParentChild {
                    Parent = SelectedFather, ParentType = Parents.Father
                },
                new ParentChild {
                    Parent = SelectedMother, ParentType = Parents.Mother
                },
                new ParentChild {
                    Parent = SelectedOther, ParentType = Parents.Other
                }
            };

            Pipe.SetParameter("parents", parents);
            AddChildCommand.NotifyCanExecute(true);
            Finish();
        }