private void UploadExecute(object obj) { var team = obj as WrapTeam; if (team == null || team.Team.ID <= 0) { return; } OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == true) { var attach = new attach() { Type = "Team", TypeID = team.Team.ID, FileName = dialog.File.Name, Path = string.Format("ClientBin/Attach/Teams/{0}/{1}", team.Team.ID, dialog.File.Name) }; var client = Utils.ServicesFactory.CreateMatchService(); client.AddAttachesAsync(new ObservableCollection <attach>() { attach }); var item = new UploadItemInfo(dialog.File.Name, dialog.File.OpenRead()); StartUpload(team.Team.ID, item); } }
public ActionResult SaveNews(IFormCollection collection) { tzb news = new tzb(); Tuple <tzb, attach> Models = Tuple.Create(new tzb(), new attach()); var model = HttpContext.Session.Get("CurrentUser"); //获取session if (model == null) { return(Success("/qian/USER/Login")); } try { if (ModelState.IsValid) { var updateResult = TryUpdateModelAsync <Tuple <tzb, attach> >(Models); //将传递过来的对象转换 news = Models.Item1; using (var db = tzbRepository.Connection) { string hex = System.Text.Encoding.Default.GetString(model); //获取json数据 ry sta = JsonConvert.DeserializeObject <ry>(hex); //转换成model数据 string userID = sta.id; string userName = sta.yhm; FTPHelper ftps = new FTPHelper(_FtpConnection.Value.FtpServerIP, _FtpConnection.Value.FtpRemotePath + "/" + news.id, _FtpConnection.Value.FtpUserID, _FtpConnection.Value.FtpPassword); List <FileStruct> files = ftps.GetFileAndDirectoryList(_FtpConnection.Value.FtpRemotePath + "/tbz/" + news.id + "/"); if (files != null) { foreach (var file in files) { attach attach = new attach(); attach.tp_name = file.Name; attach.yw_id = news.id; attach.create_time = DateTime.Now; attach.tp_lj = _FtpConnection.Value.FtpRemotePath + "/tbz/" + news.id; attachRepository.AddFile(attach, userName, attach.tp_name); } } tzbRepository.AddNews(news, userName); if (news.TSTATUS == 0) { return(Success("保存成功。")); } else { return(Success("未插入成功。")); } } } else { return(View()); } } catch (Exception ex) { return(Error("保存数据库出错")); } }
UsageExample use(attach this script to a game object) :