示例#1
0
 public ChartMainForm(Sensor sensor = null, Group group = null, PictureView pictureView = null, DateTime? startDate = null,
                      DateTime? endDate = null)
 {
     _sensor = sensor;
     _group = group;
     _pictureView = pictureView;
     _startDate = startDate;
     _endDate = endDate;
     InitializeComponent();
 }
示例#2
0
 /// <summary>
 /// Pass params to filter, set null (default) for no filtering
 /// </summary>
 /// <param name="sensor"></param>
 /// <param name="startDate"></param>
 /// <param name="endDate"></param>
 /// <param name="isEnded"></param>
 public AlarmManagerForm(Sensor sensor = null, DateTime? startDate = null, DateTime? endDate = null, bool? isEnded = null)
 {
     // set value to private field
     _sensor = sensor;
     _startDate = startDate;
     _endDate = endDate;
     _isEnded = isEnded;
     // ...
     // continue here
     InitializeComponent();
     BindingData();
 }
示例#3
0
 //public const string PARAMS_USER_DEFINED = "{0}#{1}";
 /// <summary>
 /// Calculate values of all entries of a sensor with alarm logger option
 /// Auto save changed to database
 /// </summary>
 /// <param name="sensor"></param>
 /// <param name="alarmLogger"></param>
 public void Calculating(Sensor sensor, bool alarmLogger)
 {
     foreach (var sensorValue in sensor.SensorValues)
     {
         Calculating(sensorValue);
     }
     if (alarmLogger)
     {
         foreach (var sensorValue in sensor.SensorValues)
         {
             AlarmBLL.Current.CheckAlarm(sensorValue);
         }
     }
 }
示例#4
0
        public string GetFomullaFunction(Sensor sensor)
        {
            if (!string.IsNullOrEmpty(sensor.FormulaFunction))
            {
                return sensor.FormulaFunction;
            }
            List<String> parameters = sensor.FunctionParameters.SplitToList('#');
            switch (sensor.FormulaType)
            {
                case CalculationBLL.FORMULA_LINEAR:
                    if (parameters.Count < 2) return "";
                    return string.Format("Xo = {0} + {1}*Vi", parameters[0], parameters[1]);
                case CalculationBLL.FORMULA_ARCTOLENGTH_DEGREE:
                    break;

                case CalculationBLL.FORMULA_ARCTOLENGTH_RADIAN:
                    break;

                case CalculationBLL.FORMULA_POLYNOMIAL:
                    break;

                case CalculationBLL.FORMULA_TEMPRATURE_COMP:
                    break;

                case CalculationBLL.FORMULA_VW_LINEAR:
                    break;
                case CalculationBLL.FORMULA_VW_POLY:
                    break;
                case CalculationBLL.FORMULA_USER_DEFINED:
                    return sensor.FormulaFunction;

            }
            {

            }
            return "";
        }
示例#5
0
 public void Validate(Sensor obj)
 {
     if (obj.MinValue != null && obj.MaxValue != null && obj.MinValue >= obj.MaxValue) throw new Exception(Resources.Error_SetAlarmInvalid);
     if (obj.AlarmEnabled && obj.MaxValue == null && obj.MinValue == null) throw new Exception(Resources.Error_SetAlarmInvalid);
     if (!obj.Name.IsValidLength(1, 200)) throw new Exception(Resources.Error_SensorNameInvalid);
     if (!obj.Description.IsValidLength(-1, 500)) throw new Exception(Resources.Error_SensorDescriptionInvalid);
 }
示例#6
0
 public bool Update(Sensor obj)
 {
     using (var entityConntext = new GeoViewerEntities())
     {
         SecurityBLL.Current.CheckPermissionThrowException(new string[]
                                                               {
                                                                   SecurityBLL.ROLE_DATA_EDIT,
                                                                   SecurityBLL.ROLE_DATA_MANAGE
                                                               });
         Validate(obj);
         obj.LastEditedDate = DateTime.Now;
         obj.LastEditedUser = AppContext.Current.LogedInUser.Username;
         entityConntext.AttachUpdatedObject(obj);
         return entityConntext.SaveChanges() > 0;
     }
 }
示例#7
0
 public bool Insert(Sensor obj)
 {
     using (var entityConntext = new GeoViewerEntities())
     {
         SecurityBLL.Current.CheckPermissionThrowException(SecurityBLL.ROLE_DATA_MANAGE);
         Validate(obj);
         if (AppContext.Current.OpenProject != null) obj.ProjectID = AppContext.Current.OpenProject.ProjectID;
         obj.CreatedDate = obj.LastEditedDate = DateTime.Now;
         obj.CreatedUser = obj.LastEditedUser = AppContext.Current.LogedInUser.Username;
         entityConntext.Sensors.AddObject(obj);
         return entityConntext.SaveChanges() > 0;
     }
 }
示例#8
0
        /// <summary>
        /// Get list of alarm logs by conditions, pass parameters null for select all (no condition)
        /// </summary>
        /// <param name="sensor">only select alarm logs for this sensor</param>
        /// <param name="startDate">select alarm logs from start date</param>
        /// <param name="endDate">select alarm logs to end date</param>
        /// <param name="isEnded">select alarm logs which marked IsEnded = true or fasle</param>
        /// <param name="start">started record</param>
        /// <param name="limit">number of record will return</param>
        /// <returns></returns>
        public List<AlarmLog> GetByConditions(Sensor sensor = null, DateTime? startDate = null, DateTime? endDate = null, bool? isEnded = null, int start = -1, int limit = -1)
        {
            using (var entityConntext = new GeoViewerEntities())
            {
                int? sensorID = sensor == null ? null : (int?)sensor.SensorID;

                var result = entityConntext.AlarmLogs.Where(ent =>
                                                            (sensorID == null || ent.SensorID == sensorID) &&
                                                            (startDate == null || ent.StartAlarmDatetime >= startDate) &&
                                                            (endDate == null || ent.StartAlarmDatetime <= endDate) &&
                                                            (isEnded == null || ent.IsEnded == isEnded)
                    ).OrderByDescending(ent => ent.StartAlarmDatetime).ThenByDescending(ent => ent.AlarmLogID);
                if (start >= 0 && limit > 0)
                {
                    return result.Skip(start).Take(limit).ToList();
                }
                return result.ToList();
            }
        }
示例#9
0
 public void ExportToFile(Sensor[] sensors, string filePath)
 {
 }
示例#10
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Sensors EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSensors(Sensor sensor)
 {
     base.AddObject("Sensors", sensor);
 }
示例#11
0
 /// <summary>
 /// Create a new Sensor object.
 /// </summary>
 /// <param name="sensorID">Initial value of the SensorID property.</param>
 /// <param name="loggerID">Initial value of the LoggerID property.</param>
 /// <param name="columnIndex">Initial value of the ColumnIndex property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="formulaType">Initial value of the FormulaType property.</param>
 /// <param name="alarmEnabled">Initial value of the AlarmEnabled property.</param>
 /// <param name="alarmFlag">Initial value of the AlarmFlag property.</param>
 public static Sensor CreateSensor(global::System.Int32 sensorID, global::System.Int32 loggerID, global::System.Int32 columnIndex, global::System.String name, global::System.Int32 formulaType, global::System.Boolean alarmEnabled, global::System.Boolean alarmFlag)
 {
     Sensor sensor = new Sensor();
     sensor.SensorID = sensorID;
     sensor.LoggerID = loggerID;
     sensor.ColumnIndex = columnIndex;
     sensor.Name = name;
     sensor.FormulaType = formulaType;
     sensor.AlarmEnabled = alarmEnabled;
     sensor.AlarmFlag = alarmFlag;
     return sensor;
 }
