add new

03/09/2005 - 00:55 por Super | Informe spam
por que puede ser que cuando doy para agregar un registro

Case "Agregar"

Try
'Cerrar cualquier edición en ejecución
Me.BindingContext(dsCobros, "Cobro").EndCurrentEdit()
Me.BindingContext(dsCobros, "Cobro").AddNew()
' Catch exc As Exception
Catch exc As Exception
MsgBox(exc.Message, MsgBoxStyle.Critical, Me.Text)
End Try
Habilita()

los campos de combo que cargo desde otras tablas no se quedan en blanco,
mantienen el valor del datos que trajo cada uno

Preguntas similare

Leer las respuestas

#1 Eduardo A. Morcillo [MS MVP VB]
03/09/2005 - 07:34 | Informe spam
Este comportamiento lo he notado cuando ocurre una excepcion al enlazar los
controles al nuevo registro. Revisa que el codigo que tengas en los eventos
de los controles (no necesariamente los combos) esten generando alguna
excepcion.

Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
http://mvp.support.microsoft.com/pr...4EF5A4191C
Respuesta Responder a este mensaje
#2 Super
03/09/2005 - 16:45 | Informe spam
Disculpe mi ignorancia, pero no me devuelve errores en ninguna parte, aqui
le pongo el código a ver si usted ve algo, yo no lo veo. El cuando la base
de datos está en blanco hace perfectamente un insert, pero cuando tiene
datos solo entra en el update, no acabo de darme cuenta de que pueda estar
pasando. Por favor si pudiese usted ayudarme aunque sea al menos con un
ejemplo parecido, que yo pueda comparar y ver que puede pasar.

gracias por su tiempo.

#Region "Recorrer base de datos"

Private Sub siguiente()
BindingContext(dsCobros, ViewCarga).Position += 1
ActuContador()
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''
Private Sub Ultimo()
BindingContext(dsCobros, ViewCarga).Position BindingContext(dsCobros, ViewCarga).Count
ActuContador()

End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Primero()
BindingContext(dsCobros, ViewCarga).Position = 0
ActuContador()
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''
Private Sub Anterior()

BindingContext(dsCobros, ViewCarga).Position -= 1
ActuContador()

End Sub

Sub ActuContador()

LblCuenta.Text = (((BindingContext(dsCobros, ViewCarga).Position +
1).ToString + " de ") _
+ BindingContext(dsCobros, ViewCarga).Count.ToString)

End Sub
#End Region
#Region "Declaraciones generales del Form"

Private m_dropdownRow As Infragistics.Win.UltraWinGrid.UltraGridRow Nothing
Private Mode As String = "Update"
Private dsCobros As DataSet
Private daCobros As SqlDataAdapter
Private dsFacturas As DataSet
Private sdaFacturas As SqlDataAdapter
Private dsClient As DataSet
Private dsDetCobros As DataSet
Private dtDetCobros As DataTable
Private dvDetCobros As DataView
Private ViewCarga As String
Private dtCobros As DataTable
Private dtClient As DataTable
Private dvCobros As DataView
Private dvClient As DataView
Private dsTipoDoc As DataSet
Private dtTipoDoc As DataTable
Private dvTipoDoc As DataView
Protected WithEvents m_DAL As CobrosDb
Protected WithEvents mC_DAL As SGI.DataClients
Protected WithEvents mDC_DAL As CobrosDb
Protected DidPreviouslyConnect As Boolean = False
'Para cargar en esta variable si el cobro
'es a un cliente o un importador
Protected TipoCl As String


Public Event ConnectionStatusChange(ByVal status As String)
Public Event ConnectionFailure(ByVal reason As String)
Public Event ConnectionCompleted(ByVal success As Boolean)

#End Region
#Region "Carga del formulario"

Private Sub FrmCobros_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Cnn.State = ConnectionState.Closed Then
Cnn.Open()
End If
UltraOptionSet1.Value = 1
CargaDatos()
CargaGeneral()
CargaGrid()

End Sub

Private Sub CargaGeneral()

CargaCboClient()
CargaCboTipoDoc()
GetDataSetDetCobro()

End Sub
Sub CargaDatos()
Try
CboNombre.DataBindings.Clear()
CboTipoDoc.DataBindings.Clear()
CboCuenta.DataBindings.Clear()
TxtNoDoc.DataBindings.Clear()
TxtImporte.DataBindings.Clear()
DTPIssued.DataBindings.Clear()
TxtCobrado.DataBindings.Clear()
TxtSaldo.DataBindings.Clear()
DtPCobro.DataBindings.Clear()

CboNombre.DataBindings.Add("Value", dsCobros,
"Cobro.Id_Cliente")
CboTipoDoc.DataBindings.Add("Value", dsCobros,
"Cobro.Tipo_Cobro")
CboCuenta.DataBindings.Add("Value", dsCobros,
"Cobro.IdCtaBanco")
TxtNoDoc.DataBindings.Add("Text", dsCobros, "Cobro.Numero")
TxtImporte.DataBindings.Add("Text", dsCobros, "Cobro.Importe")
DTPIssued.DataBindings.Add("Value", dsCobros,
"Cobro.Fecha_Cheque")
DtPCobro.DataBindings.Add("Value", dsCobros,
"Cobro.Fecha_Vence")
TxtCobrado.DataBindings.Add("Text", dsCobros,
"Cobro.Importe_Cobro")
TxtSaldo.DataBindings.Add("Text", dsCobros,
"Cobro.ImportePendiente")
Catch exc As Exception
MsgBox(exc.Message, MsgBoxStyle.Critical, Me.Text)
End Try
End Sub

#End Region
#Region "Creo el dataset de la tabla Cobros"
Sub GetDataSet()
Try
If m_DAL Is Nothing Then
m_DAL = New CobrosDb
End If

dsCobros = m_DAL.CreateDataSet()
dtCobros = dsCobros.Tables("CargaCobros")
dvCobros = dtCobros.DefaultView
Catch exc As Exception
MsgBox(exc.Message, MsgBoxStyle.Critical, Me.Text)
End Try

End Sub

#End Region
#Region "Carga combo Importador"
Sub CargaCboClient()

TipoCl = "Importador"

Try
Dim viewCarga1 As String
viewCarga1 = "Clientes"
If mC_DAL Is Nothing Then
mC_DAL = New SGI.DataClients
End If

dsClient = mC_DAL.CreateDataSetCobro(viewCarga1, TipoCl)

CboNombre.DataSource = dsClient.Tables("Clientes")
CboNombre.DisplayMember = "Nombre"
CboNombre.ValueMember = "Id"

CboNombre.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.ReloadData,
False)
Catch exc As Exception
MsgBox(exc.Message, MsgBoxStyle.Critical, Me.Text)
End Try
End Sub
#End Region
#Region "Carga Combo Tipo Documento"
Sub CargaCboTipoDoc()
Try
Dim viewCarga1 As String
If mC_DAL Is Nothing Then
mC_DAL = New SGI.DataClients
End If
dsTipoDoc = mC_DAL.CreateDtsTipoDocCobro("CtaBanco_TipoDoc")
dtTipoDoc = dsTipoDoc.Tables("CtaBanco_TipoDoc")
dvTipoDoc = dtTipoDoc.DefaultView

CboTipoDoc.DataSource = dsTipoDoc.Tables("CtaBanco_TipoDoc")
CboTipoDoc.DisplayMember = "Descripcion"
CboTipoDoc.ValueMember = "IdTipoDocumento"

CboTipoDoc.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.ReloadData,
False)

CboCuenta.DataSource = dsTipoDoc.Tables("CtaBanco_TipoDoc")
CboCuenta.DisplayMember = "NoCta"
CboCuenta.ValueMember = "IdCtaBanco"

CboCuenta.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.ReloadData,
False)
Catch exc As Exception
MsgBox(exc.Message, MsgBoxStyle.Critical, Me.Text)
End Try

End Sub
#End Region
#Region "Manipular barra de herramientas"
Private Sub UltraToolbarsManager1_ToolClick_1(ByVal sender As
System.Object, ByVal e As
Infragistics.Win.UltraWinToolbars.ToolClickEventArgs) Handles
UltraToolbarsManager1.ToolClick
Select Case e.Tool.Key
Case "Agregar"

Try
'Cerrar cualquier edición en ejecución
Me.BindingContext(dsCobros, "Cobro").EndCurrentEdit()
Me.BindingContext(dsCobros, "Cobro").AddNew()
Catch exc As Exception
MsgBox(exc.Message, MsgBoxStyle.Critical, Me.Text)
End Try
Habilita()

Case "Editar"
Habilita()

Case "Cancelar"
Inhabilita()

Case "Buscar"


Case "Filtrar"


Case "Cancelar Filtro"


Case "Guardar"
Actualiza()

Case "Imprimir"


Case "Primero"


Case "Anterior"


Case "Siguiente"


Case "Ultimo"


Case "Salir"
If Cnn.State = ConnectionState.Open Then
Cnn.Close()
End If
Me.Close()
Me.Dispose()
End Select

