Example #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Delete selected data?!", "Caution!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);

            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                using (LanChatDBDataContext db = new LanChatDBDataContext())
                {
                    db.DeferredLoadingEnabled = false;//
                    string   IDs    = dtgvMessage.SelectedCells[0].OwningRow.Cells["IDSender"].Value.ToString();
                    string   IDr    = dtgvMessage.SelectedCells[0].OwningRow.Cells["IDReciever"].Value.ToString();
                    mMESSAGE delete = db.mMESSAGEs.Where(p => p.IDSender.Equals(IDs) && p.IDReciever.Equals(IDr)).SingleOrDefault();
                    db.mMESSAGEs.DeleteOnSubmit(delete);
                    db.SubmitChanges();
                }
                btnRefresh_Click(sender, e);//refresh
            }
        }
Example #2
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            if (txtInput.Text != string.Empty)
            {
                BroadcastData("Message|Admin|" + txtInput.Text);
                txtReceive.Text += "Admin: " + txtInput.Text + "\r\n";
                //***save message
                using (LanChatDBDataContext db = new LanChatDBDataContext())
                {
                    db.DeferredLoadingEnabled = false;

                    mMESSAGE mes = new mMESSAGE();

                    var conversation = from c in db.mMESSAGEs
                                       where c.IDSender == "SERVE" && c.IDReciever == "PUBLI"
                                       select c;
                    if (conversation.Any())//co ton tai roi
                    {
                        mMESSAGE nmes = conversation.First();
                        nmes.Content += "Admin:" + txtInput.Text + "|";

                        db.SubmitChanges();
                    }
                    else//chua ton tai
                    {
                        mes.IDSender   = "SERVE";
                        mes.IDReciever = "PUBLI";
                        mes.Content    = "Admin:" + txtInput.Text + "|";
                        db.mMESSAGEs.InsertOnSubmit(mes);
                        db.SubmitChanges();
                    }
                }
                //save message***
                txtInput.Text = "";
            }
        }
Example #3
0
 partial void DeletemMESSAGE(mMESSAGE instance);
Example #4
0
 partial void UpdatemMESSAGE(mMESSAGE instance);
Example #5
0
 partial void InsertmMESSAGE(mMESSAGE instance);
Example #6
0
 private void detach_mMESSAGEs1(mMESSAGE entity)
 {
     this.SendPropertyChanging();
     entity.USER1 = null;
 }
Example #7
0
 private void attach_mMESSAGEs1(mMESSAGE entity)
 {
     this.SendPropertyChanging();
     entity.USER1 = this;
 }
