public static bool IsIdentifierChanged(int siteId, int channelId, int departmentId, DateTime effectDate, IContentInfo contentInfo) { var isIdentifierChanged = false; var ruleInfoList = Main.IdentifierRuleRepository.GetRuleInfoList(siteId); foreach (var ruleInfo in ruleInfoList) { var identifierType = EIdentifierTypeUtils.GetEnumType(ruleInfo.IdentifierType); if (identifierType == EIdentifierType.Department) { if (contentInfo.Get <int>(nameof(ContentAttribute.DepartmentId)) != departmentId) { isIdentifierChanged = true; } } else if (identifierType == EIdentifierType.Channel) { if (contentInfo.Id != channelId) { isIdentifierChanged = true; } } else if (identifierType == EIdentifierType.Attribute) { if (Utils.EqualsIgnoreCase(ruleInfo.AttributeName, ContentAttribute.EffectDate) && TranslateUtils.ToDateTime(contentInfo.Get <string>(ruleInfo.AttributeName)) != effectDate) { isIdentifierChanged = true; } } } return(isIdentifierChanged); }
public void DdlIdentifierType_SelectedIndexChanged(object sender, EventArgs e) { var identifierType = EIdentifierTypeUtils.GetEnumType(DdlIdentifierType.SelectedValue); if (identifierType == EIdentifierType.Department || identifierType == EIdentifierType.Channel) { PhAttributeName.Visible = false; PhFormatString.Visible = false; PhMinLength.Visible = true; PhSequence.Visible = false; } else if (identifierType == EIdentifierType.Sequence) { PhAttributeName.Visible = false; PhFormatString.Visible = false; PhMinLength.Visible = true; PhSequence.Visible = true; } else if (identifierType == EIdentifierType.Attribute) { PhAttributeName.Visible = true; PhFormatString.Visible = true; PhMinLength.Visible = true; PhSequence.Visible = false; } }
private void DgContents_ItemDataBound(object sender, DataGridItemEventArgs e) { if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem) { return; } var ruleInfo = (IdentifierRuleInfo)e.Item.DataItem; var identifierType = EIdentifierTypeUtils.GetEnumType(ruleInfo.IdentifierType); var ltlIndex = (Literal)e.Item.FindControl("ltlIndex"); var ltlRuleName = (Literal)e.Item.FindControl("ltlRuleName"); var ltlIdentifierType = (Literal)e.Item.FindControl("ltlIdentifierType"); var ltlMinLength = (Literal)e.Item.FindControl("ltlMinLength"); var ltlSuffix = (Literal)e.Item.FindControl("ltlSuffix"); var hlUpLinkButton = (HyperLink)e.Item.FindControl("hlUpLinkButton"); var hlDownLinkButton = (HyperLink)e.Item.FindControl("hlDownLinkButton"); var ltlSettingUrl = (Literal)e.Item.FindControl("ltlSettingUrl"); var ltlEditUrl = (Literal)e.Item.FindControl("ltlEditUrl"); var ltlDeleteUrl = (Literal)e.Item.FindControl("ltlDeleteUrl"); ltlIndex.Text = (e.Item.ItemIndex + 1).ToString(); ltlRuleName.Text = ruleInfo.RuleName; ltlIdentifierType.Text = EIdentifierTypeUtils.GetText(identifierType); ltlMinLength.Text = ruleInfo.MinLength.ToString(); ltlSuffix.Text = ruleInfo.Suffix; var redirectUrl = GetRedirectUrl(SiteId); hlUpLinkButton.NavigateUrl = $"{redirectUrl}&up={true}&ruleId={ruleInfo.Id}"; hlDownLinkButton.NavigateUrl = $"{redirectUrl}&down={true}&ruleId={ruleInfo.Id}"; //if (ruleInfo.IdentifierType == EIdentifierType.Department) //{ // var urlSetting = PageGovPublicDepartment.GetRedirectUrl(SiteId); // ltlSettingUrl.Text = $@"<a href=""{urlSetting}"">机构分类设置</a>"; //} //else if (ruleInfo.IdentifierType == EGovPublicIdentifierType.Channel) //{ // ltlSettingUrl.Text = $@"<a href=""{PageGovPublicChannel.GetRedirectUrl(SiteId)}"">主题分类设置</a>"; //} ltlEditUrl.Text = $@"<a href='javascript:;' onclick=""{ModalIdentifierRuleAdd.GetOpenWindowStringToEdit( SiteId, ruleInfo.Id)}"">编辑</a>"; ltlDeleteUrl.Text = $@"<a href=""{redirectUrl}&delete={true}&ruleId={ruleInfo.Id}"" onClick=""javascript:return confirm('此操作将删除规则“{ruleInfo.RuleName}”,确认吗?');"">删除</a>"; }
public static string GetPreviewIdentifier(int siteId) { var builder = new StringBuilder(); var ruleInfoList = Main.IdentifierRuleRepository.GetRuleInfoList(siteId); foreach (var ruleInfo in ruleInfoList) { var identifierType = EIdentifierTypeUtils.GetEnumType(ruleInfo.IdentifierType); if (identifierType == EIdentifierType.Department) { if (ruleInfo.MinLength > 0) { builder.Append("D123".PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix); } else { builder.Append("D123").Append(ruleInfo.Suffix); } } else if (identifierType == EIdentifierType.Channel) { if (ruleInfo.MinLength > 0) { builder.Append("C123".PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix); } else { builder.Append("C123").Append(ruleInfo.Suffix); } } else if (identifierType == EIdentifierType.Attribute) { if (ruleInfo.AttributeName == ContentAttribute.AbolitionDate || ruleInfo.AttributeName == ContentAttribute.EffectDate || ruleInfo.AttributeName == ContentAttribute.PublishDate || ruleInfo.AttributeName == nameof(IContentInfo.AddDate)) { if (ruleInfo.MinLength > 0) { builder.Append(DateTime.Now.ToString(ruleInfo.FormatString).PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix); } else { builder.Append(DateTime.Now.ToString(ruleInfo.FormatString)).Append(ruleInfo.Suffix); } } else { if (ruleInfo.MinLength > 0) { builder.Append("A123".PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix); } else { builder.Append("A123").Append(ruleInfo.Suffix); } } } else if (identifierType == EIdentifierType.Sequence) { if (ruleInfo.MinLength > 0) { builder.Append("1".PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix); } else { builder.Append("1").Append(ruleInfo.Suffix); } } } return(builder.ToString()); }
public static string GetIdentifier(int siteId, int channelId, int departmentId, IContentInfo contentInfo) { if (contentInfo == null) { return(string.Empty); } var channelInfo = Context.ChannelApi.GetChannelInfo(siteId, channelId); if (channelInfo == null) { return(string.Empty); } var builder = new StringBuilder(); var ruleInfoList = Main.IdentifierRuleRepository.GetRuleInfoList(siteId); foreach (var ruleInfo in ruleInfoList) { var identifierType = EIdentifierTypeUtils.GetEnumType(ruleInfo.IdentifierType); if (identifierType == EIdentifierType.Department) { var departmentCode = DepartmentManager.GetDepartmentCode(siteId, departmentId); if (ruleInfo.MinLength > 0) { builder.Append(departmentCode.PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix); } else { builder.Append(departmentCode).Append(ruleInfo.Suffix); } } else if (identifierType == EIdentifierType.Channel) { var channelCode = channelInfo.Id.ToString(); if (ruleInfo.MinLength > 0) { builder.Append(channelCode.PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix); } else { builder.Append(channelCode).Append(ruleInfo.Suffix); } } else if (identifierType == EIdentifierType.Attribute) { if (ruleInfo.AttributeName == ContentAttribute.AbolitionDate || ruleInfo.AttributeName == ContentAttribute.EffectDate || ruleInfo.AttributeName == ContentAttribute.PublishDate || ruleInfo.AttributeName == nameof(IContentInfo.AddDate)) { var dateTime = TranslateUtils.ToDateTime(contentInfo.Get <string>(ruleInfo.AttributeName)); if (ruleInfo.MinLength > 0) { builder.Append(dateTime.ToString(ruleInfo.FormatString).PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix); } else { builder.Append(dateTime.ToString(ruleInfo.FormatString)).Append(ruleInfo.Suffix); } } else { var attributeValue = contentInfo.Get <string>(ruleInfo.AttributeName); if (ruleInfo.MinLength > 0) { builder.Append(attributeValue.PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix); } else { builder.Append(attributeValue).Append(ruleInfo.Suffix); } } } else if (identifierType == EIdentifierType.Sequence) { var targetSiteId = siteId; var targetChannelId = 0; if (ruleInfo.IsSequenceChannelZero) { targetChannelId = channelInfo.Id; } var targetDepartmentId = 0; if (ruleInfo.IsSequenceDepartmentZero) { targetDepartmentId = departmentId; } var targetAddYear = 0; if (ruleInfo.IsSequenceYearZero && contentInfo.AddDate != null) { targetAddYear = contentInfo.AddDate.Value.Year; } var sequence = Main.IdentifierSeqRepository.GetSequence(targetSiteId, targetChannelId, targetDepartmentId, targetAddYear, ruleInfo.Sequence); if (ruleInfo.MinLength > 0) { builder.Append(sequence.ToString().PadLeft(ruleInfo.MinLength, '0')).Append(ruleInfo.Suffix); } else { builder.Append(sequence.ToString()).Append(ruleInfo.Suffix); } } } return(builder.ToString()); }
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); }