예제 #1
0
void MainWindow::on_pushButtonEsave_clicked()
{
    QString name = ui->lineEditEname->text().trimmed();
    QString gender = ui->comboBoxEgender->currentText().trimmed();
    QString phone = ui->lineEditEphone->text().trimmed();
    phone = phone.remove(" ");
    QString birthday = ui->dateEditEBirth->date().toString("yyyy-MM-dd");
    QString logdate = ui->dateEditEcurrent->date().toString("yyyy-MM-dd");

    if (!ui->tableViewDict->isHidden()) {
        ui->tableViewDict->hide();
    }

    QString pinyin = toChineseSpell(name);

    qDebug() << "name = " << pinyin;
    if (name.isEmpty()) {
        QMessageBox::information(this, "", "贤二,姓名不能为空滴啊!");
        return;
    }


    bool signStat = ifSignedToday(name, gender, phone, logdate);

    if (signStat) {
        QMessageBox::information(this, "", QString("嘿嘿,%1 %2 今天签到已经录进去啦,我们是一天签到一次哦!").arg(name).arg(phone));
        clearEdits();
        return;
    }

    updateDict(name, gender, phone, birthday);

    QString current = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");

    QSqlQuery query;
    query.exec(QString("insert into sign(name, gender, phone, birthday, logdate, current) values ('%1', '%2', '%3', '%4', '%5', '%6')").arg(name).arg(gender).arg(phone).arg(birthday).arg(logdate).arg(current));
    query.exec(QString("replace into pinyin(name, pinyin) values ('%1', '%2') ").arg(name).arg(pinyin));
    modelEdit->setFilter(QString("logdate = '%1'").arg(logdate));
    modelEdit->select();
    ui->tableViewSigns->reset();

    clearEdits();

}
예제 #2
0
bool compareNew()
{
	clearWindow(nppData._scintillaMainHandle, true);
	clearWindow(nppData._scintillaSecondHandle, true);
	
    active = true;

	int doc1Length;
	int *lineNum1;

	char **doc1 = getAllLines(nppData._scintillaMainHandle, &doc1Length, &lineNum1);

	if(doc1Length < 1)
    {
        return true;
    }

	int doc2Length;
	int *lineNum2;

	char **doc2 = getAllLines(nppData._scintillaSecondHandle, &doc2Length, &lineNum2);
	
    if(doc2Length < 1)
    {
        return true;
    }

	int	doc1Changed = 0;
	int	doc2Changed = 0;
	diff_edit *doc1Changes = NULL;
	diff_edit *doc2Changes = NULL;

	unsigned int *doc1Hashes = computeHashes(doc1, doc1Length, Settings.IncludeSpace);
	unsigned int *doc2Hashes = computeHashes(doc2, doc2Length, Settings.IncludeSpace);

	/* make diff */
	int sn;
	struct varray *ses = varray_new(sizeof(struct diff_edit), NULL);
	int result = (diff(doc1Hashes, 0, doc1Length, doc2Hashes, 0, doc2Length, (idx_fn)(getLineFromIndex), (cmp_fn)(compareLines), NULL, 0, ses, &sn, NULL));
	int changeOffset = 0;

    shift_boundries(ses, sn, doc1Hashes, doc2Hashes, doc1Length, doc2Length);
	find_moves(ses, sn, doc1Hashes, doc2Hashes, Settings.DetectMove);
	/* 
     * - insert empty lines
	 * - count changed lines
	 */
	doc1Changed = 0;
	doc2Changed = 0;

	for (int i = 0; i < sn; i++) 
    {
		struct diff_edit *e =(diff_edit*) varray_get(ses, i);
		if(e->op == DIFF_DELETE)
        {
			e->changeCount = 0;
			doc1Changed += e->len;
			struct diff_edit *e2 =(diff_edit*) varray_get(ses, i+1);
			e2->changeCount = 0;
			
            if(e2->op == DIFF_INSERT)
            {
				//see if the DELETE/INSERT COMBO includes changed lines or if its a completely new block
				if(compareWords(e, e2, doc1, doc2, Settings.IncludeSpace))
				{
					e->op = DIFF_CHANGE1;
					e2->op = DIFF_CHANGE2;
					doc2Changed += e2->len;
				}
			}
		}
        else if(e->op == DIFF_INSERT)
        {
			e->changeCount = 0;
			doc2Changed += e->len;
		}
	}

	int doc1CurrentChange = 0;
	int doc2CurrentChange = 0;
	changeOffset = 0;
	doc1Changes = new diff_edit[doc1Changed];
	doc2Changes = new diff_edit[doc2Changed];
	int doc1Offset = 0;
	int doc2Offset = 0;

	//switch from blocks of lines to one change per line. Change CHANGE to DELETE or INSERT if there are no changes on that line
	int added;

	for (int i = 0; i < sn; i++) 
    {
		struct diff_edit *e =(diff_edit*) varray_get(ses, i);
		e->set = i;

		switch(e->op)
        {
			case DIFF_CHANGE1:
			case DIFF_DELETE:
				added = setDiffLines(e, doc1Changes, &doc1CurrentChange, DIFF_DELETE, e->off + doc2Offset);
				doc2Offset -= added;
				doc1Offset += added;
				break;
			case DIFF_INSERT:
			case DIFF_CHANGE2:
				added = setDiffLines(e, doc2Changes, &doc2CurrentChange, DIFF_INSERT, e->off + doc1Offset);	
				doc1Offset -= added;
				doc2Offset += added;
				break;
		}
	}

	if (result != -1)
    {
		int textIndex;
		different = (doc1Changed > 0) || (doc2Changed > 0);
		
        for(int i = 0; i < doc1Changed; i++)
        {
			switch(doc1Changes[i].op)
            {
				case DIFF_DELETE:
					markAsRemoved(nppData._scintillaMainHandle, doc1Changes[i].off);					
					break;

				case DIFF_CHANGE1:
					markAsChanged(nppData._scintillaMainHandle, doc1Changes[i].off);
					textIndex = lineNum1[doc1Changes[i].off];

					for(int k = 0; k < doc1Changes[i].changeCount; k++)
                    {
						struct diff_change *change = (diff_change*)varray_get(doc1Changes[i].changes, k);
						markTextAsChanged(nppData._scintillaMainHandle, textIndex + change->off, change->len);
					}
					break;

				case DIFF_MOVE:					
					markAsMoved(nppData._scintillaMainHandle, doc1Changes[i].off);
					break;

			}
		}

		for(int i = 0; i < doc2Changed; i++)
        {
			switch(doc2Changes[i].op)
            {
				case DIFF_INSERT:					
					markAsAdded(nppData._scintillaSecondHandle, doc2Changes[i].off);						
					break;

				case DIFF_CHANGE2:
					markAsChanged(nppData._scintillaSecondHandle, doc2Changes[i].off);
					textIndex = lineNum2[doc2Changes[i].off];
					for(int k = 0; k < doc2Changes[i].changeCount; k++)
                    {
						struct diff_change *change=(diff_change*)varray_get(doc2Changes[i].changes, k);
						markTextAsChanged(nppData._scintillaSecondHandle, textIndex+change->off, change->len);
					}
					break;

				case DIFF_MOVE:					
					markAsMoved(nppData._scintillaSecondHandle,doc2Changes[i].off);										
					break;
			}
		}

		doc1Offset = 0;
		doc2Offset = 0;

		if(Settings.AddLine)
        {
			int length = 0;
			int off = -1;
			for(int i = 0; i < doc1Changed; i++)
            {
				switch(doc1Changes[i].op)
                {
					case DIFF_DELETE:
					case DIFF_MOVE:							
						if(doc1Changes[i].altLocation == off)
                        {
							length++;
						}
                        else
                        {
							addEmptyLines(nppData._scintillaSecondHandle, off + doc2Offset, length);
							doc2Offset += length;
							off = doc1Changes[i].altLocation;
							length = 1;						
						}
						break;
				}
			}

			addEmptyLines(nppData._scintillaSecondHandle, off + doc2Offset, length);

			if(doc2Offset > 0)
            {
				clearUndoBuffer(nppData._scintillaSecondHandle);
			}

			length = 0;
			off = 0;
			doc1Offset = 0;

			for(int i = 0; i < doc2Changed; i++)
            {
				switch(doc2Changes[i].op)
                {
					case DIFF_INSERT:
					case DIFF_MOVE:							
						if(doc2Changes[i].altLocation == off)
                        {
							length++;
						}
                        else
                        {
							addEmptyLines(nppData._scintillaMainHandle, off + doc1Offset, length);
							doc1Offset += length;
							off = doc2Changes[i].altLocation;
							length = 1;						
						}
						break;
				}
			}

			addEmptyLines(nppData._scintillaMainHandle, off + doc1Offset, length);

			if(doc1Offset > 0)
            {
				clearUndoBuffer(nppData._scintillaMainHandle);
			}
		}

//clean up resources
#if CLEANUP

		for(int i = 0; i < doc1Length; i++)
        {
			if(*doc1[i] != 0)
            {
				delete[] doc1[i];
			}
		}

		delete[] doc1;
		delete[] lineNum1;
		
        for(int i = 0; i < doc2Length; i++)
        {
			if(*doc2[i] != 0)
            {
				delete[] doc2[i];
			}
		}

		delete[] doc2;
		delete lineNum2;

		delete[] doc1Hashes;
		delete[] doc2Hashes;

		clearEdits(ses, sn);

		for(int i = 0; i < doc1Changed; i++)
        {
			clearEdit(doc1Changes + (i));
		}

		delete[] doc1Changes;

		for(int i = 0; i < doc2Changed; i++)
        {
			clearEdit(doc2Changes+(i));
		}

		delete[] doc2Changes;

#endif // CLEANUP

		if(!different)
        {
			::MessageBox(nppData._nppHandle, TEXT("Files Match"), TEXT("Results :"), MB_OK);
			return true;
		}

		::SendMessageA(nppData._scintillaMainHandle, SCI_SHOWLINES, 0, (LPARAM)1);
		::SendMessageA(nppData._scintillaSecondHandle, SCI_SHOWLINES, 0, (LPARAM)1);

		return false;
	}
    return false;
}