コード例 #1
0
ファイル: DetailForm.cs プロジェクト: KasunDA/Health-1
        private void InitializeProperties(object obj)
        {
            Type objType = obj.GetType();

            PropertyInfo[] propertiesInfo =
                objType.GetProperties().Where(
                    p =>
                    p.GetCustomAttributes(true).Where(
                        a => a.GetType() == typeof(NotDisplayAttribute) || a.GetType() == typeof(HideAttribute)).Count
                        () == 0).ToArray();
            foreach (PropertyInfo propertyInfo in propertiesInfo)
            {
                var propertyValue = propertyInfo.GetValue(obj, null);
                var att           =
                    propertyInfo.GetCustomAttributes(true).Where(a => a is DisplayNameAttribute).FirstOrDefault() as
                    DisplayNameAttribute;
                string labelText = att == null ? propertyInfo.Name : att.DisplayName;
                var    textLabel = new Label
                {
                    Text   = labelText,
                    Height = RHeight,
                    Top    = _cHeight,
                    Left   = 0
                };
                if (propertyValue is ICollection)
                {
                    var dataGridView = new YDataGridView
                    {
                        DataSource          = propertyValue,
                        BackgroundColor     = Color.White,
                        AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                        Top = textLabel.Top + textLabel.Height
                    };
                    Controls.AddRange(new Control[] { textLabel, dataGridView });
                    _cHeight = dataGridView.Height + dataGridView.Top;
                    Type operationContextType = typeof(OperationsContext <>);
                    Type dObjType             = propertyValue.GetType().GetGenericArguments()[0];
                    Type objOperContxType     = operationContextType.MakeGenericType(dObjType);
                    var  operationsContext    =
                        DIKernel.Get <OperationsRepository>().Operations.Where(o => o.GetType() == objOperContxType).
                        FirstOrDefault();
                    if (operationsContext != null)
                    {
                        PropertyInfo pi         = operationsContext.GetType().GetProperty(@"Detail");
                        Type         methodType = typeof(Func <,>).MakeGenericType(dObjType, typeof(object));
                        var          mv         = pi.GetValue(operationsContext, null);
                        var          pv         = propertyValue as ICollection;
                        var          arr        = new object[pv.Count];
                        pv.CopyTo(arr, 0);
                        if (mv != null)
                        {
                            dataGridView.Detail =
                                clickedRow =>
                            {
                                object ob = methodType.InvokeMember("DynamicInvoke", BindingFlags.InvokeMethod,
                                                                    null, mv,
                                                                    new[] { arr[clickedRow] });
                                var form = new DetailForm(DIKernel, ob)
                                {
                                    MdiParent = MdiParent
                                };
                                form.Show();
                            };
                        }
                        dataGridView.InitializeOperations();
                    }
                }
                else
                {
                    string labelValue = propertyValue.ToString();
                    var    valueLabel = new Label
                    {
                        Text     = labelValue,
                        Top      = _cHeight,
                        Left     = textLabel.Width + 10,
                        AutoSize = true
                    };
                    _cHeight += RHeight > valueLabel.Height ? RHeight : valueLabel.Height;
                    Controls.AddRange(new[] { textLabel, valueLabel });
                }
            }
        }
