Exemplo n.º 1
0
        public void deleteDetail(PersonalDetail dt)
        {
            string     delete  = "UPDATE PersonalDetails SET usable=" + 0.ToString() + " WHERE Id=" + dt.id.ToString();
            SqlCommand command = new SqlCommand(delete);

            command.Connection = DbConnection;
            command.ExecuteNonQuery();
        }
Exemplo n.º 2
0
        public void createDetail(PersonalDetail dt)
        {
            string queryFrame = "INSERT INTO PersonalDetails (Id, person, category, subcategory, content, usable) " +
                                "VALUES (@Id, @person, @category, @subcategory, @content, @usable)";

            using (SqlCommand insert = new SqlCommand(queryFrame))
            {
                insert.Connection = DbConnection;
                insert.Parameters.Add("@Id", SqlDbType.Int).Value               = Convert.ToInt32((DateTime.Now.Ticks << 32) >> 32);
                insert.Parameters.Add("@person", SqlDbType.Int).Value           = dt.account;
                insert.Parameters.Add("@category", SqlDbType.NChar, 20).Value   = dt.category;
                insert.Parameters.Add("@subcategory", SqlDbType.Char, 20).Value = dt.subcategory;
                insert.Parameters.Add("@usable", SqlDbType.Int).Value           = 1;/**/
                insert.Parameters.Add("@content", SqlDbType.Text).Value         = dt.content;
                insert.ExecuteNonQuery();
            }
        }

        public void updateDetail(PersonalDetail origin, PersonalDetail update)
        {
            deleteDetail(origin);
            createDetail(update);
        }

        public void UpdatePerson(Person per)
        {
            string queryFrame = "UPDATE Persons SET name = @name, introduction=@introduction, created=@created WHERE Id=@Id";

            using (SqlCommand update = new SqlCommand(queryFrame))
            {
                update.Connection = DbConnection;
                update.Parameters.AddWithValue("@Id", SqlDbType.Int).Value            = per.id;
                update.Parameters.AddWithValue("@name", SqlDbType.Text).Value         = per.name;
                update.Parameters.AddWithValue("@introduction", SqlDbType.Text).Value = per.introduction;
                update.Parameters.AddWithValue("@created", SqlDbType.DateTime).Value  = DateTime.Now;/**/
                update.ExecuteNonQuery();
            }
        }
Exemplo n.º 3
0
        public void SReceive(Object dest)
        {
            Socket other = dest as Socket;

            try
            {
                while (true)
                {
                    byte[] data = new byte[1024 * 5000];
                    other.Receive(data);

                    string   msg    = (string)DeserializeMsg(data);
                    string[] tokens = msg.Split('_');
                    if (tokens[0] == "STATUS")
                    {
                        if (tokens[1] == "DISCARD CONNECTION")
                        {
                            p.Remove(tokens[2].ToString().Trim());
                            Form1.getInstance().networkSubWindow1.UpdateClientList(p, others);
                            Form1.getInstance().UpdateConnectionStatus("Connected to " + tokens[2].ToString().Trim());
                        }
                        else
                        {
                            p.Add(tokens[2]);
                            Form1.getInstance().networkSubWindow1.UpdateClientList(p, others);
                            Form1.getInstance().UpdateConnectionStatus("Connected to " + tokens[2].ToString().Trim());
                        }
                    }
                    else if (tokens[0] == "ACCOUNT")
                    {
                        Account a = new Account()
                        {
                            username = tokens[3].ToString().Trim(),
                            id       = Convert.ToInt32(tokens[1]),
                            password = tokens[2].ToString().Trim(),
                            created  = Convert.ToDateTime(tokens[4].ToString().Trim()),
                        };
                        Form1.getInstance().UpdateConnectionStatus("Received information from account " + tokens[3].ToString().Trim());

                        if (DataHandle.getInstance().doesAccountExit(a))
                        {
                            Form1.getInstance().UpdateConnectionStatus("Account " + tokens[3].ToString().Trim() + " has already existed");
                        }
                        else
                        {
                            DataHandle.getInstance().saveAccount(a);
                        }
                    }
                    else if (tokens[0] == "DETAILS")
                    {
                        PersonalDetail d = new PersonalDetail()
                        {
                            id          = Convert.ToInt32(tokens[1]),
                            account     = Convert.ToInt32(tokens[5]),
                            category    = tokens[4].ToString().Trim(),
                            subcategory = tokens[2].ToString().Trim(),
                            content     = tokens[3].ToString().Trim(),
                        };

                        DataHandle.getInstance().createDetail(d);
                    }
                    else if (tokens[0] == "REMINDER")
                    {
                        Reminders r = new Reminders()
                        {
                            ID      = Convert.ToInt32(tokens[1]),
                            Tittle  = tokens[2].ToString().Trim(),
                            Content = tokens[3].ToString().Trim(),
                            Time    = tokens[4].ToString().Trim(),
                            Check   = Convert.ToInt32(tokens[5]),
                            User_id = Convert.ToInt32(tokens[6]),
                        };
                        Form1.getInstance().UpdateConnectionStatus("Received reminder from account " + tokens[tokens.Length - 1]);

                        DataHandle.getInstance().CreateNewReminder(r);
                    }
                    else if (tokens[0] == "NOTE")
                    {
                        Notes n = new Notes()
                        {
                            id      = Convert.ToInt32(tokens[1]),
                            Tittle  = tokens[2].ToString().Trim(),
                            Content = tokens[4].ToString().Trim(),
                            user_id = Convert.ToInt32(tokens[3]),
                        };
                        Form1.getInstance().UpdateConnectionStatus("Received reminder from account " + tokens[tokens.Length - 1]);
                        DataHandle.getInstance().CreateNewNote(n);
                    }
                }
            }
            catch
            {
                others.Remove(other);
                other.Close();
            }
        }
