/// <summary>
        /// Marks the given JT_Technician record as being the currently-selected
        /// technician by setting the IsCurrent flag on the local database record.
        /// </summary>
        /// <param name="technician">The JT_Technician object/record to mark as current.</param>
        public void SaveTechnicianAsCurrent(JT_Technician technician)
        {
            // dch rkl 12/08/2016 add try/catch to capture exception

            try
            {
                int rows = 0;

                lock (_locker)
                {
                    // Unset any techs that are marked as "current"
                    List <JT_Technician> currentTechnicians = _database.Table <JT_Technician>().Where(t => t.IsCurrent == true).ToList();
                    if (currentTechnicians.Count > 0)
                    {
                        foreach (JT_Technician technicianInList in currentTechnicians)
                        {
                            technicianInList.IsCurrent = false;
                        }
                        _database.UpdateAll(currentTechnicians);
                    }

                    // Set this tech as current.
                    technician.IsCurrent = true;
                    rows = _database.Update(technician);
                }

                if (rows > 0)
                {
                    OnCurrentTechnicianChanged(EventArgs.Empty);
                }
            }
            catch (Exception ex)
            {
                ErrorReporting oErrRpt = new Data.ErrorReporting();
                oErrRpt.sendException(ex, "TechDashboard.Data.TechDashboardDB_Technician.cs/SaveTechnicianAsCurrent");
            }
        }
Example #2
0
        public App_Settings GetApplicationSettings()
        {
            // dch rkl 12/06/2016 Add Try/Catch to display exceptions
            App_Settings appSettings = new Models.App_Settings();

            //App_Settings appSettings = null;

            try
            {
                lock (_locker)
                {
                    // dch rkl 12/07/2016 This is not working.  The TableMappings count is always zero, so it keeps creating a new app settings record each time. BEGIN
                    //if (_database.TableMappings.Where(tm => tm.TableName == "App_Settings").FirstOrDefault() == null)
                    //{
                    //    _database.CreateTable<App_Settings>();
                    //    _database.Insert(new App_Settings());
                    //}
                    // dch rkl 12/07/2016 This is not working.  The TableMappings count is always zero, so it keeps creating a new app settings record each time. END

                    try
                    {
                        appSettings = _database.Table <App_Settings>().FirstOrDefault();
                    }
                    catch (Exception ex)
                    {
                        //System.Diagnostics.Debug.WriteLine("Exception caught when querying for application settings.");
                        //System.Diagnostics.Debug.WriteLine(ex.Message);
                    }

                    // dch rkl 12/07/2016 If no app settings found, add a blank record now BEGIN
                    if (appSettings == null || appSettings.ID == 0)
                    {
                        try
                        {
                            _database.CreateTable <App_Settings>();
                            _database.Insert(new App_Settings());
                            appSettings = _database.Table <App_Settings>().FirstOrDefault();
                        }
                        catch (Exception ex)
                        {
                            ErrorReporting oErrRpt = new Data.ErrorReporting();
                            // dch rkl 12/07/2016 add the call/sub/proc to log
                            //oErrRpt.sendException(ex);
                            oErrRpt.sendException(ex, "TechDashboard.TechDashboardDB_AppSettings.cs/GetApplicationSettings");
                        }
                    }
                    // dch rkl 12/07/2016 If no app settings found, add a blank record now END
                }
            }
            catch (Exception ex)
            {
                // dch rkl 12/07/2016 Log Error
                ErrorReporting errorReporting = new ErrorReporting();
                errorReporting.sendException(ex, "TechDashboard.TechDashboardDB_AppSettings.GetApplicationSettings");

                throw new Exception(String.Format(
                                        "Error occurred in TechDashboardDB_AppSettings.GetApplicationSettings.  Contact your administrator.  /nMessageDetails: {0}",
                                        ex.ToString()));
            }

            return(appSettings);
        }