/// <summary> /// 刷新房间内玩家头像信息 /// </summary> private void RefreshRoomPlayerInfo() { pbPlay1.Tag = "1,{0}"; pbPlay2.Tag = "2,{0}"; pbPlay3.Tag = "3,{0}"; pbPlay4.Tag = "4,{0}"; //查询房间内所有玩家 string sql = "select id,seat,state from RoomPlayer where rid=" + 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()) { int uid = Convert.ToInt32(reader["id"]); int seat = Convert.ToInt32(reader["seat"]); int state = Convert.ToInt32(reader["state"]); GetPlayerInfo(uid, seat, state); if (uid.ToString() == id) { seatId = seat.ToString(); } } } } catch (Exception ex) { } finally { if (reader != null) { reader.Close(); } } //设置没有座位的 for (int i = 1; i <= 4; i++) { //lblPlayer1State Control pbcontrol = this.Controls.Find("pbPlay" + i, true)[0]; Label lblControl = Controls.Find("lblPlayer" + i + "State", true)[0] as Label; Label nickName = Controls.Find("lblPlay" + i + "Name", true)[0] as Label; //判断没有座位 if (pbcontrol.Tag.ToString() == (i + ",{0}")) { ControlUtils.ChangeToRect(pbcontrol); lblControl.Text = ""; nickName.Text = ""; nickName.Visible = false; (pbcontrol as PictureBox).Image = Properties.Resources.Seat; } else { ControlUtils.ChangeToCircle(pbcontrol); //获取对应座位的玩家 int uid = Convert.ToInt32(pbcontrol.Tag.ToString().Split(',')[1]); //有座位的判断准备状态 if (!GetUserReaday(uid)) { lblControl.Text = ""; lblControl.Visible = false; if (seatId == i.ToString()) { this.btnReady.Visible = true; } } else { //判断自己是否已经准备 if (seatId == i.ToString()) { this.btnReady.Visible = false; } lblControl.Text = "已准备"; lblControl.Visible = true; } } } }
private void FrmRegist_Load(object sender, EventArgs e) { ControlUtils.ChangeToCircle(pbFace); }
/// <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(); } } }