<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using IndustryEthernet;
using Newtonsoft.Json.Linq;

namespace 软件系统客户端模版
{

    //=================================================================================================
    //      登录窗口，此处实现了一些常用的代码，具体的版本号验证及账户验证需要根据实际需求实现
    //=================================================================================================


    public partial class FormLogin : Form
    {
        public FormLogin()
        {
            InitializeComponent();
        }

        #region 窗口属性及方法
        /// <summary>
        /// 指示窗体是否已经显示
        /// </summary>
        private bool IsWindowShow { get; set; } = false;

        private void FormLogin_Load(object sender, EventArgs e)
        {
            label_status.Visible = false;

            UserClient.JsonSettings.FileSavePath = Application.StartupPath + @"\JsonSettings.txt";
            UserClient.JsonSettings.LoadSettings();//根据实际实际情况选中解密算法，默认采用DES加密解密算法

            label_version.Text = "版本：" + UserClient.CurrentVersion.ToString();
            label2.Text = CommonLibrary.Resource.StringResouce.SoftName;
            label_copyright.Text = $"本软件著作权归{CommonLibrary.Resource.StringResouce.SoftCopyRight}所有";
        }

        private void FormLogin_Shown(object sender, EventArgs e)
        {
            IsWindowShow = true;

            //加载数据
            textBox_userName.Text = UserClient.JsonSettings.LoginName ?? "";
            textBox_password.Text = UserClient.JsonSettings.Password ?? "";
            checkBox_remeber.Checked = UserClient.JsonSettings.Password != "";

            //初始化输入焦点
            if (UserClient.JsonSettings.Password != "") userButton_login.Focus();
            else if (UserClient.JsonSettings.LoginName != "") textBox_password.Focus();
            else textBox_userName.Focus();
            
        }

        private void FormLogin_FormClosing(object sender, FormClosingEventArgs e)
        {
            //退出
            IsWindowShow = false;
            //延时
            Thread.Sleep(100);

        }




        #endregion


        #region 界面逻辑块

