zoukankan      html  css  js  c++  java
  • ASP.NET员工管理系统简易分了层主要只是就一个传值和CRUD

     

    实体类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace EmpPrj.Entity
    {
       public  class y_EmployeeEntity
        {
            public int EmployeeId { get; set; }
    
            public string EName { get; set; }
    
            public string Mobile { get; set; }
    
            public string HAddress { get; set; }
    
            public string Kdate { get; set; }
    
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace EmpPrj.Entity
    {
       public  class y_FamilyEntity
        {
            public int MemberId { get; set; }
    
            public int EmployeeId { get; set; }
    
            public string RelationShip { get; set; }
    
            public string FName { get; set; }
    
            public string Job { get; set; }
        }
    }

    DAL

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using EmpPrj.Entity;
    using EmpPrj.DAL;
    using System.Data.SqlClient;
    
    namespace EmpPrj.DAL
    {
        public class y_EmployeeDAL
        {
            //查询所有字段的公共方法(私有)
            private List<y_EmployeeEntity> CommSelecty_Employees(string sql)
            {
                List<y_EmployeeEntity> elist = new List<y_EmployeeEntity>();
                SqlDataReader dr = DBHelper.GetReader(sql);
                while (dr.Read())
                {
                    y_EmployeeEntity entity = new y_EmployeeEntity();
                    entity.EmployeeId = Convert.ToInt32(dr["EmployeeId"]);
                    entity.EName = Convert.ToString(dr["EName"]);
                    entity.Mobile = Convert.ToString(dr["Mobile"]);
                    entity.HAddress = Convert.ToString(dr["HAddress"]);
                    entity.Kdate = Convert.ToString(dr["Kdate"]);
                    elist.Add(entity);
                }
                return elist;
            }
    
            //查询所有数据
            public List<y_EmployeeEntity> Selecty_Employees()
            {
                string sql = string.Format("select * from y_Employee");
                return CommSelecty_Employees(sql);
            }
    
        
    
            public static string selectid()
            {
                string sql = "select top 1 EmployeeId from y_Employee order by EmployeeId desc";
                return DBHelper.GetDataTable(sql).Rows[0][0].ToString();
            }
    
            //根据ID查询单行数据
            public y_EmployeeEntity Selecty_EmployeeByEmployeeId(int employeeId)
            {
                string sql = string.Format("");
                return CommSelecty_Employees(sql)[0];
            }
    
            //插入所有数据
            public bool Inserty_Employee(y_EmployeeEntity entity)
            {
                string sql = string.Format("insert into y_Employee(EName,Mobile,HAddress)values('{0}','{1}','{2}')",entity.EName,entity.Mobile,entity.HAddress);
                return DBHelper.UpdateOpera(sql);
            }
    
    
            //根据主键删除数据
            public bool Deletey_Employee(int employeeId)
            {
                string sql = string.Format("");
                return DBHelper.UpdateOpera(sql);
            }
    
            //根据主键更新数据
            public bool Updatey_Employee(y_EmployeeEntity entity)
            {
                string sql = string.Format("");
                return DBHelper.UpdateOpera(sql);
            }
    
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using EmpPrj.Entity;
    using EmpPrj.DAL;
    using System.Data.SqlClient;
    
    namespace EmpPrj.DAL
    {
        public class y_FamilyDAL
        {
            //查询所有字段的公共方法(私有)
            private List<y_FamilyEntity> CommSelecty_Familys(string sql)
            {
                List<y_FamilyEntity> elist = new List<y_FamilyEntity>();
                SqlDataReader dr = DBHelper.GetReader(sql);
                while (dr.Read())
                {
                    y_FamilyEntity entity = new y_FamilyEntity();
                    entity.MemberId = Convert.ToInt32(dr["MemberId"]);
                    entity.EmployeeId = Convert.ToInt32(dr["EmployeeId"]);
                    entity.RelationShip = Convert.ToString(dr["RelationShip"]);
                    entity.FName = Convert.ToString(dr["FName"]);
                    entity.Job = Convert.ToString(dr["Job"]);
                    elist.Add(entity);
                }
                return elist;
            }
    
            //查询所有数据
            public List<y_FamilyEntity> Selecty_Familys()
            {
                string sql = string.Format("");
                return CommSelecty_Familys(sql);
            }
    
            public static string selectname(int id)
            {
                string sql = "select EName from y_Employee where EmployeeId = " + id + "";
                return DBHelper.GetDataTable(sql).Rows[0][0].ToString();
                   
            }
    
            //根据ID查询单行数据
            public y_FamilyEntity Selecty_FamilyByMemberId(int memberId)
            {
                string sql = string.Format("");
                return CommSelecty_Familys(sql)[0];
            }
    
            //插入所有数据
            public bool Inserty_Family(y_FamilyEntity entity)
            {
                string sql = string.Format("insert into y_Family(EmployeeId,RelationShip,FName,Job)values({0},'{1}','{2}','{3}')",entity.EmployeeId
                    ,entity.RelationShip,entity.FName,entity.Job);
                return DBHelper.UpdateOpera(sql);
            }
    
            //根据主键删除数据
            public bool Deletey_Family(int memberId)
            {
                string sql = string.Format("");
                return DBHelper.UpdateOpera(sql);
            }
    
            //根据主键更新数据
            public bool Updatey_Family(y_FamilyEntity entity)
            {
                string sql = string.Format("");
                return DBHelper.UpdateOpera(sql);
            }
    
        }
    }

    --BLL

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using EmpPrj.DAL;
    using EmpPrj.Entity;
    
    namespace EmpPrj.BLL
    {
        public class y_FamilyBLL
        {
            public static bool Inserty_Family(y_FamilyEntity entity)
            {
                return new y_FamilyDAL().Inserty_Family(entity);
            }
    
            public static string selectname(int id)
            {
                return y_FamilyDAL.selectname(id);
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using EmpPrj.Entity;
    using EmpPrj.DAL;
    
    namespace EmpPrj.BLL
    {
       public  class y_EmployeeBLL
        {
            public static List<y_EmployeeEntity> Selecty_Employees()
            {
                return new y_EmployeeDAL().Selecty_Employees();
            }
    
            public static bool Inserty_Employee(y_EmployeeEntity entity)
            {
                return new y_EmployeeDAL().Inserty_Employee(entity);
            }
            public static string selectid()
            {
                return y_EmployeeDAL.selectid();
            }
        }
    }

    UI:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using EmpPrj.Entity;
    using EmpPrj.BLL;
    
    public partial class Add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
            if (!Page.IsPostBack)
            {
                
            }
    
        }
    
        protected void Button1_Click(object sender, EventArgs e)
        {
            y_EmployeeEntity env = new y_EmployeeEntity();
            env.EName = Etext_name.Text;
            env.Mobile = Etext_mob.Text;
            env.HAddress = Etext_HA.Text;
    
            y_FamilyEntity entity = new y_FamilyEntity();
            entity.RelationShip = ytext_shop.Text;
            entity.FName = ytext_name.Text;
            entity.Job = ytext_Job.Text;
    
            y_FamilyEntity entity2= new y_FamilyEntity();
            entity2.RelationShip = ytext_shop2.Text;
            entity2.FName = ytext_name2.Text;
            entity2.Job = ytext_Job2.Text;
    
            if (y_EmployeeBLL.Inserty_Employee(env))
            {
                int refeid = Convert.ToInt32(y_EmployeeBLL.selectid());
                entity.EmployeeId = refeid;
                entity2.EmployeeId = refeid;
                if (y_FamilyBLL.Inserty_Family(entity) && y_FamilyBLL.Inserty_Family(entity2))
                {
                    Response.Write("<script> alert('添加成功!!');</script>");
                }
            }
        }
    
    
    }

    --查询

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using EmpPrj.BLL;
    
    public partial class FamilyIndex : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int id = Convert.ToInt32( Request.QueryString["id"].ToString());
                Label1.Text = y_FamilyBLL.selectname(id).ToString();
            }
        }
    }

    --主页

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using EmpPrj.BLL;
    
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GridView1.DataSource = y_EmployeeBLL.Selecty_Employees();
                GridView1.DataBind();
            }
        }
    
        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            int Eid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
            Response.Redirect("~/FamilyIndex.aspx?id=" + Eid);
        }
    }

     传值还可以在前端传:DataTextFied="Sname" DataNavigateURLfromatstring=“~fom.aspx?id={0}  DataNavigateUrlFields="sid"l

  • 相关阅读:
    手游渠道分成的那些坑来等你跳
    [手游新项目历程]-43-sql关键字解决
    一些相似词的区别
    程序员之间的“笑料”
    程序员之间的“笑料”
    2014游戏圈员工跳槽必看
    2014游戏圈员工跳槽必看
    游戏应该怎么做-美术
    游戏应该怎么做-美术
    [手游新项目历程]-44-gdb
  • 原文地址:https://www.cnblogs.com/yijieyufu/p/12347126.html
Copyright © 2011-2022 走看看