/// <summary> /// Method called during the creation of the model /// </summary> /// <param name="modelBuilder">DbModelBuilder</param> protected override void OnModelCreating(DbModelBuilder modelBuilder) { var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists <SqLiteContext>(modelBuilder); System.Data.Entity.Database.SetInitializer(sqliteConnectionInitializer); DataBaseUtils.CreateModel(modelBuilder, this); }
protected ViewModelBase() { try { DataContext = new PPTVDataContext(); _table = DataContext.GetTable <M>(); LoadFromDatabase(); } catch { DataBaseUtils.Delete(DataContext); } }
public PPTVDataContext() : base(DBConnectionString) { if (!_isLoaded) { lock (_lock) { if (!_isLoaded) { DataBaseUtils.CreateUpdate(this); _isLoaded = true; } } } }
public static IEnumerable GetDataFromDatabase() { DataBaseUtils dbConnector = new DataBaseUtils("localhost", "testdata", "root", "Gurgaon21!!"); dbConnector.OpenConnection(); string sqlQuery = "select * from test_product"; DataTable testData = dbConnector.ExecuteSelectSqlQuery(sqlQuery); dbConnector.CloseConnection(); foreach (DataRow row in testData.Rows) { yield return(new TestCaseData(row.ItemArray)); } }
/// <summary> /// Delete database tables that not part of the database /// and create the repositories for the entities /// </summary> /// <param name="context">The context</param> private void SeedDatabases(UniversalContext context) { List <string> tablesNames = new List <string>(); List <string> entitiesNames = new List <string>(); // Database name var dbname = context.DbSettings.DatabaseName; // Get all tables names List <EntitySet> dbTables = DataBaseUtils.GetTables(context); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { var entityTypes = assembly .GetTypes() .Where(t => t.GetCustomAttributes(typeof(PersistentAttribute), inherit: true) .Any()); foreach (var type in entityTypes) { // 1. Get the Persistance Attribute List <string> dbNames = DataBaseUtils.GetPersistanceAttribute(type); // Get table name var table = dbTables.Find(tb => tb.Name == type.Name); if (dbNames.Count > 0 && !dbNames.Contains(dbname) && table != null) { // Add table name into array tablesNames.Add(table.Table); entitiesNames.Add(type.Name); } else { // Create repo for each entity GenericUtils.CallMathodByReflection(typeof(UniversalContext), "Entity", type, context); } dbTables.Remove(table); } } // Delete mapping tables if (dbTables.Count > 0) { foreach (var fkTable in dbTables) { var entityNames = DataBaseUtils.SplitCamelCase(fkTable.Name); if (entityNames.Count == 2 && entitiesNames.Contains(entityNames[0]) && entitiesNames.Contains(entityNames[1])) { // suppression de la table tablesNames.Add(fkTable.Table); } } } // Delete tables if (tablesNames.Count > 0) { switch (context.DbSettings.Provider) { case ProviderType.MySQL: var tablesNamesStr = string.Join(",", tablesNames.ToArray()); context.Database.ExecuteSqlCommand("SET FOREIGN_KEY_CHECKS=0;DROP TABLE IF EXISTS " + tablesNamesStr + ";SET FOREIGN_KEY_CHECKS=1;"); break; case ProviderType.SQLite: foreach (var table in tablesNames) { context.Database.ExecuteSqlCommand("DROP TABLE IF EXISTS " + table); } break; } } }
public Result MakeChecking() { ErrorMessages.Clear(); var result = new Result() { ResultCode = ResultCode.Ok }; // Ping this._pingMsec = 0; try { using (Ping ping = new Ping()) { this._pingMsec = ping.Send(this.HostName).RoundtripTime; } } catch (Exception ex) { this._pingMsec = (int)ResultCode.CommonError; this.AddErrorMessage(ex, $"Ping of {this.HostName}"); } // Get IP try { this._ip = CommonUtils.GetIPAddressFromMachineName(this.HostName); } catch (Exception ex) { this.AddErrorMessage(ex, $"Getting IP of {this.HostName}"); } // Check Windows Services try { var servicesNames = OptionsHelper.GetWindowsServiceNamesToControl(this.HostName); if (servicesNames.Count != 0) { this.WindowsServicesStatus = ServicesControl.MakeChecking(this.HostName, servicesNames); } } catch (Exception ex) { this.AddErrorMessage(ex, $"Checking Windows Services of {this.HostName}"); } // Check disks status var disksInfo = new List <DiskDataModel>(); try { this.DisksData = DiskUtils.GetDrivesListOfRemoteMachine(this.HostName); } catch (Exception ex) { this.AddErrorMessage(ex, $"Checking disks status of {this.HostName} error"); } // Check Databases status this.IsNesseseryToCheckSqlBases = OptionsHelper.IsNessesaryToCheckDatabase(this.HostName); try { if (this.IsNesseseryToCheckSqlBases) { this.CheckingDatabaseResult = DataBaseUtils.CheckBases(this.HostName); if (!string.IsNullOrEmpty(this.CheckingDatabaseResult.ErrorMessage)) { this.AddErrorMessage(null, this.CheckingDatabaseResult.ErrorMessage); } } } catch (Exception ex) { this.AddErrorMessage(ex, $"Checking databases status of {this.HostName} error"); } return(result); }
/// <summary> /// Method called during the model creation /// </summary> /// <param name="modelBuilder">DbModelBuilder</param> protected override void OnModelCreating(DbModelBuilder modelBuilder) { DataBaseUtils.CreateModel(modelBuilder, this); }
static void Main(string[] args) { DataBaseUtils dbConnector = new DataBaseUtils("localhost", "testdata", "root", "Gurgaon21!!"); }
public override object GetData(int actionType) { //return base.GetData(actionType); ResponseObj = new TransObj(); StringBuilder sql; ExcelLoader exLoader; string path; int cat, i = 0; try { switch ((ActionType)actionType) { case ActionType.GetCatalog: #region GetCatalog GeneralController catController = new CatalogsController(); //cat = int.Parse(RequestObj.TransParms.Where(p => p.Key == "cat").FirstOrDefault().Value); catController.RequestObj = this.RequestObj; return(catController.GetData((int)CatalogsController.ActionType.GetCatalog)); #endregion case ActionType.GetWorksheets: #region GetWorksheets path = JsonConvert.DeserializeObject <string>(RequestObj.TransParms.Where(p => p.Key == "fName").FirstOrDefault().Value); exLoader = new ExcelLoader(); return(exLoader.LoadWorkSheets(path)); #endregion case ActionType.ImportDespachos: #region ImportDespachos path = JsonConvert.DeserializeObject <string>(RequestObj.TransParms.Where(p => p.Key == "fName").FirstOrDefault().Value); string workSheet = JsonConvert.DeserializeObject <string>(RequestObj.TransParms.Where(p => p.Key == "workSheet").FirstOrDefault().Value); exLoader = new ExcelLoader(); DtDespachosIn = exLoader.LoadFile(path, workSheet); return(true); #endregion case ActionType.LoadRemitente: #region LoadRemitente var clts = Entities.Database.SqlQuery <GeneralCat>(SQL_GET_CLIENTES).ToList(); clts.Insert(0, new GeneralCat { catId = -1, catVal = "Seleccione..." }); return(clts); #endregion case ActionType.LoadCitiesFullName: #region LoadCitiesFullName CitiesFullNames = Entities.Database.SqlQuery <GeneralCat>(SQL_CIUDADES).ToList(); #endregion break; case ActionType.LoadProveedores: #region LoadProveedores Proveedores = Entities.Database.SqlQuery <GeneralCat>(string.Format(SQL_PROVEEDORES, ClienteID)).ToList(); #endregion break; case ActionType.IsInDespacho: #region IsInDespacho ConsecCliente = Entities.Database.SqlQuery <string>(SQL_IS_IN_DESPACHO, ClienteID).ToList(); #endregion break; case ActionType.InsertDespachos: #region InsertDespachos //int cId = JsonConvert.DeserializeObject<int>(RequestObj.TransParms.Where(p => p.Key == "cId").FirstOrDefault().Value); DataRow r = null; sql = new StringBuilder(); string s = "", conCliente = ""; try { for (i = 0; i < DtDespachosOut.Rows.Count; i++) { r = DtDespachosOut.Rows[i]; if (r[COL_CONSECUTIVO_CLIENTE].ToString().Trim().Length == 0) { continue; } conCliente = r[COL_CONSECUTIVO_CLIENTE].ToString(); var e = Entities.LGC_DESPACHO. Where(d => d.CONSECUTIVO_CLIENTE == conCliente) .FirstOrDefault(); if (e != null) { sql.Clear(); throw new GeneralControllerException(string.Format("El registro en la fila {0} ya existe.(Consec:{1})", i + 1, conCliente)); } s = string.Format(SQL_IN_DESPACHO, ClienteID, EntUtils.GetStrFromDtRow(r, GV_COL_CONSECUTIVO), EntUtils.GetStrFromDtRow(r, GV_COL_CONSECUTVO_AVMK), EntUtils.GetStrFromDtRow(r, GV_COL_CONSECUTIVO_CLIENTE), EntUtils.GetDTFromDtRow(r, GV_COL_FECHA_ENVIO_ARCHIVO, false).Value.ToString("dd/MM/yyyy"), "", "", EntUtils.GetDTFromDtRow(r, GV_COL_FECHA_DE_REDENCION, false).Value.ToString("dd/MM/yyyy"), EntUtils.GetStrFromDtRow(r, GV_COL_CEDULA), EntUtils.GetStrFromDtRow(r, GV_COL_CLIENTE), EntUtils.GetStrFromDtRow(r, GV_COL_ENTREGAR_A), EntUtils.GetStrFromDtRow(r, GV_COL_DIRECCION), EntUtils.GetStrFromDtRow(r, GV_COL_CIUDAD), EntUtils.GetIntFromDtRow(r, GV_COL_DEPARTAMENTO), EntUtils.GetStrFromDtRow(r, GV_COL_TELEFONO), EntUtils.GetStrFromDtRow(r, GV_COL_CELULAR), EntUtils.GetStrFromDtRow(r, GV_COL_CORREO_ELECTRONICO), EntUtils.GetStrFromDtRow(r, GV_COL_CODIGO_PREMIO), EntUtils.GetStrFromDtRow(r, GV_COL_PREMIO), EntUtils.GetStrFromDtRow(r, GV_COL_ESPECIFICACIONES), EntUtils.GetIntFromDtRow(r, GV_COL_PROVEEDOR), EntUtils.GetIntFromDtRow(r, GV_COL_CANTIDAD), EntUtils.GetIntFromDtRow(r, GV_COL_VALOR), ClienteID); sql.Append(s); } DataBaseUtils dbUtils = new DataBaseUtils(); return(dbUtils.RunScriptFromStngBldr(sql, Entities)); } catch (Exception ex) { string rData = ""; if (r != null) { rData = string.Join("|", r.ItemArray); } throw new Exception(string.Format("Error en fila {0}. [{1}] ", i + 1, rData) + ex.Message); } #endregion default: break; } } catch (Exception ex) { throw ex; } return(ResponseObj); }
public CarsServices() { carRepository = new CarRepository(); dataBaseUtils = new DataBaseUtils(); }