📄 testhrmsdialog.cpp
字号:
#include "testhrmsdialog.h"
#include "quarydialogimpl.h"
#include "newdialogimpl.h"
#include "myLoadSqlSet.cpp"
#include "llf.h"
const int id_index = 7;
testHRMSDialog::testHRMSDialog( QWidget* parent, const char* name, bool modal, WFlags f )
: testHRMSDialogBase( parent, name, modal, f )
{
QString ts[id_index] = {"name", "sex", "age", "company", "job", "phone", "address"};
for (int i=0; i<id_index; i++)
{
tableStrings[i] = ts[i];
}
myLoadSqlSet sqlset( "mytest.ini" );
db = sqlset.mySet2SqlDB();
if ( db == NULL )
{
myMsgBox( "init db error!" );
return;
}
if ( db->open() )
{
//MsgBox( "sql server open ok!" );
cur = new QSqlCursor( "table_test" );
cur->select();
RefreshTable();
}
else
{
myMsgBox( "sql server open Error! ......" );
}
}
testHRMSDialog::~testHRMSDialog()
{
db->close();
}
void testHRMSDialog::RefreshTable()
{
ASSERT( cur != NULL );
//table1->clear();
tableClearAll( table1 );
int row = 0;
while ( cur->next() )
{
table1->insertRows( row );
for( int i=0; i<id_index; i++ )
{
QString str( QString::fromLocal8Bit( cur->value( tableStrings[i] ).toString().ascii() ) );
//myMsgBox( str );
//MsgBoxA( str.ascii() );
table1->setText( row, i, str );
}
table1->setText( row, i, cur->value( "id" ).toString() );
++row;
}
}
void testHRMSDialog::tableClearAll(QTable *qt)
{
ASSERT(qt != NULL);
for (int i = qt->numRows() - 1; i >=0 ; --i)
{
qt->removeRow( i );
}
}
void testHRMSDialog::buttonQuary_clicked()
{
QuaryDialog qd( this, NULL, true );
if ( qd.exec() == QDialog::Accepted )
{
QString qstr = "";
if ( qd.QuaryCustom->isChecked() )
{
qstr = tableStrings[ qd.stat->currentItem() ];
qstr += " " + qd.comp->currentText() + " ";
if ( qd.comp->currentText() == "like" )
{
qstr += "'%" + qd.usertext->text().replace( "'", "''" ) + "%'";
}
else
{
qstr += "'" + qd.usertext->text().replace( "'", "''" ) + "'";
}
}
//myMsgBox( qstr );
cur->select( qstr );
RefreshTable();
}
}
void testHRMSDialog::buttonAdd_clicked()
{
ASSERT( cur != NULL );
NewDialog nd( this, NULL, true );
if ( nd.exec() == QDialog::Accepted )
{
myMsgBoxQ( nd.nd_name->text() );
QSqlRecord *r = cur->primeInsert();
r->setValue( tableStrings[0], nd.nd_name->text().local8Bit() );
r->setValue( tableStrings[1], nd.nd_sex->currentItem() );
r->setValue( tableStrings[2], nd.nd_age->text() );
r->setValue( tableStrings[3], nd.nd_company->text().local8Bit() );
r->setValue( tableStrings[4], nd.nd_job->text().local8Bit() );
r->setValue( tableStrings[5], nd.nd_phone->text().local8Bit() );
r->setValue( tableStrings[6], nd.nd_address->text().local8Bit() );
cur->insert();
}
}
void testHRMSDialog::buttonDelete_clicked()
{
ASSERT( cur != NULL );
int n = 0;
int i = 0;
for (i = table1->numRows() - 1; i >= 0 ; --i)
{
if ( table1->isRowSelected( i, true ) )
{
n++;
}
}
if ( n > 0 )
{
if ( QMessageBox::Yes == QMessageBox::warning( this, "HRMS",
QString::fromLocal8Bit( "你确定要删除这些项目么?" ),
QMessageBox::Yes, QMessageBox::No ) )
{
QMemArray<int> qma(n);
int m = 0;
for (i = 0; i < table1->numRows(); ++i)
{
if ( table1->isRowSelected( i, true ) )
{
cur->select( "id=" + table1->text( i, id_index ) );
if ( cur->next() )
{
cur->primeDelete();
cur->del();
qma[m++] = i;
}
}
}
table1->removeRows( qma );
}
}
else
{
myMsgBox( "请先选择相应的行,然后再执行删除操作!" );
}
}
void testHRMSDialog::table1_valueChanged( int row, int col )
{
ASSERT( cur != NULL );
if ( col < id_index )
{
QSqlRecord *buffer = cur->primeUpdate();
buffer->setValue( tableStrings[col], table1->text( row, col ).local8Bit() );
cur->update();
}
else
{
// myMsgBox( "这一个单元格不能编辑!" );
}
}
void testHRMSDialog::table1_doubleClicked ( int row, int col, int button, const QPoint & mousePos )
{
if ( col >= id_index )
{
myMsgBox( "这一个单元格不能编辑!" );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -