private void login() { UserPictureBox.Invoke(new Action (() => UserPictureBox.LoadAsync(m_AppLogic.LoggedInUser.PictureNormalURL))); ButtonFirstLiker.Invoke(new Action(() => ButtonFirstLiker.Enabled = true)); ShowLikesListBtn.Invoke(new Action(() => ShowLikesListBtn.Enabled = true)); ButtonFetchFriends.Invoke(new Action(() => ButtonFetchFriends.Enabled = true)); ButtonFetchAlbums.Invoke(new Action(() => ButtonFetchAlbums.Enabled = true)); ButtonPost.Invoke(new Action(() => ButtonPost.Enabled = true)); this.Invoke(new Action(() => this.Text = "Logged in as: " + m_AppLogic.LoggedInUser.Name)); this.Invoke(new Action(() => this.listBoxAlbums.SelectedIndexChanged += ListBoxAlbums_SelectedIndexChanged)); }
private void FileDialog_Btn_Click(object sender, EventArgs e) { try { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Image files (*.jpg)|*.jpg"; if (openFileDialog.ShowDialog() == DialogResult.OK) { UserPictureBox.Load(openFileDialog.FileName); } } catch (Exception ex) { WriteLog.WriteLogger(ex.ToString()); } }
private void btnCreate_Click(object sender, EventArgs e) { if (txtUserId.Text.Length == 0) { errorProvider1.SetError(txtUserId, "User Id"); MessageBox.Show("User id is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtUserId, ""); txtUserId.Focus(); return; } else if (txtPassword.Text.Length == 0) { errorProvider1.SetError(txtPassword, "User Id"); MessageBox.Show("Password is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtPassword, ""); txtPassword.Focus(); return; } else if (txtRePassword.Text.Length == 0) { errorProvider1.SetError(txtRePassword, "User Id"); MessageBox.Show("Re-Password is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtRePassword, ""); txtRePassword.Focus(); return; } else if (txtEmail.Text.Length == 0) { errorProvider1.SetError(txtEmail, "User Id"); MessageBox.Show("Email is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtEmail, ""); txtEmail.Focus(); return; } else if (cmbType.SelectedIndex == 0) { errorProvider1.SetError(cmbType, "User Id"); MessageBox.Show("Select user type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(cmbType, ""); cmbType.Focus(); return; } else if (cmbQuestion.SelectedIndex == 0) { errorProvider1.SetError(cmbQuestion, "User Id"); MessageBox.Show("Select question", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(cmbQuestion, ""); cmbQuestion.Focus(); return; } else if (txtAnswer.Text.Length == 0) { errorProvider1.SetError(txtAnswer, "User Id"); MessageBox.Show("Answer is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtAnswer, ""); txtAnswer.Focus(); return; } else if (UserPictureBox.Image == null) { errorProvider1.SetError(UserPictureBox, "User Id"); MessageBox.Show("Choose user image", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(UserPictureBox, ""); UserPictureBox.Focus(); return; } else { if (txtPassword.Text != txtRePassword.Text) { MessageBox.Show("Password and confirm password do not matched !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { try { byte[] img = null; FileStream fstream = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fstream); img = br.ReadBytes((int)fstream.Length); using (con = new SqlConnection(ConStr)) { using (com = new SqlCommand("insert into Users values('" + txtUserId.Text.Trim() + "','" + txtPassword.Text.Trim() + "','" + txtRePassword.Text.Trim() + "','" + txtEmail.Text.Trim() + "','" + cmbType.SelectedItem + "','" + cmbQuestion.SelectedItem + "','" + txtAnswer.Text.Trim() + "',@IMG)", con)) { com.Parameters.AddWithValue("@IMG", img); if (con.State == ConnectionState.Closed) { con.Open(); } if (com.ExecuteNonQuery() > 0) { MessageBox.Show("User created successfully !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearControls(); } else { MessageBox.Show("User creation unsuccessfull !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } catch (Exception e1) { MessageBox.Show(e1.Message); //MessageBox.Show("This user already exist !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
private void btnCreate_Click(object sender, EventArgs e) { if (txtEmail.Text.Length == 0) { errorProvider1.SetError(txtEmail, "User Id"); MessageBox.Show("Email is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtEmail, ""); txtEmail.Focus(); return; } else if (cmbType.SelectedIndex == 0) { errorProvider1.SetError(cmbType, "User Id"); MessageBox.Show("Select user type", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(cmbType, ""); cmbType.Focus(); return; } else if (cmbQuestion.SelectedIndex == 0) { errorProvider1.SetError(cmbQuestion, "User Id"); MessageBox.Show("Select question", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(cmbQuestion, ""); cmbQuestion.Focus(); return; } else if (txtAnswer.Text.Length == 0) { errorProvider1.SetError(txtAnswer, "User Id"); MessageBox.Show("Answer is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtAnswer, ""); txtAnswer.Focus(); return; } else if (UserPictureBox.Image == null) { errorProvider1.SetError(UserPictureBox, "User Id"); MessageBox.Show("Choose user image", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(UserPictureBox, ""); UserPictureBox.Focus(); return; } else { if (txtPassword.Text != txtRePassword.Text) { MessageBox.Show("Password and confirm password do not matched !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { try { byte[] imgBytes = null; ImageConverter imgConverter = new ImageConverter(); imgBytes = (System.Byte[])imgConverter.ConvertTo(UserPictureBox.Image, Type.GetType("System.Byte[]")); using (con = new SqlConnection(ConStr)) { using (com = new SqlCommand("update Users set Email='" + txtEmail.Text.Trim() + "',Type='" + cmbType.SelectedItem + "',Question='" + cmbQuestion.SelectedItem + "',Answer='" + txtAnswer.Text.Trim() + "', photo=@IMG where UserId='" + txtUserId.Text.Trim() + "'", con)) { com.Parameters.AddWithValue("@IMG", imgBytes); if (con.State == ConnectionState.Closed) { con.Open(); } if (com.ExecuteNonQuery() > 0) { MessageBox.Show("User updated successfully !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearControls(); } else { MessageBox.Show("User updation unsuccessfull !", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } catch (Exception e1) { MessageBox.Show(e1.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } ClearControls(); panel3.Enabled = false; }