public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            return(obj is TeamMemberAssignedLocations other &&
                   ((AssignmentType == null && other.AssignmentType == null) || (AssignmentType?.Equals(other.AssignmentType) == true)) &&
                   ((LocationIds == null && other.LocationIds == null) || (LocationIds?.Equals(other.LocationIds) == true)));
        }
示例#2
0
        /// <summary>
        /// Applies the rule
        /// </summary>
        public override void ApplyRule(DataRow row)
        {
            if (AssignmentType.Equals(SimpleAssignType.YearsElapsed))
            {
                string minDateColumnName = AssignmentParameters[0];
                string maxDateColumnName = AssignmentParameters[1];

                if (row[minDateColumnName] == null || row[maxDateColumnName] == null || string.IsNullOrEmpty(row[minDateColumnName].ToString()) || string.IsNullOrEmpty(row[maxDateColumnName].ToString()))
                {
                    row[this.DestinationColumnName] = DBNull.Value;
                }
                else
                {
                    DateTime minDate = (DateTime)row[minDateColumnName];
                    DateTime maxDate = (DateTime)row[maxDateColumnName];

                    int years = maxDate.Year - minDate.Year;
                    if
                    (
                        maxDate.Month < minDate.Month ||
                        (maxDate.Month == minDate.Month && maxDate.Day < minDate.Day)
                    )
                    {
                        years--;
                    }

                    row[this.DestinationColumnName] = years;
                }
            }
            else if (AssignmentType.Equals(SimpleAssignType.MonthsElapsed))
            {
                string minDateColumnName = AssignmentParameters[0];
                string maxDateColumnName = AssignmentParameters[1];

                if (row[minDateColumnName] == null || row[maxDateColumnName] == null || string.IsNullOrEmpty(row[minDateColumnName].ToString()) || string.IsNullOrEmpty(row[maxDateColumnName].ToString()))
                {
                    row[this.DestinationColumnName] = DBNull.Value;
                }
                else
                {
                    DateTime minDate = Convert.ToDateTime(row[minDateColumnName]);
                    DateTime maxDate = Convert.ToDateTime(row[maxDateColumnName]);

                    int monthsApart = 12 * (maxDate.Year - minDate.Year) + maxDate.Month - minDate.Month;

                    if (maxDate.Day < minDate.Day)
                    {
                        monthsApart--;
                    }

                    row[this.DestinationColumnName] = monthsApart;
                }
            }
            else if (AssignmentType.Equals(SimpleAssignType.DaysElapsed))
            {
                string minDateColumnName = AssignmentParameters[0];
                string maxDateColumnName = AssignmentParameters[1];

                if (row[minDateColumnName] == null || row[maxDateColumnName] == null || string.IsNullOrEmpty(row[minDateColumnName].ToString()) || string.IsNullOrEmpty(row[maxDateColumnName].ToString()))
                {
                    row[this.DestinationColumnName] = DBNull.Value;
                }
                else
                {
                    DateTime minDate  = Convert.ToDateTime(row[minDateColumnName]);
                    DateTime maxDate  = Convert.ToDateTime(row[maxDateColumnName]);
                    TimeSpan timeSpan = maxDate.Subtract(minDate);
                    double   days     = Math.Round(timeSpan.TotalDays);
                    row[this.DestinationColumnName] = days;
                }
            }
            else if (AssignmentType.Equals(SimpleAssignType.HoursElapsed))
            {
                string minDateColumnName = AssignmentParameters[0];
                string maxDateColumnName = AssignmentParameters[1];

                if (row[minDateColumnName] == null || row[maxDateColumnName] == null || string.IsNullOrEmpty(row[minDateColumnName].ToString()) || string.IsNullOrEmpty(row[maxDateColumnName].ToString()))
                {
                    row[this.DestinationColumnName] = DBNull.Value;
                }
                else
                {
                    DateTime minDate  = Convert.ToDateTime(row[minDateColumnName]);
                    DateTime maxDate  = Convert.ToDateTime(row[maxDateColumnName]);
                    TimeSpan timeSpan = maxDate.Subtract(minDate);
                    double   hours    = Math.Round(timeSpan.TotalHours);
                    row[this.DestinationColumnName] = hours;
                }
            }
            else if (AssignmentType.Equals(SimpleAssignType.MinutesElapsed))
            {
                string minDateColumnName = AssignmentParameters[0];
                string maxDateColumnName = AssignmentParameters[1];

                if (row[minDateColumnName] == null || row[maxDateColumnName] == null || string.IsNullOrEmpty(row[minDateColumnName].ToString()) || string.IsNullOrEmpty(row[maxDateColumnName].ToString()))
                {
                    row[this.DestinationColumnName] = DBNull.Value;
                }
                else
                {
                    DateTime minDate  = Convert.ToDateTime(row[minDateColumnName]);
                    DateTime maxDate  = Convert.ToDateTime(row[maxDateColumnName]);
                    TimeSpan timeSpan = maxDate.Subtract(minDate);
                    double   hours    = Math.Round(timeSpan.TotalMinutes);
                    row[this.DestinationColumnName] = hours;
                }
            }
            else if (AssignmentType.Equals(SimpleAssignType.TextToNumber))
            {
                string textColumnName = AssignmentParameters[0];
                string value          = row[textColumnName].ToString().Trim();

                if (row[textColumnName] == null || string.IsNullOrEmpty(value))
                {
                    row[this.DestinationColumnName] = DBNull.Value;
                }
                else
                {
                    double result;
                    bool   success = double.TryParse(value, out result);

                    if (success)
                    {
                        row[this.DestinationColumnName] = result;
                    }
                    else
                    {
                        row[this.DestinationColumnName] = DBNull.Value;
                    }
                }
            }
            else if (AssignmentType.Equals(SimpleAssignType.TextToDate))
            {
                string textColumnName = AssignmentParameters[0];
                string value          = row[textColumnName].ToString().Trim();

                if (row[textColumnName] == null || string.IsNullOrEmpty(value))
                {
                    row[this.DestinationColumnName] = DBNull.Value;
                }
                else
                {
                    try
                    {
                        DateTime?dateField = DateTime.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
                        row[this.DestinationColumnName] = dateField;
                    }
                    catch (Exception)
                    {
                        row[this.DestinationColumnName] = DBNull.Value;
                    }
                }
            }
            else if (AssignmentType.Equals(SimpleAssignType.FindText))
            {
                string textColumnName = AssignmentParameters[0];
                string searchString   = AssignmentParameters[1];

                string value   = row[textColumnName].ToString();
                int    indexOf = value.IndexOf(searchString);

                if (indexOf == -1)
                {
                    row[this.DestinationColumnName] = DBNull.Value;
                }
                else
                {
                    row[this.DestinationColumnName] = indexOf;
                }
            }
            else if (AssignmentType.Equals(SimpleAssignType.StringLength))
            {
                string textColumnName = AssignmentParameters[0];

                string value = row[textColumnName].ToString();
                row[this.DestinationColumnName] = value.Length;
            }
            else if (AssignmentType.Equals(SimpleAssignType.Round))
            {
                string numericColumnName = AssignmentParameters[0];
                int    decimals          = 0;
                int.TryParse(AssignmentParameters[1], out decimals);

                string value = row[numericColumnName].ToString().Trim();

                if (row[numericColumnName] == null || string.IsNullOrEmpty(value))
                {
                    row[this.DestinationColumnName] = DBNull.Value;
                }
                else
                {
                    decimal result;
                    bool    success = decimal.TryParse(value, out result);
                    result = Math.Round(result, decimals);

                    if (success)
                    {
                        row[this.DestinationColumnName] = result;
                    }
                    else
                    {
                        row[this.DestinationColumnName] = DBNull.Value;
                    }
                }
            }
            else if (AssignmentType.Equals(SimpleAssignType.Substring))
            {
                string textColumnName = AssignmentParameters[0];
                int    start          = 0;
                int    length         = 0;

                if (dashboardHelper.TableColumnNames.ContainsKey(AssignmentParameters[1]))
                {
                    start = int.Parse(row[AssignmentParameters[1]].ToString());
                }
                else
                {
                    start = int.Parse(AssignmentParameters[1]);
                }

                if (dashboardHelper.TableColumnNames.ContainsKey(AssignmentParameters[2]))
                {
                    length = int.Parse(row[AssignmentParameters[2]].ToString());
                }
                else
                {
                    length = int.Parse(AssignmentParameters[2]);
                }

                --start;

                string value = row[textColumnName].ToString();

                if (start > row[textColumnName].ToString().Length)
                {
                    row[this.DestinationColumnName] = DBNull.Value;
                }
                else if (start + length > row[textColumnName].ToString().Length)
                {
                    int fullLength = row[textColumnName].ToString().Length;
                    int newLength  = fullLength - start;
                    value = row[textColumnName].ToString().Substring(start, newLength);
                }
                else
                {
                    value = row[textColumnName].ToString().Substring(start, length);
                }

                row[this.DestinationColumnName] = value;
            }
        }