public ActionResult LogMovement(string DeviceAddress, int Axis) { MovementLog ins = new MovementLog(); ins.AxisId = Axis; //...Check if DeviceAddress is in Database ins.DeviceId = logRep.GetDeviceId(DeviceAddress); if (ins.DeviceId != -1) { //...Check if Device is Connected to Animal ins.AnimalId = logRep.GetAnimalId(ins.DeviceId); if (ins.AnimalId != -1) { //...Log Proximity if (logRep.LogMovement(ins)) return Content(CommonStrings.Success, "text/html"); else return Content(CommonStrings.Error_DBFail, "text/html"); } else { return Content(CommonStrings.Error_AnimalNotConnectedToDevice, "text/html"); } } else { return Content(CommonStrings.Error_Invaild_DeviceAddress, "text/html"); } return Content(CommonStrings.Error, "text/html"); }
public bool LogMovementSim(MovementLog ins) { bool success = false; MovementLog ReturnObject = new MovementLog(); 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.InsertMovementLog; cmdI.CommandType = System.Data.CommandType.StoredProcedure; cmdI.Parameters.AddWithValue("@AnimalId", ins.AnimalId); cmdI.Parameters.AddWithValue("@DeviceId", ins.DeviceId); cmdI.Parameters.AddWithValue("@AxisId", ins.AxisId); cmdI.Parameters.AddWithValue("@LogDate", ins.LogDate); ins.MovementId = (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.MovementId != 0) { success = true; } return(success); }
public bool LogMovement(MovementLog ins) { bool success = false; MovementLog ReturnObject = new MovementLog(); 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.InsertMovementLog; cmdI.CommandType = System.Data.CommandType.StoredProcedure; cmdI.Parameters.AddWithValue("@AnimalId", ins.AnimalId); cmdI.Parameters.AddWithValue("@DeviceId", ins.DeviceId); cmdI.Parameters.AddWithValue("@AxisId", ins.AxisId); cmdI.Parameters.AddWithValue("@LogDate", DateTime.Now); ins.MovementId = (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.MovementId != 0) success = true; return success; }
public List <MovementLog> GetMovementLog() { List <MovementLog> ReturnObject = new List <MovementLog>(); MovementLog 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.GetMovementLog + " @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 MovementLog(); ins.MovementId = Convert.ToInt32(drI["MovementId"]); ins.AnimalId = Convert.ToInt32(drI["AnimalId"]); ins.DeviceId = Convert.ToInt32(drI["DeviceId"]); ins.AxisId = Convert.ToInt32(drI["AxisId"]); ins.LogDate = Convert.ToDateTime(drI["LogDate"]); ins._AnimalName = drI["AnimalName"].ToString(); ins._Axis = drI["Axis"].ToString(); ins._Company = drI["Company"].ToString(); ins._DeviceAddress = drI["DeviceAddress"].ToString(); ReturnObject.Add(ins); } } } } } return(ReturnObject); }
public List<MovementLog> GetMovementLog() { List<MovementLog> ReturnObject = new List<MovementLog>(); MovementLog 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.GetMovementLog + " @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 MovementLog(); ins.MovementId = Convert.ToInt32(drI["MovementId"]); ins.AnimalId = Convert.ToInt32(drI["AnimalId"]); ins.DeviceId = Convert.ToInt32(drI["DeviceId"]); ins.AxisId = Convert.ToInt32(drI["AxisId"]); ins.LogDate = Convert.ToDateTime(drI["LogDate"]); ins._AnimalName = drI["AnimalName"].ToString(); ins._Axis = drI["Axis"].ToString(); ins._Company = drI["Company"].ToString(); ins._DeviceAddress = drI["DeviceAddress"].ToString(); ReturnObject.Add(ins); } } } } } return ReturnObject; }
public JsonResult LogMovement(string DeviceAddress, int Axis, DateTime ModifiedDate) { MovementLog ins = new MovementLog(); ins.AxisId = Axis; ins.LogDate = ModifiedDate; //...Check if DeviceAddress is in Database ins.DeviceId = logRep.GetDeviceId(DeviceAddress); if (ins.DeviceId != -1) { //...Check if Device is Connected to Animal ins.AnimalId = logRep.GetAnimalId(ins.DeviceId); if (ins.AnimalId != -1) { //...Log Proximity if (logRep.LogMovement(ins)) return Json(CommonStrings.Success, JsonRequestBehavior.AllowGet); else return Json(CommonStrings.Error_DBFail, JsonRequestBehavior.AllowGet); } else { return Json(CommonStrings.Error_AnimalNotConnectedToDevice, JsonRequestBehavior.AllowGet); } } else { return Json(CommonStrings.Error_Invaild_DeviceAddress, JsonRequestBehavior.AllowGet); } return Json(CommonStrings.Error, JsonRequestBehavior.AllowGet); }