private void cmb_sneezers_SelectedIndexChanged(object sender, EventArgs e) { if (cmb_sneezers.SelectedIndex == 0) { AddUserForm addUserDialog = new AddUserForm(); if (addUserDialog.ShowDialog() == DialogResult.OK) { foreach (UserInfo user in SneezeClientListener.Database.IdToUser.Values) { if (user.Name == addUserDialog.UserName) { MessageBox.Show(this, "Sorry, that Username is already taken. Please select another Username.", "Username Taken", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } UserInfo recruit = new UserInfo(addUserDialog.UserName, Guid.NewGuid(), GetRandomColor()); cmb_sneezers.Items.Add(recruit); SneezeClientListener.AddUser(recruit); cmb_sneezers.SelectedItem = recruit; } } if (CurrentUser != null) { lbl_display_color.BackColor = CurrentUser.Color; Settings.Default.LastSneezer = CurrentUser.UserGuid; Settings.Default.Save(); } UpdateUIState(); }
private void btn_connect_Click(object sender, EventArgs e) { connectionOpening = true; lbl_sneeze_display.Invalidate(); Settings.Default.ServerIP = txtbx_ip.Text; Settings.Default.Save(); failedToConnect = false; connectionClosed = false; dbError = DatabaseErrorType.None; SneezeClientListener.StartListener(txtbx_ip.Text); }
private void btn_add_sneeze_Click(object sender, EventArgs e) { string message = GetLongestStreak(); // Calculate this first SneezeDatabase database = SneezeClientListener.Database; int sneezeNum = database.CountdownStart - database.Sneezes.Count; DateTime sneezeDate = CommonInfo.GetDateOfSneeze(sneezeNum); SneezeClientListener.Sneeze(new SneezeRecord(CurrentUser.UserGuid, sneezeDate, txtbx_commentary.Text)); txtbx_commentary.Clear(); if (!String.IsNullOrEmpty(message)) { MessageBox.Show(message, "Sneeze Streak Status"); } }
private void lbl_sneeze_display_MouseClick(object sender, MouseEventArgs e) { if ((e.Button & MouseButtons.Left) != 0) { return; } int sneezeIndex; SneezeRecord sneeze = GetSneezeAtLocation(lbl_sneeze_display.PointToClient(MousePosition), out sneezeIndex); if (sneeze == null) { return; } if (sneeze.UserId != CurrentUser?.UserGuid) { return; } ContextMenuStrip strip = new ContextMenuStrip(); strip.Items.Add("Edit sneeze...", null, (s, a) => { using (SneezeCommentEditorForm form = new SneezeCommentEditorForm(sneeze.Comment)) { if (form.ShowDialog(this) == DialogResult.OK) { sneeze.Comment = form.UpdatedText; SneezeClientListener.UpdateSneeze(sneeze); } } }); strip.Items.Add("Remove sneeze...", null, (s, a) => { if (DialogResult.Yes == MessageBox.Show(this, "Are you sure you want to delete this sneeze?", "Delete Sneeze", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { SneezeClientListener.RemoveSneeze(sneeze); } }); strip.Show(MousePosition); }
private void btn_change_color_Click(object sender, EventArgs e) { ColorDialog colorDlg = new ColorDialog(); colorDlg.AnyColor = true; if (colorDlg.ShowDialog(this) == DialogResult.OK) { if (ColorTaken(colorDlg.Color, CurrentUser)) { MessageBox.Show(this, "Sorry, that color is already taken. Please select another color.", "Color Taken", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } CurrentUser.Color = colorDlg.Color; lbl_display_color.BackColor = CurrentUser.Color; SneezeClientListener.UpdateUser(CurrentUser); lbl_sneeze_display.Invalidate(); } }
private void SneezeBoardForm_FormClosed(object sender, FormClosedEventArgs e) { SneezeClientListener.ShutDown(); }