欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#模擬實(shí)現(xiàn)抽獎(jiǎng)小程序的示例代碼

 更新時(shí)間:2021年12月31日 09:25:50   作者:IT邦德  
這篇文章主要介紹了通過(guò)C#模擬實(shí)現(xiàn)一個(gè)簡(jiǎn)單的抽獎(jiǎng)小程序,文中的示例代碼講解詳細(xì),對(duì)我們了解C#有一定的幫助,需要的可以參考一下

1.抽獎(jiǎng)主界面

2.操作步驟

S鍵開始;

0、1、2、3、4、5鍵分別對(duì)應(yīng)6次獎(jiǎng)項(xiàng);

分別是 特等獎(jiǎng)、一等獎(jiǎng)、二等獎(jiǎng)、三等獎(jiǎng)、四等獎(jiǎng)、五等獎(jiǎng)

9鍵是加抽獎(jiǎng);

空格退出抽獎(jiǎng)結(jié)果界面;

P鍵關(guān)閉氣泡效果。

2.1 抽獎(jiǎng)界面

2.2 抽獎(jiǎng)結(jié)果導(dǎo)出

*************特等獎(jiǎng)獎(jiǎng)獲得者:(抽獎(jiǎng)時(shí)間:2021/12/30 22:41:22)***************
工號(hào):100899    姓名:石臻臻的雜貨鋪    領(lǐng)域:后端

*************一等獎(jiǎng)獎(jiǎng)獲得者:(抽獎(jiǎng)時(shí)間:2021/12/30 22:42:09)***************
工號(hào):100931    姓名:牧羊人_阿標(biāo)    領(lǐng)域:移動(dòng)

*************三等獎(jiǎng)獎(jiǎng)獲得者:(抽獎(jiǎng)時(shí)間:2021/12/30 22:42:17)***************
工號(hào):100978    姓名:前端老實(shí)人    領(lǐng)域:前端
工號(hào):100952    姓名:Oliver尹    領(lǐng)域:前端
工號(hào):100990    姓名:愿許浪盡天涯    領(lǐng)域:運(yùn)維與安全
工號(hào):101024    姓名:?jiǎn)虇碳业凝埮?   領(lǐng)域:其他

*************特等獎(jiǎng)獎(jiǎng)獲得者:(抽獎(jiǎng)時(shí)間:2021/12/30 22:42:46)***************
工號(hào):100900    姓名:川川菜鳥    領(lǐng)域:大數(shù)據(jù)

*************六等獎(jiǎng)獲得者:(抽獎(jiǎng)時(shí)間:2021/12/30 22:42:51)***************
工號(hào):101013    姓名:憂傷額蝸牛    領(lǐng)域:移動(dòng)
工號(hào):101017    姓名:ML.star    領(lǐng)域:后端
工號(hào):100921    姓名:堅(jiān)果前端の博客    領(lǐng)域:移動(dòng)
工號(hào):100986    姓名:Mr數(shù)據(jù)楊    領(lǐng)域:全棧
工號(hào):100969    姓名:大數(shù)據(jù)小禪    領(lǐng)域:大數(shù)據(jù)
工號(hào):100898    姓名:小小明-代碼實(shí)體    領(lǐng)域:其他
工號(hào):100949    姓名:執(zhí)久呀    領(lǐng)域:后端
工號(hào):100977    姓名:yang_z_1    領(lǐng)域:大數(shù)據(jù)
工號(hào):100944    姓名:可可卷    領(lǐng)域:AI
工號(hào):100988    姓名:曲鳥    領(lǐng)域:全棧
工號(hào):101018    姓名:余光、    領(lǐng)域:前端
工號(hào):100962    姓名:拈花傾城    領(lǐng)域:運(yùn)維與安全
工號(hào):100918    姓名:艾醒    領(lǐng)域:AI
工號(hào):100979    姓名:林深時(shí)不見鹿    領(lǐng)域:后端
工號(hào):100964    姓名:繁星藍(lán)雨    領(lǐng)域:大數(shù)據(jù)
工號(hào):101022    姓名:互聯(lián)網(wǎng)-小阿宇    領(lǐng)域:運(yùn)維與安全
工號(hào):100980    姓名:振華OPPO    領(lǐng)域:移動(dòng)
工號(hào):100923    姓名:_陳哈哈    領(lǐng)域:全棧
工號(hào):100930    姓名:Java執(zhí)梗    領(lǐng)域:后端
工號(hào):100917    姓名:1_bit    領(lǐng)域:全棧

