示例#1
0
        /// <summary>
        /// 将上传文件加到某个批次
        /// </summary>
        /// <param name="curr_user"></param>
        /// <param name="postedFile"></param>
        /// <param name="batch_id"></param>
        /// <returns></returns>
        public static SysAttachment InsertAttachment(SysAttachment item, SysBatchUpload batch_entity)
        {
            SqlConnection conn = new SqlConnection(Config.ConnectionString);

            conn.Open();
            try
            {
                SqlTransaction trans = conn.BeginTransaction();
                try
                {
                    SqlHelper.Insert(trans, item);
                    SqlHelper.Insert(trans, batch_entity);

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw ex;
                }
            }
            finally
            {
                conn.Close();
            }

            return(item);
        }
示例#2
0
        /// <summary>
        /// 将上传文件加到某个批次
        /// </summary>
        /// <param name="curr_user"></param>
        /// <param name="postedFile"></param>
        /// <param name="batch_id"></param>
        /// <returns></returns>
        public static SysAttachment InsertAttachment(SysUserInfo curr_user, System.Web.HttpPostedFile postedFile, string batch_id)
        {
            string originalFilePath = postedFile.FileName;
            // save file
            // get user's site
            SysSiteList site_entity = AttachmentDataAccess.GetSysSiteList(curr_user.SiteSerial);

            if (site_entity == null)
            {
                throw new ApplicationException(string.Format("site [{0}] does not exists.", curr_user.SiteSerial));
            }

            // get site's upload path
            SysDocPath doc_path_entity = AttachmentDataAccess.GetSysDocPath(site_entity.CurrentUploadPathId);

            if (doc_path_entity == null)
            {
                throw new ApplicationException(string.Format("path_id [{0}]does not configed in db.", site_entity.CurrentUploadPathId));
            }
            string baseDir = doc_path_entity.DocPath;

            // get child dir
            DateTime dt_now  = DateTime.Now;
            string   subDir  = dt_now.ToString("yyyyMM");
            string   fileDir = Path.Combine(baseDir, subDir);

            if (!System.IO.Directory.Exists(fileDir))
            {
                System.IO.Directory.CreateDirectory(fileDir);
            }

            string attachmentId    = System.Guid.NewGuid().ToString("D");
            string currentFileName = attachmentId + Path.GetExtension(originalFilePath);
            string currentFilePath = Path.Combine(fileDir, currentFileName);

            postedFile.SaveAs(currentFilePath);

            SysAttachment item = new SysAttachment();

            item.AttachmentId    = attachmentId;
            item.CurrentFileName = currentFileName;
            item.CurrentFileDir  = subDir;
            item.FileSize        = postedFile.ContentLength;
            // postedFile.
            item.OriginalFileName = Path.GetFileName(originalFilePath);
            item.UploadTime       = dt_now;
            item.UploadUser       = curr_user.UserId;
            item.ContentType      = postedFile.ContentType;
            item.PathId           = site_entity.CurrentUploadPathId;
            item.FileExtension    = Path.GetExtension(originalFilePath);

            SysBatchUpload batch_entity = new SysBatchUpload(batch_id, attachmentId);

            AttachmentDataAccess.InsertAttachment(item, batch_entity);

            return(item);
        }
示例#3
0
        public static bool batch_attach_exists(SqlTransaction trans, SysBatchUpload entity)
        {
            string           sql = " select count(*) from sys_batch_upload where batch_id = @batch_id and attachment_id = @attachment_id ";
            ParameterBuilder pb  = new ParameterBuilder();

            pb.Add("@batch_id", entity.BatchId);
            pb.Add("@attachment_id", entity.AttachmentId);

            return((int)SqlHelper.ExecuteScalar(trans, CommandType.Text, sql, pb.ToArray()) > 0);
        }