PDA

View Full Version : سوال: مشکل در حذف و ویرایش برنامه



iran_sky
پنج شنبه 06 خرداد 1389, 19:13 عصر
با سلام به دوستان
مشکل این برنامه در مورد حذف و ویرایش این برنامه چیست
ممنون میشم کمکم کنید

iran_sky
جمعه 07 خرداد 1389, 13:30 عصر
کسی نیست کمکم کنه

Open-Source
جمعه 07 خرداد 1389, 21:04 عصر
من VS ندارم.
تکه کد هایی رو که نوشتی بزار اینجا.

iran_sky
شنبه 08 خرداد 1389, 01:01 صبح
سلام دوست عزیز
من اطلاعات رو از فایل به صورت تصادفی خوندم و در گرید قرار دادم و با کلیک روی سطرهای گرید اطلاعات اون سطر داخل تکست ها نمایش داده میشه حالا میخوام با انتخاب اون سطر از گرید و با کلیک روی دکمه حذف اطلاعات از داخل قایل پاک بشه و همچنین از داخل گرید و با ویرایش اطلاعات داخل تکستها و زدن کلید اطلاعات داخل گرید و فایل ویرایش بشه

این کد کل برنامه


Public Class Form1
Structure person
<VBFixedString(10)> Dim name As String
<VBFixedString(15)> Dim lastname As String
<VBFixedString(7)> Dim tel As String
<VBFixedString(15)> Dim addressas As String
End Structure
Dim p As person
Dim s As String = ""
Dim sa As String
'Dim x As Integer
Dim i As Integer = 1
Dim dtSource As New DataTable()
Dim col As DataColumn
Dim row As DataRow
Public Sub New()
InitializeComponent()
MakeTableCol()
DataGridView1.AutoGenerateColumns = False
DataGridView1.DataSource = dtSource
End Sub
Private Sub MakeTableCol()
col = New DataColumn("Name")
dtSource.Columns.Add(col)
col = New DataColumn("LastName")
dtSource.Columns.Add(col)
col = New DataColumn("Tel")
dtSource.Columns.Add(col)
col = New DataColumn("Address")
dtSource.Columns.Add(col)
End Sub
Private Sub btn_exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_exit.Click
Me.Close()
End Sub
Private Sub btn_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_save.Click
Dim f As Integer = FreeFile()
p.name = txt_name.Text
p.lastname = txt_lastname.Text
p.tel = txt_telephone.Text
p.addressas = txt_address.Text
Dim le As Integer = Len(p)
FileOpen(f, "e:\test.txt", OpenMode.Random, OpenAccess.Write, OpenShare.LockWrite, Len(p))
Dim l As Long = LOF(f) / Len(p)
FilePut(f, p, l + 1)
FileClose()
MsgBox(" ")
txt_name.Text = ""
txt_lastname.Text = ""
txt_telephone.Text = ""
txt_address.Text = ""
txt_name.Select()
End Sub
Private Sub btn_read_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_read.Click
Dim le As Integer = Len(p)
Dim fn As Byte = FreeFile()
FileOpen(fn, "test.txt", OpenMode.Random, OpenAccess.ReadWrite, OpenShare.Default, Len(p))
Dim index As Integer = 1
While Not EOF(fn)
FileGet(fn, p, index)
row = dtSource.NewRow()
row("Name") = p.name
row("LastName") = p.lastname
row("Tel") = p.tel
row("Address") = p.addressas
dtSource.Rows.Add(row)
index += 1
End While
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txt_name.Select()
End Sub
Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
If DataGridView1.RowCount > 1 Then
txt_name.Text = DataGridView1.CurrentRow.Cells(0).Value
txt_lastname.Text = DataGridView1.CurrentRow.Cells(1).Value
txt_telephone.Text = DataGridView1.CurrentRow.Cells(2).Value
txt_address.Text = DataGridView1.CurrentRow.Cells(3).Value
End If
End Sub
Private Sub txt_serach_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_serach.TextChanged
Dim view As DataView = dtSource.DefaultView
view.RowFilter = String.Format("Name Like('*{0}*')", txt_serach.Text) '
'view.RowFilter = String.Format("Name='{0}'", txt_serach.Text) '

End Sub
Private Sub btn_search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_search.Click
txt_serach.Enabled = True
txt_serach.Select()
End Sub
Private Sub btn_edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_edit.Click
Dim fn As Integer = FreeFile()
FileOpen(fn, "e:\test.txt", OpenMode.Random, OpenAccess.ReadWrite, OpenShare.Default, Len(p))
p.name = Trim(txt_name.Text)
p.lastname = Trim(txt_lastname.Text)
p.tel = txt_telephone.Text
p.addressas = Trim(txt_address.Text)
' FilePut(fn, p, x)
FileClose(fn)
Dim le As Integer = Len(p)
Dim fn1 As Byte = FreeFile()
FileOpen(fn1, "e:\test.txt", OpenMode.Random, OpenAccess.ReadWrite, OpenShare.Default, Len(p))
Dim index As Integer = 1
While Not EOF(fn1)
FileGet(fn1, p, index)
row = dtSource.NewRow()
row("Name") = p.name
row("LastName") = p.lastname
row("Tel") = p.tel
row("Address") = p.addressas
dtSource.Rows.Add(row)
index += 1
End While
End Sub
Private Sub btn_delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_delete.Click
Dim x As Integer = 1
Dim fn As Integer = FreeFile()
FileOpen(fn, "e:\test.txt", OpenMode.Random, OpenAccess.ReadWrite, OpenShare.Default, Len(p))
Dim rmsgbox As Byte
rmsgbox = MsgBox(" ", MsgBoxStyle.YesNo, "")
If rmsgbox = 6 Then
p.name = Nothing
p.lastname = "*"
p.tel = "*"
p.addressas = Nothing
FilePut(fn, p, x)
End If
FileClose(fn)
FileOpen(fn, "e:\test.txt", OpenMode.Random, OpenAccess.ReadWrite, OpenShare.Default, Len(p))
While Not (EOF(fn))
FileGet(fn, p, i)
If (Trim(p.name) = "*") And (Trim(p.lastname) = "*") Then
Else
FileGet(fn, p, x)
row = dtSource.NewRow()
row("Name") = p.name
row("LastName") = p.lastname
row("Tel") = p.tel
row("Address") = p.addressas
dtSource.Rows.Add(row)
End If
End While
FileClose(fn)
End Sub
End Class

Open-Source
شنبه 08 خرداد 1389, 19:45 عصر
من از کدت سر در نیاوردم.
این یه نمونه که هستش که اطلاعات یه دانش آموز رو توی یه فایل باینری ذخیره میکنه.
شاید به دردت بخوره.

iran_sky
دوشنبه 10 خرداد 1389, 20:42 عصر
کسی نیست بتونه کمکم کنه

Alirezanet
سه شنبه 11 خرداد 1389, 09:32 صبح
من برنامتون رو دیدم ... یه پیشنهاد میدم !
اول اینکه توی همچین برنامه ای باید تا جایی که میشه از دیتابیس اسفاده کرد و دوم اگه نمیخای دیتابیس باشه پیشنهاد میکنم از XML استفاده کنی که بشه اطلاعاتتون رو نشانه گذاری کرد !
در نهایت اگه نخواستی و خواستی از یه فایل Text استفاده کنی میتونی INF استفاده کنی که توی این فایل ها هم نشانه گذاری تا حدودی میشه انجام داد . ( آقای Alimanam هم کامپوننتشو نوشته میتونی دانلود کنی)
ولی در کل XML بهتره !

موفق باشی