private void btnAdd_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "文件(*.*)|*.*"; if (dlg.ShowDialog() == DialogResult.OK) { var attach = new TA_Attach() { TableName = TableName, TablePKID = TablePKID, CreateDate = DateTime.Now, CreatorName = GlobalVar.Oper.OperName, FileName = Path.GetFileName(dlg.FileName) }; FileStream fs = File.OpenRead(dlg.FileName); fs.Position = 0; byte[] blobdata = new Byte[fs.Length]; fs.Read(blobdata, 0, (int)fs.Length); attach.FileData = blobdata; fs.Close(); SpareEntities db = EntitiesFactory.CreateSpareInstance(); AttachController.AddOrUpdate(db, attach, GlobalVar.Oper); EntitiesFactory.SaveDb(db); MessageHelper.ShowInfo("保存成功!"); RefreshData(); } }
private void RefreshData() { var _attachlist = AttachController.GetList(_db).Where(p => p.TableName == TableName && p.TablePKID == TablePKID).ToList(); grid.PrimaryGrid.DataSource = _attachlist; }
static void Main(string[] args) { IAttach attach = new AttachController(); OutlookController outlookController = new OutlookController(attach); outlookController.Read(); throw new Exception(""); // IGmail gmail = new GmailController(attach); UserCredential credential; using (var stream = new FileStream(@pathinit + @"\client_secret.json", FileMode.Open, FileAccess.Read)) { try { // string credPath = System.Environment.GetFolderPath( //System.Environment.SpecialFolder.Personal); string credPath = pathinit; credPath = Path.Combine(credPath, ".credentials/gmail-dotnet-quickstart.json"); credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; Console.WriteLine("Credential file saved to: " + credPath); } catch (Exception ex) { Console.Write(ex); throw; } } // Create Gmail API service. var service = new GmailService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); // Define parameters of request. UsersResource.LabelsResource.ListRequest request = service.Users.Labels.List("me"); // start read mail //UsersResource.MessagesResource.ListRequest requestMessage = service.Users.Messages.List("me"); //IList<Message> listMessage = requestMessage.Execute().Messages; IList <Message> listMessage = gmail.ListMessages(service, "me", "has:attachment"); foreach (var item in listMessage) { var res = gmail.GetMessage(service, "me", item.Id); gmail.GetAttachments(service, "me", res.Id); } Console.Read(); }
private void btnDel_Click(object sender, EventArgs e) { if (_selectrow == null) { MessageHelper.ShowError("请选择要删除的附件!"); return; } if (MessageHelper.ShowQuestion("确认要删除选中的附件吗?") == DialogResult.Yes) { SpareEntities db = EntitiesFactory.CreateSpareInstance(); var attach = AttachController.GetList(_db).FirstOrDefault(p => p.UID == (int)_selectrow[gcUID].Value); AttachController.Delete(db, attach, GlobalVar.Oper); EntitiesFactory.SaveDb(db); MessageHelper.ShowInfo("删除成功!"); RefreshData(); } }