コード例 #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Hownet.Model.DepartmentJobs model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into DepartmentJobs(");
            strSql.Append("JobsName,DepartmentID,Remark,EmployeeCount,IsEnd)");
            strSql.Append(" values (");
            strSql.Append("@JobsName,@DepartmentID,@Remark,@EmployeeCount,@IsEnd)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@JobsName",      SqlDbType.NVarChar,  50),
                new SqlParameter("@DepartmentID",  SqlDbType.Int,        4),
                new SqlParameter("@Remark",        SqlDbType.NVarChar, 255),
                new SqlParameter("@EmployeeCount", SqlDbType.Int,        4),
                new SqlParameter("@IsEnd",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.JobsName;
            parameters[1].Value = model.DepartmentID;
            parameters[2].Value = model.Remark;
            parameters[3].Value = model.EmployeeCount;
            parameters[4].Value = model.IsEnd;

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

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
コード例 #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Hownet.Model.DepartmentJobs model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update DepartmentJobs set ");
            strSql.Append("JobsName=@JobsName,");
            strSql.Append("DepartmentID=@DepartmentID,");
            strSql.Append("Remark=@Remark,");
            strSql.Append("EmployeeCount=@EmployeeCount,");
            strSql.Append("IsEnd=@IsEnd");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID",            SqlDbType.Int,        4),
                new SqlParameter("@JobsName",      SqlDbType.NVarChar,  50),
                new SqlParameter("@DepartmentID",  SqlDbType.Int,        4),
                new SqlParameter("@Remark",        SqlDbType.NVarChar, 255),
                new SqlParameter("@EmployeeCount", SqlDbType.Int,        4),
                new SqlParameter("@IsEnd",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.ID;
            parameters[1].Value = model.JobsName;
            parameters[2].Value = model.DepartmentID;
            parameters[3].Value = model.Remark;
            parameters[4].Value = model.EmployeeCount;
            parameters[5].Value = model.IsEnd;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
コード例 #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Hownet.Model.DepartmentJobs GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,JobsName,DepartmentID,Remark,EmployeeCount,IsEnd from DepartmentJobs ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            Hownet.Model.DepartmentJobs model = new Hownet.Model.DepartmentJobs();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                model.JobsName = ds.Tables[0].Rows[0]["JobsName"].ToString();
                if (ds.Tables[0].Rows[0]["DepartmentID"].ToString() != "")
                {
                    model.DepartmentID = int.Parse(ds.Tables[0].Rows[0]["DepartmentID"].ToString());
                }
                model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
                if (ds.Tables[0].Rows[0]["EmployeeCount"].ToString() != "")
                {
                    model.EmployeeCount = int.Parse(ds.Tables[0].Rows[0]["EmployeeCount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsEnd"].ToString() != "")
                {
                    model.IsEnd = int.Parse(ds.Tables[0].Rows[0]["IsEnd"].ToString());
                }
                model.A = 1;
                return(model);
            }
            else
            {
                return(null);
            }
        }