Advertisement
vilgelmbb

Recall approving DV 5.x

Feb 5th, 2015
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.56 KB | None | 0 0
  1.     public void RecallApproving()
  2.         {
  3.             this.Try(delegate
  4.             {
  5.                 //ссылка на карточку согласования
  6.                 var recId = GetReconciliationId(CardDocument.Reconciliation.ID);
  7.                 if (!recId.HasValue)
  8.                 {
  9.                     //нет запущенного согласования
  10.                     UiService.ShowMessage(Resources.Resources.NoReconciliation);
  11.                     return;
  12.                 }
  13.                 //получили BaseCard согласования КС
  14.                 var reconciliationCard =
  15.                     Context.GetObject<BaseCard>(recId.Value);
  16.                 if (reconciliationCard == null)
  17.                 {
  18.                     Messages.TraceMessage("reconciliationCard==null");
  19.                     return;
  20.                 }
  21.                 //Секция "Ход согласования"
  22.                 var section = reconciliationCard.GetSection(CardReconcile.ReconciliationLog.ID);
  23.                 if (section != null)
  24.                 {
  25.                 }
  26.                 //ввод комментария на отмену
  27.                 var comment = UseTaskCommentForm();
  28.                 if (string.IsNullOrWhiteSpace(comment))
  29.                 {
  30.                     //пустой комментарий
  31.                     UiService.ShowMessage(Resources.Resources.EmptyCommentError);
  32.                     return;
  33.                 }
  34.                 //нажато Cancel (***MAAAAGIC***)
  35.                 else if (string.CompareOrdinal(comment, "Cancel") == 0)
  36.                 {
  37.                     return;
  38.                 }
  39.                 //служебная секция
  40.                 var section2 = reconciliationCard.GetSection(CardReconcile.Service.ID);
  41.                 if (section2 != null)
  42.                 {
  43.                     BaseCardSectionRow baseCardSectionRow;
  44.                     if (section2.Count == 0)
  45.                     {
  46.                         baseCardSectionRow = new BaseCardSectionRow();
  47.                         //создадим, если нет
  48.                         section2.Add(baseCardSectionRow);
  49.                     }
  50.                     else
  51.                     {
  52.                         baseCardSectionRow = (section2[0] as BaseCardSectionRow);
  53.                     }
  54.                     //это у них так
  55.                     if (baseCardSectionRow != null) baseCardSectionRow["CurrentStep"] = 0;
  56.                     //меняю состояние РК документа на "Canceled"
  57.                     ChangeDocumentStateTo(HelpDictionary.Document.States.IsCancelled);
  58.                     //MainInfo согласования КС
  59.                     var section3 = reconciliationCard.GetSection(CardReconcile.MainInfo.ID);
  60.                     if (section3 != null && section3.Count == 1)
  61.                     {
  62.                         var baseCardSectionRow2 = (BaseCardSectionRow)section3[0];
  63.                         baseCardSectionRow2["Document"] = null;//очищаем ссылку на документ
  64.                     }
  65.                     //Возвращаем согласование КС в состояние Prepairing
  66.                     //Тут запуститься сам бизнес процесс на смену состояние (КС Процесс отзыва)
  67.                     if (ChangeReconcileCardStateTo(reconciliationCard, "Prepairing"))
  68.                     {
  69.                         //Запишем в историю комментарий
  70.                         AddHistoryRow(comment);
  71.                         //Закроем РК
  72.                         CardFrame.Close();
  73.                     }
  74.                 }
  75.             });
  76.         }
  77.  
  78.     /// <summary>
  79.         /// Метод для задания и для документа
  80.         /// ОН ЖЕ LOG
  81.         /// </summary>
  82.         /// <param name="sectionId"></param>
  83.         /// <returns></returns>
  84.         protected Guid? GetReconciliationId(Guid sectionId)
  85.         {
  86.             return this.CardData.Sections[sectionId].FirstRow.GetGuid("Reconciliation");
  87.         }
  88.  
  89.     /// <summary>
  90.         /// Метод для вызова окна ввода комментария
  91.         /// </summary>
  92.         /// <returns></returns>
  93.         protected string UseTaskCommentForm()
  94.         {
  95.             string comment = string.Empty;
  96.             Type taskCommentFormType =
  97.                 typeof(DocsVision.BackOffice.Cards.CardTask.MainControl).Assembly.GetType("DocsVision.BackOffice.Cards.CardTask.TaskCommentForm");
  98.             if (taskCommentFormType != null)
  99.             {
  100.                 ConstructorInfo method = taskCommentFormType.GetConstructor(
  101.                         BindingFlags.Public | BindingFlags.Instance,
  102.                         null,
  103.                         new[] { typeof(ObjectContext), typeof(string), typeof(StaffEmployee), typeof(DateTime), typeof(bool) },
  104.                         null
  105.                     );
  106.                 object o = method.Invoke(new object[] { Context, comment, StaffService.GetCurrentEmployee(), DateTime.Now, false });
  107.  
  108.                 var taskCommentForm = o as XtraForm;
  109.                 if (taskCommentForm.ShowDialog() == DialogResult.OK)
  110.                 {
  111.                     var prop = taskCommentForm.GetType().GetProperty("Comment");
  112.                     if (prop != null)
  113.                     {
  114.                         comment = prop.GetValue(taskCommentForm, null).ToString();
  115.                     }
  116.                 }
  117.                 else
  118.                 {
  119.                     comment = "Cancel";
  120.                 }
  121.                 taskCommentForm.Dispose();
  122.             }
  123.             return comment;
  124.         }
  125.  
  126.         protected void ChangeDocumentStateTo(string stateName)
  127.         {
  128.             Messages.TraceMessage("Start ChangeDocumentStateTo "+stateName);
  129.             Document @object = (Document)BaseObject;//this.MyContext.GetObject<Document>(guid.GetValueOrDefault());
  130.             if (@object == null)
  131.             {
  132.                 Messages.TraceMessage("doc is null");
  133.                 return;
  134.             }
  135.             StatesCardKindStateSetting preferredCardKindSetting = this.StateService.GetPreferredCardKindSetting(@object.SystemInfo.CardKind);
  136.             if (preferredCardKindSetting == null)
  137.             {
  138.                 Messages.TraceMessage("setting is null");
  139.                 return;
  140.             }
  141.             StatesState statesState = preferredCardKindSetting.States.FirstOrDefault((StatesState item) => item.DefaultName.Equals(stateName, StringComparison.OrdinalIgnoreCase));
  142.             if (statesState == null)
  143.             {
  144.                 Messages.TraceMessage("draftingState is null");
  145.                 return;
  146.             }
  147.             @object.SystemInfo.State = statesState;
  148.             Context.SaveObject<Document>(@object);
  149.             Messages.TraceMessage("Document state changed to " + stateName);
  150.         }
  151.  
  152.         protected bool ChangeReconcileCardStateTo(BaseCard baseCard, string stateName)
  153.         {
  154.             Messages.TraceMessage("Start ChangeReconcileCardState");
  155.             BaseCard @object = baseCard;
  156.             if (@object == null)
  157.             {
  158.                 Messages.TraceMessage("reconcile card is null");
  159.                 return false;
  160.             }
  161.             StatesCardKindStateSetting preferredCardKindSetting = this.StateService.GetPreferredCardKindSetting(@object.SystemInfo.CardKind);
  162.             if (preferredCardKindSetting == null)
  163.             {
  164.                 Messages.TraceMessage("setting is null");
  165.                 return false;
  166.             }
  167.             StatesState statesState = preferredCardKindSetting.States.FirstOrDefault((StatesState item) => item.DefaultName.Equals(stateName, StringComparison.OrdinalIgnoreCase));
  168.             if (statesState == null)
  169.             {
  170.                 Messages.TraceMessage(stateName + " is null");
  171.                 return false;
  172.             }
  173.             //@object.SystemInfo.State = statesState;
  174.             StateService.ChangeState(@object, statesState);
  175.             Context.SaveObject<BaseCard>(@object);
  176.             Messages.TraceMessage("ReconcileCard state changed to " + stateName);
  177.             return true;
  178.         }
  179.  
  180.         protected void AddHistoryRow(string comment)
  181.         {
  182.             var ReconciliationCard =
  183.                 Session.CardManager.GetCardData(GetReconciliationId(CardDocument.Reconciliation.ID).Value);
  184.             if (ReconciliationCard == null) return;
  185.             ReconciliationCard.BeginUpdate();
  186.             var row = ReconciliationCard.Sections[CardReconcile.ReconciliationLog.ID].CreateRow();
  187.             if (row != null)
  188.             {
  189.                 row.SetGuid("Employee", Context.GetObjectRef(StaffService.GetCurrentEmployee()).Id);
  190.                 row.SetString("EmployeeText", StaffService.GetCurrentEmployee().ToString());
  191.                 row.SetString("Comment", "Document was recalled from approving. Comment:" + comment);
  192.                 row.SetInt32("Cycle", GetCycle(ReconciliationCard.Sections[CardReconcile.ReconciliationLog.ID]));
  193.             }
  194.         }
  195.  
  196.         private int? GetCycle(SectionData recLogSectionData)
  197.         {
  198.             int result = 0;
  199.             var data = recLogSectionData;
  200.             if (data == null) return result;
  201.             var rows = data.GetAllRows();
  202.             if (rows != null && rows.Any())
  203.             {
  204.                 result = rows.Max(i => i.GetInt32("Cycle")).GetValueOrDefault();
  205.             }
  206.  
  207.             return result;
  208.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement