public int UpDateDraftMail(MailInfo mail) { return mailService.UpDate(mail); }
public int CreateMail(MailInfo mail) { return mailService.Insert(mail); }
public int Insert(MailInfo mail) { try { lock (this) { if (SqliteHelper.ExecuteNoQuery(System.Data.CommandType.Text, "insert into hm_mailinfo (UserId,FromAddress,ToAddress,Cc,Bcc,Subject,DownloadDate,ReceiveDate,Type,Status)values(@UserId,@FromAddress,@ToAddress,@Cc,@Bcc,@Subject,@DownloadDate,@ReceiveDate,@Type,@Status)", Parameter(mail)) > 0) return Convert.ToInt32(SqliteHelper.ExecuteScaler(System.Data.CommandType.Text, "select id from hm_mailinfo order by id desc limit 0,1")); return 0; } } catch { return -1; } }
private SQLiteParameter[] Parameter(MailInfo mail) { return new SQLiteParameter[] { new SQLiteParameter("@Id",mail.Id), new SQLiteParameter("@UserId",mail.UserId), new SQLiteParameter("@FromAddress",mail.FromAddress), new SQLiteParameter("@ToAddress",mail.ToAddress), new SQLiteParameter("@Cc",mail.Cc), new SQLiteParameter("@Bcc",mail.Bcc), new SQLiteParameter("@Subject",mail.Subject), new SQLiteParameter("@DownloadDate",mail.DownloadDate), new SQLiteParameter("@ReceiveDate",mail.ReceiveDate), new SQLiteParameter("@Type",mail.Type), new SQLiteParameter("@Status",mail.Status) }; }
public int UpDate(MailInfo mail) { try { return SqliteHelper.ExecuteNoQuery(System.Data.CommandType.Text, "update hm_mailinfo set UserId = @UserId FromAddress = @FromAddress,ToAddress = @ToAddress,Cc = @Cc,Bcc = @Bcc,Subject = @Subject,DownloadDate = @DownloadDate,ReceiveDate = @ReceiveDate,Type=@Type where Id = @Id", Parameter(mail)); } catch { return -1; } }
/// <summary> /// 把邮件MailInfo转换为数据库实体 /// </summary> /// <param name="userId"></param> /// <param name="hmailInfo"></param> /// <returns></returns> public static MailInfo ConvertToDbMailEntity(int userId, HMailInfo hmailInfo) { if(hmailInfo == null) throw new ArgumentNullException("hmailInfo"); try { MailInfo mailTmp = new MailInfo(); StringBuilder sb = new StringBuilder(); mailTmp.Subject = hmailInfo.SubJect; mailTmp.FromAddress = hmailInfo.From.Address; if (hmailInfo.To != null) hmailInfo.To.AsParallel().ForAll((s) => { sb.Append(string.Format("{0}{1}", s.Address, ",")); }); mailTmp.ToAddress = sb.ToString().TrimEnd(','); sb.Clear(); if (hmailInfo.Cc != null) hmailInfo.Cc.AsParallel().ForAll((v) => { sb.Append(string.Format("{0}{1}", v.Address, ",")); }); mailTmp.Cc = sb.ToString().TrimEnd(','); sb.Clear(); if (hmailInfo.Bcc != null) hmailInfo.Bcc.AsParallel().ForAll((n) => { sb.Append(string.Format("{0}{1}", n.Address, ",")); }); mailTmp.Bcc = sb.ToString().TrimEnd(','); mailTmp.ReceiveDate = ConvertCommon.ConvertFromMailDate(hmailInfo.Date); mailTmp.DownloadDate = DateTime.Now; mailTmp.Type = (int)MailInfo.MailType.Common; mailTmp.UserId = userId; mailTmp.Del = 0; mailTmp.Status = (int)MailInfo.MailStatus.Unread; return mailTmp; } catch (Exception e) { throw e; } }