Example #1
0
    protected void CreateFarmButton_Click(object sender, EventArgs e)
    {
        //Store Farm Details and Farm Contact details into the Session
        try
        {
            ServiceAccess           serviceLoader = ServiceAccess.GetInstance();
            FarmService.FarmService farmService   = serviceLoader.GetFarm();
            //Checking File Type
            if (!ContactListFileUpload.HasFile)
            {
                ErrorLiteral.Text = "Please Select The File";
                return;
            }

            //Check for Duplicate Farm Name
            if (farmService.IsFarmNameDuplicateWhileAddingNewFarm(GetAgentId(), FarmNameTextBox.Text))
            {
                ErrorLiteral.Text = "Farm name already exists, Please enter a different farm name";
                return;
            }

            //Load the Contact File List
            IList <FarmService.ContactInfo> contacts;

            if (ContactListFileUpload.FileName.EndsWith(".csv"))
            {
                contacts = farmService.GetFarmListFromFile(ContactListFileUpload.FileName, Irmac.MailingCycle.BLLServiceLoader.Farm.ContactFileType.Csv, ContactListFileUpload.FileBytes, LoginUserId);
            }
            else
            {
                if (ContactListFileUpload.FileName.EndsWith(".xls"))
                {
                    contacts = farmService.GetFarmListFromFile(ContactListFileUpload.FileName, Irmac.MailingCycle.BLLServiceLoader.Farm.ContactFileType.Excel, ContactListFileUpload.FileBytes, LoginUserId);
                }
                else
                {
                    ErrorLiteral.Text = "Invalid File Uploaded. Please Check your file Extention (Must be either .csv or .xls)";
                    return;
                }
            }

            ContactListGridView.DataSource = contacts;
            ContactListGridView.DataBind();
            Panel1.Visible      = false;
            Panel2.Visible      = true;
            Session["Contacts"] = contacts;
            ErrorLiteral.Text   = "";
        }
        catch (Exception ex)
        {
            log.Error("UNKNOWN ERROR WHILE CONTACT FILE UPLOAD:", ex);
            if (ex.Message.Contains("Irmac.MailingCycle.BLL.NoDataException"))
            {
                ErrorLiteral.Text = "The file does not have any data.";
            }
            else if (ex.Message.Contains("Irmac.MailingCycle.BLL.InvalidFormatException"))
            {
                ErrorLiteral.Text = "The file is in invalid format.";
            }
            else if (ex.Message.Contains("Irmac.MailingCycle.BLL.InvalidDataException"))
            {
                ErrorLiteral.Text = "Incomplete data in the uploaded file.";
            }
            else if (ex.Message.Contains("Irmac.MailingCycle.BLL.InvalidFieldDataException"))
            {
                ErrorLiteral.Text = "Incomplete data in the uploaded file.";
            }
            else if (ex.Message.Contains("Farm Name already Exist. Please give another name"))
            {
                ErrorLiteral.Text = "Farm Name already Exist. Please give another name.";
            }
            else if (ex.Message.Contains("No valid Contact records in the uploaded File."))
            {
                ErrorLiteral.Text = "No valid Contact records in the uploaded File.";
            }
            else
            {
                ErrorLiteral.Text = "Unknown Error. Please Contact Administrator.";
            }
        }
    }
