Esempio n. 1
0
        public bool GetCommand(string skill)
        {
            //IWriteCommand cmd = new WriteCommand();
            //string qry = "INSERT INTO Skill (skill_id, skilltext) VALUES (skill_id_seq.nextval, '" + skill + "')";
            //if (cmd.Execute(qry) == true)
            //{
            //    return true;
            //}
            //return false;

            string formattedSkill = FormatSkill(skill);

            // if exists do nothing
            if (DetermineIfExists(formattedSkill))
            {
                Console.WriteLine(formattedSkill);
                return(true);
            }
            // else add the skill to the database
            else
            {
                ConnectionString cnString = new ConnectionString();
                IDbConnection    cn       = new OleDbConnection(cnString.GetConnString());

                try
                {
                    cn.Open();
                    IDbTransaction tran = cn.BeginTransaction();

                    // Add skill
                    int affectedRows = 0;

                    IDbCommand cmd = new OleDbCommand("sp_add_skill", (OleDbConnection)cn);
                    cmd.Transaction = tran;
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new OleDbParameter("@skilltxt", formattedSkill));
                    affectedRows = cmd.ExecuteNonQuery();


                    if (affectedRows > 0)
                    {
                        tran.Commit();
                        return(true);
                    }
                    else
                    {
                        tran.Rollback();
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                finally
                {
                    cn.Close();
                }
                return(false);
            }
        }