/// <summary> Populates a query object created by the base class. </summary> /// <param name="context"></param> /// <param name="pQuery"></param> protected override void PopulateQuery(CodeActivityContext context, ImpacRdbQuery pQuery) { // Activity inputs int patId1 = PatId1.Get(context); int sitId = (SitId.Expression != null) ? SitId.Get(context) : 0; DateTime startDate = CheckDateTime(StartDate.Get(context)); DateTime endDate = CheckDateTime(EndDate.Get(context)); // Get the Dose_Hst entries for the given patient pQuery.AddClause(DoseHst.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId1); // Filter on SIT_ID if supplied if (sitId != 0) { pQuery.AddClause(DoseHst.SIT_IDEntityColumn, EntityQueryOp.EQ, sitId); } // Filter on StartDate if supplied if (startDate > SqlDateTime.MinValue.Value) { pQuery.AddClause(DoseHst.Tx_DtTmEntityColumn, EntityQueryOp.GE, startDate); } // Filter on EndDate if supplied if (endDate > SqlDateTime.MinValue.Value) { pQuery.AddClause(DoseHst.Tx_DtTmEntityColumn, EntityQueryOp.LE, endDate); } }
/// <summary> Populates a query object created by the base class. </summary> /// <param name="context"></param> /// <param name="pQuery"></param> protected override void PopulateQuery(CodeActivityContext context, ImpacRdbQuery pQuery) { // Activity input int patId = PatId.Get(context); int pcpId = PcpId.Get(context); // In case startDate/endDate has input specified (Null/Nothing) it defaults to // DateTime.MinValue (0001-01-01 01:01:01). DateTime startDate = CheckDateTime(StartDate.Get(context)); DateTime endDate = CheckDateTime(EndDate.Get(context)); // Build the query pQuery.AddClause(PatCItem.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId); pQuery.AddClause(PatCItem.PCP_IDEntityColumn, EntityQueryOp.EQ, pcpId); // Filter on StartDate if supplied if (startDate > SqlDateTime.MinValue.Value) { pQuery.AddClause(PatCItem.Due_DtTmEntityColumn, EntityQueryOp.GE, startDate); } // Filter on EndDate if supplied if (endDate > SqlDateTime.MinValue.Value) { pQuery.AddClause(PatCItem.Due_DtTmEntityColumn, EntityQueryOp.LE, endDate); } }
protected override void Execute(NativeActivityContext context) { #region . Fill Header . var eventHeader = new EventHeader { EventKindCode = EventKindCode.Get(context), OperationCode = BillOperationCode.Get(context), ProcessCode = BPProcessCode.Get(context) }; var startDate = StartDate.Get(context); eventHeader.StartTime = startDate.HasValue ? startDate.Value : DateTime.Now; eventHeader.EndTime = EndDate.Get(context); eventHeader.MandantID = MandantId.Get <decimal?>(context); // авто-заполняемые поля eventHeader.Instance = context.WorkflowInstanceId.ToString(); #endregion . Fill Header . #region . Fill Params for Details . var evDetail = new EventDetail(); foreach (var parameter in Parameters) { var value = parameter.Value.Get(context); // пустые значение незачем передавать if (value == null) { continue; } if (evDetail.ContainsProperty(parameter.Key)) { evDetail.SetProperty(parameter.Key, value); } } #endregion . Fill Params for Details . var eventHeaderMgr = IoC.Instance.Resolve <IEventHeaderManager>(); var uw = BeginTransactionActivity.GetUnitOfWork(context); if (uw != null) { eventHeaderMgr.SetUnitOfWork(uw); } eventHeaderMgr.RegEvent(ref eventHeader, evDetail); context.SetValue(Result, eventHeader); }
protected override void Execute(CodeActivityContext executionContext) { TimeSpan?begin = DateUtilities.ParseTimeSpan(BusinessTimeStart.Get <string>(executionContext)); TimeSpan?end = DateUtilities.ParseTimeSpan(BusinessTimeEnd.Get <string>(executionContext)); var rules = DateUtilities.GetRules(executionContext); //Change the result based on the rules such as Check OnlyLastDay, etc. var result = DateUtilities.ModifyDateTime(rules, CheckOnlyLastDay.Get <bool>(executionContext), StartDate.Get <DateTime>(executionContext), Operations.Subtract, DaysToSubtract.Get <int>(executionContext), HoursToSubtract.Get <int>(executionContext), MinutesToSubtract.Get <int>(executionContext), begin, end); Result.Set(executionContext, result); }
protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (localContext == null) { throw new ArgumentNullException(nameof(localContext)); } var dateToCheck = StartDate.Get(context); dateToCheck = new DateTime(dateToCheck.Year, dateToCheck.Month, dateToCheck.Day, 0, 0, 0); var endDate = EndDate.Get(context); endDate = new DateTime(endDate.Year, endDate.Month, endDate.Day, 0, 0, 0); Entity calendar = null; EntityReference holidayClosureCalendar = HolidayClosureCalendar.Get(context); if (holidayClosureCalendar != null) { calendar = localContext.OrganizationService.Retrieve("calendar", holidayClosureCalendar.Id, new ColumnSet(true)); } var businessDays = 0; while (dateToCheck <= endDate) { if (dateToCheck.IsBusinessDay(calendar)) { businessDays++; } dateToCheck = dateToCheck.AddDays(1); } NumberOfBusinessDays.Set(context, businessDays); }
protected override void Execute(CodeActivityContext executionContext) { var result = new DateTime(); var start = StartDate.Get <DateTime>(executionContext); if (start != DateTime.MinValue) { result = start; } if (start != DateTime.MinValue && DaysToSubtract.Get <int>(executionContext) != 0) { result = start.AddYears(-1 * YearsToSubtract.Get <int>(executionContext)) .AddMonths(-1 * MonthsToSubtract.Get <int>(executionContext)) .AddDays((-7 * WeeksToSubtract.Get <int>(executionContext)) + (-1 * DaysToSubtract.Get <int>(executionContext))) .AddHours(-1 * HoursToSubtract.Get <int>(executionContext)) .AddMinutes(-1 * MinutesToSubtract.Get <int>(executionContext)); } Result.Set(executionContext, result); }
protected override void ExecuteWorkflowLogic() { var queryBids = new QueryExpression("opportunity") { ColumnSet = new ColumnSet("opportunityid", "selectedlevel", "name", "opportunitynbr", "siteid", "siteguid", "opportunityguid", "contractamount", "firstcontractlinecreated"), Criteria = new FilterExpression(LogicalOperator.And) }; queryBids.Criteria.AddCondition("ismasterbid", ConditionOperator.Equal, "0"); queryBids.Criteria.AddCondition("firstcontractlinecreated", ConditionOperator.Equal, "0"); queryBids.Criteria.AddCondition("svccontractnbr", ConditionOperator.Equal, ContractNbr.Get(Context.ExecutionContext).ToString()); EntityCollection bids = Context.UserService.RetrieveMultiple(queryBids); int bidCount = bids.Entities.Count(); WriteToLog("Bids Related to Service Contract: " + bidCount.ToString()); foreach (var bid in bids.Entities) { var bidTitle = bid.GetAttributeValue <string>("name"); decimal bidPrice; bool convertedPrice = decimal.TryParse(bid.FormattedValues["contractamount"], System.Globalization.NumberStyles.Currency, System.Globalization.CultureInfo.CurrentCulture.NumberFormat, out bidPrice); var bidPriceType = bidPrice.GetType(); var bidLevel = bid.FormattedValues["selectedlevel"]; var bidNumber = bid.GetAttributeValue <string>("opportunitynbr"); var siteGUID = bid.GetAttributeValue <string>("siteguid"); bool createContractLine = true; //Check for required fields from the child bid if (siteGUID == null) { WriteToLog("Missing site guid for child bid"); createContractLine = false; } if (bidNumber == null) { WriteToLog("Missing Child bid record"); createContractLine = false; } //if all the required fields are populated then create the contract line if (createContractLine) { WriteToLog("bidNumber = " + bidNumber.ToString()); WriteToLog("bidTitle = " + bidTitle.ToString()); WriteToLog("bidPrice = " + bidPrice.ToString()); WriteToLog("bidPrice Type = " + bidPriceType.ToString()); WriteToLog("bidLevel = " + bidLevel.ToString()); var queryProduct = new QueryExpression("product") { ColumnSet = new ColumnSet("productid", "name"), Criteria = new FilterExpression(LogicalOperator.And) }; queryProduct.Criteria.AddCondition("name", ConditionOperator.Equal, bidLevel.ToString()); EntityCollection products = Context.UserService.RetrieveMultiple(queryProduct); WriteToLog("Product Count: " + products.TotalRecordCount.ToString()); var contractLine = new Entity(ContractLineEntityName) { [ParentEntityLookupFieldName] = ParentEntity, ["title"] = bidTitle, ["activeon"] = StartDate.Get(Context.ExecutionContext), ["expireson"] = EndDate.Get(Context.ExecutionContext), ["customerid"] = BillToCustomer.Get(Context.ExecutionContext), ["price"] = new Money(bidPrice) }; WriteToLog("Adding Product"); ProcessAdditionalFields(ref contractLine); products.Entities.ToList().ForEach(product => { Guid productid = products.Entities[0].Id; WriteToLog("product GUID is: " + productid.ToString()); EntityReference relatedProduct = new EntityReference("product", productid); contractLine["productid"] = relatedProduct; }); Context.UserService.Create(contractLine); Guid contractlineid = new Guid(contractLine.Id.ToString()); WriteToLog("Contract Line GUID: " + contractlineid.ToString()); contractLine["contractlineguid"] = contractlineid.ToString(); //Get the child bid record to make the relationship from the contract line back to the bid var queryChildBid = new QueryExpression("opportunity") { ColumnSet = new ColumnSet("opportunityid", "opportunitynbr"), Criteria = new FilterExpression(LogicalOperator.And) }; queryChildBid.Criteria.AddCondition("opportunitynbr", ConditionOperator.Equal, bidNumber.ToString()); EntityCollection childBids = Context.UserService.RetrieveMultiple(queryChildBid); childBids.Entities.ToList().ForEach(childbid => { Guid opportunityid = childBids.Entities[0].Id; WriteToLog("Adding Related Child Bid"); EntityReference relatedBid = new EntityReference("opportunity", opportunityid); contractLine["nar_relatedbidid"] = relatedBid; WriteToLog("related child bid GUID = " + opportunityid.ToString()); }); //Relate the contract line to the site account WriteToLog("Adding Related Site"); WriteToLog("Site Guid is: " + siteGUID.ToString()); Guid siteid = new Guid(siteGUID); EntityReference relatedSite = new EntityReference("account", siteid); contractLine["siteid"] = relatedSite; Context.UserService.Update(contractLine); } } }