Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

custdialog.ui.h

00001 /****************************************************************************
00002 ** ui.h extension file, included from the uic-generated form implementation.
00003 **
00004 ** If you wish to add, delete or rename functions or slots use
00005 ** Qt Designer which will update this file, preserving your code. Create an
00006 ** init() function in place of a constructor, and a destroy() function in
00007 ** place of a destructor.
00008 *****************************************************************************/
00009 
00010 void CustDialog::init()
00011 {
00012         inInit = TRUE ;
00013         mode = 0 ; // Read mode
00014         active_qa = "" ;
00015         activeCust = 0 ;
00016         custs = new QSqlCursor( "Contacts", TRUE ) ;
00017         setROMode( TRUE ) ;
00018         message->setText( "" ) ;
00019         canValidate() ;
00020         inInit = FALSE ;
00021 
00022 }
00023 
00024 void CustDialog::showInfo()
00025 {
00026         if ( !inInit ) {
00027                 mode = 0 ; // Read mode
00028                 setROMode( TRUE ) ;
00029                 int custid = customerSelector->getId( customerSelector->currentText() ) ;
00030                 custs->setFilter( QString( "recid='%1'" ).arg( custid ) ) ;
00031                 custs->select() ;
00032                 if ( custs->next() ) {
00033                         activeCust = custid ;
00034                         message->setText( "" ) ;
00035                         contact_qa->setText( custs->value( "contact_qa").toString() ) ;
00036                         active_qa = contact_qa->text() ;
00037                         contact_name->setText( custs->value( "contact_name" ).toString() ) ;
00038                         address1->setText( custs->value( "address1" ).toString() ) ;
00039                         address2->setText( custs->value( "address2" ).toString() ) ;
00040                         address3->setText( custs->value( "address3" ).toString() ) ;
00041                         zip->setText( custs->value( "zip" ).toString() ) ;
00042                         city->setText( custs->value( "city" ).toString() ) ;
00043                         phone->setText( custs->value( "phone" ).toString() ) ;
00044                         fax->setText( custs->value( "fax" ).toString() ) ;
00045                         email->setText( custs->value( "email" ).toString() ) ;
00046                 } else {
00047                         activeCust = 0 ;
00048                         active_qa = "" ;
00049                         message->setText( tr( "Database Error. Unable to get customer!" ) ) ;
00050                 }
00051                 custs->setFilter( "" ) ;
00052                 canValidate() ;
00053         }
00054 }
00055 
00056 
00057 void CustDialog::custNew()
00058 {
00059         custNewButton->setEnabled( FALSE ) ;
00060         custUpdateButton->setEnabled( FALSE ) ;
00061         activeCust = 0 ;
00062         mode = 1 ; // Create
00063         active_qa = "" ;
00064         canValidate() ;
00065         contact_qa->setText( custs->value( "contact_qa").toString() ) ;
00066         active_qa = contact_qa->text() ;
00067         contact_name->setText( custs->value( "contact_name" ).toString() ) ;
00068         address1->setText( custs->value( "address1" ).toString() ) ;
00069         address2->setText( custs->value( "address2" ).toString() ) ;
00070         address3->setText( custs->value( "address3" ).toString() ) ;
00071         zip->setText( custs->value( "zip" ).toString() ) ;
00072         city->setText( custs->value( "city" ).toString() ) ;
00073         phone->setText( custs->value( "phone" ).toString() ) ;
00074         fax->setText( custs->value( "fax" ).toString() ) ;
00075         email->setText( custs->value( "email" ).toString() ) ;
00076         setROMode( FALSE ) ;
00077 }
00078 
00079 
00080 void CustDialog::custUpdate()
00081 {
00082         custNewButton->setEnabled( FALSE ) ;
00083         custUpdateButton->setEnabled( FALSE ) ;
00084         mode = 2 ; // Update
00085         setROMode( FALSE ) ;
00086 }
00087 
00088 
00089 void CustDialog::validate()
00090 {
00091         QSqlRecord * buffer = 0 ;
00092         if ( mode == 1 ) {
00093                 //create
00094                 buffer = custs->primeInsert() ;
00095                 buffer->setValue( "recid", SequenceGetNextValue( "Contacts" ) ) ;
00096                 activeCust = buffer->value( "recid" ).toInt() ;
00097                 buffer->setValue( "contact_xtype", "Customer" ) ;
00098                 buffer->setValue( "created", QDateTime::currentDateTime() ) ;
00099                 buffer->setValue( "active", 1 ) ;
00100                 buffer->setValue( "lastchangedreason", "Creation" ) ;
00101         } else if ( mode == 2 ) {
00102                 // Update
00103                 buffer = custs->primeUpdate() ;
00104                 buffer->setValue( "lastchangedreason", "Update" ) ;             
00105         }
00106         if ( mode != 0 ) {
00107                 buffer->setValue( "contact_qa", contact_qa->text().upper() ) ;
00108                 
00109                 buffer->setValue( "contact_name", contact_name->text() ) ;
00110                 buffer->setValue( "address1", address1->text() ) ;
00111                 buffer->setValue( "address2", address2->text() ) ;
00112                 buffer->setValue( "address3", address3->text() ) ;
00113                 buffer->setValue( "zip", zip->text() ) ;
00114                 buffer->setValue( "city", city->text() ) ;
00115                 buffer->setValue( "phone", phone->text() ) ;
00116                 buffer->setValue( "fax", fax->text() ) ;
00117                 buffer->setValue( "email", email->text() ) ;
00118                 if ( mode == 1 ) {
00119                         custs->insert() ;
00120                 } else {
00121                         custs->update() ;
00122                 }
00123         }
00124         accept() ;
00125 }
00126 
00127 
00128 void CustDialog::checkAbridged()
00129 {
00130         QSqlCursor * srch = new QSqlCursor( "Contacts", TRUE ) ;
00131         if ( mode == 1 ) {
00132                 QString want = contact_qa->text().upper().stripWhiteSpace() ;
00133                 srch->setFilter( QString( "contact_qa='%1' AND contact_xtype='Customer'" ) ) ;
00134                 srch->select() ;
00135                 if ( srch->next() ) {
00136                         message->setText( tr( "Invalid Abridged Code. Already present in database." ) ) ;
00137                         active_qa = "" ;
00138                 } else {
00139                         message->setText( "" ) ;
00140                         active_qa = want ;
00141                         contact_qa->setText( want ) ;
00142                 }
00143                 canValidate() ;
00144         }
00145 }
00146 
00147 
00148 void CustDialog::checkNotEmpty()
00149 {
00150         if ( contact_name->text().stripWhiteSpace().isEmpty() ) {
00151                 message->setText( tr( "Customer Name MUST be filled." ) ) ;
00152         }
00153         canValidate() ;
00154 }
00155 
00156 
00157 void CustDialog::setROMode( bool ed )
00158 {
00159         if ( mode == 2 ) {
00160                 contact_qa->setReadOnly( TRUE ) ;
00161         } else {
00162                 contact_qa->setReadOnly( ed ) ;
00163         }
00164         contact_name->setReadOnly( ed ) ;
00165         address1->setReadOnly( ed ) ;
00166         address2->setReadOnly( ed ) ;
00167         address3->setReadOnly( ed ) ;
00168         zip->setReadOnly( ed ) ;
00169         city->setReadOnly( ed ) ;
00170         phone->setReadOnly( ed ) ;
00171         fax->setReadOnly( ed ) ;
00172         email->setReadOnly( ed ) ;
00173 }
00174 
00175 
00176 int CustDialog::selected()
00177 {
00178         return activeCust ;
00179 }
00180 
00181 
00182 void CustDialog::canValidate()
00183 {
00184         if ( active_qa.isEmpty() 
00185                 || contact_name->text().stripWhiteSpace().isEmpty() ) {
00186                 okButton->setEnabled( FALSE ) ;
00187         } else {
00188                 okButton->setEnabled( TRUE ) ;
00189         }
00190 }

 

L.A.B. Project © 2001-2004 LAB Project & DJ Anubis