Beispiel #1
0
        private void button_click(object sender, EventArgs e)
        {
            Button btn = sender as Button;

            c_index             = Array.IndexOf(button_chat, btn);
            richtxtChat.Visible = true;
            richtxtChat.Text    = AddMessage(Member.chats[c_index].Messages);
            richtxtChat.Enabled = true;
            if (Member.chats[c_index].Receiver.Length == 1)
            {
                lblStatus.Text = $"\"{DBHandlerLiron.GetInstance().GetStatus(Member.chats[c_index].Receiver[0])}\" ~ {DBHandlerLiron.GetInstance().GetNameWithId(Member.chats[c_index].Receiver[0])}";
            }
            else
            {
                lblStatus.Text = "";
            }
            txtBox.Enabled         = true;
            btnAttachment.Enabled  = true;
            btnSend.Enabled        = true;
            lblStatus.Visible      = true;
            lblAttachments.Visible = true;
            foreach (var control in pnlAtta.Controls.OfType <LinkLabel>().ToList())
            {
                pnlAtta.Controls.Remove(control);
            }
            Member.chats[c_index].Att_ids = DBHandlerLiron.GetInstance().GetAttaIds(Member.c_ids[c_index]);
            AddAttachments(Member.chats[c_index].Att_ids);
        }
Beispiel #2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (txtName.Text != "" && txtPassword.Text != "")
            {
                int new_id = DBHandlerLiron.GetInstance().InsertMember(txtName.Text, txtPassword.Text);
                if (path != "")
                {
                    MemoryStream stream = new MemoryStream();
tryagain:
                    try
                    {
                        Bitmap image = new Bitmap(path);
                        image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                    catch
                    {
                        goto tryagain;
                    }
                    DBHandlerLiron.GetInstance().InsertProfilePicture(stream.ToArray(), new_id);
                }
                if (txtStatus.Text != "")
                {
                    DBHandlerLiron.GetInstance().InsertStatus(new_id, txtStatus.Text);
                }
                Close();
            }
            else
            {
                MessageBox.Show("Please input name and password!");
            }
        }
Beispiel #3
0
        public int[] GetChatIdsWithMemberId(int id)
        {
            int count = DBHandlerLiron.GetInstance().CountChatIds(id);

            connection.Open();
            OleDbCommand command = new OleDbCommand
            {
                Connection  = connection,
                CommandText = @"select Member_Chat.c_id
                                from Chat inner join (Member inner join Member_Chat on Member.id = Member_Chat.m_id) on Chat.id = Member_Chat.c_id
                                where Chat.deleted = false and Member_Chat.m_id = " + id
            };
            OleDbDataReader reader = command.ExecuteReader();

            if (!reader.Read())
            {
                connection.Close();
                return(new int[0]);
            }
            int[] c_ids = new int[count];
            for (int i = 0; i < c_ids.Length; ++i, reader.Read())
            {
                c_ids[i] = int.Parse(reader.GetValue(0).ToString());
            }
            connection.Close();
            return(c_ids);
        }
Beispiel #4
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     if (comboxType.SelectedItem.ToString() == "Admin" && DBHandlerLiron.GetInstance().GetPass("Admin", txtName.Text) == txtPassword.Text)
     {
         Hide();
         new AdminMenu().ShowDialog();
         Show();
         txtName.Text             = "";
         txtPassword.Text         = "";
         comboxType.SelectedIndex = 0;
     }
     else if (comboxType.SelectedItem.ToString() != "Admin" && DBHandlerLiron.GetInstance().GetPass("Member", txtName.Text) == txtPassword.Text)
     {
         Hide();
         if (comboxType.SelectedItem.ToString() == "Member")
         {
             new App(DBHandlerLiron.GetInstance().GetIdWithName(txtName.Text)).ShowDialog();
         }
         else if (comboxType.SelectedItem.ToString() == "Settings")
         {
             new Settings(DBHandlerLiron.GetInstance().GetIdWithName(txtName.Text)).ShowDialog();
         }
         Show();
         txtName.Text             = "";
         txtPassword.Text         = "";
         comboxType.SelectedIndex = 0;
     }
     else
     {
         MessageBox.Show("The name or password were incorrect");
     }
 }
Beispiel #5
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (comboxMember.SelectedItem != null)
     {
         DBHandlerLiron.GetInstance().DeletePlayer(DBHandlerLiron.GetInstance().GetIdWithName(comboxMember.Text));
     }
 }
Beispiel #6
0
        public void linklabel_clicked(object sender, EventArgs e)
        {
            LinkLabel lbl       = (LinkLabel)sender;
            int       lbl_index = Array.IndexOf(label_chat, lbl);

            DBHandlerLiron.GetInstance().DownloadAttachment(Member.chats[c_index].Att_ids[lbl_index]);
            MessageBox.Show("Download installed successfully!");
        }
Beispiel #7
0
 private void DeleteMember_Load(object sender, EventArgs e)
 {
     int[] ids = DBHandlerLiron.GetInstance().GetAllMembers(0);
     for (int i = 0; i < ids.Length; i++)
     {
         comboxMember.Items.Add(DBHandlerLiron.GetInstance().GetNameWithId(ids[i]));
     }
 }
Beispiel #8
0
 public static DBHandlerLiron GetInstance()
 {
     if (instance == null)
     {
         instance = new DBHandlerLiron();
     }
     return(instance);
 }
Beispiel #9
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (comboxChats.Items.Count != 0)
     {
         lblPar.Text   += comboxChats.SelectedItem.ToString() + " ";
         ids[CountId++] = DBHandlerLiron.GetInstance().GetIdWithName(comboxChats.SelectedItem.ToString());
         comboxChats.Items.Remove(comboxChats.SelectedItem);
         try { comboxChats.SelectedIndex = 0; }
         catch { }
     }
 }
Beispiel #10
0
 private void AddChat_Load(object sender, EventArgs e)
 {
     int[] ids = DBHandlerLiron.GetInstance().GetAllMembers(m_id);
     foreach (int id in ids)
     {
         comboxChats.Items.Add(DBHandlerLiron.GetInstance().GetNameWithId(id));
     }
     if (ids.Length > 0)
     {
         comboxChats.SelectedIndex = 0;
     }
     this.ids = new int[ids.Length];
     CountId  = 0;
 }
Beispiel #11
0
        private void btnAttachment_Click(object sender, EventArgs e)
        {
            DialogResult result = opnFile.ShowDialog();

            if (result == DialogResult.OK)
            {
                FileStream   fs           = new FileStream(opnFile.FileName, FileMode.Open, FileAccess.Read);
                BinaryReader br           = new BinaryReader(fs);
                byte[]       fileContents = br.ReadBytes((int)fs.Length);
                DBHandlerLiron.GetInstance().InsertAttachment(fileContents, opnFile.SafeFileName, Member.c_ids[c_index], Member.MemberId);
                Member.chats[c_index].Att_ids = DBHandlerLiron.GetInstance().GetAttaIds(Member.c_ids[c_index]);
                AddAttachments(Member.chats[c_index].Att_ids);
            }
        }
Beispiel #12
0
        public string AddMessage(TblMessage[] messages)
        {
            string message = "";

            for (int i = 0; i < messages.Length; i++)
            {
                if (messages[i].s_id == Member.MemberId)
                {
                    message += "Me: " + messages[i].content + "\n";
                }
                else
                {
                    message += DBHandlerLiron.GetInstance().GetNameWithId(messages[i].s_id) + ": " + messages[i].content + "\n";
                }
            }
            return(message);
        }
Beispiel #13
0
        public void InitializeChats(TblMember member)
        {
            button_chat  = new Button[member.c_ids.Length];
            picture_chat = new PictureBox[member.c_ids.Length];
            const int x = -2;
            int       y = richtxtChat.Location.Y;

            for (int i = 0; i < member.c_ids.Length; i++)
            {
                button_chat[i]          = new Button();
                button_chat[i].Location = new Point(x, y);
                button_chat[i].Name     = "btnChat_" + i.ToString();
                button_chat[i].Text     = DBHandlerLiron.GetInstance().GetChatName(member.MemberId, member.c_ids[i]);
                button_chat[i].Size     = new Size(btnAddChat.Size.Width, 43);
                button_chat[i].Font     = new Font("Arial Narrow", 16);
                button_chat[i].Padding  = new Padding(0);
                button_chat[i].Click   += new EventHandler(button_click);
                if (member.chats[i].Receiver.Length > 1)
                {
                    SizeButtonFont(button_chat[i]);
                }
                Controls.Add(button_chat[i]);

                if (member.chats[i].Receiver.Length == 1)
                {
                    picture_chat[i]      = new PictureBox();
                    picture_chat[i].Name = "pPic_" + i.ToString();
                    if (member.chats[i].Receiver.Length == 1)
                    {
                        picture_chat[i].Image = DBHandlerLiron.GetInstance().GetProfilePathWithMember(Member.chats[i].Receiver[0]);
                    }
                    picture_chat[i].BringToFront();
                    picture_chat[i].Location = new Point(x + 5, y + 7);
                    picture_chat[i].SizeMode = PictureBoxSizeMode.StretchImage;
                    picture_chat[i].Size     = new Size(30, 30);
                    picture_chat[i].Visible  = true;
                    Controls.Add(picture_chat[i]);
                    button_chat[i].SendToBack();
                }
                y += 43;
            }
            btnAddChat.Location = new Point(x, y);
            btnAddChat.SendToBack();
        }