End Sub
#End Region
#Region "Habilitar form para entrada de datos"

Private Sub Habilita()
CboNombre.Enabled = True
CboTipoDoc.Enabled = True
TxtNoDoc.Enabled = True
CboCuenta.Enabled = True
DTPIssued.Enabled = True
DtPCobro.Enabled = True
TxtImporte.Enabled = True
End Sub
#End Region
#Region "Inhabilita form para entrada de datos"

Private Sub Inhabilita()
CboNombre.Enabled = False
CboTipoDoc.Enabled = False
TxtNoDoc.Enabled = False
CboCuenta.Enabled = False
DTPIssued.Enabled = False
DtPCobro.Enabled = False
TxtImporte.Enabled = False
End Sub
#End Region
#Region "Carga dataset detalle cobro"
Sub GetDataSetDetCobro()
Try
If mDC_DAL Is Nothing Then
mDC_DAL = New CobrosDb
End If
dsDetCobros = mDC_DAL.CreateDataSet
Catch exc As Exception
MsgBox(exc.Message, MsgBoxStyle.Critical, Me.Text)
End Try
End Sub
#End Region
#Region "Cargar la grid con los detalles de cobro"
Private Sub CargaGrid()
With UltraGrid1
.DataSource = dsDetCobros
.DataMember = "Detalle_Cobro"
End With
End Sub
#End Region

#Region "Cargar combo de la grid"

Private Sub CargaComboGrid()

Dim import As String = CboNombre.Value

Dim cmSQL As SqlCommand
Dim strSQL As String
Dim IsConnecting As Boolean = True

While IsConnecting
Try

strSQL = "SELECT Id_Factura, Numero, Saldo" & _
" FROM Factura" & _
" WHERE (Id_Importador =" & "'" & [import] & "'" &
")"


cmSQL = New SqlCommand(strSQL, Cnn)

sdaFacturas = New SqlDataAdapter(cmSQL)

Dim scb As New SqlCommandBuilder(sdaFacturas)

dsFacturas = New DataSet
sdaFacturas.Fill(dsFacturas, "Factura")

IsConnecting = False

cmSQL.Dispose()

Catch e As SqlException
MsgBox(e.Message, MsgBoxStyle.Critical, "Error General")
Catch e As Exception
MsgBox(e.Message, MsgBoxStyle.Critical, "Error General")
End Try

End While

Me.UltraDropDown1.DataMember = "Factura"
Me.UltraDropDown1.DataSource = dsFacturas
Me.UltraDropDown1.ValueMember = "Id_Factura"
Me.UltraDropDown1.DisplayMember = "Numero"

Me.UltraGrid1.DisplayLayout.Bands(0).Columns("Factura").ValueList Me.UltraDropDown1

End Sub

#End Region

#Region "Para rellener fila descripcion cuenta"

Private Sub ultraGrid1_AfterCellListCloseUp(ByVal sender As Object,
ByVal e As Infragistics.Win.UltraWinGrid.CellEventArgs) Handles
UltraGrid1.AfterCellListCloseUp

Dim oCell As Infragistics.Win.UltraWinGrid.UltraGridCell = e.Cell
Try
If Me.m_dropdownRow Is Nothing Then Exit Sub

If 0 <> e.Cell.Band.Index Then Exit Sub

e.Cell.Row.Cells("Importe").Value m_dropdownRow.Cells("Saldo").Value.ToString()
e.Cell.Row.Cells("ACobrar").Value m_dropdownRow.Cells("Saldo").Value.ToString()
e.Cell.Row.Cells("Numero").Value = TxtNoDoc.Text
e.Cell.Row.GetUIElement().Invalidate(False)
Catch exc As Exception
MsgBox(exc.Message, MsgBoxStyle.Critical, Me.Text)
End Try
End Sub
#End Region

Private Sub UltraDropDown1_RowSelected(ByVal sender As Object, ByVal e
As Infragistics.Win.UltraWinGrid.RowSelectedEventArgs) Handles
UltraDropDown1.RowSelected
Me.m_dropdownRow = e.Row
End Sub

Private Sub btnCobrar_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCobrar.Click
CargaComboGrid()
CboNombre.Enabled = False
End Sub

Private Sub TxtNoDoc_ValueChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtNoDoc.ValueChanged
UltraGrid1.Enabled = True
CreateFormulas()
End Sub

