コード例 #1
0
ファイル: MESLoginDialog.cs プロジェクト: ChenglongMa/DNA_MES
        /// <summary>
        /// 更换IP
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnchangeServerIP_Click(object sender, EventArgs e)
        {
            try
            {
                SetDefaultStatus();

                Height            = 285;
                btnLogin.Location = new Point(btnLogin.Location.X, btnLogin.Location.Y + 40);
                btnExit.Location  = new Point(btnExit.Location.X, btnExit.Location.Y + 40);


                pdcLabelIP.Visible     = true;
                txtMESServerIP.Visible = true;
                btnSaveIP.Visible      = true;

                txtMESServerIP.Text = LoginBll.GetIPFromLocalFile();
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(ex, "Login");
                MessageBoxHelper.ShowWarning("登入系统失败!");
            }
        }
コード例 #2
0
ファイル: MESLoginDialog.cs プロジェクト: ChenglongMa/DNA_MES
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor = Cursors.WaitCursor;
                string strUserName;
                string strPassword;
                string staffno  = null;
                string serverIp = txtMESServerIP.Text;
                if (serverIp.IsNullOrEmpty())
                {
                    serverIp = LoginBll.GetIPFromLocalFile();
                }
                SysInfo.ServerIp    = IPAddress.Parse(serverIp);
                txtMESServerIP.Text = serverIp;
                try
                {
                    //todo:对比本机与服务器配置的异同
                    if (LoginBll.ExistDifferLocalAndServerFile())
                    {
                        MessageBoxHelper.ShowWarning("检测到服务器文件与本地文件存在差异,系统将更新本地文件...");
                        LoginBll.UpdateLocalFile();
                        MessageBoxHelper.ShowInformationOK("更新成功!");
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteErrorLog(ex, "Login");
                    MessageBoxHelper.ShowWarning("更新失败,系统自动从本地获取登入信息!");
                }


                if (checkBoxStaffnoLogin.Checked == false) //员工姓名登入
                {
                    SetUserNameLogin();
                    strUserName = txtBoxUserName.Text;
                    strPassword = txtBoxPassword.Text;
                    bool rtnrslt = LoginBll.CheckUser(strUserName, strPassword, txtMESServerIP.Text);
                    if (rtnrslt)
                    {
                        LoginBll.RegisterUser();
                    }
                    else
                    {
                        Cursor = Cursors.Default;
                        var strSecurity = $"用户{strUserName}登录授权失败!";
                        LogHelper.WriteWarningLog(strSecurity, "Login");
                        return;
                    }

                    //SysInfo.AllAuthIDDict = LoginBll.GetAllOperationAuthDict();
                    SysInfo.EmpId             = LoginBll.GetPersonByName(strUserName).staffno;
                    SysInfo.SysUserAuthIDDict = LoginBll.GetOperationAuthDictByName(strUserName);
                }
                else
                {
                    SetUserNameLogin(false);
                    staffno = txtStaffno.Text; //获取工号
                    LoginBll.RegisterUser();
                    Person person = LoginBll.GetPersonByStaffno(staffno);

                    if (person == null)
                    {
                        Cursor = Cursors.Default;
                        MessageBoxHelper.ShowWarning("不存在此工号的人员!");
                        return;
                    }

                    bool rtnrslt2 = LoginBll.CheckUser(person.name, person.password, txtMESServerIP.Text);
                    if (rtnrslt2 == true)
                    {
                        LoginBll.RegisterUser();
                    }
                    else
                    {
                        Cursor = Cursors.Default;
                        Cursor = Cursors.Default;
                        string strSecurity = string.Format("用户{0}登录授权失败!", person.name);
                        LogHelper.WriteWarningLog(strSecurity, "Login");
                        return;
                    }

                    strUserName   = person.name;
                    SysInfo.EmpId = staffno;
                }

                SysInfo.UserName   = strUserName;
                SysInfo.WebService = "http://" + serverIp.Replace("http://", "").Replace("\r\n", "").Replace("/", "") +
                                     ":" + ConfigurationManager.AppSettings["WebPort"] + "/" +
                                     ConfigurationManager.AppSettings["WebServiceName"] + "/FileService.asmx"; //报表设计器
                SaveTextBoxInfo();
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;
                LogHelper.WriteErrorLog(ex, "Login");
                MessageBoxHelper.ShowWarning(ex.Message);
            }
        }