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 Page_Load(object sender, EventArgs e) { _ruleId = TranslateUtils.ToInt(Request.QueryString["ruleId"]); if (IsPostBack) { return; } EIdentifierTypeUtils.AddListItems(DdlIdentifierType); var inputStyles = Main.ContentRepository.InputStyles; foreach (var tableColumn in inputStyles) { if (tableColumn.InputType == null || tableColumn.AttributeName == nameof(IContentInfo.Title) || tableColumn.AttributeName == nameof(IContentInfo.Color) || tableColumn.AttributeName == nameof(IContentInfo.Hot) || tableColumn.AttributeName == nameof(IContentInfo.Recommend) || tableColumn.AttributeName == nameof(IContentInfo.Top) || tableColumn.AttributeName == ContentAttribute.Content || tableColumn.AttributeName == ContentAttribute.DepartmentId || tableColumn.AttributeName == ContentAttribute.Description || tableColumn.AttributeName == ContentAttribute.ImageUrl || tableColumn.AttributeName == ContentAttribute.FileUrl || tableColumn.AttributeName == ContentAttribute.Identifier || tableColumn.AttributeName == ContentAttribute.Keywords || tableColumn.AttributeName == ContentAttribute.DocumentNo || tableColumn.AttributeName == ContentAttribute.IsAbolition || tableColumn.AttributeName == ContentAttribute.Publisher) { continue; } DdlAttributeName.Items.Add(new ListItem(tableColumn.DisplayName + "(" + tableColumn.AttributeName + ")", tableColumn.AttributeName)); } Utils.AddListItems(DdlIsSequenceChannelZero); Utils.AddListItems(DdlIsSequenceDepartmentZero); Utils.AddListItems(DdlIsSequenceYearZero); Utils.SelectSingleItemIgnoreCase(DdlIsSequenceChannelZero, true.ToString()); Utils.SelectSingleItemIgnoreCase(DdlIsSequenceDepartmentZero, false.ToString()); Utils.SelectSingleItemIgnoreCase(DdlIsSequenceYearZero, true.ToString()); if (_ruleId > 0) { var ruleInfo = Main.IdentifierRuleRepository.GetIdentifierRuleInfo(_ruleId); if (ruleInfo != null) { TbRuleName.Text = ruleInfo.RuleName; Utils.SelectSingleItemIgnoreCase(DdlIdentifierType, ruleInfo.IdentifierType); Utils.SelectSingleItemIgnoreCase(DdlAttributeName, ruleInfo.AttributeName); TbMinLength.Text = ruleInfo.MinLength.ToString(); TbFormatString.Text = ruleInfo.FormatString; TbSuffix.Text = ruleInfo.Suffix; TbSequence.Text = ruleInfo.Sequence.ToString(); Utils.SelectSingleItemIgnoreCase(DdlIsSequenceChannelZero, ruleInfo.IsSequenceChannelZero.ToString()); Utils.SelectSingleItemIgnoreCase(DdlIsSequenceDepartmentZero, ruleInfo.IsSequenceDepartmentZero.ToString()); Utils.SelectSingleItemIgnoreCase(DdlIsSequenceYearZero, ruleInfo.IsSequenceYearZero.ToString()); } } DdlIdentifierType_SelectedIndexChanged(null, EventArgs.Empty); }
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); }