Esempio n. 1
0
        public ActionResult Ac(int? Id = null)
        {
            AcAlert alertModel = new AcAlert();

            try
            {
                ScheduleViewModel sVM = new ScheduleViewModel();
                sVM.SelectedAlertType = DeviceAlarmType.AcAlarm;

                sVM = new AlertData().GetAlertDetails(sVM, Id);
                AlertBase alertData = sVM.AlertDatas.FirstOrDefault() as AlertBase;

                if (alertData == null)
                {
                    alertData = new AlertBase()
                    {
                        Id = 0,
                        Conditions = new List<Tracker.Common.Condition>(),
                        IsActive = false
                    };
                }

                bool IsOnAc = false;

                if (alertData.Conditions.Where(m => m.Operand == "OnAc").FirstOrDefault() != null)
                {
                    IsOnAc = Convert.ToBoolean(Convert.ToInt32(alertData.Conditions.Where(m => m.Operand == "OnAc").FirstOrDefault().Value));
                }
                else
                {
                    IsOnAc = false;
                }

                alertModel = new AcAlert()
                {
                    Id = alertData.Id,
                    IsActive = alertData.IsActive,
                    IsOnAc = IsOnAc,
                    Devices = new List<DeviceDetailSelection>()
                };
                List<DeviceDetailSelection> availableDevices = new AlertData().GetAvailableDevices();
                List<string> activeDevices = new AlertData().GetDevicesForAlert(alertData.Id);
                if (availableDevices != null && availableDevices.Count > 0)
                {
                    alertModel.Devices = availableDevices.Select(m => new DeviceDetailSelection
                    {
                        DeviceId = m.DeviceId,
                        VehicleId = m.VehicleId,
                        Checked = activeDevices.Contains(m.DeviceId)
                    }).ToList();
                }
            }
            catch (Exception ex)
            {
            }
            return View(alertModel);
        }
