private static void dbErrorAction(string errMsg) { AppFuncs.WriteLogErrorMessage(errMsg); MessageBox.Show(errMsg, "Ошибка доступа к данным", MessageBoxButtons.OK, MessageBoxIcon.Error); FlyDoc.Forms.MainForm.SendMail(@"*****@*****.**", "Error!", "Упс, помилка!\nНа комп'ютері: " + System.Environment.MachineName + " З користувачем: " + System.Environment.UserName + " сталася наступна помилка:\n\n" + errMsg); }
private void dgvTable_DataError(object sender, DataGridViewDataErrorEventArgs e) { AppFuncs.WriteLogErrorMessage("Ошибка ввода: " + e.Exception.Message); MessageBox.Show("Ошибка ввода: " + e.Exception.Message, "Проверка ввода", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
//Application.StartupPath, private void btnPrint_Click(object sender, EventArgs e) { AppFuncs.WriteLogTraceMessage(" - press button 'Друк'"); string mydocu = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string fileName = string.Format(@"{0}\doc_{1}.pdf", mydocu, _note.Id); string sText; Document document = new Document(); try { //@"C:\arial.ttf" BaseFont baseFont = BaseFont.CreateFont(@"\\192.168.46.206\FlyDoc\arial.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font font14 = new iTextSharp.text.Font(baseFont, 14f, iTextSharp.text.Font.NORMAL); iTextSharp.text.Font font14Bold = new iTextSharp.text.Font(baseFont, 14f, iTextSharp.text.Font.BOLD); iTextSharp.text.Font font12 = new iTextSharp.text.Font(baseFont, 12f, iTextSharp.text.Font.NORMAL); using (FileStream stream = new FileStream(fileName, FileMode.Create)) { PdfWriter.GetInstance(document, stream); document.Open(); // шапка - директор sText = _note.HeadDir; // _note.HeadNach; Paragraph p = new Paragraph(sText, font14Bold); p.IndentationLeft = 300f; document.Add(p); // шапка - нач.отд. sText = _note.HeadNach; p = new Paragraph(sText, font14Bold); p.IndentationLeft = 300f; p.SpacingBefore = 6f; document.Add(p); // номер служебки sText = "Службова записка №: " + _note.Id; p = new Paragraph(sText, font14Bold); p.SpacingBefore = 20f; p.SpacingAfter = 10f; p.Alignment = iTextSharp.text.Element.ALIGN_CENTER; document.Add(p); // текст 1 if (_note.BodyUp != null) { sText = _note.BodyUp; p = new Paragraph(sText, font14); p.Alignment = iTextSharp.text.Element.ALIGN_LEFT; p.FirstLineIndent = 20f; document.Add(p); } // TODO доделать вывод табилицы // таблицу взять из DataGridView if (dgvTable.Visible == true) { List <PropertyInfo> propInfos = typeof(NoteInclude).GetProperties().ToList(); int colVisCount = 0; foreach (DataGridViewColumn col in dgvTable.Columns) { if (col.Visible) { colVisCount++; } } PdfPTable table = new PdfPTable(colVisCount); table.SpacingBefore = 20f; table.SpacingAfter = 20f; table.WidthPercentage = 100; table.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT; //table.WidthPercentage foreach (DataGridViewColumn col in dgvTable.Columns) { if (col.Visible) { table.AddCell(new Paragraph(col.HeaderText, font12)); } } foreach (DataGridViewRow row in dgvTable.Rows) { foreach (DataGridViewColumn col in dgvTable.Columns) { if (col.Visible) { object oValue = row.Cells[col.Name].Value; string cellValue = oValue.ToStringNull(); table.AddCell(new Paragraph(cellValue, font12)); } } } document.Add(table); //PdfPCell cell = new PdfPCell(new Phrase("Simple table", // new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 16, // iTextSharp.text.Font.NORMAL, new BaseColor(Color.Orange)))); //cell.BackgroundColor = new BaseColor(Color.Wheat); //cell.Padding = 5; //cell.Colspan = 3; //cell.HorizontalAlignment = Element.ALIGN_CENTER; //table.AddCell(cell); //table.AddCell("Col 1 Row 1"); //table.AddCell("Col 2 Row 1"); //table.AddCell("Col 3 Row 1"); //table.AddCell("Col 1 Row 2"); //table.AddCell("Col 2 Row 2"); //table.AddCell("Col 3 Row 2"); //foreach (NoteInclude incl in _note.Include) //{ // foreach (string fldName in _note.IncludeFields) // { // propInfo = propInfos.FirstOrDefault(prp => prp.Name == fldName); // object obj = propInfo.GetValue(this, null); // } //} } // текст 2 if (_note.BodyDown != null) { sText = _note.BodyDown; p = new Paragraph(sText, font14); p.Alignment = iTextSharp.text.Element.ALIGN_LEFT; p.FirstLineIndent = 20f; document.Add(p); } document.Close(); AppFuncs.WriteLogTraceMessage($"file '{fileName}' created success"); } } catch (DocumentException ex) { AppFuncs.WriteLogErrorMessage(ex.ToString()); Console.WriteLine(ex.Message); } catch (IOException ex) { AppFuncs.WriteLogErrorMessage(ex.ToString()); Console.WriteLine(ex.Message); } ProcessStartInfo pInfo = new ProcessStartInfo(fileName); pInfo.UseShellExecute = true; Process process = Process.Start(pInfo); }