1
0

Form1.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace SUBD_Medical_Staff
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public static string txtCon = @"Data Source = (LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Personnel.mdf;Integrated Security = True; Connect Timeout = 30";
  17. struct Medic
  18. {
  19. public string id, fam, Name, Otch, pol, role, phone;
  20. public Image img;
  21. }
  22. List<Medic> lstCADR = new List<Medic>();
  23. ItemPanel CurrentItem;
  24. string uslovie = "";
  25. void GetData()
  26. {
  27. lstCADR.Clear();
  28. uslovie = "";
  29. if (cbFindPo.Text == "Фамилия" && tbFindTxt.Text != "")
  30. uslovie += string.Format(" and Surname LIKE '{0}%' ", tbFindTxt.Text);
  31. else if (cbFindPo.Text == "Имя")
  32. uslovie += string.Format(" and Name Like '{0}%' ", tbFindTxt.Text);
  33. else if (cbFindPo.Text == "Отчество")
  34. uslovie += string.Format(" and Otch Like '{0}%' ", tbFindTxt.Text);
  35. else if (cbFindPo.Text == "Телефон")
  36. uslovie += string.Format(" and Telephone LIKE '{0}%' ", tbFindTxt.Text);
  37. if (cbFindPol.Text != "Все")
  38. {
  39. if (cbFindPol.Text == "Мужчины")
  40. uslovie += " and Otch like '%ч' ";
  41. if (cbFindPol.Text == "Женщины")
  42. uslovie += " and Otch like '%а' ";
  43. }
  44. SqlConnection con = new SqlConnection(txtCon);
  45. con.Open();
  46. string txt = $@"select IDHuman, Surname, Name, Otch,Gender,Photo,Role,Telephone
  47. from Roles,Medical_staff
  48. where Roles.IDRole=Medical_staff.IDRole {uslovie}";
  49. SqlCommand com = new SqlCommand(txt, con);
  50. SqlDataReader rez = com.ExecuteReader();
  51. while (rez.Read())
  52. {
  53. Medic agent1 = new Medic();
  54. agent1.id = rez["IDHuman"].ToString();
  55. agent1.fam = rez["Surname"].ToString();
  56. agent1.Name = rez["Name"].ToString();
  57. agent1.Otch = rez["Otch"].ToString();
  58. agent1.pol = rez["Gender"].ToString();
  59. agent1.role = rez["Role"].ToString();
  60. agent1.phone = rez["Telephone"].ToString();
  61. byte[] masphoto = (byte[])rez["Photo"];
  62. MemoryStream msPhoto = new MemoryStream(masphoto);
  63. agent1.img = Image.FromStream(msPhoto);
  64. lstCADR.Add(agent1);
  65. }
  66. con.Close();
  67. }
  68. void FillPanel()
  69. {
  70. flowLayoutPanel1.Controls.Clear();
  71. foreach (Medic agent1 in lstCADR)
  72. {
  73. ItemPanel item = new ItemPanel();
  74. item.lFam.Text = agent1.fam;
  75. item.lid.Text = agent1.id;
  76. item.lName.Text = agent1.Name;
  77. item.lOtch.Text = agent1.Otch;
  78. item.lPhone.Text = agent1.phone;
  79. item.lPol.Text = agent1.pol;
  80. item.lRole.Text = agent1.role;
  81. item.pbImage.Image = agent1.img;
  82. flowLayoutPanel1.Controls.Add(item);
  83. }
  84. }
  85. class ItemPanel : Panel
  86. {
  87. //public System.Windows.Forms.Panel panel1;
  88. public System.Windows.Forms.Label lRole;
  89. public System.Windows.Forms.Label lAdr;
  90. public System.Windows.Forms.Label lOtch;
  91. public System.Windows.Forms.Label lName;
  92. public System.Windows.Forms.Label lFam;
  93. public System.Windows.Forms.PictureBox pbImage;
  94. public System.Windows.Forms.Label lPol;
  95. public System.Windows.Forms.Label lid;
  96. public System.Windows.Forms.Label lPhone;
  97. public ItemPanel()
  98. {
  99. //this.panel1 = new System.Windows.Forms.Panel();
  100. this.lid = new System.Windows.Forms.Label();
  101. this.lPol = new System.Windows.Forms.Label();
  102. this.lRole = new System.Windows.Forms.Label();
  103. this.lAdr = new System.Windows.Forms.Label();
  104. this.lOtch = new System.Windows.Forms.Label();
  105. this.lName = new System.Windows.Forms.Label();
  106. this.lFam = new System.Windows.Forms.Label();
  107. this.lPhone = new System.Windows.Forms.Label();
  108. this.pbImage = new System.Windows.Forms.PictureBox();
  109. //
  110. // panel1
  111. //
  112. this.BackColor = System.Drawing.Color.FromArgb(153, 189, 220);
  113. this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  114. this.Controls.Add(this.lid);
  115. this.Controls.Add(this.lPol);
  116. this.Controls.Add(this.lRole);
  117. this.Controls.Add(this.lAdr);
  118. this.Controls.Add(this.lOtch);
  119. this.Controls.Add(this.lName);
  120. this.Controls.Add(this.lFam);
  121. this.Controls.Add(this.lPhone);
  122. this.Controls.Add(this.pbImage);
  123. this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F);
  124. this.Location = new System.Drawing.Point(15, 178);
  125. this.Name = "panel1";
  126. this.Size = new System.Drawing.Size(950, 200);
  127. this.TabIndex = 0;
  128. //
  129. // lid
  130. //
  131. this.lid.AutoSize = true;
  132. this.lid.Location = new System.Drawing.Point(22, 188);
  133. this.lid.Name = "lid";
  134. this.lid.Size = new System.Drawing.Size(17, 17);
  135. this.lid.TabIndex = 7;
  136. this.lid.Text = "a";
  137. this.lid.Visible = false;
  138. //
  139. // lPol
  140. //
  141. this.lPol.AutoSize = true;
  142. this.lPol.Location = new System.Drawing.Point(200, 168);
  143. this.lPol.Name = "lPol";
  144. this.lPol.Size = new System.Drawing.Size(62, 17);
  145. this.lPol.TabIndex = 6;
  146. this.lPol.Text = "label1";
  147. //
  148. // lRole
  149. //
  150. this.lRole.AutoSize = true;
  151. this.lRole.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  152. this.lRole.Location = new System.Drawing.Point(200, 140);
  153. this.lRole.Name = "lRole";
  154. this.lRole.Size = new System.Drawing.Size(62, 17);
  155. this.lRole.TabIndex = 5;
  156. this.lRole.Text = "label1";
  157. //
  158. // lOtch
  159. //
  160. this.lOtch.AutoSize = true;
  161. this.lOtch.Font = new System.Drawing.Font("CMicrosoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  162. this.lOtch.Location = new System.Drawing.Point(200, 84);
  163. this.lOtch.Name = "lOTch";
  164. this.lOtch.Size = new System.Drawing.Size(62, 17);
  165. this.lOtch.TabIndex = 3;
  166. this.lOtch.Text = "label3";
  167. //
  168. // lName
  169. //
  170. this.lName.AutoSize = true;
  171. this.lName.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  172. this.lName.Location = new System.Drawing.Point(200, 56);
  173. this.lName.Name = "lName";
  174. this.lName.Size = new System.Drawing.Size(62, 17);
  175. this.lName.TabIndex = 2;
  176. this.lName.Text = "label2";
  177. //
  178. // lFam
  179. //
  180. this.lFam.AutoSize = true;
  181. this.lFam.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  182. this.lFam.Location = new System.Drawing.Point(200, 28);
  183. this.lFam.Name = "lFam";
  184. this.lFam.Size = new System.Drawing.Size(62, 17);
  185. this.lFam.TabIndex = 1;
  186. this.lFam.Text = "label1";
  187. //
  188. // lPhone
  189. //
  190. this.lPhone.AutoSize = true;
  191. this.lPhone.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  192. this.lPhone.Location = new System.Drawing.Point(200, 115);
  193. this.lPhone.Name = "lPhone";
  194. this.lPhone.Size = new System.Drawing.Size(62, 17);
  195. this.lPhone.TabIndex = 1;
  196. this.lPhone.Text = "label1";
  197. //
  198. // pbImage
  199. //
  200. this.pbImage.Location = new System.Drawing.Point(25, 28);
  201. this.pbImage.Name = "pbImage";
  202. this.pbImage.Size = new System.Drawing.Size(160, 160);
  203. this.pbImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
  204. this.pbImage.TabIndex = 0;
  205. this.pbImage.TabStop = false;
  206. }
  207. }
  208. public Form1()
  209. {
  210. InitializeComponent();
  211. }
  212. private void medical_staffBindingNavigatorSaveItem_Click(object sender, EventArgs e)
  213. {
  214. this.Validate();
  215. this.medical_staffBindingSource.EndEdit();
  216. this.tableAdapterManager.UpdateAll(this.personnelDataSet);
  217. }
  218. private void Form1_Load(object sender, EventArgs e)
  219. {
  220. //// TODO: This line of code loads data into the 'personnelDataSet.Roles' table. You can move, or remove it, as needed.
  221. //this.rolesTableAdapter.Fill(this.personnelDataSet.Roles);
  222. //// TODO: This line of code loads data into the 'personnelDataSet.Medical_staff' table. You can move, or remove it, as needed.
  223. //this.medical_staffTableAdapter.Fill(this.personnelDataSet.Medical_staff);
  224. GetData();
  225. FillPanel();
  226. }
  227. private void cbFindPo_SelectedIndexChanged(object sender, EventArgs e)
  228. {
  229. GetData();
  230. FillPanel();
  231. }
  232. private void cbFindPol_SelectedIndexChanged(object sender, EventArgs e)
  233. {
  234. GetData();
  235. FillPanel();
  236. }
  237. private void tbFindTxt_TextChanged(object sender, EventArgs e)
  238. {
  239. GetData();
  240. FillPanel();
  241. }
  242. private void button1_Click(object sender, EventArgs e)
  243. {
  244. fAdd f = new fAdd();
  245. f.Show();
  246. }
  247. }
  248. }