Example #1
0
        public ActionResult Edit_DB_File()
        {
            this.Response.ContentType = "text/plain";

            NModel.DB_File model = new NModel.DB_File();
            BLL.DB_File    dal   = new BLL.DB_File();

            String JsonStr = "";

            bool isGet = Tool.NStr.PostForSetVal <NModel.DB_File>(ref model, ref JsonStr, "");

            // 下面代码编写
            if (isGet && !string.IsNullOrEmpty(model.File_Name) &&
                !string.IsNullOrEmpty(model.File_URL) &&

                (model.File_Cty_ID > 0)

                )
            {
                //取默认值

                model.File_EditTime = DateTime.Parse(DateTime.Now.ToString("s"));

                bool isEdit = dal.Edit(model) > 0 ? true : false;

                string msg = dal.ErrorMsg;
                if (!string.IsNullOrEmpty(msg))
                {
                    msg = "原因:" + msg;
                }

                if (isEdit)
                {
                    this.Response.Write(Tool.NMsg.SetMsg("修改成功", "1"));
                    this.Response.End();
                }
                else
                {
                    this.Response.Write(Tool.NMsg.SetMsg("修改失败" + msg, "0"));
                    this.Response.End();
                }
            }
            else
            {
                this.Response.Write(Tool.NMsg.SetMsg("提交失败", "0"));
                this.Response.End();
            }
            dal.Close();

            return(View());
        }
Example #2
0
        public ActionResult Del_DB_File()
        {
            this.Response.ContentType = "text/plain";

            string delList = this.Request.Form["delList[]"];

            if (!string.IsNullOrEmpty(delList))
            {
                string[] arrStr = delList.Split(',');

                int[] delIntArr = Tool.NTool.ArrayToAll <int, string>(arrStr);

                if (Tool.NTool.IsArrNULL <int>(delIntArr))
                {
                    int[]       delOkImage = new int[delIntArr.Length];
                    string[]    delImage = new string[delIntArr.Length];
                    BLL.DB_File dal = new BLL.DB_File();
                    int         lt = 0, dt = 0;
                    foreach (int it in delIntArr)
                    {
                        NModel.DB_File cdi = dal.GetModel((long?)it);
                        if (cdi != null && !string.IsNullOrEmpty(cdi.File_URL))
                        {
                            delImage[lt] = UploadFileController.DictFilePath + cdi.File_URL;
                            bool isdelOk = Tool.NImage.DelImage(delImage[lt]);

                            if (isdelOk)
                            {
                                delOkImage[dt] = it; dt++;
                            }
                            lt++;
                        }
                    }

                    long long_Result = dal.DelList(delIntArr);

                    if (long_Result > 0)
                    {
                        this.Response.Write(Tool.NMsg.SetMsg(string.Format("删除成功!总共删除{0}条", long_Result), "1"));
                        this.Response.End();
                    }
                    else
                    {
                        this.Response.Write(Tool.NMsg.SetMsg("删除失败!", "0"));
                        this.Response.End();
                    }

                    dal.Close();
                }
                else
                {
                    this.Response.Write(Tool.NMsg.SetMsg("提交失败!", "0"));
                    this.Response.End();
                }
            }
            else
            {
                this.Response.Write(Tool.NMsg.SetMsg("提交失败!", "0"));
                this.Response.End();
            }

            return(View());
        }
