تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
هل يمكن اضافة ملف pdf علي هذه الكود
#1
الكود بيقبل الصور  محتاج اضيف معا pdf
كود :
Imports System.Data.SqlClient
Imports System.IO
Public Class Form9
   Public ID As Integer
   Private Function Add() As Boolean
       Dim temp As Boolean
       Dim pc As New PC
       With pc
           .ID = GetCount("PC")
           .Name = txtname.Text.Trim
           .code = txtcode.Text.Trim
           .floor = txtfloor.Text.Trim
           .office = txtoffice.Text.Trim
           .serial = txtSerial.Text.Trim
           .laptob = txtLaptob.Text.Trim
           .pc = txtpc.Text.Trim
           .description = txtDescription.Text.Trim
           .comment = txtComment.Text.Trim
           .usbm = txtUsbModam.Text.Trim
           .datee = txtDatee.Value
           .SNram1 = txtram1.Text.Trim
           .SNram2 = txtram2.Text.Trim
           .SNram3 = txtram3.Text.Trim
           .SNram4 = txtram4.Text.Trim
           .image1 = pbox.Image
           pbox.Image = Nothing
       End With
       temp = pc.Add()
       pc = Nothing
       Return temp
   End Function
   Private Function Edit() As Boolean
       Dim temp As Boolean
       Dim pc As New PC
       With pc
           .ID = ID
           .Name = txtname.Text.Trim
           .code = txtcode.Text.Trim
           .floor = txtfloor.Text.Trim
           .office = txtoffice.Text.Trim
           .serial = txtSerial.Text.Trim
           .laptob = txtLaptob.Text.Trim
           .pc = txtpc.Text.Trim
           .description = txtDescription.Text.Trim
           .comment = txtComment.Text.Trim
           .usbm = txtUsbModam.Text.Trim
           .datee = txtDatee.Value
           .SNram1 = txtram1.Text.Trim
           .SNram2 = txtram2.Text.Trim
           .SNram3 = txtram3.Text.Trim
           .SNram4 = txtram4.Text.Trim
           .image1 = pbox.Image
           .imagechange = imagechange
           pbox.Image = Nothing
       End With
       temp = pc.Edit(ID)
       pc = Nothing
       Return temp
   End Function
   Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles Edit_Button.Click
       'Dim bm As Bitmap = pbox.Image
       'Dim BO1 As Boolean = True
       'Try
       '    If bm.Width > Nothing Then BO1 = False
       'Catch ex As Exception
       'End Try
       If (String.IsNullOrWhiteSpace(txtname.Text) AndAlso String.IsNullOrWhiteSpace(txtcode.Text) AndAlso String.IsNullOrWhiteSpace(txtfloor.Text) AndAlso String.IsNullOrWhiteSpace(txtoffice.Text) AndAlso String.IsNullOrWhiteSpace(txtSerial.Text) AndAlso String.IsNullOrWhiteSpace(txtLaptob.Text) AndAlso String.IsNullOrWhiteSpace(txtpc.Text) AndAlso String.IsNullOrWhiteSpace(txtDescription.Text) AndAlso String.IsNullOrWhiteSpace(txtComment.Text) AndAlso String.IsNullOrWhiteSpace(txtUsbModam.Text) Or IsNothing(pbox.Image)) Then
           MessageBox.Show("يجب ملئ الخانات قبل الاضافه")
           Return
       End If
       If ID = 0 Then
           SaveLog("إضافة سجل", Me.Text, "تمت عملية إضافة سجل جديد بإسم : " & txtname.Text)
           If Add() Then
               LoadData()
               ClearForm()
           End If
       Else
           SaveLog("تعديل سجل", Me.Text, "تمت عملية تعديل سجل بإسم : " & txtname.Text)
           If Edit() Then
               LoadData()
               ClearForm()
           End If
       End If
   End Sub
   Function LoadData() As DataTable
       Dim temp As New DataTable
       If Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = True Then
           Cnn = New SqlConnection(CnnString)
       ElseIf Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = False Then
           Cnn = New SqlConnection(CnnString1)
       End If
       Cmd = New SqlCommand
       Cmd.CommandText = "Select  * From PC"
       Cmd.CommandType = CommandType.Text
       Cmd.Connection = Cnn
       Try
           Cnn.Open()
           temp.Load(Cmd.ExecuteReader())
           DataGridView1.AutoGenerateColumns = False
           'DataGridView1.DataSource = temp
           FillDesignDGV(DataGridView1, "Select  * From PC")
       Catch ex As SqlException
           MsgBox(ex.Message)
       Finally
           If Cmd IsNot Nothing Then
               Cmd.Dispose()
               Cmd = Nothing
           End If
           If Cnn IsNot Nothing Then
               Cnn.Close()
               Cnn.Dispose()
               Cnn = Nothing
           End If
       End Try
       Return temp
   End Function
   Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       SaveLog(MyBase.Text, Me.Text, "تمت عملية فتح النافذة التالية : " & MyBase.Text)
       LoadData()
   End Sub
   Function LoadOneDetail(id As Integer) As DataTable
       Dim temp As New DataTable
       If Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = True Then
           Cnn = New SqlConnection(CnnString)
       ElseIf Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = False Then
           Cnn = New SqlConnection(CnnString1)
       End If
       Cmd = New SqlCommand
       Cmd.CommandText = "Select  * From PC where id  = @id "
       Cmd.CommandType = CommandType.Text
       Cmd.Parameters.Add("@Id", SqlDbType.Int).Value = id
       Cmd.Connection = Cnn
       Try
           Cnn.Open()
           temp.Load(Cmd.ExecuteReader())
           If temp.Rows.Count <> 0 Then
               Me.ID = temp.Rows(0).Item("ID")
               txtname.Text = temp.Rows(0).Item("Name").ToString
               txtcode.Text = temp.Rows(0).Item("code").ToString
               txtfloor.Text = temp.Rows(0).Item("floor").ToString
               txtoffice.Text = temp.Rows(0).Item("office").ToString
               txtSerial.Text = temp.Rows(0).Item("serial").ToString
               txtLaptob.Text = temp.Rows(0).Item("laptob").ToString
               txtpc.Text = temp.Rows(0).Item("pc").ToString
               txtDescription.Text = temp.Rows(0).Item("description").ToString
               txtComment.Text = temp.Rows(0).Item("comment").ToString
               txtUsbModam.Text = temp.Rows(0).Item("usbm").ToString
               txtDatee.Value = temp.Rows(0).Item("datee")
               txtram1.Text = temp.Rows(0).Item("txtram1").ToString
               txtram2.Text = temp.Rows(0).Item("txtram2").ToString
               txtram3.Text = temp.Rows(0).Item("txtram3").ToString
               txtram4.Text = temp.Rows(0).Item("txtram4").ToString
               Dim b() As Byte
               b = temp.Rows(0).Item("image1")
               Dim ms As New MemoryStream(b)
               pbox.Image = Image.FromStream(ms)
               ms.Dispose()
           End If
       Catch ex As SqlException
           MsgBox(ex.Message)
       Finally
           If Cmd IsNot Nothing Then
               Cmd.Dispose()
               Cmd = Nothing
           End If
           If Cnn IsNot Nothing Then
               Cnn.Close()
               Cnn.Dispose()
               Cnn = Nothing
           End If
       End Try
       Return temp
   End Function
   Dim imagechange As Boolean
   Private Sub DataGridView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles DataGridView1.MouseDoubleClick
       LoadOneDetail(DataGridView1.CurrentRow.Cells(clID.Name).Value)
       imagechange = False

   End Sub
   Private Sub ClearForm()
       ID = 0
       For Each ctl In Me.Controls
           If TypeOf (ctl) Is TextBox Then
               CType(ctl, TextBox).Clear()
           ElseIf TypeOf (ctl) Is DateTimePicker Then
               CType(ctl, DateTimePicker).Value = Today.Date
           End If
       Next
   End Sub
   Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles Delete_Button.Click
       If ID = 0 Then
           MsgBox("Set the detail you want to delete.")
       Else
           If MsgBox("Are you sure you want to delete?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
               SaveLog("حذف سجل", Me.Text, "تمت عملية حذف سجل  بإسم : " & txtname.Text)
               If PC.Delete(ID) Then
                   LoadData()
                   ClearForm()
               End If
           End If
       End If
   End Sub
   Private Sub btnNew_Click(sender As Object, e As EventArgs) Handles Add_Button.Click
       ClearForm()
       pbox.Image = Nothing
   End Sub

   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Import_Button.Click
       ofd.FileName = ""
       ofd.Filter = "Image Files (JPEG,GIF,BMP,PNG,ICO)|*.jpg;*.jpeg;*.gif;*.bmp;*.png;*ico"
       ofd.ShowDialog()
       If ofd.FileName = "" Then Exit Sub
       pbox.Image = Image.FromFile(ofd.FileName)
       imagechange = True

   End Sub

   Private Sub pbox_Click(sender As Object, e As EventArgs) Handles pbox.Click

   End Sub

   Private Sub txtname_TextChanged(sender As Object, e As EventArgs) Handles txtname.TextChanged
       ''If txtname Is Nothing Then
       ''    txtname.BackColor = Color.DarkCyan
       ''    '  txtname.BackColor = Color.DarkCyan
       'End If
   End Sub

   Private Sub txtcode_TextChanged(sender As Object, e As EventArgs) Handles txtcode.TextChanged

   End Sub

   Private Sub txtfloor_TextChanged(sender As Object, e As EventArgs) Handles txtfloor.TextChanged

   End Sub

   Private Sub txtoffice_TextChanged(sender As Object, e As EventArgs) Handles txtoffice.TextChanged

   End Sub

   Private Sub txtSerial_TextChanged(sender As Object, e As EventArgs) Handles txtSerial.TextChanged

   End Sub

   Private Sub txtpc_TextChanged(sender As Object, e As EventArgs) Handles txtpc.TextChanged

   End Sub

   Private Sub txtDescription_TextChanged(sender As Object, e As EventArgs) Handles txtDescription.TextChanged

   End Sub

   Private Sub Label8_Click(sender As Object, e As EventArgs) Handles Label8.Click

   End Sub

   Private Sub Label7_Click(sender As Object, e As EventArgs) Handles Label7.Click

   End Sub

   Private Sub txtComment_TextChanged(sender As Object, e As EventArgs) Handles txtComment.TextChanged

   End Sub

   Private Sub txtDatee_ValueChanged(sender As Object, e As EventArgs) Handles txtDatee.ValueChanged

   End Sub

   Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

   End Sub

   Private Sub ofd_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles ofd.FileOk

   End Sub

   Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

   End Sub

   Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click

   End Sub

   Private Sub Label9_Click(sender As Object, e As EventArgs) Handles Label9.Click

   End Sub

   Private Sub Label10_Click(sender As Object, e As EventArgs) Handles Label10.Click

   End Sub
   Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
       Dim temp As New DataTable
       If Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = True Then
           Cnn = New SqlConnection(CnnString)
       ElseIf Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = False Then
           Cnn = New SqlConnection(CnnString1)
       End If

       Dim r As DataGridViewRow = Me.DataGridView1.CurrentRow
       Dim iD = r.Cells("clID").Value

       Dim cmd As New SqlCommand("Select [image1] From [PC] WHERE [iD]=@iD", Cnn)
       cmd.Parameters.AddWithValue("@iD", iD)
       If Cnn.State <> ConnectionState.Open Then Cnn.Open()
       Dim obj As Object = cmd.ExecuteScalar
       Cnn.Close()

       If obj IsNot Nothing AndAlso Not IsDBNull(obj) Then
           Dim stream As New IO.MemoryStream(CType(obj, Byte()))
           Dim img As Image = Image.FromStream(stream)

           Dim SaveFileAs As New SaveFileDialog
           SaveFileAs.Title = "Save File As"
           SaveFileAs.Filter = "Image Files (JPEG)|*.jpg;*.jpeg"
           If SaveFileAs.ShowDialog() = DialogResult.OK Then
               img.Save(SaveFileAs.FileName, Imaging.ImageFormat.Jpeg)
               MsgBox("تم حفظ الصورة")
           End If
       End If
   End Sub
End Class


كود الكلاس


Imports System.Data.SqlClient
Imports System.Drawing.Imaging
Imports System.IO

Public Class PC
    Property ID As String
    Property Name As String
    Property code As String
    Property floor As String
    Property office As String
    Property serial As String
    Property laptob As String
    Property pc As String
    Property description As String
    Property comment As String
    Property usbm As String
    Property datee As Date
    Property SNram1 As String
    Property SNram2 As String
    Property SNram3 As String
    Property SNram4 As String
    Property image1 As Image
    Property imagechange As Boolean
    Function Add() As Integer
        Dim temp As Integer
        If Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = True Then
            Cnn = New SqlConnection(CnnString)
        ElseIf Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = False Then
            Cnn = New SqlConnection(CnnString1)
        End If
        Cmd = New SqlCommand
        Cmd.CommandText = "AddPC"
        Cmd.CommandType = CommandType.StoredProcedure
        Cmd.Connection = Cnn
        Cmd.Parameters.AddWithValue("@ID", ID)
        Cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = Name
        Cmd.Parameters.Add("@code", SqlDbType.NVarChar).Value = code
        Cmd.Parameters.Add("@floor", SqlDbType.NVarChar).Value = floor
        Cmd.Parameters.Add("@office", SqlDbType.NVarChar).Value = office
        Cmd.Parameters.Add("@serial", SqlDbType.NVarChar).Value = serial
        Cmd.Parameters.Add("@laptob", SqlDbType.NVarChar).Value = laptob
        Cmd.Parameters.Add("@pc", SqlDbType.NVarChar).Value = pc
        Cmd.Parameters.Add("@description", SqlDbType.NVarChar).Value = description
        Cmd.Parameters.Add("@comment", SqlDbType.NVarChar).Value = comment
        Cmd.Parameters.Add("@usbm", SqlDbType.NVarChar).Value = usbm
        Cmd.Parameters.Add("@datee", SqlDbType.Date).Value = datee
        Cmd.Parameters.Add("@txtram1", SqlDbType.NVarChar).Value = SNram1
        Cmd.Parameters.Add("@txtram2", SqlDbType.NVarChar).Value = SNram2
        Cmd.Parameters.Add("@txtram3", SqlDbType.NVarChar).Value = SNram3
        Cmd.Parameters.Add("@txtram4", SqlDbType.NVarChar).Value = SNram4
        Dim imgByteArray() As Byte
        Dim stream As New MemoryStream

        image1.Save(stream, ImageFormat.Jpeg)

        imgByteArray = stream.ToArray()
            Cmd.Parameters.AddWithValue("@image1", imgByteArray)
            stream.Close()
            Cnn.Open()

        If Cmd.ExecuteNonQuery() <> 0 Then
                temp = True
            End If
            If Cmd IsNot Nothing Then
                Cmd.Dispose()
                Cmd = Nothing
            End If
            If Cnn IsNot Nothing Then
                Cnn.Close()
                Cnn.Dispose()
                Cnn = Nothing
            End If
            Return temp

    End Function
    Public Img() As Byte = Nothing
    Private pbox As Object

    Public Function GetImg(ByVal FilePath As String) As Byte()
        Dim Strem As FileStream = New FileStream(FilePath, FileMode.Open, FileAccess.Read)
        Dim Reader As BinaryReader = New BinaryReader(Strem)
        Dim Img() As Byte = Reader.ReadBytes(Strem.Length)
        Reader.Close()
        Strem.Close()
        Return Img
    End Function

    Function Edit(id As Integer) As Boolean
        Dim temp As Boolean
        If Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = True Then
            Cnn = New SqlConnection(CnnString)
        ElseIf Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = False Then
            Cnn = New SqlConnection(CnnString1)
        End If
        Cmd = New SqlCommand
        Cmd.CommandText = "Editpc"
        Cmd.CommandType = CommandType.StoredProcedure
        Cmd.Connection = Cnn
        Cmd.Parameters.AddWithValue("@ID", id)
        Cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = Name
        Cmd.Parameters.Add("@code", SqlDbType.NVarChar).Value = code
        Cmd.Parameters.Add("@floor", SqlDbType.NVarChar).Value = floor
        Cmd.Parameters.Add("@office", SqlDbType.NVarChar).Value = office
        Cmd.Parameters.Add("@serial", SqlDbType.NVarChar).Value = serial
        Cmd.Parameters.Add("@laptob", SqlDbType.NVarChar).Value = laptob
        Cmd.Parameters.Add("@pc", SqlDbType.NVarChar).Value = pc
        Cmd.Parameters.Add("@description", SqlDbType.NVarChar).Value = description
        Cmd.Parameters.Add("@comment", SqlDbType.NVarChar).Value = comment
        Cmd.Parameters.Add("@usbm", SqlDbType.NVarChar).Value = usbm
        Cmd.Parameters.Add("@datee", SqlDbType.Date).Value = datee
        Cmd.Parameters.Add("@txtram1", SqlDbType.NVarChar).Value = SNram1
        Cmd.Parameters.Add("@txtram2", SqlDbType.NVarChar).Value = SNram2
        Cmd.Parameters.Add("@txtram3", SqlDbType.NVarChar).Value = SNram3
        Cmd.Parameters.Add("@txtram4", SqlDbType.NVarChar).Value = SNram4

        Try
            Cnn.Open()
            If Cmd.ExecuteNonQuery() <> 0 Then
                temp = True
                If imagechange = True Then
                    Cmd = New SqlCommand
                    Cmd.CommandText = "editimagem"
                    Cmd.CommandType = CommandType.StoredProcedure
                    Cmd.Connection = Cnn
                    Cmd.Parameters.AddWithValue("@ID", id)
                    Dim imgByteArray() As Byte

                    Dim stream As New MemoryStream
                    image1.Save(stream, ImageFormat.Jpeg)
                    imgByteArray = stream.ToArray()
                    Cmd.Parameters.AddWithValue("@image1", imgByteArray)

                    Cmd.ExecuteNonQuery()
                    stream.Close()
                End If
            End If
        Catch ex As SqlException
            MsgBox(ex.Message)
        Finally
            If Cmd IsNot Nothing Then
                Cmd.Dispose()
                Cmd = Nothing
            End If
            If Cnn IsNot Nothing Then
                Cnn.Close()
                Cnn.Dispose()
                Cnn = Nothing
            End If
        End Try
        Return temp
    End Function
    Shared Function Delete(id As Integer) As Boolean
        Dim temp As Boolean
        If Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = True Then
            Cnn = New SqlConnection(CnnString)
        ElseIf Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = False Then
            Cnn = New SqlConnection(CnnString1)
        End If
        Cmd = New SqlCommand
        Cmd.CommandText = "Deletepc"
        Cmd.CommandType = CommandType.StoredProcedure
        Cmd.Connection = Cnn
        Cmd.Parameters.AddWithValue("@ID", id)
        Try
            Cnn.Open()
            If Cmd.ExecuteNonQuery() <> 0 Then
                temp = True
            End If
        Catch ex As SqlException
            MsgBox(ex.Message)
        Finally
            If Cmd IsNot Nothing Then
                Cmd.Dispose()
                Cmd = Nothing
            End If
            If Cnn IsNot Nothing Then
                Cnn.Close()
                Cnn.Dispose()
                Cnn = Nothing
            End If
        End Try
        Return temp
    End Function

End Class
الرد
تم الشكر بواسطة:
#2
(07-02-20, 09:24 PM)محمدالزند كتب : الكود بيقبل الصور  محتاج اضيف معا pdf
كود :
Imports System.Data.SqlClient
Imports System.IO
Public Class Form9
   Public ID As Integer
   Private Function Add() As Boolean
       Dim temp As Boolean
       Dim pc As New PC
       With pc
           .ID = GetCount("PC")
           .Name = txtname.Text.Trim
           .code = txtcode.Text.Trim
           .floor = txtfloor.Text.Trim
           .office = txtoffice.Text.Trim
           .serial = txtSerial.Text.Trim
           .laptob = txtLaptob.Text.Trim
           .pc = txtpc.Text.Trim
           .description = txtDescription.Text.Trim
           .comment = txtComment.Text.Trim
           .usbm = txtUsbModam.Text.Trim
           .datee = txtDatee.Value
           .SNram1 = txtram1.Text.Trim
           .SNram2 = txtram2.Text.Trim
           .SNram3 = txtram3.Text.Trim
           .SNram4 = txtram4.Text.Trim
           .image1 = pbox.Image
           pbox.Image = Nothing
       End With
       temp = pc.Add()
       pc = Nothing
       Return temp
   End Function
   Private Function Edit() As Boolean
       Dim temp As Boolean
       Dim pc As New PC
       With pc
           .ID = ID
           .Name = txtname.Text.Trim
           .code = txtcode.Text.Trim
           .floor = txtfloor.Text.Trim
           .office = txtoffice.Text.Trim
           .serial = txtSerial.Text.Trim
           .laptob = txtLaptob.Text.Trim
           .pc = txtpc.Text.Trim
           .description = txtDescription.Text.Trim
           .comment = txtComment.Text.Trim
           .usbm = txtUsbModam.Text.Trim
           .datee = txtDatee.Value
           .SNram1 = txtram1.Text.Trim
           .SNram2 = txtram2.Text.Trim
           .SNram3 = txtram3.Text.Trim
           .SNram4 = txtram4.Text.Trim
           .image1 = pbox.Image
           .imagechange = imagechange
           pbox.Image = Nothing
       End With
       temp = pc.Edit(ID)
       pc = Nothing
       Return temp
   End Function
   Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles Edit_Button.Click
       'Dim bm As Bitmap = pbox.Image
       'Dim BO1 As Boolean = True
       'Try
       '    If bm.Width > Nothing Then BO1 = False
       'Catch ex As Exception
       'End Try
       If (String.IsNullOrWhiteSpace(txtname.Text) AndAlso String.IsNullOrWhiteSpace(txtcode.Text) AndAlso String.IsNullOrWhiteSpace(txtfloor.Text) AndAlso String.IsNullOrWhiteSpace(txtoffice.Text) AndAlso String.IsNullOrWhiteSpace(txtSerial.Text) AndAlso String.IsNullOrWhiteSpace(txtLaptob.Text) AndAlso String.IsNullOrWhiteSpace(txtpc.Text) AndAlso String.IsNullOrWhiteSpace(txtDescription.Text) AndAlso String.IsNullOrWhiteSpace(txtComment.Text) AndAlso String.IsNullOrWhiteSpace(txtUsbModam.Text) Or IsNothing(pbox.Image)) Then
           MessageBox.Show("يجب ملئ الخانات قبل الاضافه")
           Return
       End If
       If ID = 0 Then
           SaveLog("إضافة سجل", Me.Text, "تمت عملية إضافة سجل جديد بإسم : " & txtname.Text)
           If Add() Then
               LoadData()
               ClearForm()
           End If
       Else
           SaveLog("تعديل سجل", Me.Text, "تمت عملية تعديل سجل بإسم : " & txtname.Text)
           If Edit() Then
               LoadData()
               ClearForm()
           End If
       End If
   End Sub
   Function LoadData() As DataTable
       Dim temp As New DataTable
       If Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = True Then
           Cnn = New SqlConnection(CnnString)
       ElseIf Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = False Then
           Cnn = New SqlConnection(CnnString1)
       End If
       Cmd = New SqlCommand
       Cmd.CommandText = "Select  * From PC"
       Cmd.CommandType = CommandType.Text
       Cmd.Connection = Cnn
       Try
           Cnn.Open()
           temp.Load(Cmd.ExecuteReader())
           DataGridView1.AutoGenerateColumns = False
           'DataGridView1.DataSource = temp
           FillDesignDGV(DataGridView1, "Select  * From PC")
       Catch ex As SqlException
           MsgBox(ex.Message)
       Finally
           If Cmd IsNot Nothing Then
               Cmd.Dispose()
               Cmd = Nothing
           End If
           If Cnn IsNot Nothing Then
               Cnn.Close()
               Cnn.Dispose()
               Cnn = Nothing
           End If
       End Try
       Return temp
   End Function
   Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       SaveLog(MyBase.Text, Me.Text, "تمت عملية فتح النافذة التالية : " & MyBase.Text)
       LoadData()
   End Sub
   Function LoadOneDetail(id As Integer) As DataTable
       Dim temp As New DataTable
       If Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = True Then
           Cnn = New SqlConnection(CnnString)
       ElseIf Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = False Then
           Cnn = New SqlConnection(CnnString1)
       End If
       Cmd = New SqlCommand
       Cmd.CommandText = "Select  * From PC where id  = @id "
       Cmd.CommandType = CommandType.Text
       Cmd.Parameters.Add("@Id", SqlDbType.Int).Value = id
       Cmd.Connection = Cnn
       Try
           Cnn.Open()
           temp.Load(Cmd.ExecuteReader())
           If temp.Rows.Count <> 0 Then
               Me.ID = temp.Rows(0).Item("ID")
               txtname.Text = temp.Rows(0).Item("Name").ToString
               txtcode.Text = temp.Rows(0).Item("code").ToString
               txtfloor.Text = temp.Rows(0).Item("floor").ToString
               txtoffice.Text = temp.Rows(0).Item("office").ToString
               txtSerial.Text = temp.Rows(0).Item("serial").ToString
               txtLaptob.Text = temp.Rows(0).Item("laptob").ToString
               txtpc.Text = temp.Rows(0).Item("pc").ToString
               txtDescription.Text = temp.Rows(0).Item("description").ToString
               txtComment.Text = temp.Rows(0).Item("comment").ToString
               txtUsbModam.Text = temp.Rows(0).Item("usbm").ToString
               txtDatee.Value = temp.Rows(0).Item("datee")
               txtram1.Text = temp.Rows(0).Item("txtram1").ToString
               txtram2.Text = temp.Rows(0).Item("txtram2").ToString
               txtram3.Text = temp.Rows(0).Item("txtram3").ToString
               txtram4.Text = temp.Rows(0).Item("txtram4").ToString
               Dim b() As Byte
               b = temp.Rows(0).Item("image1")
               Dim ms As New MemoryStream(b)
               pbox.Image = Image.FromStream(ms)
               ms.Dispose()
           End If
       Catch ex As SqlException
           MsgBox(ex.Message)
       Finally
           If Cmd IsNot Nothing Then
               Cmd.Dispose()
               Cmd = Nothing
           End If
           If Cnn IsNot Nothing Then
               Cnn.Close()
               Cnn.Dispose()
               Cnn = Nothing
           End If
       End Try
       Return temp
   End Function
   Dim imagechange As Boolean
   Private Sub DataGridView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles DataGridView1.MouseDoubleClick
       LoadOneDetail(DataGridView1.CurrentRow.Cells(clID.Name).Value)
       imagechange = False

   End Sub
   Private Sub ClearForm()
       ID = 0
       For Each ctl In Me.Controls
           If TypeOf (ctl) Is TextBox Then
               CType(ctl, TextBox).Clear()
           ElseIf TypeOf (ctl) Is DateTimePicker Then
               CType(ctl, DateTimePicker).Value = Today.Date
           End If
       Next
   End Sub
   Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles Delete_Button.Click
       If ID = 0 Then
           MsgBox("Set the detail you want to delete.")
       Else
           If MsgBox("Are you sure you want to delete?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
               SaveLog("حذف سجل", Me.Text, "تمت عملية حذف سجل  بإسم : " & txtname.Text)
               If PC.Delete(ID) Then
                   LoadData()
                   ClearForm()
               End If
           End If
       End If
   End Sub
   Private Sub btnNew_Click(sender As Object, e As EventArgs) Handles Add_Button.Click
       ClearForm()
       pbox.Image = Nothing
   End Sub

   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Import_Button.Click
       ofd.FileName = ""
       ofd.Filter = "Image Files (JPEG,GIF,BMP,PNG,ICO)|*.jpg;*.jpeg;*.gif;*.bmp;*.png;*ico"
       ofd.ShowDialog()
       If ofd.FileName = "" Then Exit Sub
       pbox.Image = Image.FromFile(ofd.FileName)
       imagechange = True

   End Sub

   Private Sub pbox_Click(sender As Object, e As EventArgs) Handles pbox.Click

   End Sub

   Private Sub txtname_TextChanged(sender As Object, e As EventArgs) Handles txtname.TextChanged
       ''If txtname Is Nothing Then
       ''    txtname.BackColor = Color.DarkCyan
       ''    '  txtname.BackColor = Color.DarkCyan
       'End If
   End Sub

   Private Sub txtcode_TextChanged(sender As Object, e As EventArgs) Handles txtcode.TextChanged

   End Sub

   Private Sub txtfloor_TextChanged(sender As Object, e As EventArgs) Handles txtfloor.TextChanged

   End Sub

   Private Sub txtoffice_TextChanged(sender As Object, e As EventArgs) Handles txtoffice.TextChanged

   End Sub

   Private Sub txtSerial_TextChanged(sender As Object, e As EventArgs) Handles txtSerial.TextChanged

   End Sub

   Private Sub txtpc_TextChanged(sender As Object, e As EventArgs) Handles txtpc.TextChanged

   End Sub

   Private Sub txtDescription_TextChanged(sender As Object, e As EventArgs) Handles txtDescription.TextChanged

   End Sub

   Private Sub Label8_Click(sender As Object, e As EventArgs) Handles Label8.Click

   End Sub

   Private Sub Label7_Click(sender As Object, e As EventArgs) Handles Label7.Click

   End Sub

   Private Sub txtComment_TextChanged(sender As Object, e As EventArgs) Handles txtComment.TextChanged

   End Sub

   Private Sub txtDatee_ValueChanged(sender As Object, e As EventArgs) Handles txtDatee.ValueChanged

   End Sub

   Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

   End Sub

   Private Sub ofd_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles ofd.FileOk

   End Sub

   Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

   End Sub

   Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click

   End Sub

   Private Sub Label9_Click(sender As Object, e As EventArgs) Handles Label9.Click

   End Sub

   Private Sub Label10_Click(sender As Object, e As EventArgs) Handles Label10.Click

   End Sub
   Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
       Dim temp As New DataTable
       If Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = True Then
           Cnn = New SqlConnection(CnnString)
       ElseIf Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = False Then
           Cnn = New SqlConnection(CnnString1)
       End If

       Dim r As DataGridViewRow = Me.DataGridView1.CurrentRow
       Dim iD = r.Cells("clID").Value

       Dim cmd As New SqlCommand("Select [image1] From [PC] WHERE [iD]=@iD", Cnn)
       cmd.Parameters.AddWithValue("@iD", iD)
       If Cnn.State <> ConnectionState.Open Then Cnn.Open()
       Dim obj As Object = cmd.ExecuteScalar
       Cnn.Close()

       If obj IsNot Nothing AndAlso Not IsDBNull(obj) Then
           Dim stream As New IO.MemoryStream(CType(obj, Byte()))
           Dim img As Image = Image.FromStream(stream)

           Dim SaveFileAs As New SaveFileDialog
           SaveFileAs.Title = "Save File As"
           SaveFileAs.Filter = "Image Files (JPEG)|*.jpg;*.jpeg"
           If SaveFileAs.ShowDialog() = DialogResult.OK Then
               img.Save(SaveFileAs.FileName, Imaging.ImageFormat.Jpeg)
               MsgBox("تم حفظ الصورة")
           End If
       End If
   End Sub
End Class


كود الكلاس


Imports System.Data.SqlClient
Imports System.Drawing.Imaging
Imports System.IO

Public Class PC
    Property ID As String
    Property Name As String
    Property code As String
    Property floor As String
    Property office As String
    Property serial As String
    Property laptob As String
    Property pc As String
    Property description As String
    Property comment As String
    Property usbm As String
    Property datee As Date
    Property SNram1 As String
    Property SNram2 As String
    Property SNram3 As String
    Property SNram4 As String
    Property image1 As Image
    Property imagechange As Boolean
    Function Add() As Integer
        Dim temp As Integer
        If Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = True Then
            Cnn = New SqlConnection(CnnString)
        ElseIf Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = False Then
            Cnn = New SqlConnection(CnnString1)
        End If
        Cmd = New SqlCommand
        Cmd.CommandText = "AddPC"
        Cmd.CommandType = CommandType.StoredProcedure
        Cmd.Connection = Cnn
        Cmd.Parameters.AddWithValue("@ID", ID)
        Cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = Name
        Cmd.Parameters.Add("@code", SqlDbType.NVarChar).Value = code
        Cmd.Parameters.Add("@floor", SqlDbType.NVarChar).Value = floor
        Cmd.Parameters.Add("@office", SqlDbType.NVarChar).Value = office
        Cmd.Parameters.Add("@serial", SqlDbType.NVarChar).Value = serial
        Cmd.Parameters.Add("@laptob", SqlDbType.NVarChar).Value = laptob
        Cmd.Parameters.Add("@pc", SqlDbType.NVarChar).Value = pc
        Cmd.Parameters.Add("@description", SqlDbType.NVarChar).Value = description
        Cmd.Parameters.Add("@comment", SqlDbType.NVarChar).Value = comment
        Cmd.Parameters.Add("@usbm", SqlDbType.NVarChar).Value = usbm
        Cmd.Parameters.Add("@datee", SqlDbType.Date).Value = datee
        Cmd.Parameters.Add("@txtram1", SqlDbType.NVarChar).Value = SNram1
        Cmd.Parameters.Add("@txtram2", SqlDbType.NVarChar).Value = SNram2
        Cmd.Parameters.Add("@txtram3", SqlDbType.NVarChar).Value = SNram3
        Cmd.Parameters.Add("@txtram4", SqlDbType.NVarChar).Value = SNram4
        Dim imgByteArray() As Byte
        Dim stream As New MemoryStream

        image1.Save(stream, ImageFormat.Jpeg)

        imgByteArray = stream.ToArray()
            Cmd.Parameters.AddWithValue("@image1", imgByteArray)
            stream.Close()
            Cnn.Open()

        If Cmd.ExecuteNonQuery() <> 0 Then
                temp = True
            End If
            If Cmd IsNot Nothing Then
                Cmd.Dispose()
                Cmd = Nothing
            End If
            If Cnn IsNot Nothing Then
                Cnn.Close()
                Cnn.Dispose()
                Cnn = Nothing
            End If
            Return temp

    End Function
    Public Img() As Byte = Nothing
    Private pbox As Object

    Public Function GetImg(ByVal FilePath As String) As Byte()
        Dim Strem As FileStream = New FileStream(FilePath, FileMode.Open, FileAccess.Read)
        Dim Reader As BinaryReader = New BinaryReader(Strem)
        Dim Img() As Byte = Reader.ReadBytes(Strem.Length)
        Reader.Close()
        Strem.Close()
        Return Img
    End Function

    Function Edit(id As Integer) As Boolean
        Dim temp As Boolean
        If Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = True Then
            Cnn = New SqlConnection(CnnString)
        ElseIf Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = False Then
            Cnn = New SqlConnection(CnnString1)
        End If
        Cmd = New SqlCommand
        Cmd.CommandText = "Editpc"
        Cmd.CommandType = CommandType.StoredProcedure
        Cmd.Connection = Cnn
        Cmd.Parameters.AddWithValue("@ID", id)
        Cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = Name
        Cmd.Parameters.Add("@code", SqlDbType.NVarChar).Value = code
        Cmd.Parameters.Add("@floor", SqlDbType.NVarChar).Value = floor
        Cmd.Parameters.Add("@office", SqlDbType.NVarChar).Value = office
        Cmd.Parameters.Add("@serial", SqlDbType.NVarChar).Value = serial
        Cmd.Parameters.Add("@laptob", SqlDbType.NVarChar).Value = laptob
        Cmd.Parameters.Add("@pc", SqlDbType.NVarChar).Value = pc
        Cmd.Parameters.Add("@description", SqlDbType.NVarChar).Value = description
        Cmd.Parameters.Add("@comment", SqlDbType.NVarChar).Value = comment
        Cmd.Parameters.Add("@usbm", SqlDbType.NVarChar).Value = usbm
        Cmd.Parameters.Add("@datee", SqlDbType.Date).Value = datee
        Cmd.Parameters.Add("@txtram1", SqlDbType.NVarChar).Value = SNram1
        Cmd.Parameters.Add("@txtram2", SqlDbType.NVarChar).Value = SNram2
        Cmd.Parameters.Add("@txtram3", SqlDbType.NVarChar).Value = SNram3
        Cmd.Parameters.Add("@txtram4", SqlDbType.NVarChar).Value = SNram4

        Try
            Cnn.Open()
            If Cmd.ExecuteNonQuery() <> 0 Then
                temp = True
                If imagechange = True Then
                    Cmd = New SqlCommand
                    Cmd.CommandText = "editimagem"
                    Cmd.CommandType = CommandType.StoredProcedure
                    Cmd.Connection = Cnn
                    Cmd.Parameters.AddWithValue("@ID", id)
                    Dim imgByteArray() As Byte

                    Dim stream As New MemoryStream
                    image1.Save(stream, ImageFormat.Jpeg)
                    imgByteArray = stream.ToArray()
                    Cmd.Parameters.AddWithValue("@image1", imgByteArray)

                    Cmd.ExecuteNonQuery()
                    stream.Close()
                End If
            End If
        Catch ex As SqlException
            MsgBox(ex.Message)
        Finally
            If Cmd IsNot Nothing Then
                Cmd.Dispose()
                Cmd = Nothing
            End If
            If Cnn IsNot Nothing Then
                Cnn.Close()
                Cnn.Dispose()
                Cnn = Nothing
            End If
        End Try
        Return temp
    End Function
    Shared Function Delete(id As Integer) As Boolean
        Dim temp As Boolean
        If Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = True Then
            Cnn = New SqlConnection(CnnString)
        ElseIf Convert.ToBoolean(GetValueFromRegistry("WindowsOrSqlServer")) = False Then
            Cnn = New SqlConnection(CnnString1)
        End If
        Cmd = New SqlCommand
        Cmd.CommandText = "Deletepc"
        Cmd.CommandType = CommandType.StoredProcedure
        Cmd.Connection = Cnn
        Cmd.Parameters.AddWithValue("@ID", id)
        Try
            Cnn.Open()
            If Cmd.ExecuteNonQuery() <> 0 Then
                temp = True
            End If
        Catch ex As SqlException
            MsgBox(ex.Message)
        Finally
            If Cmd IsNot Nothing Then
                Cmd.Dispose()
                Cmd = Nothing
            End If
            If Cnn IsNot Nothing Then
                Cnn.Close()
                Cnn.Dispose()
                Cnn = Nothing
            End If
        End Try
        Return temp
    End Function

End Class

اذا كنت تعرف كيف تضيف الصور فهو مثل الصور
الاختلاف في اللاحقة Extension للملف
الرد
تم الشكر بواسطة: محمدالزند
#3
الاسف جربت اضيفة معاهم ولم ينفع الكود

bit outside

لو ارد مساعدتي في اضافة كود p d f

هذه بيانات any disk
605498806
الرد
تم الشكر بواسطة:
#4
(07-02-20, 09:38 PM)محمدالزند كتب : الاسف جربت اضيفة معاهم ولم ينفع الكود

bit outside

هل تريد عرض ملف PDF خارج المشروع مثل برنامج Acrobat او متصفح كروم؟
الرد
تم الشكر بواسطة:
#5
اتفضل يا اخي

اي حاجة مش هتفرق Sad
الرد
تم الشكر بواسطة:
#6
(07-02-20, 10:27 PM)محمدالزند كتب : اتفضل يا اخي

اي حاجة مش هتفرق Sad

معناته اضف عمود وليكن مخفي يتم فيه تحديد نوع الملف مثل .pdf أو .jpg وهكذا
الرد
تم الشكر بواسطة:
#7
تمام اتفضل يا اخي الباب مفتوح
605498806
الرد
تم الشكر بواسطة:
#8
الف شكر يا غالي وانا اسف علي الازعاج
الرد
تم الشكر بواسطة:
#9
alsalamoni مستنيك نكمل التعديل باذن الله

(07-02-20, 10:33 PM)alsalamoni كتب :
(07-02-20, 10:27 PM)محمدالزند كتب : اتفضل يا اخي

اي حاجة مش هتفرق  Sad

معناته اضف عمود وليكن مخفي يتم فيه تحديد نوع الملف مثل .pdf أو .jpg وهكذا

مستنيك يا اخي نكمل التعديل
الرد
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [VB.NET] اضافة اللغة واستردادها من ملف بصيغة ini ميدو الفنان 11 907 منذ 6 ساعة مضت
آخر رد: عمور2016
  اضافة ملف pdf الى قاعدة بيانات sql server 2012 moh developer 5 68 منذ 7 ساعة مضت
آخر رد: moh developer
  مشكلة في كود اضافة الى sql 2012 moh developer 13 295 , 01:25 AM
آخر رد: Mohamad Anan
Rainbow [كود] ماهو الخطا في الكود الموضح لكم محمد مسافر 2 67 23-09-20, 01:09 AM
آخر رد: محمد مسافر
  هل يمكن اضافة اشعار صوتى mostafa nada 4 97 22-09-20, 03:36 PM
آخر رد: mostafa nada
  عندي مشكلة بخصوص الكود هدا The program '[13020] MainProj.exe' has exited with code 0 ٍOfelas 1 55 21-09-20, 12:27 AM
آخر رد: Anas Mahmoud
  التعديل على الكود للتخلص من مشكلة البطىء حيث عدد السجلات كبير momani33 0 115 09-09-20, 01:33 PM
آخر رد: momani33
  ماهو الخطاء في هذا الكود عمور2016 1 122 06-09-20, 06:33 PM
آخر رد: حريف برمجة
  [سؤال] طرب الويندوز ومحتاج اجداد الكود سحاب روابط قائيمة تشغيل من اليتيوب Ali Edal 11 949 05-09-20, 03:36 PM
آخر رد: معاند الحظ
  مشكلة فى اضافة البيانات ممكن المساعدة talatm 7 342 04-09-20, 04:10 PM
آخر رد: عبد العزيز البسكري

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


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم