コード例 #1
0
ファイル: Users.cs プロジェクト: iProjects/soft_books_payroll
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (dataGridViewUsers.SelectedRows.Count != 0)
     {
         try
         {
             spUser user = (spUser)bindingSourceUsers.Current;
             if (DialogResult.Yes == MessageBox.Show("Are you sure you want to delete User\n" + user.UserName.ToUpper(), "Confirm Delete", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
             {
                 db.spUsers.DeleteObject(user);
                 db.SaveChanges();
                 RefreshGrid();
             }
         }
         catch (Exception ex)
         {
             Utils.ShowError(ex);
         }
     }
 }
コード例 #2
0
        private void btnAdd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (IsUserValid())
            {
                try
                {
                    spUser su = new spUser();

                    if (!string.IsNullOrEmpty(txtUserName.Text))
                    {
                        su.UserName = txtUserName.Text.Trim();
                    }
                    if (!string.IsNullOrEmpty(txtPassword.Text))
                    {
                        su.Password = txtPassword.Text.Trim();
                    }
                    if (cboRole.SelectedIndex != -1)
                    {
                        su.RoleId = int.Parse(cboRole.SelectedValue.ToString());
                    }
                    if (!string.IsNullOrEmpty(txtSurName.Text))
                    {
                        su.Surname = txtSurName.Text.Trim();
                    }
                    if (!string.IsNullOrEmpty(txtOtherNames.Text))
                    {
                        su.OtherNames = txtOtherNames.Text.Trim();
                    }
                    if (!string.IsNullOrEmpty(txtNationalId.Text))
                    {
                        su.NationalID = txtNationalId.Text.Trim();
                    }
                    su.DateOfBirth = dtpDOB.Value;
                    if (cboGender.SelectedIndex != -1)
                    {
                        su.Gender = cboGender.SelectedValue.ToString();
                    }
                    if (cboInformBy.SelectedIndex != -1)
                    {
                        su.InformBy = cboInformBy.SelectedValue.ToString();
                    }
                    if (!string.IsNullOrEmpty(txtEmail.Text))
                    {
                        su.Email = txtEmail.Text.Trim();
                    }
                    if (!string.IsNullOrEmpty(txtTelephone.Text))
                    {
                        su.Telephone = txtTelephone.Text.Trim();
                    }
                    if (!string.IsNullOrEmpty(txtPhoto.Text))
                    {
                        su.Photo = txtPhoto.Text.Trim();
                    }
                    su.Locked     = chkLocked.Checked;
                    su.IsDeleted  = false;
                    su.SystemId   = "ws";
                    su.Status     = "A";
                    su.DateJoined = DateTime.Now;

                    if (db.spUsers.Any(i => i.UserName == su.UserName))
                    {
                        MessageBox.Show("User Name Exist!", "SB Payroll", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    if (!db.spUsers.Any(i => i.UserName == su.UserName))
                    {
                        db.spUsers.AddObject(su);
                        db.SaveChanges();

                        Users f = (Users)this.Owner;
                        f.RefreshGrid();
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    Utils.ShowError(ex);
                }
            }
        }