locked
My application has no Class RRS feed

  • Question

  • User922725412 posted

    I am writing a little test application to get a better handle on proper OOP design.  I am trying to write one class file that will define the class and sit in a BL (business layer) folder.  Another class file will handle the database activity and sit in a DAL folder.  A small program will instantiate an oject and add it to a table.  I cannot seem to get the whole namespace thing organized.  Notice  that none of the commented out using comments below will compile and thus the myManufacturer object also generates a compile error.  So basically, I cannot seem to get the three files to see each other.  The website project is called myPestReport and the two folders are BL and DAL.  The default program is in the root.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    //using ManBL;
    //using ManDAL;
    //using MyPestReport.BL;
    //using MyPestReport.DAL;
    
    
    
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                myManufacturer m = new myManufacturer();
                m.EPANUM = "M11111";
                m.Name = "US BORAX";
                m.Street1 = "103 James Creek Rd.";
                m.Street2 = "PO Box 12345";
                m.City = "Trenton";
                m.State = "NJ";
                m.Zip = "12345-98976";
                m.Add();
            }
        }
    
    
    DAL  Class here
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using MyPestReport.BL;
    
    namespace ManDAL
    {
    
    
    
    
        /// <summary>
        /// Summary description for ManufacturerDAL
        /// </summary>
        /// 
        public class ManufacturerDAL
        {
    
            //
            // TODO: Add constructor logic here
            //
            public static void AddManufacturer(myManufacturer m)
            {
                PestDataClassesDataContext ctx = new PestDataClassesDataContext();
    
                ctx.Manufacturers.InsertOnSubmit(m);
                ctx.SubmitChanges();
            }
    
        }
    
    }
    
    
    BL Class Here
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using MyPestReport.DAL;
    
    namespace ManBL
    {
        
        public class myManufacturer
        {
    
    
            private int _id;
            private string _epanum;
            private string _name;
            private string _street1;
            private string _street2;
            private string _city;
            private string _state;
            private string _zip;
            private List<myManufacturer> _manufacturerCollection;
    
            public int ID
            {
                get { return _id; }
                set { _id = value; }
            }
            public string EpaNum
            {
                get { return _epanum; }
                set { _epanum = value; }
            }
            public string Name
            {
                get { return _name; }
                set { _name = value; }
            }
            public string Street1
            {
                get { return _street1; }
                set { _street1 = value; }
            }
            public string Street2
            {
                get { return _street2; }
                set { _street2 = value; }
            }
            public string City
            {
                get { return _city; }
                set { _city = value; }
            }
            public string State
            {
                get { return _state; }
                set { _state = value; }
            }
            public string Zip
            {
                get { return _zip; }
                set { _zip = value; }
            }
    
            public void Add()
            {
    
             ManufacturerDAL.AddManufacturer(this);
    
            }
    
            
    
           
           
        }
    
    }


     

    Tuesday, January 19, 2010 12:19 PM

Answers

  • User-1483831041 posted

    Have you set a startup page?  right click on the page you are trying to use as your default page and select "set as start page."

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 19, 2010 4:35 PM

All replies

  • User-1483831041 posted

    Are your BusinessLogic and DataAccess classes in a different project than your website?  This is how I would recommend separating them out:  Add a class library for your BusinessLogic classes and a class library for you DataAccess classes.  Add project references to these class libraries in the properties of your web site.

    Now when you type out the class name myManufacturer in your website code it will get a little red box on the lower right side.  You can either click it and select to add the using statement (which will add the correct using namespace for you to the top of your partial class) or when you see the red box show up hit Ctrl + . and it will open the dialog for you and you can hit enter.  (faster than using the mouse)


    I hope this helps,


    Nate

    Tuesday, January 19, 2010 1:19 PM
  • User922725412 posted

    I am new to VS (using Express) so please bear with me.  I created this project using Create Website  not Create Project.  I added the folders and created the Class files.  Are you saying that I have to use the Create Project option to create the classes and then, create a website where I use them? 

    Tuesday, January 19, 2010 1:38 PM
  • User-1483831041 posted

    Click "Create:        Project..." on the start page

    Under "Other Project Types"   >  "Blank Solution"

     

    Right click the Solution in the Solution Explorer ->  Add -> "New Web Site..."

    ASP.NET Web Site should be selected already... make certain your language of preference (VB vs. C#) is selected.  ->  "OK"

    Note: if you want to change the name of the website from "WebSite1"  change the folder name in the path.  It will automatically create it for you.

     

    Right click the Solution in the Solution Explorer ->  Add -> "New Project..."

    Select "Class Library" (this will NOT be selected by default)

    Name: "BusinessLogic"

     

    Right click the Solution in the Solution Explorer ->  Add -> "New Project..."

    Select "Class Library" (this will NOT be selected by default)

    Name: "DataAccess"

     

    Both Class Libraries will have a class named "Class1" in it.  You can right click and rename it to whatever you like.

    Right click your website ->  select "Add Reference"  (not web or service reference)

    Note: if this is the first time opening up references for this solution it might take a bit.

     

    Click the "Projects" tab

    Select both DataAccess and BusinessLogic and hit "OK"

     

    You may want to add a reference to the DataAccess project in  your BusinessLogic Class Library, you do that the same way:  Right Click your BusinessLogic class library and select "Add Reference" select "Projects" select "DataAccess" hit "OK"

    Note: you cannot reference BusinessLogic in your dataAccess class library.  So if you were planning on defining your "Common" class (myManufacturer) in BusinessLogic you may want to, instead, add a Common Class Library and define your common classes there.  You can then reference the Common project in both your BusinessLogic and DataAccess class libraries.


    Hope this helps!


    Nate

    Tuesday, January 19, 2010 1:55 PM
  • User922725412 posted

    Thanks for trying, but I am using VWD Express and striking out.  I can't create a blank solution, so I tried a ASP WEb and added the two additional projects to it as you described.  Then I added the source code from my original example above into the Project class files and got the same unresolved references.   I must be overlooking something - I can't believe this should be so complicated.

    Tuesday, January 19, 2010 2:42 PM
  • User-1483831041 posted

    you added the project references to the web site?

    Tuesday, January 19, 2010 2:59 PM
  • User922725412 posted

    The project wouldn't compile so there was nothing to reference.

    So I decided to simplify and went back to my web application, put all the source files in App_Code and took out all the namespaces.  Now everything compiles nicely and there are no errors.  But it won't run.  All I get is:

     

     

    Server Error in '/MyPestReport' Application.

    HTTP Error 403 - Forbidden.


    Version Information: ASP.NET Development Server 9.0.0.0 

    Server Error in '/MyPestReport' Application.

    HTTP Error 403 - Forbidden.


    Version Information: ASP.NET Development Server 9.0.0.0

     

    So all I really want to do now is have my BL and DAL classes in separate files from the code behind.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
               
                ManuBL m = new ManuBL();
                m.EpaNum = "M11111";
                m.Name = "US BORAX";
                m.Street1 = "103 James Creek Rd.";
                m.Street2 = "PO Box 12345";
                m.City = "Trenton";
                m.State = "NJ";
                m.Zip = "12345-98976";
                m.Add();
            }
        }
    
    HERE IS THE DAL Class - teh method is called by the BL class
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    /// <summary>
    /// Summary description for ManuDAL
    /// </summary>
    public class ManufDAL
    {
    	
               public static void AddManufacturer(ManuBL m)
            {
                PestDataClassesDataContext ctx = new PestDataClassesDataContext();
                Manufacturer mrec = new Manufacturer();
                mrec.EPANUM = m.EpaNum;
                mrec.Name = m.Name;
                mrec.Street1 = m.Street1;
                mrec.Street2 = m.Street2;
                mrec.City = m.City;
                mrec.State = m.State;
                mrec.Zip = m.Zip;
    
                ctx.Manufacturers.InsertOnSubmit(mrec);
                ctx.SubmitChanges();
            }
    
        }
    
    HERE is the BL - note the Add method at the bottom calls Addmanufacturer above
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    
    
    
    public class ManuBL
    {
    
    
        private int _id;
        private string _epanum;
        private string _name;
        private string _street1;
        private string _street2;
        private string _city;
        private string _state;
        private string _zip;
        private List<ManuBL> _manufacturerCollection;
    
        public int ID
        {
            get { return _id; }
            set { _id = value; }
        }
        public string EpaNum
        {
            get { return _epanum; }
            set { _epanum = value; }
        }
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        public string Street1
        {
            get { return _street1; }
            set { _street1 = value; }
        }
        public string Street2
        {
            get { return _street2; }
            set { _street2 = value; }
        }
        public string City
        {
            get { return _city; }
            set { _city = value; }
        }
        public string State
        {
            get { return _state; }
            set { _state = value; }
        }
        public string Zip
        {
            get { return _zip; }
            set { _zip = value; }
        }
    
        public void Add()
        {
    
            ManufDAL.AddManufacturer(this);
    
        }
    
    
    
    
    
    }
    
    


     

     

     

     

    Tuesday, January 19, 2010 3:48 PM
  • User-1483831041 posted

    Can you create a web site rather than a web application?  And am I assuming correctly: when I see using statements in your listed code those are different code files?

    Tuesday, January 19, 2010 3:57 PM
  • User922725412 posted

    It is a website application and they are three different files.   I put a breakpoint on the first line of the pageload method and it never even got that far.

    Tuesday, January 19, 2010 4:18 PM
  • User-1483831041 posted

    Have you set a startup page?  right click on the page you are trying to use as your default page and select "set as start page."

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 19, 2010 4:35 PM
  • User922725412 posted

    I double checked - it is the start page. 

    Tuesday, January 19, 2010 4:59 PM
  • User922725412 posted

    I had to move the default.aspx file out of App_Code into the root and it works.  So I now have two classes in App_Code, one a business layer, one a data layer, and it all works fine.  I still do not understand why I cannot use different namespaces, but I am going to leave that for another day.  Thank you for your help.

    Tuesday, January 19, 2010 6:25 PM