Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Digital Disease
Jan 8, 2005

by Fragmaster
I know this could be done better if I was using arrays, but currently I'm trying not to re-write too much code that currently exists.

Is it possible to create a string that holds the variable name then uses that string to reference the variable in a parse. Here's the idea, I just don't know how to implement it correct if it's even possible.

code:
            for (int i = 1; i < 12; i++)
            {
                makeRegHrString = ("this.regHr" + i + ".Text");
                makeOTHrString = ("this.OTHrs" + i + ".Text");
                monRegHr = monRegHr + double.Parse(makeRegHrString);
                monOTHr = monOTHr + double.Parse(makeOTHrString);
            }
This idea is simply to go through the list of Text fields and grab the data and add it up together, I'm trying to avoid having to do this for each day of the week.

code:
monRegHr = monRegHr + double.Parse(this.regHr1.Text)
monRegHr = monRegHr + double.Parse(this.regHr2.Text)
...

Adbot
ADBOT LOVES YOU

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:
Is there any way to process a WebResponse's headers for HTTP headers, without making use of HttpWebRequest/Response objects?

Alternatively, is there any way to still use a HttpWebResponse object, even though the response isn't valid HTTP? As far as I can see it immediately throws up a ProtocolViolationException and closes the connection.

Basically I want all the advantages of using a HttpWebRequest/Response, while still being able to make use of it if the response isn't valid HTTP.

genki
Nov 12, 2003

Mecha posted:

