некоторые изменения в формах дохода и расхода

This commit is contained in:
xom9kxom9k 2024-11-10 10:53:31 +04:00
parent 19350de2a8
commit d0d699915e
10 changed files with 90 additions and 54 deletions

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks;
namespace ProjectFamilyBudget.Entities.Enums;
[Flags]
public enum IncomeExpenseType
{
None = 0,

View File

@ -26,5 +26,4 @@ public class People
MemberType = memberType
};
}
}

View File

@ -35,7 +35,7 @@
buttonCansel = new Button();
textBoxCategory = new TextBox();
label1 = new Label();
comboBoxExpenseType = new ComboBox();
checkedListBoxType = new CheckedListBox();
SuspendLayout();
//
// label5
@ -57,7 +57,7 @@
// label3
//
label3.AutoSize = true;
label3.Location = new Point(19, 147);
label3.Location = new Point(19, 196);
label3.Name = "label3";
label3.Size = new Size(63, 15);
label3.TabIndex = 16;
@ -65,7 +65,7 @@
//
// buttonSave
//
buttonSave.Location = new Point(12, 223);
buttonSave.Location = new Point(12, 254);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(102, 41);
buttonSave.TabIndex = 18;
@ -75,7 +75,7 @@
//
// buttonCansel
//
buttonCansel.Location = new Point(192, 223);
buttonCansel.Location = new Point(192, 254);
buttonCansel.Name = "buttonCansel";
buttonCansel.Size = new Size(97, 41);
buttonCansel.TabIndex = 19;
@ -85,7 +85,7 @@
//
// textBoxCategory
//
textBoxCategory.Location = new Point(101, 144);
textBoxCategory.Location = new Point(101, 193);
textBoxCategory.Name = "textBoxCategory";
textBoxCategory.Size = new Size(188, 23);
textBoxCategory.TabIndex = 20;
@ -99,21 +99,20 @@
label1.TabIndex = 21;
label1.Text = "Тип расхода";
//
// comboBoxExpenseType
// checkedListBoxType
//
comboBoxExpenseType.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxExpenseType.FormattingEnabled = true;
comboBoxExpenseType.Location = new Point(101, 85);
comboBoxExpenseType.Name = "comboBoxExpenseType";
comboBoxExpenseType.Size = new Size(188, 23);
comboBoxExpenseType.TabIndex = 22;
checkedListBoxType.FormattingEnabled = true;
checkedListBoxType.Location = new Point(101, 88);
checkedListBoxType.Name = "checkedListBoxType";
checkedListBoxType.Size = new Size(188, 58);
checkedListBoxType.TabIndex = 22;
//
// FormExpense
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(301, 281);
Controls.Add(comboBoxExpenseType);
ClientSize = new Size(301, 307);
Controls.Add(checkedListBoxType);
Controls.Add(label1);
Controls.Add(textBoxCategory);
Controls.Add(buttonCansel);
@ -137,6 +136,6 @@
private Button buttonCansel;
private TextBox textBoxCategory;
private Label label1;
private ComboBox comboBoxExpenseType;
private CheckedListBox checkedListBoxType;
}
}

View File

