Files
SourceCode/PROMS/VEPROMS.CSLA.Library/Extension/AdminToolsExt.cs
T
2026-09-01 08:21:41 -04:00

505 lines
16 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
namespace VEPROMS.CSLA.Library
{
public class ESP_FixHyphens : CommandBase
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region Factory Methods
public string StoredProcedure { get; set; }
public int AffectedRows { get; set; }
public static int Execute(string storedProcedure)
{
ESP_DeletePDFs cmd = new ESP_DeletePDFs
{
StoredProcedure = storedProcedure
};
DataPortal.Execute<ESP_DeletePDFs>(cmd);
return cmd.AffectedRows;
}
#endregion
#region Server-Side code
protected override void DataPortal_Execute()
{
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand(StoredProcedure, cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
AffectedRows = cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("ExecuteStoredProcedureRowsAffected Error", ex);
throw new ApplicationException("Failure on ExecuteStoredProcedureRowsAffected", ex);
}
}
#endregion
}
public class ESP_DeletePDFs : CommandBase
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region Factory Methods
public string StoredProcedure { get; set; }
public int AffectedRows { get; set; }
public static int Execute(string storedProcedure)
{
ESP_DeletePDFs cmd = new ESP_DeletePDFs
{
StoredProcedure = storedProcedure
};
DataPortal.Execute<ESP_DeletePDFs>(cmd);
return cmd.AffectedRows;
}
#endregion
#region Server-Side code
protected override void DataPortal_Execute()
{
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand(StoredProcedure, cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
AffectedRows = cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("ExecuteStoredProcedureRowsAffected Error", ex);
throw new ApplicationException("Failure on ExecuteStoredProcedureRowsAffected", ex);
}
}
#endregion
}
public class ESP_IdentifyDisconnectedItems : CommandBase
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region Factory Methods
public string StoredProcedure { get; set; }
public int RowCount { get; set; }
public static int Execute(string storedProcedure)
{
ESP_IdentifyDisconnectedItems cmd = new ESP_IdentifyDisconnectedItems
{
StoredProcedure = storedProcedure
};
DataPortal.Execute<ESP_IdentifyDisconnectedItems>(cmd);
return cmd.RowCount;
}
#endregion
#region Server-Side code
protected override void DataPortal_Execute()
{
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand(StoredProcedure, cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
RowCount = dr.GetInt32(0);
}
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("ExecuteStoredProcedureRowCount Error", ex);
throw new ApplicationException("Failure on ExecuteStoredProcedureRowCount", ex);
}
}
#endregion
}
public class ESP_PurgeDisconnectedItems : CommandBase
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region Factory Methods
public string StoredProcedure { get; set; }
public int RowCount { get; set; }
public static int Execute(string storedProcedure)
{
ESP_PurgeDisconnectedItems cmd = new ESP_PurgeDisconnectedItems
{
StoredProcedure = storedProcedure
};
DataPortal.Execute<ESP_PurgeDisconnectedItems>(cmd);
return cmd.RowCount;
}
#endregion
#region Server-Side code
protected override void DataPortal_Execute()
{
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand(StoredProcedure, cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
SqlDataReader dr = cmd.ExecuteReader();
RowCount = dr.RecordsAffected;
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("ExecuteStoredProcedureRowCount Error", ex);
throw new ApplicationException("Failure on ExecuteStoredProcedureRowCount", ex);
}
}
#endregion
}
#region MultipleROAssociations
public class ESP_GetROAssoc : CommandBase
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region Factory Methods
public string StoredProcedure { get; set; }
public int RowCount { get; set; }
public static int Execute(string storedProcedure)
{
ESP_GetROAssoc cmd = new ESP_GetROAssoc
{
StoredProcedure = storedProcedure
};
DataPortal.Execute<ESP_GetROAssoc>(cmd);
return cmd.RowCount;
}
#endregion
#region Server-Side code
protected override void DataPortal_Execute()
{
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand(StoredProcedure, cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
RowCount = dr.GetInt32(0);
}
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("ExecuteStoredProcedureRowCount Error", ex);
throw new ApplicationException("Failure on ExecuteStoredProcedureRowCount", ex);
}
}
#endregion
}
public class ESP_CleanupROAssoc : CommandBase
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region Factory Methods
public string StoredProcedure { get; set; }
public int RowCount { get; set; }
public static int Execute(string storedProcedure)
{
ESP_CleanupROAssoc cmd = new ESP_CleanupROAssoc
{
StoredProcedure = storedProcedure
};
DataPortal.Execute<ESP_CleanupROAssoc>(cmd);
return cmd.RowCount;
}
#endregion
#region Server-Side code
protected override void DataPortal_Execute()
{
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand(StoredProcedure, cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
SqlDataReader dr = cmd.ExecuteReader();
RowCount = dr.RecordsAffected;
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("ExecuteStoredProcedureRowCount Error", ex);
throw new ApplicationException("Failure on ExecuteStoredProcedureRowCount", ex);
}
}
#endregion
}
#endregion
#region UnsedRoFstsAndFigures
public class ESP_GetUnusedRoFsts : CommandBase
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region Factory Methods
public string StoredProcedure { get; set; }
public int RowCount { get; set; }
public static int Execute(string storedProcedure)
{
ESP_GetUnusedRoFsts cmd = new ESP_GetUnusedRoFsts
{
StoredProcedure = storedProcedure
};
DataPortal.Execute<ESP_GetUnusedRoFsts>(cmd);
return cmd.RowCount;
}
#endregion
#region Server-Side code
protected override void DataPortal_Execute()
{
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand(StoredProcedure, cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
RowCount = dr.GetInt32(0);
}
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("ExecuteStoredProcedureRowCount Error", ex);
throw new ApplicationException("Failure on ExecuteStoredProcedureRowCount", ex);
}
}
#endregion
}
public class ESP_GetUnusedFigures : CommandBase
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region Factory Methods
public string StoredProcedure { get; set; }
public int RowCount { get; set; }
public static int Execute(string storedProcedure)
{
ESP_GetUnusedFigures cmd = new ESP_GetUnusedFigures
{
StoredProcedure = storedProcedure
};
DataPortal.Execute<ESP_GetUnusedFigures>(cmd);
return cmd.RowCount;
}
#endregion
#region Server-Side code
protected override void DataPortal_Execute()
{
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand(StoredProcedure, cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
RowCount = dr.GetInt32(0);
}
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("ExecuteStoredProcedureRowCount Error", ex);
throw new ApplicationException("Failure on ExecuteStoredProcedureRowCount", ex);
}
}
#endregion
}
public class ESP_PurgeUnusedRoFstsAndFigures : CommandBase
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region Factory Methods
public string StoredProcedure { get; set; }
public int RowCount { get; set; }
public static int Execute(string storedProcedure)
{
ESP_PurgeUnusedRoFstsAndFigures cmd = new ESP_PurgeUnusedRoFstsAndFigures
{
StoredProcedure = storedProcedure
};
DataPortal.Execute<ESP_PurgeUnusedRoFstsAndFigures>(cmd);
return cmd.RowCount;
}
#endregion
#region Server-Side code
protected override void DataPortal_Execute()
{
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand(StoredProcedure, cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
SqlDataReader dr = cmd.ExecuteReader();
RowCount = dr.RecordsAffected;
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("ExecuteStoredProcedureRowCount Error", ex);
throw new ApplicationException("Failure on ExecuteStoredProcedureRowCount", ex);
}
}
#endregion
}
#endregion
public class ESP_IdentifyNonEditableItems : CommandBase
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region Factory Methods
public string StoredProcedure { get; set; }
public List<ItemInfo> ItemInfoList { get; set; } = new List<ItemInfo>();
public static List<ItemInfo> Execute(string storedProcedure)
{
ESP_IdentifyNonEditableItems cmd = new ESP_IdentifyNonEditableItems
{
StoredProcedure = storedProcedure
};
DataPortal.Execute<ESP_IdentifyNonEditableItems>(cmd);
return cmd.ItemInfoList;
}
#endregion
#region Server-Side code
protected override void DataPortal_Execute()
{
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand(StoredProcedure, cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
using (SafeDataReader dr = new SafeDataReader(cmd.ExecuteReader()))
{
while (dr.Read()) ItemInfoList.Add(new ItemInfo(dr));
}
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("ExecuteStoredProcedureItemInfoList Error", ex);
throw new ApplicationException("Failure on ExecuteStoredProcedureItemInfoList", ex);
}
}
#endregion
}
public class ESP_GetDatabaseSessions : CommandBase
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region Factory Methods
public string StoredProcedure { get; set; }
public string ResultsString { get; set; }
public static string Execute(string storedProcedure)
{
ESP_GetDatabaseSessions cmd = new ESP_GetDatabaseSessions
{
StoredProcedure = storedProcedure
};
DataPortal.Execute<ESP_GetDatabaseSessions>(cmd);
return cmd.ResultsString;
}
#endregion
#region Server-Side code
protected override void DataPortal_Execute()
{
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cmd = new SqlCommand(StoredProcedure, cn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
SqlDataReader dr = cmd.ExecuteReader();
StringBuilder sbs = new StringBuilder();
int sessionid = 0;
string ownertypename = string.Empty;
while (dr.Read())
{
if (dr.GetInt32(0) != sessionid)
{
if (sessionid != 0)
sbs.AppendLine();
sessionid = dr.GetInt32(0);
ownertypename = string.Empty;
sbs.AppendLine(string.Format("The User {0} on computer {1} has an {2} session.", dr.GetString(1), dr.GetString(2), dr.GetString(5)));
if (dr.GetInt32(4) == 0)
{
sbs.AppendLine(string.Format("This user has {0} checked out", dr.GetString(3)));
}
else
{
sbs.AppendLine(string.Format("This user has {0} {1}(s) checked out...", dr.GetInt32(4), dr.GetString(3)));
sbs.AppendLine(string.Format("{0} -> {1} -> {2} -> {3} checked out at {4}", dr.GetString(6), dr.GetString(7), dr.GetString(8), dr.GetString(9), dr.GetDateTime(10)));
ownertypename = dr.GetString(3);
}
}
else
{
if (dr.GetInt32(4) > 0)
{
if (dr.GetString(3) != ownertypename)
{
sbs.AppendLine(string.Format("This user has {0} {1}(s) checked out...", dr.GetInt32(4), dr.GetString(3)));
sbs.AppendLine(string.Format("{0} -> {1} -> {2} -> {3} checked out at {4}", dr.GetString(6), dr.GetString(7), dr.GetString(8), dr.GetString(9), dr.GetDateTime(10)));
ownertypename = dr.GetString(3);
}
else
sbs.AppendLine(string.Format("{0} -> {1} -> {2} -> {3} checked out at {4}", dr.GetString(6), dr.GetString(7), dr.GetString(8), dr.GetString(9), dr.GetDateTime(10)));
}
}
}
ResultsString = sbs.ToString();
}
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("ExecuteStoredProcedureString Error", ex);
throw new ApplicationException("Failure on ExecuteStoredProcedureString", ex);
}
}
#endregion
}
}