Is there some voodoo to handling drag-n-drop that I'm not seeing? I've tried setting virtually every control in my main form(and even the form itself for grins) to allow drops, and tried handling _DragEnter and _DragDrop in several controls, but none of them ever change the cursor nor allow the drop. I've looked through several tutorials which all say that this should be all you need, but for some reason it won't work at all. :(
Ah, drag'n'drop. What hell.

Here's the basic outline for the code I created to do drag-drop to a listview. Obviously, you have to set allowdrop for the listview for this code to work.
code:
        private void listView1_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(ArrayList)) == true)
            {
                e.Effect = DragDropEffects.Move;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
            listView1.Items[0].Selected = true;
        }

        private void listView1_DragDrop(object sender, DragEventArgs e)
        {
            SuspendLayout();

            try
            {
                Point lv = listView1.PointToClient(new Point(e.X, e.Y));
                ListViewItem startItem = listView1.HitTest(lv).Item;
                if (startItem != null)
                {
                    IList dropped = (IList)e.Data.GetData(typeof(ArrayList));
                    int index = startItem.Index;
                    // etc
That should allow you to drag-drop an arraylist of data from whatever source you have. Hmmm, maybe I should put in that code to.
code:
        private void listView2_ItemDrag(object sender, ItemDragEventArgs e)
        {
            ArrayList al = new ArrayList(listView2.SelectedItems);
            DoDragDrop(al, DragDropEffects.Move);
        }
There, that should provide all the code you need to handle multi-item drag/drop from one listview to another.

I also have some crap in DragOver for the receiving listview to highlight the current item you're hovering over, but that's left for an exercise for the reader, haha.

Anyhow, mostly I post this because it took me ages to figure out the mechanics of drag/drop too. I don't know why, but none of the online tutorials seemed straightforward enough to really pick up the required code. Or maybe I'm just slow.

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.

Fastbreak posted:

Awesome, thanks for giving me direction. You wouldn't happen to want to just toss me the function you wrote to get all that would you and save a brother a whole bunch of time? :)
Sorted via PMs but here's what was said, in case anyone else is interested:

Inquisitus posted:

Well there is more than one static method used to get the windows (and many imported functions). They're all in a single file along with a load of other stuff that my app uses to capture screenshots.

Here's the file in question:
http://etherea.co.uk/stuff/files/Interop.cs

I'm afraid there are about 800 lines, but you should be able to work out what's relevant from the comments and function names. You can ignore everything in lines 152-415 and 826-879.

I also use a separate class called WindowInfo to encapsulate information about each window, whose source can be found here:
http://etherea.co.uk/stuff/files/WindowInfo.cs

Enjoy!

Inquisitus fucked around with this message at 19:37 on Aug 15, 2007

Mecha
Dec 20, 2003

「チェンジ ゲッタ-1! スイッチ オン!」

genki posted:

Anyhow, mostly I post this because it took me ages to figure out the mechanics of drag/drop too. I don't know why, but none of the online tutorials seemed straightforward enough to really pick up the required code. Or maybe I'm just slow.

Actually, I figured it out last night--defining your event handlers in the Events tab will help with actually firing the events off. :doh:

Of course, now I'm struggling with actually getting the app to run on the client's machine. :cry:

uXs
May 3, 2005

Mark it zero!
I have several gridviews (asp.net) where I need to be able to hide the column with the "delete" button, depending on who is using the app.

Right now I'm using this code:

this.gridview.Columns[3].Visible = true;

I'm really bothered by having to use the column number, it's bound to cause problems down the line when someone adds a column somewhere and suddenly a whole bunch of users can now push the delete button. (I'm probably going to intercept the delete event and do an explicit check to avoid un-authorized deletes, but I still don't like it.)

Is there a way to indicate the column to hide with its name or something ?

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!
Judging from MSDN there does not exist an easy way to do that.

rckgrdn
Apr 26, 2002

So that's how it's made...

Digital Disease posted:

This idea is simply to go through the list of Text fields and grab the data and add it up together, I'm trying to avoid having to do this for each day of the week.
You can do it via Reflection in something like this (untested rough code ahead!):
code:
Type t = this.GetType();
for (int i = 1; i < 12; i++)
{
    System.Reflection.FieldInfo fi = t.GetField(String.Format("regHr{0}", i));
    TextBox tb = (TextBox)fi.GetValue(this);
    monRegHr += double.Parse(tb.Text);
}
Alternatively, if the controls you're trying to get the values out of are contained within something (which they have to be, logically) then you can iterate through the controls in the containing object and check the name to see if it matches the pattern you're looking for. Like this (again, horribly rough code ahead, but it'll give you an idea):
code:
foreach(Control c in containerControl)
{
    if(Regex.IsMatch(c.ID, "regHr\d+"))
    {
        monRegHr += double.Parse(((TextBox)c).Text);
    }
}
You might need to recurse deeper into the control structure if there are sub-containers like table rows/cells though...

Digital Disease
Jan 8, 2005

by Fragmaster

thestoreroom posted:

You can do it via Reflection in something like this (untested rough code ahead!):
code:
Type t = this.GetType();
for (int i = 1; i < 12; i++)
{
    System.Reflection.FieldInfo fi = t.GetField(String.Format("regHr{0}", i));
    TextBox tb = (TextBox)fi.GetValue(this);
    monRegHr += double.Parse(tb.Text);
}
Alternatively, if the controls you're trying to get the values out of are contained within something (which they have to be, logically) then you can iterate through the controls in the containing object and check the name to see if it matches the pattern you're looking for. Like this (again, horribly rough code ahead, but it'll give you an idea):
code:
foreach(Control c in containerControl)
{
    if(Regex.IsMatch(c.ID, "regHr\d+"))
    {
        monRegHr += double.Parse(((TextBox)c).Text);
    }
}
You might need to recurse deeper into the control structure if there are sub-containers like table rows/cells though...

Awesome, thanks! Now to do more reading on reflections. It really does help to have the correct terms to search for.

wwb
Aug 17, 2004

Reflection is very, very expensive.

Have you considered making it a template column and databinding the enabled property of the button based on your business logic? This way it can travel with the button rather than having to worry about column order dependency.

SLOSifl
Aug 10, 2002


wwb posted:

Reflection is very, very expensive.
I have an entire program that's basically built using reflection. It performs very well. Reflection *is* expensive, yes, but unless you're talking about using a lot of it in a tight, time-critical loop, there's probably not much reason to worry. It's also extremely powerful, and can make some seemingly complex things very intuitive, especially when combined with meta-data like attributes or backing databases/metabases.

Inquisitus
Aug 4, 2006

I have a large barge with a radio antenna on it.
Is there any way of filling a PropertyGrid with your own properties/values defined at run time? (As opposed to giving it an object and letting it enumerate all of its properties.)

Richard Noggin
Jun 6, 2005
Redneck By Default

Inquisitus posted:

Is there any way of filling a PropertyGrid with your own properties/values defined at run time? (As opposed to giving it an object and letting it enumerate all of its properties.)

Something like this perhaps?

wwb
Aug 17, 2004

Ran into a bit if a mystery today, wonder if anyone here has seen it. I am trying to connect one of our old (.NET 1.1) web applications to our newer (.NET 2.0) CRM system's web services. Should be simple--just setup the proxy and go--right?

Well, no, it is not. For some reason, .NET 1.1's proxy generation creates a valid proxy, but it has two big issues:

1) It ignores changes to the Dynamic Url property. When I change the proxy to be dynamic, according to visual studio, the generated class keeps the hardcoded url. I suspect this is more a symptom of VS2003 making GBS threads itself.
2) When I send a request out on the proxy, it does not carry any data--the payload is null by the time the service gets to deserialize things. I am absolutely certain that the payload is not null when the proxy is invoked.

I suspect the issue has something to do with the nature of the service, which is a class that implements two separate interfaces and comes up with two separate service classes.

Anyhow, anyone see anything like this or have any ideas why this is blowing up?

wwb
Aug 17, 2004

SLOSifl posted:

I have an entire program that's basically built using reflection. It performs very well. Reflection *is* expensive, yes, but unless you're talking about using a lot of it in a tight, time-critical loop, there's probably not much reason to worry. It's also extremely powerful, and can make some seemingly complex things very intuitive, especially when combined with meta-data like attributes or backing databases/metabases.

I probably overstated my one-liner a bit. That said, I think that it is not a good solution for this scenario mainly because it is so far beyond the typical asp.net web application pale that the poor souls maintaining this would have more trouble handling that code than dealing with a hardcoded column name.

Darth Continent
Dec 13, 2004

I sense a
disturbance
in my bowels...
Has anyone found an autocomplete textbox or dropdown control for ASP .NET which can use SQL as a datasource, but which doesn't need to use a webservice?

Or is it beneficial to use a webservice to handle the asynchronous requests from the textbox? My first impression is that having the webservice is both extra overhead and extra code to have to manage; why not just wrap the database code into the code-behind of the .aspx page?

wwb
Aug 17, 2004

Well, the issue is that you need to expose that SQL over http, and most of the boxed controls use a web service because it is the easiest way to factor out external http requests in .NET and that is the way AJAX.NET wants to work.

Insofar as extra code goes, I would argue that the logic behind the lookup should be encapsulated in your object layer rather than floating loose in the web service, so the only extra maintenence is creating the web service to wrap the method.

Finally, I *think* you can skip having a separate service by using Ajax PageMethods rather than a separate ASMX.

SLOSifl
Aug 10, 2002


Darth Continent posted:

Has anyone found an autocomplete textbox or dropdown control for ASP .NET which can use SQL as a datasource, but which doesn't need to use a webservice?

Or is it beneficial to use a webservice to handle the asynchronous requests from the textbox? My first impression is that having the webservice is both extra overhead and extra code to have to manage; why not just wrap the database code into the code-behind of the .aspx page?
It's not like it's a ton of code to deal with a webservice, but I can see where you're coming from.

Look into SQL Endpoints. They are literally webservices hosted in SQL Server.

edit: They can be a little tricky to set up initially, since the syntax is a bit weird, but you can basically say "host this stored procedure as a webservice called whatever" and that's it.

Darth Continent
Dec 13, 2004

I sense a
disturbance
in my bowels...
Thanks for the info. :D

JediGandalf
Sep 3, 2004

I have just the top prospect YOU are looking for. Whaddya say, boss? What will it take for ME to get YOU to give up your outfielders?
I'm kind of having a difficult time understanding DLINQ queries. Not so much the queries themselves but how they pull from the database. I also want to get people's opinion on "LINQ to SQL" on how good it is or scalable it is.

Suppose that I have two tables, tblStore, tblApple. There's a foreign key to tblStore in tblApple (one store has many apples). Now I discovered that when I set up a LINQ to SQL, it will create an object back to the parent table.

My question:
code:
//tblApple has fkStoreId, a foreign key to tblStore
var query = from a in tblApples
		where a.kind == "Red Delicious"
		select a;

foreach (var v in query)
{
	DoSomething(v.tblStore);   //If I do not call v.tblStore anywhere, is it still populated?
}
This make any sense?

Dromio
Oct 16, 2002
Sleeper
I'm trying to find a way in ASP.NET to use Windows Authentication AND the Active Directory membership provider together. Windows Authentication provides the username in a format "DOMAIN\username", but the membership provider doesn't seem to like this -- if I try to lookup a user I have to do something like Membership.GetAllUsers()["username@domainname.com"].

Has anyone tried to do something like this? I really need the membership provider to be able to get email addresses and stuff, but really don't want to have to do forms authentication.

uXs
May 3, 2005

Mark it zero!
For an ASP.NET app, I have the session start event retrieve user information, assign permissions to a User object, and store it in the session state.

To check what permissions someone should have, there are several Active Directory groups someone could be in. So I query the AD, and put the groups the user is a member of in a collection. Then, I need to check if the user is in group A and assign according permissions, check for group B and assign permissions, and so on.

The question is: what kind of collection do I put the groups in ? A StringCollection seems obvious, but is that fast enough ? Wouldn't a hashtable or something be better ? Or am I worrying too much again about irrelevant issues that aren't issues at all ?

wwb
Aug 17, 2004

Probably worrying too much unless you have thousands of groups to check.

I would, however, look at making your user object implement IPrincipal and push said user into the Context.User property. That way you can rely on .NET's builtin security features to handle stuff. Such as using PrincipalPermissionAttribute on methods.

ahawks
Jul 12, 2004
I know this isn't a coding question, but it still seems on topic.

Can anyone recommend an affordable web host for ASP.NET 2? Dreamhost doesn't support it, goddady.com does, but I've heard bad things about their hosting.

I am looking for something affordable, as my primary use will be a personal website to promote my photography.

fez2
Jan 24, 2002

This is a really stupid .NET question, but google can't seem to help me.

I'd like to add a warning to one of my methods so I know it's depcreciated so when I build it on older projects I'll remember that the method is older.

I still want to be able to build them, so it has to be a warning and I'd like it to appear in the usual debugging place. Does anyone know how to throw your own warning message?

csammis
Aug 26, 2003

Mental Institution

fez2 posted:

This is a really stupid .NET question, but google can't seem to help me.

I'd like to add a warning to one of my methods so I know it's depcreciated so when I build it on older projects I'll remember that the method is older.

I still want to be able to build them, so it has to be a warning and I'd like it to appear in the usual debugging place. Does anyone know how to throw your own warning message?

First, the spelling is "deprecated" which might help :)

Second, you want the Obsolete attribute.

edit: Don't feel bad about the spelling, I pronounced "deprecated" "depreciated" (as in 'fell in value') for a long time and was very confused when someone pointed out the error

havelock
Jan 20, 2004

IGNORE ME
Soiled Meat

ahawks posted:

I know this isn't a coding question, but it still seems on topic.

Can anyone recommend an affordable web host for ASP.NET 2? Dreamhost doesn't support it, goddady.com does, but I've heard bad things about their hosting.

I am looking for something affordable, as my primary use will be a personal website to promote my photography.

I use http://ultimahosts.net/ and they seem pretty good so far.

Fastbreak
Jul 4, 2002
Don't worry, I had ten bucks.
I have a gridview with a template column wiht nothing but Textboxs. In the textboxs, the user will enter a dollar amount that they want to pay for each line item. I have a javascript function in place to calculate the sum, but I was hoping to update the footer of the column to ensure proper alignment no matter what the value. Is there a way to access the footer field client side? If not, is there a better solution?

Fiend
Dec 2, 2001

fez2 posted:

This is a really stupid .NET question, but google can't seem to help me.

I'd like to add a warning to one of my methods so I know it's depcreciated so when I build it on older projects I'll remember that the method is older.

I still want to be able to build them, so it has to be a warning and I'd like it to appear in the usual debugging place. Does anyone know how to throw your own warning message?

like this?
code:
// preprocessor_warning.cs
// CS1030 expected
#define DEBUG
class MainClass 
{
    static void Main() 
    {
#if DEBUG
#warning DEBUG is defined
#endif
    }
}

uXs
May 3, 2005

Mark it zero!

wwb posted:

Probably worrying too much unless you have thousands of groups to check.

I would, however, look at making your user object implement IPrincipal and push said user into the Context.User property. That way you can rely on .NET's builtin security features to handle stuff. Such as using PrincipalPermissionAttribute on methods.

Ok thanks. I've had a quick look at IPrincipal and Context.User but it doesn't seem too useful for what I'm doing, the security checks are too complicated. Also the project is supposed to be finished at the end of next week so I don't really feel like changing it now. :v:

Made me realize (again) that there's still loads of things I don't know about asp.net though. Maybe I should take some overview course somewhere instead of just using google for everything ever.

JediGandalf
Sep 3, 2004

I have just the top prospect YOU are looking for. Whaddya say, boss? What will it take for ME to get YOU to give up your outfielders?

Fiend posted:

like this?
code:
// preprocessor_warning.cs
// CS1030 expected
#define DEBUG
class MainClass 
{
    static void Main() 
    {
#if DEBUG
#warning DEBUG is defined
#endif
    }
}
No he's talking about more of something like this
code:
public class Apples
{
	[Obsolete("GrannySmiths have been deprecated! Try a Red Delicious instead!")
	public void GrannySmith()
	{
		EatIt();
		DrinkIt();
		BakeIt();
	}

	public void RedDelicious()
	{
		EatIt();
		DrinkIt();
		CookIt();
	}
}
If you call .GrannySmith() it will flag as being obsolete as a warning on compile.

Fiend
Dec 2, 2001

JediGandalf posted:

No he's talking about more of something like this
code:
public class Apples
{
	[Obsolete("GrannySmiths have been deprecated! Try a Red Delicious instead!")
	public void GrannySmith()
	{
		EatIt();
		DrinkIt();
		BakeIt();
	}

	public void RedDelicious()
	{
		EatIt();
		DrinkIt();
		CookIt();
	}
}
If you call .GrannySmith() it will flag as being obsolete as a warning on compile.
Thanks! I'm going to start using this in my current projects :)

Dromio
Oct 16, 2002
Sleeper
Oooh, another arcane issue:

System.IO.Path.GetTempPath() in ASP.NET returns "C:\Documents and Settings\MyMachine\ASPNET\Local Settings\Temp\" on my system. But on my tester's system, it returns "C:\Documents and Settings\HisMachine\ASPNET\LOCALS~1\Temp\". Both of us are running XP SP2.

Why is it using a short filename for the "Local Settings" portion (and ONLY that portion) of his temp path? Is there some way to force a full filename? Unfortunately, a third-party component doesn't seem to like the short file names.

Dromio fucked around with this message at 21:53 on Aug 22, 2007

rckgrdn
Apr 26, 2002

So that's how it's made...
Dromio: Check the system-level TEMP (or TMP) environment variable and see what it is on the tester's system - it might be set with the awkward LOCALS~1 path rather than the long form. Apparantly GetTempPath() isn't particularly clever and just returns the TEMP environment variable for the user it's running as.

Mecha
Dec 20, 2003

「チェンジ ゲッタ-1! スイッチ オン!」
Anyone have experience with using COM and Interop DLLs? I've got a project reference to the Photoshop CS2 library(reported as "Photoshop 9.0 Object Library") to use its C# scripting interface, and it builds an Interop DLL that works fine with CS2 installations but apparently doesn't seem to recognize CS installations. The scripting interface didn't seem to change between the two, so I'm wondering if I need to take a more general approach towards getting a COM interface to the scripting system?

wwb
Aug 17, 2004

Not really a COM guy, but I did my fair share of office VBA. Anyhow, this issue you are probably having is that Photoshop CS exposes Photoshop 8.0, not 9.0. Now, if the functionality is common, you could probably put this behind some sort of facade which wrapped the interface you are using and leave mapping to the right DLL to said facade.

Dromio
Oct 16, 2002
Sleeper

thestoreroom posted:

Dromio: Check the system-level TEMP (or TMP) environment variable and see what it is on the tester's system - it might be set with the awkward LOCALS~1 path rather than the long form. Apparantly GetTempPath() isn't particularly clever and just returns the TEMP environment variable for the user it's running as.
Actually, the TEMP and TMP environment variable are always in short form on any XP machine (for compatibility reasons). Both machines show the entire path in short format. But GetTempPath() shows only PART of the path in short format on his.

biznatchio
Mar 31, 2001


Buglord

Dromio posted:

Is there some way to force a full filename?

code:
    [DllImport("kernel32")]
    private static extern int GetLongPathName(
        [MarshalAs(UnmanagedType.LPTStr)] string path,
        [MarshalAs(UnmanagedType.LPTStr)] StringBuilder longPath,
        int longPathLength
        );
        
    public string ConvertShortToLong(string shortName)
    {
        StringBuilder longPath = new StringBuilder(255);
        GetLongPathName(shortName, longPath, longPath.Capacity);
        return longPath.ToString();
    }

Hey!
Feb 27, 2001

MORE MONEY = BETTER THAN
I'm running Vista 64-bit and my code doesn't seem to be reading from machine.config. There are some appSettings elements in there, but when code tries to read them via ConfigurationManager.AppSettings["name"], they come up null. Does anyone know of some steps I can try to figure out what's going on? This same exact code works fine on XP, and a Vista 32-bit box that someone else here has.

I'm pretty sure it's not a security or permissions issue, that's all I have so far.

Edit: I just added the same key to the app.config and it still comes up null! WTF
Edit2: machine.config belongs under c:\windows\microsoft\framework64 instead of c:\windows\microsoft\framework. I knew it was something dumb like that.

Hey! fucked around with this message at 16:03 on Aug 23, 2007

Adbot
ADBOT LOVES YOU

memknock
Jul 4, 2002
When using the property grid is there a good "non hacky" way to organize the list.

For example I have two main catgories
-Communication
-Misc
-(more are coming)

But I would like for Misc to be listed first, right now the best way (which we call the hack method) is by making the name

<category( vbtab & "Misc")>

Currently it the propertysort setting is set to Category (not the categoryAlphabetical)

How can I go about changing the order of the categories?

  • Locked thread