Esempio n. 2
0
        public ScheduleViewModel GetAlertData(ScheduleViewModel svm)
        {
            DataTable alertsDt = new DataTable();
            try
            {
                List<SqlParameter> dbParams = new List<SqlParameter>();
                dbParams.Add(new SqlParameter("DeviceId", svm.SelectedDevice));
                dbParams.Add(new SqlParameter("AlertType", svm.SelectedAlertType));

                alertsDt = Data.GetData(DataBase.Api,
                    System.Data.CommandType.StoredProcedure, "Master_GetDeviceAlert", dbParams.ToArray());
            }
            catch (Exception ex)
            {
            }

            if (alertsDt != null)
            {
                switch (svm.SelectedAlertType)
                {
                    case DeviceAlarmType.PowerCutAlarm:
                        {
                            var alertDatas = new List<object>();

                            foreach (var aDt in alertsDt.AsEnumerable())
                            {
                                alertDatas.Add(new AlertBase()
                                {
                                    Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)),
                                    Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")),
                                    IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false)
                                });
                            }
                            svm.AlertDatas = alertDatas;
                            break;
                        }
                    case DeviceAlarmType.SOSAlarm:
                        {
                            var alertDatas = new List<object>();
                            foreach (var aDt in alertsDt.AsEnumerable())
                            {
                                alertDatas.Add(new AlertBase()
                                {
                                    Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)),
                                    Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")),
                                    IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false)
                                });
                            }
                            svm.AlertDatas = alertDatas;
                            break;
                        }
                    case DeviceAlarmType.SpeedAlarm:
                        {
                            var alertDatas = new List<object>();
                            foreach (var aDt in alertsDt.AsEnumerable())
                            {
                                alertDatas.Add(new AlertBase()
                                {
                                    Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)),
                                    Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")),
                                    IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false)
                                });
                            }
                            svm.AlertDatas = alertDatas;
                            break;
                        }

                    //case DeviceAlarmType.BreakAlarm:
                    //    _AlertData = new BreakAlert();
                    //    break;
                    case DeviceAlarmType.VibrationAlarm:
                        {
                            var alertDatas = new List<object>();
                            foreach (var aDt in alertsDt.AsEnumerable())
                            {
                                alertDatas.Add(new AlertBase()
                                {
                                    Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)),
                                    Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")),
                                    IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false)
                                });
                            }
                            svm.AlertDatas = alertDatas;
                            break;
                        }
                    case DeviceAlarmType.FenceAlarm:
                    case DeviceAlarmType.FenceInAlarm:
                    case DeviceAlarmType.FenceOutAlarm:
                        {
                            var alertDatas = new List<object>();
                            foreach (var aDt in alertsDt.AsEnumerable())
                            {
                                var FenceList = new List<ATFPosition>();
                                try
                                {
                                    var fenceListDt = Data.GetData(DataBase.Api,
                                        System.Data.CommandType.StoredProcedure, "Master_GetFenceList",
                                        new SqlParameter[] {
                                            new SqlParameter("DeviceAlertId", aDt["Id"])
                                        });

                                    FenceList = fenceListDt.AsEnumerable().Select(m => new ATFPosition()
                                    {
                                        Lat = Convert.ToString(m["Latitude"]),
                                        Lang = Convert.ToString(m["Longitude"]),
                                        Distance = (float)Convert.ToDouble(m["Distance"]),
                                        ListOrder = Convert.ToInt32(m["ListOrder"])
                                    }).ToList();
                                }
                                catch (Exception ex)
                                {

                                }

                                alertDatas.Add(new AlertBase()
                                {
                                    Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)),

                                    Name = Convert.ToString(aDt["Name"]),
                                    DescriptionText = Convert.ToString(aDt["DescriptionText"]),

                                    Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")),
                                    IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false),

                                    FenceList = FenceList ?? new List<ATFPosition>()
                                });
                            }
                            svm.AlertDatas = alertDatas;
                        }
                        break;
                    case DeviceAlarmType.MovingAlarm:
                        {
                            var alertDatas = new List<object>();
                            foreach (var aDt in alertsDt.AsEnumerable())
                            {
                                var _aData = new AlertBase()
                                {
                                    Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)),
                                    Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")),
                                    IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false)
                                };
                                _aData.Conditions.RemoveAll(a => a.Operand.ToLower() == "onacc");
                                alertDatas.Add(_aData);
                            }
                            svm.AlertDatas = alertDatas;
                            break;
                        }
                    case DeviceAlarmType.AccAlarm:
                        {
                            var alertDatas = new List<object>();
                            foreach (var aDt in alertsDt.AsEnumerable())
                            {
                                alertDatas.Add(new AlertBase()
                                {
                                    Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)),
                                    Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")),
                                    IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false)
                                });
                            }
                            svm.AlertDatas = alertDatas;
                            break;
                        }
                    case DeviceAlarmType.StopAlarm:
                        {
                            var alertDatas = new List<object>();
                            foreach (var aDt in alertsDt.AsEnumerable())
                            {
                                var _aData = new AlertBase()
                                {
                                    Id = Convert.ToInt32((aDt["Id"] != DBNull.Value ? aDt["Id"] : 0)),
                                    Conditions = Tracker.Common.AlertData.DeSerializeCondition(Convert.ToString(aDt["Eval"] != DBNull.Value ? aDt["Eval"] : "")),
                                    IsActive = Convert.ToBoolean(aDt["IsActive"] != DBNull.Value ? aDt["IsActive"] : false)
                                };
                                alertDatas.Add(_aData);
                            }
                            svm.AlertDatas = alertDatas;
                            break;
                        }
                    default:
                        break;
                }
            }
            return svm;
        }
