Пример #1
0
 //注册确定按钮
 private void OkBtu_Click(object sender, EventArgs e)
 {
     if (this.PasswordTXT.Text.Trim() == this.SurePasswordTXT.Text.Trim())
     {
         if (IsHaveSend == true && this.SecurityCodeTXT.Text.Trim() == SecurityCodes)
         {
             DataSet   ds    = Database.RunDataSet("select * from Person where 0=1");
             DataTable dt    = ds.Tables[0];
             DataRow   Newdr = dt.NewRow();
             Newdr["PersonID"]   = 0;
             Newdr["PersonPN"]   = this.PhoneNumberTXT.Text.Trim();
             Newdr["PersonName"] = this.UserNameTXT.Text.Trim();
             if (this.ManCheck.Checked == true)
             {
                 Newdr["Gender"] = 0;
             }
             else if (this.WomenCheck.Checked == true)
             {
                 Newdr["Gender"] = 1;
             }
             Newdr["Password"] = this.PasswordTXT.Text.Trim();
             dt.Rows.Add(Newdr);
             try
             {
                 int k = Database.update("Person", "PersonID", dt);
                 MessageBox.Show("注册成功!", "温馨提示", MessageBoxButtons.OK);
                 StreamWriter streamWriter = new StreamWriter(Hisfilepath, true);
                 string       strs         = this.UserNameTXT.Text.Trim() + "*    |    *" + this.PasswordTXT.Text.Trim() + "*    |    *" + DateTime.Now.ToString("s");
                 streamWriter.WriteLine(strs);
                 streamWriter.Close();
                 //ShopCenter sc=new ShopCenter();
                 //sc.Show();
                 //this.Hide();
                 ShopCenter sc = new ShopCenter();           //实例化一个Form2窗口 
                 sc.username = this.UserNameTXT.Text.Trim(); //设置Form2中string1的值 
                 sc.SetValue();
                 sc.Show();
                 this.Close();
             }
             catch (Exception er)
             {
                 MessageBox.Show("注册失败!", "温馨提示", MessageBoxButtons.OK);
             }
         }
         else
         {
             MessageBox.Show("验证码不正确!", "温馨提示", MessageBoxButtons.OK);
             this.SecurityCodeTXT.Focus();
         }
     }
     else
     {
         MessageBox.Show("两次密码不一致!", "温馨提示", MessageBoxButtons.OK);
         this.PasswordTXT.Focus();
         return;
     }
 }
