Ejemplo n.º 1
0
 private void button10_Click(object sender, EventArgs e)
 {
     if (frm10 == null || frm10.IsDisposed)
     {
         string title = m_unitTitle;
         frm10 = new Form10(_id, this);
         frm10.Show();
     }
     else
     {
         frm10.WindowState = FormWindowState.Normal;
         frm10.Activate();
         frm10.BringToFront();
     }
 }
Ejemplo n.º 2
0
        private void createFile()
        {
            string ttf = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIAL.TTF");

            BaseFont baseFont = BaseFont.CreateFont(ttf, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

            iTextSharp.text.Font f         = new iTextSharp.text.Font(baseFont, 12);
            iTextSharp.text.Font titleFont = new iTextSharp.text.Font(baseFont, 14, iTextSharp.text.Font.BOLD);

            SaveFileDialog savepdf = new SaveFileDialog();

            savepdf.Filter = "PDF Files |*.pdf";

            if (savepdf.ShowDialog() == DialogResult.OK)
            {
                Document pdf = new Document(PageSize.A4, 60, 20, 20, 60);

                PdfWriter.GetInstance(pdf, new FileStream(savepdf.FileName, FileMode.Create));

                PdfPTable failuresTable = new PdfPTable(4);
                PdfPTable softwareTable = new PdfPTable(4);
                PdfPTable worksTable    = new PdfPTable(6);
                PdfPTable statusTable   = new PdfPTable(3);
                //PdfPTable placeTable = new PdfPTable(5);
                PdfPTable repairTable = new PdfPTable(4);
                //
                PdfPTable headerTable1    = new PdfPTable(6);
                PdfPTable headerTable2    = new PdfPTable(3);
                PdfPTable workHoursTable  = new PdfPTable(5);
                PdfPTable placeTable      = new PdfPTable(2);
                PdfPTable contractsTable  = new PdfPTable(4);
                PdfPTable dispatchesTable = new PdfPTable(3);

                Form4  failuresForm = new Form4(_id, this);
                Form5  softwareForm = new Form5(_id, this);
                Form6  worksForm    = new Form6(_id, this);
                Form7  statusForm   = new Form7(_id, this);
                Form8  placeForm    = new Form8(_id, this);
                Form10 repairForm   = new Form10(_id, this);

                Paragraph rusParagraph;
                PdfPCell  cell;

                PdfPTable resourceTable = new PdfPTable(6);

                pdf.Open();

                rusParagraph           = new Paragraph(DateTime.Today.Date.ToString("yyyy-MM-dd"), f);
                rusParagraph.Alignment = Element.ALIGN_RIGHT;
                pdf.Add(rusParagraph);

                rusParagraph           = new Paragraph("Сведения\n\n", titleFont);
                rusParagraph.Alignment = Element.ALIGN_CENTER;
                pdf.Add(rusParagraph);

                cell = new PdfPCell(new Paragraph());
                cell.HorizontalAlignment = 1;
                cell.BackgroundColor     = BaseColor.LIGHT_GRAY;

                headerTable1.DefaultCell.Border = 0;
                headerTable1.SetWidths(new float[] { 13, 25, 15, 10, 20, 16 });
                headerTable1.DefaultCell.HorizontalAlignment = 1;
                headerTable1.WidthPercentage = 100f;
                headerTable1.AddCell(new Paragraph("Изделие", f));
                cell.Phrase = new Paragraph(textBox2.Text, f);
                headerTable1.AddCell(cell);
                headerTable1.AddCell(new Paragraph("Заводской номер", f));
                cell.Phrase = new Paragraph(textBox1.Text, f);
                headerTable1.AddCell(cell);
                headerTable1.AddCell(new Paragraph("Дата выпуска", f));
                cell.Phrase = new Paragraph(textBox3.Text, f);
                headerTable1.AddCell(cell);

                pdf.Add(headerTable1);
                pdf.Add(rusParagraph = new Paragraph("\n", f));

                headerTable2.WidthPercentage = 100f;
                headerTable2.DefaultCell.HorizontalAlignment = 1;
                headerTable2.DefaultCell.BorderWidth         = 0;
                headerTable2.AddCell(new Paragraph("Текущая версия ПО", f));
                headerTable2.AddCell(new Paragraph("", f));
                headerTable2.AddCell(new Paragraph("Статус изделия", f));
                cell.Phrase = new Paragraph(textBox4.Text, f);
                //cell.Border = 15;
                headerTable2.AddCell(cell);
                headerTable2.AddCell(new Paragraph("", f));
                cell.Phrase = new Paragraph(textBox8.Text, f);
                headerTable2.AddCell(cell);

                pdf.Add(headerTable2);
                pdf.Add(new Paragraph("\n", f));

                workHoursTable.DefaultCell.Border = 0;
                workHoursTable.DefaultCell.HorizontalAlignment = 1;
                workHoursTable.WidthPercentage = 100f;
                workHoursTable.AddCell(new Paragraph("Наработка, час", f));
                workHoursTable.AddCell(new Paragraph("СНЭ", f));
                workHoursTable.AddCell(new Paragraph("ППР", f));
                workHoursTable.AddCell(new Paragraph("Кол-во ремонтов", f));
                workHoursTable.AddCell(new Paragraph("Дата последнего ремонта", f));
                workHoursTable.AddCell(new Paragraph(" ", f));
                cell.Phrase = new Paragraph(textBox5.Text, f);
                workHoursTable.AddCell(cell);
                cell.Phrase = new Paragraph(calculateAfterFirstRepair().ToString(), f);
                workHoursTable.AddCell(cell);   // PPR hz
                cell.Phrase = new Paragraph(repairForm.dataGridView1.Rows.Count.ToString(), f);
                workHoursTable.AddCell(cell);
                cell.Phrase = new Paragraph(textBox10.Text, f);
                workHoursTable.AddCell(cell);
                pdf.Add(workHoursTable);
                pdf.Add(new Paragraph("\n", f));

                placeTable.SetWidths(new float[] { 25, 75 });
                placeTable.DefaultCell.Border = 0;
                placeTable.DefaultCell.HorizontalAlignment = 1;
                placeTable.WidthPercentage = 100f;
                placeTable.AddCell(new Paragraph("Место эксплуатации", f));
                cell.Phrase = new Paragraph(textBox7.Text, f);
                placeTable.AddCell(cell);
                pdf.Add(placeTable);
                pdf.Add(new Paragraph("\n", f));

                string sql = string.Format("SELECT contract_num, " +
                                           "contract_date, associate " +
                                           "FROM contracts WHERE unit_id = {0}", _id);

                DataTable dt = SQLCustom.SQL_Request(Form1.connection, sql);

                contractsTable.SetWidths(new float[] { 22, 32, 14, 32 });
                contractsTable.DefaultCell.Border = 0;
                contractsTable.DefaultCell.HorizontalAlignment = 1;
                contractsTable.WidthPercentage = 100f;
                contractsTable.AddCell(new Paragraph("Договор поставки", f));
                contractsTable.AddCell(new Paragraph("№ Договора", f));
                contractsTable.AddCell(new Paragraph("Дата", f));
                contractsTable.AddCell(new Paragraph("С кем заключен", f));
                contractsTable.AddCell(new Paragraph(" ", f));

                if (dt.Rows.Count > 0)
                {
                    cell.Phrase = new Paragraph(dt.Rows[0]["contract_num"].ToString(), f);
                    contractsTable.AddCell(cell);
                    cell.Phrase = new Paragraph(string.Format("{0:yyyy-MM-dd}", dt.Rows[0]["contract_date"]), f);
                    contractsTable.AddCell(cell);
                    cell.Phrase = new Paragraph(dt.Rows[0]["associate"].ToString(), f);
                    contractsTable.AddCell(cell);
                }
                else
                {
                    cell.Phrase = new Paragraph(" ", f);
                    contractsTable.AddCell(cell);
                    cell.Phrase = new Paragraph(" ", f);
                    contractsTable.AddCell(cell);
                    cell.Phrase = new Paragraph(" ", f);
                    contractsTable.AddCell(cell);
                }
                pdf.Add(contractsTable);
                pdf.Add(new Paragraph("\n", f));

                sql = string.Format("SELECT date_sending, invoice, " +
                                    "FROM unit_dispatches; WHERE unit_id = {0}", _id);

                dt = SQLCustom.SQL_Request(Form1.connection, sql);

                dispatchesTable.SetWidths(new float[] { 25, 15, 60 });
                dispatchesTable.DefaultCell.Border = 0;
                dispatchesTable.DefaultCell.HorizontalAlignment = 1;
                dispatchesTable.WidthPercentage = 100f;
                dispatchesTable.AddCell(new Paragraph("Реквизиты отправки", f));
                dispatchesTable.AddCell(new Paragraph("Дата", f));
                dispatchesTable.AddCell(new Paragraph("Накладная", f));

                if (dt.Rows.Count > 0)
                {
                    dispatchesTable.AddCell(new Paragraph(" "));
                    cell.Phrase = new Paragraph(string.Format("{0:yyyy-MM-dd}", dt.Rows[0]["date_sending"]), f);
                    dispatchesTable.AddCell(cell);
                    cell.Phrase = new Paragraph(dt.Rows[0]["invoice"].ToString(), f);
                    dispatchesTable.AddCell(cell);
                }
                else
                {
                    dispatchesTable.AddCell(new Paragraph(" "));
                    cell.Phrase = new Paragraph(" ", f);
                    dispatchesTable.AddCell(cell);
                    cell.Phrase = new Paragraph(" ", f);
                    dispatchesTable.AddCell(cell);
                }
                pdf.Add(dispatchesTable);
                pdf.Add(new Paragraph("\n", f));

                pdf.Add(new Paragraph("Ресурс\n\n", f));
                if (createResourceTable(_id, resourceTable, f))
                {
                    pdf.Add(resourceTable);
                }

                pdf.Add(new Paragraph("Изменения ПО\n\n", titleFont));
                addTableToFile(softwareForm.dataGridView1, softwareTable, pdf, f);

                pdf.Add(new Paragraph("Отклонение от КД", titleFont));
                pdf.Add(new Paragraph(textBox11.Text, f));

                pdf.Add(new Paragraph("Разрешение применения", titleFont));
                pdf.Add(new Paragraph(textBox6.Text, f));

                pdf.Add(new Paragraph("Список отказов\n\n", titleFont));
                addTableToFile(failuresForm.dataGridView1, failuresTable, pdf, f);

                pdf.Add(new Paragraph("Список работ\n\n", titleFont));
                addTableToFile(worksForm.dataGridView1, worksTable, pdf, f);

                pdf.Add(new Paragraph("Ремонт\n\n", titleFont));
                addTableToFile(repairForm.dataGridView1, repairTable, pdf, f);

                pdf.Close();

                MessageBox.Show("Файл успешно создан");
            }
        }