首页 > 作文

C#模拟实现抽奖小程序的示例代码

更新时间:2023-04-04 08:58:52 阅读: 评论:0

1.抽奖主界面

2.操作步骤

s键开始;

0、1、2、3、4、5键分别对应6次奖项;

分别是 特等奖、一等奖、二等奖、三等奖、四等奖、五等奖

9键是加抽奖;

空格退出抽奖结果界面;

p键关闭气泡效果。

2.1 抽奖界面

2.2 抽奖结果导出

*************特等奖奖获得者:(抽奖时间:2021/12/30 22:41:22)***************工号:100899    姓名:石臻臻的杂货铺    领域:后端*************一等奖奖获得者:(抽奖时间:2021/12/30 22:42:09)***************工号:100931    姓名:牧羊人_阿标    领域:移动*************三等奖奖获得者:(抽奖时间:2021/12/30 22:42:17)***************工号:100978    姓名:前端老实人    领域:前端工号:100952    姓名:oliver尹    领域:前端工号:100990    姓名:愿许浪尽天涯    领域:运维与安全工号:101024    姓名:乔乔家的龙女仆    领域:其他*************特等奖奖获得者:(抽奖时间:2021/12/30 22:42:46)***************工号:100900    姓名:川川菜鸟    领域:大数据*************六等奖获得者:(抽奖时间:2021/12/30 22:42:51)***************工号:101013    姓名:忧伤额蜗牛    领域:移动工号:101017    姓名:ml.star    领域:后端工号:100921    姓名:坚果前端の博客    领域:移动工号:100986    姓名:mr数据杨    领域:全栈工号:100969    姓名:大数据小禅    领域:大数据工号:100898    姓名:小小明-代码实体    领域:其他工号:100949    姓名:执久呀    领域:后端工号:100977    姓名:yang_z_1    领域:大数据工号:100944    姓名:可可卷    领域:ai工号:100988    姓名:曲鸟    领域:全栈工号:101018    姓名:余光、    领域:前端工号:100962    姓名:拈花倾城    领域:运维与安全工号:100918    姓名:艾醒    领域:ai工号:100979    姓名:林深时不见鹿    领域:后端工号:100964    姓名:繁星蓝雨    领域:大数据工号:101022    姓名:互联网-小阿宇    领域:运维与安全工号:100980    姓名:振华oppo    领域:移动工号:100923    姓名:_陈哈哈    领域:全栈工号:100930    姓名:java执梗    领域:后端工号:100917    姓名:1_bit    领域:全栈

3.源码

3.1 数据库连接

