int SimpleRedisClient::reconect()
 {
     
     if(debug > 1) printf("\x1b[31mredis reconect[%s:%d]\x1b[0m\n", host, port);
     
     redis_close();
     if(!redis_conect())
     {
         return false;
     }
     
     if(lastAuthPw != NULL )
     {
         printf("\x1b[31mredis reconect lastAuthPw=%s\x1b[0m\n", lastAuthPw);
         if(redis_send( RC_INLINE, "AUTH %s\r\n", lastAuthPw))
         {
             return false;
         }
     }
     
     if(lastSelectDBIndex != 0 )
     {
         if( !selectDB(lastSelectDBIndex) )
         {
             return false;
         }
     }
     
     return true;
 }
void ManagerMessage::on_pushButton_2_clicked()      //修改密码
{
    static bool tf = true;
    if(tf)
    {
        ui->pushButton_2->setText("保存密码");

        ui->label_6->show();
        ui->old->show();
        ui->label_7->show();
        ui->now->show();

        tf = false;
    }
    else
    {
        if(ui->old->text().trimmed() != mm)
        {
            Error("原始密码错误!");
            return;
        }

        if(ui->now->text().isEmpty())
        {
            Error("密码不能为空!");
            return;
        }

        QRegExp reg("^[a-zA-Z]\\w{5,31}$");
        if(!reg.exactMatch(ui->now->text().trimmed()))
        {
            Error("密码须字母开头,长度6-32,只包含字符,数字,下划线");
            return;
        }

        if(ui->now->text() == mm)
        {
            Error("新密码不能和原始密码相同!");
            return;
        }

        QString sql = "update MANAGER set TPassword where TeacherNo='" + teacherNo + "'";
        QString up = selectDB(sql);
        if(up != WRONG)
        {
            Error(WRONG);
            return;
        }

        Error("更改密码成功!");

        ui->pushButton_2->setText("修改密码");
        tf = true;
    }
}
Пример #3
0
int main()
{
    //insertDB();
    insertStmt();
    selectDB();

    std::cout << "bool:" << std::is_fundamental<bool>::value << "\n";
    std::cout << "short:" << std::is_fundamental<short>::value << "\n";
    std::cout << "int:" << std::is_fundamental<int>::value << "\n";
    std::cout << "double:" << std::is_fundamental<double>::value << "\n";
    std::cout << "long:" << std::is_fundamental<long>::value << "\n";
    std::cout << "long long:" << std::is_fundamental<long long>::value << "\n";

    std::cout << "unsigned:" << std::is_fundamental<unsigned int>::value << "\n";
    std::cout << "unsigned long:" << std::is_fundamental<unsigned long>::value << "\n";
    std::cout << "unsigned long long:" << std::is_fundamental<unsigned long long>::value << "\n";

    std::cout << "int*:" << std::is_fundamental<int*>::value << "\n";
    std::cout << "const char*:" << std::is_fundamental<const char*>::value << "\n";
    return 0;
}
void ManagerMessage::on_pushButton_clicked()        //修改基本信息
{
    if(MS)
    {
        static bool tf = true;
        if(tf)
        {
            if(super)       //超级管理员
            {
                ui->no->setEnabled(true);
                ui->major->setEnabled(true);
            }
            ui->name->setEnabled(true);
            ui->email->setEnabled(true);
            ui->pushButton->setText("保存信息");

            tf = false;
        }
        else
        {
            if(ui->no->text().isEmpty() || ui->name->text().isEmpty() || ui->email->text().isEmpty())
            {
                Error("请完善信息!");
                return;
            }

            if(super)
            {
                //判断当前工号是否存在
                if(ui->no->text().trimmed() != teacherNo)
                {
                    QString sql1 = "select TName from MANAGER where TeacherNo='" + ui->no->text() + "'";
                    QString name = selectDB(sql1);
                    if(name != WRONG)
                    {
                        Error("当前工号已存在!");
                        return;
                    }
                }

                //删除原记录
                QString sql = "delete from MANAGER where TeacherNo='" + teacherNo + "'";
                QString del = selectDB(sql);
                if(del != WRONG)
                {
                    Error(WRONG);
                    return;
                }

                QString sql2 = "insert into MANAGER(TeacherNo, TPassword, TName, TEmail, TMajor, TManager, TSuperManager) values(?,?,?,?,?,?,?)";
                if(InsertDB(sql2, NULL))
                {
                    Error("保存成功!");
                }
                else
                {
                    Error(WRONG);
                    return;
                }

                ui->no->setEnabled(false);
                ui->major->setEnabled(false);
            }
            else
            {
                QString sql = tr("update MANAGER set TName='%1', TEmail='%2' where TeacherNo='%3'").arg(ui->name->text().trimmed()).arg(ui->email->text().trimmed()).arg(ui->no->text().trimmed());
                QString up = selectDB(sql);
                if(up != WRONG)
                {
                    Error(WRONG);
                    return;
                }

                Error("保存成功!");
            }

            ui->name->setEnabled(false);
            ui->email->setEnabled(false);
            ui->pushButton->setText("修改基本信息");
            tf = true;
        }
    }
    else
    {
        if(ui->no->text().isEmpty() || ui->name->text().isEmpty() || ui->email->text().isEmpty())
        {
            Error("请完善信息!");
            add = false;
            return;
        }

        QString sql2 = "insert into MANAGER(TeacherNo, TPassword, TName, TEmail, TMajor, TManager, TSuperManager) values(?,?,?,?,?,?,?)";
        if(InsertDB(sql2, "ADD"))
        {
            Error(tr("新增成功!默认密码%1").arg("csl123456"));
            add = true;
        }
        else
        {
            Error(WRONG);
            false;
            return;
        }

        this->close();
    }
}
bool ManagerMessage::eventFilter(QObject *watched, QEvent *event)
{
    if (watched == ui->email)   //邮箱输入框
    {
        if(event->type() == QEvent::FocusOut)
        {
            if(ui->email->text().isEmpty())
            {
                Error("邮箱不能为空");
                return false;
            }
            else
            {
                QString email = ui->email->text().trimmed();
                QRegExp reg("^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$");
                if(reg.exactMatch(email))
                {
                    QString sql = "select SName from STUDENT where SEmail='"+email+"'";
                    QString tf = selectDB(sql);        //查询邮箱是否已存在
                    if(tf == WRONG)
                    {
                        QString sql1 = "select TName from MANAGER where TEmail='"+email+"'";
                        QString tf = selectDB(sql1);        //查询邮箱是否已存在
                        if(tf == WRONG)
                        {
                            return true;
                        }
                        else
                        {
                            Error("邮件已注册");
                            return false;
                        }
                    }
                    else
                    {
                        Error("邮件已注册");
                        return false;
                    }
                }
                else
                {
                    Error("邮件地址格式错误");
                    return false;
                }
            }
        }
    }
    else if(watched == ui->no)
    {
        if(event->type() == QEvent::FocusOut)
        {
            if(!MS)
            {
                QString sql1 = "select TName from MANAGER where TeacherNo='" + ui->no->text() + "'";
                QString name = selectDB(sql1);
                if(name != WRONG)
                {
                    Error("当前工号已存在!");
                    ui->no->setFocus();
                    return false;
                }
            }
        }
    }

    return QWidget::eventFilter(watched,event);     // 最后将事件交给上层对话框
}