示例#12
0
        private void addEdit()
        {
            try
            {
                if (_addEditState == 0 || _editingSensor == null)
                {
                    _editingSensor = new Sensor();
                    _editingSensor.Logger = _logger;
                }

                string functionParameters = "";
                int formulaType = 0;

                if (caclSelectTabs.SelectedTab == linearTab)
                {
                    formulaType = CalculationBLL.FORMULA_LINEAR;
                    functionParameters = string.Format(CalculationBLL.PARAMS_LINEAR,
                                                       linear_C0.Text.ToDecimalTryParse().ToDecimalString(),
                                                       linear_C1.Text.ToDecimalTryParse().ToDecimalString());
                }
                else if (caclSelectTabs.SelectedTab == arcToLengthTab)
                {
                    formulaType = arc_Degree.Checked ? CalculationBLL.FORMULA_ARCTOLENGTH_DEGREE : CalculationBLL.FORMULA_ARCTOLENGTH_RADIAN;
                    functionParameters = string.Format(CalculationBLL.PARAMS_ARCTOLENGTH_DEGREE,
                                                       arc_Length.Text.ToDecimalTryParse().ToDecimalString()
                                                       );

                }
                else if (caclSelectTabs.SelectedTab == polynomialTab)
                {
                    formulaType = CalculationBLL.FORMULA_POLYNOMIAL;
                    functionParameters = string.Format(CalculationBLL.PARAMS_POLYNOMIAL,
                                                       poly_C0.Text.ToDecimalTryParse().ToDecimalString(),
                                                       poly_C1.Text.ToDecimalTryParse().ToDecimalString(),
                                                       poly_C2.Text.ToDecimalTryParse().ToDecimalString(),
                                                       poly_C3.Text.ToDecimalTryParse().ToDecimalString(),
                                                       poly_C4.Text.ToDecimalTryParse().ToDecimalString(),
                                                       poly_C5.Text.ToDecimalTryParse().ToDecimalString()
                                                       );

                }
                else if (caclSelectTabs.SelectedTab == temperatureCompTab)
                {
                    formulaType = CalculationBLL.FORMULA_TEMPRATURE_COMP;
                    functionParameters = string.Format(CalculationBLL.PARAMS_TEMPRATURE_COMP,
                                                       temp_Tk.Text.ToDecimalTryParse().ToDecimalString(),
                                                       temp_Ti.Text.ToDecimalTryParse().ToDecimalString(),
                                                       temp_Tc.SelectedValue,//
                                                       temp_C0.Text.ToDecimalTryParse().ToDecimalString(),
                                                       temp_C1.Text.ToDecimalTryParse().ToDecimalString(),
                                                       temp_C2.Text.ToDecimalTryParse().ToDecimalString(),
                                                       temp_C3.Text.ToDecimalTryParse().ToDecimalString(),
                                                       temp_C4.Text.ToDecimalTryParse().ToDecimalString(),
                                                       temp_C5.Text.ToDecimalTryParse().ToDecimalString()
                                                       );
                }
                else if (caclSelectTabs.SelectedTab == vwLinearTab)
                {
                    formulaType = CalculationBLL.FORMULA_VW_LINEAR;
                    functionParameters = string.Format(CalculationBLL.PARAMS_VW_LINEAR,
                                                       vwLinear_Tk.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwLinear_Ti.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwLinear_Tc.SelectedValue, //
                                                       vwLinear_CK.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwLinear_Li.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwLinear_Lm.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwLinear_Bi.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwLinear_Bc.SelectedValue,
                                                       vwLinear_D.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwLinear_E.Text.ToDecimalTryParse().ToDecimalString()
                                                       );
                }
                else if (caclSelectTabs.SelectedTab == vwPoly)
                {
                    formulaType = CalculationBLL.FORMULA_VW_POLY;
                    functionParameters = string.Format(CalculationBLL.PARAMS_VW_POLY,
                                                       vwPoly_Tk.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwPoly_Ti.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwPoly_Tc.SelectedValue, //
                                                       vwPoly_A.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwPoly_B.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwPoly_Lm.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwPoly_Bi.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwPoly_Bc.SelectedValue,
                                                       vwPoly_C.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwPoly_D.Text.ToDecimalTryParse().ToDecimalString(),
                                                       vwPoly_E.Text.ToDecimalTryParse().ToDecimalString()
                                                       );
                }
                else if (caclSelectTabs.SelectedTab == tabUserDefine)
                {
                    try
                    {
                        if (string.IsNullOrEmpty(txtUserExpression.Text)) throw new Exception();
                        double result = CalculateUtils.CalculateInfixExpression(txtUserExpression.Text, "x", 10);
                        formulaType = CalculationBLL.FORMULA_USER_DEFINED;
                        _editingSensor.FormulaFunction = txtUserExpression.Text.Trim();
                    }
                    catch (Exception)
                    {
                        throw new Exception("Biểu thức không hợp lệ!");
                    }

                }

                _editingSensor.ColumnIndex = columnIndexNumeric.Value.ToInt32TryParse();
                _editingSensor.Name = nameTextBox.Text;
                _editingSensor.Description = descriptionTextBox.Text;
                _editingSensor.Unit = unitTextBox.Text;

                _editingSensor.AlarmEnabled = enableAlarmCheckBox.Checked;
                _editingSensor.MinValue = string.IsNullOrEmpty(minAlarmTextBox.Text) ? null : (decimal?)minAlarmTextBox.Text.ToDecimalTryParse();
                _editingSensor.MaxValue = string.IsNullOrEmpty(maxAlarmTextBox.Text) ? null : (decimal?)maxAlarmTextBox.Text.ToDecimalTryParse();

                _editingSensor.FunctionParameters = functionParameters;
                _editingSensor.FormulaType = formulaType;
                // Add object
                if (_addEditState == STATE_ADDING)
                {
                    if (SensorBLL.Current.Insert(_editingSensor))
                    {
                        ShowSuccessMessage(Resources.Message_AddSensorSuccess);
                    }
                    prepareToAdd();
                    BindingData();
                    return;
                }
                // Edit object
                if (_addEditState == STATE_EDITING)
                {
                    if (SensorBLL.Current.Update(_editingSensor))
                    {
                        ShowSuccessMessage(Resources.Message_EditSensorSuccess);
                        //BindingData();
                    }
                    return;
                }
                if (_addEditState == STATE_BATCH_EDITING)
                {
                    if (ShowConfirmMessage("Bạn có muốn cập nhật đồng loạt " + sensorGridView.SelectedRows.Count +
                                           " sensors không?") == DialogResult.OK)
                    {
                        SensorBLL.Current.Validate(_editingSensor);
                        _editingSensor.LastEditedDate = DateTime.Now;
                        _editingSensor.LastEditedUser = AppContext.Current.LogedInUser.Username;
                        for (int i = 0; i < sensorGridView.SelectedRows.Count; i++)
                        {
                            int id = sensorGridView.SelectedRows[i].Cells["SensorID"].Value.ToInt32TryParse();
                            var obj = entityConntext.Sensors.SingleOrDefault(ent => ent.SensorID == id);
                            if (obj != null)
                            {
                                if (updateInfo.Checked)
                                {
                                    obj.Unit = _editingSensor.Unit;
                                }
                                if (updateCalc.Checked)
                                {
                                    obj.FunctionParameters = _editingSensor.FunctionParameters;
                                    obj.FormulaType = _editingSensor.FormulaType;
                                    obj.FormulaFunction = _editingSensor.FormulaFunction;
                                }
                                if (updateAlarm.Checked)
                                {
                                    obj.AlarmEnabled = _editingSensor.AlarmEnabled;
                                    obj.MinValue = _editingSensor.MinValue;
                                    obj.MaxValue = _editingSensor.MaxValue;
                                }
                                obj.LastEditedDate = _editingSensor.LastEditedDate;
                                obj.LastEditedUser = _editingSensor.LastEditedUser;
                            }
                        }
                        entityConntext.SaveChanges();
                        ShowSuccessMessage(Resources.Message_EditSensorSuccess);
                        BindingData();

                    }
                }
                return;
            }
            catch (Exception exception)
            {
                ShowErrorMessage(exception.Message);
                if (_addEditState == 1)
                    entityConntext.Refresh(RefreshMode.StoreWins, _editingSensor);
            }
        }
示例#13
0
        private void prepareToEdit()
        {
            if (sensorGridView.SelectedRows.Count == 0)
            {
                MessageBox.Show(Resources.Warning_NoRecordSelected);
                return;
            }
            _editingSensor = SensorBLL.Current.GetByID(sensorGridView.SelectedRows[0].Cells[0].Value.ToInt32TryParse());
            if (_editingSensor != null)
            {
                //_addEditState = 1;

                addEditTabs.Enabled = saveButton.Enabled = true;
                addEditTabs.SelectedTab = infoTab;

                columnIndexNumeric.Value = _editingSensor.ColumnIndex;
                nameTextBox.Text = _editingSensor.Name;
                descriptionTextBox.Text = _editingSensor.Description;
                unitTextBox.Text = unitLabel1.Text = unitLabel2.Text = _editingSensor.Unit;

                enableAlarmCheckBox.Checked = _editingSensor.AlarmEnabled;
                minAlarmTextBox.Text = _editingSensor.MinValue != null ? _editingSensor.MinValue.ToDecimalString() : "";
                maxAlarmTextBox.Text = _editingSensor.MaxValue != null ? _editingSensor.MaxValue.ToDecimalString() : "";

                // Load Calc Parameter
                if (!string.IsNullOrEmpty(_editingSensor.FunctionParameters))
                {
                    string[] parameters;
                    if (_editingSensor.FunctionParameters.Contains("#"))
                    {
                        parameters = _editingSensor.FunctionParameters.Split('#');
                    }
                    else
                    {
                        parameters = new string[] { _editingSensor.FunctionParameters };
                    }

                    switch (_editingSensor.FormulaType)
                    {
                        case CalculationBLL.FORMULA_LINEAR:
                            caclSelectTabs.SelectedTab = linearTab;
                            linear_C0.Text = parameters[0];
                            linear_C1.Text = parameters[1];
                            break;
                        case CalculationBLL.FORMULA_ARCTOLENGTH_DEGREE:
                            caclSelectTabs.SelectedTab = arcToLengthTab;
                            arc_Degree.Checked = true;
                            arc_Length.Text = parameters[0];
                            break;
                        case CalculationBLL.FORMULA_ARCTOLENGTH_RADIAN:
                            caclSelectTabs.SelectedTab = arcToLengthTab;
                            arc_Radian.Checked = true;
                            arc_Length.Text = parameters[0];
                            break;
                        case CalculationBLL.FORMULA_POLYNOMIAL:
                            caclSelectTabs.SelectedTab = polynomialTab;
                            poly_C0.Text = parameters[0];
                            poly_C1.Text = parameters[1];
                            poly_C2.Text = parameters[2];
                            poly_C3.Text = parameters[3];
                            poly_C4.Text = parameters[4];
                            poly_C5.Text = parameters[5];
                            break;
                        case CalculationBLL.FORMULA_TEMPRATURE_COMP:
                            caclSelectTabs.SelectedTab = temperatureCompTab;
                            temp_Tk.Text = parameters[0];
                            temp_Ti.Text = parameters[1];
                            setSelectedItem(temp_Tc, parameters[2]);//
                            temp_Tc.Text = SensorBLL.Current.GetByID(parameters[2].ToInt32TryParse()).Name;
                            temp_C0.Text = parameters[3];
                            temp_C1.Text = parameters[4];
                            temp_C2.Text = parameters[5];
                            temp_C3.Text = parameters[6];
                            temp_C4.Text = parameters[7];
                            temp_C5.Text = parameters[8];
                            break;
                        case CalculationBLL.FORMULA_VW_LINEAR:
                            caclSelectTabs.SelectedTab = vwLinearTab;
                            vwLinear_Tk.Text = parameters[0];
                            vwLinear_Ti.Text = parameters[1];
                            setSelectedItem(vwLinear_Tc, parameters[2]);//
                            vwLinear_CK.Text = parameters[3];
                            vwLinear_Li.Text = parameters[4];
                            vwLinear_Lm.Text = parameters[5];
                            vwLinear_Bi.Text = parameters[6];
                            setSelectedItem(vwLinear_Bc, parameters[7]);//
                            vwLinear_D.Text = parameters[8];
                            vwLinear_E.Text = parameters[9];
                            break;
                        case CalculationBLL.FORMULA_VW_POLY:
                            caclSelectTabs.SelectedTab = vwPoly;
                            vwPoly_Tk.Text = parameters[0];
                            vwPoly_Ti.Text = parameters[1];
                            setSelectedItem(vwPoly_Tc, parameters[2]);//
                            vwPoly_A.Text = parameters[3];
                            vwPoly_B.Text = parameters[4];
                            vwPoly_Lm.Text = parameters[5];
                            vwPoly_Bi.Text = parameters[6];
                            setSelectedItem(vwPoly_Bc, parameters[7]);//
                            vwPoly_C.Text = parameters[8];
                            vwPoly_D.Text = parameters[9];
                            vwPoly_E.Text = parameters[10];
                            break;
                        case CalculationBLL.FORMULA_USER_DEFINED:
                            break;
                    }
                }
                else if (_editingSensor.FormulaType == CalculationBLL.FORMULA_USER_DEFINED)
                {
                    caclSelectTabs.SelectedTab = tabUserDefine;
                    txtUserExpression.Text = _editingSensor.FormulaFunction;
                }
                //nameTextBox.Focus();

                // Batch Edit
                if (sensorGridView.SelectedRows.Count > 1)
                {
                    _addEditState = STATE_BATCH_EDITING;
                    nameTextBox.ReadOnly = columnIndexNumeric.ReadOnly = descriptionTextBox.ReadOnly = true;
                    updateInfo.Visible = updateCalc.Visible = updateAlarm.Visible = true;
                    updateInfo.Checked = updateCalc.Checked = updateAlarm.Checked = false;
                }
                else
                {
                    _addEditState = STATE_EDITING;
                    nameTextBox.ReadOnly = columnIndexNumeric.ReadOnly = descriptionTextBox.ReadOnly = false;
                    updateInfo.Visible = updateCalc.Visible = updateAlarm.Visible = false;
                }
            }
        }
