示例#1
0
        private void addTableContent()
        {
            for (int i = 1; i <= DataList.Count; i++)
            {
                ScalesValue data = DataList[i - 1];
                string      date = data.Time.ToString();
                int         row_index, col_index;

                if (!mIndexMapper.TryGetValue(date, out row_index))
                {
                    row_index = mEndRow + 1;
                    mIndexMapper.Add(date, row_index);

                    object lastValue = mSheet.Cells[mEndRow, COL_INDEX].Value;
                    setCellData(row_index, COL_INDEX, lastValue is double?((double)lastValue) + 1 : 1);
                }
                if (!mIndexMapper.TryGetValue(data.ScaleTag, out col_index))
                {
                    col_index = mEndCol + 1;
                    mIndexMapper.Add(data.ScaleTag, col_index);
                }

                setCellData(row_index, COL_TIME_INDEX, date);
                setCellData(row_index, col_index, data.Weight);
                mSheet.Cells[row_index, col_index].NumberFormat = "#.#";

                for (int j = COL_TIME_INDEX + 1; j <= mEndCol; j++)
                {
                    Range cell = mSheet.Cells[row_index, j];
                    if (cell.Value == null)
                    {
                        cell.Value = 0;
                    }
                }
            }

            // Hardcode time column
            Range timeRange = getRange(mStartRow, mEndRow, COL_TIME_INDEX, COL_TIME_INDEX);

            timeRange.EntireColumn.AutoFit();
            Range countRange = getRange(mStartRow, mEndRow, COL_INDEX, COL_INDEX);

            countRange.Columns.AutoFit();
            Range   tableRange = getRange(mStartRow, mEndRow, mStartCol, mEndCol);
            Borders border     = tableRange.Borders;

            border.LineStyle = XlLineStyle.xlContinuous;
        }
示例#2
0
        ///<summary>
        ///Return scalesValue from database from <paramref name="fromDate"/> to <paramref name="toDate"/>
        ///</summary>
        ///<param name="fromDate">from Date, if null will get all value until toDate</param>
        ///<param name="toDate">take until Date, if null will get all value after fromDate</param>
        public List <ScalesValue> getScalesValue(string fromDate, string toDate)
        {
            try
            {
                string condition = null;
                if (fromDate != null)
                {
                    condition = " where Time >= @fromDate";
                }
                if (toDate != null)
                {
                    if (condition == null)
                    {
                        condition = " where ";
                    }
                    else
                    {
                        condition += " and ";
                    }
                    condition += "Time <= @toDate";
                }

                string query = String.Format("select {0}, {1}, {2} from {3} {4} order by {5}",
                                             COL_SCALES_TIME,
                                             COL_SCALES_WEIGHT,
                                             COL_SCALES_TAG,
                                             TABLE_SCALES_VALUE,
                                             condition,
                                             COL_SCALES_TIME);
                //SqlCeCommand cmd = new SqlCeCommand(query, mConnection);
                setQuery(query);
                if (fromDate != null)
                {
                    mCmd.Parameters.AddWithValue("@fromDate", DateTime.Parse(fromDate));
                }
                if (toDate != null)
                {
                    mCmd.Parameters.AddWithValue("@toDate", DateTime.Parse(toDate));
                }

                System.Data.Common.DbDataReader reader = mCmd.ExecuteReader();
                List <ScalesValue> list = new List <ScalesValue>();

                while (reader.Read())
                {
                    ScalesValue value = new ScalesValue(reader.GetDateTime(0),
                                                        (float)reader.GetDouble(1),
                                                        reader.GetString(2));

                    list.Add(value);
                }

                reader.Close();
                return(list);
            } catch (Exception e)
            {
                UnhandledExceptionEventArgs arg = new UnhandledExceptionEventArgs(e, false);
                CurrentDomain_UnhandledException(null, arg);
                return(null);
            }
        }