Exemplo n.º 1
0
 internal WordArea(WordDocument WordDocument)
 {
     this.Objects=new ArrayList();
     this.WordDocument=WordDocument;
 }
Exemplo n.º 2
0
        private void btnReportResearch_Click(object sender, EventArgs e)
        {
            WordDocument doc = new WordDocument(WordDocumentFormat.A4);
            Font normal = new Font("Arial", 10, FontStyle.Regular);
            Font bold = new Font("Arial", 10, FontStyle.Bold);
            Font header = new Font("Arial", 16, FontStyle.Bold);
            Font subHeader = new Font("Arial", 16, FontStyle.Italic);
            Font subSubHeader = new Font("Arial", 12, FontStyle.Italic);

            doc.SetFont(header);
            doc.WriteLine("Протокол исследований объекта '" + currentResearch.Name + "'");
            doc.WriteLine();
            doc.SetFont(normal);

            const int PICTURE_WIDTH_IN_INCH = 8;

            int picture_number = 1;
            if (pbTopView.ImageLocation != null)
            {
                int DPI = pbTopView.Image.Width / PICTURE_WIDTH_IN_INCH;
                doc.PutImage(pbTopView.ImageLocation, DPI);
                doc.WriteLine();
                doc.SetTextAlign(WordTextAlign.Center);
                doc.WriteLine("Рисуное " + picture_number++ + ". Схема размещения контрольных точек. Вид сверху");
                doc.SetTextAlign(WordTextAlign.Left);
            }

            if (pbSideView.ImageLocation != null)
            {
                int DPI = pbSideView.Image.Width / PICTURE_WIDTH_IN_INCH;
                doc.PutImage(pbSideView.ImageLocation, DPI);
                doc.WriteLine();
                doc.SetTextAlign(WordTextAlign.Center);
                doc.WriteLine("Рисуное " + picture_number + ". Схема размещения контрольных точек. Вид сбоку");
                doc.SetTextAlign(WordTextAlign.Left);
            }

            doc.SetFont(normal);
            if (currentResearch.CheckPoints.Count > 0)
            {
                doc.SetFont(subHeader);
                doc.WriteLine("Контрольные точки: Акустика");
                doc.SetFont(normal);
            }

            foreach(CheckPoint cp in currentResearch.CheckPoints)
            {
                if (cp.GetType() == Type.GetType("Diplom.Data.CPVibro"))
                {
                    continue;
                }
                doc.SetFont(subSubHeader);
                doc.WriteLine("Контрольная точка '" + cp.Name + "'");
                doc.SetFont(normal);
                WordTable table = doc.NewTable(normal, Color.Black, 7, cp.Results.Ratio.Length + 1, 1);
                table.SetColumnsWidth(new int[8] { 5, 1, 1, 1, 1, 1, 1, 1 });
                table.CellRange(0, 0, 1, 0).MergeCells();
                NewCell(table, 0, 0, "Слагаемое", bold);
                table.CellRange(0, 1, 0, 7).MergeCells();
                NewCell(table, 0, 1, "Среднегеометрическая частота октавной полосы, Гц", bold);
                NewCell(table, 1, 1, "125", bold);
                NewCell(table, 1, 2, "250", bold);
                NewCell(table, 1, 3, "500", bold);
                NewCell(table, 1, 4, "1000", bold);
                NewCell(table, 1, 5, "2000", bold);
                NewCell(table, 1, 6, "4000", bold);
                NewCell(table, 1, 7, "8000", bold);

                int noiseLevelRow = 4;
                int ratioIndex = 5;
                int wIndex = 6;

                NewCell(table, 2, 0, "Уровеь сигнала, дБ", bold);
                NewCell(table, 3, 0, "Уровеь сигнала в КТ, дБ", bold);
                NewCell(table, 4, 0, "Уровеь шума, дБ", bold);
                NewCell(table, ratioIndex, 0, "Отношение сигнал/шум, дБ", bold);

                for (int i = 1; i <= cp.Results.Ratio.Length; i++)
                {
                    NewCell(table, 2, i, cp.Results.SignalLevel[i - 1].ToString());
                    NewCell(table, 3, i, cp.Results.SoundproofLefel[i - 1].ToString());
                    NewCell(table, noiseLevelRow, i, cp.Results.NoiseLevel[i - 1].ToString());
                    NewCell(table, ratioIndex, i, cp.Results.Ratio[i - 1].ToString());
                }
                table.SaveToDocument(10000, 0);

                NewCell(table, wIndex, 0, "Словесная разборчиваость речи, %", bold);
                table.CellRange(wIndex, 1, wIndex, 7).MergeCells();
                NewCell(table, wIndex, 1, cp.Results.W.ToString());
                doc.WriteLine();
            }

            if (currentResearch.CheckPoints.Count > 0)
            {
                doc.SetFont(subHeader);
                doc.WriteLine("Контрольные точки: Виброакустика");
                doc.SetFont(normal);
            }

            foreach (CheckPoint cp in currentResearch.CheckPoints)
            {
                if (cp.GetType() != Type.GetType("Diplom.Data.CPVibro"))
                {
                    continue;
                }

                doc.SetFont(subSubHeader);
                doc.WriteLine("Контрольная точка '" + cp.Name + "'");
                doc.SetFont(normal);
                WordTable table = doc.NewTable(normal, Color.Black, 6, 6, 1);
                table.SetColumnsWidth(new int[6] { 5, 1, 1, 1, 1, 1});
                table.CellRange(0, 0, 1, 0).MergeCells();
                NewCell(table, 0, 0, "Слагаемое", bold);
                table.CellRange(0, 1, 0, 5).MergeCells();
                NewCell(table, 0, 1, "Среднегеометрическая частота октавной полосы, Гц", bold);
                NewCell(table, 1, 1, "250", bold);
                NewCell(table, 1, 2, "500", bold);
                NewCell(table, 1, 3, "1000", bold);
                NewCell(table, 1, 4, "2000", bold);
                NewCell(table, 1, 5, "4000", bold);

                int ratioIndex = 4;
                int wIndex = 5;

                NewCell(table, 2, 0, "Уровеь сигнала, дБ", bold);
                NewCell(table, 3, 0, "Уровеь сигнала в КТ, дБ", bold);
                NewCell(table, ratioIndex, 0, "Отношение сигнал/шум, дБ", bold);

                for (int i = 1; i <= 6; i++)
                {
                    NewCell(table, 2, i, cp.Results.SignalLevel[i].ToString());
                    NewCell(table, 3, i, cp.Results.SoundproofLefel[i].ToString());
                    NewCell(table, ratioIndex, i, cp.Results.Ratio[i].ToString());
                }
                table.SaveToDocument(10000, 0);

                NewCell(table, wIndex, 0, "Словесная разборчиваость речи, %", bold);
                table.CellRange(wIndex, 1, wIndex, 5).MergeCells();
                NewCell(table, wIndex, 1, cp.Results.W.ToString());
                doc.WriteLine();
            }

            SaveFileDialog sf = new SaveFileDialog();
            sf.DefaultExt = "doc";
            sf.Filter = "Документ Word |*.doc";
            if (sf.ShowDialog() == DialogResult.OK)
            {
                doc.SaveToFile(sf.FileName);
                MessageBox.Show("Отчет сформирован");
            }
        }