コード例 #1
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> if called from managed code; otherwise <c>false</c>.</param>
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            if (disposing)
            {
                // Dispose your managed resources here
                if (_application != null)
                {
                    _application.Quit();
                    _application.Dispose();
                }
            }

            // Dispose your unmanaged resources here
            _application = null;
            _disposed    = true;
        }
コード例 #2
0
        private Task StartWordWithPdfAdProcess()
        {
            var pdfBytes = System.IO.File.ReadAllBytes(_filePath);

            using (NetOffice.WordApi.Application app = new NetOffice.WordApi.Application())
            {
#if DEBUG
                app.Visible = true;
#endif
                var doc = app.Documents.Open(_filePath);

                var datasheet = new Datasheet.Dal.Ef.Datasheet
                {
                    FilePath    = _filePath,
                    Pdf         = pdfBytes,
                    PdfProvider = GetInstanceName(_filePath),
                };

                foreach (var section in doc.Paragraphs)
                {
                    var newSection = new Section
                    {
                    };

                    datasheet.Sections.Add(newSection);
                    if (!String.IsNullOrEmpty(section.Range.Text) && !String.IsNullOrWhiteSpace(section.Range.Text))
                    {
                        newSection.SectionText = section.Range.Text;
                    }
                    else
                    {
                        //Extract image!
                        //newSection.SectionImage = section.Range.
                    }
                }
                app.Quit();
                _context.Datasheets.Add(datasheet);
                return(_context.SaveChangesAsync());
            }
        }
コード例 #3
0
        private Task StartWordWithPdfAdProcess()
        {
            var pdfBytes = System.IO.File.ReadAllBytes(_filePath);
            using (NetOffice.WordApi.Application app = new NetOffice.WordApi.Application())
            {
#if DEBUG
                app.Visible = true;
#endif
                var doc = app.Documents.Open(_filePath);

                var datasheet = new Datasheet.Dal.Ef.Datasheet
                {
                    FilePath = _filePath,
                    Pdf = pdfBytes,
                    PdfProvider = GetInstanceName(_filePath),
                };

                foreach (var section in doc.Paragraphs)
                {
                    var newSection = new Section
                    {

                    };

                    datasheet.Sections.Add(newSection);
                    if (!String.IsNullOrEmpty(section.Range.Text) && ! String.IsNullOrWhiteSpace(section.Range.Text))
                    {
                        newSection.SectionText = section.Range.Text;
                    }
                    else
                    {
                        //Extract image!
                        //newSection.SectionImage = section.Range.
                    }
                }
                app.Quit();
                _context.Datasheets.Add(datasheet);
                return _context.SaveChangesAsync();
            }
        }
