Пример #1
0
        protected void GridViewParameters_Action(object sender, CommonGridViewActionEventArgs e)
        {
            if (e == null)
            {
                return;
            }

            switch (e.Action)
            {
            case CommandActions.Add:
                GridViewParameters.Visible = false;
                TableEditParameter.Visible = true;
                RuleParameterCaption.Text  = MagicForm.GetCaption(DetailsViewMode.Insert, Resources.RuleParametersControl_RuleParameterCaption_Text);
                m_EntityValue = null;
                m_FieldName   = null;
                DropDownListEntityTypes.DataBind();
                if (DropDownListEntityTypes.Items.Count > 0)
                {
                    DropDownListEntityTypes_SelectedIndexChanged(DropDownListEntityTypes, EventArgs.Empty);
                }
                break;

            case CommandActions.Edit:
                GridViewParameters.SelectedIndex = e.RowIndex;
                GridViewParameters.Visible       = false;
                TableEditParameter.Visible       = true;
                RuleParameterCaption.Text        = MagicForm.GetCaption(DetailsViewMode.Edit, Resources.RuleParametersControl_RuleParameterCaption_Text);
                ClientDataSet.RuleParametersRow row = RuleEngineProvider.GetRuleParameterRow(this.RuleParameterId);
                if (row != null)
                {
                    m_FieldName   = row.FieldName;
                    m_EntityValue = row.Value;
                    m_Term        = row.Term;
                    DropDownListEntityTypes.DataBind();
                    DropDownListEntityTypes.SelectedValue = row.EntityNodeTypeId.ToString();
                    DropDownListEntityTypes_SelectedIndexChanged(DropDownListEntityTypes, EventArgs.Empty);
                }
                break;

            case CommandActions.Delete:
                GridViewParameters.DataBind();
                break;

            default:
                break;
            }
        }
Пример #2
0
 protected void ButtonUpdateOrder_Click(object sender, EventArgs e)
 {
     foreach (GridViewRow row in List.Rows)
     {
         TextBox TextBoxOrder = row.FindControl("TextBoxOrder") as TextBox;
         object  dataId       = List.DataKeys[row.DataItemIndex].Value;
         if (TextBoxOrder != null && dataId != null)
         {
             int orderNumber = 0;
             if (int.TryParse(TextBoxOrder.Text, out orderNumber))
             {
                 RuleEngineProvider.UpdateOrderNumber((Guid)dataId, orderNumber);
             }
         }
     }
     List.DataBind();
 }
Пример #3
0
        protected void FormRuleView_DataBound(object sender, EventArgs e)
        {
            ClientDataSet.RuleRow row = FormRoleView.DataItem as ClientDataSet.RuleRow;
            Label LabelUserName       = FormRoleView.FindControl("LabelUserName") as Label;
            Label LabelUserDate       = FormRoleView.FindControl("LabelUserDate") as Label;

            if (row != null && LabelUserName != null && LabelUserDate != null)
            {
                if (!row.IsLastUsedUserNull())
                {
                    LabelUserName.Text = RuleEngineProvider.GetDisplayUserName(row.LastUsedUser, row.OrganizationId);
                }
                if (!row.IsLastUsedDateNull())
                {
                    LabelUserDate.Text = row.LastUsedDate.ToString("g", CultureInfo.CurrentCulture);
                }
            }
        }
Пример #4
0
        public static RuleCollection GetRules(Guid ruleEngineId)
        {
            Guid?instanceId = UserContext.Current.InstanceId;

            if (instanceId.Value == Guid.Empty)
            {
                instanceId = null;
            }

            RuleCollection coll = new RuleCollection();

            foreach (ClientDataSet.RuleRow row in RuleEngineProvider.GetRules(ruleEngineId, UserContext.Current.OrganizationId, instanceId))
            {
                coll.Add(Rule.Create(row));
            }
            coll.Sort();

            return(coll);
        }
