Exemplo n.º 1
0
        private void AddContractButton_Click(object sender, RoutedEventArgs e)
        {
            TimeSpan days = TimeSpan.Zero;

            if (contractListView.Items != null)
            {
                for (int i = contractListView.Items.Count - 1; i >= 0; i--)
                {
                    Items Value = (Items)contractListView.Items[i];
                    if (Value.contr.ContractTypeId == 2)
                    {
                        days += Value.contr.EndDate - Value.contr.BeginningDate;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            AddContractWindow contractWind = null;

            if (days.Days > 1826)
            {
                contractWind = new AddContractWindow(false);
            }
            else
            {
                contractWind = new AddContractWindow(true);
            }
            //1826
            //var it = ;

            this.Visibility = Visibility.Collapsed;
            if (contractWind.ShowDialog() == false)
            {
                this.Visibility = Visibility.Visible;
                return;
            }
            if (contractWind.DialogResult.HasValue && contractWind.DialogResult.Value)
            {
                Contract contract = new Contract();
                contract.ContractTypeId   = contractTypeRepositoty.Get(p => p.Name == contractWind.typeOfCon).First().ID;
                contract.BeginningDate    = (DateTime)contractWind.beginningDt;
                contract.EndDate          = (DateTime)contractWind.endDt;
                contract.WorkerId         = worker.ID;
                contract.OrderNum         = contractWind.orderN;
                contract.ArtistCategoryId = artistCategoryRepositoty.Get(p => p.Name == contractWind.artistCat).First().ID;
                contract.Position         = contractWind.posit;

                contractRepositoty.Insert(contract);

                contractListView.Items.Add(new Items
                {
                    contr = contract
                });
            }
            this.Visibility = Visibility.Visible;
            contractListView.Items.Refresh();
        }
Exemplo n.º 2
0
        private void AddWorkerButton_Click(object sender, RoutedEventArgs e)
        {
            Worker worker = new Worker();

            worker.Name              = this.name.Text;
            worker.DepartamentID     = departamentRepositoty.Get(p => p.Name == this.departament.Text).Select(p => p.ID).First();
            worker.BirthPlace        = this.birthPlace.Text;
            worker.Surname           = surname.Text;
            worker.Patronymic        = patronymic.Text;
            worker.RegistrationPlace = registrationPlace.Text;
            worker.BirthPlace        = birthPlace.Text;
            worker.DateOfBirth       = (DateTime)dateOfBirth.SelectedDate;
            worker.Nationality       = nationality.Text;
            worker.Education         = education.Text;
            worker.Sex           = sex.Text == "мужской" ? true : false;
            worker.MaritalStatus = maritalStatus.Text == "холост" ? true : false;
            worker.PhoneNum      = phoneNum.Text;
            worker.Email         = email.Text;

            workerRepositoty.Insert(worker);
            workerRepositoty.AddToCache(worker, worker.ID);

            if (contractListView.Items != null)
            {
                for (int i = 0; i < contractListView.Items.Count; i++)
                {
                    Items    Value = (Items)contractListView.Items[i];
                    Contract cnt   = new Contract();

                    cnt.ContractTypeId   = contractTypeRepositoty.Get(p => p.Name == Value.typeName).First().ID;
                    cnt.BeginningDate    = Value.beginDate;
                    cnt.EndDate          = Value.endDate;
                    cnt.WorkerId         = worker.ID;
                    cnt.OrderNum         = Value.OrderNum;
                    cnt.ArtistCategoryId = artistCategoryRepositoty.Get(p => p.Name == Value.artistCategory).First().ID;
                    cnt.Position         = Value.Position;

                    contractRepositoty.Insert(cnt);
                }
            }

            MessageBox.Show("добавлен");
            Close_Click(sender, e);
        }