frmLogin.cs 8.6 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Comm;
using Dal;
using System.Web.UI.WebControls;
using MetroFramework.Forms;
using log4net;
using System.Reflection;

namespace App
{
    public partial class frmLogin : App.FrmBase
    {
        Fuction fuction = new Fuction();
        private string m_language;
        private bool isInit=false;

        public frmLogin()
        {
            InitializeComponent();
            this.SetLanguage(this);
            isInit = true;
            //this.cmb_Language.SelectedIndex = 0;
            chooseLanguage();
            isInit = false;
            this.ControlBox = true;
            //this.groupBox1.Text = getMsg("frmLogin");
            //this.lbl_Login.Text = getMsg("frmLoginlbl_Login");
            //this.lbl_OldPSW.Text = getMsg("frmLoginlbl_OldPSW");
            //this.lbl_Language.Text = getMsg("frmLoginlbl_Language");
            //this.btn_OK1.Text = getMsg("frmLoginbtn_OK1");
            //this.btn_Cancel1.Text = getMsg("frmLoginbtn_Cancel1");

            lblVersion.Text = getMsg("Version") + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

            LOGGER.Info("language is " + System.Globalization.CultureInfo.InstalledUICulture.Name+" + "+this.lblVersion.Text);

        }

        private void btn_OK1_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.AppStarting;//ÉèÖÃÊó±ê״̬ΪÆô¶¯×´Ì¬

            if (this.cmb_Language.SelectedIndex == 0)
                _loginLanguage = Const.LANGUAGE_CHINESE;
            else if (this.cmb_Language.SelectedIndex == 1)
                _loginLanguage = Const.LANGUAGE_ENGLISH;
            else
                _loginLanguage = Const.LANGUAGE_JAPANESE;


            if (this.txt_Login.Text.Trim() == "")
            {
                ShowMessageBox.ShowErrorWithoutAppGlobal(
                    Const.MESSAGEBOX_TITLE_NOTE, this.lbl_Login.Text, Const.ERROR_NONE, _loginLanguage);
                return;
            }
            string LoginName=this.txt_Login.Text.Trim();
            string Password=this.txt_OldPSW.Text;       
            
            int login=LoginSystem(LoginName, Password);
            if (login > 0)
            {
                fuction.CreateParaConfig("", LoginName, Const.USER_LANGUAGE, _loginLanguage);
                fuction.LoadXML(LoginName);
                DialogResult = DialogResult.Yes;
                this.Close();

            }
            else
            {
            ShowMessageBox.ShowErrorWithoutAppGlobal(
                    Const.MESSAGEBOX_TITLE_NOTE,"",login , _loginLanguage);
                this.txt_OldPSW.Text = string.Empty;
                txt_OldPSW.Focus();
            }

        }
        /// <summary>
        /// µÇ¼ϵͳ
        /// </summary>
        /// <param name="LoginName">µÇ¼Ãû</param>
        /// <param name="Password">ÃÜÂë</param>
        /// <returns></returns>
        public int  LoginSystem(string LoginName, string Password)
        {
            int login=fuction.GetLoginInfoByLoginName(LoginName).Rows.Count;

            if (login <= 0)
            { 
                return Const.ERROR_LOGINNAME_NOT_EXIST;
            }
            login = fuction.GetEmployeeByLoginNameAndPassword(LoginName, Utility.SimpleEncode(Password, Utility.getExpandString(LoginName, 10)));

            if (login <= 0)
            {
                return Const.ERROR_PASSWORD_WRONG;
            }
            else
            {
                return 1;
            }
        }




