Jump to content

DooVoo

Members
  • Posts

    31
  • Joined

  • Last visited

Everything posted by DooVoo

  1. Is anyone able to help me out with this? I'd rather not override each method that uses the mUser variable just to change it to mAdminUser.
  2. Hi All,It's been a while since I last posted here. I've come across a small issue with my latest project, a registration and login system. This will then also have a seperate login system for administrators.To try and keep the amount of duplicated code to a minimum I've created a User class which the Login:Page class accesses and then created the derived classes AdminUser and AdminLogin which inherit the properties of User and Login respectively.My problem is this. The Login class uses a User instance called mUser, but the AdminLogin class needs to use an instance of AdminUser, also called mUser to avoid having to rewrite the inheritted code. Below is a stripped down version of the problem. public class User { public virtual void DoSomething() { // Do Something. }}public class AdminUser:User { public override void DoSomething() { // Do Something Else. }}public class Login:Page { private User mUser; public Login() { mUser = new User(); mUser.DoSomething(); }}public class AdminLogin:Login { public AdminLogin() { // Something to turn mUser into an AdminUser datatype. }} I believe that the data type of mUser could be set at runtime by using the base Object class and then using boxing and unboxing to assign it, but I can't quite figure it out. Below is an example, it doesn't work but it might give someone some inspiration! // Using the same User and AdminUser examples above.public class Login:Page { private User mUserRef; protected Object mUser; public Login() { mUserRef = new User(); mUser = mUserRef; // Boxing mUserRef into mUser. mUser.DoSomething(); }}public class AdminLogin:Login { private AdminUser mAdminUserRef; public AdminLogin() { mAdminUserRef = new AdminUser(); mUser = mAdminUserRef; // Boxing mAdminUserRef into base.mUser. mUser.DoSomething(); }} I hope someone can help me with this, it's incredibly fustrating!NB: I realise a single login system with userlevels would work, but i want a coded solution to help me understand more about c# - I'm being difficult I know, but it's the only way I'll learn
  3. DooVoo

    Format data

    You could also make use of String.Format to do the job. Checkout: http://idunno.org/displayBlog.aspx/2004071401
  4. DooVoo

    Tutorial

    aspnetguy is correct, but sometimes you may want your code to be more portable or accessable. By turning your classes into a class library you can access them by just referring to their namespace with a "using" statement. I've found this approach to be very flexible when working with other developers on the same project.Edit: It's far too early for spelling and grammer. Please excuse the poor attempt at English above
  5. So, does that work or are you still having problems?
  6. Hmmm, not a very specific question. You should really be reading up on database design and asp.net coding if you have to ask questions like this. With that in mind, I hope the following makes sense.First for the db. I would recommend having a chapter table and a sub chapter table with appriopriate primary and secondary keys linking them together to create a 1 chapter has many sub chapters relationship.Then for the code I would run a query that accesses all the chapters and then gets all the sub chapter for each main chapter. A stored procedure on your sql database would make this a little cleaner and help seperate out the database and coding logic.An alternative to using a database would be to use XML files, they would be faster to access and would leave your database to do more application critical operations, rather than worry about compiling the menu.Hope this helps to get you started!
  7. I'm beginning to think posting on this forum is the first step to solving an issue on my own. I can stare at the problem for hours and get no-where, then just by entering the problem here and continuing with my search do i stumble across the information i need. w3schools is now my lucky charm :)So, for those of you who might want to know the answer...When reading in multiple xml files with the same schema (and possible those that can be used to extend the current schema) there is no problem.However, if you are adding multiple xml files with different schemas then you need the DataSet to create a new table for each schema. This is done using one of the overloaded ReadXml(), such as ReadXml(string filename, XmlReadMode mode). By supplying the XmlReadMode you can tell the DataSet what to do when it encounters a schema that doesn't match the first one.To solve my issue I used: DataSet.ReadXml(string filename, XmlReadMode.InferSchema);This causes the DataSet to extend the xml schema in the first table if possible and if not, create a new table with the new schema.Excellent
  8. After some debugging Ive found that it is trying to load the second file, but into the first table rather than creating a new table. Anyone know if there is a way to force ReadXML to create another table?
  9. The title says it all really. I'm trying to populate a single DataSet with data from multiple xml files, to create either one DataTable for each xml file i read in. Here's the code: DataSet ds = new DataSet("myds");ds.ReadXml("somefile.xml");ds.ReadXml("somefile2.xml"); Unfortunately this doesn't seem to be working. The first file is read in correctly but the second file doesn't seem to load at all. Does anyone know if this is possible in .NET 1.1? I know that the DataTable type has a ReadXML method in v2 but it's not available in 1.1
  10. These links should be useful too:http://www.csharpfriends.com/quickstart/as...###=MailMessagehttp://www.csharpfriends.com/quickstart/as...&class=SmtpMail
  11. Typecasting is faster though, if you know there wont be any strange results that is.
  12. Hi Mohana,In your database I would store two strings, one as the url to the logo and one as the url it should link to.Then it's just a matter of SELECTing the two strings and putting them into your homepage at runtime.
  13. Okay, after some checking and reading I've found the following.Using the method ToString() will work with all classes that include it without any side effects of potential class "wierdness". The main downside is that it is slower that type-casting.However, having said that, the difference in speed is barely worth mentioning and so I conclude that using ToString() is the way forward!
  14. DooVoo

    Tutorial

    Was this useful for anyone? I was thinking of writing something similar each time I learnt something (I think is) useful, but if it's not benefitting anyone here then there isn't much point. Please let me know
  15. DooVoo

    Configuration

    I personally use a text editor, since the web.config file is just that, a text config file. As for all the directives it can have, I'd recommend looking on the MSDN site. They should be all on there somewhere!
  16. I am currently writing some code that extracts some string data from a DataRow and wondered which of the following two statements are the best practise and why: string myVar = (string)(MyRow["MyItem"]); string myVar = MyRow["MyItem"].ToString(); Answers on a postcard please
  17. DooVoo

    Tutorial

    Hello All,As a C++ developer I was used to being able to write all my classes in seperate files and referencing them using the #include directive. When I moved to C# development I couldn't work out how to do this and so started researching. What I found were "Assemblies", more specifically "Class Libraries". After many hours of hair pulling and furstrated rantings at tutorials that didn't explain the process in a nice simple step-by-step approach, I managed to get an implementation working. To help cement my knowledge I decided to write this following tutorial and post it on here to help people looking for the same information and for those with more knowledge to correct any mistakes or misconceptions I have made. So here goes...IntroductionASP.NET makes use of several types of assembly. This tutorial aims to describe how to manually create a Single-File Class Library and make it globally available to your applications. For this you will need:Microsoft Internet Information Services v5.1 (Available with WindowXP Professional)Microsoft .NET Framework v1.1 Microsoft .NET SDK v1.1Notepad (or your favorite text editor)What is a Class Library?A Class Library is a compiled DLL file that contains one or more class definitions. They can then be referenced by other source files in your applications for reusability.To make these classes globally available they must be registered in the Global Assembly Cache (GAC) as well as the machine level configuration. Below are all the steps needed to achieve this.Step1: Create a Strong Name key pairBefore an assembly can be added to the GAC it must have be Strong-Named. This has many benefits, which are detailed here. To make an assembly Strong-Named, we must first create a Strong Name key pair. This is done using the SDK tool “sn.exe”.At the command prompt navigate to your code directory and type: sn -k KeyPair.snk This will generate the file “KeyPair.snk” that holds the private and public keys that you will use with your assembly.Note: It should be pointed out that for the “sn” command to work in your application directories you will need to have run the “sdkvars.bat” file in the “C:\Program Files\Microsoft.NET\SDK\v1.1\Bin” folder in the same Command Prompt session!Step 2: Add assembly attributes to the source files.Now we have the key pair file, we need to tell the compiler where it is located. This can be done a number of ways, but we’ll do it in the source code for your Class Library. First, we need to use the namespace that deals with this. So add the following “Using” statement:Using System.Reflection;Following your “Using” statements add the following attribute: [assembly:AssemblyKeyFileAttribute(@"KeyPair.snk")] This, obviously, sets the path to your “KeyPair.snk” file. This attribute is one of many available for providing information about your assembly. A complete list of these attributes can be found here.Step 3: Compile the source file into a LibraryNow the source file has been setup and associated with a Strong Name key pair we can compile it into a DLL. This is done using the SDK compiler tool “csc.exe”.At the command prompt navigate to your code directory and type: csc /out:MyCode.dll /target:library MyCode.cs This will compile your source into a DLL with all the Strong Name assembly information you provided.Step 4: Add the assembly to the Global Assembly Cache [GAC]Including the assembly into the framework is simple. Just do the following:1. Select: Start -> Program Files -> Administrative -> Microsoft .NET Framework 1.1 Configuration2. Select: Assembly Cache3. Select: Action -> Add4. Browse to your compiled DLL and open itStep 5: Add the assembly to the machine.configNow, the final step in setting up your assembly, updating the machine level configuration machine.config file. The machine.config file is located by default in: “C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG”Once open, scroll down to the “<add assembly=…” lines and add a new one at the end. This will look something like below: <add assembly="MyCode, Version=1.0.1.0, Culture=neutral, PublicKeyToken=0249f9723h97"/> Note: The PublicKeyToken value is the hexadecimal version of the Strong Name public key you created earlier. You can find out this value by running the following command from your command prompt: sn -Tp MyCode.dll Step 6: Using your new Code LibraryNow that you have created and configured your new code library all that is left is to use it!Do this by creating a new source file and referencing the namespace you used in your source file, such as: Using MyNameSpace; With this any classes that you created will automatically be available for instantiation!This concludes the tutorial. If you have any suggestions or comments, please let me know in this thread.
  18. Hi cebuanoninoy welcome!Strange place in the forum to ask this question but I'll answer anyway.If you look at the bottom of the page, there is a note about Invision Power Board. That is the name of the software this forum uses. There is also a link to the invision website down there too.Hope that helps!
  19. So after a weekend of scratching my head, researching different Localization technique, such as resource files and the resource manager I found the answer...and it made my cry.instead of: <?xml version="1.0" encoding="utf-8"?> use: <?xml version="1.0" encoding="iso-8859-1"?> From all my research utf-8 should support european characters but it causes the errors I saw. Changing the xml files encoding to iso-8859-1 works perfectly! Why couldn't I have found this out on Friday!
  20. Hi All,I'm currently trying to write a multi-lingual application that uses xml files to store the different content and an XmlTextReader to read in this content. This works fine for the english version but as soon as it tries to read the French version it throws a System.Xml.XmlException about the first french language specific character (i.e. an e with an accent). The exact exception error is:System.Xml.XmlException: There is an invalid character in the given encoding. Line 6, position 29.I believe it is down to the set encoding but I can't figure out a solution, everything looks to be using utf-8, which, from my reading, should work for both these languages. Even the System.Text.Encoding that is output if there is a problem says it's all in utf-8!If anyone can help here, I would be a very happy man!Here's an example of the code and xml file:myfile.aspx <%@ Page Language="C#" Src="myfile.cs" Inherits="MyFile" ResponseEncoding="utf-8" Debug="true" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <title>MyFile</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /></head><body> <asp:Literal id="PageTitle" runat="server" /></body></html> myfile.cs using System;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.Text;// Used by Localizationusing System.Xml;public class MyFile : System.Web.UI.Page{ private Localization PageContent; pubilc MyFile() { PageContent = new Localization("French"); //PageContent = new Localization("English"); } public void Page_Load() { PageContent.GetData('PageTitle'); }}public class Localization{ private string XmlFile; private XmlTextReader LocaleReader; public Localization (string FileName) { XmlFile = FileName; } private LoadXml() { LocaleReader = XmlTextReader(XmlFile); } public string GetData(string XmlField) { string ElementValue = "Missing Xml Element"; LoadXml(); try { while (LocaleReader.Read()) { LocaleReader.MoveToElement(); if (LocaleReader.Name == XmlField) { ElementValue = LocaleReader.ReadString(); } } } catch (System.Xml.XmlException) { ElementValue = "Xml Encoding Error [" + Encoding.GetEncoding(65001) + "]"; } finally { LocaleReader.Close(); } LocaleReader.Close(); return ElementValue; }} english.xml <?xml version="1.0" encoding="utf-8"?><PageTitle>English</PageTitle> french.xml <?xml version="1.0" encoding="utf-8"?><PageTitle>Français</PageTitle>
  21. DooVoo

    Multi-Page Forms

    Post Code? Ah yes, I might have wanted to do that! Heh, sorry!I've managed to solve the issue, for people having the same problem in the future you can check is a page is valid manually.So, imagine you have a button that calls the function "button_click" you will have a function like so: protected void button_click(Object Source, EventArgs E){ if (Page.IsValid) { // Your Code Here }} This will cause your code to only be executed so long as the web controls pass any validation controls you have set.
  22. DooVoo

    Multi-Page Forms

    I'm currently writing a multi-page form that makes use of the .NET validation web components. However, once I add an onClick event to the submit button (to control the multi-page state) it breaks the validation. According to my reading the onClick event should cause a postback event which I thought would cause the validation to run. Is this not the case? If not, is there a way to solve this neatly?Any help would be lovely!
  23. <MAJOR EDIT>Might help if I had read your "I've fixed it" reply </MAJOR EDIT>
  24. DooVoo

    PHP

    It depends on the versions of Windows you are running (assuming you're running Windows). If it is XP Professional you can install it from your control panel (it's part of that edition of Windows). If not, I'd recommend using a web server like Apache.As for PHP, the best place for instructions on installing php would be http://www.php.net. The documentation on installing a web server and configuring php is all over the place, just visit your local Google for more info!
  25. DooVoo

    Getting Fatal Error

    Well, according to your error, it doesn't know what "VARIANT" means. This is because you either havn't:A. Created a class/structure/datatype of that nameB. Included a php library that includes this class/structure/datatypeC. Not compiled PHP with the correct options on you server to access this class/structure/datatypeI would go back and check any documentation for this function to find out what it depends on.
×
×
  • Create New...