src/RumahScarlett/RumahScarlett.Presentation/Helper/RoleManager.cs
/// <summary>
/// Isi setiap Button yang ada di Form ke tabel role_detail
/// </summary>
/// <param name="form">Form target</param>
/// <param name="formAction">FormActionModel object</param>
/// <param name="control">Control target</param>
Isi setiap Button yang ada di Form ke tabel role_detail
Isi setiap Button yang ada di Form ke tabel role_detail
private void PopulateButtonToRoleDetail(Form form, FormActionModel formAction, Control control)
      {
         foreach (Control ctrl in control.Controls)
         {
            if (ctrl is Button)
            {
               var button = (Button)ctrl;
               if (button.TagIgnore()) continue;
               string buttonText = button.Tag != null ? button.Tag.ToString() : button.Text;
               _colActNo += 1;
               string colActName = $"act_{_colActNo}"; 
               var propertyInfo = formAction.GetType().GetProperty(colActName);
               propertyInfo.SetValue(formAction, Convert.ChangeType(buttonText, propertyInfo.PropertyType), null);
               var roleDetail = new RoleDetailModel()
               {
                  role_kode = RoleKode,
                  menu_name = buttonText,
                  menu_parent = form.AccessibleName, 
                  form_action = form.Name,
                  tag = "action"
               };
               _roleServices.Insert(roleDetail);
            }
            PopulateButtonToRoleDetail(form, formAction, ctrl); 
         }
      }
private void PopulateButtonToRoleDetail ( Form form , FormActionModel formAction , Control control ) { foreach ( Control ctrl in control . Controls ) { if ( ctrl is Button ) { var button = ( Button ) ctrl ; if ( button . TagIgnore ( ) ) continue ; string buttonText = button . Tag != null ? button . Tag . ToString ( ) : button . Text ; _colActNo += 1 ; string colActName = $" act_ { _colActNo } " ; var propertyInfo = formAction . GetType ( ) . GetProperty ( colActName ) ; propertyInfo . SetValue ( formAction , Convert . ChangeType ( buttonText , propertyInfo . PropertyType ) , null ) ; var roleDetail = new RoleDetailModel ( ) { role_kode = RoleKode , menu_name = buttonText , menu_parent = form . AccessibleName , form_action = form . Name , tag = " " } ; _roleServices . Insert ( roleDetail ) ; } PopulateButtonToRoleDetail ( form , formAction , ctrl ) ; } }
Isi setiap Button yang ada di Form ke tabel role_detail
Isi setiap Button yang ada di Form ke tabel role_detail
// Kita hanya ingin memilih Control Button saja // Lewati Button yang mempunyai Tag ignore // Ambil menu_name dari Tag Button jika tersedia, sebaliknya ambil dari Text Button // Tambahkan ke kolom act baru jika Button ditemukan // Nama property // Atur property berdasarkan nama dari property // cari property berdasarkan nama (contoh act_1) // lalu isi value property tersebut berdasarkan tag / text dari Button // Buat RoleDetail object // Menu header (parent) di MenuStrip // Simpan data Button ke tabel role_detail // Recursive method
form
Form
None
formAction
FormActionModel
None
control
Control
None