Exemplo n.º 1
0
 public void YHSumUpdate(string yhId)
 {
     //JsonRetModel Ret = new JsonRetModel { Ret = false };
     #region 验证
     try
     {
         using (TeamWorkDbContext et = new TeamWorkDbContext())
         {
             T_YH_HiddenDanger_Entity yh = et.T_YH_HiddenDanger_Entity.FirstOrDefault(k => k.HiddenDangerId == yhId);
             if (yh != null)
             {
                 string ym = yh.CheckTime.Value.ToString("yyyyMM");
                 T_YH_SumRecords_Entity sum = et.T_YH_SumRecords_Entity.FirstOrDefault(k => k.MonthDate == ym);
                 if (sum != null)
                 {
                     DateTime _monthFirst = Convert.ToDateTime(yh.CheckTime.Value.ToString("yyyy-MM") + "-01"), _nextFirst = _monthFirst.AddMonths(1);
                     var      _list = et.T_YH_HiddenDanger_Entity.Where(k => k.CheckTime >= _monthFirst && k.CheckTime < _nextFirst && k.IsDeleted == false && k.OrgCode == yh.OrgCode);
                     sum.CommonlyCnt = _list.Where(k => k.HiddenLevel == "一般隐患").Count();
                     sum.MajorCnt    = _list.Where(k => k.HiddenLevel == "重大隐患").Count();
                     sum.CorrectCnt  = _list.Where(k => k.Result == "已整改").Count();
                     sum.ScheduleCnt = _list.Where(k => k.CompleteTime <= k.TimeLimit).Count();
                     sum.TotalCnt    = _list.Count();
                     et.SaveChanges();
                 }
             }
         }
     }
     #endregion
     #region 异常
     catch (Exception ex)
     {
     }
     #endregion
 }
Exemplo n.º 2
0
        //On<Insert|Updat|Delet|Execut><ed|ing><EntitySetName|ActionName>其中ing的前提交,并ed于提交后。

        #region T_XT_Data_Entity

        #region 新增
        protected void OnInsertingT_XT_Data_Entity(T_XT_Data_Entity entityset)
        {
            try
            {
                if (string.IsNullOrEmpty(entityset.DataId))
                {
                    entityset.DataId = Guid.NewGuid().ToString("N");
                }

                entityset.CreateTime    = DateTime.Now;
                entityset.IsDeleted     = false;
                entityset.SubItemAmount = 0;
                #region 更新子节点数量
                using (TeamWorkDbContext et = new TeamWorkDbContext())
                {
                    T_XT_Data_Entity _p = et.T_XT_Data_Entity.FirstOrDefault(k => k.DataId == entityset.ParentId);
                    if (_p != null)
                    {
                        _p.SubItemAmount = et.T_XT_Data_Entity.Where(k => k.ParentId == _p.DataId && k.IsDeleted == false).Count() + 1;
                        et.SaveChanges();
                    }
                }
                #endregion
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 文件下载
        /// </summary>
        /// <param name="docId"></param>
        /// <returns></returns>
        public FileStreamResult FileDownload(string docId)
        {
            FileStreamResult Ret = null;

            try
            {
                #region 判断是否为空
                if (!string.IsNullOrEmpty(docId))
                {
                    using (TeamWorkDbContext et = new TeamWorkDbContext())
                    {
                        KeyValModel     kv   = GetCurrentStoreDirectory();
                        T_XT_Doc_Entity _doc = et.T_XT_Doc_Entity.FirstOrDefault(d => d.IsDeleted == false && d.DocId == docId);
                        if (kv != null && _doc != null)
                        {
                            string filePath = Server.MapPath(string.Format("~/DocLib/{0}/{1}", _doc.SubDirectory, _doc.InternalName));//路径
                            Ret = File(new FileStream(filePath, FileMode.Open), "text/plain", _doc.DocName);

                            _doc.DownloadCount = _doc.DownloadCount ?? 0;
                            _doc.DownloadCount++;
                            et.SaveChanges();
                        }
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
            }
            return(Ret);
        }
Exemplo n.º 4
0
 protected void OnDeletingT_XT_Data_Entity(T_XT_Data_Entity entityset)
 {
     entityset.ModifyTime = DateTime.Now;
     entityset.IsDeleted  = true;
     #region 更新子节点数量
     using (TeamWorkDbContext et = new TeamWorkDbContext())
     {
         T_XT_Data_Entity _p = et.T_XT_Data_Entity.FirstOrDefault(k => k.DataId == entityset.ParentId);
         if (_p != null)
         {
             _p.SubItemAmount = et.T_XT_Data_Entity.Where(k => k.ParentId == _p.DataId && k.IsDeleted == false).Count() - 1;
             et.SaveChanges();
         }
     }
     #endregion
 }
Exemplo n.º 5
0
        public JsonResult PersonRecordAdd(T_WH_PersonRecord_Entity saveData)
        {
            JsonRetModel Ret = new JsonRetModel {
                Ret = false
            };

            #region 验证
            try
            {
                using (TeamWorkDbContext et = new TeamWorkDbContext())
                {
                    T_WH_PersonRecord_Entity u = et.T_WH_PersonRecord_Entity.Find(saveData.RecordId);
                    if (u != null)
                    {
                        CommonHelper.RemoveHoldingEntityInContext <T_WH_PersonRecord_Entity>(u, et);
                        u = saveData;
                        et.Entry <T_WH_PersonRecord_Entity>(u).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        saveData.RecordId = System.Guid.NewGuid().ToString("N");
                        u = et.T_WH_PersonRecord_Entity.Add(saveData);
                    }
                    et.SaveChanges();
                    Ret.Data = saveData.RecordId;
                    Ret.Msg  = "保存成功";
                    Ret.Ret  = true;
                }
            }
            #endregion
            #region 异常
            catch (Exception ex)
            {
                Ret.Ret = false;
                Ret.Msg = ex.Message;
            }
            #endregion
            return(Json(Ret, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 6
0
        public JsonResult XTStaticDatasDelete(string delId)
        {
            JsonRetModel ret = new JsonRetModel {
                Ret = false
            };

            try
            {
                using (TeamWorkDbContext et = new TeamWorkDbContext())
                {
                    T_XT_Data_Entity _d = et.T_XT_Data_Entity.FirstOrDefault(k => k.DataId == delId);

                    if (_d != null)
                    {
                        _d.ModifyTime = DateTime.Now;
                        _d.IsDeleted  = true;
                        T_XT_Data_Entity _p = et.T_XT_Data_Entity.FirstOrDefault(k => k.DataId == _d.ParentId);
                        if (_p != null)
                        {
                            _p.SubItemAmount = et.T_XT_Data_Entity.Where(k => k.ParentId == _p.DataId && k.IsDeleted == false).Count() - 1;
                        }
                        et.SaveChanges();
                        ret.Ret = true;
                        ret.Msg = "操作成功!";
                    }
                    else
                    {
                        ret.Msg = "操作失败,此节点可能已经被删除!";
                    }
                }
            }
            catch (Exception ex)
            {
                ret.Msg = ex.Message;
            }
            return(Json(ret));
        }
Exemplo n.º 7
0
        public JsonResult SignIn(string userName, string password)
        {
            JsonRetModel Ret = new JsonRetModel {
                Ret = false
            };

            #region 验证
            try
            {
                using (TeamWorkDbContext et = new TeamWorkDbContext())
                {
                    T_XT_User_Entity _u = et.T_XT_User_Entity.FirstOrDefault(u => u.EmpCode == userName);
                    #region 存在用户
                    if (_u != null)
                    {
                        #region 验证成功
                        if (_u.LoginPassword.ToUpper() == CommonHelper.StringToMD5(password))
                        {
                            _u.LastLoginTime = _u.TheLoginTime;
                            _u.TheLoginTime  = DateTime.Now;

                            T_XT_LogRecords_Entity _log = new T_XT_LogRecords_Entity {
                                LogRecordId     = Guid.NewGuid().ToString("N"),
                                EmpCode         = _u.EmpCode,
                                EmpName         = _u.EmpName,
                                CreateByEmpCode = "system",
                                CreateByEmpName = "系统",
                                CreateTime      = DateTime.Now,
                                IsDeleted       = false
                            };

                            et.T_XT_LogRecords_Entity.Add(_log);
                            et.SaveChanges();

                            #region 记录Session

                            Session["User"] = userName;
                            #endregion

                            Ret.Msg = "登录成功";
                            Ret.Ret = true;
                        }
                        #endregion
                        #region 密码错误
                        else
                        {
                            Ret.Msg = "密码错误";
                        }
                        #endregion
                    }
                    #endregion
                    #region 用户不存在
                    else
                    {
                        Ret.Msg = "用户不存在";
                    }
                    #endregion
                }
            }
            #endregion
            #region 异常
            catch (Exception ex)
            {
                Ret.Ret = false;
                Ret.Msg = ex.Message;
            }
            #endregion
            return(Json(Ret, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 8
0
        public JsonResult XTStaticDatasSort(string DataId, string SortFlag)
        {
            JsonRetModel ret = new JsonRetModel {
                Ret = false
            };

            try
            {
                using (TeamWorkDbContext et = new TeamWorkDbContext())
                {
                    T_XT_Data_Entity _d = et.T_XT_Data_Entity.Where(item => item.DataId == DataId).FirstOrDefault();
                    if (_d != null)
                    {
                        var list  = et.T_XT_Data_Entity.Where(item => item.ParentId == _d.ParentId && item.IsDeleted == false).OrderBy(k => k.SortIndex);
                        var _list = list.ToList();
                        if (_list.Any())
                        {
                            if (SortFlag == "up" && _list.FirstOrDefault().DataId == DataId)
                            {
                                ret.Msg = "已经是第一个了!";
                            }
                            else if (SortFlag == "down" && _list.LastOrDefault().DataId == DataId)
                            {
                                ret.Msg = "已经是最后一个了!";
                            }
                            else
                            {
                                int _index = 0, _target = 0;
                                foreach (var d in list)
                                {
                                    d.SortIndex = _index++;
                                    if (d.DataId == DataId)
                                    {
                                        _target = Convert.ToInt32(d.SortIndex);
                                    }
                                }

                                T_XT_Data_Entity dd = list.Skip(_target).FirstOrDefault();

                                switch (SortFlag)
                                {
                                case "up":
                                    dd.SortIndex--;
                                    var _prev = list.Skip(_target - 1).FirstOrDefault();
                                    _prev.SortIndex++;
                                    break;

                                case "down":
                                    dd.SortIndex++;
                                    var _next = list.Skip(_target + 1).FirstOrDefault();
                                    _next.SortIndex--;
                                    break;

                                default:
                                    break;
                                }
                                et.SaveChanges();
                                ret.Ret = true;
                                ret.Msg = "操作成功!";
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ret.Msg = ex.Message;
            }

            return(Json(ret));
        }
Exemplo n.º 9
0
        public JsonResult FilesDelete(string[] docIds)
        {
            JsonRetModel ret = new JsonRetModel {
                Ret = false
            };

            try
            {
                KeyValModel kv = GetCurrentStoreDirectory();
                if (!docIds.Any())
                {
                    ret.Msg = "未检测到需要删除的文件!";
                    return(Json(ret));
                }
                if (kv == null)
                {
                    ret.Msg = "未能获取到文件储存目录!";
                    return(Json(ret));
                }

                using (TeamWorkDbContext et = new TeamWorkDbContext())
                {
                    foreach (string _docId in docIds)
                    {
                        T_XT_Doc_Entity _doc = et.T_XT_Doc_Entity.FirstOrDefault(k => k.DocId == _docId);
                        if (_doc != null)
                        {
                            #region  除文件
                            string   path = string.Format("{0}\\{1}\\{2}", kv.Val, _doc.SubDirectory, _doc.InternalName);
                            FileInfo info = new FileInfo(path);
                            if (info.Exists)
                            {
                                info.Delete();
                            }
                            #endregion

                            #region 如果是图片类型的连带删除缩略图
                            if (CheckImageExt(_doc.DocType))
                            {
                                string   img_sp = string.Format("{0}\\{1}\\{2}_s{3}", kv.Val, _doc.SubDirectory, _doc.InternalName.Replace(_doc.DocType, ""), _doc.DocType);
                                FileInfo img_s  = new FileInfo(img_sp);
                                if (img_s.Exists)
                                {
                                    img_s.Delete();
                                }
                            }
                            #endregion

                            #region  除表数据(伪删除)
                            _doc.IsDeleted = true;
                            et.SaveChanges();
                            #endregion
                        }
                    }
                    ret.Msg = "操作成功";
                    ret.Ret = true;
                }
            }
            catch (Exception e)
            {
                ret.Msg = e.Message;
                ret.Ret = false;
            }
            return(Json(ret));
        }
Exemplo n.º 10
0
        public JsonResult FileUpload()
        {
            JsonRetModel ret = new JsonRetModel();

            try
            {
                Response.ContentType     = "text/plain";
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
                Response.Charset         = "utf-8";

                string _RelevanceId    = Request["RelevanceId"],
                       _FromModuleName = Request["FromModuleName"],
                       _FromTableName  = Request["FromTableName"],
                       _ExpandOne      = Request["ExpandOne"],
                       _ExpandTwo      = Request["ExpandTwo"],
                       _ExpandThree    = Request["ExpandThree"],
                       _ExpandFour     = Request["ExpandFour"],
                       _ExpandFive     = Request["ExpandFive"];

                HttpPostedFileBase file = Request.Files["file"];

                KeyValModel kv = GetCurrentStoreDirectory();//获取存储物理路径
                if (kv != null)
                {
                    using (TeamWorkDbContext et = new TeamWorkDbContext())
                    {
                        string storeDirectoryId = kv.Key,
                               storeDirectory   = kv.Val,
                               subDirectory     = DateTime.Now.ToString("yyyyMM"),
                               uploadPath       = storeDirectory + @"\" + subDirectory + @"\";
                        bool IsImg = false;

                        if (file != null)
                        {
                            if (!Directory.Exists(uploadPath))
                            {
                                Directory.CreateDirectory(uploadPath);
                            }
                            string[] array        = file.FileName.Split('.');
                            string   suffix       = "." + array[array.Length - 1],
                                     internalName = Guid.NewGuid().ToString("N"),
                                     realPath     = uploadPath + internalName,
                                     fullPath     = realPath + suffix;

                            if (CheckImageExt(suffix))
                            {
                                IsImg = true;
                                MakeSmallImg(file.InputStream, realPath + "_s" + suffix, 100, 100);
                                MakeSmallImg(file.InputStream, fullPath, 800, 800);
                            }
                            else
                            {
                                file.SaveAs(fullPath);
                            }

                            string fileName = file.FileName.Substring(file.FileName.LastIndexOf('/') + 1);

                            T_XT_Doc_Entity _doc = new T_XT_Doc_Entity
                            {
                                DocId            = Guid.NewGuid().ToString("N"),
                                StoreDirectoryId = storeDirectoryId,
                                DocName          = fileName,
                                DocType          = suffix,
                                DocSize          = file.ContentLength,
                                SubDirectory     = subDirectory,
                                InternalName     = internalName + suffix,
                                DownloadCount    = 0,
                                FromModuleName   = _FromModuleName,
                                FromTableName    = _FromTableName,
                                RelevanceId      = _RelevanceId,
                                ExpandOne        = _ExpandOne,
                                ExpandTwo        = _ExpandTwo,
                                ExpandThree      = _ExpandThree,
                                ExpandFour       = _ExpandFour,
                                ExpandFive       = _ExpandFive,
                                CreateTime       = DateTime.Now,
                                IsDeleted        = false
                            };
                            et.T_XT_Doc_Entity.Add(_doc);
                            et.SaveChanges();

                            ret.Ret = true;
                            ret.Msg = "上传成功";

                            ret.Data = new
                            {
                                DocId      = _doc.DocId,
                                DocName    = _doc.DocName,
                                Size       = _doc.DocSize,
                                CreateTime = _doc.CreateTime,
                                Path       = string.Format("DocLib/{0}/{1}", subDirectory, _doc.InternalName)
                                             //,Path_s = IsImg?string.Format("DocLib/{0}/{1}_s{2}", subDirectory, realPath, suffix):null
                            };
                        }
                        else
                        {
                            ret.Ret = false;
                            ret.Msg = "未检测到文件";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ret.Ret = false;
                ret.Msg = ex.Message;
            }

            return(Json(ret));
        }