public static void Edit() { string qs = "SELECT [MessageID],[DateOfSubmission],[Sender],[Receiver],[MessageData] FROM [ChatDb].[dbo].[Messages]"; List <message> msglist = Database_access.query_msg_DB(qs); Console.WriteLine("Message ID\t\tDate\t\tSender\t\tReceiver\t\tMessage"); for (int i = 0; i < msglist.Count(); i++) { Console.WriteLine(msglist[i].MessageID + "\t\t" + msglist[i].DateOfSubmission + "\t\t" + msglist[i].Sender + "\t\t" + msglist[i].Receiver + "\t\t" + msglist[i].Message_Data); } Console.Write("MessageId To Edit : "); string answer = Console.ReadLine(); int n = 0; bool correct = int.TryParse(answer, out n); if (correct) { try { //edit the message Console.Write("\nwrite new message : "); string newmsg = Console.ReadLine(); //write in sql string updatequery = "update [ChatDb].[dbo].[Messages] set [MessageData]='" + newmsg + "' where MessageID='" + n + "'"; Database_access.updateDB(updatequery); Console.WriteLine("Message has been updated"); } catch (Exception e) { Console.WriteLine("Sorry, wrong MessageID : " + e.Message); } } }
public static void Delete() { string qs = "SELECT [MessageID],[DateOfSubmission],[Sender],[Receiver],[MessageData] FROM [ChatDb].[dbo].[Messages]"; List <message> msglist = Database_access.query_msg_DB(qs); Console.WriteLine("Message ID\tDate\tSender\tReceiver\tMessage"); for (int i = 0; i < msglist.Count(); i++) { Console.WriteLine(msglist[i].MessageID + "\t" + msglist[i].DateOfSubmission + "\t" + msglist[i].Sender + "\t" + msglist[i].Receiver + "\t" + msglist[i].Message_Data); } Console.Write("Message ID to delete : "); string answer = Console.ReadLine(); int n = 0; bool correct1 = int.TryParse(answer, out n); if (correct1) { try { //delete the message string deletequery = "delete from [ChatDb].[dbo].[Messages] where MessageID = '" + n + "'"; Database_access.updateDB(deletequery); } catch (Exception e) { Console.WriteLine("Sorry wrong MessageID : " + e.Message); } } }
public static void View() { string qs = "SELECT [MessageID],[DateOfSubmission],[Sender],[Receiver],[MessageData] FROM [ChatDb].[dbo].[Messages]"; List <message> msglist = Database_access.query_msg_DB(qs); Console.WriteLine("Message ID\t\tDate\t\tSender\t\tReceiver\t\tMessage"); for (int i = 0; i < msglist.Count(); i++) { Console.WriteLine(msglist[i].MessageID + "\t\t" + msglist[i].DateOfSubmission + "\t" + msglist[i].Sender + "\t\t" + msglist[i].Receiver + "\t\t" + msglist[i].Message_Data); } }