Exemple #1
0
        public void SaveTrainingData(TrainingItem myItem)
        {
            using (var db = DBConnection.CreateConnection())
            {
                db.Open();

                var sql = "dbo.spInsertTraining";
                var cmd = new SqlCommand(sql, db);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@EMP_ID", myItem._EMP_ID));
                cmd.Parameters.Add(new SqlParameter("@TITLE", myItem._TITLE));
                cmd.Parameters.Add(new SqlParameter("@INSTITUTION", myItem._INSTITUTION));
                cmd.Parameters.Add(new SqlParameter("@TRAINING_DATE", myItem._TRAINING_DATE));
                cmd.Parameters.Add(new SqlParameter("@TRAINING_LOCATION", myItem._TRAINING_LOCATION));

                cmd.ExecuteNonQuery();
                db.Close();
            }
        }
        public List <TrainingItem> RetreiveEmpTraining(string employeeID)
        {
            var itemList = new List <TrainingItem>();

            using (var db = DBConnection.CreateConnection())
            {
                db.Open();

                var sql = "dbo.GetSpecificTraining";
                var cmd = new SqlCommand(sql, db);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@EMP_ID", employeeID));
                var reader = cmd.ExecuteReader();

                if (!reader.HasRows)
                {
                    return(null);
                }

                while (reader.Read())
                {
                    var item = new TrainingItem();
                    item._EMP_ID            = (string)reader["EMP_ID"];
                    item._TITLE             = (string)reader["TITLE"];
                    item._INSTITUTION       = (string)reader["INSTITUTION"];
                    item._TRAINING_DATE     = (string)reader["TRAINING_DATE"];
                    item._TRAINING_LOCATION = (string)reader["TRAINING_LOCATION"];

                    itemList.Add(item);
                }

                db.Close();

                return(itemList);
            }
        }