Ejemplo n.º 1
0
        private void btnUpdateSubscriber_Click(object sender, EventArgs e)
        {
            // Update subsriber in database
            SQL.UpdateSubscriber(sub, txtEMail.Text, txtFirstName.Text, txtLastName.Text, Convert.ToInt32(txtPhoneNumber.Text));

            // Update alarmtypes for subscriber
            foreach (CheckBox chk in grpAlarmtypes.Controls)
            {
                // Removes chk from checkbox-name, and casts string to AlarmtypesEnum. Then update alarmtype for subscriber
                string temp = chk.Name;
                temp = temp.Replace("chk", "");
                AlarmtypesEnum alarm = (AlarmtypesEnum)Enum.Parse(typeof(AlarmtypesEnum), temp);
                if (chk.Checked)
                {
                    sub.SubscribeTo(alarm);
                }
                if (!chk.Checked)
                {
                    sub.UnsubscribeTo(alarm);
                }
            }

            MessageBox.Show("Abonnent " + sub.Email + " oppdatert", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            UpdateTable();
        }
Ejemplo n.º 2
0
        public static List <string> GetEmailList(AlarmtypesEnum alarmtype)
        {
            List <string> EmailList = new List <string>();
            SqlDataReader rdr       = null;

            try
            {
                con.Open();
                command.CommandType = CommandType.Text;
                command.CommandText = @"SELECT Email FROM SUBSCRIBESTO WHERE Alarm = '" + alarmtype + "'";
                rdr = command.ExecuteReader();
                while (rdr.Read())
                {
                    string Email = rdr["Email"].ToString();
                    EmailList.Add(Email);
                }
                return(EmailList);
            }
            catch (Exception error)
            {
                Console.WriteLine(error.Message);
                return(null);
            }
            finally
            {
                con.Close();
                command.CommandType = CommandType.StoredProcedure;
            }
        }
        private void btnAddUser_Click(object sender, EventArgs e)
        {
            bool   resultTlfConvert;
            string email     = txtEMail.Text;
            string firstName = txtFirstName.Text;
            string lastName  = txtLastName.Text;
            Int32  tlfNumber;

            resultTlfConvert = int.TryParse(txtPhoneNumber.Text, out tlfNumber);

            // Test if txtPhoneNumber successfully converts to int
            if (resultTlfConvert == true)
            {
                Subscriber sub = new Subscriber(email, firstName, lastName, tlfNumber);

                // Add subscriber if it don't exist in database
                if (!SQL.SubscriberExists(sub))
                {
                    SQL.AddSubscriber(sub);
                    foreach (CheckBox chk in grpAlarmtypes.Controls)
                    {
                        if (chk.Checked)
                        {
                            // Removes chk from checkbox-name, and casts string to AlarmtypesEnum. Then it subscribes to alarmtype.
                            string temp = chk.Name;
                            temp = temp.Replace("chk", "");
                            AlarmtypesEnum alarm = (AlarmtypesEnum)Enum.Parse(typeof(AlarmtypesEnum), temp);
                            sub.SubscribeTo(alarm);
                        }
                    }
                    MessageBox.Show("Bruker lagt til i databasen", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ClearAll();
                }
                // If subscriber exists, display error-message
                else if (SQL.SubscriberExists(sub))
                {
                    MessageBox.Show("Bruker med samme e-post eksisterer i databasen", "Feil", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                // Display this error-message if everything else fails
                else
                {
                    MessageBox.Show("Oppretting av bruker feilet", "Feil", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            // Converting to int fails of txtPhoneNumber holds characters
            else
            {
                MessageBox.Show("Telefonnummer skal kun inneholde tall", "Feil", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 4
0
 //Unsubscribes a subscriber from email notifications for a given alarmtype
 public static void UnsubscribeTo(Subscriber sub, AlarmtypesEnum alarmtype)
 {
     try
     {
         con.Open();
         command.CommandText = "UnSubscribesTo";
         command.Parameters.Clear();
         command.Parameters.AddWithValue("@Email", sub.Email);
         command.Parameters.AddWithValue("@Alarmtype", alarmtype.ToString());
         command.ExecuteNonQuery();
     }
     catch (Exception error)
     {
         Console.WriteLine(error.Message);
     }
     finally
     {
         con.Close();
     }
 }
Ejemplo n.º 5
0
 //GetDescription returns the description for a specified alarmtype as a string
 public static string GetDescription(AlarmtypesEnum alarmtype)
 {
     try
     {
         con.Open();
         command.CommandText = "GetDescription";
         command.Parameters.Clear();
         command.Parameters.Add(new SqlParameter("@AlarmType", alarmtype.ToString()));
         string result = ((string)command.ExecuteScalar());
         return(result);
     }
     catch (Exception error)
     {
         return("Failed to get description: \n" + error.Message);
     }
     finally
     {
         con.Close();
     }
 }
Ejemplo n.º 6
0
 //NewAlarm inserts a alarm in the alarm history
 public static void NewAlarm(AlarmtypesEnum alarmtype)
 {
     try
     {
         con.Open();
         command.CommandText = "NewAlarm";
         command.Parameters.Clear();
         command.Parameters.Add(new SqlParameter("@Alarm", alarmtype.ToString()));
         command.ExecuteNonQuery();
         con.Close();
     }
     catch (Exception error)
     {
         Console.WriteLine(error.Message);
     }
     finally
     {
         con.Close();
     }
 }
Ejemplo n.º 7
0
 //UpdateAlarmLimit changes the alarm limits in the database
 public static void UpdateAlarmLimit(AlarmtypesEnum alarmtype, double newLimit)
 {
     try
     {
         con.Open();
         command.CommandText = "UpdateLimit";
         command.Parameters.Clear();
         command.Parameters.Add(new SqlParameter("@AlarmType", alarmtype.ToString()));
         command.Parameters.Add(new SqlParameter("@NewLimit", newLimit));
         command.ExecuteNonQuery();
         con.Close();
     }
     catch (Exception error)
     {
         Console.WriteLine(error.Message);
     }
     finally
     {
         con.Close();
     }
 }
Ejemplo n.º 8
0
 //GetLimit returns the alarm limit for a specific alarmtype as a double
 public static double GetAlarmLimit(AlarmtypesEnum alarmtype)
 {
     try
     {
         con.Open();
         command.CommandText = "GetLimit";
         command.Parameters.Clear();
         command.Parameters.Add(new SqlParameter("@AlarmType", alarmtype.ToString()));
         double result = ((double)command.ExecuteScalar());
         con.Close();
         return(result);
     }
     catch (Exception)
     {
         throw new NotImplementedException();
     }
     finally
     {
         con.Close();
     }
 }
Ejemplo n.º 9
0
 public void UnsubscribeTo(AlarmtypesEnum alarmtype)
 {
     SQLCom.UnsubscribeTo(this, alarmtype);
 }
Ejemplo n.º 10
0
 public void SubscribeTo(AlarmtypesEnum alarmtype)
 {
     SQLCom.SubscribesTo(this, alarmtype);
 }