精华内容
下载资源
问答
  • C#--作业12:winform摇奖程序的设计与实现
    2020-05-06 19:33:23

    老师要求的是这样的:
    在这里插入图片描述

    using System;
    
    using System.Collections.Generic;
    
    using System.ComponentModel;
    
    using System.Data;
    
    using System.Drawing;
    
    using System.Linq;
    
    using System.Text;
    
    using System.Threading.Tasks;
    
    using System.Windows.Forms;
    
    
    namespace _4._2._2
    
    {
    
        public partial class Form1 : Form
    
        {
    
            public Form1()
    
            {
    
                InitializeComponent();
    
            }
    
    
            private void timer1_Tick(object sender, EventArgs e)
    
            {
    
                Random random = new Random();
    
                label1.Text = random.Next(10).ToString();
    
                label2.Text = random.Next(10).ToString();
    
                label3.Text = random.Next(10).ToString();
    
                label4.Text = random.Next(10).ToString();
    
                label5.Text = random.Next(10).ToString();
    
                label6.Text = random.Next(10).ToString();
    
                label7.Text = random.Next(10).ToString();
    
    
            }
    
    
            private void button1_Click(object sender, EventArgs e)
    
            {
    
                Application.Exit();
    
            }
    
    
            private void button2_Click(object sender, EventArgs e)
    
            {
    
                timer1.Enabled = !timer1.Enabled;
    
            }
    
        }
    
    }
    

    我的是这样的。。因为我觉得这个机器人比老师的那个好看哈哈哈哈哈哈
    在这里插入图片描述

    更多相关内容
  • 这是一个用winform做的抽奖系统,可以用在多种场合的抽奖系统,默认背景默认名字是晚会抽奖系统,可以在界面稍微修改成你想要的样子。抽中的时候,会记录。
  • 抽奖系统 c#源码 拿过来就能用
  • winform自定义抽奖系统

    2015-11-28 21:46:56
    自定义抽奖项目、人员(可作弊),基于SQLite数据库开发,界面可拖动并保存布局。
  • WinForm抽奖箱 v1.0.zip

    2019-07-09 01:51:01
    WinForm实现抽奖的一个小系统,设置了8个Timer定时器,通过Timer控制Label随机显示0~9,根据时间间隔,随机显示结果,适合初学者学习。   注意: 开发环境为Visual Studio 2010
  • WinForm抽奖箱 1.0.rar

    2019-05-23 16:41:32
    WinForm实现抽奖的一个小系统,设置了8个Timer定时器,通过Timer控制Label随机显示0~9,根据时间间隔,随机显示结果,适合初学者学习。 注意: 开发环境为Visual Studio 2010
  • 年会抽奖软件: Q.Q 358189777 C#、 数据库Access; 1、系统启动,自动全屏展示。 2、背景随心切换、 3、快捷键方便自如:  F1:弹出设置界面  F2:查询人员名单、中奖名单  F3:基础人员信息导入  F4...

    年会抽奖软件:

     Q.Q 358189777

    C#、  数据库Access;

    1、系统启动,自动全屏展示。

    2、背景随心切换、

    3、快捷键方便自如:

      F1:弹出设置界面

      F2:查询人员名单、中奖名单

      F3:基础人员信息导入

      F4:查看当前抽奖项目已经抽取的名单

      F5:刷新

      F12:退出系统

      ESC:主界面自动最小化;其他设置界面自动关闭

      Delete:数据重置

    有需要源码,在我的淘宝店下单  https://item.taobao.com/item.htm?id=542768246339 ;

     

     

     

     

     

     

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.OleDb;
    using System.Drawing;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using CJ.Ctrl;
    
    namespace CJ
    {
        public partial class MainFrom : Form
        {
            public MainFrom()
            {
                InitializeComponent();
            }
            /// <summary>
            /// 人员抽奖组块
            /// </summary>
            public static List<UCNum> LstUcnum = new List<UCNum> ();
            public int YgNoLength = 6;//长度,参与人员的代号长度
            public int SX = 0;
            public int SY1 = 0;//抽奖项目框的Y周初始位置
            public int SY2 = 0;//抽奖项目框的Y轴结束位置
            public TextBox tbOtherCJNum = new TextBox();//其他抽奖项目,记录人数。
            public TextBox tbOtherCJNumName = new TextBox(); //其他抽奖项目,抽奖项目名称。
            public GroupBox GBQT = new GroupBox();
            public Image imgStr;//设置抽奖按钮背景图片,开始按钮
            public Image imgEnd;//设置抽奖按钮背景图片,结束按钮
            public int MaxNum = 0;//最大抽奖人数 
            public int SYNumn = 0;
            public   bool IsTrue = true;
            public static List<YG> LstYg = new List<YG>(); 
            public RadioButton RdioOrther = new RadioButton();
            public Label LbDispyCJ = new Label();
            public Button BtntherCJ = new Button();
            //用全局变量中转
            Point mouseLocation; 
            //---------------------------------------------------------------------
            public Prize prize = new Prize();
            public void SetBackgroundImage(string Imagestr,string Mrk)
            {
                if (Mrk == "主页")
                {
                    this.BackgroundImage = Image.FromFile(Imagestr);
                }
                else if (Mrk == "开始")
                {
                    lbbtn.Image = Image.FromFile(Imagestr);
                    imgStr = Image.FromFile(Imagestr);
                }
                else
                {
                    imgEnd = Image.FromFile(Imagestr);
                }
            }
    
             #region =========================================全屏设置================================================  
              [DllImport("user32.dll", EntryPoint = "ShowWindow")]
              public static extern Int32 ShowWindow(Int32 hwnd, Int32 nCmdShow);
              public const Int32 SW_SHOW = 5; public const Int32 SW_HIDE = 0;
      
              [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
              private static extern Int32 SystemParametersInfo(Int32 uAction, Int32 uParam, ref Rectangle lpvParam, Int32 fuWinIni);
              public const Int32 SPIF_UPDATEINIFILE = 0x1;
              public const Int32 SPI_SETWORKAREA = 47;
             public const Int32 SPI_GETWORKAREA = 48;
      
             [DllImport("user32.dll", EntryPoint = "FindWindow")]
             private static extern Int32 FindWindow(string lpClassName, string lpWindowName); 
    
             /// <summary>  
             /// 设置全屏或这取消全屏  
             /// </summary>  
             /// <param name="fullscreen">true:全屏 false:恢复</param>  
             /// <param name="rectOld">设置的时候,此参数返回原始尺寸,恢复时用此参数设置恢复</param>  
             /// <returns>设置结果</returns>  
             public Boolean SetFormFullScreen(Boolean fullscreen)//, ref Rectangle rectOld
             {
                 Rectangle rectOld = Rectangle.Empty;
                 Int32 hwnd = 0;
                 hwnd = FindWindow("Shell_TrayWnd", null);//获取任务栏的句柄
    
                 if (hwnd == 0) return false;
    
                 if (fullscreen)//全屏
                 {
                     ShowWindow(hwnd, SW_HIDE);//隐藏任务栏
    
                     SystemParametersInfo(SPI_GETWORKAREA, 0, ref rectOld, SPIF_UPDATEINIFILE);//get  屏幕范围
                     Rectangle rectFull = Screen.PrimaryScreen.Bounds;//全屏范围
                     SystemParametersInfo(SPI_SETWORKAREA, 0, ref rectFull, SPIF_UPDATEINIFILE);//窗体全屏幕显示
                 }
                 else//还原 
                 {
                     ShowWindow(hwnd, SW_SHOW);//显示任务栏
    
                     SystemParametersInfo(SPI_SETWORKAREA, 0, ref rectOld, SPIF_UPDATEINIFILE);//窗体还原
                 }
                 return true;
             }
             #endregion =========================================全屏设置================================================       
    
             private void MainFrom_Load(object sender, EventArgs e)
             {
                   tbOtherCJNum.TextChanged+=tbOtherCJNum_TextChanged;  //其他抽奖项目,记录人数。
                   tbOtherCJNumName.TextChanged+=tbOtherCJNumName_TextChanged;  //其他抽奖项目,抽奖项目名称。
                   BtntherCJ.Click += BtntherCJ_Click;
                   tbOtherCJNum.KeyPress += tbOtherCJNum_KeyPress;
                 //A.[员工代号],A.[员工名称],A.[部门代号],B.[部门名称],A.[抽奖状态],a.[中奖限制],A.[中奖号],A.[中奖名称]
                 #region ==================================加载所有员工======================================
                 DataTable DtAllYg = ReYg();
                 for (int i = 0; i < DtAllYg.Rows.Count; i++)
                 {
                     YG y = new YG();
                     YG xzy = new YG();
                     y.YG_NO = DtAllYg.Rows[i]["员工代号"].ToString();
                     y.YG_Name = DtAllYg.Rows[i]["员工名称"].ToString();
                     LstYg.Add(y); 
                 }
                 #endregion ==================================加载所有员工======================================
                 BackgroundImageLoad();//背景图片加载
                 #region =====================================全屏设置============================================
                 SetFormFullScreen(true);
                 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                 this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
                 #endregion=====================================全屏设置============================================
                 PrizeLoad();//抽奖项目加载 
                 GetNoLength();//获取人员工号长度
                 lbbtn.Tag = "开始";
             }
    
             void tbOtherCJNum_KeyPress(object sender, KeyPressEventArgs e)
             { 
                 if (e.KeyChar != '\b')//这是允许输入退格键  
                 {
                     if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字  
                     {
                         e.Handled = true;
                     }
                 }
             } 
             /// <summary>
             /// 获取所有参与抽奖的人员信息。
             /// </summary>
             /// <returns></returns>
             public DataTable ReYg()
             {
                 DataTable dt = new DataTable();
                 try
                 {
                     string sql = "SELECT A.[员工代号],A.[员工名称],A.[部门代号],B.[部门名称],A.[抽奖状态],a.[中奖限制],A.[中奖号],A.[中奖名称]  FROM 人员表 as A left join 部门表  as B on A.[部门代号] = B.[部门代号] ;";
                     dt = AccessHelper.DataSet(sql).Tables[0];
                 }
                 catch (Exception ex)
                 {
                 }
                 return dt;
             }
             void tbOtherCJNumName_TextChanged(object sender, EventArgs e)
             {
                 lb项目号.Text = tbOtherCJNumName.Text;
                 lbPrizeTile.Text = tbOtherCJNumName.Text;
             }
             void tbOtherCJNum_TextChanged(object sender, EventArgs e)
             {
                 lb总人数.Text = tbOtherCJNum.Text;            
             }
            /// <summary>
            /// 获取人员工号长度
            /// </summary>
             public void GetNoLength()
             {
                 //MaxNum
                 string sql = "SELECT Num,NumType FROM MaxNum";
                 DataTable dt = AccessHelper.DataSet(sql).Tables[0];
                 for (int i = 0; i < dt.Rows.Count; i++)
                 {
                     if (dt.Rows[i]["NumType"].ToString() == "W")
                     {
                         YgNoLength =Convert.ToInt32(dt.Rows[i]["Num"].ToString());
                     }
                     if (dt.Rows[i]["NumType"].ToString() == "N")
                     {
                         MaxNum =Convert.ToInt32( dt.Rows[i]["Num"].ToString());
                     }
                 }
             }
            /// <summary>
            /// 背景图片加载
            /// </summary>
             public void BackgroundImageLoad()
             {
                 try
                 {
                     string sql0 = "SELECT A.[Path],a.[IType] FROM BackImage AS A";
                     DataTable DtBakImage = AccessHelper.DataSet(sql0).Tables[0];
                     for (int i = 0; i < DtBakImage.Rows.Count; i++)
                     {
                         if (DtBakImage.Rows[i]["IType"].ToString() == "Main")
                         {
                             this.BackgroundImage = Image.FromFile(DtBakImage.Rows[i]["Path"].ToString()); ;
                         }
                         else if (DtBakImage.Rows[i]["IType"].ToString() == "BtnStr")
                         {
                             imgStr = Image.FromFile(DtBakImage.Rows[i]["Path"].ToString());
                             lbbtn.Image = Image.FromFile(DtBakImage.Rows[i]["Path"].ToString()); ;
                         }
                         else if (DtBakImage.Rows[i]["IType"].ToString() == "BtnEnd")
                         {
                             imgEnd = Image.FromFile(DtBakImage.Rows[i]["Path"].ToString());
                         }
                         else if (DtBakImage.Rows[i]["IType"].ToString() == "Title")
                         {
                             LbGSMC.Text = DtBakImage.Rows[i]["Path"].ToString();
                         }
                         else
                         {
                             lb标语.Text = DtBakImage.Rows[i]["Path"].ToString();
                         }
                     }
                 }
                 catch (Exception)
                 {
    
                 }
             }
            /// <summary>
            /// 抽奖项目加载
            /// </summary> 
            public void PrizeLoad()
             { 
                 try
                 {
                     PMeiun.Controls.Clear();
                     int W = this.Width;//当前宽度
                     int H = this.Height;//当前高度
                     int PX = Convert.ToInt32(Math.Floor((H - 400) * 1.0 / 2));
                     PMeiun.Location = new System.Drawing.Point(0, PX); //位置
                     SY1 = PX;//获取并设置抽奖项目Y坐标初始位置
                     SY2 = PX + 400;//获取抽奖项目Y坐标做大范围的坐标
                 }
                 catch (Exception ex)
                 { 
                 }
    
                 try
                 {
                     string sql = "SELECT a.[排序],a.[项目号],a.[奖项名称],a.[中奖人数],a.[限制因素],a.[已经抽取],a.[批次数] FROM 抽奖规则 AS a ORDER BY a.排序 ASC ";
                     DataTable DtCJ = AccessHelper.DataSet(sql).Tables[0];
                     int RH = 0;
                     int RW = 0;
                     if (DtCJ.Rows.Count > 0)
                     {
                         RH = 28;// Convert.ToInt32(Math.Floor(400 * 1.0 / (DtCJ.Rows.Count + 2)));
                         RW = 178;
                         for (int i = 0; i < DtCJ.Rows.Count; i++)
                         {
                             RadioButton rad = new RadioButton();
                             rad.Location = new System.Drawing.Point(8, 5 + RH * i);
                             rad.Size = new System.Drawing.Size(RW, RH - 2);
                             rad.TabIndex = 0;
                             rad.TabStop = true;
                             rad.Text = DtCJ.Rows[i]["中奖人数"] + "人:" + DtCJ.Rows[i]["奖项名称"].ToString();
                             rad.UseVisualStyleBackColor = true;
                             rad.CheckedChanged += rad_CheckedChanged;
                             rad.Tag = DtCJ.Rows[i]["项目号"].ToString();                          
                             this.PMeiun.Controls.Add(rad);
                         }
                         RdioOrther.Location = new System.Drawing.Point(8, 5 + RH * DtCJ.Rows.Count);
                         RdioOrther.Size = new System.Drawing.Size(RW, RH - 1);
                         RdioOrther.TabIndex = 0;
                         RdioOrther.TabStop = true;
                         RdioOrther.Text = "临时加抽";
                         RdioOrther.UseVisualStyleBackColor = true;
                         RdioOrther.CheckedChanged += RdioOrther_CheckedChanged;
                         this.PMeiun.Controls.Add(RdioOrther);
                         //-------------------------------------------------------------------------------
                         GroupBox gb = new GroupBox();
                         gb.BackColor = System.Drawing.Color.Transparent;
                         gb.Location = new System.Drawing.Point(4, RH * (DtCJ.Rows.Count + 1) - 4);
                         gb.Name = "gB";
                         gb.Size = new System.Drawing.Size(170, 130);
                         gb.TabIndex = 7;
                         gb.TabStop = false;
                         gb.Visible = false;
                         GBQT = gb;
                         this.PMeiun.Controls.Add(GBQT);
                         //--------------------------------------------------------------------------------
                         Label lbotherCJ = new Label();
                         lbotherCJ.Text = "抽奖人数";
                         lbotherCJ.AutoSize = true;
                         lbotherCJ.Location = new System.Drawing.Point(10, 40);
                         lbotherCJ.Size = new System.Drawing.Size(32, 12);
                         this.GBQT.Controls.Add(lbotherCJ);
                         tbOtherCJNum.Location = new System.Drawing.Point(62, 35);
                         tbOtherCJNum.Size = new System.Drawing.Size(100, 21);
                         this.GBQT.Controls.Add(tbOtherCJNum);
                         //--------------------------------------------------
                         Label lbotherName = new Label();
                         lbotherName.Text = "奖项名称";
                         lbotherName.AutoSize = true;
                         lbotherName.Location = new System.Drawing.Point(10, 70);
                         lbotherName.Size = new System.Drawing.Size(32, 12);
                         this.GBQT.Controls.Add(lbotherName);
                         tbOtherCJNumName.Location = new System.Drawing.Point(62, 65);
                         tbOtherCJNumName.Size = new System.Drawing.Size(100, 21);
                         tbOtherCJNumName.Text = "加抽奖" + DateTime.Now.ToString("fffff") ;
                         this.GBQT.Controls.Add(tbOtherCJNumName);
                         //
                         BtntherCJ.Text = "保 存";
                         BtntherCJ.Location = new System.Drawing.Point(62, 95);
                         BtntherCJ.Size = new System.Drawing.Size(70, 21);
                         this.GBQT.Controls.Add(BtntherCJ);
                     }
                 }
                 catch (Exception ex)
                 {
                     string xxxx = ex.Message.ToString();
                 } 
             }
    
            /// <summary>
            /// 临时加抽奖,保存按钮
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void BtntherCJ_Click(object sender, EventArgs e)
            {
                try
                {
                    if (Convert.ToInt32(tbOtherCJNum.Text.Trim())==0)
                    {
                        return;
                    }
                    string sql = "";
                    prize.IsidNum = 1;                
                    prize.Name = this.tbOtherCJNumName.Text.Trim();
                    prize.Num = Convert.ToInt32(tbOtherCJNum.Text.Trim());
                    prize.YJNum = 0;
                    prize.YJIsidNum = 0;
                    prize.ThisNum = prize.Num;
                    prize.ReMark = "";
                    sql = "Select  count(1)  From [抽奖规则] as A  Where A.[奖项名称] = '" + prize.Name + "' ";
                    int count = Convert.ToInt32(AccessHelper.DataSet(sql).Tables[0].Rows[0][0]);
                    if (count < 1)
                    {
                        prize.Item = DateTime.Now.ToString("HHmmssffffff");
                        sql = "Select  Max(A.[排序])+1 From [抽奖规则] as A ";
                        prize.ID = Convert.ToInt32(AccessHelper.DataSet(sql).Tables[0].Rows[0][0]);
                        sql = "INSERT INTO  抽奖规则([排序],[项目号],[奖项名称],[中奖人数],[已经抽取],[批次数]) VALUES("
                            + prize.ID + ",'"
                            + prize.Item + "','"
                            + prize.Name + "',"
                            + prize.Num + ",  "
                            + prize.YJNum + ","
                            + prize.IsidNum + ")";
                        AccessHelper.ExecuteSql(sql);
                        lbPrizeTile.Text = prize.Name.ToString();
                    }
                }
                catch (Exception ex)
                {
                     
                }
            }
            /// <summary>
            /// 事先设置好的项目的单选按钮的点击事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void RdioOrther_CheckedChanged(object sender, EventArgs e)
            {
                LstUcnum.Clear();//清空已经抽奖明细
                LstUcnum = new List<UCNum>();
                //------------------------------------------
                panel1.Controls.Clear();
                //------------------------------------------
                tbOtherCJNum.Text="0";// = new TextBox();//其他抽奖项目,记录人数。
                tbOtherCJNumName.Text = "加抽"+">";// new TextBox(); //其他抽奖项目,抽奖项目名称。
                GBQT.Visible = true;
                lbPrizeTile.Text = "加抽奖";
                prize.ReMark = "新添加";
                this.lb项目号.Text = "加抽奖";
                this.lb总人数.Text = "0";
                this.lb总批次.Text = "1";
                this.lb已抽取.Text = "0";
                lb完成批次.Text = "0"; 
            }
            /// <summary>
            /// 未事先设置好的项目的单选按钮的点击事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            void rad_CheckedChanged(object sender, EventArgs e)
            {
                LstUcnum.Clear();//清空已经抽奖明细
                LstUcnum = new List<UCNum>();
                //------------------------------------------
                panel1.Controls.Clear();
                //------------------------------------------
                RadioButton R = (RadioButton)sender;
                GBQT.Visible = false;
                prize = GetCJItem(R.Tag.ToString());           
                this.lb项目号.Text = prize.Name;
                this.lb项目号.Tag = prize.Item;
                this.lb已抽取.Text = prize.YJNum.ToString();
                this.lb总批次.Text = prize.IsidNum.ToString();
                this.lb总人数.Text = prize.Num.ToString();
                lb完成批次.Text = prize.YJIsidNum.ToString();
                if (prize.YJIsidNum != prize.IsidNum)
                {
                    lb抽奖状态.Text = "" + (prize.YJIsidNum).ToString() + "轮抽奖结束";
                    lbPrizeTile.Text = prize.Name+"" + (prize.YJIsidNum).ToString() + "轮抽奖结束";
                }
                else
                {
                    lb抽奖状态.Text = "抽奖结束!";
                     lbPrizeTile.Text = prize.Name+ ":抽奖结束!";
                }           
                if (prize.YJIsidNum == 0)
                {
                    lbPrizeTile.Text = prize.Name+":待抽奖!";
                } 
            }
    
            #region ========================================抽奖四步操作 ========================================
            /// <summary>
            /// 第一步、 获取抽奖人数
            /// </summary>
            /// <param name="item">抽奖号,抽奖项目号</param>
            /// <returns>返回抽奖信息</returns>
            public Prize GetCJItem(string item)
            {
                Prize Pze = new Prize();
                Dictionary<int, int> dic = new Dictionary<int, int>();
                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT    ");
                sb.Append("    A.[排序],A.[项目号],A.[奖项名称],A.[中奖人数],A.[限制因素],A.[已经抽取],A.[批次数]    ");
                sb.Append("FROM [抽奖规则] AS A   ");
                sb.Append("WHERE A.[项目号] = '" + item + "'   ");
                DataTable DtCJNO = AccessHelper.DataSet(sb.ToString()).Tables[0];
                sb.Clear();
                sb.Append("SELECT     COUNT(1) FROM  [中奖人员] AS A  WHERE A.[中奖号] =  '" + item + "'    ");
                //抽奖人数
                int Count = Convert.ToInt32(AccessHelper.DataSet(sb.ToString()).Tables[0].Rows[0][0]);
                sb.Clear();
                string 奖项名称 = (DtCJNO.Rows[0]["奖项名称"] == null) ? "" : DtCJNO.Rows[0]["奖项名称"].ToString().Trim();
                int 中奖人数 = (DtCJNO.Rows[0]["中奖人数"] == null) ? 0 : Convert.ToInt32(DtCJNO.Rows[0]["中奖人数"].ToString().Trim());
                int 已经抽取 = (DtCJNO.Rows[0]["已经抽取"] == null) ? 0 : Convert.ToInt32(DtCJNO.Rows[0]["已经抽取"].ToString().Trim());
                int 批次数 = (DtCJNO.Rows[0]["批次数"] == null) ? 0 : Convert.ToInt32(DtCJNO.Rows[0]["批次数"].ToString().Trim());
                //、、----------------------------------------------------------
                int 已抽奖批数 = 0;
                int _MaxNum = Convert.ToInt32(Math.Floor(中奖人数 * 1.0 / 批次数));//每批抽奖最少人数
                //、、----------------------------------------------------------
                int Max = _MaxNum;
                for (int i = 1; i <= 批次数; i++)
                {
                    if (i == 批次数)
                    {
                        Max = 中奖人数 - (Max * (i - 1));
                    }
                    dic.Add(i, Max);
                }
                if (已经抽取 < 中奖人数)
                {
                    已抽奖批数 = Convert.ToInt32(已经抽取 * 1.0 / _MaxNum);
                }
                else
                {
                    已抽奖批数 = 批次数;
                }
                Pze.IsidNum = 批次数;
                Pze.Item = item;//项目号
                Pze.Name = 奖项名称;
                Pze.Num = 中奖人数;
                Pze.YJNum = 已经抽取;
                Pze.YJIsidNum = 已抽奖批数;
                Pze.Dic = dic;//每批次,抽取
                Pze.IsTrue = true;
                if (已抽奖批数 != 批次数)
                {
                    Pze.ThisNum = dic[已抽奖批数 + 1];
                }
                //--------------------------------------------------------------------------------------------
                //抽奖程序异常,调整。
                if (已经抽取 != Count)
                {
                    Pze.IsTrue = false;
                    //已经抽取的人数 设置为系统后台抽奖的实际总人数
                    已经抽取 = Count;
                    //已经抽取 除以 每次抽取人数 然后取最小整数,作为已经抽奖完成的批次
                    Pze.YJIsidNum = Convert.ToInt32(Math.Floor(已经抽取 * 1.0 / _MaxNum));
                    //本次抽奖人数
                    Pze.ThisNum = Pze.Dic[已经抽取 + 1] - (Count - _MaxNum * Pze.YJIsidNum);
                }
                //-----------------------------------------------------------------
                return Pze;
            }
    
            /// <summary>
            /// 第二步、根据抽奖人数随机抽取
            /// </summary>
            /// <param name="DtNoPrize">员工列表</param>
            /// <param name="Num">当前要抽出多少人</param>
            /// <param name="ItemNumber">抽奖号</param>
            /// <returns>返回中奖人员明细:List<YG></returns>
            public List<YG> SetZJNum(DataTable DtNoPrize, int Num, string ItemNumber)
            {
                List<YG> lst = new List<YG>();
                //所有未中奖的
                DataRow[] DrCJItem = DtNoPrize.Select("[抽奖状态] = '否' and (([中奖限制] = '普通') or ([中奖限制] = '必须中奖' and [中奖号] = '" + ItemNumber + "')) ");
                DataRow[] DrMax = DtNoPrize.Select("[抽奖状态] = '否' and [中奖限制] = '必须中奖' and [中奖号] = '" + ItemNumber + "'   ");
                if (DrCJItem.Length > Num)
                {
                    foreach (DataRow dr in DrMax)
                    {
                        YG yg = new YG();
                        yg.YG_NO = dr["员工代号"].ToString();
                        yg.YG_Name = dr["员工代号"].ToString();
                        int Count = lst.Where(t => t.YG_NO == yg.YG_NO).ToList().Count;
                        if (Count < 1) //.必须不能重复
                        {
                            lst.Add(yg);
                        }
                        if (lst.Count == Num)//如果等于设定数量自动跳出
                        {
                            break;
                        }
                    }
                    //循环随机获取一个员工
                    while (true)
                    {
                        Random ran = new Random();//
                        int i = ran.Next(DrCJItem.Length - 1);
                        YG yg = new YG();
                        yg.YG_NO = DrCJItem[i]["员工代号"].ToString();
                        yg.YG_Name = DrCJItem[i]["员工名称"].ToString();
                        int Count = lst.Where(t => t.YG_NO == yg.YG_NO).ToList().Count;
                        if (Count < 1)//.必须不能重复
                        {
                            lst.Add(yg);
                        }
                        if (lst.Count == Num)//如果等于设定数量自动跳出
                        {
                            break;
                        }
                    }
                }
                return lst;
            }
            /// <summary>
            /// 第三步、分组框的设计
            /// </summary>
            /// <param name="lst">中奖人员列表</param>
            /// <param name="NoLength">工号长度</param>
            /// <param name="Num">此处中奖人数</param>
            public void LoadContrl(List<YG> lst, int NoLength, int Num, int ThisWidth, int ThisHeight, bool blcj)
            {
                int H = 0;//组块高度;
                int Hs = 0;//竖向高度 组块高度+间距
                int W = 0;//组块宽度
                int JG = 0;//组块高度间隔; 
                int Nqueue = 1;//最大放几排;
                int NC = 0;//每排人数
                int YJG = 0;//组块Y轴间隔; 
                int Mark = 93;//基数;需要大于等于93
                //--------------------------------------------
                int Hts = 0;//组块高度;
                int Hsts = 0;//竖向高度 组块高度+间距
                int Wts = 0;//组块宽度
                int JGts = 0;//组块高度间隔;
    
                int Nqueuets = 1;//最大放几排;
                int NCts = 0;//每排人数
                int YJGts = 0;//组块Y轴间隔;
                int XJGts = 0;//X轴间隔;
                int KJGts = 0;//空白间隔; 
                //--------------------------------------------
                H = Convert.ToInt32(Math.Floor(ThisHeight * 1.0 / Num)) - 3;
                W = H * (NoLength + 1) + H * 3 + 4;//"Num+1":每个小框的间隔;"H * 3":留足3个空位填名字,+4留足每排的间隔
                //组块宽度>容器宽度
                if (W > ThisWidth)//只放一排
                {
                    W = Convert.ToInt32(ThisWidth * 1.0);
                    H = Convert.ToInt32(
                            (
                                (ThisWidth - 4) * 1.0
                            ) / (Num + 1 + 3)
                        );
                    JG = Convert.ToInt32(
                            Math.Floor(
                                         (
                                             ThisHeight - H * Num
                                        ) * 1.0 / Num
                                )
                        );
                    for (int i = 0; i < lst.Count; i++)
                    {
                        ContrlSet(0, i * (H + JG), W, NoLength, LstYg, lst[i].YG_NO, lst[i].YG_Name, blcj);
                    }
                }
                else
                {
                    Hts = 0;
                    Wts = 0;
                    Hsts = 0;
                    YJGts = 0;
                    Nqueuets = 1;
                    NCts = 0;
                    Nqueue = Convert.ToInt32(Math.Floor(ThisWidth * 1.0 / W));//最多可以放多少排!  
                    //多排计算方式
                    for (int i = 1; i <= Nqueue; i++)
                    {
                        H = 0;//小模块高度;
                        W = 0;//小木块宽度;
                        NC = Convert.ToInt32(Math.Ceiling(Num * 1.0 / i));//总人数 / 排数 每排人数
                        H = Convert.ToInt32(Math.Floor((ThisHeight) * 1.0 / NC)) - 3;
                        Hs = H + 3;
                        W = H * (NoLength + 1) + H * 3 + 4;//"NoLength+1":每个小框的间隔;"H * 3":留足3个空位填名字,+4留足每排的间隔
                        if (W > (ThisWidth * 1.0 / i))//一排宽度;Width-3:留3个位置空余
                        {
                            W = Convert.ToInt32(Math.Floor(ThisWidth * 1.0 / i));
                            H = Convert.ToInt32(Math.Floor((W - 4 - NC) * 1.0 / (NC + 3))) - 3;
                            Hs = H + 3;
                        }
                        //-------------------------------------------------------------------------
                        YJG = Convert.ToInt32(
                                Math.Floor(
                                            (
                                                ThisHeight - Hs * NC
                                           ) * 1.0 / NC
                                   )
                                 );
                        //---------------------------------------------------------------------
                        if (H < Hts)
                        {
                            break;
                        }
                        Nqueuets = i;
                        Hts = H;
                        Wts = W;
                        YJGts = YJG;// JG2 = JG0;
                        NCts = NC;
                    }
                    Nqueue = Nqueuets;//最优排数
                    H = Hts;//最优高度
                    W = Wts;//最优组块宽度
                    YJG = YJGts;//间隔
                    NC = NCts; //每排人数
                    int Counts = 0;
                    for (int j = 0; j < NC; j++)
                    {
                        Counts = j;
                        for (int t = 0; t < Nqueue; t++)
                        {
                            Counts = j * Nqueue + t;
                            ContrlSet(t * (W + 1), j * (H + YJG), W, NoLength, LstYg, lst[Counts].YG_NO, lst[Counts].YG_Name, blcj);
                            if (Counts == lst.Count - 1)
                            {
                                return;
                            }
                        }
                    }
                }
            }
            /// <summary>
            /// 第四步、获取当前奖项抽奖人员明细
            /// </summary>
            /// <param name="Item"></param>
            /// <returns></returns>
            public List<YG> SetZJNum(string item)
            {
                List<YG> lst = new List<YG>();
                string sql = "SELECT A.[员工代号] ,A.[员工名称],A.[部门代号],A.[中奖号],A.[中奖名称] FROM [中奖人员] AS A WHERE A.[中奖号]= '" + item + "'";
                DataTable dt = AccessHelper.DataSet(sql).Tables[0];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    YG yg = new YG();
                    yg.YG_NO = dt.Rows[i]["员工代号"].ToString();
                    yg.YG_Name = dt.Rows[i]["员工名称"].ToString();
                    lst.Add(yg);
                }
                return lst;
            }
            /// <summary>
            /// 设置一个 单元块的长宽,以及各模块的大小
            /// </summary>
            /// <param name="X">模块的位置:X轴</param>
            /// <param name="Y">模块的位置:Y轴</param>
            /// <param name="Width">模块宽度;高度:(Width - 50) * 1.0 / N(小模块个数)</param>
            /// <param name="N">小模块个数</param>
            public void ContrlSet(int X, int Y, int Width, int N, List<YG> _lstyg, string ygno, string ygName, bool blcj)
            {
                //----------------------------------------------------------------------
                int H = Convert.ToInt32(
                                        (
                                            (Width - 4) * 1.0
                                        ) / (N + 1 + 3)
                                    );
                UCNum uc = new UCNum(this);
                //uc.dt = DtTemp;
                uc.LstYg = _lstyg;
                uc.name = ygName;
                uc.YgNo = ygno;
                uc.Width = Width;//留足空余写名字
                uc.Height = H;// Convert.ToInt32(Math.Floor((Width - 50) * 1.0 / N));//高度
                uc.H = uc.Height - 4;
                uc.W = uc.Height - 4;
                //----------------------------------------------------------------------
                uc.Num = N;
                uc.Size = new System.Drawing.Size(uc.Width, uc.Height);//大小
                uc.Location = new System.Drawing.Point(X, Y); //位置
                uc.Set();
                LstUcnum.Add(uc);
                uc.Istrue = blcj;
                this.panel1.Controls.Add(uc);
                //----------------------------------------------------------------------
            } 
            #endregion ========================================抽奖四步操作 ========================================
            /// <summary>
            /// 获取所有人员明细
            /// </summary>
            /// <param name="Item"></param>
            /// <returns></returns>
            public DataTable ReCJGZ(string Item)
            {
                if (Item.Trim() != "")
                {
                    Item = "  Where  a.[项目号] = '" + Item + "'  ";
                }
                string sql = "SELECT a.[排序],a.[项目号],a.[奖项名称],a.[中奖人数],a.[限制因素],a.[已经抽取] FROM 抽奖规则 AS a " + Item + "  ORDER BY a.排序 ASC ";
                DataTable DtCJ = AccessHelper.DataSet(sql).Tables[0];
                return DtCJ;
            }
            #region ==========================================抽奖按钮========================================
            /// <summary>
            /// 抽奖按钮
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void lbbtn_Click(object sender, EventArgs e)
            {
                try
                {
                    if (lbbtn.Tag.ToString() == "开始")
                    {
                        IsTrue = true;
                        lbbtn.Tag = "结束";
                        lbbtn.Image = imgEnd;
                        //------------------------------------------
                        LstUcnum.Clear();//清空已经抽奖明细
                        LstUcnum = new List<UCNum>();
                        //------------------------------------------
                        panel1.Controls.Clear();
                        prize = GetCJItem(prize.Item);
                        lb项目号.Text = prize.Name;
                        lb总人数.Text = prize.Num.ToString();
                        lb已抽取.Text = prize.YJNum.ToString();
                        lb总批次.Text = prize.IsidNum.ToString();
                        lb完成批次.Text = prize.YJIsidNum.ToString();
                        List<YG> lstyg;
                        if (prize.YJIsidNum != prize.IsidNum)
                        {
                            lbPrizeTile.Text = prize.Name + ":当前正在抽取第" + (prize.YJIsidNum + 1).ToString() + "轮奖";
                            lb抽奖状态.Text = "当前正在抽取第" + (prize.YJIsidNum + 1).ToString() + "轮奖";
                            DataTable DtTemp = ReYg();//所有参与人员表                    
                            //---------------------------------------------
                            lstyg = SetZJNum(DtTemp, prize.ThisNum, prize.Item);
                            LoadContrl(lstyg, YgNoLength, prize.ThisNum, panel1.Width - 4, panel1.Height, true);
                            return;
                        }
                        else
                        {
                            lb抽奖状态.Text = "抽奖结束!";
                            lbbtn.Image = imgStr;
                            lbbtn.Tag = "开始";
                            lbPrizeTile.Text = prize.Name + ":抽奖完毕!";
                        }
                    }
                    else
                    {
                        try
                        {
                            lbbtn.Image = imgStr;
                            lbbtn.Tag = "开始";
                            IsTrue = false;
                            for (int i = 0; i < LstUcnum.Count; i++)
                            {
                                LstUcnum[i].Istrue = false;
                            }
                            SaveYJ_CJ();//抽奖结束保存抽奖结果。
                            LstUcnum.Clear();
                            LstUcnum = new List<UCNum>();
                            lbPrizeTile.Text = prize.Name + "" + prize.YJIsidNum + "轮抽奖完毕!";
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message.ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            } 
            /// <summary>
            /// 抽奖保存
            /// </summary>
            public void SaveYJ_CJ()
            {
                try
                {
                    if (LstUcnum.Count > 0)
                    {
                        int Count = 0;
                        string sql = "  ";
                        OleDbConnection conn = new OleDbConnection();
                        OleDbCommand comm = new OleDbCommand();
                        conn.ConnectionString = AccessHelper.connectionString;
                        comm.Connection = conn;
                        conn.Open();
                        comm.CommandType = CommandType.Text;
                        for (int i = 0; i < LstUcnum.Count; i++)
                        {
                            Count = Count + 1;                       
                            comm.CommandText = "UPDATE [人员表] SET [抽奖状态] = '是' WHERE [员工代号] ='" + LstUcnum[i].YgNo + "'";
                            comm.ExecuteNonQuery();
                            comm.CommandText = "INSERT INTO [中奖人员] ([员工代号],[员工名称],[中奖号],[中奖名称] )VALUES('" + LstUcnum[i].YgNo + "','" + LstUcnum[i].name + "','" + prize.Item + "','" + prize.Name + "')";
                            comm.ExecuteNonQuery();
                        }
                        //----------------------------------------------------
                        //获取此奖项已经抽过奖的数量
                        DataTable dt = new DataTable(); 
                        OleDbDataAdapter da = new OleDbDataAdapter();
                        try
                        {
                            comm.CommandType = CommandType.Text;
                            comm.CommandText = "SELECT 已经抽取 FROM 抽奖规则 Where 项目号 = '" + prize.Item + "'";
                            da.SelectCommand = comm;
                            da.Fill(dt);
                        }
                        catch (Exception e)
                        {
                        }
                        int NumTemp = 0;
                        try
                        {
                           NumTemp = Convert.ToInt32(dt.Rows[0]["已经抽取"]);
                        }
                        catch (Exception )
                        {
                            NumTemp = 0;
                        }
                        //------------------------------------  
                        //保存已经并汇总已经抽奖过的
                        sql = "UPDATE 抽奖规则 SET 已经抽取 = " + (NumTemp + LstUcnum.Count).ToString() + "  WHERE 项目号 = '" + prize.Item + "' ";
                        comm.CommandType = CommandType.Text;
                        comm.CommandText = sql;
                        comm.ExecuteNonQuery();
                        //---------------------------------------------------------
                        if (conn.State == ConnectionState.Open)
                        {
                            conn.Close();
                            conn.Dispose();
                            comm.Dispose();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
                //----------------------------------------------------------------
                try
                {
                    prize = GetCJItem(prize.Item); 
                    this.lb项目号.Text = prize.Name;
                    this.lb项目号.Tag = prize.Item;
                    this.lb已抽取.Text = prize.YJNum.ToString();
                    this.lb总批次.Text = prize.IsidNum.ToString();
                    this.lb总人数.Text = prize.Num.ToString();
                    lb完成批次.Text = prize.YJIsidNum.ToString();
                    if (prize.YJIsidNum != prize.IsidNum)
                    {
                        lb抽奖状态.Text = "" + (prize.YJIsidNum).ToString() + "轮抽奖结束";
                    }
                    else
                    {
                        lb抽奖状态.Text = "抽奖结束!";
                    }                 
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                } 
            } 
            #endregion ==========================================抽奖按钮========================================
    
            /// <summary>
            /// 窗体大小变化后自动调整功能框的位置
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void MainFrom_Resize(object sender, EventArgs e)
            {
                int W = this.Width;
                int H = this.Height;
                int lw = Convert.ToInt32(Math.Floor(W * 1.0 / 2));
                int lw2 = Convert.ToInt32(Math.Floor(lbPrizeTile.Width * 1.0 / 2));
                int lw3 = Convert.ToInt32(Math.Floor(lb标语.Width * 1.0 / 2));
                lbPrizeTile.Location = new System.Drawing.Point(lw - lw2, 110); //位置
                lb标语.Location = new System.Drawing.Point(lw - lw3, 60); //位置
    
                //---------------------------------------------------------------------------
                int lwgsmc = Convert.ToInt32(Math.Floor(LbGSMC.Width * 1.0 / 2));
                LbGSMC.Location = new System.Drawing.Point(lw - lwgsmc, 5); //位置
                //---------------------------------------------------------------------------
                int PX = Convert.ToInt32(Math.Floor((H - 373) * 1.0 / 2));
                PMeiun.Location = new System.Drawing.Point(0, PX); //位置
                SY1 = PX;
                SY2 = PX + 400;
                //---------------------------------------------------------------------------
                groupBox1.Location = new System.Drawing.Point(W - groupBox1.Width - 5, PX); //位置 
                //----------------------------------------------------------------------------
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {  
                if (this.mouseLocation.X < 178 && mouseLocation.Y > SY1 && mouseLocation.Y < SY2)
                {
                    PMeiun.Width = 178;
                    PMeiun.Height = 400;
                    Cursor = Cursors.Hand;
                }
                else
                {
                    PMeiun.Width = 1;
                    PMeiun.Height = 1; 
                } 
            }
            private void MainFrom_MouseMove(object sender, MouseEventArgs e)
            {
                this.mouseLocation = e.Location;
            }
            private void lbbtn_MouseEnter(object sender, EventArgs e)
            {
                Cursor = Cursors.Hand;
            }
            private void lbbtn_MouseLeave(object sender, EventArgs e)
            {
                Cursor = Cursors.Default;
            }         
            /// <summary>  
            /// 快捷键操作  
            /// </summary>  
            protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
            {
                switch (keyData)
                {
                    case Keys.Space://空格  
                        {
                            try
                            {
                                if (lbbtn.Tag.ToString() == "开始")
                                {
                                    IsTrue = true;
                                    lbbtn.Tag = "结束";
                                    lbbtn.Image = imgEnd;
                                    //------------------------------------------
                                    LstUcnum.Clear();//清空已经抽奖明细
                                    LstUcnum = new List<UCNum>();
                                    //------------------------------------------
                                    panel1.Controls.Clear();
                                    prize = GetCJItem(prize.Item);
                                    lb项目号.Text = prize.Name;
                                    lb总人数.Text = prize.Num.ToString();
                                    lb已抽取.Text = prize.YJNum.ToString();
                                    lb总批次.Text = prize.IsidNum.ToString();
                                    lb完成批次.Text = prize.YJIsidNum.ToString();
                                    List<YG> lstyg;
                                    if (prize.YJIsidNum != prize.IsidNum)
                                    {
                                        lbPrizeTile.Text = prize.Name + ":当前正在抽取第" + (prize.YJIsidNum + 1).ToString() + "轮奖";
                                        lb抽奖状态.Text = "当前正在抽取第" + (prize.YJIsidNum + 1).ToString() + "轮奖";
                                        DataTable DtTemp = ReYg();//所有参与人员表                    
                                        //---------------------------------------------
                                        lstyg = SetZJNum(DtTemp, prize.ThisNum, prize.Item);
                                        LoadContrl(lstyg, YgNoLength, prize.ThisNum, panel1.Width - 4, panel1.Height, true);
                                       
                                    }
                                    else
                                    {
                                        lb抽奖状态.Text = "抽奖结束!";
                                        lbbtn.Image = imgStr;
                                        lbbtn.Tag = "开始";
                                        lbPrizeTile.Text = prize.Name + ":抽奖完毕!"; 
                                    }
    
                                }
                                else
                                {
                                    try
                                    { 
                                        lbbtn.Image = imgStr;
                                        lbbtn.Tag = "开始";
                                        IsTrue = false;
                                        for (int i = 0; i < LstUcnum.Count; i++)
                                        {
                                            LstUcnum[i].Istrue = false;
                                        }
                                        SaveYJ_CJ();//抽奖结束保存抽奖结果。
                                        LstUcnum.Clear();
                                        LstUcnum = new List<UCNum>();
                                        lbPrizeTile.Text = prize.Name + "" + prize.YJIsidNum + "轮抽奖完毕!";
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show(ex.Message.ToString());
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message.ToString());
                            }                         
                        }
                        break;
                    case Keys.F4://设置
                        {
                            try
                            {
                                panel1.Controls.Clear();
                                LstUcnum.Clear();
                                LstUcnum = new List<UCNum>();
    
                                List<YG> lstyg;
                                lstyg = SetZJNum(prize.Item);
                                LoadContrl(lstyg, YgNoLength, lstyg.Count, panel1.Width - 4, panel1.Height, false);
                            }
                            catch (Exception)
                            {
                                 
                            }
                        }
                        break;
                    case Keys.F1://设置
                        {
                            FormPrizeSet f = new FormPrizeSet(this);
                            f.ShowDialog();
                        }
                        break;
                    case Keys.F2://查询功能等节目
                        {
                            FormSearch f = new FormSearch();
                            f.ShowDialog();
                            //MessageBox.Show("F2");
                        }
                        break;
                    case Keys.F3://查询功能等节目
                        {
                            Form1 f = new Form1();
                            f.ShowDialog();
                        }
                        break;
                    case Keys.Escape://查询功能等节目
                        {
                            SetFormFullScreen(false);
                            WindowState = System.Windows.Forms.FormWindowState.Minimized;
                        }
                        break;
                    case Keys.Delete://查询功能等节目
                        {
    
                            try
                            {
                                panel1.Controls.Clear();
                                LstUcnum.Clear();
                                LstUcnum = new List<UCNum>();
                                int Count = 0;
                                string sql = "  ";
                                OleDbConnection conn = new OleDbConnection();
                                OleDbCommand comm = new OleDbCommand();
                                conn.ConnectionString = AccessHelper.connectionString;
                                comm.Connection = conn;
                                conn.Open();
                                //----------------------------------------------------------------------
                                comm.CommandType = CommandType.Text;
                                comm.CommandText = "UPDATE [人员表] SET [抽奖状态] = '否',中奖限制='普通',[中奖号]='',[中奖名称]='' ";
                                comm.ExecuteNonQuery();
                                //----------------------------------
                                comm.CommandText = "DELETE  FROM [中奖人员]";
                                comm.ExecuteNonQuery();
                                //-----------------------------------
                                comm.CommandText = "UPDATE [抽奖规则] SET [已经抽取]=0 ";
                                comm.ExecuteNonQuery();
                                //----------------------------------------------------------------------
                                if (conn.State == ConnectionState.Open)
                                {
                                    conn.Close();
                                    conn.Dispose();
                                    comm.Dispose();
                                }
                                MessageBox.Show("重置完成");
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message.ToString());
                            }
                        }
                        break;
                    case Keys.F5://查询功能等节目
                        {
                            panel1.Controls.Clear();
                            LstUcnum.Clear();
                            LstUcnum = new List<UCNum>();
                            //A.[员工代号],A.[员工名称],A.[部门代号],B.[部门名称],A.[抽奖状态],a.[中奖限制],A.[中奖号],A.[中奖名称]
                            #region ==================================加载所有员工======================================
                            DataTable DtAllYg = ReYg();
                            for (int i = 0; i < DtAllYg.Rows.Count; i++)
                            {
                                YG y = new YG();
                                YG xzy = new YG();
                                y.YG_NO = DtAllYg.Rows[i]["员工代号"].ToString();
                                y.YG_Name = DtAllYg.Rows[i]["员工名称"].ToString();
                                LstYg.Add(y);
                            }
                            #endregion ==================================加载所有员工======================================
                            BackgroundImageLoad();//背景图片加载
                            #region =====================================全屏设置============================================
                            SetFormFullScreen(true);
                            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
                            #endregion=====================================全屏设置============================================
                            PrizeLoad();//抽奖项目加载 
                            GetNoLength();//获取人员工号长度
                            lbbtn.Tag = "开始";
                        }
                        break;
                    case Keys.F12://查询功能等节目
                        {
                            SetFormFullScreen(false);
                            Application.Exit();
                        }
                        break;
                }
                return base.ProcessCmdKey(ref msg, keyData);
            }
            private void MainFrom_FormClosing(object sender, FormClosingEventArgs e)
            {
                SetFormFullScreen(false);
            } 
        }
    }
     

     源码9 9...¥,加我Q

    转载于:https://www.cnblogs.com/lanyubaicl/p/6178362.html

    展开全文
  • C#公司年会抽奖系统

    2014-10-30 13:32:27
    C#开发的公司年会抽奖系统,是用access数据库,可以自定义每次抽奖的人员数量。
  • 可以自定义抽奖号码、人员信息、抽奖结果便签的打印。代码简洁、明了。数据库采用ACCess方便客户安装
  • 下面介绍我做的一个winform程序,实现的结果是点击...我做的这个软件在winform中需要timer控件,而在wpf中就没有timer控件了,需要DispatcherTimer这个类,而使用这个类的时候出现了很多问题,所以暂时先放置在了...

    下面介绍我做的一个winform程序,实现的结果是点击开始,然后名字一个一个地跳跃,然后点击介绍,名字停止跳动,此名字幸运的得了奖,而且不会重复名单!我准备用wpf来做的,虽然两者有很大的同共处,但是也有很微妙的区别。我做的这个软件在winform中需要timer控件,而在wpf中就没有timer控件了,需要DispatcherTimer这个类,而使用这个类的时候出现了很多问题,所以暂时先放置在了一边,用了winform窗体程序做了这个软件。此软件分了两个窗体,一个主窗体和一个子窗体,主窗体是抽奖用的,而子窗体是实现对名单的增删改查功能。

    点击主窗体左上角的“查看人员名单”就会跳转到子窗体。

    过程很简单

    1.首先给主窗体添加一些控件,加一些label,button和listbox控件。label显示名字的跳跃,主窗体中的listbox将会获取得到的获奖名字,然后显示出来几等奖。“重新开始”是初始化,可以重新进行抽奖。

    2.子窗体实现的是对名单的增删改查,也有一个文本导入名单功能。

    3.然后就是主要的数据库操作了。我用的是sqlserver 2010数据库,我的想法是,这个软件需要两个表,一个表当然是储存名单用的,这个简单的软件只需要id和Name两个字段就行了。 另外一个表也有id和Name字段,初始是没有数据的,这个表是储存已经抽到人的名单。第二张表是对比第一张表的,抽奖的时候抽取第一张表中的名单,然后跟第二张表进行比对,如果有一样的就不显示,从而达到抽奖名单不重复的目的。

    string sqlStr = "select Name, NewID() as random from T_Staff where Name not in (select Name from T_Staff1) order by random ";

    4.上面的sql语言,放在timer里面,这样timer运行一次,此sql就运行一次。这样就实现了名字不断跳转的效果。

    下面就把代码贴上,其实很简单。也有很多不完善的地方,将在本文最后总结中指出!

      1 public partial class Main : Form
      2     {
      3         public Main()
      4         {
      5             InitializeComponent();
      6         }
      7         public static string conStr = "uid=sa;pwd=123456;initial catalog=人员名单;data source=.;";
      8         public static SqlConnection conn = new SqlConnection(conStr);
      9         //int num = 0;
     10         private void timer1_Tick(object sender, EventArgs e)
     11         {
     12             try
     13             {
     14                 string sqlStr = "select Name, NewID() as random from T_Staff where Name not in (select Name from T_Staff1) order by random ";
     15                 SqlCommand cmd = new SqlCommand(sqlStr, conn);
     16                 conn.Open();
     17                 object obj = cmd.ExecuteScalar();
     18                 label2.Text = obj.ToString();
     19                 conn.Close();
     20             }
     21             catch 
     22             {
     23             }
     24         }
     25 
     26         private void Form1_Load(object sender, EventArgs e)
     27         {
     28             timer1.Interval = 40;
     29         }
     30         private void btn1_Click(object sender, EventArgs e)
     31         {
     32             label1.Text = "一等奖";
     33         }
     34 
     35         private void btn2_Click(object sender, EventArgs e)
     36         {
     37             label1.Text = "二等奖";
     38         }
     39 
     40         private void btn3_Click(object sender, EventArgs e)
     41         {
     42             label1.Text = "三等奖";
     43         }
     44         private void btnOther_Click(object sender, EventArgs e)
     45         {
     46             label1.Text = "其它奖项";
     47         }
     48         private void btnStart_Click(object sender, EventArgs e)
     49         {
     50             SoundPlayer player=new SoundPlayer();
     51             SoundPlayer player1 = new SoundPlayer();
     52             player.SoundLocation="E:/程序/抽奖系统2/抽奖系统2/Music/301.wav";
     53             player1.SoundLocation = "E:/程序/抽奖系统2/抽奖系统2/Music/3055.wav";
     54             SqlConnection conn = new SqlConnection(conStr);
     55             if (label1.Text == "欢迎")
     56             {
     57                 MessageBox.Show("请选择奖项!");
     58             }
     59             else if (btnStart.Text == "开始")
     60             {
     61                 player.PlayLooping();
     62                 btnStart.Text = "结束";
     63                 timer1.Start();
     64             }
     65             else
     66             {
     67                 player.Stop();
     68                 player1.Play();
     69                 timer1.Enabled = false;
     70                 string sqlStr1 = "Insert into T_Staff1(Name) values ('" + label2.Text + "')";
     71                 //num++;
     72                 SqlCommand com = new SqlCommand(sqlStr1, conn);
     73                 conn.Open();
     74                 com.ExecuteNonQuery();
     75                 conn.Close();
     76                 btnStart.Text = "开始";
     77                 if (label1.Text == "一等奖")
     78                 {
     79                     listBox1.Items.Add(label2.Text);
     80                 }
     81                 else if (label1.Text == "二等奖")
     82                 {
     83                     listBox2.Items.Add(label2.Text);
     84                 }
     85                 else if (label1.Text == "三等奖")
     86                 {
     87                     listBox3.Items.Add(label2.Text);
     88                 }
     89                 else if (label1.Text == "其它奖项")
     90                 {
     91                     listBox4.Items.Add(label2.Text);
     92                 }
     93             }
     94         }
     95         private void 退出系统ToolStripMenuItem_Click(object sender, EventArgs e)
     96         {
     97             SqlConnection conn = new SqlConnection(conStr);
     98             conn.Open();
     99             string sqlclear = "delete from T_Staff1";
    100             SqlCommand com = new SqlCommand(sqlclear, conn);
    101             com.ExecuteNonQuery();
    102             conn.Close();
    103             this.Close();
    104         }
    105         private void 重新开始ToolStripMenuItem_Click(object sender, EventArgs e)
    106         {
    107             SqlConnection conn = new SqlConnection(conStr);
    108             conn.Open();
    109             string sqlclear = "delete from T_Staff1";
    110             SqlCommand com = new SqlCommand(sqlclear, conn);
    111             com.ExecuteNonQuery();
    112             conn.Close();
    113             listBox1.Items.Clear();
    114             listBox2.Items.Clear();
    115             listBox3.Items.Clear();
    116             listBox4.Items.Clear();
    117             label1.Text = "欢迎";
    118             label2.Text = "名单";
    119             MessageBox.Show("已经初始化成功,请重新开始");
    120         }
    121         private void 查看人员名单ToolStripMenuItem_Click(object sender, EventArgs e)
    122         {
    123             NameList list = new NameList();
    124             list.ShowDialog();
    125         }      
    126     }
    主窗体后台代码
      1 public partial class NameList : Form
      2     {
      3         public NameList()
      4         {
      5             InitializeComponent();
      6         }
      7         public static string conStr = "uid=sa;pwd=123456;initial catalog=人员名单;data source=.;";
      8         public static SqlConnection conn = new SqlConnection(conStr);
      9         public void NameList_Load(object sender, EventArgs e)
     10         {
     11             conn.Open();
     12             //显示总共有多少的员工
     13             string strLong = "select count(*) from T_Staff";
     14             SqlCommand com = new SqlCommand(strLong, conn);
     15             int length=(int)com.ExecuteScalar();
     16             label1.Text = "总共有" + length + "个员工";
     17             //List显示数据库中的员工名单
     18             string strName = "select Name from T_Staff";
     19             DataSet ds = new DataSet();
     20             SqlDataAdapter adapter = new SqlDataAdapter(strName, conn);
     21             adapter.Fill(ds);
     22             foreach (DataRow row in ds.Tables[0].Rows)
     23             {
     24                 listBox1.Items.Add(row[0].ToString());
     25             }
     26             conn.Close();
     27         }
     28 
     29         private void button1_Click(object sender, EventArgs e)
     30         {
     31             //单值插入
     32             if (textBox1.Text == "")
     33             {
     34                 MessageBox.Show("请在上面输入名字");
     35             }
     36             else
     37             {
     38                 conn.Open();
     39                 string strInsert = "insert into T_Staff(Name) values('" + textBox1.Text + "')";
     40                 SqlCommand com = new SqlCommand(strInsert, conn);
     41                 com.ExecuteNonQuery();
     42                 MessageBox.Show(textBox1.Text + "插入成功");
     43                 conn.Close();             
     44             }
     45         }
     46 
     47         private void button6_Click(object sender, EventArgs e)
     48         {
     49             DialogResult dr = MessageBox.Show("你真的要全部删除吗?","删除操作",MessageBoxButtons.YesNo);
     50             if (dr == DialogResult.Yes)
     51             {
     52                 conn.Open();
     53                 string strDelete = "delete from T_Staff";
     54                 SqlCommand com = new SqlCommand(strDelete, conn);
     55                 com.ExecuteNonQuery();
     56                 conn.Close();
     57                 MessageBox.Show("删除成功");
     58             }
     59             else
     60             {
     61                 return;
     62             }
     63         }
     64 
     65         private void button2_Click(object sender, EventArgs e)
     66         {
     67             //选择性删除ListBox中的数据
     68             if (listBox1.SelectedItem != null)
     69             {
     70                 string selectedName = listBox1.SelectedItem.ToString();
     71                 conn.Open();
     72                 string strDel = "delete from T_Staff where Name='" + selectedName + "'";
     73                 SqlCommand com = new SqlCommand(strDel, conn);
     74                 com.ExecuteNonQuery();
     75                 conn.Close();
     76                 MessageBox.Show("删除成功");
     77             }
     78             else
     79             {
     80                 MessageBox.Show("请在左边选择名字");
     81             }
     82         }
     83 
     84         private void button4_Click(object sender, EventArgs e)
     85         {
     86             this.Close();
     87         }
     88 
     89         private void button5_Click(object sender, EventArgs e)
     90         {
     91             OpenFileDialog ofd = new OpenFileDialog();
     92             ofd.Filter = "文本文件|*.txt";
     93             ofd.ShowDialog();
     94             string filename = ofd.FileName;
     95             IEnumerable<string> lines= File.ReadAllLines(filename,Encoding.Default);
     96             foreach (string line in lines)
     97             {
     98                 string[] segs = line.Split(' ');
     99                 string name = segs[0];
    100                 conn.Open();
    101                 string strDel = "insert into T_Staff(Name) values('" + name + "')";
    102                 SqlCommand com = new SqlCommand(strDel, conn);
    103                 com.ExecuteNonQuery();
    104                 conn.Close();
    105             }
    106             MessageBox.Show("成功导入"+lines.Count()+"条数据");
    107         }
    108     }
    子窗体代码

    这个小程序的问题很多。代码中的注释很很少,是当初写的时候没注意吧。窗体没有美化,没有太多时间去弄这个了。写这种对sql操作的时候应该把这些写到一个类中SqlHelper,这样直接调用这个类中的一些方法就行了,当初没注意,导致写的时候程序语句很冗杂。

    下面是这个程序运行的效果

    转载于:https://www.cnblogs.com/xijianyao/archive/2013/06/09/3129400.html

    展开全文
  • 最近写了一个关于winform的实训小项目(抽奖系统),有一、二、三等奖和幸运奖,摇奖时加了减速效果,摇奖结果保存在文件里面,感觉还不错,所以贴出来分享一下,希望能帮到大家
  • C#抽奖系统

    2019-01-17 17:18:01
    简单的九宫格抽奖系统,入门级,winform系统,高手勿喷……
  • winform 抽奖程序

    2011-07-26 12:50:00
    using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading;...using Sys...
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;
    using System.IO;
    using Skins.Common;
    
    namespace lucy
    {
        public partial class jiang : Skins.Common.MainForm
        {
            bool go = false;
            int a = 0;
            int jiangxiang = 1;
            int erdengjiang = 1;
            int sandengjiang = 1;
            
            ArrayList arr1 = new ArrayList();
            public main main2 = null;
            public jiang(string title,main main1)
            {
                main2 = main1;
                InitializeComponent();
                this.Text = title;
                this.qqLabel1.Text = title;
                if (title == "抽取一等奖")
                {
                    jiangxiang = 1;
                    qqPanel1.Visible = true;
                    qqPanel1.BringToFront();
                }
                else if (title == "抽取二等奖")
                {
                    jiangxiang = 2;
                    qqPanel2.BringToFront();
                    qqPanel2.Visible = true;
                    
                }
                else if (title == "抽取三等奖")
                {
                    jiangxiang = 3;
                    qqPanel3.BringToFront();
                    qqPanel3.Visible = true;
    
                }
                qqButton1.Click += new EventHandler(qqButton1_Click);
            }
    
            void qqButton1_Click(object sender, EventArgs e)
            {
                if (jiangxiang == 1)
                {
                    if (qqButton1.Text == "开始")
                    {
                        timer1.Enabled = true;
                        if (a == 0)
                        {
                            Random ran = new Random();
                            a = ran.Next(0, main.arr.Count - 1);
                        }
                        go = true;
                        qqButton1.Text = "停止";
                    }
                    else
                    {
                        main.arr.Remove(yidengjiang.Text);
                        go = false;
                        main2.zhong1.Text = yidengjiang.Text;
                        MsgBoxForm msg1 = new MsgBoxForm("一等奖中奖用户为" + yidengjiang.Text, "一等奖中奖用户", MessageBoxButtons.OK, MessageBoxIcon.None);
                        msg1.ShowDialog();
                        if (msg1.DialogResult == DialogResult.OK)
                        {
                            this.Close();
                            main2.qqComboBox1.SelectIndex = 1;
                        }
                    }
                }
                else if (jiangxiang == 2)
                {
                    if (qqButton1.Text == "开始")
                    {
                        timer1.Enabled = true;
                        if (a == 0)
                        {
                            Random ran = new Random();
                            a = ran.Next(0, main.arr.Count - 1);
                        }
                        go = true;
                        qqButton1.Text = "抽取第一位二等奖用户";
                    }
                    else if (qqButton1.Text == "抽取第一位二等奖用户")
                    {
                        erdengjiang += 1;
                        main.arr.Remove(yidengjiang1.Text);
                       
                        
                        qqButton1.Text = "抽取第二位二等奖用户";
                    }
                    else if (qqButton1.Text == "抽取第二位二等奖用户")
                    {
                        erdengjiang += 1;
                        main.arr.Remove(yidengjiang2.Text);
                       
                       
                        qqButton1.Text = "抽取第三位二等奖用户";
                    }
                    else if (qqButton1.Text == "抽取第三位二等奖用户")
                    {
                        erdengjiang += 1;
                        main.arr.Remove(yidengjiang3.Text);
                        
                        
                        qqButton1.Text = "抽取第四位二等奖用户";
                    }
                    else if (qqButton1.Text == "抽取第四位二等奖用户")
                    {
                        erdengjiang += 1;
                        main.arr.Remove(yidengjiang4.Text);
                        
                        
                        qqButton1.Text = "抽取第五位二等奖用户";
                    }
                    else if (qqButton1.Text == "抽取第五位二等奖用户")
                    {
                        erdengjiang += 1;
                        main.arr.Remove(yidengjiang5.Text);
                      
                        
                        go = false;
                        main2.zhong2.Text = yidengjiang1.Text + "  " + yidengjiang2.Text + "  " +yidengjiang3.Text + "  " +yidengjiang4.Text + "  " +yidengjiang5.Text;
                        MsgBoxForm msg1 = new MsgBoxForm("二等奖中奖用户为" + yidengjiang1.Text + "  " + yidengjiang2.Text + "  " + yidengjiang3.Text + "  " + yidengjiang4.Text + "  " + yidengjiang5.Text, "二等奖中奖用户", MessageBoxButtons.OK, MessageBoxIcon.None);
                        msg1.ShowDialog();
                        if (msg1.DialogResult == DialogResult.OK)
                        {
                            this.Close();
                            main2.qqComboBox1.SelectIndex = 2;
                        }
                    }
                }
                else if (jiangxiang == 3)
                {
                    if (qqButton1.Text == "开始")
                    {
                        timer1.Enabled = true;
                        if (a == 0)
                        {
                            Random ran = new Random();
                            a = ran.Next(0, main.arr.Count - 1);
                        }
                        go = true;
                        qqButton1.Text = "抽取第一位三等奖用户";
                    }
                    else
                    {
                        if (sandengjiang == 50)
                        {
                            
                            main.arr.Remove(label50.Text);
                            sandengjiang += 1;
                           
                            Thread.Sleep(500);
                            go = false;
                            string str = string.Empty;
                            string str1 = string.Empty;
                            int aa = 0;
                            foreach (Label lab in qqPanel3.Controls)
                            {
                                str += lab.Text+"  ";
                                aa += 1;
                                if (aa%5==0)
                                {
                                    str1 += lab.Text + "\r\n\r\n";
                                }
                                else
                                {
                                    str1 += lab.Text + "  ";
                                }
                            }
                            main2.zhong3.Text = str1;
                            MsgBoxForm msg1 = new MsgBoxForm("50名三等奖用户已经抽完", "三等奖中奖用户", MessageBoxButtons.OK, MessageBoxIcon.None);
                            msg1.ShowDialog();
                            if (msg1.DialogResult == DialogResult.OK)
                            {
                                this.Close();
                                main2.qqComboBox1.SelectIndex = 2;
                                StreamWriter sw = new StreamWriter("wlan_" + System.DateTime.Now.ToShortDateString() + "_抽奖结果.txt");
                                sw.WriteLine("一等奖用户:\r\n" + main2.zhong1.Text + "\r\n");
                                sw.WriteLine("二等奖用户:\r\n" + main2.zhong2.Text + "\r\n");
                                sw.WriteLine("三等奖用户:\r\n" + main2.zhong3.Text + "\r\n");
                                sw.WriteLine(System.DateTime.Now);
                                sw.Close();
                            }
                        }
                        else
                        {
                            //if (sandengjiang == 1)
                            //{
                            //    foreach (Label lab in qqPanel3.Controls)
                            //    {
                            //        if (lab.Name == "label" + (sandengjiang).ToString())
                            //        {
                            //            main.arr.Remove(lab.Text);
                            //            sandengjiang += 1;
    
                            //        }
                            //    }
                            //}
                            //else
                            //{
                                foreach (Label lab in qqPanel3.Controls)
                                {
                                    if (lab.Name == "label" + (sandengjiang).ToString())
                                    {
                                        
                                        main.arr.Remove(lab.Text);
                                        sandengjiang += 1;
                                        break;
                                    }
                                }
                            }
                            qqButton1.Text = "抽取第" + ConvertInt(sandengjiang.ToString()) + "位三等奖用户";
                        //}
                        
                    }
                }
            }
            private void start()
            {
                if (go)
                {
                    for (int i = a; i < main.arr.Count; i++)
                    {
                        a = i + 1;
                        yidengjiang.Text = main.arr[i].ToString();
                        if (i == main.arr.Count - 1)
                        {
                            a = 0;
                        }
                        break;
                    }
                }
    
            }
    
            private void start1()
            {
                if (go)
                {
                    for (int i = a; i < main.arr.Count; i++)
                    {
                        a = i + 1;
                        if (erdengjiang == 1)
                        {
                            yidengjiang1.Text = main.arr[i].ToString();
                        }
                        if (erdengjiang == 2)
                        {
                            yidengjiang2.Text = main.arr[i].ToString();
                        }
                        if (erdengjiang == 3)
                        {
                            yidengjiang3.Text = main.arr[i].ToString();
                        }
                        if (erdengjiang == 4)
                        {
                            yidengjiang4.Text = main.arr[i].ToString();
                        }
                        if (erdengjiang == 5)
                        {
                            yidengjiang5.Text = main.arr[i].ToString();
                        }
                        if (i == main.arr.Count - 1)
                        {
                            a = 0;
                        }
                        break;
                    }
                }
    
            }
    
            private void start2()
            {
                if (go)
                {
                    for (int i = a; i < main.arr.Count; i++)
                    {
                        a = i + 1;
                        foreach(Label lab in qqPanel3.Controls)
                        {
                            if (lab.Name == "label" + sandengjiang.ToString())
                            {
                                lab.Text = main.arr[i].ToString();
                                while(lab.Text == "")
                                {
                                    lab.Text = main.arr[i].ToString();
                                }
                            }
                        }
                        if (i == main.arr.Count - 1)
                        {
                            a = 0;
                        }
                        break;
                    }
                }
    
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                if (jiangxiang == 1)
                {
                    start();
                }
                else if (jiangxiang == 2)
                {
                    start1();
                }
                else if (jiangxiang == 3)
                {
                    start2();
                }
            }
    
            private void jiang_Load(object sender, EventArgs e)
            {
                minge.Text = "一共有" + main.arr.Count + "个待抽奖用户";
            }
            #region 阿拉伯数字转汉文
            private static string[] cstr = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
            private static string[] wstr = { "零", "十", "二", "三", "四", "五", "六", "七", "八", "九" };
            /// <summary>
            /// 阿拉伯数字转汉文 
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public static string ConvertInt(string str)
            {
                int len = str.Length;
                int i;
                string tmpstr, rstr;
                rstr = "";
                if (len == 1)
                {
                    tmpstr = str.Substring(0, 1);
                    rstr += string.Concat(cstr[Int32.Parse(tmpstr)]);
                }
                else
                {
                    for (i = 0; i < len; i++)
                    {
                        tmpstr = str.Substring(i, 1);
                        rstr += string.Concat(wstr[Int32.Parse(tmpstr)]);
                    }
    
                }
                return rstr;
            }
            #endregion
    
            private void qqPanel3_Paint(object sender, PaintEventArgs e)
            {
    
            }
        }
    }
    

    ContractedBlock.gif ExpandedBlockStart.gif View Code
     1 /// 打开新窗体抽奖
    2 void qqButton1_Click(object sender, EventArgs e)
    3 {
    4 if (zhong1.Text != "" && qqComboBox1.SelectIndex == 0)
    5 {
    6 MsgBoxForm msg1 = new MsgBoxForm("一等奖用户已经抽取请抽取其他奖项", "", MessageBoxButtons.OK, MessageBoxIcon.None);
    7 msg1.ShowDialog();
    8 }
    9 else if (zhong2.Text != "" && qqComboBox1.SelectIndex == 1)
    10 {
    11 MsgBoxForm msg1 = new MsgBoxForm("二等奖用户已经抽取请抽取其他奖项", "", MessageBoxButtons.OK, MessageBoxIcon.None);
    12 msg1.ShowDialog();
    13 }
    14 else if (zhong3.Text != "" && qqComboBox1.SelectIndex == 2)
    15 {
    16 MsgBoxForm msg1 = new MsgBoxForm("二等奖用户已经抽取请抽取其他奖项", "", MessageBoxButtons.OK, MessageBoxIcon.None);
    17 msg1.ShowDialog();
    18 }
    19 else
    20 {
    21 jiang jiang1 = new jiang(qqComboBox1.Texts, this);
    22 jiang1.ShowDialog();
    23 }
    24 }
    25 ///载入的时候新开一个线程读取抽奖列表
    26 private void main_Load(object sender, EventArgs e)
    27 {
    28 new Thread(() =>
    29 {
    30 try
    31 {
    32 string[] filearr = File.ReadAllLines("jiang.txt", Encoding.UTF8);
    33 for (int j = 0; j < filearr.Length; j++)
    34 {
    35 Invoke(new Action(() =>
    36 {
    37 arr.Add(filearr[j].ToString());
    38 }));
    39 }
    40 BeginInvoke(new Action(() =>
    41 {
    42
    43 }));
    44 }
    45 catch (Exception ex)
    46 {
    47 string aa = ex.ToString();
    48 }
    49 }).Start();
    50 }
    51 ///保存中奖名单
    52 SaveFileDialog saveFileDialog = new SaveFileDialog();
    53 private void qqButton2_Click(object sender, EventArgs e)
    54 {
    55 if (zhong1.Text != "" && zhong2.Text != "" && zhong3.Text != "")
    56 {
    57 //saveFileDialog.InitialDirectory = "C:\\";//设置保存的默认目录
    58 saveFileDialog.Filter = "txt files(*.txt)|*.txt|all files(*.*)|*.*";
    59 saveFileDialog.FileName = "wlan_"+System.DateTime.Now.ToShortDateString()+"_抽奖结果";
    60 saveFileDialog.FilterIndex = 1;//默认显示保存内型为TXT
    61 saveFileDialog.RestoreDirectory = true;
    62 if (saveFileDialog.ShowDialog() == DialogResult.OK)
    63 {
    64 try
    65 {
    66 StreamWriter sw = new StreamWriter(saveFileDialog.FileName);
    67 sw.WriteLine("一等奖用户:\r\n" + zhong1.Text + "\r\n");
    68 sw.WriteLine("二等奖用户:\r\n" + zhong2.Text + "\r\n");
    69 sw.WriteLine("三等奖用户:\r\n" + zhong3.Text + "\r\n");
    70 sw.WriteLine(System.DateTime.Now);
    71 sw.Close();
    72 }
    73 catch (Exception ex)
    74 {
    75 Console.WriteLine("Err: " + ex.Message);
    76 }
    77 finally
    78 {
    79 Console.WriteLine("Write END");
    80 }
    81 }
    82 }
    83 else
    84 {
    85 MsgBoxForm msg1 = new MsgBoxForm("请抽奖后再导出结果", "", MessageBoxButtons.OK, MessageBoxIcon.None);
    86 msg1.ShowDialog();
    87
    88 }
    89 }

    完整代码

    main.cs

      1 using System;
    2 using System.Collections;
    3 using System.ComponentModel;
    4 using System.Data;
    5 using System.Drawing;
    6 using System.Linq;
    7 using System.Text;
    8 using System.Windows.Forms;
    9 using System.Threading;
    10 using System.IO;
    11 using Skins.Common;
    12
    13 namespace lucy
    14 {
    15 public partial class main : Skins.Common.MainForm
    16 {
    17 public static ArrayList arr = new ArrayList();
    18 public main()
    19 {
    20 InitializeComponent();
    21 this.qqButton1.Click += new EventHandler(qqButton1_Click);
    22 }
    23
    24 void qqButton1_Click(object sender, EventArgs e)
    25 {
    26 if (zhong1.Text != "" && qqComboBox1.SelectIndex == 0)
    27 {
    28 MsgBoxForm msg1 = new MsgBoxForm("一等奖用户已经抽取请抽取其他奖项", "", MessageBoxButtons.OK, MessageBoxIcon.None);
    29 msg1.ShowDialog();
    30 }
    31 else if (zhong2.Text != "" && qqComboBox1.SelectIndex == 1)
    32 {
    33 MsgBoxForm msg1 = new MsgBoxForm("二等奖用户已经抽取请抽取其他奖项", "", MessageBoxButtons.OK, MessageBoxIcon.None);
    34 msg1.ShowDialog();
    35 }
    36 else if (zhong3.Text != "" && qqComboBox1.SelectIndex == 2)
    37 {
    38 MsgBoxForm msg1 = new MsgBoxForm("二等奖用户已经抽取请抽取其他奖项", "", MessageBoxButtons.OK, MessageBoxIcon.None);
    39 msg1.ShowDialog();
    40 }
    41 else
    42 {
    43 jiang jiang1 = new jiang(qqComboBox1.Texts, this);
    44 jiang1.ShowDialog();
    45 }
    46 }
    47
    48 private void main_Load(object sender, EventArgs e)
    49 {
    50 new Thread(() =>
    51 {
    52 try
    53 {
    54 string[] filearr = File.ReadAllLines("jiang.txt", Encoding.UTF8);
    55 for (int j = 0; j < filearr.Length; j++)
    56 {
    57 Invoke(new Action(() =>
    58 {
    59 arr.Add(filearr[j].ToString());
    60 }));
    61 }
    62 BeginInvoke(new Action(() =>
    63 {
    64
    65 }));
    66 }
    67 catch (Exception ex)
    68 {
    69 string aa = ex.ToString();
    70 }
    71 }).Start();
    72 }
    73 SaveFileDialog saveFileDialog = new SaveFileDialog();
    74 private void qqButton2_Click(object sender, EventArgs e)
    75 {
    76 if (zhong1.Text != "" && zhong2.Text != "" && zhong3.Text != "")
    77 {
    78 //saveFileDialog.InitialDirectory = "C:\\";//设置保存的默认目录
    79 saveFileDialog.Filter = "txt files(*.txt)|*.txt|all files(*.*)|*.*";
    80 saveFileDialog.FileName = "wlan_"+System.DateTime.Now.ToShortDateString()+"_抽奖结果";
    81 saveFileDialog.FilterIndex = 1;//默认显示保存内型为TXT
    82 saveFileDialog.RestoreDirectory = true;
    83 if (saveFileDialog.ShowDialog() == DialogResult.OK)
    84 {
    85 try
    86 {
    87 StreamWriter sw = new StreamWriter(saveFileDialog.FileName);
    88 sw.WriteLine("一等奖用户:\r\n" + zhong1.Text + "\r\n");
    89 sw.WriteLine("二等奖用户:\r\n" + zhong2.Text + "\r\n");
    90 sw.WriteLine("三等奖用户:\r\n" + zhong3.Text + "\r\n");
    91 sw.WriteLine(System.DateTime.Now);
    92 sw.Close();
    93 }
    94 catch (Exception ex)
    95 {
    96 Console.WriteLine("Err: " + ex.Message);
    97 }
    98 finally
    99 {
    100 Console.WriteLine("Write END");
    101 }
    102 }
    103 }
    104 else
    105 {
    106 MsgBoxForm msg1 = new MsgBoxForm("请抽奖后再导出结果", "", MessageBoxButtons.OK, MessageBoxIcon.None);
    107 msg1.ShowDialog();
    108
    109 }
    110 }
    111
    112 private void button1_Click(object sender, EventArgs e)
    113 {
    114 if (zhong1.Text != "" && zhong2.Text != "" && zhong3.Text != "")
    115 {
    116 //saveFileDialog.InitialDirectory = "C:\\";//设置保存的默认目录
    117 saveFileDialog.Filter = "txt files(*.txt)|*.txt|all files(*.*)|*.*";
    118 saveFileDialog.FileName = "wlan_" + System.DateTime.Now.ToShortDateString() + "_抽奖结果判断重复";
    119 saveFileDialog.FilterIndex = 1;//默认显示保存内型为TXT
    120 saveFileDialog.RestoreDirectory = true;
    121 if (saveFileDialog.ShowDialog() == DialogResult.OK)
    122 {
    123 try
    124 {
    125 StreamWriter sw = new StreamWriter(saveFileDialog.FileName);
    126 sw.WriteLine(zhong1.Text);
    127 sw.WriteLine(zhong2.Text.Replace(" ","\r\n"));
    128 sw.WriteLine(zhong3.Text.Replace("\r\n", " ").Replace(" ", "\r\n").Replace(" ", "\r\n"));
    129 sw.Close();
    130 }
    131 catch (Exception ex)
    132 {
    133 Console.WriteLine("Err: " + ex.Message);
    134 }
    135 finally
    136 {
    137 Console.WriteLine("Write END");
    138 }
    139 }
    140 }
    141 else
    142 {
    143 MsgBoxForm msg1 = new MsgBoxForm("请抽奖后再导出结果", "", MessageBoxButtons.OK, MessageBoxIcon.None);
    144 msg1.ShowDialog();
    145
    146 }
    147 }
    148 }
    149 }

    jiang.cs

    给移动做的一个抽奖程序,可能还有点漏洞,占时没有解决,抽奖的时候没有遇到什么问题。

    现在把代码放出,没有带大的难度。

    转载于:https://www.cnblogs.com/xuehuai/archive/2011/07/26/2117082.html

    展开全文
  • 年会抽奖系统

    2017-02-07 11:52:56
    简单的年会抽奖系统,调用excel人员信息,获奖情况可导出成excel文件。已获奖人员不能再次获奖
  • C#公司抽奖系统源码

    2018-05-23 15:22:50
    本程序是基于winform开发的PC端程序,支持奖品设置,抽奖人数设置,中奖人数设置
  • C#年会抽奖源码

    2019-04-11 14:11:28
    这是一款比较基础的windows窗体抽奖系统,界面比较美观,可以作为新手学习使用, 感兴趣的朋友可以下载学习一下。 该源码主要通过定时器控件实现姓名的随机滚动,从而实现随机抽奖的功能。 需要通过鼠标控制抽奖...
  • 新手练习作品,C#源码,抽奖系统,使用access数据库,能导入人员名单和奖品清单,导出中奖人员名单,可以一次产生多名中奖人员名单。
  • 如何用C#实现 简易的会员抽奖系统

    千次阅读 2018-11-10 22:14:09
    该会员抽奖系统功能说明: 1、输入会员号(只能是4位数字) 2、输入积分(大于3000才可以参与抽奖;小于等于3000不参与抽奖) 3、点击“抽奖”,随机产生随机数1~100(随机数1,奖项是 获得一等奖苹果笔记本电脑...
  • 最近班上写了一个关于winform的实训小项目(抽奖系统),90%的代码都在下面,感觉还不错,所以贴出来分享一下,希望能帮倒大家 所有界面如下: 这是自己写的一个公共类: View Code using System; ...
  • 没有数据库的,可以直接打开解决方案!虽然很简单,但是里面用到了一些很巧妙的方法和技巧,很值得一看哦!
  • C#点名程序,也可当作是一个随机摇号或幸运抽奖程序,可以帮助老师在课堂上进行随机点名, 实例采用Visual Studio 2008作为开发工具,采用C#开发。 为了简单数据存储采用文件的形式。在系统的bin目录下用lottery.asf...
  • 你也可以做一个简易抽奖程序!

    千次阅读 2021-05-31 00:57:42
    大家好,我是雄雄,欢迎关注微信公众号:雄雄的小课堂。今天给大家分享一个使用winform制作的小案例——随机点名(抽奖)程序,下面我们来看看运行结果:在班内点名为了公平起见,一直使用的该程...
  • 用C#开发的抽奖程序,可同时抽取多人,也可以用员工相片来抽奖
  • 抽奖程序实现以下功能: 1、文本框中姓名快速自动切换; 2、按任意键停止切换,再按任意键继续切换,先选出三等奖获得者,依次二等奖获得者、一等奖获得者; 3、不能重复获奖; 4、单击窗体重新开始抽奖。 using ...
  • 漂亮的抽奖C#源代码

    千次下载 热门讨论 2012-01-03 14:07:38
    系统功能很简单,但界面很精美。点击抽奖则可以随机的生成结果。
  • C#WinForm应用程序——简易摇号系统

    千次阅读 2019-04-01 22:05:23
    去年班级元旦晚会制作的要好系统,一直都忘记把代码贡献出来,把制作方法和大家说一下。 最后效果图 功能介绍: 点击开始,可以在“冲冲冲”里滚动姓名 点击结束,滚动停止 在文本框里输入姓名,添加幸运儿...
  • 这两天在搞一个抽奖系统,我负责的是系统的界面,在各个控件弄好后整体的美观也很重要,这篇博客要分享的是一个破解后的 IrisSkin4.dll 文件,很好用,记录这篇博客一来是分享给大家,二来是给自己做个记录方便今后...
  • ![图片说明](https://img-ask.csdn.net/upload/201505/09/1431140255_284089.jpg) 摇奖窗体文本框里的数据是滚动的,希望各位大神们帮帮我,第一次上csdn,谢谢了!
  • C#-WinForm-Timer控件

    2016-12-13 23:30:00
    利用Timer控件制作一个随机抽奖系统 public Form6() { InitializeComponent(); } bool start = false ; // 开始或结束抽奖 private void button1_Click( object sender, EventArgs e) { ...

空空如也

空空如也

1 2 3 4 5
收藏数 92
精华内容 36
关键字:

winform抽奖系统

友情链接: chaoshwn.zip