|
Or create an interface that includes all the others and try to cast to that?
|
|
|
|
|
I have the usual layers UI, objects, DAL and SQL Server.
In VB I instantiate the DAL in the object layer using a friend variable in a module. This allows me to use the DAL in any class in the object layer without exposing the DAL to the UI. DAL stays alive as long as the app is in process.
Now C# does not have the module concept and I do not want to pass the DAL to the UI to pass to each class in the object layer. I assume it is done with a static class but I am struggling to get it just right.
[edit] What you can do is to create a public static variable on a class and use it like...
The only problem is static classes cannot have constructors, so can I declare the static class, pass values to a method that instantiates the static DAL? Then use the static DAL var in the other classes
[/edit]
Never underestimate the power of human stupidity
RAH
modified on Tuesday, July 29, 2008 2:17 AM
|
|
|
|
|
I guess C# equivalent for friend is internal .
Mycroft Holmes wrote: Now C# does not have the module concept and I do not want to pass the DAL to the UI to pass to each class in the object layer
So multiple classes in the object layer shares a same DAL ? Your question is not clear. Posting some code would be helpful.
|
|
|
|
|
Thanks - I got it.
Declare a static class (clsMain) in the object layer with a static method to accept the credentails. Static method instantiates the DAL (gDBO) as internal using the creds.
ORM classes get at the at the DAL by using the clsMain.gDBO.????. Untested yet but it compiles
public static class clsMain
{
internal static dbOps.clsDBOps gDBO;
public static void SetCredentials(Credentials oCreds)
{
dbOps.Credentials _Creds = new dbOps.Credentials();
_Creds.Server = oCreds.Server;
_Creds.Database = oCreds.Database;
_Creds.UserID = oCreds.UserID;
_Creds.Password = oCreds.Password;
gDBO = new dbOps.clsDBOps(_Creds);
}
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You can also use static constructors in c#.
public class foo { static foo() { init stuff; }}
|
|
|
|
|
Hi All,
I have one class derived from ContentControl.
And inside it's content I have ImageSource and a TextBlock, I want to bind the Text property of TextBlock to the Name proeprty of an object but it's not working.Below is the code snippet:
public void AddBitmapToCanvas(System.Drawing.Bitmap bitmap, string pageName,int width,int height,HorizonPage hpage)
{
Binding txtBinding=new Binding("Name");
txtBinding.Source=hpage;
try
{
_pageImage = new PageImage {PageName = pageName};
content = new StringBuilder();
content.Append("<StackPanel xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" Height=\"");
content.Append(_pageImage.Height);
content.AppendFormat("\" Width=\"");
content.Append(_pageImage.Width);
content.Append("\"><Image Source=\"\" Height=\"");
content.Append(height);
content.Append("\" Width=\"");
content.Append(_pageImage.Width);
content.Append("\"></Image><TextBlock Text=\"\" TextAlignment=\"Left\" Height=\"");
content.Append(_textBlockHeight);
content.Append("\" Width=\"");
content.Append(_pageImage.Width);
content.Append("\" Foreground=\"Black\"></TextBlock></StackPanel> ");
ui = (UIElement)XamlReader.Load(xmlReader);
//Setting Image Source property
((Image)((StackPanel)ui).Children[0]).Source = WpfBitmap;
//Setting TextBlock Text property
((TextBlock)((StackPanel)ui).Children[1]).Text = pageName;
((TextBlock)((StackPanel)ui).Children[1]).SetBinding(TextBlock.TextProperty,txtBinding);
_pageImage.Content = ui;
}
}
Any help will be much appreciated..
Praveen Sharma
|
|
|
|
|
Hello,
How is it possible to determine which operating system is in use on the computer? XP Home or Professional or Vista Basic/Home Premium/Business etc.
Similarly, how is it possible to determine which version of office is installed Home and Student, Professional, Ultimate etc..
Thanks
|
|
|
|
|
|
That shows you the version numbers but i cannot find how to locate or determine whether it is home or professional for xp or any of the different versions for vista.
That class doesn't contain any other specifics.
|
|
|
|
|
|
Hi,
I saw an MSDN web page on the subject; it waw terribly complex, checking lots of things, and
switching; I did not note the link.
And then there is the registry key
@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName"
which is good enough for me.
|
|
|
|
|
Hi All,
Can someone give me some hint on how to generate web services code from C# CodeDom?
most appreciated.
Andie
|
|
|
|
|
Did you check out this?
http://www.codeplex.com/wsstudioexpress[^]
It demonstrates dynamic proxy generation and similar stuff. It is actually a tool which you can use to interact with any webservice.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
All the world's a stage,
And all the men and women merely players.
They have their exits and their entrances;
And one man in his time plays many parts... --William Shakespeare
|
|
|
|
|
Hi Kumar,
Thanks very much for your follow up. But i am actually after by using CodeDom to generate the c# web service code dynamically by looking for the DataAdapter structure in the .dll files.
Anyway, still appreciate your follow up.
Andie
|
|
|
|
|
Hi,
I can get data from SQL to datagridview, textbox and combobox objects.
I can edit or view any data from or to database with the above objects!!!
But not to StatusStrip, at least not directly!!!
I get the data from sql to other object, and then pass it to statusstrip.
Is there a direct way? like the other object. statusstrip doesn´t has a datasource
|
|
|
|
|
|
Spamming the whole site is a good way to convince us that you have no idea what it means to be professional, which is not a good way to get people to respond to your job ad.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Yes, you are right. I'm very sorry. I deleted both my messages in this and the lounge. My bad.
|
|
|
|
|
What was the message this person posted? Saw it all over in the Lounge?
Christian Graus wrote: job ad
Isn't that what the Job board is for?
---modified
Never mind, saw it in the Job Board. Sounds too good to be true.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi, I am very new to C# but I am modifying an image buffer directly within memory, I am scanning along moving the pointer to get the RGB of each pixel, but I need away to jump around the image memory and read the pixels at random rather than just p++ or p--?
Thanks...
unsafe
{
byte* p = (byte*)(void*)pBuffer;
for(int y = 0; y < Height; y++)
{
for(int x = 0; x < Width; x++)
{
int srcB = p[0];
p++;
int srcG = p[0];
p++;
int srcR = p[0];
p++;
}
}
}
|
|
|
|
|
Hi,
inside an unsafe block you can use pointers and jump around as you wish, provided you tell
the compiler to let you do that. What is the specific problem?
|
|
|
|
|
Hi, the problem is I have only used Blitz Basic before and I could jump to a pixel, eg GetColor(129,280)"Width,Height", with pointers I have to scan along the image for the data, I dont know how to jump to the pixel data I want?
|
|
|
|
|
Hi,
you can perform calculations with pointer values: every time you add one you move to the next
element of that type (same as in C or C++).
Guffa's answer below gives you a detailed example for bitmapped images.
|
|
|
|
|
For a 24 bit bitmap, the location of a pixel can be calculated with:
scan0 + y * scan + x * 3
(Note that for a bitmap that is stored upside down, which is the common way, scan0 points to the last line, and scan is a negative value.)
Your code for looping the image is incomplete. The lines might not be stored end-to-end in memory, you have to skip any extra bytes between the lines (calculated by scan - x * 3 ). Also, if the bitmap is stored upside down, you will either get the data upside down, or only getting garbage after the first line read.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
How do i explicitly free byte array?
|
|
|
|