|
This is all fairly basic stuff. What, exactly, is your background? How did you end up with this task? Judging by the number of questions you have posted recently, it seems that you are turning straight to Code Project for solutions.
|
|
|
|
|
I have 2 years of experience with C# and 1 year with VB. I only ask the simple questions here. I do not place the difficult questions here since I do not think that is what this message board is setup for.
|
|
|
|
|
So, how do you think you should solve this problem? Talk me through the problem and potential solutions. Break it down into little steps; you'll be surprised just how easy it is to solve when you know this.
|
|
|
|
|
Based on your other responses.
You were told how to create directories.
You already know the name of the file you must look for. If you don't then you MUST figure that out BEFORE you code.
So now that you know the name, from your example there is one name, so you use an 'if' to compare the name of the file to the file that you have.
So the pseudo code looks like
fileName = GetFileName()
if (fileName equals "Customer Inventory")
if (! Output dir)
CreateOutputDir()
WriteFileToInventoryDir()
else
WriteFileToMainDir
|
|
|
|
|
I am having a problem using linq to sql in a C# desktop application that connects to sql server 2008. Basically if the CustId already exists in the Trans table, I do not want to insert a new row into the table. However the code listed below does not work.
**Note the CustId is not the primary key of the table. there is an identity key that is the primary key of the table.
eDataContext rptData = new eDataContext();
var eupdate = (from a in rptData.Tran
where a.Cust_ID == CustId
select a).SingleOrDefault();
if (eupdate != null)
{
log.Info(CustId + "already exists in the Trans table");
}
else
{
Trans subCustid = null;
subCustid = new Trans();
subCustid.Package_ID = pkgid;
rptData.Trans.InsertOnSubmit(subCustid);
rptData.SubmitChanges();
}
Thus can you tell me what I can do to not allow a row to be inserted into the Trans table when the CustId already exists in the table?
|
|
|
|
|
In a C# 2010 desktop I have one solution file that have 4 separate project folders. In two of the project folders I need to access two of the same tables using linq to sql. I do not know how to make each project folder be aware of the two tables. Thus I embedded basically the same *.dbml files within each separate project folder.
I do not think what I did is the best solution. Due to this fact, I have the following questions:
1. Is there some kind of a way that each project folder can have access to the same *.dbml file? If you can you tell me how to accomplish this goal?
2. One of the project folders is a proxy file. Is it a good or bad idea to have a proxy class (project) folder update a *.dbml? Can you explain your answer to me?
|
|
|
|
|
The solution is to create a single library project that exposes the database as an object library.
Then both of the application projects can use this library and no worry abouy what you're asking about at all.
|
|
|
|
|
Can you show me code and/or point me to a link that will show me how to the code as you are just suggesting needs to occur?
|
|
|
|
|
Not really. It's a matter of thinking about the problem the correct way. Think about this... you're writing a library that interacts with the database. What do you have to expose in the way of methods and return types that any application you write can use that library and not worry about how the database is implemented at all??
Try getting a book on the Entity Framework and you'll see what I mean.
|
|
|
|
|
hello , i have a question about MdiParent click event , maybe its abit stupid to asking you guys this question , but honestly i don't know it .
i want to write some code in mdiparent click event , that's mean , if i clicked the mdiparent form or the mdiparent(page) , sth w'll happened , noticed (i don't want to put a button or label or what ever else ) i just want to click on the mdiform and some code get run , i have tried the click event _ Mouse Clicked _ and some other events but nothing so far .
any help , i'll appreciate that .
|
|
|
|
|
mohammadkaab wrote: i want to write some code in mdiparent click event , that's mean , if i clicked the mdiparent form or the mdiparent(page) , sth w'll happened , noticed (i don't want to put a button or label or what ever else ) i just want to click on the mdiform and some code get run
The click-event simply isn't fired for a MdiContainer. Hence, what you want is not possible.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I have an application which will be shown on TV in the customers' waiting area to show the ticket numbers.
I want to know how can I display a live TV in the same application within a panel or a component so it will be part of the screen?
|
|
|
|
|
jrahma wrote: I want to know how can I display a live TV in the same application within a panel or a component so it will be part of the screen?
There's no "TV-control" in .NET. How did you plan on getting the TV-information in Windows?
I've had a Pinnacle-TV card and that came with an application to operate it (and record to harddisk). If you have a similar app, you could use an old trick[^], I believe you used that one before.
Best would be to "search" on the COM-tabpage from the "Add References" dialog in Visual Studio. Most of those apps use a COM-component to display their stuff, and it might be easy to re-use it.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Has anyone done this? I've tried using wmi via c sharp with the namespace
\\[servername]\ROOT\cimv2\dell:Dell_RemoteAccessServicePort and haven't gotten anywhere.
Our drac IP list is not accurate and I'd like to have a program that queries a server list and gives an update list from WMI or some other source. I've seen racadm do it locally, so it must be stored somewhere that is accessible from the OS.
I just did a procmon on racadm and could not find anything as far as how it generates the drac ip when it does a query. Thanks for reading.
modified 7-Sep-12 16:38pm.
|
|
|
|
|
I'm refactoring a WinForms project. I have 2 forms that do the same thing, except the data entities passed in are slightly different, so the guy who wrote them decided to duplicate the forms instead of making one form that works for both. So I'm refactoring them.
Assume I have these 2 entites:
public class Entity1
{
public string SomeProperty { get; set; }
public string Name { get; set; }
}
public class Entity2
{
public string SomeProperty { get; set; }
public string Caption { get; set; }
}
In the CTOR of the form I have:
public partial class Form1<T> : Form
{
T entity;
public Form1()
{
InitializeComponent();
entity = (T)Activator.CreateInstance(typeof(T));
}
}
The problem is I now need to set properties on the object passed in. In most cases the 2 objects have the same name properties, but ther are differences.
What is the right way to work with this object? Seems like I have no choice but to cast.
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
What I think you need is:
public partial class Form1<T> : Form where T : new()
{
T entity;
public Form1()
{
InitializeComponent();
entity = new T;
}
}
|
|
|
|
|
yes, but I still wont have access to the properties, at least without doing
Type type = typeof(T);
var prop = type.GetProperty("Name");
prop.SetValue(entity, "TheName", null);
not sure I like this because the property names would have to be listed in calls to GetProperty.
I dunno, what do you think?
If it's not broken, fix it until it is
|
|
|
|
|
OK
What you need to do is create and interface:
public interface IEntity
{
string SomeProperty { get; set; }
string Caption { get; set; }
}
Then use this interface on the classes:
public class Entity1 : IEntity
{
public string SomeProperty { get; set; }
public string Name { get; set; }
}
public class Entity2 : IEntity
{
public string SomeProperty { get; set; }
public string Caption { get; set; }
}
Then use is in the generic:
public partial class Form1<T> : Form where T : IEntity, new()
{
T entity;
public Form1()
{
InitializeComponent();
entity = new T();
}
}
|
|
|
|
|
Can't use an interface because most of this code is already in place. Have to work with what I have.
However, I think this will do it:
public partial class Form1<T> : Form
{
T DataItem;
Type type = typeof(T);
public Form1()
{
InitializeComponent();
var DistrictId = 10;
DataItem = (T)Activator.CreateInstance(typeof(T), DistrictId);
setProperty<string>("Name", "The Name");
setProperty<bool>("LinkedToBilling", true);
setProperty<DateTime>("BillingStartDate", new DateTime(2012, 01, 15));
}
private void setProperty<T>(string PropertyName, T Value)
{
var prop = DataItem.GetType().GetProperty(PropertyName);
if (prop != null)
{
type.GetProperty(PropertyName).SetValue(DataItem, Value, null);
}
}
}
This will allow me to attempt to set a property. Remember that in this case most of the properties exist on both objects. But this code allows me to not have multiple IF blocks. I think it's clean, and it solved the issue.
If it's not broken, fix it until it is
|
|
|
|
|
Why bother with generics if you can't use them? You are better off doing things in a straight forward manner twice, than once in a non-obvious manner.
setProperty<string>("Name", "The Name");
setProperty<bool>("LinkedToBilling", true);
setProperty<DateTime>("BillingStartDate", new DateTime(2012, 01, 15));
May look like a nice, elegant solution, until you realize that
setProperty<string>("Name", "The Name");
setProperty<bool>("LinkedToBiling", true);
setProperty<DateTime>("BillingStartDate", new DateTime(2012, 01, 15));
doesn't give a compiler error.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: doesn't give a compiler error.
Exactly. If a property doesn't exist, then I don't want a compiler error.
If it's not broken, fix it until it is
|
|
|
|
|
I am going to have to go out on a limb here and say that yes you do. If you don't then you probably need to reconsider your approach. You are refactoring code here, refactoring implies, improving, not reducing lines of code, increasing complexity, or reducing maintainability. This fails the smell test. If you can't add improvement, don't refactor.
|
|
|
|
|
It solves what I'm trying to accomplish.
Lines of code, prettyiness, ect, are not the prime concern. I'm trying to make a form work for more than one entity.
Added multiple block of duplpicate code is exactly what I DON'T want.
Having said that, do you have an alternate solution?
If it's not broken, fix it until it is
|
|
|
|
|
I wouldn't use it but you can use the wrapper pattern below. It isn't elegant, but is a way to handle what you want without changing the underlying objects using interfaces, which really is probably the best solution.
public class Wrapper{
private Object mObject;
public string Name{
get{
string result = null;
if(mObject is SomeTypeIRecognize){
result = ((SomeTypeIRecognize)mObject).Name;
}
return result;
}
}
public Wrapper(object o){mObject = o;}
}
|
|
|
|
|
That is exaclty what I'm trying to avoid - lots of IF blocks all over the place.
The generic & reflection code I posted will work fine.
If it's not broken, fix it until it is
|
|
|
|