| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace СУБД_Швейная_фабрика
- {
- public partial class FormManager : Form
- {
- public FormManager()
- {
- InitializeComponent();
- }
- private void btnEdit_Click(object sender, EventArgs e)
- {
- FormEditUser frm = new FormEditUser();
- this.Hide();
- frm.ShowDialog();
- this.Show();
- }
- private void FormManager_Load(object sender, EventArgs e)
- {
- // TODO: This line of code loads data into the 'fabrikaLDADataSet.Products' table. You can move, or remove it, as needed.
- this.productsTableAdapter.Fill(this.fabrikaLDADataSet.Products);
- SqlConnection con = new SqlConnection(FormAuthorization.StrCon);
- con.Open();
- SqlCommand cmd = new SqlCommand($@"select Fam,Name,Otch from Users where IdUser = {FormAuthorization.IdUser}", con);
- SqlDataReader res = cmd.ExecuteReader();
- res.Read();
- lblFIO.Text = $"{res["Fam"]} {res["Name"]} {res["Otch"]}";
- res.Close();
- con.Close();
- }
- public static int Pos = -1;
- private void btnAdd_Click(object sender, EventArgs e)
- {
-
- try
- {
- if (tbxTitle.Text == "" || int.Parse(tbxLenght.Text) <= 0 || int.Parse(tbxWidth.Text) <= 0)
- {
- MessageBox.Show("Все поля должны быть заполнены и больше нуля", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- }
- catch
- {
- MessageBox.Show("Все поля должны быть заполнены и больше нуля", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- SqlConnection con = new SqlConnection(FormAuthorization.StrCon);
- con.Open();
- if (btnAdd.Text == "Сохранить" && Pos != -1)
- {
- SqlCommand cmdManager = new SqlCommand($@"update Products
- set TitleProduct = '{tbxTitle.Text}',Lenght={tbxLenght.Text},Width={tbxWidth.Text}
- where IdProduct = {Pos}", con);
- cmdManager.ExecuteNonQuery();
- con.Close();
- MessageBox.Show("Изделие отредактировано", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else if (btnAdd.Text == "Добавить") {
- SqlCommand cmdManager = new SqlCommand($@"Insert into Products(TitleProduct,Lenght,Width)
- values('{tbxTitle.Text}',{tbxLenght.Text},{tbxWidth.Text})", con);
- cmdManager.ExecuteNonQuery();
- con.Close();
- MessageBox.Show("Изделие добавлено", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
-
-
- dgvProducts.Update();
- }
- private void btnDrop_Click(object sender, EventArgs e)
- {
- Pos = -1;
- btnAdd.Text = "Добавить";
- tbxTitle.Text = "";
- tbxLenght.Text = "";
- tbxWidth.Text = "";
- }
- private void dgvProducts_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- btnAdd.Text = "Сохранить";
- Pos = int.Parse(dgvProducts.CurrentRow.Cells[0].Value.ToString());
- tbxTitle.Text = dgvProducts.CurrentRow.Cells[1].Value.ToString();
- tbxLenght.Text = dgvProducts.CurrentRow.Cells[2].Value.ToString();
- tbxWidth.Text = dgvProducts.CurrentRow.Cells[3].Value.ToString();
- }
- private void btnProducts_Click(object sender, EventArgs e)
- {
- }
- }
- }
|