Ejemplo n.º 1
0
 public void KeyEvents()
 {
     Username.KeyDown += (_, e) =>
     {
         if (e.KeyCode == Keys.Enter)
         {
             if (IsAdmin(Username.Text) && AccountsList[Username.Text] == Password.Text)
             {
                 ResetRetryTimer();
             }
             ButtonCodesReturn("Login");
         }
     };
     Password.KeyDown += (_, e) =>
     {
         if (e.KeyCode == Keys.Enter)
         {
             if (IsAdmin(Username.Text) && AccountsList[Username.Text] == Password.Text)
             {
                 ResetRetryTimer();
             }
             ButtonCodesReturn("Login");
         }
     };
     AddProduct.KeyDown += (_, e) =>
     {
         if (e.KeyCode == Keys.Enter)
         {
             if (AddProduct.Text == "")
             {
                 ToastNotification.Show(this, "Input product name first");
                 return;
             }
             if (SalesView.ReadOnly)
             {
                 ToastNotification.Show(this, ($"Can't add the product because you are on viewing mode only"));
                 return;
             }
             if (CurrentTable == null)
             {
                 ToastNotification.Show(SalesView, "No Available Sales or Selected Sales");
                 return;
             }
             if (CurrentTable.Columns.Contains(AddProduct.Text))
             {
                 ToastNotification.Show(SalesView, $"{AddProduct.Text} already existing");
                 return;
             }
             if (MessageBoxEx.Show($"Do you want to add this product: {AddProduct.Text}", "Add Product", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
                 CurrentTable.AddColumns(0, AddProduct.Text);
                 SetSalesView();
                 NotSaved = true;
             }
         }
     };
     AddAgent.KeyDown += (_, e) =>
     {
         if (e.KeyCode == Keys.Enter)
         {
             if (AddAgent.Text == "")
             {
                 ToastNotification.Show(this, "Input agent name first");
                 return;
             }
             if (SalesView.ReadOnly)
             {
                 ToastNotification.Show(this, ($"Can't add the agent because you are on viewing mode only"));
                 return;
             }
             if (Regex.IsMatch(AddAgent.Text, "[0-9]"))
             {
                 ToastNotification.Show(SalesView, "Numeric characters are invalid");
                 return;
             }
             if (CurrentTable == null)
             {
                 ToastNotification.Show(SalesView, "No Available Sales or Selected Sales");
                 return;
             }
             if (CurrentTable.Rows.Contains(AddAgent.Text))
             {
                 ToastNotification.Show(SalesView, $"{AddAgent.Text} is already existing");
                 return;
             }
             if (MessageBoxEx.Show($"Do you want to add this agent: {AddAgent.Text}", "Add Agent", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
                 CurrentTable.Rows.Add(AddAgent.Text);
                 SetSalesView();
                 NotSaved = true;
             }
         }
     };
     AccountControls.AddRange(new Control[] { AccountUsername, AccountPassword, AccountManagerName, AccountSecretAnswer, AccountSecretQuestion, AccountStatus });
     ManagerList.SelectedValueChanged += (_, ee) =>
     {
         AutoCreate.Value = false;
         AutoCreate.Refresh();
         SalesCalendar.SelectionStart = DateTime.Now;
         SalesCalendar.SelectionEnd   = DateTime.Now;
         SetSalesDataSet(ManagerList.SelectedItem.ToString(), this);
         StatusLabel.Text        = CurrentUser;
         MainStatusPanel.Visible = true;
     };
     AccountSecretQuestion.Items.AddRange(SecretQuestionList.ToArray());
     AccountStatus.Items.AddRange(new string[] { "admin", "Online", "Offline" });
     AccountsView.ReadOnly   = true;
     AccountsView.CellClick += (_, ee) =>
     {
         if (ee.RowIndex < 0)
         {
             return;
         }
         if (RegisterButton.Text == "Register")
         {
             ToastNotification.Show(this, "Can't edit data for now because you're in Create Account Mode");
             return;
         }
         BindFields(AccountsView.Rows[ee.RowIndex]);
     };
     AutoSave.ValueChanged += (_, e) =>
     {
         SaveButton.Enabled = !AutoSave.Value;
     };
     AccountsView.UserDeletedRow += (_, e) =>
     {
         if (AutoSave.Value)
         {
             ButtonCodesReturn("Save Changes");
         }
     };
     AccountsView.UserAddedRow += (_, e) =>
     {
         if (AutoSave.Value)
         {
             ButtonCodesReturn("Save Changes");
         }
     };
     AccountsView.CellValueChanged += (_, e) =>
     {
         if (AutoSave.Value)
         {
             ButtonCodesReturn("Save Changes");
         }
     };
     AccountsView.DataError += (_, e) =>
     {
         e.ThrowException = false;
     };
 }