/// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Reservation_User_Model GetModel(Guid ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(
                "select  top 1 ID,City,Fitness_Club_ID,Name,Sex,Phone,Create_Time,Activity_ID from Reservation_User ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 16)
            };
            parameters[0].Value = ID;

            Reservation_User_Model model = new Reservation_User_Model();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Reservation_User_Model DataRowToModel(DataRow row)
        {
            Reservation_User_Model model = new Reservation_User_Model();

            if (row != null)
            {
                if (row["ID"] != null && row["ID"].ToString() != "")
                {
                    model.ID = new Guid(row["ID"].ToString());
                }

                if (row["City"] != null)
                {
                    model.City = row["City"].ToString();
                }

                if (row["Fitness_Club_ID"] != null && row["Fitness_Club_ID"].ToString() != "")
                {
                    model.Fitness_Club_ID = new Guid(row["Fitness_Club_ID"].ToString());
                }

                if (row["Name"] != null)
                {
                    model.Name = row["Name"].ToString();
                }

                if (row["Sex"] != null && row["Sex"].ToString() != "")
                {
                    model.Sex = int.Parse(row["Sex"].ToString());
                }

                if (row["Phone"] != null)
                {
                    model.Phone = row["Phone"].ToString();
                }

                if (row["Create_Time"] != null && row["Create_Time"].ToString() != "")
                {
                    model.Create_Time = DateTime.Parse(row["Create_Time"].ToString());
                }

                if (row["Activity_ID"] != null && row["Activity_ID"].ToString() != "")
                {
                    model.Activity_ID = new Guid(row["Activity_ID"].ToString());
                }
            }

            return(model);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Reservation_User_Model model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Reservation_User set ");
            strSql.Append("City=@City,");
            strSql.Append("Fitness_Club_ID=@Fitness_Club_ID,");
            strSql.Append("Name=@Name,");
            strSql.Append("Sex=@Sex,");
            strSql.Append("Phone=@Phone,");
            strSql.Append("Create_Time=@Create_Time,");
            strSql.Append("Activity_ID=@Activity_ID");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@City",            SqlDbType.NVarChar,         10),
                new SqlParameter("@Fitness_Club_ID", SqlDbType.UniqueIdentifier, 16),
                new SqlParameter("@Name",            SqlDbType.NVarChar,         20),
                new SqlParameter("@Sex",             SqlDbType.Int,               4),
                new SqlParameter("@Phone",           SqlDbType.NVarChar,         20),
                new SqlParameter("@Create_Time",     SqlDbType.DateTime),
                new SqlParameter("@Activity_ID",     SqlDbType.UniqueIdentifier, 16),
                new SqlParameter("@ID",              SqlDbType.UniqueIdentifier, 16)
            };
            parameters[0].Value = model.City;
            parameters[1].Value = model.Fitness_Club_ID;
            parameters[2].Value = model.Name;
            parameters[3].Value = model.Sex;
            parameters[4].Value = model.Phone;
            parameters[5].Value = model.Create_Time;
            parameters[6].Value = model.Activity_ID;
            parameters[7].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Reservation_User_Model model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Reservation_User(");
            strSql.Append("ID,City,Fitness_Club_ID,Name,Sex,Phone,Create_Time,Activity_ID)");
            strSql.Append(" values (");
            strSql.Append("@ID,@City,@Fitness_Club_ID,@Name,@Sex,@Phone,@Create_Time,@Activity_ID)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID",              SqlDbType.UniqueIdentifier, 16),
                new SqlParameter("@City",            SqlDbType.NVarChar,         10),
                new SqlParameter("@Fitness_Club_ID", SqlDbType.UniqueIdentifier, 16),
                new SqlParameter("@Name",            SqlDbType.NVarChar,         20),
                new SqlParameter("@Sex",             SqlDbType.Int,               4),
                new SqlParameter("@Phone",           SqlDbType.NVarChar,         20),
                new SqlParameter("@Create_Time",     SqlDbType.DateTime),
                new SqlParameter("@Activity_ID",     SqlDbType.UniqueIdentifier, 16)
            };
            parameters[0].Value = Guid.NewGuid();
            parameters[1].Value = model.City;
            // parameters[2].Value = Guid.NewGuid();
            parameters[2].Value = model.Fitness_Club_ID;
            parameters[3].Value = model.Name;
            parameters[4].Value = model.Sex;
            parameters[5].Value = model.Phone;
            parameters[6].Value = model.Create_Time;
            // parameters[7].Value = Guid.NewGuid();
            parameters[7].Value = model.Activity_ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #5
0
        protected void Button1_OnClick(object sender, EventArgs e)
        {
            // 城市名称
            string cityName = DropDownList1.SelectedValue;
            // 俱乐部名称
            string clubName = DropDownList2.SelectedValue;
            string name     = TextBox1.Text;
            string phone    = TextBox2.Text;
            string sex      = DropDownList3.SelectedValue;

            // 获取活动信息
            bool result1 = GetActivity();

            if (!result1)
            {
                return;
            }


            Reservation_User_Model reservationUserModel = new Reservation_User_Model();

            reservationUserModel.ID              = new Guid();
            reservationUserModel.City            = cityName;
            reservationUserModel.Fitness_Club_ID = new Guid(Fitness_Club_ID);
            reservationUserModel.Name            = name;
            reservationUserModel.Sex             = Convert.ToInt32(sex);
            reservationUserModel.Create_Time     = DateTime.Now;
            reservationUserModel.Activity_ID     = new Guid(Activity_ID);
            reservationUserModel.Phone           = phone;
            Reservation_User_BLL reservationUserBll = new Reservation_User_BLL();
            bool result2 = reservationUserBll.Add(reservationUserModel);

            if (!result2)
            {
                Response.Write("预约失败,请联系管理员");
                return;
            }
            Response.Write("预约成功,跳转到成功页面");
            //  Activity_ID     参数:活动id
            Response.Redirect("success.aspx?Activity_ID=" + reservationUserModel.Activity_ID);
        }
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Reservation_User_Model model)
 {
     return(dal.Update(model));
 }
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(Reservation_User_Model model)
 {
     return(dal.Add(model));
 }