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

            strSql.Append("update [OA_Diary] set ");
            strSql.Append("Title=@Title,");
            strSql.Append("WorkDate=@WorkDate,");
            strSql.Append("WorkDuration=@WorkDuration,");
            strSql.Append("Note=@Note ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Title",        SqlDbType.NVarChar,   100),
                new SqlParameter("@WorkDate",     SqlDbType.DateTime),
                new SqlParameter("@WorkDuration", SqlDbType.Float,        8),
                new SqlParameter("@Note",         SqlDbType.NVarChar,  1000),
                new SqlParameter("@ID",           SqlDbType.BigInt)
            };
            parameters[0].Value = model.Title;
            parameters[1].Value = model.WorkDate;
            parameters[2].Value = model.WorkDuration;
            parameters[3].Value = model.Note;
            parameters[4].Value = model.ID;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <DiaryEntity> DataTableToList(DataTable dt)
        {
            List <DiaryEntity> modelList = new List <DiaryEntity>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                DiaryEntity model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new DiaryEntity();
                    //model.ID=dt.Rows[n]["ID"].ToString();
                    model.Title = dt.Rows[n]["Title"].ToString();
                    if (dt.Rows[n]["WorkDate"].ToString() != "")
                    {
                        model.WorkDate = DateTime.Parse(dt.Rows[n]["WorkDate"].ToString());
                    }
                    if (dt.Rows[n]["WorkDuration"].ToString() != "")
                    {
                        model.WorkDuration = decimal.Parse(dt.Rows[n]["WorkDuration"].ToString());
                    }
                    model.Note = dt.Rows[n]["Note"].ToString();
                    if (dt.Rows[n]["OwnerID"].ToString() != "")
                    {
                        model.OwnerID = int.Parse(dt.Rows[n]["OwnerID"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return(modelList);
        }
Exemplo n.º 3
0
        public void Insert(DiaryEntity item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            this._repository.Insert(item);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public DiaryEntity GetModelByDate(int AccountID, DateTime dateTime)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select ID,Title,WorkDate,WorkDuration,Note,OwnerID,Comment,CreateTime from [OA_Diary]");
            strSql.Append(" where WorkDate=convert(dateTime,'" + dateTime.ToString("yyyy-MM-dd") + "',21) ");
            strSql.Append(" and  OwnerID=@OwnerID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@WorkDate", SqlDbType.DateTime),
                new SqlParameter("@OwnerID",  SqlDbType.Int, 4)
            };
            parameters[0].Value = Convert.ToDateTime(dateTime);
            parameters[1].Value = AccountID;
            DiaryEntity model = new DiaryEntity();
            DataSet     ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = long.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
                if (ds.Tables[0].Rows[0]["WorkDate"].ToString() != "")
                {
                    model.WorkDate = DateTime.Parse(ds.Tables[0].Rows[0]["WorkDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["WorkDuration"].ToString() != "")
                {
                    model.WorkDuration = decimal.Parse(ds.Tables[0].Rows[0]["WorkDuration"].ToString());
                }
                model.Note = ds.Tables[0].Rows[0]["Note"].ToString();
                if (ds.Tables[0].Rows[0]["OwnerID"].ToString() != "")
                {
                    model.OwnerID = int.Parse(ds.Tables[0].Rows[0]["OwnerID"].ToString());
                }
                model.Note    = ds.Tables[0].Rows[0]["Note"].ToString();
                model.Comment = ds.Tables[0].Rows[0]["Comment"].ToString();
                if (ds.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DiaryEntity GetEntity(long ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,Title,WorkDate,WorkDuration,Note,OwnerID,Comment,CreateTime from [OA_Diary] ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.BigInt)
            };
            parameters[0].Value = ID;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = long.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
                if (ds.Tables[0].Rows[0]["WorkDate"].ToString() != "")
                {
                    model.WorkDate = DateTime.Parse(ds.Tables[0].Rows[0]["WorkDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["WorkDuration"].ToString() != "")
                {
                    model.WorkDuration = decimal.Parse(ds.Tables[0].Rows[0]["WorkDuration"].ToString());
                }
                model.Note = ds.Tables[0].Rows[0]["Note"].ToString();
                if (ds.Tables[0].Rows[0]["OwnerID"].ToString() != "")
                {
                    model.OwnerID = int.Parse(ds.Tables[0].Rows[0]["OwnerID"].ToString());
                }
                model.Note    = ds.Tables[0].Rows[0]["Note"].ToString();
                model.Comment = ds.Tables[0].Rows[0]["Comment"].ToString();
                if (ds.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 6
0
        public ActionResult Add(DiaryModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.CreateTime == null)
                {
                    model.CreateTime = DateTime.Today;
                }

                var normFiles = model.Files != null
                    ? model.Files.Where(f => f != null).ToArray()
                    : new HttpPostedFileBase[0];

                if (normFiles.Length > 3)
                {
                    ModelState.AddModelError("", "图片不能超过3张");
                }
                else
                {
                    if (normFiles.Any())
                    {
                        foreach (HttpPostedFileBase file in normFiles)
                        {
                            string path = System.IO.Path.Combine(Server.MapPath("~/Images/diary"), file.FileName);
                            file.SaveAs(path);
                        }

                        List <string> oldImgs =
                            (model.Images ?? "").Split(';')
                            .Where(s => !string.IsNullOrEmpty(s) && !string.IsNullOrWhiteSpace(s)).ToList();

                        oldImgs.AddRange(normFiles.Select(file => file.FileName));
                        model.Images = string.Join(";", oldImgs.Distinct());
                    }

                    var entity = new DiaryEntity();
                    model.CopyTo(entity);
                    this.ServiceManager.DiaryService.Insert(entity);

                    return(this.RedirectToAction("Index", "Diary"));
                }
            }

            return(this.View());
        }
Exemplo n.º 7
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(long ID, string Comment)
        {
            DiaryEntity diaryEntity = GetEntity(ID);

            StringBuilder strSql = new StringBuilder();

            strSql.Append("update [OA_Diary] set ");
            strSql.Append("Comment=@Comment");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID",      SqlDbType.BigInt),
                new SqlParameter("@Comment", SqlDbType.NVarChar, 500)
            };
            parameters[0].Value = ID;
            parameters[1].Value = diaryEntity.Comment + Comment;
            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(DiaryEntity model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into [OA_Diary](");
            strSql.Append("Title,WorkDate,WorkDuration,Note,OwnerID,Comment,CreateTime)");
            strSql.Append(" values (");
            strSql.Append("@Title,@WorkDate,@WorkDuration,@Note,@OwnerID,@Comment,@CreateTime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Title",        SqlDbType.NVarChar,   100),
                new SqlParameter("@WorkDate",     SqlDbType.DateTime),
                new SqlParameter("@WorkDuration", SqlDbType.Float,        8),
                new SqlParameter("@Note",         SqlDbType.NVarChar,  1000),
                new SqlParameter("@OwnerID",      SqlDbType.Int,          4),
                new SqlParameter("@Comment",      SqlDbType.NVarChar,   500),
                new SqlParameter("@CreateTime",   SqlDbType.DateTime)
            };
            parameters[0].Value = model.Title;
            parameters[1].Value = model.WorkDate;
            parameters[2].Value = model.WorkDuration;
            parameters[3].Value = model.Note;
            parameters[4].Value = model.OwnerID;
            parameters[5].Value = model.Comment;
            parameters[6].Value = DateTime.Now;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public void Update(DiaryEntity model)
 {
     dal.Update(model);
 }
Exemplo n.º 10
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(DiaryEntity model)
 {
     return(dal.Add(model));
 }