@ -10,6 +10,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Unity;
namespace ProjectFamilyBudget.Forms
{
@ -28,8 +29,15 @@ namespace ProjectFamilyBudget.Forms
{
throw new InvalidDataException(nameof(expense));
}
foreach (IncomeExpenseType elem in Enum.GetValues(typeof(IncomeExpenseType)))
{
if ((elem & expense.ExpenseType) != 0)
{
checkedListBoxType.SetItemChecked(checkedListBoxType.Items.IndexOf(
elem), true);
}
}
textBoxName.Text = expense.Name;
comboBoxExpenseType.SelectedItem = expense.ExpenseType;
textBoxCategory.Text = expense.ExpenseCategory;
_expenseId = value;
@ -46,7 +54,10 @@ namespace ProjectFamilyBudget.Forms
InitializeComponent();
_expense = expense ??
throw new ArgumentNullException(nameof(expense));
comboBoxExpenseType.DataSource = Enum.GetValues(typeof(IncomeExpenseType));
foreach (var elem in Enum.GetValues(typeof(IncomeExpenseType)))
{
checkedListBoxType.Items.Add(elem);
}
}
private void buttonSave_Click(object sender, EventArgs e)
@ -55,7 +66,7 @@ namespace ProjectFamilyBudget.Forms
{
if (string.IsNullOrWhiteSpace(textBoxName.Text)
||
string.IsNullOrWhiteSpace(textBoxCategory.Text) || (comboBoxExpenseType.SelectedIndex < 0))
string.IsNullOrWhiteSpace(textBoxCategory.Text) || checkedListBoxType.CheckedItems.Count == 0)
{
throw new Exception("Имеются незаполненные поля");
}
@ -77,7 +88,14 @@ namespace ProjectFamilyBudget.Forms
}
private void buttonCansel_Click(object sender, EventArgs e) => Close();
private Expense CreateExpense(int id) => Expense.CreateEntity(id, (IncomeExpenseType)comboBoxExpenseType.SelectedItem!
, textBoxName.Text, textBoxCategory.Text);
private Expense CreateExpense(int id)
{
IncomeExpenseType expenseType = IncomeExpenseType.None;
foreach (var elem in checkedListBoxType.CheckedItems)
{
expenseType |= (IncomeExpenseType)elem;
}
return Expense.CreateEntity(id, expenseType, textBoxName.Text, textBoxCategory.Text);
}
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter

View File

@ -36,13 +36,13 @@
textBoxName = new TextBox();
textBoxCategory = new TextBox();
label1 = new Label();
comboBoxIncomeType = new ComboBox();
checkedListBoxType = new CheckedListBox();
SuspendLayout();
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(3, 149);
label3.Location = new Point(12, 189);
label3.Name = "label3";
label3.Size = new Size(63, 15);
label3.TabIndex = 2;
@ -50,7 +50,7 @@
//
// buttonSave
//
buttonSave.Location = new Point(7, 222);
buttonSave.Location = new Point(12, 251);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(102, 41);
buttonSave.TabIndex = 6;
@ -60,7 +60,7 @@
//
// buttonCansel
//
buttonCansel.Location = new Point(191, 222);
buttonCansel.Location = new Point(191, 251);
buttonCansel.Name = "buttonCansel";
buttonCansel.Size = new Size(97, 41);
buttonCansel.TabIndex = 7;
@ -95,7 +95,7 @@
//
// textBoxCategory
//
textBoxCategory.Location = new Point(101, 146);
textBoxCategory.Location = new Point(101, 186);
textBoxCategory.Name = "textBoxCategory";
textBoxCategory.Size = new Size(187, 23);
textBoxCategory.TabIndex = 11;
@ -103,27 +103,26 @@
// label1
//
label1.AutoSize = true;
label1.Location = new Point(-2, 85);
label1.Location = new Point(7, 85);
label1.Name = "label1";
label1.Size = new Size(68, 15);
label1.TabIndex = 12;
label1.Text = "Тип дохода";
//
// comboBoxIncomeType
// checkedListBoxType
//
comboBoxIncomeType.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxIncomeType.FormattingEnabled = true;
comboBoxIncomeType.Location = new Point(101, 82);
comboBoxIncomeType.Name = "comboBoxIncomeType";
comboBoxIncomeType.Size = new Size(187, 23);
comboBoxIncomeType.TabIndex = 13;
checkedListBoxType.FormattingEnabled = true;
checkedListBoxType.Location = new Point(101, 85);
checkedListBoxType.Name = "checkedListBoxType";
checkedListBoxType.Size = new Size(187, 58);
checkedListBoxType.TabIndex = 13;
//
// FormIncome
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(300, 286);
Controls.Add(comboBoxIncomeType);
ClientSize = new Size(300, 308);
Controls.Add(checkedListBoxType);
Controls.Add(label1);
Controls.Add(textBoxCategory);
Controls.Add(textBoxName);
@ -148,6 +147,6 @@
private TextBox textBoxName;
private TextBox textBoxCategory;
private Label label1;
private ComboBox comboBoxIncomeType;
private CheckedListBox checkedListBoxType;
}
}

View File

@ -1,4 +1,5 @@
using ProjectFamilyBudget.Entities;
using Microsoft.VisualBasic.FileIO;
using ProjectFamilyBudget.Entities;
using ProjectFamilyBudget.Entities.Enums;
using ProjectFamilyBudget.Repositories;
using System;
@ -28,8 +29,15 @@ namespace ProjectFamilyBudget.Forms
{
throw new InvalidDataException(nameof(income));
}
foreach (IncomeExpenseType elem in Enum.GetValues(typeof(IncomeExpenseType)))
{
if ((elem & income.IncomeType) != 0)
{
checkedListBoxType.SetItemChecked(checkedListBoxType.Items.IndexOf(
elem), true);
}
}
textBoxName.Text = income.Name;
comboBoxIncomeType.SelectedItem = income.IncomeType;
textBoxCategory.Text = income.IncomeCategory;
_incomeId = value;
@ -46,7 +54,11 @@ namespace ProjectFamilyBudget.Forms
InitializeComponent();
_income = income ??
throw new ArgumentNullException(nameof(income));
comboBoxIncomeType.DataSource = Enum.GetValues(typeof(IncomeExpenseType));
foreach (var elem in Enum.GetValues(typeof(IncomeExpenseType)))
{
checkedListBoxType.Items.Add(elem);
}
}
private void buttonSave_Click(object sender, EventArgs e)
@ -55,7 +67,7 @@ namespace ProjectFamilyBudget.Forms
{
if (string.IsNullOrWhiteSpace(textBoxName.Text)
||
string.IsNullOrWhiteSpace(textBoxCategory.Text) || (comboBoxIncomeType.SelectedIndex < 0))
string.IsNullOrWhiteSpace(textBoxCategory.Text) || checkedListBoxType.CheckedItems.Count == 0)
{
throw new Exception("Имеются незаполненные поля");
}
@ -78,7 +90,14 @@ namespace ProjectFamilyBudget.Forms
}
private void buttonCansel_Click(object sender, EventArgs e) => Close();
private Income CreateIncome(int id) => Income.CreateEntity(id, (IncomeExpenseType)comboBoxIncomeType.SelectedItem!
,textBoxName.Text, textBoxCategory.Text);
private Income CreateIncome(int id)
{
IncomeExpenseType incomeType = IncomeExpenseType.None;
foreach (var elem in checkedListBoxType.CheckedItems)
{
incomeType |= (IncomeExpenseType)elem;
}
return Income.CreateEntity(id, incomeType, textBoxName.Text, textBoxCategory.Text);
}
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter

View File

@ -73,9 +73,9 @@
//
groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
groupBox.Controls.Add(dataGridView);
groupBox.Location = new Point(15, 102);
groupBox.Location = new Point(15, 105);
groupBox.Name = "groupBox";
groupBox.Size = new Size(334, 332);
groupBox.Size = new Size(334, 335);
groupBox.TabIndex = 3;
groupBox.TabStop = false;
groupBox.Text = "Доходы";
@ -92,7 +92,7 @@
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersVisible = false;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(328, 310);
dataGridView.Size = new Size(328, 313);
dataGridView.TabIndex = 0;
//
// ColumnIncome
@ -109,6 +109,7 @@
//
// buttonSave
//
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonSave.Location = new Point(18, 455);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(101, 34);
@ -119,6 +120,7 @@
//
// buttonCansel
//
buttonCansel.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCansel.Location = new Point(243, 455);
buttonCansel.Name = "buttonCansel";
buttonCansel.Size = new Size(103, 34);
@ -148,7 +150,7 @@
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(368, 501);
ClientSize = new Size(368, 507);
Controls.Add(label3);
Controls.Add(dateTimePicker);
Controls.Add(buttonCansel);

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@ -48,7 +48,7 @@
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter