protected void ContactListGridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { try { // Get the common web service instance. ServiceAccess serviceLoader = ServiceAccess.GetInstance(); FarmService.FarmService farmService = serviceLoader.GetFarm(); int plotId = 0; int.TryParse(PlotIdHiddenField.Value, out plotId); FarmService.ContactInfo[] contacts = farmService.GetContactListForPlot(plotId); ContactListGridView.DataSource = contacts; ContactListGridView.PageIndex = e.NewPageIndex; ContactListGridView.DataBind(); //Validation related Data stored in Hidden Field if (farmService.IsDefaultPlot(plotId)) { DefaultContactHiddenField.Value = "true"; MoveToButton.Enabled = true; //Move to for single contact in a default plot disabled /*if (contacts.Length < 2) * MoveToButton.Enabled = false; * else * MoveToButton.Enabled = true;*/ } else { DefaultContactHiddenField.Value = "false"; MoveToButton.Enabled = true; } ContactCountHiddenField.Value = contacts.Length.ToString(); } catch (Exception exception) { log.Error("UNKNOWN ERROR:", exception); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (IsPrinterRole) { DeleteContactButton.Enabled = false; EditContactButton.Enabled = false; } Int64 contactId = 0; if ((Request.QueryString["contactId"] != "") && (Request.QueryString["contactId"] != null)) { Int64.TryParse(Request.QueryString["contactId"], out contactId); } if (contactId == 0) { Response.Redirect("~/Members/FarmManagement.aspx"); } if ((Request.QueryString["parentPage"] != "") && (Request.QueryString["parentPage"] != null)) { ParentPageHiddenField.Value = Request.QueryString["parentPage"]; } else { ParentPageHiddenField.Value = ""; } try { //Get the common web service instance. ServiceAccess serviceLoader = ServiceAccess.GetInstance(); FarmService.FarmService farmService = serviceLoader.GetFarm(); //Getting Required Data FarmService.ContactInfo contact = farmService.GetContactDetails(contactId); FarmService.PlotInfo plot = farmService.GetPlotDetail(contact.PlotId); FarmService.FarmInfo farm = farmService.GetFarmDetail(plot.FarmId); int contactCount = farmService.GetContactCountForPlot(contact.PlotId); int userId = farmService.GetUserIdForFarm(plot.FarmId); UserIdHiddenField.Value = userId.ToString(); if (!IsAgentRole) { ForAgentLiteral.Visible = true; RegistrationService.RegistrationService regservice = serviceLoader.GetRegistration(); RegistrationService.RegistrationInfo regInfo = regservice.GetDetails(userId); ForAgentLiteral.Text = "Selected Agent: " + regInfo.UserName + " / " + regInfo.FirstName + " " + regInfo.LastName + " "; ForAgentUserIdHiddenField.Value = userId.ToString(); } else { ForAgentLiteral.Visible = false; } //Header Details FarmNameLabel.Text = farm.FarmName; PlotNameLabel.Text = plot.PlotName; ContactCountLabel.Text = contactCount.ToString(); ContactCountHiddenField.Value = contactCount.ToString(); if (farmService.IsDefaultPlot(plot.PlotId)) { DefaultPlotFlagHiddenField.Value = "true"; } else { DefaultPlotFlagHiddenField.Value = "false"; } CreatedOnLabel.Text = contact.CreateDate.ToShortDateString(); ModifiedOnLable.Text = contact.LastModifyDate.ToShortDateString(); //Hidden Fields FarmIdHiddenField.Value = farm.FarmId.ToString(); PlotIdHiddenField.Value = plot.PlotId.ToString(); ContactIdHiddenField.Value = contact.ContactId.ToString(); //Contact Details ContactIdLabel.Text = contact.ContactId.ToString(); ScheduleNumberLabel.Text = contact.ScheduleNumber.ToString(); OwnerFullNameLabel.Text = contact.OwnerFullName; LotNumberLabel.Text = contact.Lot.ToString(); BlockLabel.Text = contact.Block; SubdivisionLabel.Text = contact.Subdivision; FilingLabel.Text = contact.Filing; SiteAddressLabel.Text = contact.SiteAddress; BedroomsLabel.Text = contact.Bedrooms.ToString(); FullBathLabel.Text = contact.FullBath.ToString(); ThreeQuarterBathLabel.Text = contact.ThreeQuarterBath.ToString(); HalfBathLabel.Text = contact.HalfBath.ToString(); AcresLabel.Text = contact.Acres.ToString(); ActMktComboLabel.Text = contact.ActMktComb; OwnerFirstNameLabel.Text = contact.OwnerFirstName; OwnerLastNameLabel.Text = contact.OwnerLastName; OwnerAddress1Label.Text = contact.OwnerAddress1; OwnerArrdess2Label.Text = contact.OwnerAddress2; OwnerCityLabel.Text = contact.OwnerCity; OwnerStateLabel.Text = contact.OwnerState; OwnerZipLabel.Text = contact.OwnerZip; OwnerCountryLabel.Text = contact.OwnerCountry; SaleDateLabel.Text = contact.SaleDate.ToShortDateString(); TransAmountLabel.Text = contact.TransAmount.ToString(); } catch (Exception exception) { log.Error("UNKNOWN ERROR:", exception); ErrorLiteral.Text = "UNKNOWN ERROR: Contact Administrator"; } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (IsPrinterRole) { MoveToButton.Enabled = false; DeleteContactButton.Enabled = false; DeletePlotButton.Enabled = false; AddContactButton.Enabled = false; EditPlotButton.Enabled = false; } int plotId = 0; if ((Request.QueryString["plotId"] != "") && (Request.QueryString["plotId"] != null)) { int.TryParse(Request.QueryString["plotId"], out plotId); } if (plotId == 0) { Response.Redirect("~/Members/FarmManagement.aspx"); } ExportToExcelButton.CausesValidation = false; ExportToExcelButton.OnClientClick = "javascript: window.open('./ExcelOrCsvFileDownload.aspx?plotId=" + plotId.ToString() + "');"; PlotIdHiddenField.Value = plotId.ToString(); try { // Get the common web service instance. ServiceAccess serviceLoader = ServiceAccess.GetInstance(); FarmService.FarmService farmService = serviceLoader.GetFarm(); int userId = farmService.GetUserIdForPlot(plotId); UserIdHiddenField.Value = userId.ToString(); if (!IsAgentRole) { ForAgentLiteral.Visible = true; RegistrationService.RegistrationService regservice = serviceLoader.GetRegistration(); RegistrationService.RegistrationInfo regInfo = regservice.GetDetails(userId); ForAgentLiteral.Text = "Selected Agent: " + regInfo.UserName + " / " + regInfo.FirstName + " " + regInfo.LastName + " "; ForAgentUserIdHiddenField.Value = userId.ToString(); } else { ForAgentLiteral.Visible = false; } FarmService.PlotInfo plot = farmService.GetPlotDetail(plotId); PlotNameLabel.Text = plot.PlotName; ContactCountLabel.Text = plot.ContactCount.ToString(); CreateDateLabel.Text = plot.CreateDate.ToShortDateString(); FarmIdHiddenField.Value = plot.FarmId.ToString(); ContactListGridView.DataSource = plot.Contacts; ContactListGridView.DataBind(); //Default Plot flag for validation in Javascript if (farmService.IsDefaultPlot(plotId)) { DefaultPlotFlagHiddenField.Value = "true"; } else { DefaultPlotFlagHiddenField.Value = "false"; } //Validation related Data stored in Hidden Field if (farmService.IsDefaultPlot(plot.PlotId)) { DefaultContactHiddenField.Value = "true"; MoveToButton.Enabled = true; //Move to for single contact in a default plot disabled /*if (plot.Contacts.Length < 2) * MoveToButton.Enabled = false; * else * MoveToButton.Enabled = true;*/ } else { DefaultContactHiddenField.Value = "false"; MoveToButton.Enabled = true; } ContactCountHiddenField.Value = plot.Contacts.Length.ToString(); //For Single Contact in Default Plot if (IsPrinterRole) { for (int i = 0; i < plot.Contacts.Length; i++) { ContactListGridView.Rows[i].Cells[0].FindControl("EditContactHyperLink").Visible = false; ContactListGridView.Rows[i].Cells[0].FindControl("ContactIdCheckBox").Visible = false; } } } catch (Exception exception) { log.Error("UNKNOWN ERROR:", exception); } } }
protected void DeleteContactButton_Click(object sender, EventArgs e) { // List of Contacts to be deleted List <Int64> contactIdList = new List <Int64>(); for (int i = 0; i < ContactListGridView.Rows.Count; i++) { GridViewRow row = ContactListGridView.Rows[i]; bool isChecked = ((CheckBox)row.FindControl("ContactIdCheckBox")).Checked; if (isChecked) { Int64 temp = Int64.Parse(((CheckBox)row.FindControl("ContactIdCheckBox")).ToolTip); contactIdList.Add(temp); } } if (contactIdList.Count < 1) // Atleast One Contact to be selected { MessageLiteral.Text = "Select Atleast One Contact to Delete"; } else { // Delete the List of Selected Contacts try { // Get the common web service instance. ServiceAccess serviceLoader = ServiceAccess.GetInstance(); FarmService.FarmService farmService = serviceLoader.GetFarm(); for (int i = 0; i < contactIdList.Count; i++) { farmService.DeleteContact(contactIdList[i], LoginUserId); } MessageLiteral.Text = "Selected Contact List deleted"; int plotId = 0; int.TryParse(PlotIdHiddenField.Value, out plotId); int plotContactCount = farmService.GetContactCountForPlot(plotId); // Check If Plot is Empty if (plotContactCount > 0) { ContactCountLabel.Text = plotContactCount.ToString(); FarmService.ContactInfo[] contacts = farmService.GetContactListForPlot(plotId); ContactListGridView.DataSource = contacts; ContactListGridView.DataBind(); if (farmService.IsDefaultPlot(plotId)) { DefaultContactHiddenField.Value = "true"; } else { DefaultContactHiddenField.Value = "false"; } ContactCountHiddenField.Value = contacts.Length.ToString(); } else // Action for Empty Plot is to remove the Plot { farmService.DeletePlot(plotId, LoginUserId); //Check for Empty Farm if (farmService.GetPlotCountForFarm(Convert.ToInt32(FarmIdHiddenField.Value)) > 0) { Response.Redirect("~/Members/ViewFarm.aspx?farmId=" + FarmIdHiddenField.Value.ToString()); } else // Action for Empty Farm is to remove Farm { farmService.DeleteFarm(Convert.ToInt32(FarmIdHiddenField.Value), LoginUserId); Response.Redirect("~/Members/FarmManagement.aspx"); } } } catch (Exception exception) { log.Error("UNKNOWN ERROR WHILE DELETE CONTACT:", exception); if (exception.Message.Contains("This action will cause Farm to be deleted and the Parent-Farm is Active. Hence Contact Cannot be deleted")) { MessageLiteral.Text = "This action will cause Farm to be deleted and the Parent-Farm is Active. Hence Contact Cannot be deleted"; } else { MessageLiteral.Text = "Error: Unable to Delete Contact"; } } } }
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"; } } }