        private void textBox_userName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) textBox_password.Focus();
        }

        private void textBox_password_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) userButton_login.PerformClick();
        }

        private void userButton_login_Click(object sender, EventArgs e)
        {
            label_status.Visible = true;
            //验证输入
            if (string.IsNullOrEmpty(textBox_userName.Text))
            {
                label_status.Text = "请输入用户名";
                textBox_userName.Focus();
                return;
            }

            if(string.IsNullOrEmpty(textBox_password.Text))
            {
                label_status.Text = "请输入密码";
                textBox_password.Focus();
                return;
            }

            label_status.Text = "正在验证维护状态...";
            UISettings(false);

            ThreadAccountLogin = new Thread(ThreadCheckAccount);
            ThreadAccountLogin.IsBackground = true;
            ThreadAccountLogin.Start();
        }
        /// <summary>
        /// 界面的UI使能操作
        /// </summary>
        /// <param name="enable">值</param>
        private void UISettings(bool enable)
        {
            textBox_userName.Enabled = enable;
            textBox_password.Enabled = enable;
            userButton_login.Enabled = enable;
            checkBox_remeber.Enabled = enable;
        }

        #endregion

        #region 账户验证的逻辑块

        

        /// <summary>
        /// 用于验证的后台线程
        /// </summary>
        private Thread ThreadAccountLogin = null;
        /// <summary>
        /// 用户账户验证的后台端
        /// </summary>
        private void ThreadCheckAccount()
        {
            //定义委托
            Action<string> message_show = delegate (string message)
              {
                  label_status.Text = message;
              };
            Action start_update = delegate
            {
                //需要该exe支持，否则将无法是实现自动版本控制
                string update_file_name = Application.StartupPath + @"\软件自动更新.exe";
                try
                {
                    System.Diagnostics.Process.Start(update_file_name);
                }
                catch
                {<commit_msg>在启动更新软件时修复退出本系统BUG<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using IndustryEthernet;
using Newtonsoft.Json.Linq;

namespace 软件系统客户端模版
{

    //=================================================================================================
    //      登录窗口，此处实现了一些常用的代码，具体的版本号验证及账户验证需要根据实际需求实现
    //=================================================================================================


    public partial class FormLogin : Form
    {
        public FormLogin()
        {
            InitializeComponent();
        }

        #region 窗口属性及方法
        /// <summary>
        /// 指示窗体是否已经显示
        /// </summary>
        private bool IsWindowShow { get; set; } = false;

        private void FormLogin_Load(object sender, EventArgs e)
        {
            label_status.Visible = false;

            UserClient.JsonSettings.FileSavePath = Application.StartupPath + @"\JsonSettings.txt";
            UserClient.JsonSettings.LoadSettings();//根据实际实际情况选中解密算法，默认采用DES加密解密算法

            label_version.Text = "版本：" + UserClient.CurrentVersion.ToString();
            label2.Text = CommonLibrary.Resource.StringResouce.SoftName;
            label_copyright.Text = $"本软件著作权归{CommonLibrary.Resource.StringResouce.SoftCopyRight}所有";
        }

        private void FormLogin_Shown(object sender, EventArgs e)
        {
            IsWindowShow = true;

            //加载数据
            textBox_userName.Text = UserClient.JsonSettings.LoginName ?? "";
            textBox_password.Text = UserClient.JsonSettings.Password ?? "";
            checkBox_remeber.Checked = UserClient.JsonSettings.Password != "";

            //初始化输入焦点
            if (UserClient.JsonSettings.Password != "") userButton_login.Focus();
            else if (UserClient.JsonSettings.LoginName != "") textBox_password.Focus();
            else textBox_userName.Focus();
            
        }

        private void FormLogin_FormClosing(object sender, FormClosingEventArgs e)
        {
            //退出
            IsWindowShow = false;
            //延时
            Thread.Sleep(100);

        }




        #endregion


        #region 界面逻辑块

        private void textBox_userName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) textBox_password.Focus();
        }

        private void textBox_password_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) userButton_login.PerformClick();
        }

        private void userButton_login_Click(object sender, EventArgs e)
        {
            label_status.Visible = true;
            //验证输入
            if (string.IsNullOrEmpty(textBox_userName.Text))
            {
                label_status.Text = "请输入用户名";
                textBox_userName.Focus();
                return;
            }

            if(string.IsNullOrEmpty(textBox_password.Text))
            {
                label_status.Text = "请输入密码";
                textBox_password.Focus();
                return;
            }

            label_status.Text = "正在验证维护状态...";
            UISettings(false);

            ThreadAccountLogin = new Thread(ThreadCheckAccount);
            ThreadAccountLogin.IsBackground = true;
            ThreadAccountLogin.Start();
        }
        /// <summary>
        /// 界面的UI使能操作
        /// </summary>
        /// <param name="enable">值</param>
        private void UISettings(bool enable)
        {
            textBox_userName.Enabled = enable;
            textBox_password.Enabled = enable;
            userButton_login.Enabled = enable;
            checkBox_remeber.Enabled = enable;
        }

        #endregion

        #region 账户验证的逻辑块

        

        /// <summary>
        /// 用于验证的后台线程
        /// </summary>
        private Thread ThreadAccountLogin = null;
        /// <summary>
        /// 用户账户验证的后台端
        /// </summary>
        private void ThreadCheckAccount()
        {
            //定义委托
            Action<string> message_show = delegate (string message)
              {
                  label_status.Text = message;
              };
            Action start_update = delegate
            {
                //需要该exe支持，否则将无法是实现自动版本控制
                string update_file_name = Application.StartupPath + @"\软件自动更新.exe";
                try
                {
                    System.Diagnostics.Process.Start(update_file_name);
                    Environment.Exit(0);//退出系统
                }
                catch
                {
{'fraction_non_alphanumeric': 0.13233701537795106, 'fraction_numerical': 0.0009746588693957114, 'mean_word_length': 1.7427977427977428, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1677075', 'n_tokens_mistral': 2646, 'n_tokens_neox': 2720, 'n_words': 407}