163 lines
5.3 KiB
C#
163 lines
5.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SQLite;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ADSUtileriasService.Helpers;
|
|
using ADSUtileriasService.Helpers.ADSSqlite;
|
|
|
|
namespace ADSUtileriasService.Conexion.Local.Estructura
|
|
{
|
|
|
|
static class SqlLitestructura
|
|
{
|
|
//public SqlLitestructura(SqlLiteBase bd)
|
|
//{
|
|
// switch (bd.BDType)
|
|
// {
|
|
// case SqlLiteConnectionEnum.AppConfig:
|
|
// break;
|
|
// case SqlLiteConnectionEnum.Empresa:
|
|
// EstructuraBDEmpresas(bd);
|
|
// break;
|
|
// default:
|
|
// break;
|
|
// }
|
|
//}
|
|
public static void EstructuraBDEmpresas(SqlLiteBase bd)
|
|
{
|
|
bool continuar = true;
|
|
bd.BeginTransaction();
|
|
int Version = -1;
|
|
int retorno;
|
|
StringBuilder strSQL = new StringBuilder();
|
|
try
|
|
{
|
|
bd.ClearCommand("SELECT * FROM Tversion");
|
|
using (SQLiteDataReader reader = bd.ExecuteReader())
|
|
{
|
|
if (reader.Read())
|
|
{
|
|
Version = reader.GetInt32(0);
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
if (Version == -1)
|
|
{
|
|
retorno = bd.RunExecuteNonQuery("CREATE TABLE Tversion (Version INT)");
|
|
retorno = bd.RunExecuteNonQuery("INSERT INTO Tversion (Version) VALUES(0)");
|
|
}
|
|
|
|
if (Version == -1)
|
|
{
|
|
strSQL.Clear();
|
|
#region "Gral_Proyecto"
|
|
strSQL.Append("CREATE TABLE [Gral_Proyecto] (");
|
|
strSQL.Append(" ROWID INTEGER primary key autoincrement,");
|
|
strSQL.Append(" [cveProyecto] INTEGER NULL,");
|
|
strSQL.Append(" [proyecto] TEXT NULL,");
|
|
strSQL.Append(" [CveEmpresa] INTEGER NULL,");
|
|
strSQL.Append(" [estatus] INT DEFAULT 0) ");
|
|
#endregion
|
|
if (continuar)
|
|
{
|
|
try
|
|
{
|
|
retorno = bd.RunExecuteNonQuery(strSQL.ToString());
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Mod.GuardaLog(e, "Estructura Local");
|
|
continuar = false;
|
|
}
|
|
}
|
|
strSQL.Clear();
|
|
#region "SubProyecto"
|
|
strSQL.Append("CREATE TABLE [Gral_SubProyecto] (");
|
|
strSQL.Append(" ROWID INTEGER primary key autoincrement,");
|
|
strSQL.Append(" [cveSubProyecto] INTEGER NULL,");
|
|
strSQL.Append(" [subProyecto] TEXT NULL,");
|
|
strSQL.Append(" [cveProyecto] INTEGER NULL,");
|
|
strSQL.Append(" [CveEmpresa] INTEGER NULL,");
|
|
strSQL.Append(" [estatus] INT DEFAULT 0) ");
|
|
#endregion
|
|
if (continuar)
|
|
{
|
|
try
|
|
{
|
|
retorno = bd.RunExecuteNonQuery(strSQL.ToString());
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Mod.GuardaLog(e, "Estructura Local");
|
|
continuar = false;
|
|
}
|
|
}
|
|
strSQL.Clear();
|
|
if (continuar)
|
|
{
|
|
try
|
|
{
|
|
retorno = bd.RunExecuteNonQuery(Conexion.Local.Estructura.RHTablas.Checador);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Mod.GuardaLog(e, "Estructura Local");
|
|
continuar = false;
|
|
}
|
|
}
|
|
if (continuar)
|
|
{
|
|
try
|
|
{
|
|
retorno = bd.RunExecuteNonQuery(Conexion.Local.Estructura.RHTablas.Personal);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Mod.GuardaLog(e, "Estructura Local");
|
|
continuar = false;
|
|
}
|
|
}
|
|
if (continuar)
|
|
{
|
|
try
|
|
{
|
|
retorno = bd.RunExecuteNonQuery(Conexion.Local.Estructura.RHTablas.RH_RegistroPersonalChecador);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Mod.GuardaLog(e, "Estructura Local");
|
|
continuar = false;
|
|
}
|
|
}
|
|
if (continuar)
|
|
{
|
|
try
|
|
{
|
|
retorno = bd.RunExecuteNonQuery("Update Tversion SET Version=1");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Mod.GuardaLog(e, "Estructura Local Version");
|
|
continuar = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (continuar)
|
|
{
|
|
bd.Commit();
|
|
}
|
|
else
|
|
{
|
|
bd.Rollback();
|
|
}
|
|
}
|
|
}
|
|
}
|