基于C#实现简单的随机抽奖小程序
废话不多说了,直接给大家贴代码了。具体代码如下所示:
usingSystem; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Text; usingSystem.Threading.Tasks; usingSystem.Windows.Forms; usingSystem.Data.SqlClient; namespaceChouJiang { publicpartialclassForm1:Form { publicForm1() { InitializeComponent(); } privatevoidbutton1_Click(objectsender,EventArgse) { intnumber=Convert.ToInt32(textBox1.Text.ToString()); stringprize=comboBox1.Text.ToString(); stringconn=""; stringsql=""; strings=""; conn="server=XTFLZ-PC;database=Xtf;uid=sa;pwd=123456"; sql="select*fromTicket"; SqlConnectionmyconn=newSqlConnection(conn); myconn.Open(); SqlDataAdaptersda=newSqlDataAdapter(sql,myconn); DataSetds=newDataSet(); sda.Fill(ds,"Ticket"); dataGridView11.DataSource=ds; dataGridView11.DataMember="Ticket"; Randomrd=newRandom(); for(inti=0;i<number;i++) { inttmp=rd.Next(1,5); s+=dataGridView11.Rows[i].Cells["WorkerID"].Value.ToString()+ dataGridView11.Rows[i].Cells["Name"].Value.ToString()+"\n"; } MessageBox.Show("恭喜\n"+s+"\n获得"+prize); myconn.Close(); } } }
以上代码就是实现抽奖小程序的全部代码,代码简单易懂,写的不好还请见谅,有好的意见欢迎留言,谢谢大家一直以来对毛票票网站的支持。