|
Hi guys...
I have an issue with my xml file... actually im developing a console application which inserts the data from an Xml file
into my database... This happens with
certain verifications done within the console application, like
checking whether the application id given by the user matches with the application id present in the xml file and also whether that application
has certain permissions, like certain applications hav certain
previleges, sumthing like dat...
Accordingly the insertion of datas into the database takes place... the code is as follows:
class Class1
{
public string app;
public void perform()
{
OdbcConnection con= new OdbcConnection();
ADIBCrypto.Encryption64 crpto = new ADIBCrypto.Encryption64();
try
{
string connString = crpto.GetCnnStr(ConfigurationSettings.AppSettings["appname"],ConfigurationSettings.AppSettings["dsnSybase"]);
con.ConnectionString = connString;
con.Open();
Console.WriteLine("Connection Opened Successfully");
Console.WriteLine("Enter the application");
app=Console.ReadLine();
XmlDataDocument doc = new XmlDataDocument();
doc.Load(ConfigurationSettings.AppSettings["app"]);
XmlNodeList nodes = doc.GetElementsByTagName("Row");
foreach(XmlNode node in nodes)
{
if(node.HasChildNodes && node.ChildNodes.Count > 0)
{
string a_ID = node.ChildNodes[0].InnerText;
string a_ApplicationDescription = node.ChildNodes[1].InnerText;
string a_Category = node.ChildNodes[2].InnerText;
string a_Business_Owner = node.ChildNodes[3].InnerText;
string a_CreatedID = node.ChildNodes[4].InnerText;
string a_CreatedTimeStamp = node.ChildNodes[5].InnerText;
string a_Status = node.ChildNodes[6].InnerText;
if(a_ID==app)
{
Console.WriteLine("App Inserted");
}
}
}
XmlDataDocument doc1 = new XmlDataDocument();
doc1.Load(ConfigurationSettings.AppSettings["fun"]);
XmlNodeList nodes1 = doc1.GetElementsByTagName("Row");
foreach(XmlNode node1 in nodes1)
{
if(node1.HasChildNodes && node1.ChildNodes.Count > 0)
{
string f_ID = node1.ChildNodes[0].InnerText;
string f_FunctionDescription = node1.ChildNodes[1].InnerText;
string f_AppId = node1.ChildNodes[2].InnerText;
string f_FileName = node1.ChildNodes[3].InnerText;
if(f_AppId==app)
{
Console.WriteLine("fun--{0}",f_FileName);
XmlDataDocument doc2 = new XmlDataDocument();
doc2.Load(ConfigurationSettings.AppSettings["funfile"]+"\\"+f_FileName+".xml");
XmlNodeList nodes2 = doc2.GetElementsByTagName("Function");
foreach(XmlNode node2 in nodes2)
{
if(node2.HasChildNodes && node2.ChildNodes.Count > 0)
{
string ff_Id = node2.ChildNodes[0].InnerText;
string ff_FunctionDescription = node2.ChildNodes[1].InnerText;
string ff_Url = node2.ChildNodes[2].InnerText;
string ff_AppId = node2.ChildNodes[3].InnerText;
string ff_Type = node2.ChildNodes[4].InnerText;
string ff_MenuCommand = node2.ChildNodes[5].InnerText;
string ff_Status = node2.ChildNodes[6].InnerText;
Console.WriteLine("funfile--{0}",ff_Id);
}
}
}
}
}
Console.WriteLine("Function Inserted");
XmlDataDocument doc3 = new XmlDataDocument();
doc3.Load(ConfigurationSettings.AppSettings["fungrp"]);
XmlNodeList nodes3 = doc3.GetElementsByTagName("Row");
foreach(XmlNode node3 in nodes3)
{
if(node3.HasChildNodes && node3.ChildNodes.Count > 0)
{
string fg_GroupId = node3.ChildNodes[0].InnerText;
string fg_AppId = node3.ChildNodes[1].InnerText;
string fg_FuncId = node3.ChildNodes[2].InnerText;
string fg_FileName = node3.ChildNodes[3].InnerText;
if(fg_AppId==app)
{
XmlDataDocument doc4 = new XmlDataDocument();
doc4.Load(ConfigurationSettings.AppSettings["fungrpfile"]+"\\"+fg_FileName+".xml");
XmlNodeList nodes4 = doc4.GetElementsByTagName("FunctionGroup");
foreach(XmlNode node4 in nodes4)
{
if(node4.HasChildNodes && node4.ChildNodes.Count > 0)
{
string fgf_GroupId = node4.ChildNodes[0].InnerText;
string fgf_AppId = node4.ChildNodes[1].InnerText;
string fgf_FuncId = node4.ChildNodes[2].InnerText;
string fgf_Status = node4.ChildNodes[3].InnerText;
Console.WriteLine("fungrp--{0}",fgf_FuncId);
XmlDataDocument doc5 = new XmlDataDocument();
doc5.Load(ConfigurationSettings.AppSettings["grp"]);
XmlNodeList nodes5 = doc5.GetElementsByTagName("Row");
foreach(XmlNode node5 in nodes5)
{
if(node5.HasChildNodes && node5.ChildNodes.Count > 0)
{
string g_Id = node5.ChildNodes[0].InnerText;
string g_Description = node5.ChildNodes[1].InnerText;
string g_FileName = node5.ChildNodes[2].InnerText;
if(fgf_GroupId==g_Id)
{
XmlDataDocument doc6 = new XmlDataDocument();
doc6.Load(ConfigurationSettings.AppSettings["grpfile"]+"\\"+g_FileName+".xml");
XmlNodeList nodes6 = doc6.GetElementsByTagName("Group");
foreach(XmlNode node6 in nodes6)
{
if(node6.HasChildNodes && node6.ChildNodes.Count > 0)
{
string gf_Id = node6.ChildNodes[0].InnerText;
string gf_Description = node6.ChildNodes[1].InnerText;
string gf_Type = node6.ChildNodes[2].InnerText;
string gf_Level = node6.ChildNodes[3].InnerText;
int gf_DailyLimit = Convert.ToInt32(node6.ChildNodes[4].InnerText);
string gf_Status = node6.ChildNodes[5].InnerText;
Console.WriteLine("grp--{0}",gf_Id);
}
}
}
}
}
}
}
}
}
}
con.Close();
Console.WriteLine("Connection Closed");
Console.ReadLine();
}
catch(OdbcException)
{
Console.WriteLine("Record already exists");
Console.ReadLine();
}
}
The problem is that on loading the "doc3" the tags in the xml file are not in the same order.. The Xml file is as follows:
<Row>
<AppId>CAPRC</AppId>
<GroupId>CAPRC02</GroupId>
<FuncId>cap63</FuncId>
<FileName>FG_53</FileName>
</Row>
<Row>
<GroupId>ICCBranch</GroupId>
<AppId>ICC</AppId>
<FuncId>00001</FuncId>
<FileName>FG_54</FileName>
</Row>
<Row>
<GroupId>ICCBranch</GroupId>
<AppId>ICC</AppId>
<FuncId>00002</FuncId>
<FileName>FG_55</FileName>
</Row>
<Row>
<AppId>ICC</AppId>
<GroupId>ICCCardCen</GroupId>
<FuncId>00003</FuncId>
<FileName>FG_56</FileName>
</Row>
so u can see that the AppID and the GroupId tags are not in the right order.. in certain rows the tag-appid is in childnode[0]
and in certain rows the tag
is in Childnode[1]... so my check in the application is not
performed properly.. instead of childnode index number can i make it check with the name of the tag...
please guide i am 95% done with my application and at the final stage i found out this bug ... please guide me with
any better ideas...
Thanxx in advance...
Regards,
Tash
modified on Thursday, December 10, 2009 3:44 AM
|
|
|
|
|
Replace
foreach(XmlNode node in nodes)
{
if(node.HasChildNodes && node.ChildNodes.Count > 0)
{
string a_ID = node.ChildNodes[0].InnerText;
string a_ApplicationDescription = node.ChildNodes[1].InnerText;
string a_Category = node.ChildNodes[2].InnerText;
string a_Business_Owner = node.ChildNodes[3].InnerText;
string a_CreatedID = node.ChildNodes[4].InnerText;
string a_CreatedTimeStamp = node.ChildNodes[5].InnerText;
string a_Status = node.ChildNodes[6].InnerText;
if(a_ID==app)
{
Console.WriteLine("App Inserted");
}
}
} ;
With something like this:
foreach(XmlNode node in nodes)
{
if(node.HasChildNodes)
{
string a_ID = string.Empty;
string ...
...
IEnumerator nodeEnumerator = node.GetEnumerator();
while (nodeEnumerator.MoveNext())
{
XmlNode currentChildNode = (XmlNode)nodeEnumerator.Current;
if (currentChildNode.NodeType != XmlNodeType.Element)
continue;
switch (currentChildNode.Name)
{
case "AppId": a_ID = currentChildNode.InnerText; break;
case "GroupId": ...
...
}
}
}
} ;
Greetings
Covean
|
|
|
|
|
The app I'm doing now, to manage equipment records in an electrical substation, uses about 6 major devices - reclosers, regulators, transformers, capacitors, load tap changers, and breakers - but I'm only working with one type right now. Initially I defined that class in the main form of the app, but I know that's going to get unwieldy later when I add the rest of the devices. So tonight I added a code file, moved the recloser class there, and modified the 'using' statements in the rest of the project to reference the new namespace containing the equipment classes. It worked very nicely, with no errors, so I must be learning something.
Whenever I create a new form or other component in my project, VS automatically adds those ubiquitous 'using' statements, and I notice they're all selected from the list under References in Project Explorer. Is there a way I can set up the IDE to automatically add my custom namespace to each new item I create as the project grows? I tried adding a reference, but my new namespace doesn't show up in any of the tabs of the selection box. It's a minor thing, but it would be a convenience, and would probably save me a few errors later when I inevitably forget to type in the reference manually.
Or should I just shut up and go back to typing?
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Update the class file in the following zip file:
Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\CSharp\1033\Class.zip
Then, save it ans reopen VS with /setup switch. It will change the default class file.
Although, same default will be used for all the projects. So any new project you create which is not related to your current one, will throw error.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
d@nish wrote: any new project you create which is not related to your current one, will throw error.
Sounds like more trouble than it's worth. I'll just get used to typing.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Can't help you there; I don't use any using directives.
|
|
|
|
|
I was pretty much sure that as DataGridViewColumn implements IComponent, it should throw exception when manipulated by another thread. I am little bit surprised to see that we can change any property of DataGridViewClumn from any thread while it is not possible for DataGridView itself.
How is it possible that DataGridView is not editable from another thread while the datagridviewcolumn is?
I am waiting for the answer since 24 hours..
Jayant D. Kulkarni
modified on Thursday, December 10, 2009 11:29 PM
|
|
|
|
|
On creation of multifile assembly,
When i run the csc command, it gives error stating that csc command is not valid.
Can anyone say how to compile the files to create multifile assembly.
Thanks & regards,
sandhiya
|
|
|
|
|
Determine the full path of CSC and either use it or add it to the PATH environment variable.
|
|
|
|
|
I am trying to understand the standard class HashSet<T>. As I understand it, this class implements a hash table. For example, it supports the method Add which adds members to the hash table. It also supports a method Contains which returns a boolean value whether or not the data item is in the table. Let say, I am writing an application with the following class:
class person {
public int id;
public string name;
}
Now, I am going to need to overload the operators == and != for the class person. My comparison
operator will return equal if and only if the classes have the same id. If I do that,
then I believe that I can write the following declaration:
HashSet<person> personSet;
Now, given the declaration of personSet, I know how to add things to it, but given an id, how do I find the person's name. That is, I would expect that the class should have some kind of find method. However, after looking thought the documentation, I failed to find such a function. I did find a method Contains, but that just returns a bool value. What am I missing?
Thanks
Bob
|
|
|
|
|
One possible way is to enumerate the personSet and check for each person id with the expected id. Or use the extension methods like First , FirstOrDefault etc. Doing all these breaks the advantage HashSet offers and lead to O(n) complexity.
HashSet can be used only when you need to remember a value that you have already seen and when you don't care about other details about the value. Consider a scenario where you need to remove duplicates from a list. You iterate the list and add each elements to a HashSet checking Contains() before each insert. All these searches takes constant time and this makes huge difference when working with big collections.
Having said that, I think HashSet is not the right class you need. You need an associative container. Take a look at Dictionary<TKey, TValue> . Create a dictionary like Dictionary<int, Person> . Now the ids are associated with each person objects. Given an id, you can easily find the person object with a constant (O(1)) complexity.
BobInNJ wrote: I am going to need to overload the operators == and != for the class person. My comparison
operator will return equal if and only if the classes have the same id
A recommended practice is to override Equals() and let your operator overloads call this equals. You may also need to override GetHashCode() .
Best wishes,
Navaneeth
|
|
|
|
|
Hello. I have tried much here.
I want this words so be deleted everytime they are seen.
MBR
MBA
MSc Economics
I have tried this:
richTextBox1.Text = richTextBox1.Text.Replace("MBR","");
richTextBox1.Text = richTextBox1.Text.Replace("MBA","");
richTextBox1.Text = richTextBox1.Text.Replace("MSc Economics", "");
But there are comming a whitespace, and I don't want a blank space.
I want it to be total deleted.
If we have a name called: Jensen, MBA, Johan
Shall MBa be deleted so there only will be this back: Jensen Johan
With only one blank space..
Plx help
|
|
|
|
|
From you example:
You have
Jensen, MBA, Johan
You want
Jensen Johan
I consider in my answer that you want to remove (MBR/MBA/MSc Economics + all between comas)
You need to use regular expression rather than a simple Text replace.
String test = "Jensen, MBA, Johan";
String result = Regex.Replace(test, @",\s*(MBR|MBA|MSc Economics)\s*,", "");
In order to get Regex add:
using System.Text.RegularExpressions;
|
|
|
|
|
Another approach, locate for the first "," and second ','. Then remove that part of the string from the main string.
Something like -
temp.Remove(temp.IndexOf(","),temp.LastIndexOf(",") - temp.IndexOf(","));
|
|
|
|
|
Thanks for replies.
What if i have over 100 names in one Richbox, how could i so do it? :9
|
|
|
|
|
Hello,
I have a SmartDevice project (.NetCF 2.0) configured to be tested on the USA Windows Mobile 5.0 Pocket PC R2 Emulator. My project uses SqlCe 3.0. Understanding that a SmartDevice project is "more carefull" with the device's memory I am using SqlCeResultSets. The result sets are strongly typed, autogenerated by Visual Studio 2008 using the custom tool MSResultSetGenerator.
The problem I am facing is that the result set does not recognize any column names. The autogenerated code for the fields does not work.
In the client code I am using
InfoResultSet rs = new InfoResultSet();
rs.Open();
rs.ReadFirst();
string myFormattedDate = rs.MyDateColumn.ToString("dd/MM/yyyy");
When the execution on the emulator reaches the rs.MyDateColumn the application throws an System.IndexOutOfRangeException .
Investigating the stack trace
at System.Data.SqlServerCe.FieldNameLookup.GetOrdinal()
at System.Data.SqlServerCe.SqlCeDataReader.GetOrdinal()
I've tested the GetOrdinal method (in my autogenerated class that inherits SqlCeResultSet):
this.GetOrdinal("MyDateColumn");
this.GetName(1);
this.GetOrdinal(this.GetName(1));
Am I doing something wrong or am I missing something?
Thank you.
I have no smart signature yet...
modified on Wednesday, December 9, 2009 12:33 PM
|
|
|
|
|
If I have understood your issue:
if (! yourReader.IsDBNull(yourReader.GetOrdinal("MyDateColumn")))
myTime = yourReader.GetDateTime(yourReader.GetOrdinal("MyDateColumn"));
else
myTime = DateTime.MinValue;
This is because DateTime used internaly cannot handle null value
|
|
|
|
|
Thanks for your answer, but that is not the issue. The code does not fail at reading the data. The code fails at myReader.GetOrdinal("MyDateColumn")
If I use myReader.GetDateTime(1); the code works, but is dependent of the position of the column in the schema.
If I use myReader.GetDateTime(myReader.GetOrdinal("MyDateColumn")); the code does not work...
If I use myReader.GetOrdinal("MyDateColumn") the code does not work...
If I use myReader.GetName(1) the code works and the return value from the function is "MyDateColumn"...
I've worked before with ADO.Net and never had this issue. Now I am using SqlCe (SqlCeResultSet) and the only thing I can think about is that SqlCe is responsible for this (or the managed wrapper).
Any other ideeas?
I have no smart signature yet...
|
|
|
|
|
Hello,
another (I hope) little problem. I have written an own TabPage (derrived from TabPage), that is correctly initialized. Later, when the User clicks a button, the information should be updated. The button Event ist handeld correctly and the programm tries to set e.g. a new text into a Label. But the new text is never displayed. I have tried the methods "Refresh" and "Update" on both TabPage AND Label, but nothing changes. What I am doiing wrong?
Grretings, Taggi
How do you know, that Tagamoga has been assimilated by the borg?
"Recistunce ist fiutille."
Sorry for violating the english language.
|
|
|
|
|
Hard to say without seeing the code you are using. Could you post the relevant code snippets please.
|
|
|
|
|
Hello.
I will try hard.
Well, when my own written Tab is in Focus a special Button occurs. Clicking on it, it evokes following function:
private void monatsUebersichtNeueAuswertung_Click(object sender, EventArgs e)
{
MonatsUebersichtDialog dlg = new MonatsUebersichtDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
MonatsUebersichtTab tab = (MonatsUebersichtTab)Reiteransicht.SelectedTab;
tab.setNewData(dlg.User, dlg.Von, dlg.Bis, dlg.Projekt);
tab.Update();
tab.Refresh();
dlg.Dispose();
}
}
The function "setNewData" should now update the page with the new information.
public void setNewData(String newUser, String newVon, String newBis, String newProjekt)
{
lblName.Text = myData.ToString();
lblName.Update();
lblName.Refresh();
this.Update();
this.Refresh();
}
But this Label shows never the new Text. And yes, myData.toString() return the correct String value.
Greetings, Taggi
How do you know, that Tagamoga has been assimilated by the borg?
"Recistunce ist fiutille."
Sorry for violating the english language.
|
|
|
|
|
hmm...
First a couple of observations that won't directly effect the update.
You should have the dlg.Dispose() outside the if statement or it won't be disposed if you cancel.
You shouldn't ever have to call Update or Refresh . Setting the Text property causes the control to repaint anyway.
As to the Label failing to update. Nothing jumps out at me as obviously wrong. However you have subclassed the TabPage itself, and tabpages are often a pain.
Would I be correct in assuming that your Label is in the TabPage ? Or is it in a Panel on the Tabpage ?
One possible issue is that if the Label BackColor is set to Transparent it may cause painting issues when used on a TabPage .
Try using a standard System.Windows.Forms.TabPage and updating the label text from the monatsUebersichtNeueAuswertung_Click method.
Finally, good post. To many posts here have not syntax colouring, no use of code tags, and often no code either. Thanks.
|
|
|
|
|
Hello.
Thank you for your reply!
First about the dlg.Dispose() in the wrong place: Yes you are right. But a question: Isn't it in C# the same like in Java with carbage collector? I know that in c++ you have to take care by your own about your objects. But does c# not have a carbage collector?
Second: My Label is directly in the TabPage and doesn't have got a transparent Background. What are exactly panels for? Only for Layout, isn't it?
Third: I have tried with a standard TabPage and it works there perfect.
It's disgusting.... I cannot be too dump for this "problem".
Sorry, for not posting my code in my first post. I though this is a so basic problem, that I didn't understand, so that no code would be nessacary. And the snytax highlighting was made by your forum...
Well I wish you a good night, I hope a little sleep will perhaps help me.
Greetings, Taggi
How do you know, that Tagamoga has been assimilated by the borg?
"Recistunce ist fiutille."
Sorry for violating the english language.
|
|
|
|
|
You are quite correct, C# does have a garbage collector, however it is best practice to call dispose making the dialogue available for garbage collection explicitly, rather than it hanging around waiting for the .Net framework to decide it needs the memory back.
Interestingly, if you call .ShowDialog() then it is up to you to Dispose of the object. However calling .Show() will automatically invoke .Dispose() for you when the form has closed.
I can't think what could be causing the problem with the Label, however if you could send me the code for your TabPage I can try it out and see if I can work out what is happening. A bit big to post here I guess so Zip and Email it direct (using the Email link below).
|
|
|
|
|
I'm writing a small C# WinForms app. I'm not using ClickOnce (so far as I'm aware). I am making a call to
System.Windows.Forms.Application.UserAppDataPath
from another thread (other than the main UI thread) that was started *after* the main form's Form_Load event handler. This keeps causing InvalidDeploymentException to be thrown, claiming the "Application identity is not set" as an error message. Is there some magic incantation to prevent these from popping up? It's really f'ing annoying at this point.
|
|
|
|
|