C#实例代码之抽奖升级版可以经表格数据导入数据库,抽奖设置,补抽

我写代码一直是这个风格,废话不多,直接给大家贴代码,现在还是老规矩,具体代码如下所示:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;
using System.IO;
namespace Check_Ticket
{
public partial class Btn_UpLoadFile : Form
{
string conn = "server=WIN-OUDREHCH;database=Xtf;uid=sa;pwd=";
string sql = "";
int CurNum = ;//奖项人数
int second = ;//防止二次被抽取
Hashtable hashtable = new Hashtable();//存储编号
Hashtable hashtable = new Hashtable();//存储获奖名单
Hashtable hashtable = new Hashtable();//避免二次抽奖
Dictionary<int, string> dict = new Dictionary<int, string>();//词典存储所有参赛者
Random rd = new Random();
int time = ;
Label[] label = new Label[];
int index = ;//词典key键值
int total = ;//label个数
int num = ;//获奖总数
string s = "";
int End = ;//抽奖结束
public Btn_UpLoadFile()
{
InitializeComponent();
}
private void Form_Load(object sender, EventArgs e)
{
dataGridView.ForeColor = Color.Blue;
menu.Visible = false;
comboBox.SelectedIndex = ;
this.timer.Interval = ;
this.timer.Interval = ;
this.timer.Enabled = true;
this.WindowState = FormWindowState.Maximized;
}
private void getNumber(string s)
{
SqlConnection myconn = new SqlConnection(conn);
myconn.Open();
sql = "select *from SumPrize";
SqlDataAdapter da = new SqlDataAdapter(sql, myconn);
DataSet ds = new DataSet();
da.Fill(ds);
switch (s)
{
case "一等奖":
second = ;
CurNum = Convert.ToInt(ds.Tables[].Rows[]["PrizeNum"].ToString());
break;
case "二等奖":
second = ;
CurNum = Convert.ToInt(ds.Tables[].Rows[]["PrizeNum"].ToString());
break;
case "三等奖":
second = ;
CurNum = Convert.ToInt(ds.Tables[].Rows[]["PrizeNum"].ToString());
break;
case "四等奖":
second = ;
CurNum = Convert.ToInt(ds.Tables[].Rows[]["PrizeNum"].ToString());
break;
case "五等奖":
second = ;
CurNum = Convert.ToInt(ds.Tables[].Rows[]["PrizeNum"].ToString());
break;
case "六等奖":
second = ;
CurNum = Convert.ToInt(ds.Tables[].Rows[]["PrizeNum"].ToString());
break;
case "请选择":
CurNum = ;
break;
default:
break;
}
}
private void button_Click(object sender, EventArgs e)
{
SqlConnection myconn = new SqlConnection(conn);
myconn.Open();
//未选择抽奖项
if (CurNum == )
{
MessageBox.Show("未设置该奖项或未选择奖项,抽奖没有意义!!!");
return;
}
//处理已经被抽奖项
if (!hashtable.ContainsValue(second))
{
comboBox.Enabled = true;
hashtable.Add(second, second);
}
else
{
MessageBox.Show("此奖项已经被抽过,换个奖项吧?");
return;
}
string prize = comboBox.Text.ToString();
string sqlCount = "Select sum(PrizeNum) as num from SumPrize";
SqlDataAdapter sda = new SqlDataAdapter(sqlCount, myconn);
DataSet ds = new DataSet();
sda.Fill(ds);
//设置有奖总人数
num = Convert.ToInt(ds.Tables[].Rows[]["num"].ToString());
for (int i = ; i < dataGridView.RowCount-; i++)
{
dict.Add(index, dataGridView.Rows[i].Cells["WorkerID"].Value.ToString() + " " + dataGridView.Rows[i].Cells["Name"].Value.ToString());
index++;
}
myconn.Close();
timer.Start();
clearLabel();
bornLabel();
timer.Enabled = true;
comboBox.Enabled = false;
}
private void button_Click(object sender, EventArgs e)
{
End = ;
menu.Text = "";
hashtable.Clear();
clearLabel();
button.Enabled = true;
button.Enabled = true;
button.Enabled = false;
menu.Visible = false;
btnAdd.Visible = false;
tbNum.Visible = false;
ge.Visible = false;
addEnd.Visible = false;
lab.Text = "中奖名单";
dataGridView.Visible = false;
string sqlChecked = "delete from Checked";
sql = "select *from Ticket";
SqlConnection myconn = new SqlConnection(conn);
myconn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql, myconn);
DataSet ds = new DataSet();
sda.Fill(ds, "Ticket");
dataGridView.DataSource = ds;
dataGridView.DataMember = "Ticket";
SqlCommand mycomm = new SqlCommand(sqlChecked, myconn);
mycomm.ExecuteNonQuery();
myconn.Close();
}
private void button_Click(object sender, EventArgs e)
{
menu.Visible = false;
clearLabel();
sql = "select WorkerIDAndName,Prize from Checked order by PrizeID";
SqlConnection myconn = new SqlConnection(conn);
myconn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql, myconn);
DataSet ds = new DataSet();
sda.Fill(ds, "Checked");
dataGridView.DataSource = ds;
dataGridView.DataMember = "Checked";
dataGridView.Visible = true;
menu.Text += "恭喜:\n";
for(int i=;i<dataGridView.RowCount-;i++)
{
menu.Text += dataGridView.Rows[i].Cells["WorkerIDAndName"].Value.ToString() +" 获得"+ dataGridView.Rows[i].Cells["Prize"].Value.ToString() + "\n";
}
menu.Visible = true;
timer.Start();
myconn.Close();
}
private void button_Click(object sender, EventArgs e)
{
new SetPeople().ShowDialog();
}
private void comboBox_SelectedValueChanged(object sender, EventArgs e)
{
getNumber(comboBox.Text.ToString());
}
private void timer_Tick(object sender, EventArgs e)
{
lab.Left = lab.Left - ;
if (lab.Right < )
{
lab.Left = this.Width;
}
}
//创建labels
private void bornLabel()
{
int i = ;
for (i = ; i < CurNum; i++)
{
label[i] = new Label();
label[i].ForeColor = Color.Blue;
label[i].Location = new System.Drawing.Point(, + (i * ));
label[i].Size = new System.Drawing.Size(, );
label[i].BackColor = Color.Transparent;
label[i].Anchor = (AnchorStyles.Top);
label[i].Font = new System.Drawing.Font("SimSun", , FontStyle.Bold);
this.Controls.Add(label[i]);
}
total = i;
}
//清除labels
private void clearLabel()
{
for (int i = ; i < total; i++)
{
this.Controls.Remove(label[i]);
}
}
private void timer_Tick(object sender, EventArgs e)
{
hashtable.Clear();
hashtable.Clear();
SqlConnection con = new SqlConnection(conn);
string sql = "select count(*) from Ticket";
SqlCommand com = new SqlCommand(sql, con);
con.Open();
int emcount = Convert.ToInt(com.ExecuteScalar());
con.Close();
timer.Enabled = true;
timer.Interval = time;
int i;
for (i = ; i < CurNum; i++)
{
int random = Convert.ToInt(rd.Next(, emcount));
if (dataGridView.Rows[random].Cells["Checked"].Value.ToString().Trim()==""
&& !hashtable.ContainsValue(dict[random]))
{
hashtable.Add(random,random);
hashtable.Add(dict[random], dict[random]);
label[i].Text = dict[random];
}
else
{
i--;
}
}
}
private void button_Click(object sender, EventArgs e)
{
comboBox.Enabled = true;
SqlConnection con = new SqlConnection(conn);
con.Open();
string sql = "";
s = "";
timer.Stop();
foreach (DictionaryEntry de in hashtable)
{
sql = string.Format("insert into Checked(WorkerIDAndName,Prize,PrizeID) values('{}','{}','{}')", de.Value.ToString(), comboBox.Text.ToString(),second.ToString());
SqlCommand com = new SqlCommand(sql, con);
com.ExecuteNonQuery();
s += de.Value.ToString() +" ";
}
foreach (DictionaryEntry de in hashtable)
{
dataGridView.Rows[Convert.ToInt(de.Key)].Cells["Checked"].Value = "";
}
lab.Text = "恭喜: " + s + "获得" + comboBox.Text.ToString();
//判断抽奖结束
End = End + CurNum;
if (End == num)
{
button.Enabled = false;
//button.Enabled = false;
button.Enabled = true;
if (MessageBox.Show("抽奖结束,是否进行补抽,点击确定进行补抽,取消结束此次抽奖!", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
btnAdd.Visible = true;
tbNum.Visible = true;
ge.Visible = true;
addEnd.Visible = true;
}
}
}
private void timer_Tick(object sender, EventArgs e)
{
menu.Top = menu.Top - ;
if (menu.Bottom < )
{
menu.Top = this.Height-;
}
}
private void 关闭窗口ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnAdd_Click(object sender, EventArgs e)
{
CurNum = Convert.ToInt(tbNum.Text.ToString());
if (CurNum == )
{
MessageBox.Show("请输入补抽个数!!!", "温馨提示");
return;
}
End = End + CurNum;
if (End > Convert.ToInt(dataGridView.RowCount))
{
button.Enabled = false;
MessageBox.Show("抽奖超过参与人数无法进行补抽!","温馨提示");
return;
}
timer.Start();
clearLabel();
bornLabel();
}
private void addEnd_Click(object sender, EventArgs e)
{
btnAdd.Visible = false;
addEnd.Visible = false;
tbNum.Visible = false;
ge.Visible = false;
menu.Visible = false;
clearLabel();
sql = "select WorkerIDAndName,Prize from Checked order by PrizeID";
SqlConnection myconn = new SqlConnection(conn);
myconn.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql, myconn);
DataSet ds = new DataSet();
sda.Fill(ds, "Checked");
dataGridView.DataSource = ds;
dataGridView.DataMember = "Checked";
menu.Text += "恭喜:\n";
for (int i = ; i < dataGridView.RowCount - ; i++)
{
menu.Text += dataGridView.Rows[i].Cells["WorkerIDAndName"].Value.ToString() + " 获得" + dataGridView.Rows[i].Cells["Prize"].Value.ToString() + "\n";
}
menu.Visible = true;
timer.Start();
myconn.Close();
}
//先导入到dataSet
public DataSet getXSLData(string filepath)
{
string strCon = "Provider=Microsoft.ACE.OLEDB..;Data Source=" + filepath + ";Extended Properties=\"Excel .;HDR=YES;\"";
System.Data.OleDb.OleDbConnection Conn = new System.Data.OleDb.OleDbConnection(strCon);
string strCom = "SELECT * FROM [Sheet$]";
Conn.Open();
System.Data.OleDb.OleDbDataAdapter myCommand = new System.Data.OleDb.OleDbDataAdapter(strCom, Conn);
DataSet ds = new DataSet();
myCommand.Fill(ds, "[Sheet$]");
Conn.Close();
return ds;
}
public static int errorcount = ;//记录错误信息条数
public static int insertcount = ;//记录插入成功条数
public static int updatecount = ;//记录更新信息条数
public bool ImportXSL(string home)
{
try
{
DataSet ds = new DataSet();
//取得数据集
//调用上面的函数
ds = getXSLData(@home);
SqlConnection con = new SqlConnection(conn);
con.Open();
for (int i = ; i < ds.Tables[].Rows.Count; i++)
{
string WorkerID = ds.Tables[].Rows[i][].ToString();
string Name = ds.Tables[].Rows[i][].ToString();
string Checked = ds.Tables[].Rows[i][].ToString();
if (WorkerID != "" && Name != "")
{
string sq = string.Format("select * from Ticket where WorkerID='{}' and Name='{}'", WorkerID, Name);
SqlCommand selectcom = new SqlCommand(sq, con);
int count = Convert.ToInt(selectcom.ExecuteScalar());
if (count > )
{
updatecount++;
}
else
{
string s = string.Format("insert into Ticket(WorkerID,Name,Checked) values('{}','{}','{}')", WorkerID, Name,Checked);
SqlCommand insertcom = new SqlCommand(s, con);
int result = insertcom.ExecuteNonQuery();
insertcount++;
}
}
}
if (updatecount + insertcount == ds.Tables[].Rows.Count)
{
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
return false;
}
}
//导入excle
private void button_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Microsoft Excel files(*.xls)|*.xls;*.xlsx";//过滤一下,只要表格格式的
ofd.RestoreDirectory = true;
ofd.FilterIndex = ;
ofd.AddExtension = true;
ofd.CheckFileExists = true;
ofd.CheckPathExists = true;
ofd.ShowHelp = true;//是否显示帮助按钮
if (ofd.ShowDialog() == DialogResult.OK)
{
this.textBox.Text = ofd.FileName;
}
}
//导入excle表格
private void button_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conn);
con.Open();
//清空主键信息,标识自增从开始
string sqlstr = "truncate table Ticket";
SqlCommand comm = new SqlCommand(sqlstr,con);
comm.ExecuteNonQuery();
con.Close();
if (textBox.Text == "")
{
MessageBox.Show("请选择一张表格!!!", "温馨提示");
return;
}
if (ImportXSL(textBox.Text.ToString()))
{
MessageBox.Show(insertcount + "条数据导入成功!" + updatecount + "条数据重复!");
}
textBox.Text = "";
}
namespace Check_Ticket
{
partial class Btn_UpLoadFile
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.lab = new System.Windows.Forms.Label();
this.comboBox = new System.Windows.Forms.ComboBox();
this.button = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.button = new System.Windows.Forms.Button();
this.button = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.button = new System.Windows.Forms.Button();
this.lab = new System.Windows.Forms.Label();
this.timer = new System.Windows.Forms.Timer(this.components);
this.timer = new System.Windows.Forms.Timer(this.components);
this.button = new System.Windows.Forms.Button();
this.lab = new System.Windows.Forms.Label();
this.timer = new System.Windows.Forms.Timer(this.components);
this.menu = new System.Windows.Forms.Label();
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.附加功能ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.label = new System.Windows.Forms.Label();
this.btnAdd = new System.Windows.Forms.Button();
this.tbNum = new System.Windows.Forms.TextBox();
this.ge = new System.Windows.Forms.Label();
this.补抽ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.addEnd = new System.Windows.Forms.Button();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.button = new System.Windows.Forms.Button();
this.textBox = new System.Windows.Forms.TextBox();
this.button = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// lab
//
this.lab.AutoSize = true;
this.lab.BackColor = System.Drawing.Color.Blue;
this.lab.Font = new System.Drawing.Font("微软雅黑", .F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.lab.ForeColor = System.Drawing.Color.Red;
this.lab.Location = new System.Drawing.Point(, );
this.lab.Name = "lab";
this.lab.Size = new System.Drawing.Size(, );
this.lab.TabIndex = ;
this.lab.Text = "奖项名称:";
//
// comboBox
//
this.comboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox.ForeColor = System.Drawing.Color.Red;
this.comboBox.FormattingEnabled = true;
this.comboBox.Items.AddRange(new object[] {
"请选择",
"一等奖",
"二等奖",
"三等奖",
"四等奖",
"五等奖",
"六等奖"});
this.comboBox.Location = new System.Drawing.Point(, );
this.comboBox.Name = "comboBox";
this.comboBox.Size = new System.Drawing.Size(, );
this.comboBox.TabIndex = ;
this.comboBox.SelectedValueChanged += new System.EventHandler(this.comboBox_SelectedValueChanged);
//
// button
//
this.button.Enabled = false;
this.button.Font = new System.Drawing.Font("宋体", F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.button.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.button.Location = new System.Drawing.Point(, );
this.button.Name = "button";
this.button.Size = new System.Drawing.Size(, );
this.button.TabIndex = ;
this.button.Text = "开始抽奖";
this.button.UseVisualStyleBackColor = true;
this.button.Click += new System.EventHandler(this.button_Click);
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(, );
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = ;
this.dataGridView.Size = new System.Drawing.Size(, );
this.dataGridView.TabIndex = ;
this.dataGridView.Visible = false;
//
// button
//
this.button.Enabled = false;
this.button.Font = new System.Drawing.Font("宋体", F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.button.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.button.Location = new System.Drawing.Point(, );
this.button.Name = "button";
this.button.Size = new System.Drawing.Size(, );
this.button.TabIndex = ;
this.button.Text = "查看获奖名单";
this.button.UseVisualStyleBackColor = true;
this.button.Click += new System.EventHandler(this.button_Click);
//
// button
//
this.button.Font = new System.Drawing.Font("宋体", F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.button.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.button.Location = new System.Drawing.Point(, );
this.button.Name = "button";
this.button.Size = new System.Drawing.Size(, );
this.button.TabIndex = ;
this.button.Text = "人员加载";
this.button.UseVisualStyleBackColor = true;
this.button.Click += new System.EventHandler(this.button_Click);
//
// dataGridView
//
this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.GridColor = System.Drawing.Color.Black;
this.dataGridView.Location = new System.Drawing.Point(, );
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersVisible = false;
this.dataGridView.RowTemplate.Height = ;
this.dataGridView.Size = new System.Drawing.Size(, );
this.dataGridView.TabIndex = ;
this.dataGridView.Visible = false;
//
// button
//
this.button.Font = new System.Drawing.Font("宋体", F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.button.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.button.Location = new System.Drawing.Point(, );
this.button.Name = "button";
this.button.Size = new System.Drawing.Size(, );
this.button.TabIndex = ;
this.button.Text = "设置奖项对应人数";
this.button.UseVisualStyleBackColor = true;
this.button.Click += new System.EventHandler(this.button_Click);
//
// lab
//
this.lab.AutoSize = true;
this.lab.BackColor = System.Drawing.Color.Transparent;
this.lab.Font = new System.Drawing.Font("宋体", F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.lab.ForeColor = System.Drawing.Color.Blue;
this.lab.Location = new System.Drawing.Point(, );
this.lab.Name = "lab";
this.lab.Size = new System.Drawing.Size(, );
this.lab.TabIndex = ;
this.lab.Text = "获奖名单";
//
// timer
//
this.timer.Tick += new System.EventHandler(this.timer_Tick);
//
// timer
//
this.timer.Tick += new System.EventHandler(this.timer_Tick);
//
// button
//
this.button.Enabled = false;
this.button.ForeColor = System.Drawing.Color.Red;
this.button.Location = new System.Drawing.Point(, );
this.button.Name = "button";
this.button.Size = new System.Drawing.Size(, );
this.button.TabIndex = ;
this.button.Text = "停止抽奖";
this.button.UseVisualStyleBackColor = true;
this.button.Click += new System.EventHandler(this.button_Click);
//
// lab
//
this.lab.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.lab.AutoSize = true;
this.lab.BackColor = System.Drawing.Color.Transparent;
this.lab.Font = new System.Drawing.Font("华文新魏", F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.lab.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.lab.Location = new System.Drawing.Point(, );
this.lab.Name = "lab";
this.lab.Size = new System.Drawing.Size(, );
this.lab.TabIndex = ;
this.lab.Text = "善林商务年会抽奖活动";
//
// timer
//
this.timer.Tick += new System.EventHandler(this.timer_Tick);
//
// menu
//
this.menu.AutoSize = true;
this.menu.BackColor = System.Drawing.Color.Transparent;
this.menu.Font = new System.Drawing.Font("宋体", F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.menu.ForeColor = System.Drawing.Color.Blue;
this.menu.Location = new System.Drawing.Point(, );
this.menu.Name = "menu";
this.menu.Size = new System.Drawing.Size(, );
this.menu.TabIndex = ;
//
// menuStrip
//
this.menuStrip.BackColor = System.Drawing.Color.Transparent;
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ToolStripMenuItem,
this.附加功能ToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(, );
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(, );
this.menuStrip.TabIndex = ;
this.menuStrip.Text = "menuStrip";
//
// ToolStripMenuItem
//
this.ToolStripMenuItem.BackColor = System.Drawing.Color.Transparent;
this.ToolStripMenuItem.ForeColor = System.Drawing.Color.Blue;
this.ToolStripMenuItem.Name = "ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(, );
this.ToolStripMenuItem.Text = "关闭窗口";
this.ToolStripMenuItem.Click += new System.EventHandler(this.关闭窗口ToolStripMenuItem_Click);
//
// 附加功能ToolStripMenuItem
//
this.附加功能ToolStripMenuItem.Name = "附加功能ToolStripMenuItem";
this.附加功能ToolStripMenuItem.Size = new System.Drawing.Size(, );
//
// label
//
this.label.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.label.AutoSize = true;
this.label.ForeColor = System.Drawing.Color.Yellow;
this.label.Location = new System.Drawing.Point(, );
this.label.Name = "label";
this.label.Size = new System.Drawing.Size(, );
this.label.TabIndex = ;
this.label.Text = "---------------------------------------------------------------------------------" +
"------";
//
// btnAdd
//
this.btnAdd.ForeColor = System.Drawing.Color.Indigo;
this.btnAdd.Location = new System.Drawing.Point(, );
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(, );
this.btnAdd.TabIndex = ;
this.btnAdd.Text = "补抽";
this.btnAdd.UseVisualStyleBackColor = true;
this.btnAdd.Visible = false;
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// tbNum
//
this.tbNum.Location = new System.Drawing.Point(, );
this.tbNum.Name = "tbNum";
this.tbNum.Size = new System.Drawing.Size(, );
this.tbNum.TabIndex = ;
this.tbNum.Text = "";
this.tbNum.Visible = false;
//
// ge
//
this.ge.AutoSize = true;
this.ge.Font = new System.Drawing.Font("宋体", .F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.ge.Location = new System.Drawing.Point(, );
this.ge.Name = "ge";
this.ge.Size = new System.Drawing.Size(, );
this.ge.TabIndex = ;
this.ge.Text = "个";
this.ge.Visible = false;
//
// 补抽ToolStripMenuItem
//
this.补抽ToolStripMenuItem.Name = "补抽ToolStripMenuItem";
this.补抽ToolStripMenuItem.Size = new System.Drawing.Size(, );
//
// addEnd
//
this.addEnd.Location = new System.Drawing.Point(, );
this.addEnd.Name = "addEnd";
this.addEnd.Size = new System.Drawing.Size(, );
this.addEnd.TabIndex = ;
this.addEnd.Text = "补抽结束";
this.addEnd.UseVisualStyleBackColor = true;
this.addEnd.Visible = false;
this.addEnd.Click += new System.EventHandler(this.addEnd_Click);
//
// openFileDialog
//
this.openFileDialog.FileName = "openFileDialog";
//
// button
//
this.button.Location = new System.Drawing.Point(, );
this.button.Name = "button";
this.button.Size = new System.Drawing.Size(, );
this.button.TabIndex = ;
this.button.Text = "选择文件";
this.button.UseVisualStyleBackColor = true;
this.button.Click += new System.EventHandler(this.button_Click);
//
// textBox
//
this.textBox.Location = new System.Drawing.Point(, );
this.textBox.Name = "textBox";
this.textBox.Size = new System.Drawing.Size(, );
this.textBox.TabIndex = ;
//
// button
//
this.button.Location = new System.Drawing.Point(, );
this.button.Name = "button";
this.button.Size = new System.Drawing.Size(, );
this.button.TabIndex = ;
this.button.Text = "上传文件";
this.button.UseVisualStyleBackColor = true;
this.button.Click += new System.EventHandler(this.button_Click);
//
// Btn_UpLoadFile
//
this.AutoScaleDimensions = new System.Drawing.SizeF(F, F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Red;
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.button);
this.Controls.Add(this.textBox);
this.Controls.Add(this.button);
this.Controls.Add(this.addEnd);
this.Controls.Add(this.ge);
this.Controls.Add(this.tbNum);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.label);
this.Controls.Add(this.menu);
this.Controls.Add(this.lab);
this.Controls.Add(this.button);
this.Controls.Add(this.lab);
this.Controls.Add(this.button);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.button);
this.Controls.Add(this.button);
this.Controls.Add(this.comboBox);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.button);
this.Controls.Add(this.lab);
this.Controls.Add(this.menuStrip);
this.DoubleBuffered = true;
this.Font = new System.Drawing.Font("宋体", F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)()));
this.ForeColor = System.Drawing.Color.Purple;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.MainMenuStrip = this.menuStrip;
this.MaximumSize = new System.Drawing.Size(, );
this.MinimumSize = new System.Drawing.Size(, );
this.Name = "Btn_UpLoadFile";
this.ShowIcon = false;
this.Text = "抽奖界面";
this.Load += new System.EventHandler(this.Form_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lab;
private System.Windows.Forms.ComboBox comboBox;
private System.Windows.Forms.Button button;
private System.Windows.Forms.DataGridView dataGridView;
private System.Windows.Forms.Button button;
private System.Windows.Forms.Button button;
private System.Windows.Forms.DataGridView dataGridView;
private System.Windows.Forms.Button button;
private System.Windows.Forms.Label lab;
private System.Windows.Forms.Timer timer;
private System.Windows.Forms.Timer timer;
private System.Windows.Forms.Button button;
private System.Windows.Forms.Label lab;
private System.Windows.Forms.Timer timer;
private System.Windows.Forms.Label menu;
private System.Windows.Forms.MenuStrip menuStrip;
private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem;
private System.Windows.Forms.Label label;
private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.TextBox tbNum;
private System.Windows.Forms.Label ge;
private System.Windows.Forms.ToolStripMenuItem 附加功能ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem 补抽ToolStripMenuItem;
private System.Windows.Forms.Button addEnd;
private System.Windows.Forms.OpenFileDialog openFileDialog;
private System.Windows.Forms.Button button;
private System.Windows.Forms.TextBox textBox;
private System.Windows.Forms.Button button;
}
}
}
}

数据库设计

界面

好了,本文就给大家介绍这么多,有需要的朋友可以参考下本代码,根据自己实际需求适当加入,同时感谢大家一直以来对我们网站的支持。

(0)

相关推荐

  • C#操作LINQ to SQL组件进行数据库建模的基本教程

    建立实体类 使用LINQ to SQL时,需要首先建立用于映射数据库对象的模型,也就是实体类.在运行时,LINQ to SQL 根据LINQ表达式或查询运算符生成SQL语句,发送到数据库进行操作.数据库返回后,LINQ to SQL负责将结果转换成实体类对象. 建立实体类的方法有很多,例如LINQ to SQL设计器,手动编码建立,使用XML文件映射,使用命令行工具SqlMetal生成等.其中最方便的就是LINQ to SQL设计器. 1.使用LINQ to SQL设计器建立实体类       

  • C#连接数据库和更新数据库的方法

    对数据库的操作总体可以分为两类:查询(select)和更新(insert,delete,update).为什么这样来分呢?仔细看看两类的区别,select只是从数据库中将数据拿出来使用,而其余三者都会对数据库的物理数据进行修改.这篇文章将接着阐述更新数据. 更新数据库信息首先是连接数据库,对数据库的更新需要一个对象:OleDbCommand.该对象表示要对数据源执行的SQL语句或存储过程. 这个对象有三个属性:1.CommandText表示要设置命令的文本:2.Connection表示要设置命令

  • c#操作附加数据库的方法

    本文实例讲述了c#操作附加数据库的方法.分享给大家供大家参考.具体如下: /// <summary> /// 附加数据库 /// </summary> /// <returns></returns> private bool Attachdb() { try { string sql = string.Empty; if (File.Exists(sMDBFile)) { sql = "EXEC sp_attach_db @dbname = '&q

  • C#操作数据库中存取图片文件的方法

    本文实例讲述了C#操作数据库中存取图片文件的方法.分享给大家供大家参考.具体如下: private string sqlconnstr = "Data Source=.;Database=db_test;User id=sa;PWD=123456"; /*功能:把一种图片插入到数据库中 *返回值:无 */ void InsertImageToDB() { //将需要存储的图片读取为数据流 FileStream fs = new FileStream(@"D:/Bear.jpg

  • C#编程实现连接SQL SERVER数据库实例详解

    本文实例讲述了C#编程实现连接SQL SERVER数据库.分享给大家供大家参考,具体如下: 首先,在SQL SEVER里建立一个名为"Exercise"的数据库名,在该数据库下建立一张名为"lianxi"的表.好,现在开始写代码. 在FORM1里拖一个DATAGIRDVIEW用于显示表,在放一个BUTTON用于执行操作.加入命名空间 复制代码 代码如下: using system.data.sqlclient; private void button1_Click(

  • C#创建数据库及导入sql脚本的方法

    本文实例讲述了C#创建数据库及导入sql脚本的方法.分享给大家供大家参考,具体如下: C#创建数据库: /// <summary> /// 创建数据库 /// </summary> /// <param name="connStr">连接字符串</param> /// <param name="_strDBName">数据库名称</param> /// <returns></r

  • Asp.net(C#)读取数据库并生成JS文件制作首页图片切换效果(附demo源码下载)

    本文实例讲述了Asp.net(C#)读取数据库并生成JS文件制作首页图片切换效果的方法.分享给大家供大家参考,具体如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Text; using System.IO; public partial

  • C#程序连接数据库及读取数据库中字段的简单方法总结

    连接Access数据库 string connStr = @"Data Source=D:\database.mdb; Provider=Microsoft.Jet.OleDb.4.0;"; //数据库连接字符串 OleDbConnection conn = new OleDbConnection(connStr); 连接Oracle数据库 //数据库和客户端在同一台机器上 using System.Data.OracleClient; string connStr = "d

  • C#数据库操作的用法

    由于最近和数据库打交道,需要用C#和SQL Server 2005进行操作,就把近段时间内的最常用的操作做个总结.本人也是第一次用C#操作数据库,所以这三种典型用法对初学者还是挺有帮助的. 以下是我在visual studio 2005上写的一个类(连的是SQL Server 2005),已经过测试通过.里面有3个方法比较典型,源码如下: using System; using System.Collections.Generic; using System.Text; using System

  • C#实例代码之抽奖升级版可以经表格数据导入数据库,抽奖设置,补抽

    我写代码一直是这个风格,废话不多,直接给大家贴代码,现在还是老规矩,具体代码如下所示: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Imaging; using System.Linq; using System.Text; using System.Threadi

  • C++ 中实现把EXCEL的数据导入数据库(ACCESS、MSSQL等)实例代码

    C++ 中实现把EXCEL的数据导入数据库(ACCESS.MSSQL等)实例代码 在把EXCEL的数据导入数据库之前,先进行一些简单的准备工作: 1.把数据所在的EXCEL表另保存为DBF 4格式. 2.打开BCB,添加AdoTable(改名为DBFTable)和DataSource这两个控件 OK,准备工作,到此结束,剩下的就是打代码了 1.在Form_Load()事件中,加入以下代码: AnsiString filepath=ExtractFilePath(FileName); //File

  • asp.net下将纯真IP数据导入数据库中的代码

    纯真IP数据包含381085条,可以通过下载的查询软件将数据解压为文本格式,并将其编码改为UTF8,否则在程序中读取中文会乱码! 下面为程序执行分析IP数据并插入到Sql Server的截图: 程序通过AJAX在客户端进行数据插入实时更新: 实现代码如下: 前端页面及javascript: 复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or

  • 从vue基础开始创建一个简单的增删改查的实例代码(推荐)

    1.安装vue-cli    cnpm install vue-cli -g  --执行全局安装 2.创建一个webpack的基础项目:命令:vue init webpack myproject; 以下是项目的目录结构及说明 build是webpack配置 build.js       // 生产环境构建代码 check-versions.js // 检查node&npm等版本 utils.js          // 构建配置公用工具 vue-loader.conf.js // vue加载器

  • PHP读取CSV大文件导入数据库的实例

    PHP如何对CSV大文件进行读取并导入数据库? 对于数百万条数据量的CSV文件,文件大小可能达到数百M,如果简单读取的话很可能出现超时或者卡死的现象. 为了成功将CSV文件里的数据导入数据库,分批处理是非常必要的. 下面这个函数是读取CSV文件中指定的某几行数据: /** * csv_get_lines 读取CSV文件中的某几行数据 * @param $csvfile csv文件路径 * @param $lines 读取行数 * @param $offset 起始行数 * @return arr

  • PHP实现抽奖功能实例代码

    在项目开发中经常会遇到花钱抽奖类型的需求.但是老板总是担心用户用小钱抽到大奖.这样会导致项目亏损.下边这段代码可以有效制止抽奖项目亏钱. 个人奖池: 语言:thinkphp redis mysql 表:desire抽奖商品表 desire_log用户抽奖奖品表 user_desire_log用户抽奖记录表   desire_risk抽奖风控表 需求:用户奖池分为进行中奖池 和已完成奖池 当用户抽到大奖后 用户个人奖池重置 否则将继续抽奖 最后一次抽奖必中大奖 通过风控金额来判断用户是否可以抽大奖

  • JavaScript实现跑马灯抽奖活动实例代码解析与优化(一)

    最近做了个项目,其中有项目需求是要实现跑马灯抽奖效果,实现此功能主要用到js相关知识,废话不多说,感兴趣的朋友可以阅读下全文. 开始之前先来看上篇文章遗漏的两个问题和几个知识点,是自己重构的过程中需要用到的: 1.移动端1px像素线的问题 对于设计师给我的手机端网页的设计稿都是2倍图.按照道理来说,在写网页的时候,所有对象的实际尺寸都是会除2.但是对于1像素的线呢? 先来看两张图,设计稿的效果: 在三星 S4下的实际显示效果: 可以看到这个时候1px的线竟然显示不出来了.这个问题是跟 S4手机的

  • php获取用户真实IP和防刷机制的实例代码

    一. 如何获取用户IP地址 public static function getClientIp() { if (getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); } if (getenv('HTTP_X_REAL_IP')) { $ip = getenv('HTTP_X_REAL_IP'); } elseif (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FO

  • Angularjs2不同组件间的通信实例代码

    AngualrJs2官方方法是以@Input,@Output来实现组件间的相互传值,而且组件之间必须父子关系,下面给大家提供一个简单的方法,实现组件间的传值,不仅仅是父子组件,跨模块的组件也可以实现传值 /** *1.定义一个服务,作为传递参数的媒介 */ @Injectable() export class PrepService{ //定义一个属性,作为组件之间的传递参数,也可以是一个对象或方法 profileInfo: any; } /** *2.传递参数的组件,我这边简单演示,直接就在构

  • Angular动态添加、删除输入框并计算值实例代码

    Angular动态添加.删除输入框并计算值实例代码 摘要: 在学习群中交流时,有人分享了一个动态添加输入框的方法,我在其基础上进行了一些改进 这个功能本身并不复杂,但还是要注意,每个ng-model的对象必须是不同的,这样才能把它们分隔开. 下面是完整代码: JS: angular.module("myApp",[]) .controller("inputController",function($scope){ $scope.items=[]; //初始化数组,以

随机推荐