private DataTable GetEventData(DateTime startDate, DateTime endDate, string strOwner) { var masterDal = new MasterDAL(); List <EEvent> eventForCalendar = masterDal.GetEventForCalendar(SalesRepId, startDate.ToShortDateString(), endDate.ToShortDateString(), 0, HostName, FranchiseeId, PodIds, TerritoryIds); if (!string.IsNullOrEmpty(TerritoryIds)) { var territoryIds = new List <long>(); TerritoryIds.Split(',').ToList().ForEach(territoryId => territoryIds.Add(Convert.ToInt64(territoryId))); ITerritoryRepository territoryRepository = new TerritoryRepository(); List <Territory> territories = territoryRepository.GetTerritories(territoryIds); List <string> territoryZipCodes = territories.SelectMany(territory => territory.ZipCodes.Select(zipCode => zipCode.Zip)).ToList(); eventForCalendar = eventForCalendar.Where(eventData => territoryZipCodes.Contains(eventData.Host.Address.Zip)).ToList(); } if (eventForCalendar != null) { for (int count = 0; count < eventForCalendar.Count; count++) { string strEventDescription = ""; string eventData = "\"" + eventForCalendar[count].Name.Replace("'", "").Replace("\n", "") + " \""; string eventStatus = "\"" + Convert.ToString(Enum.Parse(typeof(EventStatus), eventForCalendar[count].EventStatus.ToString())).Replace("\n", "").Replace("'", "") + " \""; string currentEventDate = "\"" + Convert.ToDateTime(eventForCalendar[count].EventDate).ToLongDateString() + " \""; string eventStartTime = "\"" + Convert.ToDateTime(eventForCalendar[count].EventStartTime).ToShortTimeString() + " \""; string eventEndTime = "\"" + Convert.ToDateTime(eventForCalendar[count].EventEndTime).ToShortTimeString() + " \""; string timeZone = "\"" + eventForCalendar[count].TimeZone + " \""; string address1 = "\"" + eventForCalendar[count].Host.Address.Address1.Replace("\n", "").Replace("'", "") + " \""; string address2 = "\"" + eventForCalendar[count].Host.Address.Address2.Replace("\n", "").Replace("'", "") + " \""; string city = "\"" + eventForCalendar[count].Host.Address.City + " \""; string state = "\"" + eventForCalendar[count].Host.Address.State + " \""; string country = "\"" + eventForCalendar[count].Host.Address.Country + " \""; string zip = "\"" + eventForCalendar[count].Host.Address.Zip + " \""; string franchisee = "\"" + eventForCalendar[count].Franchisee.Name.Replace("\n", "").Replace("'", "") + " \""; string salesRep = "\"" + eventForCalendar[count].FranchiseeFranchiseeUser.FranchiseeUser.User.FirstName + " " + eventForCalendar[count].FranchiseeFranchiseeUser.FranchiseeUser.User.LastName + " \""; string controlID = "\"Event" + eventForCalendar[count].EventID + strOwner + "\""; string customerCount; TimeSpan dateDifference = Convert.ToDateTime(eventForCalendar[count].EventDate).Subtract(DateTime.Now); int days = dateDifference.Days; if (days < 0) { customerCount = "\" Registered:" + eventForCalendar[count].RegisteredCustomersCount + " | Attended:" + eventForCalendar[count].AttendedCustomersCount + " | Cancel:" + eventForCalendar[count].CancelCustomersCount + " \""; } else if (days == 0) { customerCount = "\"Registered:" + eventForCalendar[count].RegisteredCustomersCount + " | Attended:" + eventForCalendar[count].AttendedCustomersCount + " | On Site :" + eventForCalendar[count].OnSiteCustomersCount + " \""; } else { customerCount = "\"Registered:" + eventForCalendar[count].RegisteredCustomersCount + " | Paid:" + eventForCalendar[count].PaidCustomersCount + " | UnPaid :" + eventForCalendar[count].UnpaidCustomersCount + " |Cancel :" + eventForCalendar[count].CancelCustomersCount + " \""; } strEventDescription = eventData + "," + eventStatus + "," + currentEventDate + "," + eventStartTime + "," + eventEndTime + "," + timeZone + "," + customerCount + "," + address1.Trim() + "," + address2 + "," + city + "," + state + "," + country + "," + zip + "," + franchisee + "," + salesRep + "," + controlID; string strEventView = string.Empty; strEventView = "onclick = 'window.location=\"EventDetails.aspx?EventID=" + eventForCalendar[count].EventID.ToString() + "\"'"; string strAddress = CommonCode.AddressMultiLine(eventForCalendar[count].Host.Address.Address1, eventForCalendar[count].Host.Address.Address2, eventForCalendar[count].Host.Address.City, eventForCalendar[count].Host.Address.State, eventForCalendar[count].Host.Address.Zip); string podName = string.Empty; var jTipData = "Event Details for " + eventData.Replace("\"", string.Empty) + "[" + eventForCalendar[count].EventID + "] " + "<span class=\"whitetxt12\">(" + eventStatus.Replace("\"", string.Empty).Trim() + ")</span>" + "|<p class=\"jtprowtop \"><span class=\"lbljtip\">Date & Time:</span>" + "<span class=\"dtlsjtip\">" + currentEventDate.Replace("\"", string.Empty) + "<br />" + eventStartTime.Replace("\"", string.Empty) + "–" + eventEndTime.Replace("\"", string.Empty) + "<br />" + timeZone.Replace("\"", string.Empty) + "</span>" + "</p><p class=\"jtprow\"><span class=\"lbljtip\"> Address: </span>" + "<span class=\"dtlsjtip\">" + strAddress.Replace("\"", string.Empty) + "</span></p><p class=\"jtprow\"><span class=\"lbljtip\"> Owner: </span>" + "<span class=\"dtlsjtip\">" + salesRep.Replace("\"", string.Empty) + "<br />(" + franchisee.Replace("\"", string.Empty) + ")" + "</span></p>"; podName = "<p class=\"jtprow\"><span class=\"lbljtip\"> Pod Name: </span>"; podName = podName + "<span class=\"dtlsjtip\">"; if (eventForCalendar[count].EventPod != null) { for (int podcount = 0; podcount < eventForCalendar[count].EventPod.Count; podcount++) { podName = podName + eventForCalendar[count].EventPod[podcount].Pod.Name.Replace("\"", string.Empty) + "<br />"; } } podName = podName + "</span></p>"; jTipData = jTipData + podName + "<p class=\"jtprow\"><span class=\"lbljtip\"> Statistics/Health: </span> </p>" + "<p class=\"jtprowtop\"><span class=\"custcauntjtp\"><span class=\"ttxt\"> Registered Customers </span>" + "<span class=\"dtxt\">" + ": " + eventForCalendar[count].RegisteredCustomersCount.ToString().Replace("\"", string.Empty) + "</span>" + "<br />" + "<span class=\"ttxt\"> Attended Customers</span>" + "<span class=\"dtxt\">" + ": " + eventForCalendar[count].AttendedCustomersCount.ToString().Replace("\"", string.Empty) + "</span>" + "<br />" + "<span class=\"ttxt\"> Canceled Customers</span>" + "<span class=\"dtxt\">" + ": " + eventForCalendar[count].CancelCustomersCount.ToString().Replace("\"", string.Empty) + "</span></span></p>"; string strEventName = "<a class='jtip' title='" + jTipData + "'" + strEventView + " ><img src='../Images/addevent-square.gif' height='14px' width='14px' /><span class='celltxt_clnder'> </span></a>"; _tblAppointments.Rows.Add(new object[] { "Event" + eventForCalendar[count].EventID.ToString() + strOwner, "Event", strEventName, eventForCalendar[count].EventDate, strEventDescription }); } } FillBlockedDays(startDate, endDate, strOwner); return(_tblAppointments); }
private void GetEventDataByDate(DateTime startDate, DateTime endDate) { List <EEvent> eventForCalendar; if (IoC.Resolve <ISessionContext>().UserSession.CurrentOrganizationRole.CheckRole((long)Roles.SalesRep)) { eventForCalendar = _masterDal.GetEventForCalendar(0, startDate.ToShortDateString(), endDate.ToShortDateString(), 0, HostName, FranchiseeId, PodIds, TerritoryIds); } else { eventForCalendar = _masterDal.GetEventForCalendar(SalesRepId, startDate.ToShortDateString(), endDate.ToShortDateString(), 0, HostName, FranchiseeId, PodIds, TerritoryIds); } var eventIds = new List <long>(); ITerritoryRepository territoryRepository = new TerritoryRepository(); if (!string.IsNullOrEmpty(TerritoryIds) && TerritoryIds != "0") { var territoryIds = TerritoryIds.Split(',').ToList().Select(ti => Convert.ToInt64(ti)).ToList(); List <Territory> territories = territoryRepository.GetTerritories(territoryIds); List <string> territoryZipCodes = territories.SelectMany(territory => territory.ZipCodes.Select(zipCode => zipCode.Zip)).ToList(); eventForCalendar = eventForCalendar.Where(eventData => territoryZipCodes.Contains(eventData.Host.Address.Zip)).ToList(); if (SalesRepId > 0) { var salesRepTerritories = territoryRepository.GetTerritoriesForSalesRep(SalesRepId).Where(t => territoryIds.Contains(t.Id)) .ToList(); foreach (var calenderEvent in eventForCalendar) { var @event = calenderEvent; var filteredSalesRepTerritories = salesRepTerritories.Where( st => st.ZipCodes.Select(z => z.Zip).Contains(@event.Host.Address.Zip)); foreach (var filteredSalesRepTerritory in filteredSalesRepTerritories) { SalesRepTerritory territory = filteredSalesRepTerritory; if (filteredSalesRepTerritories.All(fstpt => fstpt.ParentTerritoryId != territory.Id)) { var territoryAssignment = territory.SalesRepTerritoryAssignments.SingleOrDefault(srta => srta.SalesRep.SalesRepresentativeId == SalesRepId); if (territoryAssignment != null && (int)territoryAssignment.EventTypeSetupPermission != 0 && calenderEvent.EventType.EventTypeID != (int)territoryAssignment.EventTypeSetupPermission) { eventIds.Add(@event.EventID); } } } } } } if (eventForCalendar != null) { for (int count = 0; count < eventForCalendar.Count; count++) { string eventData = "\"" + eventForCalendar[count].Name.Replace("\n", "").Replace("'", "") + " \""; string eventStatus = "\"" + Convert.ToString(Enum.Parse(typeof(EventStatus), eventForCalendar[count].EventStatus.ToString())).Replace("\n", "").Replace("'", "") + " \""; string eventDate = "\"" + Convert.ToDateTime(eventForCalendar[count].EventDate).ToLongDateString() + " \""; string eventStartTime = "\"" + Convert.ToDateTime(eventForCalendar[count].EventStartTime).ToShortTimeString() + " \""; string eventEndTime = "\"" + Convert.ToDateTime(eventForCalendar[count].EventEndTime).ToShortTimeString() + " \""; string timeZone = "\"" + eventForCalendar[count].TimeZone + " \""; string address1 = "\"" + eventForCalendar[count].Host.Address.Address1.Replace("\n", "").Replace("'", "") + " \""; string address2 = "\"" + eventForCalendar[count].Host.Address.Address2.Replace("\n", "").Replace("'", "") + " \""; string city = "\"" + eventForCalendar[count].Host.Address.City + " \""; string state = "\"" + eventForCalendar[count].Host.Address.State + " \""; string country = "\"" + eventForCalendar[count].Host.Address.Country + " \""; string zip = "\"" + eventForCalendar[count].Host.Address.Zip + " \""; string franchisee = "\"" + eventForCalendar[count].Franchisee.Name.Replace("\n", "").Replace("'", "") + " \""; string salesRep = "\"" + eventForCalendar[count].FranchiseeFranchiseeUser.FranchiseeUser.User.FirstName + " " + eventForCalendar[count].FranchiseeFranchiseeUser.FranchiseeUser.User.LastName + " \""; string controlId = "\"Event" + eventForCalendar[count].EventID + "\""; string customerCount; TimeSpan dateDifference = Convert.ToDateTime(eventForCalendar[count].EventDate).Subtract(DateTime.Now); int days = dateDifference.Days; if (days < 0) { customerCount = "\" Registered:" + eventForCalendar[count].RegisteredCustomersCount + " | Attended:" + eventForCalendar[count].AttendedCustomersCount + " | Cancel:" + eventForCalendar[count].CancelCustomersCount + " \""; } else if (days == 0) { customerCount = "\"Registered:" + eventForCalendar[count].RegisteredCustomersCount + " | Attended:" + eventForCalendar[count].AttendedCustomersCount + " | On Site :" + eventForCalendar[count].OnSiteCustomersCount + " \""; } else { customerCount = "\"Registered:" + eventForCalendar[count].RegisteredCustomersCount + " | Paid:" + eventForCalendar[count].PaidCustomersCount + " | UnPaid :" + eventForCalendar[count].UnpaidCustomersCount + " |Cancel :" + eventForCalendar[count].CancelCustomersCount + " \""; } string strAddress = CommonCode.AddressMultiLine(eventForCalendar[count].Host.Address.Address1, eventForCalendar[count].Host.Address.Address2, eventForCalendar[count].Host.Address.City, eventForCalendar[count].Host.Address.State, eventForCalendar[count].Host.Address.Zip); strAddress = "\"" + strAddress.Replace("\n", "").Replace("'", "") + " \""; string strEventDescription = eventData + "," + eventStatus + "," + eventDate + "," + eventStartTime + "," + eventEndTime + "," + timeZone + "," + customerCount + "," + strAddress.Trim() + "," + address2 + "," + city + "," + state + "," + country + "," + zip + "," + franchisee + "," + salesRep + "," + controlId; string strEventView = string.Empty; if (!eventIds.Contains(eventForCalendar[count].EventID)) { strEventView = "onclick = 'window.location=\"EventDetails.aspx?EventID=" + eventForCalendar[count].EventID.ToString() + "\"'"; } //} string salesRepInitials = eventForCalendar[count].FranchiseeFranchiseeUser.FranchiseeUser.User.FirstName.Substring(0, 1) + eventForCalendar[count].FranchiseeFranchiseeUser.FranchiseeUser.User.LastName.Substring(0, 1); string podName = string.Empty; var jTipData = "Event Details for " + eventData.Replace("\"", string.Empty) + "[" + eventForCalendar[count].EventID + "] " + "<span class=\"whitetxt12\">(" + eventStatus.Replace("\"", string.Empty).Trim() + ")</span>" + "|<p class=\"jtprowtop \"><span class=\"lbljtip\"> Date & Time: </span>" + "<span class=\"dtlsjtip\">" + eventDate.Replace("\"", string.Empty) + "<br />" + eventStartTime.Replace("\"", string.Empty) + "–" + eventEndTime.Replace("\"", string.Empty) + "<br />" + timeZone.Replace("\"", string.Empty) + "</span>" + "</p><p class=\"jtprow\"><span class=\"lbljtip\"> Address: </span>" + "<span class=\"dtlsjtip\">" + strAddress.Replace("\"", string.Empty) + "</span></p><p class=\"jtprow\"><span class=\"lbljtip\"> Owner: </span>" + "<span class=\"dtlsjtip\">" + salesRep.Replace("\"", string.Empty) + "<br />(" + franchisee.Replace("\"", string.Empty) + ")" + "</span></p>"; podName = "<p class=\"jtprow\"><span class=\"lbljtip\"> Pod Name: </span>"; podName = podName + "<span class=\"dtlsjtip\">"; if (eventForCalendar[count].EventPod != null) { for (int podcount = 0; podcount < eventForCalendar[count].EventPod.Count; podcount++) { podName = podName + eventForCalendar[count].EventPod[podcount].Pod.Name.Replace("\"", string.Empty) + "<br />"; } } podName = podName + "</span></p>"; eventStatus = "<p class=\"jtprow\"><span class=\"lbljtip\"> Event Status: </span>"; eventStatus += "<span class=\"dtlsjtip\">" + ((EventStatus)eventForCalendar[count].EventStatus).ToString() + "</span></p>"; jTipData = jTipData + podName + eventStatus + "<p class=\"jtprow\"><span class=\"lbljtip\"> Statistics/Health: </span> </p>" + "<p class=\"jtprowtop\"><span class=\"custcauntjtp\"><span class=\"ttxt\"> Registered Customers </span>" + "<span class=\"dtxt\">" + ": " + eventForCalendar[count].RegisteredCustomersCount.ToString().Replace("\"", string.Empty) + "</span>" + "<br />" + "<span class=\"ttxt\"> Attended Customers</span>" + "<span class=\"dtxt\">" + ": " + eventForCalendar[count].AttendedCustomersCount.ToString().Replace("\"", string.Empty) + "</span>" + "<br />" + "<span class=\"ttxt\"> Canceled Customers</span>" + "<span class=\"dtxt\">" + ": " + eventForCalendar[count].CancelCustomersCount.ToString().Replace("\"", string.Empty) + "</span></span></p>"; string strEventName = "<a class='jtip' title='" + jTipData + "'" + strEventView + " ><img src='../Images/addevent-square.gif' /><span class='celltxt_clnder'>" + salesRepInitials + " " + eventForCalendar[count].Host.Name + "<br>" + eventForCalendar[count].Host.Address.City + ", " + eventForCalendar[count].Host.Address.State + " - " + eventForCalendar[count].Host.Address.Zip + "</span></a>"; _tblAppointments.Rows.Add(new object[] { "Event" + eventForCalendar[count].EventID.ToString(), "Event", strEventName, eventForCalendar[count].EventDate, strEventDescription }); } } }