受保护的空缺误?

时间:2013-09-13 11:53:58

标签: c# asp.net visual-studio-2010 repository

我对c#有点新,我的代码有些问题。

我在页面加载和Button2_Click空白上收到错误预期的类,委托,枚举,界面或结构。

我的代码看起来很好,而且工作得很早。

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using c365_EntityFramework;
using c365_EntityFramework.Repository;
using ICSWebCommon;
using ICSWebControls;
using Obout.Grid;
using ICSWebPortal.AppCode;

namespace ICSWebPortal.Portal.Controls.Users
{
    public partial class CreateUser : ICSBaseUserControl
    {
        UserRepository userDao = new UserRepository();
        User user = new User();
        DateTime date = Convert.ToDateTime("2012-09-14 00:00:00.000");
    }
}


        protected void Page_Load(object sender, EventArgs e)
        {
}
        protected void Button2_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(txtTitle.Text))
            {
                user.Title = txtTitle.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtFirstName.Text))
            {
                user.Forename = txtFirstName.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtSurname.Text))
            {
                user.Surname = txtSurname.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtUsername.Text))
            {
                user.Username = txtUsername.Text;
            }
            // call save function at end of statements 
            if (!String.IsNullOrWhiteSpace(txtAddress.Text))
            {
                user.Address1 = txtAddress.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtAddress2.Text))
            {
                user.Address2 = txtAddress.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtPostcode.Text))
            {
                user.PostCode = txtPostcode.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtCode.Text))
            {
                user.CountryCode = txtCode.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtEmail.Text))
            {
                user.Email = txtEmail.Text;
            }
            //if (!string.IsNullOrWhiteSpace(txtDate.Text))
            //{
            //    DateTime _entrydate;
            //    if (DateTime.TryParse(txtDate.Text, out _entrydate))
            //    {
            //        user.EntryDate = _entrydate;
            //    }
            //}
            user.CompanyID = AppSession.Company.ID;
            user.Status = 1;
            user.PasswordHash = "test";
            user.EntryDate = DateTime.Now;
            user.UpdateDate = DateTime.Now;
            user.Deleted = false;
            bool result = userDao.SaveNewUser(user);
            if (result)
            {
                Response.Redirect("~/User/List/UserList.aspx"); //~ for root directory , if there is any page use that or use the exact url here.
            }
}

当前代码

   using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using c365_EntityFramework;
using c365_EntityFramework.Repository;
using ICSWebCommon;
using ICSWebControls;
using Obout.Grid;
using ICSWebPortal.AppCode;

namespace ICSWebPortal.Portal.Controls.Users
{
    public partial class CreateUser : ICSBaseUserControl
    {
        UserRepository userDao = new UserRepository();
        User user = new User();
        DateTime date = Convert.ToDateTime("2012-09-14 00:00:00.000");

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(txtTitle.Text))
            {
                user.Title = txtTitle.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtFirstName.Text))
            {
                user.Forename = txtFirstName.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtSurname.Text))
            {
                user.Surname = txtSurname.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtUsername.Text))
            {
                user.Username = txtUsername.Text;
            }
            // call save function at end of statements 
            if (!String.IsNullOrWhiteSpace(txtAddress.Text))
            {
                user.Address1 = txtAddress.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtAddress2.Text))
            {
                user.Address2 = txtAddress.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtPostcode.Text))
            {
                user.PostCode = txtPostcode.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtCode.Text))
            {
                user.CountryCode = txtCode.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtEmail.Text))
            {
                user.Email = txtEmail.Text;
            }
            //if (!string.IsNullOrWhiteSpace(txtDate.Text))
            //{
            //    DateTime _entrydate;
            //    if (DateTime.TryParse(txtDate.Text, out _entrydate))
            //    {
            //        user.EntryDate = _entrydate;
            //    }
            //}
            user.CompanyID = AppSession.Company.ID;
            user.Status = 1;
            user.PasswordHash = "test";
            user.EntryDate = DateTime.Now;
            user.UpdateDate = DateTime.Now;
            user.Deleted = false;
            bool result = userDao.SaveNewUser(user);
        }
    }
}

2 个答案:

答案 0 :(得分:2)

您已经结束了您的类和命名空间:

namespace ICSWebPortal.Portal.Controls.Users
{
    public partial class CreateUser : ICSBaseUserControl
    {
        UserRepository userDao = new UserRepository();
        User user = new User();
        DateTime date = Convert.ToDateTime("2012-09-14 00:00:00.000");


    } // these should be after your methods
}     //

答案 1 :(得分:0)

尝试:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using c365_EntityFramework;
using c365_EntityFramework.Repository;
using ICSWebCommon;
using ICSWebControls;
using Obout.Grid;
using ICSWebPortal.AppCode;

namespace ICSWebPortal.Portal.Controls.Users
{
    public partial class CreateUser : ICSBaseUserControl
    {
        UserRepository userDao = new UserRepository();
        User user = new User();
        DateTime date = Convert.ToDateTime("2012-09-14 00:00:00.000");

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(txtTitle.Text))
            {
                user.Title = txtTitle.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtFirstName.Text))
            {
                user.Forename = txtFirstName.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtSurname.Text))
            {
                user.Surname = txtSurname.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtUsername.Text))
            {
                user.Username = txtUsername.Text;
            }
            // call save function at end of statements 
            if (!String.IsNullOrWhiteSpace(txtAddress.Text))
            {
                user.Address1 = txtAddress.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtAddress2.Text))
            {
                user.Address2 = txtAddress.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtPostcode.Text))
            {
                user.PostCode = txtPostcode.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtCode.Text))
            {
                user.CountryCode = txtCode.Text;
            }
            if (!String.IsNullOrWhiteSpace(txtEmail.Text))
            {
                user.Email = txtEmail.Text;
            }

            user.CompanyID = AppSession.Company.ID;
            user.Status = 1;
            user.PasswordHash = "test";
            user.EntryDate = DateTime.Now;
            user.UpdateDate = DateTime.Now;
            user.Deleted = false;
            bool result = userDao.SaveNewUser(user);
            if (result)
            {
                Response.Redirect("~/User/List/UserList.aspx"); //~ for root directory , if there is any page use that or use the exact url here.
            }
        }
    }
}