Пример #1
0
        public JsonResult _InsertAnimal(Animal ins)
        {
            ins = animalRep.InsertAnimal(ins);

            if(ins.DeviceId != 0 && ins.AnimalId != 0)
            {
                // Insert Device Link
                commonRep.LinkAnimalToDevice(ins);
            }

            return Json(new GridModel(commonRep.GetAnimals()));
        }
Пример #2
0
        public Animal GetAnimal(int AnimalId)
        {
            Animal ins = new Animal();

            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            SqlCommand cmdI = con.CreateCommand();
            cmdI.Connection = con;

            cmdI.Parameters.Clear();
            cmdI.CommandText = CommonStrings.GetAnimal;
            cmdI.CommandType = System.Data.CommandType.StoredProcedure;
            cmdI.Parameters.AddWithValue("@AnimalId", AnimalId);
            cmdI.Connection.Open();

            SqlDataReader drI = cmdI.ExecuteReader();

            if (drI.HasRows)
            {
                while (drI.Read())
                {
                    ins.AnimalId = Convert.ToInt32(drI["AnimalId"]);
                    ins.AnimalTypeId = Convert.ToInt32(drI["AnimalTypeId"]);
                    ins.BirthDate = Convert.ToDateTime(drI["Birthdate"]);
                    ins.CreatedDate = Convert.ToDateTime(drI["CreatedDate"]);
                    ins.CompanyId = Convert.ToInt32(drI["CompanyId"]);
                    ins.DecriptiveName = drI["DecriptiveName"].ToString();
                    ins.ModifiedBy = Convert.ToInt32(drI["ModifiedBy"]);
                    ins.ModifiedDate = Convert.ToDateTime(drI["ModifiedDate"]);
                    ins.Removed = Convert.ToBoolean(drI["Removed"]);
                    ins.SexId = Convert.ToInt32(drI["SexId"]);
                    ins.TagNumber = drI["TagNumber"].ToString();
                    ins._AnimalType = drI["Species"].ToString();
                    ins._Company = drI["Company"].ToString();
                    ins._ModifiedBy = drI["Username"].ToString();
                    ins._Sex = drI["Sex"].ToString();
                    ins.DeviceId = Convert.ToInt32(drI["DeviceId"]);
                    ins._Address = drI["DeviceAddress"].ToString();
                }
            }

            cmdI.Connection.Close();
            con.Dispose();

            return ins;
        }
Пример #3
0
        public JsonResult AddAnimal(string Name, string Tag, int DeviceId, int SexId, int Species, int CompanyId, int UserKey, DateTime ModifiedDate)
        {
            Animal ani = new Animal();
            ani.DecriptiveName = Name;
            ani.TagNumber = Tag;
            ani.ModifiedBy = UserKey;
            ani.CompanyId = CompanyId;
            ani.DeviceId = DeviceId;
            ani.SexId = SexId;
            ani.AnimalTypeId = Species;
            ani.ModifiedDate = ModifiedDate;

            ani = aniRep.InsertAnimalSim(ani);

            if (ani.DeviceId != 0 && ani.AnimalId != 0)
            {
                comRep.LinkAnimalToDeviceSim(ani);
                return Json(ani.AnimalId, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(0, JsonRequestBehavior.AllowGet);
            }
        }
Пример #4
0
        public Animal UpdateAnimal(Animal ins)
        {
            int ModifiedBy = (int)HttpContext.Current.Session["UserNo"];
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            con.Open();
            SqlCommand cmdI = con.CreateCommand();
            cmdI.Connection = con;

            cmdI.Parameters.Clear();
            cmdI.CommandText = CommonStrings.UpdateAnimal;
            cmdI.CommandType = System.Data.CommandType.StoredProcedure;
            cmdI.Parameters.AddWithValue("@AnimalId", ins.AnimalId);
            cmdI.Parameters.AddWithValue("@AnimalTypeId", ins.AnimalTypeId);
            cmdI.Parameters.AddWithValue("@SexId", ins.SexId);
            cmdI.Parameters.AddWithValue("@DecriptiveName", ins.DecriptiveName);
            cmdI.Parameters.AddWithValue("@TagNumber", ins.TagNumber);
            cmdI.Parameters.AddWithValue("@BirthDate", ins.BirthDate);
            cmdI.Parameters.AddWithValue("@CreatedDate", DateTime.Now);
            cmdI.Parameters.AddWithValue("@ModifiedDate", DateTime.Now);
            cmdI.Parameters.AddWithValue("@ModifiedBy", ModifiedBy);
            cmdI.Parameters.AddWithValue("@CompanyId", ins.CompanyId);
            cmdI.Parameters.AddWithValue("@Removed", false);

            cmdI.ExecuteNonQuery();
            cmdI.Connection.Close();
            con.Dispose();

            return ins;
        }
Пример #5
0
        public Animal InsertAnimalSim(Animal ins)
        {
            Animal ReturnObject = new Animal();
            //int ModifiedBy = (int)HttpContext.Current.Session["UserNo"];

            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.InsertAnimal;
                cmdI.CommandType = System.Data.CommandType.StoredProcedure;
                cmdI.Parameters.AddWithValue("@AnimalTypeId", ins.AnimalTypeId);
                cmdI.Parameters.AddWithValue("@SexId", ins.SexId);
                cmdI.Parameters.AddWithValue("@DecriptiveName", ins.DecriptiveName);
                cmdI.Parameters.AddWithValue("@TagNumber", ins.TagNumber);
                cmdI.Parameters.AddWithValue("@BirthDate", DateTime.Today);
                cmdI.Parameters.AddWithValue("@CreatedDate", DateTime.Now);
                cmdI.Parameters.AddWithValue("@ModifiedDate", ins.ModifiedDate);
                cmdI.Parameters.AddWithValue("@ModifiedBy", ins.ModifiedBy);
                cmdI.Parameters.AddWithValue("@CompanyId", ins.CompanyId);
                cmdI.Parameters.AddWithValue("@Removed", false);
                ins.AnimalId = (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();
            }

            return ins;
        }
Пример #6
0
        public List<Animal> GetAnimals()
        {
            List<Animal> ReturnObject = new List<Animal>();
            Animal 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.GetAnimals + " @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 Animal();
                                ins.AnimalId = Convert.ToInt32(drI["AnimalId"]);
                                ins.AnimalTypeId = Convert.ToInt32(drI["AnimalTypeId"]);
                                ins.BirthDate = Convert.ToDateTime(drI["Birthdate"]);
                                ins.CreatedDate = Convert.ToDateTime(drI["CreatedDate"]);
                                ins.CompanyId = Convert.ToInt32(drI["CompanyId"]);
                                ins.DecriptiveName = drI["DecriptiveName"].ToString();
                                ins.ModifiedBy = Convert.ToInt32(drI["ModifiedBy"]);
                                ins.ModifiedDate = Convert.ToDateTime(drI["ModifiedDate"]);
                                ins.Removed = Convert.ToBoolean(drI["Removed"]);
                                ins.SexId = Convert.ToInt32(drI["SexId"]);
                                ins.TagNumber = drI["TagNumber"].ToString();
                                ins._AnimalType = drI["Species"].ToString();
                                ins._Company = drI["Company"].ToString();
                                ins._ModifiedBy = drI["Username"].ToString();
                                ins._Sex = drI["Sex"].ToString();
                                ins.DeviceId = Convert.ToInt32(drI["DeviceId"]);
                                ins._Address = drI["DeviceAddress"].ToString();
                                ReturnObject.Add(ins);
                            }
                        }
                    }
                }
            }

            return ReturnObject;
        }
