+ форма (заново)
This commit is contained in:
parent
fe8462c3f0
commit
66960902c9
63
LabWork/LabWork/FormContacts.Designer.cs
generated
63
LabWork/LabWork/FormContacts.Designer.cs
generated
@ -3,19 +3,19 @@
|
|||||||
partial class FormContacts
|
partial class FormContacts
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private System.ComponentModel.IContainer Contacts = null;
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clean up any resources being used.
|
/// Clean up any resources being used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing && (Contacts != null))
|
if (disposing && (components != null))
|
||||||
{
|
{
|
||||||
Contacts.Dispose();
|
components.Dispose();
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@ -23,61 +23,61 @@
|
|||||||
#region Windows Form Designer generated code
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
/// the contents of this method with the code editor.
|
/// the contents of this method with the code editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeContact()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
dataGridView = new DataGridView();
|
dataGridView1 = new DataGridView();
|
||||||
buttonAdd = new Button();
|
buttonAdd = new Button();
|
||||||
buttonUpd = new Button();
|
buttonUpd = new Button();
|
||||||
buttonRef = new Button();
|
buttonRef = new Button();
|
||||||
buttonDel = new Button();
|
buttonDel = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// dataGridView
|
// dataGridView1
|
||||||
//
|
//
|
||||||
dataGridView.BackgroundColor = Color.LavenderBlush;
|
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView1.Location = new Point(12, 12);
|
||||||
dataGridView.Location = new Point(12, 90);
|
dataGridView1.Name = "dataGridView1";
|
||||||
dataGridView.Name = "dataGridView";
|
dataGridView1.RowHeadersWidth = 62;
|
||||||
dataGridView.RowHeadersWidth = 62;
|
dataGridView1.Size = new Size(717, 426);
|
||||||
dataGridView.Size = new Size(789, 453);
|
dataGridView1.TabIndex = 0;
|
||||||
dataGridView.TabIndex = 0;
|
|
||||||
//
|
//
|
||||||
// buttonAdd
|
// buttonAdd
|
||||||
//
|
//
|
||||||
buttonAdd.Location = new Point(831, 113);
|
buttonAdd.Location = new Point(797, 94);
|
||||||
buttonAdd.Name = "buttonAdd";
|
buttonAdd.Name = "buttonAdd";
|
||||||
buttonAdd.Size = new Size(163, 64);
|
buttonAdd.Size = new Size(112, 34);
|
||||||
buttonAdd.TabIndex = 1;
|
buttonAdd.TabIndex = 1;
|
||||||
buttonAdd.Text = "Добавить";
|
buttonAdd.Text = "Добавить";
|
||||||
buttonAdd.UseVisualStyleBackColor = true;
|
buttonAdd.UseVisualStyleBackColor = true;
|
||||||
|
buttonAdd.Click += buttonAdd_Click;
|
||||||
//
|
//
|
||||||
// buttonUpd
|
// buttonUpd
|
||||||
//
|
//
|
||||||
buttonUpd.Location = new Point(831, 200);
|
buttonUpd.Location = new Point(797, 157);
|
||||||
buttonUpd.Name = "buttonUpd";
|
buttonUpd.Name = "buttonUpd";
|
||||||
buttonUpd.Size = new Size(163, 64);
|
buttonUpd.Size = new Size(112, 34);
|
||||||
buttonUpd.TabIndex = 2;
|
buttonUpd.TabIndex = 2;
|
||||||
buttonUpd.Text = "Изменить";
|
buttonUpd.Text = "Изменить";
|
||||||
buttonUpd.UseVisualStyleBackColor = true;
|
buttonUpd.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// buttonRef
|
// buttonRef
|
||||||
//
|
//
|
||||||
buttonRef.Location = new Point(831, 286);
|
buttonRef.Location = new Point(797, 223);
|
||||||
buttonRef.Name = "buttonRef";
|
buttonRef.Name = "buttonRef";
|
||||||
buttonRef.Size = new Size(163, 64);
|
buttonRef.Size = new Size(112, 34);
|
||||||
buttonRef.TabIndex = 3;
|
buttonRef.TabIndex = 3;
|
||||||
buttonRef.Text = "Обновить";
|
buttonRef.Text = "Обновить";
|
||||||
buttonRef.UseVisualStyleBackColor = true;
|
buttonRef.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// buttonDel
|
// buttonDel
|
||||||
//
|
//
|
||||||
buttonDel.Location = new Point(831, 375);
|
buttonDel.Location = new Point(797, 284);
|
||||||
buttonDel.Name = "buttonDel";
|
buttonDel.Name = "buttonDel";
|
||||||
buttonDel.Size = new Size(163, 64);
|
buttonDel.Size = new Size(112, 34);
|
||||||
buttonDel.TabIndex = 4;
|
buttonDel.TabIndex = 4;
|
||||||
buttonDel.Text = "Удалить";
|
buttonDel.Text = "Удалить";
|
||||||
buttonDel.UseVisualStyleBackColor = true;
|
buttonDel.UseVisualStyleBackColor = true;
|
||||||
@ -86,25 +86,24 @@
|
|||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
BackColor = SystemColors.ActiveCaption;
|
ClientSize = new Size(965, 450);
|
||||||
ClientSize = new Size(1019, 555);
|
|
||||||
Controls.Add(buttonDel);
|
Controls.Add(buttonDel);
|
||||||
Controls.Add(buttonRef);
|
Controls.Add(buttonRef);
|
||||||
Controls.Add(buttonUpd);
|
Controls.Add(buttonUpd);
|
||||||
Controls.Add(buttonAdd);
|
Controls.Add(buttonAdd);
|
||||||
Controls.Add(dataGridView);
|
Controls.Add(dataGridView1);
|
||||||
Name = "FormContacts";
|
Name = "FormContacts";
|
||||||
Text = "Менеджер контактов";
|
Text = "Менеджер контактов";
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private DataGridView dataGridView;
|
private DataGridView dataGridView1;
|
||||||
private Button buttonAdd;
|
private Button buttonAdd;
|
||||||
private Button buttonUpd;
|
private Button buttonUpd;
|
||||||
private Button buttonRef;
|
private Button buttonRef;
|
||||||
private Button buttonDel;
|
private Button buttonDel;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,109 +1,25 @@
|
|||||||
using LabWork.Interfaces;
|
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 LabWork
|
namespace LabWork
|
||||||
{
|
{
|
||||||
public partial class FormContacts : Form
|
public partial class FormContacts : Form
|
||||||
{
|
{
|
||||||
private readonly IContactLogic _logic;
|
public FormContacts()
|
||||||
public FormContacts(IContactLogic logic)
|
|
||||||
{
|
{
|
||||||
InitializeContact();
|
InitializeComponent();
|
||||||
_logic = logic;
|
|
||||||
}
|
|
||||||
private void FormContacts_Load(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
LoadData();
|
|
||||||
}
|
|
||||||
private void LoadData()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var list = _logic.ReadList(null);
|
|
||||||
if (list != null)
|
|
||||||
{
|
|
||||||
dataGridView.DataSource = list;
|
|
||||||
dataGridView.Columns["Id"].Visible = false;
|
|
||||||
dataGridView.Columns["ContactName"].AutoSizeMode =
|
|
||||||
DataGridViewAutoSizeColumnMode.Fill;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
|
||||||
MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
var service =
|
|
||||||
Program.ServiceProvider?.GetService(typeof(FormContact));
|
|
||||||
if (service is FormContact form)
|
|
||||||
{
|
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
LoadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ButtonUpd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
|
||||||
{
|
|
||||||
var service =
|
|
||||||
Program.ServiceProvider?.GetService(typeof(FormContact));
|
|
||||||
if (service is FormContact form)
|
|
||||||
{
|
|
||||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
LoadData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ButtonDel_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 (!_logic.Delete(new ContactBindingModel
|
|
||||||
{
|
|
||||||
Id = id
|
|
||||||
}))
|
|
||||||
{
|
|
||||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
|
||||||
}
|
|
||||||
LoadData();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка",
|
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ButtonRef_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
LoadData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeComponent()
|
private void buttonAdd_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// FormContacts
|
|
||||||
//
|
|
||||||
ClientSize = new Size(278, 244);
|
|
||||||
Name = "FormContacts";
|
|
||||||
Load += FormContacts_Load;
|
|
||||||
ResumeLayout(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace LabWork
|
|||||||
{
|
{
|
||||||
services.AddTransient<IContactStorage, ContactStorage>();
|
services.AddTransient<IContactStorage, ContactStorage>();
|
||||||
services.AddTransient<IContactLogic, ContactLogic>();
|
services.AddTransient<IContactLogic, ContactLogic>();
|
||||||
//services.AddTransient<FormContact>();
|
services.AddTransient<FormContact>();
|
||||||
services.AddTransient<FormContacts>();
|
services.AddTransient<FormContacts>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user