#include "mx.h"
int Row = 1;
MXMessageClass* InitDialog (MX* pmx)
{
MXClass* pclass;
MXMessageClass*
pmessageClass;
pclass =
MXGetClassFromName (pmx, FIOP_SYS);
pmessageClass =
MXCreateMessageClass(pclass, "Linendp", 1, 0);
MXAddObjectToMessage (pmessageClass , "CHAR" , 13 , "Code" );
MXAddObjectToMessage (pmessageClass , "CHAR" , 30 , "Libelle");
MXAddObjectToMessage (pmessageClass , "CHAR" , 2 , "Qt" );
MXAddObjectToMessage (pmessageClass , "CHAR" , 20 , "Ca" );
return
pmessageClass;
}
int
Linendp (MXMessage* pmessage, MXCom* pcom, void*
par)
{
MXCom* datacom =
(MXCom*)par;
BYTE Commit = 0;
int
error = 0;
int
i = 0;
STRING a, b, c,
d;
char
bb[65];
char
Request[500];
a = MXGetValue (pmessage,
"Code" , 1);
b = MXGetValue (pmessage,
"Libelle" , 1);
c = MXGetValue (pmessage,
"Qt" , 1);
d = MXGetValue (pmessage,
"Ca" , 1);
for
(i = 0; i < 13; i++)
if (a[i] == ' ') { a[i] = 0; break;}
sprintf
(Request, "INSERT INTO NDP (ID_NDP, POSITION_TARIFAIRE, NATURE,
QUANTITE_COMPLEMENTAIRE, CODES_ADDITIONNELS)\
VALUES (%d, '%.13s', '%.30s', %s, '%.16s');",
Row, a, bb, "NULL", d);
pmessage =
MXPutMessage (datacom, "DB", "AskStatement");
MXSetValue (pmessage,
"SqlStatement", 1, Request);
MXSetValue (pmessage,
"Commit", 1, &Commit);
MXSend (datacom->MX,
datacom, pmessage);
MXFreeMessage (pmessage);
pmessage =
MXRecv (datacom->MX, datacom);
MXFreeMessage (pmessage);
Row++;
return
1;
}
/* Synchronous mode
read from file and write in DB */
void
main ()
{
MX mx;
MXMessage* pmessage;
MXCom* DBCom;
MXCom* FileCom;
char FileType = 't';
/*
Initialize MX manager */
MXInit (&mx, MXSERVER, NULL, NULL, 0, NULL);
/*
Connect To DataBase */
DBCom = MXOpenBase (&mx,
"ORCL", "scott", "scott", DBPROTO_ORACLE, TRUE);
if (!DBCom)
return;
/* Open file where to read messages */
FileCom = MXOpenFile (pmx, FileName, "r", IOPROTO_FIOP, 'D', 0);
if (!FileCom) return;
MXAddComCallBack (pmx, fileclient, FIOP_SYS, "Linendp", MXONRECV,
Linendp, DBCom);
MXSetIOMessageClass (fileclient, InitDialog);
while (pmessage = MXRecv (pmx, fileclient))
{
MXFreeMessage (pmx, pmessage);
}
MXCloseCom (pmx , FileClient);
MXCloseCom (pmx , DBCom);
MXDispatchEvents (&mx, 0);
MXEnd (&mx);
}
|