コード例 #2
0
ファイル: DetailForm.cs プロジェクト: crashr42/Health
 private void InitializeProperties(object obj)
 {
     Type objType = obj.GetType();
     PropertyInfo[] propertiesInfo =
         objType.GetProperties().Where(
             p =>
             p.GetCustomAttributes(true).Where(
                 a => a.GetType() == typeof (NotDisplayAttribute) || a.GetType() == typeof (HideAttribute)).Count
                 () == 0).ToArray();
     foreach (PropertyInfo propertyInfo in propertiesInfo)
     {
         var propertyValue = propertyInfo.GetValue(obj, null);
         var att =
             propertyInfo.GetCustomAttributes(true).Where(a => a is DisplayNameAttribute).FirstOrDefault() as
             DisplayNameAttribute;
         string labelText = att == null ? propertyInfo.Name : att.DisplayName;
         var textLabel = new Label
                             {
                                 Text = labelText,
                                 Height = RHeight,
                                 Top = _cHeight,
                                 Left = 0
                             };
         if (propertyValue is ICollection)
         {
             var dataGridView = new YDataGridView
                                    {
                                        DataSource = propertyValue,
                                        BackgroundColor = Color.White,
                                        AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                                        Top = textLabel.Top + textLabel.Height
                                    };
             Controls.AddRange(new Control[] { textLabel, dataGridView });
             _cHeight = dataGridView.Height + dataGridView.Top;
             Type operationContextType = typeof(OperationsContext<>);
             Type dObjType = propertyValue.GetType().GetGenericArguments()[0];
             Type objOperContxType = operationContextType.MakeGenericType(dObjType);
             var operationsContext =
                 DIKernel.Get<OperationsRepository>().Operations.Where(o => o.GetType() == objOperContxType).
                     FirstOrDefault();
             if (operationsContext != null)
             {
                 PropertyInfo pi = operationsContext.GetType().GetProperty(@"Detail");
                 Type methodType = typeof(Func<,>).MakeGenericType(dObjType, typeof(object));
                 var mv = pi.GetValue(operationsContext, null);
                 var pv = propertyValue as ICollection;
                 var arr = new object[pv.Count];
                 pv.CopyTo(arr, 0);
                 if (mv != null)
                 {
                     dataGridView.Detail =
                         clickedRow =>
                         {
                             object ob = methodType.InvokeMember("DynamicInvoke", BindingFlags.InvokeMethod,
                                                                 null, mv,
                                                                 new[] { arr[clickedRow] });
                             var form = new DetailForm(DIKernel, ob) { MdiParent = MdiParent };
                             form.Show();
                         };
                 }
                 dataGridView.InitializeOperations();
             }
         }
         else
         {
             string labelValue = propertyValue.ToString();
             var valueLabel = new Label
                                  {
                                      Text = labelValue,
                                      Top = _cHeight,
                                      Left = textLabel.Width + 10,
                                      AutoSize = true
                                  };
             _cHeight += RHeight > valueLabel.Height ? RHeight : valueLabel.Height;
             Controls.AddRange(new[] {textLabel, valueLabel});
         }
     }
 }
コード例 #3
0
        public void InitializeOperations()
        {
            var operationsContext =
                DIKernel.Get <OperationsRepository>().Operations.Where(
                    o => o.GetType() == typeof(OperationsContext <TData>)).FirstOrDefault() as
                OperationsContext <TData>;

            if (operationsContext != null)
            {
                LoadData   = operationsContext.Load;
                DeleteData = operationsContext.Delete;
                DetailData = operationsContext.Detail ?? DefaulDetailData;
            }
            else
            {
                DetailData = DefaulDetailData;
            }
            if (LoadData != null)
            {
                var el = new ToolStripButton
                {
                    DisplayStyle = ToolStripItemDisplayStyle.Text,
                    Text         = @"Обновить"
                };
                el.Click += (sender, e) => RefreshData();
                ydgvwc.tsOperations.Items.Add(el);
            }
            if (DeleteData != null)
            {
                var el = new ToolStripButton
                {
                    DisplayStyle = ToolStripItemDisplayStyle.Text,
                    Text         = @"Удалить"
                };
                Action <int> deleteAction = clickedRow =>
                {
                    QueryStatus status = DeleteData(_data[clickedRow]);
                    if (status.Status == 0)
                    {
                        YMessageBox.Information(status.StatusMessage);
                    }
                };
                el.Click += (sender, e) =>
                {
                    if (ydgvwc.ydgvData.SelectedCells.Count == 0)
                    {
                        YMessageBox.Information(@"Выберите строку для удаления");
                    }
                    else
                    {
                        int selectedIndex = ydgvwc.ydgvData.SelectedCells[0].RowIndex;
                        deleteAction(selectedIndex);
                    }
                };
                ydgvwc.ydgvData.Delete = deleteAction;
                ydgvwc.tsOperations.Items.Add(el);
            }
            if (DetailData != null)
            {
                var el = new ToolStripButton
                {
                    DisplayStyle = ToolStripItemDisplayStyle.Text,
                    Text         = @"Подробнее"
                };
                Action <int> detail = clickedRow =>
                {
                    var form = new DetailForm(DIKernel, DetailData(_data[clickedRow]))
                    {
                        MdiParent = MdiParent
                    };
                    form.Show();
                };
                el.Click += (sender, e) =>
                {
                    if (ydgvwc.ydgvData.SelectedCells.Count == 0)
                    {
                        YMessageBox.Information(@"Выберите строку для просмотра подробных данных.");
                    }
                    else
                    {
                        int selectedIndex = ydgvwc.ydgvData.SelectedCells[0].RowIndex;
                        detail(selectedIndex);
                    }
                };
                ydgvwc.tsOperations.Items.Add(el);
                ydgvwc.ydgvData.Detail = detail;
            }
            ydgvwc.ydgvData.InitializeOperations();
        }