Esempio n. 3
0
        public ActionResult Ac(AcAlert alertModel)
        {
            ScheduleViewModel sVM = new ScheduleViewModel();
            sVM.SelectedAlertType = DeviceAlarmType.AcAlarm;

            sVM.AlertDatas = new List<object>();
            AlertBase alertData = new AlertBase()
            {
                Id = alertModel.Id,
                IsActive = alertModel.IsActive,
                Conditions = new List<Tracker.Common.Condition>() {
                    new Tracker.Common.Condition() {
                        Operand = "OnAc",
                        Value = alertModel.IsOnAc == true ? "1" : "0"
                    }
                }
            };

            sVM.AlertDatas.Add(alertData);

            if (new AlertData().SaveAlertData(sVM))
            {
                int updateId = 0;
                if (int.TryParse(sVM.SelectedAlertId, out updateId))
                {
                    alertModel.Id = updateId;
                    if (alertModel.Devices != null && alertModel.Devices.Count > 0)
                    {
                        alertModel.Devices.ForEach(d =>
                        {
                            try
                            {
                                new AlertData().SaveDevicesForAlert(alertModel.Id, d.DeviceId, !d.Checked);
                            }
                            catch (Exception ex)
                            {
                            }
                        });
                    }
                }
                ViewBag.AlertWriteStatus = "Success";
            }
            else
            {
                ViewBag.AlertWriteStatus = "Failed";
            }

            return View(alertModel);
        }
Esempio n. 4
0
        public ActionResult Stoppage(StoppageAlert alertModel)
        {
            {
                ScheduleViewModel sVM = new ScheduleViewModel();
                sVM.SelectedAlertType = DeviceAlarmType.StopAlarm;

                sVM.AlertDatas = new List<object>();
                AlertBase alertData = new AlertBase()
                {
                    Id = alertModel.Id,
                    Name = alertModel.Name,
                    DescriptionText = alertModel.Description,
                    IsActive = alertModel.IsActive,
                    Conditions = new List<Tracker.Common.Condition>() {
                        new Tracker.Common.Condition() {
                            Operand = "Speed",
                            Operator = "==",
                            Value = "0",
                            Conjunction = Tracker.Common.ConjunctionType.AND
                        },
                        new Tracker.Common.Condition() {
                            Operand = "Duration",
                            Operator = "<=",
                            Value = alertModel.Duration.ToString()
                        }
                    }
                };

                sVM.AlertDatas.Add(alertData);

                if (new AlertData().SaveAlertData(sVM))
                {
                    int updateId = 0;
                    if (int.TryParse(sVM.SelectedAlertId, out updateId))
                    {
                        alertModel.Id = updateId;
                        if (alertModel.Devices != null && alertModel.Devices.Count > 0)
                        {
                            alertModel.Devices.ForEach(d =>
                            {
                                try
                                {
                                    new AlertData().SaveDevicesForAlert(alertModel.Id, d.DeviceId, !d.Checked);
                                }
                                catch (Exception ex)
                                {
                                }
                            });
                        }
                    }
                    ViewBag.AlertWriteStatus = "Success";
                }
                else
                {
                    ViewBag.AlertWriteStatus = "Failed";
                }

                return View(alertModel);
            }
        }
Esempio n. 5
0
        public ActionResult Stoppage(int Id = 0)
        {
            StoppageAlert alertModel = new StoppageAlert();

            try
            {
                ScheduleViewModel sVM = new ScheduleViewModel();
                sVM.SelectedAlertType = DeviceAlarmType.StopAlarm;

                sVM = new AlertData().GetAlertDetails(sVM, Id);

                AlertBase alertData = sVM.AlertDatas.FirstOrDefault() as AlertBase;

                if (alertData == null)
                {
                    alertData = new AlertBase()
                    {
                        Id = 0,
                        Conditions = new List<Tracker.Common.Condition>(),
                        IsActive = false
                    };
                }

                int Duration = 5;
                string SpeedComparer = string.Empty;

                if (alertData.Conditions.Where(m => m.Operand == "Duration").FirstOrDefault() != null)
                {
                    Duration = Convert.ToInt32(alertData.Conditions.Where(m => m.Operand == "Duration").FirstOrDefault().Value);
                }

                alertModel = new StoppageAlert()
                {
                    Id = alertData.Id,
                    Name = alertData.Name,
                    Description = alertData.DescriptionText,
                    IsActive = alertData.IsActive,
                    Duration = Duration,
                    Devices = new List<DeviceDetailSelection>()
                };
                List<DeviceDetailSelection> availableDevices = new AlertData().GetAvailableDevices();
                List<string> activeDevices = new AlertData().GetDevicesForAlert(alertData.Id);
                if (availableDevices != null && availableDevices.Count > 0)
                {
                    alertModel.Devices = availableDevices.Select(m => new DeviceDetailSelection
                    {
                        DeviceId = m.DeviceId,
                        VehicleId = m.VehicleId,
                        Checked = activeDevices.Contains(m.DeviceId)
                    }).ToList();
                }
            }
            catch (Exception ex)
            {
            }
            return View(alertModel);
        }