Example #2
0
    protected void ModifyPlotButton_Click(object sender, EventArgs e)
    {
        //Store Plot Details and Plot Contact details into the Session
        try
        {
            ServiceAccess           serviceLoader = ServiceAccess.GetInstance();
            FarmService.FarmService farmService   = serviceLoader.GetFarm();

            IList <FarmService.ContactInfo> contacts = null;

            //Checking For Duplicate Plot Name
            if (farmService.IsPlotNameDuplicateWhileEditingPlot(
                    Convert.ToInt32(FarmIdHiddenField.Value.ToString()),
                    Convert.ToInt32(PlotIdHiddenField.Value.ToString()),
                    PlotNameTextBox.Text))
            {
                ErrorLiteral.Text = "Plot name already exists, Please enter a different Plot name";
                return;
            }

            //Checking File Type
            if (ContactListFileUpload.HasFile)
            {
                if (ContactListFileUpload.FileName.EndsWith(".csv"))
                {
                    contacts = farmService.GetFarmListFromFile(ContactListFileUpload.FileName, Irmac.MailingCycle.BLLServiceLoader.Farm.ContactFileType.Csv, ContactListFileUpload.FileBytes, LoginUserId);
                }
                else
                {
                    if (ContactListFileUpload.FileName.EndsWith(".xls"))
                    {
                        contacts = farmService.GetFarmListFromFile(ContactListFileUpload.FileName, Irmac.MailingCycle.BLLServiceLoader.Farm.ContactFileType.Excel, ContactListFileUpload.FileBytes, LoginUserId);
                    }
                    else
                    {
                        ErrorLiteral.Text = "Invalid File Uploaded. Please Check your file Extention (Must be either .csv or .xls)";
                        return;
                    }
                }
            }

            if (contacts != null)
            {
                ContactListGridView.DataSource = contacts;
                ContactListGridView.DataBind();
                Panel1.Visible      = false;
                Panel2.Visible      = true;
                Session["Contacts"] = contacts;
                ErrorLiteral.Text   = "";
            }
            else
            {
                Session.Remove("Contacts");
                FarmService.PlotInfo plot = new FarmService.PlotInfo();

                plot.PlotId       = Convert.ToInt32(PlotIdHiddenField.Value.ToString());
                plot.PlotName     = PlotNameTextBox.Text;
                plot.FarmId       = Convert.ToInt32(FarmIdHiddenField.Value.ToString());
                plot.Contacts     = null;
                plot.LastModifyBy = LoginUserId;
                farmService.UpdatePlot(plot);
                Response.Redirect(GetRedirectURL());
            }
        }
        catch (Exception ex)
        {
            log.Error("UNKNOWN ERROR:", ex);
            if (ex.Message.Contains("Irmac.MailingCycle.BLL.NoDataException"))
            {
                ErrorLiteral.Text = "The file does not have any data.";
            }
            else if (ex.Message.Contains("Irmac.MailingCycle.BLL.InvalidFormatException"))
            {
                ErrorLiteral.Text = "The file is in invalid format.";
            }
            else if (ex.Message.Contains("Irmac.MailingCycle.BLL.InvalidDataException"))
            {
                ErrorLiteral.Text = "Incomplete data in the uploaded file.";
            }
            else if (ex.Message.Contains("Irmac.MailingCycle.BLL.InvalidFieldDataException"))
            {
                ErrorLiteral.Text = "Incomplete data in the uploaded file.";
            }
            else if (ex.Message.Contains("You are changing Primary Plot Name which will change the Farm name. A Farm by this name already exisist. Please provide a differnt Plot name."))
            {
                ErrorLiteral.Text = "You are changing Primary Plot Name which will change the Farm name. A Farm by this name already exisist. Please provide a differnt Plot name.";
            }
            else if (ex.Message.Contains("No valid Contact records in the uploaded File."))
            {
                ErrorLiteral.Text = "No valid Contact records in the uploaded File.";
            }
            else
            {
                ErrorLiteral.Text = "Unknown Error. Please Contact Administrator.";
            }
        }
    }
