using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SinosysHardware.Business;

namespace SinosysHardware.UI
{
    public partial class Logon : Form
    {
        public Logon()
        {
            InitializeComponent();
        }
        
        private void btnLogon_Click(object sender, EventArgs e)
        {
            if(this.txtUserName.Text.Trim()!="")
            {
                if (this.txtPassword.Text.Trim() != "")
                {
                    RoleDB rdb=new RoleDB();
                    bool flag = rdb.VerifyCredentials(txtUserName.Text.Trim(), txtPassword.Text.Trim());
                    if(flag)
                    {
                     switch((int)this.cboRole.SelectedValue)
                     {
                         case 2:
                             CustomerService cs = new CustomerService();
                             cs.ShowDialog();
                             cs.Dispose();
                             break;
                         case 3:
                             Warehouse wh = new Warehouse();
                             wh.ShowDialog();
                             wh.Dispose();
                             break;
                         case 4:
                             Deliveries ds = new Deliveries();
                             ds.ShowDialog();
                             ds.Dispose();
                             break;
                     }
                    }
                    else
                    {
                     MessageBox.Show("权限无效");
                        txtUserName.Text="";
                        txtPassword.Text="";
                        txtUserName.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("密码无效！");
                    txtPassword.Focus();
                }
            }
            else
            {
                MessageBox.Show("用户名无效！");
                txtUserName.Focus();
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Logon_Load(object sender, EventArgs e)
        {
            RoleDB rdb = new RoleDB();
            DataSet Ds = rdb.GetRoles();    
            this.cboRole.DisplayMember = "Role";
            this.cboRole.ValueMember = "RoleId";
            this.cboRole.DataSource = Ds.Tables[0].DefaultView;
          
        }
    }
}