Exemplo n.º 1
0
        /// <summary>
        /// 附件上传
        /// </summary>
        /// <param name="fileUpload">上传控件</param>
        /// <param name="fileUrl">上传路径</param>
        /// <param name="constUrl">定义路径</param>
        /// <returns></returns>
        public static string UploadAttachment(string rootPath, FineUIPro.FileUpload fileUpload, string fileUrl, string constUrl)
        {
            if (!string.IsNullOrEmpty(fileUrl))  ////是否存在附件 存在则删除
            {
                string urlFullPath = rootPath + fileUrl;
                if (File.Exists(urlFullPath))
                {
                    File.Delete(urlFullPath);
                }
            }

            string initFullPath = rootPath + constUrl;

            if (!Directory.Exists(initFullPath))
            {
                Directory.CreateDirectory(initFullPath);
            }

            string filePath = fileUpload.PostedFile.FileName;
            string fileName = Funs.GetNewFileName() + "~" + Path.GetFileName(filePath);
            int    count    = fileUpload.PostedFile.ContentLength;
            string savePath = constUrl + fileName;
            string fullPath = initFullPath + fileName;

            if (!File.Exists(fullPath))
            {
                byte[] buffer = new byte[count];
                Stream stream = fileUpload.PostedFile.InputStream;

                stream.Read(buffer, 0, count);
                MemoryStream memoryStream = new MemoryStream(buffer);
                FileStream   fs           = new FileStream(fullPath, FileMode.Create, FileAccess.Write);
                memoryStream.WriteTo(fs);
                memoryStream.Flush();
                memoryStream.Close();
                fs.Flush();
                fs.Close();
                memoryStream = null;
                fs           = null;
                //if (!string.IsNullOrEmpty(fileUrl))
                //{
                //    fileUrl += "," + savePath;
                //}
                //else
                //{
                //    fileUrl += savePath;
                //}
                fileUrl = savePath;
            }
            else
            {
                fileUrl = string.Empty;
            }

            return(fileUrl);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 插入培训记录 2
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="arr"></param>
        public static bool AddTrainRecord(string projectId, JArray arr, Model.Sys_User user)
        {
            Model.SUBHSSEDB db   = Funs.DB;
            bool            isOk = true;

            try
            {
                foreach (var item in arr)
                {
                    string fromRecordId = item["ID"].ToString();
                    string trainTypeId  = null; ////培训类型
                    var    getTrainType = db.Base_TrainType.FirstOrDefault(x => x.TrainTypeName == item["TrainType"].ToString());
                    if (getTrainType != null)
                    {
                        trainTypeId = getTrainType.TrainTypeId;
                    }
                    string unitId = null;
                    if (!string.IsNullOrEmpty(item["TrainDepart"].ToString()))
                    {
                        var lists = Funs.GetStrListByStr(item["TrainDepart"].ToString(), ',');
                        if (lists.Count() > 0)
                        {
                            foreach (var itemList in lists)
                            {
                                var getUnit = db.Base_Unit.FirstOrDefault(x => x.UnitName == itemList);
                                if (getUnit != null)
                                {
                                    if (string.IsNullOrEmpty(unitId))
                                    {
                                        unitId = getUnit.UnitId;
                                    }
                                    else
                                    {
                                        unitId += ("," + getUnit.UnitId);
                                    }
                                }
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(unitId) && !string.IsNullOrEmpty(fromRecordId))
                    {
                        Model.EduTrain_TrainRecord newTrainRecord = new Model.EduTrain_TrainRecord
                        {
                            FromRecordId = fromRecordId,

                            ProjectId      = projectId,
                            TrainTitle     = item["RecordName"].ToString(),
                            TrainContent   = item["TrainContent"].ToString(),
                            TrainStartDate = Funs.GetNewDateTime(item["TrainStartDate"].ToString()),
                            TrainEndDate   = Funs.GetNewDateTime(item["TrainEndDate"].ToString()),
                            TeachHour      = Funs.GetNewDecimalOrZero(item["TrainPeriod"].ToString()),
                            TeachMan       = item["TrainPrincipal"].ToString(),
                            Remark         = item["TrainDescript"].ToString(),
                            TrainTypeId    = trainTypeId,
                            UnitIds        = unitId,
                            States         = Const.State_0,
                            CompileMan     = item["CreateUser"].ToString(),
                            TrainPersonNum = Funs.GetNewInt(item["PersonCount"].ToString()),
                        };

                        newTrainRecord.TrainingCode = Funs.GetNewFileName(newTrainRecord.TrainStartDate);
                        var getTrainRecord = Funs.DB.EduTrain_TrainRecord.FirstOrDefault(x => x.FromRecordId == fromRecordId);
                        if (getTrainRecord == null)
                        {
                            newTrainRecord.TrainingId = SQLHelper.GetNewID(typeof(Model.EduTrain_TrainRecord));
                            EduTrain_TrainRecordService.AddTraining(newTrainRecord);
                            BLL.LogService.AddSys_Log(user, newTrainRecord.TrainingCode, newTrainRecord.TrainingId, BLL.Const.ProjectTrainRecordMenuId, BLL.Const.BtnAdd);
                        }
                        else
                        {
                            getTrainRecord.TrainingCode   = newTrainRecord.TrainingCode;
                            getTrainRecord.TrainTitle     = newTrainRecord.TrainTitle;
                            getTrainRecord.TrainContent   = newTrainRecord.TrainContent;
                            getTrainRecord.UnitIds        = newTrainRecord.UnitIds;
                            getTrainRecord.TrainStartDate = newTrainRecord.TrainStartDate;
                            if (newTrainRecord.TrainEndDate.HasValue)
                            {
                                getTrainRecord.TrainEndDate = newTrainRecord.TrainEndDate;
                            }
                            else
                            {
                                getTrainRecord.TrainEndDate = newTrainRecord.TrainStartDate;
                            }
                            getTrainRecord.TeachHour    = newTrainRecord.TeachHour;
                            getTrainRecord.TeachMan     = newTrainRecord.TeachMan;
                            getTrainRecord.TeachAddress = newTrainRecord.TeachAddress;

                            getTrainRecord.Remark = newTrainRecord.Remark;
                            EduTrain_TrainRecordService.UpdateTraining(getTrainRecord);
                            BLL.LogService.AddSys_Log(user, getTrainRecord.TrainingCode, getTrainRecord.TrainingId, BLL.Const.ProjectTrainRecordMenuId, BLL.Const.BtnModify);
                        }
                    }
                    else
                    {
                        isOk = false;
                    }
                }
            }
            catch (Exception ex)
            {
                isOk = false;
                ErrLogInfo.WriteLog(string.Empty, ex);
            }
            return(isOk);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 附件上传 同时上传到服务器端
        /// </summary>
        /// <param name="fileUpload">上传控件</param>
        /// <param name="fileUrl">上传路径</param>
        /// <param name="constUrl">定义路径</param>
        /// <param name="serverUrl">服务端地址</param>
        /// <returns></returns>
        public static string UploadAttachmentAndServer(string rootPath, FileUpload fileUpload, string fileUrl, string constUrl, string serverUrl)
        {
            string initFullPath = rootPath + constUrl;

            if (!Directory.Exists(initFullPath))
            {
                Directory.CreateDirectory(initFullPath);
            }

            string initFullPathServer = serverUrl + constUrl;

            if (!Directory.Exists(initFullPathServer))
            {
                Directory.CreateDirectory(initFullPathServer);
            }

            string filePath       = fileUpload.PostedFile.FileName;
            string fileName       = Funs.GetNewFileName() + "~" + Path.GetFileName(filePath);
            int    count          = fileUpload.PostedFile.ContentLength;
            string savePath       = constUrl + fileName;
            string fullPath       = initFullPath + fileName;
            string fullPathServer = initFullPathServer + fileName;

            if (!File.Exists(fullPath))
            {
                byte[] buffer = new byte[count];
                Stream stream = fileUpload.PostedFile.InputStream;

                stream.Read(buffer, 0, count);
                MemoryStream memoryStream = new MemoryStream(buffer);
                FileStream   fs           = new FileStream(fullPath, FileMode.Create, FileAccess.Write);
                memoryStream.WriteTo(fs);
                memoryStream.Flush();
                memoryStream.Close();
                fs.Flush();
                fs.Close();
                memoryStream = null;
                fs           = null;
                if (!string.IsNullOrEmpty(fileUrl))
                {
                    fileUrl += "," + savePath;
                }
                else
                {
                    fileUrl += savePath;
                }

                MemoryStream memoryStreamEng = new MemoryStream(buffer);
                FileStream   fsServer        = new FileStream(fullPathServer, FileMode.Create, FileAccess.Write);
                memoryStreamEng.WriteTo(fsServer);
                memoryStreamEng.Flush();
                memoryStreamEng.Close();
                fsServer.Flush();
                fsServer.Close();
                memoryStreamEng = null;
                fsServer        = null;
            }
            else
            {
                fileUrl = string.Empty;
            }

            return(fileUrl);
        }