|
As Rob has said, deriving from a base class specialises something - a book does not derive from a previous book except when it is an expanded version: the Directors Cut if you like.
Think about it: a "Book by Charlotte Bronte" derives from "Book", and so does a "Book by Terry Pratchett" - but that is pretty much the only thing they have in common: the elements which are common to all books (Pages, a cover, a title, an author) and so forth.
You wouldn't overload a method to get a number of pages from two different books, because the number of pages is a property of the individual instance on the book. But... you might overload it to get different information which is also instance specific:
public class Book
{
private int pages;
private List<int> chapters = new List<int>();
public int GetPages()
{
return pages;
}
public int GetPages(int chapter)
{
int lastPage = pages;
if (chapter >= chapters.Count || chapter < 0) return 0;
if (chapter != chapters.Count - 1) lastPage = chapters[chapter + 1];
return lastPage - chapters[chapter];
}
}
This has two overloaded GetPages methods.
If you don't supply any parameters it returns the number of pages in the book.
If you pass it an integer, it returns the pages in that chapter.
The type of the parameter determines which version of the method gets called, and thus what the method does.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
You are right but you need make some modifications to simplify it.
|
|
|
|
|
//PRODUCT CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
[Serializable]
public class Product
{
private string ProductID;
private string ProductName;
private float Price;
private int Quantity;
public Product()
{
}
public void Read()
{
Console.WriteLine("Enter Product ID : ");
ProductID = Console.ReadLine();
Console.WriteLine("Enter Product Name : ");
ProductName = Console.ReadLine();
Console.WriteLine("Enter Price : ");
Price = float.Parse(Console.ReadLine());
Console.WriteLine("Enter Quantity : ");
Quantity = int.Parse(Console.ReadLine());
}
public void Show()
{
Console.WriteLine("{0}\t\t{1}\t\t{2}\t\t{3}", ProductID, ProductName, Price, Quantity);
}
}
}
//MAIN PROGRAM CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
List list = new List();
int op;
try
{
Stream stream = File.Open("F:\\Product.obs", FileMode.Open);
BinaryFormatter formatter = new BinaryFormatter();
list = (List)formatter.Deserialize(stream);
}
catch (Exception ex)
{
}
do
{
Console.Clear();
Console.WriteLine("1.New product");
Console.WriteLine("2.List All");
Console.WriteLine("0.Exit");
Console.WriteLine("------------------");
Console.WriteLine("Enter Choice : ");
op = int.Parse(Console.ReadLine());
switch (op)
{
case 1:
Product p = new Product();
p.Read();
list.Add(p);
break;
case 2:
Console.WriteLine("Product Details");
Console.WriteLine("--------------------");
Console.WriteLine("ProductID\t ProductName\t Price\t Quantity");
Console.WriteLine("------------------------------------------");
for (int i = 0; i < list.Count; i++)
{
p = list[i];
p.Show();
}
break;
case 0:
Stream stream = File.Open("F:\\Product.obs", FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, list);
break;
}
Console.ReadKey();
}
while (op != 0);
}
}
}
|
|
|
|
|
First, I'm not reading it like that - use the code block (<pre> tags) to preserve the formatting so the code is readable.
Then, explain you problem in reasonable detail in the question, instead of in the title - remembering that we can't see your screen, access your HDD, or read your mind.
Explain what you are having problems with - what the code does and doesn't do, and why. At the moment, you've just dumped some code on us and said "fix this".
Help us to help you!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I inherited an app that was created using EF6 - Model First. How do I update the database after making modifications to the tables? If it was code first I could use migrations to handle it, but I'm hesitant to try that with this model.
|
|
|
|
|
I think you need to clarify your terminology.
The "tables" ARE the "database".
Did you modify the "database" and now want to update the "model"? In which case, you open the ".edmx", right-click the design surface, and then click "Update model from database...".
... Backing up your project first, of course.
modified 25-Jul-14 19:49pm.
|
|
|
|
|
Doesn't that drop all the tables and their data?
|
|
|
|
|
Why would you think what I suggested "drops the tables ...".
The "model" is the "code".
"Update model from database..." READS the database schema and updates the "classes" that define the "entities" in the "model".
|
|
|
|
|
I am consolidating about 10 databases into one. I have ran across multiple cases in the older databases where they have a combo-box linked to a database table with under 10 items. What would be the best way to handle the small amount of data ? Do I create a strongly typed array or do I keep the 20 different tables that will never have any data added ?
|
|
|
|
|
Sounds like the tables might be holding enumeration types values. If so, they're probably anchored by foreign keys on other tables. Do they have just two columns, a key and a value?
It's a common problem, because in code you might use an enum to represent these values and you end up in the situation of how to keep the database and code in sync.
You could remove the tables, but that might render the database a bit meaningless without the application tier in place, limiting what could be achieved via a stored proc for instance. You can't really create enum types at runtime, although you could create the same effect using static members on a class.
Probably the best way would be to have them as a collection of key/value pairs.
I can't really offer a definitive answer I'm afraid, but for completeness it might be advisable to keep them.
Regards,
Rob Philpott.
|
|
|
|
|
I have jumped both way in the past, leave multiple emun tables or stick them into a single key/value table. I find the multiple table solution the best mainly for the FK constraint capability.
I also use my code generator to create the enum values in the application in a class called... Enums - go figure!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: I also use my code generator to create the enum values in the application
That has been my solution in the past too!
Avoids all that nasty ORM stuff. Also getting it to do a runtime check that things are aligned is useful, in case someone in their wisdom decides to reassign the enums..
Regards,
Rob Philpott.
|
|
|
|
|
Mycroft Holmes wrote: a single key/value table
I have only done that sort of thing once, but it's really only to provide translations when reporting.
But in general, it sounds like a bad idea if you are relying on the table for referential integrity.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
The problem that I find with enums is you may not be adding stuff to them but what happens if you remove an item? The rest of the items move up in the numbering scheme unless you explicitly provide the values of each enum member. If you're using that value in a database, you'll be changing the meaning of all of your stored values by adding/removing a single line of code in your enum definition.
Using an auto numbering enum may look good up front, but can bite you in the ass later on when adding/removing members to them.
|
|
|
|
|
Dave Kreskowiak wrote: The rest of the items move up in the numbering scheme unless you explicitly provide the values of each enum member
You only ever get bitten by this once, then you dig into your code generator and explicitly number the items
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Fortunately this has never happened to me because I saw the problem before I even wrote any code.
Other people I've worked with in the past, however, didn't see the problem even after their applications starting crapping all over themselves. Ask them what they changed and it's always "nothing" and then 20 minutes later the truth comes out and they changed and auto enum.
Enums are very simple things to understand but yet extremely difficult for some people for some reason.
|
|
|
|
|
For what it's worth - the way I set up drop down values is in one database table.
Below is an over-simplified example.
Doing this allows me to manage all the dropdowns, irrespective of application and control, for the whole ERP system within one reference table:
id application control_name item active position
17 proj proj_cmb Tier1 1 1
18 proj proj_cmb Tier2 1 2
19 proj proj_cmb Tier3 1 3
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
That concept is seductive, I had not considered it across apps, but I like my FKs too much to do that. We do 90% of our processing in the database so that always gets first consideration, nature of the beast (not ERP).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
As our ERP system grew, which is written in house (previously with the lead developer and me but now solely by me) we decided to split the different areas of the ERP into separate applications in order to make development/maintenance easier(the users did not appear to mind).
From the very early days I started shifting hard-coded lists, within the UI code, out into the back-end database. I have also written some tools to help me administer this database.
In practise what this means is that I can make quick changes to lists within applications without having to roll out new releases to users.
The example I gave above is an over-simplified version of what I have built.
The reference table, for lists, also allows stored procedures to be used for populating lists(with parameters being supplied from the client side) and even allows cascading dropdown design (e.g. country and state dropdowns).
This has made my life so much easier, so I can concentrate on developing new features rather than spending hours on amending the contents of dropdowns.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Thanks you guys are awesome
|
|
|
|
|
Unless there is a compelling reason to combine them, I'd keep the tables separate.
As others have also said, I can generate an enum from them. GenOmatic[^]
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
Hi All,
I use the rdcl report with c# web application and I have a 2 questions:
1. Is it possible to create the rdcl report with dynamic dataset.xsd, if yes how?
2. Is it possible to show the rows as header columns as the following:
we have Customers datatable with columns ID,Name and by default shown like this,
ID Name
1 zead
2 jan
but the customers datatable columns not have a static columns ID,Name..
it may be contains city, address, phone
(dynamic columns).
Please help me ASAP
|
|
|
|
|
|
Greetings,
I'm using a crystal report and using it to make a sales report and I want to sort the reports displayed based on the date of the sales order what I should do I create a parameter field and its type is Boolean what else I should do what is the formula to write to do such sorting
|
|
|
|
|