| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace СУБД_Швейная_фабрика
- {
- public partial class FormAddTovar : Form
- {
- public FormAddTovar()
- {
- InitializeComponent();
- }
- struct Cloth
- {
- public string Title, Color, Width, Length, Description;
- public Image Photo;
- }
- List<Cloth> lstCloth = new List<Cloth>();
- private void btnAddCloth_Click(object sender, EventArgs e)
- {
- try
- {
- if (tbxTitle.Text == "" || int.Parse(tbxLenght.Text) <= 0 || int.Parse(tbxWidth.Text) <= 0 || int.Parse(tbxColor.Text) < 0)
- {
- MessageBox.Show("Все поля должны быть заполнены(Можно не заполнять поле описания) и больше нуля, цвет должен быть числом", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- }
- catch
- {
- MessageBox.Show("Все поля должны быть заполнены(Можно не заполнять поле описания) и больше нуля, цвет должен быть числом", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- Cloth cl = new Cloth();
- cl.Title = tbxTitle.Text;
- cl.Color = tbxColor.Text;
- cl.Width = tbxWidth.Text;
- cl.Length = tbxLenght.Text;
- cl.Photo = pbxPhotoCloth.Image;
- lstCloth.Add(cl);
- dgvCloth.Rows.Add(tbxTitle.Text, tbxColor.Text, tbxLenght.Text, tbxWidth.Text, tbxDescr.Text);
- }
- private void btnLoadPhoto_Click(object sender, EventArgs e)
- {
- try
- {
- if (ofdPhoto.ShowDialog() == DialogResult.OK)
- {
- pbxPhotoCloth.Image = Image.FromFile(ofdPhoto.FileName);
- }
- }
- catch
- {
- }
- }
- private void btnClearPhoto_Click(object sender, EventArgs e)
- {
- if (DialogResult.Yes == MessageBox.Show("Удалить фотографию?","Внимание!",MessageBoxButtons.YesNo))
- pbxPhotoCloth.Image = null;
- }
-
- private void btnOk_Click(object sender, EventArgs e)
- {
- SqlConnection con = new SqlConnection(FormAuthorization.StrCon);
- for (int i = 0;i < lstCloth.Count;i++)
- {
- con.Open();
- if (lstCloth[i].Photo != null)
- {
- SqlCommand cmd = new SqlCommand($@"insert into Cloth(Title,IdColor,Weight,Height,Note,Photo)
- values('{lstCloth[i].Title}',{lstCloth[i].Color},{lstCloth[i].Width},{lstCloth[i].Length},'{lstCloth[i].Description}',@photo)", con);
- MemoryStream ms = new MemoryStream();
- lstCloth[i].Photo.Save(ms, ImageFormat.Png);
- cmd.Parameters.AddWithValue("@photo", ms.ToArray());
- cmd.ExecuteNonQuery();
- }else
- {
- SqlCommand cmd = new SqlCommand($@"insert into Cloth(Title,IdColor,Weight,Height,Note)
- values('{lstCloth[i].Title}',{lstCloth[i].Color},{lstCloth[i].Width},{lstCloth[i].Length},{lstCloth[i].Description})", con);
-
-
- cmd.ExecuteNonQuery();
- }
- con.Close();
- }
- MessageBox.Show("Документ принят к учету.", "Внимание!",
- MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.Close();
- }
- private void btnDelCloth_Click(object sender, EventArgs e)
- {
- int NumTkan = dgvCloth.CurrentRow.Index;
-
- if (NumTkan >= 0)
- {
- DialogResult res = MessageBox.Show("Удалить выделенную ткань?",
- "Внимание!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- if (res == DialogResult.Yes)
- {
-
- lstCloth.RemoveAt(NumTkan);
- dgvCloth.Rows.RemoveAt(NumTkan);
- }
- }
- }
- }
- }
|