示例#1
0
        /// <summary>
        /// Get list with information about where templates saved
        /// </summary>
        /// <returns>IEnumerable</returns>
        /// <exception cref="Exception">MySqlException</exception>
        ///

        public IEnumerable <TemplateTable> GetTemplates()
        {
            _templateTables = new ObservableCollection <TemplateTable>();
            TemplateTables.Clear();
            try
            {
                _connection.Open();
                MySqlCommand command = _connection.CreateCommand();
                command.CommandText = "SELECT name FROM templates_storage;";
                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        TemplateTable tt = new TemplateTable(reader.GetString("name"));
                        if (_templates._templateTables.Contains(tt))
                        {
                            continue;
                        }
                        _templates._templateTables.Add(tt);
                    }
                }
                _connection.Close();
            }
            catch (MySqlException e)
            {
                _connection.Close();
                Debug.Assert(true, e.Message);
            }
            _connection.Close();
            return(_templates._templateTables);
        }
示例#2
0
        /// <summary>
        /// Insert in template_storage values
        /// </summary>
        /// <param name="name">template name</param>
        /// <param name="path">path on the remote server</param>
        /// <param name="file">file name where template saved</param>
        /// <returns>true - if success</returns>
        public bool InsertTemplatesToDatabase(string name, string path, string file)
        {
            TemplateTable newRow = new TemplateTable(name, path, file);

            try
            {
                _connection.Open();
                MySqlCommand insert = _connection.CreateCommand();
                insert.CommandText =
                    "INSERT INTO templates_storage(name, folder_path, file_name) VALUES (@name, @path, @file)";
                insert.Parameters.AddWithValue("@name", name);
                insert.Parameters.AddWithValue("@path", path);
                insert.Parameters.AddWithValue("@file", file);
                insert.ExecuteNonQuery();
                _templates._templateTables.Add(newRow);
                _connection.Close();
                return(true);
            }
            catch (MySqlException e)
            {
                _connection.Close();
                Debug.Assert(true, e.Message);
                return(false);
            }
        }