Пример #7
0
        public void LinkAnimalToDeviceSim(Animal ins)
        {
            //int ModifiedBy = (int)HttpContext.Current.Session["UserNo"];
            DataBaseConnection dbConn = new DataBaseConnection();
            SqlConnection con = dbConn.SqlConn();
            con.Open();
            SqlCommand cmdI = con.CreateCommand();
            cmdI.Connection = con;

            cmdI.Parameters.Clear();
            cmdI.CommandText = CommonStrings.LinkAnimalDevice;
            cmdI.CommandType = System.Data.CommandType.StoredProcedure;
            cmdI.Parameters.AddWithValue("@DeviceId", ins.DeviceId);
            cmdI.Parameters.AddWithValue("@AnimalId", ins.AnimalId);
            cmdI.Parameters.AddWithValue("@IsCurrent", true);
            cmdI.Parameters.AddWithValue("@ModifiedDate", ins.ModifiedDate);
            cmdI.Parameters.AddWithValue("@ModifiedBy", ins.ModifiedBy);
            cmdI.ExecuteNonQuery();
            cmdI.Connection.Close();
            con.Dispose();
        }
Пример #8
0
        public JsonResult _UpdateAnimal(Animal ins)
        {
            Animal before = animalRep.GetAnimal(ins.AnimalId);

            ins = animalRep.UpdateAnimal(ins);

            if (ins.DeviceId != 0 && ins.AnimalId != 0)
            {
                if(before.DeviceId != ins.DeviceId)
                {
                    // Insert Device Link
                    commonRep.LinkAnimalToDevice(ins);
                }
            }
            else if(ins.DeviceId == 0)
            {
                commonRep.RemoveAnimalLinkedDevice(ins.AnimalId);
            }

            return Json(new GridModel(commonRep.GetAnimals()));
        }
Пример #9
0
        public ActionResult InsertAnimal(string Name, string Tag, int DeviceId, int CompanyId, int UserKey)
        {
            Animal ani = new Animal();
            ani.DecriptiveName = Name;
            ani.TagNumber = Tag;
            ani.ModifiedBy = UserKey;
            ani.CompanyId = CompanyId;
            ani.DeviceId = DeviceId;

            ani = aniRep.InsertAnimalSim(ani);

            if (ani.DeviceId != 0 && ani.AnimalId != 0)
            {
                comRep.LinkAnimalToDeviceSim(ani);
                return Content(ani.AnimalId.ToString(), "text/html");
            }
            else
            {
                return Content("Fail Animal", "text/html");
            }
        }