protected void CreatePlotButton_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(); //Checking File Type if (!ContactListFileUpload.HasFile) { ErrorLiteral.Text = "Please Select The File"; return; } 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; } } if (farmService.IsPlotNameDuplicateWhileAddingNewPlot(Convert.ToInt32(Request.QueryString["farmId"]), PlotNameTextBox.Text)) { ErrorLiteral.Text = "Plot name already exists, Please enter a different Plot name"; return; } ContactListGridView.DataSource = contacts; ContactListGridView.DataBind(); Panel1.Visible = false; Panel2.Visible = true; Session["Contacts"] = contacts; ErrorLiteral.Text = ""; } 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("Plot Name already in use. Please provide a new Plot Name")) { ErrorLiteral.Text = "Plot Name already in use. Please provide a new Plot Name"; } else if (ex.Message.Contains("No valid Contact records in uploaded File.")) { ErrorLiteral.Text = "No valid Contact records in uploaded File."; } else { ErrorLiteral.Text = "Unknown Error. Please Contact Administrator."; } } }
protected void SaveButton_Click(object sender, EventArgs e) { try { // Get the common web service instance. ServiceAccess serviceLoader = ServiceAccess.GetInstance(); FarmService.FarmService farmService = serviceLoader.GetFarm(); string contactIds = ContactIdsHiddenField.Value.ToString(); string[] arrContactId = contactIds.Split(new char[] { ';' }); RegistrationService.LoginInfo loginInfo = (RegistrationService.LoginInfo)Session["loginInfo"]; int userId = loginInfo.UserId; if (PlotListDropDownList.SelectedValue.ToString() == "-2") { //Check the New Plot Name for Duplicate if (farmService.IsPlotNameDuplicateWhileAddingNewPlot(Convert.ToInt32(FarmIdHiddenField.Value.ToString()), NewPlotHiddenField.Value.ToString())) { ErrorLiteral.Text = "Duplicate Plot Name provided. Please provide a different Plot Name"; PlotListDropDownList.Items.FindByValue("-2").Text = "New Plot ..."; PlotListDropDownList.SelectedIndex = 0; NewPlotHiddenField.Value = ""; return; } //Default Plot Check if (farmService.IsDefaultPlot(Convert.ToInt32(PlotIdHiddenField.Value.ToString()))) { if (arrContactId.Length >= farmService.GetContactCountForPlot(Convert.ToInt32(PlotIdHiddenField.Value.ToString()))) { ErrorLiteral.Text = "Error: Default Plot Cannot be empty."; PlotListDropDownList.Items.FindByValue("-2").Text = "New Plot ..."; NewPlotHiddenField.Value = ""; return; } } //Building Model Object FarmService.PlotInfo plot = new FarmService.PlotInfo(); plot.PlotId = 0; plot.PlotName = NewPlotHiddenField.Value.ToString(); plot.FarmId = Convert.ToInt32(FarmIdHiddenField.Value.ToString()); plot.LastModifyBy = userId; int plotId = farmService.CreatePlotForMoveContacts(plot); for (int i = 0; i < arrContactId.Length; i++) { farmService.MoveContactToPlot(Convert.ToInt64(arrContactId[i]), plotId, "", userId); } } else { int plotId = int.Parse(PlotListDropDownList.SelectedValue.ToString()); for (int i = 0; i < arrContactId.Length; i++) { farmService.MoveContactToPlot(Convert.ToInt64(arrContactId[i]), plotId, "", userId); } } ErrorLiteral.Text = "Contacts have been moved successfully."; SaveButton.Visible = false; CancelButton.OnClientClick = "javascript: opener.location.href('ViewFarm.aspx?farmId=" + FarmIdHiddenField.Value.ToString() + "'); window.close();"; CancelButton.Text = "Close"; } catch (Exception exception) { log.Error("UNKNOWN ERROR WHILE MOVING A CONTACT:", exception); if (exception.Message.Contains("Cannot Empty Default Plot")) { ErrorLiteral.Text = "Cannot Empty Default Plot"; } else if (exception.Message.Contains("Plot Name already Exist. Please Provide a different Plot Name")) { ErrorLiteral.Text = "Plot Name already Exist. Please Provide a different Plot Name"; } else { ErrorLiteral.Text = "Unable to Move a Contact"; } } }