        private void cmb_Language_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!isInit)
            {
                chooseLanguage();
            }
        }
        private void chooseLanguage()
        {
            if (!isInit)
            {
                if (cmb_Language.SelectedIndex == 0)
                    m_language = Const.LANGUAGE_CHINESE;
                else if (cmb_Language.SelectedIndex == 1)
                    m_language = Const.LANGUAGE_ENGLISH;
                else
                    m_language = Const.LANGUAGE_JAPANESE;
                
            }
            else
            {
                m_language = fuction.GetParameterByParaName(Const.USER_LANGUAGE, "currency");
                if (m_language.Equals(Const.LANGUAGE_CHINESE))
                {
                    cmb_Language.SelectedIndex = 0;
                }
                else if (m_language.Equals(Const.LANGUAGE_ENGLISH))
                {
                    cmb_Language.SelectedIndex=1;
                }
                else if (m_language.Equals(Const.LANGUAGE_JAPANESE))
                {
                    cmb_Language.SelectedIndex = 2;
                }
                else
                {
                    cmb_Language.SelectedIndex = 0;
                }

            }
            Fuction.m_Language = m_language;
            this.SetLanguage(this);
            lblVersion.Text = getMsg("Version") + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
        }

        private void btn_OK1_Click_1(object sender, EventArgs e)
        {
            login();
        }
        private void login()
        {
            Cursor.Current = Cursors.AppStarting;//ÉèÖÃÊó±ê״̬ΪÆô¶¯×´Ì¬

            if (this.cmb_Language.SelectedIndex == 0)
                _loginLanguage = Const.LANGUAGE_CHINESE;
            else if (this.cmb_Language.SelectedIndex == 1)
                _loginLanguage = Const.LANGUAGE_ENGLISH;
            else
                _loginLanguage = Const.LANGUAGE_JAPANESE;


            if (this.txt_Login.Text.Trim() == "")
            {
                ShowMessageBox.ShowErrorWithoutAppGlobal(
                    Const.MESSAGEBOX_TITLE_NOTE, this.lbl_Login.Text, Const.ERROR_NONE, _loginLanguage);
                return;
            }
            string LoginName = this.txt_Login.Text.Trim();
            string Password = this.txt_OldPSW.Text;

            int login = LoginSystem(LoginName, Password);
            if (login > 0)
            {
                fuction.CreateParaConfig("", "currency", Const.USER_LANGUAGE, _loginLanguage);
                fuction.LoadXML(LoginName);
                DialogResult = DialogResult.Yes;
                this.Close();

            }
            else
            {
                ShowMessageBox.ShowErrorWithoutAppGlobal(
                        Const.MESSAGEBOX_TITLE_NOTE, "", login, _loginLanguage);
                this.txt_OldPSW.Text = string.Empty;
                txt_OldPSW.Focus();
            }
        }

        private void txt_Login_KeyDown(object sender, KeyEventArgs e)
        {
            if((int)e.KeyCode == 13)
            {
                e.SuppressKeyPress = true;
            }
        }

        private void txt_OldPSW_KeyDown(object sender, KeyEventArgs e)
        {
            if ((int)e.KeyCode == 13)
            {
                e.SuppressKeyPress = true;
            }
        }

        private void btnSetting_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    FrmManageConfig frmManageConfig = new FrmManageConfig();
            //    frmManageConfig.TopMost = true;
            //    frmManageConfig.ShowDialog();
            //    frmManageConfig.Activate();
            //    //¼ì²âÊÇ·ñÒªÖØÆô
            //    if (frmManageConfig.ReStart)
            //    {
            //        this.DialogResult = DialogResult.Retry;
            //        this.Close();
            //    }
            //}
            //catch (Exception ex)
            //{
            //    LOGGER.Info(ex.StackTrace);
            //}
        }

        private void btn_Cancel1_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Application.Exit();
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            this.TopMost = true;
            this.Activate();
            
        }
        

        private void txt_Login_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                login();
            }
        }

        private void txt_OldPSW_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                login();
            }
        }

        private void btnSetting_Click_1(object sender, EventArgs e)
        {

        }

        private void btn_Cancel1_Click_1(object sender, EventArgs e)
        {

        }
 
    }
}