Esempio n. 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.";
            }
        }
    }