|
Won't work I'm afraid. The OP has properties in the derived types that won't work here because they are more specialised.
|
|
|
|
|
The big issue you have here is that properties in the derived type aren't present in the base type, so you can't really declare app as BaseApplication. Well, you can, but you need to cast to the derived type to access the properties. What you could do is something like this though:
BaseApplication app = null;
switch (courseType)
{
case "31":
app = CreateStudentApplication();
break;
}
if (app != null)
{
app.Save();
}
....
private StudentApplication CreateStudentApplication()
{
StudentApplication app = new StudentApplication();
SetBaseInformation(app);
app.SupportNeeds = SupportNeeds.Text;
return app;
}
private void SetBaseInformation(BaseApplication application)
{
application.FirstName = FirstName.Text;
application.LastName = LastName.Text;
}
|
|
|
|
|
Psst.. strategy pattern!
..and you might want to program against a simple and small (or even multiple) interfaces
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I thought of an interface but couldn't see how it would work.
Strategy pattern sounds like a proper programming thing and not something a hack merchant would be able to do
|
|
|
|
|
suzyb wrote: I thought of an interface but couldn't see how it would work.
You can have them at property-level; considered an IFirstName ?
Keep hacking, and you'll learn it as you go. Just a matter of time before you stumble over it
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
suzyb wrote: I don't know how to create the correct object based on the type of applicant
without having a lot of duplicate code.
Generic creation problems are often solved with the Factory Pattern.
Other than that I don't know what you mean by "duplicate" code. If the objects are different than they are different and you shouldn't attempt to generalize. If however the are the related (by design and NOT by your desire to avoid typing) then you should perhaps re-think your design/implementation.
|
|
|
|
|
i need to optimize all tables in a MySQL database automatically. can you please help to make programe c#.net
|
|
|
|
|
- What does optimize mean? What will you be doing with the tables?
- We got a database-forum
- Your question for help on C# is too broad; you make a C# app like all the others, and you can get help with specific questions. You'll have to do the writing yourself.
- Can you show us an example of a table before and after "optimization"?
Looking forward to your answers.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
In our data base have more than 150 tables available. In every day some table have delete and update operation is going. While after the delete memory is stored in temp. When I tried to open schema, it’ll take some time. I need to make faster in my schema. What can I do? That’s only I selected optimize all table in mysql.
Thanks,
P.Alagiri
|
|
|
|
|
I suggest you start in the database-forum; to check whether your indexes are correct, whether you could benefit from partitioning the data, whether your table-structure is correct.. The usual things a DB-admin does when the db is too slow.
C# has little to do with it.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Hi
I’ve a question regarding linq,
I’ve a DB contains main items (Product) and internal item(properties)
Class Product
{
String name
List<properties> propList { get; set; }
}
Class properties
{
String name
String value
}
I would like to know if it possible to create a query that apply on two or more categories on the same internal item at one time
Such as, if the product is "car" and if the car year is 2012 and color is "Red" I would like to get this record
List< Product > DB;
I know the syntax below is wrong, but this is the idea I wish to do
Enumerable< Product > itemQuery = from item in DB where item.name=="car"
where
(
from prop in item.propList
where (prop.name.Equals("Color") && prop.value == "Red") && (prop.name.Equals("Year") && prop.value == "2012")
select field
).Any()
select item;
|
|
|
|
|
First off, this should have been posted in the LinQ forum LinQ Forum[^], but as you posted here, I will answer here.
You can use the Contains keyword to find if the item's property list contains the required property, something like this:-
var itemQuery = DB.Where((i) => i.name == "car" &&
i.propList.Contains((from prop in i.propList where prop.name == "Colour " && prop.value == "Red" select prop).FirstOrDefault()) &&
i.propList.Contains((from prop in i.propList where prop.name == "Year" && prop.value == "2012" select prop).FirstOrDefault()));
although this looks ugly and seems to be a bit of a hack it will return the correct item.
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Message Removed
modified 21-Aug-12 9:49am.
|
|
|
|
|
thank u all,
it is a good start to begin with
|
|
|
|
|
hi
I’ve implement your idea and it work great, thank u!
I have another question and hope you can assist
The use will choose from UI several filter criteria, so the running filter should be dynamic and not hard coded
Such as sometimes it could be collection.Filter(name1, value1)
Or
collection.Filter(name1, value1).Filter(name2, value2)
collection.Filter(name1, value1).Filter(name2, value2). Filter(name3, value3)
and so on
how can I define by code the dynamic filter?
Should I use recursive ?
int interaction = #UserFilter.count;
DoFilter(string name, string value)
{
While (interaction--)
{
collection.Filter(UserFilter[interaction].name, UserFilter[interaction].value)
DoFilter(UserFilter[interaction].name, UserFilter[interaction].value);
}
}
thanks
ronen
|
|
|
|
|
|
|
I was just going through the C#4.0, I came across with keyword Dynamic. And this is used mainly if we dont know the type at the compile time so that CLR will match that type at the runtime. Then by using this we are giving an extra load to the Compiler, then why to use Dynamic if we know at the runtime what will be the data type??
Any suggestions
Gopesh Sharma
|
|
|
|
|
Keith Barrow gives an excellent description here[^] about the use of dynamic.
|
|
|
|
|
Ive followed this guide: http://studentguru.gr/b/dt008/archive/2010/12/02/querying-a-database-on-windows-phone-7-using-wcf.aspx[^]
I have tree different entries in my SQL and then i launch my application I get tree entries but they are all a copy of the first one.
CODE:
NSSService which is on my ISS.
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
namespace NSSWebServiceApplication
{
[ServiceContract(Namespace = "")]
[SilverlightFaultBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class NSSService
{
[OperationContract]
public List<Server_Log> GetAllServer_Logs()
{
using (NSSEntities entities = new NSSEntities())
{
var allServer_Logs = from x in entities.Server_Log
select x;
return allServer_Logs.ToList();
}
}
}
}
MainPage on the app
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using NSSPhoneApp.NSSServiceReference;
using System.ServiceModel;
namespace NSSPhoneApp
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
NSSServiceClient client = new NSSServiceClient();
client.GetAllServer_LogsCompleted +=
new EventHandler<GetAllServer_LogsCompletedEventArgs>(client_GetAllServer_LogsCompleted);
client.GetAllServer_LogsAsync();
}
void client_GetAllServer_LogsCompleted(object sender, GetAllServer_LogsCompletedEventArgs e)
{
if (e.Error == null)
{
lst.ItemsSource = e.Result;
}
}
}
}
Thanks.
|
|
|
|
|
It was because there was no primary key in the SQL so it used my status as the primary key.
|
|
|
|
|
May I know how can I convert a decimal (eg: 0.3333) to percent format.
I have tried with this code:
ws.Cells[1,1].Value = 0.3333;
ws.Cells[1.1].Style.Numberformat.Format = "0%";
But this give me 33% instead of 33.33%
|
|
|
|
|
Did you try "0.00%"?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
It's work! Thank you so much.
|
|
|
|
|
double t = 0.3333;
Console.WriteLine(t.ToString("##.##%"));
|
|
|
|