|
Hi every Body iam new C# developer to that great site with great background about C#
i thank everybody here for continous knowledge they offer here
so i need to develop A program with timer after specific time it logs off windows the same as log off code in microsoft windows when you click the following
start > log off > then you will see three buttons appear in borderless form then don't press any button just you will see the desktop is becoming deactivated and become like just image you can't press any thing on your desktop except when you click cancel button
i want to do something like that with C# is there any help about that please
please refer to me at
snouto@phreaker.net
Miss With The Best And Die Like The Rest
|
|
|
|
|
To do stuff like that, you need to interop the C dlls. www.pinvoke.net is the best place online to get info on that stuff. Google the C API calls first, then go there to see how to interop them.
public class Shutdown<br />
{<br />
[StructLayout(LayoutKind.Sequential, Pack=1)]<br />
internal struct TokPriv1Luid<br />
{<br />
public int Count;<br />
public long Luid;<br />
public int Attr;<br />
}<br />
<br />
[DllImport("kernel32.dll", ExactSpelling=true) ]<br />
internal static extern IntPtr GetCurrentProcess();<br />
<br />
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]<br />
internal static extern bool OpenProcessToken( IntPtr h, int acc, ref IntPtr phtok );<br />
<br />
[DllImport("advapi32.dll", SetLastError=true) ]<br />
internal static extern bool LookupPrivilegeValue( string host, string name, ref long pluid );<br />
<br />
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]<br />
internal static extern bool AdjustTokenPrivileges( IntPtr htok, bool disall,<br />
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen );<br />
<br />
[DllImport("user32.dll", ExactSpelling=true, SetLastError=true) ]<br />
internal static extern bool ExitWindowsEx( int flg, int rea );<br />
<br />
internal const int SE_PRIVILEGE_ENABLED = 0x00000002;<br />
internal const int TOKEN_QUERY = 0x00000008;<br />
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;<br />
internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";<br />
internal const int EWX_LOGOFF = 0x00000000;<br />
internal const int EWX_SHUTDOWN = 0x00000001;<br />
internal const int EWX_REBOOT = 0x00000002;<br />
internal const int EWX_FORCE = 0x00000004;<br />
internal const int EWX_POWEROFF = 0x00000008;<br />
internal const int EWX_FORCEIFHUNG = 0x00000010;<br />
<br />
private static void DoExitWin( int flg )<br />
{<br />
bool ok;<br />
TokPriv1Luid tp;<br />
IntPtr hproc = GetCurrentProcess();<br />
IntPtr htok = IntPtr.Zero;<br />
ok = OpenProcessToken( hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok );<br />
tp.Count = 1;<br />
tp.Luid = 0;<br />
tp.Attr = SE_PRIVILEGE_ENABLED;<br />
ok = LookupPrivilegeValue( null, SE_SHUTDOWN_NAME, ref tp.Luid );<br />
ok = AdjustTokenPrivileges( htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero );<br />
ok = ExitWindowsEx( flg, 0 );<br />
}<br />
<br />
public static void ShutDown()<br />
{<br />
DoExitWin( EWX_POWEROFF | EWX_FORCE );<br />
}<br />
}
That's a class that shuts down windows, I reckon that changing the flags you pass in should log off instead.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I have managed to get succesfully working the , delete and cancel functions working within the datagrid to alter data held in dataset that then updates a SQL Database.
When I click edit the correct row changes into textboxes to make the changes. Then when I click update is when I get stuck. I am using the datagrid (dgCustomers) items index and DataKeyField (CustomerID) to search for the correct row within the dataset, to update.
here is the code:
private void dgCustomers_UpdateCommand(object source, system.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// //Test Label to see the value of the datakey is correct
Label6.Text = dgCustomers.DataKeys[e.Item.ItemIndex].ToString();
//Select correct row using the index and datakeyfield.
DataRow[] adrEdit = ds.Tables["Customers"].Select("CustomerID = 'dgCustomers.DataKeys[e.Items.ItemIndex]'");
//Make sure there is data
if(adrEdit.Length > 0)
{
//Put in the edited data
TextBox txtCompanyName = (TextBox) e.Item.Cells[3].Controls[0];
adrEdit[0]["CompanyName"] = txtCompanyName.Text;
TextBox txtContactName = (TextBox) e.Item.Cells[4].Controls[0];
adrEdit[0]["ContactName"] = txtContactName.Text;
}
else
{
LblResult.Text = "Not Updated";
}
//End editing
dgCustomers.EditItemIndex = -1;
//Update the database
da.Update(ds,"Customers");
//And bind data to the ui
LoadData();
}
For some reason it doesn't find the necessary data and skips the if loop. The test label(label6) however does return the value of a customerID suck as ALFKI.
If I replace this row
DataRow[] adrEdit = ds.Tables["Customers"].Select("CustomerID = 'dgCustomers.DataKeys[e.Items.ItemIndex]'")
With this more explicit statement
DataRow[] adrEdit = ds.Tables["Customers"].Select("CustomerID = 'ALFKI'")
It actually works, but obviously updates only the ALFKI row. Can anyone shed any light on where I may be going wrong, or is it just my comp playing funny buggers with me again!
Many thanks
Paul Custance
|
|
|
|
|
Hello everyone,
I found an articles in msdn which is "Receiving SMS Messages Inside a Managed Application". I download the sample code and run it.This project contains two separte projects "mapirule" and "CaptureSMS". Mapirule was implemented by using embedded Visual C++ 4.0 and CaptureSMS contains managed code only which was implemented by using Visual Studio.NET 2003
When I built mapirule.dll in embedded C++4.0, the error "download file failed" occurred. When I tested the sample code on an emulator and clicked Start IMailRuleClient". Error message "The function is not defined" ("registerServer function). This function is defined in mapirule. How come mapirull.dll can't be loaded? Is there anyone who can give me any suggestion.It's urgent. Thank you veryyyy much.
Co
|
|
|
|
|
Hi All,
I'm kind of new to C# and I have a datagrid question. I have a master-detail form with databound controls. The selection is made by a combo box containing a list of all customers. There are then some databound text boxes with customer fields. And finally there is a data grid with a list of notes for the particular customer. To get all this to work together, I used the data table (customerDS.Customer) as the datasource for all controls. The individual fields are then the data members. For the grid, the Customers table is the datasource and the relation (Customer_CustomerNote) is the data member.
What I'm having trouble with is setting up TableStyles and ColumnStyles. I would like to change column widths, column headings, etc. on the grid. But even if I set up the TableStyles and ColumnStyles the way I want, the grid still displays as the default (i.e. all columns, field names from my dataset as column headings, etc.). For the Mapping Name for my TableStyle I use the data relation (Customer_CustomerNote) - it's the only choice in the dropdown list anyway. For Mapping Names for my ColumnStyles I drill down to Customer_CustomerNote --> (Individual field names).
If someone has any insight as to what I need to do or what I'm doing wrong I'd appreciate the help.
Thanks,
Dennis
|
|
|
|
|
Hi Dennis,
Whats the problem you are having. Can you try using the following code.
DataGridTableStyle tsstyle = new DataGridTableStyle();
tsstyle.MappingName = dataGrid1.DataSource.ToString();
dataGrid1.TableStyles.Add(tsstyle);
Console.WriteLine(dataGrid1.TableStyles[0].GridColumnStyles.Count.ToString());
dataGrid1.TableStyles[0].GridColumnStyles[0].HeaderText = "User Id";
dataGrid1.TableStyles[0].GridColumnStyles[1].HeaderText = "User First Name";
dataGrid1.TableStyles[0].GridColumnStyles[2].HeaderText = "User Last Name";
dataGrid1.TableStyles[0].GridColumnStyles[3].HeaderText = "User Age";
Hope this will help you.
Thanks
SGS
|
|
|
|
|
Thanks for your reply Kodanda.
I tried your code. Here are the results:
I wasn't sure whether you wanted me to use the above code with all my designer settings still in place or use the above code instead of setting everything up through the designer. If I kept my settings in place, the additional TableStyle you create in your code never gets used. But if I remove my settings, it appears there is no mechanism in the above code to attach ColumnStyles to the TableStyle before accessing the ColumnStyles. I tried both ways.
If I added the code above with everything set up in the designer as I had before (i.e. my TableStyle and all ColumnStyles still set up) I was able to access 3 GridColumnStyle indices (0, 1, and 2). This, I assume, is because I set up 3 ColumnStyles via the designer. If I tried to access a fourth index (there are actually 5 fields in the dataset) I got an array out of bounds exception. When I run the code, the Console.WriteLine tells me there are 3 ColumnStyles. All of this makes sense to me. But the grid still appears in my form (both in the designer and at runtime) with all 5 columns from the dataset (instead of just the 3 I set up ColumnStyles for) and the default header names and widths.
If I removed my designer-created TableStyle and ColumnStyles and tried to use your code in its place, I got an array out of bounds exception at the access of GridColumnStyles[0] as I figured I would since there didn't seem to be any mechanism for attaching the ColumnStyles to the TableStyle. The only way I could find to attach them was basically using the same code the designer had used when it hooked up my visual settings. And the result was the same - the grid showed all 5 columns with default widths and heading names.
I am at a loss. Everything appears to be set up properly. I even looked through the designer-generated code and everything made sense. But somehow the grid is not displaying the way it's set up to. When I originally had the grid hooked up to an actual table for a datasource (instead of the Customer_CustomerNotes relation) my TableStyle and ColumnStyles seemed to work. Is there an issue with these working if you hook the grid up to a data relation instead of a data table? Or am I just missing something?
Thanks again,
Dennis
|
|
|
|
|
Hello,
I have a webservice method which reads a local file and returns the byte array. But when ever i run it from the client it throws \either a SOAP exception or authentication error. (I use Windows server 2003)I continue to recieve these errors despite the following actions
1) Gave Administrator rights to ASP.NEt user in windows
2) Added HttpGet and HttpGet elements to Web.Config
3) Allowed anonymous access alone in IIS, Anonymous access + windows authentication and then Windows authentication alone.
4) created a Network credential object and gave NT user account details.
Can anyone help me ? I just need to read a file from the machine where the service runs and return the byte array.
Thanks in advance and tnx for your time.
James Poulose
|
|
|
|
|
Check the physical file permissions. I doubt they're set to allow annonymous read/write. I'd also check IIS's settings. You can always use impersonation in your web.config file to force your code to run under a specific identity. You can do the same thing in code as well. Use a WindowsPrincipal object to get the same results.
|
|
|
|
|
How to create a shallow copy of List<t> ? It doesn't seem to implement the Clone method. Is CopyTo the same ?
Best regards, Desmond
|
|
|
|
|
|
Hello:
From a web form I’m sending to execute a function contained into a class, code in web form is:
bool que = WUC_CreDes.Class1.Hay_PostBack(this, w1,w1cx, w1ID, w2, w2cx, w2ID);
In class code is:
public static bool Hay_PostBack(WUC_CreDes.WebForm1 parent1, string w1,
string w1cx,
string w1ID,
string w2,
string w2cx,
string w2ID)
{
string cual = "";
cual = HttpContext.Current.Session["par1"].ToString();
parent1.Example.Controls.Clear();
if(cual == w1)
{
Control control = parent1.Page.LoadControl(w1cx);
control.ID = w1ID;
parent1.Example.Controls.Add(control);
}
else
{
Control control = parent1.Page.LoadControl(w2cx);
control.ID = w2ID;
parent1.Example.Controls.Add(control);
}
return false;
}
As you can see, I’m sending to function container into class my WebForm1 to create in function WUC dynamically created.
Thinking in a second web form, let us say, WebForm2, if within it I send to execute my function:
bool que = WUC_CreDes.Class1.Hay_PostBack(this, w1,w1cx, w1ID, w2, w2cx, w2ID);
How can I do to function Hay_PostBack, above mentioned work also for WebForm2 What I need to change because first parameter is WUC_CreDes.Web Form1 parent1?
I’ll thank your answers.
Greetings.
A.L.
El hombre que tiene amigos debe mostrarse amigo...
|
|
|
|
|
Hey u raised the simplest inheritance question possible
All your windows forms in C# or .Net rather inherit from a common base class which System.Windows.Forms so whether u want to send webForm1 or webForm2 or .... webFormn u can do it passing it as a base class and then later converting it into the derived class and by performing a runtime check
I dont have the visual studio while writing this, so there might be some error in the code that I write in here but u will get a general idea
using System.Windows.Form;
public static bool Hay_PostBack(System.Windows.Forms.Form parent1, string w1,
string w1cx,
string w1ID,
string w2,
string w2cx,
string w2ID)
{
if(parent1.GetType().ToString() == "WUC_CreDes.WebForm1")
{
WUC_CreDes.WebForm1 frm = (WUC_CreDes.WebForm1)parent1;
if (frm!=null) frm.Do_Something();
}
else if (parent1.GetType().ToString() == "WUC_CreDes.WebForm2")
{
WUC_CreDes.WebForm2 frm = (WUC_CreDes.WebForm2)parent1;
if (frm != null) frm.Do_Something();
}
}
and there you are .... that should kinda solve your query .... if theres any problem with that one write me back .... Since I dont VS.Net right now there might be syntax errors in what I typed but if i finc some I ll key in another reply
Pushkar Pathak
|
|
|
|
|
Thanks you Pushkar:
I guess your code is right to window form, but I'm using web form.
What would be equivalent code in web form to
System.Windows.Forms.Form?
And how can I call Hay_PostBack from my web form?
maybe:
bool que = WUC_CreDes.Class1.Hay_PostBack(this, w1,w1cx, w1ID, w2, w2cx, w2ID);
Please help me.
El hombre que tiene amigos debe mostrarse amigo...
|
|
|
|
|
I’ve continued working on my code, it’s now thus:
public static bool Hay_PostBack(System.Web.UI.Page parent1, string w1,
string w1cx,
string w1ID,
string w2,
string w2cx,
string w2ID)
{
WUC_CreDes.WebForm1 frm1;
WUC_CreDes.WebForm2 frm2;
string fofoi = parent1.GetType().ToString();
if(fofoi == "ASP.WebForm1_aspx")
{
frm1 = (WUC_CreDes.WebForm1) parent1;
frm1.parent1.Example.Controls.Clear();
}
}
Yet in last line: frm1.parent1.Example.Controls.Clear();
It’s giving me error: WUC_CreDes.WebForm1' doesn’t contains a definition to 'parent1'.
Example is a place holder contening both in WebForm1 and in WebForm2.
I’ll thank your help.
A.L.
El hombre que tiene amigos debe mostrarse amigo...
|
|
|
|
|
Finally I found the solution:
To call function:
bool que = WUC_CreDes.Class1.Hay_PostBack(this, w1,w1cx, w1ID, w2, w2cx, w2ID);
The function:
public static bool Hay_PostBack(System.Web.UI.Page parent1, string w1,
string w1cx,
string w1ID,
string w2,
string w2cx,
string w2ID)
{
WUC_CreDes.WebForm1 frm1;
WUC_CreDes.WebForm2 frm2;
string cual = "";
cual = HttpContext.Current.Session["par1"].ToString();
string fofoi = parent1.GetType().ToString();
if(fofoi == "ASP.WebForm1_aspx")
{
frm1 = (WUC_CreDes.WebForm1) parent1;
frm1.Example.Controls.Clear();
if(cual == w1)
{
Control control = frm1.Page.LoadControl(w1cx);
control.ID = w1ID;
frm1.Example.Controls.Add(control);
}
else
{
Control control = frm1.Page.LoadControl(w2cx);
control.ID = w2ID;
frm1.Example.Controls.Add(control);
}
}
else
{
if(fofoi == "ASP.WebForm2_aspx")
{
frm2 = (WUC_CreDes.WebForm2) parent1;
frm2.Example.Controls.Clear();
if(cual == w1)
{
Control control = frm2.Page.LoadControl(w1cx);
control.ID = w1ID;
frm2.Example.Controls.Add(control);
}
else
{
Control control = frm2.Page.LoadControl(w2cx);
control.ID = w2ID;
frm2.Example.Controls.Add(control);
}
}
}
return false;
}
Greetings.
A.L.
El hombre que tiene amigos debe mostrarse amigo...
|
|
|
|
|
Hello all,
I have an application which runs as a windows service. When it starts up it processes a number of interfaces and sets up a timer for each of the interfaces using System.Timers timers.
If two interfaces are scheduled to run at exactly the same time the OnTimedEvent() method only gets called for one of the interfaces. If the interfaces are scheduled to run at different times everything runs fine.
As a test I knocked together a quick and dirty app using Threading.Timers and these work fine. However to re-write the service to use them would be a last resort. Also the .NET documentation recommends using the System.Timers when writing server apps etc
Does anybody know what I may be doing wrong? Or has anybody experienced a problem like this before, so I can at least tell my boss it is a known problem
Thanks
Simon
|
|
|
|
|
Try locking your method so only 1 thread can access it at any given time:
private void myTimerEvent(object sender, EventArgs e)
{
lock(this)
{
...
}
}
|
|
|
|
|
|
When a window form is working, I would like to show a small form just to tell users "Please wait...", but it seems that when the main form is working, the small form can not appear correctly. How to solve this?
|
|
|
|
|
Use a thread to display the child form
Have a wonderful evening
Doug Wright
Developer, TDCI
|
|
|
|
|
Can you teach me a little about this? I am not sure I know much of threading
|
|
|
|
|
Threading is a sure solution. But if it is possible to solve things in other way then avoid threading. Immediately before your "heavy" processing starts launch the new form and give a Application.DoEvents (In C#) This should solve your problem, or else you can go for a thread.
|
|
|
|
|
Hi all,
Anyone knows how to use pivot table in .net(c#)
It works well in vb but it is not working in .net .
since i am new to this type of concepts .Help me
Prabhakar.A
Software Engineer
|
|
|
|
|
Let’s say we have a product table where each row represents product details like product Id, Name, Description , Price etc.
Now customer might be interested to view products across (i.e. columns) and features down (row wise). This basically requires transposing product table’s rows and columns as illustrated below.
The first step is to create the new Data Table and its schema from the rows of the input table. In the following code snippet, source refers to the input table and dest is the new pivoted table.
//Create Destination Table
DataTable dest = new DataTable("Pivot" );
// from each source table row (1st column)
// create a destination column
foreach( DataRow r in source.Rows )
dest.Columns.Add( r[0].ToString() );
// assign each row the Product name Now that we have the appropriate columns defined
in the schema of the destination table, the next step is to create a DataRow for each feature defined in the columns of the source table, excluding the first column representing the Product name.
//Create columns in destination table for each row in source table.
for( int i = 0; i < source.Columns.Count - 1; i++ )
dest.Rows.Add( dest.NewRow() );
The final step is the actual transform of the columns from the source rows into the destination table. Since each table now represents a two dimensional array of its rows and columns, a very simple transform of all columns and rows could be performed by the following nested for loop.
//Transpose rows and columns
for( int r = 0; r < dest.Rows.Count; r++ )
for( int c = 0; c < source.Columns.Count; c++ )
dest.Rows[r][c] = source.Rows[c][r];
Ravindra Sadaphule
MCSD.NET
|
|
|
|
|