Exemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ClassLibrary1.Model.Dormitory model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Dormitory set ");
            strSql.Append("CreateTime=@CreateTime,");
            strSql.Append("DormitoryName=@DormitoryName,");
            strSql.Append("IsDeleted=@IsDeleted,");
            strSql.Append("AddTime=@AddTime,");
            strSql.Append("AddPeople=@AddPeople,");
            strSql.Append("SchoolDistrictUuid=@SchoolDistrictUuid");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CreateTime",         SqlDbType.DateTime2,          8),
                new SqlParameter("@DormitoryName",      SqlDbType.VarChar,          255),
                new SqlParameter("@IsDeleted",          SqlDbType.Int,                4),
                new SqlParameter("@AddTime",            SqlDbType.VarChar,          255),
                new SqlParameter("@AddPeople",          SqlDbType.VarChar,          255),
                new SqlParameter("@SchoolDistrictUuid", SqlDbType.UniqueIdentifier,  16),
                new SqlParameter("@ID",                 SqlDbType.Int,                4),
                new SqlParameter("@DormitoryUuid",      SqlDbType.UniqueIdentifier, 16)
            };
            parameters[0].Value = model.CreateTime;
            parameters[1].Value = model.DormitoryName;
            parameters[2].Value = model.IsDeleted;
            parameters[3].Value = model.AddTime;
            parameters[4].Value = model.AddPeople;
            parameters[5].Value = model.SchoolDistrictUuid;
            parameters[6].Value = model.ID;
            parameters[7].Value = model.DormitoryUuid;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public ClassLibrary1.Model.Dormitory DataRowToModel(DataRow row)
 {
     ClassLibrary1.Model.Dormitory model = new ClassLibrary1.Model.Dormitory();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["CreateTime"] != null && row["CreateTime"].ToString() != "")
         {
             model.CreateTime = DateTime.Parse(row["CreateTime"].ToString());
         }
         if (row["DormitoryUuid"] != null && row["DormitoryUuid"].ToString() != "")
         {
             model.DormitoryUuid = new Guid(row["DormitoryUuid"].ToString());
         }
         if (row["DormitoryName"] != null)
         {
             model.DormitoryName = row["DormitoryName"].ToString();
         }
         if (row["IsDeleted"] != null && row["IsDeleted"].ToString() != "")
         {
             model.IsDeleted = int.Parse(row["IsDeleted"].ToString());
         }
         if (row["AddTime"] != null)
         {
             model.AddTime = row["AddTime"].ToString();
         }
         if (row["AddPeople"] != null)
         {
             model.AddPeople = row["AddPeople"].ToString();
         }
         if (row["SchoolDistrictUuid"] != null && row["SchoolDistrictUuid"].ToString() != "")
         {
             model.SchoolDistrictUuid = new Guid(row["SchoolDistrictUuid"].ToString());
         }
     }
     return(model);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ClassLibrary1.Model.Dormitory model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Dormitory(");
            strSql.Append("CreateTime,DormitoryUuid,DormitoryName,IsDeleted,AddTime,AddPeople,SchoolDistrictUuid)");
            strSql.Append(" values (");
            strSql.Append("@CreateTime,@DormitoryUuid,@DormitoryName,@IsDeleted,@AddTime,@AddPeople,@SchoolDistrictUuid)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CreateTime",         SqlDbType.DateTime2,          8),
                new SqlParameter("@DormitoryUuid",      SqlDbType.UniqueIdentifier,  16),
                new SqlParameter("@DormitoryName",      SqlDbType.VarChar,          255),
                new SqlParameter("@IsDeleted",          SqlDbType.Int,                4),
                new SqlParameter("@AddTime",            SqlDbType.VarChar,          255),
                new SqlParameter("@AddPeople",          SqlDbType.VarChar,          255),
                new SqlParameter("@SchoolDistrictUuid", SqlDbType.UniqueIdentifier, 16)
            };
            parameters[0].Value = model.CreateTime;
            parameters[1].Value = model.DormitoryUuid;
            parameters[2].Value = model.DormitoryName;
            parameters[3].Value = model.IsDeleted;
            parameters[4].Value = model.AddTime;
            parameters[5].Value = model.AddPeople;
            parameters[6].Value = model.SchoolDistrictUuid;

            object obj = DbHelperSql.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ClassLibrary1.Model.Dormitory GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,CreateTime,DormitoryUuid,DormitoryName,IsDeleted,AddTime,AddPeople,SchoolDistrictUuid from Dormitory ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            ClassLibrary1.Model.Dormitory model = new ClassLibrary1.Model.Dormitory();
            DataSet ds = DbHelperSql.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }