fix(form_1_2): truncate at last word boundary instead of mid-word
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
Replaced the inline Substring-based truncation (which cut mid-word, e.g. "...เนื่องจากป") with a TruncateAtWord() helper in the report's ScriptText that backs off to the last space before the length limit when one exists, falling back to a hard cut only when the text has no spaces at all within that range (common in run-on Thai text). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0153wBt23EjW125ZsADwWVAs
This commit is contained in:
@@ -1,5 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Report ScriptLanguage="CSharp" ReportInfo.Created="04/15/2021 16:43:09" ReportInfo.Modified="09/08/2026 00:00:00" ReportInfo.CreatorVersion="2021.1.0.0">
|
||||
<ScriptText>using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using FastReport;
|
||||
using FastReport.Data;
|
||||
using FastReport.Dialog;
|
||||
using FastReport.Barcode;
|
||||
using FastReport.Table;
|
||||
using FastReport.Utils;
|
||||
|
||||
namespace FastReport
|
||||
{
|
||||
public class ReportScript
|
||||
{
|
||||
// ตัดข้อความยาวเกินที่จุดเว้นวรรคสุดท้ายก่อน maxLen แทนการตัดกลางคำตรง ๆ
|
||||
// (ถ้าไม่มีช่องว่างเลยในช่วงนั้น เช่น ข้อความไทยติดกันยาว ๆ จะตัดตรง maxLen เหมือนเดิม)
|
||||
public static string TruncateAtWord(string text, int maxLen)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text) || text.Length <= maxLen) return text;
|
||||
string cut = text.Substring(0, maxLen);
|
||||
int lastSpace = cut.LastIndexOf(' ');
|
||||
if (lastSpace > 0)
|
||||
{
|
||||
cut = cut.Substring(0, lastSpace);
|
||||
}
|
||||
return cut + "...";
|
||||
}
|
||||
}
|
||||
}
|
||||
</ScriptText>
|
||||
<Dictionary>
|
||||
<BusinessObjectDataSource Name="form_1_2" ReferenceName="form_1_2" DataType="null" Enabled="true">
|
||||
<Column Name="no" DataType="System.String"/>
|
||||
@@ -80,7 +114,7 @@
|
||||
<TextObject Name="P1PosQualVal" Left="292.95" Top="28.35" Width="302.4" Height="28.35" Text="[form_1_2.form_1_2_positions.old_qualification]" HorzAlign="Center" VertAlign="Bottom" Font="TH Sarabun New, 16pt"/>
|
||||
|
||||
<TextObject Name="P1Reasons" Top="66.15" Width="718.2" Height="28.35" Text="โดยมีเหตุผลและความจำเป็นดังนี้" Font="TH Sarabun New, 16pt, style=Bold"/>
|
||||
<TextObject Name="P1ReasonsText" Top="94.5" Width="718.2" Height="94.5" Text="[([form_1_2.form_1_2_positions.reason] != null && [form_1_2.form_1_2_positions.reason].Length > 300) ? [form_1_2.form_1_2_positions.reason].Substring(0, 300) + "..." : [form_1_2.form_1_2_positions.reason]]" CanGrow="true" Font="TH Sarabun New, 16pt"/>
|
||||
<TextObject Name="P1ReasonsText" Top="94.5" Width="718.2" Height="94.5" Text="[TruncateAtWord([form_1_2.form_1_2_positions.reason], 300)]" CanGrow="true" Font="TH Sarabun New, 16pt"/>
|
||||
|
||||
<TextObject Name="P1Attach" Top="189" Width="718.2" Height="28.35" Text="พร้อมทั้งแนบเอกสารประกอบการเสนอขออัตราใหม่ มาพร้อมนี้" Font="TH Sarabun New, 16pt, style=Bold"/>
|
||||
<TextObject Name="P1AttachNote" Top="217.35" Width="718.2" Height="28.35" Text="(ขอความอนุเคราะห์กองนโยบายและแผนตรวจสอบเอกสารตามนี้)" Font="TH Sarabun New, 14pt"/>
|
||||
@@ -139,11 +173,11 @@
|
||||
|
||||
<TextObject Name="P2OldWorkLabel" Top="388.35" Width="359.1" Height="28.35" Border.Lines="Left,Right" Text="ภาระงานที่รับผิดชอบ" Font="TH Sarabun New, 16pt"/>
|
||||
<TextObject Name="P2NewWorkLabel" Left="359.1" Top="388.35" Width="359.1" Height="28.35" Border.Lines="Left,Right" Text="ภาระงานที่รับผิดชอบ" Font="TH Sarabun New, 16pt"/>
|
||||
<TextObject Name="P2OldWorkVal" Top="416.7" Width="359.1" Height="132.3" Border.Lines="Left,Right,Bottom" Text="[([form_1_2.form_1_2_positions.old_workload] != null && [form_1_2.form_1_2_positions.old_workload].Length > 200) ? [form_1_2.form_1_2_positions.old_workload].Substring(0, 200) + "..." : [form_1_2.form_1_2_positions.old_workload]]" CanGrow="true" Font="TH Sarabun New, 16pt"/>
|
||||
<TextObject Name="P2NewWorkVal" Left="359.1" Top="416.7" Width="359.1" Height="132.3" Border.Lines="Left,Right,Bottom" Text="[([form_1_2.form_1_2_positions.new_workload] != null && [form_1_2.form_1_2_positions.new_workload].Length > 200) ? [form_1_2.form_1_2_positions.new_workload].Substring(0, 200) + "..." : [form_1_2.form_1_2_positions.new_workload]]" CanGrow="true" Font="TH Sarabun New, 16pt"/>
|
||||
<TextObject Name="P2OldWorkVal" Top="416.7" Width="359.1" Height="132.3" Border.Lines="Left,Right,Bottom" Text="[TruncateAtWord([form_1_2.form_1_2_positions.old_workload], 200)]" CanGrow="true" Font="TH Sarabun New, 16pt"/>
|
||||
<TextObject Name="P2NewWorkVal" Left="359.1" Top="416.7" Width="359.1" Height="132.3" Border.Lines="Left,Right,Bottom" Text="[TruncateAtWord([form_1_2.form_1_2_positions.new_workload], 200)]" CanGrow="true" Font="TH Sarabun New, 16pt"/>
|
||||
|
||||
<TextObject Name="P2ReasonLabel" Top="558.9" Width="718.2" Height="28.35" Text="เหตุผลความจำเป็น" Font="TH Sarabun New, 16pt, style=Underline,Bold"/>
|
||||
<TextObject Name="P2ReasonVal" Top="587.25" Width="718.2" Height="94.5" Border.Lines="Bottom" Text="[([form_1_2.form_1_2_positions.reason] != null && [form_1_2.form_1_2_positions.reason].Length > 300) ? [form_1_2.form_1_2_positions.reason].Substring(0, 300) + "..." : [form_1_2.form_1_2_positions.reason]]" CanGrow="true" Font="TH Sarabun New, 16pt"/>
|
||||
<TextObject Name="P2ReasonVal" Top="587.25" Width="718.2" Height="94.5" Border.Lines="Bottom" Text="[TruncateAtWord([form_1_2.form_1_2_positions.reason], 300)]" CanGrow="true" Font="TH Sarabun New, 16pt"/>
|
||||
|
||||
<TextObject Name="P2Certify" Top="700.65" Width="718.2" Height="28.35" Text="ขอรับรองว่าข้อความดังกล่าวข้างต้นเป็นความจริงทุกประการ" Font="TH Sarabun New, 16pt"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user