Exemplo n.º 4
0
        public void CReceive()
        {
            try
            {
                while (true)
                {
                    byte[] data = new byte[1024 * 5000];
                    peer.Receive(data);

                    string   msg    = (string)DeserializeMsg(data);
                    string[] tokens = msg.Split('_');
                    if (tokens[0] == "STATUS")
                    {
                        if (tokens[1] == "DISCARD CONNECTION")
                        {
                            Form1.getInstance().UpdateConnectionStatus("Disconnected to account " + tokens[tokens.Length - 1]);
                            Close();
                        }
                        else
                        {
                            Form1.getInstance().UpdateConnectionStatus("Connected to account " + tokens[tokens.Length - 1]);
                        }
                        /*p.Add(tokens[2]);*/
                    }
                    else if (tokens[0] == "ACCOUNT")
                    {
                        Account a = new Account()
                        {
                            username = tokens[3].ToString().Trim(),
                            id       = Convert.ToInt32(tokens[1]),
                            password = tokens[2].ToString().Trim(),
                            created  = Convert.ToDateTime(tokens[4].ToString().Trim()),
                        };
                        DataHandle.getInstance().saveAccount(a);

/*                        Form1.getInstance().networkSubWindow1.UpdateClientList(p, others);
 */                 }
                    else if (tokens[0] == "DETAILS")
                    {
                        PersonalDetail d = new PersonalDetail()
                        {
                            id          = Convert.ToInt32(tokens[1]),
                            account     = Convert.ToInt32(tokens[5]),
                            category    = tokens[4].ToString().Trim(),
                            subcategory = tokens[2].ToString().Trim(),
                            content     = tokens[3].ToString().Trim(),
                        };
                        DataHandle.getInstance().createDetail(d);
                    }
                    else if (tokens[0] == "REMINDER")
                    {
                        Reminders r = new Reminders()
                        {
                            ID      = Convert.ToInt32(tokens[1]),
                            Tittle  = tokens[2].ToString().Trim(),
                            Content = tokens[3].ToString().Trim(),
                            Time    = tokens[4].ToString().Trim(),
                            Check   = Convert.ToInt32(tokens[5]),
                            User_id = Convert.ToInt32(tokens[6]),
                        };
                        DataHandle.getInstance().CreateNewReminder(r);
                    }
                    else if (tokens[0] == "NOTE")
                    {
                        Notes n = new Notes()
                        {
                            id      = Convert.ToInt32(tokens[1]),
                            Tittle  = tokens[2].ToString().Trim(),
                            Content = tokens[4].ToString().Trim(),
                            user_id = Convert.ToInt32(tokens[3]),
                        };
                        DataHandle.getInstance().CreateNewNote(n);
                    }
                }
            }
            catch
            {
                Close();
            }
        }