|
I am attempting to write a method to iterate through a xml file that has multiple nodes that match a given type but for some reason it only accepts the first one and then exists. I think I may have my loop wrong or something. Can anyone tell me what the issue may be?
using System;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Diagnostics;
using System.Threading;
namespace UTS_Batch_Update
{
public class UTSB_Input
{
{
string Path = "C:\\xmlticketID.xml";
// If the user forgets to put in a path, throw a NullException.
if (Path == null)
{
throw new ArgumentNullException();
}
// Load the document.
XmlDocument sourceDoc = new XmlDocument();
sourceDoc.Load(Path);
// Retrieve each ticketID.
//XmlNodeList tickets = sourceDoc.GetElementsByTagName("TicketId");
//Create an XmlNamespaceManager for resolving namespaces.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(sourceDoc.NameTable);
foreach (XmlNode node in tickets)
if (node.Name == "TicketId")
{
//using (MemoryStream buffer = new MemoryStream())
string buffer = "c:\\xmlpost.xml";
XmlTextWriter w = new XmlTextWriter(buffer, null);
// Start the document.
w.WriteStartDocument();
w.WriteStartElement("XMLFILE");
w.WriteAttributeString("UserLogName", "REDMOND\\" + UserInfo);
w.WriteAttributeString("FileId", "MSN Search BUU");
w.WriteAttributeString("Action", "Close");
w.WriteStartElement("TICKET");
w.WriteAttributeString("TicketId", node.InnerXml.ToString());
w.WriteAttributeString("CloseControlInd", "No");
w.WriteAttributeString("ProblemResolved", Resolved);//ConvertBoolToYesNo(Resolved));
w.WriteAttributeString("WereProceduresInPlace", ProceduresInPlace);
w.WriteAttributeString("WereProceduresInPlaceNotes", ProceduresInPlaceNotes);
w.WriteAttributeString("WereProceduresAccurate", ProceduresAccurate);
w.WriteAttributeString("WereProceduresAccurateNotes", ProceduresAccurateNotes);
w.WriteAttributeString("WereToolsEffective", ToolsEffective);
w.WriteAttributeString("WereToolsEffectiveNotes", ToolsEffectiveNotes);
w.WriteAttributeString("FalseAlarmInd", FalseAlarm);
w.WriteAttributeString("VerifiedBy", VerifiedBy);
w.WriteAttributeString("NotifyAliases", NotifyAliases);
w.WriteAttributeString("ClosureNotes", Closure);
w.WriteEndElement();
// End the document.
w.WriteEndElement();
w.WriteEndDocument();
w.Flush();
w.Close();
XmlTextReader reader = new XmlTextReader(buffer);
XmlDocument outputDoc = new XmlDocument();
outputDoc.Load(reader);
string processpath = "C:\\WINDOWS\\system32\\wscript.exe";
string processargs = "C:\\uts.wsf c:\\xmlpost.xml";
System.Diagnostics.Process.Start(processpath, processargs);
return outputDoc;
}
throw new InvalidOperationException("No XML was converted.");
}
} // end method UTSBFileLoad
}
|
|
|
|
|
dbenisch wrote: I think I may have my loop wrong or something.
Yes, you have. You have the return statement inside the loop.
---
b { font-weight: normal; }
|
|
|
|
|
Is there anyway to set a tooltip for a certain coordinate area of a form and not to a specific control?
|
|
|
|
|
I figured out one way to do it, but I don't know if it's the most efficient.
This is what I did:
<br />
private void Form1_MouseMove(object sender, MouseEventArgs e)<br />
{<br />
if (e.X > 15 && e.X < 45 && e.Y > 35 && e.Y < 60)<br />
trackTip.Show("1", this, 20, 45);<br />
else if (e.X > 45 && e.X < 75 && e.Y > 35 && e.Y < 60)<br />
trackTip.Show("2", this, 55, 45);<br />
else<br />
trackTip.Hide(this);<br />
}<br />
is this the best way to do it?
|
|
|
|
|
I'm trying to capture system messages in my Windows Service. Specifically I want to know when a device is un\plugged into the usb. From what I found is appears that I need to 1) Create a callback HandlerEx, 2)RegisterServiceCtrlHandlerEx and 3)RegisterDeviceNotification.
My Problem is I always get a Error 126 when I call RegisterServiceCtrlHandlerEx. I think something might be wrong with the parameters I am passing it.
Would appreciate any suggestions or any advise on a better way to do this.
First Section of code is my Win32 class and delegate for my callback. Second section is The Service code minus all the windows generated stuff.
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace My_Service
{
public delegate int callbackEx(int control, int eventType,IntPtr eventData,IntPtr context);
class Win32
{
[DllImport("kernel32.dll")]
public static extern int GetLastError();
[DllImport("advapi32.dll", SetLastError=true)]
public static extern IntPtr RegisterServiceCtrlHandlerEx(
string lpServiceName,callbackEx cbex,IntPtr context);
}
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
namespace My_Service
{
public class My_Service: System.ServiceProcess.ServiceBase
{
private System.ComponentModel.IContainer components;
public System.Diagnostics.EventLog eventLog1;
private IntPtr MethodHandle;
private callbackEx myCallback ;
public My_Service()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();
this.RegisterCallBack();
}
private int my_Callback(int dwControl,int dwEventType,IntPtr lpEventData,IntPtr lpContext)
{
this.eventLog1.WriteEntry("CALLBACK HIT!!!!!!!!!!");
return 0;
}
void RegisterCallBack()
{
myCallback = new callbackEx(my_Callback);
MethodHandle = Win32.RegisterServiceCtrlHandlerEx(this.StrToByteArray(this.ServiceName),myCallback,IntPtr.Zero);
if(MethodHandle == IntPtr.Zero)
{
this.eventLog1.WriteEntry("RegisterCallBack " + Win32.GetLastError().ToString());
}
}
Thanks, Chris
|
|
|
|
|
Hi all,
I'm really struggling to do something very simple using a DataGridView control. I'm setting the DataGridView DataSource to an existing DataSet. All the data is displayed fine.
I now want to select a range of cells using the DataGridView, and when I click a button, have the selected cells copied to a new (previously empty) dataset. I just can't figure out how to get the data I've selected in the DataGridView control into the new dataset.
By putting a watch on the DataGridView control, I can see the list of items contained in the control, but they're all non-public so I have no way of getting at them programmatically.
Any assistance would be very much appreciated.
|
|
|
|
|
I don't know if I have understood the question right but you can access the cells with
[code]
dataGridView1.Rows[0].Cells[1].Value;
[\code]
hope this helps
|
|
|
|
|
if u are looking for this
on selectedindexchanged of gridview1 write code below
this.textbox1.text = GridView1.SelectedRow.Cells[1].Text
|
|
|
|
|
I'm trying to create a program to make thread-safe calls to form controls, specifically to instances of ToolStripStatusLabel and ToolStripProgressBar. I ran cross this page when VC# told me I was unsafely calling the control. The problem is those two classes aren't derived from Control and don't have the InvokeRequired property. I tried using the forms' own InvokeRequired but it's not working and I don't know what to do. Anyone have any help?
|
|
|
|
|
toolStripProgressBar1.Owner.Invoke((ThreadStart)delegate
{
toolStripProgressBar1.Value = 50;
});
Rather than using Invoke/BeginInvoke, you might want to use the System.ComponentModel.BackgroundWorker class, which raises events for you on the appropriate thread, handling all the Invoke/BeginInvoke for you.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
that's interesting, thanks. I unfortunately got an exception saying not enough arguments were supplied so I added in my arguments for the delegates like this:
_statusbar.Owner.Invoke((ThreadEvent)delegate
{
_statusbar.Text = "test test, started work";
}, new Object[] { this, ThreadEventArgs("test message", 0, TheadStatusType.thread_started) });
In my original delegate, I had it declared object, ThreadEventArgs so I guess that's what it wanted.
This works, and without the form-side needing a delegate. Is that the best though? With it like this, it requires a status bar to exist in order to work. I liked the idea of triggering an event and the form can receive it if it wants to and deal with it as it sees fit.
|
|
|
|
|
I think I found the problem with what I was doing originally, I don't think I was invoking the delegate right. I ran across this page which talks about BeginInvoke. I used the section of code declared as the typical way of using BeginInvoke as my inspiration and got my invoke working pretty well.
I thought anyone reading this and interested in a fix might want to know.
|
|
|
|
|
Like I said, BackgroundWorker is really want you should look at:
backgroundWorker1.DoWork += MyWorkerFunction;
backgroundWorker1.ProgressChanged += MyProgressReported;
backgroundWorker1.RunWorkerCompleted += MyWorkCompleted;
backgroundWorker1.RunAsync(someArgument);
void MyWorkerFunction(object sender, DoWorkEventArgs e)
{
...
backgroundWorker1.ReportProgress(99);
...
}
void MyProgressReported(object sender, ProgressReportedEventArgs e)
{
}
void MyWorkCompleted(object sender, RunWorkerCompletedEventArgs e)
{
}
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
I looked at BackgroundWorker after you said it and concluded that using it would require a lot of rewiring of my program, more than I was willing to do. However, I do now know it exists and I'll keep it in mind next time around.
|
|
|
|
|
Hy,
I need some tools (classes not exe) to export/transform some text(reports) in XLS, HTML, PDF, DBF, XML... format.
Tranks,
Mihai
|
|
|
|
|
Hello,
I want to use weather reports in my project.
Is anybody know a web service that provides weather reports??
|
|
|
|
|
|
Hi...
I have a Panel, and want to add a line on it. But i want the line to be drawn over time, using a timer.
But i don't know how to do that, I have drawn the first part of the line using this code:
private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawLine(new Pen(Color.Black), new Point(0,0), new Point(15,15));
}
This gives me a line from the top corner. But then the timer make the first tick i want it to continue draw the line, so the next pont will be from (15,15) to (30,30) and so on as the timer counts.
Can anyone tell me how to do, and/or give me some articles about drawing with C#?
Thanks
QzRz
|
|
|
|
|
Store the size of the line in a variable, and use that to draw the line in paint event. In the timer event you change the value of the variable and invalidate the panel, that will cause a redraw.
---
b { font-weight: normal; }
|
|
|
|
|
i am doing a Shopping Cart Application
After registration process all users will get a unique 16 digit code like,
(XXXX-XXXX-XXXX-XXXX) he can distribute this code to his friends where they get some percent discount by using this Code.
Now my problem is how to generate 16 digit Strong Unique Code
Please send the complete code to generate 16 digit Random Number using C#
Waiting for your help.
With Regards
Satisha
|
|
|
|
|
Does it have to be 16 digits? Why not just use a Guid ?
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
|
Complete code? Why? Can't you write any of the code yourself?
Here is how you create a random number between 0 and 9999 and convert it into a four digit string:
Random r = new Random();<br />
string x = r.Next(10000).ToString("0000");
That's the tricky part. That should get you far enough to very easily put together a 16 digit code.
---
b { font-weight: normal; }
|
|
|
|
|
Does it have to be one-way or can it be a reversible operation? (Like: Is the ID a secret?)
I'd use some hash.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
hi everybody,
i want to know how to menage the optimistic cuncurrency using timestamp.
i've already added a column for every table (timestamp type).
how i can modify the Update command to use it?
(im using C# 2005)
Thank you in advance
Enrico
VentoEngine corp.
Program your life ^^
|
|
|
|
|