// PrintTermEngineDlg.cpp : implementation file // #include "stdafx.h" #include "PrintTermEngine.h" #include "PrintTermEngineDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #include "Dynrec.h" #include "Print.h" #include "Com.h" #include "Facture.h" #include "DateTimeEx.h" #include "Params.h" #include "MessageDlg.h" //////////////////////////////////////////////////////////////////////////// // CPrintTermEngineDlg dialog CPrintTermEngineDlg::CPrintTermEngineDlg(CWnd* pParent /*=NULL*/) : CDialog(CPrintTermEngineDlg::IDD, pParent) { //{{AFX_DATA_INIT(CPrintTermEngineDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 //Recherche de ticket non imprimés m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CPrintTermEngineDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPrintTermEngineDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } #define PRINT_ID_EVENT 5000 // 3 secondes BEGIN_MESSAGE_MAP(CPrintTermEngineDlg, CDialog) //{{AFX_MSG_MAP(CPrintTermEngineDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDOK, OnPrint) ON_BN_CLICKED(IDC_START_TMR_BUTTON, OnStartTmrButton) ON_WM_TIMER(PRINT_ID_EVENT, OnTimer) ON_BN_CLICKED(IDC_KILL_TMR_BUTTON2, OnKillTmrButton) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPrintTermEngineDlg message handlers BOOL CPrintTermEngineDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here //Connexion à la base de données try { TRACE(m_strDsnCaisse); m_pBase.OpenEx(m_strDsnCaisse, CDatabase::noOdbcDialog); Dlg.m_strMsg = "Connexion établie!"; Dlg.DoModal(); } catch(CDBException* pEx) { pEx->Delete(); Dlg.m_strMsg = "Connexion échouée!"; Dlg.DoModal(); } SetTimer(PRINT_ID_EVENT, 2000, 0); WinExec("PrintEngine.exe", SW_HIDE); return TRUE; // return TRUE unless you set the focus to a control } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CPrintTermEngineDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CPrintTermEngineDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } //Gestion du Timer void CPrintTermEngineDlg::OnStartTmrButton() { SetTimer(PRINT_ID_EVENT, 5000, 0); } void CPrintTermEngineDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default //Recherche de ticket non imprimés CDynRec tikRec(&m_pBase); CDynRec srvRec(&m_pBase); CDynRec kesRec(&m_pBase); m_strCmd = "FROM TICKET_ACT WHERE TICKETID > 10000 AND PRINTED = 0"; if(tikRec.Select("CAISSEID, CODERAZ, TICKETID, DESTINATION, NBRCLIENTS,TYPETICKET, CODESERV,TOTAL, CODECLE", m_strCmd)) { //Détermination des params m_strCmd.Format("FROM CAISSE WHERE CAISSEID = %d", tikRec.ToLng("CAISSEID")); if(kesRec.Select("LIBELLE", m_strCmd)) { if(!kesRec.IsEOF()) { m_strLibCaisse = kesRec.ToStr("LIBELLE"); m_strAbrCaisse = kesRec.ToStr("ABREVIATION"); } } kesRec.Close(); m_strCmd.Format("FROM SERVEUR WHERE CODECLE = %d", tikRec.ToLng("CODECLE")); if(srvRec.Select("CODESERV,NOM", m_strCmd)) { if(!srvRec.IsEOF()) { m_nCodeVendeur = srvRec.ToLng("CODESERV"); m_strNomVendeur = srvRec.ToStr("NOM"); m_nKey = srvRec.ToLng("CODECLE"); } else { m_nCodeVendeur = 0; m_strNomVendeur = ""; m_nKey = 0; } srvRec.Close(); } m_nTicketID = tikRec.ToInt("TICKETID"); m_nTable = tikRec.ToInt("DESTINATION"); m_nTypeTicket = tikRec.ToInt("TYPETICKET"); m_nCaisseID = tikRec.ToInt("CAISSEID"); m_nCouvert = tikRec.ToInt("NBRCLIENTS"); m_nCodeServeur = tikRec.ToInt("CODESERV"); m_dTotal = tikRec.ToDbl("TOTAL"); m_nCodeRaz = tikRec.ToDbl("CODERAZ"); while(!tikRec.IsEOF()) { PrintTerm(m_nTicketID, m_nTypeTicket, m_nCaisseID, m_nTable, m_nCouvert, m_nCodeServeur, m_dTotal, m_nKey); tikRec.MoveNext(); } tikRec.Close(); return; } KillTimer(nIDEvent); CDialog::OnTimer(nIDEvent); } void CPrintTermEngineDlg::OnKillTmrButton() { KillTimer(PRINT_ID_EVENT); } void CPrintTermEngineDlg::OnPrint() { } void CPrintTermEngineDlg::PrintTerm(int nTicketId,int nTypeTicket,int nCaisseId,int nDestination,int nNbrClients,int nCodeServeur,double dTotal,int nCodeCle) { if(nTypeTicket==1)//Si Commande { if(nDestination==0) { PrepareTermCommande(nTicketId,nCaisseId,nDestination,nNbrClients,nCodeServeur); } PrintTermTicket(nTicketId);; } else if(nTypeTicket==2)//Si Note { PrintTermNote(nTicketId,nCaisseId,nDestination,nNbrClients,nCodeServeur,dTotal,nCodeCle); } else if(nTypeTicket==3)//Si ticket { PrepareTermCommande(nTicketId,nCaisseId,nDestination,nNbrClients,nCodeServeur); } //return true; } int CPrintTermEngineDlg::PrepareTermCommande(int nTicketId,int nCaisseId,int nDestination,int nNbrClients,int nCodeServeur) { CDynRec Rec(&m_pBase); CArray Commande; CArray PCommande; CArray BonCmd; SCmdLine Cmd; SBonCmd Bon; CString strCmd, strBon, strEntete, strPied, strServeur, strCaisse, strNum, strValeur; long nCodeImp, nCodeArt; int nCount = 0; bool bIsFirst = false; PCommande.RemoveAll(); Commande.RemoveAll(); BonCmd.RemoveAll(); strCmd.Format(" FROM TICKET_ACT T, LIGNE_TICKET_ACT L,ARTICLE A, LINK_ART LA WHERE L.TICKETID = %d AND L.CODEART=A.CODEART AND T.TICKETID=L.TICKETID AND A.CODEART=LA.CODEART AND LA.CAISSEID=T.CAISSEID AND L.PRINTED=0 ",nTicketId); if(Rec.Select(" LA.CODEIMP AS CODEIMP, T.TYPETICKET AS TYPETICKET, A.LIBELLE AS LIBELLE,L.CAISSEID AS CAISSEID,L.CODERAZ AS CODERAZ,L.TICKETID AS TICKETID,L.DESTINATION AS DESTINATION,LINEID,L.CODEART AS CODEART,QUANTITE,L.PRIX AS PRIX,PRIXU,REMISE,TVA,TAUX,ALTERED,FLAG,STATUT,L.ISTRANSF AS ISTRANSF,L.PRINTED AS PRINTED",strCmd)) { while(!Rec.IsEOF()) { SCmdLine Ligne ; Ligne.nCodeArt=Rec.ToLng("CODEART"); Ligne.dPrix=Rec.ToDbl("PRIXU"); Ligne.dQte=Rec.ToDbl("QUANTITE"); Ligne.dValeur=Rec.ToDbl("PRIX"); Ligne.nArtStatus=Rec.ToLng("STATUT"); Ligne.strLibelle=Rec.ToStr("LIBELLE"); Ligne.strType=Rec.ToStr("TYPETICKET"); Ligne.nCodeImp = Rec.ToLng("CODEIMP"); Commande.Add(Ligne); nCount++; Rec.MoveNext(); } Rec.Close(); } //MessageBox("Ligne commande préparés!", "Impression", MB_OK); strCmd.Format("FROM PRINTER WHERE CODEIMP <> 0 AND CAISSEID = %d", nCaisseId); if(Rec.Select("CODEIMP,ADRESSE,DRIVER,RATE,IMPRNV,CAISRNV", strCmd)) { while(!Rec.IsEOF()) { nCodeImp = Rec.ToLng("CODEIMP"); bIsFirst = true; for(int nItem = 0; nItem < nCount; nItem++) { SCmdLine TmpCmd=Commande.GetAt(nItem); //Si Article sauvegradé /*if(m_Facture.GetFlag(nItem, 14) || m_Facture.GetFlag(nItem, 15)) { continue; }*/ if(nCodeImp==TmpCmd.nCodeImp) { // nCodeArt = m_Facture.GetCode(nItem); /*//Verification si l'article a été déja compilé for(int nIndex = 0; nIndex < Commande.GetSize(); nIndex++) { //Si l'article existe affectuer un cumul de quantité Cmd = Commande.GetAt(nIndex); if(Cmd.nCodeArt == nCodeArt) { Cmd.dQte += strtod(m_Facture.GetItemText(nItem,0),NULL); Commande.SetAt(nIndex, Cmd); break; } }*/ /*Cmd.nCodeArt = nCodeArt; Cmd.strLibelle=m_Facture.GetItemText(nItem, 11)==""?m_Facture.GetItemText(nItem, 1):m_Facture.GetItemText(nItem, 11); Cmd.nArtStatus = 0; Cmd.dQte = strtod(m_Facture.GetItemText(nItem,0),NULL); Cmd.nCodeImp = nCodeImp; Cmd.dValeur = strtod(m_Facture.GetItemText(nItem,2),NULL);;*/ PCommande.Add(TmpCmd); //Creation des bon if(bIsFirst) { Bon.nCodeImp = nCodeImp; Bon.strDevice = Rec.ToStr("DRIVER"); Bon.nRate = Rec.ToLng("RATE"); Bon.nRevoie = Rec.ToLng("IMPRNV"); Bon.nCaisse = Rec.ToLng("CAISRNV"); Bon.nTicketID = nTicketId; Bon.nTable = nDestination; Bon.nCouverts = m_nCouvert; Bon.nServeur = m_nCodeServeur; Bon.nNumBon = 0; Bon.strHost = Rec.ToStr("ADRESSE"); Bon.strBon = ""; Bon.strEntete = ""; Bon.strPied = ""; BonCmd.Add(Bon); bIsFirst = false; } } } Rec.MoveNext(); } Rec.Close(); } //MessageBox("Bon préparés! - Début Formatage", "Impression", MB_OK); nCodeImp = -1; int nImpIndex = 0; for(int nIndex = 0; nIndex < PCommande.GetSize(); nIndex++) { Cmd = PCommande.GetAt(nIndex); //Nouveau bon : Preparation entete if(nCodeImp != Cmd.nCodeImp) { nCodeImp = Cmd.nCodeImp; //Recherche numero du bon strCmd.Format("FROM CAISSE WHERE CAISSEID = %d",nCaisseId); if(Rec.Select("NUMBON+1",strCmd)) { if(!Rec.IsEOF()) { strNum = Rec.ToStr("NUMBON+1"); } Rec.Close(); } //Incrementation du numero du bon try { if(m_pBase.BeginTrans()) { strCmd.Format("UPDATE CAISSE SET NUMBON = NUMBON + 1 WHERE CAISSEID = %d", nCaisseId); m_pBase.ExecuteSQL(strCmd); m_pBase.CommitTrans(); } } catch(CDBException* pEx) { TRACE("<<<%s>>>\n", strCmd); pEx->Delete(); m_pBase.Rollback(); } strEntete.Format("%c%c%c%c%c%c%c%c", 0x1b,0x40,0x1b,0x61,0x01,0x1b,0x21,0x1c); strCmd.Format("PREPAREZ SVP BON N%c%s\r\n", 0xf8, strNum); strEntete += strCmd; if(m_nTable == 0) { strCmd.Format("TICKET N%c %d\r\n",0xf8,nTicketId); strEntete += strCmd; } else { strCmd.Format("TABLE %d COUVERTS %d\r\n",nDestination,nNbrClients); strEntete += strCmd; } strCmd.Format("%c%c%c\r\n",0x1b,0x61,0xBB); strEntete += strCmd; strBon = ""; } //Preparation detail strValeur="";//.Format("%0.3f", Cmd.dValeur); strCmd.Format("%4d %-18s %6s\r\n",(long)Cmd.dQte, Cmd.strLibelle.Left(20), strValeur); strBon += strCmd; //Pas preparation pied (si pas derniere ligne) if(nIndex < PCommande.GetSize()-1) { Cmd = PCommande.GetAt(nIndex+1); if(nCodeImp == Cmd.nCodeImp) { continue; } } //Preparation Pied strCmd.Format("%c%c%c%c%c%c",0x1b,0x61,0x01,0x1b,0x21,0x11); strPied = strCmd; strCmd.Format("\r\n%c%c%c%s\r\n",0x1b,0x21,104,CDateTimeEx::GetStrLocalTime("%d/%m/%y-%H:%M:%S")); strPied += strCmd; strCmd.Format("%c%c%c%c%c%c",0x1b,0x61,0x01,0x1b,0x21,0x14); strPied += strCmd; strCmd.Format("Vend : %-12s Cais : %-12s\r\n",m_strNomVendeur.Left(12), m_strLibCaisse.Left(12)); //[%d] m_Facture.m_nCodeServ, [%d] m_Facture.m_nCaisseID, strPied += strCmd; strCmd.Format("%c%c%c%c%c%c",0x1b,0x61,0x01,0x1b,0x21,0x11); strPied += strCmd; /*strCmd = m_pParams.GetParam(40); strPied += strCmd;*/ strCmd.Format("\r\n\r\n\r\n\r\n\r\n%c%c%c",0x1b,0x69); strPied += strCmd; Bon = BonCmd.GetAt(nImpIndex); Bon.strBon = strBon; Bon.strEntete = strEntete; Bon.strPied = strPied; BonCmd.SetAt(nImpIndex, Bon); nImpIndex++; } TRACE("***********COMMANDE**********\n"); for(int i = 0; i < strBon.GetLength(); i++) { TRACE("%c", strBon.GetAt(i)); } TRACE("*****************************\n"); //MessageBox("Fin formatage!", "Impression", MB_OK); /*****Print*/ //SBonCmd Bon; bool bIsNotSent = true; CCom Com; //CString strCmd; long nPrinterNbr = 0, nRenvNbr = 0; //Recherche du nombre des imprimentes //pour eviter la boucle fermé if(Rec.Select("COUNT(CODEIMP)", "FROM PRINTER")) { nPrinterNbr = Rec.ToLng("COUNT(CODEIMP)"); Rec.Close(); } for( nIndex = 0; nIndex < BonCmd.GetSize(); nIndex++) { Bon = BonCmd.GetAt(nIndex); //MessageBox("Envoi vers l'imprimante, début impression!", "Impression", MB_OK); bIs NotSent = !Print(Bon.nCodeImp, Bon.strHost, Bon.strDevice, Bon.nRate, Bon.strEntete + Bon.strBon + Bon.strPied); Sleep(100); //MessageBox("Fin impression bon, attente 2ème bon!", "Impression", MB_OK); //Si l'imprimente revoie est la meme if(Bon.nCodeImp == Bon.nRevoie) { continue; } //MessageBox("Si pas imprimés, renvoi vers 2ème imprimante!", "Impression", MB_OK); if(bIsNotSent) { //Renvoie sur une autre imprimente strCmd.Format("FROM PRINTER WHERE CODEIMP = %d AND CAISSEID = %d", Bon.nRevoie, Bon.nCaisse); if(Rec.Select("CODEIMP,ADRESSE,DRIVER,RATE,IMPRNV,CAISRNV", strCmd)) { if(!Rec.IsEOF()) { Bon.nCodeImp = Bon.nRevoie; Bon.strDevice = Rec.ToStr("DRIVER"); Bon.nRate = Rec.ToLng("RATE"); Bon.nRevoie = Rec.ToLng("IMPRNV"); Bon.nCaisse = Rec.ToLng("CAISRNV"); Bon.strHost = Rec.ToStr("ADRESSE"); BonCmd.SetAt(nIndex, Bon); nIndex--; } Rec.Close(); } } } //MessageBox("Fin impression début mise à jour base!", "Impression", MB_OK); //Mise à jour etat article à printed try { if(m_pBase.BeginTrans()) { m_strCmd.Format("UPDATE LIGNE_TICKET_ACT SET PRINTED = 1 WHERE CAISSEID = %d AND TICKETID = %d", nCaisseId,nTicketId); m_pBase.ExecuteSQL(m_strCmd); m_strCmd.Format("UPDATE TICKET_ACT SET PRINTED = 1 WHERE CAISSEID = %d AND TICKETID = %d", nCaisseId,nTicketId); m_pBase.ExecuteSQL(m_strCmd); m_pBase.CommitTrans(); } } catch(CDBException *pEx) { TRACE("<<<%s>>>\n", m_strCmd); m_pBase.Rollback(); pEx->Delete(); } return BonCmd.GetSize(); } bool CPrintTermEngineDlg::PrintTermCommande(int nTicketId,int nCaisseId) { CDynRec Rec(&m_pBase); SBonCmd Bon; bool bIsNotSent = true; CCom Com; CString strCmd; long nPrinterNbr = 0, nRenvNbr = 0; //Recherche du nombre des imprimentes //pour eviter la boucle fermé if(Rec.Select("COUNT(CODEIMP)", "FROM PRINTER")) { nPrinterNbr = Rec.ToLng("COUNT(CODEIMP)"); Rec.Close(); } for(int nIndex = 0; nIndex < BonCmd.GetSize(); nIndex++) { Bon = BonCmd.GetAt(nIndex); bIsNotSent = !Print(Bon.nCodeImp, Bon.strHost, Bon.strDevice, Bon.nRate, Bon.strEntete + Bon.strBon + Bon.strPied); Sleep(100); //Si l'imprimente revoie est la meme if(Bon.nCodeImp == Bon.nRevoie) { continue; } if(bIsNotSent) { //Renvoie sur une autre imprimente strCmd.Format("FROM PRINTER WHERE CODEIMP = %d AND CAISSEID = %d", Bon.nRevoie, Bon.nCaisse); if(Rec.Select("CODEIMP,ADRESSE,DRIVER,RATE,IMPRNV,CAISRNV", strCmd)) { if(!Rec.IsEOF()) { Bon.nCodeImp = Bon.nRevoie; Bon.strDevice = Rec.ToStr("DRIVER"); Bon.nRate = Rec.ToLng("RATE"); Bon.nRevoie = Rec.ToLng("IMPRNV"); Bon.nCaisse = Rec.ToLng("CAISRNV"); Bon.strHost = Rec.ToStr("ADRESSE"); m_BonCmd.SetAt(nIndex, Bon); nIndex--; } Rec.Close(); } } } //Preparation du bon attente /*if(m_strBonAttente != "") { //m_strBonAttente.Insert(0, strBon); strCmd.Format("\r\n%c%c%c%c%c%cCL[%d] V[%d] C[%d] No%4d\r\n",0x1b,0x61,0x01,0x1b,0x21,0x01,m_Facture.m_nCodeCle, m_Facture.m_nCodeServ, m_Facture.m_nCaisseID, m_Facture.m_nTicketID); //%-10s strServeur.Left(10), //%-8s strCaisse, m_strBonAttente += strCmd; strCmd.Format("\r\n\r\n\r\n\r\n%c%c%c",0x1b,0x69); m_strBonAttente += strCmd; }*/ //Si ticket encore en commande if(m_nTypeTicket == 3) { //m_Client.Reset(); //DisplayClient(); } //Mise à jour etat article à printed try { if(m_pBase.BeginTrans()) { m_strCmd.Format("UPDATE LIGNE_TICKET_ACT SET PRINTED = 1 WHERE CAISSEID = %d AND TICKETID = %d", nCaisseId,nTicketId); m_pBase.ExecuteSQL(m_strCmd); m_strCmd.Format("UPDATE TICKET_ACT SET PRINTED = 1 WHERE CAISSEID = %d AND TICKETID = %d", nCaisseId,nTicketId); m_pBase.ExecuteSQL(m_strCmd); m_pBase.CommitTrans(); } } catch(CDBException *pEx) { TRACE("<<<%s>>>\n", m_strCmd); m_pBase.Rollback(); pEx->Delete(); } return true; } bool CPrintTermEngineDlg::PrintTermTicket(int nTicketId) { CDynRec Rec(&m_pBase); CString strCmd, strBon; CArray Commande; CArray Reglement; long nCodeReg; SCmdLine Cmd; STickReg Reg; double dTotRem = 0, dTotal = 0; int nCodeServeur=0, nNbrClients=0, nCodeRaz=0, nCaisseId=0, nDestination=0, nTypeTicket=1,nCodeCle; //Chargement des données detail du ticket strCmd.Format(" FROM TICKET_ACT T, LIGNE_TICKET_ACT L,ARTICLE A WHERE L.TICKETID = %d AND L.CODEART=A.CODEART AND T.TICKETID=L.TICKETID ",nTicketId); if(Rec.Select(" T.TYPETICKET AS TYPETICKET, A.LIBELLE AS LIBELLE,L.CAISSEID AS CAISSEID,L.CODERAZ AS CODERAZ,L.TICKETID AS TICKETID,L.DESTINATION AS DESTINATION,LINEID,L.CODEART AS CODEART,QUANTITE,L.PRIX AS PRIX,PRIXU,REMISE,TVA,TAUX,ALTERED,FLAG,STATUT,L.ISTRANSF AS ISTRANSF,L.PRINTED AS PRINTED",strCmd)) { while(!Rec.IsEOF()) { SCmdLine Ligne ; Ligne.nCodeArt=Rec.ToLng("CODEART"); Ligne.dPrix=Rec.ToDbl("PRIXU"); Ligne.dQte=Rec.ToDbl("QUANTITE"); Ligne.dValeur=Rec.ToDbl("PRIX"); Ligne.nArtStatus=Rec.ToLng("STATUT"); Ligne.strLibelle=Rec.ToStr("LIBELLE"); Ligne.nType=Rec.ToLng("TYPETICKET"); dTotal += Rec.ToDbl("PRIX"); Commande.Add(Ligne); Rec.MoveNext(); } Rec.Close(); } //Chargement de reglement strCmd.Format(" FROM REG_TICKET_ACT RT, REGLEMENT R WHERE TICKETID = 10012 AND RT.CODEREG=R.CODEREG",nTicketId); if(Rec.Select(" LIBELLE , PRECIS , CAISSEID, CODERAZ,TICKETID,DESTINATION,LINEID,HEURE,TOTAL,RT.CODEREG COD_REG,CODEDEV,COURTDEV,ISRENDU,ALTERED,STATUT ",strCmd)) { while(!Rec.IsEOF()) { STickReg LigneReg ; LigneReg.strLibelle=Rec.ToStr("LIBELLE"); LigneReg.dValeur=Rec.ToDbl("TOTAL"); LigneReg.dQte =0; LigneReg.dCourt=Rec.ToDbl("COURTDEV"); LigneReg.nCodeReg=Rec.ToLng("COD_REG"); LigneReg.nPrecision=Rec.ToInt("PRECIS"); Reglement.Add(LigneReg); Rec.MoveNext(); } Rec.Close(); } //Impression du ticket if(Commande.GetSize() > 0) { CString strPrix, strValeur; strCmd.Format("%c%c%c%c%c\r\n",0x1b,0x40,0x1b,0x61,0x01); strBon = strCmd; strCmd.Format("%c%c%c%sRESTAURANT\r\n",0x1b,0x21,0x28); //0x1b,0x21,0x60 strBon += strCmd; strCmd.Format("%c%c%cCOCONUT ISLAND\r\n",0x1b,0x21,0x79); //0x1b,0x21,0x38 strBon += strCmd; strCmd.Format("%c%c%cHotel Club El Kantaoui\r\n",0x1b,0x21,0x02); strBon += strCmd; strCmd.Format("%c%c%cTel 732 46 011 - GSM : 97 222 530\r\n",0x1b,0x21,0x02); strBon += strCmd; strCmd.Format("%c%c%c%s\r\n\r\n",0x1b,0x21,0x01,CDateTimeEx::GetStrLocalTime("%A %d %B %Y %H:%M:%S")); strBon += strCmd; //Preparation du bon rendu if(m_strBonRendu != "") { m_strBonRendu.Insert(0, strBon); strCmd.Format("\r\n%c%c%c%c%c%cCL[%d] V[%d]%-10s C[%d]%-8s No%4d\r\n",0x1b,0x61,0x01,0x1b,0x21,0x01,m_nKey, m_nCodeServeur, m_strNomVendeur.Left(10), m_nCaisseID, m_strLibCaisse, m_nTicketID); m_strBonRendu += strCmd; strCmd.Format("\r\n\r\n\r\n\r\n%c%c%c",0x1b,0x69); m_strBonRendu += strCmd; } if(nDestination != 0) { strCmd.Format("%c%c%cFACTURE N%c %d TABLE N%c %d\r\n\r\n",0x1b,0x21,0x79,0xf8,nTicketId-(nCaisseId*10000),248,nDestination); strBon += strCmd; } else { long nTicket = nTicketId; strCmd.Format("%c%c%cTICKET N%c %d\r\n\r\n",0x1b,0x21,0x79,0xf8,nTicket); strBon += strCmd; strCmd.Format("%c%c%c",0x1b,0x21,0x02); strBon += strCmd; for(int nIndex = 0; nIndex < Commande.GetSize(); nIndex++) { Cmd = Commande.GetAt(nIndex); if(Cmd.nType == 1) { if(Cmd.dQte != 0) { strPrix.Format("%3.3f",Cmd.dPrix); if(Cmd.strType != "") { strValeur = Cmd.strType; } else { strValeur.Format("%3.3f", Cmd.dValeur); } strCmd.Format("%5d %-20s %c%c%c%6s%c%c%c %8s\r\n" ,(long)Cmd.dQte, Cmd.strLibelle.Left(20),0x1b,0x21,0x01,strPrix,0x1b,0x21,0x02,strValeur); strBon += strCmd; } } else if(Cmd.strType == "2") { strPrix = ""; strValeur.Format("%3.3f", Cmd.dValeur); strCmd.Format("%5s %c%c%c%-20s %c%c%c%7s%c%c%c %8s\r\n" ,strPrix,0x1b,0x21,0x0a, Cmd.strLibelle.Left(19),0x1b,0x21,0x01,"",0x1b,0x21,0x02,strValeur); strBon += strCmd; } } strCmd.Format("%c%c%c%c%c%c%c%c%c%c%c%c%c%c \r\n",0x1b,0x61,0x02,0x1b,0x21,104,205,205,205,205,205,205,205,205); strBon += strCmd; } strValeur.Format("%0.3f", m_dTotal); strCmd.Format("%c%c%c TOTAL %12s \r\n",0x1b,0x61,0x02,strValeur); strBon += strCmd; strCmd.Format("%c%c%c%c%c%c",0x1b,0x61,0x02,0x1b,0x21,0x02); strBon += strCmd; strCmd.Format("SELECT DISTINCT(TAUX) TAUX_TVA,SUM(TVA) VALEUR FROM LIGNE_TICKET_ACT WHERE CAISSEID=%d AND CODERAZ=%d AND TICKETID = %d AND DESTINATION=%d GROUP BY TAUX", m_nCaisseID, m_nCodeRaz, nTicketId, nDestination); if(Rec.Select(strCmd)) { while(!Rec.IsEOF()) { if(Rec.ToDbl("VALEUR") != 0) { strPrix.Format("%3.2f", Rec.ToDbl("TAUX_TVA")); strValeur.Format("%0.3f", Rec.ToDbl("VALEUR")); strCmd.Format(" Dont TVA %5s%% %9s \r\n", strPrix, strValeur); strBon += strCmd; } Rec.MoveNext(); } Rec.Close(); strBon += "\r\n"; } for(int nIndex = 0; nIndex < Reglement.GetSize(); nIndex++) { CString strFormat, strCourt; Reg = Reglement.GetAt(nIndex); strFormat.Format("%%3.%df", Reg.nPrecision); strValeur.Format("%3.3f", Reg.dValeur); if(Reg.dQte != 0) { strPrix.Format(strFormat, Reg.dQte); } else { strPrix = ""; } if(Reg.dCourt != 0) { strCourt.Format("x %0.3f", Reg.dCourt); } else { strCourt = ""; } strValeur.Format("%3.3f", Reg.dValeur); strCmd.Format(" %-13s %5s %5s %7s \r\n",Reg.strLibelle, strPrix,strCourt, strValeur); strBon += strCmd; } strCmd.Format("\r\n%c%c%c%c%c%cCL[%d] V[%d]%-10s C[%d]%-8s No%4d\r\n",0x1b,0x61,0x01,0x1b,0x21,0x01,m_nKey, m_nCodeServeur, m_strNomVendeur.Left(10), m_nCaisseID, m_strLibCaisse, nTicketId); strBon += strCmd; strCmd.Format("%c%c%c**********************************\r\n",0x1b,0x21,0x02); strBon += strCmd; strCmd.Format("%c%c%cA BIENTOT ET MERCI\r\n",0x1b,0x21,33); strBon += strCmd; strCmd.Format("%c%c%c**********************************\r\n",0x1b,0x21,0x02); strBon += strCmd; strCmd.Format("\r\n\r\n\r\n\r\n%c%c%c",0x1b,0x69); strBon += strCmd; TRACE("************TICKET***********\n"); for(int i = 0; i < strBon.GetLength(); i++) { TRACE("%c", strBon.GetAt(i)); } TRACE("*****************************\n"); CString strCanAnnulPrint = "O"; //Recherche des proprietés de l'imprimente strCmd.Format("FROM PRINTER WHERE CODEIMP = %d AND CAISSEID = %d", 0, m_nCaisseID); if(Rec.Select("CODEIMP,ADRESSE,DRIVER,IMPRNV,CAISRNV,RATE", strCmd)) { if(!Rec.IsEOF()) { CCom Com; while(1) { if(!Com.Open(Rec.ToStr("DRIVER"),Rec.ToLng("RATE"))) { //break; CMessageDlg MsgOpn; MsgOpn.SetTextColor(RGB(255,0,0)); MsgOpn.m_strMsg = "Impression ticket impossible !\r\n Tapez < VALIDER > Pour réessayer."; if(MsgOpn.DoModal() == IDCANCEL) { if(strCanAnnulPrint == "O") { break; //->Annuler l'impression } else { continue; } } else { continue; } } else { while(1) { if(!Com.GetStatus(MS_DSR_ON)) { CMessageDlg MsgDsr; MsgDsr.SetTextColor(RGB(255,0,0)); MsgDsr.m_strMsg = "Impression ticket impossible !\r\n Tapez < VALIDER > Pour réessayer."; if(MsgDsr.DoModal() == IDCANCEL) { if(strCanAnnulPrint == "O") { break; //->Annuler l'impression } else { continue; } } else { continue; } continue; } else { //Initialisation Com.SendData((BYTE)0x1b); Com.SendData((BYTE)0x40); //Loading bitmap /*HBITMAP hStart = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), "c:\\dcs\\logo.img", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); if(hStart != NULL) { CBitmap Start; BITMAP Bitmap; BYTE* lpData; CString strData; Start.Attach(hStart); Start.GetBitmap(&Bitmap); lpData = new BYTE[Bitmap.bmHeight*Bitmap.bmWidthBytes]; Start.GetBitmapBits(Bitmap.bmHeight*Bitmap.bmWidthBytes, lpData); //Download Image //strData.Format("%c%c%c%c", 0x1d,0x2a,Bitmap.bmHeight/8,Bitmap.bmWidth/8); strData.Format("%c%c%c%c", 0x1d,0x2a,Bitmap.bmHeight/8,Bitmap.bmWidth/8); Com.SendData(strData); int nIndex = 0; while(nIndex < (Bitmap.bmHeight/8)*(Bitmap.bmWidth/8)*8) { Com.SendData(~(BYTE)*(lpData+nIndex)); nIndex++; } delete[] lpData; //Unidirectionnel print strData.Format("%c%c%c", 0x1b,0x55, 1); Com.SendData(strData); strData.Format("%c%c%c", 0x1d,0x2f, 3); Com.SendData(strData); }*/ Com.SendData(strBon); //Initialisation Com.SendData((BYTE)0x1b); Com.SendData((BYTE)0x40); try { if(m_pBase.BeginTrans()) { strCmd.Format("UPDATE TICKET_ACT SET PRINTED = 1 WHERE CAISSEID = %d AND CODERAZ = %d AND TICKETID = %d", m_nCaisseID, m_nCodeRaz,nTicketId); m_pBase.ExecuteSQL(strCmd); m_pBase.CommitTrans(); } } catch(CDBException* pEx) { m_pBase.Rollback(); pEx->Delete(); } break; } } Com.Close(); break; } } } Rec.Close(); } } else { m_strBonRendu = ""; //m_strBonAttente = ""; return true; } //Mise à jour etat ticket à printed try { if(m_pBase.BeginTrans()) { m_strCmd.Format("UPDATE TICKET_ACT SET PRINTED = 1 WHERE CAISSEID = %d AND CODERAZ = %d AND TICKETID = %d", m_nCaisseID, m_nCodeRaz,m_nTicketID); m_pBase.ExecuteSQL(m_strCmd); m_pBase.CommitTrans(); } } catch(CDBException* pEx) { m_pBase.Rollback(); pEx->Delete(); } m_strBonRendu = ""; return true; } bool CPrintTermEngineDlg::PrintTermNote(int nTicketId,int nCaisseId,int nDestination,int nNbrClients,int nCodeServeur,double dTot,int nCodeCle) { CDynRec Rec(&m_pBase); CString strCmd, strBon; CArray Commande; CArray PCommande; int nCount = 0; long nCodeArt; SCmdLine Cmd; SCmdLine TmpCmd; SCmdLine PTmpCmd; bool bIsNewArt = false; int nCompilStart = 0; double dTotRem = 0, dTotal = 0; Commande.RemoveAll(); PCommande.RemoveAll(); //Chargement des articles non sauvgardé strCmd.Format(" FROM TICKET_ACT T, LIGNE_TICKET_ACT L,ARTICLE A, LINK_ART LA WHERE L.TICKETID = %d AND L.CODEART=A.CODEART AND T.TICKETID=L.TICKETID AND A.CODEART=LA.CODEART AND LA.CAISSEID=T.CAISSEID ",nTicketId); if(Rec.Select(" LA.CODEIMP AS CODEIMP, T.TYPETICKET AS TYPETICKET, A.LIBELLE AS LIBELLE,L.CAISSEID AS CAISSEID,L.CODERAZ AS CODERAZ,L.TICKETID AS TICKETID,L.DESTINATION AS DESTINATION,LINEID,L.CODEART AS CODEART,QUANTITE,L.PRIX AS PRIX,PRIXU,REMISE,TVA,TAUX,ALTERED,FLAG,STATUT,L.ISTRANSF AS ISTRANSF,L.PRINTED AS PRINTED",strCmd)) { while(!Rec.IsEOF()) { SCmdLine Ligne ; Ligne.nCodeArt=Rec.ToLng("CODEART"); Ligne.dPrix=Rec.ToDbl("PRIXU"); Ligne.dQte=Rec.ToDbl("QUANTITE"); Ligne.dValeur=Rec.ToDbl("PRIX"); Ligne.nArtStatus=Rec.ToLng("STATUT"); Ligne.strLibelle=Rec.ToStr("LIBELLE"); Ligne.nType=Rec.ToLng("TYPETICKET"); Ligne.nCodeImp = Rec.ToLng("CODEIMP"); Commande.Add(Ligne); nCount++; Rec.MoveNext(); } Rec.Close(); } //Envoie des articles non sauvegardés en commande /*for(int nItem = 0; nItem < nCount; nItem++) { TmpCmd=Commande.GetAt(nItem); nCodeArt = TmpCmd.nCodeArt; //Si l'article n'est pas edité sur note if(m_Facture.GetFlag(nItem,0) && !m_Facture.GetFlag(nItem,10)) { bIsNewArt = true; dTotal += strtod(m_Facture.GetItemText(nItem,2),NULL); dTotRem += strtod(m_Facture.GetItemText(nItem,3),NULL); strCmd.Format("FROM ARTICLE A, LINK_ART L, ARTSTATUS S WHERE A.CODEART = L.CODEART AND L.ARTSTATUS = S.ARTSTATUS AND A.CODEART = %d AND CAISSEID = %d", nCodeArt, m_pParams.m_nCaisseID); if(Rec.Select("A.LIBELLE,S.VALEUR,CODEIMP,L.PRIX",strCmd)) { if(!Rec.IsEOF()) { TRACE("Article %d %s\n", nCodeArt,Rec.ToStr("A.LIBELLE")); //Verification si l'article a été déja compilé for(int nIndex = nCompilStart; nIndex < Commande.GetSize(); nIndex++) { //Si l'article existe affectuer un cumul de quantité Cmd = Commande.GetAt(nIndex); if(Cmd.nCodeArt == nCodeArt && Cmd.nType == 1) { //if(Cmd.strType.Left(3) == "ANN" || m_Facture.GetItemText(nItem,6).Left(3) == "ANN") //{ Cmd.dQte += strtod(m_Facture.GetItemText(nItem,0),NULL); Cmd.dValeur += strtod(m_Facture.GetItemText(nItem,2),NULL); Commande.SetAt(nIndex, Cmd); break; //} } } //Si l'article n'à pas été compilé if(nIndex == Commande.GetSize()) { Cmd.nCodeArt = nCodeArt; Cmd.strLibelle = Rec.ToStr("A.LIBELLE"); Cmd.nArtStatus = Rec.ToLng("S.VALEUR"); Cmd.dQte = strtod(m_Facture.GetItemText(nItem,0),NULL); Cmd.dValeur = strtod(m_Facture.GetItemText(nItem,2),NULL); Cmd.nCodeImp = Rec.ToLng("CODEIMP"); Cmd.dPrix = strtod(m_Facture.GetItemText(nItem,8),NULL); Cmd.nType = 1; Cmd.strType = m_Facture.GetItemText(nItem,6); Commande.Add(Cmd); } } Rec.Close(); } }//Si ligne remise / offre / annulation else if(m_Facture.GetFlag(nItem, 2) || m_Facture.GetFlag(nItem, 3) || m_Facture.GetFlag(nItem, 4)) { nCompilStart = Commande.GetSize(); Cmd.nType = 2; Cmd.nCodeArt = nCodeArt; Cmd.strLibelle = m_Facture.GetItemText(nItem, 1); Cmd.dQte = strtod(strCmd, NULL); Cmd.nArtStatus = 0; Cmd.nCodeImp = 0; Cmd.dPrix = 0; Cmd.dValeur = strtod(m_Facture.GetItemText(nItem, 2),NULL); //Si ligne remise if(m_Facture.GetFlag(nItem, 2)) { Cmd.nArtStatus = 2; } Commande.Add(Cmd); }}*/ for(int CmdIndex=0; CmdIndex 0) { CString strPrix, strValeur; strCmd.Format("%c%c%c%c%c\r\n",0x1b,0x40,0x1b,0x61,0x01); strBon = strCmd; strCmd.Format("%c%c%cRESTAURANT\r\n",0x1b,0x21,0x60); strBon += strCmd; strCmd.Format("%c%c%cCOCONUT ISLAND\r\n",0x1b,0x21,0x38); strBon += strCmd; strCmd.Format("%c%c%cHotel Club El Kantaoui\r\n",0x1b,0x21,0x02); strBon += strCmd; strCmd.Format("%c%c%cTel 732 46 011 - GSM : 97 222 530\r\n",0x1b,0x21,0x02); strBon += strCmd; COleDateTimeSpan Duree = m_Facture.m_Depart - m_Facture.m_Arrivee; strCmd.Format("%c%c%c%s [%s]\r\n\r\n",0x1b,0x21,0x01,CDateTimeEx::GetStrLocalTime("%A %d %B %Y %H:%M:%S"), Duree.Format("%H:%M")); strBon += strCmd; strCmd.Format("%c%c%cFACTURE TABLE N%c %d\r\n\r\n",0x1b,0x21,0x79,0xf8,nDestination); strBon += strCmd; strCmd.Format("%c%c%cCOUVERTS %d\r\n\r\n",0x1b,0x21,0x02,nNbrClients); strBon += strCmd; strCmd.Format("%c%c%c",0x1b,0x61,0x02); strBon += strCmd; strCmd.Format("%c%c%c",0x1b,0x21,0x02); strBon += strCmd; for(int nIndex = 0; nIndex < Commande.GetSize(); nIndex++) { Cmd = Commande.GetAt(nIndex); //Si ligne article && n'est pas (pas edité sur note) strPrix.Format("%3.3f",Cmd.dPrix); if(Cmd.nType == 1 && !(Cmd.nArtStatus & 0x0100)) { if(Cmd.dQte != 0) { if(Cmd.strType != "") { strValeur = Cmd.strType; } else { strValeur.Format("%3.3f", Cmd.dValeur); } strCmd.Format("%5d %-20s %c%c%c%7s%c%c%c %8s\r\n" ,(long)Cmd.dQte, Cmd.strLibelle.Left(20),0x1b,0x21,0x01,strPrix,0x1b,0x21,0x02,strValeur); strBon += strCmd; } } else if(Cmd.nType == 2) { if(Cmd.dQte != 0) { if(Cmd.strType != "") { strValeur = Cmd.strType; } else { strValeur.Format("%3.3f", Cmd.dValeur); } strCmd.Format("%5d %-20s %c%c%c%7s%c%c%c %8s\r\n" ,(long)Cmd.dQte, Cmd.strLibelle.Left(20),0x1b,0x21,0x01,strPrix,0x1b,0x21,0x02,strValeur); strBon += strCmd; } /*strPrix = ""; strValeur.Format("%3.3f", Cmd.dValeur); strCmd.Format("%5s %c%c%c%-20s %c%c%c%7s%c%c%c %8s\r\n" ,strPrix,0x1b,0x21,0x0a, Cmd.strLibelle.Left(19),0x1b,0x21,0x01,"",0x1b,0x21,0x02,strValeur); strBon += strCmd;*/ } } //Impression des remises strCmd.Format("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\r\n",0x1b,0x61,0x02,0x1b,0x21,0x79,205,205,205,205,205,205,205,205,205,205); strBon += strCmd; strCmd.Format("%c%c%cNET A PAYER %0.3f\r\n",0x1b,0x61,0x02,dTot); strBon += strCmd; //Si transfert sur compte strCmd.Format("\r\n%c%c%c%c%c%cCL[%d] V[%d]%-10s C[%d]%-8s No%4d\r\n",0x1b,0x61,0x01,0x1b,0x21,0x01,m_nKey, m_nCodeVendeur, m_strNomVendeur.Left(10), m_nCaisseID, m_strLibCaisse, m_nTicketID-m_nCaisseID*10000); strBon += strCmd; strCmd.Format("%c%c%c**********************************\r\n",0x1b,0x21,0x02); strBon += strCmd; strCmd.Format("%c%c%cA BIENTOT ET MERCI\r\n",0x1b,0x21,0x79); strBon += strCmd; strCmd.Format("%c%c%c**********************************\r\n",0x1b,0x21,0x02); strBon += strCmd; strCmd.Format("\r\n\r\n\r\n\r\n%c%c%c",0x1b,0x69); strBon += strCmd; TRACE("**************NOTE***********\n"); for(int i = 0; i < strBon.GetLength(); i++) { TRACE("%c", strBon.GetAt(i)); } TRACE("*****************************\n"); CString strCanAnnulPrint = "O"; //Recherche des proprietés de l'imprimente strCmd.Format("FROM PRINTER WHERE CODEIMP = %d AND CAISSEID = %d", 0, nCaisseId); if(Rec.Select("CODEIMP,ADRESSE,DRIVER,IMPRNV,CAISRNV,RATE", strCmd)) { if(!Rec.IsEOF()) { CCom Com; while(1) { if(!Com.Open(Rec.ToStr("DRIVER"),Rec.ToLng("RATE"))) { //break; CMessageDlg MsgOpn; MsgOpn.SetTextColor(RGB(255,0,0)); MsgOpn.m_strMsg = "Impression note impossible !\r\n Tapez < VALIDER > Pour réessayer."; if(MsgOpn.DoModal() == IDCANCEL) { if(strCanAnnulPrint == "O") { break; //->Annuler l'impression } else { continue; } } else { continue; } continue; } else { while(1) { if(!Com.GetStatus(MS_DSR_ON)) { CMessageDlg MsgDsr; MsgDsr.SetTextColor(RGB(255,0,0)); MsgDsr.m_strMsg = "Impression note impossible !\r\n Tapaz < VALIDER > Pour réessayer."; if(MsgDsr.DoModal() == IDCANCEL) { if(strCanAnnulPrint == "O") { break; //->Annuler l'impression } else { continue; } } else { continue; } continue; } else { //Loading bitmap /*HBITMAP hStart = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), "c:\\dcs\\logo.img", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); if(hStart != NULL) { CBitmap Start; BITMAP Bitmap; BYTE* lpData; CString strData; Start.Attach(hStart); Start.GetBitmap(&Bitmap); lpData = new BYTE[Bitmap.bmHeight*Bitmap.bmWidthBytes]; Start.GetBitmapBits(Bitmap.bmHeight*Bitmap.bmWidthBytes, lpData); //Download Image strData.Format("%c%c%c%c", 0x1d,0x2a,Bitmap.bmHeight/8,Bitmap.bmWidth/8); Com.SendData(strData); int nIndex = 0; while(nIndex < (Bitmap.bmHeight/8)*(Bitmap.bmWidth/8)*8) { Com.SendData(~(BYTE)*(lpData+nIndex)); nIndex++; } delete[] lpData; //Unidirectionnel print strData.Format("%c%c%c", 0x1b,0x55, 1); Com.SendData(strData); strData.Format("%c%c%c", 0x1d,0x2f, 3); Com.SendData(strData); }*/ Com.SendData(strBon); Com.SendData((BYTE)0x1b); Com.SendData((BYTE)0x40); if(m_strBonRendu != "") { Com.SendData(m_strBonRendu); //Initialisation Com.SendData((BYTE)0x1b); Com.SendData((BYTE)0x40); } break; } } Com.Close(); break; } } } Rec.Close(); } } else { m_strBonRendu = ""; return true; } m_strBonRendu = ""; //Mise à jour etat ticket try { if(m_pBase.BeginTrans()) { strCmd.Format("UPDATE TICKET_ACT SET PRINTED = 1 WHERE CAISSEID = %d AND TICKETID = %d", nCaisseId,nTicketId); m_pBase.ExecuteSQL(strCmd); m_pBase.CommitTrans(); } } catch(CDBException* pEx) { m_pBase.Rollback(); pEx->Delete(); } return true; } bool CPrintTermEngineDlg::Print(long nCodeImp, CString strHost, CString strDevice, long nBaudRate, CString strData) { STARTUPINFO StartUpInfo; PROCESS_INFORMATION ProcessInfo; DWORD ExitCode = STILL_ACTIVE; CString strCmdLine, strFileName; int nWait = 0; if(strHost == "") { strHost = "loopback"; } strFileName.Format("%-15s 8310 %4s %05d 2", strHost, strDevice, nBaudRate); strCmdLine.Format("PrintJob.exe %-15s 8310 %4s %05d 2", strHost, strDevice, nBaudRate); CFile File; CFileException Ex; if(File.Open(strFileName, CFile::modeCreate | CFile::modeNoTruncate| CFile::modeWrite, &Ex)) { File.SeekToEnd(); File.Write(strData, strData.GetLength()); File.Close(); } else { Ex.ReportError(); return false; } RETRY: ::GetStartupInfo(&StartUpInfo); if(CreateProcess(NULL, strCmdLine.GetBuffer(0), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &StartUpInfo, &ProcessInfo) == 0) { DWORD Res = GetLastError(); //MessageBox("Erreur lors de l'appel à " + strCmdLine + "\r\n" + strData); return false; } else { while(ExitCode == STILL_ACTIVE) { GetExitCodeProcess(ProcessInfo.hProcess, &ExitCode); if(nWait > (strData.GetLength()/1024)*500) { Sleep(1000); nWait+=1000; } } if(ExitCode == 0) { return true; } else { return false; } } return false; }