Esempio n. 6
0
        public ActionResult Fence(FenceAlert alertModel)
        {
            {
                ScheduleViewModel sVM = new ScheduleViewModel();
                //sVM.SelectedAlertType = DeviceAlarmType.FenceAlarm;
                sVM.SelectedAlertType = alertModel.FenceType;

                sVM.AlertDatas = new List<object>();
                AlertBase alertData = new AlertBase()
                {
                    Id = alertModel.Id,
                    Name = alertModel.Name,
                    DescriptionText = alertModel.Description,
                    IsActive = alertModel.IsActive,
                    FenceListStr = alertModel.PointsStr
                };

                sVM.AlertDatas.Add(alertData);

                if (new AlertData().SaveAlertData(sVM))
                {
                    int updateId = 0;
                    if (int.TryParse(sVM.SelectedAlertId, out updateId))
                    {
                        alertModel.Id = updateId;
                        try
                        {
                            alertModel.Points = (sVM.AlertDatas[0] as AlertBase).FenceList;
                        }
                        catch (Exception aBEx)
                        {
                        }

                        if (alertModel.Devices != null && alertModel.Devices.Count > 0)
                        {
                            alertModel.Devices.ForEach(d =>
                            {
                                try
                                {
                                    new AlertData().SaveDevicesForAlert(alertModel.Id, d.DeviceId, !d.Checked);
                                }
                                catch (Exception ex)
                                {
                                }
                            });
                        }
                    }
                    ViewBag.AlertWriteStatus = "Success";
                }
                else
                {
                    ViewBag.AlertWriteStatus = "Failed";
                }

                return View(alertModel);
            }
        }
Esempio n. 7
0
        public ActionResult Fence(int Id = 0)
        {
            FenceAlert alertModel = new FenceAlert();

            try
            {
                ScheduleViewModel sVM = new ScheduleViewModel();
                sVM.SelectedAlertType = DeviceAlarmType.FenceAlarm;

                sVM = new AlertData().GetAlertDetails(sVM, Id);

                AlertBase alertData = sVM.AlertDatas.FirstOrDefault() as AlertBase;

                if (alertData == null)
                {
                    alertData = new AlertBase()
                    {
                        Id = 0,
                        Conditions = new List<Tracker.Common.Condition>(),
                        IsActive = false
                    };
                }

                alertModel = new FenceAlert()
                {
                    Id = alertData.Id,
                    Name = alertData.Name,
                    Description = alertData.DescriptionText,
                    IsActive = alertData.IsActive,
                    FenceType = (Id == 0) ? DeviceAlarmType.FenceInAlarm : sVM.SelectedAlertType,
                    Points = alertData.FenceList,
                    Devices = new List<DeviceDetailSelection>()
                };
                List<DeviceDetailSelection> availableDevices = new AlertData().GetAvailableDevices();
                List<string> activeDevices = new AlertData().GetDevicesForAlert(alertData.Id);
                if (availableDevices != null && availableDevices.Count > 0)
                {
                    alertModel.Devices = availableDevices.Select(m => new DeviceDetailSelection
                    {
                        DeviceId = m.DeviceId,
                        VehicleId = m.VehicleId,
                        Checked = activeDevices.Contains(m.DeviceId)
                    }).ToList();
                }
            }
            catch (Exception ex)
            {
            }
            return View(alertModel);
        }