コード例 #4
0
ファイル: Editor.xaml.cs プロジェクト: Schalaschaska/AR
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(k_t.Text) || string.IsNullOrWhiteSpace(k_s.Text) || string.IsNullOrWhiteSpace(o_n.Text) || string.IsNullOrWhiteSpace(p_p.Text) ||
                string.IsNullOrWhiteSpace(v_r.Text) || string.IsNullOrWhiteSpace(Ri_t.Text) || string.IsNullOrWhiteSpace(Rn_t.Text) || string.IsNullOrWhiteSpace(H_t.Text) ||
                string.IsNullOrWhiteSpace(n1_1.Text) || string.IsNullOrWhiteSpace(n1_2.Text) || string.IsNullOrWhiteSpace(n1_3.Text) || string.IsNullOrWhiteSpace(n1_4.Text) ||
                string.IsNullOrWhiteSpace(n2_1.Text) || string.IsNullOrWhiteSpace(n2_2.Text) || string.IsNullOrWhiteSpace(n2_3.Text) || string.IsNullOrWhiteSpace(n2_4.Text) ||
                string.IsNullOrWhiteSpace(n3_1.Text) || string.IsNullOrWhiteSpace(n3_2.Text) || string.IsNullOrWhiteSpace(n3_3.Text) || string.IsNullOrWhiteSpace(n3_4.Text) ||
                string.IsNullOrWhiteSpace(n4_1.Text) || string.IsNullOrWhiteSpace(n4_2.Text) || string.IsNullOrWhiteSpace(n4_3.Text) || string.IsNullOrWhiteSpace(n4_4.Text) ||
                string.IsNullOrWhiteSpace(n5_1.Text) || string.IsNullOrWhiteSpace(n5_2.Text) || string.IsNullOrWhiteSpace(n5_3.Text) || string.IsNullOrWhiteSpace(n5_4.Text) ||
                string.IsNullOrWhiteSpace(n6_1.Text) || string.IsNullOrWhiteSpace(n6_2.Text) || string.IsNullOrWhiteSpace(n6_3.Text) || string.IsNullOrWhiteSpace(n6_4.Text) ||
                string.IsNullOrWhiteSpace(n7_1.Text) || string.IsNullOrWhiteSpace(n7_2.Text) || string.IsNullOrWhiteSpace(n7_3.Text) || string.IsNullOrWhiteSpace(n7_4.Text) ||
                string.IsNullOrWhiteSpace(n8_1.Text) || string.IsNullOrWhiteSpace(n8_2.Text) || string.IsNullOrWhiteSpace(n8_3.Text) || string.IsNullOrWhiteSpace(n8_4.Text) ||
                string.IsNullOrWhiteSpace(n9_1.Text) || string.IsNullOrWhiteSpace(n9_2.Text) || string.IsNullOrWhiteSpace(n9_3.Text) || string.IsNullOrWhiteSpace(n9_4.Text)
                )
            {
                MessageBox.Show("Ошибка ввода!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                Regex X = new Regex(@"^\d*(\,\d+)?$");

                if (X.IsMatch(n1_1.Text) && (X.IsMatch(n1_2.Text)) && (X.IsMatch(n1_3.Text)) && (X.IsMatch(n1_4.Text)) && (X.IsMatch(n2_1.Text)) && (X.IsMatch(n2_2.Text)) &&
                    (X.IsMatch(n2_3.Text)) && (X.IsMatch(n2_4.Text)) && (X.IsMatch(n3_1.Text)) && (X.IsMatch(n3_2.Text)) && (X.IsMatch(n3_3.Text)) && (X.IsMatch(n3_4.Text)) &&
                    (X.IsMatch(n4_1.Text)) && (X.IsMatch(n4_2.Text)) && (X.IsMatch(n4_3.Text)) && (X.IsMatch(n4_4.Text)) && (X.IsMatch(n5_1.Text)) && (X.IsMatch(n5_2.Text)) &&
                    (X.IsMatch(n5_3.Text)) && (X.IsMatch(n5_4.Text)) && (X.IsMatch(n6_1.Text)) && (X.IsMatch(n6_2.Text)) && (X.IsMatch(n6_3.Text)) && (X.IsMatch(n6_4.Text)) &&
                    (X.IsMatch(n7_1.Text)) && (X.IsMatch(n7_2.Text)) && (X.IsMatch(n7_3.Text)) && (X.IsMatch(n7_4.Text)) && (X.IsMatch(n8_1.Text)) && (X.IsMatch(n8_2.Text)) &&
                    (X.IsMatch(n8_3.Text)) && (X.IsMatch(n8_4.Text)) && (X.IsMatch(n9_1.Text)) && (X.IsMatch(n9_2.Text)) && (X.IsMatch(n9_3.Text)) && (X.IsMatch(n9_4.Text)) &&
                    (X.IsMatch(k_t.Text)) && (X.IsMatch(k_s.Text)) && (X.IsMatch(o_n.Text)) && (X.IsMatch(p_p.Text)) && (X.IsMatch(v_r.Text)) && (X.IsMatch(Ri_t.Text)) && (X.IsMatch(Rn_t.Text)) && (X.IsMatch(H_t.Text)))
                {
                    f  = Convert.ToDouble(k_t.Text);
                    n  = Convert.ToInt32(k_s.Text);
                    R0 = Convert.ToDouble(v_r.Text);
                    a  = Convert.ToDouble(p_p.Text);
                    q  = Convert.ToDouble(o_n.Text);
                    Ri = Convert.ToDouble(Ri_t.Text);
                    H  = Convert.ToDouble(H_t.Text);
                    if (Convert.ToDouble(n2_4.Text) <= (Convert.ToDouble(n1_4.Text)) ||
                        (Convert.ToDouble(n3_4.Text) <= (Convert.ToDouble(n2_4.Text)) ||
                         (Convert.ToDouble(n4_4.Text) <= (Convert.ToDouble(n3_4.Text)) ||
                          (Convert.ToDouble(n5_4.Text) <= (Convert.ToDouble(n4_4.Text)) ||
                           (Convert.ToDouble(n6_4.Text) <= (Convert.ToDouble(n5_4.Text)) ||
                            (Convert.ToDouble(n7_4.Text) <= (Convert.ToDouble(n6_4.Text)) ||
                             (Convert.ToDouble(n8_4.Text) <= (Convert.ToDouble(n7_4.Text)) ||
                              (Convert.ToDouble(n9_4.Text) <= (Convert.ToDouble(n8_4.Text))))))))))
                    {
                        MessageBox.Show("Ошибка ввода!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        List <double> KI_list_2 = new List <double> {
                        };
                        List <double> DI_list_2 = new List <double> {
                        };
                        List <double> RI_list_2 = new List <double> {
                        };
                        KI_list_2.Add(Convert.ToDouble(n1_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n2_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n3_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n4_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n5_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n6_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n7_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n8_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n9_2.Text));
                        DI_list_2.Add(Convert.ToDouble(n1_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n2_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n3_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n4_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n5_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n6_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n7_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n8_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n9_3.Text));
                        RI_list_2.Add(Convert.ToDouble(n1_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n2_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n3_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n4_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n5_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n6_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n7_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n8_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n9_4.Text));
                        double[]      KI_2     = KI_list_2.ToArray <double>();
                        double[]      DI_2     = DI_list_2.ToArray <double>();
                        double[]      RI_2     = RI_list_2.ToArray <double>();
                        List <double> RI_list  = new List <double> {
                        };
                        List <double> YI_list  = new List <double> {
                        };
                        List <double> VI_list  = new List <double> {
                        };
                        List <double> QI_list  = new List <double> {
                        };
                        List <double> AI_list  = new List <double> {
                        };
                        List <double> Sum_list = new List <double> {
                        };
                        RI_list.Add(Convert.ToDouble(n1_4.Text));
                        while (Ri <= Convert.ToDouble(n9_4.Text))
                        {
                            Ri = Ri + H;
                            RI_list.Add(Ri);
                            kol_e++;
                        }
                        double[] RI = RI_list.ToArray <double>();

                        for (int i = 0; i <= RI.Length - 1; i++)
                        {
                            yi = 2 * a * (RI[i] - R0);
                            YI_list.Add(yi);
                        }
                        double[] YI = YI_list.ToArray <double>();
                        for (int i = 0; i <= RI.Length - 1; i++)
                        {
                            Vi = 1 / (Math.Sqrt(1 + YI[i] * YI[i]));
                            VI_list.Add(Vi);
                        }
                        double[] VI = VI_list.ToArray <double>();


                        for (int i = 0; i <= n - 1; i++)
                        {
                            pr_sum = pr_sum + (KI_2[i] * DI_2[i] * Math.Pow(VI[i], 2));
                            pr_n++;
                        }

                        pr_sum_2 = DI_2[pr_n - 1] / pr_sum;
                        for (int i = 0; i <= RI.Length - 1; i++)
                        {
                            qi = pr_sum_2 * q * VI[i];
                            QI_list.Add(qi);
                        }
                        double[] QI = QI_list.ToArray <double>();

                        for (int i = 0; i <= RI.Length - 1; i++)
                        {
                            A = 2 * 3.141592653589793238462643383279 * f * QI[i] * RI[i];
                            AI_list.Add(A);
                        }
                        double[] AI = AI_list.ToArray <double>();
                        max = AI.Max();
                        string date_time   = DateTime.Now.ToString("dd MMMM yyyy HH:mm:ss");
                        string date_time_2 = DateTime.Now.ToString("dd MMMM yyyy HH-mm-ss");
                        NetOffice.WordApi.Application word = new NetOffice.WordApi.Application();
                        word.DisplayAlerts = WdAlertLevel.wdAlertsNone;
                        NetOffice.WordApi.Document newdoc = word.Documents.Add();
                        word.Selection.TypeText(date_time);//пока только так(
                        word.Selection.TypeParagraph();
                        word.Selection.TypeText("Исходные данные");
                        word.Selection.TypeParagraph();
                        NetOffice.WordApi.Table table = newdoc.Tables.Add(word.Selection.Range, n, 4);
                        table.Borders.InsideLineStyle  = WdLineStyle.wdLineStyleSingle;
                        table.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
                        for (int i = 0; i < n; i++)
                        {
                            for (int j = 1; j <= 1; j++)
                            {
                                table.Cell(i + 1, j).Select();
                                word.Selection.TypeText(Convert.ToString(NI[i]));
                            }
                        }
                        for (int i = 0; i < n; i++)
                        {
                            for (int j = 2; j <= 2; j++)
                            {
                                table.Cell(i + 1, j).Select();
                                word.Selection.TypeText(Convert.ToString(KI_2[i]));
                            }
                        }
                        for (int i = 0; i < n; i++)
                        {
                            for (int j = 3; j <= 3; j++)
                            {
                                table.Cell(i + 1, j).Select();
                                word.Selection.TypeText(Convert.ToString(DI_2[i]));
                            }
                        }
                        for (int i = 0; i < n; i++)
                        {
                            for (int j = 4; j <= 4; j++)
                            {
                                table.Cell(i + 1, j).Select();
                                word.Selection.TypeText(Convert.ToString(RI_2[i]));
                            }
                        }
                        word.Selection.EndKey(6);
                        word.Selection.TypeParagraph();
                        word.Selection.TypeParagraph();
                        word.Selection.TypeText("Таблица результатов");
                        NetOffice.WordApi.Table table_2 = newdoc.Tables.Add(word.Selection.Range, kol_e, 3);
                        table_2.Borders.InsideLineStyle  = WdLineStyle.wdLineStyleSingle;
                        table_2.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
                        for (int i = 0; i < kol_e; i++)
                        {
                            for (int j = 1; j <= 1; j++)
                            {
                                table_2.Cell(i + 1, j).Select();
                                word.Selection.TypeText(Convert.ToString(RI[i]));
                            }
                        }
                        for (int i = 0; i < kol_e; i++)
                        {
                            for (int j = 2; j <= 2; j++)
                            {
                                table_2.Cell(i + 1, j).Select();
                                word.Selection.TypeText(Convert.ToString(QI[i]));
                            }
                        }
                        for (int i = 0; i < kol_e; i++)
                        {
                            for (int j = 3; j <= 3; j++)
                            {
                                table_2.Cell(i + 1, j).Select();
                                word.Selection.TypeText(Convert.ToString(AI[i]));
                            }
                        }
                        int indexMax = Array.IndexOf(AI, max);
                        word.Selection.EndKey(6);
                        word.Selection.TypeParagraph();
                        word.Selection.TypeText("Максимальное значение А = " + Convert.ToString(max) + " при значении " + RI[indexMax] + " RI");
                        string fileExtension = GetDefaultExtension(word);//проверка версии
                        object documentFile  = string.Format("{0}\\" + date_time_2 + "{1}", Directory.GetCurrentDirectory(), fileExtension);
                        newdoc.SaveAs(documentFile);
                        word.Quit();
                        word.Dispose();
                        Array.Clear(RI, 0, RI.Length);
                        Array.Clear(YI, 0, YI.Length);
                        Array.Clear(VI, 0, VI.Length);
                        Array.Clear(QI, 0, QI.Length);
                        Array.Clear(AI, 0, AI.Length);
                        Array.Clear(KI_2, 0, KI_2.Length);
                        Array.Clear(RI_2, 0, RI_2.Length);
                        pr_n     = 0;
                        pr_sum   = 0;
                        pr_sum_2 = 0;
                        kol_e    = 0;
                    }
                }
                else
                {
                    MessageBox.Show("Ошибка ввода!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }//расчёт