Ejemplo n.º 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
       
         String _name = Name_Textbox.Text;
         int _number;
         if (!(int.TryParse(Number_Textbox.Text, out _number)))
         {
            // MessageBox.Show("Invalid Number");             
               label4.Visible = true;   
         }
         else
         {
             PhoneDirectory phone = new PhoneDirectory(_name, _number);
             BusinessLayer phoneDetail = new BusinessLayer();
             bool result=phoneDetail.ValidateAndAdd(phone);
             if (result == true)
             {    
                 dataGridView1.DataSource = phoneDetail.ViewPhone(phone);
                 Number_Textbox.Clear();
                 Name_Textbox.Clear();
             }
             else
             {
                 MessageBox.Show("cannot be Added");
             }
         }
     }
     catch(Exception e1)
     {
         MessageBox.Show(e1.Message);
     }
 }
Ejemplo n.º 2
0
        public bool Add(PhoneDirectory directory)
        {
            try
            {
                using (SqlConnection sq = new SqlConnection("Server=localhost;Database=phone_directory;Trusted_Connection=true"))
                {
                    sq.Open();
                    var cmd = new SqlCommand("Insert into phone_dir values(@name,@phone)");
                    cmd.Connection = sq;
                    cmd.Parameters.AddWithValue("@name",directory.name);
                    cmd.Parameters.AddWithValue("@phone",directory.number);
                    cmd.ExecuteNonQuery();
                    return true;
                }
            }
            catch(Exception)
            {
                return false;
            }

        }
Ejemplo n.º 3
0
 public DataTable ViewPhone(PhoneDirectory phoneDetails)
 {
     return repository.viewAll();
 }
Ejemplo n.º 4
0
 public bool ValidateAndAdd(PhoneDirectory phoneDetails)
 {
     bool _validateResult=ValidatePhone();
     if (_validateResult==true)
     {
         return repository.Add(phoneDetails);
     }
     else
         return false;
 }