Пример #5
0
        protected void LinkButtonUpdateParameter_Click(object sender, EventArgs e)
        {
            object entityValue = null;
            Type   entityType  = Type.GetType(LabelFieldsTypeFullName.Text);

            if (ComboBoxEntityValue.Visible)
            {
                entityValue = Support.ConvertStringToType(ComboBoxEntityValue.SelectedValue, entityType);
            }
            else if (DatePickerEntityValue.Visible)
            {
                entityValue = DatePickerEntityValue.SelectedDate;
            }
            else if (CheckBoxEntityValue.Visible)
            {
                entityValue = CheckBoxEntityValue.Checked;
            }
            else if (EntityTreeViewValue.Visible)
            {
                entityValue = Support.ConvertStringToType(EntityTreeViewValue.SelectedValue, typeof(Guid));
            }
            else
            {
                entityValue = Support.ConvertStringToType(TextBoxEntityValue.Text, entityType);
            }
            if (entityValue == null)
            {
                return;
            }
            if (!this.RuleId.Equals(Guid.Empty))
            {
                if (this.RuleParameterId.Equals(Guid.Empty))
                {
                    RuleEngineProvider.InsertRuleParameter(Guid.NewGuid(),
                                                           this.RuleId,
                                                           this.EntityTypeId,
                                                           true,
                                                           true,
                                                           DropDownListEntityFields.SelectedValue,
                                                           LabelFieldsTypeFullName.Text,
                                                           LabelFieldType.Text,
                                                           DropDownListTerm.SelectedValue,
                                                           entityValue);
                }
                else
                {
                    RuleEngineProvider.UpdateRuleParameter(this.RuleParameterId,
                                                           this.RuleId,
                                                           this.EntityTypeId,
                                                           true,
                                                           true,
                                                           DropDownListEntityFields.SelectedValue,
                                                           LabelFieldsTypeFullName.Text,
                                                           LabelFieldType.Text,
                                                           DropDownListTerm.SelectedValue,
                                                           entityValue);
                }

                GridViewParameters.Visible = true;
                TableEditParameter.Visible = false;
                GridViewParameters.DataBind();
                GridViewParameters.SelectedIndex = -1;
            }
        }
Пример #6
0
 public static Rule Create(string ruleName)
 {
     return(Create(RuleEngineProvider.GetRuleRow(ruleName)));
 }
Пример #7
0
 public static Rule Create(Guid organizationId, string ruleName)
 {
     return(Create(RuleEngineProvider.GetRuleRow(ruleName, organizationId)));
 }
Пример #8
0
 public static Rule Create(Guid ruleId)
 {
     return(Create(RuleEngineProvider.GetRuleRow(ruleId)));
 }
