the idea: I'm making a data entry program, there is a database contains text that need to be input. about 20 people will have to do the job( ofcourse there's login form ). they will input all text for the text file, then the second time, and the order is random. I've tried using a column in the access database to control the concurrent, but no use.
First, user's computer will check all the records, then choose a random empty, no lock record. after that, put a lock to it, modified the value then release the lock. But still no luck. Any body can help me ? Thanks in advance.
here is my code
i will attach the database so that you can imagin the idea, column2, column3 is the name of the people who input, column3 and 5 is the text inputted, and column 6 is use for lock
First, user's computer will check all the records, then choose a random empty, no lock record. after that, put a lock to it, modified the value then release the lock. But still no luck. Any body can help me ? Thanks in advance.
here is my code
VB.NET:
Public Class main
Dim con As New OleDb.OleDbConnection
Public ds As New DataSet
Dim da, dausr As OleDb.OleDbDataAdapter
Dim maxrow, maxrowusr, demcheck1, demcheck2, chia, sodu, chay As Integer
Dim randnum As New Random()
Dim check, ktlan1 As Boolean
Dim mix, temp, num As Integer
Dim randarray(10000) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'user gởi yêu cầu lấy từ DB, 1 vòng lặp check xem có bao nhiêu account chưa làm, mỗi account chưa làm đưa ID vào array
'randomarray rồi gởi randarray(1) cho người đó làm, làm xong update. Nếu vòng lặp báo về ko còn account trống thì chuyển qua giai đoạn
'nhập lần 2 ( có thể báo hoặc ko ) .
'Next x
Dim cb As New OleDb.OleDbCommandBuilder(da)
If TextBox1.Text = "" Then
ds.Tables("dentry").Rows(randarray(1)).Item(6) = 0
da.Update(ds, "dentry")
Else
If demcheck1 > 0 Then
ds.Tables("dentry").Rows(randarray(1)).Item(2) = Form1.hoten
ds.Tables("dentry").Rows(randarray(1)).Item(3) = TextBox1.Text
ds.Tables("dentry").Rows(randarray(1)).Item(6) = 0
Else
ds.Tables("dentry").Rows(randarray(1)).Item(4) = Form1.hoten
ds.Tables("dentry").Rows(randarray(1)).Item(5) = TextBox1.Text
ds.Tables("dentry").Rows(randarray(1)).Item(6) = 0
End If
da.Update(ds, "dentry")
End If
random()
If demcheck1 = 0 And demcheck2 = 0 Then
Exit Sub
End If
check = True
ds.Tables("Dentry").Rows(randarray(1)).Item(6) = check
da.Update(ds, "Dentry")
Label2.Text = ds.Tables("Dentry").Rows(randarray(1)).Item(1)
TextBox1.Text = ""
End Sub
Sub random()
Dim dem, dem1 As Integer
dem = 0
dem1 = 0
demcheck1 = 0
demcheck2 = 0
'con.ConnectionString = "provider = microsoft.jet.oledb.4.0;data source = C:\DBtemp\DE.mdb"
'da = New OleDb.OleDbDataAdapter("select*from usr order by id", con)
'con.Open()
'da.Fill(ds, "usr")
'con.Close()
'maxrowusr = ds.Tables("usr").Rows.Count
'nhap lan dau tien
For i = 0 To maxrow - 1
If IsDBNull(ds.Tables("dentry").Rows(i).Item(3)) = 0 Or ds.Tables("dentry").Rows(i).Item(6) = 1 Then
Continue For
Else
demcheck1 = demcheck1 + 1
dem = dem + 1
randarray(dem) = i
End If
Next
If demcheck1 = 0 Then
For i = 0 To maxrow - 1
If IsDBNull(ds.Tables("dentry").Rows(i).Item(5)) = 0 Or ds.Tables("dentry").Rows(i).Item(6) = 1 Then
Continue For
Else
demcheck2 = demcheck2 + 1
dem1 = dem1 + 1
randarray(dem1) = i
End If
Next
End If
If demcheck1 = 0 And demcheck2 = 0 Then
MsgBox("Da hoan thanh viec nhap lieu !")
Exit Sub
End If
If demcheck1 > 0 Then
num = demcheck1
For x As Integer = 1 To num
mix = randnum.Next(x, num + 1)
temp = randarray(mix)
randarray(mix) = randarray(x)
randarray(x) = temp
Next x
ds.Tables("dentry").Rows(randarray(1)).Item(6) = 1
da.Update(ds, "dentry")
TextBox2.Text = ""
For i = 1 To demcheck1
TextBox2.Text = TextBox2.Text & " " & randarray(i)
Next
Else
num = demcheck2
For x As Integer = 1 To num
mix = randnum.Next(x, num + 1)
temp = randarray(mix)
randarray(mix) = randarray(x)
randarray(x) = temp
Next x
ds.Tables("dentry").Rows(randarray(1)).Item(6) = 1
da.Update(ds, "dentry")
TextBox2.Text = ""
For i = 1 To demcheck2
TextBox2.Text = TextBox2.Text & " " & randarray(i)
Next
End If
End Sub
Private Sub main_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim cb As New OleDb.OleDbCommandBuilder(da)
check = False
ds.Tables("Dentry").Rows(randarray(1)).Item(6) = check
da.Update(ds, "Dentry")
Form1.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "ユーザ : " & Form1.hoten
con.ConnectionString = "provider = microsoft.jet.oledb.4.0;data source = " & Form1.dsDB.Tables("location").Rows(0).Item(1)
dausr = New OleDb.OleDbDataAdapter("select*from usr order by id", con)
da = New OleDb.OleDbDataAdapter("select*from Dentry order by id", con)
Dim cb As New OleDb.OleDbCommandBuilder(da)
con.Open()
da.Fill(ds, "Dentry")
dausr.Fill(ds, "usr")
con.Close()
maxrow = ds.Tables("Dentry").Rows.Count
maxrowusr = ds.Tables("usr").Rows.Count
random()
If demcheck1 = 0 And demcheck2 = 0 Then
Exit Sub
End If
check = True
ds.Tables("Dentry").Rows(randarray(1)).Item(6) = check
da.Update(ds, "Dentry")
Label2.Text = ds.Tables("Dentry").Rows(randarray(1)).Item(1)
End Sub
End Class
i will attach the database so that you can imagin the idea, column2, column3 is the name of the people who input, column3 and 5 is the text inputted, and column 6 is use for lock