Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
74adae9fc2 | ||
|
0a3d0f073f | ||
|
cb6251ab2b |
43
NewsBlog/NewsBlog.sln
Normal file
43
NewsBlog/NewsBlog.sln
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewsBlogAbstractions", "NewsBlogAbstractions\NewsBlogAbstractions.csproj", "{22CA3930-4C19-4623-9B58-C42A48B45576}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewsBlogDatabaseImplementation", "NewsBlogDatabaseImplementation\NewsBlogDatabaseImplementation.csproj", "{1DA49583-881B-4E05-A128-AEB692A174B4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewsBlogMongoDB", "NewsBlogMongoDB\NewsBlogMongoDB.csproj", "{223BAF22-6898-427D-A5D2-6D32BC50BD30}"
|
||||
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
|
||||
{223BAF22-6898-427D-A5D2-6D32BC50BD30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{223BAF22-6898-427D-A5D2-6D32BC50BD30}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{223BAF22-6898-427D-A5D2-6D32BC50BD30}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{223BAF22-6898-427D-A5D2-6D32BC50BD30}.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;
|
||||
}
|
||||
}
|
||||
}
|
198
NewsBlog/NewsBlogMongoDB/ImplementationMongoDB.cs
Normal file
198
NewsBlog/NewsBlogMongoDB/ImplementationMongoDB.cs
Normal file
@ -0,0 +1,198 @@
|
||||
using MongoDB.Driver;
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogMongoDB.Models;
|
||||
using NewsBlogMongoDB.StoragesContracts;
|
||||
using Tag = NewsBlogAbstractions.Models.Tag;
|
||||
|
||||
namespace NewsBlogMongoDB
|
||||
{
|
||||
public class ImplementationMongoDB: StorageModel
|
||||
{
|
||||
private IMongoDatabase _database;
|
||||
private IMongoCollection<ArticleMongo> _articleCollection;
|
||||
private IMongoCollection<AuthorMongo> _authorCollection;
|
||||
private IMongoCollection<CategoryMongo> _categoryCollection;
|
||||
private IMongoCollection<CommentMongo> _CommentCollection;
|
||||
private IMongoCollection<TagMongo> _TagCollection;
|
||||
private IMongoCollection<Sequence> _SequenceCollection;
|
||||
|
||||
public ImplementationMongoDB()
|
||||
{
|
||||
var client = new MongoClient("mongodb://localhost:27017");
|
||||
_database = client.GetDatabase("NewsBlog");
|
||||
|
||||
_articleCollection = _database.GetCollection<ArticleMongo>("article");
|
||||
_authorCollection = _database.GetCollection<AuthorMongo>("author");
|
||||
_categoryCollection = _database.GetCollection<CategoryMongo>("category");
|
||||
_CommentCollection = _database.GetCollection<CommentMongo>("comment");
|
||||
_TagCollection = _database.GetCollection<TagMongo>("tag");
|
||||
_SequenceCollection = _database.GetCollection<Sequence>("sequence");
|
||||
}
|
||||
|
||||
// article
|
||||
public override void AddArticle(Article article)
|
||||
{
|
||||
string Author_id = GetMongoId("Author", article.AuthorId.ToString());
|
||||
string Category_id = GetMongoId("Category", article.CategoryId.ToString());
|
||||
|
||||
var art = new ArticleMongo(article, Author_id, Category_id);
|
||||
_articleCollection.InsertOne(art);
|
||||
|
||||
var seq = new Sequence { Sql_id = article.Id.ToString(), Mongo_id = art.Id, Table_name = "Article"};
|
||||
_SequenceCollection.InsertOne(seq);
|
||||
}
|
||||
|
||||
public override List<ArticleMongo> GetArticles()
|
||||
{
|
||||
return _articleCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public override ArticleMongo GetArticleById(string id)
|
||||
{
|
||||
return _articleCollection.Find(article => article.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public override void UpdateArticle(ArticleMongo article)
|
||||
{
|
||||
_articleCollection.ReplaceOne(c => c.Id == article.Id, article);
|
||||
}
|
||||
|
||||
public override void DeleteArticle(string id)
|
||||
{
|
||||
_articleCollection.DeleteOne(article => article.Id == id);
|
||||
}
|
||||
|
||||
// Author
|
||||
public override void AddAuthor(Author author)
|
||||
{
|
||||
var art = new AuthorMongo(author);
|
||||
_authorCollection.InsertOne(art);
|
||||
|
||||
var seq = new Sequence { Sql_id = author.Id.ToString(), Mongo_id = art.Id, Table_name = "Author" };
|
||||
_SequenceCollection.InsertOne(seq);
|
||||
}
|
||||
|
||||
public override List<AuthorMongo> GetAuthors()
|
||||
{
|
||||
return _authorCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public override AuthorMongo GetAuthorById(string id)
|
||||
{
|
||||
return _authorCollection.Find(author => author.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public override void UpdateAuthor(AuthorMongo author)
|
||||
{
|
||||
_authorCollection.ReplaceOne(c => c.Id == author.Id, author);
|
||||
}
|
||||
|
||||
public override void DeleteAuthor(string id)
|
||||
{
|
||||
_authorCollection.DeleteOne(author => author.Id == id);
|
||||
}
|
||||
|
||||
// Category
|
||||
public override void AddCategory(Category category)
|
||||
{
|
||||
var cat = new CategoryMongo(category);
|
||||
_categoryCollection.InsertOne(cat);
|
||||
|
||||
var seq = new Sequence { Sql_id = category.Id.ToString(), Mongo_id = cat.Id, Table_name = "Category" };
|
||||
_SequenceCollection.InsertOne(seq);
|
||||
}
|
||||
|
||||
public override List<CategoryMongo> GetCategorys()
|
||||
{
|
||||
return _categoryCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public override CategoryMongo GetCategoryById(string id)
|
||||
{
|
||||
return _categoryCollection.Find(category => category.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public override void UpdateCategory(CategoryMongo category)
|
||||
{
|
||||
_categoryCollection.ReplaceOne(r => r.Id == category.Id, category);
|
||||
}
|
||||
|
||||
public override void DeleteCategory(string id)
|
||||
{
|
||||
_categoryCollection.DeleteOne(category => category.Id == id);
|
||||
}
|
||||
|
||||
// Comment
|
||||
public override void AddComment(Comment Comment)
|
||||
{
|
||||
string ArticleId = GetMongoId("Article", Comment.ArticleId.ToString());
|
||||
|
||||
_CommentCollection.InsertOne(new CommentMongo(Comment, ArticleId));
|
||||
}
|
||||
|
||||
public override List<CommentMongo> GetComments()
|
||||
{
|
||||
return _CommentCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public override CommentMongo GetCommentById(string id)
|
||||
{
|
||||
return _CommentCollection.Find(model => model.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public override void UpdateComment(CommentMongo Comment)
|
||||
{
|
||||
_CommentCollection.ReplaceOne(m => m.Id == Comment.Id, Comment);
|
||||
}
|
||||
|
||||
public override void DeleteComment(string id)
|
||||
{
|
||||
_CommentCollection.DeleteOne(model => model.Id == id);
|
||||
}
|
||||
|
||||
// Tag
|
||||
public override void AddTag(Tag Tag)
|
||||
{
|
||||
string ArticleId = GetMongoId("Article", Tag.ArticleId.ToString());
|
||||
|
||||
_TagCollection.InsertOne(new TagMongo(Tag, ArticleId));
|
||||
}
|
||||
|
||||
public override List<TagMongo> GetTags()
|
||||
{
|
||||
return _TagCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public override TagMongo GetTagById(string id)
|
||||
{
|
||||
return _TagCollection.Find(Tag => Tag.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public override void UpdateTag(TagMongo Tag)
|
||||
{
|
||||
_TagCollection.ReplaceOne(b => b.Id == Tag.Id, Tag);
|
||||
}
|
||||
|
||||
public override void DeleteTag(string id)
|
||||
{
|
||||
_TagCollection.DeleteOne(Tag => Tag.Id == id);
|
||||
}
|
||||
|
||||
public List<Sequence> GetSequence()
|
||||
{
|
||||
return _SequenceCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public override string GetMongoId(string tableName, string sqlId)
|
||||
{
|
||||
var sequence = _SequenceCollection.Find(s => s.Table_name == tableName && s.Sql_id == sqlId).FirstOrDefault();
|
||||
|
||||
return sequence?.Mongo_id ?? string.Empty;
|
||||
}
|
||||
|
||||
public void DeleteSequence(string id)
|
||||
{
|
||||
_SequenceCollection.DeleteOne(Sequence => Sequence.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
34
NewsBlog/NewsBlogMongoDB/Models/ArticleMongo.cs
Normal file
34
NewsBlog/NewsBlogMongoDB/Models/ArticleMongo.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
|
||||
namespace NewsBlogMongoDB.Models
|
||||
{
|
||||
public class ArticleMongo
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string Content { get; set; } = string.Empty;
|
||||
public string Publication_date { get; set; } = string.Empty;
|
||||
public string Author_id { get; set; } = string.Empty;
|
||||
public string Category_id { get; set; } = string.Empty;
|
||||
|
||||
public ArticleMongo(NewsBlogAbstractions.Models.Article model, string author_id, string category_id)
|
||||
{
|
||||
Title = model.Title;
|
||||
Content = model.Content;
|
||||
Publication_date = model.PublicationDate.ToString("d");
|
||||
Author_id = author_id;
|
||||
Category_id = category_id;
|
||||
}
|
||||
public ArticleMongo()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
31
NewsBlog/NewsBlogMongoDB/Models/AuthorMongo.cs
Normal file
31
NewsBlog/NewsBlogMongoDB/Models/AuthorMongo.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NewsBlogAbstractions.Models;
|
||||
|
||||
namespace NewsBlogMongoDB.Models
|
||||
{
|
||||
public class AuthorMongo
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public string Phone { get; set; } = string.Empty;
|
||||
|
||||
public AuthorMongo(NewsBlogAbstractions.Models.Author model)
|
||||
{
|
||||
Name = model.Name;
|
||||
Description = model.Description;
|
||||
Phone = model.Phone;
|
||||
}
|
||||
public AuthorMongo()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
27
NewsBlog/NewsBlogMongoDB/Models/CategoryMongo.cs
Normal file
27
NewsBlog/NewsBlogMongoDB/Models/CategoryMongo.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using NewsBlogAbstractions.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NewsBlogMongoDB.Models
|
||||
{
|
||||
public class CategoryMongo
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public CategoryMongo(NewsBlogAbstractions.Models.Category model)
|
||||
{
|
||||
Name = model.Name;
|
||||
}
|
||||
public CategoryMongo()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
33
NewsBlog/NewsBlogMongoDB/Models/CommentMongo.cs
Normal file
33
NewsBlog/NewsBlogMongoDB/Models/CommentMongo.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using NewsBlogAbstractions.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NewsBlogMongoDB.Models
|
||||
{
|
||||
public class CommentMongo
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string Content { get; set; } = string.Empty;
|
||||
public string Create_date { get; set; } = string.Empty;
|
||||
public string Article_id { get; set; } = string.Empty;
|
||||
|
||||
public CommentMongo(NewsBlogAbstractions.Models.Comment model, string ArticleId)
|
||||
{
|
||||
Title = model.Title;
|
||||
Content = model.Content;
|
||||
Create_date = model.CreateDate.ToString("d");
|
||||
Article_id = ArticleId;
|
||||
}
|
||||
public CommentMongo()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
20
NewsBlog/NewsBlogMongoDB/Models/Sequence.cs
Normal file
20
NewsBlog/NewsBlogMongoDB/Models/Sequence.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NewsBlogMongoDB.Models
|
||||
{
|
||||
public class Sequence
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string Sql_id { get; set; } = string.Empty;
|
||||
public string Mongo_id { get; set; } = string.Empty;
|
||||
public string Table_name { get; set;} = string.Empty;
|
||||
}
|
||||
}
|
31
NewsBlog/NewsBlogMongoDB/Models/TagMongo.cs
Normal file
31
NewsBlog/NewsBlogMongoDB/Models/TagMongo.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NewsBlogAbstractions.Models;
|
||||
|
||||
namespace NewsBlogMongoDB.Models
|
||||
{
|
||||
public class TagMongo
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Decsription { get; set; } = string.Empty;
|
||||
public string Article_id { get; set; } = string.Empty;
|
||||
|
||||
public TagMongo(NewsBlogAbstractions.Models.Tag model, string ArticleId)
|
||||
{
|
||||
Name = model.Name;
|
||||
Decsription = model.Description;
|
||||
Article_id = ArticleId;
|
||||
}
|
||||
public TagMongo()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
18
NewsBlog/NewsBlogMongoDB/NewsBlogMongoDB.csproj
Normal file
18
NewsBlog/NewsBlogMongoDB/NewsBlogMongoDB.csproj
Normal file
@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.25.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NewsBlogAbstractions\NewsBlogAbstractions.csproj" />
|
||||
<ProjectReference Include="..\NewsBlogDatabaseImplementation\NewsBlogDatabaseImplementation.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
50
NewsBlog/NewsBlogMongoDB/StoragesContracts/StorageModel.cs
Normal file
50
NewsBlog/NewsBlogMongoDB/StoragesContracts/StorageModel.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogMongoDB.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NewsBlogMongoDB.StoragesContracts
|
||||
{
|
||||
public abstract class StorageModel
|
||||
{
|
||||
// Article
|
||||
public abstract void AddArticle(Article article);
|
||||
public abstract List<ArticleMongo> GetArticles();
|
||||
public abstract ArticleMongo GetArticleById(string id);
|
||||
public abstract void UpdateArticle(ArticleMongo article);
|
||||
public abstract void DeleteArticle(string id);
|
||||
|
||||
// Author
|
||||
public abstract void AddAuthor(Author author);
|
||||
public abstract AuthorMongo GetAuthorById(string id);
|
||||
public abstract List<AuthorMongo> GetAuthors();
|
||||
public abstract void UpdateAuthor(AuthorMongo author);
|
||||
public abstract void DeleteAuthor(string id);
|
||||
|
||||
// Category
|
||||
public abstract void AddCategory(Category category);
|
||||
public abstract CategoryMongo GetCategoryById(string id);
|
||||
public abstract List<CategoryMongo> GetCategorys();
|
||||
public abstract void UpdateCategory(CategoryMongo category);
|
||||
public abstract void DeleteCategory(string id);
|
||||
|
||||
// Comment
|
||||
public abstract void AddComment(Comment comment);
|
||||
public abstract CommentMongo GetCommentById(string id);
|
||||
public abstract List<CommentMongo> GetComments();
|
||||
public abstract void UpdateComment(CommentMongo comment);
|
||||
public abstract void DeleteComment(string id);
|
||||
|
||||
// Tag
|
||||
public abstract void AddTag(Tag tag);
|
||||
public abstract TagMongo GetTagById(string id);
|
||||
public abstract List<TagMongo> GetTags();
|
||||
public abstract void UpdateTag(TagMongo tag);
|
||||
public abstract void DeleteTag(string id);
|
||||
|
||||
public abstract string GetMongoId(string tableName, string sqlId);
|
||||
}
|
||||
}
|
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;
|
||||
}
|
||||
}
|
190
NewsBlog/NewsBlogView/FormArticle.cs
Normal file
190
NewsBlog/NewsBlogView/FormArticle.cs
Normal file
@ -0,0 +1,190 @@
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogAbstractions.WorkAbstractions;
|
||||
using NewsBlogMongoDB.Models;
|
||||
using NewsBlogMongoDB.StoragesContracts;
|
||||
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;
|
||||
private readonly StorageModel _mongoLogic;
|
||||
public FormArticle(IArticleWork articleLogic, IAuthorWork authorLogic, ICategoryWork categoryLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_articleLogic = articleLogic;
|
||||
_authorLogic = authorLogic;
|
||||
_categoryLogic = categoryLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
if (Program.isPostgreSQL)
|
||||
_articleLogic.Create(newArticle);
|
||||
else
|
||||
_mongoLogic.AddArticle(newArticle);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
var articlesSql = _articleLogic.GetAll();
|
||||
|
||||
var articlesMongo = _mongoLogic.GetArticles();
|
||||
|
||||
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";
|
||||
|
||||
if(Program.isPostgreSQL)
|
||||
foreach (var article in articlesSql)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
foreach (var article in articlesMongo)
|
||||
{
|
||||
dataGridView.Rows.Add(article.Id, article.Title, article.Content, article.Publication_date,
|
||||
article.Author_id, article.Category_id, _mongoLogic.GetAuthorById(article.Author_id)?.Name, _mongoLogic.GetCategoryById(article.Category_id)?.Name);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? articleId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
ArticleMongo updated = new()
|
||||
{
|
||||
Id = articleId,
|
||||
Title = textBoxTitle.Text,
|
||||
Content = textBoxContent.Text,
|
||||
Publication_date = DateTime.Now.ToString("d"),
|
||||
Author_id = _mongoLogic.GetMongoId("Author", ((Author?)comboBoxAuthor.SelectedItem)?.Id.ToString() ?? string.Empty),
|
||||
Category_id = _mongoLogic.GetMongoId("Category", ((Category?)comboBoxCategory.SelectedItem)?.Id.ToString() ?? string.Empty),
|
||||
};
|
||||
_mongoLogic.UpdateArticle(updated);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Пожалуйста, выберите статью, информацию о которой необходимо обновить");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int articleId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
_articleLogic.Delete(articleId);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? articleIdMongo = selectedRow.Cells["Id"].Value.ToString();
|
||||
_mongoLogic.DeleteArticle(articleIdMongo);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
165
NewsBlog/NewsBlogView/FormAuthor.cs
Normal file
165
NewsBlog/NewsBlogView/FormAuthor.cs
Normal file
@ -0,0 +1,165 @@
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogAbstractions.WorkAbstractions;
|
||||
using NewsBlogMongoDB.Models;
|
||||
using NewsBlogMongoDB.StoragesContracts;
|
||||
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;
|
||||
private readonly StorageModel _mongoLogic;
|
||||
public FormAuthor(IAuthorWork authorLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_authorLogic = authorLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
if (Program.isPostgreSQL)
|
||||
_authorLogic.Create(newAuthor);
|
||||
else
|
||||
_mongoLogic.AddAuthor(newAuthor);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
var authors = _authorLogic.GetAll();
|
||||
var authorsMongo = _mongoLogic.GetAuthors();
|
||||
|
||||
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;
|
||||
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
foreach (var author in authors)
|
||||
{
|
||||
dataGridView.Rows.Add(author.Id, author.Name, author.Description, author.Phone);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var author in authorsMongo)
|
||||
{
|
||||
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];
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? authorId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
AuthorMongo updatedAuthor = new()
|
||||
{
|
||||
Id = authorId,
|
||||
Name = textBoxName.Text,
|
||||
Description = textBoxDescription.Text,
|
||||
Phone = textBoxPhone.Text,
|
||||
};
|
||||
|
||||
_mongoLogic.UpdateAuthor(updatedAuthor);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Пожалуйста, выберите автора, информацию о котором необходимо обновить");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int authorId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_authorLogic.Delete(authorId);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? authorId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
_mongoLogic.DeleteAuthor(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;
|
||||
}
|
||||
}
|
153
NewsBlog/NewsBlogView/FormCategory.cs
Normal file
153
NewsBlog/NewsBlogView/FormCategory.cs
Normal file
@ -0,0 +1,153 @@
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogAbstractions.WorkAbstractions;
|
||||
using NewsBlogMongoDB.Models;
|
||||
using NewsBlogMongoDB.StoragesContracts;
|
||||
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;
|
||||
private readonly StorageModel _mongoLogic;
|
||||
public FormCategory(ICategoryWork categoryLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_categoryLogic = categoryLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
private void FormCategory_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Category newCategory = new()
|
||||
{
|
||||
Name = textBoxName.Text,
|
||||
};
|
||||
|
||||
if (Program.isPostgreSQL)
|
||||
_categoryLogic.Create(newCategory);
|
||||
else
|
||||
_mongoLogic.AddCategory(newCategory);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
var categories = _categoryLogic.GetAll();
|
||||
var categoriesMongo = _mongoLogic.GetCategorys();
|
||||
|
||||
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;
|
||||
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
foreach (var category in categories)
|
||||
{
|
||||
dataGridView.Rows.Add(category.Id, category.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var category in categoriesMongo)
|
||||
{
|
||||
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];
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int categoryId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
Category updatedCategory = new()
|
||||
{
|
||||
Id = categoryId,
|
||||
Name = textBoxName.Text,
|
||||
};
|
||||
|
||||
_categoryLogic.Update(updatedCategory);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? categoryId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
CategoryMongo updatedCategory = new()
|
||||
{
|
||||
Id = categoryId,
|
||||
Name = textBoxName.Text,
|
||||
};
|
||||
|
||||
_mongoLogic.UpdateCategory(updatedCategory);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Пожалуйста, выберите категорию, информацию о которой необходимо обновить");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int categoryId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_categoryLogic.Delete(categoryId);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? categoryId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
_mongoLogic.DeleteCategory(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;
|
||||
}
|
||||
}
|
180
NewsBlog/NewsBlogView/FormComment.cs
Normal file
180
NewsBlog/NewsBlogView/FormComment.cs
Normal file
@ -0,0 +1,180 @@
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogAbstractions.WorkAbstractions;
|
||||
using NewsBlogMongoDB.Models;
|
||||
using NewsBlogMongoDB.StoragesContracts;
|
||||
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;
|
||||
private readonly StorageModel _mongoLogic;
|
||||
public FormComment(ICommentWork commentLogic, IArticleWork articleLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_commentLogic = commentLogic;
|
||||
_articleLogic = articleLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
if (Program.isPostgreSQL)
|
||||
_commentLogic.Create(newComment);
|
||||
else
|
||||
_mongoLogic.AddComment(newComment);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
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";
|
||||
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
var comments = _commentLogic.GetAll();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var comments = _mongoLogic.GetComments();
|
||||
|
||||
foreach (var comment in comments)
|
||||
{
|
||||
dataGridView.Rows.Add(comment.Id, comment.Title, comment.Content, comment.Create_date, comment.Article_id, _mongoLogic.GetArticleById(comment.Article_id)?.Title);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? commentId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
CommentMongo updatedComment = new()
|
||||
{
|
||||
Id = commentId,
|
||||
Title = textBoxTitle.Text,
|
||||
Content = textBoxContent.Text,
|
||||
Create_date = DateTime.Now.ToString("d"),
|
||||
Article_id = _mongoLogic.GetMongoId("Article", ((Article?)comboBoxArticle.SelectedItem)?.Id.ToString() ?? String.Empty),
|
||||
};
|
||||
|
||||
_mongoLogic.UpdateComment(updatedComment);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Пожалуйста, выберите комментарий, информацию о котором необходимо обновить");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int commentId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_commentLogic.Delete(commentId);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? commentId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
_mongoLogic.DeleteComment(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>
|
206
NewsBlog/NewsBlogView/FormMain.Designer.cs
generated
Normal file
206
NewsBlog/NewsBlogView/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,206 @@
|
||||
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()
|
||||
{
|
||||
CheckBox MongoDB;
|
||||
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();
|
||||
updateMongoDBToolStripMenuItem = new ToolStripMenuItem();
|
||||
labelTest = new Label();
|
||||
MongoDB = new CheckBox();
|
||||
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.Size = new Size(554, 24);
|
||||
menuStrip1.TabIndex = 0;
|
||||
menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// справочникиToolStripMenuItem
|
||||
//
|
||||
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { articleToolStripMenuItem, authorToolStripMenuItem, categoryToolStripMenuItem, commentToolStripMenuItem, tagToolStripMenuItem });
|
||||
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||
справочникиToolStripMenuItem.Size = new Size(94, 20);
|
||||
справочникиToolStripMenuItem.Text = "Справочники";
|
||||
//
|
||||
// articleToolStripMenuItem
|
||||
//
|
||||
articleToolStripMenuItem.Name = "articleToolStripMenuItem";
|
||||
articleToolStripMenuItem.Size = new Size(151, 22);
|
||||
articleToolStripMenuItem.Text = "Статьи";
|
||||
articleToolStripMenuItem.Click += articleToolStripMenuItem_Click;
|
||||
//
|
||||
// authorToolStripMenuItem
|
||||
//
|
||||
authorToolStripMenuItem.Name = "authorToolStripMenuItem";
|
||||
authorToolStripMenuItem.Size = new Size(151, 22);
|
||||
authorToolStripMenuItem.Text = "Авторы";
|
||||
authorToolStripMenuItem.Click += authorToolStripMenuItem_Click;
|
||||
//
|
||||
// categoryToolStripMenuItem
|
||||
//
|
||||
categoryToolStripMenuItem.Name = "categoryToolStripMenuItem";
|
||||
categoryToolStripMenuItem.Size = new Size(151, 22);
|
||||
categoryToolStripMenuItem.Text = "Категории";
|
||||
categoryToolStripMenuItem.Click += categoryToolStripMenuItem_Click;
|
||||
//
|
||||
// commentToolStripMenuItem
|
||||
//
|
||||
commentToolStripMenuItem.Name = "commentToolStripMenuItem";
|
||||
commentToolStripMenuItem.Size = new Size(151, 22);
|
||||
commentToolStripMenuItem.Text = "Комментарии";
|
||||
commentToolStripMenuItem.Click += commentToolStripMenuItem_Click;
|
||||
//
|
||||
// tagToolStripMenuItem
|
||||
//
|
||||
tagToolStripMenuItem.Name = "tagToolStripMenuItem";
|
||||
tagToolStripMenuItem.Size = new Size(151, 22);
|
||||
tagToolStripMenuItem.Text = "Тэги";
|
||||
tagToolStripMenuItem.Click += tagToolStripMenuItem_Click;
|
||||
//
|
||||
// замерВремениToolStripMenuItem
|
||||
//
|
||||
замерВремениToolStripMenuItem.Name = "замерВремениToolStripMenuItem";
|
||||
замерВремениToolStripMenuItem.Size = new Size(12, 20);
|
||||
//
|
||||
// замерыВремениToolStripMenuItem
|
||||
//
|
||||
замерыВремениToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { add1000ToolStripMenuItem, get1000ToolStripMenuItem, update1000ToolStripMenuItem, delete1000ToolStripMenuItem, updateMongoDBToolStripMenuItem });
|
||||
замерыВремениToolStripMenuItem.Name = "замерыВремениToolStripMenuItem";
|
||||
замерыВремениToolStripMenuItem.Size = new Size(114, 20);
|
||||
замерыВремениToolStripMenuItem.Text = "Замеры времени";
|
||||
//
|
||||
// add1000ToolStripMenuItem
|
||||
//
|
||||
add1000ToolStripMenuItem.Name = "add1000ToolStripMenuItem";
|
||||
add1000ToolStripMenuItem.Size = new Size(185, 22);
|
||||
add1000ToolStripMenuItem.Text = "Добавление 1000";
|
||||
add1000ToolStripMenuItem.Click += add1000ToolStripMenuItem_Click;
|
||||
//
|
||||
// get1000ToolStripMenuItem
|
||||
//
|
||||
get1000ToolStripMenuItem.Name = "get1000ToolStripMenuItem";
|
||||
get1000ToolStripMenuItem.Size = new Size(185, 22);
|
||||
get1000ToolStripMenuItem.Text = "Получение 1000";
|
||||
get1000ToolStripMenuItem.Click += get1000ToolStripMenuItem_Click;
|
||||
//
|
||||
// update1000ToolStripMenuItem
|
||||
//
|
||||
update1000ToolStripMenuItem.Name = "update1000ToolStripMenuItem";
|
||||
update1000ToolStripMenuItem.Size = new Size(185, 22);
|
||||
update1000ToolStripMenuItem.Text = "Обновление 1000";
|
||||
update1000ToolStripMenuItem.Click += update1000ToolStripMenuItem_Click;
|
||||
//
|
||||
// delete1000ToolStripMenuItem
|
||||
//
|
||||
delete1000ToolStripMenuItem.Name = "delete1000ToolStripMenuItem";
|
||||
delete1000ToolStripMenuItem.Size = new Size(185, 22);
|
||||
delete1000ToolStripMenuItem.Text = "Удаление 1000";
|
||||
delete1000ToolStripMenuItem.Click += delete1000ToolStripMenuItem_Click;
|
||||
//
|
||||
// updateMongoDBToolStripMenuItem
|
||||
//
|
||||
updateMongoDBToolStripMenuItem.Name = "updateMongoDBToolStripMenuItem";
|
||||
updateMongoDBToolStripMenuItem.Size = new Size(185, 22);
|
||||
updateMongoDBToolStripMenuItem.Text = "Обновить MongoDB";
|
||||
updateMongoDBToolStripMenuItem.Click += updateMongoDBToolStripMenuItem_Click;
|
||||
//
|
||||
// labelTest
|
||||
//
|
||||
labelTest.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelTest.Location = new Point(156, 82);
|
||||
labelTest.Name = "labelTest";
|
||||
labelTest.Size = new Size(250, 100);
|
||||
labelTest.TabIndex = 3;
|
||||
labelTest.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// MongoDB
|
||||
//
|
||||
MongoDB.AutoSize = true;
|
||||
MongoDB.Location = new Point(459, 230);
|
||||
MongoDB.Name = "MongoDB";
|
||||
MongoDB.Size = new Size(80, 19);
|
||||
MongoDB.TabIndex = 4;
|
||||
MongoDB.Text = "MongoDB";
|
||||
MongoDB.UseVisualStyleBackColor = true;
|
||||
MongoDB.CheckedChanged += MongoDB_CheckedChanged;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(554, 261);
|
||||
Controls.Add(MongoDB);
|
||||
Controls.Add(labelTest);
|
||||
Controls.Add(menuStrip1);
|
||||
MainMenuStrip = menuStrip1;
|
||||
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;
|
||||
private ToolStripMenuItem updateMongoDBToolStripMenuItem;
|
||||
}
|
||||
}
|
204
NewsBlog/NewsBlogView/FormMain.cs
Normal file
204
NewsBlog/NewsBlogView/FormMain.cs
Normal file
@ -0,0 +1,204 @@
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogAbstractions.WorkAbstractions;
|
||||
using NewsBlogMongoDB;
|
||||
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} ìèëëèñåêóíä";
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMongoDBToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
ImplementationMongoDB implementationMongoDB = new();
|
||||
|
||||
// î÷èùàåì âñ¸
|
||||
foreach (var it in implementationMongoDB.GetArticles())
|
||||
implementationMongoDB.DeleteArticle(it.Id);
|
||||
foreach (var it in implementationMongoDB.GetAuthors())
|
||||
implementationMongoDB.DeleteAuthor(it.Id);
|
||||
foreach (var it in implementationMongoDB.GetCategorys())
|
||||
implementationMongoDB.DeleteCategory(it.Id);
|
||||
foreach (var it in implementationMongoDB.GetComments())
|
||||
implementationMongoDB.DeleteComment(it.Id);
|
||||
foreach (var it in implementationMongoDB.GetTags())
|
||||
implementationMongoDB.DeleteTag(it.Id);
|
||||
foreach (var it in implementationMongoDB.GetSequence())
|
||||
implementationMongoDB.DeleteSequence(it.Id);
|
||||
|
||||
// ñêà÷èâàåì èç ïîñòãðåñà
|
||||
List<Article> listArticle = null;
|
||||
List<Author> listAuthor = null;
|
||||
List<Category> listCategory = null;
|
||||
List<Comment> listComment = null;
|
||||
List<Tag> listTag = null;
|
||||
|
||||
var service = Program.ServiceProvider?.GetService(typeof(IArticleWork));
|
||||
if (service is IArticleWork articleLogic)
|
||||
listArticle = articleLogic.GetAll();
|
||||
|
||||
service = Program.ServiceProvider?.GetService(typeof(IAuthorWork));
|
||||
if (service is IAuthorWork authorLogic)
|
||||
listAuthor = authorLogic.GetAll();
|
||||
|
||||
service = Program.ServiceProvider?.GetService(typeof(ICategoryWork));
|
||||
if (service is ICategoryWork categoryLogic)
|
||||
listCategory = categoryLogic.GetAll();
|
||||
|
||||
service = Program.ServiceProvider?.GetService(typeof(ICommentWork));
|
||||
if (service is ICommentWork commentLogic)
|
||||
listComment = commentLogic.GetAll();
|
||||
|
||||
service = Program.ServiceProvider?.GetService(typeof(ITagWork));
|
||||
if (service is ITagWork tagLogic)
|
||||
listTag = tagLogic.GetAll();
|
||||
|
||||
// âëèâàåì äàííûå ìîíãî äá
|
||||
if (listAuthor != null)
|
||||
foreach (var it in listAuthor)
|
||||
implementationMongoDB.AddAuthor(it);
|
||||
if (listCategory != null)
|
||||
foreach (var it in listCategory)
|
||||
implementationMongoDB.AddCategory(it);
|
||||
if (listArticle != null)
|
||||
foreach (var it in listArticle)
|
||||
implementationMongoDB.AddArticle(it);
|
||||
if (listComment != null)
|
||||
foreach (var it in listComment)
|
||||
implementationMongoDB.AddComment(it);
|
||||
if (listTag != null)
|
||||
foreach (var it in listTag)
|
||||
implementationMongoDB.AddTag(it);
|
||||
}
|
||||
|
||||
private void MongoDB_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
Program.isPostgreSQL = !Program.isPostgreSQL;
|
||||
}
|
||||
}
|
||||
}
|
126
NewsBlog/NewsBlogView/FormMain.resx
Normal file
126
NewsBlog/NewsBlogView/FormMain.resx
Normal file
@ -0,0 +1,126 @@
|
||||
<?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>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="MongoDB.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>False</value>
|
||||
</metadata>
|
||||
</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;
|
||||
}
|
||||
}
|
173
NewsBlog/NewsBlogView/FormTag.cs
Normal file
173
NewsBlog/NewsBlogView/FormTag.cs
Normal file
@ -0,0 +1,173 @@
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogAbstractions.WorkAbstractions;
|
||||
using NewsBlogMongoDB.Models;
|
||||
using NewsBlogMongoDB.StoragesContracts;
|
||||
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;
|
||||
private readonly StorageModel _mongoLogic;
|
||||
|
||||
public FormTag(ITagWork logic, IArticleWork articleLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_tagLogic = logic;
|
||||
_articleLogic = articleLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
if (Program.isPostgreSQL)
|
||||
_tagLogic.Create(newTag);
|
||||
else
|
||||
_mongoLogic.AddTag(newTag);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
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";
|
||||
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
var tags = _tagLogic.GetAll();
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
dataGridView.Rows.Add(tag.Id, tag.Name, tag.Description, tag.ArticleId, _articleLogic.Get(tag.ArticleId)?.Title);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var tags = _mongoLogic.GetTags();
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
dataGridView.Rows.Add(tag.Id, tag.Name, tag.Decsription, tag.Article_id, _mongoLogic.GetArticleById(tag.Article_id)?.Title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? tagId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
TagMongo updatedTag = new()
|
||||
{
|
||||
Id = tagId,
|
||||
Name = textBoxName.Text,
|
||||
Decsription = textBoxDescription.Text,
|
||||
Article_id = _mongoLogic.GetMongoId("Article", ((Article?)comboBoxArticle.SelectedItem)?.Id.ToString() ?? String.Empty),
|
||||
};
|
||||
|
||||
_mongoLogic.UpdateTag(updatedTag);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Пожалуйста, выберите тэг, информацию о котором необходимо обновить");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int tagId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_tagLogic.Delete(tagId);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? tagId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
_mongoLogic.DeleteTag(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>
|
21
NewsBlog/NewsBlogView/NewsBlogView.csproj
Normal file
21
NewsBlog/NewsBlogView/NewsBlogView.csproj
Normal file
@ -0,0 +1,21 @@
|
||||
<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" />
|
||||
<ProjectReference Include="..\NewsBlogMongoDB\NewsBlogMongoDB.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
49
NewsBlog/NewsBlogView/Program.cs
Normal file
49
NewsBlog/NewsBlogView/Program.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NewsBlogAbstractions.WorkAbstractions;
|
||||
using NewsBlogDatabaseImplementation.WorkImplementation;
|
||||
using NewsBlogMongoDB.StoragesContracts;
|
||||
using NewsBlogMongoDB;
|
||||
|
||||
namespace NewsBlogView
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
public static bool isPostgreSQL = true;
|
||||
|
||||
/// <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<StorageModel, ImplementationMongoDB>();
|
||||
|
||||
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