|
Is it possible (C# programatically) to see if the current user is an administrator-level user?
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
|
|
I have to sheepishly admit that it was a nefarious idea that created this question. However, if it was possible (the second and unspoken half of my nefarious idea), it would be commonly exploited. Don't worry, I'm not going to try it (my job might be at risk for thinking about doing what I thought about).
Thank you for the links!
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
Hi,
Could you please assist in using transaction in the following scenario?
In the datalayer the system loops through the records of a dataset, identifies the changes and then applies the necessary stored procedures for update, delete, insert.
i.e.
dataset data;
foreach record in data
if record is modified then call update stored procedure with the appropriate ID
if record is added then call insert stored procedure with the appropriate details
if record is deleted then call delete stored procedure with the appropriate ID
A sample code for an action query is below: Notice that this is the kind of action for each record as explained above.
The question is where to put the transaction please?
public void EmployeeDetailsDelete(int intEmployeeID)
{
string strSQL = "usp_EmployeeDetailsDelete";
string strConn = GetConnectionString;
using(SqlConnection oCon = new SqlConnection(strConn))
{
SqlCommand oCmd = new SqlCommand(strSQL, oCon);
oCmd.CommandType = CommandType.StoredProcedure;
oCmd.Parameters.Add("@EmployeeID", SqlDbType.Int, 4);
oCmd.Parameters["@EmployeeID"].Value = intEmployeeID;
oCon.Open();
oCmd.ExecuteNonQuery();
}
}
|
|
|
|
|
Smells like homework but here goes
SqlDataAdapter da = new SqlDataAdapter()<br />
<br />
da.SelectCommand = ...<br />
da.InsertCommand = ...<br />
da.DeleteCommand = ...<br />
da.UpdateCommand = ...<br />
<br />
DataSet ds = new DataSet();<br />
da.Fill(ds);<br />
<br />
Make modifications to data<br />
<br />
using(TransactionScope scope = new TransactionScope())<br />
{<br />
da.Update(ds.GetChanges());<br />
}
only two letters away from being an asset
|
|
|
|
|
Hello everyone, I have a question related to a program I am writing. The problem occurs when I am trying to read in a timestamp from a .gpl file and store it as a DateTime. The code I am currently using is:
long FileTime;
uint time;
time = BN.ReadUInt32();
FileTime = 10000000 * (long)time + 116444736000000000;
DateTime dt = new DateTime(FileTime);
BN is a BinaryReader.
All portions appear correct except for the year which prints as 406 instead of 2006.
Does anyone have any suggestions as to what may be causing this?? Thank you.
|
|
|
|
|
Are you sure that the date in the gpl file is stored as an offset from the first of january in the year 370?
---
b { font-weight: normal; }
|
|
|
|
|
I have a asp 3.0 application that needs some hard labor to be done. And I'm thinking to send some information in parameters and call a program in the file system to do the hard labor from the page. Of course this outside program i want to make it in C#. Now what I'm pondering is in production the program is going to be called by multiple users and probably in very narrow time intervals, what will happen if a prior call to the program hasn't finished what will happen?.
I've never encounter this problem before, and i'm thinking how could i do the program to be able to run to any number of calls and just work in different processes. If I'm writing gibberish please let me know. Or if am correct i need some help.
Thank you for your time.
Sincerely RickyRicon
|
|
|
|
|
Hi,
If the paricular operation that is going to be called by multiple users , is going to execute fast, use locking mechanisms available in the system.threading namespace, locking will automatically put all calls in a queue and cater to each request, if that is not enough, you can go with hosting multiple remote objects of the same class (with locking in place) and use handcrafted load balancing and sharing mechanish, this should not be a big problem at all,
Live and let live
|
|
|
|
|
I need source code for using System.Drawing.Printing for making Print and PrintPreviw for image displayed in picture box
thanks,
|
|
|
|
|
i need the algorithm for the a program that can gives a the shortest path between two spacific points and you are given the distance between every two points
|
|
|
|
|
nightmare_112 wrote: i need the algorithm for the a program that can gives a the shortest path between two spacific points
Maybe you need a new major. (Okay, I know that was mean...but I couldn't resist.)
See here:
wiki Shortest Path[^]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
You need google ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
What's the shortest path to to Google?
only two letters away from being an asset
|
|
|
|
|
|
It's not a question.
If you have a complete set of distances (edges) between every two of all points then the shortest way between two given points will be line segment that connects these two points.
If you mean one of typical graph problems then try reading this article.
|
|
|
|
|
dead_link wrote: If you have a complete set of distances (edges) between every two of all points then the shortest way between two given points will be line segment that connects these two points.
Not neccesarily. Your statement also requires the triangle inequality to hold true.
AB 1
BC 1
AC 10
The shortest path from A to C is AB-BC, not AC.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
Correct me if I'm wrong, but those segments (AB, BC, and AC) cannot be a triangle (the length of one side HAS to be less than the sum of the lengths of the other two sides).
If I'm misunderstanding the discussion, it wouldn't be a first time, so just tell me, "That's not what we're talking about," and I'll back out gracefully. Just thought I'd throw in two cents.
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
You're completely correct, on a flat surface the segments don't make a triangle. The triangle inequality states that for any A, B, and C that AB + BC > AC. Dead_link's answer implictly assumed that the inequality was in place, but the OP never made it an actual condition of his problem.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
Oh, yes. I know it. But the word "distance" lets me think about points on a surface and about simple geometric task.
|
|
|
|
|
I want my application to behave like MSWord 2003. i.e. Multiple-SDI Application.
I am facing problem with the code that first window always close all other windows. Please identify changes.
<br />
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.IO;<br />
<br />
<br />
namespace MultipleSDI<br />
{<br />
public partial class TopLevelForm : Form<br />
{<br />
<br />
string fileName;<br />
static int formCount = 0;<br />
<br />
public TopLevelForm()<br />
{<br />
InitializeComponent();<br />
<br />
MultiSDIApplication.Application.AddTopLevelForm(this);<br />
MultiSDIApplication.Application.AddWindowMenu(this.windowToolStripMenuItem);<br />
<br />
<br />
++formCount;<br />
this.Text += ": " + formCount.ToString();<br />
}<br />
<br />
<br />
public static TopLevelForm CreateTopLevelWindow(string fileName) <br />
{<br />
<br />
if (!string.IsNullOrEmpty(fileName))<br />
{<br />
foreach (TopLevelForm openForm in Application.OpenForms)<br />
{<br />
if (string.Compare(openForm.FileName, fileName, true) == 0)<br />
{<br />
openForm.Activate();<br />
return openForm;<br />
}<br />
}<br />
}<br />
<br />
TopLevelForm form = new TopLevelForm();<br />
form.OpenFile(fileName);<br />
form.Show();<br />
<br />
form.Activate();<br />
return form;<br />
<br />
}<br />
<br />
private void openToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
if (this.openFileDialog.ShowDialog() == DialogResult.OK)<br />
{<br />
TopLevelForm.CreateTopLevelWindow(this.openFileDialog.FileName);<br />
}<br />
<br />
}<br />
<br />
void OpenFile(string fileName)<br />
{<br />
this.fileName = fileName;<br />
if (!string.IsNullOrEmpty(fileName))<br />
{<br />
using (StreamReader reader = new StreamReader(fileName))<br />
{<br />
textBox.Text = reader.ReadToEnd();<br />
}<br />
}<br />
else this.fileName = "untitled" + formCount.ToString();<br />
this.Text = this.Text + " (" + this.fileName + ")";<br />
}<br />
<br />
string FileName<br />
{<br />
get { return this.fileName; }<br />
}<br />
<br />
private void newToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
TopLevelForm.CreateTopLevelWindow(null);<br />
}<br />
<br />
<br />
<br />
}<br />
}<br />
<br />
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using Microsoft.VisualBasic.ApplicationServices;<br />
using System.Collections.ObjectModel;<br />
<br />
<br />
<br />
namespace MultipleSDI<br />
{<br />
class MultiSDIApplication : WindowsFormsApplicationBase<br />
{<br />
<br />
static MultiSDIApplication application;<br />
internal static MultiSDIApplication Application<br />
{<br />
get<br />
{<br />
if (application == null)<br />
{<br />
application = new MultiSDIApplication();<br />
}<br />
return application;<br />
}<br />
}<br />
<br />
public MultiSDIApplication()<br />
{<br />
<br />
<br />
<br />
this.IsSingleInstance = true;<br />
<br />
<br />
this.ShutdownStyle = ShutdownMode.AfterAllFormsClose;
<br />
<br />
}<br />
<br />
protected override void OnCreateMainForm()<br />
{<br />
this.MainForm = this.CreateTopLevelWindow(this.CommandLineArgs);<br />
}<br />
<br />
TopLevelForm CreateTopLevelWindow(ReadOnlyCollection<string> args)<br />
{<br />
<br />
string fileName = (args.Count > 0 ? args[0] : null);<br />
<br />
return TopLevelForm.CreateTopLevelWindow(fileName);<br />
}<br />
<br />
protected override void OnStartupNextInstance(StartupNextInstanceEventArgs e)<br />
{<br />
this.CreateTopLevelWindow(e.CommandLine);<br />
}<br />
<br />
public void AddTopLevelForm(Form form)<br />
{<br />
<br />
form.Activated += Form_Activated;<br />
form.FormClosed += Form_FormClosed;<br />
<br />
if (this.OpenForms.Count == 1) this.MainForm = form;<br />
}<br />
<br />
void Form_Activated(object sender, EventArgs e) <br />
{<br />
this.MainForm = (Form)sender;<br />
}<br />
<br />
void Form_FormClosed(object sender, FormClosedEventArgs e) <br />
{<br />
if( ((Form)sender == this.MainForm) && (this.OpenForms.Count > 0) ) <br />
{<br />
MessageBox.Show("I reached here" + this.OpenForms.Count.ToString());<br />
this.MainForm = (Form)this.OpenForms[0];<br />
}<br />
<br />
MainForm.Activated -= Form_Activated;<br />
MainForm.FormClosed -= Form_FormClosed;<br />
}<br />
<br />
public void AddWindowMenu(ToolStripMenuItem windowMenu) <br />
{<br />
windowMenu.DropDownOpening += windowMenu_DropDownOpening;<br />
}<br />
<br />
<br />
void windowMenu_DropDownOpening(object sender, EventArgs e) <br />
{<br />
ToolStripMenuItem menu = (ToolStripMenuItem)sender;<br />
<br />
if( menu.DropDownItems.Count > 0 ) <br />
{<br />
menu.DropDown.Dispose();<br />
}<br />
<br />
menu.DropDown = new ToolStripDropDown();<br />
<br />
foreach( Form form in this.OpenForms ) <br />
{<br />
ToolStripMenuItem item = new ToolStripMenuItem();<br />
item.Text = form.Text;<br />
item.Tag = form;<br />
menu.DropDownItems.Add(item);<br />
item.Click += WindowMenuItem_Click;<br />
<br />
if( form == this.MainForm ) item.Checked = true;<br />
}<br />
}<br />
<br />
void WindowMenuItem_Click(object sender, EventArgs e)<br />
{<br />
((Form)((ToolStripMenuItem)sender).Tag).Activate();<br />
}<br />
<br />
<br />
<br />
}<br />
}<br />
<br />
<br />
<br />
|
|
|
|
|
First of all, putting large amounts of code in a post is not a good idea, since few people will take the time to check it out. And if you don't explain what's going on, it is hard to understand at first glance.
But here is an idea: maybe your message loop is running on your first window, so when it is closed the message loop returns and the app is closed. I would create an invisible window, run the message loop on it, and when the last window is closed, kill that window. You can also use that hidden window to get a list of all windows (for the Window menu, for example).
I hope this helps.
|
|
|
|
|
Is there a way to use reflection to get the variable name that a method is called on ?
For instance ...
<br />
class foo {<br />
public override string ToString() {<br />
return GetType().toString() + " " + GetType().??? VaraibleName ???;<br />
}<br />
}<br />
<br />
.<br />
.<br />
.<br />
<br />
foo myFoo = new foo();<br />
Console.WriteLine( myFoo.toString());<br />
Should ouput
foo myFoo
|
|
|
|
|
I wouldn't expect you could because variable names are stored only in your code, once you've compiled they go away. You could tell things like class name, etc., but not variable name.
|
|
|
|