private void registerButton_Click(object sender, EventArgs args) { string username = usernameTextBox.Text; string email = emailTextBox.Text; string password = passwordTextBox.Text; var resUsername = Validator.ValidateUsername(username); var resEmail = Validator.ValidateEmail(email); var resPassword = Validator.ValidatePassword(password); resultLabel.Text = ""; usernameTextBox.BackColor = Color.White; emailTextBox.BackColor = Color.White; passwordTextBox.BackColor = Color.White; passwordRepeatTextBox.BackColor = Color.White; // Valid username if (!resUsername.isValid) { resultLabel.Text += $"• {resUsername.message}\n"; usernameTextBox.BackColor = Color.FromArgb(255, 200, 200); } // Valid email if (!resEmail.isValid) { resultLabel.Text += $"• {resEmail.message}\n"; emailTextBox.BackColor = Color.FromArgb(255, 200, 200); } // Valid password if (!resPassword.isValid) { resultLabel.Text += $"• {resPassword.message}\n"; passwordTextBox.BackColor = Color.FromArgb(255, 200, 200); } // Passwords match if (passwordTextBox.Text != passwordRepeatTextBox.Text) { resultLabel.Text += $"• Passwords don't match\n"; passwordRepeatTextBox.BackColor = Color.FromArgb(255, 200, 200); } if (resultLabel.Text == "") { string result = Program.Client.CreateAccount(username, email, password); if (result == "OK") { mainForm.ShowPanel(new MainEventListPanel(null)); return; } resultLabel.Text += $"• {result}"; } }
private void loginButton_Click(object sender, EventArgs args) { if (emailTextBox.Text.Length == 0) { resultsLabel.Text = "• Invalid credentials"; resultsLabel.Visible = true; return; } if (passwordTextBox.Text.Length == 0) { resultsLabel.Text = "• Invalid credentials"; resultsLabel.Visible = true; return; } ulong vfid = Program.Client.Login(emailTextBox.Text, passwordTextBox.Text); if (vfid != 0) { Program.Client.SetVfid(vfid); mainForm.loggedIn = true; mainForm.ShowPanel(new MainEventListPanel(null)); mainForm.DrawBanner(); if (rememberCheckBox.Checked) { Program.UserDataManager.UserData.SavedEmail = emailTextBox.Text; Program.UserDataManager.UserData.SavedPassword = passwordTextBox.Text; Program.UserDataManager.Save(); } else { Program.UserDataManager.UserData.SavedEmail = ""; Program.UserDataManager.UserData.SavedPassword = ""; Program.UserDataManager.Save(); } } else { resultsLabel.Text = "• Invalid credentials"; resultsLabel.Visible = true; } }
private void backButton_Click(object sender, EventArgs e) { mainForm.ShowPanel(caller); }
private void retryButton_Click(object sender, EventArgs e) { mainForm.ShowPanel(new MainEventListPanel(null)); }
private void LoadMainEvents(EventOptions options) { eventGridPanel.Controls.Clear(); // Get events List <EventBrief> events = Program.DataProvider.GetEventsBrief(options); List <int> scores = new List <int>(); List <double> distances = new List <double>(); // Filter invisible if (!showInvisibleEventsCheckBox.Checked) { events = events.Where(item => item.Visible).ToList(); } // Calculate distances UserData user = Program.UserDataManager.GetData(); bool isAddressAdded = !(user.Address == "" || user.Address == null || (user.Latitude == 0 && user.Longitude == 0)); foreach (var evBrief in events) { distances.Add(MathSupplement.Distance(user.Latitude, user.Longitude, evBrief.Latitude, evBrief.Longitude)); } if (options.Keywords.Count > 0) { // Calculate scores KeywordFinder kFinder = new KeywordFinder(); foreach (var evBrief in events) { DataList @event = evBrief.ToDataList(); scores.Add(kFinder.Find(options.Keywords.ToArray(), @event)); } // Sort by score EventBrief[] eventArray = events.ToArray(); int[] scoreArray = scores.ToArray(); Array.Sort(scoreArray, eventArray); events = eventArray.ToList(); scores = scoreArray.ToList(); events.Reverse(); scores.Reverse(); } else { // Sort by distance EventBrief[] eventArray = events.ToArray(); double[] distanceArray = distances.ToArray(); Array.Sort(distanceArray, eventArray); events = eventArray.ToList(); distances = distanceArray.ToList(); } // Grid variables int COL_COUNT = 3; int ROW_COUNT = (events.Count + COL_COUNT - 1) / COL_COUNT; int IMAGE_WIDTH = 304; int IMAGE_HEIGHT = 171; int BANNER_HEIGHT = 60; int START_HEIGHT = 350; int MARGINS = (1000 - IMAGE_WIDTH * COL_COUNT) / (COL_COUNT + 1); // Calculate size of event grid panel eventGridPanel.Size = new Size(1000, MARGINS + (IMAGE_HEIGHT + BANNER_HEIGHT + MARGINS) * ROW_COUNT); eventGridPanel.Location = new Point(0, START_HEIGHT); mainPanel.Size = new Size(1000, START_HEIGHT + eventGridPanel.Size.Height); // Add all of them to a list int col = 0; int count = 0; foreach (var eBrief in events) { // Skip events with 0 score if (scores.Count > 0) { if (scores[count] == 0) { count++; continue; } } // Main container Panel eventPanel = new Panel(); eventPanel.AutoSize = false; eventPanel.Size = new Size(IMAGE_WIDTH, IMAGE_HEIGHT + BANNER_HEIGHT); eventPanel.BorderStyle = BorderStyle.FixedSingle; eventPanel.Click += (sender, e) => { try { mainForm.ShowPanel(new UiEventDisplayPanel(eBrief.Id, this)); //new UiEventDisplay(eBrief.Id, this).Show(); } catch { mainForm.ShowPanel(this); } }; // Calculate position of event panel eventPanel.Location = new Point ( MARGINS + (IMAGE_WIDTH + MARGINS) * col, (IMAGE_HEIGHT + BANNER_HEIGHT + MARGINS) * (count / 3) ); // Thumbnail PictureBox thumbnail = new PictureBox(); thumbnail.Size = new Size(IMAGE_WIDTH, IMAGE_HEIGHT); thumbnail.Location = new Point(0, 0); thumbnail.Click += (sender, e) => { try { mainForm.ShowPanel(new UiEventDisplayPanel(eBrief.Id, this)); //new UiEventDisplay(eBrief.Id, this).Show(); } catch { } }; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (s, e) => { try { using (WebClient client = new WebClient()) { Stream stream = client.OpenRead(eBrief.Images[0]); Bitmap bitmap = new Bitmap(stream); thumbnail.Image = Helper.ScaleBitmap(bitmap, IMAGE_WIDTH, IMAGE_HEIGHT, 16.0f / 9.0f); stream.Flush(); stream.Close(); } } catch { } }; worker.RunWorkerAsync(); // Info panel Panel infoPanel = new Panel(); infoPanel.Location = new Point(0, IMAGE_HEIGHT); infoPanel.Size = new Size(IMAGE_WIDTH, BANNER_HEIGHT); if (!eBrief.Visible) { infoPanel.BackColor = Color.FromArgb(255, 200, 200); } // Name label Label eventName = new Label(); eventName.Text = eBrief.Name; eventName.AutoSize = false; eventName.Location = new Point(10, 0); eventName.Size = new Size(IMAGE_WIDTH - 20, 30); //eventName.Font = new Font("Segoe UI Semibold", 12); eventName.Font = new Font("Arial", 12); eventName.ForeColor = Color.FromArgb(16, 16, 16); //eventName.BackColor = Color.White; eventName.TextAlign = ContentAlignment.MiddleLeft; int attempt = 0; while (true) { Size nameSize = Helper.CalculateLabelSize(eventName, 1000); if (nameSize.Width > eventName.Size.Width - 20) { eventName.Text = eventName.Text.Remove(eventName.Text.Length - 1); attempt++; continue; } else { if (attempt != 0) { eventName.Text += "..."; // Create tooltip ToolTip fullEventName = new ToolTip(); fullEventName.SetToolTip(eventName, eBrief.Name); } break; } } // Distance label Label distanceLabel = new Label(); distanceLabel.Font = new Font("Arial", 9); distanceLabel.ForeColor = Color.Gray; distanceLabel.Location = new Point(10, 25); distanceLabel.AutoSize = false; distanceLabel.TextAlign = ContentAlignment.MiddleCenter; double distance = MathSupplement.Distance(eBrief.Latitude, eBrief.Longitude, user.Latitude, user.Longitude); if (distance < 1000.0) { distanceLabel.Text = $"{distance:0}m"; } else { distanceLabel.Text = $"{distance / 1000.0:0.0}km"; } Size distanceLabelSize = Helper.CalculateLabelSize(distanceLabel, IMAGE_WIDTH); distanceLabel.Size = new Size(distanceLabelSize.Width, 30); // Separator panel Panel separatorPanel1 = new Panel(); separatorPanel1.Location = new Point(distanceLabel.Location.X + distanceLabel.Size.Width + 5, 33); separatorPanel1.Size = new Size(1, 16); separatorPanel1.BorderStyle = BorderStyle.FixedSingle; // Sport label Label sportLabel = new Label(); sportLabel.Font = new Font("Arial", 9); sportLabel.ForeColor = Color.Gray; sportLabel.Location = new Point(distanceLabel.Location.X + distanceLabel.Size.Width + 12, 25); sportLabel.AutoSize = false; sportLabel.TextAlign = ContentAlignment.MiddleCenter; try { sportLabel.Text = eBrief.Sports[0]; } catch { sportLabel.Text = ""; } Size sportLabelSize = Helper.CalculateLabelSize(sportLabel, IMAGE_WIDTH); sportLabel.Size = new Size(sportLabelSize.Width, 30); // Separator panel Panel separatorPanel2 = new Panel(); separatorPanel2.Location = new Point(sportLabel.Location.X + sportLabel.Size.Width + 5, 33); separatorPanel2.Size = new Size(1, 16); separatorPanel2.BorderStyle = BorderStyle.FixedSingle; // Date label Label dateLabel = new Label(); dateLabel.Font = new Font("Arial", 9); dateLabel.ForeColor = Color.Gray; dateLabel.Location = new Point(sportLabel.Location.X + sportLabel.Size.Width + 12, 25); dateLabel.AutoSize = false; dateLabel.TextAlign = ContentAlignment.MiddleCenter; { // Create date/time label string finalString = ""; if ((DateTime.Now - eBrief.StartDate).Ticks > 0) { int daysAgo = (DateTime.Now - eBrief.StartDate).Days; finalString += $"Happened "; if (daysAgo == 0) { finalString += "today"; } else if (daysAgo == 1) { finalString += $"{daysAgo} day ago"; } else { finalString += $"{daysAgo} days ago"; } } else { if (eBrief.StartDate.Year != DateTime.Now.Year) { finalString += $"{eBrief.StartDate:yyyy-MM-dd HH:mm}"; } else { if ((eBrief.StartDate - DateTime.Now).TotalDays == 1) { finalString += $"Tomorrow, {eBrief.StartDate:HH:mm}"; } else if ((eBrief.StartDate - DateTime.Now).TotalDays < 1) { finalString += $"Today, {eBrief.StartDate:HH:mm}"; } else { finalString += $"{eBrief.StartDate:MMMM dd, HH:mm}"; } } } dateLabel.Text = finalString; } Size dateLabelSize = Helper.CalculateLabelSize(dateLabel, IMAGE_WIDTH); dateLabel.Size = new Size(dateLabelSize.Width, 30); infoPanel.Controls.Add(eventName); infoPanel.Controls.Add(distanceLabel); infoPanel.Controls.Add(separatorPanel1); infoPanel.Controls.Add(sportLabel); infoPanel.Controls.Add(separatorPanel2); infoPanel.Controls.Add(dateLabel); //// Sport label //Label eventSports = new Label(); //eventSports.Text = ""; //eventSports.Font = new Font("Arial", 11); //foreach (var sport in eBrief.Sports) //{ // eventSports.Text += $"{sport} "; //} //eventSports.AutoSize = false; //eventSports.Location = new Point(0, 210); //eventSports.Size = new Size(180, 25); //eventSports.BackColor = Color.FromArgb(230, 230, 230); //eventSports.TextAlign = ContentAlignment.MiddleLeft; //// Distance label //Label eventDistance = new Label(); //eventDistance.Text = ""; //eventDistance.Font = new Font("Arial", 11, FontStyle.Bold); //eventDistance.Text += $"{distances[count] / 1000.0:0.0}km"; //eventDistance.AutoSize = false; //eventDistance.Location = new Point(180, 210); //eventDistance.Size = new Size(60, 25); //eventDistance.BackColor = Color.FromArgb(230, 230, 230); //eventDistance.TextAlign = ContentAlignment.MiddleCenter; //if (!isAddressAdded) //{ // eventDistance.Text = ""; //} // Add everything eventPanel.Controls.Add(thumbnail); eventPanel.Controls.Add(infoPanel); //eventPanel.Controls.Add(eventSports); //eventPanel.Controls.Add(eventDistance); eventGridPanel.Controls.Add(eventPanel); col = (++col) % COL_COUNT; count++; if (mainForm != null) { mainForm.FitCurrentPanel(); } // Redraw Invalidate(); } }
public void LoadMyEvents() { UserAccount acc = Program.UserDataManager.UserAccount; eventsPanel.Controls.Clear(); // Add create event button Button createEventButton = new Button(); createEventButton.BackColor = Color.FromArgb(109, 168, 135); createEventButton.FlatStyle = FlatStyle.Flat; createEventButton.FlatAppearance.BorderSize = 0; createEventButton.Location = new Point(0, 0); createEventButton.Size = new Size(ITEM_WIDTH, ITEM_HEIGHT); createEventButton.Font = new Font("Arial Rounded", 15.0f, FontStyle.Bold); createEventButton.ForeColor = Color.White; createEventButton.Text = "+ Create new event"; createEventButton.TextAlign = ContentAlignment.MiddleCenter; createEventButton.Click += createEventButton_Click; eventsPanel.Controls.Add(createEventButton); if (!acc.Can((uint)Permissions.MANAGE_SELF_EVENT)) { createEventButton.Enabled = false; createEventButton.Text = "Event creation disabled"; } // Get all events List <EventBrief> events = Program.DataProvider.GetEventsBrief(new EventOptions()); if (!acc.Can((uint)Permissions.EDIT_OTHER_EVENTS)) { events = events.Where(item => item.Author == acc.Id).ToList(); } else if (!acc.Can((uint)Permissions.MANAGE_SELF_EVENT)) { events = new List <EventBrief>(); } // Add events to display int counter = 1; foreach (var @event in events) { Panel eventPanel = new Panel(); eventPanel.Location = new Point(0, counter * (ITEM_HEIGHT + MARGINS)); eventPanel.Size = new Size(ITEM_WIDTH, ITEM_HEIGHT); Label eventName = new Label(); eventName.Font = new Font("Arial Rounded", 15.0f, FontStyle.Bold); eventName.Text = @event.Name; eventName.AutoSize = false; eventName.Location = new Point(0, 0); eventName.Size = new Size(ITEM_WIDTH, ITEM_HEIGHT); eventName.Padding = new Padding(10, 0, 0, 0); eventName.TextAlign = ContentAlignment.MiddleLeft; //eventName.BackColor = Color.FromArgb(109, 168, 135); eventName.BackColor = Color.FromArgb(230, 230, 230); eventName.MouseEnter += (s, e) => { eventName.BackColor = Color.FromArgb(210, 210, 210); }; eventName.MouseLeave += (s, e) => { eventName.BackColor = Color.FromArgb(230, 230, 230); }; eventName.Click += (sender, e) => { // Get full event data from database List <EventFull> eventData = Program.Client.SelectEventsFull(@event.Id); //Program.DataManager.Read(new DatabaseReader($"select from events_full id {@event.Id}"), out eventData); try { mainForm.ShowPanel(new EventEditorPanel(this, eventData[0], false)); //new EventEditorPanel(this, eventData[0], true).Show(); } catch (InvalidCastException) { Console.WriteLine($"ERROR: Event \"{@event.Name}\" can't be opened (invalid data)"); } catch (ArgumentOutOfRangeException) { Console.WriteLine($"ERROR: No events with id '{@event.Id}' retrieved from database"); } catch (NullReferenceException) { Console.WriteLine($"ERROR: database reader returned null"); } }; eventPanel.Controls.Add(eventName); eventsPanel.Controls.Add(eventPanel); counter++; } eventsPanel.Size = new Size(400, (ITEM_HEIGHT + MARGINS) * (events.Count + 1)); }