private void sqlite_database_creation()
{
//--lets do try catch
try
{
//--This is where we are going to create all the database and tables of sqlite
string databasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string databaseFile = databasePath + @"\db_psychrometric_project.s3db";
//--new database file
SQLiteConnection.CreateFile(databaseFile);
//--now lets create the tables
SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=" + databaseFile + ";Version=3;");
m_dbConnection.Open();
//--building location table : tbl_building_location
//--This one is with the zip code later zip code is removed
//string sql = "create table tbl_building_location (selection int,ID INTEGER PRIMARY KEY AUTOINCREMENT ,country varchar(255),state varchar(255),city varchar(255),street varchar(255), ZIP int,longitude varchar(255),latitude varchar(255),elevation varchar(255),BuildingName varchar(255),EngineeringUnits varchar(255))";
string sql = "create table tbl_building_location (selection int,ID INTEGER PRIMARY KEY AUTOINCREMENT ,country varchar(255),state varchar(255),city varchar(255),street varchar(255) ,longitude varchar(255),latitude varchar(255),elevation varchar(255),BuildingName varchar(255),EngineeringUnits varchar(255))";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
//--next table geo location value : tbl_geo_location_value
//string sql1 = "create table tbl_geo_location_value (ID int ,longitude varchar(255),latitude varchar(255),elevation varchar(255))";
//SQLiteCommand command1 = new SQLiteCommand(sql1, m_dbConnection);
//command1.ExecuteNonQuery();
//--next table historical data:tbl_historical_data
string sql2 = "create table tbl_historical_data (ID INTEGER,date_current datetime,hour_current int,minute_current int,distance_from_building varchar(255),temperature varchar(255),humidity varchar(255),bar_pressure varchar(255),wind varchar(255),direction varchar(255),station_name varchar(255))";
SQLiteCommand command2 = new SQLiteCommand(sql2, m_dbConnection);
command2.ExecuteNonQuery();
//--next table tbl_temp_himidity
//string sql3 = "create table tbl_temp_humidity (temp int,humidity int)";
//SQLiteCommand command3 = new SQLiteCommand(sql3, m_dbConnection);
//command3.ExecuteNonQuery();
string sql3 = "create table tbl_language_option (ID int, language_id int)";
SQLiteCommand command3 = new SQLiteCommand(sql3, m_dbConnection);
command3.ExecuteNonQuery();
////--next table weather related datas...
string sql4 = "create table tbl_weather_related_values (ID INTEGER ,location varchar(255),distance_from_building varchar(255),last_update_date varchar(255),temp varchar(255),humidity varchar(255),bar_pressure varchar(255),wind varchar(255),direction varchar(255),station_name varchar(255))";
SQLiteCommand command4 = new SQLiteCommand(sql4, m_dbConnection);
command4.ExecuteNonQuery();
//--Lets input some values in the tbl_building_location and in tbl_language_option default
string sql_input1 = "INSERT INTO tbl_building_location (selection,country,state,city,street,BuildingName,EngineeringUnits) VALUES(1, 'china','SangHai','SangHai','No.35,yi yuan garden','Default_Building','SI') ";
SQLiteCommand commandINput5 = new SQLiteCommand(sql_input1, m_dbConnection);
commandINput5.ExecuteNonQuery();
//Adding to language option
string sql_input2 = "INSERT INTO tbl_language_option (ID,language_id) VALUES(1, 1) ";
string sql_input3 = "INSERT INTO tbl_language_option (ID,language_id) VALUES(2, 0) ";
string sql_input4 = "INSERT INTO tbl_language_option (ID,language_id) VALUES(3, 0) ";
SQLiteCommand c2 = new SQLiteCommand(sql_input2, m_dbConnection);
c2.ExecuteNonQuery();
SQLiteCommand c3 = new SQLiteCommand(sql_input3, m_dbConnection);
c3.ExecuteNonQuery();
SQLiteCommand c4 = new SQLiteCommand(sql_input4, m_dbConnection);
c4.ExecuteNonQuery();
m_dbConnection.Close();//--closing the connection
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}