Beispiel #1
0
        public void Submit_OnClick(object sender, EventArgs e)
        {
            var ruleInfoList = Main.IdentifierRuleRepository.GetRuleInfoList(SiteId);

            if (_ruleId > 0)
            {
                var ruleInfo       = Main.IdentifierRuleRepository.GetIdentifierRuleInfo(_ruleId);
                var identifierType = EIdentifierTypeUtils.GetEnumType(ruleInfo.IdentifierType);

                ruleInfo.RuleName       = TbRuleName.Text;
                ruleInfo.IdentifierType = DdlIdentifierType.SelectedValue;
                ruleInfo.MinLength      = TranslateUtils.ToInt(TbMinLength.Text);
                ruleInfo.Suffix         = TbSuffix.Text;
                ruleInfo.FormatString   = TbFormatString.Text;
                ruleInfo.AttributeName  = DdlAttributeName.SelectedValue;
                ruleInfo.Sequence       = TranslateUtils.ToInt(TbSequence.Text);

                if (identifierType == EIdentifierType.Sequence)
                {
                    ruleInfo.IsSequenceChannelZero    = TranslateUtils.ToBool(DdlIsSequenceChannelZero.SelectedValue);
                    ruleInfo.IsSequenceDepartmentZero = TranslateUtils.ToBool(DdlIsSequenceDepartmentZero.SelectedValue);
                    ruleInfo.IsSequenceYearZero       = TranslateUtils.ToBool(DdlIsSequenceYearZero.SelectedValue);
                }

                foreach (var identifierRuleInfo in ruleInfoList)
                {
                    if (identifierRuleInfo.Id == ruleInfo.Id)
                    {
                        continue;
                    }
                    if (identifierType != EIdentifierType.Attribute && identifierRuleInfo.IdentifierType == ruleInfo.IdentifierType)
                    {
                        LtlMessage.Text = Utils.GetMessageHtml("规则修改失败,本类型规则只能添加一次!", false);
                        return;
                    }
                    if (identifierRuleInfo.RuleName == TbRuleName.Text)
                    {
                        LtlMessage.Text = Utils.GetMessageHtml("规则修改失败,规则名称已存在!", false);
                        return;
                    }
                }

                Main.IdentifierRuleRepository.Update(ruleInfo);
            }
            else
            {
                var identifierType = EIdentifierTypeUtils.GetEnumType(DdlIdentifierType.SelectedValue);

                foreach (var thrRuleInfo in ruleInfoList)
                {
                    var ruleIdentifierType = EIdentifierTypeUtils.GetEnumType(thrRuleInfo.IdentifierType);
                    if (identifierType != EIdentifierType.Attribute && identifierType == ruleIdentifierType)
                    {
                        LtlMessage.Text = Utils.GetMessageHtml("规则添加失败,本类型规则只能添加一次!", false);
                        return;
                    }
                    if (thrRuleInfo.RuleName == TbRuleName.Text)
                    {
                        LtlMessage.Text = Utils.GetMessageHtml("规则添加失败,规则名称已存在!", false);
                        return;
                    }
                }

                var ruleInfo = new IdentifierRuleInfo
                {
                    SiteId         = SiteId,
                    RuleName       = TbRuleName.Text,
                    IdentifierType = EIdentifierTypeUtils.GetValue(identifierType),
                    MinLength      = TranslateUtils.ToInt(TbMinLength.Text),
                    Suffix         = TbSuffix.Text,
                    FormatString   = TbFormatString.Text,
                    AttributeName  = DdlAttributeName.SelectedValue,
                    Sequence       = TranslateUtils.ToInt(TbSequence.Text)
                };

                if (identifierType == EIdentifierType.Sequence)
                {
                    ruleInfo.IsSequenceChannelZero    = TranslateUtils.ToBool(DdlIsSequenceChannelZero.SelectedValue);
                    ruleInfo.IsSequenceDepartmentZero = TranslateUtils.ToBool(DdlIsSequenceDepartmentZero.SelectedValue);
                    ruleInfo.IsSequenceYearZero       = TranslateUtils.ToBool(DdlIsSequenceYearZero.SelectedValue);
                }

                Main.IdentifierRuleRepository.Insert(ruleInfo);
            }

            Utils.CloseModalPage(Page);
        }
        public IList <IdentifierRuleInfo> GetRuleInfoList(int siteId)
        {
            var list = _repository.GetAll(Q.Where(Attr.SiteId, siteId));

            //             var list = new List<IdentifierRuleInfo>();

            //             var sqlString = $@"SELECT
            //     {nameof(IdentifierRuleInfo.Id)},
            //     {nameof(IdentifierRuleInfo.SiteId)},
            //     {nameof(IdentifierRuleInfo.RuleName)},
            //     {nameof(IdentifierRuleInfo.IdentifierType)},
            //     {nameof(IdentifierRuleInfo.MinLength)},
            //     {nameof(IdentifierRuleInfo.Suffix)},
            //     {nameof(IdentifierRuleInfo.FormatString)},
            //     {nameof(IdentifierRuleInfo.AttributeName)},
            //     {nameof(IdentifierRuleInfo.Sequence)},
            //     {nameof(IdentifierRuleInfo.Taxis)},
            //     {nameof(IdentifierRuleInfo.IsSequenceChannelZero)},
            //     {nameof(IdentifierRuleInfo.IsSequenceDepartmentZero)},
            //     {nameof(IdentifierRuleInfo.IsSequenceYearZero)}
            // FROM {TableName} WHERE {nameof(IdentifierRuleInfo.SiteId)} = @{nameof(IdentifierRuleInfo.SiteId)}";

            //             var parameters = new[]
            //             {
            //                 Context.DatabaseApi.GetParameter(nameof(IdentifierRuleInfo.SiteId), siteId)
            //             };

            //             using (var rdr = Context.DatabaseApi.ExecuteReader(Context.ConnectionString, sqlString, parameters))
            //             {
            //                 while (rdr.Read())
            //                 {
            //                     var ruleInfo = GetIdentifierRuleInfo(rdr);
            //                     list.Add(ruleInfo);
            //                 }
            //                 rdr.Close();
            //             }

            if (list.Count == 0)
            {
                list = new List <IdentifierRuleInfo>
                {
                    new IdentifierRuleInfo
                    {
                        SiteId         = siteId,
                        RuleName       = "机构分类代码",
                        IdentifierType = EIdentifierTypeUtils.GetValue(EIdentifierType.Department),
                        MinLength      = 5,
                        Suffix         = "-"
                    },
                    new IdentifierRuleInfo
                    {
                        SiteId         = siteId,
                        RuleName       = "主题分类代码",
                        IdentifierType = EIdentifierTypeUtils.GetValue(EIdentifierType.Channel),
                        MinLength      = 5,
                        Suffix         = "-"
                    },
                    new IdentifierRuleInfo
                    {
                        SiteId         = siteId,
                        RuleName       = "生效日期",
                        IdentifierType = EIdentifierTypeUtils.GetValue(EIdentifierType.Attribute),
                        Suffix         = "-",
                        AttributeName  = ContentAttribute.EffectDate,
                        FormatString   = "yyyy"
                    },
                    new IdentifierRuleInfo
                    {
                        SiteId         = siteId,
                        RuleName       = "顺序号",
                        IdentifierType = EIdentifierTypeUtils.GetValue(EIdentifierType.Sequence),
                        MinLength      = 5
                    }
                };

                foreach (var ruleInfo in list)
                {
                    ruleInfo.Id = Insert(ruleInfo);
                }
            }

            return(list);
        }