Beispiel #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public LYSC.CompanyWeb.Model.HKSJ_Employees GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,title,content,people,date,status,MainPeople from HKSJ_Employees ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            LYSC.CompanyWeb.Model.HKSJ_Employees model = new LYSC.CompanyWeb.Model.HKSJ_Employees();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "")
                {
                    model.title = ds.Tables[0].Rows[0]["title"].ToString();
                }
                if (ds.Tables[0].Rows[0]["content"] != null && ds.Tables[0].Rows[0]["content"].ToString() != "")
                {
                    model.content = ds.Tables[0].Rows[0]["content"].ToString();
                }
                if (ds.Tables[0].Rows[0]["people"] != null && ds.Tables[0].Rows[0]["people"].ToString() != "")
                {
                    model.people = ds.Tables[0].Rows[0]["people"].ToString();
                }
                if (ds.Tables[0].Rows[0]["date"] != null && ds.Tables[0].Rows[0]["date"].ToString() != "")
                {
                    model.date = DateTime.Parse(ds.Tables[0].Rows[0]["date"].ToString());
                }
                if (ds.Tables[0].Rows[0]["status"] != null && ds.Tables[0].Rows[0]["status"].ToString() != "")
                {
                    model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MainPeople"] != null && ds.Tables[0].Rows[0]["MainPeople"].ToString() != "")
                {
                    model.MainPeople = ds.Tables[0].Rows[0]["MainPeople"].ToString();
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(LYSC.CompanyWeb.Model.HKSJ_Employees model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update HKSJ_Employees set ");
            strSql.Append("title=@title,");
            strSql.Append("content=@content,");
            strSql.Append("people=@people,");
            strSql.Append("date=@date,");
            strSql.Append("status=@status,");
            strSql.Append("MainPeople=@MainPeople");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@title",      SqlDbType.VarChar,   200),
                new SqlParameter("@content",    SqlDbType.NText),
                new SqlParameter("@people",     SqlDbType.VarChar,    30),
                new SqlParameter("@date",       SqlDbType.DateTime),
                new SqlParameter("@status",     SqlDbType.Int,         4),
                new SqlParameter("@MainPeople", SqlDbType.VarChar,    20),
                new SqlParameter("@ID",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.title;
            parameters[1].Value = model.content;
            parameters[2].Value = model.people;
            parameters[3].Value = model.date;
            parameters[4].Value = model.status;
            parameters[5].Value = model.MainPeople;
            parameters[6].Value = model.ID;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(LYSC.CompanyWeb.Model.HKSJ_Employees model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into HKSJ_Employees(");
            strSql.Append("title,content,people,date,status,MainPeople)");
            strSql.Append(" values (");
            strSql.Append("@title,@content,@people,@date,@status,@MainPeople)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@title",      SqlDbType.VarChar,   200),
                new SqlParameter("@content",    SqlDbType.NText),
                new SqlParameter("@people",     SqlDbType.VarChar,    30),
                new SqlParameter("@date",       SqlDbType.DateTime),
                new SqlParameter("@status",     SqlDbType.Int,         4),
                new SqlParameter("@MainPeople", SqlDbType.VarChar, 20)
            };
            parameters[0].Value = model.title;
            parameters[1].Value = model.content;
            parameters[2].Value = model.people;
            parameters[3].Value = model.date;
            parameters[4].Value = model.status;
            parameters[5].Value = model.MainPeople;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }