Nomenklatura.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 proba
  12. {
  13. enum RowState
  14. {
  15. Existed,
  16. New,
  17. ModifiedNew,
  18. Deleted
  19. }
  20. public partial class Nomenklatura : Form
  21. {
  22. DataBase dataBase = new DataBase();
  23. public Nomenklatura()
  24. {
  25. InitializeComponent();
  26. }
  27. private void CreateColumns()
  28. {
  29. dataGridView1.Columns.Add("id_tool", "Номер инструмента");
  30. dataGridView1.Columns.Add("id_view_tools", "Номер вида инструмента");
  31. dataGridView1.Columns.Add("name", "Наиенование");
  32. dataGridView1.Columns.Add("description", "Описание");
  33. dataGridView1.Columns.Add("price", "Цена");
  34. dataGridView1.Columns.Add("id_supplier", "Номер поставщика");
  35. dataGridView1.Columns.Add("data_manufacture", "Дата поставки");
  36. dataGridView1.Columns.Add("id_country", "Код страны");
  37. dataGridView1.Columns.Add("IsNew", String.Empty);
  38. }
  39. private void ReadSingleRow(DataGridView dgw, IDataRecord record)
  40. {
  41. dgw.Rows.Add(record.GetInt32(0), record.GetInt32(1), record.GetString(2), record.GetString(3), record.GetDouble(4), record.GetInt32(5), record.GetDateTime(6), record.GetInt32(7), RowState.ModifiedNew);
  42. }
  43. private void RefresDataGird(DataGridView dgw)
  44. {
  45. dgw.Rows.Clear();
  46. string queryString = $"Select * from Tools";
  47. SqlCommand command = new SqlCommand(queryString, dataBase.GetConnection());
  48. dataBase.openConnection();
  49. SqlDataReader reader = command.ExecuteReader();
  50. while (reader.Read())
  51. {
  52. ReadSingleRow(dgw, reader);
  53. }
  54. reader.Close();
  55. }
  56. private void Nomenklatura_Load(object sender, EventArgs e)
  57. {
  58. CreateColumns();
  59. RefresDataGird(dataGridView1);
  60. }
  61. private void button_back_Click(object sender, EventArgs e)
  62. {
  63. this.Hide();
  64. MainMenu mainMenu = new MainMenu();
  65. mainMenu.ShowDialog();
  66. }
  67. public void global_FormClosed(object sender, EventArgs e)
  68. {
  69. Application.Exit();
  70. }
  71. private void pictureBox2_Click(object sender, EventArgs e)
  72. {
  73. RefresDataGird(dataGridView1);
  74. }
  75. private void button_add_Click(object sender, EventArgs e)
  76. {
  77. this.Hide();
  78. Nomenklatura_add nomenklatura_Add = new Nomenklatura_add();
  79. nomenklatura_Add.ShowDialog();
  80. }
  81. private void button1_Click(object sender, EventArgs e)
  82. {
  83. Graphics g = this.CreateGraphics();
  84. bmp = new Bitmap(this.Size.Width, this.Size.Height, g);
  85. Graphics mg = Graphics.FromImage(bmp);
  86. mg.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, this.Size);
  87. printPreviewDialog1.ShowDialog();
  88. }
  89. Bitmap bmp;
  90. private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  91. {
  92. e.Graphics.DrawImage(bmp, 0, 0);
  93. }
  94. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  95. {
  96. }
  97. }
  98. }