Example #1
0
    protected void DeleteButton_Click(object sender, EventArgs e)
    {
        Int64 contactId = 0;

        for (int i = 0; i < SearchFarmResultGridView.Rows.Count; i++)
        {
            GridViewRow row       = SearchFarmResultGridView.Rows[i];
            bool        isChecked = ((CheckBox)row.FindControl("SelectContactCheckBox")).Checked;
            if (isChecked)
            {
                contactId = Int64.Parse(((CheckBox)row.FindControl("SelectContactCheckBox")).ToolTip);
            }
        }

        try
        {
            // Get the common web service instance.

            ServiceAccess           serviceLoader = ServiceAccess.GetInstance();
            FarmService.FarmService farmService   = serviceLoader.GetFarm();

            DeleteMessageHiddenField.Value = farmService.GetDeleteContactConsiquence(contactId) + " Are you sure you want to delete the Contact.";
        }
        catch (Exception exception)
        {
            log.Error("UNKNOWN ERROR WHILE DELECTING CONATACTS:", exception);
            MessageLiteral.Text = "UNKNOWN ERROR : Please Contact Administrator";
        }

        /*
         * OLD Bulk DELETE Code
         * // List of Contacts to be deleted
         * List<Int64> contactIdList = new List<Int64>();
         * for (int i = 0; i < SearchFarmResultGridView.Rows.Count; i++)
         * {
         *  GridViewRow row = SearchFarmResultGridView.Rows[i];
         *  bool isChecked = ((CheckBox)row.FindControl("SelectContactCheckBox")).Checked;
         *
         *  if (isChecked)
         *  {
         *      Int64 temp = Int64.Parse(((CheckBox)row.FindControl("SelectContactCheckBox")).ToolTip);
         *      contactIdList.Add(temp);
         *  }
         * }
         *
         * if (contactIdList.Count > 0)
         * {
         *  // Delete the List of Selected Contacts
         *  try
         *  {
         *      // Get the common web service instance.
         *
         *      ServiceAccess serviceLoader = ServiceAccess.GetInstance();
         *      FarmService.FarmService farmService = serviceLoader.GetFarm();
         *
         *      for (int j = 0; j < contactIdList.Count; j++)
         *          farmService.DeleteContact(contactIdList[j], LoginUserId);
         *      MessageLiteral.Text = "Selected Contacts have been Deleted";
         *      int CurrentPageIndex = SearchFarmResultGridView.PageIndex;
         *
         *      string where = GenerateSearchCondition();
         *      FarmService.FarmDetailsReportInfo[] farms = farmService.GetSearchFarmData(where);
         *      SearchFarmResultGridView.DataSource = farms;
         *      SearchFarmResultGridView.PageIndex = CurrentPageIndex;
         *      SearchFarmResultGridView.DataBind();
         *
         *      //Disable actions on deleted Contacts
         *      for (int k = 0; k < SearchFarmResultGridView.Rows.Count; k++)
         *          if (farms[SearchFarmResultGridView.Rows[k].DataItemIndex].Deleted)
         *              SearchFarmResultGridView.Rows[k].Cells[1].Enabled = false;
         *
         *      ResultCountLiteral.Text = "Found " + farms.Length + " matching records.";
         *  }
         *  catch (Exception exception)
         *  {
         *      log.Error("UNKNOWN ERROR WHILE DELECTING CONATACTS:", exception);
         *      MessageLiteral.Text = "UNKNOWN ERROR : Please Contact Administrator";
         *  }
         * }
         */
    }