Ok, np.
Printable View
Ok, np.
I usually create separate class library projects for each layer. You mentioned App_Code, which indicates that you're working with web site projects which may be the reason you can only add your .cs files to App_Code. I also prefer web application projects which is slightly different.
Hey,
I didn't mention this before, but now that Mend has brought it up, I also prefer the use of a Web Application, over a Web Site. Given that you are using the Professional version of Visual Studio, there is no reason that you can't use this.
There are even steps you can follow to do the conversion if you choose to:
http://msdn.microsoft.com/en-us/libr...76(VS.80).aspx
Gary
Hi, can i ask what are the advantage of using web application ?
Hey,
Rather than repeat the content here, I thought I would just give you a link :)
http://reddnet.net/code/asp-net-web-...roject-part-2/
Gary
Thanks Gary, that article was very helpful!
Ok, so in my data access layer while i'm filling my list of object, let's say i have a column data represent DateTime and i need to check if it as a valid date value, where do i do the calculations ?, should i do it right on the spot (inside the loop) or should i call a method that placed in my business logic layer and do the calculation from there ?
One more question:
Inside my BLL/DAL i can't use the Trace.Warn methods, how do you guys debug what going on in those layers?
One More :)
I have this line up of methods calls inside my presentation layer all of those methods are placed inside my BLL, each of of those methods call to other methods that placed inside my DAL which do some kind of database operation, the target of this process is to
delete old team and add new team instead.
so i have two questions:Code:// Getting list of SiteSetting (return 1 item)
List<SiteSetting> lstSiteSetting = siteSetting.GetAllFromSiteSetting();
// Getting list of UsersDetails (return 1 item)
List<UsersDetails> lstUsersDetails = usersDetails.GetAllFromUsersDetailsByRecordID(TeamID);
// Increasing SiteSetting TeamID by 1
siteSetting.IncreaseByOneSiteSettingTeamID();
// Getting list of empty (none user) teams (Limiting to 1) from team_details
List<TeamDetails> lstOldTeamDetails =
teamDetails.GetEmptyTeamByCountryID(lstUsersDetails[0].CountryID.ToString());
if (lstOldTeamDetails.Count > 0) // Team found start updating process...
{
// Updating old team with the new team details
teamDetails.UpdateNewTeamDetailsByTeamID(lstSiteSetting[0].TeamID.ToString(),
usersDetails.RegionID.ToString(),
lstOldTeamDetails[0].RecordID.ToString());
// Updating users tables with new details.
usersDetails.UpdateNewUserDetails(lstSiteSetting[0].TeamID.ToString(),
lstUsersDetails[0].RecordID.ToString());
// Deleting Expend arena of the old team (if exist)
expendArena.DeleteExpendsByTeamID(lstOldTeamDetails[0].TeamID);
// Deleting old team Arena
teamArena.DeleteArenaByTeamID(lstOldTeamDetails[0].TeamID);
// Build arena for the new team
teamArena.BuiildArenaByTeamID(lstSiteSetting[0].TeamID, lstSiteSetting[0]);
A) is my logic looks right?
B) since all of these actions are connected, if one fail (SQL / C# Error) there will be mismatch data inside the database, that's mean i need some kind of Transaction, those is ASP.NET has some kind of built transaction mechanism that can handle these type of situations ?
Thanks.
Think about why it would have an invalid date value - you should check the value before it goes into the database. If at some point you're allowing invalid dates to be entered by the user, you should be checking it there. That's the business logic. As for dates coming from the database, you could again check it when your object or list of objects is returned to the business layer. But you shouldn't need to do this - check the values going in rather than the values coming back.
If all of that represents one piece of functionality (update team details, update user details, delete arena, rebuild arena), then move that into one function in your BL layer. Remove the bits where your web controls are involved, and have your BL function accept x number of parameters that it can use to accomplish the same thing. You can even call other BL functions from within that BL function if you need to get some data.
Mend, thank you for your suggestions, System.Web didn't helped to bring the Trace method to my DAL, i can't use the Debug method as well...
And I will check that the date is valid before i update the table.
now about the process, moving it to a single method is a good idea and i'll use it but it still not solving the problem that bad sql statement can cause for whatever reason, the only solution i can think of is to use TRANSACTION inside my database and execute all those statements in the same SP, the problem i'm facing now is
A) I'm not sure how to do ROLLBACK with MySql (but i think i can handle this)
B) MySql only support transaction when using innodb tables which is pretty slow as i remember, i hope it got a bit faster since i last used it two years ago.
that's it for now, i let you know how things went :-)
btw, Gary what is log4net ?
An easy way to use transactions now:
vb.net Code:
Using myScope As New TransactionScope '' do your database insert/update stuff here. End Using
I'm not sure if this is supported by MySql data adapter though. You could give it a try to see yourself.
Tried that already, didn't helped me, whatever executed remain the same, no rollback was take place.
Thank you for your help tough.
It works for me. I'm using sql server, so it might make difference. But this doesn't seem likely, since almost all databases support transactions and MySql should be no different.
How were you coding it?
Hey,
I seem to remember looking into Transactions a while back with the MySql Connector, and when I looked at the source code, it wasn't actually implemented. It could be that newer versions of the connector do include it, but maybe something worth checking. You could post over at the MySql Forum to make sure.
As for log4net:
http://logging.apache.org/log4net/index.html
It's a logging engine, and a very good one. Once it is set up, you simply call:
And it will log out to a text file. Or, if you want, you can log to the Event Log, an email address, lots of options there.Code:log.Debug("Your message here")
Gary
Mend, thank again but when i tried to use Transaction i did used the Complete() method at the end of the statement it just doesn't seem to work, and i didn't really had any success with the CTRL + DOT thing, nothing happen :|, but i did check for the trace method namespace and its indeed "System.Web" but for some reason it just doesn't seem to work on that page.
If you've mentioned it, I've forgotten - what version of Visual Studio are you running? Is it the VS 2008 Crippled Edition? :p
This class that you're attempting this code in - is it in App_Code or another project or somewhere else?
Show your Transaction code.
I already remove that part of the code and as i said i decided to use MySql built in Transactions, this code is part of my Data access layer and it's in a Class library i created as told earlier in this thread..
and last time i fired visual studio i didn't saw nothing about "Crippled Edition" but i think i saw some text saying something like "will run only when open by the hands of a genius" :D
no, seriously i have VS2008 pro edition :B
Hmm... in that case, either pay for my flight over there, or have a look at your references in that class library. Try adding a reference to System.Web.dll. Then do the Ctrl+. thing.
Ok, things are going really well, but i'm facing this problem now, How do i bind list of <some class> to FormView Or GridView? i tried to assign list of class to a formview, there was no errors but nothing was shown on the screen either, how do i connect between the forview (or gridview) controls to the class properties ?
In a gridview, for example, you can bind the column to a property. So if in your custom class you have a property called "JuiceType", you'd set that as the DataField in a BoundColumn in the gridview.
Thank you for the answer and with formview i shoult set it at the DataBinding event?
Ok so in my formview, i have textbox and i need the text will contain one of my class properties ... i can do it like that:
but as i been told, inline code is not a good practice, how could i set it without using inline code?Code:<asp:TextBox ID="txbCountryEnglishName" text='<%# Eval("CountryName") %>' runat="server" ></asp:TextBox>
Hey,
Use the FindControl method in the DataBound Event of the FormView:
http://msdn.microsoft.com/en-us/libr...databound.aspx
Gary
i already know how to find the control... the problem is how to connect the properties of the class to the controls of the formview without using inline...
Hey,
Assuming you have set the DataItem of the FormView to an instance of your custom class, you should be able to do something similar to the following:
http://msdn.microsoft.com/en-us/libr....dataitem.aspx
In your case, you are not going to have a DataRowView object, you will have an instance of your custom class.
Hope that helps!!
Gary
Yes i think that's what i need, i will get back to that once i'll finish my current work, thanks a lot Gary!
No probs. Let me know how you get on.
Gary
Hi again,
look I just can't make this to work, I'll try to show you some of the code:
now i have this form view EditTemplate :Code:// Getting selected country ID
int CountryID = Convert.ToInt32(ddlSelectCountry.GetCountrySelectedValue);
// Getting list of regions by the country id from BLL --> DAL
List<Regions> lstRegions = regions.GetRegionList(CountryID);
// setting the panel visibility that contain the input of creating new region to false or true
pnlAddNewRegion.Visible = regions.AddNewRegionPanelStatus(CountryID);
// setting the form view datasource as the list of regions that just been created
frvCountriesRegions.DataSource = lstRegions;
frvCountriesRegions.DataBind();
the Regions class has the properties: RecordID, region_name, i need to somehow bind these two properties to the Label and the textbox... it's very easy to with inline code, but i really don't want to go this way...Code:<asp:FormView ID="frvCountriesRegions" runat="server"
DefaultMode ="Edit">
<EditItemTemplate>
<table>
<tr>
<td>
<asp:Label ID="lblRegionID" runat="server" ></asp:Label>
</td>
<td>
<asp:TextBox ID="txbRegionName" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>
Hey,
Try something like this (note I have made up something called Region, you would need to change it to suit your own class):
GaryCode:protected void frvCountriesRegions_DataBound(object sender, EventArgs e)
{
Region tempRegion = (Region)frvCountriesRegions.DataItem;
Label tempLabel = (Label)frvCountriesRegions.FindControl("lblRegionID");
tempLabel.Text = tempRegion.RecordID.ToString();
TextBox tempTextBox = (TextBox)frvCountriesRegions.FindControl("txbRegionName");
tempTextBox.Text = tempRegion.RegionName;
}
ok man, i'll play with this a bit and let you know.
Thanks again.
Hi Gary, it seems that it solved the problem!
but from some reason i see only the first or last (i'm not sure yet) record!
is something from the above code look funny to you?
it's only the first record...
dang... i know what it is.. i shouldn't use the FormView, i should've used the repeater for this task :S..
Hey,
This is correct. A FormView is only designed to show one record:
http://msdn.microsoft.com/en-us/libr...w_members.aspx
You would need to edit the FormView to allow navigation to the different records in it's datasource.
http://msdn.microsoft.com/en-us/library/ms227443.aspx
Gary
ok i converted it to the Repeater control, but it seems that the repeater does not have the DataItem property, how can i convert your above code to work with the repeater control?
You don't ask for much do you :)
You should be able to get to this with something like this:
However, you have to do some additional checks in this case, i.e. the type of the Item that is being DataBound.Code:protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
Region tempRegion = (Region)e.Item.DataItem;
}
Have a look here for some more information:
http://msdn.microsoft.com/en-us/libr...databound.aspx
Gary
Thanks Gary, that did the trick :)
Well.. some things that looks obvious to you (like casting the repeater/formview DataItems to the regions class) can take me hours of searching, and if I can ask people with more experience then mine i don't see the problem. I have no doubt that with time things will more clearer for me. in the meantime i'll keep asking, if i'll get no answer i'll find it in the hard way.
Thanks again for the help gary.
Hey,
I am just messing with you :D
Yip, you will pick them up as you go, and never be afraid to ask questions.
Gary
Yip, I think that the hardest part in .NET is to master the way to approach items/controls
Thanks again and see you in my next question :B