// Decompiled with JetBrains decompiler
// Type: SE0085.Q2CdB.icDataConnectionQ2C
// Assembly: SE0085Q2CdB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: A5680110-30A2-457F-A920-E4C024719231
// Assembly location: C:\Users\Abishek\Downloads\SchneiderCode_Breaker_09292016\Breaker Schedule-20160930T014118Z\Breaker Schedule\Solution for gathering Breaker Data\DMS\bin\Debug\SE0085Q2CdB.dll

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

namespace SE0085.Q2CdB
{
  internal class icDataConnectionQ2C
  {
    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._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 icDataConnectionQ2C(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; }
      }
      string str1;
      string str2;
      switch (DataSource)
      {
        case emDataSource.SESQLSVR01:
          str1 = "2ua14603mz.m087.us.schneider-electric.com";
          str2 = "SESQLSVR";
          break;
        case emDataSource.BRCCSQLCLUSTER:
          str1 = "";
          str2 = "BRCCSQLCLUSTER";
          break;
        default:
          return;
      }
      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;
        case emInitCatalog.SE0085Q2C01:
          str3 = "MDSS_dbmor_d";
          break;
        case emInitCatalog.SE0085Q2C02:
          str3 = "MDSS_dbmds";
          break;
        default:
          return;
      }
      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.SEQ2C01:
          this.dbConnectionBuild01();
          break;
        case emDataEntity.SEQ2C02:
          this.dbConnectionBuild02();
          break;
      }
    }

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

    public void dbConnectionBuild01()
    {
      this._dBconnBuilder = new EntityConnectionStringBuilder();
      this._dBconnBuilder.Metadata = "res://*/SEQ2C01.csdl|res://*/SEQ2C01.ssdl|res://*/SEQ2C01.msl";
      this._dBconnBuilder.ProviderConnectionString = "Network Library=dbmssocn;Data Source=" + this.SQLServer + ";Initial Catalog=" + this.InitialCatalog + ";integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;";
      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://*/SEQ2C02.csdl|res://*/SEQ2C02.ssdl|res://*/SEQ2C02.msl";
      this._dBconnBuilder.ProviderConnectionString = "Network Library=dbmssocn;Data Source=" + this.SQLServer + ";Initial Catalog=" + this.InitialCatalog + ";integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;";
      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;
    }
  }
}
