public UIElement BuildForm(FieldInfo fi, object source, NecrobotConfigAttribute propAtt)
        {
            var type = source.GetType();

            if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Dictionary <,>)))
            {
                Type keyType   = type.GetGenericArguments()[0];
                Type valueType = type.GetGenericArguments()[1];

                MethodInfo method        = typeof(SettingsWindow).GetMethod("BuildDictionaryForm");
                MethodInfo genericMethod = method.MakeGenericMethod(keyType, valueType);
                return((UIElement)genericMethod.Invoke(this, new object[] { fi, source }));
            }

            if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(List <>)))
            {
                Type objectType = type.GetGenericArguments()[0];
                //Type valueType = type.GetGenericArguments()[1];

                MethodInfo method        = typeof(SettingsWindow).GetMethod("BuildListObjectForm");
                MethodInfo genericMethod = method.MakeGenericMethod(objectType);
                return((UIElement)genericMethod.Invoke(this, new object[] { fi, source }));
            }

            return(BuildObjectForm(fi, source, propAtt));
        }
        public UIElement BuildObjectForm(FieldInfo fi, object source, NecrobotConfigAttribute configAttibute)
        {
            StackPanel panelWrap = new StackPanel()
            {
            };

            Border border = new Border()
            {
                BorderBrush = Brushes.CadetBlue,

                BorderThickness = new Thickness(2, 2, 3, 3)
            };

            StackPanel panel = new StackPanel()
            {
                Margin = new Thickness(20, 20, 20, 20),
                HorizontalAlignment = HorizontalAlignment.Left
            };

            border.Child = panel;
            panelWrap.Children.Add(border);

            var type = source.GetType();

            var fieldName = type.Name;

            foreach (var item in type.GetProperties())
            {
                var att = item.GetCustomAttributes <NecrobotConfigAttribute>(true).FirstOrDefault();
                if (att != null)
                {
                    string resKey  = $"Setting.{fi.Name}.{item.Name}";
                    string DescKey = $"Setting.{fi.Name}.{item.Name}Desc";

                    panel.Children.Add(new Label()
                    {
                        Content = translator.GetTranslation(resKey), FontSize = 15, ToolTip = translator.GetTranslation(DescKey)
                    });
                    panel.Children.Add(GetInputControl(item, source));
                }
            }

            return(panelWrap);
        }
Exemple #3
0
        private static ExcelWorksheet BuildSheetHeader(ExcelPackage package, FieldInfo item, object att)
        {
            NecrobotConfigAttribute excelAtt  = att as NecrobotConfigAttribute;
            ExcelWorksheet          workSheet = package.Workbook.Worksheets[excelAtt.SheetName];

            if (workSheet == null)
            {
                var type = item.FieldType;

                if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary <,>))
                {
                    var pkmRef = package.Workbook.Worksheets["Pokemons"];

                    workSheet = package.Workbook.Worksheets.Add(excelAtt.SheetName, pkmRef);
                    Type keyType   = type.GetGenericArguments()[0];
                    Type valueType = type.GetGenericArguments()[1];
                    int  pos       = 1;

                    workSheet.Cells[1, 1].Value = excelAtt.SheetName;
                    workSheet.Cells[2, 1].Value = excelAtt.Description;

                    foreach (var vtp in valueType.GetProperties())
                    {
                        var att1     = vtp.GetCustomAttributes <NecrobotConfigAttribute>(true).FirstOrDefault();
                        int colIndex = (att1 == null ? pos : att1.Position) + COL_OFFSET;
                        workSheet.Column(colIndex).AutoFit();
                        workSheet.Cells[4, colIndex].Value = att1 == null ? vtp.Name : att1.Key;
                        if (att1 != null)
                        {
                            workSheet.Cells[4, colIndex].AddComment(att1.Description, "necrobot2");
                            AddValidationForType(workSheet, vtp, $"{GetCol(colIndex)}5:{GetCol(colIndex)}155");
                        }
                        pos++;
                    }
                    workSheet.Cells[$"A1:{GetCol(COL_OFFSET + pos)}1"].Merge           = true;
                    workSheet.Cells[$"A2:{GetCol(COL_OFFSET + pos)}2"].Merge           = true;
                    workSheet.Cells[$"A1:{GetCol(COL_OFFSET + pos)}1"].Style.Font.Size = 16;
                }
                else
                {
                    workSheet = package.Workbook.Worksheets.Add(excelAtt.SheetName);
                    workSheet.Cells[1, 1].Value = excelAtt.SheetName;
                    workSheet.Cells[2, 1].Value = excelAtt.Description;

                    workSheet.Cells[$"A1:C1"].Merge = true;
                    workSheet.Cells[$"A2:C2"].Merge = true;


                    workSheet.Cells["A1:C1"].Style.Font.Size = 16;
                    workSheet.Row(1).CustomHeight            = true;
                    workSheet.Row(1).Height = 30;

                    workSheet.Cells["A1:C1"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                    workSheet.Cells["A1:C1"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Justify;

                    workSheet.Cells[4, 1].Value = "Key";
                    workSheet.Cells[4, 2].Value = "Value";
                    workSheet.Cells[4, 3].Value = "Description";
                }

                workSheet.Row(4).Style.Font.Bold = true;
            }

            return(workSheet);
        }