Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void RecallApproving()
- {
- this.Try(delegate
- {
- //ссылка на карточку согласования
- var recId = GetReconciliationId(CardDocument.Reconciliation.ID);
- if (!recId.HasValue)
- {
- //нет запущенного согласования
- UiService.ShowMessage(Resources.Resources.NoReconciliation);
- return;
- }
- //получили BaseCard согласования КС
- var reconciliationCard =
- Context.GetObject<BaseCard>(recId.Value);
- if (reconciliationCard == null)
- {
- Messages.TraceMessage("reconciliationCard==null");
- return;
- }
- //Секция "Ход согласования"
- var section = reconciliationCard.GetSection(CardReconcile.ReconciliationLog.ID);
- if (section != null)
- {
- }
- //ввод комментария на отмену
- var comment = UseTaskCommentForm();
- if (string.IsNullOrWhiteSpace(comment))
- {
- //пустой комментарий
- UiService.ShowMessage(Resources.Resources.EmptyCommentError);
- return;
- }
- //нажато Cancel (***MAAAAGIC***)
- else if (string.CompareOrdinal(comment, "Cancel") == 0)
- {
- return;
- }
- //служебная секция
- var section2 = reconciliationCard.GetSection(CardReconcile.Service.ID);
- if (section2 != null)
- {
- BaseCardSectionRow baseCardSectionRow;
- if (section2.Count == 0)
- {
- baseCardSectionRow = new BaseCardSectionRow();
- //создадим, если нет
- section2.Add(baseCardSectionRow);
- }
- else
- {
- baseCardSectionRow = (section2[0] as BaseCardSectionRow);
- }
- //это у них так
- if (baseCardSectionRow != null) baseCardSectionRow["CurrentStep"] = 0;
- //меняю состояние РК документа на "Canceled"
- ChangeDocumentStateTo(HelpDictionary.Document.States.IsCancelled);
- //MainInfo согласования КС
- var section3 = reconciliationCard.GetSection(CardReconcile.MainInfo.ID);
- if (section3 != null && section3.Count == 1)
- {
- var baseCardSectionRow2 = (BaseCardSectionRow)section3[0];
- baseCardSectionRow2["Document"] = null;//очищаем ссылку на документ
- }
- //Возвращаем согласование КС в состояние Prepairing
- //Тут запуститься сам бизнес процесс на смену состояние (КС Процесс отзыва)
- if (ChangeReconcileCardStateTo(reconciliationCard, "Prepairing"))
- {
- //Запишем в историю комментарий
- AddHistoryRow(comment);
- //Закроем РК
- CardFrame.Close();
- }
- }
- });
- }
- /// <summary>
- /// Метод для задания и для документа
- /// ОН ЖЕ LOG
- /// </summary>
- /// <param name="sectionId"></param>
- /// <returns></returns>
- protected Guid? GetReconciliationId(Guid sectionId)
- {
- return this.CardData.Sections[sectionId].FirstRow.GetGuid("Reconciliation");
- }
- /// <summary>
- /// Метод для вызова окна ввода комментария
- /// </summary>
- /// <returns></returns>
- protected string UseTaskCommentForm()
- {
- string comment = string.Empty;
- Type taskCommentFormType =
- typeof(DocsVision.BackOffice.Cards.CardTask.MainControl).Assembly.GetType("DocsVision.BackOffice.Cards.CardTask.TaskCommentForm");
- if (taskCommentFormType != null)
- {
- ConstructorInfo method = taskCommentFormType.GetConstructor(
- BindingFlags.Public | BindingFlags.Instance,
- null,
- new[] { typeof(ObjectContext), typeof(string), typeof(StaffEmployee), typeof(DateTime), typeof(bool) },
- null
- );
- object o = method.Invoke(new object[] { Context, comment, StaffService.GetCurrentEmployee(), DateTime.Now, false });
- var taskCommentForm = o as XtraForm;
- if (taskCommentForm.ShowDialog() == DialogResult.OK)
- {
- var prop = taskCommentForm.GetType().GetProperty("Comment");
- if (prop != null)
- {
- comment = prop.GetValue(taskCommentForm, null).ToString();
- }
- }
- else
- {
- comment = "Cancel";
- }
- taskCommentForm.Dispose();
- }
- return comment;
- }
- protected void ChangeDocumentStateTo(string stateName)
- {
- Messages.TraceMessage("Start ChangeDocumentStateTo "+stateName);
- Document @object = (Document)BaseObject;//this.MyContext.GetObject<Document>(guid.GetValueOrDefault());
- if (@object == null)
- {
- Messages.TraceMessage("doc is null");
- return;
- }
- StatesCardKindStateSetting preferredCardKindSetting = this.StateService.GetPreferredCardKindSetting(@object.SystemInfo.CardKind);
- if (preferredCardKindSetting == null)
- {
- Messages.TraceMessage("setting is null");
- return;
- }
- StatesState statesState = preferredCardKindSetting.States.FirstOrDefault((StatesState item) => item.DefaultName.Equals(stateName, StringComparison.OrdinalIgnoreCase));
- if (statesState == null)
- {
- Messages.TraceMessage("draftingState is null");
- return;
- }
- @object.SystemInfo.State = statesState;
- Context.SaveObject<Document>(@object);
- Messages.TraceMessage("Document state changed to " + stateName);
- }
- protected bool ChangeReconcileCardStateTo(BaseCard baseCard, string stateName)
- {
- Messages.TraceMessage("Start ChangeReconcileCardState");
- BaseCard @object = baseCard;
- if (@object == null)
- {
- Messages.TraceMessage("reconcile card is null");
- return false;
- }
- StatesCardKindStateSetting preferredCardKindSetting = this.StateService.GetPreferredCardKindSetting(@object.SystemInfo.CardKind);
- if (preferredCardKindSetting == null)
- {
- Messages.TraceMessage("setting is null");
- return false;
- }
- StatesState statesState = preferredCardKindSetting.States.FirstOrDefault((StatesState item) => item.DefaultName.Equals(stateName, StringComparison.OrdinalIgnoreCase));
- if (statesState == null)
- {
- Messages.TraceMessage(stateName + " is null");
- return false;
- }
- //@object.SystemInfo.State = statesState;
- StateService.ChangeState(@object, statesState);
- Context.SaveObject<BaseCard>(@object);
- Messages.TraceMessage("ReconcileCard state changed to " + stateName);
- return true;
- }
- protected void AddHistoryRow(string comment)
- {
- var ReconciliationCard =
- Session.CardManager.GetCardData(GetReconciliationId(CardDocument.Reconciliation.ID).Value);
- if (ReconciliationCard == null) return;
- ReconciliationCard.BeginUpdate();
- var row = ReconciliationCard.Sections[CardReconcile.ReconciliationLog.ID].CreateRow();
- if (row != null)
- {
- row.SetGuid("Employee", Context.GetObjectRef(StaffService.GetCurrentEmployee()).Id);
- row.SetString("EmployeeText", StaffService.GetCurrentEmployee().ToString());
- row.SetString("Comment", "Document was recalled from approving. Comment:" + comment);
- row.SetInt32("Cycle", GetCycle(ReconciliationCard.Sections[CardReconcile.ReconciliationLog.ID]));
- }
- }
- private int? GetCycle(SectionData recLogSectionData)
- {
- int result = 0;
- var data = recLogSectionData;
- if (data == null) return result;
- var rows = data.GetAllRows();
- if (rows != null && rows.Any())
- {
- result = rows.Max(i => i.GetInt32("Cycle")).GetValueOrDefault();
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement