|
what is that soposto mean??
That C# code is for those who want to create split file app jst copy n paste n modify put in buttons etc.
At one point i needed one so i put this out for those who where in my position!!!!!
|
|
|
|
|
If you look at the very first item in this forum, it says "How to ask a question". This forum is for asking questions. So when you post something like that, we are left wondering what the questions is. In any case, you could have been more clear by stating that you're not asking a question(which the purpose of the forum) but posting a solution to a problem you encountered. Nonetheless, thanks for sharing.
|
|
|
|
|
|
you right home work 4 your self
|
|
|
|
|
You won't last long here with that attitude.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Right now due to increasing our recruitment possibilities of new staff we are moving over to C#
What is the best way that I can go about making a data collection object available to all forms in C#
In Visual Basic we can use a module and put in a friend based variable i.e. friend GlobalData as string . (the string variable is the easiest way I could explain this as an example!) This then makes the variable available to any form / class in the assembly.
Is there a way of doing this in C# or do I have to look at passing the information back and forth between each form?
Many 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
modified 17-Feb-12 11:50am.
|
|
|
|
|
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!
|
|
|
|