/// <summary>
        /// Remove Customer and associated information from Database
        /// </summary>
        /// <param name="customerID"></param>
        static public GlobalVars.ResultGeneric DeleteCustomer(int customerID)
        {
            GlobalVars.ResultGeneric result = new GlobalVars.ResultGeneric()
            {
                ReturnCode     = 0,
                Message        = "",
                RecordsCount   = 0,
                HttpStatusCode = ""
            };
            try
            {
                logger.Trace("Entering into DeleteCustomer Method ...");

                using (ScanningDBContext DB = new ScanningDBContext())
                {
                    Customers Matching_Result = DB.Customers.FirstOrDefault(x => x.CustomerId == customerID);
                    if (Matching_Result != null)
                    {
                        DB.Customers.Remove(Matching_Result);
                        DB.SaveChanges();
                        result.Message = "DeleteCustomer transaction completed successfully. One Record Deleted.";
                    }
                    else
                    {
                        result.ReturnCode = -1;
                        result.Message    = "Customer ID" + customerID + " does not exist. DeleteCustomer transaction ignore.";
                    }
                    logger.Debug(result.Message);
                }
            }
            catch (Exception e)
            {
                logger.Error("Error:" + e.Message + "\n" + "Exception: " + e.InnerException);
                result.ReturnCode = -2;
                result.Message    = e.Message;
                var baseException = e.GetBaseException();
                result.Exception = baseException.ToString();
            }
            logger.Trace("Leaving DeleteCustomer Method ...");
            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        static public GlobalVars.ResultGeneric ExistProjectID(int projectID)
        {
            List <GlobalVars.Project> projects = new List <GlobalVars.Project>();

            GlobalVars.ResultGeneric result = new GlobalVars.ResultGeneric()
            {
                ReturnCode     = 0,
                Message        = "",
                RecordsCount   = 0,
                HttpStatusCode = ""
            };
            try
            {
                logger.Trace("Entering into ExistProjectID Method ...");
                using (ScanningDBContext DB = new ScanningDBContext())
                {
                    var results = DB.Projects.Where(x => x.ProjectId == projectID);
                    result.RecordsCount = results.Count();
                    if (results.Count() >= 1)
                    {
                        result.Message = "Project ID " + projectID + " already exist.";
                    }
                    else
                    {
                        result.Message = "Project ID " + projectID + " doest not exist.";
                    }
                }
                logger.Debug(result.Message);
            }
            catch (Exception e)
            {
                logger.Error("Error:" + e.Message + "\n" + "Exception: " + e.InnerException);
                result.ReturnCode = -2;
                result.Message    = e.Message;
                var baseException = e.GetBaseException();
                result.Exception = baseException.ToString();
            }
            logger.Trace("Leaving ExistProjectID Method ...");
            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        static public GlobalVars.ResultGeneric ExistFieldName(int jobID, string fieldName)
        {
            List <GlobalVars.Field> fields = new List <GlobalVars.Field>();

            GlobalVars.ResultGeneric result = new GlobalVars.ResultGeneric()
            {
                ReturnCode     = 0,
                Message        = "",
                RecordsCount   = 0,
                HttpStatusCode = ""
            };
            try
            {
                logger.Trace("Entering into ExistJobFieldName Method ...");
                using (ScanningDBContext DB = new ScanningDBContext())
                {
                    var results = DB.JobsFields.Where(x => x.JobId == jobID & x.CpfieldName == fieldName);
                    result.RecordsCount = results.Count();
                    if (results.Count() >= 1)
                    {
                        result.Message = "Field Name" + fieldName + " for Job ID " + jobID + " already exist.";
                    }
                    else
                    {
                        result.Message = "Field Name" + fieldName + " for Job ID " + jobID + "  doest not exist.";
                    }
                }
                logger.Debug(result.Message);
            }
            catch (Exception e)
            {
                logger.Error("Error:" + e.Message + "\n" + "Exception: " + e.InnerException);
                result.ReturnCode = -2;
                result.Message    = e.Message;
                var baseException = e.GetBaseException();
                result.Exception = baseException.ToString();
            }
            logger.Trace("Leaving ExistJobFieldName Method ...");
            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        static public GlobalVars.ResultGeneric UpdateSMTP(GlobalVars.SMTP smtp)
        {
            GlobalVars.ResultGeneric result = new GlobalVars.ResultGeneric()
            {
                ReturnCode     = 0,
                Message        = "",
                RecordsCount   = 0,
                HttpStatusCode = ""
            };
            try
            {
                logger.Trace("Entering into UpdateSMTP Method ...");

                using (ScanningDBContext DB = new ScanningDBContext())
                {
                    // Customer Names must be unique in the Database. The Name could be change but it must be unique
                    Smtp Matching_Result = DB.Smtp.FirstOrDefault();
                    Smtp record          = new Smtp();
                    record.HostName           = smtp.HostName;
                    record.PortNumber         = smtp.PortNumber;
                    record.SenderEmailAddress = smtp.SenderEmailAddress;
                    record.SenderName         = smtp.SenderName;
                    record.UserName           = smtp.UserName;
                    record.Password           = smtp.Password;
                    record.EnableSslflag      = smtp.EnableSSLFlag.ToString();


                    if (Matching_Result == null)
                    {
                        // DB.Smtp.Add(record);
                        DB.Smtp.Add(record);
                        DB.SaveChanges();
                        result.Message = "There was not information associated to an SMTP Server, so new records was created successfully.";
                    }
                    else
                    {
                        // Means --> table has a record and it will be updated
                        Matching_Result.HostName           = smtp.HostName;
                        Matching_Result.PortNumber         = smtp.PortNumber;
                        Matching_Result.SenderEmailAddress = smtp.SenderEmailAddress;
                        Matching_Result.SenderName         = smtp.SenderName;
                        Matching_Result.UserName           = smtp.UserName;
                        Matching_Result.Password           = smtp.Password;
                        Matching_Result.SenderName         = record.SenderName;
                        DB.SaveChanges();
                        result.Message = "SMTP Inforation was updated successfully.";
                    }
                }
                logger.Debug(result.Message);
            }
            catch (Exception e)
            {
                logger.Error("Error:" + e.Message + "\n" + "Exception: " + e.InnerException);
                result.ReturnCode = -2;
                result.Message    = e.Message;
                var baseException = e.GetBaseException();
                result.Exception = baseException.ToString();
            }
            logger.Trace("Leaving UpdateSMTP Method ...");
            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// Get User Information by ID
        /// </summary>
        /// <returns></returns>
        static public GlobalVars.ResultUsers GetUserByID(int userID)
        {
            List <GlobalVars.User> users = new List <GlobalVars.User>();

            GlobalVars.ResultUsers resultUsers = new GlobalVars.ResultUsers()
            {
                ReturnCode     = 0,
                Message        = "",
                ReturnValue    = users,
                RecordsCount   = 0,
                HttpStatusCode = ""
            };
            try
            {
                logger.Trace("Entering into GetUserByID Method ...");
                using (ScanningDBContext DB = new ScanningDBContext())
                {
                    var results = DB.Users.Where(x => x.UserId == userID);
                    resultUsers.RecordsCount = results.Count();
                    if (results.Count() >= 1)
                    {
                        foreach (var x in results)
                        {
                            GlobalVars.User user = new GlobalVars.User()
                            {
                                UserID     = x.UserId,
                                UserName   = (x.UserName ?? "").Trim(),
                                Title      = x.Title,
                                Email      = x.Email,
                                ActiveFlag = Convert.ToBoolean(x.ActiveFlag)
                            };
                            var result_aux = from u in DB.UserUifunctionality
                                             join f in DB.Sssfunctionality on u.FunctionalityId equals f.FunctionalityId
                                             where u.UserId == x.UserId
                                             select new { f.FunctionalityId, f.Functionality };

                            List <GlobalVars.UIFunctionality> funtionalities = new List <GlobalVars.UIFunctionality>();
                            if (result_aux.Count() >= 1)
                            {
                                foreach (var y in result_aux)
                                {
                                    GlobalVars.UIFunctionality functionality = new GlobalVars.UIFunctionality();
                                    functionality.FunctionalityID = y.FunctionalityId;
                                    functionality.Description     = y.Functionality;
                                    funtionalities.Add(functionality);
                                }
                            }
                            user.UIFunctionality = funtionalities;
                            users.Add(user);
                        }
                    }
                }
                resultUsers.ReturnValue = users;
                resultUsers.Message     = "GetUserByID transaction completed successfully. Number of records found: " + resultUsers.RecordsCount;
                logger.Debug(resultUsers.Message);
            }
            catch (Exception e)
            {
                logger.Error("Error:" + e.Message + "\n" + "Exception: " + e.InnerException);
                resultUsers.ReturnCode = -2;
                resultUsers.Message    = e.Message;
                var baseException = e.GetBaseException();
                resultUsers.Exception = baseException.ToString();
            }
            logger.Trace("Leaving GetUserByID Method ...");
            return(resultUsers);
        }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        static public GlobalVars.ResultGeneric UpdateUser(GlobalVars.User user)
        {
            GlobalVars.ResultGeneric result = new GlobalVars.ResultGeneric()
            {
                ReturnCode     = 0,
                Message        = "",
                RecordsCount   = 0,
                HttpStatusCode = ""
            };
            try
            {
                logger.Trace("Entering into UpdateUser Method ...");

                using (ScanningDBContext DB = new ScanningDBContext())
                {
                    // User Name must be unique in the Database. The Name could be change but it must be unique
                    Users Matching_Result = DB.Users.FirstOrDefault(x => x.UserName == user.UserName);
                    if (Matching_Result != null)
                    {
                        // Means --> this is a new name
                        Matching_Result = DB.Users.FirstOrDefault(x => x.UserId == user.UserID);
                        if (Matching_Result != null)
                        {
                            Matching_Result.UserName   = user.UserName;
                            Matching_Result.Email      = user.Email;
                            Matching_Result.ActiveFlag = Convert.ToString(user.ActiveFlag);
                            Matching_Result.Title      = user.Title;
                            DB.SaveChanges();

                            // Update User UI Functionlaities
                            // 1- Delete existing all existimg UI Functinalities for this user
                            DB.UserUifunctionality.RemoveRange(DB.UserUifunctionality.Where(x => x.UserId == user.UserID));
                            DB.SaveChanges();

                            // 2- Add User Functionalities
                            UserUifunctionality New_Record = new UserUifunctionality();

                            foreach (GlobalVars.UIFunctionality functionlaity in user.UIFunctionality)
                            {
                                New_Record.FunctionalityId = functionlaity.FunctionalityID;
                                New_Record.UserId          = user.UserID;
                                DB.UserUifunctionality.Add(New_Record);
                                DB.SaveChanges();
                            }
                            result.Message = "UpdateUser transaction completed successfully. One Record Updated.";
                        }
                        else
                        {
                            // Means --> cannot update a Customer that does not exist
                            result.ReturnCode = -1;
                            result.Message    = "User " + user.UserName + " does not exist. UpdateUser transaction ignore.";
                        }
                    }
                    else
                    {
                        // Means --> the name already exist
                        result.ReturnCode = -1;
                        result.Message    = "User " + user.UserName + " already exist. UpdateUser transaction ignore.";
                    }
                }
                logger.Debug(result.Message);
            }
            catch (Exception e)
            {
                logger.Error("Error:" + e.Message + "\n" + "Exception: " + e.InnerException);
                result.ReturnCode = -2;
                result.Message    = e.Message;
                var baseException = e.GetBaseException();
                result.Exception = baseException.ToString();
            }
            logger.Trace("Leaving UpdateUser Method ...");
            return(result);
        }
Beispiel #7
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        static public GlobalVars.ResultGeneric NewUser(GlobalVars.User user)
        {
            GlobalVars.ResultGeneric result = new GlobalVars.ResultGeneric()
            {
                ReturnCode     = 0,
                Message        = "",
                RecordsCount   = 0,
                HttpStatusCode = ""
            };
            try
            {
                logger.Trace("Entering into NewUser Method ...");

                // Check if User Exist
                result = ExistUserName(user.UserName);
                if (result.RecordsCount == 0)
                {
                    // Create new User ...
                    using (ScanningDBContext DB = new ScanningDBContext())
                    {
                        Users New_Record = new Users();
                        New_Record.UserName   = user.UserName;
                        New_Record.Title      = user.Title;
                        New_Record.ActiveFlag = Convert.ToString(user.ActiveFlag);
                        New_Record.Email      = user.Email;

                        DB.Users.Add(New_Record);
                        DB.SaveChanges();
                    }

                    // Get the user ID created above, so it can be useed in UserUI Functionality Table below
                    GlobalVars.ResultUsers users = new GlobalVars.ResultUsers();
                    users = GetUserByName(user.UserName);

                    // Add User Functionalities ...
                    using (ScanningDBContext DB = new ScanningDBContext())
                    {
                        UserUifunctionality New_Record = new UserUifunctionality();

                        foreach (GlobalVars.UIFunctionality functionlaity in user.UIFunctionality)
                        {
                            New_Record.FunctionalityId = functionlaity.FunctionalityID;
                            New_Record.UserId          = user.UserID;
                            DB.UserUifunctionality.Add(New_Record);
                            DB.SaveChanges();
                        }
                    }
                    result.Message = "NewUser transaction completed successfully. One Record added.";
                }
                else
                {
                    result.ReturnCode = -1;
                    result.Message    = "User " + user.UserName + " already exist. NewUser transaction ignore.";
                }

                logger.Debug(result.Message);
            }
            catch (Exception e)
            {
                logger.Error("Error:" + e.Message + "\n" + "Exception: " + e.InnerException);
                result.ReturnCode = -2;
                result.Message    = e.Message;
                var baseException = e.GetBaseException();
                result.Exception = baseException.ToString();
            }
            logger.Trace("Leaving NewUser Method ...");
            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        static public GlobalVars.ResultGeneric UpdateField(GlobalVars.Field field)
        {
            GlobalVars.ResultGeneric result = new GlobalVars.ResultGeneric()
            {
                ReturnCode     = 0,
                Message        = "",
                RecordsCount   = 0,
                HttpStatusCode = ""
            };
            try
            {
                logger.Trace("Entering into UpdateField Method ...");

                using (ScanningDBContext DB = new ScanningDBContext())
                {
                    // Chedck if record exist in the Database
                    JobsFields Matching_Result = DB.JobsFields.FirstOrDefault(x => x.JobId == field.JobID & x.FieldId == field.FieldID);
                    if (Matching_Result != null)
                    {
                        // Means that Field exist in the Database.
                        // then, check if the field Name has changed
                        Matching_Result = DB.JobsFields.FirstOrDefault(x => x.JobId == field.JobID & x.FieldId == field.FieldID & x.CpfieldName == field.CPFieldName);
                        if (Matching_Result != null)
                        {
                            // Means that Field Name remain the same
                            Matching_Result.VfrfieldName         = field.VFRFieldName;
                            Matching_Result.KeyStrokeExcludeFlag = field.ExcludeFromKeystrokesCount.ToString();
                            DB.SaveChanges();
                            result.Message = "UpdateField transaction completed successfully. One Record Updated.";
                        }
                        else
                        {
                            // Means that the Field Name has Changed, so check if t he name has already been taking by another field
                            Matching_Result = DB.JobsFields.FirstOrDefault(x => x.JobId == field.JobID & x.FieldId != field.FieldID & x.CpfieldName == field.CPFieldName);
                            if (Matching_Result == null)
                            {
                                // Means that Field Name has changed
                                // Look for the record in the datbase so it can be updated
                                Matching_Result = DB.JobsFields.FirstOrDefault(x => x.JobId == field.JobID & x.FieldId == field.FieldID);
                                if (Matching_Result != null)
                                {
                                    Matching_Result.CpfieldName          = field.CPFieldName;
                                    Matching_Result.VfrfieldName         = field.VFRFieldName;
                                    Matching_Result.KeyStrokeExcludeFlag = field.ExcludeFromKeystrokesCount.ToString();
                                    DB.SaveChanges();
                                    result.Message = "UpdateField transaction completed successfully. One Record Updated.";
                                }
                            }
                            else
                            {
                                result.ReturnCode = -1;
                                result.Message    = "Field name " + field.CPFieldName.Trim() + " with Job ID " + field.JobID.ToString().Trim() + " already exists for this Job. UpdateField transaction ignore.";
                            }
                        }
                    }
                    else
                    {
                        // Means --> The field does not exist in the Database
                        result.ReturnCode = -1;
                        result.Message    = "Field " + field.CPFieldName.Trim() + " with Job ID " + field.JobID.ToString().Trim() + " does not exist. UpdateField transaction ignore.";
                    }
                }
                logger.Debug(result.Message);
            }
            catch (Exception e)
            {
                logger.Error("Error:" + e.Message + "\n" + "Exception: " + e.InnerException);
                result.ReturnCode = -2;
                result.Message    = e.Message;
                var baseException = e.GetBaseException();
                result.Exception = baseException.ToString();
            }
            logger.Trace("Leaving UpdateField Method ...");
            return(result);
        }
        /// <summary>
        /// Get Scanning Services Application Configuration File
        /// </summary>
        /// <returns></returns>
        static public SSSClientGlobalVars.ResultSSSConfig GetSSSConfig()
        {
            ScanningServicesDataObjects.SSSClientGlobalVars.ConfigSTR       SSSConfig       = new ScanningServicesDataObjects.SSSClientGlobalVars.ConfigSTR();
            ScanningServicesDataObjects.SSSClientGlobalVars.ResultSSSConfig resultSSSConfig = new ScanningServicesDataObjects.SSSClientGlobalVars.ResultSSSConfig()
            {
                ReturnCode     = 0,
                Message        = "",
                ReturnValue    = SSSConfig,
                RecordsCount   = 0,
                HttpStatusCode = ""
            };
            try
            {
                using (ScanningDBContext DB = new ScanningDBContext())
                {
                    //Get General Inforamtion, including Database information
                    GlobalVars.GeneralSettings generalSettings = new GlobalVars.GeneralSettings();
                    var resultGeneralSettings = DB.GeneralSettings.FirstOrDefault();
                    if (resultGeneralSettings != null)
                    {
                        SSSConfig.Debug = Convert.ToBoolean(resultGeneralSettings.DebugFlag);
                        SSSConfig.CaptureApplication = resultGeneralSettings.CpapplicationFilePath;
                        SSSConfig.ImageViewer        = resultGeneralSettings.ImageViewerFilePath;

                        SSSClientGlobalVars.DatabaseSTR database = new SSSClientGlobalVars.DatabaseSTR();
                        database.Server       = resultGeneralSettings.Dbserver;
                        database.UserName     = resultGeneralSettings.DbuserName;
                        database.Password     = resultGeneralSettings.Dbpassword;
                        database.Provider     = resultGeneralSettings.Dbprovider;
                        database.RDBMS        = resultGeneralSettings.Dbrdbms;
                        database.DatabaseName = resultGeneralSettings.Dbname;

                        // Add Database information to the SSSConfig Data Structure
                        SSSConfig.Database = database;
                    }
                    else
                    {
                        //There is no record for SMTP information in the database
                    }

                    //Get SMTP Information
                    GlobalVars.SMTP smtp      = new GlobalVars.SMTP();
                    var             resulSMTP = DB.Smtp.FirstOrDefault();
                    if (resulSMTP != null)
                    {
                        SSSClientGlobalVars.EmailSTR email = new SSSClientGlobalVars.EmailSTR();
                        email.Host          = resulSMTP.HostName;
                        email.Port          = Convert.ToString(resulSMTP.PortNumber);
                        email.SenderAddress = resulSMTP.SenderEmailAddress;
                        email.EnableSSL     = Convert.ToBoolean(resulSMTP.EnableSslflag);
                        email.SenderName    = resulSMTP.SenderName;
                        email.UserName      = resulSMTP.UserName;
                        email.Password      = resulSMTP.Password;
                        // Add Email information to the SSSConfig Data Structure
                        SSSConfig.Email = email;
                    }
                    else
                    {
                        //There is no record for SMTP information in the database
                    }

                    //Get Kodak Information
                    List <GlobalVars.JobExtended> jobs = new List <GlobalVars.JobExtended>();
                    int count      = 0;
                    var resultJobs = SQLFunctionsJobs.GetJobs(); //DB.Jobs;
                    if (resultJobs != null)
                    {
                        SSSClientGlobalVars.KodakSTR kodak = new SSSClientGlobalVars.KodakSTR();
                        kodak.JobTypes   = new List <string>();
                        kodak.StationsID = new List <string>();
                        kodak.JobOutpts  = new List <string>();
                        kodak.CaptureProScanDirectories = new List <string>();
                        foreach (var job in resultJobs.ReturnValue)
                        {
                            count++;
                            kodak.JobTypes.Add(job.JobName);
                            kodak.CaptureProScanDirectories.Add(job.ScanningFolder);
                            kodak.JobOutpts.Add(job.PostValidationWatchFolder);
                            kodak.StationsID.Add(Convert.ToString(count)); // Check if we are using Station ID for anything in SSS
                        }
                        // Add Kodak information to the SSSConfig Data Structure
                        SSSConfig.Kodak = kodak;
                    }
                    else
                    {
                        //There is no record for Jobs in the database
                    }

                    //Get Customer information
                    GlobalVars.ResultWorkingFolders resultWorkingFolders = new GlobalVars.ResultWorkingFolders();

                    List <GlobalVars.Customer> customers = new List <GlobalVars.Customer>();
                    var resultCustomers = DB.Customers;
                    if (resultCustomers != null)
                    {
                        SSSConfig.Customers = new List <SSSClientGlobalVars.CustomerSTR>();
                        foreach (var cust in resultCustomers)
                        {
                            SSSClientGlobalVars.CustomerSTR customer = new SSSClientGlobalVars.CustomerSTR();
                            customer.Name = cust.CustomerName;

                            // Get Jobs for a giben Customer ID
                            var customerJobs = from j in DB.Jobs
                                               join p in DB.Projects on j.ProjectId equals p.ProjectId
                                               join c in DB.Customers on p.CustomerId equals c.CustomerId
                                               where c.CustomerId == cust.CustomerId
                                               select new { j, c.CustomerId, c.CustomerName, p.ProjectName };
                            if (resultJobs != null)
                            {
                                customer.Projects = new List <SSSClientGlobalVars.CustomerProjectSTR>();
                                foreach (var job in customerJobs)
                                {
                                    resultWorkingFolders = SQLFunctionsGeneralSettings.GetWorkingFolderByID(job.j.RestingLocationId);
                                    if (resultWorkingFolders.RecordsCount > 0)
                                    {
                                        customer.BatchesLocation = resultWorkingFolders.ReturnValue[0].Path;
                                    }
                                    else
                                    {
                                        customer.BatchesLocation = "";
                                    }

                                    // We will use projects as Jobs
                                    SSSClientGlobalVars.CustomerProjectSTR customerProject = new SSSClientGlobalVars.CustomerProjectSTR();
                                    customerProject.Name        = job.ProjectName;
                                    customerProject.ExportClass = job.j.ExportClassName;

                                    // Get Job Fields to deterimine which one are Keystrokes fields
                                    var jobFields = DB.JobsFields.Where(x => x.JobId == job.j.JobId);
                                    if (resultCustomers != null)
                                    {
                                        customerProject.KeyStrokesExcludedFields = new List <string>();
                                        foreach (var field in jobFields)
                                        {
                                            if (field.KeyStrokeExcludeFlag.ToLower() == "true")
                                            {
                                                customerProject.KeyStrokesExcludedFields.Add(field.CpfieldName);
                                            }
                                        }
                                    }
                                    else
                                    {
                                    }

                                    // Get VFR Seetings
                                    customerProject.VFR = new SSSClientGlobalVars.VFRSTR();
                                    var vfrSetting = DB.Vfr.FirstOrDefault(x => x.JobId == job.j.JobId);
                                    if (vfrSetting != null)
                                    {
                                        customerProject.VFR.CADIWebServiceURL = vfrSetting.Cadiurl;
                                        customerProject.VFR.UserName          = vfrSetting.UserName;
                                        customerProject.VFR.Password          = vfrSetting.Password;
                                        customerProject.VFR.InstanceName      = vfrSetting.InstanceName;
                                        customerProject.VFR.RepositoryName    = vfrSetting.RepositoryName;
                                        customerProject.VFR.QueryField        = vfrSetting.QueryField;
                                    }
                                    else
                                    {
                                    }
                                    // Add Job information to the SSSConfig Data Structure
                                    customer.Projects.Add(customerProject);
                                }
                            }
                            else
                            {
                            }

                            // Get Customer Reports
                            var reports = from r in DB.Reports
                                          join t in DB.ReportsTemplate on r.TemplateId equals t.TemplateId
                                          join c in DB.Customers on r.CustomerId equals c.CustomerId
                                          where c.CustomerName == customer.Name
                                          select new { r, t.Name };

                            if (reports.Count() >= 1)
                            {
                                customer.Reports = new List <SSSClientGlobalVars.ReportSTR>();
                                foreach (var record in reports)
                                {
                                    SSSClientGlobalVars.ReportSTR report = new SSSClientGlobalVars.ReportSTR();
                                    report.Name = record.Name;

                                    report.Recipients = new List <string>();
                                    if (!string.IsNullOrEmpty(record.r.EmailRecipients))
                                    {
                                        string[] recipients = record.r.EmailRecipients.Split(",");
                                        foreach (string recipient in recipients)
                                        {
                                            report.Recipients.Add(recipient);
                                        }
                                    }

                                    report.Subject = record.r.EmailSubject;
                                    report.Enable  = Convert.ToBoolean(record.r.EnableFlag);

                                    SSSClientGlobalVars.ReportTitleSTR title1 = new SSSClientGlobalVars.ReportTitleSTR();
                                    title1.Content   = record.r.TitleContent1;
                                    title1.FontBold  = record.r.TitleFontBoldFlag1;
                                    title1.FontColor = record.r.TitleFontColor1;
                                    title1.FontSize  = Convert.ToString(record.r.TitleFontSize1);
                                    report.Title1    = title1;

                                    SSSClientGlobalVars.ReportTitleSTR title2 = new SSSClientGlobalVars.ReportTitleSTR();
                                    title2.Content   = record.r.TitleContent2;
                                    title2.FontBold  = record.r.TitleFontBoldFlag2;
                                    title2.FontColor = record.r.TitleFontColor2;
                                    title2.FontSize  = Convert.ToString(record.r.TitleFontSize2);
                                    report.Title2    = title2;

                                    SSSClientGlobalVars.ReportTitleSTR title3 = new SSSClientGlobalVars.ReportTitleSTR();
                                    title3.Content   = record.r.TitleContent3;
                                    title3.FontBold  = record.r.TitleFontBoldFlag3;
                                    title3.FontColor = record.r.TitleFontColor3;
                                    title3.FontSize  = Convert.ToString(record.r.TitleFontSize3);
                                    report.Title3    = title3;

                                    SSSClientGlobalVars.ReportTableSTR table = new SSSClientGlobalVars.ReportTableSTR();
                                    table.HeaderBackGroundColor = record.r.TableHeaderBackColor;
                                    table.HeaderFontBold        = record.r.TableHeaderFontBoldFlag;
                                    table.HeaderFontColor       = record.r.TableHeaderFontColor;
                                    table.HeaderFontSize        = Convert.ToString(record.r.TableHeaderFontSize.Value);
                                    //TableColumnNamesBackColor = record.r.TableColumnNamesBackColor,
                                    //TableColumnNamesFontBoldFlag = Convert.ToBoolean(record.r.TableColumnNamesFontBoldFlag),
                                    //TableColumnNamesFontColor = record.r.TableColumnNamesFontColor,
                                    //TableColumnNamesFontSize = record.r.TableColumnNamesFontSize.Value,
                                    report.ReportTable = table;

                                    var parameters = from rp in DB.ReportParameters
                                                     join rtp in DB.ReportsTemplateParameters on rp.ParameterId equals rtp.ParameterId
                                                     where (rp.ReportId == record.r.ReportId && rp.TemplateId == record.r.TemplateId)
                                                     select new { rp, rtp.Name };

                                    if (parameters.Count() >= 1)
                                    {
                                        report.Parameters = new List <SSSClientGlobalVars.ReportParameterSTR>();
                                        foreach (var p in parameters)
                                        {
                                            SSSClientGlobalVars.ReportParameterSTR parameter = new SSSClientGlobalVars.ReportParameterSTR();
                                            parameter.Name  = p.Name;
                                            parameter.Value = p.rp.Value;
                                            report.Parameters.Add(parameter);
                                        }
                                    }
                                    customer.Reports.Add(report);
                                }
                            }

                            // Add Customer information to the SSSConfig Data Structure
                            SSSConfig.Customers.Add(customer);
                        }
                    }
                    else
                    {
                        //There is no record for Jobs in the database
                    }

                    // Add System Reports to the SSSConfig Data Structure
                    // Get Customer Reports
                    var systemReports = from r in DB.Reports
                                        join t in DB.ReportsTemplate on r.TemplateId equals t.TemplateId
                                        where r.CustomerId == 0
                                        select new { r, t.Name };

                    if (systemReports.Count() >= 1)
                    {
                        SSSConfig.Reports = new List <SSSClientGlobalVars.ReportSTR>();
                        foreach (var record in systemReports)
                        {
                            SSSClientGlobalVars.ReportSTR report = new SSSClientGlobalVars.ReportSTR();
                            report.Name = record.Name;

                            report.Recipients = new List <string>();
                            if (!string.IsNullOrEmpty(record.r.EmailRecipients))
                            {
                                string[] recipients = record.r.EmailRecipients.Split(",");
                                foreach (string recipient in recipients)
                                {
                                    report.Recipients.Add(recipient);
                                }
                            }

                            report.Subject = record.r.EmailSubject;
                            report.Enable  = Convert.ToBoolean(record.r.EnableFlag);

                            SSSClientGlobalVars.ReportTitleSTR title1 = new SSSClientGlobalVars.ReportTitleSTR();
                            title1.Content   = record.r.TitleContent1;
                            title1.FontBold  = record.r.TitleFontBoldFlag1;
                            title1.FontColor = record.r.TitleFontColor1;
                            title1.FontSize  = Convert.ToString(record.r.TitleFontSize1);
                            report.Title1    = title1;

                            SSSClientGlobalVars.ReportTitleSTR title2 = new SSSClientGlobalVars.ReportTitleSTR();
                            title2.Content   = record.r.TitleContent2;
                            title2.FontBold  = record.r.TitleFontBoldFlag2;
                            title2.FontColor = record.r.TitleFontColor2;
                            title2.FontSize  = Convert.ToString(record.r.TitleFontSize2);
                            report.Title2    = title2;

                            SSSClientGlobalVars.ReportTitleSTR title3 = new SSSClientGlobalVars.ReportTitleSTR();
                            title3.Content   = record.r.TitleContent3;
                            title3.FontBold  = record.r.TitleFontBoldFlag3;
                            title3.FontColor = record.r.TitleFontColor3;
                            title3.FontSize  = Convert.ToString(record.r.TitleFontSize3);
                            report.Title3    = title3;

                            SSSClientGlobalVars.ReportTableSTR table = new SSSClientGlobalVars.ReportTableSTR();
                            table.HeaderBackGroundColor = record.r.TableHeaderBackColor;
                            table.HeaderFontBold        = record.r.TableHeaderFontBoldFlag;
                            table.HeaderFontColor       = record.r.TableHeaderFontColor;
                            table.HeaderFontSize        = Convert.ToString(record.r.TableHeaderFontSize.Value);
                            //TableColumnNamesBackColor = record.r.TableColumnNamesBackColor,
                            //TableColumnNamesFontBoldFlag = Convert.ToBoolean(record.r.TableColumnNamesFontBoldFlag),
                            //TableColumnNamesFontColor = record.r.TableColumnNamesFontColor,
                            //TableColumnNamesFontSize = record.r.TableColumnNamesFontSize.Value,
                            report.ReportTable = table;

                            var parameters = from rp in DB.ReportParameters
                                             join rtp in DB.ReportsTemplateParameters on rp.ParameterId equals rtp.ParameterId
                                             where (rp.ReportId == record.r.ReportId && rp.TemplateId == record.r.TemplateId)
                                             select new { rp, rtp.Name };

                            if (parameters.Count() >= 1)
                            {
                                report.Parameters = new List <SSSClientGlobalVars.ReportParameterSTR>();
                                foreach (var p in parameters)
                                {
                                    SSSClientGlobalVars.ReportParameterSTR parameter = new SSSClientGlobalVars.ReportParameterSTR();
                                    parameter.Name  = p.Name;
                                    parameter.Value = p.rp.Value;
                                    report.Parameters.Add(parameter);
                                }
                            }
                            SSSConfig.Reports.Add(report);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                logger.Error("Error:" + e.Message + "\n" + "Exception: " + e.InnerException);
                resultSSSConfig.ReturnCode = -2;
                resultSSSConfig.Message    = e.Message;
                var baseException = e.GetBaseException();
                resultSSSConfig.Exception = baseException.ToString();
                return(resultSSSConfig);
            }

            logger.Trace("Leaving GetCustomerByID Method ...");
            return(resultSSSConfig);
        }
Beispiel #10
0
        /// <summary>
        /// The Update Method creates a new records if it does not exist
        /// </summary>
        /// <returns></returns>
        static public GlobalVars.ResultGeneric UpdateVFRInfo(GlobalVars.VFR vfr)
        {
            GlobalVars.ResultGeneric result = new GlobalVars.ResultGeneric()
            {
                ReturnCode     = 0,
                Message        = "",
                RecordsCount   = 0,
                HttpStatusCode = ""
            };
            try
            {
                logger.Trace("Entering into UpdateVFRInfo Method ...");

                using (ScanningDBContext DB = new ScanningDBContext())
                {
                    // Customer Names must be unique in the Database. The Name could be change but it must be unique
                    Vfr Matching_Result = DB.Vfr.FirstOrDefault(x => x.JobId == vfr.JobID);
                    Vfr record          = new Vfr();
                    record.Cadiurl         = vfr.CADIUrl;
                    record.CaptureTemplate = vfr.CaptureTemplate;
                    record.InstanceName    = vfr.InstanceName;
                    record.JobId           = vfr.JobID;
                    //record.SettingId = vfr.SettingID;
                    record.Password       = vfr.Password;
                    record.UserName       = vfr.UserName;
                    record.RepositoryName = vfr.RepositoryName;
                    record.QueryField     = vfr.QueryField;
                    if (Matching_Result == null)
                    {
                        DB.Vfr.Add(record);
                        DB.SaveChanges();
                        result.Message = "There was not information associated to an VFR Server, so new records was created successfully.";
                    }
                    else
                    {
                        // Means --> table has a record and it will be updated
                        Matching_Result.Cadiurl         = vfr.CADIUrl;
                        Matching_Result.CaptureTemplate = vfr.CaptureTemplate;
                        Matching_Result.InstanceName    = vfr.InstanceName;
                        Matching_Result.JobId           = vfr.JobID;
                        //Matching_Result.SettingId = vfr.SettingID;
                        Matching_Result.Password       = vfr.Password;
                        Matching_Result.UserName       = vfr.UserName;
                        Matching_Result.RepositoryName = vfr.RepositoryName;
                        Matching_Result.QueryField     = vfr.QueryField;

                        DB.SaveChanges();
                        result.Message = "VFR Inforation was updated successfully.";
                    }
                }
                logger.Debug(result.Message);
            }
            catch (Exception e)
            {
                logger.Error("Error:" + e.Message + "\n" + "Exception: " + e.InnerException);
                result.ReturnCode = -2;
                result.Message    = e.Message;
                var baseException = e.GetBaseException();
                result.Exception = baseException.ToString();
            }
            logger.Trace("Leaving UpdateVFRInfo Method ...");
            return(result);
        }