diff --git a/Client/Forms/FormChat.Designer.cs b/Client/Forms/FormChat.Designer.cs index 7c76941..25141e5 100644 --- a/Client/Forms/FormChat.Designer.cs +++ b/Client/Forms/FormChat.Designer.cs @@ -164,6 +164,7 @@ private void InitializeComponent() this.ShadowType = MetroFramework.Forms.MetroFormShadowType.AeroShadow; this.Style = MetroFramework.MetroColorStyle.Yellow; this.Text = "섬유2팀"; + this.Load += new System.EventHandler(this.FormChat_Load); ((System.ComponentModel.ISupportInitialize)(this.picSend)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.picSetting)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.picPlus)).EndInit(); diff --git a/Client/Forms/FormChat.cs b/Client/Forms/FormChat.cs index be1c518..da05e42 100644 --- a/Client/Forms/FormChat.cs +++ b/Client/Forms/FormChat.cs @@ -1,6 +1,7 @@ using Client.Panels; using MetroFramework.Forms; using OSTLibrary.Chats; +using OSTLibrary.Networks; using System; using System.Windows.Forms; @@ -15,6 +16,14 @@ public FormChat(Room room) InitializeComponent(); this.room = room; } + private void FormChat_Load(object sender, EventArgs e) + { + // 새로운 채팅방 + if (string.IsNullOrEmpty(room.id)) + { + Program.Send(new RoomPacket(RoomType.New, room)); + } + } private void pic_MouseEnter(object sender, EventArgs e) { diff --git a/Client/Forms/FormLogin.cs b/Client/Forms/FormLogin.cs index ee1e1c4..c03e438 100644 --- a/Client/Forms/FormLogin.cs +++ b/Client/Forms/FormLogin.cs @@ -147,6 +147,7 @@ public void EndLogin(Packet packet) if (chkAutoLogin.Checked) File.WriteAllText("login.txt", Program.employee.id + "\n" + Program.employee.password); Program.employee = p.employees.Find(emp => emp.id == Program.employee.id); + Program.rooms = p.rooms; Program.employees = p.employees; BeginInvoke(new MethodInvoker(() => Close())); } diff --git a/Client/Forms/FormMain.cs b/Client/Forms/FormMain.cs index faa47cd..e6945df 100644 --- a/Client/Forms/FormMain.cs +++ b/Client/Forms/FormMain.cs @@ -4,6 +4,7 @@ using OSTLibrary.Chats; using OSTLibrary.Networks; using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Windows.Forms; @@ -50,7 +51,8 @@ private void FormMain_Shown(object sender, EventArgs e) ToolStripItem tsiInfo = node.ContextMenuStrip.Items.Add("정보"); ToolStripItem tsiChat = node.ContextMenuStrip.Items.Add("채팅"); tsiInfo.Click += (nodeSender, nodeE) => new FormInfo(emp).Show(); - tsiChat.Click += (nodeSender, nodeE) => new FormChat(new Room("", 0, "")).Show(); + tsiChat.Click += (nodeSender, nodeE) => new FormChat( + new Room("", 3, emp.id + "," + Program.employee.id)).Show(); node.ImageIndex = node.SelectedImageIndex = tvwOrganization.ImageList.Images.Count - 1; diff --git a/Client/Panels/PanelSchedule.Designer.cs b/Client/Panels/PanelSchedule.Designer.cs index 2cd3bfd..c2b3641 100644 --- a/Client/Panels/PanelSchedule.Designer.cs +++ b/Client/Panels/PanelSchedule.Designer.cs @@ -31,7 +31,6 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PanelSchedule)); - this.txtTitle = new MetroFramework.Controls.MetroTextBox(); this.dtpStart = new MetroFramework.Controls.MetroDateTime(); this.dtpEnd = new MetroFramework.Controls.MetroDateTime(); this.lblStart = new MetroFramework.Controls.MetroLabel(); @@ -41,39 +40,10 @@ private void InitializeComponent() this.txtContent = new MetroFramework.Controls.MetroTextBox(); this.cmbRange = new MetroFramework.Controls.MetroComboBox(); this.picClose = new System.Windows.Forms.PictureBox(); + this.txtTitle = new MetroFramework.Controls.MetroTextBox(); ((System.ComponentModel.ISupportInitialize)(this.picClose)).BeginInit(); this.SuspendLayout(); // - // txtTitle - // - // - // - // - this.txtTitle.CustomButton.Image = null; - this.txtTitle.CustomButton.Location = new System.Drawing.Point(-20, 2); - this.txtTitle.CustomButton.Name = ""; - this.txtTitle.CustomButton.Size = new System.Drawing.Size(17, 17); - this.txtTitle.CustomButton.Style = MetroFramework.MetroColorStyle.Yellow; - this.txtTitle.CustomButton.TabIndex = 1; - this.txtTitle.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.txtTitle.CustomButton.UseSelectable = true; - this.txtTitle.CustomButton.Visible = false; - this.txtTitle.Lines = new string[0]; - this.txtTitle.Location = new System.Drawing.Point(0, 0); - this.txtTitle.MaxLength = 32767; - this.txtTitle.Name = "txtTitle"; - this.txtTitle.PasswordChar = '\0'; - this.txtTitle.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.txtTitle.SelectedText = ""; - this.txtTitle.SelectionLength = 0; - this.txtTitle.SelectionStart = 0; - this.txtTitle.ShortcutsEnabled = true; - this.txtTitle.Size = new System.Drawing.Size(0, 22); - this.txtTitle.TabIndex = 22; - this.txtTitle.UseSelectable = true; - this.txtTitle.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.txtTitle.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // // dtpStart // this.dtpStart.Location = new System.Drawing.Point(60, 86); @@ -177,11 +147,6 @@ private void InitializeComponent() // this.cmbRange.FormattingEnabled = true; this.cmbRange.ItemHeight = 23; - this.cmbRange.Items.AddRange(new object[] { - "회사 전체", - "본부 전체", - "팀 전체", - "개인"}); this.cmbRange.Location = new System.Drawing.Point(60, 206); this.cmbRange.Name = "cmbRange"; this.cmbRange.Size = new System.Drawing.Size(240, 29); @@ -204,10 +169,45 @@ private void InitializeComponent() this.picClose.MouseEnter += new System.EventHandler(this.pic_MouseEnter); this.picClose.MouseLeave += new System.EventHandler(this.pic_MouseLeave); // + // txtTitle + // + // + // + // + this.txtTitle.CustomButton.Image = null; + this.txtTitle.CustomButton.Location = new System.Drawing.Point(216, 1); + this.txtTitle.CustomButton.Name = ""; + this.txtTitle.CustomButton.Size = new System.Drawing.Size(23, 23); + this.txtTitle.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; + this.txtTitle.CustomButton.TabIndex = 1; + this.txtTitle.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; + this.txtTitle.CustomButton.UseSelectable = true; + this.txtTitle.CustomButton.Visible = false; + this.txtTitle.DisplayIcon = true; + this.txtTitle.Icon = global::Client.Properties.Resources.calendar; + this.txtTitle.Lines = new string[0]; + this.txtTitle.Location = new System.Drawing.Point(60, 32); + this.txtTitle.MaxLength = 32767; + this.txtTitle.Name = "txtTitle"; + this.txtTitle.PasswordChar = '\0'; + this.txtTitle.PromptText = "제목"; + this.txtTitle.ScrollBars = System.Windows.Forms.ScrollBars.None; + this.txtTitle.SelectedText = ""; + this.txtTitle.SelectionLength = 0; + this.txtTitle.SelectionStart = 0; + this.txtTitle.ShortcutsEnabled = true; + this.txtTitle.Size = new System.Drawing.Size(240, 25); + this.txtTitle.TabIndex = 22; + this.txtTitle.UseSelectable = true; + this.txtTitle.WaterMark = "제목"; + this.txtTitle.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); + this.txtTitle.WaterMarkFont = new System.Drawing.Font("맑은 고딕", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))); + // // PanelSchedule // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.txtTitle); this.Controls.Add(this.cmbRange); this.Controls.Add(this.txtContent); this.Controls.Add(this.tleSubmit); @@ -216,7 +216,6 @@ private void InitializeComponent() this.Controls.Add(this.lblStart); this.Controls.Add(this.dtpEnd); this.Controls.Add(this.dtpStart); - this.Controls.Add(this.txtTitle); this.Controls.Add(this.picClose); this.Location = new System.Drawing.Point(0, 30); this.Name = "PanelSchedule"; @@ -231,7 +230,6 @@ private void InitializeComponent() #endregion private System.Windows.Forms.PictureBox picClose; - private MetroFramework.Controls.MetroTextBox txtTitle; private MetroFramework.Controls.MetroDateTime dtpStart; private MetroFramework.Controls.MetroDateTime dtpEnd; private MetroFramework.Controls.MetroLabel lblStart; @@ -240,5 +238,6 @@ private void InitializeComponent() private MetroFramework.Controls.MetroTile tleSubmit; private MetroFramework.Controls.MetroTextBox txtContent; private MetroFramework.Controls.MetroComboBox cmbRange; + private MetroFramework.Controls.MetroTextBox txtTitle; } } diff --git a/Client/Panels/PanelSchedule.cs b/Client/Panels/PanelSchedule.cs index 976c45d..4a9abff 100644 --- a/Client/Panels/PanelSchedule.cs +++ b/Client/Panels/PanelSchedule.cs @@ -1,4 +1,4 @@ -using Client.Forms; +using OSTLibrary.Chats; using System; using System.Windows.Forms; @@ -13,13 +13,7 @@ public PanelSchedule(Form owner, SlidingType type) : base(owner, type) } private void PanelSchedule_Load(object sender, EventArgs e) { - cmbRange.Items.AddRange(new string[] - { - "사내 전체", - Program.employee.central, - Program.employee.team, - Program.employee.name, - }); + cmbRange.Items.AddRange(Room.Range); } private void pic_MouseEnter(object sender, EventArgs e) diff --git a/Client/Program.cs b/Client/Program.cs index 674cdc8..3a493c8 100644 --- a/Client/Program.cs +++ b/Client/Program.cs @@ -1,4 +1,5 @@ -using OSTLibrary.Classes; +using OSTLibrary.Chats; +using OSTLibrary.Classes; using OSTLibrary.Networks; using System; using System.Collections.Generic; @@ -18,6 +19,7 @@ static class Program public static Dictionary> callback; // 타입에 따른 콜백 메소드 public static Employee employee; // 나의 사원 정보 + public static List rooms; // 채팅방 정보 public static List employees; // 사원들 정보 public static FormMain formMain; // 적당한 폼 상호작용을 위한 메인폼 diff --git a/OSTLibrary/Chats/Room.cs b/OSTLibrary/Chats/Room.cs index 0f0ea3b..f4ec670 100644 --- a/OSTLibrary/Chats/Room.cs +++ b/OSTLibrary/Chats/Room.cs @@ -7,13 +7,13 @@ public class Room { public static string[] Range = { "회사 전체", "본부 전체", "팀 전체", "개인" }; - public string roomId; + public string id; public int rangeIdx; public string target; - public Room(string roomId, int rangeIdx, string target) + public Room(string id, int rangeIdx, string target) { - this.roomId = roomId; + this.id = id; this.rangeIdx = rangeIdx; this.target = target; } diff --git a/OSTLibrary/Networks/LoginPacket.cs b/OSTLibrary/Networks/LoginPacket.cs index d8d7bbd..1868643 100644 --- a/OSTLibrary/Networks/LoginPacket.cs +++ b/OSTLibrary/Networks/LoginPacket.cs @@ -1,4 +1,5 @@ -using OSTLibrary.Classes; +using OSTLibrary.Chats; +using OSTLibrary.Classes; using System; using System.Collections.Generic; @@ -8,6 +9,7 @@ namespace OSTLibrary.Networks public class LoginPacket : Packet { public List employees; + public List rooms; public bool success = false; @@ -18,12 +20,13 @@ public LoginPacket(int empId, string password) employees = new List(); employees.Add(new Employee(empId, password)); } - public LoginPacket(bool success, List employees) + public LoginPacket(bool success, List employees, List rooms) { type = PacketType.Login; this.success = success; this.employees = employees; + this.rooms = rooms; } } } diff --git a/OSTLibrary/Networks/Packet.cs b/OSTLibrary/Networks/Packet.cs index c1c463c..57ee8e8 100644 --- a/OSTLibrary/Networks/Packet.cs +++ b/OSTLibrary/Networks/Packet.cs @@ -6,7 +6,7 @@ namespace OSTLibrary.Networks { public enum PacketType { - Header, Close, Login, Logout, Register, Chat + Header, Close, Login, Logout, Register, Chat, Room } [Serializable] diff --git a/OSTLibrary/Networks/RoomPacket.cs b/OSTLibrary/Networks/RoomPacket.cs new file mode 100644 index 0000000..fa42714 --- /dev/null +++ b/OSTLibrary/Networks/RoomPacket.cs @@ -0,0 +1,25 @@ +using OSTLibrary.Chats; +using System; + +namespace OSTLibrary.Networks +{ + public enum RoomType + { + New + } + + [Serializable] + public class RoomPacket : Packet + { + public RoomType roomType; + public Room room; + + public RoomPacket(RoomType roomType, Room room) + { + type = PacketType.Room; + + this.roomType = roomType; + this.room = room; + } + } +} diff --git a/OSTLibrary/OSTLibrary.csproj b/OSTLibrary/OSTLibrary.csproj index 6a2ecf3..079986f 100644 --- a/OSTLibrary/OSTLibrary.csproj +++ b/OSTLibrary/OSTLibrary.csproj @@ -54,6 +54,7 @@ + diff --git a/Server/Classes/Client.cs b/Server/Classes/Client.cs index 73df5f7..a2c1610 100644 --- a/Server/Classes/Client.cs +++ b/Server/Classes/Client.cs @@ -97,7 +97,7 @@ public void Recieve() } Thread.Sleep(200); // 클라이언트 스피너 보기 위함 - Send(new LoginPacket(emp != null, Program.employees)); + Send(new LoginPacket(emp != null, Program.employees, Database.GetRooms(emp))); } else if (packet.type == PacketType.Logout) { diff --git a/Server/Classes/Database.cs b/Server/Classes/Database.cs index 486b038..78a4221 100644 --- a/Server/Classes/Database.cs +++ b/Server/Classes/Database.cs @@ -178,12 +178,38 @@ public static Schedule GetSchedule(int authorID) } - public static void AddRoom(Room room) + public static bool AddRoom(Room room) { + MySqlCommand cmd = new MySqlCommand( + "INSERT INTO room VALUES (@id, @range, @target);", + con); + + cmd.Parameters.AddWithValue("@id", room.id); + cmd.Parameters.AddWithValue("@range", room.rangeIdx); + cmd.Parameters.AddWithValue("@range", room.target); + try + { + cmd.ExecuteNonQuery(); + return true; + } + catch (MySqlException) + { + return false; + } } - public static List GetRoom(Employee emp) + public static List GetRooms(Employee emp) { - return null; + List rooms = new List(); + + string sql = $"SELECT * FROM room WHERE range=0" + + $" UNION SELECT * FROM room WHERE range=1 AND target=" + emp.central + + $" UNION SELECT * FROM room WHERE range=2 AND target=" + emp.team + + $" UNION SELECT * FROM room WHERE range=3 AND target LIKE '%" + emp.id + "%'"; + using (MySqlDataReader rdr = new MySqlCommand(sql, con).ExecuteReader()) + while (rdr.Read()) + rooms.Add(new Room(rdr.GetString("id"), rdr.GetInt32("range"), rdr.GetString("target"))); + + return rooms; } public static void AddChatText(Chat chat) {