Main.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11. namespace project
  12. {
  13. public partial class Main : Form
  14. {
  15. public static string login;
  16. DataBase dataBase = new DataBase();
  17. public Main()
  18. {
  19. InitializeComponent();
  20. }
  21. private void ReadSingleRow(DataGridView dgw, IDataRecord record)
  22. {
  23. dgw.Rows.Add(record.GetInt32(0), record.GetString(1), record.GetString(2), record.GetString(3), record.GetString(4), record.GetString(5));
  24. }
  25. private void RefresDataGird(DataGridView dgw)
  26. {
  27. dgw.Rows.Clear();
  28. string queryString = $"Select * from Dannye";
  29. SqlCommand command = new SqlCommand(queryString, dataBase.GetConnection());
  30. dataBase.openConnection();
  31. SqlDataReader reader = command.ExecuteReader();
  32. while (reader.Read())
  33. {
  34. ReadSingleRow(dgw, reader);
  35. }
  36. reader.Close();
  37. }
  38. private void CreateColumns()
  39. {
  40. dataGridView1.Columns.Add("code", "Номер");
  41. dataGridView1.Columns.Add("name_dan", "Наименование");
  42. dataGridView1.Columns.Add("adres_dan", "Адрес");
  43. dataGridView1.Columns.Add("city_dan", "Город");
  44. dataGridView1.Columns.Add("number_dan", "Телефон");
  45. dataGridView1.Columns.Add("contact_dan", "Контактная информация");
  46. }
  47. private void Main_FormClosed(object sender, FormClosedEventArgs e)
  48. {
  49. Application.Exit();
  50. }
  51. private void Main_Load(object sender, EventArgs e)
  52. {
  53. CreateColumns();
  54. RefresDataGird(dataGridView1);
  55. string proverkaLogin = Login.login;
  56. dataBase.openConnection();
  57. SqlCommand sqlCommand2 = new SqlCommand($"SELECT administrator From Employee WHERE login = '{proverkaLogin}'", dataBase.GetConnection());
  58. string admPolzovatel = sqlCommand2.ExecuteScalar().ToString();
  59. if (admPolzovatel.Trim() == "true")
  60. {
  61. button1.Visible = true;
  62. button2.Visible = true;
  63. }
  64. }
  65. private void pictureBox1_Click(object sender, EventArgs e)
  66. {
  67. Profile profile = new Profile();
  68. profile.Show();
  69. }
  70. private void button1_Click(object sender, EventArgs e)
  71. {
  72. }
  73. private void button2_Click(object sender, EventArgs e)
  74. {
  75. }
  76. }
  77. }