且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

按钮由多个用户vb.net单击

更新时间:2023-12-06 12:49:58

有一个表格我在visual studio 2013中创建。它用于将数据从表单填充到excel表。它被转换为exe格式,以便它被放置在共享驱动器中。它将被多个用户同时使用。现在问题当两个
人几乎同时点击提交时,会发生错误,因为一个数据正在处理而另一个人点击了提交。我该如何解决? 


进口 excel = 微软 办公室 Interop Excel
进口 系统 运行时 InteropServices

公开 Form1
昏暗 xlapp as excel 应用
昏暗 工作簿 as excel 工作簿
昏暗 工作表 as excel 工作表

私人 Sub Form1_Load sender as Object e As EventArgs 手柄 加载
工作簿
= xlapp 工作簿 打开 " \2.xlsx"
xlapp
可见 = 错误
工作表
= 工作簿 表格 " sheet1"
结束 Sub

私人 Sub Button1_Click sender as Object e As EventArgs 手柄 Button1 点击

如果 工作簿 MultiUserEditing 然后
工作簿
AcceptAllChanges ()
workbook
Save()
结束 If

昏暗 row as Long
昏暗 alpha as Long = 0
row
= 5
worksheet
Do While 单元格 (row, 4).value IsNot Nothing
row
= row + 1
Loop

单元格 (row, 2).value = Me fname Text
单元格 (row, 3).value = Me lname Text
Me fullname 文字 = Me fname 文字 + Me lname Text
单元格 (row, 4).value = Me fullname Text

结束
xlapp
DisplayAlerts = 错误

workbook
SaveAs("\2.xlsx", AccessMode:=excel.XlSaveAsAccessMode.xlShared)

结束 Sub
结束 Class




There is a form I created in visual studio 2013. It is used to populate data from form to excel sheet. It is converted to an exe format so that it will be placed in a shared drive. It will be used by multiple users at same time. Now the problem is when two people hit submit almost at same time, an error occurs because for one the data is being processed and the other has clicked submit. How do I resolve this? 

Imports excel = Microsoft.Office.Interop.Excel
Imports System.Runtime.InteropServices

Public Class Form1
Dim xlapp As New excel.Application
Dim workbook As excel.Workbook
Dim worksheet As excel.Worksheet

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
workbook = xlapp.Workbooks.Open("\2.xlsx")
xlapp.Visible = False
worksheet = workbook.Sheets("sheet1")
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

If workbook.MultiUserEditing Then
    workbook.AcceptAllChanges()
    workbook.Save()
End If

Dim row As Long
Dim alpha As Long = 0
row = 5
With worksheet
    Do While .Cells(row, 4).value IsNot Nothing
        row = row + 1
    Loop

    .Cells(row, 2).value = Me.fname.Text
    .Cells(row, 3).value = Me.lname.Text
    Me.fullname.Text = Me.fname.Text + Me.lname.Text
    .Cells(row, 4).value = Me.fullname.Text

End With
xlapp.DisplayAlerts = False

workbook.SaveAs("\2.xlsx", AccessMode:=excel.XlSaveAsAccessMode.xlShared)

End Sub
End Class

There is a form I created in visual studio 2013. It is used to populate data from form to excel sheet. It is converted to an exe format so that it will be placed in a shared drive. It will be used by multiple users at same time. Now the problem is when two people hit submit almost at same time, an error occurs because for one the data is being processed and the other has clicked submit. How do I resolve this? 

Imports excel = Microsoft.Office.Interop.Excel
Imports System.Runtime.InteropServices

Public Class Form1
Dim xlapp As New excel.Application
Dim workbook As excel.Workbook
Dim worksheet As excel.Worksheet

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
workbook = xlapp.Workbooks.Open("\2.xlsx")
xlapp.Visible = False
worksheet = workbook.Sheets("sheet1")
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

If workbook.MultiUserEditing Then
    workbook.AcceptAllChanges()
    workbook.Save()
End If

Dim row As Long
Dim alpha As Long = 0
row = 5
With worksheet
    Do While .Cells(row, 4).value IsNot Nothing
        row = row + 1
    Loop

    .Cells(row, 2).value = Me.fname.Text
    .Cells(row, 3).value = Me.lname.Text
    Me.fullname.Text = Me.fname.Text + Me.lname.Text
    .Cells(row, 4).value = Me.fullname.Text

End With
xlapp.DisplayAlerts = False

workbook.SaveAs("\2.xlsx", AccessMode:=excel.XlSaveAsAccessMode.xlShared)

End Sub
End Class