|
|
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'
|
|
|
|
|
So why are you not asking whoever wrote the "HookManager" library about this??
|
|
|
|
|
Hai there guys...i'm new here in c# development so I really hope to get some pointers here and there.
So basically what I'm working now is to insert and display the data in dataGridView. I've already done one and it works fine but i wanna refine it. Currently when the application is run it will display all the data that had been stored in the database which can make it confusing for user when they inserted new data, then when they wanna check their data, they have to scroll all the way to find their data that had just been inputted.
So now what i wanna do is to adjust the application so that every time the user run the application, the dataGridView will display an empty view of the table which they can insert their data peacefully without needing to worry about other people data.
(all this using a single table.)
so any idea guys??because i don't even know how to start...
|
|
|
|
|
shahrulnizam wrote: they can insert their data peacefully without needing to worry about other people data.
In your database table create a field for the user ID. Then set the BindingSource.Filter property to the current userID, so that the DataGridView displays only the records pertaining to the current user. While adding the new row, using DataGridView.RowsAdded event set the userID filed of the new row to the current userID
|
|
|
|
|
where to set the bindingSource.filter??it's not at the properties window..
|
|
|
|
|
|
Hi All,
I have done lot of java work for more than 8 years. But I am new to C#. I am writting a client to the Simple Application. For that Client I need to add header..
Here is the scenario...
Server SIde code is written in Java and exposed as Web service.
Client SIde is Written in .Net/C#. I need to access that webservice.. And I am sucessful. Now I need to add a header so I can pass *ID* 122344*/ID* through soap Header. Can some one suggest me , How to do that.. I have been strugulling on this for more than 3 days..Any help really appreciated.
|
|
|
|