diff --git a/1202.cs b/1202.cs new file mode 100644 index 0000000..ecb4ad1 --- /dev/null +++ b/1202.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace samusev_42 +{ + public partial class Product + { + [NotMapped] + public string CountUnit + { + /// Объединение колонок "Количечество и Штук", чтобы выглядело красиво + get { return Count + " " + Unit.ToString(); } + } + } +} diff --git a/AuthForm.Designer.cs b/AuthForm.Designer.cs new file mode 100644 index 0000000..eabc386 --- /dev/null +++ b/AuthForm.Designer.cs @@ -0,0 +1,111 @@ +namespace samusev_42 +{ + partial class AuthForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + textBoxLogin = new TextBox(); + textBoxPassword = new TextBox(); + buttonLogin = new Button(); + label1 = new Label(); + label2 = new Label(); + SuspendLayout(); + // + // textBoxLogin + // + textBoxLogin.Font = new Font("Segoe UI Semibold", 14.25F, FontStyle.Bold); + textBoxLogin.Location = new Point(28, 66); + textBoxLogin.Name = "textBoxLogin"; + textBoxLogin.Size = new Size(230, 33); + textBoxLogin.TabIndex = 0; + // + // textBoxPassword + // + textBoxPassword.Font = new Font("Segoe UI Semibold", 14.25F, FontStyle.Bold); + textBoxPassword.Location = new Point(28, 165); + textBoxPassword.Name = "textBoxPassword"; + textBoxPassword.Size = new Size(230, 33); + textBoxPassword.TabIndex = 1; + // + // buttonLogin + // + buttonLogin.BackColor = Color.MistyRose; + buttonLogin.Font = new Font("Segoe UI Semibold", 14.25F, FontStyle.Bold); + buttonLogin.Location = new Point(75, 233); + buttonLogin.Name = "buttonLogin"; + buttonLogin.Size = new Size(148, 42); + buttonLogin.TabIndex = 2; + buttonLogin.Text = "Войти"; + buttonLogin.UseVisualStyleBackColor = false; + buttonLogin.Click += buttonLogin_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Font = new Font("Segoe UI Semibold", 14.25F, FontStyle.Bold); + label1.Location = new Point(111, 28); + label1.Name = "label1"; + label1.Size = new Size(71, 25); + label1.TabIndex = 3; + label1.Text = "Логин:"; + // + // label2 + // + label2.AutoSize = true; + label2.Font = new Font("Segoe UI Semibold", 14.25F, FontStyle.Bold); + label2.Location = new Point(98, 128); + label2.Name = "label2"; + label2.Size = new Size(84, 25); + label2.TabIndex = 4; + label2.Text = "Пароль:"; + // + // AuthForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + BackColor = Color.PeachPuff; + ClientSize = new Size(286, 308); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonLogin); + Controls.Add(textBoxPassword); + Controls.Add(textBoxLogin); + Name = "AuthForm"; + Text = "AuthForm"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxLogin; + private TextBox textBoxPassword; + private Button buttonLogin; + private Label label1; + private Label label2; + } +} \ No newline at end of file diff --git a/AuthForm.cs b/AuthForm.cs new file mode 100644 index 0000000..58bc560 --- /dev/null +++ b/AuthForm.cs @@ -0,0 +1,65 @@ +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 samusev_42 +{ + public partial class AuthForm : Form + { + Ispr2522SamusevOvLazarev2Context context = new Ispr2522SamusevOvLazarev2Context(); + + public AuthForm() + { + InitializeComponent(); + } + + private void buttonLogin_Click(object sender, EventArgs e) + { + try + { + string inputLogin = textBoxLogin.Text.Trim(); + string inputPassword = textBoxPassword.Text.Trim(); + + + if (string.IsNullOrEmpty(inputLogin) || string.IsNullOrEmpty(inputPassword)) + { + MessageBox.Show("Введите логин и пароль!", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + + + var user = context.Users.FirstOrDefault(x => x.Login == inputLogin && x.Password == inputPassword); + + if (user != null) + { + + this.Hide(); + + Form1 mainForm = new Form1(); + mainForm.ShowDialog(); + + + this.Close(); + } + else + { + + MessageBox.Show("Пользователь не найден! Проверьте правильность данных.", + "Ошибка авторизации", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + catch (Exception ex) + { + + MessageBox.Show($"Ошибка подключения: {ex.Message}", "Критическая ошибка"); + } + } + } +} + diff --git a/AuthForm.resx b/AuthForm.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/AuthForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Category.cs b/Category.cs new file mode 100644 index 0000000..c627845 --- /dev/null +++ b/Category.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace samusev_42; + +public partial class Category +{ + public int IdCategory { get; set; } + + public string CategoryName { get; set; } = null!; + + public virtual ICollection Products { get; set; } = new List(); +} diff --git a/Delivery.cs b/Delivery.cs new file mode 100644 index 0000000..e204610 --- /dev/null +++ b/Delivery.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; + +namespace samusev_42; + +public partial class Delivery +{ + public int IdDelivery { get; set; } + + public DateTime DateOrder { get; set; } + + public DateTime DateDelivery { get; set; } + + public int IdPickUpPoint { get; set; } + + public int IdUser { get; set; } + + public int Code { get; set; } + + public int IdStatus { get; set; } + + public virtual PickUpPoint IdPickUpPointNavigation { get; set; } = null!; + + public virtual Status IdStatusNavigation { get; set; } = null!; + + public virtual User IdUserNavigation { get; set; } = null!; + + public virtual ICollection OrdersProducts { get; set; } = new List(); +} diff --git a/EditForm.Designer.cs b/EditForm.Designer.cs new file mode 100644 index 0000000..dde5efe --- /dev/null +++ b/EditForm.Designer.cs @@ -0,0 +1,343 @@ +namespace samusev_42 +{ + partial class EditForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + productBindingSource = new BindingSource(components); + textBox2 = new TextBox(); + textBox4 = new TextBox(); + textBox5 = new TextBox(); + textBox8 = new TextBox(); + textBox10 = new TextBox(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + label5 = new Label(); + label6 = new Label(); + label7 = new Label(); + label8 = new Label(); + label9 = new Label(); + label10 = new Label(); + comboBox1 = new ComboBox(); + productNameBindingSource = new BindingSource(components); + comboBox2 = new ComboBox(); + supplierBindingSource = new BindingSource(components); + comboBox3 = new ComboBox(); + manufacturerBindingSource = new BindingSource(components); + comboBox4 = new ComboBox(); + categoryBindingSource = new BindingSource(components); + SaveEditButton = new Button(); + ((System.ComponentModel.ISupportInitialize)productBindingSource).BeginInit(); + ((System.ComponentModel.ISupportInitialize)productNameBindingSource).BeginInit(); + ((System.ComponentModel.ISupportInitialize)supplierBindingSource).BeginInit(); + ((System.ComponentModel.ISupportInitialize)manufacturerBindingSource).BeginInit(); + ((System.ComponentModel.ISupportInitialize)categoryBindingSource).BeginInit(); + SuspendLayout(); + // + // productBindingSource + // + productBindingSource.DataSource = typeof(Product); + // + // textBox2 + // + textBox2.DataBindings.Add(new Binding("DataContext", productBindingSource, "Article", true)); + textBox2.DataBindings.Add(new Binding("Text", productBindingSource, "Article", true, DataSourceUpdateMode.OnPropertyChanged)); + textBox2.Location = new Point(152, 32); + textBox2.Name = "textBox2"; + textBox2.Size = new Size(148, 23); + textBox2.TabIndex = 1; + // + // textBox4 + // + textBox4.DataBindings.Add(new Binding("DataContext", productBindingSource, "Count", true)); + textBox4.DataBindings.Add(new Binding("Text", productBindingSource, "Count", true, DataSourceUpdateMode.OnPropertyChanged)); + textBox4.Location = new Point(152, 119); + textBox4.Name = "textBox4"; + textBox4.Size = new Size(148, 23); + textBox4.TabIndex = 3; + // + // textBox5 + // + textBox5.DataBindings.Add(new Binding("DataContext", productBindingSource, "Price", true)); + textBox5.DataBindings.Add(new Binding("Text", productBindingSource, "Price", true, DataSourceUpdateMode.OnPropertyChanged)); + textBox5.Location = new Point(152, 162); + textBox5.Name = "textBox5"; + textBox5.Size = new Size(148, 23); + textBox5.TabIndex = 4; + // + // textBox8 + // + textBox8.DataBindings.Add(new Binding("DataContext", productBindingSource, "Discount", true)); + textBox8.DataBindings.Add(new Binding("Text", productBindingSource, "Discount", true, DataSourceUpdateMode.OnPropertyChanged)); + textBox8.Location = new Point(152, 300); + textBox8.Name = "textBox8"; + textBox8.Size = new Size(148, 23); + textBox8.TabIndex = 7; + // + // textBox10 + // + textBox10.DataBindings.Add(new Binding("DataContext", productBindingSource, "Description", true)); + textBox10.DataBindings.Add(new Binding("Text", productBindingSource, "Description", true, DataSourceUpdateMode.OnPropertyChanged)); + textBox10.Location = new Point(152, 389); + textBox10.Name = "textBox10"; + textBox10.Size = new Size(148, 23); + textBox10.TabIndex = 9; + // + // label2 + // + label2.AutoSize = true; + label2.Font = new Font("Segoe UI Black", 11.25F, FontStyle.Bold); + label2.Location = new Point(44, 32); + label2.Name = "label2"; + label2.Size = new Size(80, 20); + label2.TabIndex = 12; + label2.Text = "Артикул:"; + // + // label3 + // + label3.AutoSize = true; + label3.Font = new Font("Segoe UI Black", 11.25F, FontStyle.Bold); + label3.Location = new Point(41, 75); + label3.Name = "label3"; + label3.Size = new Size(86, 20); + label3.TabIndex = 13; + label3.Text = "Название:"; + // + // label4 + // + label4.AutoSize = true; + label4.Font = new Font("Segoe UI Black", 11.25F, FontStyle.Bold); + label4.Location = new Point(50, 118); + label4.Name = "label4"; + label4.Size = new Size(69, 20); + label4.TabIndex = 14; + label4.Text = "Кол-во\u001e:"; + // + // label5 + // + label5.AutoSize = true; + label5.Font = new Font("Segoe UI Black", 11.25F, FontStyle.Bold); + label5.Location = new Point(50, 161); + label5.Name = "label5"; + label5.Size = new Size(52, 20); + label5.TabIndex = 15; + label5.Text = "Цена:"; + // + // label6 + // + label6.AutoSize = true; + label6.Font = new Font("Segoe UI Black", 11.25F, FontStyle.Bold); + label6.Location = new Point(38, 211); + label6.Name = "label6"; + label6.Size = new Size(100, 20); + label6.TabIndex = 16; + label6.Text = "Поставщик:"; + // + // label7 + // + label7.AutoSize = true; + label7.Font = new Font("Segoe UI Black", 11.25F, FontStyle.Bold); + label7.Location = new Point(12, 252); + label7.Name = "label7"; + label7.Size = new Size(137, 20); + label7.TabIndex = 17; + label7.Text = "Производитель:"; + label7.Click += label7_Click; + // + // label8 + // + label8.AutoSize = true; + label8.Font = new Font("Segoe UI Black", 11.25F, FontStyle.Bold); + label8.Location = new Point(41, 300); + label8.Name = "label8"; + label8.Size = new Size(69, 20); + label8.TabIndex = 18; + label8.Text = "Скидка:"; + // + // label9 + // + label9.AutoSize = true; + label9.Font = new Font("Segoe UI Black", 11.25F, FontStyle.Bold); + label9.Location = new Point(31, 348); + label9.Name = "label9"; + label9.Size = new Size(92, 20); + label9.TabIndex = 19; + label9.Text = "Категория:"; + // + // label10 + // + label10.AutoSize = true; + label10.Font = new Font("Segoe UI Black", 11.25F, FontStyle.Bold); + label10.Location = new Point(37, 389); + label10.Name = "label10"; + label10.Size = new Size(86, 20); + label10.TabIndex = 20; + label10.Text = "Описание:"; + // + // comboBox1 + // + comboBox1.DataBindings.Add(new Binding("SelectedValue", productBindingSource, "IdProductName", true, DataSourceUpdateMode.OnPropertyChanged)); + comboBox1.DataSource = productNameBindingSource; + comboBox1.DisplayMember = "ProductName1"; + comboBox1.FormattingEnabled = true; + comboBox1.Location = new Point(152, 75); + comboBox1.Name = "comboBox1"; + comboBox1.Size = new Size(148, 23); + comboBox1.TabIndex = 23; + comboBox1.ValueMember = "IdProductName"; + // + // productNameBindingSource + // + productNameBindingSource.DataSource = typeof(ProductName); + // + // comboBox2 + // + comboBox2.DataBindings.Add(new Binding("SelectedValue", productBindingSource, "IdSupplier", true)); + comboBox2.DataSource = supplierBindingSource; + comboBox2.DisplayMember = "SupplierName"; + comboBox2.FormattingEnabled = true; + comboBox2.Location = new Point(152, 208); + comboBox2.Name = "comboBox2"; + comboBox2.Size = new Size(148, 23); + comboBox2.TabIndex = 24; + comboBox2.ValueMember = "IdSupplier"; + // + // supplierBindingSource + // + supplierBindingSource.DataSource = typeof(Supplier); + // + // comboBox3 + // + comboBox3.DataBindings.Add(new Binding("SelectedValue", productBindingSource, "IdManufacturer", true)); + comboBox3.DataSource = manufacturerBindingSource; + comboBox3.DisplayMember = "ManufacturerName"; + comboBox3.FormattingEnabled = true; + comboBox3.Location = new Point(152, 252); + comboBox3.Name = "comboBox3"; + comboBox3.Size = new Size(148, 23); + comboBox3.TabIndex = 25; + comboBox3.ValueMember = "IdManufacturer"; + // + // manufacturerBindingSource + // + manufacturerBindingSource.DataSource = typeof(Manufacturer); + // + // comboBox4 + // + comboBox4.DataBindings.Add(new Binding("SelectedValue", productBindingSource, "IdCategory", true)); + comboBox4.DataSource = categoryBindingSource; + comboBox4.DisplayMember = "CategoryName"; + comboBox4.FormattingEnabled = true; + comboBox4.Location = new Point(152, 345); + comboBox4.Name = "comboBox4"; + comboBox4.Size = new Size(148, 23); + comboBox4.TabIndex = 26; + comboBox4.ValueMember = "IdCategory"; + // + // categoryBindingSource + // + categoryBindingSource.DataSource = typeof(Category); + // + // SaveEditButton + // + SaveEditButton.BackColor = Color.MistyRose; + SaveEditButton.DialogResult = DialogResult.OK; + SaveEditButton.Font = new Font("Segoe UI Black", 14.25F, FontStyle.Bold, GraphicsUnit.Point, 204); + SaveEditButton.Location = new Point(85, 445); + SaveEditButton.Name = "SaveEditButton"; + SaveEditButton.Size = new Size(160, 46); + SaveEditButton.TabIndex = 27; + SaveEditButton.Text = "Сохранить"; + SaveEditButton.UseVisualStyleBackColor = false; + SaveEditButton.Click += SaveEditButton_Click; + // + // EditForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + BackColor = Color.PeachPuff; + ClientSize = new Size(324, 503); + Controls.Add(SaveEditButton); + Controls.Add(comboBox4); + Controls.Add(comboBox3); + Controls.Add(comboBox2); + Controls.Add(comboBox1); + Controls.Add(label10); + Controls.Add(label9); + Controls.Add(label8); + Controls.Add(label7); + Controls.Add(label6); + Controls.Add(label5); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(textBox10); + Controls.Add(textBox8); + Controls.Add(textBox5); + Controls.Add(textBox4); + Controls.Add(textBox2); + Name = "EditForm"; + Text = "EditForm"; + Load += EditForm_Load; + ((System.ComponentModel.ISupportInitialize)productBindingSource).EndInit(); + ((System.ComponentModel.ISupportInitialize)productNameBindingSource).EndInit(); + ((System.ComponentModel.ISupportInitialize)supplierBindingSource).EndInit(); + ((System.ComponentModel.ISupportInitialize)manufacturerBindingSource).EndInit(); + ((System.ComponentModel.ISupportInitialize)categoryBindingSource).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Label label2; + private Label label3; + private Label label4; + private Label label5; + private Label label6; + private Label label7; + private Label label8; + private Label label9; + private Label label10; + public TextBox textBox2; + public TextBox textBox4; + public TextBox textBox5; + public TextBox textBox8; + public TextBox textBox10; + public BindingSource productBindingSource; + public ComboBox comboBox1; + public ComboBox comboBox2; + public ComboBox comboBox3; + public ComboBox comboBox4; + public BindingSource productNameBindingSource; + public BindingSource supplierBindingSource; + public BindingSource manufacturerBindingSource; + public BindingSource categoryBindingSource; + public Button SaveEditButton; + } +} \ No newline at end of file diff --git a/EditForm.cs b/EditForm.cs new file mode 100644 index 0000000..13db807 --- /dev/null +++ b/EditForm.cs @@ -0,0 +1,57 @@ +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 samusev_42 +{ + public partial class EditForm : Form + { + /// валидация + public EditForm() + { + InitializeComponent(); + + + this.textBox5.Validating += textBoxPrice_Validating; + } + + private void textBoxPrice_Validating(object sender, CancelEventArgs e) + { + + if (!string.IsNullOrWhiteSpace(textBox5.Text) && !decimal.TryParse(textBox5.Text, out _)) + { + MessageBox.Show("В поле 'Цена' можно вводить только числа!", "Ошибка формата", + MessageBoxButtons.OK, MessageBoxIcon.Warning); + + textBox5.SelectAll(); + e.Cancel = true; + } + } + + private void SaveEditButton_Click(object sender, EventArgs e) + { + + } + + private void label10_Click(object sender, EventArgs e) + { + + } + + private void EditForm_Load(object sender, EventArgs e) + { + + } + + private void label7_Click(object sender, EventArgs e) + { + + } + } +} \ No newline at end of file diff --git a/EditForm.resx b/EditForm.resx new file mode 100644 index 0000000..65eb38e --- /dev/null +++ b/EditForm.resx @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 190, 17 + + + 190, 17 + + + 395, 17 + + + 395, 17 + + + 568, 17 + + + 568, 17 + + + 771, 17 + + + 771, 17 + + + 31 + + \ No newline at end of file diff --git a/Form1.Designer.cs b/Form1.Designer.cs new file mode 100644 index 0000000..80dd39b --- /dev/null +++ b/Form1.Designer.cs @@ -0,0 +1,293 @@ +namespace samusev_42 +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + bindingSource1 = new BindingSource(components); + button1 = new Button(); + categorySource = new BindingSource(components); + dataGridView1 = new DataGridView(); + idProductDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + articleDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + idProductNameDataGridViewTextBoxColumn = new DataGridViewComboBoxColumn(); + product_nameSource = new BindingSource(components); + Column2 = new DataGridViewTextBoxColumn(); + countDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + unitDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + priceDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + idSupplierDataGridViewTextBoxColumn = new DataGridViewComboBoxColumn(); + SupplierSource = new BindingSource(components); + idManufacturerDataGridViewTextBoxColumn = new DataGridViewComboBoxColumn(); + manufacturerSource = new BindingSource(components); + discountDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + idCategoryDataGridViewTextBoxColumn = new DataGridViewComboBoxColumn(); + descriptionDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + photoDataGridViewTextBoxColumn = new DataGridViewTextBoxColumn(); + button2 = new Button(); + buttonDelete = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)bindingSource1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)categorySource).BeginInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)product_nameSource).BeginInit(); + ((System.ComponentModel.ISupportInitialize)SupplierSource).BeginInit(); + ((System.ComponentModel.ISupportInitialize)manufacturerSource).BeginInit(); + SuspendLayout(); + // + // bindingSource1 + // + bindingSource1.DataSource = typeof(Product); + // + // button1 + // + button1.BackColor = Color.MistyRose; + button1.Font = new Font("Segoe UI", 12F, FontStyle.Bold); + button1.Location = new Point(128, 810); + button1.Name = "button1"; + button1.Size = new Size(161, 38); + button1.TabIndex = 1; + button1.Text = "Сохранить"; + button1.UseVisualStyleBackColor = false; + button1.Click += button1_Click; + // + // categorySource + // + categorySource.DataSource = typeof(Category); + // + // dataGridView1 + // + dataGridView1.AutoGenerateColumns = false; + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Columns.AddRange(new DataGridViewColumn[] { idProductDataGridViewTextBoxColumn, articleDataGridViewTextBoxColumn, idProductNameDataGridViewTextBoxColumn, Column2, countDataGridViewTextBoxColumn, unitDataGridViewTextBoxColumn, priceDataGridViewTextBoxColumn, idSupplierDataGridViewTextBoxColumn, idManufacturerDataGridViewTextBoxColumn, discountDataGridViewTextBoxColumn, idCategoryDataGridViewTextBoxColumn, descriptionDataGridViewTextBoxColumn, photoDataGridViewTextBoxColumn }); + dataGridView1.DataSource = bindingSource1; + dataGridView1.Location = new Point(12, 12); + dataGridView1.Name = "dataGridView1"; + dataGridView1.Size = new Size(1055, 779); + dataGridView1.TabIndex = 2; + // + // idProductDataGridViewTextBoxColumn + // + idProductDataGridViewTextBoxColumn.DataPropertyName = "IdProduct"; + idProductDataGridViewTextBoxColumn.HeaderText = "№ Товара"; + idProductDataGridViewTextBoxColumn.Name = "idProductDataGridViewTextBoxColumn"; + // + // articleDataGridViewTextBoxColumn + // + articleDataGridViewTextBoxColumn.DataPropertyName = "Article"; + articleDataGridViewTextBoxColumn.HeaderText = "Артикул Товара"; + articleDataGridViewTextBoxColumn.Name = "articleDataGridViewTextBoxColumn"; + // + // idProductNameDataGridViewTextBoxColumn + // + idProductNameDataGridViewTextBoxColumn.DataPropertyName = "IdProductName"; + idProductNameDataGridViewTextBoxColumn.DataSource = product_nameSource; + idProductNameDataGridViewTextBoxColumn.DisplayMember = "ProductName1"; + idProductNameDataGridViewTextBoxColumn.HeaderText = "Название"; + idProductNameDataGridViewTextBoxColumn.Name = "idProductNameDataGridViewTextBoxColumn"; + idProductNameDataGridViewTextBoxColumn.Resizable = DataGridViewTriState.True; + idProductNameDataGridViewTextBoxColumn.SortMode = DataGridViewColumnSortMode.Automatic; + idProductNameDataGridViewTextBoxColumn.ValueMember = "IdProductName"; + // + // product_nameSource + // + product_nameSource.DataSource = typeof(ProductName); + // + // Column2 + // + Column2.DataPropertyName = "CountUnit"; + Column2.HeaderText = "Количество"; + Column2.Name = "Column2"; + Column2.ReadOnly = true; + // + // countDataGridViewTextBoxColumn + // + countDataGridViewTextBoxColumn.DataPropertyName = "Count"; + countDataGridViewTextBoxColumn.HeaderText = "Кол-Во"; + countDataGridViewTextBoxColumn.Name = "countDataGridViewTextBoxColumn"; + countDataGridViewTextBoxColumn.Visible = false; + // + // unitDataGridViewTextBoxColumn + // + unitDataGridViewTextBoxColumn.DataPropertyName = "Unit"; + unitDataGridViewTextBoxColumn.HeaderText = "Штук"; + unitDataGridViewTextBoxColumn.Name = "unitDataGridViewTextBoxColumn"; + unitDataGridViewTextBoxColumn.Visible = false; + // + // priceDataGridViewTextBoxColumn + // + priceDataGridViewTextBoxColumn.DataPropertyName = "Price"; + priceDataGridViewTextBoxColumn.HeaderText = "Цена"; + priceDataGridViewTextBoxColumn.Name = "priceDataGridViewTextBoxColumn"; + // + // idSupplierDataGridViewTextBoxColumn + // + idSupplierDataGridViewTextBoxColumn.DataPropertyName = "IdSupplier"; + idSupplierDataGridViewTextBoxColumn.DataSource = SupplierSource; + idSupplierDataGridViewTextBoxColumn.DisplayMember = "SupplierName"; + idSupplierDataGridViewTextBoxColumn.HeaderText = "Поставщик"; + idSupplierDataGridViewTextBoxColumn.Name = "idSupplierDataGridViewTextBoxColumn"; + idSupplierDataGridViewTextBoxColumn.Resizable = DataGridViewTriState.True; + idSupplierDataGridViewTextBoxColumn.SortMode = DataGridViewColumnSortMode.Automatic; + idSupplierDataGridViewTextBoxColumn.ValueMember = "IdSupplier"; + // + // SupplierSource + // + SupplierSource.DataSource = typeof(Supplier); + // + // idManufacturerDataGridViewTextBoxColumn + // + idManufacturerDataGridViewTextBoxColumn.DataPropertyName = "IdManufacturer"; + idManufacturerDataGridViewTextBoxColumn.DataSource = manufacturerSource; + idManufacturerDataGridViewTextBoxColumn.DisplayMember = "ManufacturerName"; + idManufacturerDataGridViewTextBoxColumn.HeaderText = "Производитель"; + idManufacturerDataGridViewTextBoxColumn.Name = "idManufacturerDataGridViewTextBoxColumn"; + idManufacturerDataGridViewTextBoxColumn.Resizable = DataGridViewTriState.True; + idManufacturerDataGridViewTextBoxColumn.SortMode = DataGridViewColumnSortMode.Automatic; + idManufacturerDataGridViewTextBoxColumn.ValueMember = "IdManufacturer"; + // + // manufacturerSource + // + manufacturerSource.DataSource = typeof(Manufacturer); + // + // discountDataGridViewTextBoxColumn + // + discountDataGridViewTextBoxColumn.DataPropertyName = "Discount"; + discountDataGridViewTextBoxColumn.HeaderText = "Скидка (%)"; + discountDataGridViewTextBoxColumn.Name = "discountDataGridViewTextBoxColumn"; + // + // idCategoryDataGridViewTextBoxColumn + // + idCategoryDataGridViewTextBoxColumn.DataPropertyName = "IdCategory"; + idCategoryDataGridViewTextBoxColumn.DataSource = categorySource; + idCategoryDataGridViewTextBoxColumn.DisplayMember = "CategoryName"; + idCategoryDataGridViewTextBoxColumn.HeaderText = "Категория"; + idCategoryDataGridViewTextBoxColumn.Name = "idCategoryDataGridViewTextBoxColumn"; + idCategoryDataGridViewTextBoxColumn.Resizable = DataGridViewTriState.True; + idCategoryDataGridViewTextBoxColumn.SortMode = DataGridViewColumnSortMode.Automatic; + idCategoryDataGridViewTextBoxColumn.ValueMember = "IdCategory"; + // + // descriptionDataGridViewTextBoxColumn + // + descriptionDataGridViewTextBoxColumn.DataPropertyName = "Description"; + descriptionDataGridViewTextBoxColumn.HeaderText = "Описание"; + descriptionDataGridViewTextBoxColumn.Name = "descriptionDataGridViewTextBoxColumn"; + // + // photoDataGridViewTextBoxColumn + // + photoDataGridViewTextBoxColumn.DataPropertyName = "Photo"; + photoDataGridViewTextBoxColumn.HeaderText = "Фото"; + photoDataGridViewTextBoxColumn.Name = "photoDataGridViewTextBoxColumn"; + photoDataGridViewTextBoxColumn.Visible = false; + // + // button2 + // + button2.BackColor = Color.MistyRose; + button2.Font = new Font("Segoe UI", 12F, FontStyle.Bold); + button2.Location = new Point(360, 810); + button2.Name = "button2"; + button2.Size = new Size(149, 38); + button2.TabIndex = 3; + button2.Text = "Редактировать"; + button2.UseVisualStyleBackColor = false; + button2.Click += button2_Click; + // + // buttonDelete + // + buttonDelete.BackColor = Color.MistyRose; + buttonDelete.Font = new Font("Segoe UI", 12F, FontStyle.Bold); + buttonDelete.Location = new Point(588, 810); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(139, 38); + buttonDelete.TabIndex = 5; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = false; + buttonDelete.Click += buttonDelete_Click; + // + // buttonAdd + // + buttonAdd.BackColor = Color.MistyRose; + buttonAdd.DialogResult = DialogResult.OK; + buttonAdd.Font = new Font("Segoe UI", 12F, FontStyle.Bold); + buttonAdd.Location = new Point(807, 810); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(131, 39); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = false; + buttonAdd.Click += buttonAdd_Click_1; + // + // Form1 + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + BackColor = Color.PeachPuff; + ClientSize = new Size(1099, 861); + Controls.Add(buttonAdd); + Controls.Add(buttonDelete); + Controls.Add(button2); + Controls.Add(dataGridView1); + Controls.Add(button1); + Name = "Form1"; + Text = "Самусев ИСП-42 №3,4.5"; + ((System.ComponentModel.ISupportInitialize)bindingSource1).EndInit(); + ((System.ComponentModel.ISupportInitialize)categorySource).EndInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ((System.ComponentModel.ISupportInitialize)product_nameSource).EndInit(); + ((System.ComponentModel.ISupportInitialize)SupplierSource).EndInit(); + ((System.ComponentModel.ISupportInitialize)manufacturerSource).EndInit(); + ResumeLayout(false); + } + + #endregion + + private BindingSource bindingSource1; + private BindingSource categorySource; + private DataGridView dataGridView1; + private BindingSource manufacturerSource; + private BindingSource product_nameSource; + private BindingSource SupplierSource; + private DataGridViewTextBoxColumn idProductDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn articleDataGridViewTextBoxColumn; + private DataGridViewComboBoxColumn idProductNameDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn Column2; + private DataGridViewTextBoxColumn countDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn unitDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn priceDataGridViewTextBoxColumn; + private DataGridViewComboBoxColumn idSupplierDataGridViewTextBoxColumn; + private DataGridViewComboBoxColumn idManufacturerDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn discountDataGridViewTextBoxColumn; + private DataGridViewComboBoxColumn idCategoryDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn descriptionDataGridViewTextBoxColumn; + private DataGridViewTextBoxColumn photoDataGridViewTextBoxColumn; + public Button button2; + public Button button1; + private Button buttonDelete; + public Button buttonAdd; + } +} diff --git a/Form1.cs b/Form1.cs new file mode 100644 index 0000000..f568e34 --- /dev/null +++ b/Form1.cs @@ -0,0 +1,124 @@ +using Microsoft.EntityFrameworkCore; +namespace samusev_42 +{ + public partial class Form1 : Form + { + Ispr2522SamusevOvLazarev2Context context; + public Form1() + { + InitializeComponent(); + /// - 0 + dataGridView1.AllowUserToAddRows = false; + + dataGridView1.DataError += (s, e) => { + MessageBox.Show(" ! , .", + " ", MessageBoxButtons.OK, MessageBoxIcon.Warning); + e.ThrowException = false; + }; + + dataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically; + } + + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + context = new Ispr2522SamusevOvLazarev2Context(); + context.Products.Include(x => x.IdCategoryNavigation).Load(); + context.Products.Include(x => x.IdManufacturerNavigation).Load(); + context.Products.Include(x => x.IdProductNameNavigation).Load(); + context.Products.Include(x => x.IdSupplierNavigation).Load(); + context.Categories.Load(); + context.Manufacturers.Load(); + context.Database.EnsureCreated(); + bindingSource1.DataSource = context.Products.Local.ToBindingList(); + categorySource.DataSource = context.Categories.Local.ToBindingList(); + manufacturerSource.DataSource = context.Manufacturers.Local.ToBindingList(); + product_nameSource.DataSource = context.ProductNames.Local.ToBindingList(); + SupplierSource.DataSource = context.Suppliers.Local.ToBindingList(); + } + + private void button1_Click(object sender, EventArgs e) + { + context.SaveChanges(); + dataGridView1.Refresh(); + } + + private void button2_Click(object sender, EventArgs e) + { + if (bindingSource1.Current == null) return; + var form = new EditForm(); + form.categoryBindingSource.DataSource = categorySource.DataSource; + form.manufacturerBindingSource.DataSource = manufacturerSource.DataSource; + form.productNameBindingSource.DataSource = product_nameSource.DataSource; + form.supplierBindingSource.DataSource = SupplierSource.DataSource; + form.productBindingSource.DataSource = bindingSource1.Current; + if (form.ShowDialog() == DialogResult.OK) + { + bindingSource1.EndEdit(); + context.SaveChanges(); + dataGridView1.Refresh(); + } + } + + private void SaveEditButton_Click(object sender, EventArgs e) + { + context.SaveChanges(); + dataGridView1.Refresh(); + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + bindingSource1.RemoveCurrent(); + context.SaveChanges(); + dataGridView1.Refresh(); + } + /// + null + private void buttonAdd_Click_1(object sender, EventArgs e) + { + var newProduct = new Product(); + newProduct.Article = ""; + newProduct.Unit = "."; + newProduct.Description = "-"; + newProduct.Photo = ""; + newProduct.Price = 0; + newProduct.Count = 0; + newProduct.Discount = 0; + + var form = new EditForm(); + form.categoryBindingSource.DataSource = categorySource; + form.manufacturerBindingSource.DataSource = manufacturerSource; + form.productNameBindingSource.DataSource = product_nameSource; + form.supplierBindingSource.DataSource = SupplierSource; + form.productBindingSource.DataSource = newProduct; + if (form.ShowDialog() == DialogResult.OK) + { + try + { + if (newProduct.IdProductName <= 0) + throw new System.ComponentModel.DataAnnotations.ValidationException(" !"); + if (string.IsNullOrWhiteSpace(newProduct.Article)) + throw new System.ComponentModel.DataAnnotations.ValidationException(" !"); + if (newProduct.Price < 0) + throw new System.ComponentModel.DataAnnotations.ValidationException(" !"); + + context.Products.Add(newProduct); + context.SaveChanges(); + bindingSource1.DataSource = context.Products.Local.ToBindingList(); + dataGridView1.Refresh(); + MessageBox.Show(" !"); + } + catch (System.ComponentModel.DataAnnotations.ValidationException valEx) + { + MessageBox.Show(valEx.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + catch (Exception ex) + { + string inner = ex.InnerException?.Message ?? ex.Message; + MessageBox.Show($" : {inner}"); + context.Entry(newProduct).State = EntityState.Detached; + } + } + } + } +} \ No newline at end of file diff --git a/Form1.resx b/Form1.resx new file mode 100644 index 0000000..faa7344 --- /dev/null +++ b/Form1.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 154, 17 + + + 452, 17 + + + True + + + 619, 17 + + + 290, 17 + + + 25 + + \ No newline at end of file diff --git a/Ispr2522SamusevOvLazarev2Context.cs b/Ispr2522SamusevOvLazarev2Context.cs new file mode 100644 index 0000000..fa659c8 --- /dev/null +++ b/Ispr2522SamusevOvLazarev2Context.cs @@ -0,0 +1,311 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; +using Pomelo.EntityFrameworkCore.MySql.Scaffolding.Internal; + +namespace samusev_42; + +public partial class Ispr2522SamusevOvLazarev2Context : DbContext +{ + public Ispr2522SamusevOvLazarev2Context() + { + } + + public Ispr2522SamusevOvLazarev2Context(DbContextOptions options) + : base(options) + { + } + + public virtual DbSet Categories { get; set; } + + public virtual DbSet Deliveries { get; set; } + + public virtual DbSet Manufacturers { get; set; } + + public virtual DbSet Names { get; set; } + + public virtual DbSet OrdersProducts { get; set; } + + public virtual DbSet PickUpPoints { get; set; } + + public virtual DbSet Products { get; set; } + + public virtual DbSet ProductNames { get; set; } + + public virtual DbSet Roles { get; set; } + + public virtual DbSet Statuses { get; set; } + + public virtual DbSet Suppliers { get; set; } + + public virtual DbSet Users { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) +#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263. + => optionsBuilder.UseMySql("server=cfif31.ru;username=ISPr25-22_SamusevOV;password=ISPr25-22_SamusevOV;database=ISPr25-22_SamusevOV_Lazarev2", Microsoft.EntityFrameworkCore.ServerVersion.Parse("8.0.45-mysql")); + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder + .UseCollation("utf8mb4_0900_ai_ci") + .HasCharSet("utf8mb4"); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.IdCategory).HasName("PRIMARY"); + + entity.ToTable("category"); + + entity.Property(e => e.IdCategory).HasColumnName("id_category"); + entity.Property(e => e.CategoryName) + .HasMaxLength(45) + .HasColumnName("category_name"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.IdDelivery).HasName("PRIMARY"); + + entity.ToTable("delivery"); + + entity.HasIndex(e => e.IdPickUpPoint, "fk_delivery_pick-up point_idx"); + + entity.HasIndex(e => e.IdStatus, "fk_delivery_status_idx"); + + entity.HasIndex(e => e.IdUser, "fk_delivery_user_idx"); + + entity.Property(e => e.IdDelivery).HasColumnName("id_delivery"); + entity.Property(e => e.Code).HasColumnName("code"); + entity.Property(e => e.DateDelivery) + .HasColumnType("datetime") + .HasColumnName("date_delivery"); + entity.Property(e => e.DateOrder) + .HasColumnType("datetime") + .HasColumnName("date_order"); + entity.Property(e => e.IdPickUpPoint).HasColumnName("id_pick-up point"); + entity.Property(e => e.IdStatus).HasColumnName("id_status"); + entity.Property(e => e.IdUser).HasColumnName("id_user"); + + entity.HasOne(d => d.IdPickUpPointNavigation).WithMany(p => p.Deliveries) + .HasForeignKey(d => d.IdPickUpPoint) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("fk_delivery_pick-up point"); + + entity.HasOne(d => d.IdStatusNavigation).WithMany(p => p.Deliveries) + .HasForeignKey(d => d.IdStatus) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("fk_delivery_status"); + + entity.HasOne(d => d.IdUserNavigation).WithMany(p => p.Deliveries) + .HasForeignKey(d => d.IdUser) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("fk_delivery_user"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.IdManufacturer).HasName("PRIMARY"); + + entity.ToTable("manufacturer"); + + entity.Property(e => e.IdManufacturer).HasColumnName("id_manufacturer"); + entity.Property(e => e.ManufacturerName) + .HasMaxLength(45) + .HasColumnName("manufacturer_name"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.IdName).HasName("PRIMARY"); + + entity.ToTable("name"); + + entity.HasIndex(e => e.IdUser, "id_name_user_idx"); + + entity.Property(e => e.IdName).HasColumnName("id_name"); + entity.Property(e => e.IdUser).HasColumnName("id_user"); + entity.Property(e => e.NameFio) + .HasMaxLength(45) + .HasColumnName("name_fio"); + + entity.HasOne(d => d.IdUserNavigation).WithMany(p => p.Names) + .HasForeignKey(d => d.IdUser) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("id_name_user"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.IdOrdersProducts).HasName("PRIMARY"); + + entity.ToTable("orders_products"); + + entity.HasIndex(e => e.IdDelivery, "fk_order_products_delivery_idx"); + + entity.HasIndex(e => e.IdProduct, "fk_order_products_product_idx"); + + entity.Property(e => e.IdOrdersProducts).HasColumnName("id_orders_products"); + entity.Property(e => e.Count).HasColumnName("count"); + entity.Property(e => e.IdDelivery).HasColumnName("id_delivery"); + entity.Property(e => e.IdProduct).HasColumnName("id_product"); + + entity.HasOne(d => d.IdDeliveryNavigation).WithMany(p => p.OrdersProducts) + .HasForeignKey(d => d.IdDelivery) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("fk_order_products_delivery"); + + entity.HasOne(d => d.IdProductNavigation).WithMany(p => p.OrdersProducts) + .HasForeignKey(d => d.IdProduct) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("fk_order_products_product"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.IdPickUpPoint).HasName("PRIMARY"); + + entity.ToTable("pick-up point"); + + entity.Property(e => e.IdPickUpPoint).HasColumnName("id_pick-up point"); + entity.Property(e => e.Adress) + .HasMaxLength(45) + .HasColumnName("adress"); + entity.Property(e => e.Index) + .HasMaxLength(45) + .HasColumnName("index"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.IdProduct).HasName("PRIMARY"); + + entity.ToTable("product"); + + entity.HasIndex(e => e.IdCategory, "fk_product_category_idx"); + + entity.HasIndex(e => e.IdManufacturer, "fk_product_manufacturer_idx"); + + entity.HasIndex(e => e.IdProductName, "fk_product_product_name_idx"); + + entity.HasIndex(e => e.IdSupplier, "fk_product_supplier_idx"); + + entity.Property(e => e.IdProduct).HasColumnName("id_product"); + entity.Property(e => e.Article) + .HasMaxLength(45) + .HasColumnName("article"); + entity.Property(e => e.Count).HasColumnName("count"); + entity.Property(e => e.Description) + .HasColumnType("text") + .HasColumnName("description"); + entity.Property(e => e.Discount).HasColumnName("discount"); + entity.Property(e => e.IdCategory).HasColumnName("id_category"); + entity.Property(e => e.IdManufacturer).HasColumnName("id_manufacturer"); + entity.Property(e => e.IdProductName).HasColumnName("id_product name"); + entity.Property(e => e.IdSupplier).HasColumnName("id_supplier"); + entity.Property(e => e.Photo) + .HasMaxLength(45) + .HasColumnName("photo"); + entity.Property(e => e.Price) + .HasPrecision(5) + .HasColumnName("price"); + entity.Property(e => e.Unit) + .HasMaxLength(45) + .HasColumnName("unit"); + + entity.HasOne(d => d.IdCategoryNavigation).WithMany(p => p.Products) + .HasForeignKey(d => d.IdCategory) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("fk_product_category"); + + entity.HasOne(d => d.IdManufacturerNavigation).WithMany(p => p.Products) + .HasForeignKey(d => d.IdManufacturer) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("fk_product_manufacturer"); + + entity.HasOne(d => d.IdProductNameNavigation).WithMany(p => p.Products) + .HasForeignKey(d => d.IdProductName) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("fk_product_product_name"); + + entity.HasOne(d => d.IdSupplierNavigation).WithMany(p => p.Products) + .HasForeignKey(d => d.IdSupplier) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("fk_product_supplier"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.IdProductName).HasName("PRIMARY"); + + entity.ToTable("product name"); + + entity.Property(e => e.IdProductName).HasColumnName("id_product name"); + entity.Property(e => e.ProductName1) + .HasMaxLength(45) + .HasColumnName("product name"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.IdRole).HasName("PRIMARY"); + + entity.ToTable("role"); + + entity.Property(e => e.IdRole).HasColumnName("id_role"); + entity.Property(e => e.RoleName) + .HasMaxLength(45) + .HasColumnName("role_name"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.IdStatus).HasName("PRIMARY"); + + entity.ToTable("status"); + + entity.Property(e => e.IdStatus).HasColumnName("id_status"); + entity.Property(e => e.StatusName) + .HasMaxLength(45) + .HasColumnName("status_name"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.IdSupplier).HasName("PRIMARY"); + + entity.ToTable("supplier"); + + entity.Property(e => e.IdSupplier).HasColumnName("id_supplier"); + entity.Property(e => e.SupplierName) + .HasMaxLength(45) + .HasColumnName("supplier_name"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.IdUser).HasName("PRIMARY"); + + entity.ToTable("user"); + + entity.HasIndex(e => e.IdRole, "fk_user_role_idx"); + + entity.Property(e => e.IdUser).HasColumnName("id_user"); + entity.Property(e => e.IdRole).HasColumnName("id_role"); + entity.Property(e => e.Login) + .HasMaxLength(45) + .HasColumnName("login"); + entity.Property(e => e.Password) + .HasMaxLength(45) + .HasColumnName("password"); + + entity.HasOne(d => d.IdRoleNavigation).WithMany(p => p.Users) + .HasForeignKey(d => d.IdRole) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("fk_user_role"); + }); + + OnModelCreatingPartial(modelBuilder); + } + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); +} diff --git a/Manufacturer.cs b/Manufacturer.cs new file mode 100644 index 0000000..8334022 --- /dev/null +++ b/Manufacturer.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace samusev_42; + +public partial class Manufacturer +{ + public int IdManufacturer { get; set; } + + public string ManufacturerName { get; set; } = null!; + + public virtual ICollection Products { get; set; } = new List(); +} diff --git a/Name.cs b/Name.cs new file mode 100644 index 0000000..f052c87 --- /dev/null +++ b/Name.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace samusev_42; + +public partial class Name +{ + public int IdName { get; set; } + + public string NameFio { get; set; } = null!; + + public int IdUser { get; set; } + + public virtual User IdUserNavigation { get; set; } = null!; +} diff --git a/OrdersProduct.cs b/OrdersProduct.cs new file mode 100644 index 0000000..74fb81f --- /dev/null +++ b/OrdersProduct.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +namespace samusev_42; + +public partial class OrdersProduct +{ + public int IdOrdersProducts { get; set; } + + public int IdDelivery { get; set; } + + public int IdProduct { get; set; } + + public int Count { get; set; } + + public virtual Delivery IdDeliveryNavigation { get; set; } = null!; + + public virtual Product IdProductNavigation { get; set; } = null!; +} diff --git a/PickUpPoint.cs b/PickUpPoint.cs new file mode 100644 index 0000000..68cd9b9 --- /dev/null +++ b/PickUpPoint.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace samusev_42; + +public partial class PickUpPoint +{ + public int IdPickUpPoint { get; set; } + + public string? Adress { get; set; } + + public string Index { get; set; } = null!; + + public virtual ICollection Deliveries { get; set; } = new List(); +} diff --git a/Product.cs b/Product.cs new file mode 100644 index 0000000..e0ef771 --- /dev/null +++ b/Product.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using Microsoft.EntityFrameworkCore; + +namespace samusev_42; + +public partial class Product : IEditableObject +{ + private Ispr2522SamusevOvLazarev2Context context; + + public int IdProduct { get; set; } + public string Article { get; set; } = null!; + public int IdProductName { get; set; } + public string Unit { get; set; } = null!; + public decimal Price { get; set; } + public int IdSupplier { get; set; } + public int IdManufacturer { get; set; } + public int IdCategory { get; set; } + public int Discount { get; set; } + public int Count { get; set; } + public string Description { get; set; } = null!; + public string Photo { get; set; } = null!; + + public virtual Category IdCategoryNavigation { get; set; } = null!; + public virtual Manufacturer IdManufacturerNavigation { get; set; } = null!; + public virtual ProductName IdProductNameNavigation { get; set; } = null!; + public virtual Supplier IdSupplierNavigation { get; set; } = null!; + public virtual ICollection OrdersProducts { get; set; } = new List(); + + // Реализация валидации IEditableObject + + public void BeginEdit() + { + if (context == null) + { + context = new Ispr2522SamusevOvLazarev2Context(); + context.Products.Attach(this); + } + } + + public void CancelEdit() + { + if (context != null) + { + var entry = context.Entry(this); + if (entry.State == EntityState.Modified) + { + entry.Reload(); + } + } + } + + public void EndEdit() + { + // ВАЛИДАЦИЯ + if (string.IsNullOrWhiteSpace(this.Article)) + { + throw new ValidationException("Артикул не может быть пустым!"); + } + + if (this.Price < 0) + { + throw new ValidationException("Цена не может быть отрицательной!"); + } + + if (context != null) + { + context.SaveChanges(); + } + } +} \ No newline at end of file diff --git a/ProductName.cs b/ProductName.cs new file mode 100644 index 0000000..3844008 --- /dev/null +++ b/ProductName.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace samusev_42; + +public partial class ProductName +{ + public int IdProductName { get; set; } + + public string ProductName1 { get; set; } = null!; + + public virtual ICollection Products { get; set; } = new List(); +} diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..d7548bf --- /dev/null +++ b/Program.cs @@ -0,0 +1,17 @@ +namespace samusev_42 +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new AuthForm()); + } + } +} \ No newline at end of file diff --git a/Properties/DataSources/Category.datasource b/Properties/DataSources/Category.datasource new file mode 100644 index 0000000..e6bef85 --- /dev/null +++ b/Properties/DataSources/Category.datasource @@ -0,0 +1,10 @@ + + + + samusev_42.Category, samusev-42, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/Properties/DataSources/Manufacturer.datasource b/Properties/DataSources/Manufacturer.datasource new file mode 100644 index 0000000..60e1580 --- /dev/null +++ b/Properties/DataSources/Manufacturer.datasource @@ -0,0 +1,10 @@ + + + + samusev_42.Manufacturer, samusev-42, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/Properties/DataSources/OrdersProduct.datasource b/Properties/DataSources/OrdersProduct.datasource new file mode 100644 index 0000000..d723727 --- /dev/null +++ b/Properties/DataSources/OrdersProduct.datasource @@ -0,0 +1,10 @@ + + + + samusev_42.OrdersProduct, samusev-42, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/Properties/DataSources/Product.datasource b/Properties/DataSources/Product.datasource new file mode 100644 index 0000000..dec72e8 --- /dev/null +++ b/Properties/DataSources/Product.datasource @@ -0,0 +1,10 @@ + + + + samusev_42.Product, samusev-42, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/Properties/DataSources/ProductName.datasource b/Properties/DataSources/ProductName.datasource new file mode 100644 index 0000000..28dcbfc --- /dev/null +++ b/Properties/DataSources/ProductName.datasource @@ -0,0 +1,10 @@ + + + + samusev_42.ProductName, samusev-42, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/Properties/DataSources/Supplier.datasource b/Properties/DataSources/Supplier.datasource new file mode 100644 index 0000000..05a6e82 --- /dev/null +++ b/Properties/DataSources/Supplier.datasource @@ -0,0 +1,10 @@ + + + + samusev_42.Supplier, samusev-42, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs new file mode 100644 index 0000000..eb57fc9 --- /dev/null +++ b/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace samusev_42.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("samusev_42.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Properties/Resources.resx b/Properties/Resources.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Properties/Resources.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Role.cs b/Role.cs new file mode 100644 index 0000000..c9a9cec --- /dev/null +++ b/Role.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace samusev_42; + +public partial class Role +{ + public int IdRole { get; set; } + + public string RoleName { get; set; } = null!; + + public virtual ICollection Users { get; set; } = new List(); +} diff --git a/Status.cs b/Status.cs new file mode 100644 index 0000000..8dbdaee --- /dev/null +++ b/Status.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace samusev_42; + +public partial class Status +{ + public int IdStatus { get; set; } + + public string StatusName { get; set; } = null!; + + public virtual ICollection Deliveries { get; set; } = new List(); +} diff --git a/Supplier.cs b/Supplier.cs new file mode 100644 index 0000000..fdb4065 --- /dev/null +++ b/Supplier.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace samusev_42; + +public partial class Supplier +{ + public int IdSupplier { get; set; } + + public string SupplierName { get; set; } = null!; + + public virtual ICollection Products { get; set; } = new List(); +} diff --git a/User.cs b/User.cs new file mode 100644 index 0000000..0123542 --- /dev/null +++ b/User.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; + +namespace samusev_42; + +public partial class User +{ + public int IdUser { get; set; } + + public string Login { get; set; } = null!; + + public string Password { get; set; } = null!; + + public int IdRole { get; set; } + + public virtual ICollection Deliveries { get; set; } = new List(); + + public virtual Role IdRoleNavigation { get; set; } = null!; + + public virtual ICollection Names { get; set; } = new List(); +} diff --git a/samusev-42.csproj b/samusev-42.csproj new file mode 100644 index 0000000..da0c437 --- /dev/null +++ b/samusev-42.csproj @@ -0,0 +1,39 @@ + + + + WinExe + net8.0-windows + samusev_42 + enable + true + enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ No newline at end of file diff --git a/samusev-42.sln b/samusev-42.sln new file mode 100644 index 0000000..2b34a07 --- /dev/null +++ b/samusev-42.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35931.197 d17.13 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "samusev-42", "samusev-42.csproj", "{ED29084E-1A2F-43BE-ADD8-A4AE71F92783}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {ED29084E-1A2F-43BE-ADD8-A4AE71F92783}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ED29084E-1A2F-43BE-ADD8-A4AE71F92783}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ED29084E-1A2F-43BE-ADD8-A4AE71F92783}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ED29084E-1A2F-43BE-ADD8-A4AE71F92783}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2743F97A-92F1-4906-80DB-89C4A8873133} + EndGlobalSection +EndGlobal