public JsonResult GetInfo(string ID)
        {
            var             mql2   = TT_FilesInsuranSet.SelectAll().Where(TT_FilesInsuranSet.FileId.Equal(ID));
            TT_FilesInsuran Rmodel = OPBiz.GetEntity(mql2);

            //  groupsBiz.Add(rol);
            return(Json(Rmodel, JsonRequestBehavior.AllowGet));
        }
        public JsonResult EditInfo(TT_FilesInsuran EidModle)
        {
            HttpReSultMode ReSultMode = new HttpReSultMode();
            bool           IsAdd      = false;

            if (!(EidModle.FileId != null && !EidModle.FileId.ToString().Equals("00000000-0000-0000-0000-000000000000"))) //id为空,是添加
            {
                IsAdd = true;
                //EidModle.FileId = Guid.NewGuid();
                //EidModle.CreateTime = DateTime.Now;
                //EidModle.UpdateTime = DateTime.Now;
                EidModle.isValid   = true;
                EidModle.isDeleted = false;
            }
            if (IsAdd)
            {
                try
                {
                    OPBiz.Add(EidModle);
                    ReSultMode.Code = 11;
                    ReSultMode.Data = EidModle.FileId.ToString();
                    ReSultMode.Msg  = "添加成功";
                }
                catch (Exception e) {
                    ReSultMode.Code = -11;
                    ReSultMode.Data = e.ToString();
                    ReSultMode.Msg  = "添加失败";
                }
            }
            else
            {
                EidModle.WhereExpression = TT_FilesInsuranSet.FileId.Equal(EidModle.FileId);
                string idfilec = "FileId";
                EidModle.ChangedMap.Remove(idfilec.ToLower());//移除主键值
                if (OPBiz.Update(EidModle) > 0)
                {
                    ReSultMode.Code = 11;
                    ReSultMode.Data = "";
                    ReSultMode.Msg  = "修改成功";
                }
                else
                {
                    ReSultMode.Code = -13;
                    ReSultMode.Data = "";
                    ReSultMode.Msg  = "修改失败";
                }
            }

            return(Json(ReSultMode, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        /// <summary>
        /// 上传文件,并添加到数据库
        /// </summary>
        /// <param name="rsm">通知参数类</param>
        /// <param name="hpFile">http文件</param>
        /// <param name="lenth">最大长度,kb</param>
        /// <param name="SourceTable">来源表</param>
        /// <param name="ToId">主体Id</param>
        /// <param name="ShowName">显示名</param>
        /// <returns></returns>
        private TT_FilesInsuran AddFileOne(out HttpReSultMode rsm, HttpPostedFile hpFile, string[] allowExtensions, int lenth, string SourceTable, string ToId, string ShowName)
        {
            try
            {
                string FileName = hpFile.FileName;
                string ext      = System.IO.Path.GetExtension(FileName);// 后缀名

                FileName = FileName.Substring(FileName.LastIndexOf("\\") + 1);
                TT_FilesInsuran file = new TT_FilesInsuran();
                file.ToId        = ToId;
                file.AddTime     = DateTime.Now;
                file.SourceTable = SourceTable;

                if (!string.IsNullOrEmpty(ShowName))
                {
                    file.ShowName = ShowName + ext;
                }
                else
                {
                    file.ShowName = FileName;
                }
                file.Suffix    = ext;
                file.FileType  = "文件";
                file.isValid   = true;
                file.isDeleted = false;

                string HttpFileWeb       = ConfigurationManager.AppSettings["HttpFileWeb"].ToString();   //文件 http站点
                string HttpFileRoute     = ConfigurationManager.AppSettings["HttpFileRoute"].ToString(); //文件保存本地路径根目录
                string FileRelativeRoute = ConfigurationManager.AppSettings["TransactRoute"].ToString(); //文件保存相对目录
                //给文件取随及名
                Guid Pguid = Guid.NewGuid();
                FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + Pguid + ext;


                file.Route        = HttpFileWeb;
                file.RelativePath = FileRelativeRoute + FileName;
                file.FileName     = FileName;


                //保存文件路径
                string path = HttpFileRoute + FileRelativeRoute;

                rsm = ZFiles.FilesUpload(hpFile, allowExtensions, lenth, path, FileName);

                if (rsm.Code > 0)
                {
                    /*添加一条信息;*/
                    object resId = OPBiz.Add(file);
                    if (resId != null)
                    {
                        file.FileId = long.Parse(resId.ToString());
                        return(file);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                rsm = new HttpReSultMode()
                {
                    Code = -13,
                    Data = ex.Message,
                    Msg  = "系统出错:" + ex.Message
                };

                return(null);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public HttpReSultMode addFile(HttpContext context)
        {
            string SourceTable = "";

            if (context.Request["SourceTable"] != null)
            {
                SourceTable = context.Request["SourceTable"];
            }
            string ToId = "";

            if (context.Request["ToId"] != null)
            {
                ToId = context.Request["ToId"];
            }
            string ShowName = "";

            if (context.Request["ShowName"] != null)
            {
                ShowName = context.Request["ShowName"];
            }


            HttpReSultMode         jmsg     = new HttpReSultMode();
            List <TT_FilesInsuran> listFile = new List <TT_FilesInsuran>();
            string FileIdSet = ""; //返回Id集
            int    res       = 0;  //成功统计

            string[] Types = { ".doc", ".xls", ".ppt", ".jpg", ".gif", ".jpeg", ".bmp", ".png", ".ico" };
            int      lenth = 500;//kb

            #region
            if (context.Request.Files.Count > 0)
            {
                for (int i = 0; i < context.Request.Files.Count; i++)
                {
                    HttpPostedFile hpFile = context.Request.Files[i];
                    if (!string.IsNullOrEmpty(hpFile.FileName))
                    {
                        TT_FilesInsuran file = AddFileOne(out jmsg, hpFile, Types, lenth, SourceTable, ToId, ShowName);
                        if (file != null)
                        {
                            FileIdSet += file.FileId + ",";
                            res       += 1;
                            listFile.Add(file);
                        }
                    }
                }
            }
            #endregion
            if (!string.IsNullOrEmpty(FileIdSet))
            {
                FileIdSet = FileIdSet.Substring(0, FileIdSet.Length - 1);
            }
            if (res > 0)
            {
                jmsg.Code = res;
                jmsg.Data = JsonHelper.ToJson(listFile, true);
                jmsg.Msg  = "成功:" + context.Request.Files.Count + " 个文件,成功:" + res + "个";
            }

            return(jmsg);
        }