Ejemplo n.º 1
0
 public static bool AddControlToRole(RoleControl control, int roleID)
 {
     var connection = GetInventoryDbConnection();
     try
     {
         var mySqlCommand = new SqlCommand("proc_InsertControlForRole", connection)
         {
             CommandType = CommandType.StoredProcedure
         };
         mySqlCommand.Parameters.AddWithValue("@RoleID", roleID);
         mySqlCommand.Parameters.AddWithValue("@Form", control.FormName);
         mySqlCommand.Parameters.AddWithValue("@Control", control.Name);
         mySqlCommand.Parameters.AddWithValue("@Visible", control.Visible ? 1 : 0);
         mySqlCommand.Parameters.AddWithValue("@Disabled", control.Disabled ? 1 : 0);
         connection.Open();
         if (mySqlCommand.ExecuteNonQuery() == 1)
         {
             return true;
         }
     }
     #region Exceptions
     catch (DataException ex)
     {
         Console.WriteLine(ex.Message);
         throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex);
     }
     catch (SqlException ex)
     {
         Console.WriteLine(ex.Message);
         throw new ApplicationException(Messeges.GetMessage("SqlException"), ex);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw new ApplicationException(Messeges.GetMessage("Exception"), ex);
     }
     finally
     {
         connection.Close();
     }
     #endregion
     return false;
 }
Ejemplo n.º 2
0
        private void PopupContextMenu(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                if (editing == false)
                {

                    ContextMenuStrip roleMenu = new ContextMenuStrip();
                    String controlName;
                    if (sender is ToolStripMenuItem)
                    {
                        var toolStrip = (ToolStripMenuItem)sender;
                        controlName = toolStrip.Name;
                    }
                    else
                    {
                        var c = (Control)sender;
                        controlName = c.Name;
                    }

                    var isUpdate = _editingRoleControls.SingleOrDefault(c => c.FormName == _formName && c.Name == controlName && c.status != "NEW");
                    if (isUpdate != null)
                    {
                        Console.WriteLine(controlName);
                        roleMenu.Items.Add(controlName);
                        roleMenu.Items.Add("-");
                        roleMenu.Items.Add(!isUpdate.Disabled ? "Disable" : "Enable", null, new System.EventHandler(enable_click));
                        roleMenu.Items.Add(isUpdate.Visible ? "Hide" : "Show", null, new System.EventHandler(visible_click));
                        _currentControl = isUpdate;
                        _currentControl.RoleID = _currentRoleID;
                        _currentControl.status = "UPDATE";
                    }
                    else
                    {
                        if (_editingRoleControls.Count > 0)
                        {
                            var control = _editingRoleControls.SingleOrDefault(c => c.FormName == _formName && c.Name == controlName && c.status == "NEW");

                            Console.WriteLine(controlName);
                            roleMenu.Items.Add(controlName);
                            roleMenu.Items.Add("-");
                            roleMenu.Items.Add("Disable", null, new System.EventHandler(enable_click));
                            roleMenu.Items.Add("Hide", null, new System.EventHandler(visible_click));
                            if (control == null)
                            {
                                _currentControl = new RoleControl() { Name = controlName, FormName = _formName, Disabled = false, Active = true, Visible = true, RoleID = _currentRoleID, status = "NEW" };
                            }
                            else
                            {
                                _currentControl = control;
                            }
                        }
                        else
                        {
                            Console.WriteLine(controlName);
                            roleMenu.Items.Add(controlName);
                            roleMenu.Items.Add("-");
                            roleMenu.Items.Add("Disable", null, new System.EventHandler(enable_click));
                            roleMenu.Items.Add("Hide", null, new System.EventHandler(visible_click));
                            _currentControl = new RoleControl() { Name = controlName, FormName = _formName, Disabled = false, Active = true, Visible = true, RoleID = _currentRoleID, status = "NEW" };

                        }
                    }
                    if (sender is ToolStripMenuItem)
                    {
                        roleMenu.Show(Cursor.Position);
                    }
                    else
                    {
                        roleMenu.Show((Control)sender, e.Location);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static AccessToken Authenticate(int userID, string password)
        {
            SqlConnection conn = GetInventoryDbConnection();
            AccessToken _token = null;
            try
            {
                conn.Open();
                SqlCommand sqlCmd = new SqlCommand("proc_Authenticate", conn);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.AddWithValue("@UserID", userID);
                sqlCmd.Parameters.AddWithValue("@Password", password);

                SqlDataReader reader = sqlCmd.ExecuteReader();
                if (reader.HasRows)
                {

                    if(reader.Read())
                    {
                        _token = new AccessToken((int)reader["UserID"]){
                            Role = new Role((int)reader["RoleID"]){Name = (String)reader["Title"], Description = (String)reader["Description"]},
                            FirstName = (String) reader["FirstName"],
                            LastName = (String) reader["LastName"]
                        };
                    }
                    reader.NextResult();
                    var controls = new List<RoleControl>();
                    while(reader.Read())
                    {
                        var control = new RoleControl()
                            {
                                RoleID = (int)reader["RoleID"],
                                FormName = (String)reader["Form"],
                                Name = (String)reader["Control"],
                                Visible = (Boolean)reader["Visible"],
                                Disabled = (Boolean)reader["Disabled"]
                            };
                        controls.Add(control);
                    }
                    _token.Role.Controls = controls;
                    return _token;
                }
                reader.Close();
            }
            catch (DataException ex)
            {
                Console.WriteLine(ex.Message);
                throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex);
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
                throw new ApplicationException(Messeges.GetMessage("SqlException"), ex);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw new ApplicationException(Messeges.GetMessage("Exception"), ex);
            }
            finally
            {
                conn.Close();
            }
            return _token;
        }
Ejemplo n.º 4
0
        public static List<RoleControl> GetControlsForRole(int roleID)
        {
            List<RoleControl> roleControls = new List<RoleControl>();
            SqlConnection conn = GetInventoryDbConnection();
            try
            {
                conn.Open();
                SqlCommand sqlCmd = new SqlCommand("proc_GetControlsForRole", conn);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.AddWithValue("@RoleID", roleID);
                SqlDataReader reader = sqlCmd.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {

                        var roleControl = new RoleControl()
                        {
                            RoleID = reader.GetInt32(reader.GetOrdinal("RoleID")),
                            FormName = reader.GetString(reader.GetOrdinal("Form")),
                            Name = reader.GetString(reader.GetOrdinal("Control")),
                            Visible = reader.GetBoolean(reader.GetOrdinal("Visible")),
                            Disabled= reader.GetBoolean(reader.GetOrdinal("Disabled")),
                        };
                        roleControls.Add(roleControl);
                    }
                }
                reader.Close();
            }
            #region Exceptions
            catch (DataException ex)
            {
                Console.WriteLine(ex.Message);
                throw new ApplicationException(Messeges.GetMessage("DatabaseException"), ex);
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
                throw new ApplicationException(Messeges.GetMessage("SqlException"), ex);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw new ApplicationException(Messeges.GetMessage("Exception"), ex);
            }
            finally
            {
                conn.Close();
            }
            #endregion
            return roleControls;
        }