年会抽奖软件:
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 = ;//长度,参与人员的代号长度
public int SX = ;
public int SY1 = ;//抽奖项目框的Y周初始位置
public int SY2 = ;//抽奖项目框的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 = ;//最大抽奖人数
public int SYNumn = ;
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 = ; public const Int32 SW_HIDE = ; [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 = ;
public const Int32 SPI_GETWORKAREA = ; [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 = ;
hwnd = FindWindow("Shell_TrayWnd", null);//获取任务栏的句柄 if (hwnd == ) return false; if (fullscreen)//全屏
{
ShowWindow(hwnd, SW_HIDE);//隐藏任务栏 SystemParametersInfo(SPI_GETWORKAREA, , ref rectOld, SPIF_UPDATEINIFILE);//get 屏幕范围
Rectangle rectFull = Screen.PrimaryScreen.Bounds;//全屏范围
SystemParametersInfo(SPI_SETWORKAREA, , ref rectFull, SPIF_UPDATEINIFILE);//窗体全屏幕显示
}
else//还原
{
ShowWindow(hwnd, SW_SHOW);//显示任务栏 SystemParametersInfo(SPI_SETWORKAREA, , 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 = ; 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 < '') || (e.KeyChar > ''))//这是允许输入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[];
}
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[];
for (int i = ; 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[];
for (int i = ; 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 - ) * 1.0 / ));
PMeiun.Location = new System.Drawing.Point(, PX); //位置
SY1 = PX;//获取并设置抽奖项目Y坐标初始位置
SY2 = PX + ;//获取抽奖项目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[];
int RH = ;
int RW = ;
if (DtCJ.Rows.Count > )
{
RH = ;// Convert.ToInt32(Math.Floor(400 * 1.0 / (DtCJ.Rows.Count + 2)));
RW = ;
for (int i = ; i < DtCJ.Rows.Count; i++)
{
RadioButton rad = new RadioButton();
rad.Location = new System.Drawing.Point(, + RH * i);
rad.Size = new System.Drawing.Size(RW, RH - );
rad.TabIndex = ;
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(, + RH * DtCJ.Rows.Count);
RdioOrther.Size = new System.Drawing.Size(RW, RH - );
RdioOrther.TabIndex = ;
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(, RH * (DtCJ.Rows.Count + ) - );
gb.Name = "gB";
gb.Size = new System.Drawing.Size(, );
gb.TabIndex = ;
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(, );
lbotherCJ.Size = new System.Drawing.Size(, );
this.GBQT.Controls.Add(lbotherCJ);
tbOtherCJNum.Location = new System.Drawing.Point(, );
tbOtherCJNum.Size = new System.Drawing.Size(, );
this.GBQT.Controls.Add(tbOtherCJNum);
//--------------------------------------------------
Label lbotherName = new Label();
lbotherName.Text = "奖项名称";
lbotherName.AutoSize = true;
lbotherName.Location = new System.Drawing.Point(, );
lbotherName.Size = new System.Drawing.Size(, );
this.GBQT.Controls.Add(lbotherName);
tbOtherCJNumName.Location = new System.Drawing.Point(, );
tbOtherCJNumName.Size = new System.Drawing.Size(, );
tbOtherCJNumName.Text = "加抽奖" + DateTime.Now.ToString("fffff") ;
this.GBQT.Controls.Add(tbOtherCJNumName);
//
BtntherCJ.Text = "保 存";
BtntherCJ.Location = new System.Drawing.Point(, );
BtntherCJ.Size = new System.Drawing.Size(, );
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())==)
{
return;
}
string sql = "";
prize.IsidNum = ;
prize.Name = this.tbOtherCJNumName.Text.Trim();
prize.Num = Convert.ToInt32(tbOtherCJNum.Text.Trim());
prize.YJNum = ;
prize.YJIsidNum = ;
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[].Rows[][]);
if (count < )
{
prize.Item = DateTime.Now.ToString("HHmmssffffff");
sql = "Select Max(A.[排序])+1 From [抽奖规则] as A ";
prize.ID = Convert.ToInt32(AccessHelper.DataSet(sql).Tables[].Rows[][]);
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="";// = new TextBox();//其他抽奖项目,记录人数。
tbOtherCJNumName.Text = "加抽"+">";// new TextBox(); //其他抽奖项目,抽奖项目名称。
GBQT.Visible = true;
lbPrizeTile.Text = "加抽奖";
prize.ReMark = "新添加";
this.lb项目号.Text = "加抽奖";
this.lb总人数.Text = "";
this.lb总批次.Text = "";
this.lb已抽取.Text = "";
lb完成批次.Text = "";
}
/// <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 == )
{
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[];
sb.Clear();
sb.Append("SELECT COUNT(1) FROM [中奖人员] AS A WHERE A.[中奖号] = '" + item + "' ");
//抽奖人数
int Count = Convert.ToInt32(AccessHelper.DataSet(sb.ToString()).Tables[].Rows[][]);
sb.Clear();
string 奖项名称 = (DtCJNO.Rows[]["奖项名称"] == null) ? "" : DtCJNO.Rows[]["奖项名称"].ToString().Trim();
int 中奖人数 = (DtCJNO.Rows[]["中奖人数"] == null) ? : Convert.ToInt32(DtCJNO.Rows[]["中奖人数"].ToString().Trim());
int 已经抽取 = (DtCJNO.Rows[]["已经抽取"] == null) ? : Convert.ToInt32(DtCJNO.Rows[]["已经抽取"].ToString().Trim());
int 批次数 = (DtCJNO.Rows[]["批次数"] == null) ? : Convert.ToInt32(DtCJNO.Rows[]["批次数"].ToString().Trim());
//、、----------------------------------------------------------
int 已抽奖批数 = ;
int _MaxNum = Convert.ToInt32(Math.Floor(中奖人数 * 1.0 / 批次数));//每批抽奖最少人数
//、、----------------------------------------------------------
int Max = _MaxNum;
for (int i = ; i <= 批次数; i++)
{
if (i == 批次数)
{
Max = 中奖人数 - (Max * (i - ));
}
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[已抽奖批数 + ];
}
//--------------------------------------------------------------------------------------------
//抽奖程序异常,调整。
if (已经抽取 != Count)
{
Pze.IsTrue = false;
//已经抽取的人数 设置为系统后台抽奖的实际总人数
已经抽取 = Count;
//已经抽取 除以 每次抽取人数 然后取最小整数,作为已经抽奖完成的批次
Pze.YJIsidNum = Convert.ToInt32(Math.Floor(已经抽取 * 1.0 / _MaxNum));
//本次抽奖人数
Pze.ThisNum = Pze.Dic[已经抽取 + ] - (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 < ) //.必须不能重复
{
lst.Add(yg);
}
if (lst.Count == Num)//如果等于设定数量自动跳出
{
break;
}
}
//循环随机获取一个员工
while (true)
{
Random ran = new Random();//
int i = ran.Next(DrCJItem.Length - );
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 < )//.必须不能重复
{
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 = ;//组块高度;
int Hs = ;//竖向高度 组块高度+间距
int W = ;//组块宽度
int JG = ;//组块高度间隔;
int Nqueue = ;//最大放几排;
int NC = ;//每排人数
int YJG = ;//组块Y轴间隔;
int Mark = ;//基数;需要大于等于93
//--------------------------------------------
int Hts = ;//组块高度;
int Hsts = ;//竖向高度 组块高度+间距
int Wts = ;//组块宽度
int JGts = ;//组块高度间隔; int Nqueuets = ;//最大放几排;
int NCts = ;//每排人数
int YJGts = ;//组块Y轴间隔;
int XJGts = ;//X轴间隔;
int KJGts = ;//空白间隔;
//--------------------------------------------
H = Convert.ToInt32(Math.Floor(ThisHeight * 1.0 / Num)) - ;
W = H * (NoLength + ) + H * + ;//"Num+1":每个小框的间隔;"H * 3":留足3个空位填名字,+4留足每排的间隔
//组块宽度>容器宽度
if (W > ThisWidth)//只放一排
{
W = Convert.ToInt32(ThisWidth * 1.0);
H = Convert.ToInt32(
(
(ThisWidth - ) * 1.0
) / (Num + + )
);
JG = Convert.ToInt32(
Math.Floor(
(
ThisHeight - H * Num
) * 1.0 / Num
)
);
for (int i = ; i < lst.Count; i++)
{
ContrlSet(, i * (H + JG), W, NoLength, LstYg, lst[i].YG_NO, lst[i].YG_Name, blcj);
}
}
else
{
Hts = ;
Wts = ;
Hsts = ;
YJGts = ;
Nqueuets = ;
NCts = ;
Nqueue = Convert.ToInt32(Math.Floor(ThisWidth * 1.0 / W));//最多可以放多少排!
//多排计算方式
for (int i = ; i <= Nqueue; i++)
{
H = ;//小模块高度;
W = ;//小木块宽度;
NC = Convert.ToInt32(Math.Ceiling(Num * 1.0 / i));//总人数 / 排数 每排人数
H = Convert.ToInt32(Math.Floor((ThisHeight) * 1.0 / NC)) - ;
Hs = H + ;
W = H * (NoLength + ) + H * + ;//"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 - - NC) * 1.0 / (NC + ))) - ;
Hs = H + ;
}
//-------------------------------------------------------------------------
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 = ;
for (int j = ; j < NC; j++)
{
Counts = j;
for (int t = ; t < Nqueue; t++)
{
Counts = j * Nqueue + t;
ContrlSet(t * (W + ), j * (H + YJG), W, NoLength, LstYg, lst[Counts].YG_NO, lst[Counts].YG_Name, blcj);
if (Counts == lst.Count - )
{
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[];
for (int i = ; 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 - ) * 1.0
) / (N + + )
);
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 - ;
uc.W = uc.Height - ;
//----------------------------------------------------------------------
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[];
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 + ).ToString() + "轮奖";
lb抽奖状态.Text = "当前正在抽取第" + (prize.YJIsidNum + ).ToString() + "轮奖";
DataTable DtTemp = ReYg();//所有参与人员表
//---------------------------------------------
lstyg = SetZJNum(DtTemp, prize.ThisNum, prize.Item);
LoadContrl(lstyg, YgNoLength, prize.ThisNum, panel1.Width - , 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 = ; 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 > )
{
int Count = ;
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 = ; i < LstUcnum.Count; i++)
{
Count = Count + ;
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 = ;
try
{
NumTemp = Convert.ToInt32(dt.Rows[]["已经抽取"]);
}
catch (Exception )
{
NumTemp = ;
}
//------------------------------------
//保存已经并汇总已经抽奖过的
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 / ));
int lw2 = Convert.ToInt32(Math.Floor(lbPrizeTile.Width * 1.0 / ));
int lw3 = Convert.ToInt32(Math.Floor(lb标语.Width * 1.0 / ));
lbPrizeTile.Location = new System.Drawing.Point(lw - lw2, ); //位置
lb标语.Location = new System.Drawing.Point(lw - lw3, ); //位置 //---------------------------------------------------------------------------
int lwgsmc = Convert.ToInt32(Math.Floor(LbGSMC.Width * 1.0 / ));
LbGSMC.Location = new System.Drawing.Point(lw - lwgsmc, ); //位置
//---------------------------------------------------------------------------
int PX = Convert.ToInt32(Math.Floor((H - ) * 1.0 / ));
PMeiun.Location = new System.Drawing.Point(, PX); //位置
SY1 = PX;
SY2 = PX + ;
//---------------------------------------------------------------------------
groupBox1.Location = new System.Drawing.Point(W - groupBox1.Width - , PX); //位置
//----------------------------------------------------------------------------
} private void timer1_Tick(object sender, EventArgs e)
{
if (this.mouseLocation.X < && mouseLocation.Y > SY1 && mouseLocation.Y < SY2)
{
PMeiun.Width = ;
PMeiun.Height = ;
Cursor = Cursors.Hand;
}
else
{
PMeiun.Width = ;
PMeiun.Height = ;
}
}
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 + ).ToString() + "轮奖";
lb抽奖状态.Text = "当前正在抽取第" + (prize.YJIsidNum + ).ToString() + "轮奖";
DataTable DtTemp = ReYg();//所有参与人员表
//---------------------------------------------
lstyg = SetZJNum(DtTemp, prize.ThisNum, prize.Item);
LoadContrl(lstyg, YgNoLength, prize.ThisNum, panel1.Width - , 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 = ; 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 - , 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 = ;
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 = ; 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
年会抽奖 抽奖系统 抽奖软件 C# Winform的更多相关文章
-
分布式抽奖秒杀系统,DDD架构设计和实现分享
作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 一.用大项目,贯穿知识体系 写CRUD.堆API.改屎山⛰,熬多少个996也只是成为重复的螺丝 ...
-
CentOS系统更换软件安装源aliyun的
CentOS系统更换软件安装源第一步:备份你的原镜像文件,以免出错后可以恢复. mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS ...
-
Linux桌面系统常用软件和笔记(更新)
(一).下文涉及到的环境 manjaro.deepin.Arch等 有些可以通用 有些不可以通用 (二).常用软件下载 一.桌面美化软件 1.桌面壁纸下载软件: varirety 下载方式:可以在多个 ...
-
MAC mojave版本系统 破解软件
MAC mojave版本系统 破解软件 1 :Adobe Photoshop CC 2019.0.1 Mac中文破解版 2 :Office 2019 16.19 Mac中文破解版 3 :Paralle ...
-
【swupdate文档 三】SWUpdate: 嵌入式系统的软件升级
SWUpdate: 嵌入式系统的软件升级 概述 本项目被认为有助于从存储媒体或网络更新嵌入式系统.但是,它应该主要作为一个框架来考虑,在这个框架中可以方便地向应用程序添加更多的协议或安装程序(在SWU ...
-
【swupdate文档 一】嵌入式系统的软件管理
嵌入式系统的软件管理 嵌入式系统变得越来越复杂, 它们的软件也反映了这种复杂性的增加. 为了支持新的特性和修复,很有必要让嵌入式系统上的软件 能够以绝对可靠的方式更新. 在基于linux的系统上,我们 ...
-
符合AUTOSAR(AP&;CP)的嵌入式系统和软件设计工具
AUTOSAR Builder功能介绍 AUTOSAR Builder 是达索旗下一种基于 Eclipse 的开放性.可扩展工具套件,用于设计和开发符合 AUTOSAR 标准的系统和软件.最新版本20 ...
-
Turtlebot3入门教程-系统-SBC软件设置(ubuntu20.04)
本文针对如何在树莓派3上安装ubuntu20.04系统和软件进行讲解 树莓派3接上显示屏和鼠标后,开机后继续安装软件包 详细步骤如下: (1)系统安装 (2)ROS安装 (3)TurboBot3依赖的 ...
-
docker开源系统监控软件Nagios
开源的系统监控软件 下面整理了3个: 1.Zabbix 2.Nagios 3.Open-Falcon 这位博主进行的完整的介绍: https://www.cnblogs.com/linuxandy/p ...
随机推荐
-
iOS 自定义NavigationBar右侧按钮rightBarButtonItem--button
//两个按钮的父类view UIView *rightButtonView = [[UIView alloc] initWithFrame:CGRectMake(, , , )]; //历史浏览按钮 ...
-
解决iPhone中overflow:scroll;滑动速度慢或者卡的问题
在移动端html中经常出现横向/纵向滚动的效果,但是在iPhone中滚动速度很慢,感觉不流畅,有种卡卡的感觉,但是在安卓设备上没有这种感觉; 要解决这个问题很简单: 一行代码搞定 -webkit-ov ...
-
windows7 professional.iso
目前使用的笔记本是PC,在重新安装系统的时候,我比较挑剔. 我希望它是原样的,我希望它能够 windows update,拥有 office 2007/2003,它的个人文件夹就原封不动地在默认在 C ...
-
JDBC读取新插入Oracle数据库Sequence值的5种方法
Oracle的sequence实现非常灵活,所以也带来一些易用性问题,如何取到新插入记录生成的sequence值与其它数据库有较大差别,本文详国介绍了5种实现读取新插入记录sequence值的方法. ...
-
postconf 命令常用参数
postfix的main.cf配置文件一般不直接编辑,而多使用postconf命令来配置‘ postconf -d:查看默认配置: postconf -n:查看当前配置(即当前生效的配置): post ...
-
求N个元素的子集合个数
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt406 一个集合有n个元素,请问怎么算出来它的子集(包括空集和本身)是 2的n ...
-
exp和imp的使用场合
1.检测冲突 使用exp工具,在数据库中预先检测到物理或逻辑冲突. 导出的同时,将全扫描数据库中的每张表,读出所有行.如果某处表中有个损坏的块,必然能找到它. 2.可以用来快速恢复数据库. 使用exp ...
-
JSP编译成Servlet(二)语法树的遍历——访问者模式
语法树可以理解成是一种数据结构,假如某些语句已经被解析成一棵语法树,那么接下来就是要对此语法树进行处理,但考虑到不将处理操作与数据结构混合在一块,我们需要一种方法将其分离.其实对于语法树的处理最典型的 ...
-
Flink部署-standalone模式
Flink部署-standalone模式 2018年11月30日 00:07:41 Xlucas 阅读数:74 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.cs ...
-
Java笔记Spring(三)
spring-beans和spring-context 一.注解 1.自定义一个注解 @Target({ElementType.METHOD}) @Retention(RetentionPolicy. ...