تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[كود] محتاج مساعدة في الاكواد دي
#2
Lightbulb 
كود تصدير الداتاغريد الى Pdf ليعمل نزل المكتبة من المرفقات .
كود :
   Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
       On Error Resume Next
       Dim res As DialogResult = MsgBox("هل أنت متأكد من عملية التصدير ", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "")
       If res = Windows.Forms.DialogResult.Yes Then
           ' تجهيز الجدول
           Dim pdfTable As New PdfPTable(DataGridView1.ColumnCount)
           pdfTable.DefaultCell.Padding = 3
           pdfTable.WidthPercentage = 100
           ' توسيط الجدول في الصفحة
           pdfTable.HorizontalAlignment = Element.ALIGN_CENTER
           ' تفعيل الاتجاه من اليمين لليسار - ضروري للغة العربية
           pdfTable.RunDirection = PdfWriter.RUN_DIRECTION_RTL
           ' تحديد سماكة الاطار
           pdfTable.DefaultCell.BorderWidth = 1
           ' تعيين ارتفاع افتراضي لخلايا الجدول
           pdfTable.DefaultCell.FixedHeight = 100.0F
           ' الخطوط يجب أن تكون من خطوط النظام لتوافقها مع اللغة العربية
           ' لكن لها طريقة خاصة من معرفة مسار ملف اسم الملف الأصلي كالتالي  
           ' تجهيز خط من النظام - آريـال عريض
           ' Arial (Bold) font
           Dim fontArialBoldPath As String = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "arialbd.ttf")
           Dim fontArialBold As BaseFont = BaseFont.CreateFont(fontArialBoldPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED)
           ' fontArialBold يتم استخدام هذا الاسم للخط        
           ' قراءة عناوين أعمدة جدول الداتاجريدفيو
           For Each column As DataGridViewColumn In DataGridView1.Columns
               ' تحديد الخط وحجمه
               Dim fnt As New Font(fontArialBold, 18)
               ' تجهيز محتوى الخلية مع الخط
               Dim pdfCell As New PdfPCell(New Phrase(column.HeaderText, fnt))
               ' إرتفاع الخلية
               pdfCell.FixedHeight = 40
               ' تغيير لون خلفية الخلية
               pdfCell.BackgroundColor = New iTextSharp.text.BaseColor(240, 240, 240)
               ' توسيط عمودي
               pdfCell.VerticalAlignment = Element.ALIGN_MIDDLE
               ' توسيط أفقي
               pdfCell.HorizontalAlignment = Element.ALIGN_CENTER
               ' إضافة الخلية إلى الجدول
               pdfTable.AddCell(pdfCell)
           Next
           ' قراءة أسطر جدول الداتاجريدفيو
           For Each row As DataGridViewRow In DataGridView1.Rows
               ' يتم الخروج من الحلقة إذا كان السطر الأخير الجديد
               If row.IsNewRow Then Exit For
               ' قراءة خلايا سطر جدول التاجريدفيو
               For Each cell As DataGridViewCell In row.Cells
                   ' تصحيح محتوى نص خلية جدول التاجريدفيو
                   If IsNothing(cell.Value) Then cell.Value = String.Empty
                   ' تحديد الخط وحجمه ولونه
                   Dim fnt = New iTextSharp.text.Font(fontArialBold, 16, iTextSharp.text.Font.NORMAL, New BaseColor(193, 36, 67))
                   ' تحديد الخط وحجمه بدون تحديد اللون
                   ' Dim fnt = New iTextSharp.text.Font(fontTimesNewRomanBold, 24)
                   ' تجهيز محتوى الخلية مع الخط مع مسافة قبلها
                   Dim pdfCell As New PdfPCell(New Phrase(" " & cell.Value, fnt))
                   ' إرتفاع الخلية
                   pdfCell.FixedHeight = 40
                   ' توسيط عمودي
                   pdfCell.VerticalAlignment = Element.ALIGN_MIDDLE
                   ' إضافة الخلية إلى الجدول
                   pdfTable.AddCell(pdfCell)
               Next
           Next
           ' تجهيز المجلد
           Dim SvFile As New SaveFileDialog
           SvFile.Filter = "Pdf File |*.Pdf"
           Dim folderPath As String = String.Empty
           If SvFile.ShowDialog = Windows.Forms.DialogResult.OK Then
               folderPath = SvFile.FileName
           Else
               Exit Sub
           End If
           'Dim folderPath As String = Application.StartupPath '& "\DataGridViewExport\"
           'If Not System.IO.Directory.Exists(folderPath) Then System.IO.Directory.CreateDirectory(folderPath)
           ' إسم الملف كامل مع المسار
           Dim fileName As String = folderPath '& "DataGridViewExport.pdf"
           ' تجهيز المستند
           Dim pdfDoc As New Document(PageSize.A2, 10.0F, 10.0F, 10.0F, 0.0F)
           ' كتابة المستند في الملف
           PdfWriter.GetInstance(pdfDoc, New System.IO.FileStream(fileName, System.IO.FileMode.Create))
           pdfDoc.Open()
           pdfDoc.Add(pdfTable)
           pdfDoc.Close()
           MsgBox("تمت عملية التصدير الجدول بنجاح", "تصدير", SystemIcons.Information)
       ElseIf res = Windows.Forms.DialogResult.No Then
           MsgBox("تمت عملية إلغاء الجدول", "إلغاء", SystemIcons.Error)
           Exit Sub
       End If
   End Sub

كود التنبيه سجل فارغ .

كود :
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
       For Each row As DataGridViewRow In DataGridView1.Rows
           If row.Cells(0).Value = Nothing Then
               row.Cells(0).Style.BackColor = Color.Red
          My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)
 ElseIf row.Cells(1).Value = Nothing Then
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)
               row.Cells(1).Style.BackColor = Color.Red
           ElseIf row.Cells(2).Value = "" Then
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)
               row.Cells(2).Style.BackColor = Color.Red
           End If
       Next
   End Sub
بالنسبة للطلب رقم 2 لم اجد قاعدة بيانات في المرفقات .
على كل حال عمل استعلام عن الاسم و التاريخ .
اما اذا كان ملف صورة في مجلد عمل بحث في المجلد عن اسم المكتوب في  SaveFileDialog.FileName
مع إضافة التاريخ الكود :

كود :
   Private Sub BtnSave_Click(sender As Object, e As EventArgs) Handles BtnSave.Click
       Dim bmp1 As New Bitmap(PictureBox1.Image)
       Dim SaveFileDialog1 As New SaveFileDialog
       With SaveFileDialog1
           .Filter = "JPG File |*.JPG"
           .ShowDialog()
           If .FileName = "" Then Exit Sub
           'bmp1.Save(.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
       End With
       If System.IO.File.Exists(SaveFileDialog1.FileName & Now.ToString("yyyy-MM-dd")) Then
           MsgBox("Error Clint Is Exists", MsgBoxStyle.Critical, "Error")
           Exit Sub
       Else
           bmp1.Save(SaveFileDialog1.FileName & Now.ToString("yyyy-MM-dd"), System.Drawing.Imaging.ImageFormat.Jpeg)
       End If
   End Sub


الملفات المرفقة
.zip   itextsharp.zip (الحجم : 1.35 م ب / التحميلات : 31)
الرد }}}
تم الشكر بواسطة: اسامه الهرماوي


الردود في هذا الموضوع
RE: محتاج مساعدة في الاكواد دي - بواسطة asemshahen5 - 27-12-18, 04:50 AM


التنقل السريع :


يقوم بقرائة الموضوع: