Ejemplo n.º 1
0
        private void apply()
        {
            var transform = _session.Tenant.TransformFor(StoreOptions.PatchDoc);
            var storage   = _session.StorageFor(typeof(T));

            ISqlFragment where;
            if (_filter == null)
            {
                var statement = new StatementOperation(storage, null);
                statement.ApplyFiltering(_session, _filterExpression);

                where = statement.Where;
            }
            else
            {
                where = storage.FilterDocuments(null, _filter);
            }

            var operation = new PatchOperation(transform, storage, where, Patch, _session.Serializer)
            {
                PossiblyPolymorhpic = PossiblyPolymorphic
            };

            _session.QueueOperation(operation);
        }
Ejemplo n.º 2
0
        public void UndoDeleteWhere <T>(Expression <Func <T, bool> > expression) where T : notnull
        {
            assertNotDisposed();


            var documentStorage = StorageFor <T>();

            if (documentStorage.DeleteFragment is HardDelete)
            {
                throw new InvalidOperationException("Un-deleting documents can only be done against document types configured to be soft-deleted");
            }
            var deletion = new StatementOperation(documentStorage, new UnSoftDelete(documentStorage));


            var @where = deletion.ApplyFiltering(this, expression);

            // This is hokey, but you need to remove the normally applied filter
            // to exclude soft-deleted documents because that's exactly what you do want
            // here
            if (@where is CompoundWhereFragment compound)
            {
                var filter = compound.Children.OfType <ExcludeSoftDeletedFilter>().FirstOrDefault();
                if (filter != null)
                {
                    compound.Remove(filter);
                }
            }


            _workTracker.Add(deletion);
        }
Ejemplo n.º 3
0
        public void HardDeleteWhere <T>(Expression <Func <T, bool> > expression) where T : notnull
        {
            assertNotDisposed();

            var documentStorage = StorageFor <T>();
            var deletion        = new StatementOperation(documentStorage, documentStorage.HardDeleteFragment);

            deletion.ApplyFiltering(this, expression);

            _workTracker.Add(deletion);
        }
Ejemplo n.º 4
0
        public ColumnFilter BuildStatement <TEntity>(string key, string value, StatementOperation operation = StatementOperation.Equals) where TEntity : BaseEntity
        {
            var baseTableName = this.queryBuilder.GetTableName <TEntity>();
            var result        = new ColumnFilter();

            result.KeyName = $"{baseTableName}.{key}";
            result.Filter  = this.statementBuilder[operation].Invoke(result.KeyName, $"@{result.Params.Count}");
            result.Params.Add(new SqlParameter($"@{result.Params.Count}", value));

            return(result);
        }
Ejemplo n.º 5
0
        public void Where <T>(string transformName, Expression <Func <T, bool> > @where)
        {
            var transform = Session.Options.TransformFor(transformName);

            var storage   = Session.StorageFor <T>();
            var operation = new DocumentTransformOperationFragment(storage, transform);

            var statement = new StatementOperation(storage, operation);

            statement.ApplyFiltering(Session, @where);
            Session.QueueOperation(statement);
        }
Ejemplo n.º 6
0
        public void All <T>(string transformName)
        {
            var transform = Session.Options.TransformFor(transformName);
            var storage   = _tenant.Database.StorageFor <T>();

            var operation = new DocumentTransformOperationFragment(storage, transform);
            var statement = new StatementOperation(storage, operation);

            // To bake in the default document filtering here
            statement.CompileLocal(Session);
            Session.QueueOperation(statement);
        }
Ejemplo n.º 7
0
        public void Where <T>(string transformName, Expression <Func <T, bool> > @where)
        {
            var transform = _tenant.TransformFor(transformName);
            var mapping   = _tenant.MappingFor(typeof(T));

            using var session = (DocumentSessionBase)_store.LightweightSession();
            var operation = new DocumentTransformOperationFragment(mapping, transform);
            var statement = new StatementOperation(session.StorageFor <T>(), operation);

            statement.ApplyFiltering(session, @where);
            session.UnitOfWork.Add(statement);
            session.SaveChanges();
        }
