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; using System.Xml; using System.Net; public partial class ProjectDetails : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { //currTimeStampLabel.Text = "Today is " + Utilities.GetFormattedDateTime(); // TEMPORARY //coeRefNumTextBox.Text = "10000"; //Add client side Javascript to refresh tree control when page is submitted Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "RefreshTree", "top.fraTree.document.location.reload();"); if (!Page.IsPostBack) { // Get Windows ID of user string logonUserName = Utilities.GetLoggedInUserID(User.Identity.Name); //lblHeader.Text = "You are logged in as " + logonUserName; // Check if user is an authorized user of the system MembershipUser user = Membership.GetUser(logonUserName); if (user != null) { if (Roles.IsUserInRole(logonUserName, "AdminFinance") || Roles.IsUserInRole(logonUserName, "ReadOnlyFull") || Roles.IsUserInRole(logonUserName, "WaitingRoleAssignment")) { // Their account exists but not in role "AdminPlanning" or a Board/Portfolio, so redirect to homepage //Response.Redirect("Default.html", true); Server.Transfer("accessdenied.html", true); } else { #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, proposalStatusDropDown, "mspPPStatusGetAll", "PPStatusID", "PPStatus"); // Select the second item, which is "Pre-event Details", since "New" is not used proposalStatusDropDown.SelectedIndex = 2; 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, boardPortfolioDropDown, "mspBoardPortfolio", "BoardPortfolioID", "BoardPortfolioName"); Utilities.populateList(ds, keyPartnerListBox, "mspBoardPortfolio", "BoardPortfolioID", "BoardPortfolioName"); Utilities.populateCombo(ds, PrimaryTargetDropDown, "mspTargetSegmentGetAll", "TargetSegmentID", "TargetSegmentName"); Utilities.populateList(ds, SecondaryTargetListBox, "mspTargetSegmentGetAll", "TargetSegmentID", "TargetSegmentName"); startHourDropDown.Items.Remove("Select One"); startMinuteDropDown.Items.Remove("Select One"); endHourDropDown.Items.Remove("Select One"); endMinuteDropDown.Items.Remove("Select One"); jkNameDropDown.Items.Remove("Select One"); jkNameDropDown.Items.Insert(0, "Venue is not a JK"); #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 today's date. GetFormattedDate() returns today's date in format MMM DD, YYYY //eventDateCalendar.DateMin = Convert.ToDateTime(Utilities.GetFormattedDate()); // 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 #region Set up other controls if (Roles.IsUserInRole(logonUserName, "AdminPlanning")) { sendEmailNotifCheckBox.Enabled = true; // Remove statuses that don't make sense during PP creation RemovePPStatus(); RemovePPStatus("Pre-event Review"); } else //if (Roles.IsUserInRole(logonUserName, "ChairBoardPortfolio")) { // Remove statuses that don't make sense during PP creation RemovePPStatus(); RemovePPStatus("Pre-event Review"); // Remove statuses that this role is not allowed to select RemovePPStatus("New"); RemovePPStatus("Event Implementation"); // Set up board/portfolio of logged on user SetBPDropDown(logonUserName); } // Finish setting proposalStatusDropDown proposalStatusDropDown.Items.Remove("Select One"); // Set "Created By" label CreatedByValueLabel.Text = logonUserName; // Set the focus on the Project Title textbox projectTitleTextBox.Focus(); #endregion } } else { // Their account doesn't exists, so redirect to homepage, which will redirect to "request access" page Response.Redirect("Default.html", true); } } } protected void RemovePPStatus() { for (int x = proposalStatusDropDown.Items.Count - 1; x > 4; x--) { proposalStatusDropDown.Items.RemoveAt(x); } } protected void RemovePPStatus(string PPStatus) { string ppItemStr; for (int x = proposalStatusDropDown.Items.Count - 1; x > 0; x--) { ListItem ppItem = proposalStatusDropDown.Items[x]; ppItemStr = ppItem.ToString(); if (ppItemStr == PPStatus) { proposalStatusDropDown.Items.RemoveAt(x); } } } protected void SetBPDropDown(string logonUserName) { string boardPortfolioName = ""; string[] rolesArray; rolesArray = Roles.GetRolesForUser(logonUserName); if (rolesArray.Length >= 1) { ArrayList boardPortfolioNameArrayList = new ArrayList(); foreach (string str in rolesArray) { if (str != "ChairBoardPortfolio") { boardPortfolioName = ReadWriteManager.GetUserBoardPortfolio(str); //Response.Write("
User in role: " + boardPortfolioName); boardPortfolioNameArrayList.Add(boardPortfolioName); } } bool keepItem; bool matchFound = false; string bpItemStr; for (int x = boardPortfolioDropDown.Items.Count - 1; x > 0; x--) { ListItem bpItem = boardPortfolioDropDown.Items[x]; //Response.Write("
" + bpItem.ToString()); bpItemStr = bpItem.ToString(); keepItem = false; foreach (string bpName in boardPortfolioNameArrayList) { //Response.Write("
" + bpName); if ((bpItemStr == bpName) && (keepItem == false)) //if ((String.Compare(@bpItemStr, @bpName, true) == 0) && (keepItem == false)) { keepItem = true; matchFound = true; } } if (keepItem == false) { //Response.Write("
" + bpItemStr); // Method "Remove" does NOT work for items bounded from DB. Use method "RemoveAt" instead //boardPortfolioDropDown.Items.Remove(bpItemStr); boardPortfolioDropDown.Items.RemoveAt(x); } } //if (matchFound == true) //{ // Response.Write("

Match found."); //} //else //{ // Response.Write("

Match NOT found."); //} // If they belong to only one board, set it for them // Need to check for 2 items b/c first item is "Select One" if (boardPortfolioDropDown.Items.Count == 2) { boardPortfolioDropDown.Items.Remove("Select One"); boardPortfolioDropDown.Items.FindByText(boardPortfolioName.ToString()).Selected = true; } } } protected void createProjectButton_Click(object sender, EventArgs e) { Page.Validate("eventDetails"); bool result; string successFailureMsg; // Get project details from form string coeRefNum = ""; int ppStatusID; result = Int32.TryParse(proposalStatusDropDown.SelectedValue, out ppStatusID); string ppStatus = proposalStatusDropDown.SelectedItem.ToString(); string projectTitle = projectTitleTextBox.Text; string projectDescription = descriptionTextBox.Text; int eventCategoryID; result = Int32.TryParse(categoryDropDown.SelectedValue, out eventCategoryID); DateTime proposedProjectDate; result = DateTime.TryParse(proposedDateTextBox.Text, out proposedProjectDate); DateTime proposedStartTime; result = DateTime.TryParse(startHourDropDown.SelectedItem + ":" + startMinuteDropDown.SelectedItem, out proposedStartTime); DateTime proposedEndTime; result = DateTime.TryParse(endHourDropDown.SelectedItem + ":" + endMinuteDropDown.SelectedItem, out proposedEndTime); int jkID = -1; result = Int32.TryParse(jkNameDropDown.SelectedValue, out jkID); Int16 expectedParticipants; result = Int16.TryParse(expectedParticipantsTextBox.Text, out expectedParticipants); int boardPortfolioID; result = Int32.TryParse(boardPortfolioDropDown.SelectedValue, out boardPortfolioID); string boardPortfolioName = boardPortfolioDropDown.SelectedItem.Text; //key partners string keyPartners = ""; for (int i = 1; i <= keyPartnerListBox.Items.Count - 1; i++ ) { if (keyPartnerListBox.Items[i].Selected == true) { keyPartners += keyPartnerListBox.Items[i].Value + ";"; } } int primaryTargetSegmentID; // = Convert.ToInt32(PrimaryTargetDropDown.SelectedValue); result = Int32.TryParse(PrimaryTargetDropDown.SelectedValue, out primaryTargetSegmentID); //secondary target segments string secondaryTargetSegments = ""; for (int i = 1; i <= SecondaryTargetListBox.Items.Count - 1; i++) { if (SecondaryTargetListBox.Items[i].Selected == true) { secondaryTargetSegments += SecondaryTargetListBox.Items[i].Value + ";"; } } string projectNotes = projectNotesTextBox.Text; string createdBy = CreatedByValueLabel.Text; string modifiedBy = CreatedByValueLabel.Text; //create vars needed for email notification string startDateForEmail = proposedDateTextBox.Text; string startTimeForEmail = startHourDropDown.SelectedItem + ":" + startMinuteDropDown.SelectedItem; string endTimeForEmail = endHourDropDown.SelectedItem + ":" + endMinuteDropDown.SelectedItem; bool sendEmailNotif = sendEmailNotifCheckBox.Checked; //call method that will handle the creation of the new PP successFailureMsg = Project.CreateNewPP(projectTitle, coeRefNum, eventCategoryID, projectDescription, projectNotes, createdBy, modifiedBy, boardPortfolioID, boardPortfolioName, keyPartners, primaryTargetSegmentID, secondaryTargetSegments, expectedParticipants, proposedProjectDate, startDateForEmail, proposedStartTime, startTimeForEmail, proposedProjectDate, proposedEndTime, endTimeForEmail, jkID, ppStatusID, ppStatus, sendEmailNotif); // Display message for user saveResultLabel.Text = saveResultLabel2.Text = successFailureMsg + "
"; // top and bottom of page // Clear all fields ClearForm(); // set the focus in the project title field projectTitleTextBox.Focus(); } protected void clearFormButton_Click(object sender, EventArgs e) { ClearForm(); } protected void ClearForm() { // clear all the fields projectTitleTextBox.Text = ""; descriptionTextBox.Text = ""; categoryDropDown.SelectedIndex = 0; // NOTE: Both steps below required to clear the textbox // clear the date textbox proposedDateTextBox.Text = ""; // blank the selected date in the calendar DateTime proposedProjectDate; bool result = DateTime.TryParse("", out proposedProjectDate); eventDateCalendar.SelectedDate = proposedProjectDate; startHourDropDown.SelectedIndex = 0; startMinuteDropDown.SelectedIndex = 0; endHourDropDown.SelectedIndex = 0; endMinuteDropDown.SelectedIndex = 0; jkNameDropDown.SelectedIndex = 0; expectedParticipantsTextBox.Text = ""; boardPortfolioDropDown.SelectedIndex = 0; keyPartnerListBox.SelectedIndex = 0; PrimaryTargetDropDown.SelectedIndex = 0; SecondaryTargetListBox.SelectedIndex = 0; projectNotesTextBox.Text = ""; CreatedByValueLabel.Text = ""; // set the focus in the project title field projectTitleTextBox.Focus(); } }