Beispiel #1
0
        /// <summary>
        /// Convert a VariableValue to Cell
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="variableValue"></param>
        /// <param name="rowIndex"></param>
        /// <param name="columnIndex"></param>
        /// <returns></returns>
        protected Cell VariableValueToCell(VariableValue variableValue, int rowIndex, int columnIndex)
        {
            string message = "row :" + rowIndex + "column:" + columnIndex;
            Debug.WriteLine(message);

            DataContainerManager CM = new DataContainerManager();
            DataAttribute dataAttribute = CM.DataAttributeRepo.Get(variableValue.DataAttribute.Id);

            string cellRef = getColumnIndex(columnIndex);

            Cell cell = new Cell();
            cell.CellReference = cellRef;
            cell.StyleIndex = getExcelStyleIndex(dataAttribute.DataType.SystemType, styleIndexArray);
            //cell.DataType = new EnumValue<CellValues>(getExcelType(dataAttribute.DataType.SystemType));
            //cell.CellValue = new CellValue(variableValue.Value.ToString());

            CellValues cellValueType = getExcelType(dataAttribute.DataType.SystemType);
            object value = variableValue.Value;

            if (value != null && !(value is DBNull) && cellValueType == CellValues.Number)
            {
                cell.DataType = new EnumValue<CellValues>(CellValues.Number);

                try
                {
                    if (value != "")
                    {
                        double d = Convert.ToDouble(value, System.Globalization.CultureInfo.InvariantCulture);
                        cell.CellValue = new CellValue(d.ToString(System.Globalization.CultureInfo.InvariantCulture));
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message + "\n|"+message);
                }

                return cell;
            }
            else
            {
                if (value != null && !(value is DBNull) && cellValueType == CellValues.Date)
                {

                    cell.DataType = new EnumValue<CellValues>(CellValues.Number);
                    //CultureInfo provider = CultureInfo.InvariantCulture;
                    try
                    {
                        if (value != "")
                        {
                            DateTime dt = Convert.ToDateTime(value.ToString());
                            cell.CellValue = new CellValue(dt.ToOADate().ToString());
                        }
                    }
                    catch(Exception ex)
                    {
                        throw new Exception(ex.Message + "|" + message);
                    }
                }
                else
                {
                    cell.DataType = new EnumValue<CellValues>(CellValues.String);
                    if(value==null)
                        cell.CellValue = new CellValue("");
                    else
                        cell.CellValue = new CellValue(value.ToString());
                }
            }

            return cell;
        }
Beispiel #2
0
        /// <summary>
        /// This method creates a variable value and returns it without persisting the object in the database. Usually the returned variable value should be added to a data tuple which in turn is belonging to a data set version.
        /// A value is a compound object holding information about a single event (sampling). The event can be a(n) measurement, observation, estimation, simulation, or computation of a feature of an entity.
        /// The value can be a assigned to a variable or a parameter based on the design of the data structure.
        /// </summary>
        /// <param name="value">The result of the event which can be a(n) measurement, observation, estimation, simulation, or computation</param>
        /// <param name="note">A free format, but short, description about the value</param>
        /// <param name="samplingTime">The exact time of the start of the event. It shows when the sampling is started.</param>
        /// <param name="resultTime">The sampling, or the processing may take time (like in the computation or simulation cases), also some devices/ sensors have a response time. The parameter captures the time when the result (value) is ready.
        /// The result time and its difference to sampling time are important for some analyses.
        /// </param>
        /// <param name="obtainingMethod">Determines how the values is obtained, which is one of the measurement, observation, estimation, simulation, or computation cases.</param>
        /// <param name="variableId">The identifier of the variable that the value is belonging to.</param>
        /// <param name="parameterValues">If the variable has parameters attached, the parameter values are passed alongside, so that the method links them to their corresponding variable value using <paramref name="variableId"/>.</param>
        /// <returns>A transient object of type <seealso cref="VariableValue"/>.</returns>
        public VariableValue CreateVariableValue(string value, string note, DateTime samplingTime, DateTime resultTime, ObtainingMethod obtainingMethod, Int64 variableId, ICollection<ParameterValue> parameterValues)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(value));
            Contract.Requires(variableId > 0);
            Contract.Ensures(Contract.Result<VariableValue>() != null);

            VariableValue e = new VariableValue()
            {
                Value = value,
                Note = note,
                SamplingTime = samplingTime,
                ResultTime = resultTime,
                ObtainingMethod = obtainingMethod,
                VariableId = variableId,
                ParameterValues = new List<ParameterValue>(parameterValues),
            };

            //using (IUnitOfWork uow = this.GetUnitOfWork())
            //{
            //    IRepository<VariableValue> repo = uow.GetRepository<VariableValue>();
            //    repo.Put(e);
            //    uow.Commit();
            //}
            return (e);
        }