/// <summary>
        /// Email verification
        /// </summary>
        /// <returns></returns>
        private async Task Sign()
        {
            // 输入邮箱格式校验
            if (!Email.IsEmail())
            {
                ErrorMessage = "错误!邮箱格式不正确,请重试!";
                HasError = true;
                WipeErrorAffterMS();
                return;
            }

            // TODO :SQL Query
            await Task.Run(() =>
            {
                string ConnectionString = @"server = 127.0.0.1; userid = root; password = deamon; database = wemove; persistsecurityinfo = True;";
                MySqlDatabaseEntity mduser = new MySqlDatabaseEntity(ConnectionString);

                try
                {
                    // 打开数据库
                    mduser.Open();
                }
                catch (Exception)
                {
                    // 模拟未连接网络
                    ErrorMessage = "错误!网络连接失败,请重试!";
                    HasError = true;
                    WipeErrorAffterMS();
                    return;
                }

                // sql 查询语句
                string sqlCmdStr = @"select Email from user_info";

                var data = mduser.ExecuteSelect(sqlCmdStr);
                if (data.Tables[0] != null && data.Tables[0].Rows.Count > 0)
                {
                    var datt = data.Tables[0];

                    if (datt.Rows[0]["Email"].ToString() == email)
                    {
                        App.Current.Dispatcher.Invoke(() => ServiceProvider.Get<SignViewModel>().CurrentViewType = SignViewType.SignInPass);
                    }
                    else
                    {
                        ErrorMessage = "错误!不存在当前邮箱,请重试!";
                        HasError = true;
                        WipeErrorAffterMS();
                    }
                }

                // 关闭数据库
                mduser.Close();

            });
        }
        /// <summary>
        /// Password verification
        /// </summary>
        /// <returns></returns>
        private async Task SignIn()
        {
            if (password.Length < 6)
            {
                ErrorMessage = "错误!邮箱格式不正确,请重试!";
                HasError     = true;
                WipeErrorAffterMS();
                return;
            }

            // TODO :SQL Query
            await Task.Run(() =>
            {
                string ConnectionString    = @"server = 127.0.0.1; userid = root; password = deamon; database = wemove; persistsecurityinfo = True;";
                MySqlDatabaseEntity mduser = new MySqlDatabaseEntity(ConnectionString);

                try
                {
                    // 打开数据库
                    mduser.Open();
                }
                catch (Exception)
                {
                    // 模拟未连接网络
                    ErrorMessage = "错误!网络连接失败,请重试!";
                    HasError     = true;
                    WipeErrorAffterMS();
                    return;
                }

                // sql 查询语句
                string sqlCmdStr = @"select Password from user_info";

                var data = mduser.ExecuteSelect(sqlCmdStr);
                if (data.Tables[0] != null && data.Tables[0].Rows.Count > 0)
                {
                    var datt = data.Tables[0];

                    if (datt.Rows[0]["Password"].ToString() == password)
                    {
                        // start up main window
                        App.Current.Dispatcher.Invoke(() =>
                        {
                            Window window          = App.Current.MainWindow;
                            App.Current.MainWindow = new Views.MainWindow();
                            window.Close();
                            App.Current.MainWindow.Show();
                        });
                    }
                    else
                    {
                        ErrorMessage = "错误!密码不正确,请重试!";
                        HasError     = true;
                        WipeErrorAffterMS();
                        return;
                    }
                }

                // 关闭数据库
                mduser.Close();
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Email verification
        /// </summary>
        /// <returns></returns>
        private async Task Sign()
        {
            // 输入邮箱格式校验
            if (!Email.IsEmail())
            {
                ErrorMessage = "错误!邮箱格式不正确,请重试!";
                HasError     = true;
                WipeErrorAffterMS();
                return;
            }

            // TODO :SQL Query
            await Task.Run(() =>
            {
                string ConnectionString    = @"server = 127.0.0.1; userid = root; password = deamon; database = wemove; persistsecurityinfo = True;";
                MySqlDatabaseEntity mduser = new MySqlDatabaseEntity(ConnectionString);

                try
                {
                    // 打开数据库
                    mduser.Open();
                }
                catch (Exception)
                {
                    // 模拟未连接网络
                    ErrorMessage = "错误!网络连接失败,请重试!";
                    HasError     = true;
                    WipeErrorAffterMS();
                    return;
                }

                // sql 查询语句
                string sqlCmdStr = $"select Email from user_info where Email = '{email}'";

                var data = mduser.ExecuteSelect(sqlCmdStr);
                if (data.Tables[0] != null && data.Tables[0].Rows.Count > 0)
                {
                    ErrorMessage = "错误!当前邮箱已注册!";
                    HasError     = true;
                    WipeErrorAffterMS();

                    return;
                }


                // sql 插入
                string sqlInsert = $"insert into user_info ( Email, Username, Password, CreateDate) values ( '{email}','{username}', '{password}', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')";
                var rest         = mduser.ExecuteNonQuery(sqlInsert);
                if (rest > 0)
                {
                    // start up main window
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        var window             = App.Current.MainWindow;
                        App.Current.MainWindow = new Views.MainWindow();
                        window.Close();
                        App.Current.MainWindow.Show();
                    });
                }

                // 关闭数据库
                mduser.Close();
            });
        }