Files
BDF3/xsip.cs
Doug Macintosh a59a047cd1 Initial import
2026-01-04 10:55:36 -05:00

194 lines
7.3 KiB
C#
Executable File

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
class Program
{
static void Main(string[] args)
{
string sampleHtml = @"
<html>
<head>
<title>Insis Revenue</title>
<link rel=""stylesheet"" type=""text/css"" href=""../Images/OutputStyle.css"" />
<link rel=""stylesheet"" type=""text/css"" href=""../Images/TopHeadingStyle.css"" />
<script type=""text/javascript"" language=""javascript"" src=""../Includes/HighLightRow.js""></script>
</head>
<body onload = ""init()"";>
<div id=""container"">
<div id=""rogersheader""><center><font class=""header"">Revenue Details (<font class='name'>SSCGPAS001</font>)</font></center></div>
</div>
<center>
<form name=""myForm"" method =""post"" action="""">
<div align=""right"">
<font color=""#B22222""><b>Revision:</b>&nbsp;</font>
<select name=""revision"" class =""entry"" onchange =""revisionOnChange()"";>
<option value=""03"">03&nbsp;&nbsp;&nbsp;NS&nbsp;&nbsp;&nbsp;7/31/2025&nbsp;&nbsp;&nbsp;APPR</option>
<option value=""02"">02&nbsp;&nbsp;&nbsp;NS&nbsp;&nbsp;&nbsp;7/31/2025&nbsp;&nbsp;&nbsp;ARCH</option>
<option value=""01"">01&nbsp;&nbsp;&nbsp;NS&nbsp;&nbsp;&nbsp;7/31/2024&nbsp;&nbsp;&nbsp;ARCH</option>
</select>
</div>
<br />
<table class=""normal"" border=""1"" cellspacing=""0"" cellpadding=""0"">
<tr>
<td>
<table class=""line"" cellspacing=""0"" cellpadding=""6"">
<tr class=""heading2"">
<td class=""heading2"">Item</td>
<td class=""heading2"">Code</td>
<td class=""heading2"">Description</td>
<td class=""heading2"">Period</td>
<td class=""heading2"" align=""right"">Unit Price</td>
<td class=""heading2"" align=""center"">Qty</td>
<td class=""heading2"" align=""right"">Amount</td>
<td class=""heading2"" align=""center"">Billing Type</td>
<td class=""heading2"" align=""center"">Currency</td>
</tr>
<tr id=""R0"" onclick=""Highlight_Row(R0)"">
<td nowrap=""nowrap"">01 &nbsp;</td>
<td nowrap=""nowrap"">ACH&nbsp;</td>
<td nowrap=""nowrap"">100M Ethernet Fiber Access-BRE&nbsp;</td>
<td nowrap=""nowrap"">Monthly&nbsp;</td>
<td nowrap=""nowrap"" align=""right"">$200.00&nbsp;</td>
<td nowrap=""nowrap"" align=""center"">1&nbsp;</td>
<td nowrap=""nowrap"" align=""right"">$200.00&nbsp;</td>
<td nowrap=""nowrap"" align=""center""> &nbsp;</td>
<td nowrap=""nowrap"" align=""center"">CD&nbsp;</td>
</tr>
<tr id=""R1"" onclick=""Highlight_Row(R1)"">
<td nowrap=""nowrap"">04 &nbsp;</td>
<td nowrap=""nowrap"">VSS&nbsp;</td>
<td nowrap=""nowrap"">Voice Session Service-BRE &nbsp;</td>
<td nowrap=""nowrap"">Monthly&nbsp;</td>
<td nowrap=""nowrap"" align=""right"">$9.80&nbsp;</td>
<td nowrap=""nowrap"" align=""center"">14&nbsp;</td>
<td nowrap=""nowrap"" align=""right"">$137.20&nbsp;</td>
<td nowrap=""nowrap"" align=""center""> &nbsp;</td>
<td nowrap=""nowrap"" align=""center"">CD&nbsp;</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</center>
<script type=""text/javascript"" language =""javascript"">
function init() {
myForm.revision.value = ""03""
}
function revisionOnChange(){
window.location.href=""revenue.asp?serv_id=SSCGPAS001&revision="" + myForm.revision.value
}
</script>
<p></p>
<center>
<input class=""button2"" type=""button"" onclick=""top.close()"" value=""Close"" title=""Close"" />
</center>
</body>
</html>";
List<TableDataExtractor.RowData> data = TableDataExtractor.ExtractSpecificTableData(sampleHtml);
foreach (var row in data)
{
Console.WriteLine(row.ToString());
}
}
}
public class TableDataExtractor
{
// A class to hold the extracted data for a single row
public class RowData
{
public string Item { get; set; }
public string Code { get; set; }
public string Description { get; set; }
public string Period { get; set; }
public string UnitPrice { get; set; }
public string Qty { get; set; }
public string Amount { get; set; }
public string BillingType { get; set; }
public string Currency { get; set; }
public override string ToString()
{
return $"Item: {Item}, Description: {Description}, Unit Price: {UnitPrice}, Qty: {Qty}, Amount: {Amount}";
}
}
public static List<RowData> ExtractSpecificTableData(string htmlContent)
{
var extractedData = new List<RowData>();
// Regex to find table rows (<tr>) within a specific table structure (adjust if needed, e.g., using a table ID)
// The pattern uses capturing groups for each <td> content
// It assumes <td> tags might have extra spaces or attributes, but the content inside is the target.
// It specifically looks for rows with exactly 5 data cells.
string rowPattern = @"<tr\s*[^>]*?\bid=[^>]*?>(.*?)</tr\s*>"; //@"<tr\s*[^>]*>(.*?)</tr\s*>";
string cellPattern = @"<td\s*[^>]*>(.*?)</td>";
// Find all rows in the HTML
MatchCollection rows = Regex.Matches(htmlContent, rowPattern, RegexOptions.Singleline | RegexOptions.IgnoreCase);
foreach (Match rowMatch in rows)
{
string rowHtml = rowMatch.Groups[1].Value;
// Find all cells in the current row
MatchCollection cells = Regex.Matches(rowHtml, cellPattern, RegexOptions.Singleline | RegexOptions.IgnoreCase);
// Check if the row has exactly 5 columns of data (Item, Description, Unit Price, Qty, Amount)
if (cells.Count >= 9)
{
// Extract the inner text and clean up whitespace
string item = cells[0].Groups[1].Value.Replace("&nbsp;", " ").Trim();
string code = cells[1].Groups[1].Value.Replace("&nbsp;", " ").Trim();
string description = cells[2].Groups[1].Value.Replace("&nbsp;", " ").Trim();
string period = cells[3].Groups[1].Value.Replace("&nbsp;", " ").Trim();
string unitPrice = cells[4].Groups[1].Value.Replace("&nbsp;", " ").Trim();
string qty = cells[5].Groups[1].Value.Replace("&nbsp;", " ").Trim();
string amount = cells[6].Groups[1].Value.Replace("&nbsp;", " ").Trim();
string billingType = cells[7].Groups[1].Value.Replace("&nbsp;", " ").Trim();
string currency = cells[8].Groups[1].Value.Replace("&nbsp;", " ").Trim();
// Add to the list
extractedData.Add(new RowData
{
Item = item,
Code = code,
Description = description,
Period = period,
UnitPrice = unitPrice,
Qty = qty,
Amount = amount,
BillingType = billingType,
Currency = currency
});
}
}
return extractedData;
}
}