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
No Safe Word
Feb 26, 2005

Shy posted:

Why? I never used it but I thought it pretty much does the same job as C# almost as easily.
Not trying to call anyone out, but it would be really interesting to hear what makes it awful (other than not being C-like which is certainly a deal breaker for some people).

I cannot abide by a language that uses () for both function calls and array indexing.

Adbot
ADBOT LOVES YOU

ljw1004
Jan 18, 2005

rum

Ithaqua posted:

I'm not a huge fan of the VB syntax, but I can work with it in a pinch. It's mostly different names for the same concepts, but in some cases, the syntax is just ugly as gently caress, especially generics and LINQ.
code:
var words = new List<string> {"caterpiller", "cat", "dog", "turkey", "catatonic"}
var orderedCatWords = words.Where(x=>x.StartsWith("cat").OrderBy(x=>x).ToList();

My day job is language designer for VB. There are lots of places where it's ugly, but this example actually showcases some of its neat syntax features once you write it in idiomatic VB rather than C#...

code:
Dim words = {"caterpiller", "cat", "dog", "turkey", "catatonic"}

Dim orderedCatWords = From w In words Where w.StartsWith("cat") Order By w
* In the above, I used VB10's "array literal" feature. It's particularly handy for working with empty arrays or places where arrays need to get their type from the context:
code:
    Dim meth = GetType(String).GetMethod("IsNullOrEmpty")
    meth.Invoke("", {})

    ' C#: meth.Invoke("", new object[] {});

    Function f() As Short()
      If b Then Return {1,2,3}
      Return {}
    End Function

    ' C#: if (b) return new short[] {1,2,3}; else return new short[] {};
* And of course VB has a lot of LINQ operators so you need to fall back to the dot-style less frequently

ljw1004 fucked around with this message at 01:34 on Jan 26, 2012

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

ljw1004 posted:

My day job is language designer for VB. There are lots of places where it's ugly, but this example actually showcases some of its neat syntax features once you write it in idiomatic VB rather than C#...

code:
Dim words = {"caterpiller", "cat", "dog", "turkey", "catatonic"}

Dim orderedCatWords = From w In words Where w.StartsWith("cat") Order By w
* In the above, I used VB10's "array literal" feature. It's particularly handy for working with empty arrays or places where arrays need to get their type from the context:
code:
    Dim meth = GetType(String).GetMethod("IsNullOrEmpty")
    meth.Invoke("", {})

    ' C#: meth.Invoke("", new object[] {});

    Function f() As Short()
      If b Then Return {1,2,3}
      Return {}
    End Function

    ' C#: if (b) return new short[] {1,2,3}; else return new short[] {};
* And of course VB has a lot of LINQ operators so you need to fall back to the dot-style less frequently

Yeah, I was aware of the "SQLy" LINQ syntax, which C# also uses. I'll usually try a complex LINQ expression both ways and see which is more readable. The second I hit a GroupBy(), I'll do it "SQL" style.

As for the second thing, that's pretty neat. Is it different under the hood from something like
code:
var words = new [] {"x","y","z"};
?

ljw1004
Jan 18, 2005

rum

Ithaqua posted:

As for the second thing, that's pretty neat. Is it different under the hood from something like
code:
var words = new [] {"x","y","z"};
?

That's more or less what it's doing. The differences:

* There are two IL strategies that the compiler can use to implement the above statement. It could generate a new array and then stick elements in it one at a time by code. Or it could have a flat set of bytes in the EXE and call a different IL instruction to slurp them up all at once. C# will use the second strategy for large enough arrays. In the end it doesn't make for an observable perf win... the different IL has to basically to the same things anyway!

* For "new[] {...}", C# uses solely the dominant type of the elements; if there are no elements or no dominant type then it's a compiler error. Thus, "new[] {}" will always be an error in C#. VB first takes into account the target type of the array. The following is allowed: "Dim x As IEnumerable(Of String) = {}".



More generally, C# has striven to be a language where the meaning of an expression is determined solely by the expression. Sticking to this principle makes it easier to read and understand. VB has a few more exceptions to the principle than C#.

PUZZLE: There are three kinds of expression in C# where, to know the meaning of the expression, you need to know the type that this expression is expected to be. What are they? (by "meaning" I mean things like what IL will be generated, or what type the sub-expressions have.)

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I actually quite like VB (and not VB6 obviously). It is very verbose, but it also scans the clearest for me when trying to figure out what's going on. This relates more to other people's code than mine. Where it does fall down is those crazy (x) level deep dom-style calls, but the same is true of the other .Net languages.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
I'd like to set up a system with this kind of structure:

SolutionName
-> MainProject
-> ToolsProject

such that when you mash F5 the ToolsProject builds (if needed) and executes before the MainProject is run. The idea is that ToolsProject will pick up some files and transform the data into something that MainProject can use, and for a release version you'd only give out the build of MainProject and the pre-digested data files.

The inspiration for this setup is XNA's content pipeline system. They have a Content project that you can stuff all your models, textures, sounds, etc. into and at build time it packs everything into a binary format that is ready for the XNA game to just grab and run with.

I've never played with fancy build setups in VS, so I'm not sure where to start. Even just a 'Google for term X' hint would be great. I've looked at the project pre/post build events but it doesn't feel like I'm going down the right path there.


ljw1004 posted:

PUZZLE: There are three kinds of expression in C# where, to know the meaning of the expression, you need to know the type that this expression is expected to be. What are they? (by "meaning" I mean things like what IL will be generated, or what type the sub-expressions have.)

Is something like
code:
button1.Click += (s,e)=>{/*do stuff*/};
one of them? There's nothing in the lambda expression that tells you about the types for s or e. The types get set from the expectation that they will conform to the thing that the lambda is being assigned to, (object sender, MouseEventArgs e) in this case.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

PDP-1 posted:

I've never played with fancy build setups in VS, so I'm not sure where to start. Even just a 'Google for term X' hint would be great. I've looked at the project pre/post build events but it doesn't feel like I'm going down the right path there.

Nope, that's the right path. You need to do something post-build, it sounds like. The downside of that is that it's going to run on EVERY build, so if it takes a while to run, it's going to suck.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
OK, good to know, thanks! Hopefully runtime shouldn't be a problem - if I can figure out how to get it working I'd scan the source directory for changes/additions/deletions and just let any other existing processed data stay where it is.

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

PDP-1 posted:

I'd like to set up a system with this kind of structure:

SolutionName
-> MainProject
-> ToolsProject

such that when you mash F5 the ToolsProject builds (if needed) and executes before the MainProject is run.

Expand MainProject in the Solution Exlporer, right-click References, Add Reference..., I don't remember the exact interface from here because I use an extension that replaces it, but you want to add a project reference and not a DLL reference.

If you already have a DLL reference (likely, otherwise why would you care if it's built or not), remove it.

akadajet
Sep 14, 2003

I just hate working on mixed language solutions where my brain has to bounce back and forth. I also hate VB.Net projects because most of the time they are set up without "Option Strict" or whatever which makes certain types of refactoring a huge pain in the rear end. And having to explicitly specify which interface member I'm implementing sucks.

aBagorn
Aug 26, 2004
Another quick question:

Is there anyway I can take data from a GridView row and use it to populate text boxes?

Right now I'm using this code:

code:
var sites = from site in db.SiteLists
                        where site.Site_Address.Contains(searchText.Text)
                        || site.Router_Model.Contains(searchText.Text)
                        || site.Service_Provider.Contains(searchText.Text)
                        orderby site.Site_Address, site.Router_Model, site.Service_Provider
                        select site;
            GridView1.DataSource = sites.ToList();
            GridView1.DataBind();
to query my database and populate.

However for record updates, I want to be able to do something like this:

code:
var update = db.SiteLists.Single(site => site.Site_Address.Equals(addressBox.Text));
            update.Site_Address = addressBox.Text;
            update.Router_Model = routerBox.Text;
            update.Service_Provider = providerBox.Text;
            db.SaveChanges();
How do I select a row from GridView1 and make the data from its colums go into addressBox, routerBox, and providerBox respectively? Google has been pretty terrible in this aspect.

edit:

I have a terrible workaround, and it presents a different problem.

I used a completely new search method to populate the textboxes, and that's all well and dandy, using similar code to the above, but instead of binding it to the grid, I loop through it and populate the textboxes accordingly.

The problem arises when we have sites of similar name (e.g., our bigger sites have 2 separate connections, one for intranet and one for internet), the textboxes will only populate with the first one.

Is there some sort of if statement I can use to check whether the number of records returned >= 2, and provide an intermediate popup that allows the user to select which of these possible records they want to edit?

aBagorn fucked around with this message at 22:02 on Jan 26, 2012

ljw1004
Jan 18, 2005

rum

PDP-1 posted:

PUZZLE: There are three kinds of expression in C# where, to know the meaning of the expression, you need to know the type that this expression is expected to be. What are they?
Is something like
code:
button1.Click += (s,e)=>{/*do stuff*/};
one of them? There's nothing in the lambda expression that tells you about the types for s or e.

Yeah, that's one. The others:

code:
class C {
  static void f() {}
  static void f(int i) {}
}

Action<int> a = C.f;  // this needs the context type to pick an overload



var x = null; // "null" needs a context type to pick an overload; this won't work
short x = 0; // the type of numeric literal expressions varies with surrounding context

boo_radley
Dec 30, 2005

Politeness costs nothing
This is pretty neat (from Hidden Features of C#?:

code:
private IList<Foo> _foo;

public IList<Foo> ListOfFoo 
    { get { return _foo ?? (_foo = new List<Foo>()); } }
I'm always amazed at how different concepts come together in C#.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

aBagorn posted:


code:
var sites = from site in db.SiteLists
                where site.Site_Address.Contains(searchText.Text)
                || site.Router_Model.Contains(searchText.Text)
                || site.Service_Provider.Contains(searchText.Text)
              orderby site.Site_Address, site.Router_Model, site.Service_Provider
              select site;
            GridView1.DataSource = sites.ToList();
            GridView1.DataBind();
to query my database and populate.

I would just like to point out that you've mixed your presentation and data layers together, which is a no-no. Your presentation layer shouldn't have any sort of data access code in it whatsoever.

Luckily, you're using an ORM, so at least it's a little bit better than calling SqlCommands directly from the page.

I'd recommend looking into ObjectDataSource for what you're doing, because I can almost guarantee it will make your life easier. You define an ODS, tell it what methods to call and what parameters to provide the methods for your CRUD, and then it calls those methods as appropriate.

[edit] Check this out! Editable gridviews

If you're using ASP .NET webforms, you might as well leverage the stuff that's built-in.

New Yorp New Yorp fucked around with this message at 23:33 on Jan 26, 2012

aBagorn
Aug 26, 2004

Ithaqua posted:

I would just like to point out that you've mixed your presentation and data layers together, which is a no-no. Your presentation layer shouldn't have any sort of data access code in it whatsoever.

Luckily, you're using an ORM, so at least it's a little bit better than calling SqlCommands directly from the page.

I'd recommend looking into ObjectDataSource for what you're doing, because I can almost guarantee it will make your life easier. You define an ODS, tell it what methods to call and what parameters to provide the methods for your CRUD, and then it calls those methods as appropriate.

[edit] Check this out! Editable gridviews

If you're using ASP .NET webforms, you might as well leverage the stuff that's built-in.

Ah, cool.

Yeah this is the kind of stuff I need to know.

My code is all over the place, and I'm just worried about "does it work" rather than "best practices", and I should be concerned with both.

FWIW I have 2 WebForms with almost identical data access code on it because I was too stupid to use session data to pass values, and didn't create a new class to contain the data methods cause I'm dumb :downs:

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

aBagorn posted:

Ah, cool.

Yeah this is the kind of stuff I need to know.

My code is all over the place, and I'm just worried about "does it work" rather than "best practices", and I should be concerned with both.

FWIW I have 2 WebForms with almost identical data access code on it because I was too stupid to use session data to pass values, and didn't create a new class to contain the data methods cause I'm dumb :downs:

You're asking the right questions and learning the good stuff along the way, which is pretty much the best you can hope for. My first production application was a true horror. Write unit tests where you can and don't be afraid to refactor.

Zhentar
Sep 28, 2003

Brilliant Master Genius

boo_radley posted:

This is pretty neat (from Hidden Features of C#?:

That people would consider many of those features "hidden" saddens me. yield? Seriously?

aBagorn
Aug 26, 2004

Ithaqua posted:

You're asking the right questions and learning the good stuff along the way, which is pretty much the best you can hope for. My first production application was a true horror. Write unit tests where you can and don't be afraid to refactor.

Ithaqua I don't want to poo poo up the thread anymore with stupid questions but if you're up for it, I do have more stupid questions.

No PMs but my email is in my profile

Fastbreak
Jul 4, 2002
Don't worry, I had ten bucks.

Zhentar posted:

That people would consider many of those features "hidden" saddens me. yield? Seriously?

Of all the things on that list, you think yield is the least appropriate? They have using and var on that list which is in dozens of code samples. At least yield is come what obscure and situational.

but yeah, agree with you that "hidden" is not the right term for those features.

akadajet
Sep 14, 2003

Zhentar posted:

That people would consider many of those features "hidden" saddens me. yield? Seriously?

The only appropriate thing on that list are the undocumented keywords, but they really are of little practical value.

boo_radley
Dec 30, 2005

Politeness costs nothing

akadajet posted:

The only appropriate thing on that list are the undocumented keywords, but they really are of little practical value.

Yeah, if you're thinking of hidden as really hidden, that's true. But as a tips/ tricks/ "did you know?" thread, it's interesting reading. There's things on that list that I use every day, but as SharePoint developer I rarely touch multithreaded code, so things like volatile and multithreaded code are kinda foreign to me.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

aBagorn posted:

Ithaqua I don't want to poo poo up the thread anymore with stupid questions but if you're up for it, I do have more stupid questions.

No PMs but my email is in my profile

I emailed you, but I'd say that asking questions about .NET development isn't making GBS threads up the thread, it's the purpose of the thread.

Moey
Oct 22, 2010

I LIKE TO MOVE IT
Quick question.

I am writing a small web quiz for internal use at my company. I want to scrape the windows user name and add it with the results and dump them to a db.

Currently in my testing (Microsoft Visual Web Developer 2010 Express) when I run my webpage, I can properly pull my domain\username. When I upload it to my webserver (Server 2008 R2, IIS 7.5) and use it, it is pulling a service account? I will get this instead of the user name IIS APPPOOL\DefaultAppPool.

Is this a problem with my code to get the username, or a setting for my Application Pool?

code:
using System.Security.Principal;

String username;
username = WindowsIdentity.GetCurrent().Name;

uXs
May 3, 2005

Mark it zero!

Moey posted:

Quick question.

I am writing a small web quiz for internal use at my company. I want to scrape the windows user name and add it with the results and dump them to a db.

Currently in my testing (Microsoft Visual Web Developer 2010 Express) when I run my webpage, I can properly pull my domain\username. When I upload it to my webserver (Server 2008 R2, IIS 7.5) and use it, it is pulling a service account? I will get this instead of the user name IIS APPPOOL\DefaultAppPool.

Is this a problem with my code to get the username, or a setting for my Application Pool?

code:
using System.Security.Principal;

String username;
username = WindowsIdentity.GetCurrent().Name;

That code won't work for web apps. Use something like System.Web.HttpContext.Current.User.Identity.Name instead. And make sure that you disable anonymous access to the website.

Moey
Oct 22, 2010

I LIKE TO MOVE IT

uXs posted:

That code won't work for web apps. Use something like System.Web.HttpContext.Current.User.Identity.Name instead. And make sure that you disable anonymous access to the website.

That did it. Thanks!

Building on this note, not sure if this is an .Net question or what.

When I have Anon Access disabled, IE will scrape my windows login info and connect without any user intervention needed. With Firefox, it prompts for username/pw. Is there any way to get this/Firefox to play nicely (no user input needed)?

Moey fucked around with this message at 00:02 on Jan 28, 2012

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!

Moey posted:

That did it. Thanks!

Building on this note, not sure if this is an .Net question or what.

When I have Anon Access disabled, IE will scrape my windows login info and connect without any user intervention needed. With Firefox, it prompts for username/pw. Is there any way to get this/Firefox to play nicely (no user input needed)?

You're looking for NTLM authentication configuration.

http://sivel.net/2007/05/firefox-ntlm-sso/

To expand, Windows does it natively if the site is in the trusted zone. You will have to use a group policy to get Firefox to do it automagically.

Moey
Oct 22, 2010

I LIKE TO MOVE IT

Nurbs posted:

You're looking for NTLM authentication configuration.

http://sivel.net/2007/05/firefox-ntlm-sso/

To expand, Windows does it natively if the site is in the trusted zone. You will have to use a group policy to get Firefox to do it automagically.

Exactly what I was looking for, thanks.

No more users locking themselves out by hamfisting passwords trying to pull up our internal wiki in FF.

Dietrich
Sep 11, 2001

I'd like to attend some conferences or seminars this year since I completely neglected my training budget last year and I might lose it if I don't use it.

What conferences and seminars do you guys attend/find awesome?

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!

Dietrich posted:

I'd like to attend some conferences or seminars this year since I completely neglected my training budget last year and I might lose it if I don't use it.

What conferences and seminars do you guys attend/find awesome?

I went to TechEd a few years ago and came away with some really neat insights.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Dietrich posted:

I'd like to attend some conferences or seminars this year since I completely neglected my training budget last year and I might lose it if I don't use it.

What conferences and seminars do you guys attend/find awesome?

CodeMash was great the past 2 years, although it's in January so you already missed it for 2012. Tickets go on sale in October usually. It's in Ohio in January!

wwb
Aug 17, 2004

At this point this year I'm planning to hit WWDC and whatever Microsoft has this fall to replace MIX / BUILD. I think WWDC makes sense, even for non-iOS devs, as that is driving so much that you've got to understand that platform and where it is going. And the MS thing is probably going to be the Win8 RC0 party.

aBagorn
Aug 26, 2004
Ok goons ready for more crappy code that will make you cry?

As mentioned before, my app works. I've actually gotten it to work better than I originally hoped, even.

But as it sits there on the intranet, being really useful to the net admins and the help desk, I came back to what Ithaqua had said about best practices, and keeping my data access out of my presentation layer.

So in that vein I decided to rewrite it from scratch as a test to myself.

It doesn't work for poo poo. It compiles ok, but no data gets passed. Using the debugger I can't exactly tell where it's going from the value I have in a textbox to 'null'.

Some relevant code. On the search page, I declare a string variable and then have a button click method.

code:

public string SearchText { get; private set; }
 
protected void searchButton_Click(object sender, EventArgs e)
        {
            NhsSitesData data = new NhsSitesData();
            SearchText = searchBox.Text;
            data.GetSite();
            DropDownList1.DataSource = data.dropdown;
            DropDownList1.DataBind();
        }

The method invoked is in my fancy new data accessor class, NhsSitesData, which looks like this:
code:

public class NhsSitesData
    {
        NHSSitesEntities db = new NHSSitesEntities();
        public Search page = new Search();
        public List<string> dropdown { get; private set; }
 
        public void GetSite()
        {
            var sites = from site in db.SiteLists
                        where site.Site_Address.Contains(page.SearchText)
                        || site.Router_Model.Contains(page.SearchText)
                        || site.Service_Provider.Contains(page.SearchText)
                        orderby site.Site_Address
                        select site.Site_Address;
            dropdown = sites.ToList();
        }

As you can of course gather, what is supposed to happen is the db should be queried according to the text in the searchbox, selecting only the address property of each record, throwing it into a list, and populating a dropdown with that list.

But nothing happens. Not a drat thing. Am I missing something with session info here?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

aBagorn posted:

:words:

You're not passing any search criteria into your class, it looks like. Your class shouldn't have public properties for setting the search criteria and getting results. All that does is introduce unnecessary state into your class, which can cause weird bugs and general headaches.

The method you're calling should take parameters and return its result. Also, use using blocks around your data access stuff... it's a language construct that is equivalent to
code:
var x = new DisposableThing();
try 
{
   x.DoStuff();
}
finally
{
   x.Dispose();
}
==
code:
using (var x = new DisposableThing()) 
{
   x.DoStuff();
}

It ensures that it cleans up its managed/unmanaged resources. Very useful for database IO and file IO.

Anyway, back to your problem...
Try this:
code:
public class NhsSitesData
{
        public IEnumerable<string> GetSite(string searchCriteria)
        {
            using (var db = new NHSSitesEntities()) 
            {
                var sites = from site in db.SiteLists
                        where site.Site_Address.Contains(searchCriteria)
                        || site.Router_Model.Contains(searchCriteria)
                        || site.Service_Provider.Contains(searchCriteria)
                        orderby site.Site_Address
                        select site.Site_Address;
                return sites.ToList();
            }
        }
}

protected void searchButton_Click(object sender, EventArgs e)
{
            NhsSitesData data = new NhsSitesData();
            var searchResults = data.GetSite(searchBox.Text);
            DropDownList1.DataSource = searchResults;
            DropDownList1.DataBind();        
}
Of course, at this point you could make your class and the method static. I tend to avoid static classes, for reasons that will become apparent if you ever start unit testing.

New Yorp New Yorp fucked around with this message at 21:10 on Jan 28, 2012

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.
I have a WinForms application where I am trying to attach a Form to a class to serve as a UI view. The class has some input values and some output values that I'm trying to connect to TextBoxes on the Form using Binding and INotifyPropertyChanged to get two-way interaction.

The issue I'm runing into is that the class' output values can change at random times, and when one of them changes and fires PropertyChanged it causes *all* of the TextBoxes on the Form to update instead of just the one thing that changed value. If you happen to be midway through typing a new input value and some output value happens to change the input value TextBox gets reset to it's initial value and you lose your work.

I've tried to re-create this scenario in the code below. In this case OutputProperty gets periodically changed by a Timer. If you happen to be trying to modify the InputValue by changing the inputTextBox text, everything gets reset and you lose your data.

Is there any way to make it so only the things that actually change cause updates in their associated TextBox?

code:
    public partial class Form1 : Form, INotifyPropertyChanged
    {
        Timer timer = new Timer();
        int inputValue = 0;
        int outputValue = 0;

        public Form1()
        {
            InitializeComponent();

            timer.Tick += new EventHandler(timer_Tick);
            timer.Interval = 500;
            timer.Start();

            inputTextbox.DataBindings.Add("Text", this, "InputProperty", false, 
                DataSourceUpdateMode.OnValidation);
            outputTextbox.DataBindings.Add("Text", this, "OutputProperty", false, 
                DataSourceUpdateMode.OnPropertyChanged);
        }

        void timer_Tick(object sender, EventArgs e)
        {
            OutputProperty += 1;
        }

        // Properties
        public int InputProperty
        {
            get { return inputValue; }
            set
            {
                if (value != inputValue)
                {
                    inputValue = value;
                    NotifyPropertyChanged("InputProperty");
                }
            }
        }
        public int OutputProperty
        {
            get { return outputValue; }
            set
            {
                if (value != outputValue)
                {
                    outputValue = value;
                    NotifyPropertyChanged("OutputProperty");
                }
            }
        }

        // INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null) 
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

PDP-1 posted:

:words:

http://stackoverflow.com/questions/2820447/net-winforms-inotifypropertychanged-updates-all-bindings-when-one-is-changed-b

aBagorn
Aug 26, 2004

Ithaqua posted:

:words:

Thank you thank you thank you! It makes so much sense now.

Don't ask me why I was doing it (or trying to do it) the other way before and making it needlessly complicated.

Last question about this project, I promise.

I want to have a popup do a confirm/cancel dialog when a site is updated/deleted/added. In WinForms I would just do a MessageBox.Show and be done with it.

I'm assuming it's not so simple with web. Do I need to use JavaScript?
or something like:

<asp:Button ID="deleteButton" runat="server" Text="Delete" OnClientClick = "return confirm('Are you sure you want to delete?');"/>

aBagorn fucked around with this message at 14:38 on Jan 30, 2012

Dietrich
Sep 11, 2001

Nurbs posted:

I went to TechEd a few years ago and came away with some really neat insights.

When do they typically post their course catalog? My boss is gonna wanna see exactly what they're paying for.

Ithaqua posted:

CodeMash was great the past 2 years, although it's in January so you already missed it for 2012. Tickets go on sale in October usually. It's in Ohio in January!

I'm already in Ohio all year around, Maybe I'll try to attend this in 2013.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

aBagorn posted:

<asp:Button ID="deleteButton" runat="server" Text="Delete" OnClientClick = "return confirm('Are you sure you want to delete?');"/>

That sounds about right.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

Thanks for the link, it explains what's going on here and why the default DataBindings setup is not the way to go in this case. As an alternate solution I tried setting up and extension method to 'bind' things together. It still needs some cleanup but at least it provides the behavior I wanted and all the get/set operations are separated out individually. Worst idea, or merely a bad idea?

e: OK, there is a pretty bad flaw here - if I want to change the dataSource object repeatedly there is no way to clean up the existing event handlers.

e2: Actually it looks like you can clear the events from outside the class via reflection. It's not pretty since it clears *all* event listeners, but maybe within the limited context of this application that'd be something I could live with.

e3: Screw this idea. Messing with eventhandler lists is a mess and breaks the whole way that events are supposed to work.

code:
    // use case:
    textBox1.BindToProperty(someClass, "SomeProperty");

    // extension method:
    public static class ExtensionMethods
    {
        public static void BindToProperty(this TextBox textBox, INotifyPropertyChanged dataSource, string sourceProperty)
        {
            PropertyInfo pi = dataSource.GetType().GetProperty(sourceProperty);
            textBox.Validated += (s, e) => { pi.SetValue(dataSource, Convert.ChangeType(textBox.Text, pi.PropertyType), null); };
            dataSource.PropertyChanged += (s, e) =>
                {
                    if(e.PropertyName.Equals(sourceProperty))
                    {
                        textBox.Text = (string)Convert.ChangeType(pi.GetValue(dataSource, null), typeof(string));
                    }
                };
            textBox.Text = (string)Convert.ChangeType(pi.GetValue(dataSource, null), typeof(string));
        }
    }

PDP-1 fucked around with this message at 22:49 on Jan 30, 2012

Adbot
ADBOT LOVES YOU

aBagorn
Aug 26, 2004

Ithaqua posted:

That sounds about right.

Yeah that worked pretty well.

Now for the icing on the cake. Integrating it with our off the shelf ticketing software if I can.

(not completely necessary, but I'm going to try to do it anyway. Who wants to make everyone's lives easier? this guy :effort: )

Edit:

Tiny rant incoming: some smarmy as gently caress douche at the company tells me today, "I don't know why you bothered to code all that, it will be obsolete when we migrate to SharePoint"

Please tell me there's a way to import an existing ASP.NET application into SharePoint so I can shut his smug rear end up.

aBagorn fucked around with this message at 00:35 on Jan 31, 2012

  • Locked thread