示例#14
0
        private void prepareToAdd()
        {
            _addEditState = STATE_ADDING;
            _editingSensor = null;

            addEditTabs.Enabled = saveButton.Enabled = true;
            addEditTabs.SelectedTab = infoTab;
            nameTextBox.ReadOnly = columnIndexNumeric.ReadOnly = descriptionTextBox.ReadOnly = false;
            updateInfo.Visible = updateCalc.Visible = updateAlarm.Visible = false;

            nameTextBox.Text = unitTextBox.Text = descriptionTextBox.Text = unitLabel1.Text = unitLabel2.Text = "";
            columnIndexNumeric.Value = caclSelectTabs.SelectedIndex = 0;
            linear_C0.Text = linear_C1.Text = "";
            enableAlarmCheckBox.Checked = false;
            minAlarmTextBox.Text = maxAlarmTextBox.Text = "";
            nameTextBox.Focus();
        }
示例#15
0
 private string GetColumnName(Sensor sensor)
 {
     return sensor.SensorID + "-" + sensor.Name + " (" + sensor.Unit + ")";
 }
示例#16
0
        /// <summary>
        /// Read header, automatic add sensors' information to database
        /// </summary>
        /// <param name="logger"></param>
        public void ReadHeader(int loggerID)
        {
            using (var entityConntext = new GeoViewerEntities())
            {
                Logger logger = entityConntext.Loggers.SingleOrDefault(ent => ent.LoggerID == loggerID);
                if (logger == null) return;
                bool readFolder = !File.Exists(logger.DataPath);
                StreamReader streamReader;
                if (readFolder)
                {
                    DirectoryInfo directoryInfo = new DirectoryInfo(logger.DataPath);
                    if (!directoryInfo.Exists) throw new Exception(Properties.Resources.Error_Data_FileNotFound);
                    var files = directoryInfo.GetFiles();
                    if (files.Length == 0) throw new Exception(Properties.Resources.Error_Data_FileNotFound);
                    streamReader = new StreamReader(files[0].FullName, Encoding.UTF8);
                }
                else
                {
                    streamReader = new StreamReader(logger.DataPath, Encoding.UTF8);
                }

                var spiliter = new string[] { logger.Delimiter };
                // read meta line
                string firstline = streamReader.ReadLine();
                // check type of data file
                int type = 0;
                string[] cells = firstline.Split(spiliter, StringSplitOptions.None);
                if (cells[0].ToInt32TryParse() > 0 && cells[1].ToInt32TryParse() > 0)
                {
                    type = 1;
                }
                if (type == 0)
                {
                    logger.Meta = firstline;
                    // read header line
                    string header = streamReader.ReadLine();
                    // read after header line
                    string afterHeader = streamReader.ReadLine();
                    // read Units line
                    string units = streamReader.ReadLine();
                    string[] sensorNames = header.Split(spiliter, StringSplitOptions.RemoveEmptyEntries);
                    string[] sensorUnits = units.Split(spiliter, StringSplitOptions.RemoveEmptyEntries);
                    // Two colums for Timestamp and record number
                    for (int i = 2; i < sensorNames.Length; i++)
                    {
                        var sensor = new Sensor();

                        // Set project ID
                        sensor.ProjectID = logger.ProjectID;

                        sensor.Logger = logger;
                        sensor.ColumnIndex = i;
                        sensor.Name = CleanValue(sensorNames[i]);
                        sensor.Unit = sensorUnits.Length >= i ? CleanValue(sensorUnits[i]) : "";
                        sensor.CreatedDate = sensor.LastEditedDate = DateTime.Now;
                        sensor.CreatedUser = sensor.LastEditedUser = AppContext.Current.LogedInUser.Username;
                        logger.Sensors.Add(sensor);
                    }
                    logger.TotalSensor = sensorNames.Length - 2;

                }
                else if (type == 1)
                {
                    logger.Meta = "DS Index: " + cells[0] + "; IP Address: " + cells[4] + "#";
                    logger.TotalSensor = cells.Length - 5;
                    for (int i = 5; i < cells.Length; i++)
                    {
                        var sensor = new Sensor();
                        sensor.Logger = logger;
                        // Set project ID
                        sensor.ProjectID = logger.ProjectID;

                        sensor.ColumnIndex = i;
                        sensor.Name = "Column " + (i);
                        sensor.Unit = "Unit " + (i);
                        sensor.CreatedDate = sensor.LastEditedDate = DateTime.Now;
                        sensor.CreatedUser = sensor.LastEditedUser = AppContext.Current.LogedInUser.Username;
                        logger.Sensors.Add(sensor);
                    }
                }
                streamReader.Close();
                entityConntext.SaveChanges();
                //AppContext.Current.RefreshEntityContext();

            }
        }
示例#17
0
        private void ChartGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0) return;
            // Modify by binhpro 19/10/2012
            int id = ChartGridView.Rows[e.RowIndex].Cells[0].Value.ToInt32TryParse();
            if (combochart.SelectedIndex == 0)
            {
                _sensor = SensorBLL.Current.GetByID(id);
                _group = null;
                _pictureView = null;
            }
            else if (combochart.SelectedIndex == 1)
            {
                _group = ChartViewBLL.Current.GetGroupByID(id);
                _sensor = null;
                _pictureView = null;

            }
            else if (combochart.SelectedIndex == 2)
            {
                _pictureView =
                    PictureViewBLL.Current.GetByID(id);
                _sensor = null;
                _group = null;
            }
            BindingData();
        }
示例#18
0
        /// <summary>
        /// Pass params to build the chart on start up, set null (is default) for nothing display
        /// </summary>
        /// <param name="sensor"></param>
        /// <param name="group"></param>
        /// <param name="pictureView"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="chartName"></param>
        /// <param name="xLabel"></param>
        /// <param name="yLabel"></param>
        /// <param name="showCalcValue"></param>
        public ChartViewForm(Sensor sensor = null, Group group = null, PictureView pictureView = null, DateTime? startDate = null,
                             DateTime? endDate = null, string chartName = "Chart View", string xLabel = "Value", string yLabel = "Datetime", bool showCalcValue = true)
        {
            // set value to private field
            _sensor = sensor;
            _group = group;
            // ...
            // continue here
            InitializeComponent();
            GraphPane myPane;
            LineItem mycurve;
            Random randomGen = new Random();
            myPane = zedChartMain.GraphPane;
            myPane.XAxis.Type = AxisType.Date;
            myPane.XAxis.Scale.Format = "HH:mm:ss\ndd-MM-yyyy";
            myPane.Title.Text = chartName;
            myPane.XAxis.Title.Text = xLabel;
            myPane.YAxis.Title.Text = yLabel;
            myPane.XAxis.MajorGrid.IsVisible = true;
            myPane.YAxis.MajorGrid.IsVisible = true;

            if (sensor != null)
            {
                List<SensorValue> listvalue = entityConntext.SensorValues.Where(ent => ent.SensorID == sensor.SensorID).ToList();
                DataSourcePointList dsp = new DataSourcePointList();
                dsp.DataSource = listvalue;
                if (!showCalcValue)
                {
                    dsp.YDataMember = "RawValue";
                }
                if (showCalcValue)
                {
                    dsp.YDataMember = "CalcValue";
                }
                dsp.XDataMember = "MeaTime";

                mycurve = myPane.AddCurve(sensor.Name, dsp, Color.FromArgb(randomGen.Next(255), randomGen.Next(255), randomGen.Next(255)));
                mycurve.Line.Width = 1;
            }

            if (group != null)
            {
                List<Sensor> sensorsInGroup = group.Sensors.ToList();
                for (int i = 0; i < sensorsInGroup.Count; i++)
                {
                    int idsen = Convert.ToInt16(sensorsInGroup[i].SensorID);
                    List<SensorValue> listvalue = entityConntext.SensorValues.Where(ent => ent.SensorID == idsen).ToList();

                    DataSourcePointList dsp = new DataSourcePointList();
                    dsp.DataSource = listvalue;
                    if (!showCalcValue)
                    {
                        dsp.YDataMember = "RawValue";
                    }
                    if (showCalcValue)
                    {
                        dsp.YDataMember = "CalcValue";
                    }
                    dsp.XDataMember = "MeaTime";

                    mycurve = myPane.AddCurve(sensorsInGroup[i].Name, dsp, Color.FromArgb(randomGen.Next(255), randomGen.Next(255), randomGen.Next(255)));
                    mycurve.Line.Width = 1;

                }
            }

            //lenh hien thi chart
            zedChartMain.IsShowPointValues = true;
            zedChartMain.AxisChange();
            zedChartMain.Invalidate();
            zedChartMain.Refresh();
        }
示例#19
0
 private void Searching()
 {
     _sensor = sensorCombo.SelectedIndex == -1 ? null : SensorBLL.Current.GetByID(sensorCombo.SelectedValue.ToInt32TryParse());
     _startDate = fromdateTextBox.Text.ToDateTimeTryParse(null);
     _endDate = todateTextBox.Text.ToDateTimeTryParse(null);
     if (endedRadio.Checked)
         _isEnded = true;
     else if (runningRadio.Checked)
         _isEnded = false;
     else
         _isEnded = null;
     ReloadGrid();
 }