Guest User

Untitled

a guest
Jan 8th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  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.Data.OleDb;
  10. using System.IO;
  11. using System.Windows.Forms;
  12.  
  13.  
  14. namespace tiny_basket
  15. {
  16. public partial class AddProduct : Form
  17. {
  18. public AddProduct()
  19. {
  20. InitializeComponent();
  21. }
  22.  
  23. private void button2_Click(object sender, EventArgs e)
  24. {
  25. this.Close();
  26. }
  27.  
  28. private void AddProduct_Load(object sender, EventArgs e)
  29. {
  30.  
  31. }
  32.  
  33. private void textBox1_KeyDown(object sender, KeyEventArgs e)
  34. {
  35. if (e.KeyValue == 13)
  36. textBox2.Focus();
  37. }
  38.  
  39.  
  40.  
  41. private void Price_KeyDown(object sender, KeyEventArgs e)
  42. {
  43. if (e.KeyValue == 13)
  44. button1.Focus();
  45. }
  46.  
  47. private void textBox2_KeyDown(object sender, KeyEventArgs e)
  48. {
  49. if (e.KeyValue == 13)
  50. Price.Focus();
  51. }
  52.  
  53. private void AddProduct_Click(object sender, EventArgs e)
  54. {
  55. {
  56. if (textBox1.Text == "")
  57. {
  58. MessageBox.Show("Заполните все поля.", "Ошибка.");
  59. }
  60. else
  61. {
  62. DataSet ds = new DataSet(); // создаем пока что пустой кэш данных
  63. DataTable dt = new DataTable(); // создаем пока что пустую таблицу данных
  64. dt.TableName = "Table"; // название таблицы
  65. dt.Columns.Add("Название"); // название колонок
  66. dt.Columns.Add("Где");
  67. dt.Columns.Add("Цена");
  68. ds.Tables.Add(dt); //в ds создается таблица, с названием и колонками, созданными выше
  69. foreach (DataGridViewRow r in dataGridView1.Rows) // пока в dataGridView1 есть строки
  70. {
  71. DataRow row = ds.Tables["Table"].NewRow(); // создаем новую строку в таблице, занесенной в ds
  72. row["Название"] = r.Cells[0].Value; //в столбец этой строки заносим данные из первого столбца dataGridView1
  73. row["Где"] = r.Cells[1].Value; // то же самое со вторыми столбцами
  74. row["Цена"] = r.Cells[2].Value; //то же самое с третьими столбцами
  75. ds.Tables["Table"].Rows.Add(row); //добавление всей этой строки в таблицу ds.
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
Add Comment
Please, Sign In to add comment