Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

From Yesterday To Today

From Yesterday to Today

What I am doing wrong?. Is it posible?. This can be also good-

O.K. Here is what I wanted to solve and here is how I could solve the problem.
I am working in a family incomes and expenses program far from the big
accounting programs.
The program can be managed by the whole family and each member with
his/her database but a common interface.
This interface(an MDI with several childs) has only one general Menu.
One of the menu items is "Other Accounts" and as you can understand,
depends on the number of accounts you have in one or several savings banks.
I want these accounts to appear as submenus items of this Menu acording your
creation.How could I manage the situation.
First of all I create the new account in a general account creation Child Fom and
at the same time I save the name of the account in a table in the same database
and on the fly, I install the name of the account as a submenu.
Here is the code.

(I am in ChildFom11)

Dim newOption As New ToolStripMenuItem()
newOption.Checked = False
newOption.CheckOnClick = True
newOption.Text = "Cuenta:" & paratabla

AddHandler newOption.Click, AddressOf Me.MenuOption_Click
Form1.OtrasCuentasToolStripMenuItem.DropDownItems.Add(newOption)

(I save newoption.text in a table in the database)

When I load the program again,depending on the member of the
family using it and the number of accounts, I can put all the
submenus of the proper database and then have a look into them.
Here is the code
Private Sub OtrasCuentasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OtrasCuentasToolStripMenuItem.Click
Dim myValue As Object, senda As String = ""
Dim message, title As String

' Set prompt.
message = "Entre el Nombre del Almacen en la forma ej. ENERO2007:Una vez elegido el ALMACEN, vuelva a pulsar sobre Otras Cuentas y sin soltar el ratn arrstrelo hacia la cuenta que quiere seleccionar"
' Set title.
title = "Otras Cuentas"

myValue = InputBox(message, title)


senda = myValue.ToString()
If Val(Mid(senda, 1, 1)) > 0 Or Mid(senda, 1, 1) = "0" Then
MsgBox("El Archivo no puede empezar por un nmero")
senda = ""
Exit Sub
End If
If senda = "" Then
MsgBox("Tiene que escribir un nombre")
Exit Sub
End If
Dim datos As String = senda + ".mdb"

'**estoy probando esto para hacer una base de datos Access
Dim File_Path As String
File_Path = AppDomain.CurrentDomain.BaseDirectory & datos

intercambioparaotrascuentas = datos

If File.Exists(File_Path) Then

'intentamos limpiar los submenus existentes de cualquier otro almacen

OtrasCuentasToolStripMenuItem.DropDownItems.Clear()

Dim Access_ConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & " Data Source=" & File_Path
'

Dim Access_Conn As OleDb.OleDbConnection
Access_Conn = New OleDb.OleDbConnection(Access_ConnStr)
Access_Conn.Open()

Dim srcReader As System.Data.OleDb.OleDbDataReader
Dim strSQL As String = "SELECT * from OTRASCUENTAS"

Dim cmd As OleDbCommand = Access_Conn.CreateCommand()
Dim SrcCmd As New OleDbCommand(strSQL, Access_Conn)

'Read from Source and populate in the Access DB
srcReader = SrcCmd.ExecuteReader()

While srcReader.Read
'aqui hay que meter los datos de la base en el submenu

Dim newOption As New ToolStripMenuItem()
newOption.Checked = False
newOption.CheckOnClick = True
newOption.Text = srcReader.GetValue(1).ToString

AddHandler newOption.Click, AddressOf Form11.MenuOption_Click
OtrasCuentasToolStripMenuItem.DropDownItems.Add(newOption)
End While
srcReader.Close()

Else
MsgBox("NO EXISTE ESE ALMACEN EN EL DIRECTORIO DEL PROGRAMA.COMPRUEBELO O ESCRIBA OTRO NOMBRE")
Exit Sub
End If

End Sub
And finally the code to view the diferent tables
Public Sub MenuOption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' aqui hay que convertir la cuenta pulsada en un string para extraer el nmero de cuenta

Dim cuenta As String
For Each item As Object In Form1.OtrasCuentasToolStripMenuItem.DropDownItems
If (TypeOf item Is ToolStripMenuItem) Then
Dim itemObject As ToolStripMenuItem = CType(item, ToolStripMenuItem)
Dim ayuda As String = "Ha elegido el almacen:" & intercambioparaotrascuentas & " y la cuenta:"
If itemObject.Checked = True Then

'abrir aqui la cuenta para verla
cuenta = itemObject.Text

cuentagenerica = Mid(cuenta, 8, 11)
Dim NewMDIChild19 As New Form19()
NewMDIChild19.MdiParent = Form1
NewMDIChild19.Label1.Text = ayuda + cuentagenerica

NewMDIChild19.Top = 0
NewMDIChild19.Left = 0
'Display the new form.
NewMDIChild19.Show()
NewMDIChild19.BringToFront()
' hay que crear un formulario genrico al que se le envie el valor de cada cuenta y pueda mostrarla en dicho
'formulario. Ser uno para todo el resto de cuentas.
'itemObject.Checked = False
Exit For
End If
itemObject.Checked = False
End If
Next
'itemObject.Checked = False
Dim selectedItem As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
selectedItem.Checked = False
End Sub
Hope it CAN BE USEFUL FOR SOMEONE
[6721 byte] By [emari] at [2007-11-11 9:57:40]