|
Say, Luc, I have a related question, since you've been helpful on project I've been working on. When you are dealing with classes that represent real world objects that need to be handled in similar ways, do you define them in a separate file, or just inline where you need them?
For example, the project I'm working on is intended to manage about 6 types of devices used in electrical substations. I'm only working on one type right now, because the techniques that work there will work for the others. I've defined the one type in the main program form, but I'm thinking it will be more convenient later to create a library file containing all of the devices and 'using' it whenever I need to later as the program develops.
I really prefer to keep everything in one file (from past history with procedural programming) because it's easier to follow the program flow. But I can already see that this approach will be a nightmare with a Windows program if it grows beyond a few thousand lines. And it will...
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Hi Roger,
I don't have any strict rules for this; I don't start a new file for every new class (or type) I create; however I try and keep most files at less than 500 lines of code, using either separate classes, or partial classes, or inheritance as outlined before.
|
|
|
|
|
Thanks, Luc!
I moved the Recloser class to its own file and namespace, then modified the rest of the project to 'use' my new namespace. That file will grow, adding new equipment types as I expand the app, and defining them on the fly, wherever I happen to need them is going to get really ugly. This is much better, though it was a scary moment there when I commented out my original class definition on the main page and clicked Build Solution. It worked very well, much to my surprise.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
It's good that you're thinking about this now while your code base is small
I find that Windows Forms code is pretty easy to keep tidy. If you feel like a given class is getting untidy, it's probably time to decompose it into simpler components. That said, don't over-decompose to start with as this creates unnecessary levels of indirection. Defer refactoring until it makes sense (e.g. if you want to re-use common functionality in multiple places).
The best tip I can give is to be rigorous about namespace organization and use meaningful type names so that someone else (or you 6 months from now) can know where to start looking.
|
|
|
|
|
I think you've gone along the same lines as Luc (above) so that's another vote for decomposing.
I'll have a look though the code and see where I can best split it up.
Many thanks
"If you can't explain it simply, you don't understand it well enough" ~ Albert Einstein
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." ~ Paul Neal "Red" Adair
Now reading: 'The Third Reich', by Michael Burleigh
|
|
|
|
|
These might help (or drive you mad as they do me!)
StyleCop and FXCop - they are both free AFAIK
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Oh man, FXCop... that brings back (painful) memories....
I used it about 6 years ago on a team with lots of junior developers (and senior developers who thought they were above adhering to conventions). It was effective, but comes with a lot of overhead.
On a team of competent developers, I much prefer a document describing the style convention rather than a tool that enforces it. Come to think of it, I prefer teams of competent developers outright
|
|
|
|
|
I didn't say I would use it through choice
Like you say though, for juniors in particular it can stop some bad habits (and introduce some different ones ), so I thought it may be of interest to the OP
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Same form runs every time i run even if the address provided is changed in the program in c sharp. Plz help
|
|
|
|
|
Well that is one of the most obscure questions I have seen this week.
What is this address you are providing?
What are you providing the address to?
You seem to be confused between data and application. I presume an address is data and the form is coded, if so address does not define a form but the data in the form.
Try stepping through the code and inspecting the value of the variables as you progress, this will tell you what you are getting instead of what you expect to get.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: Well that is one of the most obscure questions I have seen this week.
Well it is only Tuesday (here), so there's plenty of time to beat it
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
when login credential are succesfull i want to show mdi form and close login screen. in VB.net i have done it simply as below and is working fine:
Me.Dispose()
Me.Close()
AttendanceMDI.ShowDialog()
in c# i did it like
this.Dispose();
this.Close();
AttendanceMDI.ShowDialog();
but it closes the application
plz help....
|
|
|
|
|
Use Show instead of ShowDialog and just hide the login form after the call to Show method.
Do not close or dispose the login form.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
The login form should NOT be your startup form. The MDIParent form should be the startup and if it finds that the user needs to login, it shows your login dialog.
|
|
|
|
|
Hi. Whenever internet explorer opens a window should popup. I am want to do this using dotnet. Please help me. How to identify internet explorer opens using dotnet code?
|
|
|
|
|
I guess a windows service that will regularly check for iexplorer.exe in the processes running on a system should work. If, it finds the process, start your windows application then.
I also think you can probably make your application as IE add-in. You can find help creating add-in here[^].
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Hi, I am new at this so please go easy on me...;)
I am working on a treeview control in visual studio 2008 using visual basic. I am trying to populate the treeview with data from 2 sql database tables. I am able to populate the parent nodes but cannot populate the child nodes at this point. [Note: With my data, Parents are "Firms" which are stored in the Firm's table and Childs are "Funds" and are stored in the Funds table. The two tables are related using a FK with FirmID connecting the two tables].
My code to populate the parent node is as follows:
'populate the tree view control
TreeView1.Nodes.Clear()
Dim ParentRow As DataRow
Dim ParentTable As DataTable
ParentTable = FirmFundDataSet.Tables("RAInput_Firms")
For Each ParentRow In ParentTable.Rows
Dim ParentNode As TreeNode
ParentNode = New TreeNode(ParentRow.Item("FirmName"))
TreeView1.Nodes.Add(ParentNode)
Next
The ultimate goal of my project is to use the treeview as a way to navigate other forms in my project.
I have seen some examples on the web that show a solution were you relate the two datatables (e.g. dataset.Relations.Add(etc)) and then use some code like the following to add the child nodes. This does not work for me because I get an error that states that a relationship already exists between my tables (note: I added a relation in vb to tables that are related in sql, so this kind of makes sense. Not sure how to work with an existing dataset relationship though).
''''populate child'''''
Dim childrow As DataRow
Dim childnode As TreeNode
childnode = New TreeNode()
For Each childrow In parentrow.GetChildRows("FirmToFund")
childnode = parentnode.Nodes.Add(childrow(2))
Next childrow
Any help would be appreciated.
|
|
|
|
|
Hi All,
I am using help provider control.
my requirement is when i press F1 i should get the .chm file -- I done
but my .chm file should highlight the "Index" part as the default however, I want to highlight the "content" Tab not the "index" Tab.
For example if i am seeing the customer form and when i hit the F1 it should highlight the Customer page which is in the .chm file
Thank in advance
Ramkumar
("When you build bridges you can keep crossing them. ")
http://ramkumarishere.blogspot.com
|
|
|
|
|
I need to be able to resize my form but i don't want the ControlBox to be visible...
I've tried set ControlBox = False, FormBorderStyle = Sizeable, and Text = (Empty)... But i still could see the small thin border surrounding the form.
I need to make it completely disappear, just like when using FormBorderStyle = None
Is that possible???
Please helpppp
Thanks
|
|
|
|
|
Not without digging down into some ugly Win32 APIs. Why not set the FormBorderStyle to None and write your own resize code?
If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.
|
|
|
|
|
hi All
I am new to window application.plz help...
I want a datagridview in this I will have a row and "add" button in the last colomn,
when i click the add button same row should repeat.And if i want to delete it should be possible(window application)
Please help me with this.
thanks in advance
Ramkumar
("When you build bridges you can keep crossing them. ")
http://ramkumarishere.blogspot.com
|
|
|
|
|
You can use DataGridViewButtonColumn to add buttons to your gridview. Then, handle its click event to insert/delete rows.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
This question has been answered so many time and so well covered this may help you[^]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm back at it, trying to build an app to manage substation equipment. I had to take a little break to design a substation and some new sewer plant motor control circuits, but I'm back at it and still confused. Before you tell me to read a book, I have read two, and ordered another. But the third book won't arrive until Friday, and I have a five day weekend for the Thanksgiving holiday I'd like not to waste. I've also reduced the scope of the problem to manage one kind of device, instead of tackling 4 different types with entirely different information to manage. I figure that if I can get one to work, it won't be nearly as hard to expand as it would be to write it all at once.
I have a SQL Server DB with several tables - a master that holds equipment information that is invariant, a status table that holds information about the current location, last service date, and number of operations since last service, and a pair of tables to hold the histories of readings taken and services performed on each device. I have created a boilerplate app with a main form, and that form has a menu to allow the user to Add, Edit, Move, Service, Read, or View devices. I know this is easy to anyone who does it all the time, but I am well and truly stuck for ideas about where to go from here.
I've tried before to use a sequence of forms, hiding and showing them, to walk a user through a few pages of data entry, but it turned out to be problematic to transfer the data between forms. I've tried using dialog boxes for each step, but had similar problems. I tried using data-bound controls on each form but that quickly became a nightmare, so I'm leaning toward a solution that has the main form collect all the data, then pass it off to functions that update the database. Besides, I believe the separation of data functions and user interface makes good sense from a maintenance point of view.
Is this a place where a MDI is appropriate? Or is the idea of using multiple forms in sequence a better approach? Or should I stick with one form and change the visibility of controls as the user moves through the process. I'm lost here. I think the question is one of architecture, rather than procedure or actual coding, but I don't know if I'm even asking the right questions yet. I've read lots of stuff about making and using forms, but not one example of using two or more in the same app has appeared anywhere I've searched. That leads me to believe that I'm barking up the wrong tree entirely, and there's some secret method used by almost every modern program I've used that isn't written up anywhere. Any book can tell me how to make a form, and I have several that do, in multiple languages. But not one of them mentions movingsfrom form to form, persisting data along the way, until the time comes to save the data from all of them.
Can someone get me started? Pretty please...
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Wrong forum so consider yourself .... Excoriated, where the bloody dictionary when I need it.
The is definitely a design issue and we all have our favourite flavours. Here is mine, caveat most of my apps a batch management so no transactions to speak of.
Main form with a navigation control on the left, menu for methods not based on a specific piece of data (exit, process, help and reports), an icon strip for CRUD keys
Changing selection in the nav control populates a list in the main body of the form. From the list you pop a dialog ALWAYS, never edit in a list control. You can either pass an ID or an object to the dialog in the constructor. Your list has the ID of the records you want to work with so I pass that to a dialog designed to work with that object.
When the dialog is opened it inspects the ID passed in, if you passed a 0 (ADD) then it gets an empty datatable from the database, if there is an id (EDIT) then it gets that record from the database. The class that gets the datatable (designed for that object) also populates the object. I then bind the form to the object. When the user edits the form the data is passed to the object via the binding.
When the user saves the dialog I write the data back to the database and return DialogResult.OK to the main form and closes.
Main form detects the OK and reloads the list control with the new record.
I rarely need more than 3 levels of nested dialogs for any operation.
BTW, Last Serviced date is redundant on the Tool table, Select top 1 from service table should do it. Otherwise you need to reconcile between the last service field and the service table, what happens if someone deletes a service record?
|
|
|
|