#Region "Total debitos y creditos"
Private Sub CreateFormulas()
Dim calcSettings As CalcSettings = Nothing
Try
calcSettings Me.ultraCalcManager1.GetCalcSettings(Me.TxtCobrado)
calcSettings.Alias = "TotalCobro"
calcSettings.PropertyName = "Text"
calcSettings.Formula = "sum( [//UltraGrid1/Detalle_Cobro/ACobrar] )"
Catch exc As Exception
MsgBox(exc.Message, MsgBoxStyle.Critical, Me.Text)
End Try
End Sub
#End Region

Private Sub TxtCobrado_ValueChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles TxtCobrado.ValueChanged
TxtSaldo.Text = TxtImporte.Text - TxtCobrado.Text
End Sub

Private Sub UltraOptionSet1_ValueChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles UltraOptionSet1.ValueChanged
Try
If UltraOptionSet1.Value = 1 Then
CobrosImprotadores()
Else
MsgBox("Cliente")
End If
Catch exc As Exception
MsgBox(exc.Message, MsgBoxStyle.Critical, Me.Text)
End Try

End Sub

Private Sub CobrosClientes()

End Sub

Private Sub CobrosImprotadores()

CargaCobro()

End Sub

Private Sub CargaCobro()
Try
Dim SQL_STRING_MARCAS As String = "Select * From Cobro"

daCobros = New SqlDataAdapter(SQL_STRING_MARCAS, Cnn)
Dim oCommandBuilder1 As SqlCommandBuilder = New
SqlCommandBuilder(daCobros)

dsCobros = New DataSet
daCobros.Fill(dsCobros, "Cobro")
Catch exc As Exception
MsgBox(exc.Message, MsgBoxStyle.Critical, Me.Text)
End Try

End Sub

Private Sub Actualiza()
Try
Me.BindingContext(dsCobros, "Cobro").EndCurrentEdit()
If (Me.daCobros Is Nothing) Then
CargaCobro()
End If

If Not dsCobros.GetChanges(DataRowState.Deleted) Is Nothing Then

Me.daCobros.Update(dsCobros.GetChanges(DataRowState.Deleted), "Cobro")

End If

If Not dsCobros.GetChanges(DataRowState.Added) Is Nothing Then
Me.daCobros.Update(dsCobros.GetChanges(DataRowState.Added),
"Cobro")

End If

If Not dsCobros.GetChanges(DataRowState.Modified) Is Nothing
Then

Me.daCobros.Update(dsCobros.GetChanges(DataRowState.Modified), "Cobro")

End If
dsCobros.AcceptChanges()

Catch exc As Exception
MsgBox(exc.Message, MsgBoxStyle.Critical, Me.Text)
End Try
End Sub

End Class
Respuesta Responder a este mensaje
#3 Eduardo A. Morcillo [MS MVP VB]
03/09/2005 - 17:09 | Informe spam
Puede ser que este ocurriendo aqui:

Private Sub TxtCobrado_ValueChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles TxtCobrado.ValueChanged
TxtSaldo.Text = TxtImporte.Text - TxtCobrado.Text
End Sub



Como primer punto, restar dos Strings es algo que no es posible. Esta
funcionando porque no tienes Option Explicit On y entonces VB lo esta
convirtiendo a Double para realizar el calculo. Siempre es mejor hacer las
conversiones de tipo de forma explicita pues se tiene mas control. Entonces
el problema se genera al agregar el nuevo registro, el contenido de
TxtCobrado cambia y se genera el evento, al estar los textbox vacios la
conversion a Double entonces falla y se genera una excepcion. La excepcion
es capturada por el enlace a datos y debido a esto no se continua con el
enlace de los controles. Cambia el metodo por este:

Private Sub TxtCobrado_ValueChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TxtCobrado.ValueChanged

Dim importe As Double
Dim cobrado As Double

' TxtImporte tiene datos?
If TxtImporte.Text.length > 0 Then

' Convierto el texto a Double
importe = Double.Parse(TxtImporte.Text)

End If

If TxtCobrado.Text.length > 0 Then
cobrado = Double.Parse(TxtCobrado.Text)
End If

TxtSaldo.Text = (importe - cobrado).ToString

End Sub

Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
http://mvp.support.microsoft.com/pr...4EF5A4191C
Respuesta Responder a este mensaje
#4 Super
04/09/2005 - 17:43 | Informe spam
EFECTIVO...

Muchas gracias Eduardo, son cositas que me van quedando y esto que me dices
no lo sabia, lo que si me extrañaba era que no me limpiaba los datos cuando
daba agregar.

Muchas gracias nuevamente por su tiempo y su explicación
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida