private void button3_Click(object sender, EventArgs e) { String commandText = "UPDATE UserSet SET FirstName=@firstname, LastName=@lastname, JobTitle=@jobtitle, Email=@email, PhoneNumber=@phonenumber, HireDate=@hiredate, ManagerID=@managerid, Address_AddressID=@addressid, Username=@username WHERE UserID=@param"; string sConnection = Properties.Settings.Default.BD2ConnectionString; SqlConnection conn = new SqlConnection(); conn.ConnectionString = sConnection; conn.Open(); try { SqlCommand command = new SqlCommand(commandText, conn); command.Parameters.AddWithValue("@param", UserMonitor.pomoc); command.Parameters.AddWithValue("@firstname", textBox1.Text.ToString()); command.Parameters.AddWithValue("@lastname", textBox2.Text.ToString()); command.Parameters.AddWithValue("@jobtitle", comboBox1.Text.ToString()); command.Parameters.AddWithValue("@email", textBox4.Text.ToString()); maskedTextBox1.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; command.Parameters.AddWithValue("@phonenumber", Convert.ToInt32(maskedTextBox1.Text.ToString())); command.Parameters.AddWithValue("@hiredate", dateTimePicker1.Value.Date); command.Parameters.AddWithValue("@managerid", label10.Text.ToString()); command.Parameters.AddWithValue("@addressid", label11.Text.ToString()); command.Parameters.AddWithValue("@username", textBox3.Text.ToString()); command.ExecuteNonQuery(); conn.Close(); UserMonitor powrot = new UserMonitor(); powrot.Show(); this.Hide(); } catch (SqlException er) { String text = "There was an error reported by SQL Server, " + er.Message; MessageBox.Show(text, "ERROR"); } }
private void button3_Click(object sender, EventArgs e) { String commandText = "INSERT INTO UserSet VALUES(@firstname, @lastname, @jobtitle, @email, @phonenumber, @hiredate, @managerid, @addressid, @username)"; String commandText2 = "select count(*) from UserSet where Username = @param2"; string sConnection = Properties.Settings.Default.BD2ConnectionString; SqlConnection conn = new SqlConnection(); conn.ConnectionString = sConnection; conn.Open(); try { SqlCommand command2 = new SqlCommand(commandText2, conn); command2.Parameters.AddWithValue("@param2", textBox3.Text.ToString()); if (Convert.ToInt32(command2.ExecuteScalar()) > 0) { SqlCommand command = new SqlCommand(commandText, conn); command.Parameters.AddWithValue("@firstname", textBox1.Text.ToString()); command.Parameters.AddWithValue("@lastname", textBox2.Text.ToString()); command.Parameters.AddWithValue("jobtitle", comboBox1.Text.ToString()); command.Parameters.AddWithValue("@email", textBox4.Text.ToString()); maskedTextBox1.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; command.Parameters.AddWithValue("@phonenumber", Convert.ToInt32(maskedTextBox1.Text.ToString())); command.Parameters.Add("@hiredate", SqlDbType.Date).Value = dateTimePicker1.Value.Date; command.Parameters.AddWithValue("@managerid", label10.Text.ToString()); command.Parameters.AddWithValue("@addressid", label11.Text.ToString()); String pomoc = textBox1.Text.ToString().ToLower() + "." + Convert.ToString((Convert.ToInt32(command2.ExecuteScalar()) + 1)) + "." + textBox2.Text.ToString().ToLower(); command.Parameters.AddWithValue("@username", pomoc); username = pomoc; command.ExecuteNonQuery(); } else { SqlCommand command = new SqlCommand(commandText, conn); command.Parameters.AddWithValue("@firstname", textBox1.Text.ToString()); command.Parameters.AddWithValue("@lastname", textBox2.Text.ToString()); command.Parameters.AddWithValue("jobtitle", comboBox1.Text.ToString()); command.Parameters.AddWithValue("@email", textBox4.Text.ToString()); maskedTextBox1.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; command.Parameters.AddWithValue("@phonenumber", Convert.ToInt32(maskedTextBox1.Text.ToString())); command.Parameters.Add("@hiredate", SqlDbType.Date).Value = dateTimePicker1.Value.Date; command.Parameters.AddWithValue("@managerid", label10.Text.ToString()); command.Parameters.AddWithValue("@addressid", label11.Text.ToString()); command.Parameters.AddWithValue("@username", textBox1.Text.ToString().ToLower() + ".x." + textBox2.Text.ToString().ToLower()); username = textBox1.Text.ToString().ToLower() + ".x." + textBox2.Text.ToString().ToLower(); command.ExecuteNonQuery(); } setPassword ustawhaslo = new setPassword(); ustawhaslo.Show(); conn.Close(); UserMonitor powrot = new UserMonitor(); powrot.Show(); this.Hide(); } catch (SqlException er) { String text = "There was an error reported by SQL Server, " + er.Message; MessageBox.Show(text, "ERROR"); } }
private void button3_Click(object sender, EventArgs e) { UserMonitor paneluzytkownikow = new UserMonitor(); paneluzytkownikow.Show(); }