public Form2()
 {
     InitializeComponent();
     this.FormClosing += Form2_FormClosing;
     data = new ContactData();
     button1.Text = "Add Contact";
     button1.Click += button1Click_close;
 }
 public Form2(ContactData _data)
 {
     InitializeComponent();
     this.FormClosing += Form2_FormClosing;
     data = _data;
     textBox1.Text = data.name;
     textBox1.ReadOnly = true;
     textBox2.Text = data.number.ToString();
     button1.Text = "Change phone number";
     button1.Click += button1Click_close;
 }
 public Form2(int state)
 {
     InitializeComponent();
     this.FormClosing += Form2_FormClosing;
     data = new ContactData();
     if (state==1)
         //request for number input
     {
         textBox1.ReadOnly = true;
         button1.Text = "Search name";
         button1.Click += button1Click_close_data1;
     }
     if (state==2)
         //request for name input
     {
         textBox2.ReadOnly = true;
         button1.Text = "Search phone";
         button1.Click += button1Click_close_data2;
     }
 }
 private void button4_Click(object sender, EventArgs e)
 {
     //modify contact
     int index = dataGridView1.CurrentRow.Index;
     try
     {
         string name = dataGridView1.Rows[index].Cells[0].Value.ToString();
         int number = Convert.ToInt32(dataGridView1.Rows[index].Cells[1].Value.ToString());
         Form2 form2 = new Form2(new ContactData(name, number));
         form2.ShowDialog();
         ContactData data = new ContactData();
         data = form2.ReturnData();
         TestServiceClient client = new TestServiceClient();
         client.Open();
         client.ModifyContact(number, data.number);
         client.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }