private void BtnOK_Click(object sender, EventArgs e) { int ret = 0; string strID = TxtID.Text.Trim(); string strPwdAnswer = TxtPwdAnswer.Text.Trim(); SQLExecute excute = new SQLExecute(); ret = excute.CompareUserIdentity(strID, strPwdAnswer); if (ret == 1) { MessageBox.Show("忘记密码成功!\n请输入新的信息", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information); FormReUserPwd FrmRePwd = new FormReUserPwd(); //传递用户名 FrmRePwd.TxtID.Text = TxtID.Text.Trim(); FrmRePwd.Show(); Close(); //提示用户要干什么 MessageBox.Show("请输入新的密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("除密码外其余若不想更改可为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("忘记密码失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void FormForgetPwdByMail_Load(object sender, EventArgs e) { string strID = TxtID.Text.Trim(); DataSet ds = new DataSet(); SQLExecute excute = new SQLExecute(); ds = excute.GetUserMailAddress(strID); TxtMailAddress.Text = Convert.ToString(ds.Tables[0].Rows[0][0]); }
private void LstMailAddress_Click(object sender, EventArgs e) { TxtMailAddress.Text = LstMailAddress.Text.Trim().ToString(); LstMailAddress.Visible = false; LstMailAddress.Items.Clear(); string[] strTemp = TxtMailAddress.Text.Trim().Split('@'); string strMailDomain = "@" + strTemp[1].ToString(); SQLExecute excute = new SQLExecute(); excute.MailDomainHotIndexPlus(strMailDomain); }
private void FormForgetPwdByPwdQuestion_Load(object sender, EventArgs e) { string strID = TxtID.Text.Trim(); SQLExecute excute = new SQLExecute(); DataSet ds = new DataSet(); ds = excute.GetUserAuthentication(strID); TxtPwdQuestion.Text = Convert.ToString(ds.Tables[0].Rows[0][0]); TxtPwdAnswer.Focus(); }
private void FormReUserPwd_Load(object sender, EventArgs e) { TxtPwd.Focus(); DataSet ds = new DataSet(); SQLExecute excute = new SQLExecute(); ds = excute.GetUserInfo(TxtID.Text.Trim()); TxtNickName.Text = ds.Tables[0].Rows[0][0].ToString(); TxtMailAddress.Text = ds.Tables[0].Rows[0][1].ToString(); CmbPwdQuestion.Text = ds.Tables[0].Rows[0][2].ToString(); TxtPwdAnswer.Text = ds.Tables[0].Rows[0][3].ToString(); }
/// <summary> /// 查询返回第一行第一列字段的值 /// </summary> /// <typeparam name="TResult">接受查询结果类型</typeparam> /// <param name="field">查询的字段</param> /// <returns></returns> public TResult ToScalar <TResult>(string field) { if (!string.IsNullOrEmpty(GroupByText)) { throw new ArgumentException("聚合查询不允许使用 GROUP BY 条件!"); } Fields.Clear(); Fields.Add(field); string cmdText = ToSQL(); SQLExecute execute = byMaster ? dbContext.ByMaster().Execute : dbContext.Execute; object result = execute.ExecuteScalar(CommandType.Text, cmdText, Parameters.ToArray()); return(result == null ? default : (TResult)result); }
private void CmbCity_SelectedIndexChanged(object sender, EventArgs e) { CmbDistrict.Items.Clear(); SQLExecute excute = new SQLExecute(); DataSet ds = new DataSet(); int intCount = 0; ds = excute.GetDistrictByProvinceAndCity(CmbProvince.SelectedItem.ToString(),CmbCity.SelectedItem.ToString()); intCount = ds.Tables[0].DefaultView.Count; for (int i = 0; i < intCount; i++) { CmbDistrict.Items.Add(ds.Tables[0].Rows[i][0].ToString()); } }
public static void GetInfo(string table) { try { // Query. string query = "SELECT * FROM" + WDWGet.windowName + "WHERE(ABS(CAST(BINARY_CHECKSUM(*) *RAND()) as int)) % 100) < 10"; // Execute. SQLExecute.executeQuery(query); //return query; } catch (Exception ex) { throw ex; } }
private void BtnUploadPic_Click(object sender, EventArgs e) { OpenFileDialog openFile = new OpenFileDialog(); if (openFile.ShowDialog() == DialogResult.OK) { int ret = 0; PicUserAvatar.Image = Image.FromFile(openFile.FileName); ImageConverter imgconv = new ImageConverter(); byte[] bytesPic = (byte[])imgconv.ConvertTo(PicUserAvatar.Image, typeof(byte[])); SQLExecute excute = new SQLExecute(); ret = excute.UplodaFile(bytesPic, TxtPicIntroduction.Text.Trim()); if (ret == 1) { MessageBox.Show("上传成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void FormUserInfoInsert_Load(object sender, EventArgs e) { CmbProvince.Items.Clear(); CmbCity.Items.Clear(); CmbDistrict.Items.Clear(); SQLExecute excute = new SQLExecute(); DataSet ds = new DataSet(); int intCount = 0; ds = excute.GetProvince(); intCount = ds.Tables[0].DefaultView.Count; for (int i = 0; i < intCount; i++) { CmbProvince.Items.Add(ds.Tables[0].Rows[i][0]); } }
private void FormMain_Load(object sender, EventArgs e) { try { SQLExecute excute = new SQLExecute(); DataSet ds = new DataSet(); ds = excute.GetMailDomain(); publicIntDomainCount = ds.Tables[0].DefaultView.Count; for (int i = 0; i < publicIntDomainCount; i++) { publicStraMailDomain[i] = Convert.ToString(ds.Tables[0].Rows[i][0]); } //如果已经在本地保存了图片, 就直接到保存图片的文件里面去加载, 否则从数据库中读取 try { PicUserAvatar.SizeMode = PictureBoxSizeMode.Zoom; //PicUserAvatar.Image = Image.FromFile(Environment.CurrentDirectory + @"\Pic\LoadingPic.png"); PicUserAvatar.LoadAsync(Environment.CurrentDirectory + @"\Pic\LoadingPic.png"); } catch (Exception) { ds = excute.GetAvatarLoadingPic("LoadingPic"); MemoryStream ms = new MemoryStream((byte[])ds.Tables[0].Rows[0][0]); PicUserAvatar.Image = Image.FromStream(ms); Directory.CreateDirectory(Environment.CurrentDirectory + @"\Pic"); PicUserAvatar.Image.Save(Environment.CurrentDirectory + @"\Pic\LoadingPic.png"); } //为了在开始就能够连接, 为了后续的连接能够快一点, 在load事件里面就连接, //但如果没有一个messagebox的话, 后续的连接依旧是异常的慢, 所以... MessageBox.Show("已连接数据库!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("FormMain_Load:" + ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void FormRegister_Load(object sender, EventArgs e) { SQLExecute excute = new SQLExecute(); DataSet ds = new DataSet(); try { //似乎只要定义了为zoom之后, 只要不更改, 后续加载的图片还是zoom的 PicAvatar.SizeMode = PictureBoxSizeMode.Zoom; PicAvatar.Image = Image.FromFile(Environment.CurrentDirectory + "\\Pic\\LoadingPic.png"); } catch (Exception) { ds = excute.GetAvatarLoadingPic("loadingPic"); MemoryStream ms = new MemoryStream((byte[])ds.Tables[0].Rows[0][0]); PicAvatar.Image = Image.FromStream(ms); Directory.CreateDirectory(Environment.CurrentDirectory + "\\Pic"); PicAvatar.Image.Save(Environment.CurrentDirectory + "\\Pic\\LoadingPic.png"); // MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } ds = excute.GetMailDomain(); intMailDomainCows = ds.Tables[0].DefaultView.Count; try { for (int i = 0; i < intMailDomainCows; i++) { straMailDomain[i] = Convert.ToString(ds.Tables[0].Rows[i][0]); LstMailAddress.Items.Add(straMailDomain[i]); } } catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void TxtID_TextChanged(object sender, EventArgs e) { SQLExecute excute = new SQLExecute(); string strID = TxtID.Text.Trim(); int ret = 0; ret = excute.JudegeIfExitThisID(strID); if (ret == 1) { BtnRegister.Enabled = false; LblWhetherIDExit.Text = "此账户名已存在!"; LblWhetherIDExit.ForeColor = Color.Red; LblWhetherIDExit.Visible = true; } else { BtnRegister.Enabled = true; LblWhetherIDExit.Text = "可用的用户名"; LblWhetherIDExit.ForeColor = Color.Green; LblWhetherIDExit.Visible = true; } }
private void BtnLogin_Click(object sender, EventArgs e) { bool isRet = false; string strID = string.Empty; string strPwd = string.Empty; DataSet ds = new DataSet(); SQLExecute excute = new SQLExecute(); strID = TxtID.Text.Trim(); strPwd = TxtPwd.Text.Trim(); ds = excute.UserLogin(strID); isRet = PasswordStorage.VerifyPassword(strPwd, ds.Tables[0].Rows[0][0].ToString()); if (isRet) { MessageBox.Show("登录成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //FormMain FrmM = new FormMain(); //FrmM.LblShowUserName.Text = "欢迎" + TxtID.Text.Trim(); LblChange.ChangeLbl("欢迎您: " + TxtID.Text.Trim()); //发现这边要是用show方法的话, main窗体show不出来, 就尝试在另一个线程里运行 //new System.Threading.Thread(() => // { // Application.Run(FrmM); // }).Start(); ds.Clear(); ds = excute.GetUserAvatarFileName(TxtID.Text.Trim()); Image image = null; //从保存用户头像的文件夹加载头像, 如果没有就从数据库拉取, 并将其以用户名+格式的形式保存 try { image = Image.FromFile(ds.Tables[0].Rows[0][0].ToString()); } catch (Exception) { byte[] bytes = null; ds = excute.GetUserAvatar(TxtID.Text.Trim()); bytes = (byte[])ds.Tables["temp"].Rows[0][0]; MemoryStream ms = new MemoryStream(bytes); image = Image.FromStream(ms); string ext = Pic.GetExtension(image); //如果没有此目录的话, 就创建 Directory.CreateDirectory(Environment.CurrentDirectory + "\\UsersAvatars"); string strFileName = Environment.CurrentDirectory + "\\UsersAvatars\\" + TxtID.Text.Trim() + ext; image.Save(strFileName); //并将此目录更新到数据库, 以便下次从本地加载头像 excute.UpdateAvatarFileName(TxtID.Text.Trim(), strFileName); } ImageChange.ImageChange(image); Close(); } else { MessageBox.Show("登录失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void BtnRegister_Click(object sender, EventArgs e) { if (PicAvatar.Image == null) { DialogResult DRret; DRret = MessageBox.Show("要上传头像吗", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (DRret == DialogResult.Yes) { return; } else { } } else { } int ret = 0; DialogResult retDR; User user = new User() { ID = TxtID.Text.Trim(), Nickname = TxtNickName.Text.Trim(), Mailaddress = TxtMailAddress.Text.Trim(), PwdQuestion = CmbPwdQuestion.Text.Trim(), PwdAnswer = TxtPwdAnswer.Text.Trim(), FileNameOfAvatar = strAvatarFileName, }; if (TxtPwd.Text.Trim().Equals(TxtPwdConfirm.Text.Trim()) != true) { MessageBox.Show("您输入的密码前后不一样!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); TxtPwd.Text = string.Empty; TxtPwdConfirm.Text = string.Empty; TxtPwd.Focus(); return; } if (user.ID.Equals(string.Empty) || TxtPwd.Text.Trim().Equals(string.Empty) || user.Mailaddress.Equals(string.Empty) || TxtPwdConfirm.Text.Trim().Equals(string.Empty) || user.PwdQuestion.Equals(string.Empty) || user.PwdAnswer.Equals(string.Empty)) { MessageBox.Show("您有选项没有输入!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (TxtVerticationCode.Text.Trim().Equals(strVttCode) == false || TxtVerticationCode.Text.Trim().Equals(string.Empty)) { MessageBox.Show("验证码不正确!\n或不能为空", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //将image转为byte[]保存到数据库MEDIUMBLOB里面 byte[] bytesAvatar = null; ImageConverter imgconv = new ImageConverter(); bytesAvatar = (byte[])imgconv.ConvertTo(PicAvatar.Image, typeof(byte[])); user.Avatar = bytesAvatar; //将密码转为hash保存到数据库 user.Password = PasswordStorage.CreateHash(TxtPwd.Text.Trim()); retDR = MessageBox.Show("您确定注册?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (retDR == DialogResult.Yes) { try { SQLExecute Excute = new SQLExecute(); ret = Excute.InsertUserInfo(user); if (ret > 0) { MessageBox.Show("注册成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("请登录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); TxtID.Text = string.Empty; TxtID.Focus(); } } else { //用户选择了不注册, 就什么都不干 } }
private void BtnRePwd_Click(object sender, EventArgs e) { User user = new User(); if (TxtID.Text.Trim().Equals(string.Empty) != true) { user.ID = TxtID.Text.Trim(); } if (TxtNickName.Text.Trim().Equals(string.Empty) != true) { user.Nickname = TxtNickName.Text.Trim(); } if (TxtPwd.Text.Trim().Equals(string.Empty) != true) { user.Password = TxtPwd.Text.Trim(); } if (TxtMailAddress.Text.Trim().Equals(string.Empty) != true) { user.Mailaddress = TxtMailAddress.Text.Trim(); } if (CmbPwdQuestion.Text.Trim().Equals(string.Empty) != true) { user.PwdQuestion = CmbPwdQuestion.Text.Trim(); } if (TxtPwdAnswer.Text.Trim().Equals(string.Empty) != true) { user.PwdAnswer = TxtPwdAnswer.Text.Trim(); } int ret = 0; string strPwdConfirm = TxtPwdConfirm.Text.Trim(); DialogResult DRret; if (user.Password.Equals(strPwdConfirm) != true) { MessageBox.Show("您输入的密码前后不一样!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); TxtPwd.Text = string.Empty; TxtPwdConfirm.Text = string.Empty; TxtPwd.Focus(); return; } if (user.Password.Equals(string.Empty) || strPwdConfirm.Equals(string.Empty)) { MessageBox.Show("密码和密码确认不可空缺!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DRret = MessageBox.Show("确定重置?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (DRret == DialogResult.Yes) { SQLExecute excute = new SQLExecute(); ret = excute.UpdateUserInfo(user); if (ret == 1) { MessageBox.Show("重置成功!\n请重新登录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); FormLogin FrmLogin = new FormLogin(); FrmLogin.TxtID.Text = TxtID.Text.Trim(); FrmLogin.Show(); Close(); } else { MessageBox.Show("失败", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { } }