Esempio n. 1
0
 private void BtnNew_Click(object sender, EventArgs e)
 {
     try
     {
         string phoneNumber = txbPhoneNumber.Text;
         string firstName   = txbFirstName.Text;
         string lastName    = txbLastName.Text;
         string address     = txbAddress.Text;
         if (PhoneAddress.checkPhoneNumber(phoneNumber) == false)
         {
             MessageBox.Show("Wrong format at PhoneNumber field", "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else if (PhoneAddress.checkName(firstName) == false || PhoneAddress.checkName(lastName) == false)
         {
             MessageBox.Show("Your name must contain alphabet characters only", "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else
         {
             string formedPhoneNumber = phoneNumber.Replace(" ", ""); //moi sua
             if (DataAccess.Insert(formedPhoneNumber, firstName, lastName, address) == 1)
             {
                 DialogResult dr = MessageBox.Show("Success", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); //can them event dong form khi click OK
                 if (dr == DialogResult.OK)
                 {
                     ParentMainForm.refreshDataGridView(PhoneAddress.SearchPhoneAddress(SearchDetails[0], SearchDetails[1], SearchDetails[2], SearchDetails[3]));
                     this.Close();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("This number are already existed", "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
        private void btnReset_Click(object sender, EventArgs e)
        {
            txbPhoneNumber.Text = "";
            txbLastName.Text    = "";
            txbFirstName.Text   = "";
            txbAddress.Text     = "";
            selectedRowIndex    = -1;

            refreshDataGridView(PhoneAddress.GetAllPhoneAddress());
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string phoneNumber = txbPhoneNumber.Text;
            string firstName   = txbFirstName.Text;
            string lastName    = txbLastName.Text;
            string address     = txbAddress.Text;

            selectedRowIndex = -1;

            refreshDataGridView(PhoneAddress.SearchPhoneAddress(phoneNumber, firstName, lastName, address));
            //lbInfo.Text = "Your search is successful. Here is the result";
        }
Esempio n. 4
0
        public static List <PhoneAddress> SearchPhoneAddress(string phoneNumber, string firstName, string lastName, string address)
        {
            List <PhoneAddress> listPhoneAddress = new List <PhoneAddress>();
            DataTable           dt = DataAccess.SearchPhoneAddress(phoneNumber, firstName, lastName, address);

            foreach (DataRow dr in dt.Rows)
            {
                string phoneNumber2 = PhoneAddress.PhoneForming(dr["PhoneNumber"].ToString()); //moi sua
                string firstName2   = dr["FirstName"].ToString();
                string lastName2    = dr["LastName"].ToString();
                string address2     = dr["Address"].ToString();

                listPhoneAddress.Add(new PhoneAddress(phoneNumber2, firstName2, lastName2, address2));
            }
            return(listPhoneAddress);
        }
        private void dgPhoneBook_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1)
            {
                if (dgPhoneBook.Columns[e.ColumnIndex].Name == "deleteCol")
                {
                    string       phoneNumber = dgPhoneBook.Rows[e.RowIndex].Cells[0].Value.ToString();
                    DialogResult result      = MessageBox.Show("Do you want to delete?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (result == DialogResult.Yes)
                    {
                        PhoneAddress.DeletePhoneAddress(phoneNumber);
                        refreshDataGridView(PhoneAddress.SearchPhoneAddress(txbPhoneNumber.Text, txbFirstName.Text, txbLastName.Text, txbAddress.Text));
                        MessageBox.Show("Delete " + phoneNumber + " successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        selectedRowIndex = -1;
                    }

                    return;
                }
            }
        }
 private void MainForm_Load(object sender, EventArgs e)
 {
     refreshDataGridView(PhoneAddress.GetAllPhoneAddress());
 }