我正在处理已经创建的窗口窗体,我必须使用该代码并进一步处理现在认为该代码在一个地方工作但它不会在其他地方工作它会给我一个错误消息长度不能小于零
这是我的代码:
aspx.cs 代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
namespace AQCConsolidator1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnGetData_Click(object sender, EventArgs e)
{
List<String> list = new List<String>();
List<String> list1 = new List<String>();
string request = @"RP/DCA1S219C/DCA1S219C SL/SU 9APR13/2223Z 4YYTR7
45 FA PAX 257-7242858184/ETOS/USD736.23/08APR13/DCA1S211E/49881
134/S3-6/P1
46 FA PAX 257-7242858185/ETOS/USD736.23/08APR13/DCA1S211E/49881
134/S3-6/P2
030 AF/FA 257-7242215364/ETOS/USD778.23/07APR13/DCA1S219C/
49881134/OS 850 K 31MAY TIAVIE/OS 087 K 31MAY VIEJFK/OS
088 L 09JUN JFKVIE/OS 847 L 10JUN VIETIA/MBYETI/PETRAQ(
ADT)
030 AF/FA 257-7242215365/ETOS/USD778.23/07APR13/DCA1S219C/
49881134/OS 850 K 31MAY TIAVIE/OS 087 K 31MAY VIEJFK/OS
088 L 09JUN JFKVIE/OS 847 L 10JUN VIETIA/MBYETI/JORGJIE(
ADT)
030 RF-WS-NMC-US/WSTMTFTP CR-DCA1S219C 49881134 SU 9999WS/RO
-9CCF46CE TNGW33TMT 00000000 07APR1829Z
030/035 CF/FA 257-7242215364/ETOS/USD778.23/07APR13/DCA1S219C/
49881134/OS 850 K 31MAY TIAVIE/OS 088 L 09JUN JFKVIE/OS
087 K 31MAY VIEJFK/OS 847 L 10JUN VIETIA/MBYETI/PETRAQ(
ADT)
030/035 AF/FA 257-7242215364/ETOS/USD778.23/07APR13/DCA1S219C/
49881134/OS 850 K 31MAY TIAVIE/OS 087 K 31MAY VIEJFK/
MBYETI/PETRAQ(ADT)
string request1 = @"RP/DCA1S219C/DCA1S219C SL/SU 7FEB13/2215Z 8TXSAK
36 FA PAX 125-7239038457/ETBA/07FEB13/DCA1S211E/49881134
/S4-5/P3
37 FA PAX 125-7239038458/ETBA/07FEB13/DCA1S211E/49881134
/S4-5/P1
38 FA PAX 125-7239038459/ETBA/07FEB13/DCA1S211E/49881134 @
/S4-5/P2
39 FB PAX 0700449140 TTP/ET/RT/INVJ OK ETICKET/S4-5/P1-3
40 FE PAX BA ONLY/NONREF/NONEND SEE GGAIRBAGUSA -BG:BA/S4-5/P3
41 FE PAX BA ONLY/NONREF/NONEND SEE GGAIRBAGUSA -BG:BA
/S4-5/P1-2
42 FI PAX 0700449140 INV 0011436178/S4-5/P1-3
43 FI PAX 0700449140 INV 0011436178/S6/P1-3
44 FI PAX 0700449140 INV 0011436178/S7/P1-3
45 FM *M*0.00A
46 FP CHECK
47 FT *BT1195364
48 FV PAX BA/S4-5/P3
49 FV PAX BA/S4-5/P1-2
50 FY BULK/TBULK";
string request2 = @"RP/DCA1S219C/DCA1S219C SL/SU 9APR13/2223Z 4YYTR7
45 FA PAX 257-7242858184/ETOS/USD736.23/08APR13/DCA1S211E/49881
134/S3-6/P1
46 FA PAX 257-7242858185/ETOS/USD736.23/08APR13/DCA1S211E/49881
134/S3-6/P2
47 FB PAX 0800499541 TTP/ET/INVJ/RT OK ETICKET/S3-6/P1-2
48 FE *M*//REFTHRUAGT/NONEND
49 FI PAX 0800499541 INV 0011466820/S3-6/P1-2
50 FI PAX 0800499541 INV 0011466820/S7/P1-2
51 FI PAX 0800499541 INV 0011466820/S8/P1-2
52 FM *M*8
53 FP CHECK
54 FT *815ZU
55 FV PAX OS/S3-6/P1-2";
list.Add(request);
list.Add(request1);
list.Add(request2);
MyClass1 obj1 = new MyClass1();
DataTable datatable1 = obj1.GetNumber(list);
}
}
}
如果我从我的 aspx.cs 文件中删除请求,则此代码有效,但如果我包含它,它会给出此错误仍在等待回复我添加检查条件,但它仍然给我错误
这是我的课程代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Text.RegularExpressions;
namespace AQCConsolidator1
{
class MyClass1
{
string output;
string subs;
DataTable dt = new DataTable();
DataRow dr = null;
public DataTable GetNumber(List<string> request)
{
dt.Columns.Add("TickitNumber", typeof(string));
foreach (string data in request)
{
string item = data;
while (item.Trim() != "")
{
dr = dt.NewRow();
int r1 = item.IndexOf("\r",3);
subs = item.Substring(0, r1); ///Got error in this line
if (subs.Contains("ET"))
{
Regex regexs = new Regex(@"[0-9||-]{14}");
foreach (Match m in regexs.Matches(subs))
{
output = m.ToString();
dr["TickitNumber"] = output;
}
dt.Rows.Add(dr);
}
item = item.Substring(subs.Length);
r1 = item.IndexOf("\r\n", 0);
item = item.Substring(r1);
}
}
return dt;
}
}
}