private void btnPrevious_Click(object sender, EventArgs e) { List <HandView> listHandView = new List <HandView>(); HandView handViewGetter = new HandView(); handViewGetter.IDSession = this.IDSession; listHandView = handViewGetter.GetAllHands(Convert.ToInt32(this.txtPage.Text) - 1, Convert.ToInt32(cboPlayer.SelectedValue), this.txtFilteredHands.Text); this.dataGridView1.Rows.Clear(); this.dataGridView1.Columns[1].Width = 60; this.dataGridView1.Columns[2].Width = 60; int counter = 0; foreach (HandView handView in listHandView) { this.dataGridView1.Rows.Add(handView.IDHand.ToString(), new Bitmap(Image.FromFile(@"Images\" + handView.CardOne + ".jpg"), 60, 80), new Bitmap(Image.FromFile(@"Images\" + handView.CardTwo + ".jpg"), 60, 80), handView.NetWon); this.dataGridView1.Rows[counter].Height = 80; counter++; } this.txtPage.Text = (Convert.ToInt32(this.txtPage.Text) - 1).ToString(); this.btnFirst.Enabled = (this.txtPage.Text != "1"); this.btnNext.Enabled = true; this.btnPrevious.Enabled = btnFirst.Enabled; this.btnLast.Enabled = true; }
private void btnFilterHands_Click(object sender, EventArgs e) { frmFilterHands frmfilterhands = new frmFilterHands(); frmfilterhands.txtFilterHands.Text = this.txtFilteredHands.Text; frmfilterhands.FillButtons(); frmfilterhands.ShowDialog(); this.txtFilteredHands.Text = frmfilterhands.txtFilterHands.Text; List <HandView> listHandView = new List <HandView>(); HandView handViewGetter = new HandView(); listHandView = handViewGetter.GetHandsByIDSession(this.IDSession, Convert.ToInt32(cboPlayer.SelectedValue), Convert.ToInt32(this.txtPage.Text), this.txtFilteredHands.Text); this.dataGridView1.Rows.Clear(); int counter = 0; foreach (HandView handView in listHandView) { this.dataGridView1.Rows.Add(handView.IDHand.ToString(), new Bitmap(Image.FromFile(@"Images\" + handView.CardOne + ".jpg"), 60, 80), new Bitmap(Image.FromFile(@"Images\" + handView.CardTwo + ".jpg"), 60, 80), handView.NetWon); this.dataGridView1.Rows[counter].Height = 80; counter++; } this.txtMaxPages.Text = handViewGetter.GetMaxPagesSession(Convert.ToInt32(cboPlayer.SelectedValue)).ToString(); this.txtPage.Text = "1"; this.btnFirst.Enabled = false; this.btnPrevious.Enabled = false; this.btnNext.Enabled = (Convert.ToInt32(this.txtMaxPages.Text) > 1); this.btnLast.Enabled = this.btnNext.Enabled; }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { DataGridView senderGrid = (DataGridView)sender; List <HandView> listHandView = new List <HandView>(); HandView handViewGetter = new HandView(); List <Players> listPlayers = new List <Players>(); Players playersGettter = new Players(); frmHands frmhands = new frmHands(); int idSession = Convert.ToInt32(senderGrid[0, e.RowIndex].Value); int heroIdPlayer = playersGettter.GetHeroID(idSession); listPlayers = playersGettter.GetPlayersSession(idSession); frmhands.cboPlayer.DataSource = listPlayers; frmhands.cboPlayer.ValueMember = "IDPlayer"; frmhands.cboPlayer.DisplayMember = "Nickname"; frmhands.cboPlayer.SelectedValue = heroIdPlayer; listHandView = handViewGetter.GetHandsByIDSession(idSession, heroIdPlayer, 1, ""); frmhands.dataGridView1.Columns[1].Width = 60; frmhands.dataGridView1.Columns[2].Width = 60; int counter = 0; foreach (HandView handView in listHandView) { frmhands.dataGridView1.Rows.Add(handView.IDHand.ToString(), new Bitmap(Image.FromFile(@"Images\" + handView.CardOne + ".jpg"), 60, 80), new Bitmap(Image.FromFile(@"Images\" + handView.CardTwo + ".jpg"), 60, 80), handView.NetWon); frmhands.dataGridView1.Rows[counter].Height = 80; counter++; } handViewGetter.IDSession = idSession; frmhands.IDSession = idSession; frmhands.txtMaxPages.Text = handViewGetter.GetMaxPagesSession(heroIdPlayer).ToString(); frmhands.txtPage.Text = "1"; frmhands.btnFirst.Enabled = false; frmhands.btnPrevious.Enabled = false; frmhands.btnNext.Enabled = (Convert.ToInt32(frmhands.txtMaxPages.Text) > 1); frmhands.btnLast.Enabled = frmhands.btnNext.Enabled; frmhands.Show(); } }
public List <HandView> GetAllHands(int page, int idPlayer, string filteredHands) { List <HandView> listHandView = new List <HandView>(); HandView handView = new HandView(); string subquery = ""; if (filteredHands != "") { string[] hands = filteredHands.Split(','); string suited = ""; foreach (string hand in hands) { if (hand.Length > 2 && hand.Substring(2, 1) == "o") { suited = "SUBSTR(C1.CARD,2,1) <> SUBSTR(C2.CARD,2,1) AND "; } if (hand.Length > 2 && hand.Substring(2, 1) == "s") { suited = "SUBSTR(C1.CARD,2,1) = SUBSTR(C2.CARD,2,1) AND "; } if (hand.Length == 2) { suited = ""; } if (subquery != "") { subquery = subquery + " UNION "; } subquery = subquery + "SELECT C.IDHAND " + "FROM CARDS C " + "INNER JOIN HANDPLAYERS HP ON HP.IDPLAYER = C.IDPLAYER AND HP.IDHAND = C.IDHAND " + "INNER JOIN HANDSESSIONS HS ON C.IDHAND = HS.IDHAND " + "INNER JOIN CARDS C1 ON C.IDHAND = C1.IDHAND AND C.IDPLAYER = C1.IDPLAYER AND C1.CARDORDER = 1 AND C1.CARD IN ('" + hand.Substring(0, 1) + "h', '" + hand.Substring(0, 1) + "d', '" + hand.Substring(0, 1) + "s', '" + hand.Substring(0, 1) + "c') " + "INNER JOIN CARDS C2 ON C.IDHAND = C2.IDHAND AND C.IDPLAYER = C2.IDPLAYER AND C2.CARDORDER = 2 AND C2.CARD IN ('" + hand.Substring(1, 1) + "h', '" + hand.Substring(1, 1) + "d', '" + hand.Substring(1, 1) + "s', '" + hand.Substring(1, 1) + "c') " + "WHERE " + suited + " C.IDPLAYER = " + idPlayer.ToString() + " " + "UNION " + "SELECT C.IDHAND " + "FROM CARDS C " + "INNER JOIN HANDPLAYERS HP ON HP.IDPLAYER = C.IDPLAYER AND HP.IDHAND = C.IDHAND " + "INNER JOIN HANDSESSIONS HS ON C.IDHAND = HS.IDHAND " + "INNER JOIN CARDS C1 ON C.IDHAND = C1.IDHAND AND C.IDPLAYER = C1.IDPLAYER AND C1.CARDORDER = 1 AND C1.CARD IN ('" + hand.Substring(1, 1) + "h', '" + hand.Substring(1, 1) + "d', '" + hand.Substring(1, 1) + "s', '" + hand.Substring(1, 1) + "c') " + "INNER JOIN CARDS C2 ON C.IDHAND = C2.IDHAND AND C.IDPLAYER = C2.IDPLAYER AND C2.CARDORDER = 2 AND C2.CARD IN ('" + hand.Substring(0, 1) + "h', '" + hand.Substring(0, 1) + "d', '" + hand.Substring(0, 1) + "s', '" + hand.Substring(0, 1) + "c')" + "WHERE " + suited + " C.IDPLAYER = " + idPlayer + " "; } } SQLiteDataReader dr = null; if (this.IDSession > 0) { if (filteredHands == "") { dr = sql.Select("SELECT C.IDHAND, C.CARD, HP.NETWON FROM CARDS C INNER JOIN PLAYERS P ON C.IDPLAYER = P.IDPLAYER INNER JOIN HANDPLAYERS HP ON HP.IDPLAYER=P.IDPLAYER AND HP.IDHAND=C.IDHAND INNER JOIN HANDSESSIONS HS ON HP.IDHAND=HS.IDHAND WHERE P.IDPLAYER = " + idPlayer + " AND HS.IDSESSION = " + this.IDSession + " ORDER BY C.IDHAND LIMIT 200 OFFSET " + ((page - 1) * 200).ToString()); } else { dr = sql.Select("SELECT C.IDHAND, C.CARD, HP.NETWON " + "FROM CARDS C " + "INNER JOIN PLAYERS P ON C.IDPLAYER = P.IDPLAYER " + "INNER JOIN HANDPLAYERS HP ON HP.IDPLAYER=P.IDPLAYER AND HP.IDHAND=C.IDHAND " + "INNER JOIN HANDSESSIONS HS ON HP.IDHAND=HS.IDHAND " + "WHERE P.IDPLAYER = " + idPlayer + " AND HS.IDSESSION = " + this.IDSession + " AND C.IDHAND IN (" + subquery + ") ORDER BY C.IDHAND LIMIT 200 OFFSET " + ((page - 1) * 200).ToString()); } } else { if (filteredHands == "") { dr = sql.Select("SELECT C.IDHAND, C.CARD, HP.NETWON FROM CARDS C INNER JOIN PLAYERS P ON C.IDPLAYER = P.IDPLAYER INNER JOIN HANDPLAYERS HP ON HP.IDPLAYER=P.IDPLAYER AND HP.IDHAND=C.IDHAND WHERE P.IDPLAYER = " + idPlayer + " ORDER BY C.IDHAND LIMIT 200 OFFSET " + ((page - 1) * 200).ToString()); } else { dr = sql.Select("SELECT C.IDHAND, C.CARD, HP.NETWON " + "FROM CARDS C " + "INNER JOIN PLAYERS P ON C.IDPLAYER = P.IDPLAYER " + "INNER JOIN HANDPLAYERS HP ON HP.IDPLAYER=P.IDPLAYER AND HP.IDHAND=C.IDHAND " + "INNER JOIN HANDSESSIONS HS ON HP.IDHAND=HS.IDHAND " + "WHERE P.IDPLAYER = " + idPlayer + " AND C.IDHAND IN (" + subquery + ") ORDER BY C.IDHAND LIMIT 200 OFFSET " + ((page - 1) * 200).ToString()); } } while (dr.Read()) { if (handView.CardOne == "" || handView.CardOne == null) { handView.IDHand = Convert.ToDouble(dr["IDHAND"]); handView.NetWon = Convert.ToDouble(dr["NETWON"]); handView.CardOne = dr["CARD"].ToString(); } else { handView.CardTwo = dr["CARD"].ToString(); listHandView.Add(handView); handView = new HandView(); } } return(listHandView); }