Exemple #1
0
        public static void LogError(string message, string details, bool showErrorFrm = true)
        {
            try
            {
                using (StreamWriter outfile = new StreamWriter(errorfile, true))
                {
                    outfile.Write("[" + DateTime.Now.ToString() + "]\r\n" + message + "\r\n" + details + "\r\nVersion(" + Info.VERSION + ")\r\n\r\n");
                }
            }
            catch (Exception ex)
            {
                /* Couldnt log it, oh well just show the error message form */
            }

            if (showErrorFrm)
            {
                ErrorMsgFrm.Show(message, details);
            }
        }
Exemple #2
0
        /// <summary>
        /// Load all the service users
        /// </summary>
        /// <param name="ignoreDeleted"></param>
        public void LoadServiceUsers(bool ignoreDeleted = true)
        {
            if (isLoading)
            {
                return;
            }

            isLoading = true;

            //load here
            if (_ServiceUsers == null)
            {
                _ServiceUsers = new ServiceUserCollection();
            }
            else
            {
                _ServiceUsers.Clear();
            }

            try
            {
                string query = "SELECT id, Firstname, Surname, PNumber, Notes, contactno_primary, contactno_secondary, datetime(dob), idStatus, idGender, location_longitude, location_latitude, medicalinfo, datetime(serviceperiodstart), serviceperiodweeks, postcode, add1, add2 FROM tbl_ServiceUser";

                if (ignoreDeleted)
                {
                    query += " WHERE idStatus <> 3";
                }

                DataTable dt = Common.Database.ExecuteDatabaseQuery(query);

                foreach (DataRow row in dt.Rows)
                {
                    DateTime?dob;

                    if (row[7] == DBNull.Value)
                    {
                        dob = null;
                    }
                    else
                    {
                        try
                        {
                            dob = DateTime.ParseExact(row[7].ToString(), "yyyy-MM-dd 00:00:00", CultureInfo.InvariantCulture);
                        }
                        catch (FormatException ex)
                        {
                            dob = null;
                        }
                    }

                    DateTime periodstart;

                    if (row[13] == DBNull.Value)
                    {
                        /*this should never happen!*/
                        ErrorMsgFrm.Show("oh dear failed to load a service user", "bad period start date");
                        continue;
                    }
                    else
                    {
                        try
                        {
                            periodstart = DateTime.ParseExact(row[13].ToString(), "yyyy-MM-dd 00:00:00", CultureInfo.InvariantCulture);
                        }
                        catch (FormatException ex)
                        {
                            /*this should never happen!*/
                            ErrorMsgFrm.Show("oh dear failed to load service user", "bad period start date");
                            continue;
                        }
                    }


                    ServiceUser s = new ServiceUser()
                    {
                        id                  = Convert.ToInt32(row[0]),
                        firstname           = row[1].ToString(),
                        surname             = row[2].ToString(),
                        PNumber             = row[3].ToString(),
                        notes               = row[4].ToString(),
                        contactno_primary   = row[5].ToString(),
                        contactno_secondary = row[6].ToString(),
                        dob                 = dob,
                        idStatus            = (ServiceUser.Status)Convert.ToInt16(row[8]),
                        idGender            = (ServiceUser.Gender)Convert.ToInt16(row[9]),
                        LongLatCoords       = new LongLat((row[10] == DBNull.Value ? null : row[10].ToString()), (row[11] == DBNull.Value ? null : row[11].ToString()), (row[15] == DBNull.Value ? null : row[15].ToString())),
                        medicalinfo         = row[12].ToString(),
                        ServiceBegins       = periodstart,
                        PeriodWeekCount     = Convert.ToInt32(row[14]),
                        postcode            = row[15].ToString(),
                        add1                = row[16].ToString(),
                        add2                = row[17].ToString()
                    };

                    s.ConstructOld();

                    _ServiceUsers.Add(s);
                }

                //load all the key workers and refresh their old list
                List <OldConstructable> listModified = LoadKeyWorkers();
                foreach (OldConstructable obj in listModified)
                {
                    obj.ConstructOld();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to load all service users", ex);
            }

            isLoading = false;
        }