fGetMaterial.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Drawing.Imaging;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace garment_factory
  14. {
  15. public partial class fGetMaterial : Form
  16. {
  17. public fGetMaterial()
  18. {
  19. InitializeComponent();
  20. }
  21. public struct Tkani
  22. {
  23. public string NameTkan, ColorTkan, WidthTkan, LengthTkan, Description;
  24. public Image PhotoTkan;
  25. }
  26. List<Tkani> LstTkani = new List<Tkani>();
  27. public struct Fur
  28. {
  29. public string NameFur, Count;
  30. public Image PhotoFur;
  31. }
  32. List<Fur> LstFur = new List<Fur>();
  33. private void fGetMaterial_Load(object sender, EventArgs e)
  34. {
  35. if (Tkan1.SelectedIndex == 0) TbxColorTkan.Text = "1";
  36. }
  37. private void DelFurnit_Click(object sender, EventArgs e)
  38. {
  39. int NumFur = dgvFur.CurrentRow.Index;
  40. if (NumFur >= 0)
  41. {
  42. DialogResult res = MessageBox.Show("Удалить выделенную ткань?",
  43. "Внимание!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  44. if (res == DialogResult.Yes)
  45. {
  46. LstFur.RemoveAt(NumFur);
  47. dgvFur.Rows.RemoveAt(NumFur);
  48. }
  49. }
  50. }
  51. private void BtnLoadPhotoTkan_Click(object sender, EventArgs e)
  52. {
  53. try
  54. {
  55. if (openFileDialog1.ShowDialog() == DialogResult.OK)
  56. PbxPhotoTkan.Image = Image.FromFile(openFileDialog1.FileName);
  57. }
  58. catch { }
  59. }
  60. private void BtnClearPhotoTkan_Click(object sender, EventArgs e)
  61. {
  62. DialogResult res = MessageBox.Show("Очистить фотографию?", "Внимание!",
  63. MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  64. if (res == DialogResult.Yes)
  65. PbxPhotoTkan.Image = null;
  66. }
  67. private void BtnAddTkan_Click(object sender, EventArgs e)
  68. {
  69. if (Tkan1.SelectedIndex == 0) TbxColorTkan.Text = "1";
  70. else if (Tkan1.SelectedIndex == 1) TbxColorTkan.Text = "2";
  71. else if (Tkan1.SelectedIndex == 2) TbxColorTkan.Text = "3";
  72. else if (Tkan1.SelectedIndex == 3) TbxColorTkan.Text = "4";
  73. else if (Tkan1.SelectedIndex == 4) TbxColorTkan.Text = "5";
  74. else if (Tkan1.SelectedIndex == 5) TbxColorTkan.Text = "6";
  75. else if (Tkan1.SelectedIndex == 6) TbxColorTkan.Text = "7";
  76. else if (Tkan1.SelectedIndex == 7) TbxColorTkan.Text = "8";
  77. else if (Tkan1.SelectedIndex == 8) TbxColorTkan.Text = "9";
  78. else if (Tkan1.SelectedIndex == 9) TbxColorTkan.Text = "10";
  79. else if (Tkan1.SelectedIndex == 10) TbxColorTkan.Text = "10";
  80. else if (Tkan1.SelectedIndex == 12) TbxColorTkan.Text = "12";
  81. else if (Tkan1.SelectedIndex == 13) TbxColorTkan.Text = "13";
  82. else if (Tkan1.SelectedIndex == 14) TbxColorTkan.Text = "14";
  83. else TbxColorTkan.Text = "15";
  84. Tkani Tk1 = new Tkani();
  85. Tk1.NameTkan = TbxNameTkan.Text;
  86. Tk1.ColorTkan = TbxColorTkan.Text;
  87. Tk1.WidthTkan = TbxWidthTkan.Text;
  88. Tk1.LengthTkan = TbxLengthTkan.Text;
  89. Tk1.Description = TbxDescriptionTkan.Text;
  90. Tk1.PhotoTkan = PbxPhotoTkan.Image;
  91. LstTkani.Add(Tk1);
  92. DgvTkani.Rows.Add(Tk1.NameTkan, Tk1.ColorTkan, Tk1.WidthTkan, Tk1.LengthTkan, Tk1.Description);
  93. }
  94. private void BtnDelTkan_Click(object sender, EventArgs e)
  95. {
  96. int NumTkan = DgvTkani.CurrentRow.Index;
  97. if (NumTkan >= 0)
  98. {
  99. DialogResult res = MessageBox.Show("Удалить выделенную ткань?",
  100. "Внимание!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  101. if (res == DialogResult.Yes)
  102. {
  103. LstTkani.RemoveAt(NumTkan);
  104. DgvTkani.Rows.RemoveAt(NumTkan);
  105. }
  106. }
  107. }
  108. private void BtnOK_Click(object sender, EventArgs e)
  109. {
  110. SqlConnection con = new SqlConnection(Properties.Settings.Default.Fabrika2024ConnectionString);
  111. foreach (Tkani Tk1 in LstTkani)
  112. {
  113. con.Open();
  114. if (Tk1.PhotoTkan != null)
  115. {
  116. string t = string.Format(@"
  117. insert into Tkani (Nazvanie, id_cvet, Shirina, Dlina, Primechanie, Photo)
  118. values ('{0}', '{1}', {2}, {3}, '{4}', @phototkan)",
  119. Tk1.NameTkan, Tk1.ColorTkan, Tk1.WidthTkan, Tk1.LengthTkan, Tk1.Description);
  120. SqlCommand query1 = new SqlCommand(t, con);
  121. MemoryStream ms = new MemoryStream();
  122. Tk1.PhotoTkan.Save(ms, ImageFormat.Jpeg);
  123. query1.Parameters.AddWithValue("@phototkan", ms.ToArray());
  124. query1.ExecuteNonQuery();
  125. }
  126. else
  127. {
  128. string t = string.Format(@"
  129. insert into Tkani (Nazvanie, id_cvet, Shirina, Dlina, Primechanie)
  130. values ('{0}', '{1}', {2}, {3}, '{4}')",
  131. Tk1.NameTkan, Tk1.ColorTkan, Tk1.WidthTkan, Tk1.LengthTkan, Tk1.Description);
  132. SqlCommand query1 = new SqlCommand(t, con);
  133. query1.ExecuteNonQuery();
  134. }
  135. con.Close();
  136. }
  137. SqlConnection con1 = new SqlConnection(Properties.Settings.Default.Fabrika2024ConnectionString);
  138. foreach (Fur Fur1 in LstFur)
  139. {
  140. con1.Open();
  141. if (Fur1.PhotoFur != null)
  142. {
  143. string t = string.Format(@"insert into Furnitura (namefur,photo,countfur) values ('{0}', '{1}', {2})", Fur1.NameFur, Fur1.PhotoFur, int.Parse(Fur1.Count));
  144. SqlCommand query1 = new SqlCommand(t, con1);
  145. MemoryStream ms = new MemoryStream();
  146. Fur1.PhotoFur.Save(ms, ImageFormat.Jpeg);
  147. query1.Parameters.AddWithValue("@photo", ms.ToArray());
  148. query1.ExecuteNonQuery();
  149. }
  150. else
  151. {
  152. string t = string.Format(@"insert into Furnitura (namefur,countfur) values ('{0}', '{1}')", Fur1.NameFur, int.Parse(Fur1.Count));
  153. SqlCommand query1 = new SqlCommand(t, con1);
  154. query1.ExecuteNonQuery();
  155. }
  156. con1.Close();
  157. }
  158. MessageBox.Show("Документ принят к учету.", "Внимание!",
  159. MessageBoxButtons.OK, MessageBoxIcon.Information);
  160. this.Close();
  161. }
  162. private void btnaddPhotofurnit_Click(object sender, EventArgs e)
  163. {
  164. try
  165. {
  166. if (openFileDialog1.ShowDialog() == DialogResult.OK)
  167. pictureBox2.Image = Image.FromFile(openFileDialog1.FileName);
  168. }
  169. catch { }
  170. }
  171. private void btndelPhotofurnit_Click(object sender, EventArgs e)
  172. {
  173. DialogResult res = MessageBox.Show("Очистить фотографию?", "Внимание!",
  174. MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  175. if (res == DialogResult.Yes)
  176. pictureBox2.Image = null;
  177. }
  178. private void AddFurnitura_Click(object sender, EventArgs e)
  179. {
  180. Fur Tk1 = new Fur();
  181. Tk1.NameFur = tbxNameFur.Text;
  182. Tk1.Count = tbxCount.Text;
  183. Tk1.PhotoFur = pictureBox2.Image;
  184. LstFur.Add(Tk1);
  185. dgvFur.Rows.Add(Tk1.NameFur, Tk1.Count);
  186. }
  187. private void BtnCancel_Click(object sender, EventArgs e)
  188. {
  189. DialogResult = DialogResult.Cancel;
  190. }
  191. }
  192. }