Bladeren bron

Кнопки Добавить и Удалить

sanyogromov@mail.ru 2 jaren geleden
bovenliggende
commit
a10e263fcf
7 gewijzigde bestanden met toevoegingen van 500 en 43 verwijderingen
  1. 217 0
      project/DannyeAdd.Designer.cs
  2. 48 0
      project/DannyeAdd.cs
  3. 120 0
      project/DannyeAdd.resx
  4. 23 22
      project/Main.Designer.cs
  5. 67 5
      project/Main.cs
  6. 16 16
      project/Main.resx
  7. 9 0
      project/project.csproj

+ 217 - 0
project/DannyeAdd.Designer.cs

@@ -0,0 +1,217 @@
+
+namespace project
+{
+    partial class DannyeAdd
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.button4 = new System.Windows.Forms.Button();
+            this.label1 = new System.Windows.Forms.Label();
+            this.label2 = new System.Windows.Forms.Label();
+            this.label3 = new System.Windows.Forms.Label();
+            this.label4 = new System.Windows.Forms.Label();
+            this.label5 = new System.Windows.Forms.Label();
+            this.textBox1 = new System.Windows.Forms.TextBox();
+            this.textBox2 = new System.Windows.Forms.TextBox();
+            this.textBox3 = new System.Windows.Forms.TextBox();
+            this.textBox4 = new System.Windows.Forms.TextBox();
+            this.textBox5 = new System.Windows.Forms.TextBox();
+            this.button1 = new System.Windows.Forms.Button();
+            this.SuspendLayout();
+            // 
+            // button4
+            // 
+            this.button4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(150)))), ((int)(((byte)(125)))));
+            this.button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
+            this.button4.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+            this.button4.ForeColor = System.Drawing.SystemColors.Window;
+            this.button4.Location = new System.Drawing.Point(359, 237);
+            this.button4.Name = "button4";
+            this.button4.Size = new System.Drawing.Size(123, 35);
+            this.button4.TabIndex = 18;
+            this.button4.Text = "Добавить";
+            this.button4.UseVisualStyleBackColor = false;
+            this.button4.Click += new System.EventHandler(this.button4_Click);
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+            this.label1.ForeColor = System.Drawing.SystemColors.Window;
+            this.label1.Location = new System.Drawing.Point(58, 44);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(149, 24);
+            this.label1.TabIndex = 19;
+            this.label1.Text = "Наименование:";
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+            this.label2.ForeColor = System.Drawing.SystemColors.Window;
+            this.label2.Location = new System.Drawing.Point(136, 78);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(71, 24);
+            this.label2.TabIndex = 20;
+            this.label2.Text = "Город:";
+            // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+            this.label3.ForeColor = System.Drawing.SystemColors.Window;
+            this.label3.Location = new System.Drawing.Point(136, 115);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(72, 24);
+            this.label3.TabIndex = 21;
+            this.label3.Text = "Адрес:";
+            // 
+            // label4
+            // 
+            this.label4.AutoSize = true;
+            this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+            this.label4.ForeColor = System.Drawing.SystemColors.Window;
+            this.label4.Location = new System.Drawing.Point(41, 149);
+            this.label4.Name = "label4";
+            this.label4.Size = new System.Drawing.Size(167, 24);
+            this.label4.TabIndex = 22;
+            this.label4.Text = "Номер телефона:";
+            // 
+            // label5
+            // 
+            this.label5.AutoSize = true;
+            this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+            this.label5.ForeColor = System.Drawing.SystemColors.Window;
+            this.label5.Location = new System.Drawing.Point(12, 187);
+            this.label5.Name = "label5";
+            this.label5.Size = new System.Drawing.Size(196, 24);
+            this.label5.TabIndex = 23;
+            this.label5.Text = "Контактные данные:";
+            // 
+            // textBox1
+            // 
+            this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+            this.textBox1.Location = new System.Drawing.Point(225, 44);
+            this.textBox1.MaxLength = 30;
+            this.textBox1.Name = "textBox1";
+            this.textBox1.Size = new System.Drawing.Size(257, 29);
+            this.textBox1.TabIndex = 24;
+            // 
+            // textBox2
+            // 
+            this.textBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+            this.textBox2.Location = new System.Drawing.Point(225, 79);
+            this.textBox2.MaxLength = 30;
+            this.textBox2.Name = "textBox2";
+            this.textBox2.Size = new System.Drawing.Size(257, 29);
+            this.textBox2.TabIndex = 25;
+            // 
+            // textBox3
+            // 
+            this.textBox3.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+            this.textBox3.Location = new System.Drawing.Point(225, 115);
+            this.textBox3.MaxLength = 50;
+            this.textBox3.Name = "textBox3";
+            this.textBox3.Size = new System.Drawing.Size(257, 29);
+            this.textBox3.TabIndex = 26;
+            // 
+            // textBox4
+            // 
+            this.textBox4.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+            this.textBox4.Location = new System.Drawing.Point(225, 150);
+            this.textBox4.MaxLength = 11;
+            this.textBox4.Name = "textBox4";
+            this.textBox4.Size = new System.Drawing.Size(257, 29);
+            this.textBox4.TabIndex = 27;
+            // 
+            // textBox5
+            // 
+            this.textBox5.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+            this.textBox5.Location = new System.Drawing.Point(225, 184);
+            this.textBox5.MaxLength = 120;
+            this.textBox5.Name = "textBox5";
+            this.textBox5.Size = new System.Drawing.Size(257, 29);
+            this.textBox5.TabIndex = 28;
+            // 
+            // button1
+            // 
+            this.button1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(150)))), ((int)(((byte)(125)))));
+            this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
+            this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+            this.button1.ForeColor = System.Drawing.SystemColors.Window;
+            this.button1.Location = new System.Drawing.Point(45, 237);
+            this.button1.Name = "button1";
+            this.button1.Size = new System.Drawing.Size(123, 35);
+            this.button1.TabIndex = 29;
+            this.button1.Text = "Назад";
+            this.button1.UseVisualStyleBackColor = false;
+            this.button1.Click += new System.EventHandler(this.button1_Click);
+            // 
+            // DannyeAdd
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(180)))), ((int)(((byte)(145)))));
+            this.ClientSize = new System.Drawing.Size(561, 284);
+            this.Controls.Add(this.button1);
+            this.Controls.Add(this.textBox5);
+            this.Controls.Add(this.textBox4);
+            this.Controls.Add(this.textBox3);
+            this.Controls.Add(this.textBox2);
+            this.Controls.Add(this.textBox1);
+            this.Controls.Add(this.label5);
+            this.Controls.Add(this.label4);
+            this.Controls.Add(this.label3);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.button4);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
+            this.Name = "DannyeAdd";
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+            this.Text = "Добавление записи";
+            this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.DannyeAdd_FormClosed);
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Button button4;
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.Label label4;
+        private System.Windows.Forms.Label label5;
+        private System.Windows.Forms.TextBox textBox1;
+        private System.Windows.Forms.TextBox textBox2;
+        private System.Windows.Forms.TextBox textBox3;
+        private System.Windows.Forms.TextBox textBox4;
+        private System.Windows.Forms.TextBox textBox5;
+        private System.Windows.Forms.Button button1;
+    }
+}

