private void PersonsListView_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Delete)
            {
                if (PersonsListView.SelectedItem != null &&
                    MessageBox.Show("Удалить группу? У участников будут очищены соотвествующие поля", "Подтверждение удаления", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
                {
                    var ug = PersonsListView.SelectedItem as UchebGruppaViewModel;
                    var vm = DataContext as ObucheniyasViewModel;

                    using (var db = new ProvodnikContext())
                    {
                        var toDelete = (from p in db.Persons
                                        where p.UchebGruppa == ug.UchebGruppa && p.UchebCentr == ug.UchebCentr &&
                                        p.UchebStartDat == ug.UchebStartDat &&
                                        p.UchebEndDat == ug.UchebEndDat
                                        select p).ToList();
                        foreach (var p in toDelete)
                        {
                            p.UchebGruppa   = null;
                            p.UchebCentr    = null;
                            p.UchebStartDat = null;
                            p.UchebEndDat   = null;
                            db.SaveChanges();

                            var pvm = new PersonViewModel(p.Id, false);
                            pvm.FillMessagesAndAlls(p);
                            db.SaveChanges();
                        }
                        vm.List.Remove(ug);
                    }
                }
            }
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            var vm = this.DataContext as MedKomZayavkaViewModel;

            if (!vm.Validator.IsValid)
            {
                MessageBox.Show(string.Join(Environment.NewLine, vm.Validator.ValidationMessages));
            }

            var db = new ProvodnikContext();

            MedKomZayavka p;

            if (vm.Id.HasValue)
            {
                p = db.MedKomZayavki.Single(pp => pp.Id == vm.Id.Value);

                MainWindow.Mapper.Value.Map(vm, p);
                var currents = vm.Persons.Select(pp => pp.PersonId).ToList();
                var toDelete = (from pd in db.MedKomZayavkaPersons
                                where pd.MedKomZayavkaId == p.Id && !currents.Contains(pd.PersonId)
                                select pd);
                db.MedKomZayavkaPersons.RemoveRange(toDelete);
                db.SaveChanges();
            }
            else
            {
                p = new MedKomZayavka();
                MainWindow.Mapper.Value.Map(vm, p);
                db.MedKomZayavki.Add(p);
                db.SaveChanges();
            }

            foreach (var d in vm.Persons)
            {
                MedKomZayavkaPerson pd;
                if (d.Id == null)
                {
                    db.MedKomZayavkaPersons.Add(pd = new MedKomZayavkaPerson()
                    {
                        MedKomZayavkaId = p.Id, PersonId = d.PersonId
                    });
                    db.SaveChanges();
                }
                var person = (from pe in db.Persons where d.PersonId == pe.Id select pe).FirstOrDefault();
                if (person != null)
                {
                    person.IsNaprMedZakazano  = d.IsNaprMedZakazano;
                    person.IsNaprMedPolucheno = d.IsNaprMedPolucheno;
                    person.IsNaprMedVidano    = d.IsNaprMedVidano;
                    db.SaveChanges();
                }
            }
            DialogResult = true;
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var vm = this.DataContext as SendGroupViewModel;
                if (!vm.Validator.IsValid)
                {
                    MessageBox.Show(string.Join(Environment.NewLine, vm.Validator.ValidationMessages));
                }

                var db = new ProvodnikContext();

                SendGroup p;
                if (vm.Id.HasValue)
                {
                    p = db.SendGroups.Single(pp => pp.Id == vm.Id.Value);

                    MainWindow.Mapper.Value.Map(vm, p);
                    var currents = vm.Persons.Select(pp => pp.PersonId).ToList();
                    var toDelete = (from pd in db.SendGroupPersons
                                    where pd.SendGroupId == p.Id && !currents.Contains(pd.PersonId)
                                    select pd);
                    db.SendGroupPersons.RemoveRange(toDelete);
                    db.SaveChanges();
                }
                else
                {
                    p = new SendGroup();
                    MainWindow.Mapper.Value.Map(vm, p);
                    db.SendGroups.Add(p);
                    db.SaveChanges();
                }

                foreach (var d in vm.Persons)
                {
                    SendGroupPerson pd;
                    if (d.Id == null)
                    {
                        db.SendGroupPersons.Add(pd = new SendGroupPerson()
                        {
                            IsMain = d.IsMain, SendGroupId = p.Id, PersonId = d.PersonId
                        });
                        db.SaveChanges();
                    }
                }
                DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка при сохранении" + Environment.NewLine + ex.Message);
            }
        }
