Exemple #1
0
        /*
         * 加载word 文件
         *
         * @param DocumentViewer 显示容器
         *
         * @param DControl ctl 控件信息
         */
        public static void loadWord(CWord cWord, string wordFullFile)
        {
            cWord.clearContent();
            string                xpsFile = wordFullFile;
            XpsDocument           xpsDoc  = new XpsDocument(xpsFile, FileAccess.Read);
            FixedDocumentSequence fds     = xpsDoc.GetFixedDocumentSequence();

            System.Windows.Size size = fds.DocumentPaginator.PageSize;

            foreach (DocumentReference DocRef in fds.References)
            {
                bool          bForceReload = false;
                FixedDocument DocFd        = DocRef.GetDocument(bForceReload);

                foreach (PageContent DocFpPc in DocFd.Pages)
                {
                    FixedPage fp = new FixedPage();
                    fp.SetValue(DockPanel.DockProperty, Dock.Top);
                    fp.Width      = size.Width;
                    fp.Height     = size.Height;
                    fp.Background = System.Windows.Media.Brushes.Red;

                    //FixedPage DocFp = DocFpPc.GetPageRoot(bForceReload);
                    //for (int i = 0; i < DocFp.Children.Count; i++)
                    //{
                    //    UIElement DocFpUiElem = DocFp.Children[i];
                    //    DocFp.Children.Remove(DocFpUiElem);
                    //    fp.Children.Add(DocFpUiElem);
                    //}
                    cWord.insertContent(fp);
                }
            }
            xpsDoc.Close();//这个地方需要注意关闭,否则的话会出现莫名其妙的错误
        }
Exemple #2
0
        private void CommandBinding_WordsDatagrid_SpreadData(object sender, ExecutedRoutedEventArgs e)
        {
            DataGrid     ctrl              = ctrl_DataGrid_Words;
            List <CWord> selItems          = ctrl.SelectedItems.Cast <CWord>().ToList <CWord>();
            CWord        firstSelectedItem = selItems.FirstOrDefault();
            DateTime     startTime         = firstSelectedItem.CreatedAt;
            Int32        secondsPerOneItem = 180;
            Int32        itemNo            = 0;

            selItems.ForEach(x => x.CreatedAt = startTime + TimeSpan.FromSeconds(itemNo++ *secondsPerOneItem));
            ctrl.Items.Refresh();
            return;
        }
        private double GetRangeWord(CWord source, CWord target, bool translation)
        {
            var MinDistance   = double.MaxValue;
            var CroppedSource = new CWord();
            var Length        = Math.Min(source.Text.Length, target.Text.Length + 1);

            for (var I = 0; I <= source.Text.Length - Length; I++)
            {
                CroppedSource.Text  = source.Text.Substring(I, Length);
                CroppedSource.Codes = source.Codes.Skip(I).Take(Length).ToList();
                //TODO Подобрать коэффициент, в зависимости от размера справочника (10)
                MinDistance = Math.Min(MinDistance, LevenshteinDistance(CroppedSource, target, CroppedSource.Text.Length == source.Text.Length, translation) + I * 2 / 10.0);
            }
            return(MinDistance);
        }
        private int LevenshteinDistance(CWord source, CWord target, bool fullWord, bool translation)
        {
            if (string.IsNullOrEmpty(source.Text))
            {
                if (string.IsNullOrEmpty(target.Text))
                {
                    return(0);
                }
                return(target.Text.Length * 2);
            }
            if (string.IsNullOrEmpty(target.Text))
            {
                return(source.Text.Length * 2);
            }
            var N        = source.Text.Length;
            var M        = target.Text.Length;
            var Distance = new int[3, M + 1];

            for (var J = 1; J <= M; J++)
            {
                Distance[0, J] = J * 2;
            }
            var CurrentRow = 0;

            for (var I = 1; I <= N; ++I)
            {
                CurrentRow = I % 3;
                var PreviousRow = (I - 1) % 3;
                Distance[CurrentRow, 0] = I * 2;
                for (var J = 1; J <= M; J++)
                {
                    Distance[CurrentRow, J] = Math.Min(Math.Min(
                                                           Distance[PreviousRow, J] + (!fullWord && I == N ? 2 - 1 : 2),
                                                           Distance[CurrentRow, J - 1] + (!fullWord && I == N ? 2 - 1 : 2)),
                                                       Distance[PreviousRow, J - 1] + CostDistanceSymbol(source, I - 1, target, J - 1, translation));

                    if (I > 1 && J > 1 && source.Text[I - 1] == target.Text[J - 2] &&
                        source.Text[I - 2] == target.Text[J - 1])
                    {
                        Distance[CurrentRow, J] = Math.Min(Distance[CurrentRow, J], Distance[(I - 2) % 3, J - 2] + 2);
                    }
                }
            }
            return(Distance[CurrentRow, M]);
        }
Exemple #5
0
        private void CommandBinding_TableItems_Enumerate(object sender, ExecutedRoutedEventArgs e)
        {
            DataGrid ctrl = ctrl_DataGrid_Words;

            Int32 selectedIndex = ctrl.SelectedIndex;

            if (selectedIndex >= 0 && selectedIndex <= Words.Count - 1)
            {
                Int32 itemsSelected    = ctrl_DataGrid_Words.SelectedItems.Count;
                Int32 indexOfFirstItem = selectedIndex;
                CWord word             = Words[indexOfFirstItem];
                Int32 lesson           = word.IndexA_Lesson;
                Int32 order            = word.IndexB_Order;
                ctrl_DataGrid_Words.ItemsSource = null;
                Int32 countOfSelItems = Math.Min(selectedIndex + itemsSelected, Words.Count) - selectedIndex;
                Words.GetRange(selectedIndex, countOfSelItems).ForEach(x => { x.IndexA_Lesson = lesson; x.IndexB_Order = order++; });
                ctrl_DataGrid_Words.ItemsSource = Words;
            }
        }
        private int CostDistanceSymbol(CWord source, int sourcePosition, CWord search, int searchPosition, bool translation)
        {
            if (source.Text[sourcePosition] == search.Text[searchPosition])
            {
                return(0);
            }
            if (translation)
            {
                return(2);
            }
            if (source.Codes[sourcePosition] != 0 && source.Codes[sourcePosition] == search.Codes[searchPosition])
            {
                return(0);
            }

            int        ResultWeight;
            List <int> nearKeys;

            if (!s_distanceCodeKey.TryGetValue(source.Codes[sourcePosition], out nearKeys))
            {
                ResultWeight = 2;
            }
            else
            {
                ResultWeight = nearKeys.Contains(search.Codes[searchPosition]) ? 1 : 2;
            }

            List <char> phoneticGroups;

            if (PhoneticGroupsRus.TryGetValue(search.Text[searchPosition], out phoneticGroups))
            {
                ResultWeight = Math.Min(ResultWeight, phoneticGroups.Contains(source.Text[sourcePosition]) ? 1 : 2);
            }
            if (PhoneticGroupsEng.TryGetValue(search.Text[searchPosition], out phoneticGroups))
            {
                ResultWeight = Math.Min(ResultWeight, phoneticGroups.Contains(source.Text[sourcePosition]) ? 1 : 2);
            }
            return(ResultWeight);
        }
Exemple #7
0
 public CTaskItem(CWord word, string term, string question)
 {
     Word     = word;
     Term     = term;
     Question = question;
 }
Exemple #8
0
 public void SetSelectedWord(CWord tWord, bool tshow)
 {
     _SelectedWord = tWord;
     _wordselect = tshow;
     UpdateScaleFactor();
     Invalidate();
 }