locked
Can I read from database table and load screen in Lightswitch application in CanRun Method RRS feed

  • Question

  • Hello Team,

    Currently I'm having myUserData Table with boolean column canViewModule to specify wether the user can view the Module or not. How can i access the table data and loop the data for checking permissions and show screens on my lightswitch silverlight client application.

     Private Sub MyModulePage_CanRun(ByRef result As Boolean)
     /*Loop my users table here and check they are having the  access or not by comparing each and every record with  Me.User.FullName Value */
    
     End Sub

    Does anybody Have guesses ??

    Thanks,

    Hemakiran

    Thursday, August 27, 2015 9:53 AM

Answers

  • Hi Hemakiran,

    Do you mean you want to validate something can run with the boolean column on the screen? Please try to find the DataGrid control when the screen created. Then register SelectionChanged event for the DataGrid. Define a parameter which user to get the boolean value on screen. When selection changed, the value of the parameter will changed too. Following code implement the steps. Hope that can help you.

            bool r = true;
            DataGrid dg;
            partial void gridEditSelected_CanExecute(ref bool result)
            {
                // Write your code here.
                result = r;
            }
     
            partial void EditableCustomersGrid_Created()
            {
                // Write your code here.
                this.FindControl("grid").ControlAvailable += EditableCustomersGrid_ControlAvailable;
            }
     
            void EditableCustomersGrid_ControlAvailable(object sender, ControlAvailableEventArgs e)
            {
                if(e.Control is DataGrid)
                {
                    dg = (DataGrid)e.Control;
                    dg.SelectionChanged += dg_SelectionChanged;
                }
               
            }
     
            void dg_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                if (dg.SelectedItem != null)
                {
                    Customer c = (Customer)dg.SelectedItem;
                    if (c.AdminUser == false)
                    {
                        r = false;
                    }
                }
            }

     



    Best Regards,
    Weiwei

    • Proposed as answer by Angie Xu Tuesday, September 8, 2015 12:21 PM
    • Marked as answer by Angie Xu Tuesday, September 8, 2015 12:23 PM
    Friday, August 28, 2015 9:42 AM
    Moderator

All replies

  • Hi!

    I don't know how your app and relations are designed, but usually you go with setting permissions.. so if user have permission to view screen it will be shown on menu.. 

     Private Sub MyModulePage_CanRun(ByRef result As Boolean)
     /*Loop my users table here and check they are having the  access or not by comparing each and every record with  Me.User.FullName Value */
    
    result = Application.Current.User.HasPermission(permissions.canViewModule)
    
     End Sub

    it finds who current user is, and if he have specific permission he can run module (screen).. usually with forms authentication you can have table appUsers with additional details for your users "linked" to asp.net users table over username property, SL app always knows who current user is.. hope this helps!

    Kivito 


    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Thursday, August 27, 2015 5:44 PM
  • Hi Hemakiran,

    Do you mean you want to validate something can run with the boolean column on the screen? Please try to find the DataGrid control when the screen created. Then register SelectionChanged event for the DataGrid. Define a parameter which user to get the boolean value on screen. When selection changed, the value of the parameter will changed too. Following code implement the steps. Hope that can help you.

            bool r = true;
            DataGrid dg;
            partial void gridEditSelected_CanExecute(ref bool result)
            {
                // Write your code here.
                result = r;
            }
     
            partial void EditableCustomersGrid_Created()
            {
                // Write your code here.
                this.FindControl("grid").ControlAvailable += EditableCustomersGrid_ControlAvailable;
            }
     
            void EditableCustomersGrid_ControlAvailable(object sender, ControlAvailableEventArgs e)
            {
                if(e.Control is DataGrid)
                {
                    dg = (DataGrid)e.Control;
                    dg.SelectionChanged += dg_SelectionChanged;
                }
               
            }
     
            void dg_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                if (dg.SelectedItem != null)
                {
                    Customer c = (Customer)dg.SelectedItem;
                    if (c.AdminUser == false)
                    {
                        r = false;
                    }
                }
            }

     



    Best Regards,
    Weiwei

    • Proposed as answer by Angie Xu Tuesday, September 8, 2015 12:21 PM
    • Marked as answer by Angie Xu Tuesday, September 8, 2015 12:23 PM
    Friday, August 28, 2015 9:42 AM
    Moderator