private void btnSave_Click(object sender, EventArgs e) { if (faceList.picid.Length == 0) { UCMessageBox.Show("请选择一个头像!", this); return; } else if (txtNickName.Text.Trim().Length == 0) { UCMessageBox.Show("昵称不能为空!", this); return; } else if (txtPwd.Text.Trim().Length == 0) { UCMessageBox.Show("密码不能为空!", this); return; } else if (txtPwd.Text.Trim().Length < 6 || txtPwd.Text.Trim().Length > 16) { UCMessageBox.Show("密码长度为6~16位!", this); return; } else if (txtPwd2.Text.Trim().Length == 0) { UCMessageBox.Show("确认密码不能为空!", this); return; } else if (txtPwd2.Text.Trim() != txtPwd.Text.Trim()) { UCMessageBox.Show("两次密码需一致!", this); return; } RegistUser(); }
/// <summary> /// 检查登录 /// </summary> /// <returns></returns> private bool CheckUser() { string id = txtUserName.Text.Trim(); string pwd = txtPwd.Text.Trim(); string sql = string.Format(@"select COUNT(*) from Users where id={0} and pwd='{1}'", id, pwd); DBHelper dbHelper = new DBHelper(); try { dbHelper.Connection.Open(); SqlCommand command = new SqlCommand(sql, dbHelper.Connection); int result = Convert.ToInt32(command.ExecuteScalar()); if (result == 1) { return(true); } } catch (Exception ex) { UCMessageBox.Show(ex.Message, this); return(false); } finally { dbHelper.Connection.Close(); } return(false); }
private void RegistUser() { string sql = string.Format(@"insert into Users (nickName,face,pwd) values('{0}','{1}','{2}'); select @@IDENTITY", txtNickName.Text.Trim(), faceList.picid, txtPwd2.Text.Trim()); DBHelper dbHelper = new DBHelper(); try { dbHelper.Connection.Open(); SqlCommand command = new SqlCommand(sql, dbHelper.Connection); int id = Convert.ToInt32(command.ExecuteScalar()); if (id > 0) { MessageBox.Show(string.Format("注册的QQ号码为:{0}\r\n请牢记!", id)); } else { UCMessageBox.Show("服务器繁忙,请稍后重试!", this); } } catch (Exception ex) { UCMessageBox.Show(ex.Message, this); } finally { dbHelper.Connection.Close(); } this.Close(); }
/// <summary> /// 更新房间状态及信息 /// </summary> private void UpdateRoomInfo() { //为了安全,先检查后更新数据 if (CheckRoomState() && GetRoomPlayerCount() < 4) { //占座 if (IsNowRoom()) { if (SaveSeat()) { UCMessageBox.Show("占座成功!", this); } } else { UCMessageBox.Show("占座失败!别处游戏中", this); this.Close(); } } else { UCMessageBox.Show("人数已满或已经开始,不能加入房间!", this); //this.Close(); } }
/// <summary> /// 检查房间的状态为未开始 /// </summary> /// <returns></returns> public bool CheckRoomState() { DBHelper dbHelper = new DBHelper(); string sql = string.Format("select state from Rooms where rid={0}", roomId); try { dbHelper.Connection.Open(); SqlCommand command = new SqlCommand(sql, dbHelper.Connection); int state = Convert.ToInt32(command.ExecuteScalar()); if (state == 2) { return(false); } } catch (Exception ex) { UCMessageBox.Show(ex.Message, this); } finally { dbHelper.Connection.Close(); } return(true); }
public bool CheckInput() { if (txtUserName.Text.Length == 0) { UCMessageBox.Show("输入用户名!", this); return(false); } else if (txtPwd.Text.Length == 0) { UCMessageBox.Show("输入用户名!", this); return(false); } return(true); }
//登录按钮的点击事件 private void pbLoginBtn_Click(object sender, EventArgs e) { if (CheckInput()) { if (CheckUser()) { FrmRooms rooms = FrmRooms.GetFrmRooms(txtUserName.Text.Trim()); rooms.Show(); this.Visible = false; } else { UCMessageBox.Show("账号或密码有误!", this); } } }
private void button1_Click(object sender, EventArgs e) { UCMessageBox.Show("获得 媳妇儿 一个", this); }
/// <summary> /// 获取玩家数据-头像和昵称,同时切换鼠标悬浮样式 /// </summary> private void GetPlayerData(string uid, int seat) { DBHelper dbHelper = new DBHelper(); string sql = string.Format("select nickName,face from users where id={0}", uid); SqlDataReader reader = null; try { dbHelper.Connection.Open(); SqlCommand command = new SqlCommand(sql, dbHelper.Connection); reader = command.ExecuteReader(CommandBehavior.CloseConnection); if (reader.Read()) { string name = reader["nickName"].ToString(); string face = reader["face"].ToString(); switch (seat) { case 1: lblPlay1Name.Text = name; lblPlay1Name.Visible = true; //通过头像名字获取对应的资源 pbPlay1.Image = Properties.Resources.ResourceManager.GetObject(face) as Image; //头像变圆 ControlUtils.ChangeToCircle(pbPlay1); pbPlay1.Tag = string.Format(pbPlay1.Tag.ToString(), uid); pbPlay1.Cursor = Cursors.Hand; break; case 2: lblPlay2Name.Text = name; lblPlay2Name.Visible = true; pbPlay2.Image = Properties.Resources.ResourceManager.GetObject(face) as Image; ControlUtils.ChangeToCircle(pbPlay2); pbPlay2.Tag = string.Format(pbPlay2.Tag.ToString(), uid); pbPlay2.Cursor = Cursors.Hand; break; case 3: lblPlay3Name.Text = name; lblPlay3Name.Visible = true; pbPlay3.Image = Properties.Resources.ResourceManager.GetObject(face) as Image; ControlUtils.ChangeToCircle(pbPlay3); pbPlay3.Tag = string.Format(pbPlay3.Tag.ToString(), uid); pbPlay3.Cursor = Cursors.Hand; break; case 4: lblPlay4Name.Text = name; lblPlay4Name.Visible = true; pbPlay4.Image = Properties.Resources.ResourceManager.GetObject(face) as Image; ControlUtils.ChangeToCircle(pbPlay4); pbPlay4.Tag = string.Format(pbPlay4.Tag.ToString(), uid); pbPlay4.Cursor = Cursors.Hand; break; } } else { switch (seat) { case 1: lblPlay1Name.Text = ""; lblPlay1Name.Visible = false; //通过头像名字获取对应的资源 pbPlay1.Image = Properties.Resources.ResourceManager.GetObject("Seat") as Image; //头像变方 ControlUtils.ChangeToRect(pbPlay1); pbPlay1.Tag = "1,{0}"; if (roomState == 1) { pbPlay1.Cursor = Cursors.No; } else { pbPlay1.Cursor = Cursors.Hand; } break; case 2: lblPlay2Name.Text = ""; lblPlay2Name.Visible = false; pbPlay2.Image = Properties.Resources.ResourceManager.GetObject("Seat") as Image; ControlUtils.ChangeToRect(pbPlay2); pbPlay2.Tag = "2,{0}"; if (roomState == 1) { pbPlay2.Cursor = Cursors.No; } else { pbPlay2.Cursor = Cursors.Hand; } break; case 3: lblPlay3Name.Text = ""; lblPlay3Name.Visible = false; pbPlay3.Image = Properties.Resources.ResourceManager.GetObject("Seat") as Image; ControlUtils.ChangeToRect(pbPlay3); pbPlay3.Tag = "3,{0}"; if (roomState == 1) { pbPlay3.Cursor = Cursors.No; } else { pbPlay3.Cursor = Cursors.Hand; } break; case 4: lblPlay4Name.Text = ""; lblPlay4Name.Visible = false; pbPlay4.Image = Properties.Resources.ResourceManager.GetObject("Seat") as Image; ControlUtils.ChangeToRect(pbPlay4); pbPlay4.Tag = "4,{0}"; if (roomState == 1) { pbPlay4.Cursor = Cursors.No; } else { pbPlay4.Cursor = Cursors.Hand; } break; } } } catch (Exception ex) { UCMessageBox.Show(ex.Message, FrmRooms.GetFrmRooms(id)); } finally { if (reader != null) { reader.Close(); } } }
//获取房间数据 private void GetRoomData() { //重置座位数据,用于标记 pbPlay1.Tag = "1,{0}"; pbPlay2.Tag = "2,{0}"; pbPlay3.Tag = "3,{0}"; pbPlay4.Tag = "4,{0}"; string sql = string.Format(@"select Rooms.state as rstate,id,seat, RoomPlayer.state ustate from Rooms inner join RoomPlayer on Rooms.rid=RoomPlayer.rid where Rooms.rid={0}", roomId); DBHelper dbHelper = new DBHelper(); SqlDataReader reader = null; try { dbHelper.Connection.Open(); SqlCommand command = new SqlCommand(sql, dbHelper.Connection); reader = command.ExecuteReader(CommandBehavior.CloseConnection); for (int i = 1; i <= 4; i++) { if (reader.Read()) { //将四个头像设置信息 roomState = Convert.ToInt32(reader["rstate"]); int id = Convert.ToInt32(reader["id"]); int seat = Convert.ToInt32(reader["seat"]); int ustate = Convert.ToInt32(reader["ustate"]); GetPlayerData(id.ToString(), seat); } //GetPlayerData(0.ToString(), tempNum); } //遍历所有座位,得到没有上座的座位 for (int i = 1; i <= 4; i++) { Control item = this.Controls.Find("pbPlay" + i, true)[0]; //座位信息 string[] info = item.Tag.ToString().Split(','); if (info[1] == "{0}") { GetPlayerData(0.ToString(), Convert.ToInt32(info[0])); } } //0为可用,1为已经开始游戏 if (roomState == 0) { pbRoomState.Image = Properties.Resources.tablen; } else if (roomState == 1) { //更换图标 pbRoomState.Image = Properties.Resources.tables; } } catch (Exception ex) { UCMessageBox.Show(ex.Message, FrmRooms.GetFrmRooms(id)); } finally { if (reader != null) { reader.Close(); } } }
private void button2_Click(object sender, EventArgs e) { UCMessageBox boc = new UCMessageBox(this); boc.Show("DENEME", "DENEME 2", MsgButtons.OK, DisplayState.Normal, 30); }
private void btn_show1_Click(object sender, EventArgs e) { ucMessageBox1.Show("Hello", "This is test message!", MsgButtons.YesNo, DisplayState.FullScreen, 0); }