public void Config_dbg() { string ret = ""; foreach (User user in Singleton.Instance.users) { ret += user.Get_ID() + ":\n"; if (Singleton.Instance.configuration.ContainsKey(user.Get_ID())) { foreach (KeyValuePair <string, Configuration> config in Singleton.Instance.configuration[user.Get_ID()]) { bool su, sd, eu, ed; su = config.Value.sms_up; sd = config.Value.sms_down; eu = config.Value.email_up; ed = config.Value.email_down; ret += su + " " + sd + " " + eu + " " + ed + "\n"; } } else { Singleton.Instance.configuration[user.Get_ID()] = new Dictionary <string, Configuration>(); } ret += "--------------\n"; } Singleton.Show_MessageBox(ret); }
private void Save_Click(Object sender, EventArgs e) { if (Singleton.Instance.Admin) { if (Singleton.Instance.configuration.ContainsKey(user_id)) { int it = Singleton.Get_Nr_From_Object(sender); if (it == selected_line_new) { string msg_id = ((TextBlock)IDNew_Panel.Children[it]).Text; for (int i = 0; i < ID_Panel.Children.Count; i++) { if (((TextBlock)ID_Panel.Children[i]).Text.Equals(msg_id)) { Singleton.Show_MessageBox("najpierw usuń tą wiadomość użytkownikowi!"); return; } } CheckBox_Panel currentconfig_panel = ((CheckBox_Panel)ConfigurationNew_Panel.Children[it]); Configuration currentconfig = new Configuration((bool)((CheckBox)currentconfig_panel.Children[0]).IsChecked, (bool)((CheckBox)currentconfig_panel.Children[1]).IsChecked, (bool)((CheckBox)currentconfig_panel.Children[2]).IsChecked, (bool)((CheckBox)currentconfig_panel.Children[3]).IsChecked); Singleton.Instance.configuration[user_id][msg_id] = currentconfig; this.Refresh(); } } } else { Singleton.Show_MessageBox("Niewystarczające uprawnienia!"); } }
private void RemoveButton_Click(object sender, EventArgs e) { if (Singleton.Instance.Admin) { if (Singleton.Show_MessageBox("Czy napewno chcesz usunąć użytkownika?", true)) { Button thisButton = (Button)sender; int it = Singleton.Get_Nr_From_Object(thisButton); string id = ((TextBlock)ID_Panel.Children[it]).Text; ID_Panel.Children.RemoveAt(it); Name_Panel.Children.RemoveAt(it); PhoneNumber_Panel.Children.RemoveAt(it); Email_Panel.Children.RemoveAt(it); RemoveButtons_Panel.Children.RemoveAt(it); for (int i = it; i < ID_Panel.Children.Count; i++) { ((Button)RemoveButtons_Panel.Children[i]).Name = "rmv" + i.ToString(); } Singleton.Instance.Remove_User(id); Singleton.Instance.Remove_User_From_Configuration(id); Singleton.Instance.configuration_page.Refresh(); } } else { Singleton.Show_MessageBox("Niewystarczające uprawnienia!"); } }
private void RemoveButton_Click(object sender, EventArgs e) { if (Singleton.Instance.Admin) { if (Singleton.Show_MessageBox("Czy na pewno chcesz usunąć tą wiadomość?", true)) { Button thisButton = (Button)sender; int it = Singleton.Get_Nr_From_Object(thisButton); string nr = ((TextBlock)Number_Panel.Children[it]).Text; Singleton.Instance.Remove_Message_From_Dict(nr); Singleton.Instance.Remove_Msg_From_Configuration(nr); Number_Panel.Children.RemoveAt(it); //Description_Panel.Children.RemoveAt(it); Comments_Panel.Children.RemoveAt(it); Active_Panel.Children.RemoveAt(it); RemoveButtons_Panel.Children.RemoveAt(it); for (int i = it; i < Number_Panel.Children.Count; i++) { ((Button)RemoveButtons_Panel.Children[i]).Name = "rmv" + i.ToString(); ((TextBlock)Comments_Panel.Children[i]).Name = "CMT" + i.ToString(); ((CheckBox)Active_Panel.Children[i]).Name = "ACT" + i.ToString(); } } } else { Singleton.Show_MessageBox("Niewystarczające uprawnienia!"); } }
public void Send(string message, string nr) { SmsSubmitPdu pdu = new SmsSubmitPdu(message, nr, ""); try { if (!comm.IsOpen()) { comm.Open(); } if (!comm.IsConnected()) { Singleton.Show_MessageBox("błąd portu"); return; } /*if (comm.GetPinStatus() != PinStatus.Ready) { * comm.EnterPin(PIN); * Thread.Sleep(1000); * }*/ comm.SendMessage(pdu); Thread.Sleep(1000); } catch (Exception ex) { Singleton.Show_MessageBox(ex.Message); return; } //Singleton.Show_MessageBox("wysyłam " + message + "na numer: " + nr); }
private void RemoveButton_Click(object sender, EventArgs e) { if (Singleton.Instance.Admin) { if (Singleton.Show_MessageBox("Czy napewno chcesz usunąć tą wiadomość?", true)) { Button thisButton = (Button)sender; int it = Singleton.Get_Nr_From_Object(thisButton); string msg_id = ((TextBlock)ID_Panel.Children[it]).Text; Select_Panel.Children.RemoveAt(it); ID_Panel.Children.RemoveAt(it); ConfigurationCur_Panel.Children.RemoveAt(it); Remove_Panel.Children.RemoveAt(it); for (int i = it; i < ID_Panel.Children.Count; i++) { ((Button)Select_Panel.Children[i]).Name = "SLC" + i.ToString(); ((Button)Remove_Panel.Children[i]).Name = "rmv" + i.ToString(); ((CheckBox_Panel)ConfigurationCur_Panel.Children[i]).Name = "CTR" + i.ToString(); } Singleton.Instance.configuration[user_id].Remove(msg_id); Refresh(); } } else { Singleton.Show_MessageBox("Niewystarczające uprawnienia!"); } }
public void Load_Users() { try { Singleton.Instance.Clear_Users(); Singleton.Instance.users_page.Window_Clear(); cmd.CommandText = "select * from users_table"; cmd.Connection = cnn; cmd.CommandType = System.Data.CommandType.Text; reader = cmd.ExecuteReader(); while (reader.Read()) { string user_id = reader["id użytkownika"].ToString(); string username = reader["nazwa użytkownika"].ToString(); string phone_number = reader["numer telefonu"].ToString(); string email = reader["adres email"].ToString(); Singleton.Instance.users_page.Add_Line(user_id, username, phone_number, email); } } catch (Exception ex) { Singleton.Show_MessageBox(ex.Message); } try { reader.Close(); } catch (Exception ex) { } }
public void Load_Settings_With_Password() { try { IFormatter formatter = new BinaryFormatter(); Stream stream = File.Open("default.cnf", FileMode.Open); password = (string)formatter.Deserialize(stream); int users_count = (int)formatter.Deserialize(stream); int msgs_count = (int)formatter.Deserialize(stream); Clear_Users(); for (int i = 0; i < users_count; i++) { User user = (User)formatter.Deserialize(stream); Add_User(user); } Singleton.Instance.messages_dict = new Dictionary <string, Message_Add>(); for (int i = 0; i < msgs_count; i++) { string id = (string)formatter.Deserialize(stream); Message_Add msg = (Message_Add)formatter.Deserialize(stream); Add_Message(id, msg); } Singleton.Instance.configuration = new Dictionary <string, Dictionary <string, Configuration> >(); foreach (User user in Singleton.Instance.users) { Singleton.Instance.configuration[user.Get_ID()] = new Dictionary <string, Configuration>(); } foreach (User user in Singleton.Instance.users) { int n = (int)formatter.Deserialize(stream); for (int i = 0; i < n; i++) { string msg_id = (string)formatter.Deserialize(stream); Configuration load = (Configuration)formatter.Deserialize(stream); Add_To_Config(user.Get_ID(), msg_id, load); } } Add_Lines_To_Windows(); //Singleton.Show_MessageBox("wczytano pomyślnie"); } catch (Exception ex) { Singleton.Show_MessageBox(ex.Message); } }
void ImportMessages_Click(Object sender, EventArgs e) { try { IFormatter formatter = new BinaryFormatter(); OpenFileDialog openFileDialog = new OpenFileDialog { InitialDirectory = "c:\\Users\\Szymon\\Desktop", Filter = "mes files (*.mes)|*.mes", FilterIndex = 2, RestoreDirectory = true }; bool? result = openFileDialog.ShowDialog(); Stream stream; if (result == true) { if ((stream = openFileDialog.OpenFile()) != null) { int msgs_count = (int)formatter.Deserialize(stream); Singleton.Instance.Clear_Messages(); Dictionary<string, Message_Add> new_msgs = new Dictionary<string, Message_Add>(); for (int i = 0; i < msgs_count; i++) { string key = (string)formatter.Deserialize(stream); Message_Add new_msg = (Message_Add)formatter.Deserialize(stream); new_msgs[key] = new_msg; } foreach (KeyValuePair<string, Message_Add> msg in new_msgs) { Singleton.Instance.Add_Message(msg.Key, msg.Value); } Singleton.Instance.configuration = new Dictionary<string, Dictionary<string, Configuration>>(); Singleton.Instance.messages_page.Window_Clear(); foreach (KeyValuePair<string, Message_Add> msg in new_msgs) Singleton.Instance.messages_page.Add_Line(msg.Key, msg.Value.Comment, msg.Value.IsActive()); Singleton.Instance.configuration_page.Refresh(); Singleton.Show_MessageBox("wczytano pomyślnie"); } } } catch (Exception ex) { Singleton.Show_MessageBox(ex.Message); } }
private void Send_SMS(string msg, string number) { //if (sms_manager.connected) //{ Singleton.Show_MessageBox("Wysłano sms na nr: " + number + " o treści: " + msg); //sms_manager.Send(msg, number); //} }
public void Users_dbg() { string ret = ""; for (int i = 0; i < Singleton.Instance.users.Count; i++) { ret += Singleton.Instance.users[i].ToString() + "\n"; } Singleton.Show_MessageBox(ret); }
public void SetMessageActive(string id, bool active) { if (messages_dict.ContainsKey(id)) { messages_dict[id].SetActive(active); } else { Singleton.Show_MessageBox("nie ma takiej wiadomości"); } }
public void Copy_Config(string from_id, string to_id) { if (Singleton.Instance.configuration.ContainsKey(from_id)) { Singleton.Instance.configuration[to_id] = Singleton.Instance.configuration[from_id]; } else { Singleton.Show_MessageBox("Nie przypisano konfiguracji do użytkownika wyjściowego!"); } }
public bool Add_Message(string id, Message_Add msg) { if (messages_dict.ContainsKey(id)) { Singleton.Show_MessageBox("id nie mogą się powtarzać"); return(false); } messages_dict[id] = msg; return(true); }
void ImportUsers_Click(Object sender, EventArgs e) { if (Singleton.Instance.Admin) { try { IFormatter formatter = new BinaryFormatter(); OpenFileDialog openFileDialog = new OpenFileDialog { InitialDirectory = "c:\\Users\\Szymon\\Desktop", Filter = "usr files (*.usr)|*.usr", FilterIndex = 2, RestoreDirectory = true }; bool? result = openFileDialog.ShowDialog(); Stream stream; if (result == true) { if ((stream = openFileDialog.OpenFile()) != null) { int users_count = (int)formatter.Deserialize(stream); Singleton.Instance.Clear_Users(); for (int i = 0; i < users_count; i++) { User user = (User)formatter.Deserialize(stream); Singleton.Instance.Add_User(user); } Singleton.Instance.users_page.Window_Clear(); foreach (User user in Singleton.Instance.users) Singleton.Instance.users_page.Add_Line(user.Get_ID(), user.Get_Name(), user.Get_Number(), user.Get_Email()); Singleton.Show_MessageBox("wczytano pomyślnie"); } } Singleton.Instance.configuration = new Dictionary<string, Dictionary<string, Configuration>>(); Singleton.Instance.configuration_page.Refresh(); } catch (Exception ex) { Singleton.Show_MessageBox(ex.Message); } } else Singleton.Show_MessageBox("Niewystarczające uprawnienia!"); }
void ExportConfig_Click(Object sender, EventArgs e) { try { IFormatter formatter = new BinaryFormatter(); SaveFileDialog saveFileDialog = new SaveFileDialog { Filter = "config files (*.cnf)|*.cnf", FilterIndex = 2, RestoreDirectory = true }; bool? result = saveFileDialog.ShowDialog(); Stream stream; if (result == true) { if ((stream = saveFileDialog.OpenFile()) != null) { formatter.Serialize(stream, Singleton.Instance.users.Count); formatter.Serialize(stream, Singleton.Instance.messages_dict.Count); foreach (User user in Singleton.Instance.users) formatter.Serialize(stream, user); foreach (KeyValuePair<string, Message_Add> msg_in in Singleton.Instance.messages_dict) { formatter.Serialize(stream, msg_in.Key); formatter.Serialize(stream, msg_in.Value); } foreach (User user in Singleton.Instance.users) { formatter.Serialize(stream, Singleton.Instance.configuration[user.Get_ID()].Count); foreach (KeyValuePair<string, Configuration> cnf in Singleton.Instance.configuration[user.Get_ID()]) { formatter.Serialize(stream, cnf.Key); formatter.Serialize(stream, cnf.Value); } } Singleton.Show_MessageBox("zapisano pomyślnie!"); stream.Close(); } } } catch (Exception ex) { Singleton.Show_MessageBox(ex.Message); } }
private void ChangePassword_Click(Object sender, EventArgs e) { if (Singleton.Instance.Admin) { string newPassword = Singleton.Get_Dialog("tu wpisz nowe hasło"); Singleton.Instance.ChangePassword(newPassword); } else { Singleton.Show_MessageBox("Niewystarczające uprawnienia!"); } }
private void AddButton_Click(object sender, EventArgs e) { if (Singleton.Instance.Admin) { AddUser_Dialog dialog = new AddUser_Dialog(); dialog.Show(); } else { Singleton.Show_MessageBox("Niewystarczające uprawnienia!"); } }
public void Clear_Window() { try { ID_Panel.Children.RemoveRange(0, ID_Panel.Children.Count); Users_Panel.Children.RemoveRange(0, Users_Panel.Children.Count); Config_Panel.Children.RemoveRange(0, Config_Panel.Children.Count); } catch (Exception ex) { Singleton.Show_MessageBox(ex.Message); } }
private void CredentialLogin_Click(object sender, RoutedEventArgs e) { if (Credential_Box.Password == Singleton.Instance.password || Credential_Box.Password == Singleton.Instance.backup_password) { Singleton.Instance.Admin = true; CredentialStatus_Block.Text = "Administrator"; CredentialStatus_Block.FontWeight = FontWeights.Bold; CredentialStatus_Block.Foreground = Brushes.PaleGoldenrod; } else { Singleton.Instance.Admin = false; CredentialStatus_Block.Text = "Gość"; CredentialStatus_Block.FontWeight = FontWeights.Bold; CredentialStatus_Block.Foreground = Brushes.DarkGray; Singleton.Show_MessageBox("Niepoprawne hasło!"); } }
private void AddUser_Dialog_Click(object sender, EventArgs e) { string id = ID_text.Text; if (!Singleton.Instance.Is_User_ID_Repeated(id)) { string name = Name_text.Text; string phone_number = Nr_text.Text; string email = Email_text.Text; Singleton.Instance.users_page.Add_Line(id, name, phone_number, email); Singleton.Instance.Add_User(new User(id, name, phone_number, email)); Singleton.Instance.configuration_page.Refresh(); this.Close(); } else { Singleton.Show_MessageBox("ID nie mogą się powtarzać!"); } }
public void Save_Settings_With_Password() { File.Delete("default.cnf"); try { IFormatter formatter = new BinaryFormatter(); Stream stream = File.Open("default.cnf", FileMode.OpenOrCreate); formatter.Serialize(stream, password); formatter.Serialize(stream, users.Count); formatter.Serialize(stream, messages_dict.Count); foreach (User user in Singleton.Instance.users) { formatter.Serialize(stream, user); } foreach (KeyValuePair <string, Message_Add> msg_in in Singleton.Instance.messages_dict) { formatter.Serialize(stream, msg_in.Key); formatter.Serialize(stream, msg_in.Value); } foreach (User user in Singleton.Instance.users) { formatter.Serialize(stream, configuration[user.Get_ID()].Count); foreach (KeyValuePair <string, Configuration> cnf in Singleton.Instance.configuration[user.Get_ID()]) { formatter.Serialize(stream, cnf.Key); formatter.Serialize(stream, cnf.Value); } } stream.Close(); } catch (Exception ex) { Singleton.Show_MessageBox(ex.Message); } }
void ExportMessages_Click(Object sender, EventArgs e) { try { IFormatter formatter = new BinaryFormatter(); SaveFileDialog saveFileDialog = new SaveFileDialog { Filter = "mes files (*.mes)|*.mes", FilterIndex = 2, RestoreDirectory = true }; bool? result = saveFileDialog.ShowDialog(); Stream stream; if (result == true) { if ((stream = saveFileDialog.OpenFile()) != null) { formatter.Serialize(stream, Singleton.Instance.messages_dict.Count); foreach (KeyValuePair<string, Message_Add> msg in Singleton.Instance.messages_dict) { formatter.Serialize(stream, msg.Key); formatter.Serialize(stream, msg.Value); } Singleton.Show_MessageBox("zapisano pomyślnie!"); stream.Close(); } } } catch (Exception ex) { Singleton.Show_MessageBox(ex.Message + "\nspróbuj ponownie za chwilę"); } }
void ExportUsers_Click(Object sender, EventArgs e) { try { IFormatter formatter = new BinaryFormatter(); SaveFileDialog saveFileDialog = new SaveFileDialog { Filter = "usr files (*.usr)|*.usr", FilterIndex = 2, RestoreDirectory = true }; bool? result = saveFileDialog.ShowDialog(); Stream stream; if (result == true) { if ((stream = saveFileDialog.OpenFile()) != null) { formatter.Serialize(stream, Singleton.Instance.users.Count); foreach (User user in Singleton.Instance.users) { formatter.Serialize(stream, user); } Singleton.Show_MessageBox("zapisano pomyślnie!"); stream.Close(); } } } catch (Exception ex) { Singleton.Show_MessageBox(ex.Message + "\nspróbuj ponownie za chwilę"); } }
public void Load_Messages() { if (status) { try { Singleton.Instance.Clear_Messages(); Singleton.Instance.messages_page.Window_Clear(); cmd.CommandText = "select * from messages_table"; cmd.Connection = cnn; cmd.CommandType = System.Data.CommandType.Text; reader = cmd.ExecuteReader(); while (reader.Read()) { string msg_id = reader["id wiadomości"].ToString(); string description = reader["opis"].ToString(); bool active = reader["aktywność"].ToString() == "TRUE"; Singleton.Instance.messages_page.Add_Line(msg_id, description, active); Singleton.Instance.Add_Message(msg_id, new Message_Add(description, active)); } } catch (Exception ex) { Singleton.Show_MessageBox(ex.Message); } try { reader.Close(); } catch (Exception ex) { } } }
private void AddButton_Click(object sender, EventArgs e) { if (Singleton.Instance.Admin) { AddMessage_Dialog msg_dialog = new AddMessage_Dialog(); msg_dialog.ShowDialog(); string id = msg_dialog.ID; if (msg_dialog.closed) { return; } string comment = msg_dialog.Comment; if (Singleton.Instance.Add_Message(id, new Message_Add(comment))) { Add_Line(id, comment, true); } } else { Singleton.Show_MessageBox("Niewystarczające uprawnienia!"); } }
public void Set_Start(int interval) { try { using (StreamReader sr = new StreamReader("settings.txt")) { try { filePath = sr.ReadLine(); } catch (Exception ex) { System.Windows.MessageBox.Show("BŁĄD WCZYTYWANIA USTAWIEŃ!", "FATAL ERROR"); } try { Load_Settings_With_Password(); } catch (Exception ex) { Singleton.Show_MessageBox(ex.Message + "nie można wczytać ustawień"); } } } catch (Exception eee) { } timer.Interval = new TimeSpan(0, 0, 0, 0, interval); timer.Tick += new EventHandler(OnTimedEvent); timer.Start(); Checker_Thread = new Thread(Status_Checker); Checker_Thread.Start(); Alarm_Thread = new Thread(Alarm); Alarm_Thread.Start(); }
public bool Login(string username, string password, string serveradres, string database) { Thread thread = new Thread(() => { Wait_Dialog w = new Wait_Dialog("proszę czekać"); w.Show(); w.Closed += (sender2, e2) => w.Dispatcher.InvokeShutdown(); System.Windows.Threading.Dispatcher.Run(); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); Thread.Sleep(1000); string connetionString = null; connetionString = $"Server={serveradres};" + $" Database={database};" + $"User Id={ username };" + $"Password = { password }; "; cnn = new SqlConnection(connetionString); try { cnn.Open(); status = true; } catch (Exception ex) { thread.Abort(); Singleton.Show_MessageBox("Nie można połączyć się z serwerem SQL"); status = false; return(status); } thread.Abort(); return(status); }
private void Copy_Click(Object sender, EventArgs e) { Singleton.Instance.Copy_Config(_copyFrom_id, _copyTo_id); Singleton.Show_MessageBox(_copyFrom_id + " " + copyTo_id); }
private void Send_Email(string msg, string adress) { Singleton.Show_MessageBox("Wysłano email na adres: " + adress + " o treści: " + msg); //email_manager.Send(adress, "ALERT", msg); }