Ejemplo n.º 1
0
        public QPS.NEW.Model.Room GetModel(int Id)
        {
            QPS.NEW.Model.Room room = null;

            DataTable dt = sqlHelper_.GetDataTable(
                "select * from Room where Id=@id",
                CommandType.Text,
                new System.Data.SqlClient.SqlParameter[]
            {
                new System.Data.SqlClient.SqlParameter("@id", Id)
            }
                );

            if (dt != null && dt.Rows.Count > 0)
            {
                room = new Model.Room();

                room.Id            = Convert.ToInt32(dt.Rows[0]["Id"]);
                room.Name          = dt.Rows[0]["Name"].ToString();
                room.RoomType      = dt.Rows[0]["RoomType"].ToString();
                room.RoomPrice     = Convert.ToDecimal(dt.Rows[0]["RoomPrice"]);
                room.Are           = dt.Rows[0]["Are"].ToString();
                room.Address       = dt.Rows[0]["Address"].ToString();
                room.ImagePath     = dt.Rows[0]["ImagePath"].ToString();
                room.Content       = dt.Rows[0]["Content"].ToString();
                room.RoomState     = Convert.ToInt32(dt.Rows[0]["RoomState"]);
                room.OwnerID       = Convert.ToInt32(dt.Rows[0]["OwnerID"]);
                room.IfRecommend   = Convert.ToInt32(dt.Rows[0]["IfRecommend"]);
                room.Examine       = Convert.ToInt32(dt.Rows[0]["IfExamine"]);
                room.RecommendTime = dt.Rows[0]["RecommendTime"].ToString();
            }

            return(room);
        }
Ejemplo n.º 2
0
        public bool Update(QPS.NEW.Model.Room model)
        {
            bool res = false;

            string[]       filedName = new string[50];
            string[]       paramName = new string[50];
            SqlParameter[] sqlParams = new SqlParameter[50];
            int            Count     = 0;

            if (model.Id == -999)
            {
                return(false);
            }

            if (model.Id != -999)
            {
                filedName[Count] = "Id";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Id);
                Count++;
            }
            if (model.Name != null)
            {
                filedName[Count] = "Name";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Name);
                Count++;
            }
            if (model.RoomType != null)
            {
                filedName[Count] = "RoomType";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.RoomType);
                Count++;
            }
            if (model.RoomPrice != -999)
            {
                filedName[Count] = "RoomPrice";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.RoomPrice);
                Count++;
            }
            if (model.Are != null)
            {
                filedName[Count] = "Are";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Are);
                Count++;
            }
            if (model.Address != null)
            {
                filedName[Count] = "Address";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Address);
                Count++;
            }
            if (model.ImagePath != null)
            {
                filedName[Count] = "ImagePath";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.ImagePath);
                Count++;
            }
            if (model.Content != null)
            {
                filedName[Count] = "Content";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Content);
                Count++;
            }
            if (model.RoomState != -999)
            {
                filedName[Count] = "RoomState";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.RoomState);
                Count++;
            }
            if (model.OwnerID != -999)
            {
                filedName[Count] = "OwnerID";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.OwnerID);
                Count++;
            }
            if (model.IfRecommend != -999)
            {
                filedName[Count] = "IfRecommend";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.IfRecommend);
                Count++;
            }
            if (model.Examine != -999)
            {
                filedName[Count] = "IfExamine";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Examine);
                Count++;
            }
            if (model.RecommendTime != null)
            {
                filedName[Count] = "RecommendTime";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.RecommendTime);
                Count++;
            }

            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Room set ");
            for (int i = 1; i < Count; i++)
            {
                strSql.Append(filedName[i]);
                strSql.Append("=");
                strSql.Append(paramName[i]);
                if (i != Count - 1)
                {
                    strSql.Append(",");
                }
            }
            strSql.Append(" where ");
            strSql.Append(filedName[0] + "=" + paramName[0]);


            int num = Convert.ToInt32(sqlHelper_.ExecuteCommand(
                                          strSql.ToString(),
                                          CommandType.Text,
                                          sqlParams
                                          ));

            if (num != 1)
            {
                res = false;
            }
            else
            {
                res = true;
            }

            return(res);
        }
Ejemplo n.º 3
0
        public int Add(QPS.NEW.Model.Room model)
        {
            string[]       filedName = new string[50];
            string[]       paramName = new string[50];
            SqlParameter[] sqlParams = new SqlParameter[50];
            int            Count     = 0;



            if (model.Name != null)
            {
                filedName[Count] = "Name";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Name);
                Count++;
            }
            if (model.RoomType != null)
            {
                filedName[Count] = "RoomType";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.RoomType);
                Count++;
            }
            if (model.RoomPrice != -999)
            {
                filedName[Count] = "RoomPrice";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.RoomPrice);
                Count++;
            }
            if (model.Are != null)
            {
                filedName[Count] = "Are";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Are);
                Count++;
            }
            if (model.Address != null)
            {
                filedName[Count] = "Address";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Address);
                Count++;
            }
            if (model.ImagePath != null)
            {
                filedName[Count] = "ImagePath";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.ImagePath);
                Count++;
            }
            if (model.Content != null)
            {
                filedName[Count] = "Content";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Content);
                Count++;
            }
            if (model.RoomState != -999)
            {
                filedName[Count] = "RoomState";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.RoomState);
                Count++;
            }
            if (model.OwnerID != -999)
            {
                filedName[Count] = "OwnerID";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.OwnerID);
                Count++;
            }
            if (model.IfRecommend != -999)
            {
                filedName[Count] = "IfRecommend";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.IfRecommend);
                Count++;
            }
            if (model.Examine != -999)
            {
                filedName[Count] = "IfExamine";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.Examine);
                Count++;
            }
            if (model.RecommendTime != null)
            {
                filedName[Count] = "RecommendTime";
                paramName[Count] = "@" + filedName[Count];
                sqlParams[Count] = new SqlParameter(paramName[Count], model.RecommendTime);
                Count++;
            }


            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Room(");
            for (int i = 0; i < Count; i++)
            {
                strSql.Append(filedName[i]);
                if (i != Count - 1)
                {
                    strSql.Append(",");
                }
            }
            strSql.Append(")values(");
            for (int i = 0; i < Count; i++)
            {
                strSql.Append(paramName[i]);
                if (i != Count - 1)
                {
                    strSql.Append(",");
                }
            }
            strSql.Append(")");


            int res = -1;

            res = sqlHelper_.ExecuteCommand(
                strSql.ToString(),
                CommandType.Text,
                sqlParams
                );

            if (res != 1)
            {
                return(0);
            }

            return(1);
        }