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
zokie
Feb 13, 2006

Out of many, Sweden
I'm having a problem in Access and a ListBox. I have a ListBox, with multiple columns, filled with information from a table where each row represents a record. I also have a regular form where you can ,with Access built in interface, browse through all records.
The idea is that when a user double clicks a row in the ListBox the "details form" opens with the correct record showing. This should be quite simple but I can't for the life of me access the value of the bound column in the ListBox, which I of course want to use in my OpenForm WHERE-statement.

Does anyone know how to do this?

Adbot
ADBOT LOVES YOU

zokie
Feb 13, 2006

Out of many, Sweden
You can also pass the list with the ViewBag, but that's not really a good practice. I recently learned MVC 4 and at first I used the drop down list helper and the ViewBag but I have now moved on to jQuery.

zokie
Feb 13, 2006

Out of many, Sweden

Sedro posted:

You can't. Write to a temp file and use InsertFile.

I'd look into open xml sdk, it can do some neat poo poo without office automation. I'm not sure I entertains what needs to be done but making word documents with it is quite easy.

zokie
Feb 13, 2006

Out of many, Sweden

Dromio posted:

I'm struggling a bit with modularity and reusable code using Entity Framework. I have some slightly complex logic to determine sales for a user, something like this (simplified, but enough to go on):

code:
public int GetSalesVolume(int ID)
{
return from user in UsersTable
join sales in SalesTable.DefaultIfEmpty() on sales.UserID equals user.ID
join payouts in PayoutsTable.DefaultIfEmpty() on payouts.UserID equals user.ID
where user.ID == ID
select (sales.sum(s=>s.Amount)) - (payouts.sum(p=>p.Amount))
}
Now, I want to do a query that returns a specific user with their sales:

code:
from user in UsersTable
where user.Region = TheRegionToCheck
select new{User = user, Volume = GetSalesVolume(user.ID)}
This sort of thing always confuses the SQL parser for EF-- "System.NotSupportedException : LINQ to Entities does not recognize the method 'Int32 GetSalesVolume(Int32)' method, and this method cannot be translated into a store expression"

Is there something I can do to my original query to make it reusable within other queries like this? Of course I could just call one query to get the user by region, then another to get the volume, but I want to avoid some situations where I'd end up with a ton of calls to the db if I need to get the volume for a lot of users.

Look in to deferred execution, C# actually only executes your queries when you enumerate them etc. So keeping stuff as an IQueryable as long as possible means that it will reflect changes deeper down. This is what makes EF angry at you "this method cannot be translated into a store expression".

zokie
Feb 13, 2006

Out of many, Sweden
I'm having issues with ASP.NET MVC, when deployed to our ISS any first visit to the website is soo sloooow. Does anyone have the same experience and any idea of how to fix it?

zokie
Feb 13, 2006

Out of many, Sweden
Cool, thanks for the replies. Figured it was something like that. I'll check your repo GitHub :)

zokie
Feb 13, 2006

Out of many, Sweden

Gul Banana posted:

has anyone been paid to use winrt yet? does anyone know anyone who's been paid to do winrt?
is this even the right thread to ask?

This but WPF, I work at a small shop were most people work mostly with Biztalk the rest of us (two old geezers and me) are regular developers. They have always worked with just WinForms and I'm just a new guy so now that we are soon going to start a new big project we think that maybe it's time to make the switch. Is this the right call?

zokie
Feb 13, 2006

Out of many, Sweden

Dirk Pitt posted:

I understand that as well. I have a shitlord architect who forces everyone to use his custom mvvm pattern.

So to summarize, is the
code:

Onclick poo poo()
{
Viewmodel.SetLoad(id);
}

internal async void SetLoad(int loadId){}
Acceptable in this instance? Or should SetLoad be an internal async Task<T>?

I have a rare chance to force my twenty coworkers to stop loving up and want to do this right.

I think you are missing the fact that an async method can return Task, just Task. Not a Task of T. Hope this helps.

zokie
Feb 13, 2006

