Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            label11.Text = "";

            string   keyword    = textBox2.Text.Trim();     //关键词
            string   copyWriter = richTextBox1.Text.Trim(); //文案
            DateTime startTime  = dateTimePicker3.Value.Date;
            DateTime endTime    = dateTimePicker4.Value.Date;

            if (keyword.Equals(""))
            {
                label11.Text = "错误:关键词不得为空";
                return;
            }
            else if (startTime >= endTime)
            {
                label11.Text = "错误:请确保:开始时间 < 结束时间";
                return;
            }
            // 测试
            //Console.WriteLine(keyword + " " + filter + " " + copyWriter + " " + startTime.ToString() + " " + endTime.ToString() );

            Activity activity = new Activity();

            activity.KeyWord   = keyword;    //关键词
            activity.CopyWrite = copyWriter; //文案
            activity.BeginTime = startTime;
            activity.EndTime   = endTime;

            //黑名单内所有id
            activity.AddBlockedParticipant("1000008");
            activity.AddBlockedParticipant("10000");
            activity.AddBlockedParticipant("80000008");
            activity.AddBlockedParticipant("215757537");
            activity.AddBlockedParticipant("825561994");

            int dataLine1 = dataGridView1.RowCount - 1;

            for (int i = 0; i < dataLine1; i++)
            {
                string id = dataGridView1.Rows[i].Cells[0].Value.ToString();//id
                //Console.WriteLine(id);
                //黑名单置入
                activity.AddBlockedParticipant(id);
            }
            try
            {
                //奖项爬取  奖励名,奖品信息 人数,你们自己封装成数据结构吧
                int dataLine2 = dataGridView2.RowCount - 1;
                for (int i = 0; i < dataLine2; i++)
                {
                    string awardName    = dataGridView2.Rows[i].Cells[0].Value.ToString();       //奖励名
                    string awardMessage = dataGridView2.Rows[i].Cells[1].Value.ToString();       //奖品
                    int    count        = Convert.ToInt32(dataGridView2.Rows[i].Cells[2].Value); //人数
                    Award  award        = new Award(awardName, awardMessage, count);
                    //奖励名单置入
                    activity.AddAward(award);
                }
                //往活动管理中添加活动
                if (!activityManager.AddActivity(activity))
                {
                    label11.Text = "错误:在此时间段已有相同关键词活动存在";
                    return;
                }
                MessageBox.Show("新增成功");
            }
            catch (FormatException err)
            {
                Console.WriteLine(err.Message);
                label11.Text = "错误:人数应为整数,请重新输入";
                return;
                //转换int的异常
            }
            catch (Exception err)
            {
                label11.Text = "错误:未知来源,请联系我们团队:[email protected]";
                Console.WriteLine(err.Message);
                return;
            }
        }
Example #2
0
 /// <summary>
 /// 给活动添加奖项
 /// </summary>
 /// <param name="award">要添加的奖项</param>
 public void AddAward(Award award)
 {
     awardList.Add(award);
 }