コード例 #1
0
        private string SaveFile(string Folder, string tmbname, System.Web.HttpPostedFile hpf, Boolean isImageFile, Boolean isPdfFile, string comp_code)
        {
            string     retval    = "";
            string     FileName  = "";
            string     thumbNail = "";
            imageTools tools     = new imageTools();

            try
            {
                Lib.CreateFolder(Folder);

                FileName = Path.Combine(Folder, Path.GetFileName(hpf.FileName));
                hpf.SaveAs(FileName);

                if (isImageFile)
                {
                    thumbNail = Path.Combine(Folder, tmbname);
                    tools.Save(FileName, thumbNail);
                }
                if (isPdfFile)
                {
                    thumbNail = Path.Combine(Folder, tmbname);
                    SavePdf2Image(FileName, thumbNail, comp_code);
                }
            }
            catch (Exception Ex)
            {
                retval = Ex.Message.ToString();
            }

            return(retval);
        }
コード例 #2
0
        private static string SaveFile(string Folder, System.Web.HttpPostedFile hpf, string comp_code)
        {
            string     retval   = "";
            string     FileName = "";
            imageTools tools    = new imageTools();

            try
            {
                Lib.CreateFolder(Folder);
                FileName = Path.Combine(Folder, Path.GetFileName(hpf.FileName));
                hpf.SaveAs(FileName);
            }
            catch (Exception Ex)
            {
                retval = Ex.Message.ToString();
            }
            return(retval);
        }
コード例 #3
0
        public IHttpActionResult Save()
        {
            Dictionary <string, object> RetData = new Dictionary <string, object>();

            try
            {
                string     Folder = "";
                string     slno   = "";
                imageTools tools  = new imageTools();

                Boolean isImageFile = false;
                Boolean isPdfFile   = false;

                DataTable Dt_Record  = new DataTable();
                DataTable Dt_Records = new DataTable();

                string uploadError = "";

                Dictionary <string, object> SearchData = new Dictionary <string, object>();

                Dictionary <string, string> Files2Remove = new Dictionary <string, string>();

                var      model  = HttpContext.Current.Request.Form["record"];
                pim_docm record = JsonConvert.DeserializeObject <pim_docm>(model);

                var        columnList = HttpContext.Current.Request.Form["records"];
                tablesd [] records    = JsonConvert.DeserializeObject <tablesd[]>(columnList);


                string ServerImageURL   = Lib.GetSeverImageURL(record._globalvariables.comp_code);
                string ServerReportPath = Lib.GetReportPath(record._globalvariables.comp_code);
                string ServerImagePath  = Lib.GetImagePath(record._globalvariables.comp_code);

                using (DocService obj = new DocService())
                {
                    Dt_Record = obj.getDataTableRecord(record.doc_pkid);
                    RetData   = obj.Save(record, records, ServerImageURL);
                    slno      = RetData["slno"].ToString();
                }

                // first save to report/temp folder
                System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
                string REPID = System.Guid.NewGuid().ToString().ToUpper();
                ServerReportPath = Path.Combine(ServerReportPath, System.DateTime.Now.ToString("yyyy-MM-dd"), REPID);
                string smallname = "";
                for (int iCnt = 0; iCnt <= hfc.Count - 1; iCnt++)
                {
                    isImageFile = false;
                    isPdfFile   = false;
                    if (record.doc_file_name.ToUpper() == hfc[iCnt].FileName.ToUpper())
                    {
                        if (hfc[iCnt].ContentType.ToString().ToUpper().StartsWith("IMAGE"))
                        {
                            isImageFile = true;
                            smallname   = "ts.jpg";
                        }
                        if (Path.GetExtension(hfc[iCnt].FileName).ToUpper() == ".PDF")
                        {
                            isPdfFile = true;
                            smallname = "ts.jpg";
                        }
                    }
                    SaveFile(ServerReportPath, smallname, hfc[iCnt], isImageFile, isPdfFile, record._globalvariables.comp_code);
                }

                if (smallname != "")
                {
                    using (DocService obj = new DocService())
                    {
                        obj.UpdateDocFileName(record, "doc_thumbnail", smallname);
                        RetData["thumbnail"] = smallname;
                    }
                }

                //then copy to original folder
                string sError = "";
                if (record.doc_file_name.ToString().Trim().Length > 0)
                {
                    Folder = Lib.getPath(ServerImagePath, record._globalvariables.comp_code, record.doc_table_name, record.doc_slno.ToString(), true);
                    sError = Lib.CopyFile(Path.Combine(ServerReportPath, record.doc_file_name), Path.Combine(Folder, record.doc_file_name));
                    if (sError != "")
                    {
                        uploadError += "\n" + sError;
                        using (DocService obj = new DocService())
                        {
                            obj.UpdateDocFileName(record, "doc_file_name");
                            obj.UpdateDocFileName(record, "doc_thumbnail", "");
                        }
                    }
                    if (smallname != "")
                    {
                        sError = Lib.CopyFile(Path.Combine(ServerReportPath, smallname), Path.Combine(Folder, smallname));
                    }
                }

                foreach (tablesd mRow in records)
                {
                    if (mRow.tabd_col_type == "FILE")
                    {
                        Folder = Lib.getPath(ServerImagePath, record._globalvariables.comp_code, record.doc_table_name, record.doc_slno.ToString(), true);
                        sError = Lib.CopyFile(Path.Combine(ServerReportPath, mRow.tabd_col_value), Path.Combine(Folder, mRow.tabd_col_value));
                        if (sError != "")
                        {
                            uploadError += "\n" + sError;
                            using (DocService obj = new DocService())
                            {
                                obj.UpdateDocFileName(record, "COL_" + mRow.tabd_col_name);
                            }
                        }
                    }
                }

                RetData.Add("uploaderror", uploadError);

                return(Ok(RetData));
            }
            catch (Exception Ex)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, Ex.Message.ToString())));
            }
        }