using SwanCSharp.Users;
using SwanCSharp.DataAccess;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace UserManage
{
    public partial class Form1 : Form
    {
        public UserManagement gobjUserManage = null;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            gobjUserManage = new UserManagement("CONTROL-TRAFICO\\SQLEXPRESS", "Database");
            gobjUserManage.ShowLoginWindow(UserManagement.InterfaceLanguage.English);
            if (!gobjUserManage.LoggedIn)
            {
                MessageBox.Show("Login incorrect.", "Test", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Dispose();
            }
            MenuManage();
        }

        private void MenuManage()
        {
            // Standard User
            if (gobjUserManage.Profile == UserManagement.UserProfiles.StandardUser)
            {
                mnuSave.Enabled = false;
                mnuSetup.Enabled = false;
                mnuDelete.Enabled = false;
            }
            // Administrator
            else if (gobjUserManage.Profile == UserManagement.UserProfiles.Administrator)
            {
                mnuDelete.Enabled = false;
                mnuAddUser.Enabled = false;
            }
        }

        private void mnuAddUser_Click(object sender, EventArgs e)
        {
            try
            {
                gobjUserManage.ShowUserAddWindow(gobjUserManage.Profile, UserManagement.InterfaceLanguage.English);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void mnuRemoveUser_Click(object sender, EventArgs e)
        {
            try
            {
                gobjUserManage.ShowUserRemoveWindow(gobjUserManage.Profile, UserManagement.InterfaceLanguage.English);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void mnuChangePassword_Click(object sender, EventArgs e)
        {
            try
            {
                gobjUserManage.ShowUserPasswordChangeWindow(gobjUserManage.UserName, UserManagement.InterfaceLanguage.English);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}