Формы

This commit is contained in:
Ismailov_Rovshan 2023-09-06 21:16:28 +04:00
parent e46735d32d
commit c1c2c3a9f4
48 changed files with 4338 additions and 30 deletions

View File

@ -1,11 +1,11 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using BlogDatabaseImplement.Model;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.ComponentModel; using System.ComponentModel;
using BlogDatabase.Models;
namespace BlogDatabaseImplement namespace BlogDatabaseImplement
{ {
@ -15,21 +15,14 @@ namespace BlogDatabaseImplement
{ {
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
optionsBuilder.UseNpgsql(@" optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=ForumSubd;Username=postgres;Password=postgres");
Host=localhost;
Port=5432;
Database=BlogDB;
Username=postgres;
Password=postgres");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }
public virtual DbSet<Tag> Tags { set; get; } public virtual DbSet<Role> Roles { set; get; }
public virtual DbSet<User> Users { set; get; } public virtual DbSet<User> Users { set; get; }
public virtual DbSet<News> News { set; get; } public virtual DbSet<Topic> Topics { set; get; }
public virtual DbSet<Comment> Comments { set; get; } public virtual DbSet<Category> Categories { set; get; }
public virtual DbSet<NewsTag> NewsTags { set; get; } public virtual DbSet<Message> Messages { set; get; }
} }
} }

View File