+ 48 - 0
project/DannyeAdd.cs

@@ -0,0 +1,48 @@
+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;
+using System.Data.SqlClient;
+
+namespace project
+{
+    public partial class DannyeAdd : Form
+    {
+
+        DataBase dataBase = new DataBase();
+        public DannyeAdd()
+        {
+            InitializeComponent();
+        }
+
+        private void button4_Click(object sender, EventArgs e)
+        {
+            dataBase.openConnection();
+            var addQuery = $"insert into Dannye (name_dan, adres_dan, city_dan, number_dan, contact_dan) values ('{textBox1.Text}','{textBox2.Text}','{textBox3.Text}','{textBox4.Text}','{textBox5.Text}')";
+            var command = new SqlCommand(addQuery, dataBase.GetConnection());
+            command.ExecuteNonQuery();
+            MessageBox.Show("Запись успешно добавлена в таблицу");
+            dataBase.closeConnection();
+            this.Hide();
+            Main MAIN = new Main();
+            MAIN.Show();
+        }
+
+        private void DannyeAdd_FormClosed(object sender, FormClosedEventArgs e)
+        {
+            Application.Exit();
+        }
+
+        private void button1_Click(object sender, EventArgs e)
+        {
+            this.Hide();
+            Main main = new Main();
+            main.Show();
+        }
+    }
+}

+ 120 - 0
project/DannyeAdd.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    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
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 23 - 22
project/Main.Designer.cs

@@ -33,8 +33,8 @@ namespace project
             this.dataGridView1 = new System.Windows.Forms.DataGridView();
             this.pictureBox1 = new System.Windows.Forms.PictureBox();
             this.button2 = new System.Windows.Forms.Button();
-            this.button1 = new System.Windows.Forms.Button();
             this.groupBox1 = new System.Windows.Forms.GroupBox();
+            this.button4 = new System.Windows.Forms.Button();
             ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
             this.groupBox1.SuspendLayout();
@@ -52,6 +52,7 @@ namespace project
             this.dataGridView1.ReadOnly = true;
             this.dataGridView1.Size = new System.Drawing.Size(776, 385);
             this.dataGridView1.TabIndex = 1;
+            this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick);
             // 
             // pictureBox1
             // 
@@ -69,35 +70,22 @@ namespace project
             // 
             this.button2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(150)))), ((int)(((byte)(125)))));
             this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
-            this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+            this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
             this.button2.ForeColor = System.Drawing.SystemColors.Window;
-            this.button2.Location = new System.Drawing.Point(202, 22);
+            this.button2.Location = new System.Drawing.Point(145, 19);
             this.button2.Name = "button2";
-            this.button2.Size = new System.Drawing.Size(155, 35);
+            this.button2.Size = new System.Drawing.Size(123, 35);
             this.button2.TabIndex = 14;
             this.button2.Text = "Удалить";
             this.button2.UseVisualStyleBackColor = false;
             this.button2.Visible = false;
             this.button2.Click += new System.EventHandler(this.button2_Click);
             // 
-            // button1
-            // 
-            this.button1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(150)))), ((int)(((byte)(125)))));
-            this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
-            this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
-            this.button1.ForeColor = System.Drawing.SystemColors.Window;
-            this.button1.Location = new System.Drawing.Point(22, 22);
-            this.button1.Name = "button1";
-            this.button1.Size = new System.Drawing.Size(155, 35);
-            this.button1.TabIndex = 13;
-            this.button1.Text = "Изменить";
-            this.button1.UseVisualStyleBackColor = false;
-            this.button1.Visible = false;
-            this.button1.Click += new System.EventHandler(this.button1_Click);
-            // 
             // groupBox1
             // 
             this.groupBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
+            this.groupBox1.Controls.Add(this.button4);
+            this.groupBox1.Controls.Add(this.button2);
             this.groupBox1.Controls.Add(this.pictureBox1);
             this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.groupBox1.Location = new System.Drawing.Point(6, 0);
@@ -106,14 +94,27 @@ namespace project
             this.groupBox1.TabIndex = 15;
             this.groupBox1.TabStop = false;
             // 
+            // button4
+            // 
+            this.button4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(150)))), ((int)(((byte)(125)))));
+            this.button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
+            this.button4.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
+            this.button4.ForeColor = System.Drawing.SystemColors.Window;
+            this.button4.Location = new System.Drawing.Point(16, 19);
+            this.button4.Name = "button4";
+            this.button4.Size = new System.Drawing.Size(123, 35);
+            this.button4.TabIndex = 17;
+            this.button4.Text = "Добавить";
+            this.button4.UseVisualStyleBackColor = false;
+            this.button4.Visible = false;
+            this.button4.Click += new System.EventHandler(this.button4_Click);
+            // 
             // Main
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(180)))), ((int)(((byte)(145)))));
             this.ClientSize = new System.Drawing.Size(820, 468);
-            this.Controls.Add(this.button2);
-            this.Controls.Add(this.button1);
             this.Controls.Add(this.dataGridView1);
             this.Controls.Add(this.groupBox1);
             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
@@ -134,7 +135,7 @@ namespace project
         private System.Windows.Forms.DataGridView dataGridView1;
         private System.Windows.Forms.PictureBox pictureBox1;
         private System.Windows.Forms.Button button2;
-        private System.Windows.Forms.Button button1;
         private System.Windows.Forms.GroupBox groupBox1;
+        private System.Windows.Forms.Button button4;
     }
 }

+ 67 - 5
project/Main.cs

