コード例 #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);
     }
 }
コード例 #2
0
        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";
        }
コード例 #3
0
        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;
                }
            }
        }