Ejemplo n.º 1
0
    protected void RestoreFarmButton_Click(object sender, EventArgs e)
    {
        try
        {
            // Get the common web service instance.
            ServiceAccess           serviceLoader = ServiceAccess.GetInstance();
            FarmService.FarmService farmService   = serviceLoader.GetFarm();

            for (int i = 0; i < FarmGridView.Rows.Count; i++)
            {
                GridViewRow row       = FarmGridView.Rows[i];
                bool        isChecked = ((CheckBox)row.FindControl("FarmIdCheckBox")).Checked;
                if (isChecked)
                {
                    int farmId = int.Parse(((CheckBox)row.FindControl("FarmIdCheckBox")).ToolTip);
                    farmService.RestoreFarmPlot(farmId, LoginUserId);
                }
            }

            FarmService.FarmInfo[] farmList;
            farmList = farmService.GetArchivedFarmSummary(GetAgentId());
            FarmGridView.DataSource = farmList;
            FarmGridView.DataBind();
            if (farmList.Length == 0)
            {
                NoFarmDataPanel.Visible = true;
            }
            else
            {
                NoFarmDataPanel.Visible = false;
                for (int i = 0; i < FarmGridView.Rows.Count; i++)
                {
                    if (farmList[i].Deleted == true)
                    {
                        FarmGridView.Rows[i].ForeColor = System.Drawing.Color.Red;
                    }
                    else if (farmList[i].PlotCount == 0)
                    {
                        FarmGridView.Rows[i].ForeColor = System.Drawing.Color.Green;
                    }
                    else
                    {
                        FarmGridView.Rows[i].ForeColor = System.Drawing.Color.DarkKhaki;
                    }
                }
            }
        }
        catch (Exception exception)
        {
            log.Error("UNKNOWN ERROR WHILE RESTORE FARM:", exception);
            MessageLiteral.Text = "Error: Unable to Restore Farm";
        }
    }