@@ -11,8 +11,16 @@ using System.Data.SqlClient;
 
 namespace project
 {
+    enum RowState
+    {
+        Existed,
+        New,
+        ModifiedNew,
+        Deleted
+    }
     public partial class Main : Form
     {
+        string code, name_dan, adres_dan, city_dan, number_dan, contact_dan;
         public static string login;
         DataBase dataBase = new DataBase();
         public Main()
@@ -40,7 +48,7 @@ namespace project
 
         private void CreateColumns()
         {
-            dataGridView1.Columns.Add("code", "Номер");
+            dataGridView1.Columns.Add("code", "ID");
             dataGridView1.Columns.Add("name_dan", "Наименование");
             dataGridView1.Columns.Add("adres_dan", "Адрес");
             dataGridView1.Columns.Add("city_dan", "Город");
@@ -64,8 +72,8 @@ namespace project
             string admPolzovatel = sqlCommand2.ExecuteScalar().ToString();
             if (admPolzovatel.Trim() == "true")
             {
-                button1.Visible = true;
                 button2.Visible = true;
+                button4.Visible = true;
             }
         }
 
@@ -75,14 +83,68 @@ namespace project
             profile.Show();
         }
 
-        private void button1_Click(object sender, EventArgs e)
+        private void button2_Click(object sender, EventArgs e)
         {
+            deleteRow();
+            Update();
+        }
 
+        private void deleteRow()
+        {
+            int index = dataGridView1.CurrentCell.RowIndex;
+            dataGridView1.Rows[index].Visible = false;
+            if (dataGridView1.Rows[index].Cells[0].Value.ToString() == String.Empty)
+            {
+                dataGridView1.Rows[index].Cells[5].Value = RowState.Deleted;
+                return;
+            }
+            dataGridView1.Rows[index].Cells[5].Value = RowState.Deleted;
         }
 
-        private void button2_Click(object sender, EventArgs e)
+        new private void Update()
+        {
+            dataBase.openConnection();
+            for (int index = 0; index < dataGridView1.Rows.Count; index++)
+            {
+                try
+                {
+                    var rowState = (RowState)dataGridView1.Rows[index].Cells[5].Value;
+                    if (rowState == RowState.Existed)
+                        continue;
+                    if (rowState == RowState.Deleted)
+                    {
+                        var id = Convert.ToInt32(dataGridView1.Rows[index].Cells[0].Value);
+                        var deleteQuery = $"delete from Dannye where code = {id}";
+                        var command = new SqlCommand(deleteQuery, dataBase.GetConnection());
+                        command.ExecuteNonQuery();
+                    }
+                }
+                catch { }
+
+            }
+            dataBase.closeConnection();
+        }
+
+        private void button4_Click(object sender, EventArgs e)
         {
-            
+            this.Hide();
+            DannyeAdd add = new DannyeAdd();
+            add.Show();
+        }
+
+        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
+        {
+            var selectedRow = e.RowIndex;
+            if (e.RowIndex >= 0)
+            {
+                DataGridViewRow row = dataGridView1.Rows[selectedRow];
+                code = row.Cells[0].Value.ToString();
+                name_dan = row.Cells[1].Value.ToString();
+                adres_dan = row.Cells[2].Value.ToString();
+                city_dan = row.Cells[3].Value.ToString();
+                number_dan = row.Cells[4].Value.ToString();
+                contact_dan = row.Cells[5].Value.ToString();
+            }
         }
     }
 }

+ 16 - 16
project/Main.resx

@@ -120,22 +120,22 @@
   <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   <data name="pictureBox1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
     <value>
-        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
+        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
 </value>
   </data>
 </root>

+ 9 - 0
project/project.csproj

@@ -46,6 +46,12 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="DannyeAdd.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="DannyeAdd.Designer.cs">
+      <DependentUpon>DannyeAdd.cs</DependentUpon>
+    </Compile>
     <Compile Include="DataBase.cs" />
     <Compile Include="Login.cs" />
     <Compile Include="Main.cs">
@@ -86,6 +92,9 @@
     <Compile Include="Vhod.Designer.cs">
       <DependentUpon>Vhod.cs</DependentUpon>
     </Compile>
+    <EmbeddedResource Include="DannyeAdd.resx">
+      <DependentUpon>DannyeAdd.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="Main.resx">
       <DependentUpon>Main.cs</DependentUpon>
     </EmbeddedResource>