// Load all message templates. private void LoadAllMessageTemplates() { DataTable dtTemplates = MessageTemplateDAL.GetAllMessageTemplates(); foreach (DataRow dr in dtTemplates.Rows) { int templateId = StringUtil.GetSafeInt(dr["TemplateId"]); int templateCategoryId = StringUtil.GetSafeInt(dr["TemplateCategoryId"]); String templateName = StringUtil.GetSafeString(dr["TemplateName"]); String templateContent = StringUtil.GetSafeString(dr["TemplateContent"]); MessageTemplateType templateType = new MessageTemplateType(); templateType.TemplateId = templateId; templateType.TemplateName = templateName; templateType.TemplateCategoryId = templateCategoryId; templateType.TemplateContent = templateContent; TreeNode newNode = new TreeNode(); newNode.Tag = templateType; newNode.Text = templateName; newNode.Name = templateId.ToString(); // Find the category node. TreeNode[] categoryNodes = treeViewMessageTemplate.Nodes.Find(templateCategoryId.ToString(), false); if (categoryNodes.Length == 1) { categoryNodes[0].Nodes.Add(newNode); categoryNodes[0].ExpandAll(); } } }
private void tvMessageTemplates_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode node = this.tvMessageTemplates.SelectedNode; if (node == null) { return; } if (node.Tag == null) { return; } if (node.Tag.GetType() != typeof(MessageTemplateType)) { return; } MessageTemplateType messageTemplate = (MessageTemplateType)node.Tag; if (messageTemplate == null) { return; } String replacedMsg = replaceMessageMacros(messageTemplate.TemplateContent, mTransaction); this.rtbMessageToSend.Text = replacedMsg; }
// Invoked when user right click one message template and chose to delete that message template. private void ToolStripMenuItemDelMessageTemplate_Click(object sender, EventArgs e) { TreeNode node = treeViewMessageTemplate.SelectedNode; if (node == null) { return; } if (node.Tag == null) { return; } if (node.Tag.GetType() != typeof(MessageTemplateType)) { return; } MessageTemplateType messageTemplate = (MessageTemplateType)node.Tag; if (messageTemplate == null) { return; } MessageTemplateDAL.DeleteOneMessageTemplate(messageTemplate.TemplateId); // Find the category node. TreeNode[] categoryNodes = treeViewMessageTemplate.Nodes.Find(messageTemplate.TemplateCategoryId.ToString(), false); if (categoryNodes.Length > 0) { categoryNodes[0].Nodes.Remove(node); } }
private void treeViewMessageTemplates_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode node = this.treeViewMessageTemplates.SelectedNode; if (node == null) { return; } if (node.Tag == null) { return; } if (node.Tag.GetType() != typeof(MessageTemplateType)) { return; } MessageTemplateType messageTemplate = (MessageTemplateType)node.Tag; if (messageTemplate == null) { return; } this.richTextBoxMessageToSend.Text = messageTemplate.TemplateContent; }
// Insert one message template. public static bool InsertOneMessageTemplate(MessageTemplateType messageTemplate, out int newTemplateId) { newTemplateId = 0; IDbCommand cmd = DataFactory.CreateCommand(null); cmd.CommandText = @"Insert into [MessageTemplate] (TemplateCategoryId, TemplateName, TemplateContent) values (@TemplateCategoryId, @TemplateName, @TemplateContent)"; DataFactory.AddCommandParam(cmd, "@TemplateCategoryId", DbType.Int32, messageTemplate.TemplateCategoryId); DataFactory.AddCommandParam(cmd, "@TemplateName", DbType.String, StringUtil.GetSafeString(messageTemplate.TemplateName)); DataFactory.AddCommandParam(cmd, "@TemplateContent", DbType.String, StringUtil.GetSafeString(messageTemplate.TemplateContent)); bool result = DataFactory.ExecuteInsertCommand(cmd, out newTemplateId); return result; }
public static bool ModifyOneMessageTemplate(MessageTemplateType messageTemplate) { IDbCommand cmd = DataFactory.CreateCommand(null); cmd.CommandText = @"Update [MessageTemplate] set TemplateCategoryId=@TemplateCategoryId, TemplateName=@TemplateName, TemplateContent=@TemplateContent where TemplateId=@TemplateId"; DataFactory.AddCommandParam(cmd, "@TemplateCategoryId", DbType.Int32, messageTemplate.TemplateCategoryId); DataFactory.AddCommandParam(cmd, "@TemplateName", DbType.String, StringUtil.GetSafeString(messageTemplate.TemplateName)); DataFactory.AddCommandParam(cmd, "@TemplateContent", DbType.String, StringUtil.GetSafeString(messageTemplate.TemplateContent)); DataFactory.AddCommandParam(cmd, "@TemplateId", DbType.Int32, StringUtil.GetSafeInt(messageTemplate.TemplateId)); bool result = DataFactory.ExecuteCommandNonQuery(cmd); return(result); }
// Insert one message template. public static bool InsertOneMessageTemplate(MessageTemplateType messageTemplate, out int newTemplateId) { newTemplateId = 0; IDbCommand cmd = DataFactory.CreateCommand(null); cmd.CommandText = @"Insert into [MessageTemplate] (TemplateCategoryId, TemplateName, TemplateContent) values (@TemplateCategoryId, @TemplateName, @TemplateContent)"; DataFactory.AddCommandParam(cmd, "@TemplateCategoryId", DbType.Int32, messageTemplate.TemplateCategoryId); DataFactory.AddCommandParam(cmd, "@TemplateName", DbType.String, StringUtil.GetSafeString(messageTemplate.TemplateName)); DataFactory.AddCommandParam(cmd, "@TemplateContent", DbType.String, StringUtil.GetSafeString(messageTemplate.TemplateContent)); bool result = DataFactory.ExecuteInsertCommand(cmd, out newTemplateId); return(result); }
private void LoadAllMessageTemplates() { this.tvMessageTemplates.Nodes.Clear(); DataTable dtMessageCategories = MessageTemplateCategoryDAL.GetAllMessageTemplateCategories(); DataTable dtMessageTemplates = MessageTemplateDAL.GetAllMessageTemplates(); foreach (DataRow drCategory in dtMessageCategories.Rows) { int categoryId = StringUtil.GetSafeInt(drCategory["CategoryId"]); String categoryName = StringUtil.GetSafeString(drCategory["CategoryName"]); MessageTemplateCategoryType catType = new MessageTemplateCategoryType(); TreeNode catNode = new TreeNode(); catNode.Tag = catType; catNode.Text = categoryName; catNode.Name = categoryId.ToString(); this.tvMessageTemplates.Nodes.Add(catNode); } foreach (DataRow drMessageTemplate in dtMessageTemplates.Rows) { int templateId = StringUtil.GetSafeInt(drMessageTemplate["TemplateId"]); int categoryId = StringUtil.GetSafeInt(drMessageTemplate["TemplateCategoryId"]); String templateName = StringUtil.GetSafeString(drMessageTemplate["TemplateName"]); String templateContent = StringUtil.GetSafeString(drMessageTemplate["TemplateContent"]); MessageTemplateType templateType = new MessageTemplateType(); templateType.TemplateId = templateId; templateType.TemplateCategoryId = categoryId; templateType.TemplateName = templateName; templateType.TemplateContent = templateContent; TreeNode msgNode = new TreeNode(); msgNode.Tag = templateType; msgNode.Text = templateName; TreeNode[] catNodes = this.tvMessageTemplates.Nodes.Find(categoryId.ToString(), false); if (catNodes.Length > 0) { catNodes[0].Nodes.Add(msgNode); } } this.tvMessageTemplates.ExpandAll(); }
public static MessageTemplateType GetMessageTemplate(int parentCategoryId, String templateName) { String sql_getTemplate = String.Format("select * from [MessageTemplate] where TemplateCategoryId={0} and TemplateName='{1}'", parentCategoryId, templateName); DataTable dt = DataFactory.ExecuteSqlReturnTable(sql_getTemplate); if (dt.Rows.Count == 0) return null; DataRow dr = dt.Rows[0]; MessageTemplateType templateType = new MessageTemplateType(); templateType.TemplateCategoryId = StringUtil.GetSafeInt(dr["TemplateCategoryId"]); templateType.TemplateName = StringUtil.GetSafeString(dr["TemplateName"]); templateType.TemplateContent = StringUtil.GetSafeString(dr["TemplateContent"]); return templateType; }
} // treeViewMessageTemplate_AfterSelect private void buttonModifyMessageTemplate_Click(object sender, EventArgs e) { TreeNode node = treeViewMessageTemplate.SelectedNode; if (node == null) { return; } if (node.Tag == null) { return; } if (node.Tag.GetType() != typeof(MessageTemplateType)) { return; } MessageTemplateType messageTemplate = (MessageTemplateType)node.Tag; if (messageTemplate == null) { return; } this.buttonModifyMessageTemplate.Enabled = false; int templateId = messageTemplate.TemplateId; int templateCategoryId = messageTemplate.TemplateCategoryId; String templateName = StringUtil.GetSafeString(this.textBoxMessageTemplateName.Text); String templateContent = StringUtil.GetSafeString(this.richTextBoxMessageTemplateContent.Text); messageTemplate.TemplateName = templateName; messageTemplate.TemplateContent = templateContent; MessageTemplateDAL.ModifyOneMessageTemplate(messageTemplate); MessageBox.Show("成功修改消息模板!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); this.buttonModifyMessageTemplate.Enabled = true; }
// When user selects one of the node in the treeview. private void treeViewMessageTemplate_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode node = treeViewMessageTemplate.SelectedNode; if (node == null) { return; } if (node.Tag == null) { return; } if (typeof(MessageTemplateType) == node.Tag.GetType()) { MessageTemplateType messageTemplate = (MessageTemplateType)node.Tag; if (messageTemplate == null) { return; } this.textBoxMessageTemplateName.Text = StringUtil.GetSafeString(messageTemplate.TemplateName); this.richTextBoxMessageTemplateContent.Text = StringUtil.GetSafeString(messageTemplate.TemplateContent); this.buttonAddMessageTemplate.Enabled = false; this.buttonModifyMessageTemplate.Enabled = true; } else if (typeof(MessageTemplateCategoryType) == node.Tag.GetType()) { MessageTemplateCategoryType messageCategoryType = (MessageTemplateCategoryType)node.Tag; if (messageCategoryType == null) { return; } this.textBoxMessageTemplateName.Text = ""; this.richTextBoxMessageTemplateContent.Text = ""; this.buttonAddMessageTemplate.Enabled = true; this.buttonModifyMessageTemplate.Enabled = false; } } // treeViewMessageTemplate_AfterSelect
public static MessageTemplateType GetMessageTemplate(int parentCategoryId, String templateName) { String sql_getTemplate = String.Format("select * from [MessageTemplate] where TemplateCategoryId={0} and TemplateName='{1}'", parentCategoryId, templateName); DataTable dt = DataFactory.ExecuteSqlReturnTable(sql_getTemplate); if (dt.Rows.Count == 0) { return(null); } DataRow dr = dt.Rows[0]; MessageTemplateType templateType = new MessageTemplateType(); templateType.TemplateCategoryId = StringUtil.GetSafeInt(dr["TemplateCategoryId"]); templateType.TemplateName = StringUtil.GetSafeString(dr["TemplateName"]); templateType.TemplateContent = StringUtil.GetSafeString(dr["TemplateContent"]); return(templateType); }
// Add message template button handler. private void buttonAddMessageTemplate_Click(object sender, EventArgs e) { int categoryId = -1; { if (treeViewMessageTemplate.SelectedNode == null) { return; } MessageTemplateCategoryType categoryType = (MessageTemplateCategoryType)treeViewMessageTemplate.SelectedNode.Tag; if (categoryType == null) { return; } categoryId = categoryType.CategoryId; } if (categoryId < 0) { return; } String templateName = this.textBoxMessageTemplateName.Text.Trim(); if (templateName == null || templateName == "") { MessageBox.Show("消息模板名称不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.buttonAddMessageTemplate.Enabled = false; // Whether we have already added one message template with the same name. MessageTemplateType existedMessagetTemplateType = MessageTemplateDAL.GetMessageTemplate(categoryId, templateName); if (existedMessagetTemplateType != null) { MessageBox.Show("已存在此消息模板名,请输入不同消息模板名称!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); this.buttonAddMessageTemplate.Enabled = true; return; } String templateContent = this.richTextBoxMessageTemplateContent.Text.Trim(); if (templateContent == null || templateContent.Trim() == "") { MessageBox.Show("消息模板正文不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); this.buttonAddMessageTemplate.Enabled = true; return; } MessageTemplateType templateType = new MessageTemplateType(); templateType.TemplateName = templateName; templateType.TemplateContent = templateContent; templateType.TemplateCategoryId = categoryId; int newTemplateId = 0; MessageTemplateDAL.InsertOneMessageTemplate(templateType, out newTemplateId); TreeNode newNode = new TreeNode(); newNode.Text = templateName; newNode.Tag = templateType; treeViewMessageTemplate.SelectedNode.Nodes.Add(newNode); treeViewMessageTemplate.SelectedNode.ExpandAll(); MessageBox.Show("成功添加消息模板!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); this.buttonAddMessageTemplate.Enabled = true; }
private void LoadAllMessageTemplates() { this.treeViewMessageTemplates.Nodes.Clear(); DataTable dtMessageCategories = MessageTemplateCategoryDAL.GetAllMessageTemplateCategories(); DataTable dtMessageTemplates = MessageTemplateDAL.GetAllMessageTemplates(); foreach (DataRow drCategory in dtMessageCategories.Rows) { int categoryId = StringUtil.GetSafeInt(drCategory["CategoryId"]); String categoryName = StringUtil.GetSafeString(drCategory["CategoryName"]); MessageTemplateCategoryType catType = new MessageTemplateCategoryType(); TreeNode catNode = new TreeNode(); catNode.Tag = catType; catNode.Text = categoryName; catNode.Name = categoryId.ToString(); this.treeViewMessageTemplates.Nodes.Add(catNode); } foreach (DataRow drMessageTemplate in dtMessageTemplates.Rows) { int templateId = StringUtil.GetSafeInt(drMessageTemplate["TemplateId"]); int categoryId = StringUtil.GetSafeInt(drMessageTemplate["TemplateCategoryId"]); String templateName = StringUtil.GetSafeString(drMessageTemplate["TemplateName"]); String templateContent = StringUtil.GetSafeString(drMessageTemplate["TemplateContent"]); MessageTemplateType templateType = new MessageTemplateType(); templateType.TemplateId = templateId; templateType.TemplateCategoryId = categoryId; templateType.TemplateName = templateName; templateType.TemplateContent = templateContent; TreeNode msgNode = new TreeNode(); msgNode.Tag = templateType; msgNode.Text = templateName; TreeNode[] catNodes = this.treeViewMessageTemplates.Nodes.Find(categoryId.ToString(), false); if (catNodes.Length > 0) catNodes[0].Nodes.Add(msgNode); } this.treeViewMessageTemplates.ExpandAll(); }
// Add message template button handler. private void buttonAddMessageTemplate_Click(object sender, EventArgs e) { int categoryId = -1; { if (treeViewMessageTemplate.SelectedNode == null) return; MessageTemplateCategoryType categoryType = (MessageTemplateCategoryType)treeViewMessageTemplate.SelectedNode.Tag; if (categoryType == null) return; categoryId = categoryType.CategoryId; } if (categoryId < 0) return; String templateName = this.textBoxMessageTemplateName.Text.Trim(); if (templateName == null || templateName == "") { MessageBox.Show("消息模板名称不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.buttonAddMessageTemplate.Enabled = false; // Whether we have already added one message template with the same name. MessageTemplateType existedMessagetTemplateType = MessageTemplateDAL.GetMessageTemplate(categoryId, templateName); if (existedMessagetTemplateType != null) { MessageBox.Show("已存在此消息模板名,请输入不同消息模板名称!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); this.buttonAddMessageTemplate.Enabled = true; return; } String templateContent = this.richTextBoxMessageTemplateContent.Text.Trim(); if (templateContent == null || templateContent.Trim() == "") { MessageBox.Show("消息模板正文不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); this.buttonAddMessageTemplate.Enabled = true; return; } MessageTemplateType templateType = new MessageTemplateType(); templateType.TemplateName = templateName; templateType.TemplateContent = templateContent; templateType.TemplateCategoryId = categoryId; int newTemplateId = 0; MessageTemplateDAL.InsertOneMessageTemplate(templateType, out newTemplateId); TreeNode newNode = new TreeNode(); newNode.Text = templateName; newNode.Tag = templateType; treeViewMessageTemplate.SelectedNode.Nodes.Add(newNode); treeViewMessageTemplate.SelectedNode.ExpandAll(); MessageBox.Show("成功添加消息模板!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information); this.buttonAddMessageTemplate.Enabled = true; }
public static bool ModifyOneMessageTemplate(MessageTemplateType messageTemplate) { IDbCommand cmd = DataFactory.CreateCommand(null); cmd.CommandText = @"Update [MessageTemplate] set TemplateCategoryId=@TemplateCategoryId, TemplateName=@TemplateName, TemplateContent=@TemplateContent where TemplateId=@TemplateId"; DataFactory.AddCommandParam(cmd, "@TemplateCategoryId", DbType.Int32, messageTemplate.TemplateCategoryId); DataFactory.AddCommandParam(cmd, "@TemplateName", DbType.String, StringUtil.GetSafeString(messageTemplate.TemplateName)); DataFactory.AddCommandParam(cmd, "@TemplateContent", DbType.String, StringUtil.GetSafeString(messageTemplate.TemplateContent)); DataFactory.AddCommandParam(cmd, "@TemplateId", DbType.Int32, StringUtil.GetSafeInt(messageTemplate.TemplateId)); bool result = DataFactory.ExecuteCommandNonQuery(cmd); return result; }