// HANDLERS /////////////////////////////////////////////////////////////////////////////// private async void SendBtn_Click(Object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(MessageTb.Text)) { return; } if (UsersLv.SelectedItems.Count == 0) { return; } try { var selectedUserData = UsersLv.SelectedItems[0].Tag as UserTag; if (!EmailOnlyCb.Checked) { await _twilioService.SendSmsMessageAsync(selectedUserData.Phone, MessageTb.Text); } await _emailService.SendAsync(new EmailMessage() { Subject = "Appointment reminder notification", Body = MessageTb.Text, Destination = selectedUserData.Email }); MessagesRtb.Text += $"Sent: {MessageTb.Text}\r\n"; MessageTb.Clear(); } catch (Exception ex) { MessagesRtb.Text += $"Error: {ex.Message}\r\n"; _logger.Error(ex.Message); } }
/// <summary> /// 回复消息 /// </summary> /// <param name="Item"></param> /// <returns></returns> public int ReplyMessage(MessageTb Item) { try { SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@PMid", Item.PMid), new SqlParameter("@MessageBody", Item.MessageBody), new SqlParameter("@PMid", Item.MessageToUId), new SqlParameter("@MessageToUId", Item.MessageToUId), new SqlParameter("@Uid", Item.CreateUid), new SqlParameter("@Title", Item.Title), }; StringBuilder sb = new StringBuilder(); sb.Append(" INSERT INTO dbo.MessageTb( Title,MessageBody ,MessageToUId ,Attachment ,DeleteFlag , "); sb.Append(" IsReply ,PMid ,CreateDate ,CreateUid ,LastUpdateDate ,LastUpdateUId) "); sb.Append(" VALUES (@Title, @MessageBody ,@MessageToUId,'',0,1,@PMid,GETDATE(),@Uid,GETDATE(),Uid)"); return(SQLHelper.ExcuteScalarSQL(sb.ToString(), parms)); } catch (Exception) { return(-1); } }
/// <summary> /// 发送消息 /// </summary> /// <param name="Item"></param> /// <returns></returns> public int SendMessage(MessageTb Item) { try { SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@Title", Item.Title), new SqlParameter("@MessageBody", Item.MessageBody), new SqlParameter("@MessageToUId", Item.MessageBody), new SqlParameter("@Attachment", Item.MessageBody), new SqlParameter("@Uid", Item.CreateUid), }; StringBuilder sb = new StringBuilder(); sb.Append(" DECLARE @MId int "); sb.Append(" INSERT INTO dbo.MessageTb( Title,MessageBody ,MessageToUId ,Attachment , "); sb.Append(" DeleteFlag ,IsReply ,PMid ,CreateDate ,CreateUid ,LastUpdateDate ,LastUpdateUId) "); sb.Append(" VALUES (@Title,@MessageBody,@MessageToUId,@Attachment,'N',0,0,GETDATE(),@Uid,GETDATE(),@Uid) "); sb.Append(" set @MId= SCOPE_IDENTITY(); "); sb.Append(" select @MId as 'MId' "); return(SQLHelper.ExcuteScalarSQL(sb.ToString(), parms)); } catch (Exception) { return(-1); } }
private List <MessageTb> DataTableToList(DataTable dt) { List <MessageTb> Res = new List <MessageTb>(); for (int i = 0; i < dt.Rows.Count; i++) { var dr = dt.Rows[i]; var Item = new MessageTb() { Title = Convert.IsDBNull(dr["Title"]) ? "" : dr["Title"].ToString(), Attachment = Convert.IsDBNull(dr["Attachment"]) ? "" : dr["Attachment"].ToString(), CreateDate = Convert.IsDBNull(dr["CreateDate"]) ? new DateTime(1900, 1, 1) : Convert.ToDateTime(dr["CreateDate"]), CreateUid = Convert.IsDBNull(dr["CreateUid"]) ? 0 : Convert.ToInt32(dr["CreateUid"]), DeleteFlag = Convert.IsDBNull(dr["DeleteFlag"]) ? 0 : Convert.ToInt32(dr["DeleteFlag"]), IsReply = Convert.IsDBNull(dr["IsReply"]) ? 0 : Convert.ToInt32(dr["IsReply"]), LastUpdateDate = Convert.IsDBNull(dr["LastUpdateDate"]) ? new DateTime(1900, 1, 1) : Convert.ToDateTime(dr["LastUpdateDate"]), LastUpdateUId = Convert.IsDBNull(dr["LastUpdateUId"]) ? 0 : Convert.ToInt32(dr["LastUpdateUId"]), MessageBody = Convert.IsDBNull(dr["MessageBody"]) ? "" : dr["MessageBody"].ToString(), MessageToUId = Convert.IsDBNull(dr["MessageToUId"]) ? 0 : Convert.ToInt32(dr["MessageToUId"]), Mid = Convert.IsDBNull(dr["Mid"]) ? 0 : Convert.ToInt32(dr["Mid"]), PMid = Convert.IsDBNull(dr["PMid"]) ? 0 : Convert.ToInt32(dr["PMid"]) }; } return(Res); }
/// <summary> /// 回复消息 /// </summary> /// <param name="Item"></param> /// <returns></returns> public int ReplyMessage(MessageTb Item) { return(_dal.ReplyMessage(Item)); }
/// <summary> /// 发送消息 /// </summary> /// <param name="Item"></param> /// <returns></returns> public int SendMessage(MessageTb Item) { return(_dal.SendMessage(Item)); }