[go: up one dir, main page]

Menu

[ceb706]: / database.cpp  Maximize  Restore  History

Download this file

768 lines (652 with data), 27.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
/****************************************************************************
// mtafsir Copyright (C) 2012 yahia nouah <yahiaui@gmail.com>
//
// This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
// This is free software, and you are welcome to redistribute it
// under certain conditions; type `show c' for details.
//
// The hypothetical commands `show w' and `show c' should show the appropriate
// parts of the General Public License. Of course, your program's commands
// might be different; for a GUI interface, you would use an "about box".
//
// You should also get your employer (if you work as a programmer) or school,
// if any, to sign a "copyright disclaimer" for the program, if necessary.
// For more information on this, and how to apply and follow the GNU GPL, see
// <http://www.gnu.org/licenses/>.
//
// The GNU General Public License does not permit incorporating your program
// into proprietary programs. If your program is a subroutine library, you
// may consider it more useful to permit linking proprietary applications with
// the library. If this is what you want to do, use the GNU Lesser General
// Public License instead of this License. But first, please read
// <http://www.gnu.org/philosophy/why-not-lgpl.html>.
// ----------------------------------------------------------
** If you have questions regarding the use of this file, please contact
** yahia nouah (yahiaui@gmail.com)
** $mtafsir_END_LICENSE$
**
****************************************************************************/
#include "database.h"
//#include <QtGui>
//#include <QObject>
#include <QSqlDatabase>
#include <QSqlTableModel>
#include <QSqlRecord>
#include <QSqlQuery>
//#include <QDomDocument>
#include <QFile>
#include <QXmlStreamReader>
#include <QTextStream>
#include <QFileInfo>
#include <QApplication>
#include <QDebug>
#include <QMessageBox>
#include <QDir>
#include <QAction>
#include <QSqlError>
#include <QTextDocument>
#include <QTextCursor>
Database::Database()
{
QDir appDir(qApp->applicationDirPath());
#if defined(Q_OS_WIN)
appDir.cdUp();
appPath= appDir.absolutePath()+"/share/mtafsir";
#elif defined(Q_OS_MAC)
if (appDir.dirName() == "MacOS") {
appDir.cdUp();
appDir.cdUp();
appDir.cdUp();
appPath= appDir.absolutePath()+"/mtafsir";
}
#else
appDir.cdUp();
appPath= appDir.absolutePath()+"/share/mtafsir";
// qDebug()<<appPath;
#endif
db = QSqlDatabase::addDatabase("QSQLITE");
}
void Database::treeChargeSoura(QTreeWidget *view,QComboBox *combo)
{
if(openQuranDb(false)==false)
return;
QLocale lc(QLocale::Arabic);
lc.setNumberOptions(QLocale::OmitGroupSeparator);
QString querytxt;
querytxt=QString("SELECT* FROM sura_info ORDER BY id");
QSqlQuery query(querytxt,db);
while (query.next()) {
int fieldId= query.record().indexOf("id");
QString myid= query.value(fieldId).toString();
int fieldTxt= query.record().indexOf("sura");
QString mytext = query.value(fieldTxt).toString();
int fieldPos= query.record().indexOf("pos");
QString mypos= query.value(fieldPos).toString();
int fieldAyats= query.record().indexOf("ayats");
QString ayatscount= query.value(fieldAyats).toString();
QString suratext=lc.toString(myid.toInt())+"-"+mytext;
QTreeWidgetItem *item=new QTreeWidgetItem(view);
item->setText(0,suratext);
item->setText(1,mypos);
combo->addItem(suratext,mypos+","+ayatscount);
}
//-----
query.clear();
querytxt=QString("SELECT* FROM quran ORDER BY id");
query.exec(querytxt);
while (query.next()) {
int fieldId= query.record().indexOf("id");
QString myid= query.value(fieldId).toString();
int fieldTxt= query.record().indexOf("text");
QString mytext = query.value(fieldTxt).toString();
int fieldSura= query.record().indexOf("sura");
QString mysura= query.value(fieldSura).toString();
int fieldAya= query.record().indexOf("aya");
QString myaya= query.value(fieldAya).toString();
int fieldnass_safy= query.record().indexOf("nass_safy");
QString mynass_safy= query.value(fieldnass_safy).toString();
QTreeWidgetItem *item=new QTreeWidgetItem(view->topLevelItem(mysura.toInt()-1));
item->setText(0,lc.toString(myaya.toInt())+"-"+mynass_safy);
item->setData(0,Qt::UserRole,myaya);
item->setText(1,myid);
item->setText(2,mytext );
}
}
//! تحميل الاجزاء والارباع والاحزاب في الشجرة
void Database::treeChargeJozaa(QTreeWidget *view)
{
//-------------------------------------------
QTreeWidgetItem *item=new QTreeWidgetItem(view) ;
QTreeWidgetItem *osloItem=new QTreeWidgetItem(item) ;
QTreeWidgetItem *osloItem2 ;
QFile file(appPath+"/ajzaa.xml");
// qDebug()<<appPath+"/ajzaa.xml";
file.open(QIODevice::ReadOnly);
view->clear();
QXmlStreamReader xml;
xml.setDevice(&file);
int nJoz=0;
int nHizb=0;
int nRob=0;
QString idjoza;
QString idhizb;
QString idhrobaa;
while (!xml.atEnd()) {
xml.readNext();
if (xml.name() == "root"){
idjoza= xml.attributes().value("id").toString();
QString textjoza=xml.attributes().value("Name").toString();
//QString id= creatIndex(idjoza);
if(!textjoza.isNull()){
nJoz++;
item= new QTreeWidgetItem(view);
item->setText(0,QString::number(nJoz)+"-"+textjoza );
// item->setData(1,1,idjoza);
item->setText(1,idjoza );
}
}else if (xml.name() == "Item"){
idhizb= xml.attributes().value("id").toString();
QString texthizb= xml.attributes().value("Name").toString();
//QString id= creatIndex(idhizb);
if(!texthizb.isNull()){
nHizb++;
osloItem= new QTreeWidgetItem(item);
osloItem->setText(0,QString::number(nHizb)+"-"+texthizb );
// osloItem->setData(1,1,idhizb);
osloItem->setText(1,idhizb);
}
}else if (xml.name() == "bk"){
idhrobaa= xml.attributes().value("id").toString();
QString textrobaa= xml.attributes().value("name").toString();
// QString id= creatIndex(idhrobaa);
if(!textrobaa.isNull()){
nRob++;
if(nRob==5){
nRob=1;
}
osloItem2= new QTreeWidgetItem(osloItem);
osloItem2->setText(0,QString::number(nRob)+"-"+textrobaa );
// osloItem2->setData(1,1,idhrobaa);
osloItem2->setText(1,idhrobaa );
}
}
}
xml.clear();
file.close();
// fileReciter.close();
}
//! فتح قاعدة بيانات القرءان الكريم
bool Database:: openQuranDb(bool debug)
{
db.setDatabaseName(appPath+"/quran.db");
QString txt="no database";
if(!db.open()){
txt=db.lastError().text();
if(debug==false){
QMessageBox::information(0,"error",txt);
}else{
qDebug()<<txt;
}
return false;
}
return true;
}
//! فتح قاعدة البيانات
void Database::openDb(QString dataName)
{
qDebug()<<dataName;
databaseName=dataName;
QFileInfo fi(dataName);
tableName = fi.completeBaseName();
db.setDatabaseName(dataName);
QString txt="no database";
if(!db.open()){
txt=db.lastError().text();
QMessageBox::information(0,"",txt);
}
}
//! جلب التفسير
QString Database::getTranslation(int pos)
{
QString querytxt=QString("SELECT* FROM %1 WHERE id=%2 ORDER BY id").arg(tableName).arg(QString::number(pos));
QSqlQuery query(querytxt,db);
if(query.lastError().isValid()){
qDebug()<<query.lastError();
// QMessageBox::information(0,"",query.lastError().text());
return query.lastError().text();
}
query.next();
int fieldNo = query.record().indexOf("text");
if (fieldNo==-1){
fieldNo = query.record().indexOf("tafsir");
}
QString mytext = query.value(fieldNo).toString();
query.next();
qDebug()<<mytext;
return mytext;
}
//! [1] البحث في الشجرة
void Database::searchInTreeview(QTreeWidget *view,QString searchString,int colum,bool hamza)
{
for( int i = 0; i <view->topLevelItemCount(); i++ ) {
view->topLevelItem(i)->setHidden(false );
showAllItems(view->topLevelItem(i),view);
}
if (!searchString.isEmpty()){
for( int i = 0; i <view->topLevelItemCount(); i++ ) {
searchTreeForString(searchString,view->topLevelItem(i),true,i,view,colum,hamza) ;
}
}
}
//! [2] البحث في الشجرة
bool Database::searchTreeForString(const QString &searchString, QTreeWidgetItem* parent
, bool itemtop, int topindex, QTreeWidget *view, int colum, bool hamza)
{
int hiddenCount = 0;
int hiddenparent=0;
if (parent->childCount()==0 && !parent->text(colum).contains( searchString, Qt::CaseInsensitive )) {
parent->setHidden(true);
}
for( int i = 0; i < parent->childCount(); ++i) {
QTreeWidgetItem *child = parent->child(i);
QString txtChild=child->text(colum);
if(hamza==true){
txtChild.replace(trUtf8("أ"),trUtf8("ا"));
txtChild.replace(trUtf8("إ"),trUtf8("ا"));
txtChild.replace(trUtf8("ؤ"),trUtf8("و"));
// txtChild.replace(trUtf8("ئ"),trUtf8(""));
}
if( parent->isHidden() )
hiddenCount++;
else if(child->childCount()>0
&& !txtChild.contains( searchString, Qt::CaseInsensitive ) ) {//لا يحمل النص وله ابناء
if( !searchTreeForString( searchString, child ,false,topindex,view,colum,hamza)) {
child->setHidden(true);
hiddenCount++;
}
} else if(child->childCount()>0// يحمل النص له ابناء
&& ( txtChild.contains( searchString, Qt::CaseInsensitive ) ) ){
searchTreeForString( searchString, child ,false,topindex,view,colum,hamza);
} else if(child->childCount()==0//لا يحمل النص وليس له ابناء
&& ( !txtChild.contains( searchString, Qt::CaseInsensitive ) ) ) {
child->setHidden(true);
hiddenCount++;
}
if (itemtop==true){
if(child->isHidden()){hiddenparent++;}
}
}
QTreeWidgetItem *toplevel=view->topLevelItem(topindex);
int topc=toplevel->childCount();
QString txtTop=toplevel->text(colum);
if(hamza==true){
txtTop.replace(trUtf8("أ"),trUtf8("ا"));
txtTop.replace(trUtf8("إ"),trUtf8("ا"));
txtTop.replace(trUtf8("ؤ"),trUtf8("و"));
}
if( hiddenparent == topc && !txtTop.contains( searchString, Qt::CaseInsensitive )){
toplevel->setHidden(true);
}
if( hiddenCount == parent->childCount() )
return false;
return true;
}
//! [3] البحث في الشجرة
bool Database::showAllItems( QTreeWidgetItem* parent,QTreeWidget *view )
{
for( int i = 0; i < parent->childCount(); i++ ) {
view->setItemHidden(parent->child(i),false);
showAllItems( parent->child( i) ,view);
}
return true;
}
//--------------------------------search- treeview------------------------------
//---------------------------------search --------------------
//! البحث في القرءان الكريم
void Database::searchInQuran(QTreeWidget *view,QString arg1,QString arg2,QString orAnd ,int option)
{
if(openQuranDb(false)==false)
return;
//-----------------------
QString querytxt;
if(option==3){
querytxt=QString("SELECT* FROM quran WHERE nass_safy like '%%1%' %2 nass_safy like'%%3%' ORDER BY id").arg(arg1).arg(orAnd).arg(arg2);
}else{
if(option==0){
querytxt=QString("SELECT* FROM quran WHERE nass_safy like '%%1%' ORDER BY id").arg(arg1);
}else if(option==1){
querytxt=QString("SELECT* FROM quran WHERE nass_safy like '%1%' ORDER BY id").arg(arg1);
}else if(option==2){
querytxt=QString("SELECT* FROM quran WHERE nass_safy like '%%1' ORDER BY id").arg(arg1);
}
}
QSqlQuery query(querytxt,db);
if(query.lastError().isValid()){
qDebug()<<query.lastError();
QMessageBox::information(0,"",query.lastError().text());
return ;
}
//query.next();
view->clear();
while (query.next()) {
int fieldId= query.record().indexOf("id");
QString myid= query.value(fieldId).toString();
int fieldTxt= query.record().indexOf("nass_safy");
QString mytext = query.value(fieldTxt).toString();
int fieldSura= query.record().indexOf("sura");
QString mysura= query.value(fieldSura).toString();
int fieldAya= query.record().indexOf("aya");
QString myaya= query.value(fieldAya).toString();
QTreeWidgetItem *item=new QTreeWidgetItem(view);
int fieldpage= query.record().indexOf("safha");
QString mypage= query.value(fieldpage).toString();
item->setText(0,mysura);
item->setText(1,myaya);
item->setText(2,mytext);
item->setText(3,myid);
// QMessageBox::information(0,"",mytext);
qDebug()<< mypage;
// query.next();
}
// int i=query.record().count();
// for (int r = 0; r < i; ++r) {
// qDebug()<< query.record().fieldName(r);
// }
openDb(databaseName);
}
//! البحث في التفاسير
void Database::searchInTefsir(QTreeWidget *view,QString arg1,QString arg2,QString orAnd ,int option)
{
QString querytxt;
if(option==3){
querytxt=QString("SELECT* FROM %4 WHERE text like '%%1%' %2 text like'%%3%' ORDER BY id")
.arg(arg1).arg(orAnd).arg(arg2).arg(tableName);
}else if(option==0){
querytxt=QString("SELECT* FROM %1 WHERE text like '%%2%' ORDER BY id").arg(tableName).arg(arg1);
}
QSqlQuery query(querytxt,db);
if(query.lastError().isValid()){
qDebug()<<query.lastError();
QMessageBox::information(0,"",query.lastError().text());
return ;
}
//query.next();
view->clear();
while (query.next()) {
int fieldId= query.record().indexOf("id");
QString myid= query.value(fieldId).toString();
int fieldSura= query.record().indexOf("sura");
QString mysura= query.value(fieldSura).toString();
int fieldAya= query.record().indexOf("aya");
QString myaya= query.value(fieldAya).toString();
QTreeWidgetItem *item=new QTreeWidgetItem(view);
item->setText(0,mysura);
item->setText(1,myaya);
item->setText(2,myid);
}
}
//! لبيحث في الصفحة
bool Database::searchInDoc(QTextDocument *document,QString searchString,QString searchString2,QColor color)
{
bool firstModified=false;
if (document->isModified()){
firstModified=true;
}
bool found = false;
// if (findMultiFind==false){
// chargelistStrToFind(searchString);
// }else{
// chargelistStrMultiFind(searchString);
// }
QStringList list;
list<<searchString<<searchString2;
for (int i=0;i<2;i++) {
QString findText=list.at(i);
if(!findText.isEmpty()){
QFont font= document->defaultFont();
// document->undo();
QTextCursor highlightCursor(document);
QTextCursor cursor(document);
cursor.beginEditBlock();
QTextCharFormat colorFormat(highlightCursor.charFormat());
colorFormat.setForeground(color);
colorFormat.setFont(font);
colorFormat.setFontPointSize(font.pointSize());
while (!highlightCursor.isNull() && !highlightCursor.atEnd()) {
highlightCursor = document->find(findText, highlightCursor, QTextDocument::FindCaseSensitively);
if (!highlightCursor.isNull()) {
found = true;
highlightCursor.movePosition(QTextCursor::Right,
QTextCursor::KeepAnchor,-1);
highlightCursor.mergeCharFormat(colorFormat);
}
}
cursor.endEditBlock();
}
}
if (found == false) {
return false;
}
document->setModified(firstModified);
return true;
}
QStringList Database::getQuranPage(int pos)
{
QStringList list;
if(openQuranDb(false)==false)
return list;
QString querytxt=QString("SELECT* FROM quran WHERE id=%1 ORDER BY id").arg(QString::number(pos));
QSqlQuery query(querytxt,db);
if(query.lastError().isValid()){
qDebug()<<query.lastError();
QMessageBox::information(0,"",query.lastError().text());
return list;
}
query.next();
int fieldpage= query.record().indexOf("safha");
QString mypage= query.value(fieldpage).toString();
list<<"page:"+mypage;
querytxt=QString("SELECT* FROM quran WHERE safha=%1 ORDER BY id").arg(mypage);
query.exec(querytxt);
while (query.next()) {
int fieldTxt= query.record().indexOf("text");
QString mytext = query.value(fieldTxt).toString();
int fieldAya= query.record().indexOf("aya");
QString myaya= query.value(fieldAya).toString();
int fieldsura= query.record().indexOf("sura");
QString mysura= query.value(fieldsura).toString();
int fieldid= query.record().indexOf("id");
QString myid= query.value(fieldid).toString();
list<<"sura:"+mysura<<"id:"+myid<<"aya:"+myaya<<mytext;
// QMessageBox::information(0,"",mytext);
qDebug()<< mypage<<mytext<<myaya;
// query.next();
}
openDb(databaseName);
return list;
}
QStringList Database::getQuranForPage(int page)
{
QStringList list;
if(openQuranDb(false)==false)
return list;
list<<"page:"+QString::number(page);
QString querytxt=QString("SELECT* FROM quran WHERE safha=%1 ORDER BY id").arg(QString::number(page));
QSqlQuery query(querytxt,db);
while (query.next()) {
int fieldTxt= query.record().indexOf("text");
QString mytext = query.value(fieldTxt).toString();
int fieldAya= query.record().indexOf("aya");
QString myaya= query.value(fieldAya).toString();
int fieldsura= query.record().indexOf("sura");
QString mysura= query.value(fieldsura).toString();
int fieldid= query.record().indexOf("id");
QString myid= query.value(fieldid).toString();
list<<"sura:"+mysura<<"id:"+myid<<"aya:"+myaya<<mytext;
// QMessageBox::information(0,"",mytext);
qDebug()<< page<<mytext<<myaya;
// query.next();
}
openDb(databaseName);
return list;
}
/*****************************************************************************
*********************************CMD*****************************************
******************************************************************************/
void Database::cmdGetTafsirName()
{
QFile file;
//-تحميل التفاسير
file.setFileName(appPath+"/tafasir/tafasirInfo");
if(file.open( QFile::ReadOnly)){
QTextStream textStream(&file);
// textStream.setCodec(QTextCodec::codecForName("UTF-8"));
QString line;
int id=0;
line = textStream.readLine();//premier line
while (!line.isNull()) {
id++;
QString txtdata=line.section(",",0,0);
QString txt=line.section(",",1,1);
qDebug()<<id<<" - "+txt<<" id= "<<txtdata;
line = textStream.readLine();
}
}
file.close();
}
void Database::cmdGetTranslation(int sura,int aya,const QString &tafsir)
{
if(sura<0||sura>114){
qDebug()<< trUtf8("لا توجد سورة بهذا الرقم")<<QString::number(sura);
return;
}
int aCount=cmdGetAyatNumber( sura,false);
if(aya<0||aya>aCount){
qDebug()<< trUtf8("لا توجد آية بهذا الرقم :")+QString::number(aya);
qDebug()<< trUtf8("عدد الايات في هذه السورة هو : ")+QString::number(aCount);
return;
}
//open data-----
QString dataName= appPath+"/tafasir/"+tafsir;
QFileInfo fi(dataName);
QString tName = fi.completeBaseName();
db.setDatabaseName(dataName);
QString txt="no database";
if(!db.open()){
txt=db.lastError().text();
qDebug()<<txt;
return;
}
//end open data-----
QString querytxt=QString("SELECT* FROM %1 WHERE sura='%2' and aya='%3' ORDER BY id")
.arg(tName).arg(QString::number(sura)).arg(QString::number(aya));
// QString querytxt=QString("SELECT* FROM %1 WHERE id=%2 ORDER BY id").arg(tName).arg(QString::number(pos));
QSqlQuery query(querytxt,db);
if(query.lastError().isValid()){
qDebug()<<query.lastError();
// QMessageBox::information(0,"",query.lastError().text());
return ;
}
query.next();
int fieldNo = query.record().indexOf("text");
if (fieldNo==-1){
fieldNo = query.record().indexOf("tafsir");
}
QString mytext = query.value(fieldNo).toString();
int fieldSura= query.record().indexOf("sura");
QString mysura= query.value(fieldSura).toString();
int fieldAya= query.record().indexOf("aya");
QString myaya= query.value(fieldAya).toString();
query.next();
qDebug()<<mytext;
qDebug()<<"sura "+mysura<<"aya "+myaya;
return ;
}
int Database::cmdGetAyatNumber(int sura,bool debug)
{
if(openQuranDb(true)==false)
return 0;
//-----------------------
QString querytxt=QString("SELECT* FROM sura_info WHERE id='%1' ORDER BY id").arg(QString::number(sura));
QSqlQuery query(querytxt,db);
query.first();
int fieldAya= query.record().indexOf("ayats");
QString myaya= query.value(fieldAya).toString();
int fieldsura= query.record().indexOf("sura");
QString mysura= query.value(fieldsura).toString();
if(debug==true)
qDebug()<<mysura+trUtf8(" عدد الايات : ")+myaya;
return myaya.toInt();
}
QString Database::cmdGetSuraName(int sura,bool debug)
{
if(openQuranDb(true)==false)
return 0;
//-----------------------
QString querytxt=QString("SELECT* FROM sura_info WHERE id='%1' ORDER BY id").arg(QString::number(sura));
QSqlQuery query(querytxt,db);
query.first();
int fieldsura= query.record().indexOf("sura");
QString mysura= query.value(fieldsura).toString();
if(debug==false)
openDb(databaseName);
qDebug()<<mysura;
return mysura;
}
void Database::cmdGetAyat(int sura,int aya)
{
if(sura<0||sura>114){
qDebug()<< trUtf8("لا توجد سورة بهذا الرقم")<<QString::number(sura);
return;
}
int aCount=cmdGetAyatNumber( sura,false);
if(aya<0||aya>aCount){
qDebug()<< trUtf8("لا توجد آية بهذا الرقم :")+QString::number(aya);
qDebug()<< trUtf8("عدد الايات في هذه السورة هو : ")+QString::number(aCount);
return;
}
//open data-----
if(openQuranDb(true)==false)
return;
//end open data-----
QString querytxt=QString("SELECT* FROM quran WHERE sura='%1' and aya ='%3' ORDER BY id").arg(QString::number(sura)).arg(QString::number(aya));
// QString querytxt=QString("SELECT* FROM %1 WHERE id=%2 ORDER BY id").arg(tName).arg(QString::number(pos));
QSqlQuery query(querytxt,db);
if(query.lastError().isValid()){
qDebug()<<query.lastError();
// QMessageBox::information(0,"",query.lastError().text());
return ;
}
query.next();
int fieldNo = query.record().indexOf("nass_safy");
QString mytext = query.value(fieldNo).toString();
int fieldSura= query.record().indexOf("sura");
QString mysura= query.value(fieldSura).toString();
int fieldAya= query.record().indexOf("aya");
QString myaya= query.value(fieldAya).toString();
query.next();
qDebug()<<mytext+"\n["+mysura<<" : "+myaya+"]";
return ;
}
void Database::cmdSearchInQuran(QString searchString )
{
//open data-----
if(openQuranDb(true)==false)
return;
//end open data-----
QString querytxt=QString("SELECT* FROM quran WHERE nass_safy like '%%1%' ORDER BY id").arg(searchString);
QSqlQuery query(querytxt,db);
if(query.lastError().isValid()){
qDebug()<<query.lastError();
return ;
}
while (query.next()) {
int fieldTxt= query.record().indexOf("nass_safy");
QString mytext = query.value(fieldTxt).toString();
int fieldSura= query.record().indexOf("sura");
QString mysura= query.value(fieldSura).toString();
int fieldAya= query.record().indexOf("aya");
QString myaya= query.value(fieldAya).toString();
qDebug()<< mysura+"-"+myaya+"("+mytext+")";
}
}