3.源碼

3.1 數(shù)據(jù)庫(kù)連接

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;
            }
            _dataSet=GetDataSet(sqlstr);
            if (_dataSet!=null)
            {
                _dataTable = _dataSet.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:Database Password=123456";
        string sqlstr = "select *  from lottery ";
       
        DataSet _dataSet = null;
        DataTable _dataTable = null;

        public int MaxNO {get;set;}
        public int IMaxNO { get; set; }
        /// <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.Close();
                }
                return false;
            	throw ex;
                
            }
            return true;

        }

        
        public bool CloseConnection()
        {
            
            if (connection!=null)
            {
                connection.Close();
            }
            return true;
        }

        public DataSet GetDataSet(string sqlString)
        {
            try
            {
                DataSet dataSet = new DataSet();
                dataAdapter = new OleDbDataAdapter(sqlString, connection);
                dataAdapter.Fill(dataSet);
                return dataSet;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

        }

        public List<KeyValuePair<int,int>> rowData { get; set; }

        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 (_dataSet.Tables["lottery"].Rows.Count == 0) return 0; 對(duì)不對(duì)

            return _dataTable.Rows.Count;

        }

        

        /// <summary>
        /// 根據(jù)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.AsEnumerable() where (int)p.Field<Int16>("userid") == employeeId select p;
            

            foreach(var data in queryData)
            {               
               employee.EmployeeNo=data.Field<string>("userno");
               employee.EmployeeName = data.Field<string>("username");
               employee.EmployeeDep = data.Field<string>("userdep");
   
            }
            return employee;
        }

        /// <summary>
        /// 根據(jù)EmployNo獲取用戶信息
        /// </summary>
        /// <param name="employNo"></param>
        /// <returns></returns>

        public Employee GetQueryDataByNo(int employNo)
        {
            IEnumerable<DataRow> queryData = from p in _dataTable.AsEnumerable() where p.Field<string>("userno") == employNo.ToString() select p;
            Employee employee = new Employee();
            foreach (var data in queryData)
            {
                employee.EmployeeNo= data.Field<string>("userno");
                employee.EmployeeID = (int)data.Field<Int16>("userid");
                employee.EmployeeName = data.Field<string>("username");
                employee.EmployeeDep = data.Field<string>("userdep");

            }
            return employee;

        }
        public void GetAdDB(int employNo)   
        {
            IEnumerable<DataRow> queryData = from p in _dataTable.AsEnumerable() where p.Field<string>("userno") == employNo.ToString() select p;
            if (queryData.Count() == 0) return;
            DataRow row = _dataTable.NewRow();
            
            foreach(var data in queryData)
            {     
               
               row["userno"]=data.Field<string>("userno");               
               row["userid"] = GetMaxNoDB()+1;
              
                   rowData.Add(new KeyValuePair<int,int>((int)data.Field<Int16>("userid"), GetMaxNoDB() + 1));
              
                   //rowData.Add(new KeyValuePair<int,int>(GetMaxNoDB() + 1,(int)data.Field<Int16>("userid")));
               //row["userid"] = (int)data.Field<Int16>("userid");
               row["username"] = data.Field<string>("username");
               row["userdep"] = data.Field<string>("userdep");

               
            }
            _dataTable.Rows.Add(row);

        }

    }
}