Example #8
0
        private void client_Received(Client sender, byte[] data)
        {
            this.Invoke(() =>
            {
                for (int i = 0; i < clientList.Items.Count; i++)
                {
                    var client = clientList.Items[i].Tag as Client;
                    if (client == null || client.Ip != sender.Ip)
                    {
                        continue;
                    }
                    var command = Encoding.ASCII.GetString(data).Split('|');
                    switch (command[0])
                    {
                    case "Connect":
                        //txtReceive.SelectionColor = System.Drawing.Color.Red;

                        txtReceive.Text += "<< " + command[1] + " joined the room >>\r\n";

                        clientList.Items[i].SubItems[1].Text = command[1];     // nickname
                        clientList.Items[i].SubItems[2].Text = command[2];     // status
                        string users = string.Empty;
                        for (int j = 0; j < clientList.Items.Count; j++)
                        {
                            users += clientList.Items[j].SubItems[1].Text + "|";
                        }
                        BroadcastData("Users|" + users.TrimEnd('|'));
                        BroadcastData("RefreshChat|" + command[1]);    //nguoi vao sau khong thay nguoi vao truoc join room
                        break;

                    case "Message":
                        //public chat
                        txtReceive.Text += command[1] + ": " + command[2] + "\r\n";
                        BroadcastData("RefreshChat|" + command[1] + "|" + command[2]);
                        //***save message
                        using (LanChatDBDataContext db = new LanChatDBDataContext())
                        {
                            db.DeferredLoadingEnabled = false;

                            mMESSAGE mes = new mMESSAGE();

                            var id = from Id in db.USERs
                                     where Id.UserName == command[1].ToString()
                                     select Id.ID;    //lay id tu table users

                            string newid     = id.FirstOrDefault().ToString();
                            var conversation = from c in db.mMESSAGEs
                                               where c.IDSender == newid && c.IDReciever == "PUBLI"
                                               select c;
                            if (conversation.Any())    //co ton tai roi
                            {
                                mMESSAGE nmes = conversation.First();
                                nmes.Content += command[1] + ": " + command[2] + "|";

                                db.SubmitChanges();
                            }
                            else    //chua ton tai
                            {
                                mes.IDSender   = newid;
                                mes.IDReciever = "PUBLI";
                                mes.Content    = command[1] + ": " + command[2] + "|";
                                db.mMESSAGEs.InsertOnSubmit(mes);
                                db.SubmitChanges();
                            }
                        }
                        //save message***
                        break;

                    case "pMessage":
                        //private chat client voi server
                        this.Invoke(() =>
                        {
                            pChat.txtReceive.Text += command[1] + ": " + command[2] + "\r\n";
                            //***save message
                            using (LanChatDBDataContext db = new LanChatDBDataContext())
                            {
                                db.DeferredLoadingEnabled = false;

                                mMESSAGE mes = new mMESSAGE();

                                var id = from Id in db.USERs
                                         where Id.UserName == command[1].ToString()
                                         select Id.ID;    //lay id tu table users

                                string newid     = id.FirstOrDefault().ToString();
                                var conversation = from c in db.mMESSAGEs
                                                   where c.IDSender == newid && c.IDReciever == "SERVE"
                                                   select c;
                                if (conversation.Any())    //co ton tai roi
                                {
                                    mMESSAGE nmes = conversation.First();
                                    nmes.Content += command[1] + ": " + command[2] + "|";

                                    db.SubmitChanges();
                                }
                                else    //chua ton tai
                                {
                                    mes.IDSender   = newid;
                                    mes.IDReciever = "SERVE";
                                    mes.Content    = command[1] + ": " + command[2] + "|";
                                    db.mMESSAGEs.InsertOnSubmit(mes);
                                    db.SubmitChanges();
                                }
                            }
                        });
                        break;

                    case "pChat":

                        break;

                    case "pChatwithUser":
                        //private chat client voi client
                        this.Invoke(() =>
                        {
                            if (command[3] != "Server")
                            {
                                txtReceive.Text += command[1] + " to " + command[3] + ": " + command[2] + "\r\n";
                                string onlychat  = Encoding.ASCII.GetString(data);
                                BroadcastData(onlychat);
                                //***save message
                                using (LanChatDBDataContext db = new LanChatDBDataContext())
                                {
                                    db.DeferredLoadingEnabled = false;

                                    mMESSAGE mes = new mMESSAGE();

                                    var id1 = from Id in db.USERs
                                              where Id.UserName == command[1].ToString()
                                              select Id.ID;   //lay id tu table users

                                    var id2 = from Id in db.USERs
                                              where Id.UserName == command[3].ToString()
                                              select Id.ID;    //lay id tu table users


                                    string newid     = id1.FirstOrDefault().ToString();
                                    string newid2    = id2.FirstOrDefault().ToString();
                                    var conversation = from c in db.mMESSAGEs
                                                       where c.IDSender == newid && c.IDReciever == newid2
                                                       select c;
                                    if (conversation.Any())    //co ton tai roi
                                    {
                                        mMESSAGE nmes = conversation.First();
                                        nmes.Content += command[1] + ": " + command[2] + "|";

                                        db.SubmitChanges();
                                    }
                                    else    //chua ton tai
                                    {
                                        mes.IDSender   = newid;
                                        mes.IDReciever = newid2;
                                        mes.Content    = command[1] + ": " + command[2] + "|";
                                        db.mMESSAGEs.InsertOnSubmit(mes);
                                        db.SubmitChanges();
                                    }
                                }
                            }
                        });
                        break;
                    }
                }
            });
        }