Skip to content

Commit

Permalink
Continuing chat
Browse files Browse the repository at this point in the history
  • Loading branch information
geoje committed May 28, 2021
1 parent 117fcb5 commit b56cebf
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 58 deletions.
1 change: 1 addition & 0 deletions Client/Forms/FormChat.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Client/Forms/FormChat.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Client.Panels;
using MetroFramework.Forms;
using OSTLibrary.Chats;
using OSTLibrary.Networks;
using System;
using System.Windows.Forms;

Expand All @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions Client/Forms/FormLogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
4 changes: 3 additions & 1 deletion Client/Forms/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
75 changes: 37 additions & 38 deletions Client/Panels/PanelSchedule.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions Client/Panels/PanelSchedule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Client.Forms;
using OSTLibrary.Chats;
using System;
using System.Windows.Forms;

Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OSTLibrary.Classes;
using OSTLibrary.Chats;
using OSTLibrary.Classes;
using OSTLibrary.Networks;
using System;
using System.Collections.Generic;
Expand All @@ -18,6 +19,7 @@ static class Program
public static Dictionary<PacketType, Action<Packet>> callback; // 타입에 따른 콜백 메소드

public static Employee employee; // 나의 사원 정보
public static List<Room> rooms; // 채팅방 정보
public static List<Employee> employees; // 사원들 정보
public static FormMain formMain; // 적당한 폼 상호작용을 위한 메인폼

Expand Down
6 changes: 3 additions & 3 deletions OSTLibrary/Chats/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 5 additions & 2 deletions OSTLibrary/Networks/LoginPacket.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OSTLibrary.Classes;
using OSTLibrary.Chats;
using OSTLibrary.Classes;
using System;
using System.Collections.Generic;

Expand All @@ -8,6 +9,7 @@ namespace OSTLibrary.Networks
public class LoginPacket : Packet
{
public List<Employee> employees;
public List<Room> rooms;

public bool success = false;

Expand All @@ -18,12 +20,13 @@ public LoginPacket(int empId, string password)
employees = new List<Employee>();
employees.Add(new Employee(empId, password));
}
public LoginPacket(bool success, List<Employee> employees)
public LoginPacket(bool success, List<Employee> employees, List<Room> rooms)
{
type = PacketType.Login;

this.success = success;
this.employees = employees;
this.rooms = rooms;
}
}
}
2 changes: 1 addition & 1 deletion OSTLibrary/Networks/Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OSTLibrary.Networks
{
public enum PacketType
{
Header, Close, Login, Logout, Register, Chat
Header, Close, Login, Logout, Register, Chat, Room
}

[Serializable]
Expand Down
25 changes: 25 additions & 0 deletions OSTLibrary/Networks/RoomPacket.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
1 change: 1 addition & 0 deletions OSTLibrary/OSTLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Compile Include="Networks\LoginPacket.cs" />
<Compile Include="Networks\LogoutPacket.cs" />
<Compile Include="Networks\Packet.cs" />
<Compile Include="Networks\RoomPacket.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Networks\RegisterPacket.cs" />
<Compile Include="Securities\AES256.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Server/Classes/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
32 changes: 29 additions & 3 deletions Server/Classes/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Room> GetRoom(Employee emp)
public static List<Room> GetRooms(Employee emp)
{
return null;
List<Room> rooms = new List<Room>();

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)
{
Expand Down

0 comments on commit b56cebf

Please sign in to comment.