mitchell042997
asked on
Updating Multiple Recordsets using Access '97 & ODBC Drivers
OK, here is my big problem. I have two Recordsets open. I can view them fine, scroll through them fine, delete fine. In access, these two recordsets have a 1 to many relationship. I can insert, but I can only enter values for the main data set, the one explicitly coded in the CView. Here is the code:
void CTestView::OnDatabaseoptio nsAddnewre cord()
{
CAddHotelDialog dlg;
if (dlg.DoModal()==IDOK) {
m_pSet->m_HotelID=CURRENT_ PRIMARY_IN DEX++;
m_pSet->m_Name=dlg.m_Hotel Name;
UpdateData(FALSE);
m_pSet->AddNew();
UpdateData(TRUE);
if (m_pSet->CanUpdate())
m_pSet->Update();
CDateSet db_DateInfo(&GetDocument() ->m_databa se);
db_DateInfo.Open();
db_DateInfo.m_Date=CTime(1 999, 3, 19, 22, 15, 0);
db_DateInfo.m_Status=TRUE;
db_DateInfo.m_HotelID=CURR ENT_PRIMAR Y_INDEX-1;
db_DateInfo.m_DateID=20L;
db_DateInfo.AddNew();
m_pSet->Requery();
if (!m_pSet->IsEOF())
m_pSet->MoveLast();
LoadListBox();
}
}
This code creates another entry in teh table, but affects only the Hotel table, and doesn't update the Date table. Any ideas on how to get this working? Thanks!
void CTestView::OnDatabaseoptio
{
CAddHotelDialog dlg;
if (dlg.DoModal()==IDOK) {
m_pSet->m_HotelID=CURRENT_
m_pSet->m_Name=dlg.m_Hotel
UpdateData(FALSE);
m_pSet->AddNew();
UpdateData(TRUE);
if (m_pSet->CanUpdate())
m_pSet->Update();
CDateSet db_DateInfo(&GetDocument()
db_DateInfo.Open();
db_DateInfo.m_Date=CTime(1
db_DateInfo.m_Status=TRUE;
db_DateInfo.m_HotelID=CURR
db_DateInfo.m_DateID=20L;
db_DateInfo.AddNew();
m_pSet->Requery();
if (!m_pSet->IsEOF())
m_pSet->MoveLast();
LoadListBox();
}
}
This code creates another entry in teh table, but affects only the Hotel table, and doesn't update the Date table. Any ideas on how to get this working? Thanks!
ASKER
I had these two lines in there, but it still didn't work, so I took them out.
if (db_DateInfo.CanUpdate())
db_DateInfo.Update();
These directly proceeded db_DateInfo.AddNew()
(Did I offer too many points, or too few? That last comment has me curious)
if (db_DateInfo.CanUpdate())
db_DateInfo.Update();
These directly proceeded db_DateInfo.AddNew()
(Did I offer too many points, or too few? That last comment has me curious)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Assides from flaviosousa's answer, which is correct by the way, I have had a teerible time getting any multiple table ODBC program working while using instances of the CRecordSet created on the stack. I.e.: db_DateInfo.AddNew(), etc.
I have had no problem when creating the instance on the heap though, i.e.: db_DateInfo->AddNew()
I've never seem to have enough time to try to figure out why, but changinge instantiation from the stack to the heap seems to almost magicaly solve all kinds of problems.
I have had no problem when creating the instance on the heap though, i.e.: db_DateInfo->AddNew()
I've never seem to have enough time to try to figure out why, but changinge instantiation from the stack to the heap seems to almost magicaly solve all kinds of problems.
ASKER
I'll try out the code tonight and get back to you... as far as the ODBC updating multiple records on the stack... do you think it would beehove me to just say screw it and go with DAO? I know Access will work with DAO, but will MS SQL? Thanks!!
(This is just a question, not worth any points, so if you don't want to answer it, understood.)
(This is just a question, not worth any points, so if you don't want to answer it, understood.)
Although I somehow ended up with a rather embarasingly large ammount of points, I don't get paid for it. I answer the questions for only 2 reasons. 1) I have been exasperatedly stuck myself, and know what it feels like. 2) It actualy helps me relax.
So ask away...
Yes, DAO will work with MS-SQL, via an ODBC bridge (sic). SO thats not going to be much help, besides, the strange behaviour I indicated regarding stack/heap behaviour also repeats on DAO.
If you are going to make the code changes, the following program I wrote will probably help you in getting to run faster:
// Ops.cpp : implementation file
//
#include "stdafx.h"
#include "inversim.h"
#include "Ops.h"
#include "stdio.h"
#include "memory.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////// ////////// ////////// ////////// ////////// ////////// /
// COps dialog
COps::COps(CWnd* pParent /*=NULL*/)
: CDialog(COps::IDD, pParent)
{
//{{AFX_DATA_INIT(COps)
m_Fecha = _T("");
m_Paterno = _T("");
m_Clave = _T("");
m_Materno = _T("");
m_Nombres = _T("");
m_RFC = _T("");
m_Instrumento = _T("");
m_Unidades = 0;
m_Saldo = 0.0f;
m_valCompra = _T("");
m_valVenta = _T("");
m_Valor = _T("");
m_Buy = -1;
m_paper = -1;
m_Registrado = _T("");
//}}AFX_DATA_INIT
}
void COps::DoDataExchange(CData Exchange* pDX)
{
CDialog::DoDataExchange(pD X);
//{{AFX_DATA_MAP(COps)
DDX_Control(pDX, IDC_NUEVO, m_btnNuevo);
DDX_Control(pDX, IDC_GUARDAR, m_btnGuardar);
DDX_Control(pDX, IDC_UNIDADES, m_EditUnidades);
DDX_Control(pDX, IDC_EDITAR, m_btnEditar);
DDX_Control(pDX, IDC_BORRAR, m_btnBorrar);
DDX_Control(pDX, IDC_LISTINSTRUMENTO, m_ListOperaciones);
DDX_Control(pDX, IDC_LISTOPERACIONES, m_Operaciones);
DDX_Control(pDX, IDC_COMPRA, m_CompraVenta);
DDX_Control(pDX, IDC_INSTRUMENTOS, m_Inst);
DDX_Control(pDX, IDC_TIPO, m_Tipo);
DDX_Text(pDX, IDC_FECHA, m_Fecha);
DDX_Text(pDX, IDC_APEPATERNO, m_Paterno);
DDX_Text(pDX, IDC_CLIENTE, m_Clave);
DDV_MaxChars(pDX, m_Clave, 9);
DDX_Text(pDX, IDC_APEMATERNO, m_Materno);
DDX_Text(pDX, IDC_NOMBRE, m_Nombres);
DDX_Text(pDX, IDC_RFC, m_RFC);
DDX_LBString(pDX, IDC_LISTINSTRUMENTO, m_Instrumento);
DDX_Text(pDX, IDC_UNIDADES, m_Unidades);
DDX_Text(pDX, IDC_SALDO, m_Saldo);
DDX_Text(pDX, IDC_ValCompra, m_valCompra);
DDX_Text(pDX, IDC_VALVENTA, m_valVenta);
DDX_Text(pDX, IDC_VALOR, m_Valor);
DDX_Radio(pDX, IDC_COMPRA, m_Buy);
DDX_Radio(pDX, IDC_INSTRUMENTOS, m_paper);
DDX_Text(pDX, IDC_REGISTRADO, m_Registrado);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(COps, CDialog)
//{{AFX_MSG_MAP(COps)
ON_BN_CLICKED(IDC_BUSCAR, OnBuscar)
ON_BN_CLICKED(IDC_FIRST, OnFirst)
ON_BN_CLICKED(IDC_PREV, OnPrev)
ON_BN_CLICKED(IDC_NEXT, OnNext)
ON_BN_CLICKED(IDC_LAST, OnLast)
ON_BN_CLICKED(IDC_GUARDAR, OnGuardar)
ON_BN_CLICKED(IDC_NUEVO, OnNuevo)
ON_BN_CLICKED(IDC_BORRAR, OnBorrar)
ON_BN_CLICKED(IDC_EDITAR, OnEditar)
ON_BN_CLICKED(IDC_COMPRAVE NTA, OnCompraventa)
ON_BN_CLICKED(IDC_TIPO, OnTipo)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_LIMPIAR1 , OnLimpiar1)
ON_LBN_SELCHANGE(IDC_LISTI NSTRUMENTO , OnSelchangeListinstrumento )
ON_BN_CLICKED(IDC_COMPRA, OnCompra)
ON_BN_CLICKED(IDC_INSTRUME NTOS, OnInstrumentos)
ON_BN_CLICKED(IDC_VENTA, OnVenta)
ON_BN_CLICKED(IDC_PESOS, OnPesos)
ON_LBN_SELCHANGE(IDC_LISTO PERACIONES , OnSelchangeListoperaciones )
ON_EN_SETFOCUS(IDC_UNIDADE S, OnSetfocusUnidades)
ON_LBN_SETFOCUS(IDC_LISTIN STRUMENTO, OnSetfocusListinstrumento)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
////////////////////////// ////////// ////////// ////////// ////////// ////////// /
// COps message handlers
void COps::OnBuscar()
{
UpdateData(TRUE);
CString where = "UserID LIKE \'";
if (m_Clave.IsEmpty()){
AfxMessageBox("Debe capturar una clave de usuaro!");
return;
}
where += m_Clave + "%\'";
ClientesRS->m_strFilter = where;
try {
ClientesRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
if( ClientesRS->IsBOF()){
AfxMessageBox(_T("No se encontrs el registro"));
return;
}
try {
ClientesRS->MoveFirst();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
m_Materno = ClientesRS->m_Materno;
m_Paterno = ClientesRS->m_Paterno;
m_Nombres = ClientesRS->m_Nombres;
m_RFC = ClientesRS->m_RFC;
m_Clave = ClientesRS->m_UserID;
ReadOps();
m_btnEditar.EnableWindow(T RUE);
m_btnBorrar.EnableWindow(T RUE);
m_btnNuevo.EnableWindow(TR UE);
UpdateData(FALSE);
}
void COps::OnFirst()
{
if( ClientesRS->IsBOF()){
AfxMessageBox("La tabla esta Vacia");
return;
}
try {
ClientesRS->MoveFirst();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
m_Materno = ClientesRS->m_Materno;
m_Paterno = ClientesRS->m_Paterno;
m_Nombres = ClientesRS->m_Nombres;
m_RFC = ClientesRS->m_RFC;
m_Clave = ClientesRS->m_UserID;
ReadOps();
m_btnEditar.EnableWindow(T RUE);
m_btnBorrar.EnableWindow(T RUE);
m_btnNuevo.EnableWindow(TR UE);
UpdateData(FALSE);
}
void COps::OnPrev()
{
if( ClientesRS->IsBOF()){
AfxMessageBox("Principio de la Tabla");
return;
}
try {
ClientesRS->MovePrev();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
m_Materno = ClientesRS->m_Materno;
m_Paterno = ClientesRS->m_Paterno;
m_Nombres = ClientesRS->m_Nombres;
m_RFC = ClientesRS->m_RFC;
m_Clave = ClientesRS->m_UserID;
ReadOps();
m_btnEditar.EnableWindow(T RUE);
m_btnBorrar.EnableWindow(T RUE);
m_btnNuevo.EnableWindow(TR UE);
UpdateData(FALSE);
}
void COps::OnNext()
{
if( ClientesRS->IsEOF()){
AfxMessageBox("Final de la Tabla");
return;
}
try {
ClientesRS->MoveNext();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
m_Materno = ClientesRS->m_Materno;
m_Paterno = ClientesRS->m_Paterno;
m_Nombres = ClientesRS->m_Nombres;
m_RFC = ClientesRS->m_RFC;
m_Clave = ClientesRS->m_UserID;
ReadOps();
m_btnEditar.EnableWindow(T RUE);
m_btnBorrar.EnableWindow(T RUE);
m_btnNuevo.EnableWindow(TR UE);
UpdateData(FALSE);
}
void COps::OnLast()
{
if( ClientesRS->IsEOF()){
AfxMessageBox("La tabla esta Vacia");
return;
}
try {
ClientesRS->MoveLast();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
m_Materno = ClientesRS->m_Materno;
m_Paterno = ClientesRS->m_Paterno;
m_Nombres = ClientesRS->m_Nombres;
m_RFC = ClientesRS->m_RFC;
m_Clave = ClientesRS->m_UserID;
ReadOps();
m_btnEditar.EnableWindow(T RUE);
m_btnBorrar.EnableWindow(T RUE);
m_btnNuevo.EnableWindow(TR UE);
UpdateData(FALSE);
}
void COps::Limpiar()
{
m_Instrumento = "";
m_Valor = "";
m_valCompra = "";
m_valVenta = "";
m_Unidades = (long)0;
m_Saldo = (float)0.0;
UpdateData(FALSE);
}
void COps::OnGuardar()
{
Ejecutar();
UpdateData(TRUE);
int d = atoi(m_Fecha.Left(m_Fecha. Find("/")) );
int j = m_Fecha.Find("/")+1;
int k = m_Fecha.GetLength() - m_Fecha.ReverseFind('/');
int m = atoi(m_Fecha.Mid(j,k));
j = m_Fecha.GetLength() - m_Fecha.ReverseFind('/') - 1;
int y = atoi(m_Fecha.Right(j))+190 0;
CTime t(y,m,d,0,0,0);
if (!Edit)
t = t.GetCurrentTime();
OpsRS->m_Fecha = t;
OpsRS->m_NumValores = m_Unidades;
OpsRS->m_Baja = FALSE;
if (m_Buy == 0)
OpsRS->m_Compra = "T";
else
OpsRS->m_Compra = "F";
if (m_Inst.GetCheck() == 1)
OpsRS->m_Tipo = "I";
else
OpsRS->m_Tipo = "P";
if (Edit)
Buffer = m_Instrumento;
OpsRS->m_IDInstrumento = atol(LPCSTR(Buffer.Mid(Buf fer.Find(' \t') + 1)));
if (!Edit){
OpsRS->m_IDCliente=m_Clave ;
if (!m_Valor.IsEmpty())
OpsRS->m_Valor = m_Valor;
else{
if (OpsRS->m_Compra == "F")
OpsRS->m_valCompra = m_valCompra;
else
OpsRS->m_valVenta = m_valVenta;
}
}
else{
OpsRS->m_Valor = m_Registrado;
OpsRS->m_valCompra = "";
OpsRS->m_valVenta = "";
}
CString where = "UserID = \'" + m_Clave + "\'";
SaldosRS->m_strFilter = where;
try {
SaldosRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
try {
SaldosRS->Edit();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
float saldo = (float) atof(SaldosRS->m_Saldo1);
float opValue;
float st;
float st2 = (float)0.0;
if (m_Buy == 0){
opValue = (float)-1.0;
st = (float) atof(m_valVenta);
}
else{
opValue = (float)1.0;
st = (float) atof(m_valCompra);
}
if (st == 0.0) st = (float) atof(m_Valor);
if (Edit){
if ((InstRS->m_MercadoID == 12) || (InstRS->m_MercadoID == 13))
st2 = (-1) * opValue * (float)atof(OldRegistrado) ;
else
st2 = (-1) * opValue * (float)atof(OldRegistrado) * (long)m_OldUnidades;
st = (float)atof(m_Registrado);
}
if (m_Inst.GetCheck() == 1){
float st1;
if ((InstRS->m_MercadoID == 12) || (InstRS->m_MercadoID == 13))
st1 = st * opValue;
else
st1 = st * (long)m_Unidades * opValue;
saldo += st1 + st2 ;
}else{
float st1;
if ((InstRS->m_MercadoID == 12) || (InstRS->m_MercadoID == 13))
st1 = st * opValue;
else {
st1 = (long)m_Unidades/st;
st1 = (float) ((long) st1 ); // Actual # of units purchased
st1 = st1 * st * opValue;
}
saldo += st1 + st2;
}
char tot [20];
sprintf(tot, "%.4f", saldo);
SaldosRS->m_Saldo1 = tot;
m_Saldo = saldo;
try {
SaldosRS->Update();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
try {
OpsRS->Update();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
ReadOps();
t = CTime::GetCurrentTime();
m_Fecha = t.Format("%d/%m/%y");
m_btnGuardar.EnableWindow( FALSE);
m_EditUnidades.EnableWindo w(FALSE);
m_CompraVenta.EnableWindow (FALSE);
m_Tipo.EnableWindow(FALSE) ;
m_ListOperaciones.EnableWi ndow(FALSE );
UpdateData(FALSE);
// Actualizar Portafolio
char x[6];
sprintf(x, "%ld", atol(LPCSTR(Buffer.Mid(Buf fer.Find(' \t') + 1))));
where = "((ClientID = \'" + m_Clave + "\' ) AND ( InstrumentoID = "+ x + "))";
PortafolioRS->m_strFilter = where;
if( !PortafolioRS->IsBOF()){
try {
PortafolioRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
}
if( PortafolioRS->IsBOF()){
try {
PortafolioRS->AddNew();
PortafolioRS->m_CantidadAn terior=0L;
PortafolioRS->m_ClientID = m_Clave;
PortafolioRS->m_Instrument oID = atol(LPCSTR(Buffer.Mid(Buf fer.Find(' \t') + 1)));
PortafolioRS->m_Cantidad = 0L;
PortafolioRS->m_Instancias =0L;
PortafolioRS->m_Portafolio ID = m_Clave + LPCSTR(Buffer.Mid(Buffer.F ind('\t') + 1));
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
} else {
try {
PortafolioRS->Edit();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
}
if (m_Buy == 1){ //Venta
PortafolioRS->m_Cantidad -= m_Unidades;
if (Edit) PortafolioRS->m_Cantidad += m_OldUnidades;
}else{
PortafolioRS->m_Cantidad += m_Unidades;
if (Edit){
PortafolioRS->m_Cantidad -= m_OldUnidades;
if (Edit) PortafolioRS->m_Instancias --;
}
PortafolioRS->m_Instancias ++;
char y[20];
sprintf(y,"%.2f", st + ((float)atof(OldRegistrado ) * (-1)) + atof(PortafolioRS->m_Costo ));
PortafolioRS->m_Costo=y;
}
try {
PortafolioRS->Update();
try {
PortafolioRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
Limpiar();
Edit = FALSE;
return;
}
Limpiar();
Edit = FALSE;
AfxMessageBox("Actualizaci sn Exitosa!");
}
void COps::OnNuevo()
{
Limpiar();
CTime t = CTime::GetCurrentTime();
m_Fecha = t.Format("%d/%m/%y");
try {
OpsRS->AddNew();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
UpdateData(FALSE);
m_Fecha = t.Format("%d/%m/%y");
m_ListOperaciones.EnableWi ndow(TRUE) ;
}
void COps::OnBorrar()
{
int index = m_Operaciones.GetCurSel();
if (index == LB_ERR){
AfxMessageBox("Debe selccionar una operacisn!");
return;
}
CString where = "IDCliente = \'";
where += m_Clave + "\'";
OpsRS->m_strFilter = where;
try {
OpsRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
try {
OpsRS->SetAbsolutePosition ((long) index + 1);
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
try {
OpsRS->Edit();
OpsRS->m_Baja = TRUE;
OpsRS->Update();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
m_Fecha = OpsRS->m_Fecha.Format("%d/ %m/%y");
m_Unidades = OpsRS->m_NumValores;
if (atof(OpsRS->m_valCompra) > 0.0)
m_Registrado = OpsRS->m_valCompra;
if (atof(OpsRS->m_Valor) > 0.0)
m_Registrado = OpsRS->m_Valor;
if (atof(OpsRS->m_valVenta) > 0.0)
m_Registrado = OpsRS->m_valVenta;
if (OpsRS->m_Compra == "T" )
m_Buy=0;
else
m_Buy=1;
if (OpsRS->m_Tipo == "I")
m_paper=0;
else
m_paper = 1;
where = "UserID = \'" + m_Clave + "\'";
SaldosRS->m_strFilter = where;
try {
SaldosRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
try {
SaldosRS->Edit();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
float saldo = (float) atof(SaldosRS->m_Saldo1);
float opValue;
float st;
if (m_Buy == 0){
opValue = (float)1.0;
st = (float) atof(m_Registrado);
}
else{
opValue = (float)-1.0;
st = (float) atof(m_Registrado);
}
if (st == 0.0) st = (float) atof(m_Registrado);
if (m_Inst.GetCheck() == 1){
float st1 = st * (long)m_Unidades * opValue;
saldo += st1;
}else{
float st1 = (long)m_Unidades/st;
st1 = (float) ((long) st1 ); // Actual # of units purchased
st1 = st1 * st * opValue;
saldo += st1;
}
char tot [20];
sprintf(tot, "%.4f", saldo);
SaldosRS->m_Saldo1 = tot;
m_Saldo = saldo;
try {
SaldosRS->Update();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
char x [6];
sprintf(x, "%ld", OpsRS->m_IDInstrumento);
where = "(PortafolioID = \'" + m_Clave + x +"\' )";
PortafolioRS->m_strFilter = where;
try {
PortafolioRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
try {
PortafolioRS->Edit();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
PortafolioRS->m_Cantidad -= m_Unidades;
PortafolioRS->m_Instancias --;
char y[20];
sprintf(y,"%.2f", atof(PortafolioRS->m_Costo )-st);
PortafolioRS->m_Costo=y;
try {
PortafolioRS->Update();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
ReadOps();
}
void COps::OnEditar()
{
int index = m_Operaciones.GetCurSel();
if (index == LB_ERR){
AfxMessageBox("Debe selccionar una operacisn!");
return;
}
CString where = "IDCliente = \'";
where += m_Clave + "\'";
OpsRS->m_strFilter = where;
try {
OpsRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
try {
OpsRS->SetAbsolutePosition ((long) index + 1);
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
m_Fecha = OpsRS->m_Fecha.Format("%d/ %m/%y");
m_Unidades = m_OldUnidades = OpsRS->m_NumValores;
if (atof(OpsRS->m_valCompra) > 0.0)
m_Registrado = OpsRS->m_valCompra;
if (atof(OpsRS->m_Valor) > 0.0)
m_Registrado = OpsRS->m_Valor;
if (atof(OpsRS->m_valVenta) > 0.0)
m_Registrado = OpsRS->m_valVenta;
if (OpsRS->m_Compra == "T" )
m_Buy=0;
else
m_Buy=1;
if (OpsRS->m_Tipo == "I")
m_paper=0;
else
m_paper = 1;
char c[20];
sprintf(c, "%ld", OpsRS->m_IDInstrumento);
try {
index = OpsRS->m_IDInstrumento /*- 5L*/; /* -5L Due to offset in Instrumentos DB*/
InstUnSortRS->SetAbsoluteP osition( index);
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
index = m_ListOperaciones.FindStri ng( -1, InstUnSortRS->m_Nombre );
m_ListOperaciones.SetCurSe l(index);
UpdateData(FALSE);
try {
OpsRS->Edit();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
Edit = TRUE;
m_btnGuardar.EnableWindow( TRUE);
m_EditUnidades.EnableWindo w(TRUE);
m_CompraVenta.EnableWindow (TRUE);
m_Tipo.EnableWindow(TRUE);
m_ListOperaciones.EnableWi ndow(TRUE) ;
OldRegistrado = m_Registrado;
}
void COps::OnCompraventa()
{
m_Tipo.EnableWindow(TRUE);
}
void COps::OnTipo()
{
m_btnGuardar.EnableWindow( TRUE);
}
// Initialize when needed
CDatabase* COps::GetDatabase()
{
// Connect the object to a data source
if( !m_dbInversim.IsOpen( ) &&
!m_dbInversim.OpenEx( NULL ) )
return NULL;
return &m_dbInversim;
}
CDatabase* COps::GetDatosDatabase()
{
// Connect the object to a data source
if( !m_dbDatos.IsOpen( ) &&
!m_dbDatos.OpenEx( NULL ) )
return NULL;
return &m_dbDatos;
}
BOOL COps::OnInitDialog()
{
AfxGetApp()->LoadStandardC ursor(IDC_ WAIT);
CDialog::OnInitDialog();
m_dbInversim.Open( _T( "Inversim" ), FALSE,
FALSE, _T( "ODBC;UID=admin;PWD=ncc170 1d"));
ASSERT(m_dbInversim.IsOpen ());
if (m_dbInversim.IsOpen() == FALSE){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox( "ERROR!\nNo se pudo abrir la base de datos Inversim!");
return FALSE;
}
m_dbDatos.Open( _T( "Datos" ));
ASSERT(m_dbDatos.IsOpen()) ;
if (m_dbDatos.IsOpen() == FALSE){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox( "ERROR!\nNo se pudo abrir la base de datos Datos 32!");
return FALSE;
}
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxGetApp()->LoadStandardC ursor(IDC_ WAIT);
ClientesRS = new CClientesRecordSet(GetData base());
ClientesRS->Open(CRecordse t::snapsho t, NULL, CRecordset::readOnly);
ASSERT(ClientesRS->IsOpen( ));
if (ClientesRS->IsOpen() == FALSE){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox( "ERROR!\nNo se pudo abrir el Querry de Clientes!");
return FALSE;
}
OpsRS = new COpsRecordSet(GetDatabase( ));
OpsRS->Open(CRecordset::sn apshot, NULL);
ASSERT(OpsRS->IsOpen());
if (OpsRS->IsOpen() == FALSE){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox( "ERROR!\nNo se pudo abrir el Querry de Operaciones!");
return FALSE;
}
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxGetApp()->LoadStandardC ursor(IDC_ WAIT);
try {
InstRS = new CInstsRecordSet(GetDatabas e());
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
InstRS->m_strSort = "Nombre";
try{
InstRS->Open(CRecordset::s napshot);
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
InstRS->m_strSort = "Nombre";
ASSERT(InstRS->IsOpen());
if (InstRS->IsOpen() == FALSE){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox( "ERROR!\nNo se pudo abrir el Querry de Operaciones!");
return FALSE;
}
InstUnSortRS = new CInstsRecordSet(GetDatabas e());
InstUnSortRS->Open(CRecord set::snaps hot, NULL, CRecordset::readOnly);
ASSERT(InstUnSortRS->IsOpe n());
if (InstUnSortRS->IsOpen() == FALSE){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox( "ERROR!\nNo se pudo abrir el Querry de Operaciones!");
return FALSE;
}
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxGetApp()->LoadStandardC ursor(IDC_ WAIT);
do{
CString Line;
char dato[20];
Line += InstRS->m_Nombre + '\t';
sprintf(dato, "%ld", InstRS->m_InstrumentoID);
CString d(dato);
Line += d;
m_ListOperaciones.AddStrin g(LPCTSTR (Line) );
try {
InstRS->MoveNext();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
Line = "";
} while (!InstRS->IsEOF());
SaldosRS = new CSaldosRecordSet(GetDataba se());
SaldosRS->Open(CRecordset: :snapshot, NULL, CRecordset::none);
ASSERT(SaldosRS->IsOpen()) ;
if (SaldosRS->IsOpen() == FALSE){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox( "ERROR!\nNo se pudo abrir el Querry de Saldos!");
return FALSE;
}
PortafolioRS = new PortafoliosRecordSet(GetDa tabase());
PortafolioRS->Open(CRecord set::snaps hot, NULL);
ASSERT(PortafolioRS->IsOpe n());
if (PortafolioRS->IsOpen() == FALSE){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox( "ERROR!\nNo se pudo abrir el Querry de Portafolio!");
return FALSE;
}
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void COps::OnOK()
{
ClientesRS->Close();
delete ClientesRS;
ClientesRS=NULL;
OpsRS->Close();
delete OpsRS;
OpsRS=NULL;
InstRS->Close();
delete InstRS;
InstRS=NULL;
InstUnSortRS->Close();
delete InstUnSortRS;
InstUnSortRS=NULL;
PortafolioRS->Close();
delete PortafolioRS;
PortafolioRS = NULL;
m_dbDatos.Close();
m_dbInversim.Close();
CDialog::OnClose();
DestroyWindow();
}
BOOL COps::Create(CWnd *pParent)
{
if (IsWindow(m_hWnd)){
SetActiveWindow();
return TRUE;
}
else return (CDialog::Create(COps::IDD , pParent));
}
void COps::OnClose()
{
ClientesRS->Close();
OpsRS->Close();
InstRS->Close();
m_dbInversim.Close();
CDialog::OnClose();
DestroyWindow();
}
void COps::OnLimpiar1()
{
m_Materno = _T("");
m_Paterno = _T("");
m_Nombres = _T("");
m_RFC = _T("");
m_Saldo = (float)0.0;
m_Clave = _T("");
m_Registrado = _T("");
m_Operaciones.ResetContent ();
UpdateData(FALSE);
ClientesRS->m_strFilter = "";
try {
ClientesRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
}
void COps::ReadOps(){
// Get operations for client
AfxGetApp()->LoadStandardC ursor(IDC_ WAIT);
CString where = "IDCliente = \'";
where += m_Clave + "\'";
OpsRS->m_strFilter = where;
try {
OpsRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
m_Saldo = (float)0.0;
if( OpsRS->IsEOF()){
m_Operaciones.ResetContent ();
UpdateData(FALSE);
return;
}
try {
OpsRS->MoveFirst();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
m_Operaciones.ResetContent ();
if( OpsRS->IsBOF()){
return;
}
char data[20], data1[20];
CString d(data), d1(data1);
CString Line = "";
do {
wsprintf(data, "%ld", OpsRS->m_IDInstrumento);
wsprintf(data1, "%ld", OpsRS->m_NumValores);
d=data; d1=data1;
where = "(Instrumentos.Instrumento ID=" + d + ")";
try {
InstUnSortRS->SetAbsoluteP osition( atol(data) /*- 5L*/);/* -5L Due to offset in Instrumentos DB*/
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
Line += OpsRS->m_Fecha.Format("%d/ %m/%y") + '\t';
Line += InstUnSortRS->m_Nombre + '\t';
Line += OpsRS->m_Tipo +'\t';
if (*(LPCTSTR)OpsRS->m_Compra == 'T')
Line += (CString)"Compra" + '\t';
else
Line += (CString)"Venta" + '\t';
wsprintf(data1, "%ld", OpsRS->m_NumValores);
CString dd(data1);
Line += dd + '\t'; // Numero de Valores comprados
char data3[20];
memset(data3, 0, 20);
double num = atof(LPCTSTR(OpsRS->m_Valo r));
if (num != 0.0){
sprintf(data3, "%.2f", num) ;
CString d3(data3);
Line += d3;
}
num = atof(LPCTSTR(OpsRS->m_valV enta));
if (num != 0.0){
sprintf(data3, "%.2f", num) ;
CString d3(data3);
Line += d3;
}
num = atof(LPCTSTR(OpsRS->m_valC ompra));
if (num != 0.0){
sprintf(data3, "%.2f", num) ;
CString d3(data3);
Line += d3;
}
if (OpsRS->m_Baja == TRUE)
Line += "\tDado de Baja";
m_Operaciones.AddString(LP CTSTR (Line) );
try {
OpsRS->MoveNext();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
Line = "";
} while (!OpsRS->IsEOF());
where = "UserID = \'" + m_Clave + "\'";
SaldosRS->m_strFilter = where;
try {
SaldosRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
m_Saldo = (float) atof(SaldosRS->m_Saldo1);
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
}
void COps::OnSelchangeListinstr umento()
{
long IDInst;
m_ListOperaciones.GetText( m_ListOper aciones.Ge tCurSel(), Buffer);
IDInst = atol(LPCSTR(Buffer.Mid(Buf fer.Find(' \t') + 1)));
char data[20];
wsprintf(data, "%ld", IDInst);
CString d(data);
CString where = "(Instrumentos.Instrumento ID=" + d + ")";
InstRS->m_strFilter = where;
try {
InstRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
}
m_Valor ="";
m_valCompra="";
m_valVenta="";
char data3[20];
double num = atof(LPCTSTR(InstRS->m_Val or));
if (num != 0.0){
sprintf(data3, "%.2f", num) ;
CString d3(data3);
m_Valor = d3;
}
num = atof(LPCTSTR(InstRS->m_Ven ta));
if (num != 0.0){
sprintf(data3, "%.2f", num) ;
CString d3(data3);
m_valVenta = d3;
}
num = atof(LPCTSTR(InstRS->m_Com pra));
if (num != 0.0){
sprintf(data3, "%.2f", num) ;
CString d3(data3);
m_valCompra = d3;
}
UpdateData(FALSE);
}
void COps::OnCompra()
{
m_Inst.EnableWindow(TRUE);
}
void COps::OnInstrumentos()
{
m_btnGuardar.EnableWindow( TRUE);
}
void COps::OnVenta()
{
m_Inst.EnableWindow(TRUE);
}
void COps::OnPesos()
{
m_btnGuardar.EnableWindow( TRUE);
}
void COps::Ejecutar()
{
CDatabase m_dbInversim;
HCURSOR hCursor;
hCursor = AfxGetApp()->LoadStandardC ursor(IDC_ WAIT);
m_dbInversim.Open( _T( "Inversim" ), FALSE,
FALSE, _T( "ODBC;UID=admin;PWD=ncc170 1d"));
ASSERT(m_dbInversim.IsOpen ());
if (m_dbInversim.IsOpen() == FALSE){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox( "ERROR!\nNo se pudo abrir la base de datos!");
return;
}
// Acciones
CString str = "UPDATE Instrumentos INNER JOIN T_NCap_Accion ON Instrumentos.Nombre = T_NCap_Accion.Emisora SET Instrumentos.Valor = T_NCap_Accion.Precio_actua l WHERE Instrumentos.MercadoID = 5";
try{
m_dbInversim.ExecuteSQL(st r);
}
catch (CDBException *pEx){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
//Cambios
str = "UPDATE Instrumentos INNER JOIN T_NCap_Cambios ON Instrumentos.Nombre = T_NCap_Cambios.Clave_pizar ra SET Instrumentos.Valor = T_NCap_Cambios.Precio_actu al WHERE Instrumentos.MercadoID = 6";
try{
m_dbInversim.ExecuteSQL(st r);
}
catch (CDBException *pEx){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
//Cambios-Coberturas
str = "UPDATE Instrumentos INNER JOIN T_NCam_Coberturas ON Instrumentos.Nombre = T_NCam_Coberturas.Fuente_p lazo SET Instrumentos.Compra = T_NCam_Coberturas.Compra, Instrumentos.Venta = T_NCam_Coberturas.Venta WHERE Instrumentos.MercadoID = 2";
try{
m_dbInversim.ExecuteSQL(st r);
}
catch (CDBException *pEx){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
//Cambios-Dolar Internacional
str = "UPDATE Instrumentos INNER JOIN T_NCam_Dolar_Int ON Instrumentos.Nombre = T_NCam_Dolar_Int.Fuente_va lor SET Instrumentos.Compra = T_NCam_Dolar_Int.Compra, Instrumentos.Venta = T_NCam_Dolar_Int.Venta WHERE Instrumentos.MercadoID = 3";
try{
m_dbInversim.ExecuteSQL(st r);
}
catch (CDBException *pEx){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
//Cambios-Monedas Internacional
str = "UPDATE Instrumentos INNER JOIN T_ICam_Monedas_Int ON Instrumentos.Nombre = T_ICam_Monedas_Int.Divisa SET Instrumentos.Compra = T_ICam_Monedas_Int.Compra, Instrumentos.Venta = T_ICam_Monedas_Int.Venta WHERE Instrumentos.MercadoID = 1";
try{
m_dbInversim.ExecuteSQL(st r);
}
catch (CDBException *pEx){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
//Dinero-Promedio
str = "UPDATE Instrumentos INNER JOIN T_NDin_Promedio ON Instrumentos.Nombre = T_NDin_Promedio.Instrument o_plazo SET Instrumentos.Valor = T_NDin_Promedio.Tasa_actua l WHERE Instrumentos.MercadoID = 9";
try{
m_dbInversim.ExecuteSQL(st r);
}
catch (CDBException *pEx){
AfxGetApp()->LoadStandardC ursor(IDC_ ARROW);
AfxMessageBox(pEx->m_strEr ror);
pEx->Delete();
return;
}
//Intermedio
str = "UPDATE Instrumentos INNER JOIN T_Nint_Mdo_Intermedio ON Instrumentos.Nombre = T_Nint_Mdo_Intermedio.Emis ora SET Instrumentos.Valor = T_Nint_Mdo_Intermedio.P
So ask away...
Yes, DAO will work with MS-SQL, via an ODBC bridge (sic). SO thats not going to be much help, besides, the strange behaviour I indicated regarding stack/heap behaviour also repeats on DAO.
If you are going to make the code changes, the following program I wrote will probably help you in getting to run faster:
// Ops.cpp : implementation file
//
#include "stdafx.h"
#include "inversim.h"
#include "Ops.h"
#include "stdio.h"
#include "memory.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////////////
// COps dialog
COps::COps(CWnd* pParent /*=NULL*/)
: CDialog(COps::IDD, pParent)
{
//{{AFX_DATA_INIT(COps)
m_Fecha = _T("");
m_Paterno = _T("");
m_Clave = _T("");
m_Materno = _T("");
m_Nombres = _T("");
m_RFC = _T("");
m_Instrumento = _T("");
m_Unidades = 0;
m_Saldo = 0.0f;
m_valCompra = _T("");
m_valVenta = _T("");
m_Valor = _T("");
m_Buy = -1;
m_paper = -1;
m_Registrado = _T("");
//}}AFX_DATA_INIT
}
void COps::DoDataExchange(CData
{
CDialog::DoDataExchange(pD
//{{AFX_DATA_MAP(COps)
DDX_Control(pDX, IDC_NUEVO, m_btnNuevo);
DDX_Control(pDX, IDC_GUARDAR, m_btnGuardar);
DDX_Control(pDX, IDC_UNIDADES, m_EditUnidades);
DDX_Control(pDX, IDC_EDITAR, m_btnEditar);
DDX_Control(pDX, IDC_BORRAR, m_btnBorrar);
DDX_Control(pDX, IDC_LISTINSTRUMENTO, m_ListOperaciones);
DDX_Control(pDX, IDC_LISTOPERACIONES, m_Operaciones);
DDX_Control(pDX, IDC_COMPRA, m_CompraVenta);
DDX_Control(pDX, IDC_INSTRUMENTOS, m_Inst);
DDX_Control(pDX, IDC_TIPO, m_Tipo);
DDX_Text(pDX, IDC_FECHA, m_Fecha);
DDX_Text(pDX, IDC_APEPATERNO, m_Paterno);
DDX_Text(pDX, IDC_CLIENTE, m_Clave);
DDV_MaxChars(pDX, m_Clave, 9);
DDX_Text(pDX, IDC_APEMATERNO, m_Materno);
DDX_Text(pDX, IDC_NOMBRE, m_Nombres);
DDX_Text(pDX, IDC_RFC, m_RFC);
DDX_LBString(pDX, IDC_LISTINSTRUMENTO, m_Instrumento);
DDX_Text(pDX, IDC_UNIDADES, m_Unidades);
DDX_Text(pDX, IDC_SALDO, m_Saldo);
DDX_Text(pDX, IDC_ValCompra, m_valCompra);
DDX_Text(pDX, IDC_VALVENTA, m_valVenta);
DDX_Text(pDX, IDC_VALOR, m_Valor);
DDX_Radio(pDX, IDC_COMPRA, m_Buy);
DDX_Radio(pDX, IDC_INSTRUMENTOS, m_paper);
DDX_Text(pDX, IDC_REGISTRADO, m_Registrado);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(COps, CDialog)
//{{AFX_MSG_MAP(COps)
ON_BN_CLICKED(IDC_BUSCAR, OnBuscar)
ON_BN_CLICKED(IDC_FIRST, OnFirst)
ON_BN_CLICKED(IDC_PREV, OnPrev)
ON_BN_CLICKED(IDC_NEXT, OnNext)
ON_BN_CLICKED(IDC_LAST, OnLast)
ON_BN_CLICKED(IDC_GUARDAR,
ON_BN_CLICKED(IDC_NUEVO, OnNuevo)
ON_BN_CLICKED(IDC_BORRAR, OnBorrar)
ON_BN_CLICKED(IDC_EDITAR, OnEditar)
ON_BN_CLICKED(IDC_COMPRAVE
ON_BN_CLICKED(IDC_TIPO, OnTipo)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_LIMPIAR1
ON_LBN_SELCHANGE(IDC_LISTI
ON_BN_CLICKED(IDC_COMPRA, OnCompra)
ON_BN_CLICKED(IDC_INSTRUME
ON_BN_CLICKED(IDC_VENTA, OnVenta)
ON_BN_CLICKED(IDC_PESOS, OnPesos)
ON_LBN_SELCHANGE(IDC_LISTO
ON_EN_SETFOCUS(IDC_UNIDADE
ON_LBN_SETFOCUS(IDC_LISTIN
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//////////////////////////
// COps message handlers
void COps::OnBuscar()
{
UpdateData(TRUE);
CString where = "UserID LIKE \'";
if (m_Clave.IsEmpty()){
AfxMessageBox("Debe capturar una clave de usuaro!");
return;
}
where += m_Clave + "%\'";
ClientesRS->m_strFilter = where;
try {
ClientesRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
if( ClientesRS->IsBOF()){
AfxMessageBox(_T("No se encontrs el registro"));
return;
}
try {
ClientesRS->MoveFirst();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
m_Materno = ClientesRS->m_Materno;
m_Paterno = ClientesRS->m_Paterno;
m_Nombres = ClientesRS->m_Nombres;
m_RFC = ClientesRS->m_RFC;
m_Clave = ClientesRS->m_UserID;
ReadOps();
m_btnEditar.EnableWindow(T
m_btnBorrar.EnableWindow(T
m_btnNuevo.EnableWindow(TR
UpdateData(FALSE);
}
void COps::OnFirst()
{
if( ClientesRS->IsBOF()){
AfxMessageBox("La tabla esta Vacia");
return;
}
try {
ClientesRS->MoveFirst();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
m_Materno = ClientesRS->m_Materno;
m_Paterno = ClientesRS->m_Paterno;
m_Nombres = ClientesRS->m_Nombres;
m_RFC = ClientesRS->m_RFC;
m_Clave = ClientesRS->m_UserID;
ReadOps();
m_btnEditar.EnableWindow(T
m_btnBorrar.EnableWindow(T
m_btnNuevo.EnableWindow(TR
UpdateData(FALSE);
}
void COps::OnPrev()
{
if( ClientesRS->IsBOF()){
AfxMessageBox("Principio de la Tabla");
return;
}
try {
ClientesRS->MovePrev();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
m_Materno = ClientesRS->m_Materno;
m_Paterno = ClientesRS->m_Paterno;
m_Nombres = ClientesRS->m_Nombres;
m_RFC = ClientesRS->m_RFC;
m_Clave = ClientesRS->m_UserID;
ReadOps();
m_btnEditar.EnableWindow(T
m_btnBorrar.EnableWindow(T
m_btnNuevo.EnableWindow(TR
UpdateData(FALSE);
}
void COps::OnNext()
{
if( ClientesRS->IsEOF()){
AfxMessageBox("Final de la Tabla");
return;
}
try {
ClientesRS->MoveNext();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
m_Materno = ClientesRS->m_Materno;
m_Paterno = ClientesRS->m_Paterno;
m_Nombres = ClientesRS->m_Nombres;
m_RFC = ClientesRS->m_RFC;
m_Clave = ClientesRS->m_UserID;
ReadOps();
m_btnEditar.EnableWindow(T
m_btnBorrar.EnableWindow(T
m_btnNuevo.EnableWindow(TR
UpdateData(FALSE);
}
void COps::OnLast()
{
if( ClientesRS->IsEOF()){
AfxMessageBox("La tabla esta Vacia");
return;
}
try {
ClientesRS->MoveLast();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
m_Materno = ClientesRS->m_Materno;
m_Paterno = ClientesRS->m_Paterno;
m_Nombres = ClientesRS->m_Nombres;
m_RFC = ClientesRS->m_RFC;
m_Clave = ClientesRS->m_UserID;
ReadOps();
m_btnEditar.EnableWindow(T
m_btnBorrar.EnableWindow(T
m_btnNuevo.EnableWindow(TR
UpdateData(FALSE);
}
void COps::Limpiar()
{
m_Instrumento = "";
m_Valor = "";
m_valCompra = "";
m_valVenta = "";
m_Unidades = (long)0;
m_Saldo = (float)0.0;
UpdateData(FALSE);
}
void COps::OnGuardar()
{
Ejecutar();
UpdateData(TRUE);
int d = atoi(m_Fecha.Left(m_Fecha.
int j = m_Fecha.Find("/")+1;
int k = m_Fecha.GetLength() - m_Fecha.ReverseFind('/');
int m = atoi(m_Fecha.Mid(j,k));
j = m_Fecha.GetLength() - m_Fecha.ReverseFind('/') - 1;
int y = atoi(m_Fecha.Right(j))+190
CTime t(y,m,d,0,0,0);
if (!Edit)
t = t.GetCurrentTime();
OpsRS->m_Fecha = t;
OpsRS->m_NumValores = m_Unidades;
OpsRS->m_Baja = FALSE;
if (m_Buy == 0)
OpsRS->m_Compra = "T";
else
OpsRS->m_Compra = "F";
if (m_Inst.GetCheck() == 1)
OpsRS->m_Tipo = "I";
else
OpsRS->m_Tipo = "P";
if (Edit)
Buffer = m_Instrumento;
OpsRS->m_IDInstrumento = atol(LPCSTR(Buffer.Mid(Buf
if (!Edit){
OpsRS->m_IDCliente=m_Clave
if (!m_Valor.IsEmpty())
OpsRS->m_Valor = m_Valor;
else{
if (OpsRS->m_Compra == "F")
OpsRS->m_valCompra = m_valCompra;
else
OpsRS->m_valVenta = m_valVenta;
}
}
else{
OpsRS->m_Valor = m_Registrado;
OpsRS->m_valCompra = "";
OpsRS->m_valVenta = "";
}
CString where = "UserID = \'" + m_Clave + "\'";
SaldosRS->m_strFilter = where;
try {
SaldosRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
try {
SaldosRS->Edit();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
float saldo = (float) atof(SaldosRS->m_Saldo1);
float opValue;
float st;
float st2 = (float)0.0;
if (m_Buy == 0){
opValue = (float)-1.0;
st = (float) atof(m_valVenta);
}
else{
opValue = (float)1.0;
st = (float) atof(m_valCompra);
}
if (st == 0.0) st = (float) atof(m_Valor);
if (Edit){
if ((InstRS->m_MercadoID == 12) || (InstRS->m_MercadoID == 13))
st2 = (-1) * opValue * (float)atof(OldRegistrado)
else
st2 = (-1) * opValue * (float)atof(OldRegistrado)
st = (float)atof(m_Registrado);
}
if (m_Inst.GetCheck() == 1){
float st1;
if ((InstRS->m_MercadoID == 12) || (InstRS->m_MercadoID == 13))
st1 = st * opValue;
else
st1 = st * (long)m_Unidades * opValue;
saldo += st1 + st2 ;
}else{
float st1;
if ((InstRS->m_MercadoID == 12) || (InstRS->m_MercadoID == 13))
st1 = st * opValue;
else {
st1 = (long)m_Unidades/st;
st1 = (float) ((long) st1 ); // Actual # of units purchased
st1 = st1 * st * opValue;
}
saldo += st1 + st2;
}
char tot [20];
sprintf(tot, "%.4f", saldo);
SaldosRS->m_Saldo1 = tot;
m_Saldo = saldo;
try {
SaldosRS->Update();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
try {
OpsRS->Update();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
ReadOps();
t = CTime::GetCurrentTime();
m_Fecha = t.Format("%d/%m/%y");
m_btnGuardar.EnableWindow(
m_EditUnidades.EnableWindo
m_CompraVenta.EnableWindow
m_Tipo.EnableWindow(FALSE)
m_ListOperaciones.EnableWi
UpdateData(FALSE);
// Actualizar Portafolio
char x[6];
sprintf(x, "%ld", atol(LPCSTR(Buffer.Mid(Buf
where = "((ClientID = \'" + m_Clave + "\' ) AND ( InstrumentoID = "+ x + "))";
PortafolioRS->m_strFilter = where;
if( !PortafolioRS->IsBOF()){
try {
PortafolioRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
}
if( PortafolioRS->IsBOF()){
try {
PortafolioRS->AddNew();
PortafolioRS->m_CantidadAn
PortafolioRS->m_ClientID = m_Clave;
PortafolioRS->m_Instrument
PortafolioRS->m_Cantidad = 0L;
PortafolioRS->m_Instancias
PortafolioRS->m_Portafolio
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
} else {
try {
PortafolioRS->Edit();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
}
if (m_Buy == 1){ //Venta
PortafolioRS->m_Cantidad -= m_Unidades;
if (Edit) PortafolioRS->m_Cantidad += m_OldUnidades;
}else{
PortafolioRS->m_Cantidad += m_Unidades;
if (Edit){
PortafolioRS->m_Cantidad -= m_OldUnidades;
if (Edit) PortafolioRS->m_Instancias
}
PortafolioRS->m_Instancias
char y[20];
sprintf(y,"%.2f", st + ((float)atof(OldRegistrado
PortafolioRS->m_Costo=y;
}
try {
PortafolioRS->Update();
try {
PortafolioRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
Limpiar();
Edit = FALSE;
return;
}
Limpiar();
Edit = FALSE;
AfxMessageBox("Actualizaci
}
void COps::OnNuevo()
{
Limpiar();
CTime t = CTime::GetCurrentTime();
m_Fecha = t.Format("%d/%m/%y");
try {
OpsRS->AddNew();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
UpdateData(FALSE);
m_Fecha = t.Format("%d/%m/%y");
m_ListOperaciones.EnableWi
}
void COps::OnBorrar()
{
int index = m_Operaciones.GetCurSel();
if (index == LB_ERR){
AfxMessageBox("Debe selccionar una operacisn!");
return;
}
CString where = "IDCliente = \'";
where += m_Clave + "\'";
OpsRS->m_strFilter = where;
try {
OpsRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
try {
OpsRS->SetAbsolutePosition
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
try {
OpsRS->Edit();
OpsRS->m_Baja = TRUE;
OpsRS->Update();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
m_Fecha = OpsRS->m_Fecha.Format("%d/
m_Unidades = OpsRS->m_NumValores;
if (atof(OpsRS->m_valCompra) > 0.0)
m_Registrado = OpsRS->m_valCompra;
if (atof(OpsRS->m_Valor) > 0.0)
m_Registrado = OpsRS->m_Valor;
if (atof(OpsRS->m_valVenta) > 0.0)
m_Registrado = OpsRS->m_valVenta;
if (OpsRS->m_Compra == "T" )
m_Buy=0;
else
m_Buy=1;
if (OpsRS->m_Tipo == "I")
m_paper=0;
else
m_paper = 1;
where = "UserID = \'" + m_Clave + "\'";
SaldosRS->m_strFilter = where;
try {
SaldosRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
try {
SaldosRS->Edit();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
float saldo = (float) atof(SaldosRS->m_Saldo1);
float opValue;
float st;
if (m_Buy == 0){
opValue = (float)1.0;
st = (float) atof(m_Registrado);
}
else{
opValue = (float)-1.0;
st = (float) atof(m_Registrado);
}
if (st == 0.0) st = (float) atof(m_Registrado);
if (m_Inst.GetCheck() == 1){
float st1 = st * (long)m_Unidades * opValue;
saldo += st1;
}else{
float st1 = (long)m_Unidades/st;
st1 = (float) ((long) st1 ); // Actual # of units purchased
st1 = st1 * st * opValue;
saldo += st1;
}
char tot [20];
sprintf(tot, "%.4f", saldo);
SaldosRS->m_Saldo1 = tot;
m_Saldo = saldo;
try {
SaldosRS->Update();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
char x [6];
sprintf(x, "%ld", OpsRS->m_IDInstrumento);
where = "(PortafolioID = \'" + m_Clave + x +"\' )";
PortafolioRS->m_strFilter = where;
try {
PortafolioRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
try {
PortafolioRS->Edit();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
PortafolioRS->m_Cantidad -= m_Unidades;
PortafolioRS->m_Instancias
char y[20];
sprintf(y,"%.2f", atof(PortafolioRS->m_Costo
PortafolioRS->m_Costo=y;
try {
PortafolioRS->Update();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
ReadOps();
}
void COps::OnEditar()
{
int index = m_Operaciones.GetCurSel();
if (index == LB_ERR){
AfxMessageBox("Debe selccionar una operacisn!");
return;
}
CString where = "IDCliente = \'";
where += m_Clave + "\'";
OpsRS->m_strFilter = where;
try {
OpsRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
try {
OpsRS->SetAbsolutePosition
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
m_Fecha = OpsRS->m_Fecha.Format("%d/
m_Unidades = m_OldUnidades = OpsRS->m_NumValores;
if (atof(OpsRS->m_valCompra) > 0.0)
m_Registrado = OpsRS->m_valCompra;
if (atof(OpsRS->m_Valor) > 0.0)
m_Registrado = OpsRS->m_Valor;
if (atof(OpsRS->m_valVenta) > 0.0)
m_Registrado = OpsRS->m_valVenta;
if (OpsRS->m_Compra == "T" )
m_Buy=0;
else
m_Buy=1;
if (OpsRS->m_Tipo == "I")
m_paper=0;
else
m_paper = 1;
char c[20];
sprintf(c, "%ld", OpsRS->m_IDInstrumento);
try {
index = OpsRS->m_IDInstrumento /*- 5L*/; /* -5L Due to offset in Instrumentos DB*/
InstUnSortRS->SetAbsoluteP
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
index = m_ListOperaciones.FindStri
m_ListOperaciones.SetCurSe
UpdateData(FALSE);
try {
OpsRS->Edit();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
Edit = TRUE;
m_btnGuardar.EnableWindow(
m_EditUnidades.EnableWindo
m_CompraVenta.EnableWindow
m_Tipo.EnableWindow(TRUE);
m_ListOperaciones.EnableWi
OldRegistrado = m_Registrado;
}
void COps::OnCompraventa()
{
m_Tipo.EnableWindow(TRUE);
}
void COps::OnTipo()
{
m_btnGuardar.EnableWindow(
}
// Initialize when needed
CDatabase* COps::GetDatabase()
{
// Connect the object to a data source
if( !m_dbInversim.IsOpen( ) &&
!m_dbInversim.OpenEx( NULL ) )
return NULL;
return &m_dbInversim;
}
CDatabase* COps::GetDatosDatabase()
{
// Connect the object to a data source
if( !m_dbDatos.IsOpen( ) &&
!m_dbDatos.OpenEx( NULL ) )
return NULL;
return &m_dbDatos;
}
BOOL COps::OnInitDialog()
{
AfxGetApp()->LoadStandardC
CDialog::OnInitDialog();
m_dbInversim.Open( _T( "Inversim" ), FALSE,
FALSE, _T( "ODBC;UID=admin;PWD=ncc170
ASSERT(m_dbInversim.IsOpen
if (m_dbInversim.IsOpen() == FALSE){
AfxGetApp()->LoadStandardC
AfxMessageBox( "ERROR!\nNo se pudo abrir la base de datos Inversim!");
return FALSE;
}
m_dbDatos.Open( _T( "Datos" ));
ASSERT(m_dbDatos.IsOpen())
if (m_dbDatos.IsOpen() == FALSE){
AfxGetApp()->LoadStandardC
AfxMessageBox( "ERROR!\nNo se pudo abrir la base de datos Datos 32!");
return FALSE;
}
AfxGetApp()->LoadStandardC
AfxGetApp()->LoadStandardC
ClientesRS = new CClientesRecordSet(GetData
ClientesRS->Open(CRecordse
ASSERT(ClientesRS->IsOpen(
if (ClientesRS->IsOpen() == FALSE){
AfxGetApp()->LoadStandardC
AfxMessageBox( "ERROR!\nNo se pudo abrir el Querry de Clientes!");
return FALSE;
}
OpsRS = new COpsRecordSet(GetDatabase(
OpsRS->Open(CRecordset::sn
ASSERT(OpsRS->IsOpen());
if (OpsRS->IsOpen() == FALSE){
AfxGetApp()->LoadStandardC
AfxMessageBox( "ERROR!\nNo se pudo abrir el Querry de Operaciones!");
return FALSE;
}
AfxGetApp()->LoadStandardC
AfxGetApp()->LoadStandardC
try {
InstRS = new CInstsRecordSet(GetDatabas
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
InstRS->m_strSort = "Nombre";
try{
InstRS->Open(CRecordset::s
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
InstRS->m_strSort = "Nombre";
ASSERT(InstRS->IsOpen());
if (InstRS->IsOpen() == FALSE){
AfxGetApp()->LoadStandardC
AfxMessageBox( "ERROR!\nNo se pudo abrir el Querry de Operaciones!");
return FALSE;
}
InstUnSortRS = new CInstsRecordSet(GetDatabas
InstUnSortRS->Open(CRecord
ASSERT(InstUnSortRS->IsOpe
if (InstUnSortRS->IsOpen() == FALSE){
AfxGetApp()->LoadStandardC
AfxMessageBox( "ERROR!\nNo se pudo abrir el Querry de Operaciones!");
return FALSE;
}
AfxGetApp()->LoadStandardC
AfxGetApp()->LoadStandardC
do{
CString Line;
char dato[20];
Line += InstRS->m_Nombre + '\t';
sprintf(dato, "%ld", InstRS->m_InstrumentoID);
CString d(dato);
Line += d;
m_ListOperaciones.AddStrin
try {
InstRS->MoveNext();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
Line = "";
} while (!InstRS->IsEOF());
SaldosRS = new CSaldosRecordSet(GetDataba
SaldosRS->Open(CRecordset:
ASSERT(SaldosRS->IsOpen())
if (SaldosRS->IsOpen() == FALSE){
AfxGetApp()->LoadStandardC
AfxMessageBox( "ERROR!\nNo se pudo abrir el Querry de Saldos!");
return FALSE;
}
PortafolioRS = new PortafoliosRecordSet(GetDa
PortafolioRS->Open(CRecord
ASSERT(PortafolioRS->IsOpe
if (PortafolioRS->IsOpen() == FALSE){
AfxGetApp()->LoadStandardC
AfxMessageBox( "ERROR!\nNo se pudo abrir el Querry de Portafolio!");
return FALSE;
}
AfxGetApp()->LoadStandardC
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void COps::OnOK()
{
ClientesRS->Close();
delete ClientesRS;
ClientesRS=NULL;
OpsRS->Close();
delete OpsRS;
OpsRS=NULL;
InstRS->Close();
delete InstRS;
InstRS=NULL;
InstUnSortRS->Close();
delete InstUnSortRS;
InstUnSortRS=NULL;
PortafolioRS->Close();
delete PortafolioRS;
PortafolioRS = NULL;
m_dbDatos.Close();
m_dbInversim.Close();
CDialog::OnClose();
DestroyWindow();
}
BOOL COps::Create(CWnd *pParent)
{
if (IsWindow(m_hWnd)){
SetActiveWindow();
return TRUE;
}
else return (CDialog::Create(COps::IDD
}
void COps::OnClose()
{
ClientesRS->Close();
OpsRS->Close();
InstRS->Close();
m_dbInversim.Close();
CDialog::OnClose();
DestroyWindow();
}
void COps::OnLimpiar1()
{
m_Materno = _T("");
m_Paterno = _T("");
m_Nombres = _T("");
m_RFC = _T("");
m_Saldo = (float)0.0;
m_Clave = _T("");
m_Registrado = _T("");
m_Operaciones.ResetContent
UpdateData(FALSE);
ClientesRS->m_strFilter = "";
try {
ClientesRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
}
void COps::ReadOps(){
// Get operations for client
AfxGetApp()->LoadStandardC
CString where = "IDCliente = \'";
where += m_Clave + "\'";
OpsRS->m_strFilter = where;
try {
OpsRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
m_Saldo = (float)0.0;
if( OpsRS->IsEOF()){
m_Operaciones.ResetContent
UpdateData(FALSE);
return;
}
try {
OpsRS->MoveFirst();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
m_Operaciones.ResetContent
if( OpsRS->IsBOF()){
return;
}
char data[20], data1[20];
CString d(data), d1(data1);
CString Line = "";
do {
wsprintf(data, "%ld", OpsRS->m_IDInstrumento);
wsprintf(data1, "%ld", OpsRS->m_NumValores);
d=data; d1=data1;
where = "(Instrumentos.Instrumento
try {
InstUnSortRS->SetAbsoluteP
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
Line += OpsRS->m_Fecha.Format("%d/
Line += InstUnSortRS->m_Nombre + '\t';
Line += OpsRS->m_Tipo +'\t';
if (*(LPCTSTR)OpsRS->m_Compra
Line += (CString)"Compra" + '\t';
else
Line += (CString)"Venta" + '\t';
wsprintf(data1, "%ld", OpsRS->m_NumValores);
CString dd(data1);
Line += dd + '\t'; // Numero de Valores comprados
char data3[20];
memset(data3, 0, 20);
double num = atof(LPCTSTR(OpsRS->m_Valo
if (num != 0.0){
sprintf(data3, "%.2f", num) ;
CString d3(data3);
Line += d3;
}
num = atof(LPCTSTR(OpsRS->m_valV
if (num != 0.0){
sprintf(data3, "%.2f", num) ;
CString d3(data3);
Line += d3;
}
num = atof(LPCTSTR(OpsRS->m_valC
if (num != 0.0){
sprintf(data3, "%.2f", num) ;
CString d3(data3);
Line += d3;
}
if (OpsRS->m_Baja == TRUE)
Line += "\tDado de Baja";
m_Operaciones.AddString(LP
try {
OpsRS->MoveNext();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
Line = "";
} while (!OpsRS->IsEOF());
where = "UserID = \'" + m_Clave + "\'";
SaldosRS->m_strFilter = where;
try {
SaldosRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
m_Saldo = (float) atof(SaldosRS->m_Saldo1);
AfxGetApp()->LoadStandardC
}
void COps::OnSelchangeListinstr
{
long IDInst;
m_ListOperaciones.GetText(
IDInst = atol(LPCSTR(Buffer.Mid(Buf
char data[20];
wsprintf(data, "%ld", IDInst);
CString d(data);
CString where = "(Instrumentos.Instrumento
InstRS->m_strFilter = where;
try {
InstRS->Requery();
}
catch (CDBException *pEx ){
AfxMessageBox(pEx->m_strEr
pEx->Delete();
}
m_Valor ="";
m_valCompra="";
m_valVenta="";
char data3[20];
double num = atof(LPCTSTR(InstRS->m_Val
if (num != 0.0){
sprintf(data3, "%.2f", num) ;
CString d3(data3);
m_Valor = d3;
}
num = atof(LPCTSTR(InstRS->m_Ven
if (num != 0.0){
sprintf(data3, "%.2f", num) ;
CString d3(data3);
m_valVenta = d3;
}
num = atof(LPCTSTR(InstRS->m_Com
if (num != 0.0){
sprintf(data3, "%.2f", num) ;
CString d3(data3);
m_valCompra = d3;
}
UpdateData(FALSE);
}
void COps::OnCompra()
{
m_Inst.EnableWindow(TRUE);
}
void COps::OnInstrumentos()
{
m_btnGuardar.EnableWindow(
}
void COps::OnVenta()
{
m_Inst.EnableWindow(TRUE);
}
void COps::OnPesos()
{
m_btnGuardar.EnableWindow(
}
void COps::Ejecutar()
{
CDatabase m_dbInversim;
HCURSOR hCursor;
hCursor = AfxGetApp()->LoadStandardC
m_dbInversim.Open( _T( "Inversim" ), FALSE,
FALSE, _T( "ODBC;UID=admin;PWD=ncc170
ASSERT(m_dbInversim.IsOpen
if (m_dbInversim.IsOpen() == FALSE){
AfxGetApp()->LoadStandardC
AfxMessageBox( "ERROR!\nNo se pudo abrir la base de datos!");
return;
}
// Acciones
CString str = "UPDATE Instrumentos INNER JOIN T_NCap_Accion ON Instrumentos.Nombre = T_NCap_Accion.Emisora SET Instrumentos.Valor = T_NCap_Accion.Precio_actua
try{
m_dbInversim.ExecuteSQL(st
}
catch (CDBException *pEx){
AfxGetApp()->LoadStandardC
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
//Cambios
str = "UPDATE Instrumentos INNER JOIN T_NCap_Cambios ON Instrumentos.Nombre = T_NCap_Cambios.Clave_pizar
try{
m_dbInversim.ExecuteSQL(st
}
catch (CDBException *pEx){
AfxGetApp()->LoadStandardC
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
//Cambios-Coberturas
str = "UPDATE Instrumentos INNER JOIN T_NCam_Coberturas ON Instrumentos.Nombre = T_NCam_Coberturas.Fuente_p
try{
m_dbInversim.ExecuteSQL(st
}
catch (CDBException *pEx){
AfxGetApp()->LoadStandardC
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
//Cambios-Dolar Internacional
str = "UPDATE Instrumentos INNER JOIN T_NCam_Dolar_Int ON Instrumentos.Nombre = T_NCam_Dolar_Int.Fuente_va
try{
m_dbInversim.ExecuteSQL(st
}
catch (CDBException *pEx){
AfxGetApp()->LoadStandardC
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
//Cambios-Monedas Internacional
str = "UPDATE Instrumentos INNER JOIN T_ICam_Monedas_Int ON Instrumentos.Nombre = T_ICam_Monedas_Int.Divisa SET Instrumentos.Compra = T_ICam_Monedas_Int.Compra,
try{
m_dbInversim.ExecuteSQL(st
}
catch (CDBException *pEx){
AfxGetApp()->LoadStandardC
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
//Dinero-Promedio
str = "UPDATE Instrumentos INNER JOIN T_NDin_Promedio ON Instrumentos.Nombre = T_NDin_Promedio.Instrument
try{
m_dbInversim.ExecuteSQL(st
}
catch (CDBException *pEx){
AfxGetApp()->LoadStandardC
AfxMessageBox(pEx->m_strEr
pEx->Delete();
return;
}
//Intermedio
str = "UPDATE Instrumentos INNER JOIN T_Nint_Mdo_Intermedio ON Instrumentos.Nombre = T_Nint_Mdo_Intermedio.Emis
ASKER
Don't worry, I will grade your answer soon enough, just been veru busy lately and unable to try out your suggestions. Sorry, I should be able to get to it by the weekend. Don't worry, I haven't forgotten!!!
Not worried at all. You are not grading my comment. This one was to answer your no point question.
ASKER
Thank you for your answer... sorry it took so long to grade!
Based on the ammount of points you placed here though, I don't believe that this is the complete nature of your problem
I have some code that updates multiple RecordSets but is not based on CRecordView, let me know if you feel that would help and I will post it.