| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace SUBD_Medical_Staff
- {
- public partial class fAdd : Form
- {
-
- public static string txtCon = @"Data Source=DESKTOP-5VOE8QR\SQLEXPRESS;Initial Catalog=Personnel;Integrated Security=True";
-
- public fAdd()
- {
- InitializeComponent();
- }
-
- List<string> lstId = new List<string>();
- byte[] NewPhoto;
- void GetRole()
- {
- lstId.Clear();
- cbDolj.Items.Clear();
- SqlConnection con = new SqlConnection(Form1.txtCon);
- con.Open();
- string txt = "select * from Roles";
- SqlCommand com = new SqlCommand(txt, con);
- SqlDataReader rez = com.ExecuteReader();
- while (rez.Read())
- {
- lstId.Add(rez["IDRole"].ToString());
- cbDolj.Items.Add(rez["Role"].ToString());
- }
- con.Close();
- }
- private void fAdd_Load(object sender, EventArgs e)
- {
- GetRole();
- }
- string zapr1 = "";
- string zapr2 = "";
- private void bOk_Click(object sender, EventArgs e)
- {
- if (tbFam.Text != "" && tbName.Text != "" && tbOtch.Text != "" && tbPol.Text != "" && tbPhone.Text != "" && cbDolj.Text != "" )
- {
- SqlConnection con = new SqlConnection(txtCon);
- con.Open();
- string txt = $@"insert into Medical_staff(Name, Surname, Otch, Gender, Telephone, IDRole)
- values (N'{tbName.Text}', N'{tbFam.Text}', N'{tbOtch.Text}',N'{tbPol.Text}',N'{tbPhone.Text}',N'{lstId[cbDolj.SelectedIndex]}')";
- SqlCommand com = new SqlCommand(txt, con);
- com.ExecuteNonQuery();
- con.Close();
- string idnewuser = "";
- con.Open();
- txt = "select * from Medical_staff";
- com = new SqlCommand(txt, con);
- SqlDataReader rez = com.ExecuteReader();
- while (rez.Read())
- {
- idnewuser = rez["IDHuman"].ToString();
- }
- con.Close();
- con.Open();
- MemoryStream stream = new MemoryStream();
- pbImage.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
- NewPhoto = stream.ToArray();
- byte[] masImages = stream.ToArray();
- string txtqe = $@"update Medical_staff
- set Photo=@newphoto
- where IDHuman={idnewuser}";
- zapr2 = txtqe;
- com = new SqlCommand(txtqe, con);
- com.Parameters.AddWithValue("@newphoto", NewPhoto);
- com.ExecuteNonQuery();
- con.Close();
- NewPhoto = null;
- MessageBox.Show("Выполено!", "Внимание",
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- MessageBox.Show($"Запрос {zapr1}\nЗапрос2 {zapr2}");
- con.Close();
- }
- else
- {
- MessageBox.Show("Вы не ввели все данные");
- }
- }
- private void bCancel_Click(object sender, EventArgs e)
- {
- this.Hide();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- pbImage.Image = Properties.Resources.pngwing_com;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- openFileDialog1.Filter = "Image files(*.png; *.jpg; *jpeg; *.bmp)| *.png; *.jpg; *jpeg; *.bmp";
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- try
- {
- pbImage.Image = new Bitmap(openFileDialog1.FileName);
- }
- catch
- {
- MessageBox.Show("Невозможно открыть!", "Внимание",
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
-
- }
- }
|