保存到共享驱动器exe

时间:2014-11-21 13:36:37

标签: vb.net

好吧,所以这就是我所拥有的,我为我的团队创建了一个仪表板界面,以简化过去手动的过程。此处输入的所有信息偶尔需要转手。现在,.exe是独立的,所有团队成员都可以通过共享驱动器访问它。叫它驱动器

团队成员已经创建了一个s:/dashboard.exe的快捷方式,所有来自同一个仪表板(让我更容易简化更新)..今天我实现了一个功能,我认为这个功能比它做了。我使用My.Settings

创建了一个保存功能

看起来像这样

Private Sub HandoffToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles HandoffToolStripMenuItem.Click My.Settings.SaveIncident = IncidentBox.Text My.Settings.SaveNumber = IncidentNum.Text My.Settings.SaveOpened = OpenedCall.CheckState My.Settings.SaveAnnounced = AnnouncedIC.CheckState My.Settings.SaveImpact = ImpactReport.CheckState My.Settings.SaveOC = OCBox.CheckState My.Settings.SaveSent = CheckBox6.CheckState My.Settings.SaveExec = CheckBox3.CheckState My.Settings.SaveCFAM = CBCFAM.CheckState My.Settings.SaveCFEC = CBCFEC.CheckState My.Settings.SaveCCMC = CBCCMC.CheckState My.Settings.SaveCORE = CBCORE.CheckState My.Settings.SaveFEIN = CBFEIN.CheckState My.Settings.SaveFORE = CBFORE.CheckState My.Settings.SaveFRAN = CBFRANK.CheckState My.Settings.SaveGLEN = CBGLEN.CheckState My.Settings.SaveHUNT = CBHUNT.CheckState My.Settings.SaveLENO = CBLENO.CheckState My.Settings.SaveLIJM = CBLIJ.CheckState My.Settings.SaveLIJB = CBBED.CheckState My.Settings.SaveNSUH = CBNSUH.CheckState My.Settings.SavePlAI = CBPLAI.CheckState My.Settings.SaveSOUT = CBSOUT.CheckState My.Settings.SaveSIUHN = CBSIUN.CheckState My.Settings.SaveSIUHS = CBSIUS.CheckState My.Settings.SaveSYOS = CBSYOS.CheckState My.Settings.SaveZUCK = CBZUCK.CheckState My.Settings.SaveLIHO = CBLIJH.CheckState My.Settings.SavePANS = CBMEDI.CheckState My.Settings.SaveMembers = CallMembers.Text My.Settings.SaveTRIGM = Minute.Text My.Settings.SaveTRIGS = Seconds.Text My.Settings.SaveBRIDM = BM.Text My.Settings.SaveBRIDS = BS.Text My.Settings.SaveEXECM = EM.Text My.Settings.SaveEXECS = ES.Text My.Settings.SaveTimeline = TimeLine.Text Me.Close() End Sub

这是保存的代码

这是我们将其拉回变量

的地方

Private Sub Dashboard_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.ToolTip1.SetToolTip(Me.CTOText, "Clicking this will send a text to the CTO") Me.ToolTip1.SetToolTip(Me.resolveText, "This will send a resolution text") Me.ToolTip1.SetToolTip(Me.SMSBtn, "This will send a text to SLBackupAlert") Me.ToolTip1.SetToolTip(Me.Complete, "This will output an e-mail timeline to the IC") Me.ToolTip1.SetToolTip(Me.LdrBTN, "This will populate regional directors based on sites selected") 'Handoff' IncidentBox.Text = My.Settings.SaveIncident IncidentNum.Text = My.Settings.SaveNumber OpenedCall.CheckState = My.Settings.SaveOpened AnnouncedIC.CheckState = My.Settings.SaveAnnounced ImpactReport.CheckState = My.Settings.SaveImpact OCBox.CheckState = My.Settings.SaveOC CheckBox6.CheckState = My.Settings.SaveSent CheckBox3.CheckState = My.Settings.SaveExec CBCFAM.CheckState = My.Settings.SaveCFAM CBCFEC.CheckState = My.Settings.SaveCFEC CBCCMC.CheckState = My.Settings.SaveCCMC CBCORE.CheckState = My.Settings.SaveCORE CBFEIN.CheckState = My.Settings.SaveFEIN CBFORE.CheckState = My.Settings.SaveFORE CBFRANK.CheckState = My.Settings.SaveFRAN CBGLEN.CheckState = My.Settings.SaveGLEN CBHUNT.CheckState = My.Settings.SaveHUNT CBLENO.CheckState = My.Settings.SaveLENO CBLIJ.CheckState = My.Settings.SaveLIJM CBBED.CheckState = My.Settings.SaveLIJB CBNSUH.CheckState = My.Settings.SaveNSUH CBPLAI.CheckState = My.Settings.SavePlAI CBSOUT.CheckState = My.Settings.SaveSOUT CBSIUN.CheckState = My.Settings.SaveSIUHN CBSIUS.CheckState = My.Settings.SaveSIUHS CBSYOS.CheckState = My.Settings.SaveSYOS CBZUCK.CheckState = My.Settings.SaveZUCK CBLIJH.CheckState = My.Settings.SaveLIHO CBMEDI.CheckState = My.Settings.SavePANS CallMembers.Text = My.Settings.SaveMembers Minute.Text = My.Settings.SaveTRIGM Seconds.Text = My.Settings.SaveTRIGS BM.Text = My.Settings.SaveBRIDM BS.Text = My.Settings.SaveBRIDS EM.Text = My.Settings.SaveEXECM ES.Text = My.Settings.SaveEXECS TimeLine.Text = My.Settings.SaveTimeline

一旦我拉出变量,它在我的机器上完美运行,当我抓住我的仪表板时,如果保存正确,它将有变量。但是我假设这是保存到.exe所以当有人打开s:/dashboard.exe他们会删除任何人保存的最新副本。相反,即使它是共享驱动器,它也会提取最近保存的副本。

有没有办法让它保存到.exe中,这样访问共享驱动器中的文件的任何人都可以提取相同的信息?

基本上,如果用户1将其保存在用户1的计算机上,我希望用户2能够使用用户1的数据从s:/驱动器中获取它。

提前致谢。

1 个答案:

答案 0 :(得分:0)

正如@James所说,'my.setting'不适合这个。我喜欢做的是使用数据表将它们写成XML。

<!-- language: lang-vb -->
'Declare a DataTable public to your application
Public MySettings As New DataTable

'On load of your form or application, load the existing setting if they exist
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'If you don't supply a full path for your file, the path will be the same as your EXE.
    If System.IO.File.Exists("MySettings.xml") Then
        'File exists, read from it
        MySettings.ReadXml("MySettings.xml")
    Else
        'File does not exist, define it here
        'Create the schema for the table
        MySettings.Columns.Add(New DataColumn("SaveIncident", GetType(String)))
        MySettings.Columns.Add(New DataColumn("SaveNumber", GetType(String)))
        'Create you one record
        MySettings.Rows.Add(MySettings.NewRow)
        'Set Default values
        MySettings.Rows(0)("SaveIncident") = ""
        MySettings.Rows(0)("SaveNumber") = ""
        'You may want to save it so it is out there now
        'MySettings.WriteXml("MySettings.xml")
    End If
    'Set your variables if you want to use them
    With MySettings.Rows(0)
        IncidentBox.Text = .Item("SaveIncident")
        IncidentNum.Text = .Item("SaveNumber")

    End With
End Sub
'Here the settings are being saved on close of the form but you should do this through a save button or something.
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
    With MySettings.Rows(0)
        .Item("SaveIncident") = IncidentBox.Text
        .Item("SaveNumber") = IncidentNum.Text
    End With
    MySettings.WriteXml("MySettings.xml")
End Sub

注意:这不是多用户友好的。最后一个保存的人将覆盖其他任何人的更改。这应该只用于很少改变的事情。

此外,使用此方法,您可以在NotePad之类的内容中打开XML并进行编辑。因此,您无需打开exe即可更改设置。