コード例 #1
0
    protected void RestorePlotButton_Click(object sender, EventArgs e)
    {
        bool jumpError = false;

        try
        {
            // Get the common web service instance.
            ServiceAccess           serviceLoader = ServiceAccess.GetInstance();
            FarmService.FarmService farmService   = serviceLoader.GetFarm();

            for (int i = 0; i < PlotListGridView.Rows.Count; i++)
            {
                GridViewRow row       = PlotListGridView.Rows[i];
                bool        isChecked = ((CheckBox)row.FindControl("PlotIdCheckBox")).Checked;
                if (isChecked)
                {
                    int plotId = int.Parse(((CheckBox)row.FindControl("PlotIdCheckBox")).ToolTip);
                    farmService.RestorePlotContact(plotId, LoginUserId);
                }
            }

            int farmId = int.Parse(FarmIdHiddenField.Value.ToString());
            FarmService.FarmInfo farm = farmService.GetArchivedFarmSummaryDetails(farmId);
            FarmNameLabel.Text         = farm.FarmName;
            MailingPlanLabel.Text      = farm.MailingPlan.Title;
            CreateDateLabel.Text       = farm.CreateDate.ToShortDateString();
            FarmContactCountLabel.Text = farm.ContactCount.ToString();
            PlotCountLabel.Text        = farm.PlotCount.ToString();

            FarmService.PlotInfo[] Plots = farmService.GetArchivedPlotSummary(farmId);

            PlotListGridView.DataSource = Plots;
            PlotListGridView.DataBind();
            for (int i = 0; i < PlotListGridView.Rows.Count; i++)
            {
                if (Plots[i].Deleted)
                {
                    PlotListGridView.Rows[i].ForeColor = System.Drawing.Color.DarkKhaki;
                }
                else
                {
                    PlotListGridView.Rows[i].ForeColor        = System.Drawing.Color.Green;
                    PlotListGridView.Rows[i].Cells[0].Enabled = false;
                }
            }
        }
        catch (Exception exception)
        {
            if (exception.Message.Contains("Parent Farm is in Deleted State. Plot Cannot be restored"))
            {
                ErrorLiteral.Text = "Parent Farm is in Deleted State. Plot Cannot be restored";
            }
            else
            {
                log.Error("UNKNOWN ERROR WHILE RESTORING CONTACT:", exception);
                ErrorLiteral.Text = "Unknown Error Please contact Administrator:";
                jumpError         = true;
            }
            if (jumpError)
            {
                Response.Redirect("~/Members/ArchivedFarmList.aspx");
            }
        }
    }