FormZak.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace СУБД_Фабрика
  12. {
  13. public partial class FormZak : Form
  14. {
  15. public FormZak()
  16. {
  17. InitializeComponent();
  18. }
  19. SqlConnection Con = new SqlConnection(FormMain.txtCon);
  20. public class ClothPanel : Panel
  21. {
  22. public System.Windows.Forms.Label LblComment;
  23. public System.Windows.Forms.Label LblLenght;
  24. public System.Windows.Forms.Label LblTitle;
  25. public System.Windows.Forms.Label LblWidth;
  26. public System.Windows.Forms.Label LblColor;
  27. public System.Windows.Forms.PictureBox PbxPhoto;
  28. public ClothPanel()
  29. {
  30. this.LblColor = new System.Windows.Forms.Label();
  31. this.LblWidth = new System.Windows.Forms.Label();
  32. this.LblTitle = new System.Windows.Forms.Label();
  33. this.LblLenght = new System.Windows.Forms.Label();
  34. this.LblComment = new System.Windows.Forms.Label();
  35. this.PbxPhoto = new System.Windows.Forms.PictureBox();
  36. this.SuspendLayout();
  37. ((System.ComponentModel.ISupportInitialize)(this.PbxPhoto)).BeginInit();
  38. this.SuspendLayout();
  39. //
  40. // panel1
  41. //
  42. this.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  43. | System.Windows.Forms.AnchorStyles.Right)));
  44. this.BackColor = System.Drawing.Color.WhiteSmoke;
  45. this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  46. this.Controls.Add(this.LblComment);
  47. this.Controls.Add(this.LblLenght);
  48. this.Controls.Add(this.LblTitle);
  49. this.Controls.Add(this.LblWidth);
  50. this.Controls.Add(this.LblColor);
  51. this.Controls.Add(this.PbxPhoto);
  52. this.Font = new System.Drawing.Font("Arial Narrow", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
  53. this.Location = new System.Drawing.Point(38, 53);
  54. this.Name = "panel1";
  55. this.Size = new System.Drawing.Size(391, 132);
  56. this.TabIndex = 0;
  57. //
  58. // LblColor
  59. //
  60. this.LblColor.AutoSize = true;
  61. this.LblColor.Location = new System.Drawing.Point(141, 38);
  62. this.LblColor.Name = "LblColor";
  63. this.LblColor.Size = new System.Drawing.Size(35, 16);
  64. this.LblColor.TabIndex = 1;
  65. this.LblColor.Text = "label1";
  66. //
  67. // LblWidth
  68. //
  69. this.LblWidth.AutoSize = true;
  70. this.LblWidth.Location = new System.Drawing.Point(141, 64);
  71. this.LblWidth.Name = "LblWidth";
  72. this.LblWidth.Size = new System.Drawing.Size(35, 16);
  73. this.LblWidth.TabIndex = 2;
  74. this.LblWidth.Text = "label2";
  75. //
  76. // LblTitle
  77. //
  78. this.LblTitle.AutoSize = true;
  79. this.LblTitle.Location = new System.Drawing.Point(141, 13);
  80. this.LblTitle.Name = "LblTitle";
  81. this.LblTitle.Size = new System.Drawing.Size(35, 16);
  82. this.LblTitle.TabIndex = 3;
  83. this.LblTitle.Text = "label3";
  84. //
  85. // LblLenght
  86. //
  87. this.LblLenght.AutoSize = true;
  88. this.LblLenght.Location = new System.Drawing.Point(141, 80);
  89. this.LblLenght.Name = "LblLenght";
  90. this.LblLenght.Size = new System.Drawing.Size(35, 16);
  91. this.LblLenght.TabIndex = 4;
  92. this.LblLenght.Text = "label4";
  93. //
  94. // LblComment
  95. //
  96. this.LblComment.AutoSize = true;
  97. this.LblComment.Location = new System.Drawing.Point(141, 102);
  98. this.LblComment.Name = "LblComment";
  99. this.LblComment.Size = new System.Drawing.Size(35, 16);
  100. this.LblComment.TabIndex = 5;
  101. this.LblComment.Text = "label5";
  102. //
  103. // PbxPhoto
  104. //
  105. this.PbxPhoto.Location = new System.Drawing.Point(12, 13);
  106. this.PbxPhoto.Name = "PbxPhoto";
  107. this.PbxPhoto.Size = new System.Drawing.Size(123, 105);
  108. this.PbxPhoto.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
  109. this.PbxPhoto.TabIndex = 0;
  110. this.PbxPhoto.TabStop = false;
  111. }
  112. }
  113. public class FurnPanel : Panel
  114. {
  115. public System.Windows.Forms.PictureBox PbxPhoto;
  116. public System.Windows.Forms.Label LblCount;
  117. public System.Windows.Forms.Label LblTitle;
  118. public FurnPanel()
  119. {
  120. this.PbxPhoto = new System.Windows.Forms.PictureBox();
  121. this.LblCount = new System.Windows.Forms.Label();
  122. this.LblTitle = new System.Windows.Forms.Label();
  123. ((System.ComponentModel.ISupportInitialize)(this.PbxPhoto)).BeginInit();
  124. this.SuspendLayout();
  125. this.SuspendLayout();
  126. //
  127. // PbxPhoto
  128. //
  129. this.PbxPhoto.Location = new System.Drawing.Point(29, 3);
  130. this.PbxPhoto.Name = "PbxPhoto";
  131. this.PbxPhoto.Size = new System.Drawing.Size(123, 105);
  132. this.PbxPhoto.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
  133. this.PbxPhoto.TabIndex = 0;
  134. this.PbxPhoto.TabStop = false;
  135. //
  136. // LblCount
  137. //
  138. this.LblCount.AutoSize = true;
  139. this.LblCount.Location = new System.Drawing.Point(13, 150);
  140. this.LblCount.Name = "LblCount";
  141. this.LblCount.Size = new System.Drawing.Size(35, 16);
  142. this.LblCount.TabIndex = 1;
  143. this.LblCount.Text = "label1";
  144. //
  145. // LblTitle
  146. //
  147. this.LblTitle.AutoSize = true;
  148. this.LblTitle.Location = new System.Drawing.Point(13, 122);
  149. this.LblTitle.Name = "LblTitle";
  150. this.LblTitle.Size = new System.Drawing.Size(35, 16);
  151. this.LblTitle.TabIndex = 3;
  152. this.LblTitle.Text = "label3";
  153. //
  154. // panel1
  155. //
  156. this.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  157. | System.Windows.Forms.AnchorStyles.Right)));
  158. this.BackColor = System.Drawing.Color.WhiteSmoke;
  159. this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  160. this.Controls.Add(this.PbxPhoto);
  161. this.Controls.Add(this.LblTitle);
  162. this.Controls.Add(this.LblCount);
  163. this.Font = new System.Drawing.Font("Arial Narrow", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
  164. this.Location = new System.Drawing.Point(69, 53);
  165. this.Name = "panel1";
  166. this.Size = new System.Drawing.Size(451, 185);
  167. this.TabIndex = 0;
  168. }
  169. }
  170. void FillClothes()
  171. {
  172. string txtQuery = "SELECT Title, Color, Width, Length, Comment, Photo FROM Cloth";
  173. Con.Open();
  174. SqlCommand query = new SqlCommand(txtQuery, Con);
  175. SqlDataReader res = query.ExecuteReader();
  176. while (res.Read())
  177. {
  178. ClothPanel cp = new ClothPanel();
  179. cp.LblTitle.Text = "Название " + res["Title"].ToString();
  180. cp.LblColor.Text = "Цвет: " + res["Color"].ToString();
  181. cp.LblLenght.Text = "Длина: " + res["Length"].ToString();
  182. cp.LblWidth.Text = "Ширина: " + res["Width"].ToString();
  183. cp.LblComment.Text = "Описание: " + res["Comment"].ToString();
  184. try
  185. {
  186. cp.PbxPhoto.Image = Image.FromFile(Application.StartupPath + "\\Clothes\\" + res["Photo"]);
  187. }
  188. catch
  189. {
  190. cp.PbxPhoto.Image = Image.FromFile(Application.StartupPath + "\\Picture.png");
  191. }
  192. PanelClothes.Controls.Add(cp);
  193. }
  194. Con.Close();
  195. }
  196. void FillFur()
  197. {
  198. string txtQuery = "SELECT namefur, photo, countfur FROM Furnitura";
  199. Con.Open();
  200. SqlCommand query = new SqlCommand(txtQuery, Con);
  201. SqlDataReader res = query.ExecuteReader();
  202. while (res.Read())
  203. {
  204. FurnPanel fp = new FurnPanel();
  205. fp.LblTitle.Text = "Название " + res["namefur"].ToString();
  206. fp.LblCount.Text = "Кол-во на складе: " + res["countfur"].ToString();
  207. try
  208. {
  209. fp.PbxPhoto.Image = Image.FromFile(Application.StartupPath + "\\Furn\\" + res["Photo"]);
  210. }
  211. catch
  212. {
  213. fp.PbxPhoto.Image = Image.FromFile(Application.StartupPath + "\\Picture.png");
  214. }
  215. PanelFurn.Controls.Add(fp);
  216. }
  217. Con.Close();
  218. }
  219. void FillOrders()
  220. {
  221. string txtQuery = $@"SELECT Izdelia.Title as Izd, Users.Fam, Cloth.Title AS Cloth, Furnitura.namefur, Orders.CountFur, Orders.CountIzd
  222. FROM Cloth INNER JOIN
  223. Orders ON Cloth.IDCloth = Orders.IDCloth INNER JOIN
  224. Furnitura ON Orders.IDFur = Furnitura.idfur INNER JOIN
  225. Izdelia ON Orders.IDIzd = Izdelia.IDIzd INNER JOIN
  226. Users ON Orders.IDMen = Users.IDUser
  227. where Users.Role = 2 and Orders.IDZak = {FormMain.IDUser}";
  228. Con.Open();
  229. SqlCommand query = new SqlCommand(txtQuery, Con);
  230. SqlDataReader res = query.ExecuteReader();
  231. int i = 0;
  232. while (res.Read())
  233. {
  234. DgvOrders.Rows.Add();
  235. DgvOrders.Rows[i].Cells[0].Value = res["Izd"].ToString();
  236. DgvOrders.Rows[i].Cells[1].Value = (res["Fam"].ToString());
  237. DgvOrders.Rows[i].Cells[2].Value = (res["Cloth"].ToString());
  238. DgvOrders.Rows[i].Cells[3].Value = (res["namefur"].ToString());
  239. DgvOrders.Rows[i].Cells[4].Value = (res["CountFur"].ToString());
  240. DgvOrders.Rows[i].Cells[5].Value = (res["CountIzd"].ToString());
  241. i++;
  242. }
  243. Con.Close();
  244. }
  245. private void FormZak_Load(object sender, EventArgs e)
  246. {
  247. // TODO: This line of code loads data into the 'sewingFactoryMURDataSet1.Izdelia' table. You can move, or remove it, as needed.
  248. this.izdeliaTableAdapter.Fill(this.sewingFactoryMURDataSet1.Izdelia);
  249. // TODO: This line of code loads data into the 'sewingFactoryMURDataSet1.Users' table. You can move, or remove it, as needed.
  250. this.usersTableAdapter.Fill(this.sewingFactoryMURDataSet1.Users);
  251. BsUsers.Filter = $"IDUser = {FormMain.IDUser}";
  252. FillFur();
  253. FillClothes();
  254. FillOrders();
  255. }
  256. private void BtnProfile_Click(object sender, EventArgs e)
  257. {
  258. FormProfile FrmProf = new FormProfile();
  259. if(FrmProf.ShowDialog() == DialogResult.OK)
  260. {
  261. this.usersTableAdapter.Fill(this.sewingFactoryMURDataSet1.Users);
  262. }
  263. }
  264. private void BtnAddZak_Click(object sender, EventArgs e)
  265. {
  266. FormAddOrder FrmAddOrd = new FormAddOrder();
  267. FrmAddOrd.ShowDialog();
  268. FillOrders();
  269. }
  270. private void BtnLevin_Click(object sender, EventArgs e)
  271. {
  272. FormLevin FrmLev = new FormLevin();
  273. FrmLev.ShowDialog();
  274. }
  275. }
  276. }