Advertisement
vilgelmbb

UseTaskCommentForm DV 5.3

May 27th, 2015
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1.     protected string UseTaskCommentForm()
  2.         {
  3.             string comment = string.Empty;
  4.             //Получим необходимый тип по полному имени
  5.             Type taskCommentFormType = typeof(DocsVision.BackOffice.Cards.CardTask.MainControl).
  6.                     Assembly.GetType("DocsVision.BackOffice.Cards.CardTask.TaskCommentForm");
  7.             if (taskCommentFormType != null)
  8.             {
  9.                 //Получим конструктор, т.к. знаем набор и тип аргументов благодаря IlSpy
  10.                 ConstructorInfo method = taskCommentFormType.GetConstructor(
  11.                         BindingFlags.Public | BindingFlags.Instance,
  12.                         null,
  13.                         new[] { typeof(ObjectContext), typeof(string), typeof(StaffEmployee), typeof(DateTime), typeof(bool) },
  14.                         null
  15.                     );
  16.                 //Вызовем конструктор, передав параметры в виде массива объектов
  17.                 object o = method.Invoke(new object[]
  18.         { Context, comment, StaffService.GetCurrentEmployee(), DateTime.Now, false });
  19.  
  20.                 var taskCommentForm = o as XtraForm;//Т.к. знаем, что TaskCommentForm наследует XtraForm
  21.                 if (taskCommentForm != null && taskCommentForm.ShowDialog() == DialogResult.OK)
  22.                 {
  23.                     var prop = taskCommentForm.GetType().GetProperty("Comment");
  24.                     if (prop != null)
  25.                     {
  26.                         //Обработаем работу с формой и "заберём" введённый комментарий
  27.                         comment = prop.GetValue(taskCommentForm, null).ToString();
  28.                     }
  29.                 }
  30.                 if (taskCommentForm != null) taskCommentForm.Dispose();//Принудительно избавимся от объекта формы
  31.             }
  32.             return comment;
  33.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement