public void CalcuateResult(DataRow dr) { if (dr == null || this._MaskedField == string.Empty || !dr.Table.Columns.Contains(this._MaskedField)) { this._MaskedText = string.Empty; } else { object objValue = CResolveFieldValue.GetResolveValue(this._MaskedField, _DateFormat, dr[this._MaskedField]); this._MaskedText = objValue.ToString(); } foreach (MaskInfo brotherInfo in this.BrotherMaskInfos) { brotherInfo.CalcuateResult(dr); } }
private void CalculateAverage(DataTable i_Table, Webb.Collections.Int32Collection i_OuterRows, Webb.Collections.Int32Collection i_Rows, Data.StatTypes i_Type) { decimal m_Sum = 0, fieldValue = 0m; DateTime totalDateTime = new DateTime(0); long timeTicks = 0; Type type = null; Webb.Reports.DataProvider.WebbDataProvider publicprovider = Webb.Reports.DataProvider.VideoPlayBackManager.PublicDBProvider; bool isTimeData = (publicprovider != null && publicprovider.IsCCRMTimeData(this._FieldName)); bool isFeetInchesData = (publicprovider != null && publicprovider.IsFeetInchesData(this._FieldName)); if (!i_Table.Columns.Contains(this._FieldName)) { goto EXIT; } type = i_Table.Columns[_FieldName].DataType; foreach (int i_RowIndex in i_Rows) { try { #region Old //string strValue = i_Table.Rows[i_RowIndex][this._FieldName].ToString(); //if (strValue == null || strValue == string.Empty) //{ // continue; //} //double fieldValue = Convert.ToDouble(strValue); //switch (i_Type) //{ // case Data.StatTypes.AveragePlus: // if (fieldValue > 0) m_Sum += fieldValue; // break; // case Data.StatTypes.AverageMinus: // if (fieldValue < 0) m_Sum += fieldValue; // break; // case Data.StatTypes.Average: // default: // m_Sum += fieldValue; // break; //} #endregion object objValue = i_Table.Rows[i_RowIndex][this._FieldName]; if (objValue == null || objValue is System.DBNull) { continue; } if (isTimeData) { TimeSpan timeSpan = Webb.Utility.ConvertToTimeTicks(objValue.ToString()); totalDateTime = totalDateTime.Add(timeSpan); } if (isFeetInchesData) { fieldValue = Webb.Utility.ConvertFeetInchToNum(objValue.ToString()); m_Sum += fieldValue; } else if (type == typeof(DateTime)) { timeTicks += Convert.ToDateTime(objValue).Ticks; } else { #region calcaulate Numer string strValue = objValue.ToString(); if (strValue == null || strValue == string.Empty) { continue; } fieldValue = Convert.ToDecimal(strValue); switch (i_Type) { case Data.StatTypes.AveragePlus: if (fieldValue > 0) { m_Sum += fieldValue; } break; case Data.StatTypes.AverageMinus: if (fieldValue < 0) { m_Sum += fieldValue; } break; case Data.StatTypes.Average: default: m_Sum += fieldValue; break; } #endregion } } catch { continue; } } EXIT: if (i_Rows.Count > 0) { #region Old //this._Result.Add(m_Sum / i_Rows.Count); #endregion object objResultValue = string.Empty; #region New if (type == typeof(DateTime)) { objResultValue = new DateTime(timeTicks / i_Rows.Count); objResultValue = CResolveFieldValue.GetResolveValue(this._FieldName, @"M/d/yy", objResultValue); } if (isTimeData) { timeTicks = totalDateTime.Ticks / i_Rows.Count; DateTime dateTime = new DateTime(timeTicks); bool outputTimeFormat = Webb.Utility.IsTimeFormatForOut(i_Table, i_OuterRows, _FieldName); if (outputTimeFormat) { if (dateTime.Hour > 0) { objResultValue = dateTime.ToString("h:m:s.ff"); } else { objResultValue = dateTime.ToString("m:s.ff");; } } else { objResultValue = dateTime.TimeOfDay.TotalSeconds; } } else if (isFeetInchesData) { m_Sum = m_Sum / i_Rows.Count; objResultValue = Webb.Utility.FormatFeetInchData(m_Sum); } else { objResultValue = m_Sum / i_Rows.Count; } #endregion this._Result.Add(objResultValue); } else { this._Result.Add(0); } }