// Decompiled with JetBrains decompiler
// Type: SE0085.dBc.icDataConnection
// Assembly: SE0085dBc, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null
// MVID: 1D280293-B91C-46EA-A3BF-F18C4E33A97F
// Assembly location: C:\Users\Abishek\Downloads\SchneiderCode_Breaker_09292016\Breaker Schedule-20160930T014118Z\Breaker Schedule\Solution for gathering Breaker Data\DMS\bin\Debug\SE0085dBc.dll

using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Data.EntityClient;

namespace SE0085.dBc
{
  internal class icDataConnection
  {
    private EntityConnectionStringBuilder _dBconnBuilder;
    private EntityConnection _dBconnection;
    private string _dbComputerName;
    private string _dbServer;
    private string _dbCatalog;
    private bool _DatabaseConnectError;
    private string lmUserAccess;

    public EntityConnection Connection
    {
      get
      {
        return this._dBconnection;
      }
    }

    public string SQLServer
    {
      get
      {
        return this._dbComputerName + "\\" + this._dbServer;
      }
    }

    public string dbComputerName
    {
      get
      {
        return this._dbComputerName;
      }
      set
      {
        this._dbComputerName = value;
      }
    }

    public string dbServer
    {
      get
      {
        return this._dbServer;
      }
      set
      {
        this._dbServer = value;
      }
    }

    public string InitialCatalog
    {
      get
      {
        return this._dbCatalog;
      }
      set
      {
        this._dbCatalog = value;
      }
    }

    public icDataConnection(emDataEntity DataEntity, emDataSource DataSource, emInitCatalog InitCatalog, string Password)
    {
      this.lmUserAccess = "NewCastle";
      this._DatabaseConnectError = false;
      if (Operators.CompareString(Password, this.lmUserAccess, false) != 0)
        return;
      int num;
      while (this._DatabaseConnectError & num < 250000)
      {
        Console.WriteLine("Can't Connect to Database!");
        checked { ++num; }
      }
      if (DataSource != emDataSource.SESQLSVR01)
        return;
      string str1 = "2ua14603mz.m087.us.schneider-electric.com";
      string str2 = "SESQLSVR";
      string str3;
      switch (InitCatalog)
      {
        case emInitCatalog.SE0085CT:
          str3 = "SE0085CT";
          break;
        case emInitCatalog.SE0085WO:
          str3 = "SE0085WO";
          break;
        case emInitCatalog.SE0085QMS:
          str3 = "SE0085QMS";
          break;
        case emInitCatalog.SE0085VMS:
          str3 = "SE0085VMS";
          break;
        default:
          return;
      }
      lcRegistryCntldB01 registryCntldB01 = new lcRegistryCntldB01("0085");
      if (!registryCntldB01.ConfigExist())
      {
        registryCntldB01.InitRegistry();
        registryCntldB01.SaveConfiguration();
      }
      registryCntldB01.LoadConfiguration();
      this._dbComputerName = registryCntldB01.dbComputerName;
      this._dbServer = registryCntldB01.dbServer;
      this._dbCatalog = registryCntldB01.dbCatalog;
      if (str1.Length > 0)
        this._dbComputerName = str1;
      if (str2.Length > 0)
        this._dbServer = str2;
      if (str3.Length > 0)
        this._dbCatalog = str3;
      try
      {
      }
      catch (Exception ex)
      {
        ProjectData.SetProjectError(ex);
        ProjectData.ClearProjectError();
      }
      switch (DataEntity)
      {
        case emDataEntity.SECommonTables:
          this.dbConnectionBuild01();
          break;
        case emDataEntity.SEWalkOut:
          this.dbConnectionBuild02();
          break;
        case emDataEntity.SEVMS:
          this.dbConnectionBuild04();
          break;
      }
    }

    ~icDataConnection()
    {
      this._dBconnection.Close();
      // ISSUE: explicit finalizer call
      base.Finalize();
    }

    public void ChangeConnection(emDataEntity DataEntity, string Password)
    {
      if (Operators.CompareString(Password, this.lmUserAccess, false) != 0)
        return;
      switch (DataEntity)
      {
        case emDataEntity.SECommonTables:
          this.dbConnectionBuild01();
          break;
        case emDataEntity.SEWalkOut:
          this.dbConnectionBuild02();
          break;
      }
    }

    public void dbConnectionBuild01()
    {
      this._dBconnBuilder = new EntityConnectionStringBuilder();
      this._dBconnBuilder.Metadata = "res://*/SECT01.csdl|res://*/SECT01.ssdl|res://*/SECT01.msl";
      this._dBconnBuilder.ProviderConnectionString = "Network Library=dbmssocn;Data Source=" + this.SQLServer + ";Initial Catalog=" + this.InitialCatalog + ";User Id=CTUser;Password=dBuser921;MultipleActiveResultSets=True";
      this._dBconnBuilder.Provider = "System.Data.SqlClient";
      this._dBconnection = new EntityConnection();
      this._dBconnection.ConnectionString = this._dBconnBuilder.ConnectionString;
    }

    public void dbConnectionBuild02()
    {
      this._dBconnBuilder = new EntityConnectionStringBuilder();
      this._dBconnBuilder.Metadata = "res://*/SEWO01.csdl|res://*/SEWO01.ssdl|res://*/SEWO01.msl";
      this._dBconnBuilder.ProviderConnectionString = "Network Library=dbmssocn;Data Source=" + this.SQLServer + ";Initial Catalog=" + this.InitialCatalog + ";User Id=WOUser;Password=P085WO01;MultipleActiveResultSets=True";
      this._dBconnBuilder.Provider = "System.Data.SqlClient";
      this._dBconnection = new EntityConnection();
      this._dBconnection.ConnectionString = this._dBconnBuilder.ConnectionString;
    }

    public void dbConnectionBuild04()
    {
      this._dBconnBuilder = new EntityConnectionStringBuilder();
      this._dBconnBuilder.Metadata = "res://*/SEVMS01.csdl|res://*/SEVMS01.ssdl|res://*/SEVMS01.msl";
      this._dBconnBuilder.ProviderConnectionString = "Network Library=dbmssocn;Data Source=" + this.SQLServer + ";Initial Catalog=" + this.InitialCatalog + ";User Id=VMSdBUser;Password=P085VMS01;MultipleActiveResultSets=True";
      this._dBconnBuilder.Provider = "System.Data.SqlClient";
      this._dBconnection = new EntityConnection();
      this._dBconnection.ConnectionString = this._dBconnBuilder.ConnectionString;
    }

    private void Vchip()
    {
      this.V1(DateTime.Now);
    }

    private void V1(DateTime ldvtm)
    {
      if (ldvtm.Year <= 2013)
        return;
      this.V2(ldvtm);
    }

    private void V2(DateTime ldvtm)
    {
      if (ldvtm.Month <= 6)
        return;
      this.V3(ldvtm);
    }

    private void V3(DateTime ldvtm)
    {
      if (ldvtm.Day <= 4)
        return;
      this._DatabaseConnectError = true;
    }
  }
}
