Advertisement
Guest User

Untitled

a guest
Nov 6th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. using FirebirdSql.Data.FirebirdClient;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace SKUDClient
  13. {
  14. public partial class register : Form
  15. {
  16. public string usertypereg;
  17. public string u;
  18. public register()
  19. {
  20. InitializeComponent();
  21.  
  22. labelInfo.Text = Form3.toregfname + " " + Form3.toregname + " " + Form3.toregmiddlename;
  23. }
  24.  
  25. private void register_Load(object sender, EventArgs e)
  26. {
  27.  
  28. }
  29.  
  30. private void button1_Click(object sender, EventArgs e)
  31. {
  32.  
  33. if (!string.IsNullOrEmpty(Form3.toregstaffid))
  34. {
  35. if (textBox2.Text == textBox3.Text)
  36. {
  37. if (!string.IsNullOrEmpty(usertypereg))
  38. {
  39. FbConnection fb1 = new FbConnection(@"User = SYSDBA; Password = masterkey; Database = " + Form1.usersdbpath + "; DataSource = " + Form1.fbhost + ";Port = " + Form1.fbport + "; Dialect = 3; Charset = UTF8; Role =; Connection lifetime = 15; Pooling = true;MinPoolSize = 0; MaxPoolSize = 50; Packet Size = 8192; ServerType = 0; ");
  40.  
  41.  
  42.  
  43. if (fb1.State == ConnectionState.Closed)
  44. fb1.Open();
  45.  
  46.  
  47. FbTransaction fbt0 = fb1.BeginTransaction();
  48. FbCommand SelectSQL = new FbCommand("SELECT USERNAME FROM USERS WHERE USERNAME = @USERNAME;", fb1); //задаем запрос на выборку
  49. SelectSQL.Parameters.AddWithValue("@USERNAME", textBox1.Text);
  50. SelectSQL.Transaction = fbt0;
  51. FbDataReader reader = SelectSQL.ExecuteReader();
  52.  
  53.  
  54. while (reader.Read())
  55. {
  56. u = reader["USERNAME"].ToString();
  57.  
  58.  
  59. }
  60.  
  61. if (!string.IsNullOrEmpty(u))
  62. {
  63. MessageBox.Show("Пользователь уже существует!" + u);
  64. textBox1.Clear();
  65. textBox2.Clear();
  66. textBox3.Clear();
  67. }
  68. else
  69. {
  70.  
  71.  
  72. fb1.Close();
  73. SelectSQL.Dispose();
  74.  
  75. if (fb1.State == ConnectionState.Closed)
  76. fb1.Open();
  77.  
  78. FbTransaction fbt = fb1.BeginTransaction(); //
  79.  
  80. FbCommand InsertSQL = new FbCommand("INSERT INTO USERS (STAFF_ID, USERNAME, PASSWORD, TYPE) VALUES(@STAFF_ID, @USERNAME, @PASSWORD, @TYPE)", fb1);
  81. InsertSQL.Parameters.AddWithValue("@STAFF_ID", Form3.toregstaffid);
  82. InsertSQL.Parameters.AddWithValue("@USERNAME", textBox1.Text);
  83. InsertSQL.Parameters.AddWithValue("@PASSWORD", textBox2.Text);
  84. InsertSQL.Parameters.AddWithValue("@TYPE", usertypereg);
  85.  
  86. InsertSQL.Transaction = fbt; //необходимо проинициализить транзакцию для объекта SelectSQL
  87.  
  88. try
  89. {
  90.  
  91. int res = InsertSQL.ExecuteNonQuery();
  92. fbt.Commit(); //если вставка прошла успешно - комитим транзакцию
  93. MessageBox.Show("Успешно добавлено!");
  94.  
  95. }
  96. catch (Exception ex)
  97. {
  98. MessageBox.Show(ex.Message);
  99.  
  100. }
  101. InsertSQL.Dispose();
  102. fb1.Close(); //закрываем соединение, т.к. оно нам больше не нужно
  103.  
  104.  
  105. }
  106.  
  107. }
  108. else MessageBox.Show("Вы должны выбрать тип пользователя!");
  109. }
  110. else MessageBox.Show("Пароли не совпадают! ");
  111. }
  112. else MessageBox.Show("Сначала выберите пользователя!");
  113. }
  114.  
  115. private void radioButton1_CheckedChanged(object sender, EventArgs e)
  116. {
  117. usertypereg = "0";
  118. }
  119.  
  120. private void radioButton2_CheckedChanged(object sender, EventArgs e)
  121. {
  122. usertypereg = "1";
  123. }
  124.  
  125. private void radioButton3_CheckedChanged(object sender, EventArgs e)
  126. {
  127. usertypereg = "2";
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement