|
That looks a bit better!
Now, remove the "temp.txt" bit, and use an empty folder!
Create a folder in "My Documents", and give it read and write permissions to everybody.
then
File.WriteAllText(@"C:\Users\grantlinhart\Documents\WorkingFolder\" + files.ToString("0000") + ".txt", files.ToString()); And you should get the files (and just the files)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Yeah when I ran it in that version it called every file temp0001, temp0002....etc.
I fixed that bit I put them in a temp folder all by themselves and this is what I get when i run it now. it should be the random #s that are in the random file as individual files right? now when i run it i get 12 files named 0010 0013 0048 0049 0050 0051 0052 0053 0054 0055 0056 0057 all of the files values correspond to the name, however the random numbers generated by my file are from 1-40 and shouldn't there be 20 files since the loop iterated 20 times or should i use a while loop that iterates to the end of the file?
I tried to put it in the workingfolder but it always threw an exception. Is there a way to paste a picture on these posts
}
<pre>writetext.Close();
readtext.Close();
StreamReader rt = new StreamReader(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\write.txt");
<pre>
for (int i = 0; i < 20; i++)
{
int files = rt.Read();
File.WriteAllText(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\temp\"
+ files.ToString("0000") + ".txt", files.ToString());
}
}</pre></pre>
|
|
|
|
|
this is what I tried to do to sort the #s into files: I found a getFiles method in a Process directory method and my intent was to import the whole directory and read each file and write the contence to the sorted file as you suggested, however nothing appears in the Sorted file after I run it. If you see why please let me know I will still keep trying to debug it but if a glaring error pops out to you please let me know, thanks
private void button2_Click(object sender, EventArgs e)
{
string path = @"C:Random # File.txt";
StreamReader readtext = new StreamReader(path);
StreamWriter writetext = new StreamWriter("write.txt");
for (int j = 0; j < 20; j++)
{
string readmetext = readtext.ReadLine();
writetext.WriteLine(Convert.ToInt32(readmetext));
<pre>
}
writetext.Close();
readtext.Close();
StreamReader rt = new StreamReader(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\write.txt");
for (int i = 0; i < 20; i++)
{
int files = rt.Read();
File.WriteAllText(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\temp\"
+ files.ToString("0000") + ".txt", files.ToString());
}
rt.Close();
ProcessDirectory(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\temp\");
}
public static void ProcessDirectory(string targetDirectory)
{
string variable1;
StreamReader readToSort = new StreamReader(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\write.txt");
StreamWriter writeSorted = new StreamWriter(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\Sorted_File.txt");
string[] fileEntries = Directory.GetFiles(@"C:\Users\grantlinhart\Documents\Visual Studio 2013\Projects\InputOut\InputOut\bin\Debug\temp\");
foreach (string fileName in fileEntries)
{
variable1 = readToSort.ReadLine();
writeSorted.WriteLine(variable1.ToString() + "\n");
}
}</pre>
|
|
|
|
|
the text file looks like this it is all #s and it is randomly generated each time
the app is run
I have to do 2 things with the text file that is generated. I have to put the #s in order
and find the lowest one without using an array or assigning variables to be parsed. I have been researching the file class trying to see if i could create a temp file to hold them and then sort the temp file contents in some way. It is a hard problem given the constraints of not being able to use an array and a simple sort. there is one # per line this thread does not show it that way
40
21
2
1
7
18
32
10
|
|
|
|
|
i spoke too soon, now its just pulling the first # in the line of random numbers and not comparing the other #s that come after it in the list oh well back to the drawing board
|
|
|
|
|
Hi, how to split list to two columns in winform gridview.
I have some list
public static string[] addresses = { "192.168.1.45", "10.36.15.1", "10.36.47.1", "10.36.63.1", "10.36.50.1", "10.36.15.16", "10.36.47.11", "10.36.63.11", "10.36.50.16" };
and results are shown in a single column.
List<string> resultsList = new List<string>();
Parallel.ForEach(addresses, address =>
{
string ip = "";
<pre>
Ping pinger = new Ping();
PingReply reply = pinger.Send(address);
if (reply.Status.ToString() != "Success")
ip = address + " Failed";
else
ip = reply.Address.ToString() + " , Time: " + reply.RoundtripTime.ToString() + "ms , " + " OK";
pinger.Dispose();
resultsList.Add(ip);
});
foreach (var something in resultsList)
{
dataGridView1.Rows.Add(something);
}</pre>
I want to separate the results in two columns. Especially ip, especially time
Please help
|
|
|
|
|
arsale wrote: I want to separate the results in two columns.
dataGridView1.Rows.Add(new object[] { "Row 1, Col 1", "Row 1, Col 2" });
dataGridView1.Rows.Add(new object[] { "Row 2, Col 1", "Row 2, Col 2" }); Would only work if the dgv actually has two columns.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes, but i want to split ping result (var something in resultsList) on two columns.
|
|
|
|
|
arsale wrote: Yes, but i want to split ping result (var something in resultsList) on two
columns. Which two ping-results would you want in there?
dataGridView1.Rows.Add(new object[] { reply.Address.ToString(), reply.RoundtripTime.ToString() + "ms" });
dataGridView1.Rows.Add(new object[] { reply.Address.ToString(), reply.RoundtripTime.ToString() + "ms" }); Further, I'd recommend Convert.ToString(T) over (T).ToString, as the former does not throw an exception on null values.
--edit;
along the lines of
dataGridView1.Rows.Add(new object[] { Convert.ToString(reply.Address), string.Format("{0} ms", reply.RoundtripTime) });
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
We did not understand. I have a list that should be every line splitted into two parts and display each in a separate column. The problem is how to separate the list into two parts and display them in the same row. When you split variable, gridview each part put into a separate row.
Thanks for advice
|
|
|
|
|
Ah, indeed, I misunderstood.
foreach (var something in resultsList)
There's only one "something" that needs to be splitted over multiple columns?
ip = reply.Address.ToString() + " , Time: " + reply.RoundtripTime.ToString() + "ms , " + " OK"; The "var" should contain a string. A string.Split[^] should do the trick;
foreach (string s in resultsList)
{
string[] parts = s.Split(",", StringSplitOptions.RemoveEmptyEntries);
dataGridView1.Rows.Add(parts[0], parts[1]);
}
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I'm sorry i not a purify code.
ip = reply.Address.ToString() + " , Time: " + reply.RoundtripTime.ToString() + "ms"
In part
string[] parts = s.Split(",", StringSplitOptions.RemoveEmptyEntries);
i I'm getting a error "cannot convert from 'string' to 'char[]'"
modified 1-Apr-15 6:04am.
|
|
|
|
|
VOILA, bravo! Thanks for good advice.
I'm use only
string[] parts = s.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
insted above and works like a charm.
Thanks again
|
|
|
|
|
Sorry, forgot that it requires an array - but well done
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes, it's very useful piece of code.
My regards
|
|
|
|
|
I have 2 User control added on the main form??
UserControl1 have TextBox which accept the input.
UserControl2 Will display the text From TextBox which is on UserControl1.
UserControl1
{
public delegate void TextChangeHandler(string strText);
public event TextChangedHandler _textChanged;
UserControl1()
{
this._textChanged+=new TextChangeHandler(UserControl2.onTitleChanged);
}
textBox1_textEntered()
{
if(_textChanged!=null)
{<br />
_textChanged(textBox1.text);
}
}
}
UserControl2
{
OnPaint()
{
drawString(text,..);
}
onTitleChanged(strText)
{
text = strText();
this.Refresh();
}
}
Could not refresh here.
Is It require to register TextChangeHandler in uSerControl2 also??
because I register It in USerControl1.
|
|
|
|
|
Yes, if you want it to be available to the outside world.
Unless classes are derived from each other (class2 derived from class1 for example) they do not automatically inherit any behaviour!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
then How Should I register iT??
|
|
|
|
|
The same way you do in UserControl1?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
still could not repaint.Actually I added 2 control on the panel.Could It be the issue for repainting??
May be due to added on the panel we could not repaint??
|
|
|
|
|
Step back a moment and remember that we can't see your screen, access your HDD, or read your mind.
So try posting the relevant code fragments which show exactly what you are doing, and what you expect to get.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
HI,
I have 3 tables. I wish to select the latest Unit Rate from those tables....like SQL Cross Apply.Is it possible from Ms-Access?
The below SQL-Query Select the latest unit_price, price_date from three tables..... Itemmst, Pomst, Grinmst
Actually the query checks those three tables and will select the greatest Price_date and Unit_Rate
Select i.itm_code,i.itm_description,i.unit_measure,t.unit_rate,t.price_date from itemmst i cross apply ( select top 1 unit_rate,price_date from( select im.unit_rate,''as price_date,0 as ord from itemmst im where im.itm_code=i.itm_code and im.unit_rate is not null union all select unit_price as unit_rate,po_date as price_date,1 as ord from pomst where pomst.itm_code =i.itm_code and pomst.unit_price is not null union all select grinmst.unit_rate,grinmst.grn_date,1 from grinmst where grinmst.itm_code =i.itm_code and grinmst.unit_rate is not null )r order by price_date desc,ord desc )t
Output :-
- Item1, Pencil, Nos, 25.00, 26/03/2015 => from Grimst
- Item2, Pen, Nos, 22.00, 21/03/2015 => from Pomst
- Item3, Paper, Nos, 65.00, 01/04/2014 => from Itemst
Thanks
|
|
|
|
|
Short answer would be, yes you can use SQL-based commands for data in MS-Access, because MS-Access can also work with SQL commands. Please read this[^] for more.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
im basically wana make a project of microcontroller in which from inkcanvas what ever i draw , by sending drawing to microcontroller ,it will show on graphical lcd . as graphical lcd get "
const code char array[1024] = {
88, 160, 88, 160, 80, 16, 160, 96, 160,.....}" array as argument mean get array i.e array .. and display respected image on lcd . so problem is that i dnt understand how i get array of drawing in inkcanvas .plz gude me properly
malikkamranhafeez
|
|
|
|
|
i am monitoring a database table for data change like insert/Update. some sql dependency throw error i heard like when no activity is there for a specific table for long days like 3/4 days. i am trying to say if i am monitoring a table and if no data inserted or updated in that table for long time then SQL Dependency throw error. here is my code. please see my code and tell me am i handing the error properly.
my sql dependency code is written in windows service. i want if any error is thrown then my windows service should restart. here is my full code
public partial class PartIndexer : ServiceBase
{
static string connectionString = "server=222;uid=222;password=222;database=wwww;Pooling=true;Connect Timeout=20;";
SqlDependency dep;
public PartIndexer()
{
InitializeComponent();
}
#region OnStart
protected override void OnStart(string[] args)
{
RegisterNotification();
MailNotify("STARTED");
}
#endregion
#region RegisterNotification
///
/// RegisterNotification
/// this is main routine which will monitor data change in ContentChangeLog table
///
private void RegisterNotification()
{
string tmpdata = "";
System.Data.SqlClient.SqlDependency.Stop(connectionString);
System.Data.SqlClient.SqlDependency.Start(connectionString);
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT ActivityDate FROM [bba-reman].MyLog";
dep = new SqlDependency(cmd);
dep.OnChange += new OnChangeEventHandler(OnDataChange);
SqlDataReader dr = cmd.ExecuteReader();
{
while (dr.Read())
{
if (dr[0] != DBNull.Value)
{
tmpdata = dr[0].ToString();
}
}
}
dr.Dispose();
cmd.Dispose();
}
}
finally
{
//SqlDependency.Stop(connStr);
}
}
#endregion
// this below function never used
public void ReStartService()
{
ServiceController service = new ServiceController("PartIndexer");
if ((service.Status.Equals(ServiceControllerStatus.Stopped)) || (service.Status.Equals(ServiceControllerStatus.StopPending)))
{
service.Start();
}
else
{
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running);
}
}
#region OnDataChange
///
/// OnDataChange
/// OnDataChange will fire when after data change found in ContentChangeLog table
///
/// <param name="sender" />
/// <param name="e" />
void OnDataChange(object sender, SqlNotificationEventArgs e)
{
((SqlDependency)sender).OnChange -= OnDataChange;
if (e.Source == SqlNotificationSource.Timeout)
{
var template = new MailTemplate()
.WithBody("HI,
Part Indexer Service Exception Timeout occur " + DateTime.Now.ToLongDateString())
.WithSubject("Part Indexer Service Exception Timeout occur")
.WithSender("xxx@xxx.com")
.WithRecepient("xxx@xxx.com")
.Send();
Environment.Exit(1);
return;
}
else if (e.Source != SqlNotificationSource.Data)
{
var template = new MailTemplate()
.WithBody("HI,
Part Indexer Service Exception SqlNotificationSource.Data " + DateTime.Now.ToLongDateString())
.WithSubject("Part Indexer Service Exception SqlNotificationSource.Data")
.WithSender("xxx@xxx.com")
.WithRecepient("xxx@xxx.com")
.Send();
Environment.Exit(1);
}
StartIndex();
RegisterNotification();
}
#endregion
#region StartIndex
///
/// StartIndex
/// this routine will call web service in bba reman website which will invoke routine to re-index data
///
void StartIndex()
{
//eventLog1.WriteEntry("Web Service called start for indexing data");
PartIndexerWS.AuthHeader oAuth = new PartIndexerWS.AuthHeader();
oAuth.Username = "Admin";
oAuth.Password = "Admin";
PartIndexerWS.SearchDataIndex DataIndex = new PartIndexerWS.SearchDataIndex();
DataIndex.AuthHeaderValue = oAuth;
try
{
DataIndex.StartIndex();
//eventLog1.WriteEntry("Web Service called stop for indexing data");
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message.ToString());
//eventLog1.WriteEntry("Web Service call error "+ex.Message.ToString());
}
}
#endregion
#region MailNotify
///
/// MailNotify
/// fire mail when apps start & exit
///
/// <param name="strStatus" />
void MailNotify(string strStatus)
{
if (strStatus == "STARTED")
{
var template = new MailTemplate()
.WithBody("HI,
Part Indexer Started Date " + DateTime.Now.ToLongDateString())
.WithSubject("Part Indexer Started")
.WithSender("xxx@xxx.com")
.WithRecepient("xxx@xxx.com")
.Send();
//eventLog1.WriteEntry("mail fired ");
}
else if (strStatus == "STOPPED")
{
var template = new MailTemplate()
.WithBody("HI,
Part Indexer stopped Date " + DateTime.Now.ToLongDateString())
.WithSubject("Part Indexer Stopped")
.WithSender("xxx@xxx.com")
.WithRecepient("xxx@xxx.com")
.Send();
//eventLog1.WriteEntry("mail fired ");
}
}
#endregion
#region OnStop
protected override void OnStop()
{
System.Data.SqlClient.SqlDependency.Stop(connectionString);
MailNotify("STOPPED");
//eventLog1.WriteEntry("Part Indexer stopped Date : " + DateTime.Now.ToLongDateString());
}
#endregion
}
see this function because if error occur then i am restarting service from here by this code Environment.Exit(1);.
void OnDataChange(object sender, SqlNotificationEventArgs e)
{
((SqlDependency)sender).OnChange -= OnDataChange;
if (e.Source == SqlNotificationSource.Timeout)
{
var template = new MailTemplate()
.WithBody("HI,
Part Indexer Service Exception Timeout occur " + DateTime.Now.ToLongDateString())
.WithSubject("Part Indexer Service Exception Timeout occur")
.WithSender("xxx@xxx.com")
.WithRecepient("xxx@xxx.com")
.Send();
Environment.Exit(1);
return;
}
else if (e.Source != SqlNotificationSource.Data)
{
var template = new MailTemplate()
.WithBody("HI,
Part Indexer Service Exception SqlNotificationSource.Data " + DateTime.Now.ToLongDateString())
.WithSubject("Part Indexer Service Exception SqlNotificationSource.Data")
.WithSender("xxx@xxx.com")
.WithRecepient("xxx@xxx.com")
.Send();
Environment.Exit(1);
}
StartIndex();
RegisterNotification();
}
the problem is my service is not sending any mail when data change in specific table but if i restart my service then service is sending mail when data is changed in specific table which is monitoring by the sql dependency. need help.
tbhattacharjee
|
|
|
|
|