Beispiel #14
0
        public void AddAttachments(int[] a_ids)
        {
            label_chat = new LinkLabel[a_ids.Length];
            int x = 3, y = 40;

            for (int i = 0; i < a_ids.Length; i++)
            {
                label_chat[i]          = new LinkLabel();
                label_chat[i].Text     = DBHandlerLiron.GetInstance().SelectFileDetails(a_ids[i]);
                label_chat[i].Name     = "lblLink_" + i.ToString();
                label_chat[i].Location = new Point(x, y);
                label_chat[i].BringToFront();
                label_chat[i].Visible  = true;
                label_chat[i].Click   += linklabel_clicked;
                label_chat[i].AutoSize = true;
                pnlAtta.Controls.Add(label_chat[i]);
                y += 32;
            }
        }
Beispiel #15
0
        private void btnAddChat_Click(object sender, EventArgs e)
        {
            AddChat input = new AddChat(Member.MemberId);

            if (input.ShowDialog(this) == DialogResult.OK && input.CountId != 0)
            {
                int[] ids = new int[input.CountId];
                for (int i = 0; i < input.CountId; i++)
                {
                    ids[i] = input.ids[i];
                }
                DBHandlerLiron.GetInstance().InsertChat(Member.MemberId, ids);
                Visible       = false;
                Member.Active = false;
                tmrCheckData.Stop();
                new App(Member.MemberId).ShowDialog();
                Close();
            }
        }
Beispiel #16
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool update = false;

            if (txtName.Text != "")
            {
                DBHandlerLiron.GetInstance().UpdateName(id, txtName.Text);
                update = true;
            }
            if (path != "")
            {
                MemoryStream stream = new MemoryStream();
tryagain:
                try
                {
                    Bitmap image = new Bitmap(path);
                    image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                }
                catch
                {
                    goto tryagain;
                }
                DBHandlerLiron.GetInstance().InsertProfilePicture(stream.ToArray(), id);
                update = true;
            }
            if (txtStatus.Text != "")
            {
                DBHandlerLiron.GetInstance().InsertStatus(id, txtStatus.Text);
                update = true;
            }
            if (update)
            {
                MessageBox.Show("Updated successfully\n          *\n         * *\n        *   *\n     ***      ***\n      *        *\n       *      *\n      *    *   *\n     *           *\n");
            }
            Close();
        }
Beispiel #17
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     if (Member.chats.Length > 0 && DBHandlerLiron.GetInstance().CountIds(Member.chats[c_index].Id) != Member.chats[c_index].Messages.Length)
     {
         Member.chats[c_index] = DBHandlerLiron.GetInstance().GetChat(Member.chats[c_index].Id, DBHandlerLiron.GetInstance().CountIds(Member.chats[c_index].Id));
         Member.UpdateReceiver(c_index);
         richtxtChat.Text = AddMessage(Member.chats[c_index].Messages);
     }
     if (Member.chats.Length > 0 && DBHandlerLiron.GetInstance().CountAttIds(Member.chats[c_index].Id) != Member.chats[c_index].Att_ids.Length)
     {
         foreach (var control in pnlAtta.Controls.OfType <LinkLabel>().ToList())
         {
             pnlAtta.Controls.Remove(control);
         }
         AddAttachments(Member.chats[c_index].Att_ids);
     }
     if (Member.chats.Length > 0 && DBHandlerLiron.GetInstance().CountChatIds(Member.MemberId) != Member.chats.Length && this == ActiveMdiChild)
     {
         Visible = false;
         tmrCheckData.Stop();
         new App(Member.MemberId).ShowDialog();
         Close();
     }
 }
Beispiel #18
0
 private void Settings_Load(object sender, EventArgs e)
 {
     Text = "Update " + DBHandlerLiron.GetInstance().GetNameWithId(id);
     path = "";
 }
Beispiel #19
0
 private void button1_Click(object sender, EventArgs e)
 {
     richtxtChat.Text += $"Me: {txtBox.Text}\n";
     DBHandlerLiron.GetInstance().InsertMessage(txtBox.Text, Member.MemberId, Member.chats[c_index].Id);
     txtBox.Clear();
 }
Beispiel #20
0
 private void App_Load(object sender, EventArgs e)
 {
     InitializeChats(Member);
     Text = DBHandlerLiron.GetInstance().GetNameWithId(Member.MemberId);
 }