private void btnSaveFarm_Click(object sender, EventArgs e)
        {
            try
            {
                bool validateFrom = true;
                var message = "Operation failed to add new farm.";
                int result = 0;

                if (string.IsNullOrEmpty(txtFarmName.Text))
                {
                    validateFrom = false;
                    message = "Please enter farm Name.";
                }
                else if (string.IsNullOrEmpty(cbCustomers.SelectedValue.ToString()))
                {
                    validateFrom = false;
                    message = "Please select customer.";
                }

                if (validateFrom)
                {
                    var farm = new CustomerFarm()
                    {
                        Name = txtFarmName.Text,
                        CustomerId = Convert.ToInt32(cbCustomers.SelectedValue),
                        CustomerFarmId = _editFarm != null ? _editFarm.CustomerFarmId : 0
                    };

                    if (farm.CustomerFarmId > 0)
                    {
                        result = _farmRepository.UpdateFarm(farm);
                    }
                    else
                    {
                        result = _farmRepository.AddFarm(farm);
                    }

                    if (result > 0)
                    {
                        message = "Farm saved successfully.";

                        clearFormValue();
                        initGridView();
                    }
                    else
                    {
                        message = "Operation failed to save farm.";
                    }
                }

                MessageBox.Show(message);

            }
            catch (Exception)
            {
            }
        }
 void clearFormValue()
 {
     txtFarmName.Text = null;
     cbCustomers.SelectedIndex = -1;
     _editFarm = new CustomerFarm();
     dgFarmsList.ClearSelection();
 }
 void setEditFormFields(int row)
 {
     try
     {
         if (_farmsList != null && _farmsList.Count > 0)
         {
             tabFarm.SelectedTab = tabPageForm;
             _editFarm = _farmsList[row];
             txtFarmName.Text = _editFarm.Name;
             cbCustomers.SelectedValue = _editFarm.CustomerId;
         }
     }
     catch (Exception)
     {
         throw;
     }
 }