352 lines
10 KiB
C#
352 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using De.Lambertz.Portal;
|
|
using System.Data.SqlClient;
|
|
using De.Lambertz.Tools;
|
|
using System.Data;
|
|
|
|
namespace De.Lambertz.ODAL
|
|
{
|
|
public class ODALUser
|
|
{
|
|
private string login = null;
|
|
private int userID = 0;
|
|
private string name = null;
|
|
private string eMail = null;
|
|
private string kostenstelle = null;
|
|
private int firma = 1;
|
|
private bool admin = false;
|
|
private bool freigabe = false;
|
|
private bool te = false;
|
|
private bool darfBestellungenErstelllen = false;
|
|
private string telefon = null;
|
|
private string unterschrift = null;
|
|
private Dictionary<int, ODALBereich> bereiche = null;
|
|
private Dictionary<int, FachBereich> fachBereiche = null;
|
|
private string vergleichsname = null;
|
|
private List<String> projektNummernVorgabe = null;
|
|
private DateTime istGesperrtSeit = DateTime.MinValue;
|
|
private bool istGesperrtNachgeladen = false;
|
|
|
|
public ODALUser()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool DarfBestellungenErstelllen
|
|
{
|
|
get { return darfBestellungenErstelllen; }
|
|
set { darfBestellungenErstelllen = value; }
|
|
}
|
|
|
|
public string Login
|
|
{
|
|
get { return login; }
|
|
set { login = value; }
|
|
}
|
|
|
|
public int UserID
|
|
{
|
|
get { return userID; }
|
|
set { userID = value; }
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get { return name; }
|
|
set { name = value; }
|
|
}
|
|
|
|
public string EMail
|
|
{
|
|
get { return eMail; }
|
|
set { eMail = value; }
|
|
}
|
|
|
|
public string Kostenstelle
|
|
{
|
|
get { return kostenstelle; }
|
|
set { kostenstelle = value; }
|
|
}
|
|
|
|
public int Firma
|
|
{
|
|
get { return firma; }
|
|
set { firma = value; }
|
|
}
|
|
|
|
public bool Admin
|
|
{
|
|
get { return admin; }
|
|
set { admin = value; }
|
|
}
|
|
|
|
public bool Freigabe
|
|
{
|
|
get { return freigabe; }
|
|
set { freigabe = value; }
|
|
}
|
|
|
|
public string Vergleichsname
|
|
{
|
|
get { return vergleichsname; }
|
|
set
|
|
{
|
|
vergleichsname = value;
|
|
}
|
|
}
|
|
|
|
public Dictionary<int, ODALBereich> Bereiche
|
|
{
|
|
get
|
|
{
|
|
if (bereiche == null)
|
|
{
|
|
this.loadBereiche();
|
|
}
|
|
return bereiche;
|
|
}
|
|
}
|
|
|
|
public ODALBereich GetBereich(int bereichsNr)
|
|
{
|
|
ODALBereich result = null;
|
|
|
|
if (Bereiche.ContainsKey(bereichsNr)) //<B>ereiche damit sie geladen werden falls nicht vorhanden!
|
|
{
|
|
result = bereiche[bereichsNr];
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public Dictionary<int, FachBereich> FachBereiche
|
|
{
|
|
get
|
|
{
|
|
if (fachBereiche == null)
|
|
{
|
|
this.loadFachBereiche();
|
|
}
|
|
|
|
return fachBereiche;
|
|
}
|
|
}
|
|
|
|
public bool userHatBereich(int bereichsNr)
|
|
{
|
|
bool result = false;
|
|
|
|
if (FachBereiche.ContainsKey(bereichsNr)) //<F>achbereiche, damit sie geladen werden wenn nicht vorhanden
|
|
{
|
|
result = true;
|
|
}
|
|
else if (Bereiche.ContainsKey(bereichsNr)) //<B>ereiche damit sie geladen werden falls nicht vorhanden!
|
|
{
|
|
result = true;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holt die Verbindung zum MSSQL Server
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private SqlConnection getConnection()
|
|
{
|
|
SqlConnection result = null;
|
|
try
|
|
{
|
|
result = new SqlConnection();
|
|
result.ConnectionString = DBTools.ConnectionStringODAL();
|
|
result.Open();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
result = null;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Schliesst die Verbindung zum MSSQL Server
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private void returnConnection(SqlConnection con)
|
|
{
|
|
if (con != null && con.State == ConnectionState.Open)
|
|
{
|
|
con.Close();
|
|
}
|
|
}
|
|
|
|
private void loadFachBereiche()
|
|
{
|
|
this.fachBereiche = new Dictionary<int, FachBereich>();
|
|
UserSingelton us = UserSingelton.GetInstance();
|
|
using (SqlConnection con = new SqlConnection(DBTools.ConnectionStringODAL()))
|
|
{
|
|
con.Open();
|
|
String sql = "select FBID from ODAL.ANWENDER_X_FACHBEREICH where USERNR in (";
|
|
|
|
String token = "";
|
|
foreach (int user in us.Vertretungen)
|
|
{
|
|
sql = sql + token + user.ToString();
|
|
if (token == "")
|
|
{
|
|
token = ", ";
|
|
}
|
|
}
|
|
sql = sql + ")";
|
|
|
|
SqlCommand cmd = new SqlCommand(sql, con);
|
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
int id = DBTools.DBGetInt(reader, 0);
|
|
if (!this.fachBereiche.ContainsKey(id))
|
|
{
|
|
if (us.FachBereiche.ContainsKey(id))
|
|
{
|
|
this.fachBereiche.Add(id, us.FachBereiche[id]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void loadBereiche()
|
|
{
|
|
bereiche = new Dictionary<int, ODALBereich>();
|
|
UserSingelton us = UserSingelton.GetInstance();
|
|
using (SqlConnection con = new SqlConnection(DBTools.ConnectionStringODAL()))
|
|
{
|
|
con.Open();
|
|
String sql = "select BEREICHNR from ODAL.ANWENDER_X_BEREICH where USERNR in (";
|
|
|
|
String token = "";
|
|
foreach (int user in us.Vertretungen)
|
|
{
|
|
sql = sql + token + user.ToString();
|
|
if (token == "")
|
|
{
|
|
token = ", ";
|
|
}
|
|
}
|
|
sql = sql + ")";
|
|
|
|
SqlCommand cmd = new SqlCommand(sql, con);
|
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
int id = DBTools.DBGetInt(reader, 0);
|
|
if (!this.bereiche.ContainsKey(id))
|
|
{
|
|
if (us.Bereiche.ContainsKey(id))
|
|
{
|
|
this.bereiche.Add(id, us.Bereiche[id]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public string Telefon
|
|
{
|
|
get { return telefon; }
|
|
set { telefon = value; }
|
|
}
|
|
|
|
public string Unterschrift
|
|
{
|
|
get { return unterschrift; }
|
|
set { unterschrift = value; }
|
|
}
|
|
|
|
public bool Te
|
|
{
|
|
get { return te; }
|
|
set { te = value; }
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return this.name;
|
|
}
|
|
|
|
|
|
public List<String> ProjektNummernVorgabe
|
|
{
|
|
get
|
|
{
|
|
if (projektNummernVorgabe == null)
|
|
{
|
|
projektNummernVorgabe = new List<string>();
|
|
|
|
using (SqlConnection con = new SqlConnection(DBTools.ConnectionStringODAL()))
|
|
{
|
|
con.Open();
|
|
String sql = "Select PROJEKTNR from ANWENDER_X_PROJEKT where USERNR = @p1 order by PROJEKTNR";
|
|
SqlCommand cmd = new SqlCommand(sql, con);
|
|
cmd.Parameters.AddWithValue("@p1", userID);
|
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
projektNummernVorgabe.Add(DBTools.DBGetString(reader, 0));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return projektNummernVorgabe;
|
|
}
|
|
}
|
|
|
|
public DateTime IstGesperrtSeit
|
|
{
|
|
get
|
|
{
|
|
DateTime result = DateTime.MinValue;
|
|
if (istGesperrtNachgeladen)
|
|
{
|
|
result = istGesperrtSeit;
|
|
}
|
|
else
|
|
{
|
|
using (SqlConnection con = new SqlConnection(DBTools.ConnectionStringLAMBERTZ()))
|
|
{
|
|
con.Open();
|
|
String sql = "Select [GesperrtAb] from [Lambertz].[LA].[EDVUser] where [login] = @p1";
|
|
SqlCommand cmd = new SqlCommand(sql, con);
|
|
cmd.Parameters.AddWithValue("@p1", login);
|
|
using (SqlDataReader reader = cmd.ExecuteReader())
|
|
{
|
|
if (reader.Read())
|
|
{
|
|
IstGesperrtSeit = DBTools.DBGetDate(reader, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
set
|
|
{
|
|
istGesperrtSeit = value;
|
|
istGesperrtNachgeladen = true;
|
|
}
|
|
}
|
|
}
|
|
}
|