3.2 抽獎(jiǎng)程序

       //各獎(jiǎng)項(xiàng)所有的人數(shù) { 特等獎(jiǎng)、一等獎(jiǎng)、二等獎(jiǎng)、三等獎(jiǎng)、四等獎(jiǎng) }
       public int[] WinnerNums = {4, 4, 12, 16, 40, 60, 80};         
        //抽獎(jiǎng)次數(shù)
        public int[] LotteryTimes = {4, 4, 3, 4, 2, 3, 4};               
        public int[] HasNotWonNums=new int[7] ;//= { 5, 1, 1, 1, 12 };        
        


        #endregion

        #region 設(shè)置綁定ICommand
        public ICommand StartLotteryCommand { get; private set; }        // 開始抽獎(jiǎng)
        public ICommand SpecialLotteryCommand { get; private set; }        //特等獎(jiǎng)
        public ICommand FirstLotteryCommand { get; private set; }
        public ICommand SecondLotteryCommand { get; private set; }
        public ICommand ThirdLotteryCommand { get; private set; }
        public ICommand FouthLotteryCommand { get; private set; }
        public ICommand SouvenirLotteryCommand { get; private set; }
        public ICommand SixvenirLotteryCommand { get; private set; }


        public ICommand ExtendLotteryCommand { get; private set; }        //加抽獎(jiǎng)

        #endregion

        public MainViewModel()
        {

            //HasNotWonNums = LotteryTimes;                     //未中獎(jiǎng)的賦值
            for (int i = 0; i < 7;i++ )
            {
                HasNotWonNums[i] = LotteryTimes[i];
            }
            //GetWinner();
            //添加八個(gè)時(shí)鐘
            AddTimer(10);
           
            StartLotteryCommand = new RelayCommand(
                ()=>{
                    TimerStart();
                }
                );

            SpecialLotteryCommand = new RelayCommand(
                ()=>
                    {
                        
                        logger.WriteLog("*************特等獎(jiǎng)獎(jiǎng)獲得者:(抽獎(jiǎng)時(shí)間:" + DateTime.Now.ToString() + ")***************");
                        Messenger.Default.Send("特等", "showResultGrade");
                        Lotterying(0);
                        
                        //添加顯示邏輯

                    }
                );

            ExtendLotteryCommand = new RelayCommand(
                () =>
                {

                    logger.WriteLog("*************加抽獎(jiǎng)獎(jiǎng)獲得者:(抽獎(jiǎng)時(shí)間:" + DateTime.Now.ToString() + ")***************");
                   
                    TimerStop();                                                   
                    List<Employee> employWinners = GetLotteryList(1);
                    if (employWinners.Count == 0)
                    {
                        return;
                    }
                    Messenger.Default.Send("加抽", "showResultGrade");
                    ShowResult(employWinners);
                    
                    //添加顯示邏輯

                }
                );
            FirstLotteryCommand = new RelayCommand(
                ()=>
                {
                    logger.WriteLog("*************一等獎(jiǎng)獎(jiǎng)獲得者:(抽獎(jiǎng)時(shí)間:" + DateTime.Now.ToString() + ")***************");
                    Messenger.Default.Send("一等", "showResultGrade");
                    Lotterying(1);
                   
                }

                );
            SecondLotteryCommand = new RelayCommand(
                ()=>
                    {
                        logger.WriteLog("*************二等獎(jiǎng)獎(jiǎng)獲得者:(抽獎(jiǎng)時(shí)間:" + DateTime.Now.ToString() + ")***************");
                        Messenger.Default.Send("二等", "showResultGrade");
                        Lotterying(2);
                        
                    }
                    
                );
            ThirdLotteryCommand = new RelayCommand(
                ()=>
                    {
                        logger.WriteLog("*************三等獎(jiǎng)獎(jiǎng)獲得者:(抽獎(jiǎng)時(shí)間:" + DateTime.Now.ToString() + ")***************");
                        Messenger.Default.Send("三等", "showResultGrade");
                        Lotterying(3);
                        
                    }
                );
            FouthLotteryCommand = new RelayCommand(
                () =>
                   {
                        logger.WriteLog("*************四等獎(jiǎng)獎(jiǎng)獲得者:(抽獎(jiǎng)時(shí)間:" + DateTime.Now.ToString() + ")***************");
                        Messenger.Default.Send("四等", "showResultGrade");
                        Lotterying(4);

                   }
                );
            SouvenirLotteryCommand = new RelayCommand(
                ()=>
                    {
                        logger.WriteLog("*************五等獎(jiǎng)獲得者:(抽獎(jiǎng)時(shí)間:" + DateTime.Now.ToString() + ")***************");
                        Messenger.Default.Send("五等", "showResultGrade");
                        Lotterying(5);
                        
                    }
                );

            //public ICommand SixvenirLotteryCommand { get; private set; }
            SixvenirLotteryCommand = new RelayCommand(
               () =>
               {
                   logger.WriteLog("*************六等獎(jiǎng)獲得者:(抽獎(jiǎng)時(shí)間:" + DateTime.Now.ToString() + ")***************");
                   Messenger.Default.Send("六等", "showResultGrade");
                   Lotterying(6);

               }
               );

            Messenger.Default.Register<string>(this, "AppClose",
                (msg) =>
                {
                    logger.Close();
                    lotteryDataContext.CloseConnection();
               }
                );
        } 

以上就是C#模擬實(shí)現(xiàn)抽獎(jiǎng)小程序的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于C#抽獎(jiǎng)小程序的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論