Example #3
0
        public ActionResult UploadFile()
        {
            Response.Clear();
            System.Drawing.Image    thumbnail_image = null;
            System.Drawing.Image    original_image  = null;
            System.Drawing.Bitmap   final_image     = null;
            System.Drawing.Graphics graphic         = null;
            MemoryStream            ms = null;

            try
            {
                string dffpath = this.Server.MapPath(UFPath);
                bool   Has     = System.IO.Directory.Exists(dffpath);
                if (!Has)
                {
                    System.IO.Directory.CreateDirectory(dffpath);
                }

                // Get the data
                HttpPostedFileBase jpeg_image_upload = Request.Files["image"];
                if (jpeg_image_upload == null)
                {
                    jpeg_image_upload = Request.Files["file"];
                }

                string type = this.Request.QueryString["type"];

                string cid   = this.Request.QueryString["cid"];
                int    count = Request.Files.Count;

                // Retrieve the uploaded image

                string thumbnail_id = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                string file_id      = DateTime.Now.ToString("yyyyMMdd");

                string AllFilePath = dffpath;

                string allPath   = this.Server.MapPath(DictFilePath);
                string ALLDFPath = this.Server.MapPath(DFPath);

                long _cid = 0;
                long.TryParse(cid, out _cid);
                string size = "0x0";
                int    x = 0, y = 0;

                //jpeg_image_upload.FileName

                string extName = System.IO.Path.GetExtension(jpeg_image_upload.FileName);

                switch (extName.ToLower())
                {
                case ".jpg":
                case ".png":
                case ".jpeg":
                case ".gif":
                case ".pdf":
                case ".txt":
                case ".zip":
                case ".rar":
                case ".doc":

                    break;

                default:
                    return(View());
                }

                string mine = type;
                switch (mine)
                {
                case "img":
                {
                    BLL.DB_Img_Category    dal   = new BLL.DB_Img_Category();
                    NModel.DB_Img_Category c_dic = new NModel.DB_Img_Category();

                    if (_cid > 0)
                    {
                        c_dic = dal.GetModel(_cid);
                        if (c_dic != null && !string.IsNullOrEmpty(c_dic.Img_category_Folder))
                        {
                            file_id = c_dic.Img_category_Folder;
                        }

                        if (c_dic != null && !string.IsNullOrEmpty(c_dic.Img_category_Size))
                        {
                            size = c_dic.Img_category_Size;
                        }
                    }

                    // original_image = System.Drawing.Image.FromStream(jpeg_image_upload.InputStream);
                    //system.Drawing.Image.FromFile(ph)
                    string[] sz = size.Split(';');
                    string[] fr = file_id.Split(';');

                    if (fr != null && fr.Length <= 10 && sz != null && sz.Length <= 10)
                    {
                        for (int i = 0; i < fr.Length; i++)
                        {
                            bool _Has = System.IO.Directory.Exists(ALLDFPath + "/" + fr[i]);
                            if (!_Has)
                            {
                                System.IO.Directory.CreateDirectory(ALLDFPath + "/" + fr[i]);
                            }

                            string[] xy = sz[i].Split('x');

                            int.TryParse(xy[0], out x);
                            int.TryParse(xy[1], out y);
                            string lastName = System.IO.Path.GetExtension(jpeg_image_upload.FileName);

                            string savepath = "/" + fr[i] + "/" + thumbnail_id + "" + lastName;
                            ;

                            string ap = ALLDFPath + savepath;
                            original_image = System.Drawing.Image.FromStream(jpeg_image_upload.InputStream);

                            if (x == 0 && y == 0)
                            {
                                jpeg_image_upload.SaveAs(ap);
                            }
                            else
                            {
                                Tool.NImage.MakeThumbnail(original_image, ap, x, y, "Cut");
                            }

                            BLL.DB_Image    dal_di = new BLL.DB_Image();
                            NModel.DB_Image c_di   = new NModel.DB_Image();

                            c_di.Image_AddTime     = DateTime.Parse(DateTime.Now.ToString("s"));
                            c_di.Image_EditTime    = DateTime.Parse(DateTime.Now.ToString("s"));
                            c_di.Image_Category_ID = _cid;
                            c_di.Image_SortNo      = 1;
                            c_di.Image_Status      = 1;
                            c_di.Image_Size        = sz[i];
                            c_di.Image_Operate     = 1;
                            c_di.Image_Url         = savepath;
                            c_di.Image_Name        = System.IO.Path.GetFileNameWithoutExtension(jpeg_image_upload.FileName);
                            bool isadd = dal_di.Add(c_di) > 0 ? true : false;

                            if (isadd)
                            {
                                Response.Write(Tool.NMsg.SetMsg("" + savepath + "", "1"));
                                Response.End();
                            }
                            else
                            {
                                Response.Write(Tool.NMsg.SetMsg("上传失败", "0"));
                                Response.End();
                            }
                            dal.Close();
                            dal_di.Close();
                        }
                    }
                }
                break;

                default:
                {
                    BLL.DB_File          dal_di = new BLL.DB_File();
                    NModel.DB_File       c_di   = new NModel.DB_File();
                    BLL.DB_File_Category dal    = new BLL.DB_File_Category();

                    if (_cid > 0)
                    {
                        NModel.DB_File_Category _c_di = dal.GetModel(_cid);
                        if (_c_di != null && !string.IsNullOrEmpty(c_di.File_Category_Folder))
                        {
                            file_id = _c_di.File_Category_Folder;
                        }

                        //if (c_dic != null && !string.IsNullOrEmpty(c_dic.File_Category_Size))
                        //{
                        //    size = c_dic.File_Category_Size;

                        //}
                    }

                    //string[] sz = size.Split(';');
                    string[] fr = file_id.Split(';');
                    if (fr != null && fr.Length <= 10)
                    {
                        for (int i = 0; i < fr.Length; i++)
                        {
                            bool _Has = System.IO.Directory.Exists(allPath + "/" + fr[i]);
                            if (!_Has)
                            {
                                System.IO.Directory.CreateDirectory(allPath + "/" + fr[i]);
                            }

                            string lastName = System.IO.Path.GetExtension(jpeg_image_upload.FileName);

                            string savepath = "/" + fr[i] + "/" + thumbnail_id + "" + lastName;
                            ;

                            string ap = allPath + savepath;

                            /// 保存文件
                            jpeg_image_upload.SaveAs(ap);

                            c_di.File_AddTime  = DateTime.Parse(DateTime.Now.ToString("s"));
                            c_di.File_EditTime = DateTime.Parse(DateTime.Now.ToString("s"));
                            c_di.File_Cty_ID   = _cid;
                            c_di.File_SortNo   = 1;
                            c_di.File_Status   = 1;
                            c_di.File_Size     = jpeg_image_upload.ContentLength + "";
                            c_di.File_Operate  = 1;
                            c_di.File_URL      = savepath;
                            c_di.File_Name     = System.IO.Path.GetFileNameWithoutExtension(jpeg_image_upload.FileName);

                            bool isadd = dal_di.Add(c_di) > 0 ? true : false;

                            if (isadd)
                            {                                              //  var img= info["response"];
                                Response.Write(Tool.NMsg.SetMsg("" + savepath + "", "1"));
                                Response.End();
                            }
                            else
                            {
                                Response.Write(Tool.NMsg.SetMsg("上传失败", "0"));
                                Response.End();
                            }
                        }
                    }
                    dal_di.Close();
                    dal.Close();
                }
                break;
                }

                Response.StatusCode = 200;
            }
            catch
            {
                // If any kind of error occurs return a 500 Internal Server error
                Response.StatusCode = 500;
                Response.Write("{\"jsonrpc\" : \"2.0\", \"error\" : {\"code\": 101, \"message\": \"Failed to open input stream.\"}, \"id\" : \"id\"}");
                // Response.End();
            }
            finally
            {
                // Clean up
                if (final_image != null)
                {
                    final_image.Dispose();
                }
                if (graphic != null)
                {
                    graphic.Dispose();
                }
                if (original_image != null)
                {
                    original_image.Dispose();
                }
                if (thumbnail_image != null)
                {
                    thumbnail_image.Dispose();
                }
                if (ms != null)
                {
                    ms.Close();
                }
                // Response.End();
            }

            return(View());
        }