|
Yeah, see? Use a switch instead.
|
|
|
|
|
Hi
Is there any way to inject new class to assemby ?
The Reflexil is good tool to assembly manipulation, but it works fine when i change the existing code or add some code to existing method, when i add new class to my assembly by reflexil, the output assembly does not works and throw exception. how can i do that ?
thanks
|
|
|
|
|
Hi guys!
Please help, I am trying to pass data from form1 to form2 using a datagridview cell click event (passing data from datagridview1 in form1 to datagridview2 in form2)
It is working fine if I open form1 and then form2, if I open form2 before form1 then it doesn't because it can't capture instance of form1 to access it.
Here is what I am doing presently:
in Parent (MDI), I have a public form instance for form1, I use that when I open form1 and then pass that instance to form2 when I open it.
This is what I am doing:
In Parent:
public frmGrid1 frm1;
....
//Form1 click event in parent
frm1 = new frmGrid1(m_ADBCnn, 1, notWorkedToolStripMenuItem.Text);
frm1.MdiParent = this;
frm1.Show();
....
//Form2 click event in parent
frm2 = new frmGrid2(frm1,m_ADBCnn,1,presentToolStripMenuItem.Text);
frm2.Show();
frm2.MdiParent = this;
I then assign frm1 in the constructor of form2 as follows:
private frmGrid1 frm1;
public frmGrid2(frmGrid1 f1)
{
try
{
InitializeComponent();
frm1 = f1;
}
catch (Exception ex)
{
MessageBox.Show("Failed on initialization: " + ex.Message);
}
}
Again, this works if I open form1 before form2. How can I retrieve frm1 from frm2 if it is null?
Please help
Sameer
|
|
|
|
|
Best way to do this would be with events[^], each form will have an event that fires when the cell is clicked (or whatever) the parent form then listens for this event. When it is fired then the parent form can receive the data from one form (through event args or property) and then pass the data to the other form (through method or property)
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi Musefan,
Thank you for your prompt response. Pardon me but I have never used custom events, is there any way you can show me an example, I will appreciate it.
Thanks
Sameer
|
|
|
|
|
|
|
Hello,
I have a problem:
I used the overriding of Wndproc to catch the minimize button and replace it with a "fade out" by reducing the forms opacity and hiding it. I also added a tray icon and with a click on it you can fade the form in and out. The form never appears in the task bar.
This works rather fine but now the problem:
I maximize the form, then minimize it (it fades out) and again fade it in with a click on the tray icon. The form comes back maximized but now if I want to switch to "normal" the form is normal but with the size of the maximized form. So my form seems to forget its previous size, although I don´t work with the form size in my code at all...
Questions:
1. I would really be interested why this happens...
2. Is there an elegant way to fix this or will I have to fix it manually (store size and resize it on my own if I recognize a transition of maximized to normal)?
Thanks for your help!
Bye
Thomas
|
|
|
|
|
When I was using forms in a similar way, the only way I found to get round in was to store the FormWindowState when ever it was resized (providing it was not set to Minimized) and then when I need to show it again I could set it to the stored state
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi,
finally had time to check my code and found the error:
when fading in the form I did a
this.WindowState = FormWindowState.Normal
just to be sure that the form doesn´t return minimized. But I don´t need this line because the form IS never minimized and it seems to make some confusion when you fade in the form when it was maximized before. Reason seems to be that a second Resize event is raised which mixes up the size of the WindowStates.
Thanks and bye
Thomas
|
|
|
|
|
HI,
While trying to run the below code for copying a file from my system to another share folder, it returns an exception saying "Incorrect function" at the line WindowsIdentity idnt = new WindowsIdentity("domain_username", "password") in the below given code:
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Text;
using System.Management;
using System.Windows;
using System.Security.Principal;
namespace Authentication
{
class Program
{
AppDomain.CurrentDomain.SetPrincipalPolicy(System.Security.Principal.PrincipalPolicy.WindowsPrincipal);
WindowsIdentity idnt = new WindowsIdentity("domain_username", "password");
WindowsImpersonationContext context = idnt.Impersonate();
System.IO.File.Copy("G:\\E-Drive\\batfiles\\java.bat", "\\\\10.200.93.93\\share\\java.bat", true);
Can any one help me out to resolve this issue?
Thanks in Advance _
|
|
|
|
|
Is the username and password in your code an example or is it what you're actually using?
|
|
|
|
|
|
Here's a clue:
Where is the author of this most likely to be? Here or OVER ON CODESOURCE!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hi folks. This is probably a simple one for the XML gurus, but it has me stumped. I am trying deserialise an XML file, which is easy enough. But now I need to create objects based on an XML element's attribute, and I can't see how to do it.
Here is a simplified version of the problem. I started with a file that looks like this:
<fleet>
<auto>boss's limo</auto>
<auto<delivery truck</auto>
<auto<employee's rusty corvair</auto>
</fleet>
Easy enough to deserialise:
public class AutoClass { ... }
[XmlRoot("fleet")]
public class FleetClass
{
[XmlElement("auto")
public AutoClass[] Vehicles { ... }
}
But now, I need to change the classes around. I need a CarClass and TruckClass that inherit from AutoClass . So I created:
public class CarClass : AutoClass { ... }
public class TruckClass : AutoClass { ... }
Additionally, the file should look like this
<fleet>
<auto type="car">boss's limo</auto>
<auto type="truck"/>delivery truck</auto>
<auto type="car">employee's rusty corvair</auto>
</fleet>
But the Vehicles property generates AutoClass objects and I need the results to be of type CarClass and TruckClass . I can't downcast Vehicles[0] to CarClass (or can I?). How do I get Vehicles to examine the type attribute of the auto element and create 2 CarClass objects and one TruckClass ?
I hope that is clear - if not, let me know.
Clive Pottinger
Victoria, BC
|
|
|
|
|
|
Thanks for the speedy reply. However, I don't see how the XSD tool will help in this case. From the documentation here (http://msdn.microsoft.com/en-us/library/x6c1kb0s%28VS.80%29.aspx) it seems that the tool will simply generate code for classes based on the XML elements found. I don't see how to use it to generate a class based on an XML element's attribute.
Clive Pottinger
Victoria, BC
|
|
|
|
|
Perhaps I need to clarify further. I would like to deserialise this XML
<fleet>
<auto type="car">boss's limo</auto>
<auto type="truck"/>delivery truck</auto>
<auto type="car">employee's rusty corvair</auto>
</fleet> into these classes
public class AutoClass { ... }
[XmlRoot("fleet")]
public class FleetClass
{
[XmlElement("auto")
public AutoClass[] Vehicles { ... }
}
public class CarClass : AutoClass { ... }
public class TruckClass : AutoClass { ... } so that
XmlSerializer s = new XmlSerializer( typeof( FleetClass ) );
TextReader r = new StreamReader( "example.xml" );
FleetClass myFleet = (FleetClass)s.Deserialize( r );
AutoClass[] myVehicles = myFleet.Vehicles; should result in myVehicles containing 2 objects of type CarClass and 1 object of type TruckClass - not 3 objects of type AutoClass .
Edit: I know I could change the <auto> tags to <car> and <truck> and collect them in the Vehicles property - but that is not the goal. The XML tag should remain as <auto> but the objects created need to be of types CarClass and TruckClass .
Is there any way to decorate the classes and properties to accomplish this?
Clive Pottinger
Victoria, BC
modified on Thursday, July 23, 2009 12:11 PM
|
|
|
|
|
i have a XML file and wanted to read value from XML and search it into the registry of system.
i can read the file but unable to find out the way to find it into the registry.
can anybody help me??
here is the code and the XML file.
string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion";
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
{
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
string a = "";
XmlTextReader reader = new XmlTextReader(@"D:\REGFile.xml");
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Text:
a = reader.Value;
string b = sk.GetValue(a);
if (sk.equals(a))
{
Console.WriteLine("Exists in Registry");
}
else
{
Console.WriteLine("Wrong");
}
break;
}
}
}
}
Console.ReadLine();
****************************XML FILE*********************
<?xml version="1.0"?>
<RegistryValues>
<Values>
<Value>HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\winzip32.exe</Value>
<Value> HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\winzip.exe</Value>
<Value>HKCR\CLSID\{00000000-0000-0000-0000-000000000000</Value>
<Value>HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\winzip.exe</Value>
<Value>HKCR\WinZip\DefaultIcon</Value>
<Value>HKCR\WinZip\shell\open\command</Value>
<Value>HKCR\WinZip\shell\open</Value>
<Value>HKCR\WinZip\shell\print\command</Value>
<Value>HKCR\WinZip\shell\print</Value>
<Value>HKCR\WinZip\shell</Value>
<Value>HKCR\WinZip\shellex\DropHandler</Value>
<Value>HKCR\WinZip\shellex</Value>
<Value>HKCR\WinZip</Value>
<Value>HKCR\.ARC</Value>
<Value>HKCR\.TAR</Value>
<Value>HKCR\.TAZ</Value>
<Value>HKCR\.TGZ</Value>
<Value>HKCR\.TZ</Value>
<Value>HKCR\.GZ</Value>
<Value>HKCR\.Z</Value>
<Value>HKCR\.CAB</Value>
<Value>HKCR\.UU</Value>
<Value>HKCR\.UUE</Value>
<Value>HKCR\.XXE</Value>
<Value>HKCR\.B64</Value>
<Value>HKCR\.HQX</Value>
<Value>HKCR\.BHX</Value>
<Value>HKCR\.MIM</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip\WinIni</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip\caution</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip\fm</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip\Programs</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip\Uninstall</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip\WinZip</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip\wzshlext</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing\WinZip</Value>
<Value>HKLM\SOFTWARE\Nico Mak Computing</Value>
</Values>
</RegistryValues>
sweety
|
|
|
|
|
Hi, i am very new to C#, im trying to create a file that enumerates the processes constantly, checking whether a process which is written in a txt file is running, and if so, it prints it in a .ini file, So far everythings working fine. But it only works when i open the file while the desired process is already running, thus the program has to be re-opened everytime for it to update. is there a way to make this code loop? or a mor efficiant way to get the desired effect?
Heres my code
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
class Program
{
[STAThread]
[DllImport("kernel32.dll", EntryPoint = "WritePrivateProfileString")]
private static extern bool WritePrivateProfileString(string lpAppName, string lpKeyName, string lpString, string lpFileName);
static void Main(string[] args)
{
string line;
System.IO.StreamReader file = new System.IO.StreamReader("X:\\file.txt");
while ((line = file.ReadLine()) != null)
{
Process[] procs;
procs = Process.GetProcessesByName(line);
foreach (Process p in procs)
{
WritePrivateProfileString("Main", "Current Process", line, ("X:\\config.ini"));
}
}
file.Close();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
|
|
|
|
|
As you're using Windows Forms you can add a timer to the form and fire your code in the Ticks (or Elapsed, can never remember which) event of said timer. That way it will periodically check the running processes and update your ini file without the need for a loop.
|
|
|
|
|
Hey, thanks for the reply, very useful, and it was ticks... Works perfectly
modified on Thursday, July 23, 2009 11:40 AM
|
|
|
|
|
I created a method that makes use of the .Select() method so that to check in a datatable if the value is already in the data table. For 1/4 of the recordss its working but at certain point it prompts out the fllowing error
Min (14) must be less than or equal to max (-1) in a Range object.
I am getting the data from MS Access. I have changed the databases so that to check if it was only with one version but It still showed me the error. only the number 14 changed. I have checked the records of the ids that the program was stopping all and they are all good values. Can some one help on that please. it is very urgent. THAnks alot for your time and help.
|
|
|
|
|
jonhbt wrote: it is very urgent
Of course it is, all questions here are urgent to the poster. But this is a free site so... (hint don't post that again)
As to your problem can you provide the code that does the select (so your method) and some of the values where the code gives that error on?
|
|
|
|
|
Sry for that I didn't want to cause any problems the code that I am using is this
DataTable dtAllEmps = new DataTable();<br />
dtAllEmps = cetData.GetALLEmployessByDate(conString, sensors);<br />
<br />
<br />
foreach (DataRow dataRow in dtAllEmps.Rows)<br />
{<br />
if(dtCSV.Rows.Count == 0)<br />
{<br />
DataRow newRow = dtCSV.NewRow();<br />
newRow["UserID"] = dataRow["USERID"];<br />
newRow["Department"] = dataRow["DEPTNAME"];<br />
newRow["Date"] = dataRow["CHECKTIME"];<br />
newRow["Name"] = dataRow["NAME"];<br />
newRow["CheckType"] = dataRow["CHECKTYPE"];<br />
dtCSV.Rows.Add(newRow);<br />
}<br />
else<br />
{<br />
Console.WriteLine("User ID " + dataRow["USERID"].ToString());<br />
if (dataRow["USERID"].ToString() != "")<br />
{<br />
string strExpr = "UserID = " + dataRow["USERID"].ToString();<br />
Console.WriteLine("Expression " + strExpr);<br />
DataRow[] filteredRows = dtCSV.Select(strExpr);<br />
<br />
<br />
if (filteredRows.Count() == 1)<br />
{<br />
Console.WriteLine("Number of Rows " + filteredRows.Count().ToString());<br />
DataRow csvRow = filteredRows[0];<br />
DateTime csvDate = Convert.ToDateTime(csvRow["Date"]);<br />
DateTime tableDate = Convert.ToDateTime(dataRow["CHECKTIME"]);<br />
Console.WriteLine("csvDate" + csvRow["Date"].ToString());<br />
Console.WriteLine("tableDate" + dataRow["CHECKTIME"].ToString());<br />
if (csvDate < tableDate)<br />
{<br />
filteredRows[0]["Date"] = tableDate.ToString();<br />
filteredRows[0]["CheckType"] = dataRow["CHECKTYPE"].ToString();<br />
filteredRows[0]["Department"] = dataRow["DEPTNAME"].ToString();<br />
}<br />
|
|
|
|