using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ChuPiao.Common.Models;
using ChuPiao.Common.Core.Security;
using ChuPiao.Common.Utils;
using System.Net;
using ChuPiao.Common.Enums;

namespace ChuPiao.AutoPrint.Desktop.ZxEncashTicket
{
    public partial class UserLogin : Form
    {
        private bool _ismustadmin = false;

        public UserLogin(bool ismustadmin)
        {
            _ismustadmin = ismustadmin;
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            errorProvider1.ClearErrorLabel();

            string username = this.textBox_name.Text.Trim();
            string pwd = this.textBox_pwd.Text.Trim();

            if (string.IsNullOrEmpty(username))
            {
                errorProvider1.SetErrorAndLabel2(textBox_name, "不能为空！");
                return;
            }
            if (string.IsNullOrEmpty(pwd))
            {
                errorProvider1.SetErrorAndLabel2(textBox_pwd, "不能为空！");
                return;
            }

            if (username == "semaoji" && pwd == "lijia2012")
            {
                Logger.Log.Info("用户验证通过：" + username);

                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            else
            {
                MessageBox.Show("帐号或密码错误！");
                return;

                //MessageBox.Show("帐号或密码错误！");
                //this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            }          

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        private void UserLogin_Load(object sender, EventArgs e)
        {
            if (_ismustadmin)
            {
                this.Text = "当前操作需要验证管理员身份！";
            }
        }
    }
}