示例#1
0
EmployeeForm::EmployeeForm(int id, QWidget *parent)
    : QDialog(parent)
{
    nameEdit = new QLineEdit;

    nameLabel = new QLabel(tr("Na&me:"));
    nameLabel->setBuddy(nameEdit);

    departmentComboBox = new QComboBox;

    departmentLabel = new QLabel(tr("Depar&tment:"));
    departmentLabel->setBuddy(departmentComboBox);

    extensionLineEdit = new QLineEdit;
	extensionLineEdit->setValidator(
								new QIntValidator(0, 99999, this));

    extensionLabel = new QLabel(tr("E&xtension:"));
    extensionLabel->setBuddy(extensionLineEdit);

    emailEdit = new QLineEdit;

    emailLabel = new QLabel(tr("&Email:"));
    emailLabel->setBuddy(emailEdit);

    startDateEdit = new QDateEdit;
    startDateEdit->setCalendarPopup(true);
    QDate today = QDate::currentDate();
	startDateEdit->setDateRange(
			today.addDays(-90), today.addDays(90));

    startDateLabel = new QLabel(tr("&Start Date:"));
    startDateLabel->setBuddy(startDateEdit);

    firstButton = new QPushButton(tr("<< &First"));
    previousButton = new QPushButton(tr("< &Previous"));
    nextButton = new QPushButton(tr("&Next >"));
    lastButton = new QPushButton(tr("&Last >>"));

    addButton = new QPushButton(tr("&Add"));
    deleteButton = new QPushButton(tr("&Delete"));
    closeButton = new QPushButton(tr("&Close"));

    buttonBox = new QDialogButtonBox;
    buttonBox->addButton(addButton, QDialogButtonBox::ActionRole);
    buttonBox->addButton(deleteButton, QDialogButtonBox::ActionRole);
    buttonBox->addButton(closeButton, QDialogButtonBox::AcceptRole);

    tableModel = new QSqlRelationalTableModel(this);
    tableModel->setTable("employee");
    tableModel->setRelation(Employee_DepartmentId,
                            QSqlRelation("department", "id", "name"));
    tableModel->setSort(Employee_Name, Qt::AscendingOrder);
    tableModel->select();

    QSqlTableModel *relationModel =
            tableModel->relationModel(Employee_DepartmentId);
    departmentComboBox->setModel(relationModel);
    departmentComboBox->setModelColumn(
            relationModel->fieldIndex("name"));

    mapper = new QDataWidgetMapper(this);
    mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
    mapper->setModel(tableModel);
    mapper->setItemDelegate(new QSqlRelationalDelegate(this));
    mapper->addMapping(nameEdit, Employee_Name);
    mapper->addMapping(departmentComboBox, Employee_DepartmentId);
    mapper->addMapping(extensionLineEdit, Employee_Extension);
    mapper->addMapping(emailEdit, Employee_Email);
    mapper->addMapping(startDateEdit, Employee_StartDate);

	if (id != -1)
	{
		for (int row = 0; row < tableModel->rowCount(); ++row)
		{
            QSqlRecord record = tableModel->record(row);
            if (record.value(Employee_Id).toInt() == id) {
                mapper->setCurrentIndex(row);
                break;
            }
        }
	 }
	else
	{
        mapper->toFirst();
    }

    connect(firstButton, SIGNAL(clicked()), mapper, SLOT(toFirst()));
    connect(previousButton, SIGNAL(clicked()),
            mapper, SLOT(toPrevious()));
    connect(nextButton, SIGNAL(clicked()), mapper, SLOT(toNext()));
    connect(lastButton, SIGNAL(clicked()), mapper, SLOT(toLast()));

	connect(addButton, SIGNAL(clicked()),
			this, SLOT(addEmployee()));
    connect(deleteButton, SIGNAL(clicked()),
            this, SLOT(deleteEmployee()));
    connect(closeButton, SIGNAL(clicked()), this, SLOT(accept()));

    QHBoxLayout *topButtonLayout = new QHBoxLayout;
    topButtonLayout->setContentsMargins(20, 0, 20, 5);
    topButtonLayout->addStretch();
    topButtonLayout->addWidget(firstButton);
    topButtonLayout->addWidget(previousButton);
    topButtonLayout->addWidget(nextButton);
    topButtonLayout->addWidget(lastButton);
    topButtonLayout->addStretch();

    QGridLayout *mainLayout = new QGridLayout;
    mainLayout->addLayout(topButtonLayout, 0, 0, 1, 3);
    mainLayout->addWidget(nameLabel, 1, 0);
    mainLayout->addWidget(nameEdit, 1, 1, 1, 2);
    mainLayout->addWidget(departmentLabel, 2, 0);
    mainLayout->addWidget(departmentComboBox, 2, 1, 1, 2);
    mainLayout->addWidget(extensionLabel, 3, 0);
    mainLayout->addWidget(extensionLineEdit, 3, 1);
    mainLayout->addWidget(emailLabel, 4, 0);
    mainLayout->addWidget(emailEdit, 4, 1, 1, 2);
    mainLayout->addWidget(startDateLabel, 5, 0);
    mainLayout->addWidget(startDateEdit, 5, 1);
    mainLayout->addWidget(buttonBox, 7, 0, 1, 3);
    mainLayout->setRowMinimumHeight(6, 10);
    mainLayout->setRowStretch(6, 1);
    mainLayout->setColumnStretch(2, 1);
    setLayout(mainLayout);

    if (id == -1) {
        nextButton->setFocus();
    } else {
        nameEdit->setFocus();
    }

    setWindowTitle(tr("Edit Employees"));
}
示例#2
0
int main()
{
    ArrayList* arrayListC=al_newArrayList();
    ArrayList* DeleteHistory=al_newArrayList();
    ArrayList* Backup=al_newArrayList();
    eEmployee* employeeAux;
    int id=0;
    int auxInt;
    int option;
    char continueDo='s';
//    loadCant(arrayListC);
    loadFile(arrayListC,"Nomina.dat");
    loadFile(DeleteHistory,"Exempl.dat");

//   loader(arrayListC);
    do
    {
        getInt(&option,"######CASO DE USO ARRAYLIST###\n\n1-Agregar un empleado\n2-Modificar empleado\n3-Eliminar empleado"
               "\n4-Tamaño de la nomina\n5-Informes\n6-Salir"
               "\n10-Salir\noption:","Opcion no valida\n",1,8);
        switch(option)
        {
        case 1:
            employeeAux=loadEmployee(arrayListC);
            auxInt=findByName(DeleteHistory,employeeAux->name,employeeAux->lastName);
            if(auxInt==-1)
            {
                id++;
                if(al_add(arrayListC,(void*)employeeAux))
                {
                    id--;
                }
            }
            else
            {
                getInt(&option,"\nEl empleado ya pertenecia a la empresa, desea agregarlo nuevamente?? \n1-Si\n2-No","Error opcion no valida",1,2);
                switch(option)
                {
                case 1:
                    employeeAux=(ArrayList*)arrayListC->get(DeleteHistory,auxInt);
                    al_push(arrayListC,(employeeAux->id-1),(void*)employeeAux);
                    al_remove(DeleteHistory,auxInt);
                    break;
                case 2:
                    id++;
                    if(al_add(arrayListC,(void*)employeeAux))
                    {
                        id--;
                    }
                }
                break;
            }
            break;
        case 2:
            modifyEmployee(arrayListC);
            break;
        case 3:
            deleteEmployee(arrayListC,DeleteHistory);
            break;
        case 4:
            printf("\n\n@@@@@@@@ HISTORIAL @@@@@@@\n\n");
            PrintEmployees(DeleteHistory);
            break;
        case 5:
            informes(arrayListC);
            break;
        case 6:
            continueDo='n';
            saveToFileActive(arrayListC,"Nomina.dat");
            saveToFileActive(DeleteHistory,"Exempl.dat");
            break;
        case 7:

            break;
        case 8:
            al_push(arrayListC,2,loadEmployee(arrayListC));

            break;

        default:
            break;
        }


    }
    while(continueDo!='n');
//    saveCant(arrayListC);


    return 0;
}