Example #1
0
        public void uploadFile(DataTable pdataExcel, String psoeid, String pfileID, String pspName, String pyear, String pmonth)
        {
            try
            {
                // Create connections with the database
                string connString = SessionUtil.GetConnectionString("ConnString");
                System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);

                // Create a command object identifying the stored procedure
                System.Data.SqlClient.SqlCommand _command = new System.Data.SqlClient.SqlCommand(pspName, conn);

                // Set the command object so it knows to execute a stored procedure
                _command.CommandType = System.Data.CommandType.StoredProcedure;
                _command.CommandTimeout = 999999999;

                SqlParameter _table = new SqlParameter("@EXCELTABLE", SqlDbType.Structured);
                _table.Value = pdataExcel;
                _command.Parameters.Add(_table);

                SqlParameter _soeid = new SqlParameter("@SOEID_UPLOADER", SqlDbType.VarChar);
                _soeid.Value = psoeid;
                _command.Parameters.Add(_soeid);

                SqlParameter _fileID = new SqlParameter("@FILE_ID", SqlDbType.VarChar);
                _fileID.Value = pfileID;
                _command.Parameters.Add(_fileID);

                SqlParameter _year = new SqlParameter("@YEAR", SqlDbType.VarChar);
                _year.Value = pyear;
                _command.Parameters.Add(_year);

                SqlParameter _month = new SqlParameter("@MONTH", SqlDbType.VarChar);
                _month.Value = pmonth;
                _command.Parameters.Add(_month);

                // Execute the command
                conn.Open();

                _command.ExecuteNonQuery();

                conn.Close();
            }
            catch (UtilException uEx)
            {
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                throw uEx;
            }
            catch (Exception ex)
            {
                UtilException uEx = new UtilException(ex);
                uEx.OriginalExceptionClass = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
                uEx.OriginalExceptionMethod = System.Reflection.MethodBase.GetCurrentMethod().Name;
                uEx.StackTrace.Add(uEx.OriginalExceptionClass + " : " + uEx.OriginalExceptionMethod);
                throw uEx;
            }
        }
Example #2
0
        public string deleteRow(string spDBDelete, List<Dictionary<string, string>> spDBToDeleteParams)
        {
            string message = "Row was deleted successful";
            try
            {
                DataSet ds = null;
                Database db = DatabaseFactory.CreateDatabase();
                DbCommand comm = db.GetStoredProcCommand(spDBDelete);

                foreach (var item in spDBToDeleteParams)
                {
                    db.AddInParameter(comm, item["Name"], DbType.String, item["Value"]);
                }

                ds = db.ExecuteDataSet(comm);

            }
            catch (UtilException uEx)
            {
                String extraInfo = "\n[SQL]:EXEC " + spDBDelete + " | \n[Params]:";
                extraInfo += "================================\n";

                foreach (var item in spDBToDeleteParams)
                {
                    extraInfo += item["Name"] + ": [" + item["Value"] + "]\n";
                }

                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name) + ": " + extraInfo);
                message = uEx.GetMessage();
                throw uEx;
            }
            catch (Exception ex)
            {
                String extraInfo = "\n[SQL]:EXEC " + spDBDelete + " | \n[Params]:";
                extraInfo += "================================\n";

                foreach (var item in spDBToDeleteParams)
                {
                    extraInfo += item["Name"] + ": [" + item["Value"] + "]\n";
                }

                UtilException uEx = new UtilException(ex);
                uEx.OriginalExceptionClass = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
                uEx.OriginalExceptionMethod = System.Reflection.MethodBase.GetCurrentMethod().Name;
                uEx.StackTrace.Add(uEx.OriginalExceptionClass + " : " + uEx.OriginalExceptionMethod + ": " + extraInfo);
                message = uEx.GetMessage();
                throw uEx;
            }
            return message;
        }
