Exemplo n.º 1
0
        public static void updatePassword(int USERID, string PASSWORD)
        {
            DateTime now = DateTime.Now;

            try
            {
                ZXPUserData zxpUD       = ZXPUserData.GetZXPUserDataFromCookie();
                string      sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;
                using (var scope = new TransactionScope())
                {
                    string sqlCmdText;
                    //sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;

                    ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "Password", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, DataTransformer.PasswordHash(PASSWORD).ToString(), null, "UserID", USERID.ToString());
                    cl.CreateChangeLogEntryIfChanged();

                    sqlCmdText = "UPDATE dbo.Users SET Password = @Password WHERE UserID = @UserID";
                    SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@Password", DataTransformer.PasswordHash(PASSWORD)),
                                            new SqlParameter("@UserID", USERID));
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_Users GetPODetailsFromMSID(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
                throw ex;
            }
        }
        public static void DisableDockSpot(int SPOTID)
        {
            DateTime now = DateTime.Now;

            try
            {
                ZXPUserData zxpUD = ZXPUserData.GetZXPUserDataFromCookie();
                using (var scope = new TransactionScope())
                {
                    string sqlCmdText;
                    //sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;

                    ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "TruckDockSpots", "isDisabled", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, "'true'", null, "SpotID", SPOTID.ToString());
                    cl.CreateChangeLogEntryIfChanged();

                    sqlCmdText = "UPDATE dbo.TruckDockSpots SET isDisabled = 'true' WHERE SpotID = @SpotID";
                    SqlHelper.ExecuteNonQuery(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@SpotID", SPOTID));

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_DockSpots DisableDockSpot(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
                throw ex;
            }
        }
Exemplo n.º 3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         ZXPUserData zxpUD = ZXPUserData.GetZXPUserDataFromCookie();
         if (zxpUD._uid != new ZXPUserData()._uid)
         {
             if (!zxpUD._isAdmin) //make sure this matches whats in Site.Master and Default
             {
                 Response.BufferOutput = true;
                 Response.Redirect("ErrorPage.aspx?ErrorCode=5", false); //zxp live url
             }
         }
         else
         {
             Response.BufferOutput = true;
             Response.Redirect("Account/Login.aspx?ReturnURL=~/AdminMainPage.aspx", false);//zxp live url
         }
     }
     catch (SqlException excep)
     {
         string strErr = " SQLException Error in Admin_Users Page_Load(). Details: " + excep.ToString();
         ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
         System.Web.HttpContext.Current.Session["ErrorNum"] = 2;
         ErrorLogging.sendtoErrorPage(2);
     }
     catch (Exception ex)
     {
         string strErr = " Exception Error in Admin_Users Page_Load(). Details: " + ex.ToString();
         ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
         System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
         ErrorLogging.sendtoErrorPage(1);
     }
 }
        public static void UpdateDockSpot(int SPOTID, string SPOTDESCRIPTION, string SPOTTYPE, string HOURSINTIMEBLOCK)
        {
            DateTime now = DateTime.Now;

            try
            {
                ZXPUserData zxpUD = ZXPUserData.GetZXPUserDataFromCookie();
                using (var scope = new TransactionScope())
                {
                    string sqlCmdText;
                    //sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;

                    SqlParameter paramSpotID           = new SqlParameter("@SpotID", SqlDbType.Int);
                    SqlParameter paramSpotType         = new SqlParameter("@SpotType", SqlDbType.NVarChar);
                    SqlParameter paramSpotDescription  = new SqlParameter("@SpotDescription", SqlDbType.NVarChar);
                    SqlParameter paramHoursInTimeBlock = new SqlParameter("@HoursInTimeBlock", SqlDbType.Float);

                    paramSpotID.Value           = SPOTID;
                    paramSpotType.Value         = SPOTTYPE;
                    paramSpotDescription.Value  = SPOTDESCRIPTION;
                    paramHoursInTimeBlock.Value = HOURSINTIMEBLOCK;

                    sqlCmdText = "SELECT COUNT(SpotID) FROM dbo.TruckDockSpots WHERE (isDisabled = 'false') AND (SpotDescription = @SpotDescription) AND SpotID != @SpotID";
                    int hasRows = Convert.ToInt32(SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@SpotDescription", SPOTDESCRIPTION),
                                                                          new SqlParameter("@SpotID", SPOTID)));


                    if (hasRows == 0)
                    {
                        ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "TruckDockSpots", "SpotDescription", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, SPOTDESCRIPTION.ToString(), null, "SpotID", SPOTID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "TruckDockSpots", "SpotType", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, SPOTTYPE.ToString(), null, "SpotID", SPOTID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "TruckDockSpots", "HoursInTimeBlock", now, zxpUD._uid, ChangeLog.ChangeLogDataType.FLOAT, HOURSINTIMEBLOCK.ToString(), null, "SpotID", SPOTID.ToString());
                        cl.CreateChangeLogEntryIfChanged();

                        sqlCmdText = "UPDATE dbo.TruckDockSpots SET SpotType = @SpotType, SpotDescription = @SpotDescription, HoursInTimeBlock = @HoursInTimeBlock WHERE SpotID = @SpotID";
                        SqlHelper.ExecuteNonQuery(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@SpotType", SPOTTYPE),
                                                  new SqlParameter("@SpotDescription", SPOTDESCRIPTION),
                                                  new SqlParameter("@HoursInTimeBlock", HOURSINTIMEBLOCK),
                                                  new SqlParameter("@SpotID", SPOTID));
                    }
                    else
                    {//if it does exist, throw exception
                        throw new Exception("Another spot with that name already exist");
                    }
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_DockSpots UpdateDockSpot(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
                throw ex;
            }
        }
        protected void BtnLogin_Click(object sender, EventArgs e)
        {
            ZXPUserData zxpUD = GetLoginCredentials();

            try
            {
                if (zxpUD._uid > 0)
                {
                    AuditLog aLog = new AuditLog(zxpUD._uid);
                    aLog.createNewAuditLogEntry(aLog);

                    string strUserData = zxpUD.SerializeZXPUserData(zxpUD);

                    System.Web.Security.FormsAuthenticationTicket ticket = new System.Web.Security.FormsAuthenticationTicket(1, LoginControl.UserName, DateTime.Now, DateTime.Now.AddDays(5), LoginControl.RememberMeSet, strUserData);
                    string enticket = System.Web.Security.FormsAuthentication.Encrypt(ticket);
                    System.Web.HttpCookie authcookie = new System.Web.HttpCookie(System.Web.Security.FormsAuthentication.FormsCookieName, enticket);
                    if (ticket.IsPersistent)
                    {
                        authcookie.Expires = ticket.Expiration;
                    }
                    Response.Cookies.Add(authcookie);


                    string logMsg = string.Concat("btnLogin_click : ", zxpUD._UserName, " cookie: ", authcookie.Value.ToString());
                    ErrorLogging.WriteEvent(logMsg, EventLogEntryType.Information);

                    string pageURL = System.Web.Security.FormsAuthentication.GetRedirectUrl(LoginControl.UserName, LoginControl.RememberMeSet);
                    Response.Redirect(pageURL);

                    // Response.Redirect(pageURL, false);
                    // Context.ApplicationInstance.CompleteRequest(); // end response
                }
                else
                {
                    string ErrorText = "Login failed. Please check your Username and Password and try again.";
                    string pageURL   = Request.Url.AbsolutePath + "?ErrorText=" + ErrorText;
                    Response.Redirect(pageURL);
                    // Response.Redirect(pageURL, false);
                    //Context.ApplicationInstance.CompleteRequest(); // end response
                }
            }
            catch (System.Threading.ThreadAbortException ex)
            {
                ex.ToString();
                //do nothing - caused by response.redirect
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Login BtnLogin_Click(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
            }
        }
        public static int SetNewSpot(string SPOTDESCRIPTION, string SPOTTYPE, float HOURSINTIMENBLOCK)
        {
            Int32    SpotID = 0;
            DateTime now    = DateTime.Now;

            try
            {
                ZXPUserData zxpUD = ZXPUserData.GetZXPUserDataFromCookie();
                using (var scope = new TransactionScope())
                {
                    string sqlCmdText;
                    //sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;

                    sqlCmdText = "SELECT COUNT(SpotID) FROM dbo.TruckDockSpots WHERE (isDisabled = 'false') AND (SpotDescription = @SpotDescription)";
                    int hasRows = Convert.ToInt32(SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@SpotDescription", SPOTDESCRIPTION)));

                    if (hasRows == 0)
                    {
                        sqlCmdText = "INSERT INTO dbo.TruckDockSpots (SpotDescription, SpotType, HoursInTimeBlock, isDisabled) " +
                                     "VALUES (@SpotDescription, @SpotType, @HoursInTimeBlock, 'false'); " +
                                     "SELECT CAST(scope_identity() AS int)";
                    }
                    else
                    {//if it does exist, throw exception
                        throw new Exception("The combination of Spot Name and Spot Type already exist");
                    }
                    SpotID = Convert.ToInt32(SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@SpotDescription", SPOTDESCRIPTION),
                                                                     new SqlParameter("@SpotType", SPOTTYPE),
                                                                     new SqlParameter("@HoursInTimeBlock", HOURSINTIMENBLOCK)));

                    ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "TruckDockSpots", "SpotDescription", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, SPOTDESCRIPTION.ToString(), null, "SpotID", SpotID.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "TruckDockSpots", "SpotType", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, SPOTTYPE.ToString(), null, "SpotID", SpotID.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "TruckDockSpots", "HoursInTimeBlock", now, zxpUD._uid, ChangeLog.ChangeLogDataType.FLOAT, HOURSINTIMENBLOCK.ToString(), null, "SpotID", SpotID.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "TruckDockSpots", "isDisabled", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, "'false'", null, "SpotID", SpotID.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_DockSpots SetNewSpot(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
                throw ex;
            }
            return(SpotID);
        }
        public static void updatePatternAndProcessFile(int PATTERNID, string FILENAME)
        {
            DateTime now = DateTime.Now;

            try
            {
                ZXPUserData zxpUD          = ZXPUserData.GetZXPUserDataFromCookie();
                string[]    newFileAndPath = TransportHelperFunctions.ProcessFileAndData(FILENAME, "PATTERN");

                if (2 == newFileAndPath.Length)
                {
                    using (var scope = new TransactionScope())
                    {
                        string sqlCmdText;
                        //sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;
                        string filepath    = ConfigurationManager.AppSettings["fileUploadPath"];
                        string newFilePath = string.Empty;
                        newFilePath = filepath + ConfigurationManager.AppSettings["PATTERNPATH"];
                        newFilePath = newFilePath.Replace("~/", "").Replace('/', '\\');

                        ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Patterns", "FileNameOld", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, FILENAME.ToString(), null, "PatternID", PATTERNID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Patterns", "FileNameNew", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, newFileAndPath[1].ToString(), null, "PatternID", PATTERNID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Patterns", "FilePath", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, newFileAndPath[0].ToString(), null, "PatternID", PATTERNID.ToString());
                        cl.CreateChangeLogEntryIfChanged();

                        sqlCmdText = "UPDATE dbo.Patterns " +
                                     "SET FileNameOld = @FileNameOld, FileNameNew = @FileNameNew, FilePath = @FilePath " +
                                     "WHERE PatternID = @PatternID";
                        SqlHelper.ExecuteNonQuery(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@FileNameOld", FILENAME),
                                                  new SqlParameter("@FileNameNew", newFileAndPath[1]),
                                                  new SqlParameter("@FilePath", newFileAndPath[0]),
                                                  new SqlParameter("@PatternID", PATTERNID));
                        scope.Complete();
                    }
                }
                else
                {
                    throw new Exception("renameAndMoveFile returned null or empty string");
                }
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_Patterns updatePatternAndProcessFile(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
                throw ex;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //HttpCookie cookie = Request.Cookies[System.Web.Security.FormsAuthentication.FormsCookieName];
                //if (null != cookie && !string.IsNullOrEmpty(cookie.Value))

                ZXPUserData zxpUD = ZXPUserData.GetZXPUserDataFromCookie();
                if (zxpUD._uid != new ZXPUserData()._uid)
                {
                    //ZXPUserData zxpUD = ZXPUserData.GetZXPUserDataFromCookie();

                    if (zxpUD._isAdmin) //make sure this matches whats in Site.Master and Default
                    {
                        sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;
                        if (sql_connStr == String.Empty)
                        {
                            throw new Exception("Missing SQLConnectionString in web.config");
                        }
                    }
                    else
                    {
                        Response.BufferOutput = true;
                        Response.Redirect("ErrorPage.aspx?ErrorCode=5", false); //zxp live url
                    }
                }
                else
                {
                    Response.BufferOutput = true;
                    Response.Redirect("Account/Login.aspx?ReturnURL=~/AdminMainPage.aspx", false);//zxp live url
                }
            }
            catch (SqlException excep)
            {
                string strErr = " SQLException Error in Admin_DockSpots Page_Load(). Details: " + excep.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 2;
                ErrorLogging.sendtoErrorPage(2);
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_DockSpots Page_Load(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
            }
        }
        public static void updateTank(int TANKID, string TANKNAME, decimal CAPACITY, decimal CURRENTVOL)
        {
            DateTime now = DateTime.Now;

            try
            {
                ZXPUserData zxpUD = ZXPUserData.GetZXPUserDataFromCookie();
                using (var scope = new TransactionScope())
                {
                    string sqlCmdText;
                    //sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;

                    if (CAPACITY <= 0)
                    {
                        throw new Exception("Max capacity can not be 0.");
                    }
                    else if (CAPACITY < CURRENTVOL)
                    {
                        throw new Exception("Current capacity can not be a greater volume than the max capcity.");
                    }
                    else if (CURRENTVOL < 0)
                    {
                        throw new Exception("Current capacity can not be less than 0.");
                    }
                    sqlCmdText = "UPDATE dbo.Tanks SET TankName = @TankName, TankCapacity = @TankCapacity, CurrentTankVolume = @CurrentTankVolume WHERE TankID = @TankID";
                    SqlHelper.ExecuteNonQuery(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@TankName", TANKNAME),
                                              new SqlParameter("@TankCapacity", CAPACITY),
                                              new SqlParameter("@CurrentTankVolume", CURRENTVOL),
                                              new SqlParameter("@TankID", TANKID));
                    //No errors
                    ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Tanks", "TankName", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, TANKNAME.ToString(), null, "TankID", TANKID.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Tanks", "TankCapacity", now, zxpUD._uid, ChangeLog.ChangeLogDataType.DECIMAL, CAPACITY.ToString(), null, "TankID", TANKID.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_Tanks updateTank(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
                throw ex;
            }
        }
        public static int insertPatternToDBEntry(string FILENAMEOLD, string FILENAMENEW, string FILEPATH, string PATTERNNAME)
        {
            Int32    patternID = 0;
            DateTime now       = DateTime.Now;

            try
            {
                ZXPUserData zxpUD = ZXPUserData.GetZXPUserDataFromCookie();
                using (var scope = new TransactionScope())
                {
                    string sqlCmdText;
                    //sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;

                    sqlCmdText = "INSERT INTO dbo.Patterns (FileNameOld, FileNameNew, FilePath, PatternName, isHidden) VALUES (@FileNameOld, @FileNameNew, @FilePath, @PatternName, 'false'); " +
                                 "SELECT CAST(scope_identity() AS int)";
                    patternID = Convert.ToInt32(SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@FileNameOld", FILENAMEOLD),
                                                                        new SqlParameter("@FileNameNew", FILENAMENEW),
                                                                        new SqlParameter("@FilePath", FILEPATH),
                                                                        new SqlParameter("@PatternName", PATTERNNAME)));

                    ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Patterns", "FileNameOld", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, FILENAMEOLD.ToString(), null, "PatternID", patternID.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Patterns", "FileNameNew", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, FILENAMENEW.ToString(), null, "PatternID", patternID.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Patterns", "FilePath", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, FILEPATH.ToString(), null, "PatternID", patternID.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Patterns", "PatternName", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, PATTERNNAME.ToString(), null, "PatternID", patternID.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Patterns", "isHidden", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, "'false'", null, "PatternID", patternID.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_Patterns insertPatternToDBEntry(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
                throw ex;
            }
            return(patternID);
        }
        public static void updatePatternName(int PATTERNID, string PATTERNNAME)
        {
            int      rowCount;
            DateTime now = DateTime.Now;

            try
            {
                ZXPUserData zxpUD = ZXPUserData.GetZXPUserDataFromCookie();
                using (var scope = new TransactionScope())
                {
                    string sqlCmdText;
                    //sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;

                    sqlCmdText = "SELECT COUNT (*) FROM dbo.Patterns " +
                                 "WHERE PatternName = @PatternName AND isHidden = 'false' AND PatternID != @PatternID";
                    rowCount = Convert.ToInt32(SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@PatternName", PATTERNNAME),
                                                                       new SqlParameter("@PatternID", PATTERNID)));
                    if (rowCount <= 0)
                    {
                        ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Patterns", "PatternName", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, PATTERNNAME.ToString(), null, "PatternID", PATTERNID.ToString());
                        cl.CreateChangeLogEntryIfChanged();

                        sqlCmdText = "UPDATE dbo.Patterns SET PatternName = @PatternName WHERE PatternID = @PatternID";
                        SqlHelper.ExecuteNonQuery(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@PatternName", PATTERNNAME),
                                                  new SqlParameter("@PatternID", PATTERNID));
                    }
                    else
                    {
                        throw new Exception("Pattern name already exist");
                    }
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_Patterns updatePatternName(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
                throw ex;
            }
        }
Exemplo n.º 12
0
        public ZXPUserData GetLoginCredentials()
        {
            ZXPUserData     zxpUD   = new ZXPUserData();
            List <object[]> data    = new List <object[]>();
            DataSet         dataSet = new DataSet();

            try
            {
                using (var scope = new TransactionScope())
                {
                    string sqlCmdText;

                    string sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;

                    string hashedPassword = MD5Hash(LoginControl.Password);

                    sqlCmdText = "SELECT TOP 1 UserID, isAdmin,  isDockManager,  isInspector,  isGuard,  isLabPersonel,  isLoader,  isYardMule, canViewReports, isLabAdmin, isAccountManager," +
                                 "UserName, FirstName, LastName FROM dbo.Users WHERE [Password] = @UPASS AND UserName = @UNAME AND isDisabled = 0";
                    dataSet = SqlHelper.ExecuteDataset(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@UNAME", LoginControl.UserName), new SqlParameter("@UPASS", hashedPassword));

                    //populate return object
                    foreach (System.Data.DataRow row in dataSet.Tables[0].Rows)
                    {
                        zxpUD = new ZXPUserData(Convert.ToInt32(row.ItemArray[0]), true, Convert.ToBoolean(row.ItemArray[1]), Convert.ToBoolean(row.ItemArray[2]), Convert.ToBoolean(row.ItemArray[3]),
                                                Convert.ToBoolean(row.ItemArray[4]), Convert.ToBoolean(row.ItemArray[5]), Convert.ToBoolean(row.ItemArray[6]), Convert.ToBoolean(row.ItemArray[7]),
                                                Convert.ToBoolean(row.ItemArray[8]), Convert.ToBoolean(row.ItemArray[9]), Convert.ToBoolean(row.ItemArray[10]), Convert.ToString(row.ItemArray[11]),
                                                Convert.ToString(row.ItemArray[12]), Convert.ToString(row.ItemArray[13]));
                    }
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Login GetLoginCredentials(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
                throw ex;
            }
            return(zxpUD);
        }
Exemplo n.º 13
0
        public static int setNewUserAlert(int USERID, int ALERTID, int ALERTTYPE)
        {
            Int32    userAlertID = 0;
            DateTime now         = DateTime.Now;

            try
            {
                ZXPUserData zxpUD = ZXPUserData.GetZXPUserDataFromCookie();
                using (var scope = new TransactionScope())
                {
                    string sqlCmdText;
                    //sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;

                    sqlCmdText = "INSERT INTO dbo.UserAlerts (UserID, AlertID, AlertType, isDisabled) VALUES (@UserID, @AlertID, @AlertType, 'false')" +
                                 "SELECT CAST(scope_identity() AS int)";
                    userAlertID = Convert.ToInt32(SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@UserID", USERID),
                                                                          new SqlParameter("@AlertID", ALERTID),
                                                                          new SqlParameter("@AlertType", ALERTTYPE)));

                    ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "UserAlerts", "UserID", now, zxpUD._uid, ChangeLog.ChangeLogDataType.INT, USERID.ToString(), null, "AlertUserID", userAlertID.ToString(), "UserID", zxpUD._uid.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "UserAlerts", "AlertID", now, zxpUD._uid, ChangeLog.ChangeLogDataType.INT, ALERTID.ToString(), null, "AlertUserID", userAlertID.ToString(), "UserID", zxpUD._uid.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "UserAlerts", "AlertType", now, zxpUD._uid, ChangeLog.ChangeLogDataType.INT, ALERTTYPE.ToString(), null, "AlertUserID", userAlertID.ToString(), "UserID", zxpUD._uid.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "UserAlerts", "isDisabled", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, "'false'", null, "AlertUserID", userAlertID.ToString(), "UserID", zxpUD._uid.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_UserAlerts setNewUserAlert(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
                throw ex;
            }
            return(userAlertID);
        }
        public static Object setNewPatternAndProcessFile(string PATTERNNAME, string FILENAME)
        {
            Int32         patternID = 0;
            List <string> data      = new List <string>();
            Int32         rowCount;
            DateTime      now = DateTime.Now;

            try
            {
                ZXPUserData zxpUD          = ZXPUserData.GetZXPUserDataFromCookie();
                string[]    newFileAndPath = TransportHelperFunctions.ProcessFileAndData(FILENAME, "PATTERN");

                if (2 == newFileAndPath.Length)
                {
                    using (var scope = new TransactionScope())
                    {
                        string sqlCmdText;
                        //sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;

                        sqlCmdText = "SELECT COUNT (*) FROM dbo.Patterns " +
                                     "WHERE PatternName = @PatternName AND isHidden = 'false'";
                        rowCount = Convert.ToInt32(SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@PatternName", PATTERNNAME)));

                        if (rowCount <= 0)
                        {
                            sqlCmdText = "INSERT INTO dbo.Patterns (FileNameOld, FileNameNew, FilePath, PatternName, isHidden) VALUES (@FileNameOld, @FileNameNew, @FilePath, @PatternName, 'false'); " +
                                         "SELECT CAST(scope_identity() AS int)";

                            patternID = Convert.ToInt32(SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@FileNameOld", FILENAME),
                                                                                new SqlParameter("@FileNameNew", newFileAndPath[1]),
                                                                                new SqlParameter("@FilePath", newFileAndPath[0]),
                                                                                new SqlParameter("@PatternName", PATTERNNAME)));

                            ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Patterns", "isHidden", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, "'false'", null, "PatternID", patternID.ToString());
                            cl.CreateChangeLogEntryIfChanged();
                            cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Patterns", "FileNameOld", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, FILENAME.ToString(), null, "PatternID", patternID.ToString());
                            cl.CreateChangeLogEntryIfChanged();
                            cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Patterns", "FileNameNew", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, newFileAndPath[1].ToString(), null, "PatternID", patternID.ToString());
                            cl.CreateChangeLogEntryIfChanged();
                            cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Patterns", "PatternName", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, PATTERNNAME.ToString(), null, "PatternID", patternID.ToString());
                            cl.CreateChangeLogEntryIfChanged();
                            cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Patterns", "FilePath", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, PATTERNNAME.ToString(), null, "PatternID", patternID.ToString());
                            cl.CreateChangeLogEntryIfChanged();

                            data.Add(patternID.ToString());
                            data.Add(newFileAndPath[0]);
                            data.Add(newFileAndPath[1]);
                        }
                        else
                        {
                            throw new Exception("Pattern name already exist");
                        }
                        scope.Complete();
                    }
                }
                else
                {
                    throw new Exception("renameAndMoveFile returned null or empty string");
                }
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_Patterns setNewPatternAndProcessFile(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
                throw ex;
            }
            return(data);
        }
        public static void disableCustomer(string CUSTOMERID)
        {
            SqlConnection sqlConn = new SqlConnection();
            SqlCommand    sqlCmd;
            DateTime      now = DateTime.Now;

            try
            {
                ZXPUserData zxpUD = ZXPUserData.GetZXPUserDataFromCookie();
                using (var scope = new TransactionScope())
                {
                    // TransactionScope scope = new TransactionScope();
                    sqlConn = new SqlConnection();
                    sqlCmd  = new SqlCommand();

                    sqlConn = new SqlConnection(sql_connStr);
                    sqlConn.Open();

                    SqlParameter paramCustomerID_CMS = new SqlParameter("@CustomerID_CMS", SqlDbType.Char);

                    paramCustomerID_CMS.Value = CUSTOMERID;

                    sqlCmd.Parameters.Clear();
                    sqlCmd.Parameters.Add(paramCustomerID_CMS);

                    //connects to DB
                    sqlCmd.Connection  = sqlConn;
                    sqlCmd.CommandText = "UPDATE dbo.CustomersVendorsProducts " +
                                         "SET isDisabled = 'true' " +
                                         "WHERE CustomerID_CMS = @CustomerID_CMS";
                    ///////////////////////////////David 4-20-16
                    ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "CustomersVendorsProducts", "isDisabled", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, "'true'", null, "CustomerProductID", CUSTOMERID.ToString());
                    cl.CreateChangeLogEntryIfChanged(sqlConn);
                    //////////////////////////////////////
                    sqlCmd.ExecuteNonQuery();


                    scope.Complete();
                }
            }//end of try
            catch (SqlException excep)
            {
                string strErr = " SQLException Error in Admin_CustomerVendorProducts disableCustomer(). Details: " + excep.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 2;
                ErrorLogging.sendtoErrorPage(2);
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_CustomerVendorProducts disableCustomer(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
            }
            finally
            {
                if (sqlConn != null && sqlConn.State != ConnectionState.Closed)
                {
                    sqlConn.Close();
                    sqlConn.Dispose();
                }
            }
        }//end of disableCustomer(string CUSTOMERID)
Exemplo n.º 16
0
        public static void updateUser(int USERID, string USERNAME, string FIRSTNAME, string LASTNAME, string EMAIL, string CELLPHONENUMBER, int?CELLPHONEPROVIDER, bool ADMIN, bool DOCKMANAGER, bool INSPECTOR, bool GUARD, bool LABPERSONEL, bool LOADER, bool YARDMULE, bool LABADMIN, bool REPORTER, bool ACCTMANAGER)
        {
            DateTime now = DateTime.Now;

            try
            {
                ZXPUserData zxpUD       = ZXPUserData.GetZXPUserDataFromCookie();
                string      sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;
                using (var scope = new TransactionScope())
                {
                    string sqlCmdText;

                    if (CELLPHONENUMBER == null && CELLPHONEPROVIDER == null)
                    {
                        ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "UserName", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, USERNAME.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "FirstName", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, FIRSTNAME.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "LastName", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, LASTNAME.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "EmailAddress", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, EMAIL.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isAdmin", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, ADMIN.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isDockManager", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, DOCKMANAGER.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isInspector", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, INSPECTOR.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isGuard", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, GUARD.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isLabPersonel", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, LABPERSONEL.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isLoader", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, LOADER.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isYardMule", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, YARDMULE.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "canViewReports", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, REPORTER.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isLabAdmin", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, LABADMIN.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Users", "isAccountManager", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, ACCTMANAGER.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "Phone", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, "NULL", null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "CellProviderID", now, zxpUD._uid, ChangeLog.ChangeLogDataType.INT, "NULL", null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();

                        sqlCmdText = "UPDATE dbo.Users SET UserName = @UserName, FirstName = @FirstName, LastName = @LastName, EmailAddress = @EmailAddress, isAdmin = @isAdmin, isDockManager = @isDockManager, isInspector = @isInspector, " +
                                     "isGuard = @isGuard, isLabPersonel = @isLabPersonel, isLoader = @isLoader, isYardMule = @isYardMule, isLabAdmin = @isLabAdmin, canViewReports = @canViewReports, isAccountManager = @isAccountManager, " +
                                     "Phone = null, CellProviderID = null WHERE UserID = @UserID";
                        SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@UserName", USERNAME),
                                                new SqlParameter("@FirstName", FIRSTNAME),
                                                new SqlParameter("@LastName", LASTNAME),
                                                new SqlParameter("@EmailAddress", EMAIL),
                                                new SqlParameter("@Password", DataTransformer.PasswordHash("ZXPpassword1!")),
                                                new SqlParameter("@isAdmin", ADMIN),
                                                new SqlParameter("@isDockManager", DOCKMANAGER),
                                                new SqlParameter("@isInspector", INSPECTOR),
                                                new SqlParameter("@isGuard", GUARD),
                                                new SqlParameter("@isLabPersonel", LABPERSONEL),
                                                new SqlParameter("@isLoader", LOADER),
                                                new SqlParameter("@isYardMule", YARDMULE),
                                                new SqlParameter("@canViewReports", REPORTER),
                                                new SqlParameter("@isLabAdmin", LABADMIN),
                                                new SqlParameter("@isAccountManager", ACCTMANAGER),
                                                new SqlParameter("@UserID", USERID));
                    }
                    else if (CELLPHONEPROVIDER != null && CELLPHONENUMBER != null)
                    {
                        ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "UserName", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, USERNAME.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "FirstName", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, FIRSTNAME.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "LastName", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, LASTNAME.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "EmailAddress", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, EMAIL.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isAdmin", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, ADMIN.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isDockManager", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, DOCKMANAGER.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isInspector", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, INSPECTOR.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isGuard", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, GUARD.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isLabPersonel", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, LABPERSONEL.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isLoader", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, LOADER.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isYardMule", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, YARDMULE.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "canViewReports", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, REPORTER.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "isLabAdmin", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, LABADMIN.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Users", "isAccountManager", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, ACCTMANAGER.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "Phone", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, CELLPHONENUMBER.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();
                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "Users", "CellProviderID", now, zxpUD._uid, ChangeLog.ChangeLogDataType.INT, CELLPHONEPROVIDER.ToString(), null, "UserID", USERID.ToString());
                        cl.CreateChangeLogEntryIfChanged();

                        sqlCmdText = "UPDATE dbo.Users SET UserName = @UserName, FirstName = @FirstName, LastName = @LastName, EmailAddress = @EmailAddress, Phone = @Phone, CellProviderID = @CellProviderID, " +
                                     "isAdmin = @isAdmin, isDockManager = @isDockManager, isInspector = @isInspector, isGuard = @isGuard, isLabPersonel = @isLabPersonel, isLoader = @isLoader, isYardMule = @isYardMule, " +
                                     "isLabAdmin = @isLabAdmin, canViewReports = @canViewReports, isAccountManager = @isAccountManager WHERE UserID = @UserID";
                        SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@UserName", USERNAME),
                                                new SqlParameter("@FirstName", FIRSTNAME),
                                                new SqlParameter("@LastName", LASTNAME),
                                                new SqlParameter("@EmailAddress", EMAIL),
                                                new SqlParameter("@Phone", CELLPHONENUMBER),
                                                new SqlParameter("@CellProviderID", CELLPHONEPROVIDER),
                                                new SqlParameter("@Password", DataTransformer.PasswordHash("ZXPpassword1!")),
                                                new SqlParameter("@isAdmin", ADMIN),
                                                new SqlParameter("@isDockManager", DOCKMANAGER),
                                                new SqlParameter("@isInspector", INSPECTOR),
                                                new SqlParameter("@isGuard", GUARD),
                                                new SqlParameter("@isLabPersonel", LABPERSONEL),
                                                new SqlParameter("@isLoader", LOADER),
                                                new SqlParameter("@isYardMule", YARDMULE),
                                                new SqlParameter("@canViewReports", REPORTER),
                                                new SqlParameter("@isLabAdmin", LABADMIN),
                                                new SqlParameter("@isAccountManager", ACCTMANAGER),
                                                new SqlParameter("@UserID", USERID));
                    }
                    else if (CELLPHONEPROVIDER == null && CELLPHONENUMBER != null)
                    {
                        throw new Exception("Trying to add a cell phone provider without a cell phone number to a user.");
                    }
                    else if (CELLPHONEPROVIDER != null && CELLPHONENUMBER == null)
                    {
                        throw new Exception("Trying to add a cell phone number without a cell phone provider to a user.");
                    }
                    else
                    {
                        throw new Exception("Username already exists");
                    }
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_Users updateUser(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
                throw ex;
            }
        }
        public static int setNewTank(string TANKNAME, decimal CAPACITY, decimal CURRENTVOL)
        {
            Int32    tankID = 0;
            DateTime now    = DateTime.Now;

            try
            {
                ZXPUserData zxpUD = ZXPUserData.GetZXPUserDataFromCookie();
                using (var scope = new TransactionScope())
                {
                    string sqlCmdText;
                    //sql_connStr = new TruckScheduleConfigurationKeysHelper().sql_connStr;

                    if (CAPACITY <= 0)
                    {
                        throw new Exception("Max capacity can not be 0.");
                    }
                    else if (CAPACITY < CURRENTVOL)
                    {
                        throw new Exception("Current capacity can not be a greater volume than the max capcity.");
                    }
                    else if (CURRENTVOL < 0)
                    {
                        throw new Exception("Current capacity can not be less than 0.");
                    }

                    //checks to see if a tank with that name exsist
                    sqlCmdText = "SELECT COUNT(*) FROM dbo.Tanks WHERE (TankName = @TankName) AND (isDisabled = 'false')";
                    int tankCount = Convert.ToInt32(SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@TankName", TANKNAME)));

                    //checks to see if tank exists
                    if (tankCount == 0)
                    {
                        //if it doesnt exist, go ahead and create tank
                        sqlCmdText = "INSERT INTO dbo.Tanks (TankName, TankCapacity, CurrentTankVolume, isDisabled) VALUES (@TankName, @TankCapacity, @CurrentVol, 'false'); " +
                                     "SELECT CAST(scope_identity() AS int)";
                        tankID = Convert.ToInt32(SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@TankName", TANKNAME),
                                                                         new SqlParameter("@TankCapacity", CAPACITY),
                                                                         new SqlParameter("@CurrentVol", CURRENTVOL)));
                    }
                    else
                    {//if it does exist, throw exception
                        throw new Exception("A tank by that name already exist");
                    }

                    ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Tanks", "TankName", now, zxpUD._uid, ChangeLog.ChangeLogDataType.NVARCHAR, TANKNAME.ToString(), null, "TankID", tankID.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Tanks", "TankCapacity", now, zxpUD._uid, ChangeLog.ChangeLogDataType.DECIMAL, CAPACITY.ToString(), null, "TankID", tankID.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "Tanks", "isDisabled", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, "'false'", null, "TankID", tankID.ToString());
                    cl.CreateChangeLogEntryIfChanged();
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_Tanks setNewTank(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
                throw ex;
            }
            return(tankID);
        }
        public static void updateProduct(int CUSTOMERPROUDCTID, string PRODUCTID_CMS, string CUSTOMERID_CMS)
        {
            SqlConnection sqlConn  = new SqlConnection();
            SqlCommand    sqlCmd   = new SqlCommand();
            int           rowCount = 0;
            DateTime      now      = DateTime.Now;

            try
            {
                using (var scope = new TransactionScope())
                {
                    ZXPUserData zxpUD = ZXPUserData.GetZXPUserDataFromCookie();
                    sqlConn = new SqlConnection();
                    sqlCmd  = new SqlCommand();
                    sqlConn = new SqlConnection(sql_connStr);


                    if (sqlConn.State != ConnectionState.Open)
                    {
                        sqlConn.Open();
                    }

                    //Connects to DB
                    sqlCmd.Connection = sqlConn;
                    SqlParameter paramProductID_CMS     = new SqlParameter("@ProductID_CMS", SqlDbType.Char);
                    SqlParameter paramCustomerProductID = new SqlParameter("@CustomerProductID", SqlDbType.Int);
                    SqlParameter paramCustomerID_CMS    = new SqlParameter("@CustomerID_CMS", SqlDbType.Char);

                    paramCustomerProductID.Value = CUSTOMERPROUDCTID;
                    paramProductID_CMS.Value     = PRODUCTID_CMS;
                    paramCustomerID_CMS.Value    = CUSTOMERID_CMS;

                    sqlCmd.Parameters.Clear();
                    sqlCmd.Parameters.Add(paramCustomerProductID);
                    sqlCmd.Parameters.Add(paramProductID_CMS);
                    sqlCmd.Parameters.Add(paramCustomerID_CMS);


                    sqlCmd.CommandText = "SELECT COUNT(*) FROM dbo.CustomersVendorsProducts as CVP " +
                                         "WHERE (CVP.CustomerID_CMS = @CustomerID_CMS AND CVP.ProductID_CMS = @ProductID_CMS AND CVP.isDisabled = 'false')";

                    rowCount = (int)sqlCmd.ExecuteScalar();
                    if (rowCount == 0)
                    {     ///////////////////////////////David 4-20-16
                        ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.UPDATE, "CustomersVendorsProducts", "PRODUCTID_CMS", now, zxpUD._uid, ChangeLog.ChangeLogDataType.CHAR, CUSTOMERID_CMS.ToString(), null, "CustomerProductID", CUSTOMERPROUDCTID.ToString());
                        cl.CreateChangeLogEntryIfChanged(sqlConn);
                        //////////////////////////////////////
                        sqlCmd.CommandText = "UPDATE dbo.CustomersVendorsProducts SET PRODUCTID_CMS = @PRODUCTID_CMS WHERE CustomerProductID = @CustomerProductID";
                        sqlCmd.ExecuteNonQuery();
                    }
                    else
                    {//if it does exist, throw exception
                        throw new Exception("This product already exist with this customer");
                    }
                    scope.Complete();
                }
            }
            catch (SqlException excep)
            {
                string strErr = " SQLException Error in Admin_CustomerVendorProducts updateProduct(). Details: " + excep.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 2;
                ErrorLogging.sendtoErrorPage(2);
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_CustomerVendorProducts updateProduct(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
            }
            finally
            {
                if (sqlConn != null && sqlConn.State != ConnectionState.Closed)
                {
                    sqlConn.Close();
                    sqlConn.Dispose();
                }
            }
        } //end of updateProduct(int CUSTOMERPROUDCTID, string PRODUCTID_CMS)
Exemplo n.º 19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string errorText = Request.QueryString["ErrorText"];
                if (!string.IsNullOrEmpty(errorText))
                {
                    LabelError.Text = errorText;
                }
                else
                {
                    LabelError.Text = string.Empty;
                }
                HttpCookie cookie       = Request.Cookies[FormsAuthentication.FormsCookieName];
                string     isLoggingOut = Request.QueryString["out"];
                if (null != cookie && !string.IsNullOrEmpty(cookie.Value))
                {
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
                    ZXPUserData zxpUD = new ZXPUserData();
                    zxpUD = ZXPUserData.DeserializeZXPUserData(ticket.UserData);
                    LoginControl.UserName = zxpUD._UserName;


                    if (zxpUD._isValid)
                    {
                        if (zxpUD.hasLoaderOrYMAccessOnly() && string.IsNullOrEmpty(isLoggingOut))
                        {
                            Response.Redirect("/loaderMobile.aspx", false);
                            Context.ApplicationInstance.CompleteRequest(); // end response
                        }
                        else
                        {
                            Response.Redirect("/default.aspx", false);
                            Context.ApplicationInstance.CompleteRequest(); // end response
                        }
                        LabelError.Text = "Already logged in. Please navigate to the page you would like to see by using the links in the menu above.";
                    }
                    else
                    {
                        if (zxpUD.hasLoaderOrYMAccessOnly())
                        {
                            Response.Redirect("/loaderMobile.aspx", false);
                            Context.ApplicationInstance.CompleteRequest(); // end response
                        }
                        else
                        {
                            String pageURL = FormsAuthentication.GetRedirectUrl(LoginControl.UserName, LoginControl.RememberMeSet);
                            Response.Redirect(pageURL, false);
                            Context.ApplicationInstance.CompleteRequest(); // end response
                        }
                    }
                    AuditLog aLog = new AuditLog(zxpUD._uid);
                    aLog.createNewAuditLogEntry(aLog);
                }

                if (!string.IsNullOrEmpty(isLoggingOut))
                {
                    int  islogout      = 0;
                    bool isValidLogout = int.TryParse(isLoggingOut, out islogout);
                    if (isValidLogout && 1 == islogout)
                    {
                        Session.Abandon();
                        System.Web.Security.FormsAuthentication.SignOut();
                    }
                }
            }
            catch (System.Threading.ThreadAbortException ex)
            {
                ex.ToString();
                //do nothing - caused by response.redirect
            }
            catch (SqlException excep)
            {
                string strErr = " SQLException Error in Login Page_Load(). Details: " + excep.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 2;
                ErrorLogging.sendtoErrorPage(2);
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Login Page_Load(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
            }
        }
        public static int setNewProductToCustomer(string CUSTOMERID_CMS, string PRODUCTID_CMS)
        {
            SqlConnection sqlConn          = new SqlConnection();
            SqlCommand    sqlCmd           = new SqlCommand();
            Int32         CustProd_ComboID = 0;
            int           rowCount         = 0;
            DateTime      now = DateTime.Now;

            try
            {
                ZXPUserData zxpUD = ZXPUserData.GetZXPUserDataFromCookie();
                using (var scope = new TransactionScope())
                {
                    sqlConn = new SqlConnection();
                    sqlCmd  = new SqlCommand();
                    sqlConn = new SqlConnection(sql_connStr);


                    if (sqlConn.State != ConnectionState.Open)
                    {
                        sqlConn.Open();
                    }

                    //Connects to DB
                    sqlCmd.Connection = sqlConn;
                    SqlParameter paramCustomerID_CMS = new SqlParameter("@CustomerID_CMS", SqlDbType.Char);
                    SqlParameter paramProductID_CMS  = new SqlParameter("@ProductID_CMS", SqlDbType.Char);

                    paramCustomerID_CMS.Value = CUSTOMERID_CMS;
                    paramProductID_CMS.Value  = PRODUCTID_CMS;

                    sqlCmd.Parameters.Clear();
                    sqlCmd.Parameters.Add(paramCustomerID_CMS);
                    sqlCmd.Parameters.Add(paramProductID_CMS);


                    sqlCmd.CommandText = "SELECT COUNT(*) FROM dbo.CustomersVendorsProducts as CVP " +
                                         "WHERE (CVP.CustomerID_CMS = @CustomerID_CMS AND CVP.ProductID_CMS = @ProductID_CMS AND CVP.isDisabled = 'false')";

                    rowCount = (int)sqlCmd.ExecuteScalar();
                    if (rowCount == 0)
                    {
                        sqlCmd.CommandText = "INSERT INTO dbo.CustomersVendorsProducts (CustomerID_CMS, ProductID_CMS, isDisabled) " +
                                             "VALUES (@CustomerID_CMS, @ProductID_CMS, 'false'); " +
                                             "SELECT CAST(scope_identity() AS int)";
                        CustProd_ComboID = (int)sqlCmd.ExecuteScalar();
                        ///////////////////////////////David 4-20-16
                        ChangeLog cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "CustomersVendorsProducts", "CustomerID_CMS", now, zxpUD._uid, ChangeLog.ChangeLogDataType.CHAR, CUSTOMERID_CMS.ToString(), null, "CustomerProductID", CustProd_ComboID.ToString());
                        cl.CreateChangeLogEntryIfChanged(sqlConn);

                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "CustomersVendorsProducts", "ProductID_CMS", now, zxpUD._uid, ChangeLog.ChangeLogDataType.CHAR, PRODUCTID_CMS.ToString(), null, "CustomerProductID", CustProd_ComboID.ToString());
                        cl.CreateChangeLogEntryIfChanged(sqlConn);

                        cl = new ChangeLog(ChangeLog.ChangeLogChangeType.INSERT, "CustomersVendorsProducts", "isDisabled", now, zxpUD._uid, ChangeLog.ChangeLogDataType.BIT, "'false'", null, "CustomerProductID", CustProd_ComboID.ToString());
                        cl.CreateChangeLogEntryIfChanged(sqlConn);
                        ////////////////////////////////////////////
                    }
                    else
                    {
                        throw new Exception("This product already exist with this customer");
                    }
                    scope.Complete();
                }
            }
            catch (SqlException excep)
            {
                string strErr = " SQLException Error in Admin_CustomerVendorProducts setNewProductToCustomer(). Details: " + excep.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 2;
                ErrorLogging.sendtoErrorPage(2);
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_CustomerVendorProducts setNewProductToCustomer(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
            }
            finally
            {
                if (sqlConn != null && sqlConn.State != ConnectionState.Closed)
                {
                    sqlConn.Close();
                    sqlConn.Dispose();
                }
            }
            return((int)CustProd_ComboID);
        } //end of setNewProductToCustomer(string CUSTOMERID_CMS, int PRODUCTID_CMS)