using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class ProjectDetails : System.Web.UI.Page
{
//int ppCurrStatusID = 0;
//string ppCurrStatus = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
#region Populate Combos
//ASP.NET 2.0
SqlDataSource ds = new SqlDataSource();
ds.ConnectionString = ConfigurationManager.ConnectionStrings["cnPPDB"].ToString();
ds.DataSourceMode = SqlDataSourceMode.DataSet;
// Populate drop-downs
Utilities.populateCombo(ds, isVenueJKDropDown, "mspYesNoGetAll", "YesNoOptionValue", "YesNoOptionText");
Utilities.populateCombo(ds, mgmtContactedDropDown, "mspYesNoGetAll", "YesNoOptionValue", "YesNoOptionText");
Utilities.populateCombo(ds, partOfOpPlanDropDown, "mspYesNoGetAll", "YesNoOptionValue", "YesNoOptionText");
Utilities.populateCombo(ds, alakhbar, "mspYesNoGetAll", "YesNoOptionValue", "YesNoOptionText");
Utilities.populateCombo(ds, transportation, "mspYesNoGetAll", "YesNoOptionValue", "YesNoOptionText");
Utilities.populateCombo(ds, insurance, "mspYesNoGetAll", "YesNoOptionValue", "YesNoOptionText");
Utilities.populateCombo(ds, ivc, "mspYesNoGetAll", "YesNoOptionValue", "YesNoOptionText");
Utilities.populateCombo(ds, categoryDropDown, "mspEventCategoryGetAll", "EventCategoryID", "EventCategory");
Utilities.populateCombo(ds, startHourDropDown, "mspHourGetAll", "HourID", "HourValue");
Utilities.populateCombo(ds, startMinuteDropDown, "mspMinuteGetAll", "MinuteID", "MinuteValue");
Utilities.populateCombo(ds, endHourDropDown, "mspHourGetAll", "HourID", "HourValue");
Utilities.populateCombo(ds, endMinuteDropDown, "mspMinuteGetAll", "MinuteID", "MinuteValue");
Utilities.populateCombo(ds, jkNameDropDown, "mspJKGetAll", "JKID", "JKName");
Utilities.populateCombo(ds, venueNameDropDown, "mspVenueGetAll", "VenueID", "VenueName");
Utilities.populateCombo(ds, venueTypeDropDown, "mspVenueTypeGetAll", "VenueTypeID", "VenueType");
Utilities.populateCombo(ds, venueCityDropDown, "mspCityGetAll", "CityID", "CityName");
startHourDropDown.Items.Remove("Select One");
startMinuteDropDown.Items.Remove("Select One");
endHourDropDown.Items.Remove("Select One");
endMinuteDropDown.Items.Remove("Select One");
// Need to add entry for "New Venue" to venueNameDropDown
venueNameDropDown.Items.Insert(1, "New Venue");
#endregion
#region Set up calendar control
// Set up special dates
eventDateCalendar.AddSpecialDate(-1, 7, 11, "Immamat Day");
eventDateCalendar.AddSpecialDate(-1, 3, 21, "Navroz");
eventDateCalendar.AddSpecialDate(-1, 12, 13, "Shah Karim's B'day");
//To add dates programatically, do so in a loop
//eventDateCalendar.AddSpecialDate(Convert.ToDateTime(dateVenueRow.ProposedProjectDate.ToString()), projectRow.ProjectTitle);
// Set up calendar behavior
eventDateCalendar.DatePickerMode = true;
//These are set by ReadWriteManager.cs
//eventDateCalendar.AllowDeselect = true;
//eventDateCalendar.OnClientDateChanged = "onDateChange";
//eventDateCalendar.TextBoxId = proposedDateTextBox.ID;
eventDateCalendar.DateFormat = "MMM dd yyyy";
// Set Min date to date specified in Web.config variable "MinCalendarDate"
eventDateCalendar.DateMin = Convert.ToDateTime(ConfigurationManager.AppSettings["MinCalendarDate"]);
// Set Max date to date specified in Web.config variable "MaxCalendarDate"
eventDateCalendar.DateMax = Convert.ToDateTime(ConfigurationManager.AppSettings["MaxCalendarDate"]);
eventDateCalendar.TitleText = "Today is " + DateTime.Now.ToString("dddd MMMM dd, yyyy") + " ";
eventDateCalendar.ShowYearSelector = false;
#endregion
// If ProjectID was passed in then retrieve project details from DB
if (Request.QueryString["ProjectID"] != null)
{
// Get the ProjectID from the QueryString
//int projectID = 6;
int projectID = Convert.ToInt32(Request.QueryString["ProjectID"]);
// Get project details for this project from DB
dsProjectTableAdapters.tblProjectTableAdapter projectTableAdapter = new dsProjectTableAdapters.tblProjectTableAdapter();
dsProject.tblProjectDataTable dtProject = new dsProject.tblProjectDataTable();
dsProject.tblProjectRow projectRow;
dtProject = projectTableAdapter.GetByID(projectID);
// We have a single project, so a single row of data
projectRow = (dsProject.tblProjectRow)dtProject.Rows[0];
//Response.Write("here");
//Response.End();
string coeRefNum = projectRow.COENumber;
string projectTitle = projectRow.ProjectTitle;
string projectTitleForFileName = Utilities.removeIllegalChars(projectTitle);
string boardPortfolioName = projectRow.BoardPortfolioName;
string boardPortfolioSubDirName = Utilities.removeIllegalChars(boardPortfolioName);
string uploadedServicesFileName = string.Format(@"{0}{1}{2}", coeRefNum, "_", projectTitleForFileName + "_ServiceRequest.xls");
string userUploadPath = ConfigurationManager.AppSettings["UserUploadFolderPath"];
string userUploadFolder = ConfigurationManager.AppSettings["UserUploadFolder"];
string createdBy = projectRow.CreatedBy;
string modifiedBy = projectRow.ModifiedBy;
// Set controls
coeRefNumLabel.Text = coeRefNum;
if (!projectRow.IsGLCodeNull())
{
glCodeValueLabel.Text = projectRow.GLCode.ToString();
}
else
{
glCodeValueLabel.Text = "None";
}
// Populate Status dropdown first
// Contents generated in ReadWriteManager.cs
projectTitleTextBox.Text = projectRow.ProjectTitle;
if (!projectRow.IsProjectDescriptionNull())
{
descriptionTextBox.Text = projectRow.ProjectDescription;
}
if (!projectRow.IsEventCategoryIDNull())
{
categoryDropDown.Items.FindByValue(projectRow.EventCategoryID.ToString()).Selected = true;
}
#region Set Board/Portfolio Details
// Get Board/Portfolio details from DB
dsProjectTableAdapters.mspProjectCommitteeGetByProjectIDTableAdapter project_committeeTableAdapter = new dsProjectTableAdapters.mspProjectCommitteeGetByProjectIDTableAdapter();
dsProject.mspProjectCommitteeGetByProjectIDDataTable dtProjectCommittee = new dsProject.mspProjectCommitteeGetByProjectIDDataTable();
dtProjectCommittee = project_committeeTableAdapter.GetByProjectID(projectID);
DataTableReader dtReader = new DataTableReader(dtProjectCommittee);
// Loop through datatable to set the Board/Portfolio controls
string keyPartners = "";
while (dtReader.Read())
{
// If IsPrimaryOrganizerYN = 1, set controls for primary organizer
if (dtReader["IsPrimaryOrganizerYN"].ToString() == 1.ToString())
{
boardPortfolioValueLabel.Text = dtReader["BoardPortfolioName"].ToString();
boardPortfolioIDHidden.Value = dtReader["BoardPortfolioID"].ToString();
committeeTextBox.Text = dtReader["CommitteeName"].ToString();
}
else
{
if(keyPartners.Length > 0)
{
keyPartners += ", ";
}
keyPartners += dtReader["BoardPortfolioName"].ToString();
}
}
// Set the Key Partners value label
if (keyPartners.Length == 0)
{
keyPartners = "None";
}
keyPartnerValueLabel.Text = keyPartners;
#endregion
if (!projectRow.IsPartOfOperationalPlanYNNull())
{
partOfOpPlanDropDown.Items.FindByValue(projectRow.PartOfOperationalPlanYN.ToString()).Selected = true;
}
// If dataset returns DBNull then modify dsProject.xsd
// See ProjectNotes as an example
// Article at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingannotationswithtypeddataset.asp
projectNotesTextBox.Text = projectRow.ProjectNotes;
#region Set Date/Venue Details
//Get date/venue details from DB for this project
dsProjectTableAdapters.mspDateVenueGetByProjectIDTableAdapter dateVenueAdapter = new dsProjectTableAdapters.mspDateVenueGetByProjectIDTableAdapter();
dsProject.mspDateVenueGetByProjectIDDataTable dtDateVenue = new dsProject.mspDateVenueGetByProjectIDDataTable();
dsProject.mspDateVenueGetByProjectIDRow dateVenueRow;
dtDateVenue = dateVenueAdapter.GetByProjectID(projectID);
if (dtDateVenue.Rows.Count > 0)
{
// Set date/venue controls since there's at least one date/venue row
// This would be the place to add event date controls dynamically
// to the form for each date that makes up this event.
// The height of the DIV for the date controls would have to be
// adjusted accordingly
dateVenueRow = (dsProject.mspDateVenueGetByProjectIDRow)dtDateVenue.Rows[0];
if (!dateVenueRow.IsProjectDateIDNull())
{
projectDateIDHidden.Value = dateVenueRow.ProjectDateID.ToString();
}
if (!dateVenueRow.IsProposedProjectDateNull())
{
proposedDateTextBox.Text = dateVenueRow.ProposedProjectDate.ToString();
proposedDateHidden.Value = dateVenueRow.ProposedProjectDate.ToString();
}
//Attempt to pre-set event date when calendar is opened isn't working
//eventDateCalendar.SelectedDate = (DateTime)dateVenueRow.ProposedProjectDate;
// PadLeft method specifies to add a leading zero if
// the numeric time string is less than 4 characters (eg. 900 -> 0900)
if (!dateVenueRow.IsProposedStartTimeNull())
{
startHourDropDown.Items.FindByText(dateVenueRow.ProposedStartTime.ToString().PadLeft(4, '0').Substring(0, 2)).Selected = true;
startMinuteDropDown.Items.FindByText(dateVenueRow.ProposedStartTime.ToString().PadLeft(4, '0').Substring(2, 2)).Selected = true;
}
if (!dateVenueRow.IsProposedEndTimeNull())
{
endHourDropDown.Items.FindByText(dateVenueRow.ProposedEndTime.ToString().PadLeft(4, '0').Substring(0, 2)).Selected = true;
endMinuteDropDown.Items.FindByText(dateVenueRow.ProposedEndTime.ToString().PadLeft(4, '0').Substring(2, 2)).Selected = true;
}
if (dateVenueRow.IsJKIDNull())
{
isVenueJKDropDown.Items.FindByText("No").Selected = true;
}
else
{
isVenueJKDropDown.Items.FindByText("Yes").Selected = true;
jkNameDropDown.Items.FindByValue(dateVenueRow.JKID.ToString()).Selected = true;
if (!dateVenueRow.IsMgmtCommContactedYNNull())
{
mgmtContactedDropDown.Items.FindByValue(dateVenueRow.MgmtCommContactedYN.ToString()).Selected = true;
}
}
if (!dateVenueRow.IsJKIDNull())
{
isVenueJKDropDown.Items.FindByText("Yes").Selected = true;
}
else
{
venueNameDropDown.Visible = true;
if (!dateVenueRow.IsVenueIDNull())
{
venueNameDropDown.Items.FindByValue(dateVenueRow.VenueID.ToString()).Selected = true;
}
if (!dateVenueRow.IsVenueTypeIDNull())
{
venueTypeDropDown.Items.FindByValue(dateVenueRow.VenueTypeID.ToString()).Selected = true;
}
if (!dateVenueRow.IsVenueAddressNull())
{
addressTextBox.Text = dateVenueRow.VenueAddress.ToString();
}
if (!dateVenueRow.IsCityIDNull())
{
venueCityDropDown.Items.FindByValue(dateVenueRow.CityID.ToString()).Selected = true;
}
if (!dateVenueRow.IsProvinceAbbrevNull())
{
provinceStringLabel.Text = dateVenueRow.ProvinceAbbrev.ToString();
}
if (!dateVenueRow.IsVenuePostalCodeNull())
{
postalCodeTextBox.Text = dateVenueRow.VenuePostalCode.ToString();
}
if (!dateVenueRow.IsVenueCapacityNull())
{
capacityTextBox.Text = dateVenueRow.VenueCapacity.ToString();
}
}
// Set visibility and enale/disable JK and Venue controls
isVenueJKDropDown_SelectedIndexChanged(isVenueJKDropDown, e);
venueNameDropDown_SelectedIndexChanged(venueNameDropDown, e);
}
#endregion
#region Set Project Service Details
// Get project service details from DB
dsProjectTableAdapters.tblProject_ServiceTableAdapter project_serviceTableAdapter = new dsProjectTableAdapters.tblProject_ServiceTableAdapter();
dsProject.tblProject_ServiceDataTable dtProjectServices = new dsProject.tblProject_ServiceDataTable();
dtProjectServices = project_serviceTableAdapter.GetByProjectID(projectID);
//DataTableReader dtReader = new DataTableReader(dtProjectServices);
dtReader = new DataTableReader(dtProjectServices);
// Loop through datatable to set the dropdowns
while (dtReader.Read())
{
// Get a handle on the dropdown
//DropDownList dropdown = (DropDownList) FindControl("ctl00$middleContent$" + dtReader["ServiceStringID"].ToString());
DropDownList dropdown = (DropDownList)FindControl(dtReader["ServiceStringID"].ToString());
// Set the yes/no value
dropdown.Items.FindByValue(dtReader["YesNoOptionValue"].ToString()).Selected = true;
}
if (FileHandler.CheckUploadedFileExists(userUploadPath, boardPortfolioSubDirName, uploadedServicesFileName))
{
ppServicesSpreadsheetHyperLink.NavigateUrl = userUploadFolder + "/" + boardPortfolioSubDirName + "/" + uploadedServicesFileName;
ppServicesSpreadsheetHyperLink.Text = "Uploaded File";
}
#endregion
// Enable/Disable controls based on role and status
ReadWriteManager.SetProjectDetailsPermissions(projectRow.PPStatusID, projectRow.PPStatus, form1, ds);
// Finish setting proposalStatusDropDown
proposalStatusDropDown.Items.Remove("Select One");
// Now select the current status of the project
proposalStatusDropDown.Items.FindByValue(projectRow.PPStatusID.ToString()).Selected = true;
#region Set CreatedBy and ModifiedBy
CreatedByLabel.Text = createdBy;
ModifiedByLabel.Text = modifiedBy;
#endregion
// store the current status in a hidden form element
ppCurrStatusIDHidden.Value = proposalStatusDropDown.SelectedValue;
}
else
{
// Project ID was not retrieved from Query String
}
// clean up
}
// Validate intially to force *s to appear before the first round-trip
Page.Validate();
}
protected void updateStatusButton_Click(object sender, EventArgs e)
{
if (Request.QueryString["ProjectID"] != null)
{
bool result;
string updateStatusResult;
// Get the new status
int ppNewStatusID = Convert.ToInt32(proposalStatusDropDown.SelectedValue);
string ppNewStatus = proposalStatusDropDown.SelectedItem.ToString();
if (ppNewStatusID != Convert.ToInt32(ppCurrStatusIDHidden.Value))
{
string coeRefNum = coeRefNumLabel.Text;
// Store the new status in the hidden form element
ppCurrStatusIDHidden.Value = ppNewStatusID.ToString();
string projectTitle = projectTitleTextBox.Text;
string boardPortfolioName = boardPortfolioValueLabel.Text;
int boardPortfolioID;
result = Int32.TryParse(boardPortfolioIDHidden.Value, out boardPortfolioID);
string committeeName = committeeTextBox.Text;
string proposedProjectDate = proposedDateTextBox.Text;
string proposedStartTime = startHourDropDown.SelectedItem + ":" + startMinuteDropDown.SelectedItem;
string proposedEndTime = endHourDropDown.SelectedItem + ":" + endMinuteDropDown.SelectedItem;
// Get the current logged user
string modifiedBy = User.Identity.Name;
//string modifiedBy = Request.ServerVariables["LOGON_USER"];
string userName = Utilities.GetLoggedInUserID(modifiedBy);
int projectID = Convert.ToInt32(Request.QueryString["ProjectID"]);
// TO DO
// If the Chair is attempting to set the status to Post-event Eval Review,
// check that HR values have been provided before allowing status change
// Get table adapter for Project table
dsProjectTableAdapters.tblProjectTableAdapter projectTableAdapter = new dsProjectTableAdapters.tblProjectTableAdapter();
// Call the method to update the database
projectTableAdapter.UpdatePPStatusByID(ppNewStatusID, modifiedBy, projectID);
//send email notification
string sendResult;
sendResult = PPSNotification.SendStatusUpdateEmail(coeRefNum, projectTitle, proposedProjectDate,
proposedStartTime, proposedEndTime, boardPortfolioName, boardPortfolioID,
committeeName, ppNewStatus, userName);
// Display message for user
updateStatusResult = "Project status has been set to '" + ppNewStatus + "'. " + sendResult;
saveResultLabel.Text = saveResultLabel2.Text = updateStatusResult; // top and bottom of page
}
else
{
// Display message for user
updateStatusResult = "WARNING! Project status is already set to '" + ppNewStatus + "'. Please change status first.";
saveResultLabel.Text = saveResultLabel2.Text = updateStatusResult; // top and bottom of page
}
}
}
protected void updateEventDateButton_Click(object sender, EventArgs e)
{
bool result;
string changeDateResult;
DateTime proposedProjectDate;
string modifiedBy = Request.ServerVariables["LOGON_USER"];
int projectID = Convert.ToInt32(Request.QueryString["ProjectID"]);
if (Request.QueryString["ProjectID"] != null)
{
// Update Project Date
int projectDateID;
result = Int32.TryParse(projectDateIDHidden.Value, out projectDateID);
//result = DateTime.TryParse(proposedDateHidden.Value, out proposedProjectDate);
result = DateTime.TryParse(proposedDateTextBox.Text, out proposedProjectDate);
if (result == false)
{
//Error, so cannot save changes. Most likely NULL date passed in
// Display message for user
changeDateResult = "There was an error changing the date. Make sure a date has been selected.";
saveResultLabel.Text = saveResultLabel2.Text = changeDateResult; // top and bottom of page
}
else
{
// Get table adapter for Project date & venue (adapter based on stored proc)
dsProjectTableAdapters.mspDateVenueGetByProjectIDTableAdapter date_venueAdapter = new dsProjectTableAdapters.mspDateVenueGetByProjectIDTableAdapter();
// Call the method to update the database
date_venueAdapter.UpdateEventDateByID(
projectDateID, projectID, proposedProjectDate, modifiedBy);
changeDateResult = "Event date was succesfully changed to " + proposedProjectDate.ToLongDateString();
saveResultLabel.Text = saveResultLabel2.Text = changeDateResult; // top and bottom of page
}
}
}
protected void saveProjectButton_Click(object sender, EventArgs e)
{
Page.Validate("eventDetails");
if (Request.QueryString["ProjectID"] != null)
{
// Create variable to hold return value from SP
int spReturnVal;
bool result;
string modifiedBy = Request.ServerVariables["LOGON_USER"];
int projectID = Convert.ToInt32(Request.QueryString["ProjectID"]);
// Get project details
string projectTitle = projectTitleTextBox.Text;
string projectTitleForFileName = Utilities.removeIllegalChars(projectTitle);
string boardPortfolioName = boardPortfolioValueLabel.Text;
string boardPortfolioSubDirName = Utilities.removeIllegalChars(boardPortfolioName);
int eventCategoryID;
result = Int32.TryParse(categoryDropDown.SelectedValue, out eventCategoryID);
string projectDescription = descriptionTextBox.Text;
int partOfOpPlan = Convert.ToInt32(partOfOpPlanDropDown.SelectedValue);
string projectNotes = projectNotesTextBox.Text;
// BoardPortfolioID needed to insert/update committee name
int boardPortfolioID;
result = Int32.TryParse(boardPortfolioIDHidden.Value, out boardPortfolioID);
string committeeName = committeeTextBox.Text;
string uploadResult = "";
string userUploadFolderPath = ConfigurationManager.AppSettings["UserUploadFolderPath"];
string rootUploadFolder = ConfigurationManager.AppSettings["UserUploadFolder"];
string userServicesFileName = servicesFileUpload.PostedFile.FileName;
string createdServicesFileName = "";
string allowedServicesFileExtensions = ".xls";
userServicesFileName = userServicesFileName.Substring(userServicesFileName.LastIndexOfAny(new char[] { Char.Parse(@"\"), Char.Parse(@"/") }) + 1);
// Upload the Services spreadsheet if it was specified
uploadResult = FileHandler.UploadFile(servicesFileUpload, false,
boardPortfolioSubDirName, coeRefNumLabel.Text, projectTitleForFileName + "_ServiceRequest",
userUploadFolderPath, rootUploadFolder, allowedServicesFileExtensions);
// If file was uploaded, display message & URL for uploaded file
if (uploadResult.IndexOf(@rootUploadFolder) == 0)
{
ppServicesSpreadsheetHyperLink.NavigateUrl = uploadResult;
ppServicesSpreadsheetHyperLink.Text = "New Uploaded File";
createdServicesFileName = uploadResult.Substring(uploadResult.LastIndexOfAny(new char[] { Char.Parse(@"\"), Char.Parse(@"/") }) + 1);
uploadResult = "File '" + userServicesFileName + "' uploaded as '" + createdServicesFileName + "'.";
}
else
{
// Suppress messages if user indicated that no services are required
if (alakhbar.SelectedItem.ToString().ToUpper() == "NO"
&& transportation.SelectedItem.ToString().ToUpper() == "NO"
&& insurance.SelectedItem.ToString().ToUpper() == "NO"
&& ivc.SelectedItem.ToString().ToUpper() == "NO")
{
uploadResult = "";
}
else if (uploadResult == "File for upload not specified")
{
uploadResult = "Services are required but request form was not uploaded.";
}
}
// Display upload result message for user
saveResultLabel.Text = saveResultLabel2.Text =uploadResult; // top and bottom of page
// Get table adapter for Project table
dsProjectTableAdapters.tblProjectTableAdapter projectTableAdapter = new dsProjectTableAdapters.tblProjectTableAdapter();
// Call the method to update project table in the database
//spReturnVal = (int)projectTableAdapter.UpdateByID(...not working
projectTableAdapter.UpdateByID(projectTitle, eventCategoryID,
projectDescription, partOfOpPlan, projectNotes, modifiedBy, projectID,
boardPortfolioID, committeeName);
// Retrieve return value
// hard-coded because was not able to retrieve it from the method call
spReturnVal = 0;
if (spReturnVal != 0)
{
// Error condition
}
// Update Project Date & Venue details
int projectDateID;
result = Int32.TryParse(projectDateIDHidden.Value, out projectDateID);
DateTime proposedProjectDate;
result = DateTime.TryParse(proposedDateTextBox.Text, out proposedProjectDate);
if (result == false)
{
proposedProjectDate = Convert.ToDateTime("01/01/2006");
}
DateTime proposedStartTime; //= Convert.ToDateTime(startHourDropDown.SelectedItem + ":" + startMinuteDropDown.SelectedItem);
result = DateTime.TryParse(startHourDropDown.SelectedItem + ":" + startMinuteDropDown.SelectedItem, out proposedStartTime);
DateTime proposedEndTime; //= Convert.ToDateTime(endHourDropDown.SelectedItem + ":" + endMinuteDropDown.SelectedItem);
result = DateTime.TryParse(endHourDropDown.SelectedItem + ":" + endMinuteDropDown.SelectedItem, out proposedEndTime);
int jkID = -1;
Int16 mgmtCommContactedYN = 0;
int venueID = -1;
string newVenueName = null;
int venueTypeID = 0;
string venueAddress = null;
int venueCityID = 0;
string venuePostalCode = null;
string venueCapacity = null;
// If the venue is not a JK
if (isVenueJKDropDown.SelectedItem.ToString().ToUpper() == "NO")
{
// If it's a new venue, get the details
if (venueNameDropDown.SelectedItem.ToString().ToUpper() == "NEW VENUE")
{
newVenueName = newVenueNameTextBox.Text;
venueTypeID = Convert.ToInt32(venueTypeDropDown.SelectedValue);
venueAddress = addressTextBox.Text;
venueCityID = Convert.ToInt32(venueCityDropDown.SelectedValue);
venuePostalCode = postalCodeTextBox.Text;
venueCapacity = capacityTextBox.Text;
}
else
{
// VenueID needs to be added or updated for project date
venueID = Convert.ToInt32(venueNameDropDown.SelectedValue);
}
}
else
{
// If the venue IS a JK
if (isVenueJKDropDown.SelectedItem.ToString().ToUpper() == "YES")
{
jkID = Convert.ToInt32(jkNameDropDown.SelectedValue);
mgmtCommContactedYN = Convert.ToInt16(mgmtContactedDropDown.SelectedValue);
}
}
// Get table adapter for Project date & venue (adapter based on stored proc)
dsProjectTableAdapters.mspDateVenueGetByProjectIDTableAdapter date_venueAdapter = new dsProjectTableAdapters.mspDateVenueGetByProjectIDTableAdapter();
// Call the method to update the database
date_venueAdapter.UpdateByProjectID(
projectDateID, projectID, proposedProjectDate, proposedStartTime,
proposedEndTime, jkID, mgmtCommContactedYN, modifiedBy, newVenueName,
venueTypeID, venueAddress, venueCityID, venuePostalCode, venueCapacity, venueID);
// Update project service details
short alakhbarRequired;
result = Int16.TryParse(alakhbar.SelectedValue, out alakhbarRequired);
short transportationRequired;
result = Int16.TryParse(transportation.SelectedValue, out transportationRequired);
short insuranceRequired;
result = Int16.TryParse(insurance.SelectedValue, out insuranceRequired);
short ivcRequired;
result = Int16.TryParse(ivc.SelectedValue, out ivcRequired);
// Get table adapter for Project_Service table
dsProjectTableAdapters.tblProject_ServiceTableAdapter project_serviceTableAdapter = new dsProjectTableAdapters.tblProject_ServiceTableAdapter();
// Call the method to update the database
project_serviceTableAdapter.UpdateByProjectID(projectID, "alakhbar", alakhbarRequired, modifiedBy, modifiedBy);
project_serviceTableAdapter.UpdateByProjectID(projectID, "transportation", transportationRequired, modifiedBy, modifiedBy);
project_serviceTableAdapter.UpdateByProjectID(projectID, "insurance", insuranceRequired, modifiedBy, modifiedBy);
project_serviceTableAdapter.UpdateByProjectID(projectID, "ivc", ivcRequired, modifiedBy, modifiedBy);
// Retrieve return value
spReturnVal = 0;
if (spReturnVal != 0)
{
// Error condition
}
// Code for Target Segments
int newPrimaryTargetID;
Int32.TryParse(Request.Form["IsPrimaryTargetRadioButton"], out newPrimaryTargetID);
int rowNo = 0;
GridView targetGrid = (GridView)FindControl("TargetSegmentGridView");
SqlDataSource SqlDataSource1 = (SqlDataSource)FindControl("SqlDataSource1");
foreach (GridViewRow row in targetGrid.Rows)
{
string newAdditional = Request.Form["IsAdditionalCheckBox" + (rowNo + 1)];
int projectTargetSegmentID = (int)targetGrid.DataKeys[rowNo].Value;
int targetSegmentID = (int)targetGrid.DataKeys[rowNo].Values[1];
bool IsOrigPrimaryTarget = (bool)targetGrid.DataKeys[rowNo].Values[2];
//Response.Write("projectTargetSegmentID: " + projectTargetSegmentID + "
");
//Response.Write("TargetSegmentID: " + targetSegmentID + "
");
//Response.Write("NewPrimaryTargetID: " + newPrimaryTargetID + "
");
//Response.Write("New TargetSegmentID: " + newAdditional + "
");
//Response.Write("IsOrigPrimaryTarget: " + IsOrigPrimaryTarget + "
");
if (projectTargetSegmentID == 0)
{
if (newPrimaryTargetID == targetSegmentID)
{
// Create new row & set as primary
//Response.Write("Create new row & set as primary
");
SqlDataSource1.UpdateParameters.Clear();
// Setting update params
SqlDataSource1.UpdateParameters.Add("ProjectID", projectID.ToString());
SqlDataSource1.UpdateParameters.Add("TargetSegmentID", targetSegmentID.ToString());
SqlDataSource1.UpdateParameters.Add("IsPrimaryTargetYN", 1.ToString());
SqlDataSource1.UpdateParameters.Add("ModifiedBy", modifiedBy);
SqlDataSource1.Update();
}
else if (Convert.ToInt32(newAdditional) == targetSegmentID)
{
// Create new row, but don't set as primary
//Response.Write("Create new row but don't set as primary
");
SqlDataSource1.UpdateParameters.Clear();
SqlDataSource1.UpdateParameters.Add("ProjectID", projectID.ToString());
SqlDataSource1.UpdateParameters.Add("TargetSegmentID", targetSegmentID.ToString());
SqlDataSource1.UpdateParameters.Add("IsPrimaryTargetYN", 0.ToString());
SqlDataSource1.UpdateParameters.Add("ModifiedBy", modifiedBy);
SqlDataSource1.Update();
}
else
{
// Do nothing
//Response.Write("Do nothing 1
");
}
}
else
{
// Update or Delete
if (newPrimaryTargetID != targetSegmentID)
{
if (Convert.ToInt32(newAdditional) != targetSegmentID)
{
// Delete the existing row
//Response.Write("Delete the existing row
");
SqlDataSource1.DeleteParameters.Clear();
SqlDataSource1.DeleteParameters.Add("Project_TargetSegmentID", projectTargetSegmentID.ToString());
SqlDataSource1.Delete();
}
else if (IsOrigPrimaryTarget)
{
// Set Primary target to 0 or NULL & update row
//Response.Write("Set Primary target to 0 or NULL & update row
");
SqlDataSource1.UpdateParameters.Clear();
SqlDataSource1.UpdateParameters.Add("Project_TargetSegmentID", projectTargetSegmentID.ToString());
SqlDataSource1.UpdateParameters.Add("ProjectID", projectID.ToString());
SqlDataSource1.UpdateParameters.Add("TargetSegmentID", targetSegmentID.ToString());
SqlDataSource1.UpdateParameters.Add("IsPrimaryTargetYN", 0.ToString());
SqlDataSource1.UpdateParameters.Add("ModifiedBy", modifiedBy);
SqlDataSource1.Update();
}
else
{
// Do nothing
//Response.Write("Do nothing 2
");
}
}
else if (!IsOrigPrimaryTarget)
{
// Set Primary target to 1 & update row
//Response.Write("Set Primary target to 1 & update row
");
SqlDataSource1.UpdateParameters.Clear();
SqlDataSource1.UpdateParameters.Add("Project_TargetSegmentID", projectTargetSegmentID.ToString());
SqlDataSource1.UpdateParameters.Add("ProjectID", projectID.ToString());
SqlDataSource1.UpdateParameters.Add("TargetSegmentID", targetSegmentID.ToString());
SqlDataSource1.UpdateParameters.Add("IsPrimaryTargetYN", 1.ToString());
SqlDataSource1.UpdateParameters.Add("ModifiedBy", modifiedBy);
SqlDataSource1.Update();
}
else
{
// Do nothing
//Response.Write("Do nothing 3
");
}
}
// increment the row count
rowNo++;
}
targetGrid.DataBind();
//Code for Target segments Above
}
else
{
// The ID was not received so handle problem
}
}
protected void isVenueJKDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
if (isVenueJKDropDown.SelectedItem.ToString().ToUpper() == "NO")
{
//venueDetails.Style["top"] = jkNameLabel.Style["top"];
jkNameLabel.Visible = false;
jkNameValidator.Visible = false;
jkNameDropDown.Visible = false;
jkNameDropDown.Enabled = false;
mgmtContactedLabel.Visible = false;
mgmtContactedValidator.Visible = false;
mgmtContactedDropDown.Visible = false;
mgmtContactedDropDown.Enabled = false;
// Show the venue section
venueDetails.Visible = true;
//venueDetails.Style["visibility"] = "show";
venueNameLabel.Visible = true;
venueNameDropDown.Visible = true;
venueNameDropDown.Attributes.Add("onMouseOver","checkEvent(this.event)");
venueNameDropDown.Attributes.Add("onMouseOut", "checkEvent(this.event)");
//venueNameDropDown.Attributes.Add("onMouseMove", "checkEvent(this.event)");
}
else
{
jkNameLabel.Visible = true;
jkNameValidator.Visible = true;
jkNameDropDown.Visible = true;
jkNameDropDown.Enabled = true;
jkNameDropDown.Attributes.Add("onMouseOver", "checkEvent(this.event)");
jkNameDropDown.Attributes.Add("onMouseOut", "checkEvent(this.event)");
//jkNameDropDown.Attributes.Add("onMouseMove", "checkEvent(this.event)");
mgmtContactedLabel.Visible = true;
mgmtContactedValidator.Visible = true;
mgmtContactedDropDown.Visible = true;
mgmtContactedDropDown.Enabled = true;
// Hide the venue section
venueDetails.Visible = false;
//venueDetails.Style["visibility"] = "hidden";
}
}
protected void venueNameDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
if (venueNameDropDown.SelectedItem.ToString().ToUpper() == "NEW VENUE")
{
// Show/Enable & clear controls if not already visible
if (!newVenueNameLabel.Visible)
{
newVenueNameLabel.Visible = true;
newVenueNameValidator.Visible = true;
newVenueNameTextBox.Visible = true;
venueTypeLabel.Visible = true;
addressLabel.Visible = true;
cityLabel.Visible = true;
provinceLabel.Visible = true;
provinceStringLabel.Visible = true;
postalCodeLabel.Visible = true;
capacityLabel.Visible = true;
venueTypeValidator.Visible = true;
addressValidator.Visible = true;
venueCityValidator.Visible = true;
postalCodeValidator.Visible = true;
capacityValidator.Visible = true;
venueTypeDropDown.Visible = true;
addressTextBox.Visible = true;
venueCityDropDown.Visible = true;
postalCodeTextBox.Visible = true;
capacityTextBox.Visible = true;
venueTypeDropDown.Enabled = true;
addressTextBox.Enabled = true;
venueCityDropDown.Enabled = true;
postalCodeTextBox.Enabled = true;
capacityTextBox.Enabled = true;
// Blank out the controls
venueTypeDropDown.ClearSelection();
addressTextBox.Text = "";
venueCityDropDown.ClearSelection();
postalCodeTextBox.Text = "";
capacityTextBox.Text = "";
}
}
else if (venueNameDropDown.SelectedItem.ToString().ToUpper() == "SELECT ONE")
{
// Hide/Disable the controls
newVenueNameLabel.Visible = false;
newVenueNameValidator.Visible = false;
newVenueNameTextBox.Visible = false;
// Blank out the controls
venueTypeDropDown.ClearSelection();
addressTextBox.Text = "";
venueCityDropDown.ClearSelection();
postalCodeTextBox.Text = "";
capacityTextBox.Text = "";
venueTypeLabel.Visible = false;
addressLabel.Visible = false;
cityLabel.Visible = false;
provinceLabel.Visible = false;
provinceStringLabel.Visible = false;
postalCodeLabel.Visible = false;
capacityLabel.Visible = false;
venueTypeValidator.Visible = false;
addressValidator.Visible = false;
venueCityValidator.Visible = false;
postalCodeValidator.Visible = false;
capacityValidator.Visible = false;
venueTypeDropDown.Visible = false;
addressTextBox.Visible = false;
venueCityDropDown.Visible = false;
postalCodeTextBox.Visible = false;
capacityTextBox.Visible = false;
}
else
{
//Get venue details from DB for this venueID
dsProjectTableAdapters.tluVenueTableAdapter venueAdapter = new dsProjectTableAdapters.tluVenueTableAdapter();
dsProject.tluVenueDataTable dtVenue = new dsProject.tluVenueDataTable();
dsProject.tluVenueRow venueRow;
dtVenue = venueAdapter.GetByID(Convert.ToInt32(venueNameDropDown.SelectedValue));
if (dtVenue.Rows.Count > 0)
{
venueTypeLabel.Visible = true;
addressLabel.Visible = true;
cityLabel.Visible = true;
provinceLabel.Visible = true;
provinceStringLabel.Visible = true;
postalCodeLabel.Visible = true;
capacityLabel.Visible = true;
venueTypeValidator.Visible = true;
addressValidator.Visible = true;
venueCityValidator.Visible = true;
postalCodeValidator.Visible = true;
capacityValidator.Visible = true;
venueTypeDropDown.Visible = true;
addressTextBox.Visible = true;
venueCityDropDown.Visible = true;
postalCodeTextBox.Visible = true;
capacityTextBox.Visible = true;
// Blank out the controls
venueTypeDropDown.ClearSelection();
newVenueNameTextBox.Text = "";
addressTextBox.Text = "";
venueCityDropDown.ClearSelection();
postalCodeTextBox.Text = "";
capacityTextBox.Text = "";
venueRow = (dsProject.tluVenueRow)dtVenue.Rows[0];
venueTypeDropDown.Items.FindByValue(venueRow.VenueTypeID.ToString()).Selected = true;
if (!venueRow.IsVenueAddressNull())
{
addressTextBox.Text = venueRow.VenueAddress.ToString();
}
venueCityDropDown.Items.FindByValue(venueRow.CityID.ToString()).Selected = true;
//if (!venueRow.IsProvinceAbbrevNull())
//{
// provinceStringLabel.Text = venueRow.ProvinceAbbrev.ToString();
//}
if (!venueRow.IsVenuePostalCodeNull())
{
postalCodeTextBox.Text = venueRow.VenuePostalCode.ToString();
}
if (!venueRow.IsVenueCapacityNull())
{
capacityTextBox.Text = venueRow.VenueCapacity.ToString();
}
}
// Hide/Disable the controls
newVenueNameLabel.Visible = false;
newVenueNameValidator.Visible = false;
newVenueNameTextBox.Visible = false;
venueTypeDropDown.Enabled = false;
addressTextBox.Enabled = false;
venueCityDropDown.Enabled = false;
postalCodeTextBox.Enabled = false;
capacityTextBox.Enabled = false;
}
}
}