Exemple #4
0
        private void buttonOpen_Click(object sender, RoutedEventArgs e)
        {
            string error = null;

            // Rabotnik r = null;
            if (string.IsNullOrWhiteSpace(rabPopup.Text))
            {
                error = "Не выбран пользователь!";
            }
            else
            {
                App.user = new ProvodnikContext().Users.First(pp => pp.Login == rabPopup.Text);   //rabPopup.selElem.param as Rabotnik;
                if (App.user.Wand != passwordBox.Password.GetHashCode().ToString())
                {
                    error = "Не верный пароль!";
                }
            }
            if (rowNewPass.Height.IsAuto && newPasswordBox.Password.Length == 0 && isonload)
            {
                error = "Пустой новый пароль!";
            }
            if (error != null)
            {
                MessageBox.Show(error, "Ошибка"); return;
            }
            /**/ if (passwordBox.Password == "123" && rowNewPass.Height.IsAbsolute &&
                     MessageBox.Show("Рекомендуется сменить стандартный пароль! Сменить сейчас?", "Смена пароля", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                rowNewPass.Height = new GridLength(1, GridUnitType.Auto);
                newPasswordBox.Focus();
                return;
            }
            if (newPasswordBox.Password.Length > 0)
            {
                if (!checkNewPassword(newPasswordBox.Password))
                {
                    MessageBox.Show(error, "Пароль слишком простой");
                    return;
                }

                /* SafeQuery.RunAsync(() =>
                 * SafeQuery.Run(() =>
                 * {*/
                App.user.Wand = newPasswordBox.Password.GetHashCode().ToString();
                using (var db = new ProvodnikContext())
                {
                    db.Users.First(pp => pp.Id == App.user.Id).Wand = App.user.Wand;
                    db.SaveChanges();
                }

                /* }, 15000, () => { })
                 * , () => {//MessageBox.Show("Пароль изменен!");
                 * });*/
            }
Exemple #5
0
 private void PersonsListView_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Delete)
     {
         if (PersonsListView.SelectedItem != null &&
             MessageBox.Show("Удалить?", "Подтверждение удаления", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
         {
             var g = PersonsListView.SelectedItem as PersonShortViewModel;
             vm.PersonList.Remove(g);
             var db = new ProvodnikContext();
             db.Persons.Remove(db.Persons.First(pp => pp.Id == g.Id));
             db.SaveChanges();
         }
     }
 }
Exemple #6
0
 private void Patch_ExecOnceThanDelete()
 {
     using (var db = new ProvodnikContext())
     {
         /*  foreach (var p in db.Persons.Where(x=>x.Fio== "Белых Артём Александрович"))
          * {
          *    //db.PersonDocs.Add(new PersonDoc() { PersonId = p.Id, IsActive = true, DocTypeId = DocConsts.СвидетельствоВакцинации });
          *    if (!new ProvodnikContext().PersonDocs.Any(x=>x.PersonId==p.Id && x.DocTypeId == DocConsts.ЗаключениеВЭК2))
          *        db.PersonDocs.Add(new PersonDoc() { PersonId = p.Id, IsActive = true, DocTypeId = DocConsts.ЗаключениеВЭК2 });
          *    //db.PersonDocs.Add(new PersonDoc() { PersonId = p.Id, IsActive = true, DocTypeId = DocConsts.ТрудоваяКнижка1});
          *    //db.PersonDocs.Add(new PersonDoc() { PersonId = p.Id, IsActive = true, DocTypeId = DocConsts.ТрудоваяКнижка2 });
          *
          * }*/
         /*foreach (var p in db.MedKomZayavki)
          * {
          *  p.BolnicaName = @"Поликлиника: ЧУЗ «КБ «РЖД - Медицина» г.Новосибирск»  
          * Псих.освидетельствование:Медицинский психодиагностический центр ""МЕНТАЛ КОНСАЛТИНГ""";
          *  p.BolnicaAdres = @"Поликлиника: г.Новосибирск, ул.Сибирская, 21
          * Псих.осведетельствование: г.Новосибирск, ул.Красный проспект, 99";
          * }*/
         db.SaveChanges();
     }
 }
Exemple #7
0
      private bool Save()
      {
          vm = this.DataContext as PersonViewModel;
          List <string> errors      = vm.GetModelErrors();
          var           enterErrors = errors.Where(pp => /*!pp.StartsWith("Не прикреплен скан документа") && */ !pp.EndsWith(" не заполнено"));

          if (enterErrors.Any() && MessageBox.Show(string.Join(Environment.NewLine, enterErrors) + Environment.NewLine + "Чтобы поправить, нажмите Отмена", "", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
          {
              return(false);
          }

          try
          {
              //await new ProgressRunner().RunAsync(
              //    new Action<ProgressHandler>((progressChanged) =>
              {
                  //progressChanged(1, "Сохранение");


                  //MessageBox.Show(string.Join(Environment.NewLine, errors));


                  var db = new ProvodnikContext();

                  Person p;
                  if (vm.Id.HasValue)
                  {
                      p = db.Persons.Single(pp => pp.Id == vm.Id.Value);

                      MainWindow.Mapper.Value.Map(vm, p);
                      var currents = vm.Documents.Where(pp => pp.Id.HasValue).Select(pp => pp.Id.Value).ToList();
                      var toDelete = (from pd in db.PersonDocs
                                      where pd.PersonId == p.Id && !currents.Contains(pd.Id)
                                      select pd);
                      db.PersonDocs.RemoveRange(toDelete);
                      db.SaveChanges();
                  }
                  else
                  {
                      db.Persons.Add(p = new Person());  // { Fio = vm.Fio });
                      MainWindow.Mapper.Value.Map(vm, p);
                      db.SaveChanges();
                  }


                  //progressChanged(29, "Загрузка сканов");
                  var share = 70.0 / vm.Documents.Count;
                  using (var client = new FluentFTP.FtpClient())
                  {
                      App.ConfigureFtpClient(client);
                      client.Connect();
                      foreach (var d in vm.Documents)
                      {
                          PersonDoc pd;
                          if (d.Id.HasValue)
                          {
                              pd = db.PersonDocs.Single(pp => pp.Id == d.Id.Value);
                          }
                          else
                          {
                              db.PersonDocs.Add(pd = new PersonDoc()
                                {
                                    PersonId = p.Id, IsActive = true, DocTypeId = d.DocTypeId, FileName = d.FileName
                                });
                              db.SaveChanges();
                          }

                          if (d.FileName == null)
                          {
                              ImageSource source = null;
                              Application.Current.Dispatcher.Invoke((Action)(() =>
                                {
                                    source = d.Bitmap.Source;
                                }));
                              if (source != null)
                              {
                                  var remotePath = $@"ProvodnikDocs/{p.Id.ToString()}/{DateTime.Now.Ticks}.jpg";  // "/1_Иванов";

                                  while (client.Upload(ToByteArray(source as BitmapSource), remotePath, FtpRemoteExists.Overwrite, true)
                                         != FtpStatus.Success)
                                  {
                                  }                          //, FtpVerify.Retry);
                                  pd.FileName = remotePath;
                                  d.FileName  = remotePath;  //for GetScanErrors(true)
                                                             /**/

                                  /*using (WebClient wc = new WebClient() { Credentials = new NetworkCredential(App.CurrentConfig.FtpUser, App.CurrentConfig.FtpPassw) })
                                   * {
                                   *  var fileName = $@"{DateTime.Now.Ticks}.jpg";
                                   *  System.IO.File.Copy(d.LocalFileName, fileName);
                                   *
                                   *  var remotePath = $@"ProvodnikDocs/{p.Id.ToString()}/";// "/1_Иванов";
                                   *                                                        //  wc.DownloadProgressChanged += wc_DownloadProgressChanged;
                                   *                                                        //wc.UploadFile("http://u0920601.plsk.regruhosting.ru/" +remotePath, "STOR", fileName);
                                   *                                                        //wc.UploadData("http://u0920601.plsk.regruhosting.ru/" + remotePath, "STOR", ToByteArray(source as BitmapSource));
                                   *                                                        //HttpContent stringContent = new StringContent(paramString);
                                   *                                                        //HttpContent fileStreamContent = new StreamContent(paramFileStream);
                                   * var res= Upload("http://u0920601.plsk.regruhosting.ru/" + remotePath, ToByteArray(source as BitmapSource));
                                   * //  var ff=  res.Result;
                                   *  pd.FileName = remotePath;
                                   *  d.FileName = remotePath; //for GetScanErrors(true)
                                   * }*/
                              }
                              else
                              {
                                  pd.FileName = null;
                              }
                              db.SaveChanges();
                          }
                          pd.PrinesetK = d.PrinesetK;
                          db.SaveChanges();
                          //progressChanged(share);
                      }
                  }

                  vm.FillMessagesAndAlls(p);
                  db.SaveChanges();
              }  //));
          }
          catch (Exception ex) { MessageBox.Show(ex.Message); }

          //ProgressChanged(100);
          IsChanged = false;
          return(true);
      }