public int BatchSend(string[] receiverIds, string organizeId, string roleId, BaseMessageEntity messageEntity, bool saveSend = true) { string[] organizeIds = null; string[] roleIds = null; if (!string.IsNullOrEmpty(organizeId)) { organizeIds = new string[] { organizeId }; } if (!string.IsNullOrEmpty(roleId)) { roleIds = new string[] { roleId }; } return BatchSend(receiverIds, organizeIds, roleIds, messageEntity, saveSend); }
/// <summary> /// 批量发送站内信息 /// </summary> /// <param name="userInfo">用户</param> /// <param name="receiverIds">接受者主键数组</param> /// <param name="organizeIds">组织机构主键数组</param> /// <param name="roleIds">角色主键数组</param> /// <param name="messageEntity">消息内容</param> /// <returns>影响行数</returns> public int BatchSend(BaseUserInfo userInfo, string[] receiverIds, string[] organizeIds, string[] roleIds, BaseMessageEntity messageEntity) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif int returnValue = 0; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); returnValue = messageManager.BatchSend(receiverIds, organizeIds, roleIds, messageEntity, true); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.MessageService_BatchSend, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return returnValue; }
/// <summary> /// 发送即时通讯提醒 /// </summary> /// <param name="workFlowCurrentEntity">当前审核流实体信息</param> /// <param name="auditStatus">审核状态</param> /// <param name="auditIdea">审核意见</param> /// <param name="userIds">发送给用户主键</param> /// <param name="roleIds">发送给角色主键</param> /// <returns>影响行数</returns> public virtual int SendRemindMessage(BaseWorkFlowCurrentEntity workFlowCurrentEntity, AuditStatus auditStatus, string[] userIds, string organizeId, string roleId) { // string currentId, string objectId, string objectFullName int returnValue = 0; // 不用给自己发消息了,消息多了也烦恼 userIds = StringUtil.Remove(userIds, this.UserInfo.Id); // BaseUserEntity userEntity = userManager.GetEntity(userId); // 发送请求审核的信息 BaseMessageEntity messageEntity = new BaseMessageEntity(); messageEntity.Id = BaseBusinessLogic.NewGuid(); // 这里是回调的类,用反射要回调的 messageEntity.FunctionCode = MessageFunction.Remind.ToString(); // messageEntity.FunctionCode = this.GetType().ToString(); messageEntity.ObjectId = workFlowCurrentEntity.ObjectId; // 这里是网页上的显示地址 // messageEntity.Title = this.GetUrl(id); string auditIdea = string.Empty; if (!string.IsNullOrEmpty(workFlowCurrentEntity.AuditIdea)) { auditIdea = " 批示: " + workFlowCurrentEntity.AuditIdea; } // messageEntity.Contents = userEntity.DepartmentName + " " + userEntity.RealName messageEntity.Contents = workFlowCurrentEntity.CreateBy + " 发出审批申请: " + "<a title='点击这里,直接查看单据' target='_blank' href='" + this.GetUrl(workFlowCurrentEntity.Id) + "'>" + workFlowCurrentEntity.ObjectFullName + "</a> " + Environment.NewLine + this.UserInfo.RealName + " " + BaseBusinessLogic.GetAuditStatus(auditStatus) + " " + Environment.NewLine + auditIdea; messageEntity.Contents = "有单据" + BaseBusinessLogic.GetAuditStatus(auditStatus); messageEntity.IsNew = 1; messageEntity.ReadCount = 0; messageEntity.Enabled = 1; messageEntity.DeletionStateCode = 0; BaseMessageManager messageManager = new BaseMessageManager(this.UserInfo); returnValue = messageManager.BatchSend(userIds, organizeId, roleId, messageEntity, false); return returnValue; }
// 这个是声明扩展方法 partial void SetEntityExpand(SQLBuilder sqlBuilder, BaseMessageEntity baseMessageEntity);
/// <summary> /// 更新实体 /// </summary> /// <param name="baseMessageEntity">实体</param> public int UpdateEntity(BaseMessageEntity baseMessageEntity) { SQLBuilder sqlBuilder = new SQLBuilder(DbHelper); sqlBuilder.BeginUpdate(this.CurrentTableName); this.SetEntity(sqlBuilder, baseMessageEntity); if (UserInfo != null) { sqlBuilder.SetValue(BaseMessageEntity.FieldModifiedUserId, UserInfo.Id); sqlBuilder.SetValue(BaseMessageEntity.FieldModifiedBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseMessageEntity.FieldModifiedOn); sqlBuilder.SetWhere(BaseMessageEntity.FieldId, baseMessageEntity.Id); return sqlBuilder.EndUpdate(); }
/// <summary> /// 获取实体 /// </summary> /// <param name="id">主键</param> public BaseMessageEntity GetEntity(string id) { BaseMessageEntity baseMessageEntity = new BaseMessageEntity(this.GetDataTable(new KeyValuePair<string, object>(BaseMessageEntity.FieldId, id))); return baseMessageEntity; }
/// <summary> /// 添加 /// </summary> /// <param name="baseMessageEntity">实体</param> /// <param name="identity">自增量方式</param> /// <param name="returnId">返回主键</param> /// <returns>主键</returns> public string Add(BaseMessageEntity baseMessageEntity, bool identity, bool returnId) { this.Identity = identity; this.ReturnId = returnId; return this.AddEntity(baseMessageEntity); }
public bool OnReceiveMessage(BaseMessageEntity messageEntity) { bool returnValue = false; // 判断消息,是否发送给本窗体的 //if (this.ReceiverId.Equals(Message.ReceiverId)) //{ returnValue = true; if (this.InvokeRequired) { SetMessage SetMessage = new SetMessage(OnReceiveMessage); this.Invoke(SetMessage, new object[] { messageEntity }); } else { //this.txtMessage.AppendText(messageEntity.CreateBy + " " + ((DateTime)messageEntity.CreateOn).ToString(BaseSystemInfo.DateTimeFormat) + " 说: " + "\r\n"); //this.txtMessage.AppendText(messageEntity.Content + "\r\n"); //this.txtMessage.AppendText("- - - - - - - - - - - - - - -" + "\r\n"); //this.txtMessage.ScrollToCaret(); //StringBuilder sbContent = new StringBuilder(); //sbContent.Append("<div style='color:#00f;font-size:12px;'>" + messageEntity.CreateBy + " ["); //if (isToday((DateTime)messageEntity.CreateOn)) //{ // sbContent.Append(((DateTime)messageEntity.CreateOn).ToLongTimeString() + "]:</div>"); //} //else //{ // sbContent.Append(((DateTime)messageEntity.CreateOn).ToString(BaseSystemInfo.DateTimeFormat) + "]:</div>"); //} //// Web里的单点登录识别码进行转换 //messageEntity.Contents = messageEntity.Contents.Replace("{OpenId}", this.UserInfo.OpenId); //sbContent.Append(messageEntity.Contents); //strOneShow.Append(sbContent.ToString()); //this.webBMsg.DocumentText = this.webBMsg.DocumentText.Insert(this.webBMsg.DocumentText.Length, sbContent.ToString()); messageEntity.Contents = ReplaceMessage(messageEntity.Contents); StringBuilder sbContent = new StringBuilder(); sbContent.Append("<div style='color:#00f;font-size:12px;'>" + messageEntity.CreateBy + " ["); if (isToday((DateTime)messageEntity.CreateOn)) { sbContent.Append(((DateTime)messageEntity.CreateOn).ToLongTimeString() + "]:</div>"); } else { sbContent.Append(((DateTime)messageEntity.CreateOn).ToString(BaseSystemInfo.DateTimeFormat) + "]:</div>"); } sbContent.Append(messageEntity.Contents); OneShow.Append(sbContent.ToString()); this.webMessage.DocumentText = this.webMessage.DocumentText.Insert(this.webMessage.DocumentText.Length, GetHtmlFace(sbContent.ToString())); this.PlaySound(); FlashWindow(this.Handle, true); } //} return returnValue; }
/// <summary> /// 按部门群发短信 /// </summary> /// <param name="messageEntity">实体</param> /// <param name="organizeId">部门主键</param> /// <returns>影响行数</returns> public int Send(BaseMessageEntity messageEntity, string organizeId, bool saveSend = true) { int returnValue = 0; int i = 0; BaseUserManager userManager = new BaseUserManager(DbHelper, UserInfo); DataTable dataTable = userManager.GetChildrenUsers(organizeId); string[] receiverIds = new string[dataTable.Rows.Count]; foreach (DataRow dataRow in dataTable.Rows) { receiverIds[i++] = dataRow[BaseMessageEntity.FieldId].ToString(); } returnValue = this.Send(messageEntity, receiverIds, saveSend); return returnValue; }
/// <summary> /// 添加短信,可以发给多个人 /// </summary> /// <param name="messageEntity">实体</param> /// <param name="receiverIds">接收者ID组</param> /// <returns>影响行数</returns> public int Send(BaseMessageEntity messageEntity, string[] receiverIds, bool saveSend = true) { BaseUserManager userManager = new BaseUserManager(DbHelper, UserInfo); // 每发一条短信,数据库中需要记录两条记录,他们的CreateUserId都为创建者ID。 // 接收者多人的话,不要重复设置创建人的记录了,即对发送者来说,只要记录一条记录就够了 int returnValue = 0; messageEntity.CategoryCode = MessageCategory.Receiver.ToString(); messageEntity.IsNew = (int)MessageStateCode.New; messageEntity.IPAddress = UserInfo.IPAddress; messageEntity.ParentId = null; messageEntity.DeletionStateCode = 0; messageEntity.Enabled = 1; returnValue++; BaseUserEntity userEntity = null; for (int i = 0; i < receiverIds.Length; i++) { messageEntity.ParentId = null; messageEntity.Id = Guid.NewGuid().ToString(); messageEntity.CategoryCode = MessageCategory.Receiver.ToString(); messageEntity.ReceiverId = receiverIds[i]; userEntity = userManager.GetEntity(receiverIds[i]); if (userEntity != null && !string.IsNullOrEmpty(userEntity.Id)) { messageEntity.ReceiverRealName = userEntity.RealName; // 发给了哪个部门的人,意义不大,是来自哪个部门的人,意义更大一些 // messageEntity.DepartmentId = userEntity.DepartmentId; // messageEntity.DepartmentName = userEntity.DepartmentName; } messageEntity.Enabled = 1; messageEntity.IsNew = 1; if (messageEntity.ReceiverId.Equals(UserInfo.Id)) { messageEntity.IsNew = (int)MessageStateCode.Old; } // 接收信息 string parentId = this.Add(messageEntity, false, false); if (saveSend) { // 已发送信息 messageEntity.Id = Guid.NewGuid().ToString(); messageEntity.ParentId = parentId; messageEntity.CategoryCode = MessageCategory.Send.ToString(); messageEntity.DeletionStateCode = 0; messageEntity.Enabled = 0; this.Add(messageEntity, false, false); } returnValue++; } return returnValue; }
/// <summary> /// 添加一条短信,只能发给一个人,在数据库中加入两条记录 /// </summary> /// <param name="messageEntity">添加对象</param> /// <returns>影响行数</returns> public int Send(BaseMessageEntity messageEntity, bool saveSend = true) { string[] receiverIds = new string[1]; receiverIds[0] = messageEntity.ReceiverId.ToString(); return this.Send(messageEntity, receiverIds, saveSend); }
/// <summary> /// 阅读短信 /// </summary> /// <param name="id">短信ID</param> /// <returns>数据权限</returns> public DataTable Read(string id) { // 这里需要改进一下,运行一个高性能的sql语句就可以了,效率会高一些 DataTable dataTable = this.GetDataTableById(id); BaseMessageEntity messageEntity = new BaseMessageEntity(dataTable); this.OnRead(messageEntity, id); dataTable = this.GetDataTableById(id); return dataTable; }
/// <summary> /// 获取最新一条信息 /// </summary> /// <returns>记录个数</returns> public BaseMessageEntity GetNewOne() { BaseMessageEntity messageEntity = new BaseMessageEntity(); string sqlQuery = " SELECT * " + " FROM (SELECT * FROM " + BaseMessageEntity.TableName + " WHERE (" + BaseMessageEntity.FieldIsNew + " = " + ((int)MessageStateCode.New).ToString() + " ) " + " AND (" + BaseMessageEntity.FieldReceiverId + " = '" + UserInfo.Id + "') " + " ORDER BY " + BaseMessageEntity.FieldCreateOn + " DESC) " + " WHERE ROWNUM = 1 "; DataTable dataTable = DbHelper.Fill(sqlQuery); return messageEntity.GetSingle(dataTable); }
/// <summary> /// 广播消息 /// </summary> /// <param name="userInfo">用户</param> /// <param name="message">消息内容</param> /// <returns>主键</returns> public int Broadcast(BaseUserInfo userInfo, string message) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif int returnValue = 0; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); string[] receiverIds = null; BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); receiverIds = userManager.GetIds(new KeyValuePair<string, object>(BaseUserEntity.FieldEnabled, 1), new KeyValuePair<string, object>(BaseUserEntity.FieldDeletionStateCode, 0)); BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); BaseMessageEntity messageEntity = new BaseMessageEntity(); messageEntity.Id = BaseBusinessLogic.NewGuid(); messageEntity.FunctionCode = MessageFunction.Remind.ToString(); messageEntity.Contents = message; messageEntity.IsNew = 1; messageEntity.ReadCount = 0; messageEntity.Enabled = 1; messageEntity.DeletionStateCode = 0; returnValue = messageManager.BatchSend(receiverIds, string.Empty, string.Empty, messageEntity, false); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.MessageService_BatchSend, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return returnValue; }
/// <summary> /// 阅读短信后设置状态值和阅读次数 /// </summary> /// <param name="messageEntity">实体</param> /// <param name="id">短信主键</param> /// <returns>影响的条数</returns> private int OnRead(BaseMessageEntity messageEntity, string id) { int returnValue = 0; // 针对“已发送”的情况 if (messageEntity.ReceiverId == UserInfo.Id) { // 针对“删除的信息”的情况 if (messageEntity.IsNew == (int)MessageStateCode.New) { SQLBuilder sqlBuilder = new SQLBuilder(this.DbHelper); sqlBuilder.BeginUpdate(this.CurrentTableName); sqlBuilder.SetValue(BaseMessageEntity.FieldIsNew, ((int)MessageStateCode.Old).ToString()); sqlBuilder.SetDBNow(BaseMessageEntity.FieldReadDate); sqlBuilder.SetWhere(BaseMessageEntity.FieldId, id); sqlBuilder.EndUpdate(); } } // 增加阅读次数 messageEntity.ReadCount++; this.SetProperty(id, new KeyValuePair<string, object>(BaseMessageEntity.FieldReadCount, messageEntity.ReadCount.ToString())); returnValue++; return returnValue; }
/// <summary> /// 发送消息 /// </summary> /// <param name="userInfo">用户</param> /// <param name="receiverId">接收者主键</param> /// <param name="contents">内容</param> /// <returns>主键</returns> public string Send(BaseUserInfo userInfo, string receiverId, string contents) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif string returnValue = string.Empty; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseMessageEntity messageEntity = new BaseMessageEntity(); messageEntity.Id = Guid.NewGuid().ToString(); messageEntity.CategoryCode = MessageCategory.Send.ToString(); messageEntity.FunctionCode = MessageFunction.Message.ToString(); messageEntity.ReceiverId = receiverId; messageEntity.Contents = contents; messageEntity.IsNew = (int)MessageStateCode.New; messageEntity.ReadCount = 0; messageEntity.DeletionStateCode = 0; messageEntity.Enabled = 1; BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); messageManager.Send(messageEntity, true); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.MessageService_Send, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return returnValue; }
/// <summary> /// 批量发送消息 /// </summary> /// <param name="receiverIds">接收者主键组</param> /// <param name="organizeIds">组织机构主键组</param> /// <param name="roleIds">角色主键组</param> /// <param name="content">内容</param> /// <returns>影响行数</returns> public int BatchSend(string[] receiverIds, string[] organizeIds, string[] roleIds, BaseMessageEntity messageEntity, bool saveSend = true) { BaseUserManager userManager = new BaseUserManager(DbHelper, UserInfo); receiverIds = userManager.GetUserIds(receiverIds, organizeIds, roleIds); return this.Send(messageEntity, receiverIds, saveSend); }
/// <summary> /// 发送即时通讯提醒 /// </summary> /// <param name="id">主键</param> /// <param name="auditStatus">审核状态</param> /// <param name="auditIdea">审核意见</param> /// <param name="userId">发送给用户主键</param> /// <param name="roleId">发送给角色主键</param> /// <returns>影响行数</returns> public int SendRemindMessage(string id, AuditStatus auditStatus, string auditIdea, string[] userIds, string[] organizeIds, string[] roleIds) { int returnValue = 0; // 发送请求审核的信息 BaseMessageEntity messageEntity = new BaseMessageEntity(); messageEntity.Id = BaseBusinessLogic.NewGuid(); // 这里是回调的类,用反射要回调的 messageEntity.FunctionCode = this.GetType().ToString(); messageEntity.ObjectId = id; // 这里是网页上的显示地址 // messageEntity.Title = this.GetUrl(id); // messageEntity.Content = BaseBusinessLogic.GetAuditStatus(auditStatus) + ":" + this.GetEntity(id).Title + " 请查收" // + Environment.NewLine // + this.GetUrl(id) // + auditIdea; messageEntity.IsNew = 1; messageEntity.ReadCount = 0; messageEntity.Enabled = 1; messageEntity.DeletionStateCode = 0; BaseMessageManager messageManager = new BaseMessageManager(this.UserInfo); returnValue = messageManager.BatchSend(userIds, organizeIds, roleIds, messageEntity, false); return returnValue; }
private void btnSend_Click(object sender, EventArgs e) { StringBuilder sbmy = new StringBuilder(); sbmy.Append("<div style='margin:2px;padding:0px 0px 0px 15px;" + "font-family:" + this.txtContents.Font.FontFamily.Name + ";" + "font-size:" + this.txtContents.Font.Size + "pt;color:#" + this.txtContents.ForeColor.R.ToString("X2") + this.txtContents.ForeColor.G.ToString("X2") + this.txtContents.ForeColor.B.ToString("X2")); sbmy.Append(";font-weight:"); sbmy.Append(this.txtContents.Font.Bold ? "bold" : ""); sbmy.Append(";font-style:"); sbmy.Append(this.txtContents.Font.Italic ? "italic" : ""); sbmy.Append(";'>"); sbmy.Append(GetHtmlHref(this.txtContents.Text) + "</div>"); DotNetService dotNetService = new DotNetService(); if (this.ucUser.SelectedIds != null) { // 发送信息 BaseMessageEntity messageEntity = new BaseMessageEntity(); messageEntity.Id = BaseBusinessLogic.NewGuid(); messageEntity.FunctionCode = MessageFunction.Message.ToString(); messageEntity.Contents = sbmy.ToString(); messageEntity.IsNew = 1; messageEntity.ReadCount = 0; messageEntity.Enabled = 1; messageEntity.DeletionStateCode = 0; dotNetService.MessageService.BatchSend(UserInfo, this.ucUser.SelectedIds, null, null, messageEntity); } else { if (this.ucUser.SelectedId != null) { dotNetService.MessageService.Send(UserInfo, this.ucUser.SelectedId, sbmy.ToString()); } } if (dotNetService.MessageService is ICommunicationObject) { ((ICommunicationObject)dotNetService.MessageService).Close(); } // 2010-12-15 发好信息了,还是关闭了比较好 // this.txtContent.Clear(); // this.txtContent.Focus(); this.Close(); }
/// <summary> /// 添加 /// </summary> /// <param name="baseMessageEntity">实体</param> /// <returns>主键</returns> public string Add(BaseMessageEntity baseMessageEntity) { return this.AddEntity(baseMessageEntity); }
public void ShowMessage(BaseMessageEntity messageEntity) { if (!string.IsNullOrEmpty(messageEntity.CreateUserId)) { // 检查窗体,是否已经打开了窗体 FrmMessageRead frmMessageRead = this.ShowMessageRead(messageEntity.CreateUserId, this); if (frmMessageRead != null) { frmMessageRead.OnReceiveMessage(messageEntity); } } }
/// <summary> /// 添加实体 /// </summary> /// <param name="baseMessageEntity">实体</param> public string AddEntity(BaseMessageEntity baseMessageEntity) { string sequence = string.Empty; this.Identity = false; if (baseMessageEntity.SortCode == null || baseMessageEntity.SortCode == 0) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); baseMessageEntity.SortCode = int.Parse(sequence); } if (baseMessageEntity.Id != null) { sequence = baseMessageEntity.Id.ToString(); } SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(this.CurrentTableName, BaseMessageEntity.FieldId); if (!this.Identity) { if (string.IsNullOrEmpty(baseMessageEntity.Id)) { sequence = BaseBusinessLogic.NewGuid(); baseMessageEntity.Id = sequence ; } sqlBuilder.SetValue(BaseMessageEntity.FieldId, baseMessageEntity.Id); } else { if (!this.ReturnId && (DbHelper.CurrentDbType == DbTypes.Oracle || DbHelper.CurrentDbType == DbTypes.DB2)) { if (DbHelper.CurrentDbType == DbTypes.Oracle) { sqlBuilder.SetFormula(BaseMessageEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } if (DbHelper.CurrentDbType == DbTypes.DB2) { sqlBuilder.SetFormula(BaseMessageEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper()); } } else { if (this.Identity && (DbHelper.CurrentDbType == DbTypes.Oracle || DbHelper.CurrentDbType == DbTypes.DB2)) { if (string.IsNullOrEmpty(baseMessageEntity.Id)) { if (string.IsNullOrEmpty(sequence)) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); } baseMessageEntity.Id = sequence; } sqlBuilder.SetValue(BaseMessageEntity.FieldId, baseMessageEntity.Id); } } } this.SetEntity(sqlBuilder, baseMessageEntity); if (UserInfo != null) { sqlBuilder.SetValue(BaseMessageEntity.FieldCreateUserId, UserInfo.Id); sqlBuilder.SetValue(BaseMessageEntity.FieldCreateBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseMessageEntity.FieldCreateOn); if (UserInfo != null) { sqlBuilder.SetValue(BaseMessageEntity.FieldModifiedUserId, UserInfo.Id); sqlBuilder.SetValue(BaseMessageEntity.FieldModifiedBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseMessageEntity.FieldModifiedOn); if (this.Identity && (DbHelper.CurrentDbType == DbTypes.SqlServer || DbHelper.CurrentDbType == DbTypes.Access)) { sequence = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } return sequence; }
public void ShowRemind(BaseMessageEntity messageEntity) { if (this.frmMessageRemind == null || !this.frmMessageRemind.Visible) { this.frmMessageRemind = new FrmMessageRemind(); frmMessageRemind.Show(this); } this.frmMessageRemind.OnReceiveMessage(messageEntity); }
/// <summary> /// 更新 /// </summary> /// <param name="baseMessageEntity">实体</param> public int Update(BaseMessageEntity baseMessageEntity) { return this.UpdateEntity(baseMessageEntity); }
private void GetNewMessage() { if (!this.ExitApplication) { if (this.FormLoaded && (!this.Busyness)) { if (this.tvOrganize.InvokeRequired) { if (!this.ExitApplication) { SetGetNewMessage getNewMessage = new SetGetNewMessage(this.GetNewMessage); if (getNewMessage != null) { this.Invoke(getNewMessage); } } } else { try { // 获取最新即时通讯消息 DotNetService dotNetService = new DotNetService(); // 这里获取用户的登录凭证,看与本地的是否一致? string openId = string.Empty; DataTable dataTable = dotNetService.MessageService.GetDataTableNew(this.UserInfo, out openId); if ((dataTable != null) && (dataTable.Rows.Count > 0)) { BaseMessageEntity messageEntity = new BaseMessageEntity(); for (int i = 0; i < dataTable.Rows.Count; i++) { messageEntity.GetFrom(dataTable.Rows[i]); if (messageEntity.FunctionCode.Equals("Message")) { this.ShowMessage(messageEntity); } else { this.ShowRemind(messageEntity); } // 将信息标记为已阅读 dotNetService.MessageService.Read(UserInfo, messageEntity.Id); } if (dotNetService.MessageService is ICommunicationObject) { ((ICommunicationObject)dotNetService.MessageService).Close(); } } // 若检查在线状态,根本就无法登录了,所以加上这样的判断 if (BaseSystemInfo.CheckOnLine && !UserInfo.OpenId.Equals(openId)) { //if (Program.frmMessage != null) //{ // Program.frmMessage.ExitApplication = true; // Program.frmMessage.AbortThread(); // Program.frmMessage.Close(); // Program.frmMessage.Dispose(); //} throw new InvalidOperationException(); // 修改当前用户的登录状态 BaseSystemInfo.UserIsLogOn = false; if (MessageBox.Show(AppMessage.MSG0300, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Stop) == System.Windows.Forms.DialogResult.OK) { Application.Exit(); } } } catch (System.Exception ex) { // 在本地记录异常 FileUtil.WriteException(UserInfo, ex); } } } } }
/// <summary> /// 设置实体 /// </summary> /// <param name="baseMessageEntity">实体</param> private void SetEntity(SQLBuilder sqlBuilder, BaseMessageEntity baseMessageEntity) { SetEntityExpand(sqlBuilder, baseMessageEntity); sqlBuilder.SetValue(BaseMessageEntity.FieldParentId, baseMessageEntity.ParentId); sqlBuilder.SetValue(BaseMessageEntity.FieldReceiverDepartmentId, baseMessageEntity.ReceiverDepartmentId); sqlBuilder.SetValue(BaseMessageEntity.FieldReceiverDepartmentName, baseMessageEntity.ReceiverDepartmentName); sqlBuilder.SetValue(BaseMessageEntity.FieldReceiverId, baseMessageEntity.ReceiverId); sqlBuilder.SetValue(BaseMessageEntity.FieldReceiverRealName, baseMessageEntity.ReceiverRealName); sqlBuilder.SetValue(BaseMessageEntity.FieldFunctionCode, baseMessageEntity.FunctionCode); sqlBuilder.SetValue(BaseMessageEntity.FieldCategoryCode, baseMessageEntity.CategoryCode); sqlBuilder.SetValue(BaseMessageEntity.FieldObjectId, baseMessageEntity.ObjectId); sqlBuilder.SetValue(BaseMessageEntity.FieldTitle, baseMessageEntity.Title); sqlBuilder.SetValue(BaseMessageEntity.FieldContents, baseMessageEntity.Contents); sqlBuilder.SetValue(BaseMessageEntity.FieldIsNew, baseMessageEntity.IsNew); sqlBuilder.SetValue(BaseMessageEntity.FieldReadCount, baseMessageEntity.ReadCount); sqlBuilder.SetValue(BaseMessageEntity.FieldReadDate, baseMessageEntity.ReadDate); sqlBuilder.SetValue(BaseMessageEntity.FieldTargetURL, baseMessageEntity.TargetURL); sqlBuilder.SetValue(BaseMessageEntity.FieldIPAddress, baseMessageEntity.IPAddress); sqlBuilder.SetValue(BaseMessageEntity.FieldCreateDepartmentId, baseMessageEntity.CreateDepartmentId); sqlBuilder.SetValue(BaseMessageEntity.FieldCreateDepartmentName, baseMessageEntity.CreateDepartmentName); sqlBuilder.SetValue(BaseMessageEntity.FieldDeletionStateCode, baseMessageEntity.DeletionStateCode); sqlBuilder.SetValue(BaseMessageEntity.FieldEnabled, baseMessageEntity.Enabled); sqlBuilder.SetValue(BaseMessageEntity.FieldDescription, baseMessageEntity.Description); sqlBuilder.SetValue(BaseMessageEntity.FieldSortCode, baseMessageEntity.SortCode); }
public bool OnReceiveMessage(BaseMessageEntity messageEntity) { bool returnValue = false; if (this.InvokeRequired) { SetMessage SetMessage = new SetMessage(OnReceiveMessage); this.Invoke(SetMessage, new object[] { messageEntity }); } else { OnReceiveMessage(messageEntity.Contents, ((DateTime)messageEntity.CreateOn).ToString(BaseSystemInfo.DateTimeFormat)); returnValue = true; } return returnValue; }
/// <summary> /// 添加用户 /// </summary> /// <param name="dbHelper">数据库连接</param> /// <param name="userInfo">用户信息</param> /// <param name="userEntity">用户实体</param> /// <param name="statusCode">状态码</param> /// <param name="statusMessage">状态信息</param> /// <returns>主键</returns> public string AddUser(IDbHelper dbHelper, BaseUserInfo userInfo, BaseUserEntity userEntity, out string statusCode, out string statusMessage) { // 加强安全验证防止未授权匿名调用 #if (!DEBUG) BaseSystemInfo.IsAuthorized(userInfo); #endif string returnValue = string.Empty; BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); // 若是系统需要用加密的密码,这里需要加密密码。 if (BaseSystemInfo.ServerEncryptPassword) { userEntity.UserPassword = userManager.EncryptUserPassword(userEntity.UserPassword); // 安全通讯密码、交易密码也生成好 userEntity.CommunicationPassword = userManager.EncryptUserPassword(userEntity.CommunicationPassword); } returnValue = userManager.Add(userEntity, out statusCode); statusMessage = userManager.GetStateMessage(statusCode); // 自己不用给自己发提示信息,这个提示信息是为了提高工作效率的,还是需要审核通过的,否则垃圾信息太多了 if (userEntity.Enabled == 0 && statusCode.Equals(StatusCode.OKAdd.ToString())) { // 不是系统管理员添加 if (!userInfo.IsAdministrator) { // 给超级管理员群组发信息 BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo); string[] roleIds = roleManager.GetIds(new KeyValuePair<string, object>(BaseRoleEntity.FieldCode, "Administrators")); string[] userIds = userManager.GetIds(new KeyValuePair<string, object>(BaseUserEntity.FieldCode, "Administrator")); // 发送请求审核的信息 BaseMessageEntity messageEntity = new BaseMessageEntity(); messageEntity.FunctionCode = MessageFunction.WaitForAudit.ToString(); // Pcsky 2012.05.04 显示申请的用户名 messageEntity.Contents = userInfo.RealName + "(" + userInfo.IPAddress + ")" + AppMessage.UserService_Application + userEntity.UserName + AppMessage.UserService_Check; //messageEntity.Contents = userInfo.RealName + "(" + userInfo.IPAddress + ")" + AppMessage.UserService_Application + userEntity.RealName + AppMessage.UserService_Check; BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); messageManager.BatchSend(userIds, null, roleIds, messageEntity, false); } } return returnValue; }
/// <summary> /// 发送文件 /// </summary> /// <param name="userInfo">用户</param> /// <param name="fileName">文件名</param> /// <param name="file">文件内容</param> /// <param name="toUserId">发送给谁主键</param> /// <returns>文件主键</returns> public string Send(BaseUserInfo userInfo, string fileName, byte[] file, string toUserId) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif string returnValue = string.Empty; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseFolderEntity folderEntity = new BaseFolderEntity(); BaseFolderManager folderManager = new BaseFolderManager(dbHelper, userInfo); // 检查相应的系统必备文件夹 folderManager.FolderCheck(); BaseUserEntity userEntity = new BaseUserManager(dbHelper, userInfo).GetEntity(toUserId); if (!string.IsNullOrEmpty(userEntity.Id)) { // 04:判断发送者的空间是否存在? // 05:判断已收文件夹是否存在? if (!folderManager.Exists(userEntity.Id.ToString())) { folderEntity.FolderName = userEntity.RealName + AppMessage.FileService_File; folderEntity.ParentId = "UserSpace"; folderEntity.Id = userEntity.Id.ToString(); folderEntity.Enabled = 1; folderEntity.DeletionStateCode = 0; folderManager.AddEntity(folderEntity); } // 06:判断来自谁的文件夹是否存在? // 07:判断发给谁的文件夹是否存在? if (!folderManager.Exists(toUserId + "_Receive")) { folderEntity.FolderName = AppMessage.FileService_ReceiveFile; folderEntity.ParentId = toUserId; folderEntity.Id = toUserId + "_Receive"; folderEntity.Enabled = 1; folderEntity.DeletionStateCode = 0; folderManager.AddEntity(folderEntity); } if (!folderManager.Exists(userInfo.Id + "_Send_" + toUserId)) { folderEntity.FolderName = userEntity.RealName + "(" + userEntity.UserName + ")"; folderEntity.ParentId = userInfo.Id + "_Send"; folderEntity.Id = userInfo.Id + "_Send_" + toUserId; folderEntity.Enabled = 1; folderEntity.DeletionStateCode = 0; folderManager.AddEntity(folderEntity); } if (!folderManager.Exists(toUserId + "_Receive_" + userInfo.Id)) { folderEntity.FolderName = userInfo.RealName + "(" + userInfo.UserName + ")"; folderEntity.ParentId = toUserId + "_Receive"; folderEntity.Id = toUserId + "_Receive_" + userInfo.Id; folderEntity.Enabled = 1; folderEntity.DeletionStateCode = 0; folderManager.AddEntity(folderEntity); } // 08:已发送文件夹多一个文件。 // 09:已接收文件夹多一个文件。 BaseFileEntity fileEntity = new BaseFileEntity(); fileEntity.FileName = fileName; fileEntity.Contents = file; fileEntity.Enabled = 1; fileEntity.ReadCount = 0; fileEntity.FolderId = userInfo.Id + "_Send_" + toUserId; // 把修改人显示出来 fileEntity.ModifiedBy = userInfo.RealName; fileEntity.ModifiedUserId = userInfo.Id; fileEntity.ModifiedOn = DateTime.Now; BaseFileManager fileManager = new BaseFileManager(dbHelper, userInfo); fileManager.AddEntity(fileEntity); fileEntity.FolderId = toUserId + "_Receive_" + userInfo.Id; returnValue = fileManager.AddEntity(fileEntity); // string webHostUrl = BaseSystemInfo.WebHostUrl; // if (string.IsNullOrEmpty(webHostUrl)) // { // webHostUrl = "WebHostUrl"; // } // 10:应该还发一个短信提醒一下才对。 BaseMessageEntity messageEntity = new BaseMessageEntity(); messageEntity.Id = Guid.NewGuid().ToString(); messageEntity.CategoryCode = MessageCategory.Send.ToString(); messageEntity.FunctionCode = MessageFunction.Message.ToString(); messageEntity.ObjectId = returnValue; messageEntity.ReceiverId = toUserId; // target=\"_blank\" messageEntity.Contents = AppMessage.FileService_SendFileFrom + " <a href={WebHostUrl}Download.aspx?Id=" + returnValue + ">" + fileName + "</a>" + AppMessage.FileService_CheckReceiveFile; messageEntity.IsNew = (int)MessageStateCode.New; messageEntity.ReadCount = 0; messageEntity.DeletionStateCode = 0; messageEntity.Enabled = 1; BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); returnValue = messageManager.Add(messageEntity); } BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return returnValue; }