|
I understand that the Database data can be easily displayed in a grid in WPF, by clicking a table in the Data Sources windows and dragging it onto the form.
we can then click a cell to change its value.
Say, if we have a field say Quotation_Date, and when we want to change/edit that field at a certain row, I would want a Calendar control with DatePicker to appear, such that user can change the date for the Quotation_Date at that row, from the Calendar control. Is that possible?
Similarly, say if we have a field say Weather, and when we want to change/edit that field at a certain row, I would want a ComboBox to appear, such that user can select from the ComboBox collections (Rainy, Sunny, Stormy), and update it. Is that possible?
Third question. With its DataGridView displaying all items from the database, I would want to have a button Add New Item, such that when user click on that button, a second WPF form (new and empty) appears such that all those fields [Items_ID, Quotation_Date, Weather] would appear, and when user adds new items from the second form, thoes Calendar control and ComboBox control would also appears on the second form. When user clicks a Save button, it would close the second form and update its new item to the first form. Is that possible?
thanks.
|
|
|
|
|
1. Yes
2. Yes
3. Yes
All these are possible but if you expect to be able to just drag and drop controls onto a window it will not work. Before attempting this I suggest you get a book, or at least some tutorials, and work through the examples.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
yes, I have worked with those examples already. it seem that for those things which I needed, it is not trivial, especially putting those Calendar controls inside the editable fields. Could you give me some hints?
also, to update the database with new records from another new form, I have problems too.
|
|
|
|
|
TAN THIAM HUAT wrote: it is not trivia
You are right it is not trivial, and yet you are asking for help in the most trivial of manners, a support forum. You questions are so wide in scope they cannot possibly be answered in a forum post.
If you are still at the drag and drop stage then you need to do a whole lot more work to make these structures and controls work.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
can you then suggest which website is more suitable for me to post my non-trivial questions then?
|
|
|
|
|
plz help me some one. I am trying to read images and after some operation then save image(8bit image or Gray scale image).
|
|
|
|
|
Search through the Code Project articles. Look for ones by Christian Graus on image manipulation in C#.
|
|
|
|
|
+5 for suggesting nice articles..
Happy Coding...
|
|
|
|
|
I put together a simple web browser using c#. Its great, its simple. I
added a button. I click the button and I want to be able to log into a
particular website. I have this code:
string username = "username";
string password = "pass";
string commit = "Login";
string postData = string.Format("txtuserid={0}&txtpassword={1}&btnlogin={2}", username, password, commit);
ASCIIEncoding enc = new ASCIIEncoding();
webBrowser1.Navigate("new page.html", "", enc.GetBytes(postData), "Content-Type: application/x-www-form-urlencoded\r\n");
But it doesnt do anything. Is there a way to make the username and password
appear in there respective boxes? Is there another command that I use to
make it click that Login button and move onto the next page?
Please any response any one can give me will be greatly appreciated.
|
|
|
|
|
|
In reading that link that you provide, it almost seems like its possible
in C# to fill out a page and click "login" and log into that page.
If its possible, can I send you a sample project and can you help me log
into an account, any account?
|
|
|
|
|
Is there anything like this I can use:
http://www.netomatix.com/httppostdata.aspx
If I sent you a sample project, could you help me make it log into a site,
any site?
|
|
|
|
|
Hi,
I think it is possible to do this but before I spend another 8 hours on it I would like to ask for some advice please.
Basically I am trying to get the values from tasklist /v into my C# code.
I have tried retrieving the indexes but they are not output as recurring values or some form of table they just keep going until the end of the output.
I am thus trying to send the output of the split string to a foreach value but am ending up with the individual values (as expected). Is there some way I can concatenate these values into a coherent string whose values can be meaningfully separated.
string output = "";
try
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo("tasklist");
p.StartInfo.Arguments = " /v";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
output = (p.StandardOutput.ReadToEnd());
output = output.Remove(0,453);
output = output.Trim();
output = output.Replace(" ", " ");
output = output.Replace(" ", " ");
output = output.Replace(" ", " ");
output = output.Replace(" ", " ");
output = output.Replace(" ", " ");
output = output.Replace(" ", " ");
output = output.Replace(" ", " ");
output = output.Replace(" ", " ");
output = output.Replace(" ", " ");
output = output.Replace(" ", " ");
output = output.Replace('\r', ' ');
output = output.Replace('\n', ' ');
while (true)
{
string[] s = output.Split(' ');
{
foreach (string value in s)
{
if (!string.IsNullOrEmpty(value))
{
Console.WriteLine(value);
Console.ReadLine();
}
}
}
p.WaitForExit();
}
}
catch (Exception se)
{
Console.WriteLine(se.Message + output.ToString() + se.InnerException);
Console.ReadLine();
}
from this I get:
System
Idle
Process
0
Console
0
28
K
Running
NT
AUTHORITY\SY
33:30:14
N/A
Is there a way to "convert" this to:
s[0] = SystemIdleProcess
s[1] = 0
s[2] = Console
s[3] = 0
s[4] = 28K
s[5] = Running
s[6] = NTAUTHORITY\SYSTEM
S[7] = 33:30:14
S[8] = N/A
Thank you for your time..
|
|
|
|
|
Why don't you use the Diagnostics namespace to programmatically determine what processes are running?
Process.GetProcesses();
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I need the total elapsed time of "Idle" to calculate % cpu usage per process. WMI & performance counters are too slow because of their thread.sleep(1000) requirement.
|
|
|
|
|
Try opening a command window and type tasklist /? to get all the options.
You'll find that there is /NH to remove the column headers and /FO CSV to dump the output in comma separated value format.
The output from "tasklist /v /nh /fo csv" will be something like this:
"System Idle Process","0","Console","0","28 K","Running","NT AUTHORITY\SYSTEM","71:33:38","N/A"
"System","4","Console","0","256 K","Running","NT AUTHORITY\SYSTEM","0:24:32","N/A"
"smss.exe","1680","Console","0","924 K","Running","NT AUTHORITY\SYSTEM","0:00:00","N/A"
It will be advantageous to capture the output as lines rather than one long string. For this use ReadLine in a loop instead of ReadToEnd.
The final step is subdivision of each line at the comma delimiters to get the individual fields (use the String.Split method).
Alan
|
|
|
|
|
Excellent!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Alan,
Nice catch on the /nh /fo /csv thing.
Quick question though...
How would you suggest trimming the '"' quote marks from the values & given that you can't split on ',' commas because e.g. "csrss.exe","996","Console","0","7,372 K" (the comma in the memory component 7,732K) would cause a problem.
|
|
|
|
|
|
Hi Luc, gee thanks...didn't know you cared...
The issue is that if you run
Process p = new Process();
p.StartInfo = new ProcessStartInfo("tasklist");
p.StartInfo.Arguments = " /v /nh /fo csv";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
while (true)
{
string o = p.StandardOutput.ReadLine();
if (!string.IsNullOrEmpty(o))
{
string [] s = o.Split(',');
Console.WriteLine(o);
Console.ReadLine();
}
}
occasionally, you only get the last 2 values of the first line. Also, you can't do this
Console.WriteLine(a.Remove(0,1).Remove(a.Length -1,1)); without an exception 'System.ArgumentOutOfRangeException: Index and count must refer to a location within the string. Parameter name: count' which doesn't make much sense because if:-
string s = "bob";
s = s.Remove(s.length -1,1)
result = bo
why is Remove(a.Length -1,1) causing an exception?
Could anyone make any (relevant) suggestions...
|
|
|
|
|
CCodeNewbie wrote: Console.WriteLine(a.Remove(0,1).Remove(a.Length -1,1));
It is way better to write 5 simple lines you understand, than one complex one you think you understand but you don't.
|
|
|
|
|
There are a few things I don't understand with this.
Why does this...
string o = p.StandardOutput.ReadLine();
o = o.Replace("\n", string.Empty);
if (!string.IsNullOrEmpty(o))
{
Console.WriteLine(o);
}
...which gives me...
"System Idle Process","0","Console","0","28 K","Running","NT AUTHORITY\SYSTEM","46:49:36","N/A"
work perfectly, but this...
string o = p.StandardOutput.ReadLine();
o = o.Replace("\n", string.Empty);
if (!string.IsNullOrEmpty(o))
{
string [] s = o.Split(',');
string a = s[0];
string b = s[1];
string c = s[2];
Console.WriteLine(a + b + c);
}
give me a flashing cursor and when I hit enter I get...
"System""4""Console"
where has "System Idle Process" gone?...
and despite having this...
if (!string.IsNullOrEmpty(o))
I still get-
System.NullReferenceException: Object reference not set to an instance of an object.
Aargh!!!
|
|
|
|
|
CCodeNewbie wrote: and despite having this...
if (!string.IsNullOrEmpty(o))
I still get-
System.NullReferenceException: Object reference not set to an instance of an object.
..you're not getting the exception on that particular line, are you?
if (!string.IsNullOrEmpty(null))
This is allowed, and doesn't result in an exception.
It helps if you chop your function up into smaller bits. That way you'll also be looking at less code when there's a failure.
You might also want to dump the entire exception to the console;
try
{
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
The exception will tell you which line blew up.
..and as someone else mentioned in this thread, it's easier to write a lot of simple statements than to maintain a single complex one.
Bastard Programmer from Hell
|
|
|
|
|
That's the irritating part, it doesn't blow up. It just outputs only part of the first line.
just ran it, worked perfectly. ran it again & got Quote: "81:15:36","N/A" as the first line..
Quote: You might also want to dump the entire exception to the console; I always put everything inside try..catch, I am not experienced enough to be able to accurately predict what the code is going to do.
try
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo("tasklist");
p.StartInfo.Arguments = " /v /nh /fo csv";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
while (true)
{
string o = p.StandardOutput.ReadLine();
if (!string.IsNullOrEmpty(o))
{
Console.WriteLine(o);
string[] s = o.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
string a = s[0];
string b = s[1];
string c = s[2];
Console.WriteLine(a + " : " + b + " : " + c);
Console.ReadLine();
}
}
}
catch (Exception se)
{
Console.WriteLine(se.ToString());
Console.ReadLine();
}
|
|
|
|
|
ran it again and got
81:33:06","N/A"
"System Idle Process" : "0" : "Console"
WT? Could it be that "while (true)" is exiting properly? I am noticing that the Console window doesn't close after the last Readline().
|
|
|
|
|