Ejemplo n.º 1
0
        public JsonResult UploadFile()
        {
            // 获取从MIME中读取出来的文件
            var    listFile      = Request.Files;
            Guid   fid           = Guid.Empty;
            string fileId2Return = "";
            string message       = "";

            if (!string.IsNullOrEmpty(Request.QueryString["fileId"]))
            {
                fid = new Guid(Request.QueryString["fileId"]);
            }
            var islocal = Request.QueryString["islocal"];

            if (islocal == "1")
            {
                string filePath = Server.MapPath("~/Content/images/header/");
                for (int n = 0; n < listFile.Count; n++)
                {
                    var fileId = Guid.NewGuid().ToString().ToUpper() + Path.GetExtension(listFile[n].FileName);
                    listFile[n].SaveAs(filePath + fileId);
                    fileId2Return += fileId.ToString() + ";";
                }
            }
            else
            {
                for (int n = 0; n < listFile.Count; n++)
                {
                    Guid fileId = fid;
                    if (fid == Guid.Empty)
                    {
                        fileId = Guid.NewGuid();
                    }
                    HttpPostedFileBase file = listFile[n];
                    if (!string.IsNullOrEmpty(file?.FileName))
                    {
                        fileId2Return += fileId.ToString() + ";";
                        string fileName = Path.GetFileName(file.FileName);
                        //string FileNameNotExtension = Path.GetFileNameWithoutExtension(file.FileName);
                        //string FileExtensionName = Path.GetExtension(file.FileName);

                        try
                        {
                            using (Stream inStream = StaticFunction.StreamToMemoryStream(file.InputStream))
                            {
                                using (Stream fmpStream = FileManager.CreateFile(fileId, fileName))
                                {
                                    StaticFunction.StreamSourceStreamToTargetStream(inStream, fmpStream);
                                }

                                //OpenFileItemData context = new OpenFileItemData();
                                //context.FileID = fileId;
                                //context.UpdateMode = UpdateMode.None;
                                //context.FileAccess = Topevery.FMP.ObjectModel.FileAccess.ReadWrite;
                                //context.FileMode = Topevery.FMP.ObjectModel.FileMode.Create;
                                //context.ClientFileName = fileName;
                            }
                        }
                        catch (Exception ex)
                        {
                            message = ex.ToString();
                            Logger.Error("FMP错误", ex);
                            throw ex;
                        }
                    }
                }
            }


            if (string.IsNullOrEmpty(message) && !string.IsNullOrEmpty(fileId2Return))
            {
                return(Json(new AjaxResponse <string> {
                    Success = true, Result = fileId2Return.Substring(0, fileId2Return.Length - 1)
                }));
            }
            return(Json(new AjaxResponse {
                Success = false, Error = new ErrorInfo(message)
            }));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 导入房屋平面图纸
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnImportHouseImage_OnClick(object sender, EventArgs e)
        {
            this.lblImportImage.Text = "";
            string importImagePath = txtImportImagePath.Text.Trim();

            if (importImagePath != "")
            {
                if (!Directory.Exists(importImagePath))
                {
                    this.lblImportImage.Text = "您输入的文件导入路径不存在!";
                    return;
                }
                int       rel      = 0;
                DataTable dtResult = new DataTable();
                dtResult.Columns.Add("Index", Type.GetType("System.String"));
                dtResult.Columns.Add("DataId", Type.GetType("System.String"));
                dtResult.Columns.Add("HouseNo", Type.GetType("System.String"));
                dtResult.Columns.Add("ImageName", Type.GetType("System.String"));

                foreach (string item in Directory.GetDirectories(importImagePath))
                {
                    DirectoryInfo     directoryinfo = new DirectoryInfo(item);
                    string            houseNo       = directoryinfo.Name;
                    DateTime          creationTime  = directoryinfo.CreationTime;
                    string            strSql        = "select * from HM_HouseBan where HouseNo =:HouseNo ";
                    OracleParameter[] parameters    =
                    {
                        new OracleParameter("HouseNo", OracleDbType.Varchar2, 50)
                    };
                    parameters[0].Value = houseNo;
                    //string strSql = "select * from HM_HouseBan where HouseNo ='"+ houseNo + "' ";

                    string connectionString = ConfigurationManager.ConnectionStrings["jmgf_new_oracle"].ConnectionString;

                    DataTable dt = OracleHelper.ExecuteDataTable(connectionString, CommandType.Text, strSql, parameters);

                    if (dt != null && dt.Rows.Count > 0)
                    {
                        try
                        {
                            Guid       fid     = Guid.Empty;
                            FileInfo[] arrFile = directoryinfo.GetFiles();

                            foreach (FileInfo fileInfo in arrFile)
                            {
                                string fileName          = Path.GetFileName(fileInfo.FullName);
                                string fileExtensionName = Path.GetExtension(fileInfo.FullName);
                                string fileid            = fileName.Replace(fileExtensionName, "");
                                Guid   fileId            = fid;
                                if (fid == Guid.Empty)
                                {
                                    fileId = Guid.NewGuid();
                                }
                                using (Stream inStream = StaticFunction.StreamToMemoryStream(fileInfo.OpenRead()))
                                {
                                    using (Stream fmpStream = FileManager.CreateFile(fileId, fileName))
                                    {
                                        StaticFunction.StreamSourceStreamToTargetStream(inStream, fmpStream);
                                        StringBuilder strSql0 = new StringBuilder();
                                        strSql0.Append(" insert into Sys_FileRelation(Id,ModuleId,KeyId,FileId,FileName,CreatorUserId,CreationTime,FileType) ");
                                        strSql0.Append(" values(SYS_FILERELATION_SEQ.Nextval,:ModuleId,:KeyId,:FileId,:FileName,:CreatorUserId,:CreationTime,:FileType)");
                                        OracleParameter[] parameters0 =
                                        {
                                            new OracleParameter("ModuleId",      OracleDbType.Int32,     10),
                                            new OracleParameter("KeyId",         OracleDbType.Int32,     10),
                                            new OracleParameter("FileId",        OracleDbType.Raw),
                                            new OracleParameter("FileName",      OracleDbType.Varchar2, 200),
                                            new OracleParameter("CreatorUserId", OracleDbType.Int32,     10),
                                            new OracleParameter("CreationTime",  OracleDbType.Date),
                                            new OracleParameter("FileType",      OracleDbType.Int32, 1)
                                        };
                                        parameters0[0].Value = Topevery.ModuleType.HouseBan;
                                        parameters0[1].Value = int.Parse(dt.Rows[0]["Id"].ToString());
                                        parameters0[2].Value = fileId.ToByteArray();
                                        parameters0[3].Value = fileName;
                                        parameters0[4].Value = 0;
                                        parameters0[5].Value = System.DateTime.Now;
                                        parameters0[6].Value = FileHelper.GetAttachType(fileExtensionName);
                                        rel += OracleHelper.ExecuteNonQuery(connectionString, CommandType.Text, strSql0.ToString(), parameters0);

                                        DataRow newRow = dtResult.NewRow();
                                        newRow["Index"]     = rel.ToString();
                                        newRow["DataId"]    = dt.Rows[0]["Id"].ToString();
                                        newRow["HouseNo"]   = houseNo;
                                        newRow["ImageName"] = fileName;
                                        dtResult.Rows.Add(newRow);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                        }
                    }
                }
                DataGridView1.DataSource = dtResult;
                DataGridView1.DataBind();
                this.lblImportImage.Text = "成功导入了" + rel + "张图片";
            }
            else
            {
                this.lblImportImage.Text = "请输入文件导入路径!";
            }
        }