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));
        }
Ejemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            string action = context.Request["action"];


            HttpReSultMode jmsg = new HttpReSultMode();

            switch (action)
            {
            case "addImg":    //上传单图片 返回文件信息json

                jmsg = addImg(context);
                context.Response.Write(JsonHelper.ToJson(jmsg));
                context.Response.End();
                break;

            case "addFile":    //上传文件 返回文件信息json

                jmsg = addFile(context);
                context.Response.Write(JsonHelper.ToJson(jmsg));
                context.Response.End();
                break;

            case "GetFileList":    //根据id集获取文件列表

                #region
                string id          = context.Request["ToId"];
                string SourceTable = context.Request["SourceTable"];
                if (!string.IsNullOrEmpty(id))
                {
                    var mql = TT_FilesInsuranSet.SelectAll().Where(TT_FilesInsuranSet.ToId.Equal(id).And(TT_FilesInsuranSet.SourceTable.Equal(SourceTable)));
                    List <TT_FilesInsuran> list = OPBiz.GetOwnList(mql);
                    context.Response.Write(JsonHelper.ToJson(list, true));
                }
                else
                {
                    context.Response.Write("[]");
                }
                context.Response.End();
                #endregion
                break;

            case "SaveToid":    //保存更改ToID

                #region

                string Tid   = FilterTools.FilterSpecial(context.Request["ToId"]);
                string IdSet = FilterTools.FilterSpecial(context.Request["IdSet"]);
                if (!string.IsNullOrEmpty(context.Request["ToId"]) && !string.IsNullOrEmpty(context.Request["IdSet"]))
                {
                    string sql = " update TT_FilesInsuran set ToId='" + Tid + "'  where FileId in (" + IdSet + ")";
                    int    i   = OPBiz.ExecuteSqlWithNonQuery(sql);
                    if (i > 0)
                    {
                        jmsg.Code = 11;
                        jmsg.Data = i.ToString();
                        jmsg.Msg  = "上传成功";
                    }
                    else
                    {
                        jmsg.Code = -11;
                        jmsg.Data = "0";
                        jmsg.Msg  = "上传失败";
                    }
                }
                else
                {
                    jmsg.Code = -11;
                    jmsg.Data = "0";
                    jmsg.Msg  = "数据为空";
                }
                context.Response.Write(JsonHelper.ToJson(jmsg, true));
                context.Response.End();

                #endregion
                break;

            case "Delfile":    //删除文件

                #region


                if (!string.IsNullOrEmpty(context.Request["IdSet"]))
                {
                    string[] IDSet = context.Request["IdSet"].ToString().Split(',');
                    var      mql2  = TT_FilesInsuranSet.FileId.In(IDSet);

                    var selectm = TT_FilesInsuranSet.SelectAll().Where(mql2);
                    List <TT_FilesInsuran> listDel = OPBiz.GetEntities(selectm);

                    //数据库删除
                    int f = OPBiz.Remove <TT_FilesInsuranSet>(mql2);


                    if (f > 0)
                    {
                        jmsg.Code = 11;
                        jmsg.Data = f.ToString();
                        jmsg.Msg  = "删除成功";

                        #region 文件删除
                        try
                        {
                            string HttpFileRoute = ConfigurationManager.AppSettings["HttpFileRoute"].ToString();    //文件保存本地路径根目录
                            for (int i = 0; i < listDel.Count; i++)
                            {
                                string path = HttpFileRoute + listDel[i].RelativePath;
                                ZFiles.FilePicDelete(path);
                            }
                        }
                        catch (Exception ex)
                        {
                            //jmsg.Code = -13;
                            //jmsg.Data = ex.Message;
                            //jmsg.Msg = "删除失败";
                        }
                        #endregion
                    }
                    else
                    {
                        jmsg.Code = -11;
                        jmsg.Data = "0";
                        jmsg.Msg  = "删除失败";
                    }
                }
                else
                {
                    jmsg.Code = -11;
                    jmsg.Data = "0";
                    jmsg.Msg  = "数据为空";
                }
                context.Response.Write(JsonHelper.ToJson(jmsg, true));
                context.Response.End();

                #endregion
                break;

            case "Download":
                #region
                if (!string.IsNullOrEmpty(context.Request["Url"]))
                {
                    // 检查请求下载文件的有效性
                    string filePath = System.Web.HttpContext.Current.Server.MapPath(context.Request["Url"]);
                    if (!System.IO.File.Exists(filePath))
                    {
                        throw new ArgumentException("无效文件,文件不存在!");
                    }

                    //WriteFile实现下载
                    string   fileName = context.Request["fileName"];  //客户端保存的文件名
                    FileInfo fileInfo = new FileInfo(filePath);
                    context.Response.Clear();
                    context.Response.ClearContent();
                    context.Response.ClearHeaders();
                    context.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
                    context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                    context.Response.AddHeader("Content-Transfer-Encoding", "binary");
                    context.Response.ContentType     = "application/octet-stream";
                    context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                    context.Response.WriteFile(fileInfo.FullName);
                    context.Response.Flush();
                    context.Response.End();
                }
                #endregion

                break;
            }
        }