Ejemplo n.º 8
0
        public void All <T>(string transformName)
        {
            var transform = _tenant.TransformFor(transformName);
            var storage   = _tenant.StorageFor <T>();

            using var session = (DocumentSessionBase)_store.LightweightSession();
            var operation = new DocumentTransformOperationFragment(storage, transform);
            var statement = new StatementOperation(storage, operation);

            // To bake in the default document filtering here
            statement.CompileLocal(session);
            session.WorkTracker.Add(statement);
            session.SaveChanges();
        }
        private void GetOperationid(object sender, object data)
        {
            Days = 0;

            SelectedLeg = 0;
            Doctors     = new ObservableCollection <Docs>();
            //OperationType = Data.OperationType.Get(Operation.OperationTypeId).LongName;
            //TextResultCancle = "Итоги операции";
            CurrentDocument = new StatementOperation();

            Operation   = Data.Operation.Get((int)data);
            operationId = (int)data;
            //DateTime bufTime = DateTime.Parse(Operation.Time);

            //Operation.Date = new DateTime(Operation.Date.Year, Operation.Date.Month, Operation.Date.Day, bufTime.Hour, bufTime.Minute, bufTime.Second);
            Date = Data.OperationDateTime.Get(Operation.Datetime_id.Value).Datetime;

            CurrentPatient = Data.Patients.Get(Operation.PatientId);

            foreach (var doc in Data.Doctor.GetAll)
            {
                Doctors.Add(new Docs(doc));
            }
            if (Operation.StatementId != null && Operation.StatementId != 0)
            {
                IsDocAdded      = Visibility.Visible;
                TextForDoWhat   = "";
                CurrentDocument = Data.StatementOperation.Get(Operation.StatementId.Value);
                Days            = CurrentDocument.CountDays;
                SelectedLeg     = CurrentDocument.FirstIsRightIfNull;
                if (CurrentDocument.DoctorId != 0)
                {
                    var doc = Data.Doctor.Get(CurrentDocument.DoctorId);
                    foreach (var docs in Doctors)
                    {
                        if (docs.doc.Id == doc.Id)
                        {
                            SelectedDoctor = Doctors.IndexOf(docs);
                        }
                    }
                }
            }
            else
            {
                SelectedDoctor = 0;
                IsDocAdded     = Visibility.Hidden;
                TextForDoWhat  = "Сформируйте или загрузите документ";
            }
        }
Ejemplo n.º 10
0
        private void transformOne <T>(string transformName, ISqlFragment filter)
        {
            var transform = _tenant.TransformFor(transformName);
            var mapping   = _tenant.MappingFor(typeof(T));

            using var session = (DocumentSessionBase)_store.LightweightSession();
            var operation = new DocumentTransformOperationFragment(mapping, transform);
            var statement = new StatementOperation(session.StorageFor <T>(), operation);

            // To bake in the default document filtering here
            statement.Where = filter;
            statement.CompileLocal(session);
            session.UnitOfWork.Add(statement);
            session.SaveChanges();
        }
Ejemplo n.º 11
0
        private void transformOne <T>(string transformName, ISqlFragment filter)
        {
            var transform = Session.Options.TransformFor(transformName);

            var storage   = Session.StorageFor <T>();
            var operation = new DocumentTransformOperationFragment(storage, transform);

            var statement = new StatementOperation(storage, operation)
            {
                Where = filter
            };

            // To bake in the default document filtering here
            statement.CompileLocal(Session);
            Session.QueueOperation(statement);
        }
Ejemplo n.º 12
0
 public ColumnFilter BuildStatement <TEntity>(string key, int value, StatementOperation operation = StatementOperation.Equals) where TEntity : BaseEntity
 {
     return(this.BuildStatement <TEntity>(key, value.ToString(), operation));
 }
