Tech_Men
asked on
reading from a file
hi there , i have a very a problem when i read from a file to my App
i am on WinForm c# .
this is the code that read the file :
sqlConnection1.Close();
IDbCommand cmdGetPath = sqlConnection1.CreateComma nd();
cmdGetPath.Parameters.Clea r();
cmdGetPath.CommandText="Se lect @FilePath=FileToReadPath from Bakara";
SqlParameter path = new SqlParameter("@FilePath",S qlDbType.V arChar,50) ;
path.Direction=ParameterDi rection.Ou tput;
cmdGetPath.Parameters.Add( path);
sqlConnection1.Open();
cmdGetPath.ExecuteNonQuery ();
sqlConnection1.Close();
string FilePath=path.Value.ToStri ng();
StreamReader sr = new StreamReader(FilePath);
string input = sr.ReadToEnd();
sr.Close();
Regex re = new Regex(@"(?<ProdKey>[\d-]+) \s+(?<Quan t>-\d+)",
RegexOptions.Compiled);
MatchCollection mc;
comboBox1.Text="drawing";
mc = re.Matches(input);
foreach( Match m in mc )
{
// Get the information from the Regex object
string ProdKey = m.Groups["ProdKey"].Value;
NewConn.ConnectionString=B izLog.Conn .ConnStrin g();
IDbCommand CmdRunOver=NewConn.CreateC ommand();
CmdRunOver.CommandText="SE LECT ProRunID,ProKey from Products";
NewConn.Open();
IDataReader reader = CmdRunOver.ExecuteReader() ;
while (reader.Read())
{
if (ProdKey==reader["ProKey"] .ToString( ))
{
int QuantitySold = Convert.ToInt32(m.Groups[" Quant"].Va lue);
tbCodeParit.Text=ProdKey.T oString();
tbKamot.Text=QuantitySold. ToString() ;
tbAsmhata.Text="999";
try
{
button1.PerformClick();
}
catch
{
}
}
}
NewConn.Close();
reader.Close();
}
this.tbAsmhata.Clear();
this.tbKamot.Clear();
this.tbCodeParit.Clear();
this.lblPname.Text="";
string Dir=System.IO.Path.GetDire ctoryName( FilePath);
DirectoryInfo dirInfo = new DirectoryInfo(Dir);
DateTime dtYez = new DateTime();
foreach ( FileInfo f in dirInfo.GetFiles() )
{
if( f.Extension.Equals(".DOC") && (f.Name.Equals("PRESTO.DOC ") ) )
{
dtYez = DateTime.Parse(f.CreationT ime.ToStri ng());
f.Delete();
statusBar1.Text="File is del !!!";
}
}
Bt.klitatTenoa(dtYez,DateT ime.Now);
}
this is the file txt :
-2 422
-4 425
-5 544
-4 545
-1 566
-5 574
-1 593
-1 596
-2 652
-2 679
-2 681
-1 709
-3 713
-2 715
-3 720
-2 754
-1 813
-5 832
-79 3022
-60 3029
-30 3030
-115 3100
-56 3110
-30 3117
-123 3120
-77 3125
-227 3127
-202 3128
-103 3140
-82 3141
-70 3142
-49 3144
-75 3146
-107 3150
-75 3151
-75 3205
-45 3222
1 3223
-50 3231
-50 3232
-107 3233
-227 3236
-75 3305
now when he read the ProductsKey and quantity the reading is worng he read the first ProKey like 422 and the second quant like -4 i dont know why he dose it is anyone here can help me to solve that problem that i have ??
i need to read 422 and -2 like the first Products row in the file
i am on WinForm c# .
this is the code that read the file :
sqlConnection1.Close();
IDbCommand cmdGetPath = sqlConnection1.CreateComma
cmdGetPath.Parameters.Clea
cmdGetPath.CommandText="Se
SqlParameter path = new SqlParameter("@FilePath",S
path.Direction=ParameterDi
cmdGetPath.Parameters.Add(
sqlConnection1.Open();
cmdGetPath.ExecuteNonQuery
sqlConnection1.Close();
string FilePath=path.Value.ToStri
StreamReader sr = new StreamReader(FilePath);
string input = sr.ReadToEnd();
sr.Close();
Regex re = new Regex(@"(?<ProdKey>[\d-]+)
RegexOptions.Compiled);
MatchCollection mc;
comboBox1.Text="drawing";
mc = re.Matches(input);
foreach( Match m in mc )
{
// Get the information from the Regex object
string ProdKey = m.Groups["ProdKey"].Value;
NewConn.ConnectionString=B
IDbCommand CmdRunOver=NewConn.CreateC
CmdRunOver.CommandText="SE
NewConn.Open();
IDataReader reader = CmdRunOver.ExecuteReader()
while (reader.Read())
{
if (ProdKey==reader["ProKey"]
{
int QuantitySold = Convert.ToInt32(m.Groups["
tbCodeParit.Text=ProdKey.T
tbKamot.Text=QuantitySold.
tbAsmhata.Text="999";
try
{
button1.PerformClick();
}
catch
{
}
}
}
NewConn.Close();
reader.Close();
}
this.tbAsmhata.Clear();
this.tbKamot.Clear();
this.tbCodeParit.Clear();
this.lblPname.Text="";
string Dir=System.IO.Path.GetDire
DirectoryInfo dirInfo = new DirectoryInfo(Dir);
DateTime dtYez = new DateTime();
foreach ( FileInfo f in dirInfo.GetFiles() )
{
if( f.Extension.Equals(".DOC")
{
dtYez = DateTime.Parse(f.CreationT
f.Delete();
statusBar1.Text="File is del !!!";
}
}
Bt.klitatTenoa(dtYez,DateT
}
this is the file txt :
-2 422
-4 425
-5 544
-4 545
-1 566
-5 574
-1 593
-1 596
-2 652
-2 679
-2 681
-1 709
-3 713
-2 715
-3 720
-2 754
-1 813
-5 832
-79 3022
-60 3029
-30 3030
-115 3100
-56 3110
-30 3117
-123 3120
-77 3125
-227 3127
-202 3128
-103 3140
-82 3141
-70 3142
-49 3144
-75 3146
-107 3150
-75 3151
-75 3205
-45 3222
1 3223
-50 3231
-50 3232
-107 3233
-227 3236
-75 3305
now when he read the ProductsKey and quantity the reading is worng he read the first ProKey like 422 and the second quant like -4 i dont know why he dose it is anyone here can help me to solve that problem that i have ??
i need to read 422 and -2 like the first Products row in the file
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
soory but its not working its dosent read any :-(
ASKER
this line is working good :
Regex re = new Regex(@"(?<Quant>-\d+)\s+( ?<ProdKey> [\d-]+)", RegexOptions.Compiled);
but its dosent read to row whit postive number like 1 3223
how can i read pos an neg numbers in this Reg Line?
Regex re = new Regex(@"(?<Quant>-\d+)\s+(
but its dosent read to row whit postive number like 1 3223
how can i read pos an neg numbers in this Reg Line?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i dont think that thie will be the problem .... its working great .. i love u all ... thanks !!!
ASKER
how can i get this line 2 ?
i must to get the Postive number to the APP .