private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text) || string.IsNullOrEmpty(textBox3.Text) || string.IsNullOrEmpty(textBox4.Text) || string.IsNullOrEmpty(textBox5.Text) || string.IsNullOrEmpty(textBox6.Text)) { MessageBox.Show("Нужно заполнить все поля!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!isMatch) { MessageBox.Show("Пароли не совпадают!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } try { conn_string.Server = textBox1.Text; conn_string.UserID = textBox2.Text; conn_string.Password = textBox3.Text; conn_string.Database = "itweek"; MySqlConnection connection = new MySqlConnection(conn_string.ToString()); connection.Open(); connection.Close(); }catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string sdata = textBox1.Text + "\n" + textBox2.Text + "\n" + textBox3.Text; byte[] data = Encoding.ASCII.GetBytes(sdata); try { string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\itweek\\user\\" + textBox4.Text; if (!Directory.Exists(Path.GetDirectoryName(path))) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } RCC5 rcc5 = new RCC5(Encoding.ASCII.GetBytes(textBox5.Text)); byte[] edata = rcc5.Encode(data); FileStream stream = File.Create(path); stream.Write(edata, 0, edata.Length); stream.Close(); //conninfo = new ConnInfo(textBox1.Text, textBox2.Text, textBox3.Text); DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
private void button1_Click(object sender, EventArgs e) { string dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\itweek\\user"; if (Directory.GetFiles(dir).Length == 0) { MessageBox.Show("Файл пользователя не найден! Перезапустите программу.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("Заполните поле!", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } try { RCC5 rcc5 = new RCC5(Encoding.ASCII.GetBytes(textBox1.Text)); byte[] edata = File.ReadAllBytes(Directory.GetFiles(dir)[0]); byte[] data = rcc5.Decode(edata); string sdata = Encoding.ASCII.GetString(data); string[] msdata = sdata.Split('\n'); conn_string.Server = msdata[0]; conn_string.UserID = msdata[1]; conn_string.Password = msdata[2]; conn_string.Database = "usersitweek"; MySqlConnection connection = new MySqlConnection(conn_string.ToString()); connection.Open(); connection.Close(); DialogResult = DialogResult.OK; Close(); }catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }