Example #1
0
        private void beautifyButton_Click(object sender, EventArgs e)
        {
            InitDictionaryManagerPaths();
            if (excelApp == null)
            {
                string pathToExcel = FileSaver.OpenExcelFile();
                if (pathToExcel == "")
                {
                    MessageBox.Show("Файл " + DM.PathToExcel + " не найден");
                    return;
                }
                excelApp = new ExcelManager();
                excelApp.Open(DM.PathToExcel);
            }

            string textToAnalyze = FileSaver.ReadTextToAnalize();

            if (textToAnalyze == "")
            {
                MessageBox.Show("Файл " + DM.fileToAnalizePath + " не найден");
                return;
            }

            WordsFormer allWords = new WordsFormer();

            allWords.analyzeAll(textToAnalyze);

            List <string> lWords      = excelApp.GetColumn(DM.Columns.word);
            List <string> lfreq       = excelApp.GetColumn(DM.Columns.freq);
            List <string> lLvl        = excelApp.GetColumn(DM.Columns.level);
            List <string> lSrs        = excelApp.GetColumn(DM.Columns.src);
            List <string> ltrans1     = excelApp.GetColumn(DM.Columns.trans1);
            List <string> ltrans2     = excelApp.GetColumn(DM.Columns.trans2);
            List <string> ltrans3     = excelApp.GetColumn(DM.Columns.trans3);
            List <string> ldefinition = excelApp.GetColumn(DM.Columns.definition);


            string addFreq;
            string miniDict = "";

            for (int i = 0; i < allWords.dict.Count; i++)
            {
                string word = allWords.dict[i].word;

                this.Text = i.ToString();

                int ind = lWords.IndexOf(word);
                if (ind < 0)
                {
                    continue;
                }

                addFreq = lfreq[ind];

                Stylizer styleze = new Stylizer();

                //string translation = ltrans1[ind] + ',' + ltrans2[ind] + ',' + ltrans3[ind];
                string translation = ltrans1[ind] + ',' + ltrans2[ind] + ',' + ltrans3[ind] + "\n------\n";
                translation += ldefinition[ind].Replace("\"", "").Replace("'", "");


                if (lSrs[ind] == sourceTextBox.Text) //that source
                {
                    if (lLvl[ind] == "0")            //dont know, new
                    {
                        styleze.StylizeWord(word, ref textToAnalyze, addFreq, DM.Styles.bold, translation);
                    }

                    if (lLvl[ind] == "1")//maybe know, new
                    {
                        styleze.StylizeWord(word, ref textToAnalyze, addFreq, DM.Styles.brown, translation);
                    }

                    bool writeFullMiniDIct = true;
                    if (writeFullMiniDIct && (lLvl[ind] == "0" || lLvl[ind] == "1"))
                    {
                        miniDict = miniDict + word + '\t' + ltrans1[ind] + '\t' + ltrans2[ind] + '\t' + ltrans3[ind] + '\r';
                    }
                }
                else
                {
                    if (lLvl[ind] == "0" || lLvl[ind] == "1")//maybe know and don't know, another source
                    {
                        styleze.StylizeWord(word, ref textToAnalyze, addFreq, DM.Styles.italic, translation);
                        miniDict = miniDict + word + '\t' + ltrans1[ind] + '\t' + ltrans2[ind] + '\t' + ltrans3[ind] + '\r';
                    }
                    if (lLvl[ind] == "2")//maybe know and don't know, another source
                    {
                        styleze.StylizeWord(word, ref textToAnalyze, addFreq, DM.Styles.blue, translation);
                        miniDict = miniDict + word + '\t' + ltrans1[ind] + '\t' + ltrans2[ind] + '\t' + ltrans3[ind] + '\r';
                    }
                }
            }
            textToAnalyze = textToAnalyze.Replace("\r", "<br>");

            string name = commonSourceTextBox.Text + " " + sourceTextBox.Text;

            FileSaver.WriteFiles(name, miniDict, textToAnalyze);

            excelApp.Quit();
            Application.Exit();
        }