mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Syncing uppdev
git-svn-id: svn://ultimatepp.org/upp/trunk@915 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
7c25490b2f
commit
35058c97fa
9 changed files with 315 additions and 2 deletions
24
uppdev/SqlProblem/SqlProblem.lay
Normal file
24
uppdev/SqlProblem/SqlProblem.lay
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
LAYOUT(SqlProblemLayout, 232, 228)
|
||||
ITEM(Button, openCommander, SetLabel(t_("SQL COMMANDER")).LeftPosZ(68, 96).TopPosZ(160, 28))
|
||||
ITEM(Button, openCompetiterButton, SetLabel(t_("COMPETITER")).LeftPosZ(68, 96).TopPosZ(40, 28))
|
||||
ITEM(Button, openClubsButton, SetLabel(t_("CLUBS")).LeftPosZ(68, 96).TopPosZ(88, 28))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(SaisieCompetiteursLayout, 400, 224)
|
||||
ITEM(EditString, name, LeftPosZ(68, 84).TopPosZ(84, 28))
|
||||
ITEM(Button, openClubsButton, SetLabel(t_("MODIFY CLUBS")).LeftPosZ(172, 92).TopPosZ(84, 28))
|
||||
ITEM(EditString, clubId, LeftPosZ(68, 84).TopPosZ(124, 28))
|
||||
ITEM(Label, dv___3, SetLabel(t_("Club ID")).LeftPosZ(8, 60).TopPosZ(124, 28))
|
||||
ITEM(Label, dv___4, SetLabel(t_("Name")).LeftPosZ(8, 58).TopPosZ(84, 28))
|
||||
ITEM(Button, ok, SetLabel(t_("OK")).LeftPosZ(232, 56).TopPosZ(184, 15))
|
||||
ITEM(Button, cancel, SetLabel(t_("CANCEL")).LeftPosZ(116, 56).TopPosZ(184, 15))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(ClubsLayout, 400, 256)
|
||||
ITEM(SqlArray, clubsList, LeftPosZ(216, 150).TopPosZ(12, 176))
|
||||
ITEM(EditString, city, LeftPosZ(68, 104).TopPosZ(56, 28))
|
||||
ITEM(Label, dv___2, SetLabel(t_("City")).LeftPosZ(8, 58).TopPosZ(56, 24))
|
||||
ITEM(Button, ok, SetLabel(t_("OK")).LeftPosZ(236, 56).TopPosZ(220, 15))
|
||||
ITEM(Button, cancel, SetLabel(t_("CANCEL")).LeftPosZ(120, 56).TopPosZ(220, 15))
|
||||
END_LAYOUT
|
||||
|
||||
14
uppdev/SqlProblem/SqlProblem.upp
Normal file
14
uppdev/SqlProblem/SqlProblem.upp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
uses
|
||||
CtrlLib,
|
||||
Sql,
|
||||
SqlCtrl,
|
||||
plugin/sqlite3;
|
||||
|
||||
file
|
||||
mysql.sch,
|
||||
main.cpp,
|
||||
SqlProblem.lay;
|
||||
|
||||
mainconfig
|
||||
"" = "GUI";
|
||||
|
||||
7
uppdev/SqlProblem/init
Normal file
7
uppdev/SqlProblem/init
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#ifndef _SqlProblem_icpp_init_stub
|
||||
#define _SqlProblem_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "Sql/init"
|
||||
#include "SqlCtrl/init"
|
||||
#include "plugin/sqlite3/init"
|
||||
#endif
|
||||
176
uppdev/SqlProblem/main.cpp
Normal file
176
uppdev/SqlProblem/main.cpp
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
#include <SqlCtrl/SqlCtrl.h>
|
||||
#include <plugin/sqlite3/Sqlite3.h>
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define LAYOUTFILE <SqlProblem/SqlProblem.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
|
||||
#define MODEL <SqlProblem/mysql.sch>
|
||||
#include "Sql/sch_header.h"
|
||||
|
||||
|
||||
|
||||
#include <Sql/sch_schema.h>
|
||||
#include <Sql/sch_source.h>
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
class ClubsDlg : public WithClubsLayout<TopWindow> {
|
||||
typedef ClubsDlg CLASSNAME;
|
||||
|
||||
public:
|
||||
ClubsDlg()
|
||||
{
|
||||
CtrlLayoutOKCancel(*this, "");
|
||||
clubsList.SetTable(CLUBS);
|
||||
clubsList.AddKey(CLUB_ID);
|
||||
clubsList.AddColumn(CLUB_NAME, "NAME");
|
||||
clubsList.AddCtrl(CLUB_CITY, city);
|
||||
clubsList.Query();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// ==========================================================
|
||||
class CompetiteurDlg : public WithSaisieCompetiteursLayout<TopWindow> {
|
||||
public:
|
||||
typedef CompetiteurDlg CLASSNAME;
|
||||
SqlCtrls ctrls;
|
||||
|
||||
public:
|
||||
CompetiteurDlg()
|
||||
{
|
||||
CtrlLayoutOKCancel(*this, "Competiteurs");
|
||||
ctrls(COMPH_NAME, name) (COMPH_REF_CLUB_ID, clubId);
|
||||
openClubsButton << THISBACK(openClubs);
|
||||
}
|
||||
|
||||
void openClubs()
|
||||
{
|
||||
ClubsDlg dlg;
|
||||
dlg.Run();
|
||||
}
|
||||
};
|
||||
|
||||
// ==========================================================
|
||||
class SqlProblem : public WithSqlProblemLayout<TopWindow> {
|
||||
public:
|
||||
typedef SqlProblem CLASSNAME;
|
||||
SqlProblem()
|
||||
{
|
||||
CtrlLayout(*this, "Window title");
|
||||
openCompetiterButton << THISBACK(openCompetiter);
|
||||
openClubsButton << THISBACK(openClubs);
|
||||
openCommander << callback(SQLCommander);
|
||||
}
|
||||
|
||||
void openCompetiter()
|
||||
{
|
||||
CompetiteurDlg dlg;
|
||||
Sql sql;
|
||||
sql * Select( dlg.ctrls ).From(COMPETITERS).Where(COMPH_ID == 1);
|
||||
if (dlg.ctrls.Fetch(sql))
|
||||
{
|
||||
dlg.RunAppModal();
|
||||
}
|
||||
}
|
||||
|
||||
void openClubs()
|
||||
{
|
||||
ClubsDlg dlg;
|
||||
dlg.Run();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// ==========================================================
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
SQL;
|
||||
Sqlite3Session sqlite3;
|
||||
sqlite3.SetTrace();
|
||||
|
||||
// DATA BASE
|
||||
// Gestion de la DB
|
||||
String statsusMsg = "Ouverture de la base de donnees";
|
||||
//statusBar.Set(statsusMsg);
|
||||
if(!sqlite3.Open(ConfigFile("FNPSA.db"))) {
|
||||
Exclamation("Can't create or open database file\n");
|
||||
return;
|
||||
}
|
||||
SQL = sqlite3;
|
||||
|
||||
// if DB is empty ==> create structure
|
||||
{
|
||||
Vector<String> table_list = sqlite3.EnumTables("");
|
||||
if (table_list.GetCount() == 0)
|
||||
{
|
||||
statsusMsg = "Initialisation de la base de donnees en cours ...";
|
||||
//statusBar.Set(statsusMsg);
|
||||
|
||||
// Update the schema to match the schema described in MODEL
|
||||
SqlSchema sch(SQLITE3);
|
||||
StdStatementExecutor se(sqlite3);
|
||||
All_Tables(sch);
|
||||
if(sch.ScriptChanged(SqlSchema::UPGRADE))
|
||||
Sqlite3PerformScript(sch.Upgrade(),se);
|
||||
if(sch.ScriptChanged(SqlSchema::ATTRIBUTES)) {
|
||||
Sqlite3PerformScript(sch.Attributes(),se);
|
||||
}
|
||||
if(sch.ScriptChanged(SqlSchema::CONFIG)) {
|
||||
Sqlite3PerformScript(sch.ConfigDrop(),se);
|
||||
Sqlite3PerformScript(sch.Config(),se);
|
||||
}
|
||||
sch.SaveNormal();
|
||||
|
||||
statsusMsg = "Initialisation de la base de donnees termin<69>e";
|
||||
//statusBar.Set(statsusMsg);
|
||||
}
|
||||
}
|
||||
{
|
||||
// Get the list of tables
|
||||
Vector<String> table_list = sqlite3.EnumTables("");
|
||||
std::cout << "Tables: " << table_list.GetCount() << std::flush;
|
||||
LOG(Format("Tables: (%d)",table_list.GetCount()));
|
||||
for (int i = 0; i < table_list.GetCount(); ++i)
|
||||
LOG(Format(" #%d: %s",i+1,table_list[i]));
|
||||
}
|
||||
|
||||
|
||||
Sql sql(sqlite3);
|
||||
sql.ClearError();
|
||||
|
||||
#define NEW_DB
|
||||
#ifdef NEW_DB
|
||||
|
||||
sql.Begin();
|
||||
sql * Delete(CLUBS);
|
||||
sql * Delete(COMPETITERS);
|
||||
|
||||
sql * Insert(CLUBS) (CLUB_NAME,"CLUB 1") (CLUB_CITY,"NY");
|
||||
sql * Insert(CLUBS) (CLUB_NAME,"CLUB 2") (CLUB_CITY,"PARIS");
|
||||
sql * Insert(CLUBS) (CLUB_NAME,"CLUB 3") (CLUB_CITY,"ROME");
|
||||
sql * Insert(CLUBS) (CLUB_NAME,"CLUB 4") (CLUB_CITY,"LONDON");
|
||||
|
||||
sql * Insert(COMPETITERS) (COMPH_REF_CLUB_ID, 1)(COMPH_NAME, "Didier");
|
||||
sql * Insert(COMPETITERS) (COMPH_REF_CLUB_ID, 1)(COMPH_NAME, "Alex");
|
||||
sql * Insert(COMPETITERS) (COMPH_REF_CLUB_ID, 2)(COMPH_NAME, "Mathieu");
|
||||
sql * Insert(COMPETITERS) (COMPH_REF_CLUB_ID, 2)(COMPH_NAME, "Fred");
|
||||
|
||||
// enregistrement de la DB
|
||||
sql.Commit();
|
||||
|
||||
#endif
|
||||
// ======================== COMPETITION ==========================
|
||||
|
||||
SqlProblem().Run();
|
||||
|
||||
}
|
||||
|
||||
12
uppdev/SqlProblem/mysql.sch
Normal file
12
uppdev/SqlProblem/mysql.sch
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
TABLE_(CLUBS)
|
||||
INT_ (CLUB_ID) PRIMARY_KEY AUTO_INCREMENT
|
||||
STRING_ (CLUB_NAME, 30)
|
||||
STRING_ (CLUB_CITY, 30)
|
||||
END_TABLE
|
||||
|
||||
TABLE_(COMPETITERS)
|
||||
INT_ (COMPH_ID) PRIMARY_KEY AUTO_INCREMENT
|
||||
INT_ (COMPH_REF_CLUB_ID) REFERENCES(CLUBS)
|
||||
STRING_ (COMPH_NAME, 30) INDEX
|
||||
END_TABLE
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue