public static string[] renameAndMoveFile(string filename)
        {
            string[] pathObj  = new string[3];
            string   filepath = ConfigurationManager.AppSettings["fileUploadPath"];

            filepath = filepath.Replace("~/", string.Empty).Replace('/', '\\');
            filename = filename.Replace("~/", string.Empty).Replace('/', '\\');

            string newFilePath = string.Empty;
            string newFilename = Path.GetFileNameWithoutExtension(filename) + TransportHelperFunctions.getTimestamp(DateTime.UtcNow) + Path.GetExtension(filename);

            if (File.Exists(HttpRuntime.AppDomainAppPath + filepath + filename))
            {
                newFilePath = filepath + ConfigurationManager.AppSettings["PatternsPath"];

                newFilePath = newFilePath.Replace("~/", "").Replace('/', '\\');
                newFilename = newFilename.Replace("~/", "").Replace('/', '\\');

                File.Move(HttpRuntime.AppDomainAppPath + filepath + filename, HttpRuntime.AppDomainAppPath + newFilePath + newFilename);
                ErrorLogging.WriteEvent(HttpRuntime.AppDomainAppPath + filepath + filename, EventLogEntryType.Information);
                ErrorLogging.WriteEvent(HttpRuntime.AppDomainAppPath + newFilePath + newFilename, EventLogEntryType.Information);

                pathObj[0] = filename;
                pathObj[1] = newFilename;
                pathObj[2] = HttpRuntime.AppDomainAppPath + newFilePath;
            }
            return(pathObj);
        }
        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;
            }
        }
        public static string[] ProcessFileAndData(string filename, string strUploadType)
        {
            try
            {
                string[] newFileAndPath = TransportHelperFunctions.ProcessFileAndData(filename, strUploadType);
                return(newFileAndPath);
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_Patterns ProcessFileAndData(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
            }

            return(null);
        }
        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);
        }
Esempio n. 5
0
        public static Object setNewInspectionSetNewTestAndAssociate(string INSPECTIONHEADERNAME, int INSPECTIONTYPEID, string LOADTYPE, bool IS2RUNNER, int SORTORDER, string TESTTEXT, bool ISDEALBREAKER)
        {
            List <string> data = new List <string>();
            Int32         InspectionHeaderID = 0;
            Int32         TestID             = 0;

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

                    // Query 1: create inspection header
                    sqlCmdText = "INSERT INTO dbo.InspectionHeader (InspectionHeaderName, InspectionTypeID, LoadType, needsVerificationTest, isDisabled) VALUES " +
                                 "(@InspectionHeaderName, @InspectionTypeID, @LoadType, @is2Runner, 'false') " +
                                 "SELECT CAST(scope_identity() AS int)";
                    InspectionHeaderID = Convert.ToInt32(SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@InspectionHeaderName", INSPECTIONHEADERNAME),
                                                                                 new SqlParameter("@InspectionTypeID", INSPECTIONTYPEID),
                                                                                 new SqlParameter("@LoadType", TransportHelperFunctions.convertStringEmptyToDBNULL(LOADTYPE)),
                                                                                 new SqlParameter("@is2Runner", IS2RUNNER)));
                    // Query 2: create test
                    sqlCmdText = "INSERT INTO dbo.InspectionTestTemplates (TestDescription) VALUES (@TestDescription) " +
                                 "SELECT CAST(scope_identity() AS int)";
                    TestID = Convert.ToInt32(SqlHelper.ExecuteScalar(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@TestDescription", TESTTEXT)));
                    //Query 3: set new test to new inspection
                    sqlCmdText = "INSERT INTO dbo.InspectionHeaderDetails (InspectionHeaderID, TestID, SortOrder, isDealBreaker, isDisabled) VALUES (@InspectionHeaderID, @TestID, @SortOrder, @isDealBreaker, 'false') ";
                    SqlHelper.ExecuteNonQuery(sql_connStr, CommandType.Text, sqlCmdText, new SqlParameter("@InspectionHeaderID", InspectionHeaderID),
                                              new SqlParameter("@TestID", TestID),
                                              new SqlParameter("@SortOrder", SORTORDER),
                                              new SqlParameter("@isDealBreaker", ISDEALBREAKER));
                    data.Add(InspectionHeaderID.ToString());
                    data.Add(TestID.ToString());
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                string strErr = " Exception Error in Admin_Inspections setNewInspectionSetNewTestAndAssociate(). Details: " + ex.ToString();
                ErrorLogging.WriteEvent(strErr, EventLogEntryType.Error);
                System.Web.HttpContext.Current.Session["ErrorNum"] = 1;
                ErrorLogging.sendtoErrorPage(1);
                throw ex;
            }
            return(data);
        }