private void TxtCompany_OnKeyDown(object sender, KeyRoutedEventArgs e)
 {
     if (e.Key == VirtualKey.Enter)
     {
         TxtEmailAddress.Focus(FocusState.Programmatic);
         e.Handled = true;
     }
 }
Exemple #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtIDNUMBER.Text == "")
            {
                MessageBox.Show("This field is required!.", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                txtIDNUMBER.Focus();
            }
            else if (TxtFirstName.Text == "")
            {
                MessageBox.Show("This field is required!.", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                TxtFirstName.Focus();
            }
            else if (TxtLastName.Text == "")
            {
                MessageBox.Show("This field is required!.", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                TxtLastName.Focus();
            }
            else if (TxtMiddleName.Text == "")
            {
                MessageBox.Show("This field is required!.", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                TxtLastName.Focus();
            }

            else if (TxtEmailAddress.Text == "")
            {
                MessageBox.Show("This field is required!.", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                TxtEmailAddress.Focus();
            }

            else if (cboPOstion.SelectedValue.ToString() == "")//Nothing selected
            {
                MessageBox.Show("This field is required!.", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                cboPOstion.Focus();
            }
            else if (cboDepartments.SelectedValue.ToString() == "")//Nothing selected
            {
                MessageBox.Show("This field is required!.", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                cboDepartments.Focus();
            }

            else
            {
                string StringReturn = "";


                SqlConnection con = new SqlConnection(conStr);
                SqlCommand    cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.CommandText = "TRAN_SAVEWORKER";
                cmd.Parameters.Add("@IDRef", SqlDbType.VarChar, 15).Value = txtIDNUMBER.Text.ToString();

                cmd.Parameters.Add("@Lastname", SqlDbType.VarChar, 100).Value      = TxtLastName.Text.ToString();
                cmd.Parameters.Add("@Firstname", SqlDbType.VarChar, 100).Value     = TxtFirstName.Text.ToString();
                cmd.Parameters.Add("@MidName", SqlDbType.VarChar, 100).Value       = TxtMiddleName.Text.ToString();
                cmd.Parameters.Add("@EmailAddress", SqlDbType.VarChar, 100).Value  = TxtEmailAddress.Text.ToString();
                cmd.Parameters.Add("@DesignationCode", SqlDbType.VarChar, 4).Value = cboPOstion.SelectedValue.ToString();

                cmd.Parameters.Add("@DeptCode", SqlDbType.VarChar, 15).Value = cboDepartments.SelectedValue.ToString();

                cmd.Connection = con;
                try
                {
                    con.Open();
                    StringReturn = cmd.ExecuteScalar().ToString();
                    if (StringReturn == "EXISTS")
                    {
                        MessageBox.Show("ID Number Already Exists", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                    }



                    if (StringReturn == "DONE")
                    {
                        MessageBox.Show("Record Saved", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);


                        UserMaintainance um = new UserMaintainance();


                        um.Show();
                        this.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    con.Close();
                    con.Dispose();
                }
            }
        }