protected void btnUpload_ServerClick(object sender, EventArgs e) { //是否有版权的资源 int hasCopyRight = 0; try { hasCopyRight = Convert.ToInt32(this.rblCopyright.SelectedValue); } catch (Exception ex) { } #region 验证日期部分 //if (this.shotDate1.Text.Trim() == string.Empty) //{ // this.ShowMessage(this, "请选择时间"); // return; //} //else //{ // if (Convert.ToDateTime(this.shotDate1.Text) > DateTime.Now) // { // this.ShowMessage(this, "拍摄时间应比现在早"); // return; // } //} //验证日期 DateTime sDate = new DateTime(); DateTime eDate = new DateTime(); if (this.startDate.Text != "") { //有效开始日期就不做验证了,只要结束日期比现在晚就可以了。 sDate = Convert.ToDateTime(this.startDate.Text); //if (sDate <= DateTime.Now) //{ // this.ShowMessage(this, "有效开始日期应比现在日期晚"); // return; //} } else { sDate = Convert.ToDateTime("1900-01-01"); } if (this.endDate.Text != "") { eDate = Convert.ToDateTime(this.endDate.Text); if (sDate == Convert.ToDateTime("1900-01-01") && eDate < DateTime.Now) { this.ShowMessage(this, "有效结束日期应至少比现在日期晚"); return; } else if (eDate < sDate) { this.ShowMessage(this, "有效结束日期应比有效开始日期晚"); return; } } else { eDate = Convert.ToDateTime("1900-01-01"); } #endregion #region 验证是否选择目录节点 ////根节点 //TreeNode parentNode = catalogTree.RootNode; ////获取checked的节点List //ArrayList nodeList = new ArrayList(); //this.catalogTree.ArrCheckbox(nodeList, parentNode); //ArrayList catalogIds = new ArrayList(nodeList.Count); //foreach (TreeNode node in nodeList) //{ // catalogIds.Add(new Guid(node.Value)); //} //if (catalogIds.Count == 0) //{ // this.ShowMessage(this, "没有选择分类,上传失败!"); // return; //} string catIds = this.hidCatIds.Value.Trim().Trim(new char[] { ',' }); string[] arrCatIds = catIds.Split(",".ToCharArray()); if (arrCatIds.Length == 0) { this.ShowMessage(this, "没有选择分类,上传失败!"); return; } ArrayList catalogIds = new ArrayList(arrCatIds.Length); foreach(string _s in arrCatIds) { catalogIds.Add(new Guid(_s)); } #endregion string fileName = ""; //原始文件名 if (!string.IsNullOrEmpty(Request["selectedFile"])) { fileName = Request["selectedFile"].ToString().ToLower(); } else { return; } string uploadFileName = ""; //上传以后重新分配的文件名 prefix+yymmdd+00001.extention if (!string.IsNullOrEmpty(Request["uploadFileName"])) { uploadFileName = Request["uploadFileName"].ToString(); } else { return; } string[] arrFiles = uploadFileName.Split(','); foreach (string singleFiles in arrFiles) { if (!singleFiles.Contains(":")) { continue; } string[] _arr = singleFiles.Split(':'); string strClientFileName = _arr[1]; string strServerFileName = _arr[0]; fileName = strClientFileName; uploadFileName = strServerFileName; /** start **/ Resource objResource = new Resource(); ResourceEntity model = new ResourceEntity(); //管理员上传直接审核通过 if (IsSuperAdmin) { model.Status = (int)ResourceEntity.ResourceStatus.IsPass; } else { model.Status = (int)ResourceEntity.ResourceStatus.NewUpload; } //改成所有人上传的都可以直接通过 , 到时直接注释下面一句话就可以 model.Status = (int)ResourceEntity.ResourceStatus.IsPass; model.Status = 0; if (this.txt_Caption.Value.Trim().Length > 0) { model.Caption = this.txt_Caption.Value; } else { model.Caption = Path.GetFileNameWithoutExtension(strClientFileName); } model.Description = this.description.Value; model.EndDate = eDate; model.FileName = fileName; model.FolderName = CurrentUser.UserLoginName; if (uploadFileName.ToLower().IndexOf(".cr2") != -1 || uploadFileName.ToLower().IndexOf(".nef") != -1 || uploadFileName.ToLower().IndexOf(".psd") != -1) { model.ServerFileName = uploadFileName.Replace("cr2", "jpg").Replace("nef", "jpg").Replace("psd", "jpg"); } else { model.ServerFileName = uploadFileName; } model.GroupId = CurrentUser.UserGroupId; model.ItemId = Guid.NewGuid(); model.ItemSerialNum = Path.GetFileNameWithoutExtension(uploadFileName); //model.Keyword = this.keyWord.Value; model.Keyword = this.txtKeyWords.Text.Trim().Trim(",".ToCharArray()); //model.shotDate = Convert.ToDateTime(this.shotDate1.Text); model.StartDate = sDate; model.uploadDate = DateTime.Now; model.userId = CurrentUser.UserId; model.updateDate = DateTime.Now; model.Author = this.txt_Author.Value.Trim(); //取得文件的扩展名,不包括.号 string fileExtName = string.Empty; fileExtName = Path.GetExtension(fileName); if (fileExtName.IndexOf(".") > -1) { fileExtName = fileExtName.Substring(1); } model.ResourceType = ResourceTypeFactory.getResourceType(fileExtName).ResourceType; model.FileSize = Resource.GetResourceFileSize(uploadFileName, model.FolderName, fileExtName, ""); model.HasCopyright = hasCopyRight; model.shotDate = DateTime.Now; DateTime shotDateTime = Resource.GetResourceShotDateTime(uploadFileName, model.FolderName, model.ResourceType, ""); if (shotDateTime != DateTime.MinValue) { model.shotDate = shotDateTime; } objResource.Add(model); objResource.CreateRelationshipResourceAndCatalog(model.ItemId, (Guid[])catalogIds.ToArray(typeof(Guid))); //同时更新索引 string[] SNs = new string[] { model.ItemSerialNum }; ResourceIndex.updateIndex(SNs); } /** end **/ #region 注释部分 //VideoStorageClass vsc = new VideoStorageClass(); //VideoStorage v = new VideoStorage(); //v.Caption = this.txt_Caption.Value; //v.Description = this.description.Value; //v.EndDate = eDate; //v.FileName = fileName; //v.FolderName = CurrentUser.UserLoginName; //v.ServerFileName = uploadFileName; //v.GroupId = CurrentUser.UserGroupId; //v.ItemId = Guid.NewGuid(); //v.ItemSerialNum = Path.GetFileNameWithoutExtension(uploadFileName); //v.Keyword = this.keyWord.Value; //v.shotDate = Convert.ToDateTime(this.shotDate.Value); //v.StartDate = sDate; //v.uploadDate = DateTime.Now; //v.userId = CurrentUser.UserId; //v.updateDate = DateTime.Now; ////存储数据库记录 //// img.ItemSerialNum = ImageStorageClass.AddImageStorage(img); //if (!vsc.Add(v)) //{ // this.ShowMessage(this, "上传失败"); // return; //} //vsc.CreateRelationshipVideoAndCatalog(v.ItemId, (Guid[])catalogIds.ToArray(typeof(Guid))); #endregion //this.shotDate1.Text = ""; this.keyWord.Value = ""; this.description.Value = ""; this.txt_Caption.Value = ""; this.startDate.Text = ""; this.endDate.Text = ""; initCalendar(); //this.ShowMessage(this, "上传成功"); //Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>myUploadSuccess2()</script>"); Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>myUploadSuccess2()</script>"); }
private string newUploadImage() { //HttpPostedFile objFile = Request.Files["Filedata"]; HttpPostedFile objFile = this.fuImage.PostedFile; if (objFile != null) { string filename = objFile.FileName; string fileType = Path.GetExtension(filename).ToLower(); if (fileType.IndexOf(".") == -1) { fileType = "." + fileType; } //string resourceType = new Resource().GetResourceTypeByFileExtention(fileType); string resourceType = ResourceTypeFactory.getResourceType(fileType.Substring(1)).ResourceType; if (resourceType.Equals("image")) { string strClientFileName = filename; string strServerFileName = SaveImage(); if (string.IsNullOrEmpty(strServerFileName)) { ShowMessage("发生错误"); return string.Empty; } /** start **/ Resource objResource = new Resource(); ResourceEntity model = new ResourceEntity(); //管理员上传直接审核通过 if (IsSuperAdmin) { model.Status = (int)ResourceEntity.ResourceStatus.IsPass; } else { model.Status = (int)ResourceEntity.ResourceStatus.NewUpload; } if (this.txtTitle.Text.Trim().Length > 0) { model.Caption = this.txtTitle.Text.Trim(); } else { model.Caption = Path.GetFileNameWithoutExtension(strClientFileName); } model.Description = this.txtRemark.Text.Trim(); model.EndDate = DateTime.Now.AddYears(10); model.FileName = strClientFileName; model.FolderName = CurrentUser.UserLoginName; model.ServerFileName = strServerFileName; model.GroupId = CurrentUser.UserGroupId; model.ItemId = Guid.NewGuid(); model.ItemSerialNum = Path.GetFileNameWithoutExtension(strServerFileName); //model.Keyword = this.keyWord.Value; model.Keyword = this.txtTitle.Text.Trim(); //model.shotDate = Convert.ToDateTime(this.shotDate1.Text); model.StartDate = Convert.ToDateTime("1900-01-01"); model.uploadDate = DateTime.Now; model.userId = CurrentUser.UserId; model.updateDate = DateTime.Now; model.Author = ""; //取得文件的扩展名,不包括.号 string fileExtName = string.Empty; fileExtName = Path.GetExtension(filename); if (fileExtName.IndexOf(".") > -1) { fileExtName = fileExtName.Substring(1); } model.ResourceType = ResourceTypeFactory.getResourceType(fileExtName).ResourceType; model.FileSize = Resource.GetResourceFileSize(strServerFileName, model.FolderName, fileExtName, ""); model.HasCopyright = 0; model.shotDate = DateTime.Now; objResource.Add(model); //objResource.CreateRelationshipResourceAndCatalog(model.ItemId, (Guid[])catalogIds.ToArray(typeof(Guid))); //return strServerFileName; return model.ItemId.ToString(); } } return string.Empty; }