تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
بحاول اعمل صتدوق بحث
#1
قبل البحث
  


بعد البحث


كود البحث


كود :
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

           .datafile = IO.File.ReadAllBytes(Me.filename)
           .extfile = IO.Path.GetExtension(Me.filename)

           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 = 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

           If filename <> "" Then
               .datafile = IO.File.ReadAllBytes(Me.filename)
               .extfile = IO.Path.GetExtension(Me.filename)
           End If


           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
       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

       'Dim da As New SqlDataAdapter("Select  * From PC", Cnn)
       'Dim dt As New DataTable
       'da.Fill(dt)
       'Me.DataGridView1.DataSource = dt

       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")
           DataGridView1.DataSource = temp ' هنا يتم ربط البيانات
           ' لديم امرين لتعبئة الداتاجريد المفروض واحد منهم

           For Each r As DataGridViewRow In DataGridView1.Rows
               If r.Cells("extfile").Value.ToString.ToLower = ".pdf" Then
                   r.Cells("Column1").Value = My.Resources.pdf
               Else
                   r.Cells("Column1").Value = My.Resources.jpeg
               End If
           Next
       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
       Me.DataGridView1.AutoGenerateColumns = False

       SaveLog(MyBase.Text, Me.Text, "تمت عملية فتح النافذة التالية : " & MyBase.Text)
       LoadData()

       DataGridView1.AllowUserToDeleteRows = False
       DataGridView1.AllowUserToAddRows = False
       DataGridView1.ReadOnly = True

       Label16.Text = (From x In DataGridView1.Rows Where x.Cells("cllaptob").Value.Equals("yes")).Count
       Label19.Text = (From x In DataGridView1.Rows Where x.Cells("clpc").Value.Equals("yes")).Count
   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 = temp.Rows(0).Item("datafile")

               If temp.Rows(0).Item("extfile") = ".pdf" Then
                   pbox.Image = My.Resources.pdf
               Else
                   Dim ms As New MemoryStream(b)
                   pbox.Image = Image.FromStream(ms)
                   ms.Dispose()

               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
   Dim imagechange As Boolean
   Private Sub DataGridView1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles DataGridView1.MouseDoubleClick
       Dim id As Integer = Val(DataGridView1.CurrentRow.Cells("clID").Value.ToString)
       LoadOneDetail(id)
       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

   Dim filename As String

   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,PDF)|*.jpg;*.jpeg;*.gif;*.bmp;*.png;*.ico;*.pdf"
       If ofd.ShowDialog() = DialogResult.OK Then
           Me.filename = ofd.FileName

           Dim ext = IO.Path.GetExtension(filename)
           If ext.ToLower = ".pdf" Then
               pbox.Image = My.Resources.pdf
           Else
               pbox.Image = Image.FromFile(filename)
               imagechange = True
           End If

       End If

   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 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 As Integer = Val(r.Cells("clID").Value.ToString)
       Dim sr As Integer = r.Index + 1

       If MsgBox("هل تريد تحميل الصورة رقم: " & sr, MsgBoxStyle.YesNo) <> MsgBoxResult.Yes Then Exit Sub

       Dim cmd As New SqlCommand("Select [datafile] 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

           If r.Cells("extfile").Value = ".pdf" Then

               Dim SaveFileAs As New SaveFileDialog
               SaveFileAs.Title = "Save File As"
               SaveFileAs.Filter = "PDF Files (PDF)|*.pdf"
               If SaveFileAs.ShowDialog() = DialogResult.OK Then
                   IO.File.WriteAllBytes(SaveFileAs.FileName, obj)
                   MsgBox("تم حفظ الملف")
               End If


           Else
               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 If
   End Sub



   Private Sub DataGridView1_DataError(sender As Object, e As DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError
       ' يترك فاضي
   End Sub

   Private Sub DataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
       If sender.Columns(e.ColumnIndex).Name = "clSR" Then e.Value = e.RowIndex + 1
   End Sub


   Private Sub DataGridView1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
       'Try
       '    If DataGridView1.Rows(e.RowIndex).Cells("extfile").Value = ".pdf" Then
       '        DataGridView1.Rows(e.RowIndex).Cells("Column1").Value = My.Resources.pdf
       '    Else
       '        DataGridView1.Rows(e.RowIndex).Cells("Column1").Value = My.Resources.jpeg
       '    End If

       'Catch ex As Exception

       'End Try


   End Sub



   Private Sub _TextChanged(sender As Object, e As EventArgs) Handles txtLaptob.TextChanged
       If txtLaptob.Text = "" Then
           txtLaptob.BackColor = Color.Red
       Else
           txtLaptob.BackColor = Color.Black
       End If
   End Sub

   Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
       Dim SqlStr As String = String.Empty


       SqlStr = "SELECT name FROM Pc where [code] like N'%" & TextBox1.Text & "%' or [name] Like N'%" & TextBox1.Text & "%'"
       '  SqlStr = "SELECT * FROM Pc where [Name,code] like N'%" & TextBox1.Text & "%' or [ Name,code,floor,office,serial,laptob,pc,description,datee] Like N'%" & TextBox1.Text & "%'"
       FillDesignDGV(DataGridView1, SqlStr)
   End Sub
End Class
[/code]
الرد }}}
تم الشكر بواسطة:
#2
استبدل كلمة name بـ * في الاستعلام :

