示例#1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (Global.isUserEdit == true)
            {
                if (string.IsNullOrEmpty(txtEmpNo.Text))
                {
                    //this is for saving
                    DialogResult dialogSave = MessageBox.Show("Proceed with saving?", "Save User", MessageBoxButtons.YesNo);
                    if (dialogSave == DialogResult.Yes)
                    {
                        //save user
                        lastUserId = _userService.SaveUser(txtFirstName.Text, txtMiddleName.Text,
                                                           txtLastName.Text, txtContact.Text, txtEmail.Text,
                                                           null, Global.loggedUserId, DateTime.Now, null, null, !String.IsNullOrEmpty(newPath) ? newPath : defaultImage);


                        //give user access
                        _userAccessService.SaveUserAccess(Convert.ToInt32(cmbAccessLevel.SelectedValue), lastUserId, txtUsername.Text, txtPassword.Text.Trim(), 0, false, true, DateTime.Now,
                                                          Global.loggedUserId, null, false);

                        MessageBox.Show("User has been created");
                        Global.isUserEdit = false;
                    }
                }

                else
                {
                    //this is for update
                    DialogResult dialogUpdate = MessageBox.Show("User has been edited. Save changes?", "Edit User", MessageBoxButtons.YesNo);
                    if (dialogUpdate == DialogResult.Yes)
                    {
                        //this is update
                        _userService.UpdateUser(txtEmpNo.Text.Trim(), txtFirstName.Text, txtMiddleName.Text,
                                                txtLastName.Text, txtContact.Text, txtEmail.Text,
                                                null, null, null, DateTime.Now, Global.loggedUserId, Global.selectedUser
                                                , !String.IsNullOrEmpty(newPath) ? newPath : defaultImage);
                        MessageBox.Show("User has been updated");
                        //update access
                        //_userAccessService.UpdateUserAccess(Convert.ToInt32(cmbAccessLevel.SelectedValue), Convert.ToInt32(cmbEmployeeNo.SelectedValue),
                        //    txtUsername.Text, "password",0,
                        //    false, true, null, null, Global.loggedUserId, false);
                    }
                    else if (dialogUpdate == DialogResult.No)
                    {
                        //do nothing
                    }
                }
            }
        }