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 class ContactViewModel
{ {
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Название контакта")] [DisplayName("Название компонента")]
public string ContactName { get; set; } = string.Empty; public string ContactName { get; set; } = string.Empty;
[DisplayName("Цена")] [DisplayName("Цена")]
public double Number { get; set; } public double Number { get; set; }

View File

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

View File

@ -28,23 +28,22 @@
/// </summary> /// </summary>
private void InitializeComponent() 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, 12); dataGridView1.Name = "dataGridView1";
dataGridView.Name = "dataGridView"; dataGridView1.RowHeadersWidth = 62;
dataGridView.RowHeadersWidth = 62; dataGridView1.Size = new Size(717, 426);
dataGridView.Size = new Size(717, 426); dataGridView1.TabIndex = 0;
dataGridView.TabIndex = 0;
// //
// buttonAdd // buttonAdd
// //
@ -64,7 +63,6 @@
buttonUpd.TabIndex = 2; buttonUpd.TabIndex = 2;
buttonUpd.Text = "Изменить"; buttonUpd.Text = "Изменить";
buttonUpd.UseVisualStyleBackColor = true; buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += buttonUpd_Click;
// //
// buttonRef // buttonRef
// //
@ -74,7 +72,6 @@
buttonRef.TabIndex = 3; buttonRef.TabIndex = 3;
buttonRef.Text = "Обновить"; buttonRef.Text = "Обновить";
buttonRef.UseVisualStyleBackColor = true; buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += buttonRef_Click;
// //
// buttonDel // buttonDel
// //
@ -84,7 +81,6 @@
buttonDel.TabIndex = 4; buttonDel.TabIndex = 4;
buttonDel.Text = "Удалить"; buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true; buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += buttonDel_Click;
// //
// FormContacts // FormContacts
// //
@ -95,17 +91,16 @@
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 = "Менеджер контактов";
Load += FormContacts_Load; ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
((System.ComponentModel.ISupportInitialize)dataGridView).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;

View File

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