PHP كود :
SqlStr "SELECT * FROM Pc where [code] like N'%" TextBox1.Text "%' or [name] Like N'%" TextBox1.Text "%'" 
الرد }}}
تم الشكر بواسطة:
#3
(22-02-20, 04:58 PM)asemshahen5 كتب : استبدل كلمة name بـ * في الاستعلام :

PHP كود :
SqlStr "SELECT * FROM Pc where [code] like N'%" TextBox1.Text "%' or [name] Like N'%" TextBox1.Text "%'" 

المشكلة انه في صور   علشان كدة حاطط الكود في الموضوع   
عرض الصور بيجيب مربع وعليه كروس احمر
الرد }}}
تم الشكر بواسطة:
#4
هذا الكود كاملا :

PHP كود :
SqlStr "SELECT * FROM Pc where [code] like N'%" TextBox1.Text "%' or [name] Like N'%" TextBox1.Text "%'"
FillDesignDGV(DataGridView1SqlStr)
For 
Each r As DataGridViewRow In DataGridView1.Rows
    
If r.Cells("extfile").Value.ToString.ToLower ".pdf" Then
        r
.Cells("Column1").Value My.Resources.pdf
    
Else
 
       r.Cells("Column1").Value My.Resources.jpeg
    End 
If
Next 
الرد }}}
تم الشكر بواسطة:
#5
الف شكر يا غالي تم حل المشكلة
الرد }}}
تم الشكر بواسطة: asemshahen5
#6
الحمد لله و الشكر لله رب العالمين .
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [سؤال] كيف استطيع ان اعمل مثل هذه التبويبات في الواجهة كما في المرفق ادناه aYHAMMMS 0 298 14-07-23, 10:21 AM
آخر رد: aYHAMMMS
  مش قادر اعمل استيراد لقتعدة بيانات عندى حماده ممدوح البحيرى 2 765 01-08-22, 03:59 PM
آخر رد: aljzazy
  [سؤال] كيف يمكنني ان اعمل شاشة دخول مستخدم hassan 17 10,080 22-05-22, 03:30 AM
آخر رد: أبو خالد الشكري
  لو عايز اعمل اعلانات لمنتج معين Lathe1 1 991 26-05-21, 01:30 AM
آخر رد: Lathe1
  [سؤال] سؤال طريق اعمل بحث و اضافة و تعديل دخل قاعد البيانات فى نفس الوقت alims 1 1,298 15-03-21, 07:17 AM
آخر رد: alims
  عاوز اعمل رساله لمستخدمي البرنامج بتاعي عبر الانترنت كيف اضيف حاجه شكل دي ف البرنامج Hosam Ashraf Elwakel 1 1,498 10-02-21, 01:09 AM
آخر رد: أبو عبدالله الحلواني
  ازاي اعمل تثبيت تلقائي اليوم السابع 0 861 14-11-20, 02:53 AM
آخر رد: اليوم السابع
  ازاي اعمل shortcut file اليوم السابع 7 2,242 14-11-20, 02:35 AM
آخر رد: اليوم السابع
  بحاول اربط السكول بال crstal report Hosam Ashraf Elwakel 2 1,213 15-08-20, 12:27 AM
آخر رد: حريف برمجة
  عاوز اعمل Timer يشوف اللي معمول عليه صح ويعملو enable تلقائي Hosam Ashraf Elwakel 0 1,061 09-08-20, 07:41 PM
آخر رد: Hosam Ashraf Elwakel

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


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