Example #3
0
    protected void ModifyFarmButton_Click(object sender, EventArgs e)
    {
        //Store Farm Details and Farm Contact details into the Session
        try
        {
            ServiceAccess           serviceLoader = ServiceAccess.GetInstance();
            FarmService.FarmService farmService   = serviceLoader.GetFarm();

            //Checking For Duplicate Farm Name
            if (farmService.IsFarmNameDuplicateWhileEditingFarm(
                    GetAgentId(),
                    Convert.ToInt32(FarmIdHiddenField.Value),
                    FarmNameTextBox.Text))
            {
                ErrorLiteral.Text = "Farm name already exists, Please enter a different farm name";
                return;
            }

            IList <FarmService.ContactInfo> contacts = null;
            //Checking File Type
            if (ContactListFileUpload.HasFile)
            {
                if (ContactListFileUpload.FileName.EndsWith(".csv"))
                {
                    contacts = farmService.GetFarmListFromFile(ContactListFileUpload.FileName, Irmac.MailingCycle.BLLServiceLoader.Farm.ContactFileType.Csv, ContactListFileUpload.FileBytes, LoginUserId);
                }
                else
                {
                    if (ContactListFileUpload.FileName.EndsWith(".xls"))
                    {
                        contacts = farmService.GetFarmListFromFile(ContactListFileUpload.FileName, Irmac.MailingCycle.BLLServiceLoader.Farm.ContactFileType.Excel, ContactListFileUpload.FileBytes, LoginUserId);
                    }
                    else
                    {
                        ErrorLiteral.Text = "Invalid File Uploaded. Please Check your file Extention (Must be either .csv or .xls)";
                        return;
                    }
                }
            }

            if (contacts != null)
            {
                ContactListGridView.DataSource = contacts;
                ContactListGridView.DataBind();
                Panel1.Visible      = false;
                Panel2.Visible      = true;
                Session["Contacts"] = contacts;
                if (!IsAgentRole)
                {
                    ForAgentLiteral1.Visible = true;
                    ForAgentLiteral1.Text    = ForAgentLiteral.Text;
                }
                else
                {
                    ForAgentLiteral1.Visible = false;
                }

                ErrorLiteral.Text = "";
            }
            else
            {
                FarmService.FarmInfo farm = new FarmService.FarmInfo();
                farm.FarmId      = Convert.ToInt32(FarmIdHiddenField.Value);
                farm.FarmName    = FarmNameTextBox.Text;
                farm.MailingPlan = new FarmService.MailingPlanInfo();
                farm.MailingPlan.MailingPlanId = int.Parse(MailingPlanDropDownList.SelectedValue);
                farm.LastModifyBy          = LoginUserId;
                farm.Plots                 = new FarmService.PlotInfo[1];
                farm.Plots[0]              = new FarmService.PlotInfo();
                farm.Plots[0].PlotId       = Convert.ToInt32(PlotIdHiddenField.Value);
                farm.Plots[0].PlotName     = FarmNameTextBox.Text;
                farm.Plots[0].LastModifyBy = LoginUserId;
                farm.Plots[0].Contacts     = null;
                farm.UserId                = GetAgentId();
                farmService.UpdateFarmPlot(farm);
                Response.Redirect(GetRedirectURL());
            }
        }
        catch (Exception ex)
        {
            log.Error("UNKNOWN ERROR:", ex);
            if (ex.Message.Contains("Irmac.MailingCycle.BLL.NoDataException"))
            {
                ErrorLiteral.Text = "The file does not have any data.";
            }
            else if (ex.Message.Contains("Irmac.MailingCycle.BLL.InvalidFormatException"))
            {
                ErrorLiteral.Text = "The file is in invalid format.";
            }
            else if (ex.Message.Contains("Irmac.MailingCycle.BLL.InvalidDataException"))
            {
                ErrorLiteral.Text = "Incomplete data in the uploaded file.";
            }
            else if (ex.Message.Contains("Irmac.MailingCycle.BLL.InvalidFieldDataException"))
            {
                ErrorLiteral.Text = "Incomplete data in the uploaded file.";
            }
            else if (ex.Message.Contains("Farm Name already Exist"))
            {
                ErrorLiteral.Text = "Farm Name already exists";
            }
            else if (ex.Message.Contains("You are changing Farm Name and this will change the name of Primary Plot.This name already existing in its Plot lists. Please Provide a different Farm name."))
            {
                ErrorLiteral.Text = "You are changing Farm Name and this will change the name of Primary Plot.This name already existing in its Plot lists. Please Provide a different Farm name.";
            }
            else if (ex.Message.Contains("No valid Contact records in the uploaded File."))
            {
                ErrorLiteral.Text = "No valid Contact records in the uploaded File.";
            }
            else
            {
                ErrorLiteral.Text = "Unknown Error. Please Contact Administrator.";
            }
        }
    }