using system;using system.collections.generic;using system.linq;using system.text;using system.data;using system.data.oledb;using system.collections;namespace boelottery.model{    public class lotterydatacontext    {               public lotterydatacontext()        {            if (!openconnection(connectionstring))            {                                return;            }            _datat=getdatat(sqlstr);            if (_datat!=null)            {                _datatable = _datat.tables[0];                rowdata = new list<keyvaluepair<int, int>>();            }            maxno=imaxno = getmaxnodb();            getdatabyte();            maxno = getmaxnodb()+1;                    }        private oledbdataadapter dataadapter = null;        private oledbconnection connection = null;        private string connectionstring = "provider=microsoft.jet.oledb.4.0;data source=data//lottery.mdb;jet oledb:databa password=123456";        string sqlstr = "lect *  from lottery ";               datat _datat = null;        datatable _datatable = null;        public int maxno {get;t;}        public int imaxno { get; t; }        /// <summary>        /// open connection        /// </summary>        /// <param name="connectionstring"></param>        /// <returns></returns>        public bool openconnection(string connectionstring)        {            try            {                connection = new oledbconnection(connectionstring);                connection.open();            }            catch (system.exception ex)            {                if (connection!=null)                {                    connection.clo();                }                return fal;            throw ex;                            }            return true;        }                public bool cloconnection()        {                        if (connection!=null)            {                connection.clo();            }            return true;        }        public datat getdatat(string sqlstring)        {            try            {                datat datat = new datat();                dataadapter = new oledbdataadapter(sqlstring, connection);                dataadapter.fill(datat);                return datat;            }            catch (system.exception ex)            {                throw ex;            }        }        public list<keyvaluepair<int,int>> rowdata { get; t; }        public oledbdatareader getdatareader(string sqlstring)        {            oledbcommand command = new oledbcommand(sqlstring, connection);            oledbdatareader datareader = command.executereader();            return datareader;        }        public void getdatabyte()        {            string data = helper.logger.readlog("system.data.datamangentextensions.dll");            string[] datasplit=data.split(';');            foreach (string item in datasplit)            {                getaddb(convert.toint32(item));            }        }        public int getmaxnodb()        {            //if (_datat.tables["lottery"].rows.count == 0) return 0; 对不对            return _datatable.rows.count;        }                /// <summary>        /// 根据id获取用户信息        /// </summary>        /// <param name="employeeid"></param>        /// <returns></returns>        public employee getquerydata(int employeeid)        {            employee employee = new employee();            employee.employeeid = employeeid;            ienumerable<datarow> querydata = from p in _datatable.anumerable() where (int)p.field<int16征文500字>("urid") == employeeid lect p;                        foreach(var data in querydata)            {                              employee.employeeno=data.field<string>("urno");               employee.employeename = data.field<string>("urname");               employee.employeedep = data.field<string>("urdep");               }            return employee;        }        /// <summary>        /// 根据employno获取用户信息        /// </summary>        /// <param name="employno"></param>        /// <returns></returns>        public employee getquerydatabyno(int employno)        {            ienumerable<datarow> querydata = from p in _datatable.anumerable() where p.field<string>("urno") == employno.tostring() lect p;            employee employee = new employee();            foreach (var data in querydata)            {                employee.employeeno= data.field<string>("urno");                employee.employeeid = (int)data.field<int16>("urid");                employee.employeename = data.field<string>("urname");                employee.employeedep = data.field<string>("urdep");            }            return employee;        }        public void getaddb(int employno)           {            ienumerable<datarow> querydata = from p in _datatable.anumerable() where p.field<string>("urno") == employno.tostring() lect p;            if (querydata.count() == 0) return;            datarow row = _datatable.newrow();                        foreach(var data in querydata)            {                                   row["urno"]=data.field<string>("urno");                              row["urid"] = getmaxnodb()+1;                                 rowdata.add(new keyvaluepair<int,int>((int)data.field<int16>("urid"), getmaxnodb() + 1));                                 //rowdata.add(new keyvaluepair<int,int>(getmaxnodb() + 1,(int)data.field<int16>("urid")));               //row["urid"] = (int)data.field<int16>("urid");               row["urname"] = data.field<string>("urname");               row["urdep"] = data.field<string>("urdep");                           }            _datatable.rows.add(row);        }    }}

3.2 抽奖程序

       //各奖项所有的人数 { 特等奖、一等奖、二等奖、三等奖、四等奖 }       public int[] winnernums = {4, 4, 12, 16, 40, 60, 80};                 //抽奖次数        public int[] lotterytimes = {4, 4, 3, 4, 2, 3, 4};                       public int[] hasnotwonnums=new int[7] ;//= { 5, 1, 1, 1, 12 };                        #endregion        #region 设置绑定icommand        public icommand startlotterycommand { get; private t; }        // 开始抽奖        public icommand speciallotterycommand { get; private t; }        //特等奖        public icommand firstlotterycommand { get; private t; }        public icommand condlotterycommand { get; private t; }        public icommand thirdlotterycommand { get; private t; }        public icommand fouthlotterycommand { get; private t; }        public icommand souvenirlotterycommand { get; private t; }        public icommand sixvenirlotterycommand { get; private t; }        public icommand extendlotterycommand { get; private t; }        //加抽奖        #endregion        public mainviewmodel()        {            //hasnotwonnums = lotterytimes;                     //未中奖的赋值            for (int i = 0; i < 7;i++ )            {                hasnotwonnums[i] = lotterytimes[i];            }            //getwinner();            //添加八个时钟            addtimer(10);                       startlotterycommand = new relaycommand(                ()=>{                    timerstart();                }                );            speciallotterycommand = new relaycommand(                ()=>                    {                                                logger.writelog("*************特等奖奖获得者:(抽奖时间:" + datetime.now.tostring() + ")***************");                        mesnger.default.nd("特等", "showresultgrade");                        lotterying(0);                                                //添加显示逻辑                    }                );            extendlotterycommand = new relaycommand(                () =>                {                    logger.writelog("*************加抽奖奖获得者:(抽奖时间:" + datetime.now.tostring() + ")***************");                                       timerstop();                                                                       list<employee> employwinners = getlotterylist(1);                    if (employwinners.count == 0)                    {                        return;                    }                    mesnger.default.nd("加抽", "showresultgrade");                    showresult(employwinners);                                        //添加显示逻辑                }                );            firstlotterycommand = new relaycommand(                ()=>                {                    logger.writelog("*************一等奖奖获得者:(抽奖时间:" + datetime.now.tostring() + ")***************");                    mesnger.default.nd("一等", "showresultgrade");                    lotterying(1);                                   }                );            condlotterycommand = new relaycommand(                ()=>                    {                        logger.writelog("*************二等奖奖获得者:(抽奖时间:" + datetime.now.tostring() + ")***************");                        mesnger.default.nd("二等", "showresultgrade");                        lotterying(2);                                            }                                    );            thirdlotterycommand = new relaycommand(                ()=>                    {                        logger.writelog("*************三等奖奖获得者:(抽奖时间:" + dateti元旦几月几号me.now.tostring() + ")***************");                        mesnger.default.nd("三等", "showresultgrade");                        lotterying(3);                                            }                );            fouthlotterycommand = new relaycommand(                () =>                   {                        logger.writelog("*************四等奖奖获得者:(抽奖时间:" + datetime.now.tostring() + ")***************");                        mesnger.default.nd("四等", "showresultgrade");                        lotterying(4);                   }                );            souvenirlotterycommand = new relaycommand(                ()=>                    {                        logger.writelog("*************五等奖获得者:(抽奖时间:" + datetime.now.tostring() + ")***************");                        mesnger.default.nd("五等", "showresultgrade");                        lotterying(5);                                            }                );            //public icommand sixvenirlotterycommand { get; private t; }            sixvenirlotterycommand = new relaycommand(               () =>               {       化学方程式配平            logger.writelog("*************六等奖获得者:(抽奖时间:" + datetime.now.tostring() + ")***************");                   mesn国庆云南旅游ger.default.nd("六等", "showresultgrade");                   lotterying(6);               }               );            mesnger.default.register<string>(this, "appclo",                (msg) =>                {                    logger.clo();                    lotterydatacontext.cloconnection();      高分子材料与工程专业         }                );        } 

以上就是c#模拟实现抽奖小程序的示例代码的详细内容,更多关于c#抽奖小程序的资料请关注www.887551.com其它相关文章!

本文发布于:2023-04-04 08:58:51,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/a6c6b1b47452c1ff61f477f3666dea6b.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:C#模拟实现抽奖小程序的示例代码.doc

本文 PDF 下载地址:C#模拟实现抽奖小程序的示例代码.pdf

标签:姓名   领域   获得者   时间
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图