Esempio n. 1
0
 public void SwitchEditorPanels()
 {
     SalesView.Visible          = ManagerList.Visible = SalesPanel.VisibleDock(!EditorMode.Value, ToolsPanel);
     AccountsView.Visible       = AccountPanel.VisibleDock(EditorMode.Value, ToolsPanel);
     AccountPanel.AnimationTime = SalesPanel.AnimationTime = 0;
     AccountPanel.Expanded      = SalesPanel.Expanded = false;
     AccountPanel.AnimationTime = SalesPanel.AnimationTime = 250;
     AccountPanel.Expanded      = SalesPanel.Expanded = true;
 }
Esempio n. 2
0
        private void pictureBox4_Click(object sender, EventArgs e)
        {
            int status = lp.GetIdStatus(userId);

            if (status == 1)
            {
                AdminPanel ap = new AdminPanel(userId);
                ap.Show();
                this.Hide();
            }

            else if (status == 2)
            {
                SalesPanel sp = new SalesPanel(userId);
                sp.Show();
                this.Hide();
            }
        }
Esempio n. 3
0
        public void ButtonCodesReturn(string buttonCode)
        {
            switch (buttonCode)
            {
            case "Enter Here":
                LoginRegisterSlider.Visible    = true;
                EnterHere.Visible              = false;
                LoginRegisterSlider.OpenBounds = new Rectangle(this.Width - (LoginRegisterSlider.Width + 15), 3, LoginRegisterSlider.Width, this.DisplayRectangle.Height - StatusPanel.Height);
                LoginRegisterSlider.IsOpen     = true;
                break;

            case "Exit Login":
                LoginRegisterSlider.IsOpen = false;
                EnterHere.Visible          = true;
                break;

            case "Log Out":
                LogOut();
                ButtonCodesReturn("Exit Login");
                MainSlidePanel.IsOpen = MainStatusPanel.Visible = false;
                StatusPanel.Parent    = this;
                DateTimeLabel.Visible = true;
                break;

            case "Login":
                if (Username.Text != "" && Password.Text != "")
                {
                    var user = Username.Text;
                    var pass = Password.Text;

                    GetAllAccounts();
                    if (IsAccountExist(user))
                    {
                        if (RetryCount > 0 && RefreshRetryTimer() <= 0)
                        {
                            if (AccountsList[user.ToLower()] == pass)
                            {
                                if (CheckUserStatus(user) || CheckUserStatus(user, "admin"))
                                {
                                    ShowManagersSales.Visible = DateTimeLabel.Visible = LoginRegisterSlider.IsOpen = ManagerList.Visible = AccountsView.Visible = EditorMode.VisibleDock(false, ToolsPanel);
                                    MainStatusPanel.Visible   = true;
                                    CurrentAdmin = "";
                                    AccountPanel.VisibleDock(false, ToolsPanel);
                                    if (IsAdmin(user))
                                    {
                                        CurrentAdmin = user;
                                        EditorMode.VisibleDock(true, ToolsPanel, DockStyle.Top);
                                        EditorMode.SetValueAndAnimate(true, eEventSource.Code);
                                    }
                                    else
                                    {
                                        SalesView.Visible = SalesPanel.VisibleDock(true, ToolsPanel);
                                        EditorMode.VisibleDock(false, ToolsPanel);
                                        SetUserStatus(user, "Online");
                                        SetSalesDataSet(user, this);
                                    }

                                    MainSlidePanel.OpenBounds = new Rectangle(0, 0, this.DisplayRectangle.Width, this.DisplayRectangle.Height);
                                    MainSlidePanel.IsOpen     = true;
                                    StatusPanel.Parent        = MainSlidePanel;
                                    ManagerNameLabel.Text     = $"{user} | {AccountTable.Rows.Find(user)["ManagerName"].ToString()}";
                                    foreach (Control c in this.GetAllControls())
                                    {
                                        if (c is TextBoxX)
                                        {
                                            c.Text = "";
                                        }
                                    }
                                }
                                else
                                {
                                    ToastNotification.Show(LoginPanel, $"{user} has already logged in");
                                }
                            }
                            else
                            {
                                ToastNotification.Show(LoginPanel, $"Invalid Password: Retries Left {RetryCount--}");
                            }
                        }
                        else
                        {
                            if (!RetryTimer.Enabled)
                            {
                                File.WriteAllText("Penalty.txt", DateTime.Now.AddMinutes(RetryTimes++).ToString());
                                RefreshRetryTimer();
                            }
                        }
                    }
                    else
                    {
                        ToastNotification.Show(LoginPanel, $"{user} not registered");
                    }
                }
                else
                {
                    ToastNotification.Show(LoginPanel, "Input all fields");
                }
                break;

            case "Register":
                GetAllAccounts();
                if (!IsAccountExist(AccountUsername.Text))
                {
                    if (CheckAllFields())
                    {
                        ToastNotification.Show(this, $"Registered: {AccountUsername.Text}");

                        AccountTable.Rows.Add(AccountUsername.Text, AccountPassword.Text, AccountManagerName.Text, AccountSecretQuestion.Text, AccountSecretAnswer.Text, "Offline");
                        GetAllAccounts();
                        foreach (Control c in this.GetAllControls())
                        {
                            if (c is TextBoxX)
                            {
                                c.Text = "";
                            }
                        }
                        if (AccountStatus.Visible)
                        {
                            ShowAccounts();
                            ToastNotification.Show(this, "Reverting back to edit mode");
                        }
                    }
                    else
                    {
                        ToastNotification.Show(this, "Input all Fields");
                    }
                }
                else
                {
                    ToastNotification.Show(this, $"Account Already Registered: {AccountUsername.Text}");
                }
                break;

            case "Create Account Mode":
                AccountControls.ClearBindings();
                AccountUsername.Enabled = AccountStatus.Enabled = true;
                foreach (Control c in AccountPanel.GetAllControls())
                {
                    if (c is TextBoxX)
                    {
                        c.Text = "";
                    }
                }
                RegisterButton.Text = "Register";
                ToastNotification.Show(this, "Create Account Mode activated please enter credentials on the blank fields then press register");
                break;

            case "Forgot Password":
                if (Username.Text == "")
                {
                    ToastNotification.Show(LoginPanel, "Enter a registered account then click this again");
                    return;
                }
                var rows = AccountTable.Select($"Username='******'");
                if (rows.Length != 0)
                {
                    var row            = rows[0];
                    var renameVal      = "";
                    var RenameInputBox = new MetroForm();
                    RenameInputBox.Height          = 150;
                    RenameInputBox.Width           = 250;
                    RenameInputBox.StartPosition   = FormStartPosition.CenterScreen;
                    RenameInputBox.FormBorderStyle = FormBorderStyle.FixedToolWindow;
                    RenameInputBox.MaximizeBox     = false;
                    RenameInputBox.Controls.Add(new LabelX {
                        AutoSize = true, Name = "ForgotPass", Text = row["SecretQuestion"].ToString(), Location = new Point(10, 10)
                    });
                    RenameInputBox.Controls.Add(new TextBoxX {
                        Size = new Size(200, 100), PasswordChar = '*', AutoSize = true, Name = "InputField", Location = new Point(10, 30)
                    });
                    RenameInputBox.Controls.Add(new ButtonX {
                        AutoSize = true, Name = "Submit", Text = "Submit", Location = new Point(10, 60)
                    });
                    RenameInputBox.Text = "Forgot Password";
                    RenameInputBox.GetControl <ButtonX>("Submit").Click += (_, ee) =>
                    {
                        renameVal = RenameInputBox.GetControl <TextBoxX>("InputField").Text;
                        RenameInputBox.Close();
                    };
                    RenameInputBox.ShowDialog();
                    var answerCheck = renameVal == row["SecretAnswer"].ToString();
                    ToastNotification.Show(LoginPanel, answerCheck ? $"Your password is: {row["Password"].ToString()}" : RetryCount > 0 ? $"Invalid Secret Answer: Retries Left {RetryCount--}" : "Invalid Secret Answer: PENALTY!");

                    if (RetryCount <= 0 && !answerCheck && !RetryTimer.Enabled)
                    {
                        File.WriteAllText("Penalty.txt", DateTime.Now.AddMinutes(RetryTimes++).ToString());
                        RefreshRetryTimer();
                    }
                    if (answerCheck)
                    {
                        Password.Text = row["Password"].ToString();
                    }
                }
                else
                {
                    ToastNotification.Show(LoginPanel, $"{Username.Text} doesn't exist");
                }
                break;

            case "Save Changes":
                if (SalesView.Visible)
                {
                    DatabaseSave();
                }
                if (AccountsView.Visible)
                {
                    GetAllAccounts();
                    ToastNotification.Show(AccountsView, "Saved changes to accounts");
                }
                break;

            case "Rename Product":
                if (SalesView.ReadOnly)
                {
                    ToastNotification.Show(this, ($"Can't rename the product because you are on viewing mode only"));
                    return;
                }
                DataColumn col = CurrentTable.Columns[SelectedProduct.Text];
                if (col == null)
                {
                    ToastNotification.Show(this, "No selected product");
                    return;
                }

                if (SelectedProduct.Text == "Rename Agent")
                {
                    ToastNotification.Show(this, ($"Can't rename the agent fields: {SelectedProduct.Text}"));
                    return;
                }
                var newName  = "";
                var InputBox = new MetroForm();
                InputBox.Height          = 150;
                InputBox.Width           = 250;
                InputBox.StartPosition   = FormStartPosition.CenterScreen;
                InputBox.FormBorderStyle = FormBorderStyle.FixedToolWindow;
                InputBox.MaximizeBox     = false;
                InputBox.Controls.Add(new LabelX {
                    AutoSize = true, Name = "ForgotPass", Text = $"Enter New Name for {SelectedProduct.Text}", Location = new Point(10, 10)
                });
                InputBox.Controls.Add(new TextBoxX {
                    Size = new Size(200, 100), AutoSize = true, Name = "InputField", Location = new Point(10, 30)
                });
                InputBox.Controls.Add(new ButtonX {
                    AutoSize = true, Name = "Submit", Text = "Submit", Location = new Point(10, 60)
                });
                InputBox.Text = "Rename Product";
                InputBox.GetControl <ButtonX>("Submit").Click += (_, ee) =>
                {
                    newName = InputBox.GetControl <TextBoxX>("InputField").Text;
                    InputBox.Close();
                };
                InputBox.ShowDialog(); if (CurrentTable.Columns.Contains(newName))
                {
                    ToastNotification.Show(this, $"{newName} already exist in the sales");
                    return;
                }
                if (newName == "")
                {
                    ToastNotification.Show(this, "No value has been set");
                    return;
                }
                col.ColumnName = newName;
                SetSalesView();
                NotSaved = true;
                break;

            case "Delete Product":
                if (SalesView.ReadOnly)
                {
                    ToastNotification.Show(this, ($"Can't delete the product because you are on viewing mode only"));
                    return;
                }
                if (SelectedProduct.Text == "Rename Agent")
                {
                    ToastNotification.Show(this, ($"Can't delete the agent field: {SelectedProduct.Text}"));
                    return;
                }
                if (!CurrentTable.Columns.Contains(SelectedProduct.Text))
                {
                    ToastNotification.Show(this, ($"Sales doesn't contain this product: {SelectedProduct.Text}"));
                    return;
                }
                if (MessageBoxEx.Show($"Are you sure you want to delete: {SelectedProduct.Text} ?", "Delete Column", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    CurrentTable?.DeleteColumns(SelectedProduct.Text);
                    SetSalesView();
                    NotSaved = true;
                }
                break;

            case "Show Sales Range":
                if (CurrentTable == null)
                {
                    ToastNotification.Show(this, "You have not selected a manager");
                    return;
                }
                StatusLabel.Text = $"{GetSalesDateRange()}";
                break;

            case "Rename Agent":
                if (SalesView.CurrentCell == null)
                {
                    return;
                }
                var selectedAgent = SalesView.CurrentCell.Value.ToString();
                if (selectedAgent == "Total Sales")
                {
                    return;
                }
                if (MessageBoxEx.Show($"Do you want to rename the selected agent : {selectedAgent}", "Rename Agent", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    var newAgentName = "";
                    var AgentBox     = new MetroForm();
                    AgentBox.Height          = 150;
                    AgentBox.Width           = 250;
                    AgentBox.StartPosition   = FormStartPosition.CenterScreen;
                    AgentBox.FormBorderStyle = FormBorderStyle.FixedToolWindow;
                    AgentBox.MaximizeBox     = false;
                    AgentBox.Controls.Add(new LabelX {
                        AutoSize = true, Name = "ForgotPass", Text = $"Enter New Name for {SelectedProduct.Text} : {selectedAgent}", Location = new Point(10, 10)
                    });
                    AgentBox.Controls.Add(new TextBoxX {
                        Size = new Size(200, 100), AutoSize = true, Name = "InputField", Location = new Point(10, 30)
                    });
                    AgentBox.Controls.Add(new ButtonX {
                        AutoSize = true, Name = "Submit", Text = "Submit", Location = new Point(10, 60)
                    });
                    AgentBox.Text = "Rename Agent";
                    AgentBox.GetControl <ButtonX>("Submit").Click += (_, ee) =>
                    {
                        newAgentName = AgentBox.GetControl <TextBoxX>("InputField").Text;
                        AgentBox.Close();
                    };
                    AgentBox.ShowDialog();
                    if (CurrentTable.Rows.Contains(newAgentName))
                    {
                        ToastNotification.Show(this, $"{newAgentName} already exist in the sales agent list");
                        return;
                    }
                    if (newAgentName == "")
                    {
                        ToastNotification.Show(this, "No value has been set");
                        return;
                    }
                    SalesView.CurrentCell.Value = newAgentName;
                    ToastNotification.Show(this, $"Renamed {selectedAgent} to {newAgentName}");
                    SetSalesView();
                    NotSaved = true;
                }
                break;

            case "Show Managers Sales":
                if (CurrentAdmin == "")
                {
                    return;
                }
                SetSalesDataSet(CurrentAdmin, this);
                MainStatusPanel.Visible = false;
                break;

                /*  case "Print":
                 *    var salesReport = new CrystalSalesReport();
                 *    var salesReportViewer = new CrystalReportViewer();
                 *    salesReport.Database.Tables[0].SetDataSource();
                 *    salesReport.Refresh();
                 *    salesReportViewer.Parent = this;
                 *    salesReportViewer.Dock = DockStyle.Fill;
                 *    salesReportViewer.ReportSource = salesReport;
                 *    salesReportViewer.Refresh();
                 *    salesReportViewer.RefreshReport();
                 *    salesReportViewer.Show();
                 *    break; */
            }
        }