public Capacitor(TypeBLO type) { this.type = type; sum = 0; saturation = new Dictionary <string, int>(); notNullRows = 0; rows = 0; }
public Store(string name) { if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Name is not empty"); } BLObj = name; type = TypeBLO.None; }
/// <summary> /// Определяет тип входного объекта, /// если таковой еще не определен /// </summary> /// <param name="value">Объект</param> /// <returns>Возвращает False, если числовой тип /// True, если строковый</returns> private void DeclareTypeBLO(string value) { if (type != TypeBLO.None && type != TypeBLO.Boolean) { return; } if (String.IsNullOrEmpty(value)) { return; } double res; if (double.TryParse(value, out res)) { if (type == TypeBLO.None) { if (res != 1 && res != 0) { type = TypeBLO.Number; } else { type = TypeBLO.Boolean; } } else { if (res != 1 && res != 0) { type = TypeBLO.Number; } } } else { if (double.TryParse(value.Remove(value.Length - 1), out res)) { type = TypeBLO.Percent; } else { type = TypeBLO.String; map = new Dictionary <string, double[]>(); map["None"] = null; } } }
/// <summary> /// Просчитывает новое значение для текущего столбца /// </summary> /// <param name="index">Индекс текущего столбца</param> /// <param name="value">Значение текущего столбца</param> public void Set(int index, string value) { TypeBLO type = DeclareTypeBLO(value); if (!capasitor.Keys.Contains(index)) { capasitor.Add(index, new Capacitor(type)); } if ((capasitor[index].type == TypeBLO.Boolean || capasitor[index].type == TypeBLO.None) && type == TypeBLO.Number) { capasitor[index].type = type; } switch (type) { case TypeBLO.Boolean: if (!String.IsNullOrEmpty(value)) { capasitor[index].notNullRows++; capasitor[index].sum += double.Parse(value); } break; case TypeBLO.Number: if (!String.IsNullOrEmpty(value)) { capasitor[index].notNullRows++; capasitor[index].sum += double.Parse(value); } break; case TypeBLO.String: if (!String.IsNullOrEmpty(value)) { capasitor[index].notNullRows++; if (!capasitor[index].saturation.Keys.Contains(value)) { capasitor[index].saturation.Add(value, 0); } capasitor[index].saturation[value]++; } break; } capasitor[index].rows++; }