Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using FirebirdSql.Data.FirebirdClient;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace SKUDClient
- {
- public partial class register : Form
- {
- public string usertypereg;
- public string u;
- public register()
- {
- InitializeComponent();
- labelInfo.Text = Form3.toregfname + " " + Form3.toregname + " " + Form3.toregmiddlename;
- }
- private void register_Load(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(Form3.toregstaffid))
- {
- if (textBox2.Text == textBox3.Text)
- {
- if (!string.IsNullOrEmpty(usertypereg))
- {
- 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; ");
- if (fb1.State == ConnectionState.Closed)
- fb1.Open();
- FbTransaction fbt0 = fb1.BeginTransaction();
- FbCommand SelectSQL = new FbCommand("SELECT USERNAME FROM USERS WHERE USERNAME = @USERNAME;", fb1); //задаем запрос на выборку
- SelectSQL.Parameters.AddWithValue("@USERNAME", textBox1.Text);
- SelectSQL.Transaction = fbt0;
- FbDataReader reader = SelectSQL.ExecuteReader();
- while (reader.Read())
- {
- u = reader["USERNAME"].ToString();
- }
- if (!string.IsNullOrEmpty(u))
- {
- MessageBox.Show("Пользователь уже существует!" + u);
- textBox1.Clear();
- textBox2.Clear();
- textBox3.Clear();
- }
- else
- {
- fb1.Close();
- SelectSQL.Dispose();
- if (fb1.State == ConnectionState.Closed)
- fb1.Open();
- FbTransaction fbt = fb1.BeginTransaction(); //
- FbCommand InsertSQL = new FbCommand("INSERT INTO USERS (STAFF_ID, USERNAME, PASSWORD, TYPE) VALUES(@STAFF_ID, @USERNAME, @PASSWORD, @TYPE)", fb1);
- InsertSQL.Parameters.AddWithValue("@STAFF_ID", Form3.toregstaffid);
- InsertSQL.Parameters.AddWithValue("@USERNAME", textBox1.Text);
- InsertSQL.Parameters.AddWithValue("@PASSWORD", textBox2.Text);
- InsertSQL.Parameters.AddWithValue("@TYPE", usertypereg);
- InsertSQL.Transaction = fbt; //необходимо проинициализить транзакцию для объекта SelectSQL
- try
- {
- int res = InsertSQL.ExecuteNonQuery();
- fbt.Commit(); //если вставка прошла успешно - комитим транзакцию
- MessageBox.Show("Успешно добавлено!");
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- InsertSQL.Dispose();
- fb1.Close(); //закрываем соединение, т.к. оно нам больше не нужно
- }
- }
- else MessageBox.Show("Вы должны выбрать тип пользователя!");
- }
- else MessageBox.Show("Пароли не совпадают! ");
- }
- else MessageBox.Show("Сначала выберите пользователя!");
- }
- private void radioButton1_CheckedChanged(object sender, EventArgs e)
- {
- usertypereg = "0";
- }
- private void radioButton2_CheckedChanged(object sender, EventArgs e)
- {
- usertypereg = "1";
- }
- private void radioButton3_CheckedChanged(object sender, EventArgs e)
- {
- usertypereg = "2";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement