private void Create_Click(object sender, EventArgs e) { try { cmd = new SQLiteCommand(); Random rastgele = new Random(); int Roomid = rastgele.Next(100000, 999999); con.Open(); cmd.Connection = con; cmd.CommandText = "insert into Rooms (Roomid,RoomAdmin,RoomTitle,RoomGame,PlayerCount) values ('" + Roomid.ToString() + "','" + Onlineusername + "','" + Roomtitle.Text + "','" + Gamename.Text + "','" + PlayerCount.SelectedItem + "')"; cmd.ExecuteNonQuery(); con.Close(); inroom inroom = new inroom(); inroom.OnlineUser = Onlineusername; inroom.roomid = Roomid.ToString(); inroom.roomtitle = Roomtitle.Text; inroom.gamename = Gamename.Text; inroom.laterornow = now.Checked; this.Close(); inroom.Show(); } catch { MessageBox.Show("Zaten bir odanız var"); Rooms rooms = new Rooms(); rooms.Onlineusername = Onlineusername; rooms.Show(); } }
private void insertplayer(int id) { string emptyplace = ""; con.Open(); cmd = new SQLiteCommand(); cmd.Connection = con; cmd.CommandText = "select Player1,Player2,Player3,Player4 from Rooms where Roomid=" + Roomids[id]; SQLiteDataReader readit = cmd.ExecuteReader(); while (readit.Read()) { if (Onlineusername == readit[0].ToString() || Onlineusername == readit[1].ToString() || Onlineusername == readit[2].ToString() || Onlineusername == readit[3].ToString()) { inroom inroom = new inroom(); inroom.roomid = Roomids[id].ToString(); inroom.Roomsid.Text = Roomids[id].ToString(); inroom.Show(); break; } else { if (readit[0].ToString() == "") { emptyplace = "Player1"; break; } else if (readit[1].ToString() == "") { emptyplace = "Player2"; break; } else if (readit[2].ToString() == "") { emptyplace = "Player3"; break; } else if (readit[3].ToString() == "") { emptyplace = "Player4"; break; } else { emptyplace = ""; } } } if (emptyplace != "") { cmd = new SQLiteCommand("update Rooms set " + emptyplace + "=@name where Roomid=" + Roomids[id], con); cmd.Parameters.AddWithValue("@name", Onlineusername); cmd.ExecuteNonQuery(); con.Close(); inroom inroom = new inroom(); inroom.roomid = id.ToString(); inroom.Show(); } else { MessageBox.Show("ODA DOLU"); con.Close(); } label6.Text = emptyplace; }