123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- 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;
- using static СУБД_Фабрика.FormGetMaterial;
- namespace СУБД_Фабрика
- {
- public partial class FormGetMaterial : Form
- {
- public FormGetMaterial()
- {
- InitializeComponent();
- }
- public struct Tkan
- {
- public string TitleTkan, ColorTkan, WidthTkan, LengthTkan, Comment;
- public Image PhotoTkan;
- }
- public struct Furn
- {
- public string TitleFurn, CountFurn;
- public Image PhotoFurn;
- }
- SqlConnection Con = new SqlConnection(FormMain.txtCon);
- List<Tkan> LstTkan = new List<Tkan>();
- List<Furn> LstFurn = new List<Furn>();
- private void BtnLoadPhoto_Click(object sender, EventArgs e)
- {
- try
- {
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- PbxPhotoTkan.Image = Image.FromFile(openFileDialog1.FileName);
- }
- catch { }
- }
- private void BtnClearPhoto_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("Очистить фотографию?", "Внимание",
- MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
- PbxPhotoTkan.Image = null;
- }
- private void BtnAddTkan_Click(object sender, EventArgs e)
- {
- Tkan Tk1 = new Tkan();
- Tk1.TitleTkan = TbxTitleTkan.Text;
- Tk1.ColorTkan = TbxColorTkan.Text;
- Tk1.WidthTkan = TbxWidthTkan.Text;
- Tk1.LengthTkan = TbxLengthTkan.Text;
- Tk1.Comment = TbxCommentTkan.Text;
- Tk1.PhotoTkan = PbxPhotoTkan.Image;
- LstTkan.Add(Tk1);
- DgvTkan.Rows.Add(Tk1.TitleTkan, Tk1.ColorTkan, Tk1.WidthTkan, Tk1.LengthTkan, Tk1.Comment);
- }
- private void BtnDelTkan_Click(object sender, EventArgs e)
- {
- int NumTkan = DgvTkan.CurrentRow.Index;
- if (NumTkan >= 0)
- {
- if (MessageBox.Show("Удалить выделенную ткань?",
- "Внимание", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- LstTkan.RemoveAt(NumTkan);
- DgvTkan.Rows.RemoveAt(NumTkan);
- }
- }
- else
- MessageBox.Show("Ткань не выделена",
- "Внимание", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- }
- private void BtnOK_Click(object sender, EventArgs e)
- {
- foreach (Tkan tkan in LstTkan)
- {
- Con.Open();
- if (tkan.PhotoTkan != null) // если есть изображение
- {
- string PhotoName = Guid.NewGuid().ToString() + ".jpg";
- string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Application.StartupPath + "\\Clothes", PhotoName);
- string txtQuery = $@"insert into Cloth(Title, Color, Width, Length, Comment, Photo) values('{tkan.TitleTkan}','{tkan.ColorTkan}',{tkan.WidthTkan},{tkan.LengthTkan},'{tkan.Comment}','{PhotoName}')";
- SqlCommand query = new SqlCommand(txtQuery, Con);
- query.ExecuteNonQuery();
- tkan.PhotoTkan.Save(fileName, ImageFormat.Jpeg);
- }
- else
- {
- string txtQuery = $@"insert into Cloth(Title, Color, Width, Length, Comment) values('{tkan.TitleTkan}','{tkan.ColorTkan}',{tkan.WidthTkan},{tkan.LengthTkan},'{tkan.Comment}')";
- SqlCommand query = new SqlCommand(txtQuery, Con);
- query.ExecuteNonQuery();
- }
- Con.Close();
- }
- foreach(Furn frn in LstFurn)
- {
- Con.Open();
- if(frn.PhotoFurn != null)
- {
- string PhotoName = Guid.NewGuid().ToString() + ".jpg";
- string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Application.StartupPath + "\\Clothes", PhotoName);
- string txtQuery = $@"insert into Furnitura(namefur, countfur, photo) values('{frn.TitleFurn}',{frn.CountFurn},'{PhotoName}')";
- SqlCommand query = new SqlCommand(txtQuery, Con);
- query.ExecuteNonQuery();
- frn.PhotoFurn.Save(fileName, ImageFormat.Jpeg);
- }
- else
- {
- string txtQuery = $@"insert into Furnitura(namefur, countfur) values('{frn.TitleFurn}',{frn.CountFurn})";
- SqlCommand query = new SqlCommand(txtQuery, Con);
- query.ExecuteNonQuery();
- }
- Con.Close();
- }
- MessageBox.Show("Документ принят к учету.", "Внимание!",
- MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.Close();
- }
- private void BtnSavePhotoFurn_Click(object sender, EventArgs e)
- {
- try
- {
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- PbxPhotoFurn.Image = Image.FromFile(openFileDialog1.FileName);
- }
- catch { }
- }
- private void BtnClearPhotoFurn_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("Очистить фотографию?", "Внимание",
- MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
- PbxPhotoFurn.Image = null;
- }
- private void BtnAddFur_Click(object sender, EventArgs e)
- {
- Furn frn = new Furn();
- frn.TitleFurn = TbxTitleFur.Text;
- frn.CountFurn = TbxCountFur.Text;
- frn.PhotoFurn = PbxPhotoFurn.Image;
- LstFurn.Add(frn);
- DgvFurn.Rows.Add(frn.TitleFurn, frn.CountFurn);
- }
- private void BtnDelFur_Click(object sender, EventArgs e)
- {
- int NumFurn = DgvFurn.CurrentRow.Index;
- if (NumFurn >= 0)
- {
- if (MessageBox.Show("Удалить выделенную фурнитуру?",
- "Внимание", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- LstFurn.RemoveAt(NumFurn);
- DgvFurn.Rows.RemoveAt(NumFurn);
- }
- }
- else
- MessageBox.Show("Фурнитура не выделена",
- "Внимание", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
- }
- }
- }
|