public ActionResult DeleteConfirmed(Guid id)
        {
            List<Object> logList = new List<Object>();
            ViewData["ValidationErrorMessage"] = String.Empty;

            try
            {
                SignalAppliance signalAppliance = dbSA.GetById(id);

                IRepository<MappingTag> dbMT = new MappingTagRepository();
                IRepository<Monitoring> dbM = new MonitoringRepository();
                IRepository<Appliance> dbA = new ApplianceRepository();
                IRepository<Signal> dbS = new SignalRepository();

                int associatedRecords = (from mapp in dbMT.GetAll()
                                        join mon in dbM.GetAll() on mapp.Id equals mon.MappingTag.Id
                                        where mapp.Signal.Id.Equals(signalAppliance.Signal.Id)
                                           && mapp.Appliance.Id.Equals(signalAppliance.Appliance.Id)
                                        select mon.Id).Count();

                if (associatedRecords == 0)
                {

                    var signalAppliancesValues = dbSAppV.GetByProperty("SignalAppliance.Id", id);

                    foreach (var signalApplianceValue in signalAppliancesValues)
                    {
                        dbSAppV.Delete(signalApplianceValue.Id);
                    }

                    dbSA.Delete(id);

                    logList.Add(log.GetNewLog(ConfigurationManager.AppSettings["DeleteText"] +
                                              ControllerContext.RouteData.Values["controller"] +
                                              "(Id=" + DotNetToOracle(signalAppliance.Id.ToString()).Replace("-", "").ToUpper() +
                                              " - SignalName=" + dbS.GetById(signalAppliance.Signal.Id).Name +
                                              " - ApplianceName=" + dbA.GetById(signalAppliance.Appliance.Id).NameAppliance +
                                              " - Tolerance=" + signalAppliance.Tolerance + ")",
                                              (int)EventTypes.Delete,
                                              (int)Session["UserId"]));
                    log.Write(logList);
                }
                else
                {
                    ViewData["ValidationErrorMessage"] = ConfigurationManager.AppSettings["CannotDeleteHasAssociatedRecords"];

                    logList.Add(log.GetNewLog(ConfigurationManager.AppSettings["DeleteText"] +
                                              ConfigurationManager.AppSettings["CannotDeleteHasAssociatedRecords"] + " " +
                                              ControllerContext.RouteData.Values["controller"] +
                                              "(Id=" + DotNetToOracle(signalAppliance.Id.ToString()).Replace("-", "").ToUpper() +
                                              " - SignalName=" + dbS.GetById(signalAppliance.Signal.Id).Name +
                                              " - ApplianceName=" + dbA.GetById(signalAppliance.Appliance.Id).NameAppliance +
                                              " - Tolerance=" + signalAppliance.Tolerance + ")",
                                              (int)EventTypes.Delete,
                                              (int)Session["UserId"]));
                    log.Write(logList);

                    int differentialPressure = int.Parse(ConfigurationManager.AppSettings["DifferentialPressure"]);
                    int temperature = int.Parse(ConfigurationManager.AppSettings["Temperature"]);
                    int rh = int.Parse(ConfigurationManager.AppSettings["RH"]);

                    string measureUnit = "N/A";

                    if (signalAppliance.Signal.Id == differentialPressure)
                    {
                        measureUnit = ConfigurationManager.AppSettings["Percentage"].ToString();
                    }
                    else if (signalAppliance.Signal.Id == temperature)
                    {
                        measureUnit = ConfigurationManager.AppSettings["DegreeCelsius"].ToString();
                    }
                    else if (signalAppliance.Signal.Id == rh)
                    {
                        measureUnit = ConfigurationManager.AppSettings["InchesOfWater"].ToString();
                    }

                    Dictionary<string, object> properties = new Dictionary<string, object>();
                    properties.Add("SignalAppliance.Id", signalAppliance.Id);

                    float setPoint = 0, highValue = 0, lowValue = 0;

                    foreach (SignalApplianceValue signalApplianceValue in dbSAppV.GetByProperties(properties))
                    {
                        if (signalApplianceValue.AlarmType.Id == int.Parse(ConfigurationManager.AppSettings["NormalAlarmId"]))
                        {
                            setPoint = signalApplianceValue.Value;
                        }
                        else if (signalApplianceValue.AlarmType.Id == int.Parse(ConfigurationManager.AppSettings["HighAlarmId"]))
                        {
                            highValue = signalApplianceValue.Value;
                        }
                        else if (signalApplianceValue.AlarmType.Id == int.Parse(ConfigurationManager.AppSettings["LowAlarmId"]))
                        {
                            lowValue = signalApplianceValue.Value;
                        }
                    }

                    ViewBag.ApplianceName = dbA.GetById(dbSA.GetById(id).Appliance.Id).NameAppliance;
                    ViewBag.HighValue = highValue;
                    ViewBag.LowValue = lowValue;
                    ViewBag.MeasureUnit = measureUnit;
                    ViewBag.SetPoint = setPoint;
                    ViewBag.SignalName = dbS.GetById(dbSA.GetById(id).Signal.Id).Name;

                    return View(signalAppliance);
                }
            }
            catch (GenericADOException ex)
            {
                ViewData["ValidationErrorMessage"] = ConfigurationManager.AppSettings["CannotDeleteHasAssociatedRecords"];

                logList.Add(log.GetNewLog(ConfigurationManager.AppSettings["DeleteText"] + ex.InnerException.Message, (int)EventTypes.Delete, (int)Session["UserId"]));
                log.Write(logList);

                SignalAppliance signalAppliance = dbSA.GetById(id);

                int differentialPressure = int.Parse(ConfigurationManager.AppSettings["DifferentialPressure"]);
                int temperature = int.Parse(ConfigurationManager.AppSettings["Temperature"]);
                int rh = int.Parse(ConfigurationManager.AppSettings["RH"]);

                string measureUnit = "N/A";

                if (signalAppliance.Signal.Id == differentialPressure)
                {
                    measureUnit = ConfigurationManager.AppSettings["Percentage"].ToString();
                }
                else if (signalAppliance.Signal.Id == temperature)
                {
                    measureUnit = ConfigurationManager.AppSettings["DegreeCelsius"].ToString();
                }
                else if (signalAppliance.Signal.Id == rh)
                {
                    measureUnit = ConfigurationManager.AppSettings["InchesOfWater"].ToString();
                }

                Dictionary<string, object> properties = new Dictionary<string, object>();
                properties.Add("SignalAppliance.Id", signalAppliance.Id);

                float setPoint = 0, highValue = 0, lowValue = 0;

                foreach (SignalApplianceValue signalApplianceValue in dbSAppV.GetByProperties(properties))
                {
                    if (signalApplianceValue.AlarmType.Id == int.Parse(ConfigurationManager.AppSettings["NormalAlarmId"]))
                    {
                        setPoint = signalApplianceValue.Value;
                    }
                    else if (signalApplianceValue.AlarmType.Id == int.Parse(ConfigurationManager.AppSettings["HighAlarmId"]))
                    {
                        highValue = signalApplianceValue.Value;
                    }
                    else if (signalApplianceValue.AlarmType.Id == int.Parse(ConfigurationManager.AppSettings["LowAlarmId"]))
                    {
                        lowValue = signalApplianceValue.Value;
                    }
                }

                ViewBag.ApplianceName = dbA.GetById(dbSA.GetById(id).Appliance.Id).NameAppliance;
                ViewBag.HighValue = highValue;
                ViewBag.LowValue = lowValue;
                ViewBag.MeasureUnit = measureUnit;
                ViewBag.SetPoint = setPoint;
                ViewBag.SignalName = dbS.GetById(dbSA.GetById(id).Signal.Id).Name;

                return View(signalAppliance);
            }
            catch (Exception ex)
            {
                ViewData["ValidationErrorMessage"] = ConfigurationManager.AppSettings["UnknownError"];

                logList.Add(log.GetNewLog(ConfigurationManager.AppSettings["DeleteText"] + ex.InnerException.Message, (int)EventTypes.Delete, (int)Session["UserId"]));
                log.Write(logList);

                return View();
            }

            return RedirectToAction("Index");
        }
