Compare commits

..

No commits in common. "4234c0c2da2525af113e6195ff3deff835f8f941" and "66960902c923358ea5b7cb5fea961e16ec0fa4dd" have entirely different histories.

4 changed files with 16 additions and 106 deletions

View File

@ -11,7 +11,7 @@ namespace LabWork
public class ContactViewModel
{
public int Id { get; set; }
[DisplayName("Название контакта")]
[DisplayName("Название компонента")]
public string ContactName { get; set; } = string.Empty;
[DisplayName("Цена")]
public double Number { get; set; }

View File

@ -29,7 +29,8 @@ namespace LabWork
{
var view = _logic.ReadElement(new ContactSearchModel
{
Id = _id.Value
Id =
_id.Value
});
if (view != null)
{

View File

@ -28,23 +28,22 @@
/// </summary>
private void InitializeComponent()
{
dataGridView = new DataGridView();
dataGridView1 = new DataGridView();
buttonAdd = new Button();
buttonUpd = new Button();
buttonRef = new Button();
buttonDel = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
SuspendLayout();
//
// dataGridView
// dataGridView1
//
dataGridView.BackgroundColor = Color.LavenderBlush;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 12);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 62;
dataGridView.Size = new Size(717, 426);
dataGridView.TabIndex = 0;
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView1.Location = new Point(12, 12);
dataGridView1.Name = "dataGridView1";
dataGridView1.RowHeadersWidth = 62;
dataGridView1.Size = new Size(717, 426);
dataGridView1.TabIndex = 0;
//
// buttonAdd
//
@ -64,7 +63,6 @@
buttonUpd.TabIndex = 2;
buttonUpd.Text = "Изменить";
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += buttonUpd_Click;
//
// buttonRef
//
@ -74,7 +72,6 @@
buttonRef.TabIndex = 3;
buttonRef.Text = "Обновить";
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += buttonRef_Click;
//
// buttonDel
//
@ -84,7 +81,6 @@
buttonDel.TabIndex = 4;
buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += buttonDel_Click;
//
// FormContacts
//
@ -95,17 +91,16 @@
Controls.Add(buttonRef);
Controls.Add(buttonUpd);
Controls.Add(buttonAdd);
Controls.Add(dataGridView);
Controls.Add(dataGridView1);
Name = "FormContacts";
Text = "Менеджер контактов";
Load += FormContacts_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private DataGridView dataGridView1;
private Button buttonAdd;
private Button buttonUpd;
private Button buttonRef;

View File

@ -7,105 +7,19 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LabWork.Interfaces;
namespace LabWork
{
public partial class FormContacts : Form
{
private readonly IContactLogic _logic;
public FormContacts(IContactLogic logic)
public FormContacts()
{
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 buttonRef_Click(object sender, EventArgs e)
{
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);
}
}
}
}
}
}