Пример #9
0
        public bool Resolve()
        {
            ClientDataSet.RuleParametersDataTable table = RuleEngineProvider.GetRuleParameters(this.RuleId);
            this.LastUsedUserId = UserContext.Current.UserId;
            RuleEngineProvider.UpdateRuleUses(
                UserContext.Current.OrganizationId,
                this.RuleId,
                UserContext.Current.UserId,
                DateTime.UtcNow);
            int count = table.Count;

            if (count == 0)
            {
                return(true);
            }
            int result = 0;

            foreach (ClientDataSet.RuleParametersRow row in table)
            {
                foreach (Entity ent in this.InputEntities)
                {
                    if (ent.Id.Equals(row.EntityNodeTypeId))
                    {
                        EntityField field = ent.Fields[row.FieldName];
                        if (field != null)
                        {
                            if (field.DataType.FullName.Equals(row.FullName) && field.Value != null)
                            {
                                #region Comparing
                                if (field.DataType == typeof(short))
                                {
                                    short short1 = (short)row.Value;
                                    short short2 = (short)field.Value;
                                    switch (row.Term)
                                    {
                                    case "==":
                                        if (short2 == short1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "!=":
                                        if (short2 != short1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case ">":
                                        if (short2 > short1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case ">=":
                                        if (short2 >= short1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "<":
                                        if (short2 < short1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "<=":
                                        if (short2 <= short1)
                                        {
                                            result++;
                                        }
                                        break;
                                    }
                                }
                                else if (field.DataType == typeof(int))
                                {
                                    int int1 = (int)row.Value;
                                    int int2 = (int)field.Value;
                                    switch (row.Term)
                                    {
                                    case "==":
                                        if (int2 == int1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "!=":
                                        if (int2 != int1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case ">":
                                        if (int2 > int1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case ">=":
                                        if (int2 >= int1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "<":
                                        if (int2 < int1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "<=":
                                        if (int2 <= int1)
                                        {
                                            result++;
                                        }
                                        break;
                                    }
                                }
                                else if (field.DataType == typeof(long))
                                {
                                    long long1 = (long)row.Value;
                                    long long2 = (long)field.Value;
                                    switch (row.Term)
                                    {
                                    case "==":
                                        if (long2 == long1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "!=":
                                        if (long2 != long1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case ">":
                                        if (long2 > long1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case ">=":
                                        if (long2 >= long1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "<":
                                        if (long2 < long1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "<=":
                                        if (long2 <= long1)
                                        {
                                            result++;
                                        }
                                        break;
                                    }
                                }
                                else if (field.DataType == typeof(decimal))
                                {
                                    decimal decimal1 = (decimal)row.Value;
                                    decimal decimal2 = (decimal)field.Value;
                                    switch (row.Term)
                                    {
                                    case "==":
                                        if (decimal2 == decimal1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "!=":
                                        if (decimal2 != decimal1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case ">":
                                        if (decimal2 > decimal1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case ">=":
                                        if (decimal2 >= decimal1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "<":
                                        if (decimal2 < decimal1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "<=":
                                        if (decimal2 <= decimal1)
                                        {
                                            result++;
                                        }
                                        break;
                                    }
                                }
                                else if (field.DataType == typeof(double))
                                {
                                    double double1 = (double)row.Value;
                                    double double2 = (double)field.Value;
                                    switch (row.Term)
                                    {
                                    case "==":
                                        if (double2 == double1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "!=":
                                        if (double2 != double1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case ">":
                                        if (double2 > double1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case ">=":
                                        if (double2 >= double1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "<":
                                        if (double2 < double1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "<=":
                                        if (double2 <= double1)
                                        {
                                            result++;
                                        }
                                        break;
                                    }
                                }
                                else if (field.DataType == typeof(float))
                                {
                                    float float1 = (float)row.Value;
                                    float float2 = (float)field.Value;
                                    switch (row.Term)
                                    {
                                    case "==":
                                        if (float2 == float1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "!=":
                                        if (float2 != float1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case ">":
                                        if (float2 > float1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case ">=":
                                        if (float2 >= float1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "<":
                                        if (float2 < float1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "<=":
                                        if (float2 <= float1)
                                        {
                                            result++;
                                        }
                                        break;
                                    }
                                }
                                else if (field.DataType == typeof(DateTime))
                                {
                                    DateTime DateTime1 = (DateTime)row.Value;
                                    DateTime DateTime2 = (DateTime)field.Value;
                                    switch (row.Term)
                                    {
                                    case "==":
                                        if (DateTime2 == DateTime1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "!=":
                                        if (DateTime2 != DateTime1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case ">":
                                        if (DateTime2 > DateTime1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case ">=":
                                        if (DateTime2 >= DateTime1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "<":
                                        if (DateTime2 < DateTime1)
                                        {
                                            result++;
                                        }
                                        break;

                                    case "<=":
                                        if (DateTime2 <= DateTime1)
                                        {
                                            result++;
                                        }
                                        break;
                                    }
                                }
                                else if (field.DataType == typeof(Entity))
                                {
                                    Guid guid1 = (Guid)row.Value;
                                    Guid guid2 = (Guid)field.Value;
                                    if (row.Term == "==")
                                    {
                                        if (guid1 == guid2)
                                        {
                                            result++;
                                        }
                                    }
                                    else if (row.Term == "!=")
                                    {
                                        if (guid1 != guid2)
                                        {
                                            result++;
                                        }
                                    }
                                }
                                else
                                {
                                    if (row.Term == "==")
                                    {
                                        if (field.Value.Equals(row.Value))
                                        {
                                            result++;
                                        }
                                    }
                                    else
                                    {
                                        if (!field.Value.Equals(row.Value))
                                        {
                                            result++;
                                        }
                                    }
                                }
                                #endregion
                                break;
                            }
                        }
                    }
                }
            }
            return(count == result);
        }