ผมสร้า่ง dataset ไว้เก็บรายการข้อมูลไว้ก่อนส่งไปเก็บใน ฐานข้อมูล เพื่อให้ User สามารถลบหรือแก้ไขข้อมูลก่อนส่งได้ แต่เกิดปัญหาเมื่อมี User อื่นมาทำด้วยกลายเป็นว่าไปเขียนทับรายการของคนเก่า ซึ่งพอต่างคนต่างแก้ข้อมูล ข้อมูลเลยมั่วไปหมด มีวิธีให้dataset แยกข้อมูลของ user ออกจากกัน หรือการสำรองข้อมูลแบบอื่น ไหม๊ครับ
Partial Class test
Inherits System.Web.UI.Page
Dim plantcode As String
Shared DSPendingDailyOperation As PendingDailyOperationDataSet
Dim x As Boolean
Shared dr As DataRow
Shared addr As DataRow
Shared selectedEditRowIndex As Integer
Dim cutdateText As String
Shared editst As Boolean
Sub ClearTextbox()
TxOperator.Text = ""
TxNotification.Text = ""
TxJobOrder.Text = ""
TxWhat.Text = ""
TxHow.Text = ""
TxWhy.Text = ""
DdlWhose.SelectedIndex = 0
End Sub
Sub cutdate(ByVal cutdatetochange As String)
Dim cutdate() As String = Split(cutdatetochange.ToString, "/")
End Sub
Sub CreatePendingDailyOperation()
DSPendingDailyOperation = New PendingDailyOperationDataSet
Session("PendingDailyOperation") = DSPendingDailyOperation
End Sub
Sub EditRow()
Dim cdr As DataRow
Try
cdr = DSPendingDailyOperation.Tables("PendingOperationDetails").Rows(selectedEditRowIndex)
Dim timestart As DateTime = calOperatedateStart.DatetimeValue.AddHours(hTStart.SelectedValue).AddMinutes(mTStart0.SelectedValue)
Dim timestop As DateTime = calOperatedateStop.DatetimeValue.AddHours(hTStop.SelectedValue).AddMinutes(mTStop.SelectedValue)
If timestop > timestart Then
If TxOperator.Text = "" Then
Label3.Text = "Error : ไม่ระบุชื่อผู้ปฏิบัติงาน"
Exit Sub
Else
If TxWhat.Text = "" Then
Label3.Text = "Error : ไม่ระบุงานที่ทำ"
Exit Sub
Else
Dim NumLoopCheck As Integer = gvPending.Rows.Count - 1
Dim CountLoop As Integer = 0
Dim teststop As DateTime
teststop = calOperatedateStop.DatetimeValue.AddHours(CInt(mTStart0.Text)).AddMinutes(CInt(mTStop.Text))
If gvPending.Rows.Count > 0 Then 'รายการแรกไม่มีการตรวจสอบเวลาซ้อนทับกัน
'''''''''''''''''''''''''''''''''''''''''''Check Time Loop''''''''''''''''''''''''''''''''''''''''''''''''''''
For CountLoop = 0 To NumLoopCheck Step 1
DSPendingDailyOperation = Session("PendingDailyOperation")
If (TxOperator.Text = gvPending.Rows(CountLoop).Cells(9).Text) Then
If teststart > CDate(gvPending.Rows(CountLoop).Cells(1).Text) And teststart < CDate(gvPending.Rows(CountLoop).Cells(2).Text) Then
Label3.Text = "Error : เวลาทำงานซ้อนทับ"
Exit Sub
ElseIf teststop > CDate(gvPending.Rows(CountLoop).Cells(1).Text) And teststop < CDate(gvPending.Rows(CountLoop).Cells(2).Text) Then
Label3.Text = "Error : เวลาทำงานซ้อนทับ"
Exit Sub
ElseIf teststart = CDate(gvPending.Rows(CountLoop).Cells(1).Text) Then
Label3.Text = "Error : เวลาทำงานซ้อนทับ"
Exit Sub
ElseIf teststop = CDate(gvPending.Rows(CountLoop).Cells(2).Text) Then
Label3.Text = "Error : เวลาทำงานซ้อนทับ"
Exit Sub
End If
End If
Next
'''''''''''''''''''''''''''''''''''''''''''End Check Time Loop''''''''''''''''''''''''''''''''''''''''''''''''''''
Else
If editst = False Then
Label3.Text = ""
AddToPending()
ClearTextbox()
Else
EditRow()
ClearTextbox()
End If
bAddItem.Text = "เพิ่มรายการ"
Exit Sub
End If
End If
End If
Else : Label3.Text = "Error : กรอกเวลาไม่ถูกต้อง"
Exit Sub
End If
If editst = False Then
AddToPending()
Else : EditRow()
End If
Label3.Text = ""
ClearTextbox()
bdelete.Visible = False
bedit.Visible = False
bAddItem.Text = "เพิ่มรายการ"
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Master.DisplayPageTitle("บันทึกรายงานประจำวัน")
If Not IsPostBack Then
CreatePendingDailyOperation()
End If
Dim UserName As String = User.Identity.Name.ToString
lbUsername.Text = UserName
Dim conn As New SqlConnection(WebConfigurationManager.ConnectionStrings("Feedusers").ConnectionString)
Dim Cmd As SqlCommand = New SqlCommand("SELECT * FROM [UserProfiles] WHERE ([UserName] = @Username)", conn)
Cmd.Parameters.AddWithValue("Username", UserName)
conn.Open()
Dim Rd As SqlDataReader
Rd = Cmd.ExecuteReader()
Rd.Read()
plantcode = Rd("PlantID").ToString
Session("Plantcode") = plantcode
conn.Close()
Protected Sub bsent_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bsent.Click
Dim conn2 As New SqlConnection(WebConfigurationManager.ConnectionStrings("PlantMaintenance").ConnectionString)
Dim sqlcmd2 As New SqlCommand("addDailyOperationRecorder", conn2)
sqlcmd2.CommandType = CommandType.StoredProcedure
sqlcmd2.Parameters.AddWithValue("Plantcode", Session("Plantcode"))
Dim i As Integer = gvPending.Rows.Count - 1
Dim j As Integer = 0
For j = 0 To i Step 1
'''''''''''''''''''''''''''''''''''Copy DATA From gvPending'''''''''''''''''''''''''''''''''''
Dim conn As New SqlConnection(WebConfigurationManager.ConnectionStrings("PlantMaintenance").ConnectionString)
Dim sqlcmd As New SqlCommand("addDailyOperations", conn)
sqlcmd.CommandType = CommandType.StoredProcedure
Dim cdr As DataRow = DSPendingDailyOperation.Tables("PendingOperationDetails").Rows(j)
Dim Equipment = cdr("Equipment")
Dim what As String = cdr("What")
Dim How As String = cdr("How")
Dim Why As String = cdr("Why")
Dim Operatorname = cdr("Operator")
Dim StartTime As DateTime = cdr("TaskStart")
Dim StopTime As DateTime = cdr("TaskStop")
Dim Whose As String = cdr("Whose")
Dim JobOrderID As String = cdr("JobOrderID")
Dim NotificationID = cdr("NotificationID")
Dim taskid = cdr("TaskID")
Dim MachineName = cdr("MachineName")
Dim Subdivide As String = cdr("Subdivide")
''''''''''''''' Sent Data To DATABASE '''''''''''''''''''''''''
sqlcmd.Parameters.AddWithValue("Plantcode", plantcode)
Catch ex As Exception
Label3.ForeColor = Drawing.Color.Red
Label3.Text = "การส่งรายงานล้มเหลว! : " & ex.Message
Exit Sub
Finally
conn.Close()
End Try
Next
Protected Sub bCear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bCear.Click
Label3.Text = ""
DSPendingDailyOperation = Session("PendingDailyOperation")
DSPendingDailyOperation.Tables("PendingOperationDetails").Clear()
DSPendingDailyOperation.Tables("PendingDailyOperations").Clear()
gvPending.DataSource = DSPendingDailyOperation.Tables("PendingOperationDetails")
gvPending.DataBind()
ClearTextbox()
End Sub
Protected Sub gvPending_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvPending.SelectedIndexChanged
selectedEditRowIndex = gvPending.SelectedIndex
Protected Sub Menu1_MenuItemClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles Menu1.MenuItemClick
If Menu1.SelectedValue = "How" Then
mvDailyRecord.SetActiveView(View3)
ElseIf Menu1.SelectedValue = "Operator" Then
mvDailyRecord.SetActiveView(view1)
ElseIf Menu1.SelectedValue = "What" Then
mvDailyRecord.SetActiveView(View2)
ElseIf Menu1.SelectedValue = "Why" Then
mvDailyRecord.SetActiveView(View4)
End If
End Sub
Protected Sub bedit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bedit.Click
Dim cutdateClick() As String = Split(FormatDateTime(gvPending.Rows(selectedEditRowIndex).Cells(2).Text, DateFormat.ShortDate), "/")
Dim cDay As String = cutdateClick(1)
Dim cMonth As String = cutdateClick(0)
Dim cYear As String = cutdateClick(2)
If gvPending.Rows(selectedEditRowIndex).Cells(11).Text = " " Then
TxNotification.Text = ""
Else : TxNotification.Text = gvPending.Rows(selectedEditRowIndex).Cells(11).Text
End If
If gvPending.Rows(selectedEditRowIndex).Cells(8).Text = " " Then
gvPending.Rows(selectedEditRowIndex).Cells(8).Text = ""
Else : TxJobOrder.Text = gvPending.Rows(selectedEditRowIndex).Cells(8).Text
End If
Dim i As Integer = gvPending.Rows.Count - 2
Dim j As Integer = 0
Dim cdr As DataRow
For j = 0 To i Step 1
cdr = DSPendingDailyOperation.Tables("PendingOperationDetails").Rows(j)
cdr.BeginEdit()
cdr("Taskid") = j + 1
cdr.EndEdit()
Next
gvPending.DataSource = DSPendingDailyOperation.Tables("PendingOperationDetails")
gvPending.DataBind()
bdelete.Enabled = False
bedit.Enabled = False
bdelete.Visible = False
bedit.Visible = False
End Sub
Protected Sub cbsent_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbsent.CheckedChanged
If cbsent.Checked Then
bsent.Enabled = True
Else : bsent.Enabled = False