Out of many, Sweden
So we're making the switch to WPF and because of 'not built here' we are making our own little MVVM-framework. In previous business applications we've always made frequent use of disabling and enabling buttons depending on what actions are available to the user (such as Save being disabled if the form is invalid) and we want to keep this behavior. While we haven't really looked at IDataError yet we figured we could get this behavior with either special properties (bools like CanSave) databound to controls or value converters evaluating states we think that using the former is best. To avoid having this state evaluating code everywhere my boss wants us to use one centralized States(string field, object value) method to change all states and to contain the code that sets flags etc. I think that while it does work it's not very elegant or smart, since we are using the INotifyPropertyChanged interface I figured, why not subscribe to ourselves? Kinda like this:

code:
    
public abstract class ViewModel : INotifyPropertyChanged
{
        private readonly Dictionary<string, List<Action<object, PropertyChangedEventArgs>>> subscribers;

        protected ViewModel()
        {
            subscribers = new Dictionary<string, List<Action<object, PropertyChangedEventArgs>>>();
            
            Action<object, PropertyChangedEventArgs> masterSubscriber = (sender, args) =>
            {
                if (string.IsNullOrEmpty(args.PropertyName)) return;
                foreach (var sub in subscribers[args.PropertyName])
                    sub(sender, args);
            };

            PropertyChanged += new PropertyChangedEventHandler(masterSubscriber);
        }

        protected void AddSubscriber(string propertyName, Action<object, PropertyChangedEventArgs> sub)
        {
            if (subscribers[propertyName] == null)
                subscribers[propertyName] = new List<Action<object, PropertyChangedEventArgs>>();

            subscribers[propertyName].Add(sub);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
}
All viewmodels inherit this abstract class. I think this is a really neat and hopefully efficient. What I really like is that I can register delegates and easily see what they do without having a giant bloated method handling it all (While it can of course be re-factored into smaller ones I still don't like it). One thing I particularly like is that it's quite easy to subscribe to other eventhandlers referenced in the class (and of course that fact that the delegates allow us to add new subscribers on the fly :v:)

I figure that each viewmodel can implement a method like this:
code:
private void RegisterSubscribers()
{
            this.AddSubscriber("Name", (s, args) =>
                {
                    var me = s as Person;
                    me.CanSave = !string.IsNullOrEmpty(me.Name);
                });

            this.AddSubscriber("ProjectId", (s, args) =>
            {
                var me = s as Person;
                me.CanSetProjectId = me.ProjectId == 0;
            });

            this.AddSubscriber("Age", (s, args) =>
            {
                var me = s as Person;
                me.OfAge = me.Age >= 18;
            });
}
What I wonder is, am I doing this right? I'm still quite junior but we are a small shop so I have a lot of opportunity to influence the way we do things. But I haven't worked that much with events before. Am I doing it right using the sender object instead of this when checking state? They should be equivalent since here I'm subscribing to myself...

zokie
Feb 13, 2006

Out of many, Sweden

Sedro posted:

ICommand exists specifically for what you are trying to do. How do you expect to create a MVVM framework without knowing MVVM?

Well, I did say I was a new guy. We are only just starting with this and ICommand together with what I have found about RelayCommand looks almost exactly like what we have been trying to do. Oddly Pluralsight which teaches me a lot has basically nothing about ICommand! edit: Found something there :v:

zokie fucked around with this message at 08:07 on May 28, 2013

zokie
Feb 13, 2006

Out of many, Sweden
So while we are trying to get our heads out of our asses to get started with WPF and MVVM I'm doing a side web project. One of the requirements are to be able to have the client download several files by clicking one link. To me that seems really stupid and borderline impossible, am I correct in saying: Either they click one link per download or they get a .zip file?

Also in the same vein. You know how a mailto: link usually opens someones mail client when they click it. I need to get one or several attachments in there to. I this what ActiveX is about?

zokie
Feb 13, 2006

Out of many, Sweden
If none at your job at least mentioned PCI-DSS quoting your job might not be such a bad idea.
Seriously: if your are handling credit card info your boss should tell you what and how he expects of security...

zokie
Feb 13, 2006

Out of many, Sweden

Polidoro posted:

Quick question:
If I have the following form
code:
<form id="form1">
   <input type="text" name="blah">
   <input type="text" name="blah1">
   <input type="text" name="blah2">
   <input type="file" name="file1">
   <input type="file" name="file2">
</form>
I'm submiting it using javascript doing form1.submit() when a button is clicked

I receive the form as follows:
code:
[HttpPost]
public ActionResult Create(HttpPostedFileBase file1, HttpPostedFileBase file2, FormCollection collection)
{
   //do stuff
}
Why are both file1 and file2 null on Create? I thought the only requirement was to have the same name in the input and the parameters.

Use the developer tools of your chosen webbrowser and/or Fiddler to see if anything actually gets posted.

zokie
Feb 13, 2006

Out of many, Sweden
Using IValidatableObject you can get serverside validation, it has access to this and will trip up on ModelState.IsValid. To use it be sure to include a validation summary in your form (Html.ValidationSummary). If you want clientside you probably need Javascript which has lovely not iso dates....

zokie
Feb 13, 2006

Out of many, Sweden
Can I get some help getting arguments for using the TPL to do asynchronous stuff? The senior developers here are all like: "We have this old thing with callbacks that we know works bla bla bla" OR "Just because you though it was pretty easy to learn that doesn't mean everyone else will get it." If it helps this is a discussion we're having regarding a new big project we are in the midst of starting, our first real big WPF-project.

zokie
Feb 13, 2006

Out of many, Sweden

glompix posted:

ASP.NET MVC goons! I'm catching up on the framework features and am not really sure how to avoid ending up with a /Views/Shared/EditorTemplates folder that's a mile long. The project I worked in before started nearly as soon as the framework was released, so we wrote our own binding, validation, and HTML helpers. I want to start using the built in stuff, though. Before, I just used partial views to achieve the same thing, (which was easy to keep organized across a big application) but can't here. Any tips?

It would help if you specified the actual problem you are trying to solve/solving. Personally I've only used EditorTemplates for formating DateTimes to different stuff... But I guess I have similiar "problems", I tend to get a lot of shared partial views that are needed everywhere.

zokie
Feb 13, 2006

Out of many, Sweden
Can't you just uncheck the namespace provider property of the folder? Sometimes I do that when I need folders to organize it for myself but still want stuff to have the same namespace. It will still gently caress it up when making a new class with Alt+C though...

Edit: I read good after just eating way too spicy food.

zokie
Feb 13, 2006

Out of many, Sweden

Ithaqua posted:

I generally mediate all of my controller interactions with another layer.

FooController -> FooTasks -> FooRepository.

The controller gives the model to FooTasks, which in turn translates the model into a business object that goes to the FooRepository. The upside there is that any sort of lower-level representation of the data is nicely hidden from the controller. The controller shouldn't need to know how the data looks when it's getting persisted.

This is some good poo poo, and definitively how I'm going to structure my MVC apps from now on. And on a side note I made the effort to learn T4-templates today, now I wan't to code-generate all the code :getin:

Still most of the plumbing that needs to be generated/made is either because WCF doesn't handle generics (can't be avoided), because my boss/colleagues don't seem to comfortable generics (ugh) or that it was decided to only use one WCF-service for client-server communication (:stare:, countless businessobjects all with CRUD, GetById and GetAll at a minimum). Luckily almost everyone is on vacation and won't be able to stop me from at least segregating the service interface... But any way, T4-tempating is really neat.

zokie
Feb 13, 2006

Out of many, Sweden
In this WPF-project I'm working on I have a basic list of stuff, if you double-click an item or whatever a dialog appears that let's you edit it. Said dialog is opened from the code-behind of the view containing the list, in the dialog I attach a click handler to the Save-button which closes the dialog with DialogResult = true. I check this in the view that opened the dialog and if it's set to true (changes made) I update the list from the server.

My problem is this, using TPL the Save-command called on the ViewModel of the dialog returns control super fast, too fast :v:. The view gets the dialog result and updates itself before the ViewModel was done saving changes...

I already have an ICommandViewModel interface for ICommands on ViewModels, I figured I should implement an CommandExecuted-Event and close the dialog by subscribing to it instead? But I wan't the dialog to disappear as soon as possible, hide and then close?

What are your thoughts?

zokie
Feb 13, 2006

Out of many, Sweden

His Divine Shadow posted:

Is there some LINQ equivalent to this Mysql sorting ability?

ORDER BY FIELD(FieldName,"heyo", "this is second", "third")

Essentially I can make a custom sorting order based on what said field contains, can be numbers, can be strings.

LINQ provides OrderBy and ThenBy and Descending versions of them both.

zokie
Feb 13, 2006

Out of many, Sweden

VVildo posted:

I have a hard .NET == 4.0 requirement on this WPF project. I'm trying to do the old don't block the UI thread trick. I tried using Tasks and ContinueWith and am running into basically the exact same problem as this guy.

The canExecute() of the ICommand of a Button on my window isn't being called until I click on any other window in the OS. The solution they gave in that thread was to convert the Task into a BackgroundWorker. Is that what I really have to do? I thought Tasks were supposed to supersede (in a way) BackgroundWorkers?

I've had the same problem, in your AsyncCommand, or whatever, call CommandManager.Invalidateblahblah after you set the isExecuting to false right after the the delegate is done executing. This tells the CommandManager to raise the RequerySuggested event which should tell fix your UI problem.

zokie
Feb 13, 2006

Out of many, Sweden
Can't you make an extension method that takes and IEnumerable and foreaches on you collection?

zokie
Feb 13, 2006

Out of many, Sweden
Since Ithaqua said it was so easy getting the C#-cert I decided to try, but being cautious I'm gonna read the exam reference first. I found some pretty neat things in there I thought I'd share.

First, it advocates assigning an empty delegate to EventHandlers as has been discussed here and also mentions that EventHandlers can ONLY be assigned a null value from within it's class. This saves you from having to null-check the handler all the time (if(OnSomeEvent != null)).
code:
public event EventHandler OnSomeEvent = delegate { };
public void RaiseSomeEvent() {
	OnSomeEvent(this, EventArgs.Empty);
}
Second, you can have multiple loop variables :)
code:
for(int x = 0, y = 10; (x < 10) && (y > 0); x++, y--)
	Console.WriteLine("x: " + x + " y: " + y);
//Prints
//x: 0 y: 10
//x: 1 y: 9
//x: 2 y: 8
//x: 3 y: 7
//x: 4 y: 6
//x: 5 y: 5
//x: 6 y: 4
//x: 7 y: 3
//x: 8 y: 2
//x: 9 y: 1
Thirdly you can create your own scopes with curly braces.
code:
	{
		var index = 0;
		while(index < 10)
		{
                                     
		}
	}
	index = 1 // Unless this line is removed this won't compile!
And finally you can use the XOR (^) operator for other things than bitwise.
code:
	var t = true;
	var f = false;
            
	if(f ^ t)
		Console.WriteLine("true");
	if(t ^ f)
		Console.WriteLine("true");
	if(t ^ t)
		 Console.WriteLine("false");
	if(f ^ f)
		Console.WriteLine("false");
//Prints
//true
//true

zokie
Feb 13, 2006

Out of many, Sweden
Am I the only one that want's to puke on doing stuff that way? It looks like you wan't to tie classes to tables but use richer objects in your code but still use the EF classes causing you to use this strange behavior. I'm sure this isn't your real business case but from you example it looks like Students and Addresses map One-to-Many so how does you DTO know which address to edit?

I either use richer classes or handle everything separately and use transactions if necessary...

zokie
Feb 13, 2006

Out of many, Sweden
A database cluttered with stored procedures :allears:

zokie
Feb 13, 2006

Out of many, Sweden
Don't expose IQueryable<T>!! You should be able to figure this out by yourself, but when you think: "I don't want a repository pattern because then I can't test/expose IQueryable" you are a danger to yourself and those around you.

zokie
Feb 13, 2006

Out of many, Sweden
I always get burned by assigning stuff to the backing field and not the property which doesn't cause a notification. You might also be on to something with the x:Name maybe causing it to become a regular property or field and not a DependencyProperty or something

zokie
Feb 13, 2006

Out of many, Sweden
So how do people deal with styling for WPF? Anyone know of any good themes available for a non-shitload of money? Are the things by Telerik worth the money?

zokie
Feb 13, 2006

Out of many, Sweden

Uziel posted:

MVC question:
I have a view, whose purpose is to say "We can't accept your submission and here is why". It takes a model with many fields and displays only the ones relevant to the reason why the submission should be rejected. I want this to be override-able with a button that says "Do it anyways" and just pass the full model back to another action in the controller that sends it to the next relevant view.

Is there an easy way to pass that full model along on form submit other than recreating the full model as hidden fields in the form?

When I need to do stuff like this, I always use hidden fields.

zokie
Feb 13, 2006

Out of many, Sweden

Mr. Crow posted:

WPF Question.

Is there a technical reason (or otherwise) to not use Application.Current.Windows?

Backstory, we need to check if there are any modal views open before creating and showing another modal view from the 'backend', and then if there is one, don't create/show the 'backend' view.

Doing some research the common suggestion seems to be have some sort of view manager that's responsible for keeping track of open views, and in lieu of that you can use Application.Current.Windows. My concern is everyone seems to hint that using App.Current.Windows is a bad thing, but I'm having trouble finding out why.

We have a couple very specific view managers elsewhere, but don't really have a need for a general all-encompassing one beyond this specific instance and I'm getting pushback for creating an all-encompassing ViewManager at this time.

Can the user create new dialogs still? To handle dialogs in an application where all windows were modal I've previously used a Stack<Window> in a view manager, we needed to keep any window open until the viewmodel had finished with any remote calls and then close it. So when a new dialog needed to be opened we pushed it on the stack and then when we're done and need to close it we pop it of and close it.

Still it seems to me that any solution for maintaining control-flow with views doing MVVM seems to involve some kind of horror...

zokie
Feb 13, 2006

Out of many, Sweden
Who ever said the Programming in C# cert. was easy wasn't kidding. It was really loving easy, so thanks :)

zokie
Feb 13, 2006

Out of many, Sweden
Why not make your classes more pure and turn things that need a date into a method with the date as a parameter? IsValid(DateTime date) instead of properties and the like. In the end you need to get the date from somewhere, but I think it's better to explicitly provide something like a date as a parameter instead of as dependency...

zokie
Feb 13, 2006

Out of many, Sweden
I'm a bit unsure about what you are trying to accomplish, but one big difference between Java and C# is that in Java all methods are virtual by default were as you have to explicitly declare them as virtual to be able to override them in C#.

zokie
Feb 13, 2006

Out of many, Sweden
So I've encountered a strange thing happening to me in WPF. Calling this method:

code:

public void AddBar(Bar bar)
{
	var list = aTabControl.ItemSource as List<Bar>;
	list.Add(bar);
	
	myTabControl.SelectedItem = bar;
}

Will select the new TabItem, but won't "highlight" its headerthingy. Because of the Visual Tree and stuff. To fix it I tried:

code:

public void AddBar(Bar bar)
{
	var list = aTabControl.ItemSource as List<Bar>;
	list.Add(bar);
	myTabControl.Dispatcher.Invoke(UpdateLayout);

	myTabControl.SelectedItem = bar;
}

But that didn't work. So I tried this:

code:

public async Task AddBar(Bar bar)
{
	var list = aTabControl.ItemSource as List<Bar>;
	list.Add(bar);
	await myTabControl.Dispatcher.InvokeAsync(UpdateLayout);

	myTabControl.SelectedItem = bar;
}

And it works :wtc:

zokie fucked around with this message at 15:08 on Dec 6, 2013

zokie
Feb 13, 2006

Out of many, Sweden
And here I thought dynamic was about working with JSON easier or when you don't feel the need to create an interface for some shared properties or whatever...

I guess I should be glad I don't have to deal with COM stuff...

zokie
Feb 13, 2006

Out of many, Sweden
I'm having trouble with using a DataGrid in WPF for the first time. What happens is that when you select the placeholder for a new item any further input adds a new row in the DataGrid but doesn't switch focus or anything. So if you click the bottom row and start typing you're gonna end up with as many new rows as keys you pressed... I hooked up some eventhandler and selected the item with index count -1, but this doesn't fix things because I still lose the first character that "initiated" the creation of the row. I hope this isn't intended behavior because it's stupid...

Does anyone have any tips or ideas for me to try?

zokie
Feb 13, 2006

Out of many, Sweden
Have you tried contravariance and generic type constraints?

Edit: Sorry for killing the thread :( Also maybe this could help you?

zokie fucked around with this message at 15:14 on Feb 11, 2014

zokie
Feb 13, 2006

Out of many, Sweden
Anyone done 70-461, sql something something? Was it hard?

zokie
Feb 13, 2006

Out of many, Sweden
Google gave me this, is it a desktop application or a web-thingy?

Adbot
ADBOT LOVES YOU

zokie
Feb 13, 2006

Out of many, Sweden
What problem are you trying to solve exaclty? Embrace the null instead. Absolutely use nullables for keys and such. Using int? keys and the like has made my life so much easier. What you are doing just seems strange, and I really don't see any benefit to it.

  • Locked thread