コード例 #1
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear();
            if (IsRoleValid())
            {
                try
                {
                    if (!string.IsNullOrEmpty(txtShortCode.Text))
                    {
                        role.ShortCode = txtShortCode.Text;
                    }
                    if (!string.IsNullOrEmpty(txtDescription.Text))
                    {
                        role.Description = Utils.ConvertFirstLetterToUpper(txtDescription.Text);
                    }

                    rep.UpdateRole(role);

                    RolesListForm f = (RolesListForm)this.Owner;
                    f.RefreshGrid();
                    this.Close();
                }
                catch (Exception ex)
                {
                    Utils.ShowError(ex);
                }
            }
        }
コード例 #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear();
            if (IsRoleValid())
            {
                try
                {
                    spRole role = new spRole();
                    if (!string.IsNullOrEmpty(txtShortCode.Text))
                    {
                        role.ShortCode = Utils.ConvertFirstLetterToUpper(txtShortCode.Text);
                    }
                    if (!string.IsNullOrEmpty(txtDescription.Text))
                    {
                        role.Description = Utils.ConvertFirstLetterToUpper(txtDescription.Text);
                    }
                    role.IsDeleted = false;

                    if (db.spRoles.Any(i => i.ShortCode == role.ShortCode))
                    {
                        MessageBox.Show("Role Code Exist!", "SB Payroll", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    if (!db.spRoles.Any(i => i.ShortCode == role.ShortCode))
                    {
                        db.spRoles.AddObject(role);
                        db.SaveChanges();

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