private void SavePassword()
        {
            SqlCommand cmd = new SqlCommand("UPDATE dbo.tblUserAccounts SET UserPassword=@Pass where UserID=@ID");

            cmd.CommandType = System.Data.CommandType.Text;

            cmd.Parameters.AddWithValue("@ID", userid);

            cmd.Parameters.AddWithValue("@Pass", ClsEncrypt_Decrypt_String.Encrypt(tbPassword.Password.Trim()));

            SqlHelper.ExecuteNonQuery(ClsConfig.Cantier_LotCardLabelConnectionString, cmd);

            MessageBox.Show("Record successfully updated");

            this.Close();
        }
        private void Userpass_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Return)
            {
                SqlCommand cmd = new SqlCommand("select * from dbo.tblUserAccounts where " +
                                                "Username = '******' and UserPassword = '******' ");

                cmd.CommandType = CommandType.Text;

                if (SqlHelper.ExecuteDataReader(ClsConfig.OnlineSystemsLoginConnectionString, cmd).Rows.Count > 0)
                {
                    foreach (DataRow dr in SqlHelper.ExecuteDataReader(ClsConfig.OnlineSystemsLoginConnectionString, cmd).Rows)
                    {
                        //if (Convert.ToBoolean(dr[8]) == true)
                        //{
                        MainForm frm = new MainForm();
                        frm._deptcode = dr[5].ToString().Trim();
                        frm._sectcode = dr[6].ToString().Trim();
                        frm._userid   = Convert.ToInt32(dr[0]);
                        frm._fullname = dr[3].ToString();
                        frm.Height    = frmSize_Height;

                        frm.Width = frmSize_Width;

                        frm.WindowState = WindowState.Normal;

                        frm.ResizeMode = ResizeMode.CanResize;
                        this.Hide();
                        frm.Show();
                        //}
                        //else
                        //{
                        //    MessageBox.Show("Access Denied");
                        //}
                    }
                }
                else
                {
                    MessageBox.Show("Access Denied");
                }
            }
        }
        private void Signin_Click(object sender, RoutedEventArgs e)
        {
            SqlCommand cmd = new SqlCommand("select * from dbo.tblUserAccounts where " +
                                            "Username = '******' and UserPassword = '******' ");

            cmd.CommandType = CommandType.Text;

            if (SqlHelper.ExecuteDataReader(ClsConfig.OnlineSystemsLoginConnectionString, cmd).Rows.Count > 0)
            {
                foreach (DataRow dr in SqlHelper.ExecuteDataReader(ClsConfig.OnlineSystemsLoginConnectionString, cmd).Rows)
                {
                    //if (Convert.ToBoolean(dr[8]) == true)
                    //{
                    MainForm frm = new MainForm();
                    frm._deptcode = dr[5].ToString().Trim();
                    frm._sectcode = dr[6].ToString().Trim();
                    frm._userid   = Convert.ToInt32(dr[0]);
                    frm.Height    = frmSize_Height;
                    frm._fullname = dr[3].ToString();
                    frm.Width     = frmSize_Width;

                    frm.WindowState = WindowState.Normal;

                    frm.ResizeMode = ResizeMode.CanResize;
                    this.Hide();
                    frm.Show();
                    //}
                    //else
                    //{
                    //    MessageBox.Show("Access Denied");
                    //}
                }
            }
            else
            {
                MessageBox.Show("Access Denied");
            }

            //SqlCommand cmdSelect = new SqlCommand("select * from tblUserAccounts");
            //cmdSelect.CommandType = CommandType.Text;

            //foreach (DataRow dr in SqlHelper.ExecuteDataReader(ClsConfig.Cantier_LotCardLabelConnectionString, cmdSelect).Rows)
            //{
            //    SqlCommand cmd = new SqlCommand("update tblUserAccounts set UserEncryptedPassword=@Pass where userid = @userid");
            //    cmd.CommandType = CommandType.Text;
            //    cmd.Parameters.AddWithValue("@userid", Convert.ToInt32(dr["userid"]));
            //    cmd.Parameters.AddWithValue("@Pass", ClsEncrypt_Decrypt_String.Encrypt(dr["UserPassword"].ToString().Trim()));
            //    SqlHelper.ExecuteNonQuery(ClsConfig.Cantier_LotCardLabelConnectionString, cmd);
            //}
        }
        private Boolean _SaveData()
        {
            Boolean _isValid = false;

            _isValid = _ValidateFields();


            SqlCommand cmd = new SqlCommand("SaveUser");

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@ID", id);

            cmd.Parameters.AddWithValue("@UserName", tbUsername.Text.Trim());

            cmd.Parameters.AddWithValue("@UserPassword", ClsEncrypt_Decrypt_String.Encrypt("skpi"));

            cmd.Parameters.AddWithValue("@FullName", chkIsCommon.IsChecked == true ? tbEmpName_Single.Text.Trim() : cboName.Text.ToString());

            cmd.Parameters.AddWithValue("@EmpID", chkIsCommon.IsChecked == true ? DBNull.Value.ToString() : cboName.SelectedValue.ToString());

            cmd.Parameters.AddWithValue("@Department", cboDepartment.SelectedValue.ToString());

            cmd.Parameters.AddWithValue("@Section", cboSection.SelectedValue.ToString());

            cmd.Parameters.AddWithValue("@RawMaterialAccess", RawMaterialAccess.IsChecked == true ? true : false);

            cmd.Parameters.AddWithValue("@IsLotCardUser", IsLotCardUser.IsChecked == true ? true : false);

            cmd.Parameters.AddWithValue("@AllowReprintLotCard", AllowReprintLotCard.IsChecked == true ? true : false);

            cmd.Parameters.AddWithValue("@ReprintLotCardPassword", AllowReprintLotCard.IsChecked == true ? ClsEncrypt_Decrypt_String.Encrypt(tbLotCardPassword.Password) : DBNull.Value.ToString());

            cmd.Parameters.AddWithValue("@IsPEZAUser", IsPEZAUser.IsChecked == true ? true : false);

            cmd.Parameters.AddWithValue("@IsNGDataUser", IsNGDataUser.IsChecked == true ? true : false);

            cmd.Parameters.AddWithValue("@IsOQCInspector", IsOQCInspector.IsChecked == true ? true : false);

            cmd.Parameters.AddWithValue("@IsPMCDeliveryPerson", IsPMCDeliveryPerson.IsChecked == true ? true : false);

            cmd.Parameters.AddWithValue("@IsCommonAccount", chkIsCommon.IsChecked == true ? true : false);

            cmd.Parameters.AddWithValue("@IsAdmin", IsAdmin.IsChecked == true ? true : false);

            cmd.Parameters.AddWithValue("@IsChangePassword", 0);

            cmd.Parameters.Add("@Result", SqlDbType.Int).Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(ClsConfig.Cantier_LotCardLabelConnectionString, cmd);

            MessageBox.Show("Saved");

            ClearFields();

            groupDetails.IsEnabled = false;

            btnAddNewRecord.IsEnabled = true;

            btnEdit.IsEnabled = false;

            btnDelete.IsEnabled = false;

            btnSave.IsEnabled = false;

            btnCancelChanges.IsEnabled = false;

            LoadLists();

            LoadEmployees();

            LoadDepartment();

            _command = string.Empty;

            return(true);
        }