Example #3
0
        public Dictionary<string, string> insertNew(string spDBInsert, List<Dictionary<string, string>> spDBInsertParams, List<Dictionary<string, string>> colsDBToSelect)
        {
            Dictionary<string, string> newObjectData = new Dictionary<string, string>();
            try
            {
                DataSet ds = null;
                Database db = DatabaseFactory.CreateDatabase();
                DbCommand comm = db.GetStoredProcCommand(spDBInsert);

                foreach (var item in spDBInsertParams)
                {
                    db.AddInParameter(comm, item["Name"], DbType.String, item["Value"]);
                }

                ds = db.ExecuteDataSet(comm);

                if ((ds != null))
                {
                    if (ds.Tables.Count >= 1)
                    {
                        DataTable objTable = ds.Tables[0];

                        for (int _i = 0; _i <= objTable.Rows.Count - 1; _i++)
                        {
                            //Add atributes information
                            foreach (var item in colsDBToSelect)
                            {
                                if (item.ContainsKey("Name"))
                                {
                                    newObjectData.Add(item["Name"], objTable.Rows[_i][item["Name"]].ToString());
                                }
                            }
                        }
                    }
                }
                else
                {
                    return null;
                }
            }
            catch (UtilException uEx)
            {
                String extraInfo = "\n[SQL]:EXEC " + spDBInsert + " | \n[Params]:";
                extraInfo += "================================\n";

                foreach (var item in spDBInsertParams)
                {
                    extraInfo += item["Name"] + ": [" + item["Value"] + "]\n";
                }

                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name) + ": " + extraInfo);
                throw uEx;
            }
            catch (Exception ex)
            {
                String extraInfo = "\n[SQL]:EXEC " + spDBInsert + " | \n[Params]:";
                extraInfo += "================================\n";

                foreach (var item in spDBInsertParams)
                {
                    extraInfo += item["Name"] + ": [" + item["Value"] + "]\n";
                }

                UtilException uEx = new UtilException(ex);
                uEx.OriginalExceptionClass = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
                uEx.OriginalExceptionMethod = System.Reflection.MethodBase.GetCurrentMethod().Name;
                uEx.StackTrace.Add(uEx.OriginalExceptionClass + " : " + uEx.OriginalExceptionMethod + ": " + extraInfo);
                throw uEx;
            }
            return newObjectData;
        }
Example #4
0
        public static String CreateReportLog(string reportName)
        {
            int appID = 7;
            String pSQL = "EXEC [Automation].[dbo].[proc_Create_ReportLog] " +
                          "     @ApplicationID = " + appID + ", " +
                          "     @ReportName = '" + reportName + "', " +
                          "     @ExecutedBy = '" + GetSOEID() + "' ";
            String result = "";
            String LConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
            SqlConnection conn = new SqlConnection(LConnectionString);
            SqlCommand comm = new SqlCommand(pSQL, conn);
            conn.Open();
            try
            {
                comm.ExecuteNonQuery();
            }
            catch (UtilException uEx)
            {
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                uEx.SoeidSession = GetSOEID();
                uEx.SaveExceptionInBD();
                ShowErrorMessage(uEx);
            }
            catch (Exception ex)
            {
                String extraInfo = "\n[SQL]:" + pSQL + " | \n[Params]:";

                String OriginalExceptionClass = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
                String OriginalExceptionMethod = System.Reflection.MethodBase.GetCurrentMethod().Name;

                UtilException uEx = new UtilException(ex, extraInfo);
                uEx.StackTrace.Add(OriginalExceptionClass + " : " + OriginalExceptionMethod);
                uEx.SoeidSession = GetSOEID();
                uEx.SaveExceptionInBD();
                ShowErrorMessage(uEx);
            }
            finally
            {
                comm.Dispose();
                conn.Close();
            }

            return result;
        }
Example #5
0
        public static void ShowErrorMessage(UtilException pex)
        {
            Page _page = (Page)HttpContext.Current.CurrentHandler;
            string exceptionsTimeOutServer = "";
            string exceptionsTimeOutWaitingTime = "";
            string pMessage = pex.UserMessage;
            bool isSupport = true;

            if (pex.OriginalException.Message.Contains("System.Data.SqlClient.SqlException: Timeout expired.") ||
                pex.OriginalException.Message.Contains("A transport-level error has occurred when receiving results from the server.") ||
                pex.OriginalException.Message.Contains("A connection was successfully established with the server, but then an error occurred during the pre-login handshake."))
            {
                exceptionsTimeOutServer = GetAppSetting("ExceptionsTimeOutServer");
                exceptionsTimeOutWaitingTime = GetAppSetting("ExceptionsTimeOutWaitingTime");

                pMessage = "The server <b>" + exceptionsTimeOutServer + "</b> not responding, please refresh your page with F5 key in your keyboard and try again.";
                isSupport = false;
            }

            if (pex.OriginalException.Message.Contains("System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible."))
            {
                exceptionsTimeOutServer = GetAppSetting("ExceptionsTimeOutServer");
                pMessage = "<b>(" + exceptionsTimeOutServer + "</b>) " + "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.";

                isSupport = false;
            }
            ShowErrorMessage(pMessage, isSupport);
        }
Example #6
0
        public static void RefreshSession()
        {
            try
            {
                if (sessionWasRefreshed == false)
                {
                    //Refresh session only One time by post back
                    sessionWasRefreshed = true;

                }
            }
            catch (System.Threading.ThreadAbortException)
            {
                //Ignore Redirect Exception: System.Threading.ThreadAbortException: Thread was being aborted.
            }
            catch (UtilException uEx)
            {
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                uEx.SoeidSession = GetSOEID();
                throw uEx;
            }
            catch (Exception ex)
            {
                UtilException uEx = new UtilException(ex);
                uEx.OriginalExceptionClass = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
                uEx.OriginalExceptionMethod = System.Reflection.MethodBase.GetCurrentMethod().Name;
                uEx.StackTrace.Add(uEx.OriginalExceptionClass + " : " + uEx.OriginalExceptionMethod);
                uEx.SoeidSession = GetSOEID();
                throw uEx;
            }
        }
Example #7
0
        public static Employee GetUser()
        {
            //cls_Employee _objUser = null;

            try
            {
                //_objUser = HttpContext.Current.Session["USER"] as cls_Employee;
                //if (_objUser == null)
                //{
                //    RefreshSession();
                //    _objUser = HttpContext.Current.Session["USER"] as cls_Employee;

                //    if (_objUser == null)
                //    {
                //        throw new Exception("[cls_Employee not found]: GetUser() return null");
                //    }
                //}
            }
            catch (System.Threading.ThreadAbortException)
            {
                //Ignore Redirect Exception: System.Threading.ThreadAbortException: Thread was being aborted.
            }
            catch (UtilException uEx)
            {
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                throw uEx;
            }
            catch (Exception ex)
            {
                UtilException uEx = new UtilException(ex);
                uEx.OriginalExceptionClass = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
                uEx.OriginalExceptionMethod = System.Reflection.MethodBase.GetCurrentMethod().Name;
                uEx.StackTrace.Add(uEx.OriginalExceptionClass + " : " + uEx.OriginalExceptionMethod);
                throw uEx;
            }
            return new Employee();
        }
Example #8
0
        public static string GetUpdatedUserRoles()
        {
            string userRoles = "";
            try
            {
                userRoles += "Admin";
                //using (SqlCommand comm = SQL_GetSPCommand("FROU_spAdminSecurityUsersXRolesList"))
                //{
                //    comm.Parameters.Add(new SqlParameter("@SOEID", GetSOEID()));

                //    // Execute the command
                //    comm.Connection.Open();
                //    SqlDataReader rdr = comm.ExecuteReader();

                //    while (rdr.Read())
                //    {
                //        if (rdr["Grant"].ToString() == "True" || rdr["Grant"].ToString() == "1")
                //        {
                //            userRoles += rdr["RoleName"].ToString() + ", ";
                //        }
                //    }

                //    comm.Connection.Close();
                //}
            }
            catch (UtilException uEx)
            {
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                uEx.SoeidSession = GetSOEID();
                uEx.SaveExceptionInBD();
                ShowErrorMessage(uEx);
            }
            catch (Exception ex)
            {
                UtilException uEx = new UtilException(ex);
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                uEx.SoeidSession = GetSOEID();
                uEx.SaveExceptionInBD();
                ShowErrorMessage(uEx);
            }
            return userRoles;
        }
Example #9
0
        public static bool UserHasPermit(string pidPermit, bool redirectToAccessDenied, bool forceRefreshRoles)
        {
            var resultHasAccess = false;
            try
            {
                List<Dictionary<string, string>> userPermits = (List<Dictionary<string, string>>)HttpContext.Current.Session["USER_PERMITS"];
                string prefresh = HttpContext.Current.Request.QueryString["prefreshRoles"];
                if (userPermits == null || prefresh == "1" || forceRefreshRoles)
                {
                    HttpContext.Current.Session["USER_PERMITS"] = GetUpdatedUserPermits();
                    userPermits = (List<Dictionary<string, string>>)HttpContext.Current.Session["USER_PERMITS"];
                }

                Dictionary<string, string> permitData = userPermits.Where(o => o["IDPermit"] == pidPermit).Single();
                if (permitData["HasAccess"] == "True" || permitData["HasAccess"] == "1")
                {
                    resultHasAccess = true;
                }
                else
                {
                    if (redirectToAccessDenied)
                    {
                        if (!HttpContext.Current.Request.Url.AbsoluteUri.Contains("AccessDenied"))
                        {
                            HttpContext.Current.Response.Redirect("AccessDeniedToPage.aspx");
                        }
                    }
                }
            }
            catch (System.Threading.ThreadAbortException)
            {
                //Ignore Redirect Exception: System.Threading.ThreadAbortException: Thread was being aborted.
            }
            catch (UtilException uEx)
            {
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                uEx.SoeidSession = GetSOEID();
                throw uEx;
            }
            catch (Exception ex)
            {
                UtilException uEx = new UtilException(ex);
                uEx.OriginalExceptionClass = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
                uEx.OriginalExceptionMethod = System.Reflection.MethodBase.GetCurrentMethod().Name;
                uEx.StackTrace.Add(uEx.OriginalExceptionClass + " : " + uEx.OriginalExceptionMethod);
                uEx.SoeidSession = GetSOEID();
                throw uEx;
            }
            return resultHasAccess;
        }
Example #10
0
        public static System.Data.DataTable GetDataTableFromExcel(AjaxControlToolkit.AsyncFileUpload pfileUpload, String puploadFolder, String psheetName, String pfileID)
        {
            System.Data.DataTable retval = null;
            try
            {
                if (pfileUpload.HasFile)
                {
                    string userSOEID = GetSOEID();
                    String _path = String.Empty;
                    String _fileName = String.Empty;
                    _fileName = pfileUpload.FileName;

                    //Save file
                    String uploadFolder = GetAppSetting("Upload_Folder");
                    uploadFolder += puploadFolder;

                    _path = System.Web.HttpContext.Current.Server.MapPath(uploadFolder);
                    _path = _path + pfileID + "_" + _fileName;
                    pfileUpload.SaveAs(_path);

                    string strConn = null;

                    strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + _path + ";Extended Properties=Excel 12.0;";

                    using (System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strConn))
                    {
                        conn.Open();
                        using (System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand("SELECT * FROM [" + psheetName + "$]", conn))
                        {
                            cmd.CommandType = System.Data.CommandType.Text;
                            using (System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(cmd))
                            {
                                retval = new System.Data.DataTable();
                                da.Fill(retval);
                            }
                        }
                        conn.Close();
                    }
                }
                else
                {
                    System.Web.HttpContext.Current.Session["uploadMessage"] = "UploadError: No file";
                }
            }
            catch (UtilException uEx)
            {
                if (uEx.OriginalException.ToString().Contains("user-defined table type requires 77 column"))
                {
                    System.Web.HttpContext.Current.Session["uploadMessage"] = "UploadError: The Sheet in the excel must be have 77 columns (ID, DepartmentID, Department, Process, Group, Activity, RecoverableTCD, OwnerSOEID, OwnerName, OwnerWorkPhone, OwnerHomePhone, OwnerAlternatePhone, OwnerEmail, BackupSOEID, BackupName, BackupWorkPhone, BackupHomePhone, BackupAlternatePhone, BackupEmail, BackupCenter, TCDSOEID, TCDName, TCDWorkPhone, TCDHomePhone, TCDAlternatePhone, TCDEmail, TCDCenter, GPLSOEID, GPLName, GPLWorkPhone, GPLHomePhone, GPLAlternatePhone, GPLEmail, GPLCenter, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, BD-14, BD-13, BD-12, BD-11, BD-10, BD-9, BD-8, BD-7, BD-6, BD-5, BD-4, BD-3, BD-2, BD-1, BD1, BD2, BD3, BD4, BD5, BD6, BD7, BD8, BD9, BD10, BD11, BD12, BD13, BD14, BD15, BD16, BD17, BD18, BD19, BD20, BD21, DocumentLink), please review witch columns are missing in your file.";
                }
                else
                {
                    System.Web.HttpContext.Current.Session["uploadMessage"] = "Exception: " + uEx.OriginalException.ToString();
                }
            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("'" + psheetName + "$' is not a valid name."))
                {
                    System.Web.HttpContext.Current.Session["uploadMessage"] = "UploadError: The Sheet name in the excel must be '" + psheetName + "'.";
                }
                else
                {
                    UtilException uEx = new UtilException(ex);
                    uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                    uEx.SoeidSession = GetSOEID();
                    uEx.SaveExceptionInBD();

                    System.Web.HttpContext.Current.Session["uploadMessage"] = "Exception: " + uEx.OriginalException.ToString();
                }
            }
            return retval;
        }
Example #11
0
        public static string GetConnectionString(string pkey)
        {
            string connString = "";
            try
            {
                // Get DLL configuration options
                string assemblyPath = new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath;
                Configuration cfg = ConfigurationManager.OpenExeConfiguration(assemblyPath);

                connString = cfg.ConnectionStrings.ConnectionStrings[pkey].ToString();
            }
            catch (UtilException uEx)
            {
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                uEx.SoeidSession = GetSOEID();
                uEx.SaveExceptionInBD();
                ShowErrorMessage(uEx);
            }
            catch (Exception ex)
            {
                UtilException uEx = new UtilException(ex);
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                uEx.SoeidSession = GetSOEID();
                uEx.SaveExceptionInBD();
                ShowErrorMessage(uEx);
            }
            return connString;
        }
Example #12
0
        public static String FastSQL(string pSQL, params SqlParameter[] arrParam)
        {
            String result = "";
            SqlConnection conn = null;
            SqlCommand comm = null;
            try
            {
                String LConnectionString = GetConnectionString("ConnString");
                conn = new SqlConnection(LConnectionString);
                comm = new SqlCommand(pSQL, conn);
                conn.Open();

                if (arrParam != null)
                {
                    foreach (SqlParameter param in arrParam)
                    {
                        comm.Parameters.Add(param);
                    }
                }

                SqlDataReader reader = comm.ExecuteReader();
                if (reader.Read())
                {
                    result = reader.GetString(0);
                }
            }
            catch (UtilException uEx)
            {
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                uEx.SoeidSession = GetSOEID();
                uEx.SaveExceptionInBD();
                ShowErrorMessage(uEx);
            }
            catch (Exception ex)
            {
                String extraInfo = "\n[SQL]:" + pSQL + " | \n[Params]:";
                foreach (SqlParameter param in arrParam)
                {
                    extraInfo = extraInfo + param.ParameterName + "=" + param.Value + ", ";
                }

                String OriginalExceptionClass = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
                String OriginalExceptionMethod = System.Reflection.MethodBase.GetCurrentMethod().Name;

                UtilException uEx = new UtilException(ex, extraInfo);
                uEx.StackTrace.Add(OriginalExceptionClass + " : " + OriginalExceptionMethod);
                uEx.SoeidSession = GetSOEID();
                uEx.SaveExceptionInBD();
                ShowErrorMessage(uEx);
            }
            finally
            {
                if (comm != null)
                {
                    comm.Dispose();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }

            return result;
        }
Example #13
0
 public static void ValidateUserLogin()
 {
     try
     {
         Microsoft.Practices.EnterpriseLibrary.Data.Database db = Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase("ConnString");
         using (System.Data.Common.DbCommand comm = db.GetStoredProcCommand("ASP_ValidateUserLogin"))
         {
             db.AddInParameter(comm, "@SOE_ID", System.Data.DbType.String, GetSOEID());
             db.ExecuteNonQuery(comm);
         }
     }
     catch (UtilException uEx)
     {
         uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
         uEx.SoeidSession = GetSOEID();
     }
     catch (Exception ex)
     {
         UtilException uEx = new UtilException(ex);
         uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
         uEx.SoeidSession = GetSOEID();
     }
 }
Example #14
0
        public static bool UserHasRol(string proleFormat)
        {
            var resultHasAccess = false;
            string[] roles;
            string[] stringSeparators = new string[] { "||" };
            try
            {
                roles = proleFormat.Split(stringSeparators, StringSplitOptions.None);
                var currentRoles = GetUserRoles(false);
                foreach (string roleName in roles)
                {
                    if (currentRoles.Contains(roleName))
                    {
                        resultHasAccess = true;
                    }
                }

                if (!resultHasAccess)
                {
                    if (!HttpContext.Current.Request.Url.AbsoluteUri.Contains("AccessDenied"))
                    {
                        HttpContext.Current.Response.Redirect("AccessDeniedToPage.aspx");
                    }
                }
            }
            catch (System.Threading.ThreadAbortException)
            {
                //Ignore Redirect Exception: System.Threading.ThreadAbortException: Thread was being aborted.
            }
            catch (UtilException uEx)
            {
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                uEx.SoeidSession = GetSOEID();
                throw uEx;
            }
            catch (Exception ex)
            {
                UtilException uEx = new UtilException(ex);
                uEx.OriginalExceptionClass = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
                uEx.OriginalExceptionMethod = System.Reflection.MethodBase.GetCurrentMethod().Name;
                uEx.StackTrace.Add(uEx.OriginalExceptionClass + " : " + uEx.OriginalExceptionMethod);
                uEx.SoeidSession = GetSOEID();
                throw uEx;
            }
            return resultHasAccess;
        }
Example #15
0
        public static string GetSOEID()
        {
            string SOEID = "";
            try
            {
                //Query String User
                string psoeid = HttpContext.Current.Request.QueryString["psoeid"];
                if (!String.IsNullOrEmpty(psoeid))
                {
                    HttpContext.Current.Session["TestUser"] = psoeid;
                    SOEID = psoeid;

                    //We can call this every where, but only once by post back is executed "sessionWasRefreshed"
                    RefreshSession();
                }
                else
                {
                    if (HttpContext.Current.Session["TestUser"] != null)
                    {
                        SOEID = HttpContext.Current.Session["TestUser"].ToString();
                    }
                }

                string pclear = HttpContext.Current.Request.QueryString["pclear"];
                if (!String.IsNullOrEmpty(pclear))
                {
                    HttpContext.Current.Session.Remove("TestUser");
                    SOEID = "";
                    //We can call this every where, but only once by post back is executed "sessionWasRefreshed"
                    RefreshSession();
                }

                //Priority to queryString
                if (!String.IsNullOrEmpty(SOEID))
                {
                    return SOEID;
                }

                //SSO User
                if (HttpContext.Current.Request.Headers.Get("SM_User") != null)
                {
                    SOEID = HttpContext.Current.Request.Headers.Get("SM_User").ToString();
                }

                //Try with Windows User if SSO not exists
                if (String.IsNullOrEmpty(SOEID))
                {
                    string UserLine = HttpContext.Current.User.Identity.Name.ToString();
                    if (!String.IsNullOrEmpty(UserLine))
                    {
                        string[] UserRow = UserLine.Split('\\');
                        SOEID = UserRow[1].ToUpper();
                    }
                }

                //Try with web.config User if SSO and Windows User not exist
                if (!String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["SOEIDOverride"]))
                {
                    SOEID = System.Configuration.ConfigurationManager.AppSettings["SOEIDOverride"].ToString();
                }
            }
            catch (UtilException uEx)
            {
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                uEx.SoeidSession = "Error Getting SOEID";
                uEx.SaveExceptionInBD();
                ShowErrorMessage(uEx);
            }
            catch (Exception ex)
            {
                UtilException uEx = new UtilException(ex);
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                uEx.SoeidSession = GetSOEID();
                uEx.SaveExceptionInBD();
                ShowErrorMessage(uEx);
            }

            if (!String.IsNullOrEmpty(SOEID))
            {
                return SOEID;
            }
            else
            {
                throw new Exception("GetSOEID() : [SOEID NOT FOUND] : No SOEID in Session");
            }
        }
Example #16
0
        public List<Dictionary<string, string>> getResultList(string pspDB, List<Dictionary<string, string>> pspDBParmas, List<Dictionary<string, string>> pcolsToSelect)
        {
            var resultList = new List<Dictionary<string, string>>();
            try
            {
                SqlCommand comm = SessionUtil.SQL_GetSPCommand(pspDB);

                if (pspDBParmas != null)
                {
                    foreach (var item in pspDBParmas)
                    {
                        comm.Parameters.Add(new SqlParameter(item["Name"], item["Value"]));
                    }
                }

                comm.Connection.Open();
                System.Data.SqlClient.SqlDataReader rdr = comm.ExecuteReader();

                while (rdr.Read())
                {
                    var rowData = new Dictionary<String, String>();

                    //Add columns information
                    foreach (var item in pcolsToSelect)
                    {
                        rowData.Add(item["Name"], rdr[item["Name"]].ToString());
                    }
                    resultList.Add(rowData);
                }

                comm.Connection.Close();
            }
            catch (UtilException uEx)
            {
                String extraInfo = "\n[SQL]:EXEC " + pspDB + " | \n[Params]:";
                extraInfo += "================================\n";

                foreach (var item in pspDBParmas)
                {
                    extraInfo += item["Name"] + ": [" + item["Value"] + "]\n";
                }

                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name) + ": " + extraInfo);
                throw uEx;
            }
            catch (Exception ex)
            {
                String extraInfo = "\n[SQL]:EXEC " + pspDB + " | \n[Params]:";
                extraInfo += "================================\n";

                if (pspDBParmas != null)
                {
                    foreach (var item in pspDBParmas)
                    {
                        extraInfo += item["Name"] + ": [" + item["Value"] + "]\n";
                    }
                }

                UtilException uEx = new UtilException(ex);
                uEx.OriginalExceptionClass = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name;
                uEx.OriginalExceptionMethod = System.Reflection.MethodBase.GetCurrentMethod().Name;
                uEx.StackTrace.Add(uEx.OriginalExceptionClass + " : " + uEx.OriginalExceptionMethod + ": " + extraInfo);
                throw uEx;
            }
            return resultList;
        }
Example #17
0
        public static List<Dictionary<string, string>> GetUpdatedUserPermits()
        {
            List<Dictionary<string, string>> userPermits = new List<Dictionary<string, string>>();
            try
            {
                userPermits.Add(new Dictionary<string, string>() {
                    {"IDPermit" , "1"},
                    {"PermitName" , "Upload files"},
                    {"HasAccess" , "1"}
                });
                //using (SqlCommand comm = SQL_GetSPCommand("FROU_spAdminSecurityUsersXPermitsList"))
                //{
                //    comm.Parameters.Add(new SqlParameter("@SOEID", GetSOEID()));

                //    // Execute the command
                //    comm.Connection.Open();
                //    System.Data.SqlClient.SqlDataReader rdr = comm.ExecuteReader();

                //    while (rdr.Read())
                //    {
                //        Dictionary<string, string> permitData = new Dictionary<string, string>();

                //        permitData.Add("IDPermit", rdr["IDPermit"].ToString());
                //        permitData.Add("PermitName", rdr["PermitName"].ToString());
                //        permitData.Add("HasAccess", rdr["HasAccess"].ToString());

                //        userPermits.Add(permitData);
                //    }

                //    comm.Connection.Close();
                //}
            }
            catch (UtilException uEx)
            {
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                uEx.SoeidSession = GetSOEID();
                uEx.SaveExceptionInBD();
                ShowErrorMessage(uEx);
            }
            catch (Exception ex)
            {
                UtilException uEx = new UtilException(ex);
                uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
                uEx.SoeidSession = GetSOEID();
                uEx.SaveExceptionInBD();
                ShowErrorMessage(uEx);
            }
            return userPermits;
        }