Exemplo n.º 1
0
        public void Add(AnimalInsemnation currAnimalInsemnation)
        {
            SqlConnection con = DALHelper.getConnection();
            SqlCommand    cmd = new SqlCommand("sp_insertAnimalInsemnation", con);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@Animal", DALHelper.getNullORValue(currAnimalInsemnation.CurrCattle.ID));
            cmd.Parameters.AddWithValue("@Date", DALHelper.getNullORValue(currAnimalInsemnation.DateofInsemnation));
            cmd.Parameters.AddWithValue("@Comments", DALHelper.getNullORValue(currAnimalInsemnation.Comments));

            con.Open();
            using (con)
            {
                cmd.ExecuteNonQuery();
            }

            //return cmd_success;
        }
Exemplo n.º 2
0
        private List <AnimalInsemnation> selectInsemnations(SqlCommand cmd)
        {
            cmd.CommandType = CommandType.StoredProcedure;
            SqlConnection            con             = cmd.Connection;
            List <AnimalInsemnation> listInsemnation = new List <AnimalInsemnation>();

            con.Open();
            using (con)
            {
                SqlDataReader dr = cmd.ExecuteReader();

                //            i.ID,
                //i.Animal,
                //a.TagNo,
                //i.Date,
                //i.Comments

                if (dr.HasRows)
                {
                    listInsemnation = new List <AnimalInsemnation>();
                    while (dr.Read())
                    {
                        Cattle currCattle = new Cattle
                        {
                            ID    = Convert.ToInt32(dr[1]),
                            TagNo = Convert.ToString(dr[2]),
                        };

                        AnimalInsemnation currInsem = new AnimalInsemnation();

                        currInsem.CurrCattle        = currCattle;
                        currInsem.Comments          = Convert.ToString(dr[4]);
                        currInsem.DateofInsemnation = Convert.ToDateTime(dr[3]);

                        listInsemnation.Add(currInsem);
                    }
                }
            }
            return(listInsemnation);
        }
        public void Save()
        {
            try
            {
                currAnimalInsemnation = new AnimalInsemnation();

                currAnimalInsemnation.Comments          = textBoxComments.Text;
                currAnimalInsemnation.CurrCattle        = (Cattle)comboBoxMother.SelectedItem;
                currAnimalInsemnation.DateofInsemnation = datePickerInsemnation.SelectedDate.Value;

                insemnationHandler.Add(currAnimalInsemnation);
            }

            catch (Exception fexp)
            {
                MessageBox.Show(fexp.Message);
                return;
            }

            textBoxComments.Text         = "";
            comboBoxMother.SelectedIndex = -1;
            datePickerInsemnation.Text   = "";
        }
 public void Add(AnimalInsemnation currAnimalInsemnation)
 {
     new AnimalInseminationsDAL().Add(currAnimalInsemnation);
 }