public List <ProximityLog> GetProximityLog() { List <ProximityLog> ReturnObject = new List <ProximityLog>(); ProximityLog ins; DataBaseConnection dbConn = new DataBaseConnection(); var table = GetCompaniesDBVariable(); if (table != null) { using (var con = dbConn.SqlConn()) { con.Open(); using (SqlCommand cmd = new SqlCommand("exec " + CommonStrings.GetProximityLog + " @Companies", con)) { var pList = new SqlParameter("@Companies", SqlDbType.Structured); pList.TypeName = "dbo.IntList"; pList.Value = table; cmd.Parameters.Add(pList); using (var drI = cmd.ExecuteReader()) { while (drI.Read()) { ins = new ProximityLog(); ins.ProximityId = Convert.ToInt32(drI["ProximityId"]); ins.AnimalConnectedTo = Convert.ToInt32(drI["AnimalConnectedTo"]); ins.AnimalInProximity = Convert.ToInt32(drI["AnimalInProximity"]); ins.DeviceConnectedTo = Convert.ToInt32(drI["DeviceConnectedTo"]); ins.DeviceInProximity = Convert.ToInt32(drI["DeviceInProximity"]); ins.LogDate = Convert.ToDateTime(drI["LogDate"]); ins.ProximityEnded = Convert.ToDateTime(drI["ProximityEnded"]); ins.ProximityStarted = Convert.ToDateTime(drI["ProximityStarted"]); ins._AnimalConnectedTo = drI["AnimalA"].ToString(); ins._AnimalInProximity = drI["AnimalB"].ToString(); ins._Company = drI["Company"].ToString(); ins._DeviceConnectedTo = drI["DeviceA"].ToString(); ins._DeviceInProximity = drI["DeviceB"].ToString(); ins.SecondsConnected = Math.Round((ins.ProximityEnded - ins.ProximityStarted).TotalSeconds, 2); ReturnObject.Add(ins); } } } } } return(ReturnObject); }
public ActionResult LogProximity(string DeviceReceivedAddress, string DeviceConnectedAddress, DateTime ConncetionStart, DateTime ConnectionEnd) { ProximityLog ins = new ProximityLog(); ins.ProximityStarted = ConncetionStart; ins.ProximityEnded = ConnectionEnd; //...Check if DeviceReceivedAddress is in Database ins.DeviceConnectedTo = logRep.GetDeviceId(DeviceReceivedAddress); if(ins.DeviceConnectedTo != -1) { //... Check if DeviceConnectedAddress is in Database ins.DeviceInProximity = logRep.GetDeviceId(DeviceConnectedAddress); if (ins.DeviceInProximity != -1) { //...Check if Device is Connected to Animal ins.AnimalConnectedTo = logRep.GetAnimalId(ins.DeviceConnectedTo); if(ins.AnimalConnectedTo != -1) { //...Check if Device is Connected to Animal ins.AnimalInProximity = logRep.GetAnimalId(ins.DeviceInProximity); if(ins.AnimalInProximity != -1) { //...Log Proximity if(logRep.LogProximity(ins)) return Content(CommonStrings.Success, "text/html"); else return Content(CommonStrings.Error_DBFail, "text/html"); } else { return Content(CommonStrings.Error_DeviceConnectedNotConnectedToAnimal, "text/html"); } } else { return Content(CommonStrings.Error_DeviceReceivedNotConnectedToAnimal, "text/html"); } } else { return Content(CommonStrings.Error_DeviceConnected, "text/html"); } } else { return Content(CommonStrings.Error_DeviceReceived, "text/html"); } return Content(CommonStrings.Error, "text/html"); }
public bool LogProximity(ProximityLog ins) { bool success = false; ProximityLog ReturnObject = new ProximityLog(); DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); con.Open(); SqlCommand cmdI = con.CreateCommand(); SqlTransaction trx = con.BeginTransaction(CommonStrings.InsertTransaction); cmdI.Connection = con; cmdI.Transaction = trx; try { cmdI.Parameters.Clear(); cmdI.CommandText = CommonStrings.InsertProximityLog; cmdI.CommandType = System.Data.CommandType.StoredProcedure; cmdI.Parameters.AddWithValue("@DeviceConnectedTo", ins.DeviceConnectedTo); cmdI.Parameters.AddWithValue("@DeviceInProximity", ins.DeviceInProximity); cmdI.Parameters.AddWithValue("@AnimalConnectedTo", ins.AnimalConnectedTo); cmdI.Parameters.AddWithValue("@AnimalInProximity", ins.AnimalInProximity); cmdI.Parameters.AddWithValue("@ProximityStarted", ins.ProximityStarted); cmdI.Parameters.AddWithValue("@ProximityEnded", ins.ProximityEnded); cmdI.Parameters.AddWithValue("@LogDate", DateTime.Now); ins.ProximityId = (int)cmdI.ExecuteScalar(); trx.Commit(); cmdI.Connection.Close(); } catch (SqlException ex) { if (trx != null) trx.Rollback(); } finally { if (con.State != ConnectionState.Closed) { con.Close(); } con.Dispose(); cmdI.Dispose(); trx.Dispose(); } if (ins.ProximityId != 0) success = true; return success; }
public List<ProximityLog> GetProximityLog() { List<ProximityLog> ReturnObject = new List<ProximityLog>(); ProximityLog ins; DataBaseConnection dbConn = new DataBaseConnection(); var table = GetCompaniesDBVariable(); if (table != null) { using (var con = dbConn.SqlConn()) { con.Open(); using (SqlCommand cmd = new SqlCommand("exec " + CommonStrings.GetProximityLog + " @Companies", con)) { var pList = new SqlParameter("@Companies", SqlDbType.Structured); pList.TypeName = "dbo.IntList"; pList.Value = table; cmd.Parameters.Add(pList); using (var drI = cmd.ExecuteReader()) { while (drI.Read()) { ins = new ProximityLog(); ins.ProximityId = Convert.ToInt32(drI["ProximityId"]); ins.AnimalConnectedTo = Convert.ToInt32(drI["AnimalConnectedTo"]); ins.AnimalInProximity = Convert.ToInt32(drI["AnimalInProximity"]); ins.DeviceConnectedTo = Convert.ToInt32(drI["DeviceConnectedTo"]); ins.DeviceInProximity = Convert.ToInt32(drI["DeviceInProximity"]); ins.LogDate = Convert.ToDateTime(drI["LogDate"]); ins.ProximityEnded = Convert.ToDateTime(drI["ProximityEnded"]); ins.ProximityStarted = Convert.ToDateTime(drI["ProximityStarted"]); ins._AnimalConnectedTo = drI["AnimalA"].ToString(); ins._AnimalInProximity = drI["AnimalB"].ToString(); ins._Company = drI["Company"].ToString(); ins._DeviceConnectedTo = drI["DeviceA"].ToString(); ins._DeviceInProximity = drI["DeviceB"].ToString(); ins.SecondsConnected = Math.Round((ins.ProximityEnded - ins.ProximityStarted).TotalSeconds, 2); ReturnObject.Add(ins); } } } } } return ReturnObject; }
public bool LogProximity(ProximityLog ins) { bool success = false; ProximityLog ReturnObject = new ProximityLog(); DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); con.Open(); SqlCommand cmdI = con.CreateCommand(); SqlTransaction trx = con.BeginTransaction(CommonStrings.InsertTransaction); cmdI.Connection = con; cmdI.Transaction = trx; try { cmdI.Parameters.Clear(); cmdI.CommandText = CommonStrings.InsertProximityLog; cmdI.CommandType = System.Data.CommandType.StoredProcedure; cmdI.Parameters.AddWithValue("@DeviceConnectedTo", ins.DeviceConnectedTo); cmdI.Parameters.AddWithValue("@DeviceInProximity", ins.DeviceInProximity); cmdI.Parameters.AddWithValue("@AnimalConnectedTo", ins.AnimalConnectedTo); cmdI.Parameters.AddWithValue("@AnimalInProximity", ins.AnimalInProximity); cmdI.Parameters.AddWithValue("@ProximityStarted", ins.ProximityStarted); cmdI.Parameters.AddWithValue("@ProximityEnded", ins.ProximityEnded); cmdI.Parameters.AddWithValue("@LogDate", DateTime.Now); ins.ProximityId = (int)cmdI.ExecuteScalar(); trx.Commit(); cmdI.Connection.Close(); } catch (SqlException ex) { if (trx != null) { trx.Rollback(); } } finally { if (con.State != ConnectionState.Closed) { con.Close(); } con.Dispose(); cmdI.Dispose(); trx.Dispose(); } if (ins.ProximityId != 0) { success = true; } return(success); }