コード例 #1
0
        //Get SnippetCollectionInfo related to CollectionID
        private static SnippetCollectionInfo GetSnippetCollectionInfo(int CollectionID)
        {
            //Create Temp
            SnippetCollectionInfo info = null;

            //create connection and open it
            MySqlConnection connection = DbInfo.Connection();

            //Build Mysql command
            MySqlCommand cmd = connection.CreateCommand();

            //Add the CommandText
            cmd.CommandText = "SELECT `ID`, `UserID`, `Name`, `CreateDate` FROM `snippedcollection` WHERE `ID` = @CollectionID";

            //Add Parameter
            cmd.Parameters.AddWithValue("@CollectionID", CollectionID);

            //Create reader
            MySqlDataReader reader = cmd.ExecuteReader();

            //While reading
            if (reader.Read())
            {
                info = new SnippetCollectionInfo(
                    int.Parse(reader["ID"].ToString()),
                    int.Parse(reader["UserID"].ToString()),
                    reader["Name"].ToString(),
                    DateTime.Parse(reader["CreateDate"].ToString())
                    );
            }
            //Return Value
            return(info);
        }
コード例 #2
0
        //Update new Collection
        public static void UpdateSnippetCollection(SnippetCollectionInfo SnippetCollectionInfo)
        {
            //Create Connection
            using (MySqlConnection connection = DbInfo.Connection())
            {
                //Create Cmd
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    cmd.Connection  = connection;
                    cmd.CommandType = CommandType.Text;

                    //Create CommandText
                    cmd.CommandText = "UPDATE `snippedcollection` SET `Name`=@Name WHERE `ID`=@ID";

                    //Set Parameters
                    cmd.Parameters.AddWithValue("@ID", SnippetCollectionInfo.ID);
                    cmd.Parameters.AddWithValue("@Name", SnippetCollectionInfo.Name);

                    try
                    {
                        int recordsAffected = cmd.ExecuteNonQuery();
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
        }
コード例 #3
0
        //-------------------------CRUD------------------------------
        //Add new Collection
        public static void AddNewSnippetCollection(SnippetCollectionInfo SnippetCollectionInfo)
        {
            //Create Connection
            using (MySqlConnection connection = DbInfo.Connection())
            {
                //Create cmd
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    cmd.Connection  = connection;
                    cmd.CommandType = CommandType.Text;

                    //Create CommandText
                    cmd.CommandText = "INSERT INTO `snippedcollection`(`ID`, `Name`) VALUES (@ID, @Name)";

                    //Set Parameters
                    cmd.Parameters.AddWithValue("@ID", "");
                    cmd.Parameters.AddWithValue("@Name", SnippetCollectionInfo.Name);

                    try
                    {
                        int recordsAffected = cmd.ExecuteNonQuery();
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
        }
コード例 #4
0
 public CollectionCompleteInfo(SnippetCollectionInfo _collectioninfo, List <SnippetInfo> _snippets)
 {
     collectioninfo = _collectioninfo;
     snippets       = _snippets;
 }