int main()
{
	long day;
	ifstream input("diary.txt");
	ifstream ainput("pdshow.txt");
	ainput >> day;
	Diary diary;
	diary.show(day,input);
	return 0;
}
Пример #2
0
/*--------------------------------------------------------------------------*/
bool compareDiary(const Diary& first, const Diary& second)
{
    if (first.getID() < second.getID())
    {
        return true;
    }
    else
    {
        return false;
    }
}
int main(int argc,char* argv[])
{
	vector<Diary> my_diary;
	string str;
	Diary diary;
	Diary *p;
	string date;
	ifstream f_in(fpath);
	while (!f_in.eof())
	{
		getline(f_in,date);
		diary.SetDate(date);
		diary.Reset();
		string str;
		getline(f_in,str);
		while (str!=".")
		{
			diary.AddLine(str);
			getline(f_in,str);
		}
		my_diary.push_back(diary);
	}
	f_in.close();

	date=argv[1];
	vector<Diary>::size_type i,ii,Size;
	Size=my_diary.size();
	for (i=0;i<Size;i++)
		if (my_diary[i].GetDate()==date) break;
	if (i==Size)
		cout<<"There is not such a diary which date is "<<date<<"."<<endl;
	else
	{	for (ii=i;ii<Size-1;ii++)
			my_diary[ii] = my_diary[ii+1];
		my_diary.pop_back();
	

		ofstream f_out(fpath);
		for (i=0;i<my_diary.size();i++)
		{
			f_out<<my_diary[i].GetDate()<<endl;
			vector<string>::size_type j;
			for (j=0;j<my_diary[i].Size();j++)
				f_out<<my_diary[i].GetText(j)<<endl;
			f_out<<"."<<endl;
		}

		f_out.close();
		return 1;
	}
	return 0;
}
Пример #4
0
int main()
{	Diary	di;
	char	ch;
	cout << "I to insert an entry, S to show a week's entries:" << endl;
	while (cin >> ch)
	{	switch (ch)
		{	case 'I' : case 'i' : di.add_entry(); break;
			case 'S' : case 's' : di.show_week(); break;
			default : return 0;
		}
		cout << "I, S or Q to quit" << endl;
	}
}
void Register::on_pushButton_2_clicked()
{
    ui->label_7->setText("");
    ui->label_8->setText("");
    ui->label_9->setText("");
    ui->label_10->setText("");
    int error=0,pass=0;
    int uname=0,error_name=0,error_username=0,error_pass1=0,error_pass2=0;
    QString name = ui->lineEdit->text();
    QString username =ui->lineEdit_2->text();
    QString pass1 =ui->lineEdit_3->text();
    QString pass2 =ui->lineEdit_4->text();
    name=name.simplified();
    username=username.simplified();
    pass1=pass1.simplified();
    pass2=pass2.simplified();
    name=name.toUpper();
    username=username.toLower();


    QString count;
    QString uid;

    QDate date = ui->dateEdit->date();
    QString dob = date.toString("dd-MM-yyyy");


    QSqlQuery query;

        // ----------------- error = -1 --- used if any field is empty------with the distinct flag-----
    if(name=="")
       { error_name=1; error=-1;}
    if(username=="")
      {  error_username=1;error=-1;}
    if(pass1=="")
      {  error_pass1=1; error=-1;}
    if(pass2=="")
       { error_pass2=1; error=-1;}
    if(error==0)
    {       // ----------------------------All Fields Entered-------------------

        query.exec("select count(*) as counter from users where username = '******'");
        query.next();
        count=query.value(0).toString();

        if(count=="0")
       {    //QMessageBox::information(this,"Succesful","hmmm=0");
           uname=1;     //----------------Username available------------
       }
        else if ( count =="1")
           {// QMessageBox::information(this,"Failed","hmmm=1");
                error=1;        // --------------- error = 1 -----used for non availability of username----------
           }

    if(pass1==pass2)
     {   pass=1;  }       //----------------Passwords Matched------------
    else
      {  error=2;   }     // --------- error = 2 --------used for passwords not matching

    }
    // ----------------------------All Fields Entered-------------------

    if(error==-1)
    {
        if(error_name==1)
            ui->label_7->setText(tr("<font color=red>Enter The Name</font>"));
        if(error_username==1)
            ui->label_8->setText(tr("<font color=red>Enter The Username</font>"));
        if(error_pass1==1)
            ui->label_9->setText(tr("<font color=red>Enter The Password</font>"));
        if(error_pass2==1)
            ui->label_10->setText(tr("<font color=red>Re-Enter The Password</font>"));
    }
    else if(error==1)
        ui->label_8->setText(tr("<font color=red>Username Already Exists. Choose a different one.</font>"));
    else if(error==2)
        ui->label_10->setText(tr("<font color=red>Passwords Do Not Match</font>"));


    if(uname==1 && pass==1 && error==0) // -----------Register The Person -----------------
    {   int uno;
        query.exec("SELECT MAX(userid) as total FROM users");
        query.next();
        uid = query.value(0).toString();
        uno = uid.toInt();

        uno++;
        uid.setNum(uno);
       // QMessageBox::information(this,"USERID",uid);

        QString cur_year=QDate::currentDate().toString("yyyy");

        if ( query.exec("INSERT INTO users VALUES('"+uid+"','"+username+"','"+pass1+"','"+name+"','"+dob+"','"+cur_year+"')") )
        {

            QMessageBox::information(this,"Registered","You have succesfully created your diary.");
            Diary *user = new Diary(uid);
            user->show();
            this->close();
        }
        else
            QMessageBox::information(this,"Error","Your diary was not created because of database error.");


    }
}