Пример #1
0
        private void confirm_Click(object sender, EventArgs e)
        {
            ComponentResourceManager res = new ComponentResourceManager(typeof(DailyAdminForm));

            if (nameBox.Text == "")
            {
                errorProvider.SetError(nameLabel, res.GetString("error.EmptyName"));
                nameBox.Focus();
                SystemSounds.Beep.Play();
                return;
            }
            if (AddMode && passwordBox.Text == "")
            {
                errorProvider.SetError(passwordLabel, res.GetString("error.EmptyName"));
                passwordLabel.Focus();
                SystemSounds.Beep.Play();
                return;
            }
            DialogResult = DialogResult.OK;
            if (AddMode)
            {
                ValueReturn = new DailyAdmin(nameBox.Text, passwordBox.Text);
            }
            else
            {
                ValueReturn.Name = nameBox.Text;
                if (passwordBox.Text != "")
                {
                    ValueReturn.ChangePassword(passwordBox.Text);
                }
            }
            Close();
        }
Пример #2
0
        private void SyncWorkdaySelections()
        {
            if (listView1.Tag != null)
            {
                CheckBox[] selections = new CheckBox[7] {
                    sun, mon, tue, wed, thur, fri, sat
                };
                DailyAdmin lastSelect = (DailyAdmin)listView1.Tag;

                for (int i = 0; i < selections.Length; i++)
                {
                    CheckBox checkBox = selections[i];
                    if (checkBox.Checked && !lastSelect.WorkingDays.Contains((DayOfWeek)i))
                    {
                        lastSelect.WorkingDays.Add((DayOfWeek)i);
                    }
                    else if (!checkBox.Checked && lastSelect.WorkingDays.Contains((DayOfWeek)i))
                    {
                        lastSelect.WorkingDays.Remove((DayOfWeek)i);
                    }
                }

                listView1.Tag = null;
            }
        }
Пример #3
0
        public DailyAdminForm(DailyAdmin admin)
        {
            InitializeComponent();
            Utility.ApplySource(this);
            ValueReturn = admin;
            AddMode     = false;

            nameBox.Text = admin.Name;
        }
Пример #4
0
        private void UpdateSelections(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            CheckBox[] selections = new CheckBox[7] {
                sun, mon, tue, wed, thur, fri, sat
            };
            ComponentResourceManager res = new ComponentResourceManager(typeof(ProjectForm));

            listView1.ContextMenu = new ContextMenu();
            if (listView1.SelectedItems.Count == 1)
            {
                SyncWorkdaySelections();
                foreach (CheckBox checkBox in selections)
                {
                    checkBox.Checked = false;
                    checkBox.Enabled = true;
                }
                DailyAdmin modify = dailyAdmins.Find((it) => it.Name == listView1.SelectedItems[0].Text);
                listView1.Tag = modify;

                modify.WorkingDays.ForEach((day) =>
                {
                    selections[(int)day].Checked = true;
                });

                listView1.ContextMenu.MenuItems.Add(res.GetString("properities"),
                                                    (s, ea) =>
                {
                    DailyAdminForm form = new DailyAdminForm(modify);
                    form.ShowDialog();
                    form.Dispose();
                }
                                                    );
            }
            else
            {
                SyncWorkdaySelections();
                foreach (CheckBox checkBox in selections)
                {
                    checkBox.Enabled = false;
                }
            }
            listView1.ContextMenu.MenuItems.Add(res.GetString("remove"),
                                                (s, ea) =>
            {
                ListView.SelectedListViewItemCollection selected = listView1.SelectedItems;
                foreach (ListViewItem item in selected)
                {
                    listView1.Items.Remove(item);
                    dailyAdmins.RemoveAll((it) => it.Name == item.Text);
                }
            }
                                                );
        }
Пример #5
0
        public Form1()
        {
            Settings.Default.Language = Settings.Default.Language ?? Thread.CurrentThread.CurrentCulture.Name;
            Icon = Resources.AppIcon;
            InitializeComponent();
            Relayout();
            //FormBorderStyle = FormBorderStyle.None;
            ComponentResourceManager res = new ComponentResourceManager(typeof(Form1));

            notifyIcon.Text        = res.GetString("this.Text");
            notifyIcon.Icon        = Resources.AppIcon;
            notifyIcon.ContextMenu = new ContextMenu();
            notifyIcon.ContextMenu.MenuItems.Add(res.GetString("exit"), (e, a) => {
                Application.Exit();
            });

            FormClosed += (sender, e) =>
            {
                if (Settings.Default.Scoreboards != null)
                {
                    Settings.Default.Scoreboards.Clear();
                    scoreboards.ForEach((it) =>
                    {
                        if (!it.Removed)
                        {
                            Settings.Default.Scoreboards.Add(it.ToString());
                        }
                    });
                }
                Settings.Default.Save();
            };
            listView.ItemSelectionChanged += (sender, e) =>
            {
                recordScore.Enabled = unlocked.CanChangeScore && listView.SelectedItems.Count > 0;
                UpdatePropertiesButtons();
                DrawCharts();
            };
            adminBox.DropDownItemClicked += (sender, e) =>
            {
                int oldIndex = adminBox.Tag != null ? (int)adminBox.Tag : adminBox.DropDownItems.Count - 1;
                adminBox.Tag = adminBox.SelectedIndex;
                if (adminBox.SelectedIndex < adminBox.DropDownItems.Count - 1)
                {
                    bool       isAdmin = adminBox.SelectedIndex == 0;
                    DailyAdmin target  = !isAdmin ? CurrentProject.TodaysAdmins[adminBox.SelectedIndex - 1] : null;
                    EditValue  edit    = new EditValue(isAdmin ? res.GetString("password.Chief") : res.GetString("password.Speciafic").Replace("%s", target.Name), true);
                    if (edit.ShowDialog() == DialogResult.OK)
                    {
                        MatchResult result = CurrentProject.MatchPassword(edit.ValueReturn);
                        void showError()
                        {
                            MessageBox.Show(res.GetString("error.WrongPassword"), res.GetString("validate.Text"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                            adminBox.SelectedIndex = oldIndex;
                        }

                        if (isAdmin)
                        {
                            if (result.Permission == Permission.ChiefAdmin)
                            {
                                unlocked = MatchResult.ChiefAdmin;
                                UpdateRibbonMenu();
                            }
                            else
                            {
                                showError();
                            }
                        }
                        else
                        {
                            if (result.Permission == Permission.DailyAdmin && result.Admin.Equals(target))
                            {
                                unlocked = result;
                                UpdateRibbonMenu();
                            }
                            else
                            {
                                showError();
                            }
                        }
                    }
                    else
                    {
                        adminBox.SelectedIndex = oldIndex;
                    }
                    edit.Dispose();
                }
                else
                {
                    unlocked = MatchResult.Locked;
                    UpdateRibbonMenu();
                }
            };

            if (Settings.Default.Scoreboards != null)
            {
                foreach (string json in Settings.Default.Scoreboards)
                {
                    try
                    {
                        Scoreboard.Scoreboard scoreboard = Scoreboard.Scoreboard.Deserialize(json);
                        scoreboards.Add(scoreboard);
                        scoreboard.NewForm(this).Show();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.GetType().FullName + ": " + e.Message, res.GetString("error.LoadScoreboard"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }