基本信息
源码名称:wpf 抽奖 程序源码下载
源码大小:11.14M
文件格式:.zip
开发语言:C#
更新时间:2015-12-25
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
using System.Windows.Threading;
namespace WpfCJ
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
protected List<Person> persons = new List<Person>();
private DispatcherTimer timer = new DispatcherTimer();
private DispatcherTimer timer2 = new DispatcherTimer();
private int index = 0;
#region NP
string[] np = new string[] { "12", "15", "23" };
#endregion
public Window1()
{
InitializeComponent();
InitData();
timer.Tick = new EventHandler(timer_Tick);
timer.Interval = TimeSpan.FromSeconds(0.03);
timer2.Tick = new EventHandler(timer2_Tick);
timer2.Interval = TimeSpan.FromSeconds(0.0001);
btnStart.Focus();
}
void timer_Tick(object sender, EventArgs e)
{
if (index == persons.Count)
index = 0;
ShowName(persons, index);
index ;
}
void timer2_Tick(object sender, EventArgs e)
{
if (index == persons.Count)
index = 0;
ShowName(persons, index);
if (!CheckIn(lblNameShow.Content.ToString()) && !persons.Find(delegate(Person toFind) { return toFind.Name == lblNameShow.Content.ToString(); }).Check)
{
timer2.Stop();
persons.Find(delegate(Person toFind) { return toFind.Name == lblNameShow.Content.ToString(); }).Check = true;
}
else
timer2.Stop();
index ;
}
protected void InitData()
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load("Data.xml");
XmlElement root = xdoc.DocumentElement;
foreach (XmlNode temp in root.ChildNodes)
{
Person tempPerson = new Person();
tempPerson.Name = temp.FirstChild.Value;
persons.Add(tempPerson);
}
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
persons = RandomSortList<Person>(persons);
timer.Start();
btnStart.Visibility = Visibility.Hidden;
btnStop.Visibility = Visibility.Visible;
btnStop.Focus();
}
private void btnStop_Click(object sender, RoutedEventArgs e)
{
if (CheckIn(lblNameShow.Content.ToString()) || persons.Find(delegate(Person toFind) { return toFind.Name == lblNameShow.Content.ToString(); }).Check)
{
timer.Stop();
timer2.Start();
}
else
{
timer.Stop();
//persons.Find(delegate(Person toFind) { return toFind.Name == lblNameShow.Content.ToString(); }).Check = true;
persons.Find(p => p.Name == lblNameShow.Content.ToString()).Check = true;
}
btnStart.Visibility = Visibility.Visible;
btnStop.Visibility = Visibility.Hidden;
btnStart.Focus();
}
protected bool CheckIn(string name)
{
bool result = false;
for (int i = 0; i < 3; i )
{
if (np[i].ToString() == name)
result = true;
}
return result;
}
//51aspx.com 下载
protected void RemovePerson()
{
Person temp = new Person();
temp.Name = lblNameShow.Content.ToString();
persons.Remove(temp);
}
/// <summary>
/// 对List进行随机排序
/// </summary>
/// <param name="ListT"></param>
/// <returns></returns>
public List<T> RandomSortList<T>(List<T> ListT)
{
Random random = new Random();
List<T> newList = new List<T>();
foreach (T item in ListT)
{
newList.Insert(random.Next(newList.Count 1), item);
}
return newList;
}
public void ShowName(List<Person> toshow, int index)
{
lblNameShow.Content = toshow[index].Name;
}
private void btnStart_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space)
e.Handled = true;
}
private void btnStop_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Space)
e.Handled = true;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
}
public class Person
{
private string _name;
private bool _check = false;
public string Name
{
get { return _name; }
set { this._name = value; }
}
public bool Check
{
get { return _check; }
set { this._check = value; }
}
}
}