From 8577f351a9d3775cb32e59d7fbcc4c2974c20946 Mon Sep 17 00:00:00 2001 From: GyeongHo Yang Date: Mon, 31 May 2021 21:30:12 +0900 Subject: [PATCH] Modify office room --- Server/Classes/Database.cs | 35 ++++++++++++++++++++++------------- Server/Program.cs | 2 +- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Server/Classes/Database.cs b/Server/Classes/Database.cs index 8e655ce..4b66dea 100644 --- a/Server/Classes/Database.cs +++ b/Server/Classes/Database.cs @@ -210,21 +210,30 @@ public static bool CreateOfficeRoom() { // 회사 전체 톡방이 없을 경우 만듦 MySqlCommand cmd = new MySqlCommand( - "INSERT INTO room VALUES (@id, @scope, @target);", - con); - - cmd.Parameters.AddWithValue("@id", MD5.NextRandom()); - cmd.Parameters.AddWithValue("@scope", 0); - cmd.Parameters.AddWithValue("@target", Room.Scope[0]); - try - { - cmd.ExecuteNonQuery(); - return true; - } - catch + "SELECT * FROM room WHERE scope=0;", con); + MySqlDataReader rdr = cmd.ExecuteReader(); + if (!rdr.HasRows) { - return false; + rdr.Close(); + cmd = new MySqlCommand( + "INSERT INTO room VALUES (@id, @scope, @target);", + con); + + cmd.Parameters.AddWithValue("@id", MD5.NextRandom()); + cmd.Parameters.AddWithValue("@scope", 0); + cmd.Parameters.AddWithValue("@target", Room.Scope[0]); + try + { + cmd.ExecuteNonQuery(); + return true; + } + catch + { + return false; + } } + rdr.Close(); + return false; } public static List GetRooms(Employee emp) { diff --git a/Server/Program.cs b/Server/Program.cs index 31bb127..b3ca321 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -30,7 +30,7 @@ static void Main(string[] args) { Log("DB", $"Server {Database.hostname} is connected"); if (Database.CreateOfficeRoom()) - Log("DB", $"Office room is created"); + Log("DB", "Office room is created"); employees = Database.GetEmployees(); } else