Esempio n. 1
0
        private void Txttiimkiem_TextChanged(object sender, EventArgs e)
        {
            var contactListNoSort = Contactservice.GetContactBySearch(txttiimkiem.Text, pathcontact);

            datacontact.DataSource = contactListNoSort;
            datacontact.ResetBindings(true);
        }
Esempio n. 2
0
        private void Label_Click(object sender, EventArgs e)
        {
            var labelName         = ((Label)sender).Text;
            var listContactNoSort = Contactservice.GetContactInAlphabetic(labelName, pathcontact);
            var newContactList    = listContactNoSort.OrderBy(x => x.Name).ToList();

            datacontact.DataSource = newContactList;
            datacontact.ResetBindings(true);
        }
Esempio n. 3
0
        private void Btnadd_Click(object sender, EventArgs e)
        {
            var f = new  ThemContact();

            if (f.ShowDialog() == DialogResult.OK)
            {
                datacontact.DataSource = null;

                var list1          = Contactservice.GetContact(pathcontact);
                var newContactList = list1.OrderBy(x => x.Name);
                datacontact.DataSource = newContactList;
                datacontact.ResetBindings(true);
                AddNewLabel();
            }
        }
Esempio n. 4
0
        public void AddNewLabel()
        {
            flowLayoutPanel1.Controls.Clear();
            List <string> listLabelDuplicate = new List <string>();
            var           listContactNoSort  = Contactservice.GetContact(pathcontact);

            foreach (var item in listContactNoSort)
            {
                listLabelDuplicate.Add(item.Ma);
            }
            List <String> labels = listLabelDuplicate.Distinct().ToList();

            labels.Sort();
            for (int i = 0; i < labels.Count; i++)
            {
                Label lbl = new Label();
                lbl.Text   = labels[i];
                lbl.Click += new System.EventHandler(this.Label_Click);
                flowLayoutPanel1.Controls.Add(lbl);
            }
        }
Esempio n. 5
0
        public NguyenQuocHoang()
        {
            InitializeComponent();
            pathcontact = Application.StartupPath + @"\Data\contact.txt";

            datacontact.DataSource        = null;
            dtcontact.AutoGenerateColumns = false;
            var list1       = Contactservice.GetContact(pathcontact);
            var listContact = list1.OrderBy(x => x.Name).ToList();

            if (listContact == null)
            {
                throw new Exception("Không có liên lạc ");
            }
            else
            {
                datacontact.DataSource = listContact;
            }
            dtcontact.DataSource = datacontact;
            AddNewLabel();
        }
Esempio n. 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (ct != null)
            {
                var    listContact = Contactservice.GetContact(pathcontact);
                string moi         = txtname.Text + "#" + txtphone.Text + "#" + txtemail.Text;

                String cu       = ct.Name + "#" + ct.Phone + "#" + ct.Email;
                var    Lines    = File.ReadAllLines(pathcontact);
                var    newLines = Lines.Where(line => !line.Contains(cu));
                File.WriteAllLines(pathcontact, newLines);
                File.AppendAllText(pathcontact, moi);
            }
            else
            {
                string newContact = txtname.Text + "#" + txtphone.Text + "#" + txtemail.Text;
                File.AppendAllText(pathcontact, "\n" + newContact);
                Console.WriteLine("\nđã thêm");
            }
            MessageBox.Show("đã cập nhật dữ liệu thành công");
            DialogResult = DialogResult.OK;
        }
Esempio n. 7
0
        private void Btndelete_Click(object sender, EventArgs e)
        {
            var rs = MessageBox.Show(
                "Bạn Có Muốn Xóa Không?",
                "Thông Báo",
                MessageBoxButtons.OKCancel,
                MessageBoxIcon.Warning);

            if (rs == DialogResult.OK)
            {
                var ct = datacontact.Current as contact;

                if (ct != null)
                {
                    String ma    = ct.Ma;
                    String name  = ct.Name;
                    String phone = ct.Phone;
                    String email = ct.Email;
                    String td    = name + "#" + phone + "#" + email;
                    File.WriteAllLines(pathcontact,
                                       File.ReadLines(pathcontact).Where(l => (l != td)).ToList());
                }

                datacontact.DataSource        = null;
                dtcontact.DataSource          = null;
                dtcontact.AutoGenerateColumns = false;
                datacontact.DataSource        = Contactservice.GetContact(pathcontact);
                dtcontact.DataSource          = datacontact;
                MessageBox.Show(
                    "Xóa Thành Công" + ct.Name);
                AddNewLabel();
            }
            else
            {
                MessageBox.Show("Không Xóa");
            }
        }