• 章节:26
  • 访问:615
  • 时长:00:07:42
  • 日期:2020-01-09 09:19
DROP TABLE IF EXISTS `templatemessage`;
CREATE TABLE `templatemessage` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `touser` varchar(255) DEFAULT NULL,
  `template_id` varchar(255) DEFAULT NULL,
  `url` varchar(255) DEFAULT NULL,
  `first` varchar(255) DEFAULT NULL,
  `first_color` varchar(255) DEFAULT NULL,
  `remark` varchar(255) DEFAULT NULL,
  `remark_color` varchar(255) DEFAULT NULL,
  `keyword1` varchar(255) DEFAULT NULL,
  `keyword1_color` varchar(255) DEFAULT NULL,
  `keyword2` varchar(255) DEFAULT NULL,
  `keyword2_color` varchar(255) DEFAULT NULL,
  `keyword3` varchar(255) DEFAULT NULL,
  `keyword3_color` varchar(255) DEFAULT NULL,
  `keyword4` varchar(255) DEFAULT NULL,
  `keyword4_color` varchar(255) DEFAULT NULL,
  `keyword5` varchar(255) DEFAULT NULL,
  `keyword5_color` varchar(255) DEFAULT NULL,
  `keyword6` varchar(255) DEFAULT NULL,
  `keyword6_color` varchar(255) DEFAULT NULL,
  `keyword7` varchar(255) DEFAULT NULL,
  `keyword7_color` varchar(255) DEFAULT NULL,
  `keyword8` varchar(255) DEFAULT NULL,
  `keyword8_color` varchar(255) DEFAULT NULL,
  `keyword9` varchar(255) DEFAULT NULL,
  `keyword9_color` varchar(255) DEFAULT NULL,
  `addtime` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8;
DROP TRIGGER IF EXISTS `delt`;
DELIMITER ;;
CREATE TRIGGER `delt` AFTER DELETE ON `templatemessage` FOR EACH ROW INSERT INTO templatemessagehistory(  oldid,
  touser,
  template_id,
  url,
  first,
  first_color,
  remark,
  remark_color,
  keyword1,
  keyword1_color,
  keyword2,
  keyword2_color,
  keyword3,
  keyword3_color,
  keyword4,
  keyword4_color,
  keyword5,
  keyword5_color,
  keyword6,
  keyword6_color,
  keyword7,
  keyword7_color,
  keyword8,
  keyword8_color,
  keyword9,
  keyword9_color,
  oldaddtime,
  addtime
) VALUES ( old.id,
  old.touser,
  old.template_id,
  old.url,
  old.first,
  old.first_color,
  old.remark,
  old.remark_color,
  old.keyword1,
  old.keyword1_color,
  old.keyword2,
  old.keyword2_color,
  old.keyword3,
  old.keyword3_color,
  old.keyword4,
  old.keyword4_color,
  old.keyword5,
  old.keyword5_color,
  old.keyword6,
  old.keyword6_color,
  old.keyword7,
  old.keyword7_color,
  old.keyword8,
  old.keyword8_color,
  old.keyword9,
  old.keyword9_color,
  old.addtime, now())
;;
DELIMITER ;

添加一张历史表

DROP TABLE IF EXISTS `templatemessagehistory`;
CREATE TABLE `templatemessagehistory` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `oldid` int(11) DEFAULT NULL,
  `touser` varchar(255) DEFAULT NULL,
  `template_id` varchar(255) DEFAULT NULL,
  `url` varchar(255) DEFAULT NULL,
  `first` varchar(255) DEFAULT NULL,
  `first_color` varchar(255) DEFAULT NULL,
  `remark` varchar(255) DEFAULT NULL,
  `remark_color` varchar(255) DEFAULT NULL,
  `keyword1` varchar(255) DEFAULT NULL,
  `keyword1_color` varchar(255) DEFAULT NULL,
  `keyword2` varchar(255) DEFAULT NULL,
  `keyword2_color` varchar(255) DEFAULT NULL,
  `keyword3` varchar(255) DEFAULT NULL,
  `keyword3_color` varchar(255) DEFAULT NULL,
  `keyword4` varchar(255) DEFAULT NULL,
  `keyword4_color` varchar(255) DEFAULT NULL,
  `keyword5` varchar(255) DEFAULT NULL,
  `keyword5_color` varchar(255) DEFAULT NULL,
  `keyword6` varchar(255) DEFAULT NULL,
  `keyword6_color` varchar(255) DEFAULT NULL,
  `keyword7` varchar(255) DEFAULT NULL,
  `keyword7_color` varchar(255) DEFAULT NULL,
  `keyword8` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT '',
  `keyword8_color` varchar(255) DEFAULT NULL,
  `keyword9` varchar(255) DEFAULT NULL,
  `keyword9_color` varchar(255) DEFAULT NULL,
  `oldaddtime` datetime DEFAULT NULL,
  `addtime` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8;

增加 TemplateSend.xaml 页面

<Page x:Class="WeixinManager.TemplateSend"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:WeixinManager"
      mc:Ignorable="d" 
      d:DesignHeight="450" d:DesignWidth="800"
      Title="模板消息">
    <Page.Resources>
        <Style TargetType="Label">
            <Setter Property="Width" Value="120"/>
        </Style>
    </Page.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition  Height="40"/>
                <RowDefinition  Height="40"/>
                <RowDefinition  Height="40"/>
                <RowDefinition  Height="40"/>
                <RowDefinition  Height="40"/>
                <RowDefinition  Height="40"/>
                <RowDefinition  Height="40"/>
                <RowDefinition  Height="40"/>
                <RowDefinition  Height="40"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="450"/>
                <ColumnDefinition Width="450"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0">
                <Label Content="模板ID" VerticalAlignment="Center"/>
                <TextBox Name="tbTemplateID" Width="300" Height="30" Text="coA2OijGsDxN3b2i48D0vaPLd5BraRQnDYcJ8MazzAc" VerticalContentAlignment="Center"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="1">
                <Label Content="链接" VerticalAlignment="Center"/>
                <TextBox Name="tbUrl" Width="300" Height="30" Text="http://www.linkfair.com.cn/"  VerticalContentAlignment="Center"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="0">
                <Label Content="用户OPENID" VerticalAlignment="Center"/>
                <TextBox Name="tbOpenID" Width="300" Height="30" Text="oEuos1IXm0JJPyUD6G3GwzBOOifg"  VerticalContentAlignment="Center"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="1">
                <Label Content="标题" VerticalAlignment="Center"/>
                <TextBox Name="tbFirst" Width="300" Height="30" Text="测试内容的标题"  VerticalContentAlignment="Center"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="0">
                <Label Content="描述" VerticalAlignment="Center"/>
                <TextBox Name="tbRemark" Width="300" Height="30" Text="描述描述描述"  VerticalContentAlignment="Center"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1">
                <Label Content="关键字1" VerticalAlignment="Center"/>
                <TextBox Name="tbKeyWord1" Width="300" Height="30"  VerticalContentAlignment="Center"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="0">
                <Label Content="关键字2" VerticalAlignment="Center"/>
                <TextBox Name="tbKeyWord2" Width="300" Height="30"  VerticalContentAlignment="Center"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="1">
                <Label Content="关键字3" VerticalAlignment="Center"/>
                <TextBox Name="tbKeyWord3" Width="300" Height="30"  VerticalContentAlignment="Center"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="0">
                <Label Content="关键字4" VerticalAlignment="Center"/>
                <TextBox  Name="tbKeyWord4" Width="300" Height="30"  VerticalContentAlignment="Center"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="4" Grid.Column="1">
                <Label Content="关键字5" VerticalAlignment="Center"/>
                <TextBox Name="tbKeyWord5" Width="300" Height="30"  VerticalContentAlignment="Center"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="5" Grid.Column="0">
                <Label Content="关键字6" VerticalAlignment="Center"/>
                <TextBox Name="tbKeyWord6" Width="300" Height="30"  VerticalContentAlignment="Center"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="5" Grid.Column="1">
                <Label Content="关键字7" VerticalAlignment="Center"/>
                <TextBox Name="tbKeyWord7" Width="300" Height="30"  VerticalContentAlignment="Center"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="0">
                <Label Content="关键字8" VerticalAlignment="Center"/>
                <TextBox Name="tbKeyWord8" Width="300" Height="30"  VerticalContentAlignment="Center"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal" Grid.Row="6" Grid.Column="1">
                <Label Content="关键字9" VerticalAlignment="Center"/>
                <TextBox Name="tbKeyWord9" Width="300" Height="30"  VerticalContentAlignment="Center"/>
            </StackPanel>
            <Button Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="2" Width="120" Height="30" HorizontalAlignment="Left" Click="Button_Click">加入发送队列</Button>
        </Grid>
    </Grid>
</Page>
public partial class TemplateSend : Page
    {
        public TemplateSend()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            using (var db = SugarDao.GetInstance())
            {
                var id = db.Insert(new TemplateMessage() {
                    touser = this.tbOpenID.Text,
                    first = this.tbFirst.Text,
                    remark = this.tbRemark.Text,
                    url = this.tbUrl.Text,
                    template_id = this.tbTemplateID.Text,
                    keyword1 = this.tbKeyWord1.Text,
                    keyword2 = this.tbKeyWord2.Text,
                    keyword3 = this.tbKeyWord3.Text,
                    keyword4 = this.tbKeyWord4.Text,
                    keyword5 = this.tbKeyWord5.Text,
                    keyword6 = this.tbKeyWord6.Text,
                    keyword7 = this.tbKeyWord7.Text,
                    keyword8 = this.tbKeyWord8.Text,
                    keyword9 = this.tbKeyWord9.Text,
                    addtime = DateTime.Now
                });
                bool res = Convert.ToBoolean(id);
                if (res)
                {
                    MessageBox.Show("保存成功");
                }
                else
                {
                    MessageBox.Show("保存失败");
                }
            }
        }
    }

clipboard.png