|
All you need do is create a static property or member.
|
|
|
|
|
Always the simplest Thanks Pete
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
A single static instance of a data storage class, probably. You could make the data storage class itself static but that makes it trickier to, for example, serialise it. Put this static instance somewhere that all classes have access to. For example
public class DataStore {
public int AwesomenessFactor;
public string Description;
public static DataStore Global = new DataStore();
}
And access it (from anywhere) with
DataStore.Global.(field)
Try to restrict the amount of global data you have, though. Global data is generally symptomatic of a poor design, because (by definition) it's coupled to everything, and excessive coupling is a maintenance problem.
|
|
|
|
|
The use of "Global" data is firstly limited to the search of a client, on a successful search it retrieves their insurance portfolio.
i.e. Search For me Simon Whale
it will return a list of all the quotes (this is restricted to a predefined date range) and live insurance policies that I have and its associated child objects only. This accommodates the archive strategy that management has made as a major requirement of the back office system.
BobJanova wrote: it's coupled to everything, and excessive coupling is a maintenance problem.
This is something that I have to fight / deal with the managements requests on the system design.
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
Simon_Whale wrote: i.e. Search For me Simon Whale
it will return a list of all the quotes This does imply to me that there is a back-end database here of all Customers, and you are querying it to retrieve a specific Customer's data.
In this context, the concerns Bob J. raises here about whether this is a multi-user access scenario, where threading may come into play, and where many users may be viewing the same Customer's data seem very salient. Who gets to change said data ? Who gets read-only permissions.
best, Bill
"The first principle is that you must not fool yourself, and you are the easiest person to fool." Richard Feynman
|
|
|
|
|
Thanks for the response Bill.
I have taken into account the business logic of opening more than one client at a time.
My question at the time was what was the best way of passing this collection of client information through 1 to many different forms, which I knew that I was doing but not in the best way but with the moving towards c# was after how to do it in c# and BETTER.
Luc pointed my towards a more OO method of passing the data between forms by using properties
Thanks
Simon
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
|
may be Global was the wrong term to use. What I am trying to do is at the beginning of the process load a client's insurance portfolio which could include multiple policies and or multiple properties and cars.
I then need to pass this through to various different forms in the main application and I am trying to find out to do this in C#
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
I suggest you keep such data in a Customer object, then pass this object to each and every Form that needs it, with an explicit parameter in the Form's constructor, or through a dedicated public property. That is the OO way of doing things: provide what is needed where and when it is needed.
Making things global isn't a very good idea, as each and every code snippet now can access and modify such data, making the whole app less robust and harder to debug.
|
|
|
|
|
Thanks Luc!
I'll adopt that seeming its a rewrite as such!
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
hi everyone I'm trying to not only make my cod emore readable but also reusable so i'm trying to rewrite the following bit of logic;
protected void Page_Load(object sender, EventArgs e)
{
clsDB = new clsDB();
GetSalesmanDesc();
if (!IsPostBack)
Populate_ddlCustomers();
}
public void GetSalesmanDesc()
{
salesmanList = new List<Salesman>();
try
{
salesmanList = new List<Salesman>();
con = new SqlConnection(strConnString);
SqlCommand com;
com = new SqlCommand();
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "GetSalesmanDesc";
com.CommandTimeout = 300;
com.Connection = con;
com.Connection.Open();
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
Salesman salesman = new Salesman();
salesman.SalesmanID = reader["SalesmanCode"] as String;
salesman.SalesmanName = reader["Salesman"] as String;
salesmanList.Add(salesman);
}
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Fetch Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
con.Close();
}
}
I would really like to try and keep the SQL actions separate from my main procedure so instead of the above I am tryign something like this:
public void GetSalesmanDesc()
{
salesmanList = new List<Salesman>();
clsDB.getSalesmanDesc();
}
the code in clsDB.getSalesmanDesc() is:
public bool getSalesmanDesc()
{
com = new SqlCommand();
com.CommandTimeout = 300;
com.CommandText = "GetSalesmanDesc";
com.Connection = sqlCon;
com.CommandType = CommandType.StoredProcedure;
da.SelectCommand = com;
try
{
sqlCon.Open();
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
Salesman salesman = new Salesman();
salesman.SalesmanID = reader["SalesmanCode"] as String;
salesman.SalesmanName = reader["Salesman"] as String;
salesmanList.Add(salesman);
}
return true;
}
catch (System.Data.SqlClient.SqlException Sex)
{
strDBErrorMsg = Sex.Message;
return false;
}
catch (System.Exception Ex)
{
strDBErrorMsg = Ex.Message;
return false;
}
finally
{
DestroyDatasource();
}
}
Can anyone help me out please?
|
|
|
|
|
Your impulse to separate data access and processing is a good one. It's hard to know what level of advice to offer here – depending on the application anything up to a full blown entity management framework might be the right answer.
Try passing salesmanList to the data access method you just pulled out, or having that method create and return the list.
Also, there's probably a one line Linq query you can run against the database to create this list (I'll leave that to one of our Linq gurus).
|
|
|
|
|
the application itself is a 1 page web app to allow a user to manage product/Salesman data in a gridview, nothing to special. I could rewrite the above bit of code t populate a dataset and use that to populate the ddlSalesman, I'm just wondering how I would do it using the exisiting List that I have created?
|
|
|
|
|
Hello All,
I am developing a Windows Application using C#.
I have set the Gujarati font as the font Property of the TextBox.
When I am trying to store the data in the Database at that time it returns the English Characters. Means it displays the data in Gujarati but when I am trying to store data it returns english..
I have typed something in Gujarati and when i am taking the value it returns the English in code behind..
objGujarati.Name = TextBox1.Text.Trim();// This statement returns english..
also i want to store the Gujarati data in SQL Serevr by using the stored procedure.
Please anyone help me, i am stuck in my work.
Thanks in Advance,
Rakesh Gupta
|
|
|
|
|
Make sure the encoding for the database is set to UTF8 (or some other unicode format). Older database providers default the encoding to ISO-8859-1 (i.e. 256 character ANSI).
|
|
|
|
|
Okay..
Thanks but right now its not my problem.
My Problem is the that returning from the text box is Gujarati.. As i have typed Gujarati thought it returns English..
|
|
|
|
|
The font does not change the content, it only makes it look differently. When you display the text in Wingdings, hardly anyone will be able to read it. Looks like your Gujarati font does something similar like the Wingdings font.
Rather change the input method such that you get Gujarati characters, the .NET Textbox will handle them automatically because it uses Unicode.
|
|
|
|
|
Hi all,
Please I am trying to generate income statement and balance sheet with data from sql using C#. Is there an easy way to go about this, as gridview does not give me the report in the right format. Many thanks.
|
|
|
|
|
Pull the SQL data, iterate the result set and build a custom HTML output and push to a webbrowser control or write out to file as HTML or via a pdf writer.
Just one option!
|
|
|
|
|
dondrey wrote: Is there an easy way to go about this
In general - no.
If you can pull data, regardless of the business use, and display it any way you want then that is easy because there are no restrictions.
Once you add restrictions then your output must conform to those restrictions. The more restrictions the more involved it becomes (not necessarily more complex but complexity could enter into it as well.)
This is why software specifically for reporting exists. Such software isn't necessarily easier than doing it yourself but with more complex reports and with an increasing number of different types of reports learning such a system is probably a good idea. Whether you need it however depends on your (business) current and future needs.
|
|
|
|
|
Actually my task is create a structure to the mails, store those mails into a file(like pst file) i dont have any idea about this. if anybody know this. please help me
i am getting mails from mail server but i dont know. how to create a Structure and how to create file (like pst file)using c#.net
Saikumar
|
|
|
|
|
Since this is a single user app, look at creating a SqlCE database - it is built in to .NET so it needs no special installation, and it can provide all the structure you will probably need.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
OriginalGriff wrote: SqlCE database - it is built in to .NET
Ummm, no it's not. SQL Server Express Edition is installed with Visual Studio.
If you write an application with it you have to install SQLCE on the client machine seperately from the .NET Framework.
|
|
|
|
|
Your manager has asked you to do this? If so you should tell him that you need help since you've not done this before. Never ceases to amaze me when managers hand out work without knowing whether or not the recipient can actually do the work!
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
Error 2 No overload for 'HookManager_MouseClick' matches delegate 'System.Windows.Forms.MouseEventHandler'
|
|
|
|