public void EventCaseCompleted(object sender, EventArgs args) { lock (_lockLogic) { try { Case_Dto trigger = (Case_Dto)sender; int siteId = trigger.SiteUId; string caseType = trigger.CaseType; string caseUid = trigger.CaseUId; string mUId = trigger.MicrotingUId; string checkUId = trigger.CheckUId; //-------------------- Random rdn = new Random(); #region create offering if (caseType == "Step one") { CoreElement reply = core.CaseRead(mUId, checkUId); CheckListValue replyDataE = (CheckListValue)reply.ElementList[0]; FieldValue answer = (FieldValue)replyDataE.DataItemList[0]; MainElement mainElement = core.TemplateRead(step2tId); DataElement dataE = (DataElement)mainElement.ElementList[0]; None none = (None)dataE.DataItemList[0]; none.Label = "Container with stat:" + answer.Value + " is ready for collection"; none.Description = new CDataValue(); none.Description.InderValue = DateTime.Now.ToShortDateString() + "/" + DateTime.Now.ToLongTimeString(); foreach (int siteIdTemp in siteIdsSA) { core.CaseCreate(mainElement, "", siteIdTemp); } } #endregion #region create replies (winner/others) if (caseType == "Step two") { #region is the first? bool isFirst = false; int found = 0; try { List <Case_Dto> lst = core.CaseLookupCaseUId(caseUid); foreach (var item in lst) { if (item.Stat == "Completed") { found++; } } if (found == 1) { isFirst = true; } } catch (Exception ex) { throw new Exception("isFirst failed", ex); } #endregion if (isFirst) { #region send win eForm CoreElement reply = core.CaseRead(mUId, checkUId); DataElement replyDataE = (DataElement)reply.ElementList[0]; FieldValue answer = (FieldValue)replyDataE.DataItemList[0]; MainElement mainElement = core.TemplateRead(step3WtId); DataElement dataE = (DataElement)mainElement.ElementList[0]; Date date = (Date)dataE.DataItemList[0]; dataE.Description = new CDataValue(); dataE.Description.InderValue = DateTime.Now.ToShortDateString() + "/" + DateTime.Now.ToLongTimeString(); date.MinValue = DateTime.Now; date.MaxValue = DateTime.Now.AddDays(1); date.DefaultValue = DateTime.Now.AddMinutes(1).ToString("u"); core.CaseCreate(mainElement, "", siteId); #endregion } else { #region send loss eForm CoreElement reply = core.CaseRead(mUId, checkUId); DataElement replyDataE = (DataElement)reply.ElementList[0]; FieldValue answer = (FieldValue)replyDataE.DataItemList[0]; MainElement mainElement = core.TemplateRead(step3LtId); DataElement dataE = (DataElement)mainElement.ElementList[0]; None none = (None)dataE.DataItemList[0]; none.Description = new CDataValue(); none.Description.InderValue = "Collection missed at:" + DateTime.Now.ToShortDateString() + "/" + DateTime.Now.ToLongTimeString(); core.CaseCreate(mainElement, "", siteId); #endregion } } #endregion #region final step if (caseType == "Step three") { CoreElement reply = core.CaseRead(mUId, checkUId); DataElement replyDataE = (DataElement)reply.ElementList[0]; FieldValue answer = (FieldValue)replyDataE.DataItemList[0]; #region is the winner? bool isWinner = false; try { if (replyDataE.Label == "Won - Container collection") { isWinner = true; } } catch (Exception ex) { throw new Exception("isWinner failed", ex); } #endregion if (isWinner) { MainElement mainElement = core.TemplateRead(step4tId); DataElement dataE = (DataElement)mainElement.ElementList[0]; None none = (None)dataE.DataItemList[0]; none.Label = "Container collect at:" + answer.Value; foreach (int siteIdTemp in siteIdsDW) { core.CaseCreate(mainElement, "", siteIdTemp); } } } #endregion } catch (Exception ex) { EventMessage(ex.ToString(), EventArgs.Empty); } } }