Example #1
0
        private void btnPick_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.InitialDirectory = "d:\\";
                openFileDialog.Filter           = "文本文件|*.txt|C#文件|*.cs|所有文件|*.*";
                openFileDialog.RestoreDirectory = true;
                openFileDialog.FilterIndex      = 1;
                if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string path     = openFileDialog.FileName;
                    string fileName = path.Split('\\')[path.Split('\\').Length - 1];
                    string fileType = fileName.Split('.')[1];

                    txtFile.Text = fileName;

                    byte[] buffer      = File.ReadAllBytes(path);
                    string fileContent = Convert.ToBase64String(buffer);

                    BaersTool.DB.Data data = new BaersTool.DB.Data("UploadFile");
                    data["FileName"]    = fileName;
                    data["FileType"]    = fileType;
                    data["FileContent"] = fileContent;
                    data.Insert();

                    System.Windows.MessageBox.Show("文件上传成功!");
                }
            }
            catch (Exception ex)
            {
                BaersTool.Log.LogOperate.WriteLog(ex.ToString(), DateTime.Now.ToString("yyyy_MM_dd") + ".log", System.Windows.Forms.Application.StartupPath + "\\LogFiles");
                throw;
            }
        }
Example #2
0
        /// <summary>
        /// 初始化游戏
        /// 1、生产54张牌
        /// 2、发牌
        /// add by baer
        /// </summary>
        public void initCard()
        {
            //获取本局游戏唯一标志
            gameGuid = Guid.NewGuid().ToString();

            //游戏信息入库
            BaersTool.DB.Data data = new BaersTool.DB.Data("GameInfo");
            data["GameGuid"] = gameGuid;
            data.Insert();

            //玩家信息入库
            foreach (Player player in players)
            {
                data               = new BaersTool.DB.Data("GameAndPlayer");
                data["GameGuid"]   = gameGuid;
                data["PlayerGuid"] = player.PlayerGuid;
                data.Insert();
            }

            //生产54张牌,并插入数据库
            BaersTool.DB.Data db;
            for (int no = 1; no < 55; no++)
            {
                int point, color;
                getPointAndColor(no, out point, out color);
                db             = new BaersTool.DB.Data("GameCards");
                db["No"]       = no;
                db["Point"]    = point;
                db["Color"]    = color;
                db["GameGuid"] = gameGuid;
                db.Insert();
            }

            #region 发牌
            string   strSql  = "select * from GameCards where GameGuid = '" + gameGuid + "' order by RowGuid";
            DataView dvCards = BaersTool.DB.Data.ExecuteToDataView(strSql);
            for (int i = 0; i < dvCards.Count; i++)
            {
                db = new BaersTool.DB.Data("GameCards", Convert.ToString(dvCards[i]["RowGuid"]));
                if (i < 17)
                {
                    db["PlayerGuid"] = players[0].PlayerGuid;
                    db["CardType"]   = (int)GameCardType.玩家;
                }
                else if (i < 34)
                {
                    db["PlayerGuid"] = players[1].PlayerGuid;
                    db["CardType"]   = (int)GameCardType.玩家;
                }
                else if (i < 51)
                {
                    db["PlayerGuid"] = players[2].PlayerGuid;
                    db["CardType"]   = (int)GameCardType.玩家;
                }
                else
                {
                    db["CardType"] = (int)GameCardType.地主;
                }
                db.Update();
            }
            #endregion

            printCards();

            //轮询获取地主
            getLandload(0);
        }