コード例 #1
0
        protected void btnSaveFiles_Click(object sender, EventArgs e)
        {
            int id        = QS("id", 0);
            int companyid = QS("companyid", 0);

            if (fileProject.HasFile)
            {
                FilesEntity model = FileFactory.CreateFileEntity(UserInfo.ID, ObjectFactory.GetInstance <ISystemDateTime>());
                model.FilePath = UtilFactory.Helpers.FileHelper.SaveUploadFiles("Project", id, fileProject.PostedFile);;

                model.CompanyID   = companyid;
                model.ContentType = fileProject.PostedFile.ContentType;
                model.FileID      = 0;
                model.FileSize    = fileProject.PostedFile.ContentLength;
                if (string.IsNullOrEmpty(txtFileTitle.Text))
                {
                    model.FileTitle = Path.GetFileName(fileProject.FileName);
                    model.FileTitle = model.FileTitle.Substring(0, model.FileTitle.LastIndexOf("."));
                }
                else
                {
                    model.FileTitle = txtFileTitle.Text;
                }
                model.IsDelete   = false;
                model.IsPublic   = UserInfo.Role == RolesEnum.CLIENT;
                model.SourceType = (int)FileSourceType.Project;
                model.ProjectId  = id;
                model.ThumbPath  = Path.GetFileName(fileProject.PostedFile.FileName);
                model.IsDelete   = false;

                FileApplication fileApp = new FileApplication();
                int             result  = fileApp.AddFile(model);

                OperateDocManagements.OperateDocManagementSoapClient client = new OperateDocManagements.OperateDocManagementSoapClient();
                List <FilesEntity> clientFiles = new List <FilesEntity>();
                clientFiles.Add(model);
                client.AddDocManagement(Newtonsoft.Json.JsonConvert.SerializeObject(clientFiles));

                if (result <= 0)
                {
                    this.ShowFailMessageToClient(fileApp.BrokenRuleMessages, false);
                }
                else
                {
                    InitFiles();
                    this.ShowSuccessMessageToClient(false, false);
                    txtFileTitle.Text = "";
                }
            }
        }
コード例 #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int id = QS("id", 0);

            if (id == 0)
            {
                ShowFailMessageToClient("unauthorized access.");
                return;
            }
            else
            {
                ProjectsEntity projectEntity = new ProjectApplication().Get(id);
                if (projectEntity == null)
                {
                    ShowFailMessageToClient("unauthorized access.");
                    return;
                }

                if (fileUpload.PostedFile.ContentLength == 0)
                {
                    ShowFailMessageToClient("Please specify a file to upload.");
                    return;
                }

                FilesEntity model = FileFactory.CreateFileEntity(UserInfo.ID, ObjectFactory.GetInstance <ISystemDateTime>());
                model.FilePath = UtilFactory.Helpers.FileHelper.SaveUploadFiles("Project", id, fileUpload.PostedFile);;

                model.CompanyID   = projectEntity.CompanyID;
                model.ContentType = fileUpload.PostedFile.ContentType;
                model.FileID      = 0;
                model.FileSize    = fileUpload.PostedFile.ContentLength;
                if (string.IsNullOrEmpty(txtFileTitle.Text))
                {
                    model.FileTitle = Path.GetFileName(fileUpload.FileName);
                    model.FileTitle = model.FileTitle.Substring(0, model.FileTitle.LastIndexOf("."));
                }
                else
                {
                    model.FileTitle = txtFileTitle.Text;
                }
                model.IsDelete   = false;
                model.IsPublic   = UserInfo.Role == RolesEnum.CLIENT;
                model.SourceType = (int)FileSourceType.Project;
                model.ProjectId  = id;
                model.ThumbPath  = Path.GetFileName(fileUpload.PostedFile.FileName);
                model.IsDelete   = false;

                FileApplication fileApp = new FileApplication();
                int             result  = fileApp.AddFile(model);

                OperateDocManagements.OperateDocManagementSoapClient client = new OperateDocManagements.OperateDocManagementSoapClient();
                List <FilesEntity> clientFiles = new List <FilesEntity>();
                clientFiles.Add(model);
                client.AddDocManagement(Newtonsoft.Json.JsonConvert.SerializeObject(clientFiles));

                if (result <= 0)
                {
                    Redirect("File upload error.", "AddProjectFile.aspx?ID" + QS("ID"));
                }
                else
                {
                    Redirect(EmptyPopPageUrl, false, true);
                }
            }
        }