Ejemplo n.º 13
0
 public string Build(string key, string value, StatementOperation operation)
 {
     return(this.statementBuilder[operation].Invoke(key, value));
 }
        public ViewModelCreateStatement(NavigationController controller) : base(controller)
        {
            LeftOrRight = new List <string>();
            LeftOrRight.Add("Правая нижняя конечность");
            LeftOrRight.Add("Левая нижняя конечность");

            MessageBus.Default.Subscribe("GetOperationResultForCreateStatement", GetOperationid);
            HasNavigation    = false;
            SaveWordDocument = new DelegateCommand(
                () =>
            {
                try
                {
                    if (!string.IsNullOrWhiteSpace(FileName))
                    {
                        byte[] bteToBD        = File.ReadAllBytes(FileName);
                        StatementOperation Hv = new StatementOperation();
                        //bool tester = true;

                        if (CurrentDocument.Id != 0)
                        {
                            Hv = Data.StatementOperation.Get(CurrentDocument.Id);
                            CurrentDocument.DocTemplate = bteToBD;
                            Hv.DocTemplate        = bteToBD;
                            Hv.FirstIsRightIfNull = SelectedLeg;
                            Hv.CountDays          = Days;
                            Hv.DoctorId           = Doctors[SelectedDoctor].doc.Id;
                            Data.Complete();
                        }
                        else
                        {
                            Hv.FirstIsRightIfNull       = SelectedLeg;
                            Hv.CountDays                = Days;
                            Hv.DocTemplate              = bteToBD;
                            Hv.DoctorId                 = Doctors[SelectedDoctor].doc.Id;
                            CurrentDocument.DocTemplate = bteToBD;
                            Data.StatementOperation.Add(Hv);

                            Data.Complete();
                            Operation             = Data.Operation.Get(Operation.Id);
                            Operation.StatementId = Hv.Id;
                            //    Operation.StatementId = Hv.Id;
                            CurrentDocument.Id = Hv.Id;
                            Data.Complete();
                            //   MessageBus.Default.Call("SetIdOfOverview", null, CurrentDocument.Id);
                        }

                        TextForDoWhat = "Изменения в " + _fileNameOnly + " были сохранены";
                        CurrentSavePanelViewModel.PanelOpened = false;
                    }
                }
                catch
                {
                    MessageBox.Show("Закройте документ");
                }
            }
                );



            CurrentSelectDoctorPanelViewModel = new SclerozPanelViewModel(this);
            RevertSelectDoctorCommand         = new DelegateCommand(() =>
            {
                CurrentSelectDoctorPanelViewModel.PanelOpened = false;
            });
            OpenSelectDoctorCommand = new DelegateCommand(() =>
            {
                CurrentSelectDoctorPanelViewModel.ClearPanel();
                CurrentSelectDoctorPanelViewModel.PanelOpened = true;
            });
            OpenFile = new DelegateCommand(
                () =>
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter         = "Word Documents (.docx)|*.docx|Word Template (.dotx)|*.dotx|All Files (*.*)|*.*";
                openFileDialog.ValidateNames  = true;
                openFileDialog.FilterIndex    = 1;
                if (openFileDialog.ShowDialog() == true)
                {
                    _fileNameOnly         = openFileDialog.SafeFileName;
                    FileName              = openFileDialog.FileName;
                    byte[] bteToBD        = File.ReadAllBytes(FileName);
                    StatementOperation Hv = new StatementOperation();

                    if (CurrentDocument.Id != 0)
                    {
                        Hv = Data.StatementOperation.Get(CurrentDocument.Id);

                        Hv.DocTemplate        = bteToBD;
                        Hv.DoctorId           = Doctors[SelectedDoctor].doc.Id;
                        Hv.FirstIsRightIfNull = SelectedLeg;
                        Hv.CountDays          = Days;
                        Data.Complete();
                        CurrentDocument.Id = Hv.Id;
                    }
                    else
                    {
                        Hv.DocTemplate        = bteToBD;
                        Hv.DoctorId           = Doctors[SelectedDoctor].doc.Id;
                        Hv.FirstIsRightIfNull = SelectedLeg;
                        Hv.CountDays          = Days;
                        Data.StatementOperation.Add(Hv);

                        Data.Complete();
                        CurrentDocument.Id    = Hv.Id;
                        Operation             = Data.Operation.Get(Operation.Id);
                        Operation.StatementId = Hv.Id;
                        Data.Complete();
                    }
                    GetOperationid(null, Operation.Id);

                    TextForDoWhat = "Был загружен документ " + _fileNameOnly;
                }
            }
                );
            OpenWordDocument = new DelegateCommand(
                () =>
            {
                int togle = 0;

                FileName = System.IO.Path.GetTempPath() + "Выписка_заготовка.docx";

                _fileNameOnly = "Выписка_заготовка.docx";

                byte[] bte = CurrentDocument.DocTemplate;

                for (; ;)
                {
                    try
                    {
                        File.WriteAllBytes(FileName, bte);

                        break;
                    }
                    catch
                    {
                        togle        += 1;
                        FileName      = System.IO.Path.GetTempPath() + "Выписка_заготовка" + togle + ".docx";
                        _fileNameOnly = "Выписка_заготовка" + togle + ".docx";
                    }
                }
                TextForDoWhat = "Был открыт документ " + _fileNameOnly + ". Для сохранения изменений в документе сохраните данные в Word, закройте документ и нажмите кнопку \"Сохранить изменения\".";

                Process.Start("WINWORD.EXE", FileName);
            }
                );


            LostFocus = new DelegateCommand <object>(
                (sender) =>
            {
                if (string.IsNullOrWhiteSpace(((TextBox)sender).Text))
                {
                    ((TextBox)sender).Text = "0";
                    Days = 0;
                }
            }
                ); ClickOnWeight = new DelegateCommand <object>(
                (sender) =>
            {
                if (((TextBox)sender).Text == "0")
                {
                    ((TextBox)sender).Text = "";
                }
            }
                );


            ToCreateStatementCommand = new DelegateCommand(
                () =>
            {
                int togle     = 0;
                _fileNameOnly = "";
                // string fileName = System.IO.Path.GetTeWmpPath() + Guid.NewGuid().ToString() + ".docx";
                _fileNameOnly   = "Выписка_заготовка.docx";
                string fileName = System.IO.Path.GetTempPath() + "Выписка_заготовка.docx";
                byte[] bte      = Data.doc_template.Get(1).DocTemplate;
                //File.WriteAllBytes(fileName, bte);
                for (; ;)
                {
                    try
                    {
                        if (togle == 0)
                        {
                            File.WriteAllBytes(System.IO.Path.GetTempPath() + "Выписка_заготовка.docx", bte);
                            _fileNameOnly = "Выписка_заготовка.docx";
                        }
                        else
                        {
                            File.WriteAllBytes(System.IO.Path.GetTempPath() + "Выписка_заготовка" + togle + ".docx", bte);
                            _fileNameOnly = "Выписка_заготовка" + togle + ".docx";
                        }
                        break;
                    }
                    catch
                    {
                        togle        += 1;
                        fileName      = System.IO.Path.GetTempPath() + "Выписка_заготовка" + togle + ".docx";
                        _fileNameOnly = "Выписка_заготовка" + togle + ".docx";
                    }
                }


                using (DocX document = DocX.Load(fileName))
                {
                    FileName = fileName;
                    document.ReplaceText("«ФИО»", CurrentPatient.Sirname + " " + CurrentPatient.Name + " " + CurrentPatient.Patronimic);
                    string day1  = "0";
                    string day2  = "0";
                    string mnth1 = "0";
                    string mnth2 = "0";
                    string year1 = CurrentPatient.Birthday.Year.ToString();
                    string year2 = CurrentPatient.Birthday.Year.ToString();
                    if (CurrentPatient.Birthday.Day.ToString().ToCharArray().Length == 1)
                    {
                        day1 = "0";
                        day2 = CurrentPatient.Birthday.Day.ToString().ToCharArray()[0].ToString();
                    }
                    else
                    {
                        day1 = CurrentPatient.Birthday.Day.ToString().ToCharArray()[0].ToString();
                        day2 = CurrentPatient.Birthday.Day.ToString().ToCharArray()[1].ToString();
                    }    //«сутки»
                    if (CurrentPatient.Birthday.Month.ToString().ToCharArray().Length == 1)
                    {
                        mnth1 = "0";
                        mnth2 = CurrentPatient.Birthday.Month.ToString().ToCharArray()[0].ToString();
                    }
                    else
                    {
                        mnth1 = CurrentPatient.Birthday.Month.ToString().ToCharArray()[0].ToString();
                        mnth2 = CurrentPatient.Birthday.Month.ToString().ToCharArray()[1].ToString();
                    }
                    try
                    {
                        year1 = CurrentPatient.Birthday.Year.ToString().ToCharArray()[2].ToString();
                        year2 = CurrentPatient.Birthday.Year.ToString().ToCharArray()[3].ToString();
                        document.ReplaceText("Г1", year1);
                        document.ReplaceText("Г2", year2);
                    }
                    catch
                    {
                        document.ReplaceText("Г1", CurrentPatient.Birthday.Year.ToString());
                    }

                    document.ReplaceText("Ч1", day1);
                    document.ReplaceText("Ч2", day2);
                    document.ReplaceText("М1", mnth1);
                    document.ReplaceText("М2", mnth2);

                    document.ReplaceText("область", "область " + Data.Regions.Get(CurrentPatient.Region).Str);
                    if (CurrentPatient.District != null)
                    {
                        document.ReplaceText("район", "район " + Data.Districts.Get(CurrentPatient.District.Value).Str);
                    }
                    else
                    {
                        document.ReplaceText("район,", "");
                    }
                    document.ReplaceText("місто(село)", "місто(село) " + Data.Cities.Get(CurrentPatient.City).Str);
                    document.ReplaceText("вулиця", "вулиця " + Data.Streets.Get(CurrentPatient.Street).Str);
                    document.ReplaceText("будинок", "будинок " + CurrentPatient.House);
                    document.ReplaceText("кв.", "кв. " + CurrentPatient.Flat.ToString());
                    if (CurrentPatient.Work != null)
                    {
                        document.ReplaceText("МестоРаботы", CurrentPatient.Work);
                    }
                    else
                    {
                        document.ReplaceText("МестоРаботы", "-");
                    }


                    string patologis    = "";
                    string diabet       = "";
                    string lettersLeft  = "";
                    string lettersRight = "";
                    string leftDiag     = "", rightDiag = "";

                    List <DiagnosisType> LeftDiagnosisList = new List <DiagnosisType>();

                    foreach (var diag in Data.Diagnosis.GetAll.Where(s => s.isLeft == true && s.id_operation == Operation.Id).ToList())
                    {
                        LeftDiagnosisList.Add(Data.DiagnosisTypes.Get(diag.id_diagnosis.Value));
                    }

                    List <DiagnosisType> RightDiagnosisList = new List <DiagnosisType>();



                    foreach (var diag in Data.Diagnosis.GetAll.Where(s => s.isLeft == false && s.id_operation == Operation.Id).ToList())
                    {
                        RightDiagnosisList.Add(Data.DiagnosisTypes.Get(diag.id_diagnosis.Value));
                    }


                    var PatologysOfCurrPatient = Data.Patology.GetAll.ToList().Where(s => s.id_пациента == CurrentPatient.Id && s.isArchivatied == false).ToList();

                    int zz = 0;
                    foreach (var x in PatologysOfCurrPatient)
                    {
                        //zz++;
                        if (zz != PatologysOfCurrPatient.Count - 1)
                        {
                            patologis += GetStrFixedForDocumemnt(Data.PatologyType.Get(x.id_патологии).Str) + ", ";
                        }
                        else
                        {
                            patologis += GetStrFixedForDocumemnt(Data.PatologyType.Get(x.id_патологии).Str);
                        }
                        zz++;
                    }

                    char[] chararrbuF12 = patologis.ToCharArray();

                    if (chararrbuF12.Length != 0 && chararrbuF12[0] == ' ')
                    {
                        patologis = patologis.Remove(0, 1);
                    }
                    if (chararrbuF12.Length != 0 && chararrbuF12[chararrbuF12.Length - 1] == '.')
                    {
                    }
                    else
                    {
                        patologis += ".";
                    }
                    if (!string.IsNullOrWhiteSpace(patologis) && patologis != ".")
                    {
                        document.ReplaceText("Патологии", "Патологии: " + patologis + "\n");
                    }
                    else
                    {
                        document.ReplaceText("Патологии", "");
                    }
                    //if(patologis == ".")
                    //{
                    //    document.ReplaceText("Патологии", "");
                    //}
                    diabet += CurrentPatient.Sugar;
                    if (!string.IsNullOrWhiteSpace(diabet))
                    {
                        document.ReplaceText("Диабет", "Сахарный диабет: " + diabet + "\n");
                    }
                    else
                    {
                        document.ReplaceText("Диабет", "");
                    }

                    var ExamsOfCurrPatient = Data.Examination.GetAll.ToList().Where(s => s.PatientId == CurrentPatient.Id).ToList();

                    if (ExamsOfCurrPatient.Count > 0)
                    {
                        DateTime MaxExam                   = ExamsOfCurrPatient.Max(s => s.Date);
                        var ExamsOfCurrPatientLatest       = ExamsOfCurrPatient.Where(s => s.Date == MaxExam).ToList();
                        ExaminationLeg leftLegExam         = Data.ExaminationLeg.Get(ExamsOfCurrPatientLatest[0].idLeftLegExamination.Value);
                        ExaminationLeg rightLegExam        = Data.ExaminationLeg.Get(ExamsOfCurrPatientLatest[0].idRightLegExamination.Value);
                        List <ComplainsType> ComplainsList = new List <ComplainsType>();

                        foreach (var diag in Data.ComplanesObs.GetAll.Where(s => s.id_Examination == ExamsOfCurrPatientLatest[0].Id).ToList())
                        {
                            ComplainsList.Add(Data.ComplainsTypes.Get(diag.id_Complains));
                        }
                        string complanes = "";
                        if (ComplainsList != null)
                        {
                            int xxx = 0;
                            foreach (var rec in ComplainsList)
                            {
                                if (xxx == 0)
                                {
                                    complanes += GetStrFixedForDocumemnt(rec.Str);
                                }
                                else
                                {
                                    complanes += ", " + GetStrFixedForDocumemnt(rec.Str);
                                }
                                xxx++;
                            }
                            char[] chararrbuF1 = complanes.ToCharArray();
                            if (chararrbuF1.Length != 0 && chararrbuF1[0] == ' ')
                            {
                                complanes = complanes.Remove(0, 1);
                            }
                            if (chararrbuF1.Length != 0 && chararrbuF1[chararrbuF1.Length - 1] == '.')
                            {
                            }
                            else
                            {
                                complanes += ".";
                            }
                        }
                        document.ReplaceText("«Жалобы»", complanes);



                        //document.ReplaceText("«Жалобы»", complanes);



                        Letters bufLetter = new Letters();
                        if (leftLegExam.C != null)
                        {
                            bufLetter    = Data.Letters.Get(leftLegExam.C.Value);
                            lettersLeft += bufLetter.Leter + bufLetter.Text1 + " ";
                        }
                        if (leftLegExam.A != null)
                        {
                            bufLetter    = Data.Letters.Get(leftLegExam.A.Value);
                            lettersLeft += bufLetter.Leter + bufLetter.Text1 + " ";
                        }
                        if (leftLegExam.E != null)
                        {
                            bufLetter    = Data.Letters.Get(leftLegExam.E.Value);
                            lettersLeft += bufLetter.Leter + bufLetter.Text1 + " ";
                        }
                        if (leftLegExam.P != null)
                        {
                            bufLetter    = Data.Letters.Get(leftLegExam.P.Value);
                            lettersLeft += bufLetter.Leter + bufLetter.Text1 + " ";
                        }

                        if (rightLegExam.C != null)
                        {
                            bufLetter     = Data.Letters.Get(rightLegExam.C.Value);
                            lettersRight += bufLetter.Leter + bufLetter.Text1 + " ";
                        }
                        if (rightLegExam.A != null)
                        {
                            bufLetter     = Data.Letters.Get(rightLegExam.A.Value);
                            lettersRight += bufLetter.Leter + bufLetter.Text1 + " ";
                        }
                        if (rightLegExam.E != null)
                        {
                            bufLetter     = Data.Letters.Get(rightLegExam.E.Value);
                            lettersRight += bufLetter.Leter + bufLetter.Text1 + " ";
                        }
                        if (rightLegExam.P != null)
                        {
                            bufLetter     = Data.Letters.Get(rightLegExam.P.Value);
                            lettersRight += bufLetter.Leter + bufLetter.Text1 + " ";
                        }
                    }
                    else
                    {
                        document.ReplaceText("«Жалобы»", "");
                    }


                    int day12       = Data.OperationDateTime.Get(Operation.Datetime_id.Value).Datetime.Day;
                    int mnth12      = Data.OperationDateTime.Get(Operation.Datetime_id.Value).Datetime.Month;
                    string mnthStr1 = "";
                    string dayStr1  = "";
                    if (mnth12 < 10)
                    {
                        mnthStr1 += "0" + mnth12.ToString();
                    }
                    else
                    {
                        mnthStr1 = mnth12.ToString();
                    }

                    if (day12 < 10)
                    {
                        dayStr1 += "0" + day12.ToString();
                    }
                    else
                    {
                        dayStr1 = day12.ToString();
                    }
                    document.ReplaceText("«Дата»", dayStr1 + "." + mnthStr1 + "." + Data.OperationDateTime.Get(Operation.Datetime_id.Value).Datetime.Year.ToString());
                    int xx = 0;
                    foreach (var x in LeftDiagnosisList)
                    {
                        if (xx == 0)
                        {
                            leftDiag += GetStrFixedForDocumemnt(x.Str);
                        }
                        else
                        {
                            leftDiag += ", " + GetStrFixedForDocumemnt(x.Str);
                        }
                        xx++;
                    }
                    char[] chararrbuF = leftDiag.ToCharArray();
                    if (chararrbuF.Length != 0 && chararrbuF[0] == ' ')
                    {
                        leftDiag = leftDiag.Remove(0, 1);
                    }
                    //if (chararrbuF.Length != 0 && chararrbuF[chararrbuF.Length - 1] == '.')
                    //{ }
                    //else
                    //{
                    //    leftDiag += ".";
                    //}
                    leftDiag += " левой нижней конечности.";

                    xx = 0;
                    foreach (var x in RightDiagnosisList)
                    {
                        if (xx == 0)
                        {
                            rightDiag += GetStrFixedForDocumemnt(x.Str);
                        }
                        else
                        {
                            rightDiag += ", " + GetStrFixedForDocumemnt(x.Str);
                        }
                        xx++;
                    }
                    chararrbuF = rightDiag.ToCharArray();
                    if (chararrbuF.Length != 0 && chararrbuF[0] == ' ')
                    {
                        rightDiag = rightDiag.Remove(0, 1);
                    }
                    //if (chararrbuF.Length != 0 && chararrbuF[chararrbuF.Length - 1] == '.')
                    //{ }
                    //else
                    //{
                    //    rightDiag += ".";
                    //}

                    rightDiag += " правой нижней конечности.";



                    int day        = Data.OperationDateTime.Get(Operation.Datetime_id.Value).Datetime.Day;
                    int mnth       = Data.OperationDateTime.Get(Operation.Datetime_id.Value).Datetime.Month;
                    string mnthStr = "";
                    string dayStr  = "";
                    if (mnth < 10)
                    {
                        mnthStr += "0" + mnth.ToString();
                    }
                    else
                    {
                        mnthStr = mnth.ToString();
                    }

                    if (day < 10)
                    {
                        dayStr += "0" + day.ToString();
                    }
                    else
                    {
                        dayStr = day.ToString();
                    }
                    document.ReplaceText("«Дата_операции»", dayStr + "." + mnthStr + "." + Data.OperationDateTime.Get(Operation.Datetime_id.Value).Datetime.Year.ToString());

                    string leftP = "", rightP = "", operationType = "";
                    int i1       = 0, i2 = 0;

                    foreach (var Diagnosis in Data.OperationTypeOperations.GetAll)
                    {
                        if (Diagnosis.id_operation == Operation.Id)
                        {
                            if (Diagnosis.isLeft == true)
                            {
                                if (i1 != 0)
                                {
                                    leftP += ", " + Data.OperationType.Get(Diagnosis.id_operation_type.Value).Str;
                                }
                                else
                                {
                                    leftP += Data.OperationType.Get(Diagnosis.id_operation_type.Value).Str;
                                }
                                i1++;
                            }
                            else
                            {
                                if (i2 != 0)
                                {
                                    rightP += ", " + Data.OperationType.Get(Diagnosis.id_operation_type.Value).Str;
                                }
                                else
                                {
                                    rightP += Data.OperationType.Get(Diagnosis.id_operation_type.Value).Str;
                                }
                                i2++;
                            }
                        }
                    }

                    //if (Operation.OnWhatLegOp == "0")
                    //{
                    // document.ReplaceText("буквы_2Ж", lettersLeft);
                    //  document.ReplaceText("буквы_1Ж", "");
                    document.ReplaceText("«Заключение_11»", rightDiag + "\n");
                    document.ReplaceText("«Заключение_22»", "Диагноз: " + leftDiag + "\n");
                    //document.ReplaceText("«Заключение_1»", rightDiag + "\n");

                    //document.ReplaceText("«Заключение_2»", "");

                    document.ReplaceText(" буквы_1", lettersRight);
                    document.ReplaceText(" буквы_2", lettersLeft);

                    //}
                    //if (Operation.OnWhatLegOp == "1")
                    //{
                    //  //  document.ReplaceText("буквы_1Ж", lettersRight);
                    ////    document.ReplaceText("буквы_2Ж", "");
                    //    document.ReplaceText("«Заключение_11Ж»", rightDiag + "\n");

                    //    document.ReplaceText("«Заключение_22Ж»", "");
                    //    document.ReplaceText("«Заключение_2»", leftDiag + "\n");
                    //    document.ReplaceText("«Заключение_1»", "");

                    //    document.ReplaceText(" буквы_1", "");

                    //    document.ReplaceText(" буквы_2", lettersLeft);
                    //}
                    //if (Operation.OnWhatLegOp == "2")
                    //{
                    //    document.ReplaceText("«Заключение_11Ж»", rightDiag + "\n");
                    //   // document.ReplaceText("буквы_1Ж", lettersRight);
                    //    document.ReplaceText("«Заключение_22Ж»", leftDiag + "\n");
                    //   // document.ReplaceText("буквы_2Ж", lettersLeft);
                    //    document.ReplaceText("«Заключение_1»", "");
                    //    document.ReplaceText("«Заключение_2»", "");
                    //    document.ReplaceText(" буквы_1", "");
                    //    document.ReplaceText(" буквы_2", "");
                    //}
                    if (SelectedLeg == 0)
                    {
                        if (Operation.OnWhatLegOp == "0")
                        {
                            document.ReplaceText(" «Заключение_11Ж»", "");
                            document.ReplaceText(" «Заключение_22Ж»", leftDiag + "\n");
                            document.ReplaceText("«Заключение_1»", rightDiag + "\n");
                            document.ReplaceText("«Заключение_2»", "");
                        }
                        if (Operation.OnWhatLegOp == "1")
                        {
                            document.ReplaceText(" «Заключение_11Ж»", rightDiag + "\n");

                            document.ReplaceText(" «Заключение_22Ж»", "");
                            document.ReplaceText("«Заключение_2»", "Диагноз: " + leftDiag + "\n");
                            document.ReplaceText("«Заключение_1»", "");
                        }
                        if (Operation.OnWhatLegOp == "2")
                        {
                            document.ReplaceText(" «Заключение_11Ж»", rightDiag + "\n");
                            // document.ReplaceText("буквы_1Ж", lettersRight);
                            document.ReplaceText(" «Заключение_22Ж»", leftDiag + "\n");
                            // document.ReplaceText("буквы_2Ж", lettersLeft);
                            document.ReplaceText("«Заключение_1»", "");
                            document.ReplaceText("«Заключение_2»", "");
                        }
                    }
                    else
                    {
                        if (Operation.OnWhatLegOp == "0")
                        {
                            document.ReplaceText(" «Заключение_11Ж»", leftDiag + "\n");
                            document.ReplaceText(" «Заключение_22Ж»", "");
                            document.ReplaceText("«Заключение_1»", "");
                            document.ReplaceText("«Заключение_2»", "Диагноз: " + rightDiag + "\n");
                        }
                        if (Operation.OnWhatLegOp == "1")
                        {
                            document.ReplaceText(" «Заключение_11Ж»", "");

                            document.ReplaceText(" «Заключение_22Ж»", rightDiag + "\n");
                            document.ReplaceText("«Заключение_2»", "");
                            document.ReplaceText("«Заключение_1»", leftDiag + "\n");
                        }
                        if (Operation.OnWhatLegOp == "2")
                        {
                            document.ReplaceText(" «Заключение_11Ж»", leftDiag + "\n");
                            // document.ReplaceText("буквы_1Ж", lettersRight);
                            document.ReplaceText(" «Заключение_22Ж»", rightDiag + "\n");
                            // document.ReplaceText("буквы_2Ж", lettersLeft);
                            document.ReplaceText("«Заключение_1»", "");
                            document.ReplaceText("«Заключение_2»", "");
                        }
                        //document.ReplaceText("«Заключение_1»", leftDiag);
                        //document.ReplaceText("«Заключение_2»", rightDiag);
                        //document.ReplaceText("буквы_1", lettersLeft);
                        //document.ReplaceText("буквы_2", lettersRight);
                    }

                    if (Operation.OnWhatLegOp == "0")
                    {
                        operationType = "На левую нижнюю конечность :" + leftP;
                        document.ReplaceText("«IsLeft»", "ЛЕВАЯ");
                    }
                    if (Operation.OnWhatLegOp == "1")
                    {
                        operationType = "На правую нижнюю конечность :" + rightP;
                        document.ReplaceText("«IsLeft»", "ПРАВАЯ");
                    }
                    if (Operation.OnWhatLegOp == "2")
                    {
                        operationType = "На левую нижнюю конечность :" + leftP + " " + "На правую нижнюю конечность :" + rightP;
                    }

                    document.ReplaceText("«Операция2»", operationType);
                    //if (!string.IsNullOrWhiteSpace(Data.OperationType.Get(Operation.OperationTypeId).ShortName))
                    //    document.ReplaceText("«Операция2»", Data.OperationType.Get(Operation.OperationTypeId).ShortName);
                    //else
                    //    document.ReplaceText("«Операция2»", Data.OperationType.Get(Operation.OperationTypeId).LongName);

                    day     = DateTime.Now.Day;
                    mnth    = DateTime.Now.Month;
                    mnthStr = "";
                    dayStr  = "";
                    if (mnth < 10)
                    {
                        mnthStr += "0" + mnth.ToString();
                    }
                    else
                    {
                        mnthStr = mnth.ToString();
                    }

                    if (day < 10)
                    {
                        dayStr += "0" + day.ToString();
                    }
                    else
                    {
                        dayStr = day.ToString();
                    }
                    document.ReplaceText("«сутки»", Days.ToString());
                    //document.ReplaceText("сутки", "суток");
                    document.ReplaceText("“сегодняшнеечисломесяц”  ", dayStr + "." + mnthStr);
                    document.ReplaceText("«год»", DateTime.Now.Year.ToString());
                    document.ReplaceText("«Врач»", Doctors[SelectedDoctor].ToString());

                    //область

                    document.Save();
                    byte[] bteToBD        = File.ReadAllBytes(fileName);
                    StatementOperation Hv = new StatementOperation();
                    if (Operation.StatementId != null && Operation.StatementId != 0)
                    {
                        Hv = Data.StatementOperation.Get(Operation.StatementId.Value);
                        Hv.FirstIsRightIfNull = SelectedLeg;
                        Hv.CountDays          = Days;
                        Hv.DocTemplate        = bteToBD;
                        Hv.DoctorId           = Doctors[SelectedDoctor].doc.Id;
                        Data.Complete();
                    }
                    else
                    {
                        Hv.DocTemplate        = bteToBD;
                        Hv.DoctorId           = Doctors[SelectedDoctor].doc.Id;
                        Hv.CountDays          = Days;
                        Hv.FirstIsRightIfNull = SelectedLeg;
                        Data.StatementOperation.Add(Hv);

                        Data.Complete();
                        Operation             = Data.Operation.Get(Operation.Id);
                        Operation.StatementId = Hv.Id;
                        Data.Complete();
                    }
                    //Release this document from memory.
                    IsDocAdded = Visibility.Visible;

                    Process.Start("WINWORD.EXE", fileName);
                    GetOperationid(null, Operation.Id);
                    TextForDoWhat = "Вы создали новый документ " + _fileNameOnly;
                }
                CurrentSelectDoctorPanelViewModel.PanelOpened = false;
                //MessageBus.Default.Call("GetOperationResultForCreateStatement", this, operationId);
                // Controller.NavigateTo<ViewModelCreateStatement>();
            }
                );
            ToOperationOverviewCommand = new DelegateCommand(
                () =>
            {
                if (!string.IsNullOrWhiteSpace(FileName))
                {
                    MessageBoxResult dialogResult = MessageBox.Show("Вы сохранили изменения в документе?", "", MessageBoxButton.YesNo);
                    if (dialogResult == MessageBoxResult.Yes)
                    {
                        MessageBus.Default.Call("GetOperationForOverwiev", this, operationId);
                        //GetObsForOverview
                        Controller.NavigateTo <ViewModelOperationOverview>();
                        FileName = "";
                    }
                }
                else
                {
                    MessageBus.Default.Call("GetOperationForOverwiev", this, operationId);
                    //GetObsForOverview
                    Controller.NavigateTo <ViewModelOperationOverview>();
                    FileName = "";
                }
            }
                );
            CurrentSavePanelViewModel = new SclerozPanelViewModel(this);

            OpenAddSaveCommand = new DelegateCommand(() =>
            {
                if (!string.IsNullOrWhiteSpace(FileName))
                {
                    CurrentSavePanelViewModel.ClearPanel();
                    CurrentSavePanelViewModel.PanelOpened = true;
                }
                else
                {
                    MessageBox.Show("Сначала откройте документ");
                }
            });

            RevertSaveCommand = new DelegateCommand(() =>
            {
                CurrentSavePanelViewModel.PanelOpened = false;
                // Handled = false;
            });
        }