将字符串加粗,显示在RadGrid txtNote和标签中
本文关键字:txtNote RadGrid 标签 显示 字符串 | 更新日期: 2023-09-27 17:53:01
我有一个RadGrid,它在注释列中显示txtNote作为文本。我还有一个标签叫lblShowAllSessionNotes。当会话记录被添加或追加到现有的记录中时,在实际的txt消息之前会出现一种类型的ID戳,如下所示:
NoteTYPE - CommunicationType - ContactType 电子签名:某人的名字6/12/2016 12:00:00这是笔记文本。它是文本。
如果我把…在后面代码中的字符串变量中,然后在radGrid中它显示为:由电子签名:某人的名字;而不是电子签名:某人的名字....在标签中,它看起来像预期的那样粗体。
我有一个方法:
/// <summary>
/// Creates and shows all session notes in a text format.
/// </summary>
protected void ShowAllSessionNotes()
{
var allNotes = new StringBuilder();
string splitStr = "";
string[] newStr = null;
foreach (var noteItem in SessionNotes())
{
allNotes.Append("<b>" + noteItem.DmSessionNoteType + " - </b>");
allNotes.Append("<b>" + noteItem.DmCommunicationType + " - </b>");
allNotes.Append("<b>" + noteItem.DmContactType + " - </b>");
allNotes.Append(noteItem.AddDateTime + " (CST)");
if (ShowDuration)
{
allNotes.AppendFormat(" - <b>Duration:</b> {0} - <b>Electronically signed by: </b> {1}",
FormatDuration(noteItem.Duration), noteItem.CCName);
}
if (noteItem.Note.Contains('|'))
{
splitStr = noteItem.Note;
newStr = splitStr.Split('|');
noteItem.Note = String.Join("<br/>", newStr);
}
if (noteItem.Note.Contains(':') && noteItem.Note.StartsWith("Electronically"))
{
splitStr = noteItem.Note;
string bldStr = splitStr.Split(':')[0];
}
allNotes.Append("<br />");
allNotes.Append(noteItem.Note);
allNotes.Append("<br /><br />");
}
lblShowAllSessionNotes.Text = allNotes.ToString();
lblShowAllSessionNotes.Visible = true;
}
,另一个……
/// <summary>
/// Helper function that populates a session note entity.
/// </summary>
/// <param name="item">The GridEditableItem to pull data from.</param>
/// <param name="sessionNote">Existing PatientSessionNote entity.</param>
/// <returns>Returns a populated PatientSessionNote entity.</returns>
private PatientSessionNote PopulatePatientSessionNote(GridEditableItem item, ref List<string> errors)
{
var id = item.ItemIndex != -1 ? Convert.ToInt32(item.OwnerTableView.DataKeyValues[item.ItemIndex]["ID"]) : 0;
var rcb = item.FindControl("radCmbNoteType") as RadComboBox;
var rcbCC = item.FindControl("radCmbCommunicationType") as RadComboBox;
var rcbC = item.FindControl("radCmbContactType") as RadComboBox;
var rtb = item.FindControl("rtbNote") as RadTextBox;
string userSign = "Electronically signed by: ";
var appendDate = DateTime.Now;
var appendUser = User.Identity.Name;
var appendName = new MasterBLL().getUserName(appendUser);
var origSessNote = item.FindControl("HideOriginalSessionNote") as HiddenField;
string sessionNoteSent = "";
if (origSessNote.Value == "".Trim() || origSessNote == null)
{
sessionNoteSent = rtb.Text;
}
else
{
sessionNoteSent = origSessNote.Value + " | " + Environment.NewLine + userSign + appendName + " " + appendDate.ToString() + " | " + Environment.NewLine + rtb.Text;
}
var sessionNote = new PatientSessionNote
{
Id = id,
PatientId = _patientId,
DeleteReason = string.Empty,
IsDeleted = false,
LastUpdateDateTime = DateTime.Now,
LastUpdateUserName = CurrentUserId,
CommunicationTypeId = Convert.ToInt32(rcbCC.SelectedValue),
ContactTypeId = Convert.ToInt32(rcbC.SelectedValue),
SessionNoteTypeId = Convert.ToInt32(rcb.SelectedValue),
Note = Server.HtmlDecode(sessionNoteSent)
};
if (id == 0)
{
sessionNote.AddDateTime = DateTime.Now;
sessionNote.AddUserName = CurrentUserId;
}
if (ShowDuration)
{
var rdpSessionDate = item.FindControl("rdpSessionDate") as RadDatePicker;
var txtSessionStartTime = item.FindControl("txtSessionStartTime") as TextBox;
var txtSessionEndTime = item.FindControl("txtSessionEndTime") as TextBox;
//Set any existing values to NULL (for UPDATEs) so that validation doesn't allow incorrect inputs because of pre-existing old values
//This values will be redefined thru the standard INSERT practices
sessionNote.SessionStart = null;
sessionNote.SessionEnd = null;
sessionNote.Duration = 0;
if (rdpSessionDate != null && txtSessionStartTime != null && txtSessionEndTime != null)
{
var regexDate = Regex.Match(rdpSessionDate.DbSelectedDate.ToString(), @"'d{1,2}/'d{1,2}/'d{4}",
RegexOptions.Singleline);
if (regexDate.Success)
{
var startTime = Regex.Match(txtSessionStartTime.Text,
@"(?i)(?<Hours>'d{1,2}):(?<Minutes>'d{2})(?<Meridian>am|pm)", RegexOptions.Singleline);
var endTime = Regex.Match(txtSessionEndTime.Text,
@"(?i)(?<Hours>'d{1,2}):(?<Minutes>'d{2})(?<Meridian>am|pm)", RegexOptions.Singleline);
if (startTime.Success && endTime.Success)
{
//SessionStart & SessionEnd Dates
DateTime varDate;
if (DateTime.TryParse(rdpSessionDate.DbSelectedDate.ToString(), out varDate))
{
var startHours = int.Parse(startTime.Groups["Hours"].Value)%12;
var endHours = int.Parse(endTime.Groups["Hours"].Value)%12;
var startMinutes = int.Parse(startTime.Groups["Minutes"].Value);
var endMinutes = int.Parse(endTime.Groups["Minutes"].Value);
var isStartAM = Regex.IsMatch(startTime.Groups["Meridian"].Value.ToLower(), "am");
var isEndAM = Regex.IsMatch(endTime.Groups["Meridian"].Value.ToLower(), "am");
if (varDate != DateTime.MinValue)
{
var startDate = new DateTime(varDate.Year, varDate.Month, varDate.Day,
((isStartAM) ? startHours : (startHours + 12)), startMinutes, 0);
var endDate = new DateTime(varDate.Year, varDate.Month, varDate.Day,
((isEndAM) ? endHours : (endHours + 12)), endMinutes, 0);
var span = endDate.Subtract(startDate);
sessionNote.SessionStart = startDate;
if (span.TotalMinutes > 0)
//Only log if the amount of minutes is a positive number (integer)
{
sessionNote.SessionEnd = endDate;
sessionNote.Duration = (int) span.TotalMinutes;
}
else
{
errors.Add(@"The start time is greater than the end time");
errors.Add(@"Date chosen: " + rdpSessionDate.DbSelectedDate);
errors.Add(@"Start date time: " + startDate);
errors.Add(@"End date time: " + endDate);
errors.Add(@"Total minutes: " + span.TotalMinutes);
}
}
else
{
errors.Add(@"Invalid date format: " + rdpSessionDate.DbSelectedDate);
}
}
else
{
errors.Add(@"Invalid date format: " + rdpSessionDate.DbSelectedDate);
}
}
else
{
if (!startTime.Success)
{
errors.Add(@"Invalid start time format: " + txtSessionStartTime.Text);
}
if (!endTime.Success)
{
errors.Add(@"Invalid end time format: " + txtSessionEndTime.Text);
}
}
}
else
{
errors.Add(@"Invalid date format: " + rdpSessionDate.DbSelectedDate);
}
}
else
{
if (rdpSessionDate == null)
{
errors.Add(@"RadDatePicker ControlID ""rdpSessionDate"" could not be found");
}
if (txtSessionStartTime == null)
{
errors.Add(@"TextBox ControlID ""txtSessionStartTime"" could not be found");
}
if (txtSessionEndTime == null)
{
errors.Add(@"TextBox ControlID ""txtSessionEndTime"" could not be found");
}
}
}
if (errors.Count > 0)
{
errors.Add("Server date: " + DateTime.Today);
}
return sessionNote;
}
如果我加上在第二个方法PopulatePatientSessionNote(…)上的字符串userSign,然后它适用于标签,但不适用于网格。谢谢你的帮助!
由于时间限制,我这样做了:这是混乱的,但它的工作。
我首先添加了一个属性:
公共字符串UserSign {get;设置;}
在PopulatePatientSessionNote(…)方法中,我添加了这个:
UserSign = "" + UserSign + "";
sessionNoteSent = origSessNote。值+ " | " +环境。NewLine + " ' " + appendName + " " + appendDate.ToString() + " | " + Environment。
然后在ShowAllSessionNotes(…)方法中我添加了:
splitStr = noteItem.Note;newStr = splitStr.Split(' ");noteItem。注释=字符串。加入(UserSign newStr);
这是混乱的,但它的工作。有人有更好的主意吗?多谢了!!