Exemplo n.º 2
0
        public void ListMonitoringRecordsForInbox()
        {
            IRepository<SignalAppliance> dbSA = new SignalApplianceRepository();
            IRepository<MappingTag> dbMapT = new MappingTagRepository();
            IRepository<Monitoring> dbMon = new MonitoringRepository();
            IRepository<Signal> dbS = new SignalRepository();
            IRepository<Appliance> dbApp = new ApplianceRepository();
            IRepository<SignalApplianceValue> dbSAppV = new SignalApplianceValueRepository();
            IRepository<AlarmType> dbAT = new AlarmTypeRepository();
            IRepository<Area> dbA = new AreaRepository();

            var monRecords = from r in (
                                          from mon in dbMon.GetAll()
                                          join mapp in dbMapT.GetAll() on mon.MappingTag.Id equals mapp.Id
                                        select new { monDatetime = mon.DateTime, appId = mapp.Appliance.Id, sigId = mapp.Signal.Id, pv =  (mapp.AlarmType.Id.Equals(Convert.ToInt32("1")) ? mon.Value: 0 ), alarm = (mon.Value == 1 && !mapp.AlarmType.Id.Equals(Convert.ToInt32("1")) ? mapp.AlarmType.Id : 0 ) ,userId = mon.User.Id})
                            group r by new {r.monDatetime, r.appId, r.sigId, r.userId} into g
                           select new { monRecord = g.Key, monValue = g.Sum(d => d.pv), alarm = g.Sum(d => d.alarm) };

            var result = from m in monRecords
                         join mon in dbMon.GetAll() on m.monRecord.monDatetime equals mon.DateTime
                         join mapp in dbMapT.GetAll() on new { mapId = mon.MappingTag.Id, appId = m.monRecord.appId, sigId = m.monRecord.sigId } equals new { mapId = mapp.Id, appId = mapp.Appliance.Id, sigId = mapp.Signal.Id }
                         where (m.alarm == 0 ? 1 : m.alarm) == mapp.AlarmType.Id
                         select new { monId = mon.Id, dateTime = m.monRecord.monDatetime, appId = m.monRecord.appId, sigId = m.monRecord.sigId, alarm = m.alarm, monValue = m.monValue, userId = m.monRecord.userId };

            /*
                to_char(tmp.datetime, 'yyyy/mm/dd hh24:mi:ss') mon_datetime, area.are_name, sig.sig_name,
                decode(tmp.alarm, 'A', 'Alta', 'B', 'Baja', 'N', 'Normal', 'Desconodido') ala_typ_name,
                smcl_get_appl_signal_comment(tmp.datetime, tmp.app_id, tmp.sig_id, tmp.alarm) mon_comment_on_alarm,
                appl.app_name, case when tmp.sig_id = 1 then round_half_way_down(trunc(tmp.mon_value, 3), 2) else round_half_way_down(trunc(tmp.mon_value, 2), 1) end mon_value ,
                tmp.sig_id, usr.usr_first_name || ' ' || usr.usr_last_name_1 || '(' || usr.usr_login_email || ')' username,
             */
            //group new {a.Id, a.NameAlarmType, sapv.Value } by new {sa.Id, app.NameAppliance, s.Name, sa.Tolerance} into g
            //select new { signalAppliance = g.Key, setPoint = from v in g where v.Id == 1 select v.Value, highValue = from v in g where v.Id == 2 select v.Value, lowValue = from v in g where v.Id == 3 select v.Value };

            ObjectDumper.Write(result.Count());

            foreach (var v in result)
            {
                ObjectDumper.Write(v);
            }
        }