Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
0a3d0f073f | ||
|
cb6251ab2b |
37
NewsBlog/NewsBlog.sln
Normal file
37
NewsBlog/NewsBlog.sln
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.8.34330.188
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewsBlogView", "NewsBlogView\NewsBlogView.csproj", "{13D9F9B7-6693-4D26-8178-08389235382C}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewsBlogAbstractions", "NewsBlogAbstractions\NewsBlogAbstractions.csproj", "{22CA3930-4C19-4623-9B58-C42A48B45576}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewsBlogDatabaseImplementation", "NewsBlogDatabaseImplementation\NewsBlogDatabaseImplementation.csproj", "{1DA49583-881B-4E05-A128-AEB692A174B4}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{13D9F9B7-6693-4D26-8178-08389235382C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{13D9F9B7-6693-4D26-8178-08389235382C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{13D9F9B7-6693-4D26-8178-08389235382C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{13D9F9B7-6693-4D26-8178-08389235382C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{22CA3930-4C19-4623-9B58-C42A48B45576}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{22CA3930-4C19-4623-9B58-C42A48B45576}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{22CA3930-4C19-4623-9B58-C42A48B45576}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{22CA3930-4C19-4623-9B58-C42A48B45576}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{1DA49583-881B-4E05-A128-AEB692A174B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{1DA49583-881B-4E05-A128-AEB692A174B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{1DA49583-881B-4E05-A128-AEB692A174B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{1DA49583-881B-4E05-A128-AEB692A174B4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {F171E585-9195-4FAC-AF2A-ADEE7DC12398}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
23
NewsBlog/NewsBlogAbstractions/Models/Article.cs
Normal file
23
NewsBlog/NewsBlogAbstractions/Models/Article.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogAbstractions.Models
|
||||||
|
{
|
||||||
|
public class Article
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Content { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTime PublicationDate { get; set; }
|
||||||
|
|
||||||
|
public int AuthorId { get; set; }
|
||||||
|
|
||||||
|
public int CategoryId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
19
NewsBlog/NewsBlogAbstractions/Models/Author.cs
Normal file
19
NewsBlog/NewsBlogAbstractions/Models/Author.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogAbstractions.Models
|
||||||
|
{
|
||||||
|
public class Author
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Description { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Phone { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
15
NewsBlog/NewsBlogAbstractions/Models/Category.cs
Normal file
15
NewsBlog/NewsBlogAbstractions/Models/Category.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogAbstractions.Models
|
||||||
|
{
|
||||||
|
public class Category
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
21
NewsBlog/NewsBlogAbstractions/Models/Comment.cs
Normal file
21
NewsBlog/NewsBlogAbstractions/Models/Comment.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogAbstractions.Models
|
||||||
|
{
|
||||||
|
public class Comment
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Content { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTime CreateDate { get; set; }
|
||||||
|
|
||||||
|
public int ArticleId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
19
NewsBlog/NewsBlogAbstractions/Models/Tag.cs
Normal file
19
NewsBlog/NewsBlogAbstractions/Models/Tag.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogAbstractions.Models
|
||||||
|
{
|
||||||
|
public class Tag
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Description { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public int ArticleId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,22 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogAbstractions.WorkAbstractions
|
||||||
|
{
|
||||||
|
public interface IArticleWork
|
||||||
|
{
|
||||||
|
List<Article> GetAll();
|
||||||
|
|
||||||
|
Article? Get(int id);
|
||||||
|
|
||||||
|
Article? Create(Article article);
|
||||||
|
|
||||||
|
Article? Update(Article article);
|
||||||
|
|
||||||
|
Article? Delete(int id);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogAbstractions.WorkAbstractions
|
||||||
|
{
|
||||||
|
public interface IAuthorWork
|
||||||
|
{
|
||||||
|
List<Author> GetAll();
|
||||||
|
|
||||||
|
Author? Get(int id);
|
||||||
|
|
||||||
|
Author? Create(Author author);
|
||||||
|
|
||||||
|
Author? CreateId(Author author);
|
||||||
|
|
||||||
|
Author? Update(Author author);
|
||||||
|
|
||||||
|
Author? Delete(int id);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogAbstractions.WorkAbstractions
|
||||||
|
{
|
||||||
|
public interface ICategoryWork
|
||||||
|
{
|
||||||
|
List<Category> GetAll();
|
||||||
|
|
||||||
|
Category? Get(int id);
|
||||||
|
|
||||||
|
Category? Create(Category category);
|
||||||
|
|
||||||
|
Category? Update(Category category);
|
||||||
|
|
||||||
|
Category? Delete(int id);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogAbstractions.WorkAbstractions
|
||||||
|
{
|
||||||
|
public interface ICommentWork
|
||||||
|
{
|
||||||
|
List<Comment> GetAll();
|
||||||
|
|
||||||
|
Comment? Get(int id);
|
||||||
|
|
||||||
|
Comment? Create(Comment comment);
|
||||||
|
|
||||||
|
Comment? Update(Comment comment);
|
||||||
|
|
||||||
|
Comment? Delete(int id);
|
||||||
|
}
|
||||||
|
}
|
22
NewsBlog/NewsBlogAbstractions/WorkAbstractions/ITagWork.cs
Normal file
22
NewsBlog/NewsBlogAbstractions/WorkAbstractions/ITagWork.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogAbstractions.WorkAbstractions
|
||||||
|
{
|
||||||
|
public interface ITagWork
|
||||||
|
{
|
||||||
|
List<Tag> GetAll();
|
||||||
|
|
||||||
|
Tag? Get(int id);
|
||||||
|
|
||||||
|
Tag? Create(Tag tag);
|
||||||
|
|
||||||
|
Tag? Update(Tag tag);
|
||||||
|
|
||||||
|
Tag? Delete(int id);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\NewsBlogAbstractions\NewsBlogAbstractions.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
12
NewsBlog/NewsBlogDatabaseImplementation/SqlConnection.cs
Normal file
12
NewsBlog/NewsBlogDatabaseImplementation/SqlConnection.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using Npgsql;
|
||||||
|
|
||||||
|
namespace NewsBlogDatabaseImplementation
|
||||||
|
{
|
||||||
|
public class SqlConnection
|
||||||
|
{
|
||||||
|
public static NpgsqlConnection GetConnection()
|
||||||
|
{
|
||||||
|
return new NpgsqlConnection("Host=192.168.56.103;Port=5432;Username=postgres;Database=postgres;Password=postgres");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using NewsBlogAbstractions.WorkAbstractions;
|
||||||
|
using Npgsql;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogDatabaseImplementation.WorkImplementation
|
||||||
|
{
|
||||||
|
public class ArticleWork : IArticleWork
|
||||||
|
{
|
||||||
|
public Article? Create(Article article)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("INSERT INTO article (title, content, publication_date, author_id, category_id) VALUES (@Title, @Content, @Publication_date, @Author_id, @Category_id)", con);
|
||||||
|
cmd.Parameters.AddWithValue("@Title", article.Title);
|
||||||
|
cmd.Parameters.AddWithValue("@Content", article.Content);
|
||||||
|
cmd.Parameters.AddWithValue("@Publication_date", article.PublicationDate);
|
||||||
|
cmd.Parameters.AddWithValue("@Author_id", article.AuthorId == 0 ? DBNull.Value : article.AuthorId);
|
||||||
|
cmd.Parameters.AddWithValue("@Category_id", article.CategoryId == 0 ? DBNull.Value : article.CategoryId);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
return article;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Article? Delete(int id)
|
||||||
|
{
|
||||||
|
var element = Get(id);
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"DELETE FROM article WHERE article_id = {id}", con);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Article? Get(int id)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"SELECT * FROM article WHERE article_id = {id}", con);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
return new Article
|
||||||
|
{
|
||||||
|
Id = reader.GetInt32(0),
|
||||||
|
Title = reader.GetString(1),
|
||||||
|
Content = reader.GetString(2),
|
||||||
|
PublicationDate = reader.GetDateTime(3),
|
||||||
|
AuthorId = !reader.IsDBNull(4) ? reader.GetInt32(4) : 0,
|
||||||
|
CategoryId = !reader.IsDBNull(5) ? reader.GetInt32(5) : 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Article> GetAll()
|
||||||
|
{
|
||||||
|
var articles = new List<Article>();
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("SELECT * FROM article order by article_id", con);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
articles.Add(new Article
|
||||||
|
{
|
||||||
|
Id = reader.GetInt32(0),
|
||||||
|
Title = reader.GetString(1),
|
||||||
|
Content = reader.GetString(2),
|
||||||
|
PublicationDate = reader.GetDateTime(3),
|
||||||
|
AuthorId = !reader.IsDBNull(4) ? reader.GetInt32(4) : 0,
|
||||||
|
CategoryId = !reader.IsDBNull(5) ? reader.GetInt32(5) : 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return articles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Article? Update(Article article)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"UPDATE article SET title = '{article.Title}', content = '{article.Content}', publication_date = '{article.PublicationDate}', author_id = @Author_Id, category_id = @Category_id WHERE article_id = {article.Id}", con);
|
||||||
|
cmd.Parameters.AddWithValue("@Author_Id", article.AuthorId == 0 ? DBNull.Value : article.AuthorId);
|
||||||
|
cmd.Parameters.AddWithValue("@Category_Id", article.CategoryId == 0 ? DBNull.Value : article.CategoryId);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
var element = Get(article.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using NewsBlogAbstractions.WorkAbstractions;
|
||||||
|
using Npgsql;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogDatabaseImplementation.WorkImplementation
|
||||||
|
{
|
||||||
|
public class AuthorWork : IAuthorWork
|
||||||
|
{
|
||||||
|
public Author? Create(Author author)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("INSERT INTO author (name, description, phone) VALUES (@Name, @Description, @Phone)", con);
|
||||||
|
cmd.Parameters.AddWithValue("@Name", author.Name);
|
||||||
|
cmd.Parameters.AddWithValue("@Description", author.Description);
|
||||||
|
cmd.Parameters.AddWithValue("@Phone", author.Phone);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
return author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Author? CreateId(Author author)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("INSERT INTO author (author_id, name, description, phone) VALUES (@Author_id, @Name, @Description, @Phone)", con);
|
||||||
|
cmd.Parameters.AddWithValue("@Author_id", author.Id);
|
||||||
|
cmd.Parameters.AddWithValue("@Name", author.Name);
|
||||||
|
cmd.Parameters.AddWithValue("@Description", author.Description);
|
||||||
|
cmd.Parameters.AddWithValue("@Phone", author.Phone);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
return author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Author? Delete(int id)
|
||||||
|
{
|
||||||
|
var element = Get(id);
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"DELETE FROM author WHERE author_id = {id}", con);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Author? Get(int id)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"SELECT * FROM author WHERE author_id = {id}", con);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
return new Author
|
||||||
|
{
|
||||||
|
Id = reader.GetInt32(0),
|
||||||
|
Name = reader.GetString(1),
|
||||||
|
Description = reader.GetString(2),
|
||||||
|
Phone = reader.GetString(3),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Author> GetAll()
|
||||||
|
{
|
||||||
|
var authors = new List<Author>();
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("SELECT * FROM author order by author_id", con);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
authors.Add(new Author
|
||||||
|
{
|
||||||
|
Id = reader.GetInt32(0),
|
||||||
|
Name = reader.GetString(1),
|
||||||
|
Description = reader.GetString(2),
|
||||||
|
Phone = reader.GetString(3),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Author? Update(Author author)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"UPDATE author SET name = '{author.Name}', description = '{author.Description}', phone = '{author.Phone}' WHERE author_id = {author.Id}", con);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
var element = Get(author.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using NewsBlogAbstractions.WorkAbstractions;
|
||||||
|
using Npgsql;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogDatabaseImplementation.WorkImplementation
|
||||||
|
{
|
||||||
|
public class CategoryWork : ICategoryWork
|
||||||
|
{
|
||||||
|
public Category? Create(Category category)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("INSERT INTO category (name) VALUES (@Name)", con);
|
||||||
|
cmd.Parameters.AddWithValue("@Name", category.Name);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Category? Delete(int id)
|
||||||
|
{
|
||||||
|
var element = Get(id);
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"DELETE FROM category WHERE category_id = {id}", con);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Category? Get(int id)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"SELECT * FROM category WHERE category_id = {id}", con);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
return new Category
|
||||||
|
{
|
||||||
|
Id = reader.GetInt32(0),
|
||||||
|
Name = reader.GetString(1),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Category> GetAll()
|
||||||
|
{
|
||||||
|
var categorys = new List<Category>();
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("SELECT * FROM category order by category_id", con);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
categorys.Add(new Category
|
||||||
|
{
|
||||||
|
Id = reader.GetInt32(0),
|
||||||
|
Name = reader.GetString(1),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return categorys;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Category? Update(Category category)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"UPDATE category SET name = '{category.Name}' WHERE category_id = {category.Id}", con);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
var element = Get(category.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using NewsBlogAbstractions.WorkAbstractions;
|
||||||
|
using Npgsql;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogDatabaseImplementation.WorkImplementation
|
||||||
|
{
|
||||||
|
public class CommentWork : ICommentWork
|
||||||
|
{
|
||||||
|
public Comment? Create(Comment comment)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("INSERT INTO comment (title, content, create_date, article_id) VALUES (@Title, @Content, @Create_date, @Article_id)", con);
|
||||||
|
cmd.Parameters.AddWithValue("@Title", comment.Title);
|
||||||
|
cmd.Parameters.AddWithValue("@Content", comment.Content);
|
||||||
|
cmd.Parameters.AddWithValue("@Create_date", comment.CreateDate);
|
||||||
|
cmd.Parameters.AddWithValue("@Article_id", comment.ArticleId == 0 ? DBNull.Value : comment.ArticleId);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Comment? Delete(int id)
|
||||||
|
{
|
||||||
|
var element = Get(id);
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"DELETE FROM comment WHERE comment_id = {id}", con);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Comment? Get(int id)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"SELECT * FROM comment WHERE comment_id = {id}", con);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
return new Comment
|
||||||
|
{
|
||||||
|
Id = reader.GetInt32(0),
|
||||||
|
Title = reader.GetString(1),
|
||||||
|
Content = reader.GetString(2),
|
||||||
|
CreateDate = reader.GetDateTime(3),
|
||||||
|
ArticleId = !reader.IsDBNull(4) ? reader.GetInt32(4) : 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Comment> GetAll()
|
||||||
|
{
|
||||||
|
var comments = new List<Comment>();
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("SELECT * FROM comment order by comment_id", con);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
comments.Add(new Comment
|
||||||
|
{
|
||||||
|
Id = reader.GetInt32(0),
|
||||||
|
Title = reader.GetString(1),
|
||||||
|
Content = reader.GetString(2),
|
||||||
|
CreateDate = reader.GetDateTime(3),
|
||||||
|
ArticleId = !reader.IsDBNull(4) ? reader.GetInt32(4) : 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return comments;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Comment? Update(Comment comment)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"UPDATE comment SET title = '{comment.Title}', content = '{comment.Content}', create_date = '{comment.CreateDate}', article_id = @Article_Id WHERE comment_id = {comment.Id}", con);
|
||||||
|
cmd.Parameters.AddWithValue("@Article_Id", comment.ArticleId == 0 ? DBNull.Value : comment.ArticleId);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
var element = Get(comment.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using NewsBlogAbstractions.WorkAbstractions;
|
||||||
|
using Npgsql;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NewsBlogDatabaseImplementation.WorkImplementation
|
||||||
|
{
|
||||||
|
public class TagWork : ITagWork
|
||||||
|
{
|
||||||
|
public Tag? Create(Tag tag)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("INSERT INTO tag (name, description, article_id) VALUES (@Name, @Description, @Article_id)", con);
|
||||||
|
cmd.Parameters.AddWithValue("@Name", tag.Name);
|
||||||
|
cmd.Parameters.AddWithValue("@Description", tag.Description);
|
||||||
|
cmd.Parameters.AddWithValue("@Article_id", tag.ArticleId == 0 ? DBNull.Value : tag.ArticleId);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tag? Delete(int id)
|
||||||
|
{
|
||||||
|
var element = Get(id);
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"DELETE FROM tag WHERE tag_id = {id}", con);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tag? Get(int id)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"SELECT * FROM tag WHERE tag_id = {id}", con);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
return new Tag
|
||||||
|
{
|
||||||
|
Id = reader.GetInt32(0),
|
||||||
|
Name = reader.GetString(1),
|
||||||
|
Description = reader.GetString(2),
|
||||||
|
ArticleId = !reader.IsDBNull(3) ? reader.GetInt32(3) : 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Tag> GetAll()
|
||||||
|
{
|
||||||
|
var tags = new List<Tag>();
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("SELECT * FROM tag order by tag_id", con);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
tags.Add(new Tag
|
||||||
|
{
|
||||||
|
Id = reader.GetInt32(0),
|
||||||
|
Name = reader.GetString(1),
|
||||||
|
Description = reader.GetString(2),
|
||||||
|
ArticleId = !reader.IsDBNull(3) ? reader.GetInt32(3) : 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tag? Update(Tag tag)
|
||||||
|
{
|
||||||
|
using var con = SqlConnection.GetConnection();
|
||||||
|
con.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"UPDATE tag SET name = '{tag.Name}', description = '{tag.Description}', article_id = @Article_Id WHERE tag_id = {tag.Id}", con);
|
||||||
|
cmd.Parameters.AddWithValue("@Article_Id", tag.ArticleId == 0 ? DBNull.Value : tag.ArticleId);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
var element = Get(tag.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
201
NewsBlog/NewsBlogView/FormArticle.Designer.cs
generated
Normal file
201
NewsBlog/NewsBlogView/FormArticle.Designer.cs
generated
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace NewsBlogView
|
||||||
|
{
|
||||||
|
partial class FormArticle
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
buttonDelete = new Button();
|
||||||
|
buttonUpdate = new Button();
|
||||||
|
buttonCreate = new Button();
|
||||||
|
comboBoxAuthor = new ComboBox();
|
||||||
|
comboBoxCategory = new ComboBox();
|
||||||
|
textBoxTitle = new TextBox();
|
||||||
|
dataGridView = new DataGridView();
|
||||||
|
textBoxContent = new TextBox();
|
||||||
|
labelTitle = new Label();
|
||||||
|
labelContent = new Label();
|
||||||
|
labelAuthor = new Label();
|
||||||
|
labelCategory = new Label();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonDelete
|
||||||
|
//
|
||||||
|
buttonDelete.Location = new Point(755, 292);
|
||||||
|
buttonDelete.Name = "buttonDelete";
|
||||||
|
buttonDelete.Size = new Size(128, 30);
|
||||||
|
buttonDelete.TabIndex = 28;
|
||||||
|
buttonDelete.Text = "Удалить";
|
||||||
|
buttonDelete.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelete.Click += ButtonDelete_Click;
|
||||||
|
//
|
||||||
|
// buttonUpdate
|
||||||
|
//
|
||||||
|
buttonUpdate.Location = new Point(755, 256);
|
||||||
|
buttonUpdate.Name = "buttonUpdate";
|
||||||
|
buttonUpdate.Size = new Size(128, 30);
|
||||||
|
buttonUpdate.TabIndex = 27;
|
||||||
|
buttonUpdate.Text = "Изменить";
|
||||||
|
buttonUpdate.UseVisualStyleBackColor = true;
|
||||||
|
buttonUpdate.Click += ButtonUpdate_Click;
|
||||||
|
//
|
||||||
|
// buttonCreate
|
||||||
|
//
|
||||||
|
buttonCreate.Location = new Point(755, 220);
|
||||||
|
buttonCreate.Name = "buttonCreate";
|
||||||
|
buttonCreate.Size = new Size(128, 30);
|
||||||
|
buttonCreate.TabIndex = 26;
|
||||||
|
buttonCreate.Text = "Добавить";
|
||||||
|
buttonCreate.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreate.Click += ButtonCreate_Click;
|
||||||
|
//
|
||||||
|
// comboBoxAuthor
|
||||||
|
//
|
||||||
|
comboBoxAuthor.FormattingEnabled = true;
|
||||||
|
comboBoxAuthor.Location = new Point(718, 129);
|
||||||
|
comboBoxAuthor.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
comboBoxAuthor.Name = "comboBoxAuthor";
|
||||||
|
comboBoxAuthor.Size = new Size(201, 23);
|
||||||
|
comboBoxAuthor.TabIndex = 35;
|
||||||
|
//
|
||||||
|
// comboBoxCategory
|
||||||
|
//
|
||||||
|
comboBoxCategory.FormattingEnabled = true;
|
||||||
|
comboBoxCategory.Location = new Point(717, 174);
|
||||||
|
comboBoxCategory.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
comboBoxCategory.Name = "comboBoxCategory";
|
||||||
|
comboBoxCategory.Size = new Size(201, 23);
|
||||||
|
comboBoxCategory.TabIndex = 35;
|
||||||
|
//
|
||||||
|
// textBoxTitle
|
||||||
|
//
|
||||||
|
textBoxTitle.Location = new Point(717, 41);
|
||||||
|
textBoxTitle.Name = "textBoxTitle";
|
||||||
|
textBoxTitle.Size = new Size(201, 23);
|
||||||
|
textBoxTitle.TabIndex = 21;
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.AllowUserToAddRows = false;
|
||||||
|
dataGridView.AllowUserToDeleteRows = false;
|
||||||
|
dataGridView.BackgroundColor = SystemColors.Window;
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Location = new Point(13, 14);
|
||||||
|
dataGridView.MultiSelect = false;
|
||||||
|
dataGridView.Name = "dataGridView";
|
||||||
|
dataGridView.RowHeadersWidth = 51;
|
||||||
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
dataGridView.Size = new Size(610, 608);
|
||||||
|
dataGridView.TabIndex = 15;
|
||||||
|
dataGridView.CellClick += DataGridView_CellClick;
|
||||||
|
//
|
||||||
|
// textBoxContent
|
||||||
|
//
|
||||||
|
textBoxContent.Location = new Point(717, 84);
|
||||||
|
textBoxContent.Name = "textBoxContent";
|
||||||
|
textBoxContent.Size = new Size(201, 23);
|
||||||
|
textBoxContent.TabIndex = 32;
|
||||||
|
//
|
||||||
|
// labelTitle
|
||||||
|
//
|
||||||
|
labelTitle.AutoSize = true;
|
||||||
|
labelTitle.Location = new Point(633, 44);
|
||||||
|
labelTitle.Name = "labelTitle";
|
||||||
|
labelTitle.Size = new Size(71, 15);
|
||||||
|
labelTitle.TabIndex = 31;
|
||||||
|
labelTitle.Text = "Заголовок: ";
|
||||||
|
//
|
||||||
|
// labelContent
|
||||||
|
//
|
||||||
|
labelContent.AutoSize = true;
|
||||||
|
labelContent.Location = new Point(629, 87);
|
||||||
|
labelContent.Name = "labelContent";
|
||||||
|
labelContent.Size = new Size(82, 15);
|
||||||
|
labelContent.TabIndex = 42;
|
||||||
|
labelContent.Text = "Содержимое:";
|
||||||
|
//
|
||||||
|
// labelAuthor
|
||||||
|
//
|
||||||
|
labelAuthor.AutoSize = true;
|
||||||
|
labelAuthor.Location = new Point(630, 132);
|
||||||
|
labelAuthor.Name = "labelAuthor";
|
||||||
|
labelAuthor.Size = new Size(43, 15);
|
||||||
|
labelAuthor.TabIndex = 44;
|
||||||
|
labelAuthor.Text = "Автор:";
|
||||||
|
//
|
||||||
|
// labelCategory
|
||||||
|
//
|
||||||
|
labelCategory.AutoSize = true;
|
||||||
|
labelCategory.Location = new Point(629, 177);
|
||||||
|
labelCategory.Name = "labelCategory";
|
||||||
|
labelCategory.Size = new Size(66, 15);
|
||||||
|
labelCategory.TabIndex = 44;
|
||||||
|
labelCategory.Text = "Категория:";
|
||||||
|
//
|
||||||
|
// FormArticle
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(990, 450);
|
||||||
|
Controls.Add(labelAuthor);
|
||||||
|
Controls.Add(labelContent);
|
||||||
|
Controls.Add(labelTitle);
|
||||||
|
Controls.Add(labelCategory);
|
||||||
|
Controls.Add(textBoxContent);
|
||||||
|
Controls.Add(buttonDelete);
|
||||||
|
Controls.Add(buttonUpdate);
|
||||||
|
Controls.Add(buttonCreate);
|
||||||
|
Controls.Add(textBoxTitle);
|
||||||
|
Controls.Add(dataGridView);
|
||||||
|
Controls.Add(comboBoxAuthor);
|
||||||
|
Controls.Add(comboBoxCategory);
|
||||||
|
Name = "FormArticle";
|
||||||
|
Text = "Статьи";
|
||||||
|
Load += FormArticle_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonDelete;
|
||||||
|
private Button buttonUpdate;
|
||||||
|
private Button buttonCreate;
|
||||||
|
private TextBox textBoxTitle;
|
||||||
|
private TextBox textBoxContent;
|
||||||
|
private ComboBox comboBoxAuthor;
|
||||||
|
private ComboBox comboBoxCategory;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private Label labelTitle;
|
||||||
|
private Label labelContent;
|
||||||
|
private Label labelAuthor;
|
||||||
|
private Label labelCategory;
|
||||||
|
}
|
||||||
|
}
|
148
NewsBlog/NewsBlogView/FormArticle.cs
Normal file
148
NewsBlog/NewsBlogView/FormArticle.cs
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using NewsBlogAbstractions.WorkAbstractions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.ComponentModel.Design;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace NewsBlogView
|
||||||
|
{
|
||||||
|
public partial class FormArticle : Form
|
||||||
|
{
|
||||||
|
private readonly IArticleWork _articleLogic;
|
||||||
|
private readonly IAuthorWork _authorLogic;
|
||||||
|
private readonly ICategoryWork _categoryLogic;
|
||||||
|
public FormArticle(IArticleWork articleLogic, IAuthorWork authorLogic, ICategoryWork categoryLogic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_articleLogic = articleLogic;
|
||||||
|
_authorLogic = authorLogic;
|
||||||
|
_categoryLogic = categoryLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormArticle_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Article newArticle = new()
|
||||||
|
{
|
||||||
|
Title = textBoxTitle.Text,
|
||||||
|
Content = textBoxContent.Text,
|
||||||
|
PublicationDate = DateTime.Now,
|
||||||
|
AuthorId = ((Author?)comboBoxAuthor.SelectedItem)?.Id ?? 0,
|
||||||
|
CategoryId = ((Category?)comboBoxCategory.SelectedItem)?.Id ?? 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
_articleLogic.Create(newArticle);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
var articles = _articleLogic.GetAll();
|
||||||
|
|
||||||
|
dataGridView.Rows.Clear();
|
||||||
|
|
||||||
|
if (dataGridView.ColumnCount == 0)
|
||||||
|
{
|
||||||
|
dataGridView.Columns.Add("Id", "ID");
|
||||||
|
dataGridView.Columns.Add("Title", "Заголовок");
|
||||||
|
dataGridView.Columns.Add("Content", "Содержимое");
|
||||||
|
dataGridView.Columns.Add("Date", "Дата публикации");
|
||||||
|
dataGridView.Columns.Add("AuthorId", "AuthorId");
|
||||||
|
dataGridView.Columns.Add("CategoryId", "CategoryId");
|
||||||
|
dataGridView.Columns["AuthorId"].Visible = false;
|
||||||
|
dataGridView.Columns["CategoryId"].Visible = false;
|
||||||
|
dataGridView.Columns.Add("Author", "Автор");
|
||||||
|
dataGridView.Columns.Add("Category", "Категория");
|
||||||
|
}
|
||||||
|
|
||||||
|
dataGridView.Columns["Id"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Title"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Content"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Date"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Author"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Category"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
|
||||||
|
comboBoxAuthor.DataSource = _authorLogic.GetAll();
|
||||||
|
comboBoxAuthor.DisplayMember = "Author";
|
||||||
|
comboBoxAuthor.ValueMember = "Name";
|
||||||
|
|
||||||
|
comboBoxCategory.DataSource = _categoryLogic.GetAll();
|
||||||
|
comboBoxCategory.DisplayMember = "Category";
|
||||||
|
comboBoxCategory.ValueMember = "Name";
|
||||||
|
|
||||||
|
foreach (var article in articles)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(article.Id, article.Title, article.Content, article.PublicationDate.ToString("d"),
|
||||||
|
article.AuthorId, article.CategoryId, _authorLogic.Get(article.AuthorId)?.Name, _categoryLogic.Get(article.CategoryId)?.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count > 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||||
|
int articleId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
|
Article updatedArticle = new()
|
||||||
|
{
|
||||||
|
Id = articleId,
|
||||||
|
Title = textBoxTitle.Text,
|
||||||
|
Content = textBoxContent.Text,
|
||||||
|
PublicationDate = DateTime.Now,
|
||||||
|
AuthorId = ((Author?)comboBoxAuthor.SelectedItem)?.Id ?? 0,
|
||||||
|
CategoryId = ((Category?)comboBoxCategory.SelectedItem)?.Id ?? 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
_articleLogic.Update(updatedArticle);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Пожалуйста, выберите статью, информацию о которой необходимо обновить");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDelete_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count > 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||||
|
int articleId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
|
_articleLogic.Delete(articleId);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Пожалуйста, выберите статью, информацию о которой необходимо удалить");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.RowIndex >= 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
|
||||||
|
textBoxTitle.Text = row.Cells["Title"].Value.ToString();
|
||||||
|
textBoxContent.Text = row.Cells["Content"].Value.ToString();
|
||||||
|
comboBoxAuthor.SelectedValue = row.Cells["Author"].Value ?? new Author { Name = "Неизвестный автор" };
|
||||||
|
comboBoxCategory.SelectedValue = row.Cells["Category"].Value ?? new Category { Name = "Неизвестная категория" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
NewsBlog/NewsBlogView/FormArticle.resx
Normal file
120
NewsBlog/NewsBlogView/FormArticle.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
175
NewsBlog/NewsBlogView/FormAuthor.Designer.cs
generated
Normal file
175
NewsBlog/NewsBlogView/FormAuthor.Designer.cs
generated
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace NewsBlogView
|
||||||
|
{
|
||||||
|
partial class FormAuthor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
buttonDelete = new Button();
|
||||||
|
buttonUpdate = new Button();
|
||||||
|
buttonCreate = new Button();
|
||||||
|
textBoxPhone = new TextBox();
|
||||||
|
textBoxName = new TextBox();
|
||||||
|
dataGridView = new DataGridView();
|
||||||
|
textBoxDescription = new TextBox();
|
||||||
|
labelName = new Label();
|
||||||
|
labelDescription = new Label();
|
||||||
|
labelPhone = new Label();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonDelete
|
||||||
|
//
|
||||||
|
buttonDelete.Location = new Point(741, 292);
|
||||||
|
buttonDelete.Name = "buttonDelete";
|
||||||
|
buttonDelete.Size = new Size(128, 30);
|
||||||
|
buttonDelete.TabIndex = 28;
|
||||||
|
buttonDelete.Text = "Удалить";
|
||||||
|
buttonDelete.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelete.Click += ButtonDelete_Click;
|
||||||
|
//
|
||||||
|
// buttonUpdate
|
||||||
|
//
|
||||||
|
buttonUpdate.Location = new Point(741, 256);
|
||||||
|
buttonUpdate.Name = "buttonUpdate";
|
||||||
|
buttonUpdate.Size = new Size(128, 30);
|
||||||
|
buttonUpdate.TabIndex = 27;
|
||||||
|
buttonUpdate.Text = "Изменить";
|
||||||
|
buttonUpdate.UseVisualStyleBackColor = true;
|
||||||
|
buttonUpdate.Click += ButtonUpdate_Click;
|
||||||
|
//
|
||||||
|
// buttonCreate
|
||||||
|
//
|
||||||
|
buttonCreate.Location = new Point(741, 220);
|
||||||
|
buttonCreate.Name = "buttonCreate";
|
||||||
|
buttonCreate.Size = new Size(128, 30);
|
||||||
|
buttonCreate.TabIndex = 26;
|
||||||
|
buttonCreate.Text = "Добавить";
|
||||||
|
buttonCreate.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreate.Click += ButtonCreate_Click;
|
||||||
|
//
|
||||||
|
// textBoxPhone
|
||||||
|
//
|
||||||
|
textBoxPhone.Location = new Point(703, 131);
|
||||||
|
textBoxPhone.Name = "textBoxPhone";
|
||||||
|
textBoxPhone.Size = new Size(201, 23);
|
||||||
|
textBoxPhone.TabIndex = 35;
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
textBoxName.Location = new Point(704, 41);
|
||||||
|
textBoxName.Name = "textBoxName";
|
||||||
|
textBoxName.Size = new Size(201, 23);
|
||||||
|
textBoxName.TabIndex = 21;
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.AllowUserToAddRows = false;
|
||||||
|
dataGridView.AllowUserToDeleteRows = false;
|
||||||
|
dataGridView.BackgroundColor = SystemColors.Window;
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Location = new Point(13, 14);
|
||||||
|
dataGridView.MultiSelect = false;
|
||||||
|
dataGridView.Name = "dataGridView";
|
||||||
|
dataGridView.RowHeadersWidth = 51;
|
||||||
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
dataGridView.Size = new Size(610, 608);
|
||||||
|
dataGridView.TabIndex = 15;
|
||||||
|
dataGridView.CellClick += DataGridView_CellClick;
|
||||||
|
//
|
||||||
|
// textBoxDescription
|
||||||
|
//
|
||||||
|
textBoxDescription.Location = new Point(703, 84);
|
||||||
|
textBoxDescription.Name = "textBoxDescription";
|
||||||
|
textBoxDescription.Size = new Size(201, 23);
|
||||||
|
textBoxDescription.TabIndex = 32;
|
||||||
|
//
|
||||||
|
// labelName
|
||||||
|
//
|
||||||
|
labelName.AutoSize = true;
|
||||||
|
labelName.Location = new Point(633, 44);
|
||||||
|
labelName.Name = "labelName";
|
||||||
|
labelName.Size = new Size(40, 15);
|
||||||
|
labelName.TabIndex = 31;
|
||||||
|
labelName.Text = "ФИО: ";
|
||||||
|
//
|
||||||
|
// labelDescription
|
||||||
|
//
|
||||||
|
labelDescription.AutoSize = true;
|
||||||
|
labelDescription.Location = new Point(629, 87);
|
||||||
|
labelDescription.Name = "labelDescription";
|
||||||
|
labelDescription.Size = new Size(68, 15);
|
||||||
|
labelDescription.TabIndex = 42;
|
||||||
|
labelDescription.Text = "Описание: ";
|
||||||
|
//
|
||||||
|
// labelPhone
|
||||||
|
//
|
||||||
|
labelPhone.AutoSize = true;
|
||||||
|
labelPhone.Location = new Point(629, 134);
|
||||||
|
labelPhone.Name = "labelPhone";
|
||||||
|
labelPhone.Size = new Size(58, 15);
|
||||||
|
labelPhone.TabIndex = 44;
|
||||||
|
labelPhone.Text = "Телефон:";
|
||||||
|
//
|
||||||
|
// FormAuthor
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(990, 450);
|
||||||
|
Controls.Add(labelPhone);
|
||||||
|
Controls.Add(labelDescription);
|
||||||
|
Controls.Add(labelName);
|
||||||
|
Controls.Add(buttonDelete);
|
||||||
|
Controls.Add(buttonUpdate);
|
||||||
|
Controls.Add(buttonCreate);
|
||||||
|
Controls.Add(textBoxName);
|
||||||
|
Controls.Add(textBoxDescription);
|
||||||
|
Controls.Add(textBoxPhone);
|
||||||
|
Controls.Add(dataGridView);
|
||||||
|
Name = "FormAuthor";
|
||||||
|
Text = "Авторы";
|
||||||
|
Load += FormAuthor_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonDelete;
|
||||||
|
private Button buttonUpdate;
|
||||||
|
private Button buttonCreate;
|
||||||
|
private TextBox textBoxName;
|
||||||
|
private TextBox textBoxDescription;
|
||||||
|
private TextBox textBoxPhone;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private Label labelName;
|
||||||
|
private Label labelDescription;
|
||||||
|
private Label labelPhone;
|
||||||
|
}
|
||||||
|
}
|
121
NewsBlog/NewsBlogView/FormAuthor.cs
Normal file
121
NewsBlog/NewsBlogView/FormAuthor.cs
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using NewsBlogAbstractions.WorkAbstractions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace NewsBlogView
|
||||||
|
{
|
||||||
|
public partial class FormAuthor : Form
|
||||||
|
{
|
||||||
|
private readonly IAuthorWork _authorLogic;
|
||||||
|
public FormAuthor(IAuthorWork authorLogic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_authorLogic = authorLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormAuthor_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Author newAuthor = new()
|
||||||
|
{
|
||||||
|
Name = textBoxName.Text,
|
||||||
|
Description = textBoxDescription.Text,
|
||||||
|
Phone = textBoxPhone.Text,
|
||||||
|
};
|
||||||
|
|
||||||
|
_authorLogic.Create(newAuthor);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
var authors = _authorLogic.GetAll();
|
||||||
|
|
||||||
|
dataGridView.Rows.Clear();
|
||||||
|
|
||||||
|
if (dataGridView.ColumnCount == 0)
|
||||||
|
{
|
||||||
|
dataGridView.Columns.Add("Id", "ID");
|
||||||
|
dataGridView.Columns.Add("Name", "Имя");
|
||||||
|
dataGridView.Columns.Add("Description", "Описание");
|
||||||
|
dataGridView.Columns.Add("Phone", "Телефон");
|
||||||
|
}
|
||||||
|
|
||||||
|
dataGridView.Columns["Id"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Description"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Phone"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
|
||||||
|
foreach (var author in authors)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(author.Id, author.Name, author.Description, author.Phone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count > 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||||
|
int authorId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
|
Author updatedAuthor = new()
|
||||||
|
{
|
||||||
|
Id = authorId,
|
||||||
|
Name = textBoxName.Text,
|
||||||
|
Description = textBoxDescription.Text,
|
||||||
|
Phone = textBoxPhone.Text,
|
||||||
|
};
|
||||||
|
|
||||||
|
_authorLogic.Update(updatedAuthor);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Пожалуйста, выберите автора, информацию о котором необходимо обновить");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDelete_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count > 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||||
|
int authorId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
|
_authorLogic.Delete(authorId);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Пожалуйста, выберите автора, информацию о котором необходимо удалить");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.RowIndex >= 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
|
||||||
|
textBoxName.Text = row.Cells["Name"].Value.ToString();
|
||||||
|
textBoxDescription.Text = row.Cells["Description"].Value.ToString();
|
||||||
|
textBoxPhone.Text = row.Cells["Phone"].Value.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
NewsBlog/NewsBlogView/FormAuthor.resx
Normal file
120
NewsBlog/NewsBlogView/FormAuthor.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
129
NewsBlog/NewsBlogView/FormCategory.Designer.cs
generated
Normal file
129
NewsBlog/NewsBlogView/FormCategory.Designer.cs
generated
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
namespace NewsBlogView
|
||||||
|
{
|
||||||
|
partial class FormCategory
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
buttonDelete = new Button();
|
||||||
|
buttonUpdate = new Button();
|
||||||
|
buttonCreate = new Button();
|
||||||
|
textBoxName = new TextBox();
|
||||||
|
dataGridView = new DataGridView();
|
||||||
|
labelName = new Label();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonDelete
|
||||||
|
//
|
||||||
|
buttonDelete.Location = new Point(741, 292);
|
||||||
|
buttonDelete.Name = "buttonDelete";
|
||||||
|
buttonDelete.Size = new Size(128, 30);
|
||||||
|
buttonDelete.TabIndex = 28;
|
||||||
|
buttonDelete.Text = "Удалить";
|
||||||
|
buttonDelete.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelete.Click += ButtonDelete_Click;
|
||||||
|
//
|
||||||
|
// buttonUpdate
|
||||||
|
//
|
||||||
|
buttonUpdate.Location = new Point(741, 256);
|
||||||
|
buttonUpdate.Name = "buttonUpdate";
|
||||||
|
buttonUpdate.Size = new Size(128, 30);
|
||||||
|
buttonUpdate.TabIndex = 27;
|
||||||
|
buttonUpdate.Text = "Изменить";
|
||||||
|
buttonUpdate.UseVisualStyleBackColor = true;
|
||||||
|
buttonUpdate.Click += ButtonUpdate_Click;
|
||||||
|
//
|
||||||
|
// buttonCreate
|
||||||
|
//
|
||||||
|
buttonCreate.Location = new Point(741, 220);
|
||||||
|
buttonCreate.Name = "buttonCreate";
|
||||||
|
buttonCreate.Size = new Size(128, 30);
|
||||||
|
buttonCreate.TabIndex = 26;
|
||||||
|
buttonCreate.Text = "Добавить";
|
||||||
|
buttonCreate.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreate.Click += ButtonCreate_Click;
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
textBoxName.Location = new Point(704, 41);
|
||||||
|
textBoxName.Name = "textBoxName";
|
||||||
|
textBoxName.Size = new Size(201, 23);
|
||||||
|
textBoxName.TabIndex = 21;
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.AllowUserToAddRows = false;
|
||||||
|
dataGridView.AllowUserToDeleteRows = false;
|
||||||
|
dataGridView.BackgroundColor = SystemColors.Window;
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Location = new Point(13, 14);
|
||||||
|
dataGridView.MultiSelect = false;
|
||||||
|
dataGridView.Name = "dataGridView";
|
||||||
|
dataGridView.RowHeadersWidth = 51;
|
||||||
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
dataGridView.Size = new Size(610, 608);
|
||||||
|
dataGridView.TabIndex = 15;
|
||||||
|
dataGridView.CellClick += DataGridView_CellClick;
|
||||||
|
//
|
||||||
|
// labelName
|
||||||
|
//
|
||||||
|
labelName.AutoSize = true;
|
||||||
|
labelName.Location = new Point(633, 44);
|
||||||
|
labelName.Name = "labelName";
|
||||||
|
labelName.Size = new Size(65, 15);
|
||||||
|
labelName.TabIndex = 31;
|
||||||
|
labelName.Text = "Название: ";
|
||||||
|
//
|
||||||
|
// FormCategory
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(990, 450);
|
||||||
|
Controls.Add(textBoxName);
|
||||||
|
Controls.Add(dataGridView);
|
||||||
|
Controls.Add(buttonDelete);
|
||||||
|
Controls.Add(buttonUpdate);
|
||||||
|
Controls.Add(buttonCreate);
|
||||||
|
Controls.Add(labelName);
|
||||||
|
Name = "FormCategory";
|
||||||
|
Text = "Категории";
|
||||||
|
Load += FormCategory_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonDelete;
|
||||||
|
private Button buttonUpdate;
|
||||||
|
private Button buttonCreate;
|
||||||
|
private TextBox textBoxName;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private Label labelName;
|
||||||
|
}
|
||||||
|
}
|
111
NewsBlog/NewsBlogView/FormCategory.cs
Normal file
111
NewsBlog/NewsBlogView/FormCategory.cs
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using NewsBlogAbstractions.WorkAbstractions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace NewsBlogView
|
||||||
|
{
|
||||||
|
public partial class FormCategory : Form
|
||||||
|
{
|
||||||
|
private readonly ICategoryWork _categoryLogic;
|
||||||
|
public FormCategory(ICategoryWork categoryLogic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_categoryLogic = categoryLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormCategory_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Category newCategory = new()
|
||||||
|
{
|
||||||
|
Name = textBoxName.Text,
|
||||||
|
};
|
||||||
|
|
||||||
|
_categoryLogic.Create(newCategory);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
var categories = _categoryLogic.GetAll();
|
||||||
|
|
||||||
|
dataGridView.Rows.Clear();
|
||||||
|
|
||||||
|
if (dataGridView.ColumnCount == 0)
|
||||||
|
{
|
||||||
|
dataGridView.Columns.Add("Id", "ID");
|
||||||
|
dataGridView.Columns.Add("Name", "Имя");
|
||||||
|
}
|
||||||
|
|
||||||
|
dataGridView.Columns["Id"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
|
||||||
|
foreach (var category in categories)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(category.Id, category.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count > 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||||
|
int categoryId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
|
Category updatedCategory = new()
|
||||||
|
{
|
||||||
|
Id = categoryId,
|
||||||
|
Name = textBoxName.Text,
|
||||||
|
};
|
||||||
|
|
||||||
|
_categoryLogic.Update(updatedCategory);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Пожалуйста, выберите категорию, информацию о которой необходимо обновить");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDelete_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count > 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||||
|
int categoryId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
|
_categoryLogic.Delete(categoryId);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Пожалуйста, выберите категорию, информацию о которой необходимо удалить");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.RowIndex >= 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
|
||||||
|
textBoxName.Text = row.Cells["Name"].Value.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
NewsBlog/NewsBlogView/FormCategory.resx
Normal file
120
NewsBlog/NewsBlogView/FormCategory.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
177
NewsBlog/NewsBlogView/FormComment.Designer.cs
generated
Normal file
177
NewsBlog/NewsBlogView/FormComment.Designer.cs
generated
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace NewsBlogView
|
||||||
|
{
|
||||||
|
partial class FormComment
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
buttonDelete = new Button();
|
||||||
|
buttonUpdate = new Button();
|
||||||
|
buttonCreate = new Button();
|
||||||
|
textBoxTitle = new TextBox();
|
||||||
|
textBoxContent = new TextBox();
|
||||||
|
comboBoxArticle = new ComboBox();
|
||||||
|
dataGridView = new DataGridView();
|
||||||
|
labelTitle = new Label();
|
||||||
|
labelContent = new Label();
|
||||||
|
labelArticle = new Label();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonDelete
|
||||||
|
//
|
||||||
|
buttonDelete.Location = new Point(758, 247);
|
||||||
|
buttonDelete.Name = "buttonDelete";
|
||||||
|
buttonDelete.Size = new Size(128, 30);
|
||||||
|
buttonDelete.TabIndex = 28;
|
||||||
|
buttonDelete.Text = "Удалить";
|
||||||
|
buttonDelete.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelete.Click += ButtonDelete_Click;
|
||||||
|
//
|
||||||
|
// buttonUpdate
|
||||||
|
//
|
||||||
|
buttonUpdate.Location = new Point(758, 211);
|
||||||
|
buttonUpdate.Name = "buttonUpdate";
|
||||||
|
buttonUpdate.Size = new Size(128, 30);
|
||||||
|
buttonUpdate.TabIndex = 27;
|
||||||
|
buttonUpdate.Text = "Изменить";
|
||||||
|
buttonUpdate.UseVisualStyleBackColor = true;
|
||||||
|
buttonUpdate.Click += ButtonUpdate_Click;
|
||||||
|
//
|
||||||
|
// buttonCreate
|
||||||
|
//
|
||||||
|
buttonCreate.Location = new Point(758, 175);
|
||||||
|
buttonCreate.Name = "buttonCreate";
|
||||||
|
buttonCreate.Size = new Size(128, 30);
|
||||||
|
buttonCreate.TabIndex = 26;
|
||||||
|
buttonCreate.Text = "Добавить";
|
||||||
|
buttonCreate.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreate.Click += ButtonCreate_Click;
|
||||||
|
//
|
||||||
|
// textBoxTitle
|
||||||
|
//
|
||||||
|
textBoxTitle.Location = new Point(721, 41);
|
||||||
|
textBoxTitle.Name = "textBoxTitle";
|
||||||
|
textBoxTitle.Size = new Size(201, 23);
|
||||||
|
textBoxTitle.TabIndex = 21;
|
||||||
|
//
|
||||||
|
// textBoxContent
|
||||||
|
//
|
||||||
|
textBoxContent.Location = new Point(720, 84);
|
||||||
|
textBoxContent.Name = "textBoxContent";
|
||||||
|
textBoxContent.Size = new Size(201, 23);
|
||||||
|
textBoxContent.TabIndex = 32;
|
||||||
|
//
|
||||||
|
// comboBoxArticle
|
||||||
|
//
|
||||||
|
comboBoxArticle.FormattingEnabled = true;
|
||||||
|
comboBoxArticle.Location = new Point(720, 131);
|
||||||
|
comboBoxArticle.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
comboBoxArticle.Name = "comboBoxArticle";
|
||||||
|
comboBoxArticle.Size = new Size(201, 23);
|
||||||
|
comboBoxArticle.TabIndex = 35;
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.AllowUserToAddRows = false;
|
||||||
|
dataGridView.AllowUserToDeleteRows = false;
|
||||||
|
dataGridView.BackgroundColor = SystemColors.Window;
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Location = new Point(13, 14);
|
||||||
|
dataGridView.MultiSelect = false;
|
||||||
|
dataGridView.Name = "dataGridView";
|
||||||
|
dataGridView.RowHeadersWidth = 51;
|
||||||
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
dataGridView.Size = new Size(610, 608);
|
||||||
|
dataGridView.TabIndex = 15;
|
||||||
|
dataGridView.CellClick += DataGridView_CellClick;
|
||||||
|
//
|
||||||
|
// labelTitle
|
||||||
|
//
|
||||||
|
labelTitle.AutoSize = true;
|
||||||
|
labelTitle.Location = new Point(633, 44);
|
||||||
|
labelTitle.Name = "labelTitle";
|
||||||
|
labelTitle.Size = new Size(71, 15);
|
||||||
|
labelTitle.TabIndex = 31;
|
||||||
|
labelTitle.Text = "Заголовок: ";
|
||||||
|
//
|
||||||
|
// labelContent
|
||||||
|
//
|
||||||
|
labelContent.AutoSize = true;
|
||||||
|
labelContent.Location = new Point(629, 87);
|
||||||
|
labelContent.Name = "labelContent";
|
||||||
|
labelContent.Size = new Size(85, 15);
|
||||||
|
labelContent.TabIndex = 42;
|
||||||
|
labelContent.Text = "Содержимое: ";
|
||||||
|
//
|
||||||
|
// labelArticle
|
||||||
|
//
|
||||||
|
labelArticle.AutoSize = true;
|
||||||
|
labelArticle.Location = new Point(633, 134);
|
||||||
|
labelArticle.Name = "labelArticle";
|
||||||
|
labelArticle.Size = new Size(46, 15);
|
||||||
|
labelArticle.TabIndex = 44;
|
||||||
|
labelArticle.Text = "Статья:";
|
||||||
|
//
|
||||||
|
// FormComment
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(990, 450);
|
||||||
|
Controls.Add(labelArticle);
|
||||||
|
Controls.Add(labelContent);
|
||||||
|
Controls.Add(labelTitle);
|
||||||
|
Controls.Add(buttonDelete);
|
||||||
|
Controls.Add(buttonUpdate);
|
||||||
|
Controls.Add(buttonCreate);
|
||||||
|
Controls.Add(textBoxContent);
|
||||||
|
Controls.Add(textBoxTitle);
|
||||||
|
Controls.Add(dataGridView);
|
||||||
|
Controls.Add(comboBoxArticle);
|
||||||
|
Name = "FormComment";
|
||||||
|
Text = "Комментарии";
|
||||||
|
Load += FormComment_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonDelete;
|
||||||
|
private Button buttonUpdate;
|
||||||
|
private Button buttonCreate;
|
||||||
|
private TextBox textBoxTitle;
|
||||||
|
private TextBox textBoxContent;
|
||||||
|
private ComboBox comboBoxArticle;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private Label labelTitle;
|
||||||
|
private Label labelContent;
|
||||||
|
private Label labelArticle;
|
||||||
|
}
|
||||||
|
}
|
133
NewsBlog/NewsBlogView/FormComment.cs
Normal file
133
NewsBlog/NewsBlogView/FormComment.cs
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using NewsBlogAbstractions.WorkAbstractions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace NewsBlogView
|
||||||
|
{
|
||||||
|
public partial class FormComment : Form
|
||||||
|
{
|
||||||
|
private readonly ICommentWork _commentLogic;
|
||||||
|
private readonly IArticleWork _articleLogic;
|
||||||
|
public FormComment(ICommentWork commentLogic, IArticleWork articleLogic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_commentLogic = commentLogic;
|
||||||
|
_articleLogic = articleLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormComment_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Comment newComment = new()
|
||||||
|
{
|
||||||
|
Title = textBoxTitle.Text,
|
||||||
|
Content = textBoxContent.Text,
|
||||||
|
CreateDate = DateTime.Now,
|
||||||
|
ArticleId = ((Article?)comboBoxArticle.SelectedItem)?.Id ?? 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
_commentLogic.Create(newComment);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
var comments = _commentLogic.GetAll();
|
||||||
|
|
||||||
|
dataGridView.Rows.Clear();
|
||||||
|
|
||||||
|
if (dataGridView.ColumnCount == 0)
|
||||||
|
{
|
||||||
|
dataGridView.Columns.Add("Id", "ID");
|
||||||
|
dataGridView.Columns.Add("Title", "Заголовок");
|
||||||
|
dataGridView.Columns.Add("Content", "Содержимое");
|
||||||
|
dataGridView.Columns.Add("Date", "Дата написания");
|
||||||
|
dataGridView.Columns.Add("ArticleId", "ArticleId");
|
||||||
|
dataGridView.Columns["ArticleId"].Visible = false;
|
||||||
|
dataGridView.Columns.Add("Article", "Статья");
|
||||||
|
}
|
||||||
|
|
||||||
|
dataGridView.Columns["Id"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Title"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Content"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Date"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Article"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
|
||||||
|
comboBoxArticle.DataSource = _articleLogic.GetAll();
|
||||||
|
comboBoxArticle.DisplayMember = "Article";
|
||||||
|
comboBoxArticle.ValueMember = "Title";
|
||||||
|
|
||||||
|
foreach (var comment in comments)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(comment.Id, comment.Title, comment.Content, comment.CreateDate.ToString("d"), comment.ArticleId, _articleLogic.Get(comment.ArticleId)?.Title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count > 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||||
|
int commentId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
|
Comment updatedComment = new()
|
||||||
|
{
|
||||||
|
Id = commentId,
|
||||||
|
Title = textBoxTitle.Text,
|
||||||
|
Content = textBoxContent.Text,
|
||||||
|
CreateDate = DateTime.Now,
|
||||||
|
ArticleId = ((Article?)comboBoxArticle.SelectedItem)?.Id ?? 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
_commentLogic.Update(updatedComment);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Пожалуйста, выберите комментарий, информацию о котором необходимо обновить");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDelete_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count > 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||||
|
int commentId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
|
_commentLogic.Delete(commentId);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Пожалуйста, выберите комментарий, информацию о котором необходимо удалить");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.RowIndex >= 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
|
||||||
|
textBoxTitle.Text = row.Cells["Title"].Value.ToString();
|
||||||
|
textBoxContent.Text = row.Cells["Content"].Value.ToString();
|
||||||
|
comboBoxArticle.SelectedValue = row.Cells["Article"].Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
NewsBlog/NewsBlogView/FormComment.resx
Normal file
120
NewsBlog/NewsBlogView/FormComment.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
185
NewsBlog/NewsBlogView/FormMain.Designer.cs
generated
Normal file
185
NewsBlog/NewsBlogView/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
namespace NewsBlogView
|
||||||
|
{
|
||||||
|
partial class FormMain
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
menuStrip1 = new MenuStrip();
|
||||||
|
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
articleToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
authorToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
categoryToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
commentToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
tagToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
замерВремениToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
замерыВремениToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
add1000ToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
get1000ToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
update1000ToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
delete1000ToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
labelTest = new Label();
|
||||||
|
menuStrip1.SuspendLayout();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// menuStrip1
|
||||||
|
//
|
||||||
|
menuStrip1.ImageScalingSize = new Size(20, 20);
|
||||||
|
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, замерВремениToolStripMenuItem, замерыВремениToolStripMenuItem });
|
||||||
|
menuStrip1.Location = new Point(0, 0);
|
||||||
|
menuStrip1.Name = "menuStrip1";
|
||||||
|
menuStrip1.Padding = new Padding(7, 3, 0, 3);
|
||||||
|
menuStrip1.Size = new Size(633, 30);
|
||||||
|
menuStrip1.TabIndex = 0;
|
||||||
|
menuStrip1.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// справочникиToolStripMenuItem
|
||||||
|
//
|
||||||
|
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { articleToolStripMenuItem, authorToolStripMenuItem, categoryToolStripMenuItem, commentToolStripMenuItem, tagToolStripMenuItem });
|
||||||
|
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||||
|
справочникиToolStripMenuItem.Size = new Size(117, 24);
|
||||||
|
справочникиToolStripMenuItem.Text = "Справочники";
|
||||||
|
//
|
||||||
|
// articleToolStripMenuItem
|
||||||
|
//
|
||||||
|
articleToolStripMenuItem.Name = "articleToolStripMenuItem";
|
||||||
|
articleToolStripMenuItem.Size = new Size(157, 26);
|
||||||
|
articleToolStripMenuItem.Text = "Статьи";
|
||||||
|
articleToolStripMenuItem.Click += articleToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// authorToolStripMenuItem
|
||||||
|
//
|
||||||
|
authorToolStripMenuItem.Name = "authorToolStripMenuItem";
|
||||||
|
authorToolStripMenuItem.Size = new Size(157, 26);
|
||||||
|
authorToolStripMenuItem.Text = "Авторы";
|
||||||
|
authorToolStripMenuItem.Click += authorToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// CategoryToolStripMenuItem
|
||||||
|
//
|
||||||
|
categoryToolStripMenuItem.Name = "categoryToolStripMenuItem";
|
||||||
|
categoryToolStripMenuItem.Size = new Size(157, 26);
|
||||||
|
categoryToolStripMenuItem.Text = "Категории";
|
||||||
|
categoryToolStripMenuItem.Click += categoryToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// commentToolStripMenuItem
|
||||||
|
//
|
||||||
|
commentToolStripMenuItem.Name = "commentToolStripMenuItem";
|
||||||
|
commentToolStripMenuItem.Size = new Size(157, 26);
|
||||||
|
commentToolStripMenuItem.Text = "Комментарии";
|
||||||
|
commentToolStripMenuItem.Click += commentToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// tagToolStripMenuItem
|
||||||
|
//
|
||||||
|
tagToolStripMenuItem.Name = "tagToolStripMenuItem";
|
||||||
|
tagToolStripMenuItem.Size = new Size(157, 26);
|
||||||
|
tagToolStripMenuItem.Text = "Тэги";
|
||||||
|
tagToolStripMenuItem.Click += tagToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// замерВремениToolStripMenuItem
|
||||||
|
//
|
||||||
|
замерВремениToolStripMenuItem.Name = "замерВремениToolStripMenuItem";
|
||||||
|
замерВремениToolStripMenuItem.Size = new Size(14, 24);
|
||||||
|
//
|
||||||
|
// замерыВремениToolStripMenuItem
|
||||||
|
//
|
||||||
|
замерыВремениToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { add1000ToolStripMenuItem, get1000ToolStripMenuItem, update1000ToolStripMenuItem, delete1000ToolStripMenuItem });
|
||||||
|
замерыВремениToolStripMenuItem.Name = "замерыВремениToolStripMenuItem";
|
||||||
|
замерыВремениToolStripMenuItem.Size = new Size(144, 24);
|
||||||
|
замерыВремениToolStripMenuItem.Text = "Замеры времени";
|
||||||
|
//
|
||||||
|
// add1000ToolStripMenuItem
|
||||||
|
//
|
||||||
|
add1000ToolStripMenuItem.Name = "add1000ToolStripMenuItem";
|
||||||
|
add1000ToolStripMenuItem.Size = new Size(224, 26);
|
||||||
|
add1000ToolStripMenuItem.Text = "Добавление 1000";
|
||||||
|
add1000ToolStripMenuItem.Click += add1000ToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// get1000ToolStripMenuItem
|
||||||
|
//
|
||||||
|
get1000ToolStripMenuItem.Name = "get1000ToolStripMenuItem";
|
||||||
|
get1000ToolStripMenuItem.Size = new Size(224, 26);
|
||||||
|
get1000ToolStripMenuItem.Text = "Получение 1000";
|
||||||
|
get1000ToolStripMenuItem.Click += get1000ToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// update1000ToolStripMenuItem
|
||||||
|
//
|
||||||
|
update1000ToolStripMenuItem.Name = "update1000ToolStripMenuItem";
|
||||||
|
update1000ToolStripMenuItem.Size = new Size(224, 26);
|
||||||
|
update1000ToolStripMenuItem.Text = "Обновление 1000";
|
||||||
|
update1000ToolStripMenuItem.Click += update1000ToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// delete1000ToolStripMenuItem
|
||||||
|
//
|
||||||
|
delete1000ToolStripMenuItem.Name = "delete1000ToolStripMenuItem";
|
||||||
|
delete1000ToolStripMenuItem.Size = new Size(224, 26);
|
||||||
|
delete1000ToolStripMenuItem.Text = "Удаление 1000";
|
||||||
|
delete1000ToolStripMenuItem.Click += delete1000ToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// labelTest
|
||||||
|
//
|
||||||
|
labelTest.BorderStyle = BorderStyle.FixedSingle;
|
||||||
|
labelTest.Location = new Point(178, 109);
|
||||||
|
labelTest.Name = "labelTest";
|
||||||
|
labelTest.Size = new Size(285, 133);
|
||||||
|
labelTest.TabIndex = 3;
|
||||||
|
labelTest.TextAlign = ContentAlignment.MiddleCenter;
|
||||||
|
//
|
||||||
|
// FormMain
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(633, 348);
|
||||||
|
Controls.Add(labelTest);
|
||||||
|
Controls.Add(menuStrip1);
|
||||||
|
MainMenuStrip = menuStrip1;
|
||||||
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
|
Name = "FormMain";
|
||||||
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
|
Text = "Электронный дневник";
|
||||||
|
menuStrip1.ResumeLayout(false);
|
||||||
|
menuStrip1.PerformLayout();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private MenuStrip menuStrip1;
|
||||||
|
private ToolStripMenuItem справочникиToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem замерВремениToolStripMenuItem;
|
||||||
|
private Label labelTest;
|
||||||
|
private ToolStripMenuItem articleToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem authorToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem categoryToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem commentToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem tagToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem замерыВремениToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem add1000ToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem get1000ToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem update1000ToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem delete1000ToolStripMenuItem;
|
||||||
|
}
|
||||||
|
}
|
135
NewsBlog/NewsBlogView/FormMain.cs
Normal file
135
NewsBlog/NewsBlogView/FormMain.cs
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using NewsBlogAbstractions.WorkAbstractions;
|
||||||
|
using System.Security.Policy;
|
||||||
|
|
||||||
|
namespace NewsBlogView
|
||||||
|
{
|
||||||
|
public partial class FormMain : Form
|
||||||
|
{
|
||||||
|
public FormMain()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void articleToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormArticle));
|
||||||
|
if (service is FormArticle form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void authorToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormAuthor));
|
||||||
|
if (service is FormAuthor form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void categoryToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormCategory));
|
||||||
|
if (service is FormCategory form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void commentToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormComment));
|
||||||
|
if (service is FormComment form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tagToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormTag));
|
||||||
|
if (service is FormTag form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void add1000ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(IAuthorWork));
|
||||||
|
if (service is IAuthorWork authorLogic)
|
||||||
|
{
|
||||||
|
DateTime startTime = DateTime.Now;
|
||||||
|
for (int i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
|
Author author = new()
|
||||||
|
{
|
||||||
|
Id = i + 1000,
|
||||||
|
Name = "ÔÈÎ " + i,
|
||||||
|
Description = "Îïèñàíèå " + i,
|
||||||
|
Phone = "Íîìåð " + i
|
||||||
|
};
|
||||||
|
authorLogic.CreateId(author);
|
||||||
|
}
|
||||||
|
DateTime endTime = DateTime.Now;
|
||||||
|
|
||||||
|
labelTest.Text = $"Äîáàâëåíèå 1000 ñòðîê âûïîëíåíî çà {(endTime - startTime).TotalMilliseconds} ìèëëèñåêóíä";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void get1000ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(IAuthorWork));
|
||||||
|
if (service is IAuthorWork authorLogic)
|
||||||
|
{
|
||||||
|
DateTime startTime = DateTime.Now;
|
||||||
|
for (int i =0; i < 1000; i++)
|
||||||
|
authorLogic.Get(i + 1000);
|
||||||
|
DateTime endTime = DateTime.Now;
|
||||||
|
|
||||||
|
labelTest.Text = $"Ïîëó÷åíèå 1000 ñòðîê âûïîëíåíî çà {(endTime - startTime).TotalMilliseconds} ìèëëèñåêóíä";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void update1000ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(IAuthorWork));
|
||||||
|
if (service is IAuthorWork authorLogic)
|
||||||
|
{
|
||||||
|
DateTime startTime = DateTime.Now;
|
||||||
|
for (int i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
|
Author author = new()
|
||||||
|
{
|
||||||
|
Id = i + 1000,
|
||||||
|
Name = "ÔÈÎ " + i + 2000,
|
||||||
|
Description = "Îïèñàíèå " + i + 2000,
|
||||||
|
Phone = "Íîìåð " + i + 2000
|
||||||
|
};
|
||||||
|
authorLogic.Update(author);
|
||||||
|
}
|
||||||
|
DateTime endTime = DateTime.Now;
|
||||||
|
|
||||||
|
labelTest.Text = $"Îáíîâëåíèå 1000 ñòðîê âûïîëíåíî çà {(endTime - startTime).TotalMilliseconds} ìèëëèñåêóíä";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void delete1000ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(IAuthorWork));
|
||||||
|
if (service is IAuthorWork authorLogic)
|
||||||
|
{
|
||||||
|
DateTime startTime = DateTime.Now;
|
||||||
|
for (int i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
|
authorLogic.Delete(i + 1000);
|
||||||
|
}
|
||||||
|
DateTime endTime = DateTime.Now;
|
||||||
|
|
||||||
|
labelTest.Text = $"Óäàëåíèå 1000 ñòðîê âûïîëíåíî çà {(endTime - startTime).TotalMilliseconds} ìèëëèñåêóíä";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
NewsBlog/NewsBlogView/FormMain.resx
Normal file
120
NewsBlog/NewsBlogView/FormMain.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
177
NewsBlog/NewsBlogView/FormTag.Designer.cs
generated
Normal file
177
NewsBlog/NewsBlogView/FormTag.Designer.cs
generated
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace NewsBlogView
|
||||||
|
{
|
||||||
|
partial class FormTag
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
buttonDelete = new Button();
|
||||||
|
buttonUpdate = new Button();
|
||||||
|
buttonCreate = new Button();
|
||||||
|
comboBoxArticle = new ComboBox();
|
||||||
|
textBoxName = new TextBox();
|
||||||
|
dataGridView = new DataGridView();
|
||||||
|
textBoxDescription = new TextBox();
|
||||||
|
labelName = new Label();
|
||||||
|
labelDescription = new Label();
|
||||||
|
labelArticle = new Label();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonDelete
|
||||||
|
//
|
||||||
|
buttonDelete.Location = new Point(741, 292);
|
||||||
|
buttonDelete.Name = "buttonDelete";
|
||||||
|
buttonDelete.Size = new Size(128, 30);
|
||||||
|
buttonDelete.TabIndex = 28;
|
||||||
|
buttonDelete.Text = "Удалить";
|
||||||
|
buttonDelete.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelete.Click += ButtonDelete_Click;
|
||||||
|
//
|
||||||
|
// buttonUpdate
|
||||||
|
//
|
||||||
|
buttonUpdate.Location = new Point(741, 256);
|
||||||
|
buttonUpdate.Name = "buttonUpdate";
|
||||||
|
buttonUpdate.Size = new Size(128, 30);
|
||||||
|
buttonUpdate.TabIndex = 27;
|
||||||
|
buttonUpdate.Text = "Изменить";
|
||||||
|
buttonUpdate.UseVisualStyleBackColor = true;
|
||||||
|
buttonUpdate.Click += ButtonUpdate_Click;
|
||||||
|
//
|
||||||
|
// buttonCreate
|
||||||
|
//
|
||||||
|
buttonCreate.Location = new Point(741, 220);
|
||||||
|
buttonCreate.Name = "buttonCreate";
|
||||||
|
buttonCreate.Size = new Size(128, 30);
|
||||||
|
buttonCreate.TabIndex = 26;
|
||||||
|
buttonCreate.Text = "Добавить";
|
||||||
|
buttonCreate.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreate.Click += ButtonCreate_Click;
|
||||||
|
//
|
||||||
|
// comboBoxArticle
|
||||||
|
//
|
||||||
|
comboBoxArticle.FormattingEnabled = true;
|
||||||
|
comboBoxArticle.Location = new Point(703, 131);
|
||||||
|
comboBoxArticle.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
comboBoxArticle.Name = "comboBoxArticle";
|
||||||
|
comboBoxArticle.Size = new Size(201, 23);
|
||||||
|
comboBoxArticle.TabIndex = 35;
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
textBoxName.Location = new Point(704, 41);
|
||||||
|
textBoxName.Name = "textBoxName";
|
||||||
|
textBoxName.Size = new Size(201, 23);
|
||||||
|
textBoxName.TabIndex = 21;
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.AllowUserToAddRows = false;
|
||||||
|
dataGridView.AllowUserToDeleteRows = false;
|
||||||
|
dataGridView.BackgroundColor = SystemColors.Window;
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Location = new Point(13, 14);
|
||||||
|
dataGridView.MultiSelect = false;
|
||||||
|
dataGridView.Name = "dataGridView";
|
||||||
|
dataGridView.RowHeadersWidth = 51;
|
||||||
|
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||||
|
dataGridView.Size = new Size(610, 608);
|
||||||
|
dataGridView.TabIndex = 15;
|
||||||
|
dataGridView.CellClick += DataGridView_CellClick;
|
||||||
|
//
|
||||||
|
// textBoxDescription
|
||||||
|
//
|
||||||
|
textBoxDescription.Location = new Point(703, 84);
|
||||||
|
textBoxDescription.Name = "textBoxDescription";
|
||||||
|
textBoxDescription.Size = new Size(201, 23);
|
||||||
|
textBoxDescription.TabIndex = 32;
|
||||||
|
//
|
||||||
|
// labelName
|
||||||
|
//
|
||||||
|
labelName.AutoSize = true;
|
||||||
|
labelName.Location = new Point(633, 44);
|
||||||
|
labelName.Name = "labelName";
|
||||||
|
labelName.Size = new Size(65, 15);
|
||||||
|
labelName.TabIndex = 31;
|
||||||
|
labelName.Text = "Название: ";
|
||||||
|
//
|
||||||
|
// labelDescription
|
||||||
|
//
|
||||||
|
labelDescription.AutoSize = true;
|
||||||
|
labelDescription.Location = new Point(629, 87);
|
||||||
|
labelDescription.Name = "labelDescription";
|
||||||
|
labelDescription.Size = new Size(68, 15);
|
||||||
|
labelDescription.TabIndex = 42;
|
||||||
|
labelDescription.Text = "Описание: ";
|
||||||
|
//
|
||||||
|
// labelArticle
|
||||||
|
//
|
||||||
|
labelArticle.AutoSize = true;
|
||||||
|
labelArticle.Location = new Point(629, 134);
|
||||||
|
labelArticle.Name = "labelArticle";
|
||||||
|
labelArticle.Size = new Size(46, 15);
|
||||||
|
labelArticle.TabIndex = 44;
|
||||||
|
labelArticle.Text = "Статья:";
|
||||||
|
//
|
||||||
|
// FormTag
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(990, 450);
|
||||||
|
Controls.Add(labelArticle);
|
||||||
|
Controls.Add(labelDescription);
|
||||||
|
Controls.Add(labelName);
|
||||||
|
Controls.Add(textBoxDescription);
|
||||||
|
Controls.Add(buttonDelete);
|
||||||
|
Controls.Add(buttonUpdate);
|
||||||
|
Controls.Add(buttonCreate);
|
||||||
|
Controls.Add(textBoxName);
|
||||||
|
Controls.Add(dataGridView);
|
||||||
|
Controls.Add(comboBoxArticle);
|
||||||
|
Name = "FormTag";
|
||||||
|
Text = "Тэги";
|
||||||
|
Load += FormTag_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonDelete;
|
||||||
|
private Button buttonUpdate;
|
||||||
|
private Button buttonCreate;
|
||||||
|
private TextBox textBoxName;
|
||||||
|
private TextBox textBoxDescription;
|
||||||
|
private ComboBox comboBoxArticle;
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
private Label labelName;
|
||||||
|
private Label labelDescription;
|
||||||
|
private Label labelArticle;
|
||||||
|
}
|
||||||
|
}
|
130
NewsBlog/NewsBlogView/FormTag.cs
Normal file
130
NewsBlog/NewsBlogView/FormTag.cs
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
using NewsBlogAbstractions.Models;
|
||||||
|
using NewsBlogAbstractions.WorkAbstractions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace NewsBlogView
|
||||||
|
{
|
||||||
|
public partial class FormTag : Form
|
||||||
|
{
|
||||||
|
private readonly ITagWork _tagLogic;
|
||||||
|
private readonly IArticleWork _articleLogic;
|
||||||
|
|
||||||
|
public FormTag(ITagWork logic, IArticleWork articleLogic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_tagLogic = logic;
|
||||||
|
_articleLogic = articleLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormTag_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Tag newTag = new()
|
||||||
|
{
|
||||||
|
Name = textBoxName.Text,
|
||||||
|
Description = textBoxDescription.Text,
|
||||||
|
ArticleId = ((Article?)comboBoxArticle.SelectedItem)?.Id ?? 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
_tagLogic.Create(newTag);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
var tags = _tagLogic.GetAll();
|
||||||
|
|
||||||
|
dataGridView.Rows.Clear();
|
||||||
|
|
||||||
|
if (dataGridView.ColumnCount == 0)
|
||||||
|
{
|
||||||
|
dataGridView.Columns.Add("Id", "ID");
|
||||||
|
dataGridView.Columns.Add("Name", "Имя");
|
||||||
|
dataGridView.Columns.Add("Description", "Описание");
|
||||||
|
dataGridView.Columns.Add("ArticleId", "ArticleId");
|
||||||
|
dataGridView.Columns["ArticleId"].Visible = false;
|
||||||
|
dataGridView.Columns.Add("Article", "Статья");
|
||||||
|
}
|
||||||
|
|
||||||
|
dataGridView.Columns["Id"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Description"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
dataGridView.Columns["Article"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
|
||||||
|
comboBoxArticle.DataSource = _articleLogic.GetAll();
|
||||||
|
comboBoxArticle.DisplayMember = "Article";
|
||||||
|
comboBoxArticle.ValueMember = "Title";
|
||||||
|
|
||||||
|
foreach (var tag in tags)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(tag.Id, tag.Name, tag.Description, tag.ArticleId, _articleLogic.Get(tag.ArticleId)?.Title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count > 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||||
|
int tagId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
|
Tag updatedTag = new()
|
||||||
|
{
|
||||||
|
Id = tagId,
|
||||||
|
Name = textBoxName.Text,
|
||||||
|
Description = textBoxDescription.Text,
|
||||||
|
ArticleId = ((Article?)comboBoxArticle.SelectedItem)?.Id ?? 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
_tagLogic.Update(updatedTag);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Пожалуйста, выберите тэг, информацию о котором необходимо обновить");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDelete_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (dataGridView.SelectedRows.Count > 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||||
|
int tagId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
|
_tagLogic.Delete(tagId);
|
||||||
|
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Пожалуйста, выберите тэг, информацию о котором необходимо удалить");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.RowIndex >= 0)
|
||||||
|
{
|
||||||
|
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
|
||||||
|
textBoxName.Text = row.Cells["Name"].Value.ToString();
|
||||||
|
textBoxDescription.Text = row.Cells["Description"].Value.ToString();
|
||||||
|
comboBoxArticle.SelectedValue = row.Cells["Article"].Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
NewsBlog/NewsBlogView/FormTag.resx
Normal file
120
NewsBlog/NewsBlogView/FormTag.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
20
NewsBlog/NewsBlogView/NewsBlogView.csproj
Normal file
20
NewsBlog/NewsBlogView/NewsBlogView.csproj
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\NewsBlogAbstractions\NewsBlogAbstractions.csproj" />
|
||||||
|
<ProjectReference Include="..\NewsBlogDatabaseImplementation\NewsBlogDatabaseImplementation.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
43
NewsBlog/NewsBlogView/Program.cs
Normal file
43
NewsBlog/NewsBlogView/Program.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using NewsBlogAbstractions.WorkAbstractions;
|
||||||
|
using NewsBlogDatabaseImplementation.WorkImplementation;
|
||||||
|
|
||||||
|
namespace NewsBlogView
|
||||||
|
{
|
||||||
|
internal static class Program
|
||||||
|
{
|
||||||
|
private static ServiceProvider? _serviceProvider;
|
||||||
|
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The main entry point for the application.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
|
// see https://aka.ms/applicationconfiguration.
|
||||||
|
ApplicationConfiguration.Initialize();
|
||||||
|
var services = new ServiceCollection();
|
||||||
|
ConfigureServices(services);
|
||||||
|
_serviceProvider = services.BuildServiceProvider();
|
||||||
|
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddTransient<IArticleWork, ArticleWork>();
|
||||||
|
services.AddTransient<IAuthorWork, AuthorWork>();
|
||||||
|
services.AddTransient<ICategoryWork, CategoryWork>();
|
||||||
|
services.AddTransient<ICommentWork, CommentWork>();
|
||||||
|
services.AddTransient<ITagWork, TagWork>();
|
||||||
|
|
||||||
|
services.AddTransient<FormMain>();
|
||||||
|
services.AddTransient<FormArticle>();
|
||||||
|
services.AddTransient<FormAuthor>();
|
||||||
|
services.AddTransient<FormCategory>();
|
||||||
|
services.AddTransient<FormComment>();
|
||||||
|
services.AddTransient<FormTag>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user