Пример #2
0
        private void LoginBtu_Click(object sender, EventArgs e)
        {
            string username = this.UserNameCombobox.Text.Trim();

            if (string.IsNullOrEmpty(username))
            {
                MessageBox.Show("请输入用户名!", "温馨提示", MessageBoxButtons.OKCancel);
                this.UserNameCombobox.Focus();
                return;
            }
            string password = this.PasswordTXt.Text.Trim();

            try
            {
                //手机号与用户名都可以登陆
                DataSet ds = Database.RunDataSet(String.Format("select * from Person where PersonName='{0}' or PersonPN='{1}'", username, username));
                //DataSet ds = Database.RunDataSet(String.Format("select * from Person where PersonName='{0}' ", username));
                if (password == ds.Tables[0].Rows[0]["Password"].ToString())
                {
                    UserInfo user = new UserInfo();
                    user.UserName = UserNameCombobox.Text;
                    user.UserPwd  = PasswordTXt.Text.Trim();
                    StreamWriter streamWriter = new StreamWriter(Hisfilepath, true);
                    string       strs         = user.UserName + "*    |    *" + user.UserPwd + "*    |    *" + DateTime.Now.ToString("s");
                    streamWriter.WriteLine(strs);
                    streamWriter.Close();
                    //当选择记住密码时  将用户名和密码都写到文件上
                    if (checkBox1.Checked)
                    {
                        string nowtime = DateTime.Now.ToString("G");
                        if (!users.ContainsKey(user.UserName))
                        {
                            StreamWriter sw = new StreamWriter(filepath, true);
                            //string linestr = user.UserName + "|" + user.UserPwd+"|"+nowtime;
                            string linestr = user.UserName + "|" + user.UserPwd;
                            users.Add(user.UserName, user);
                            sw.WriteLine(linestr);
                            sw.Close();
                        }
                        else
                        {
                            StreamReader sr      = new StreamReader(filepath, true);
                            string       content = sr.ReadToEnd(); //这个就是文本内容
                            string       str     = user.UserName + "|" + users[user.UserName].UserPwd + "\r\n";
                            content = content.Replace(str, "");
                            sr.Close();
                            System.IO.File.Delete(filepath);
                            StreamWriter sw = new StreamWriter(filepath, true);
                            users.Remove(user.UserName);
                            users.Add(user.UserName, user);
                            sw.Write(content);
                            sw.WriteLine(user.UserName + "|" + user.UserPwd);
                            sw.Close();
                        }
                    }

                    //当不记住密码时  只将用户名写到文件上
                    else
                    {
                        if (!users.ContainsKey(user.UserName))
                        {
                            StreamWriter sw      = new StreamWriter(filepath, true);
                            string       content = user.UserName + "|";
                            users.Add(user.UserName, user);
                            sw.WriteLine(content);
                            sw.Close();
                        }
                        else
                        {
                            StreamReader sr      = new StreamReader(filepath, true);
                            string       content = sr.ReadToEnd(); //这个就是文本内容
                            string       str     = user.UserName + "|" + users[user.UserName].UserPwd + "\r\n";
                            content = content.Replace(str, "");
                            sr.Close();
                            System.IO.File.Delete(filepath);
                            StreamWriter sw = new StreamWriter(filepath, true);
                            users.Remove(user.UserName);
                            users.Add(user.UserName, user);
                            sw.Write(content);
                            sw.WriteLine(user.UserName + "|");
                            sw.Close();
                        }
                    }
                    ShopCenter sc = new ShopCenter();                            //实例化一个Form2窗口 
                    sc.username = ds.Tables[0].Rows[0]["PersonName"].ToString(); //设置Form2中string1的值 
                    sc.SetValue();
                    sc.Show();
                    this.Hide();
                }
                else
                {
                    this.PasswordTXt.Focus();
                    MessageBox.Show("请检查密码是否正确!", "温馨提示", MessageBoxButtons.OKCancel);
                }
            }
            catch (Exception)
            {
                DataSet ds2 = Database.RunDataSet(String.Format("select * from Seller where SellerName='{0}' or SellerPN='{1}'", username, username));
                //DataSet ds2 = Database.RunDataSet(String.Format("select * from Seller where SellerName='{0}' ", username));

                if (ds2.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("用户名不存在!", "温馨提示", MessageBoxButtons.OKCancel);
                    this.UserNameCombobox.Focus();
                    return;
                }
                if (password == ds2.Tables[0].Rows[0]["Password"].ToString())
                {
                    UserInfo user = new UserInfo();
                    user.UserName = UserNameCombobox.Text;
                    user.UserPwd  = PasswordTXt.Text.Trim();
                    StreamWriter streamWriter = new StreamWriter(Hisfilepath, true);
                    string       strs         = user.UserName + "*    |    *" + user.UserPwd + "*    |    *" + DateTime.Now.ToString("s");
                    streamWriter.WriteLine(strs);
                    streamWriter.Close();
                    //当选择记住密码时  将用户名和密码都写到文件上
                    if (checkBox1.Checked)
                    {
                        string nowtime = DateTime.Now.ToString("G");
                        if (!users.ContainsKey(user.UserName))
                        {
                            StreamWriter sw = new StreamWriter(filepath, true);
                            //string linestr = user.UserName + "|" + user.UserPwd+"|"+nowtime;
                            string linestr = user.UserName + "|" + user.UserPwd;
                            users.Add(user.UserName, user);
                            sw.WriteLine(linestr);
                            sw.Close();
                        }
                        else
                        {
                            StreamReader sr      = new StreamReader(filepath, true);
                            string       content = sr.ReadToEnd(); //这个就是文本内容
                            string       str     = user.UserName + "|" + users[user.UserName].UserPwd + "\r\n";
                            content = content.Replace(str, "");
                            sr.Close();
                            System.IO.File.Delete(filepath);
                            StreamWriter sw = new StreamWriter(filepath, true);
                            users.Remove(user.UserName);
                            users.Add(user.UserName, user);
                            sw.Write(content);
                            sw.WriteLine(user.UserName + "|" + user.UserPwd);
                            sw.Close();
                        }
                    }

                    //当不记住密码时  只将用户名写到文件上
                    else
                    {
                        if (!users.ContainsKey(user.UserName))
                        {
                            StreamWriter sw      = new StreamWriter(filepath, true);
                            string       content = user.UserName + "|";
                            users.Add(user.UserName, user);
                            sw.WriteLine(content);
                            sw.Close();
                        }
                        else
                        {
                            StreamReader sr      = new StreamReader(filepath, true);
                            string       content = sr.ReadToEnd(); //这个就是文本内容
                            string       str     = user.UserName + "|" + users[user.UserName].UserPwd + "\r\n";
                            content = content.Replace(str, "");
                            sr.Close();
                            System.IO.File.Delete(filepath);
                            StreamWriter sw = new StreamWriter(filepath, true);
                            users.Remove(user.UserName);
                            users.Add(user.UserName, user);
                            sw.Write(content);
                            sw.WriteLine(user.UserName + "|");
                            sw.Close();
                        }
                    }
                    //ShopCenter sc = new ShopCenter();
                    //sc.Show();
                    //this.Hide();
                    ShopManager lForm = new ShopManager();                           //实例化一个Form2窗口 
                    lForm.username = ds2.Tables[0].Rows[0]["SellerName"].ToString(); //设置Form2中string1的值
                    lForm.SetValue();
                    lForm.Show();
                    this.Hide();
                }
                else
                {
                    this.PasswordTXt.Focus();
                    MessageBox.Show("请检查密码是否正确!", "温馨提示", MessageBoxButtons.OKCancel);
                }
            }
        }