@ -18,6 +18,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\BlogContracts\BlogContracts.csproj" /> <ProjectReference Include="..\BlogContracts\BlogContracts.csproj" />
<ProjectReference Include="..\BlogDataModels\BlogDataModels.csproj" /> <ProjectReference Include="..\BlogDataModels\BlogDataModels.csproj" />
<ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -0,0 +1,91 @@
using ForumContracts.BindingModels;
using ForumContracts.SearchModels;
using ForumContracts.StoragesContracts;
using ForumContracts.ViewModels;
using BlogDatabase.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlogDatabase.Implements
{
public class CategoryStorage : ICategoryStorage
{
public CategoryViewModel? Delete(CategoryBindingModel model)
{
using var context = new BlogDatabase();
var element = context.Categories.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Categories.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public CategoryViewModel? GetElement(CategorySearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new BlogDatabase();
return context.Categories
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Name) && x.Name ==
model.Name) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<CategoryViewModel> GetFilteredList(CategorySearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
using var context = new BlogDatabase();
return context.Categories
.Where(x => x.Name.Contains(model.Name))
.Select(x => x.GetViewModel)
.ToList();
}
public List<CategoryViewModel> GetFullList()
{
using var context = new BlogDatabase();
return context.Categories
.Select(x => x.GetViewModel)
.ToList();
}
public CategoryViewModel? Insert(CategoryBindingModel model)
{
var newCategory = Category.Create(model);
if (newCategory == null)
{
return null;
}
using var context = new BlogDatabase();
context.Categories.Add(newCategory);
context.SaveChanges();
return newCategory.GetViewModel;
}
public CategoryViewModel? Update(CategoryBindingModel model)
{
using var context = new BlogDatabase();
var component = context.Categories.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,165 @@
using ForumContracts.BindingModels;
using ForumContracts.SearchModels;
using ForumContracts.StoragesContracts;
using ForumContracts.ViewModels;
using BlogDatabase.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlogDatabase.Implements
{
public class MessageStorage : IMessageStorage
{
public MessageViewModel? Delete(MessageBindingModel model)
{
using var context = new BlogDatabase();
var element = context.Messages.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Messages.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public MessageViewModel? GetElement(MessageSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new BlogDatabase();
return context.Messages
.Include(x => x.User)
.Include(x => x.Topic)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id).GetViewModel;
}
public List<MessageViewModel> GetFilteredList(MessageSearchModel model)
{
using var context = new BlogDatabase();
return context.Messages
.Include(x => x.User)
.Include(x => x.Topic)
.Select(x => x.GetViewModel)
.ToList();
}
public List<MessageViewModel> GetFullList()
{
using var context = new BlogDatabase();
return context.Messages
.Include(x => x.User)
.Include(x => x.Topic)
.Select(x => x.GetViewModel)
.ToList();
}
public MessageViewModel? Insert(MessageBindingModel model)
{
var newMessage = Message.Create(model);
if (newMessage == null)
{
return null;
}
using var context = new BlogDatabase();
context.Messages.Add(newMessage);
context.SaveChanges();
return newMessage.GetViewModel;
}
public string TestInsertList(int num, List<UserViewModel> users, List<TopicViewModel> topics)
{
Random rnd = new Random();
using var context = new BlogDatabase();
for (int i = 0; i < num; ++i)
{
var model = new MessageBindingModel
{
Id = 0,
Text = "hello",
Date = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
UserId = users[rnd.Next(users.Count)].Id,
TopicId = topics[rnd.Next(topics.Count)].Id,
};
context.Messages.Add(Message.Create(model));
}
Stopwatch stopwatch = new();
stopwatch.Start();
context.SaveChanges();
stopwatch.Stop();
return stopwatch.ElapsedMilliseconds.ToString();
}
public string TestJoinReadList(int num)
{
using var context = new BlogDatabase();
Stopwatch stopwatch = new();
stopwatch.Start();
var list = context.Messages
.Include(x => x.User)
.Include(x => x.Topic)
.Join(context.Users,
r => r.UserId,
c => c.Id,
(r, c) => new { Message = r, User = c })
.Join(context.Topics,
rc => rc.Message.TopicId,
car => car.Id,
(rc, topic) => new { rc.Message, rc.User, Topic = topic })
.Select(rc => new
{
Message = rc.Message.GetViewModel,
User = rc.User.GetViewModel,
Topic = rc.Topic.GetViewModel,
})
.Take(num)
.ToList();
stopwatch.Stop();
return stopwatch.ElapsedMilliseconds.ToString();
}
public string TestReadList(int num)
{
using var context = new BlogDatabase();
Stopwatch stopwatch = new();
stopwatch.Start();
List<MessageViewModel> list = context.Messages
.Include(x => x.User)
.Include(x => x.Topic)
.Take(num)
.Select(x => x.GetViewModel)
.ToList();
stopwatch.Stop();
return stopwatch.ElapsedMilliseconds.ToString();
}
public MessageViewModel? Update(MessageBindingModel model)
{
using var context = new BlogDatabase();
var component = context.Messages.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,106 @@
using ForumContracts.BindingModels;
using ForumContracts.SearchModels;
using ForumContracts.StoragesContracts;
using ForumContracts.ViewModels;
using BlogDatabase.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlogDatabase.Implements
{
public class RoleStorage : IRoleStorage
{
public void RoleInsertList(int num)
{
Random rnd = new Random();
using var context = new BlogDatabase();
for (int i = 0; i < num; ++i)
{
var model = new RoleBindingModel
{
Id = 0,
Name = rnd.Next(1000).ToString(),
};
context.Roles.Add(Role.Create(model));
}
context.SaveChanges();
}
public RoleViewModel? Delete(RoleBindingModel model)
{
using var context = new BlogDatabase();
var element = context.Roles.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Roles.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public RoleViewModel? GetElement(RoleSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new BlogDatabase();
return context.Roles
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Name) && x.Name ==
model.Name) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<RoleViewModel> GetFilteredList(RoleSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
using var context = new BlogDatabase();
return context.Roles
.Where(x => x.Name.Contains(model.Name))
.Select(x => x.GetViewModel)
.ToList();
}
public List<RoleViewModel> GetFullList()
{
using var context = new BlogDatabase();
return context.Roles
.Select(x => x.GetViewModel)
.ToList();
}
public RoleViewModel? Insert(RoleBindingModel model)
{
var newRole = Role.Create(model);
if (newRole == null)
{
return null;
}
using var context = new BlogDatabase();
context.Roles.Add(newRole);
context.SaveChanges();
return newRole.GetViewModel;
}
public RoleViewModel? Update(RoleBindingModel model)
{
using var context = new BlogDatabase();
var component = context.Roles.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,95 @@
using ForumContracts.BindingModels;
using ForumContracts.SearchModels;
using ForumContracts.StoragesContracts;
using ForumContracts.ViewModels;
using BlogDatabase.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlogDatabase.Implements
{
public class TopicStorage : ITopicStorage
{
public TopicViewModel? Delete(TopicBindingModel model)
{
using var context = new BlogDatabase();
var element = context.Topics.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Topics.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public TopicViewModel? GetElement(TopicSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new BlogDatabase();
return context.Topics
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Name) && x.Name ==
model.Name) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<TopicViewModel> GetFilteredList(TopicSearchModel model)
{
using var context = new BlogDatabase();
if (model.CategoryId.HasValue)
{
return context.Topics
.Where(x => x.CategoryId == model.CategoryId)
.Select(x => x.GetViewModel)
.ToList();
}
return context.Topics
.Where(x => x.Name.Contains(model.Name))
.Select(x => x.GetViewModel)
.ToList();
}
public List<TopicViewModel> GetFullList()
{
using var context = new BlogDatabase();
return context.Topics
.Select(x => x.GetViewModel)
.ToList();
}
public TopicViewModel? Insert(TopicBindingModel model)
{
var newTopic = Topic.Create(model);
if (newTopic == null)
{
return null;
}
using var context = new BlogDatabase();
context.Topics.Add(newTopic);
context.SaveChanges();
return newTopic.GetViewModel;
}
public TopicViewModel? Update(TopicBindingModel model)
{
using var context = new BlogDatabase();
var component = context.Topics.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,115 @@
using ForumContracts.BindingModels;
using ForumContracts.SearchModels;
using ForumContracts.StoragesContracts;
using ForumContracts.ViewModels;
using BlogDatabase.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
namespace BlogDatabase.Implements
{
public class UserStorage : IUserStorage
{
public UserViewModel? Delete(UserBindingModel model)
{
using var context = new BlogDatabase();
var element = context.Users.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Users.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public UserViewModel? GetElement(UserSearchModel model)
{
if (string.IsNullOrEmpty(model.Username) && !model.Id.HasValue && string.IsNullOrEmpty(model.Email))
{
return null;
}
using var context = new BlogDatabase();
return context.Users
.Include(x => x.Role)
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Username) && x.Username ==
model.Username) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<UserViewModel> GetFilteredList(UserSearchModel model)
{
if (string.IsNullOrEmpty(model.Username) || string.IsNullOrEmpty(model.Email))
{
return new();
}
using var context = new BlogDatabase();
return context.Users
.Include(x => x.Role)
.Where(x => x.Username.Contains(model.Username))
.Select(x => x.GetViewModel)
.ToList();
}
public List<UserViewModel> GetFullList()
{
using var context = new BlogDatabase();
return context.Users
.Include(x => x.Role)
.Select(x => x.GetViewModel)
.ToList();
}
public UserViewModel? Insert(UserBindingModel model)
{
var newUser = User.Create(model);
if (newUser == null)
{
return null;
}
using var context = new BlogDatabase();
context.Users.Add(newUser);
context.SaveChanges();
return newUser.GetViewModel;
}
public UserViewModel? Update(UserBindingModel model)
{
using var context = new BlogDatabase();
var component = context.Users.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
public void UserInsertList(int num, List<RoleViewModel> roles)
{
Random rnd = new Random();
using var context = new BlogDatabase();
for (int i = 0; i < num; ++i)
{
var model = new UserBindingModel
{
Id = 0,
Username = rnd.Next(1000).ToString(),
Email = rnd.Next(1000).ToString(),
Password = rnd.Next(1000).ToString(),
RoleId = roles[rnd.Next(roles.Count)].Id,
};
context.Users.Add(User.Create(model));
}
context.SaveChanges();
}
}
}

View File

@ -0,0 +1,54 @@
using ForumContracts.BindingModels;
using ForumContracts.ViewModels;
using ForumDataModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
namespace BlogDatabase.Models
{
public class Category : ICategoryModel
{
[Required]
public string Name { get; set; } = string.Empty;
public int Id { get; private set; }
[Required]
public int UserId { get; set; }
[ForeignKey("TopicId")]
List<Topic> Topics { get; set; } = new();
public static Category? Create(CategoryBindingModel model)
{
if (model == null)
{
return null;
}
return new Category()
{
Id = model.Id,
Name = model.Name,
};
}
public void Update(CategoryBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
}
public CategoryViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
};
}
}

View File

@ -0,0 +1,69 @@
using ForumContracts.BindingModels;
using ForumContracts.ViewModels;
using ForumDataModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace BlogDatabase.Models
{
public class Message : IMessageModel
{
[Required]
public string Text { get; set; } = string.Empty;
[Required]
public DateTime Date { get; set; } = DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc);
public int Id { get; private set; }
[Required]
public int UserId { get; set; }
[Required]
public int TopicId { get; set; }
public virtual User? User { get; set; }
public virtual Topic? Topic { get; set; }
public static Message? Create(MessageBindingModel model)
{
if (model == null)
{
return null;
}
return new Message()
{
Id = model.Id,
Text = model.Text,
Date = model.Date,
UserId = model.UserId,
TopicId = model.TopicId,
};
}
public void Update(MessageBindingModel model)
{
if (model == null)
{
return;
}
Text = model.Text;
Date = model.Date;
}
public MessageViewModel GetViewModel => new()
{
Id = Id,
Text = Text,
Date = Date,
TopicId = TopicId,
UserId = UserId,
Username = User == null ? string.Empty : User.Username,
TopicName = Topic == null ? string.Empty : Topic.Name,
};
}
}

View File

@ -0,0 +1,52 @@
using ForumContracts.BindingModels;
using ForumContracts.ViewModels;
using ForumDataModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace BlogDatabase.Models
{
public class Role : IRoleModel
{
[Required]
public string Name { get; set; } = string.Empty;
public int Id { get; private set; }
[ForeignKey("UserId")]
List<User> Users { get; set; } = new();
public static Role? Create(RoleBindingModel model)
{
if (model == null)
{
return null;
}
return new Role()
{
Id = model.Id,
Name = model.Name,
};
}
public void Update(RoleBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
}
public RoleViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
};
}
}

View File

@ -0,0 +1,62 @@
using ForumContracts.BindingModels;
using ForumContracts.ViewModels;
using ForumDataModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
namespace BlogDatabase.Models
{
public class Topic : ITopicModel
{
[Required]
public string Name { get; set; } = string.Empty;
public int Id { get; private set; }
[Required]
public int UserId { get; set; }
[Required]
public int CategoryId { get; set; }
[ForeignKey("MessageId")]
List<Message> Messages { get; set; } = new();
public virtual Category? Category { get; set; }
public static Topic? Create(TopicBindingModel model)
{
if (model == null)
{
return null;
}
return new Topic()
{
Id = model.Id,
Name = model.Name,
CategoryId = model.CategoryId,
};
}
public void Update(TopicBindingModel model)
{
if (model == null)
{
return;
}
model.Id = Id;
model.Name = Name;
}
public TopicViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
CategoryId = CategoryId,
};
}
}

View File

@ -0,0 +1,82 @@
using ForumContracts.BindingModels;
using ForumContracts.ViewModels;
using ForumDataModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
namespace BlogDatabase.Models
{
public class User : IUserModel
{
[Required]
public string Username { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[Required]
public DateTime RegistrationDate { get; set; }
public int Id { get; set; }
[Required]
public int RoleId { get; set; }
[ForeignKey("CategoryId")]
List<Category> Categories { get; set; } = new();
[ForeignKey("TopicId")]
List<Topic> Topics { get; set; } = new();
[ForeignKey("MessageId")]
List<Message> Messages { get; set; } = new();
public virtual Role Role { get; set; }
public static User? Create(UserBindingModel model)
{
if (model == null)
{
return null;
}
return new User()
{
Id = model.Id,
Username = model.Username,
Email = model.Email,
Password = model.Password,
RegistrationDate = model.RegistrationDate,
RoleId = model.RoleId,
};
}
public void Update(UserBindingModel model)
{
if (model == null)
{
return;
}
Username = model.Username;
Email = model.Email;
Password = model.Password;
RegistrationDate = model.RegistrationDate;
}
public UserViewModel GetViewModel => new()
{
Id = Id,
Username = Username,
Email = Email,
Password = Password,
RegistrationDate = RegistrationDate,
RoleId = RoleId,
RoleName = Role == null ? string.Empty : Role.Name,
};
}
}

View File

@ -19,6 +19,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\BlogContracts\BlogContracts.csproj" /> <ProjectReference Include="..\BlogContracts\BlogContracts.csproj" />
<ProjectReference Include="..\BlogDatabaseImplement\BlogDatabaseImplement.csproj" /> <ProjectReference Include="..\BlogDatabaseImplement\BlogDatabaseImplement.csproj" />
<ProjectReference Include="..\BlogDataModels\BlogDataModels.csproj" />
<ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj" /> <ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -0,0 +1,88 @@
namespace Forum
{
partial class FormAddTopic
{
/// <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()
{
this.textBoxTopic = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBoxTopic
//
this.textBoxTopic.Location = new System.Drawing.Point(18, 9);
this.textBoxTopic.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxTopic.Name = "textBoxTopic";
this.textBoxTopic.Size = new System.Drawing.Size(191, 23);
this.textBoxTopic.TabIndex = 0;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(18, 34);
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(82, 22);
this.buttonSave.TabIndex = 1;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(126, 34);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(82, 22);
this.buttonCancel.TabIndex = 2;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// FormAddTopic
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(220, 63);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxTopic);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormAddTopic";
this.Text = "Тема";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private TextBox textBoxTopic;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,67 @@
using ForumContracts.BindingModels;
using ForumContracts.BusinessLogicContracts;
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 Forum
{
public partial class FormAddTopic : Form
{
private readonly ITopicLogic _topicLogic;
private readonly ICategoryLogic _categoryLogic;
private int? _id;
public int Id { set { _id = value; } }
public FormAddTopic(ITopicLogic topicLogic, ICategoryLogic categoryLogic)
{
InitializeComponent();
_topicLogic = topicLogic;
_categoryLogic = categoryLogic;
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxTopic.Text))
{
MessageBox.Show("Название темы не может быть пустой", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
try
{
var model = new TopicBindingModel
{
Name = textBoxTopic.Text,
CategoryId = _id ?? 0,
};
var operationResult = _topicLogic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранеии.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -0,0 +1,134 @@
namespace Forum
{
partial class FormAddTopics
{
/// <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()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.textBoxCategory = new System.Windows.Forms.TextBox();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonChange = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(10, 40);
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(357, 141);
this.dataGridView.TabIndex = 0;
//
// textBoxCategory
//
this.textBoxCategory.Location = new System.Drawing.Point(10, 9);
this.textBoxCategory.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxCategory.Name = "textBoxCategory";
this.textBoxCategory.ReadOnly = true;
this.textBoxCategory.Size = new System.Drawing.Size(110, 23);
this.textBoxCategory.TabIndex = 1;
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(381, 40);
this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(82, 22);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonChange
//
this.buttonChange.Location = new System.Drawing.Point(381, 67);
this.buttonChange.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonChange.Name = "buttonChange";
this.buttonChange.Size = new System.Drawing.Size(82, 22);
this.buttonChange.TabIndex = 3;
this.buttonChange.Text = "Изменить";
this.buttonChange.UseVisualStyleBackColor = true;
this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(381, 93);
this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(82, 22);
this.buttonDelete.TabIndex = 4;
this.buttonDelete.Text = "Удалить";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(381, 119);
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(82, 22);
this.buttonUpdate.TabIndex = 5;
this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
//
// FormAddTopics
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(469, 190);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonChange);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.textBoxCategory);
this.Controls.Add(this.dataGridView);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormAddTopics";
this.Text = "Добавление тем";
this.Load += new System.EventHandler(this.FormAddTopic_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private DataGridView dataGridView;
private TextBox textBoxCategory;
private Button buttonCreate;
private Button buttonChange;
private Button buttonDelete;
private Button buttonUpdate;
}
}

View File

@ -0,0 +1,117 @@
using ForumContracts.BindingModels;
using ForumContracts.BusinessLogicContracts;
using ForumContracts.SearchModels;
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 Forum
{
public partial class FormAddTopics : Form
{
private readonly ICategoryLogic _categoryLogic;
private readonly ITopicLogic _topicLogic;
private int? _id;
public int Id { set { _id = value; } }
public FormAddTopics(ITopicLogic topicLogic, ICategoryLogic categoryLogic)
{
InitializeComponent();
_topicLogic = topicLogic;
_categoryLogic = categoryLogic;
}
private void FormAddTopic_Load(object sender, EventArgs e)
{
LoadData();
try
{
var view = _categoryLogic.ReadElement(new CategorySearchModel { Id = _id.Value });
if (view != null)
{
textBoxCategory.Text = view.Name;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAddTopic));
if (service is FormAddTopic form)
{
form.Id = _id ?? 0;
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void LoadData()
{
try
{
var list = _topicLogic.ReadList(new TopicSearchModel { CategoryId = _id });
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["CategoryId"].Visible = false;
dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception)
{ }
}
private void buttonChange_Click(object sender, EventArgs e)
{
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try
{
if (!_topicLogic.Delete(new TopicBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении.");
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -0,0 +1,128 @@
namespace Forum
{
partial class FormCategories
{
/// <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()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonChange = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
this.buttonAddTopicInCategory = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(300, 188);
this.dataGridView.TabIndex = 0;
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(330, 12);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.TabIndex = 1;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonChange
//
this.buttonChange.Location = new System.Drawing.Point(330, 47);
this.buttonChange.Name = "buttonChange";
this.buttonChange.Size = new System.Drawing.Size(94, 29);
this.buttonChange.TabIndex = 2;
this.buttonChange.Text = "Изменить";
this.buttonChange.UseVisualStyleBackColor = true;
this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(330, 82);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(94, 29);
this.buttonDelete.TabIndex = 3;
this.buttonDelete.Text = "Удалить";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(330, 117);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(94, 29);
this.buttonUpdate.TabIndex = 4;
this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
//
// buttonAddTopicInCategory
//
this.buttonAddTopicInCategory.Location = new System.Drawing.Point(330, 152);
this.buttonAddTopicInCategory.Name = "buttonAddTopicInCategory";
this.buttonAddTopicInCategory.Size = new System.Drawing.Size(94, 54);
this.buttonAddTopicInCategory.TabIndex = 5;
this.buttonAddTopicInCategory.Text = "Добавить темы";
this.buttonAddTopicInCategory.UseVisualStyleBackColor = true;
this.buttonAddTopicInCategory.Click += new System.EventHandler(this.buttonAddTopicInCategory_Click);
//
// FormCategories
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(438, 211);
this.Controls.Add(this.buttonAddTopicInCategory);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonChange);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.dataGridView);
this.Name = "FormCategories";
this.Text = "Категории";
this.Load += new System.EventHandler(this.FormCategories_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonCreate;
private Button buttonChange;
private Button buttonDelete;
private Button buttonUpdate;
private Button buttonAddTopicInCategory;
}
}

View File

@ -0,0 +1,129 @@
using ForumContracts.BindingModels;
using ForumContracts.BusinessLogicContracts;
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 Forum
{
public partial class FormCategories : Form
{
private readonly ICategoryLogic _categoryLogic;
public FormCategories(ICategoryLogic categoryLogic)
{
InitializeComponent();
_categoryLogic = categoryLogic;
}
private void buttonCreate_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCategory));
if (service is FormCategory form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void LoadData()
{
try
{
var list = _categoryLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception)
{ }
}
private void FormCategories_Load(object sender, EventArgs e)
{
LoadData();
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try
{
if (!_categoryLogic.Delete(new CategoryBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении.");
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void buttonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCategory));
if (service is FormCategory form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
private void buttonAddTopicInCategory_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAddTopics));
if (service is FormAddTopics form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -0,0 +1,85 @@
namespace Forum
{
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()
{
this.textBoxCategory = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBoxCategory
//
this.textBoxCategory.Location = new System.Drawing.Point(12, 12);
this.textBoxCategory.Name = "textBoxCategory";
this.textBoxCategory.Size = new System.Drawing.Size(194, 27);
this.textBoxCategory.TabIndex = 0;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(12, 45);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(94, 29);
this.buttonSave.TabIndex = 1;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(112, 45);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 2;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// FormCategory
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(222, 82);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxCategory);
this.Name = "FormCategory";
this.Text = "Категория";
this.Click += new System.EventHandler(this.FormCategory_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private TextBox textBoxCategory;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,88 @@
using ForumContracts.BindingModels;
using ForumContracts.BusinessLogicContracts;
using ForumContracts.SearchModels;
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 Forum
{
public partial class FormCategory : Form
{
private readonly ICategoryLogic _categoryLogic;
private int? _id;
public int Id { set { _id = value; } }
public FormCategory(ICategoryLogic categoryLogic)
{
InitializeComponent();
_categoryLogic = categoryLogic;
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCategory.Text))
{
MessageBox.Show("Введите название роли", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
try
{
var model = new CategoryBindingModel
{
Id = _id ?? 0,
Name = textBoxCategory.Text
};
var operationResult = _id.HasValue ? _categoryLogic.Update(model) : _categoryLogic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранеии.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormCategory_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
var view = _categoryLogic.ReadElement(new CategorySearchModel { Id = _id.Value });
if (view != null)
{
textBoxCategory.Text = view.Name;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -0,0 +1,156 @@
namespace Forum
{
partial class FormCreateMessage
{
/// <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()
{
this.comboBoxCategory = new System.Windows.Forms.ComboBox();
this.comboBoxTopic = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.comboBoxUser = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label();
this.textBoxMessage = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// comboBoxCategory
//
this.comboBoxCategory.FormattingEnabled = true;
this.comboBoxCategory.Location = new System.Drawing.Point(141, 6);
this.comboBoxCategory.Name = "comboBoxCategory";
this.comboBoxCategory.Size = new System.Drawing.Size(147, 23);
this.comboBoxCategory.TabIndex = 0;
this.comboBoxCategory.SelectedIndexChanged += new System.EventHandler(this.comboBoxCategory_SelectedIndexChanged);
//
// comboBoxTopic
//
this.comboBoxTopic.FormattingEnabled = true;
this.comboBoxTopic.Location = new System.Drawing.Point(141, 35);
this.comboBoxTopic.Name = "comboBoxTopic";
this.comboBoxTopic.Size = new System.Drawing.Size(147, 23);
this.comboBoxTopic.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(123, 15);
this.label1.TabIndex = 2;
this.label1.Text = "Выберите категорию";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 38);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(90, 15);
this.label2.TabIndex = 3;
this.label2.Text = "Выберите тему";
//
// comboBoxUser
//
this.comboBoxUser.FormattingEnabled = true;
this.comboBoxUser.Location = new System.Drawing.Point(141, 64);
this.comboBoxUser.Name = "comboBoxUser";
this.comboBoxUser.Size = new System.Drawing.Size(147, 23);
this.comboBoxUser.TabIndex = 4;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 67);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(84, 15);
this.label3.TabIndex = 5;
this.label3.Text = "Пользователь";
//
// textBoxMessage
//
this.textBoxMessage.Location = new System.Drawing.Point(12, 93);
this.textBoxMessage.Multiline = true;
this.textBoxMessage.Name = "textBoxMessage";
this.textBoxMessage.Size = new System.Drawing.Size(276, 70);
this.textBoxMessage.TabIndex = 6;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(132, 169);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
this.buttonSave.TabIndex = 7;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(213, 169);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 8;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// FormCreateMessage
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(296, 198);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxMessage);
this.Controls.Add(this.label3);
this.Controls.Add(this.comboBoxUser);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBoxTopic);
this.Controls.Add(this.comboBoxCategory);
this.Name = "FormCreateMessage";
this.Text = "Написать сообщение";
this.Load += new System.EventHandler(this.FormCreateMessage_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private ComboBox comboBoxCategory;
private ComboBox comboBoxTopic;
private Label label1;
private Label label2;
private ComboBox comboBoxUser;
private Label label3;
private TextBox textBoxMessage;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,139 @@
using ForumBusinessLogic;
using ForumContracts.BindingModels;
using ForumContracts.BusinessLogicContracts;
using ForumContracts.SearchModels;
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 Forum
{
public partial class FormCreateMessage : Form
{
private readonly IMessageLogic _messageLogic;
private readonly ICategoryLogic _categoryLogic;
private readonly ITopicLogic _topicLogic;
private readonly IUserLogic _userLogic;
private int? _id;
public int Id { set { _id = value; } }
public FormCreateMessage(ICategoryLogic categoryLogic, ITopicLogic topicLogic, IUserLogic userLogic, IMessageLogic messageLogic)
{
InitializeComponent();
_categoryLogic = categoryLogic;
_topicLogic = topicLogic;
_userLogic = userLogic;
_messageLogic = messageLogic;
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (comboBoxCategory.SelectedValue == null)
{
MessageBox.Show("Выберите категорию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxTopic.SelectedValue == null)
{
MessageBox.Show("Выберите тему", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxUser.SelectedValue == null)
{
MessageBox.Show("Выберите пользователя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxMessage.Text))
{
MessageBox.Show("Напишите сообщение", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
var model = new MessageBindingModel
{
Id = _id ?? 0,
Date = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
Text = textBoxMessage.Text,
TopicId = Convert.ToInt32(comboBoxTopic.SelectedValue),
UserId = Convert.ToInt32(comboBoxUser.SelectedValue),
};
var operationResult = _id.HasValue ? _messageLogic.Update(model) : _messageLogic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при создании сообщения.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
}
private void FormCreateMessage_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var user = _userLogic.ReadList(null);
if (user != null)
{
comboBoxUser.DisplayMember = "Username";
comboBoxUser.ValueMember = "Id";
comboBoxUser.DataSource = user;
comboBoxUser.SelectedItem = null;
}
var category = _categoryLogic.ReadList(null);
if (category != null)
{
comboBoxCategory.DisplayMember = "Name";
comboBoxCategory.ValueMember = "Id";
comboBoxCategory.DataSource = category;
comboBoxCategory.SelectedItem = null;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void comboBoxCategory_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
var topics = _topicLogic.ReadList(new TopicSearchModel { CategoryId = Convert.ToInt32(comboBoxCategory.SelectedValue), });
if (topics != null)
{
comboBoxTopic.DisplayMember = "Name";
comboBoxTopic.ValueMember = "Id";
comboBoxTopic.DataSource = topics;
comboBoxTopic.SelectedItem = null;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -0,0 +1,163 @@
namespace Forum
{
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()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.ролиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.пользователиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.категорииToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
this.тестыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(10, 32);
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(554, 296);
this.dataGridView.TabIndex = 0;
//
// menuStrip1
//
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ролиToolStripMenuItem,
this.пользователиToolStripMenuItem,
this.категорииToolStripMenuItem,
this.тестыToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2);
this.menuStrip1.Size = new System.Drawing.Size(653, 24);
this.menuStrip1.TabIndex = 1;
this.menuStrip1.Text = "menuStrip1";
//
// ролиToolStripMenuItem
//
this.ролиToolStripMenuItem.Name = "ролиToolStripMenuItem";
this.ролиToolStripMenuItem.Size = new System.Drawing.Size(47, 20);
this.ролиToolStripMenuItem.Text = "Роли";
this.ролиToolStripMenuItem.Click += new System.EventHandler(this.ролиToolStripMenuItem_Click);
//
// пользователиToolStripMenuItem
//
this.пользователиToolStripMenuItem.Name = "пользователиToolStripMenuItem";
this.пользователиToolStripMenuItem.Size = new System.Drawing.Size(97, 20);
this.пользователиToolStripMenuItem.Text = "Пользователи";
this.пользователиToolStripMenuItem.Click += new System.EventHandler(this.пользователиToolStripMenuItem_Click);
//
// категорииToolStripMenuItem
//
this.категорииToolStripMenuItem.Name = атегорииToolStripMenuItem";
this.категорииToolStripMenuItem.Size = new System.Drawing.Size(76, 20);
this.категорииToolStripMenuItem.Text = "Категории";
this.категорииToolStripMenuItem.Click += new System.EventHandler(this.категорииToolStripMenuItem_Click);
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(570, 32);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(570, 61);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(75, 23);
this.buttonDelete.TabIndex = 4;
this.buttonDelete.Text = "Удалить";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(570, 90);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(75, 23);
this.buttonUpdate.TabIndex = 5;
this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
//
// тестыToolStripMenuItem
//
this.тестыToolStripMenuItem.Name = естыToolStripMenuItem";
this.тестыToolStripMenuItem.Size = new System.Drawing.Size(51, 20);
this.тестыToolStripMenuItem.Text = "Тесты";
this.тестыToolStripMenuItem.Click += new System.EventHandler(this.тестыToolStripMenuItem_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(653, 338);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormMain";
this.Text = "Форум";
this.Load += new System.EventHandler(this.FormMain_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private DataGridView dataGridView;
private MenuStrip menuStrip1;
private ToolStripMenuItem ролиToolStripMenuItem;
private ToolStripMenuItem пользователиToolStripMenuItem;
private ToolStripMenuItem категорииToolStripMenuItem;
private Button buttonCreate;
private Button buttonDelete;
private Button buttonUpdate;
private ToolStripMenuItem тестыToolStripMenuItem;
}
}

View File

@ -0,0 +1,147 @@
using ForumBusinessLogic;
using ForumContracts.BindingModels;
using ForumContracts.BusinessLogicContracts;
using System.Windows.Forms;
namespace Forum
{
public partial class FormMain : Form
{
private readonly IMessageLogic _messageLogic;
public FormMain(IMessageLogic messageLogic)
{
InitializeComponent();
_messageLogic = messageLogic;
}
private void ðîëèToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormRoles));
if (service is FormRoles form)
{
form.ShowDialog();
}
}
private void ïîëüçîâàòåëèToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormUsers));
if (service is FormUsers form)
{
form.ShowDialog();
}
}
private void êàòåãîðèèToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCategories));
if (service is FormCategories form)
{
form.ShowDialog();
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateMessage));
if (service is FormCreateMessage form)
{
form.ShowDialog();
LoadData();
}
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _messageLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["UserId"].Visible = false;
dataGridView.Columns["TopicId"].Visible = false;
dataGridView.Columns["Username"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["TopicName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Text"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Date"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Óäàëèòü çàïèñü?", "Âîïðîñ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try
{
if (!_messageLogic.Delete(new MessageBindingModel
{
Id = id
}))
{
throw new Exception("Îøèáêà ïðè óäàëåíèè.");
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
private void buttonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateMessage));
if (service is FormCreateMessage form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void òåñòûToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormTests));
if (service is FormTests form)
{
form.ShowDialog();
}
}
}
}

View File

@ -0,0 +1,63 @@
<root>
<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>
</root>

View File

@ -0,0 +1,102 @@
namespace Forum
{
partial class FormRole
{
/// <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()
{
this.textBoxRoleName = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonAddRoles = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBoxRoleName
//
this.textBoxRoleName.Location = new System.Drawing.Point(10, 9);
this.textBoxRoleName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxRoleName.Name = "textBoxRoleName";
this.textBoxRoleName.Size = new System.Drawing.Size(218, 23);
this.textBoxRoleName.TabIndex = 0;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(10, 34);
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(82, 22);
this.buttonSave.TabIndex = 1;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(10, 63);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(82, 22);
this.buttonCancel.TabIndex = 2;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// buttonAddRoles
//
this.buttonAddRoles.Location = new System.Drawing.Point(153, 34);
this.buttonAddRoles.Name = "buttonAddRoles";
this.buttonAddRoles.Size = new System.Drawing.Size(75, 54);
this.buttonAddRoles.TabIndex = 3;
this.buttonAddRoles.Text = "Добавить 1000 ролей";
this.buttonAddRoles.UseVisualStyleBackColor = true;
this.buttonAddRoles.Click += new System.EventHandler(this.buttonAddRoles_Click);
//
// FormRole
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(234, 96);
this.Controls.Add(this.buttonAddRoles);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxRoleName);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormRole";
this.Text = "Роль";
this.Load += new System.EventHandler(this.FormRole_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private TextBox textBoxRoleName;
private Button buttonSave;
private Button buttonCancel;
private Button buttonAddRoles;
}
}

View File

@ -0,0 +1,102 @@
using ForumContracts.BindingModels;
using ForumContracts.BusinessLogicContracts;
using ForumContracts.SearchModels;
using Microsoft.EntityFrameworkCore.Diagnostics;
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 Forum
{
public partial class FormRole : Form
{
private readonly IRoleLogic _roleLogic;
private int? _id;
public int Id { set { _id = value; } }
public FormRole(IRoleLogic roleLogic)
{
InitializeComponent();
_roleLogic = roleLogic;
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxRoleName.Text))
{
MessageBox.Show("Введите название роли", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
try
{
var model = new RoleBindingModel
{
Id = _id ?? 0,
Name = textBoxRoleName.Text
};
var operationResult = _id.HasValue ? _roleLogic.Update(model) : _roleLogic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранеии.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormRole_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
var view = _roleLogic.ReadElement(new RoleSearchModel { Id = _id.Value });
if (view != null)
{
textBoxRoleName.Text = view.Name;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonAddRoles_Click(object sender, EventArgs e)
{
try
{
_roleLogic.RoleInsertList(1000);
FormRole_Load(sender, e);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -0,0 +1,115 @@
namespace Forum
{
partial class FormRoles
{
/// <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()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonChange = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(371, 268);
this.dataGridView.TabIndex = 0;
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(389, 12);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.TabIndex = 1;
this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(389, 47);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(94, 29);
this.buttonDelete.TabIndex = 2;
this.buttonDelete.Text = "Удалить";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
//
// buttonChange
//
this.buttonChange.Location = new System.Drawing.Point(389, 82);
this.buttonChange.Name = "buttonChange";
this.buttonChange.Size = new System.Drawing.Size(94, 29);
this.buttonChange.TabIndex = 3;
this.buttonChange.Text = "Изменить";
this.buttonChange.UseVisualStyleBackColor = true;
this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(389, 117);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(94, 29);
this.buttonUpdate.TabIndex = 4;
this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
//
// FormRoles
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(495, 292);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonChange);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.dataGridView);
this.Name = "FormRoles";
this.Text = "Роли";
this.Load += new System.EventHandler(this.FormRoles_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonCreate;
private Button buttonDelete;
private Button buttonChange;
private Button buttonUpdate;
}
}

View File

@ -0,0 +1,111 @@
using ForumContracts.BindingModels;
using ForumContracts.BusinessLogicContracts;
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 Forum
{
public partial class FormRoles : Form
{
private readonly IRoleLogic _roleLogic;
public FormRoles(IRoleLogic roleLogic)
{
InitializeComponent();
_roleLogic = roleLogic;
}
private void buttonCreate_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormRole));
if (service is FormRole form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void LoadData()
{
try
{
var list = _roleLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception)
{ }
}
private void FormRoles_Load(object sender, EventArgs e)
{
LoadData();
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try
{
if (!_roleLogic.Delete(new RoleBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении.");
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void buttonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormRole));
if (service is FormRole form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -0,0 +1,229 @@
namespace Forum
{
partial class FormTests
{
/// <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()
{
this.buttonInsertTest = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBoxInsertTime = new System.Windows.Forms.TextBox();
this.buttonReadTest = new System.Windows.Forms.Button();
this.textBoxReadTime = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.numericUpDownInsert = new System.Windows.Forms.NumericUpDown();
this.numericUpDownRead = new System.Windows.Forms.NumericUpDown();
this.buttonJoinQuery = new System.Windows.Forms.Button();
this.numericUpDownJoin = new System.Windows.Forms.NumericUpDown();
this.textBoxJoin = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownJoin)).BeginInit();
this.SuspendLayout();
//
// buttonInsertTest
//
this.buttonInsertTest.Location = new System.Drawing.Point(12, 12);
this.buttonInsertTest.Name = "buttonInsertTest";
this.buttonInsertTest.Size = new System.Drawing.Size(86, 61);
this.buttonInsertTest.TabIndex = 0;
this.buttonInsertTest.Text = "Тест вставки сообщений";
this.buttonInsertTest.UseVisualStyleBackColor = true;
this.buttonInsertTest.Click += new System.EventHandler(this.buttonInsertTest_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(104, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(156, 15);
this.label1.TabIndex = 1;
this.label1.Text = "Введите кол-во элементов:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(104, 53);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(146, 15);
this.label2.TabIndex = 3;
this.label2.Text = "Итоговое время запроса:";
//
// textBoxInsertTime
//
this.textBoxInsertTime.Location = new System.Drawing.Point(266, 50);
this.textBoxInsertTime.Name = "textBoxInsertTime";
this.textBoxInsertTime.ReadOnly = true;
this.textBoxInsertTime.Size = new System.Drawing.Size(100, 23);
this.textBoxInsertTime.TabIndex = 4;
//
// buttonReadTest
//
this.buttonReadTest.Location = new System.Drawing.Point(12, 106);
this.buttonReadTest.Name = "buttonReadTest";
this.buttonReadTest.Size = new System.Drawing.Size(86, 56);
this.buttonReadTest.TabIndex = 5;
this.buttonReadTest.Text = "Тест чтения сообщений";
this.buttonReadTest.UseVisualStyleBackColor = true;
this.buttonReadTest.Click += new System.EventHandler(this.buttonReadTest_Click);
//
// textBoxReadTime
//
this.textBoxReadTime.Location = new System.Drawing.Point(266, 144);
this.textBoxReadTime.Name = "textBoxReadTime";
this.textBoxReadTime.ReadOnly = true;
this.textBoxReadTime.Size = new System.Drawing.Size(100, 23);
this.textBoxReadTime.TabIndex = 9;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(104, 147);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(146, 15);
this.label3.TabIndex = 8;
this.label3.Text = "Итоговое время запроса:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(104, 106);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(156, 15);
this.label4.TabIndex = 6;
this.label4.Text = "Введите кол-во элементов:";
//
// numericUpDownInsert
//
this.numericUpDownInsert.Location = new System.Drawing.Point(266, 10);
this.numericUpDownInsert.Name = "numericUpDownInsert";
this.numericUpDownInsert.Size = new System.Drawing.Size(100, 23);
this.numericUpDownInsert.TabIndex = 10;
//
// numericUpDownRead
//
this.numericUpDownRead.Location = new System.Drawing.Point(266, 104);
this.numericUpDownRead.Name = "numericUpDownRead";
this.numericUpDownRead.Size = new System.Drawing.Size(100, 23);
this.numericUpDownRead.TabIndex = 11;
//
// buttonJoinQuery
//
this.buttonJoinQuery.Location = new System.Drawing.Point(12, 197);
this.buttonJoinQuery.Name = "buttonJoinQuery";
this.buttonJoinQuery.Size = new System.Drawing.Size(86, 74);
this.buttonJoinQuery.TabIndex = 12;
this.buttonJoinQuery.Text = "Тест сложного чтения (Join)";
this.buttonJoinQuery.UseVisualStyleBackColor = true;
this.buttonJoinQuery.Click += new System.EventHandler(this.buttonJoinQuery_Click);
//
// numericUpDownJoin
//
this.numericUpDownJoin.Location = new System.Drawing.Point(266, 195);
this.numericUpDownJoin.Name = "numericUpDownJoin";
this.numericUpDownJoin.Size = new System.Drawing.Size(100, 23);
this.numericUpDownJoin.TabIndex = 16;
//
// textBoxJoin
//
this.textBoxJoin.Location = new System.Drawing.Point(266, 235);
this.textBoxJoin.Name = "textBoxJoin";
this.textBoxJoin.ReadOnly = true;
this.textBoxJoin.Size = new System.Drawing.Size(100, 23);
this.textBoxJoin.TabIndex = 15;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(104, 238);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(146, 15);
this.label5.TabIndex = 14;
this.label5.Text = "Итоговое время запроса:";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(104, 197);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(156, 15);
this.label6.TabIndex = 13;
this.label6.Text = "Введите кол-во элементов:";
//
// FormTests
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(383, 286);
this.Controls.Add(this.numericUpDownJoin);
this.Controls.Add(this.textBoxJoin);
this.Controls.Add(this.label5);
this.Controls.Add(this.label6);
this.Controls.Add(this.buttonJoinQuery);
this.Controls.Add(this.numericUpDownRead);
this.Controls.Add(this.numericUpDownInsert);
this.Controls.Add(this.textBoxReadTime);
this.Controls.Add(this.label3);
this.Controls.Add(this.label4);
this.Controls.Add(this.buttonReadTest);
this.Controls.Add(this.textBoxInsertTime);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.buttonInsertTest);
this.Name = "FormTests";
this.Text = "Тесты запросов к бд";
((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownJoin)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonInsertTest;
private Label label1;
private Label label2;
private TextBox textBoxInsertTime;
private Button buttonReadTest;
private TextBox textBoxReadTime;
private Label label3;
private Label label4;
private NumericUpDown numericUpDownInsert;
private NumericUpDown numericUpDownRead;
private Button buttonJoinQuery;
private NumericUpDown numericUpDownJoin;
private TextBox textBoxJoin;
private Label label5;
private Label label6;
}
}

View File

@ -0,0 +1,75 @@
using ForumContracts.BusinessLogicContracts;
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 Forum
{
public partial class FormTests : Form
{
private readonly IMessageLogic _messageLogic;
private readonly IUserLogic _userLogic;
private readonly ITopicLogic _topicLogic;
public FormTests(IUserLogic userLogic, ITopicLogic topicLogic, IMessageLogic messageLogic)
{
InitializeComponent();
_userLogic = userLogic;
_topicLogic = topicLogic;
_messageLogic = messageLogic;
numericUpDownInsert.Minimum = 0;
numericUpDownInsert.Maximum = 1000000;
numericUpDownRead.Minimum = 0;
numericUpDownRead.Maximum = 1000000;
numericUpDownJoin.Minimum = 0;
numericUpDownJoin.Maximum = 1000000;
}
private void buttonInsertTest_Click(object sender, EventArgs e)
{
try
{
var result = _messageLogic.TestInsertList(Convert.ToInt32(numericUpDownInsert.Value),
_userLogic.ReadList(null) ?? new(),
_topicLogic.ReadList(null) ?? new());
textBoxInsertTime.Text = result;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonReadTest_Click(object sender, EventArgs e)
{
try
{
var result = _messageLogic.TestReadList(Convert.ToInt32(numericUpDownInsert.Value));
textBoxReadTime.Text = result;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonJoinQuery_Click(object sender, EventArgs e)
{
try
{
var result = _messageLogic.TestJoinReadList(Convert.ToInt32(numericUpDownJoin.Value));
textBoxJoin.Text = result;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -0,0 +1,184 @@
namespace Forum
{
partial class FormUser
{
/// <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()
{
this.textBoxUsername = new System.Windows.Forms.TextBox();
this.textBoxLogin = new System.Windows.Forms.TextBox();
this.textBoxPassword = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.comboBoxSelectRole = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
this.buttonAddUsers = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBoxUsername
//
this.textBoxUsername.Location = new System.Drawing.Point(80, 9);
this.textBoxUsername.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxUsername.Name = "textBoxUsername";
this.textBoxUsername.Size = new System.Drawing.Size(133, 23);
this.textBoxUsername.TabIndex = 0;
//
// textBoxLogin
//
this.textBoxLogin.Location = new System.Drawing.Point(80, 34);
this.textBoxLogin.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxLogin.Name = "textBoxLogin";
this.textBoxLogin.Size = new System.Drawing.Size(133, 23);
this.textBoxLogin.TabIndex = 1;
//
// textBoxPassword
//
this.textBoxPassword.Location = new System.Drawing.Point(80, 58);
this.textBoxPassword.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxPassword.Name = "textBoxPassword";
this.textBoxPassword.Size = new System.Drawing.Size(133, 23);
this.textBoxPassword.TabIndex = 2;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(10, 14);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(60, 15);
this.label1.TabIndex = 3;
this.label1.Text = "Username";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(10, 39);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(37, 15);
this.label2.TabIndex = 4;
this.label2.Text = "Login";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(10, 64);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(57, 15);
this.label3.TabIndex = 5;
this.label3.Text = "Password";
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(219, 11);
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(82, 22);
this.buttonSave.TabIndex = 6;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(219, 37);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(82, 22);
this.buttonCancel.TabIndex = 7;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// comboBoxSelectRole
//
this.comboBoxSelectRole.FormattingEnabled = true;
this.comboBoxSelectRole.Location = new System.Drawing.Point(80, 88);
this.comboBoxSelectRole.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.comboBoxSelectRole.Name = "comboBoxSelectRole";
this.comboBoxSelectRole.Size = new System.Drawing.Size(133, 23);
this.comboBoxSelectRole.TabIndex = 8;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(10, 90);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(30, 15);
this.label4.TabIndex = 9;
this.label4.Text = "Role";
//
// buttonAddUsers
//
this.buttonAddUsers.Location = new System.Drawing.Point(219, 64);
this.buttonAddUsers.Name = "buttonAddUsers";
this.buttonAddUsers.Size = new System.Drawing.Size(82, 77);
this.buttonAddUsers.TabIndex = 10;
this.buttonAddUsers.Text = "Добавить 1000 пользователей";
this.buttonAddUsers.UseVisualStyleBackColor = true;
this.buttonAddUsers.Click += new System.EventHandler(this.buttonAddUsers_Click);
//
// FormUser
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(310, 145);
this.Controls.Add(this.buttonAddUsers);
this.Controls.Add(this.label4);
this.Controls.Add(this.comboBoxSelectRole);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBoxPassword);
this.Controls.Add(this.textBoxLogin);
this.Controls.Add(this.textBoxUsername);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormUser";
this.Text = "Пользователь";
this.Load += new System.EventHandler(this.FormUser_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private TextBox textBoxUsername;
private TextBox textBoxLogin;
private TextBox textBoxPassword;
private Label label1;
private Label label2;
private Label label3;
private Button buttonSave;
private Button buttonCancel;
private ComboBox comboBoxSelectRole;
private Label label4;
private Button buttonAddUsers;
}
}

View File

@ -0,0 +1,138 @@
using ForumContracts.BindingModels;
using ForumContracts.BusinessLogicContracts;
using ForumContracts.SearchModels;
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 Forum
{
public partial class FormUser : Form
{
private readonly IUserLogic _userLogic;
private readonly IRoleLogic _roleLogic;
private int? _id;
public int Id { set { _id = value; } }
public FormUser(IRoleLogic roleLogic, IUserLogic userLogic)
{
InitializeComponent();
_roleLogic = roleLogic;
_userLogic = userLogic;
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxUsername.Text))
{
MessageBox.Show("Заполните поле Username", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxLogin.Text))
{
MessageBox.Show("Заполните поле Login", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxPassword.Text))
{
MessageBox.Show("Заполните поле Password", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxSelectRole.SelectedValue == null)
{
MessageBox.Show("Выберите Role", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
var model = new UserBindingModel
{
Id = _id ?? 0,
Username = textBoxUsername.Text,
Email = textBoxLogin.Text,
Password = textBoxPassword.Text,
RegistrationDate = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
RoleId = Convert.ToInt32(comboBoxSelectRole.SelectedValue),
};
var operationResult = _id.HasValue ? _userLogic.Update(model) : _userLogic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при создании пользователя.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormUser_Load(object sender, EventArgs e)
{
LoadData();
if (_id.HasValue)
{
try
{
var view = _userLogic.ReadElement(new UserSearchModel { Id = _id.Value });
if (view != null)
{
textBoxLogin.Text = view.Email;
textBoxPassword.Text = view.Password;
textBoxUsername.Text = view.Username;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
try
{
var role = _roleLogic.ReadList(null);
if (role != null)
{
comboBoxSelectRole.DisplayMember = "Name";
comboBoxSelectRole.ValueMember = "Id";
comboBoxSelectRole.DataSource = role;
comboBoxSelectRole.SelectedItem = null;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonAddUsers_Click(object sender, EventArgs e)
{
try
{
_userLogic.UserInsertList(1000, _roleLogic.ReadList(null));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -0,0 +1,115 @@
namespace Forum
{
partial class FormUsers
{
/// <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()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreate = new System.Windows.Forms.Button();
this.buttonChange = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 12);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(676, 291);
this.dataGridView.TabIndex = 0;
//
// buttonCreate
//
this.buttonCreate.Location = new System.Drawing.Point(694, 22);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
this.buttonCreate.TabIndex = 1;
this.buttonCreate.Text = "Добавить";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
//
// buttonChange
//
this.buttonChange.Location = new System.Drawing.Point(694, 57);
this.buttonChange.Name = "buttonChange";
this.buttonChange.Size = new System.Drawing.Size(94, 29);
this.buttonChange.TabIndex = 2;
this.buttonChange.Text = "Изменить";
this.buttonChange.UseVisualStyleBackColor = true;
this.buttonChange.Click += new System.EventHandler(this.buttonChange_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(694, 92);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(94, 29);
this.buttonDelete.TabIndex = 3;
this.buttonDelete.Text = "Удалить";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(694, 127);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(94, 29);
this.buttonUpdate.TabIndex = 4;
this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
//
// FormUsers
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 316);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonChange);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.dataGridView);
this.Name = "FormUsers";
this.Text = "Пользователи";
this.Load += new System.EventHandler(this.FormUsers_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonCreate;
private Button buttonChange;
private Button buttonDelete;
private Button buttonUpdate;
}
}

View File

@ -0,0 +1,113 @@
using ForumBusinessLogic;
using ForumContracts.BindingModels;
using ForumContracts.BusinessLogicContracts;
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 Forum
{
public partial class FormUsers : Form
{
private readonly IUserLogic _userLogic;
public FormUsers(IUserLogic userLogic)
{
InitializeComponent();
_userLogic = userLogic;
}
private void FormUsers_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _userLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["RoleId"].Visible = false;
dataGridView.Columns["Username"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Email"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["RoleName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCreate_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormUser));
if (service is FormUser form)
{
form.ShowDialog();
LoadData();
}
}
private void buttonChange_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormUser));
if (service is FormUser form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try
{
if (!_userLogic.Delete(new UserBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении.");
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>

View File

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ForumBusinessLogic\ForumBusinessLogic.csproj" />
<ProjectReference Include="..\ForumContracts\ForumContracts.csproj" />
<ProjectReference Include="..\ForumDatabase\ForumDatabase.csproj" />
<ProjectReference Include="..\ForumDataModels\ForumDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -1,9 +1,11 @@
using BlogContracts using ForumBusinessLogic;
using ForumContracts.BusinessLogicContracts;
using ForumContracts.StoragesContracts;
using BlogDatabase.Implements;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using System;
using NLog.Extensions.Logging;
namespace BlogViewModel namespace Forum
{ {
internal static class Program internal static class Program
{ {
@ -21,26 +23,33 @@ namespace BlogViewModel
var services = new ServiceCollection(); var services = new ServiceCollection();
ConfigureServices(services); ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider(); _serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormMain>()); Application.Run(_serviceProvider.GetRequiredService<FormMain>());
} }
private static void ConfigureServices(ServiceCollection services) private static void ConfigureServices(ServiceCollection services)
{ {
services.AddLogging(option => services.AddTransient<ICategoryStorage, CategoryStorage>();
{ services.AddTransient<IMessageStorage, MessageStorage>();
option.SetMinimumLevel(LogLevel.Information); services.AddTransient<IRoleStorage, RoleStorage>();
option.AddNLog("nlog.config"); services.AddTransient<ITopicStorage, TopicStorage>();
});
services.AddTransient<FormMain>();
services.AddTransient<FormUser>();
services.AddTransient<FormUsers>();
services.AddTransient<IUser, User>();
services.AddTransient<IUserStorage, UserStorage>(); services.AddTransient<IUserStorage, UserStorage>();
services.AddTransient<ICategoryLogic, CategoryLogic>();
services.AddTransient<IMessageLogic, MessageLogic>();
services.AddTransient<IRoleLogic, RoleLogic>();
services.AddTransient<ITopicLogic, TopicLogic>();
services.AddTransient<IUserLogic, UserLogic>(); services.AddTransient<IUserLogic, UserLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormRoles>();
services.AddTransient<FormRole>();
services.AddTransient<FormUsers>();
services.AddTransient<FormUser>();
services.AddTransient<FormCategories>();
services.AddTransient<FormCategory>();
services.AddTransient<FormAddTopics>();
services.AddTransient<FormAddTopic>();
services.AddTransient<FormCreateMessage>();
services.AddTransient<FormTests>();
} }
} }
} }