예제 #1
0
        private void btnYes_Click(object sender, EventArgs e)
        {
            PlayingBoard playingBoard = FrmPlayingBoard.SelectedPlayingBoard;

            if (int.Parse(txtPrice.Text.Trim()).Equals(0) || string.IsNullOrWhiteSpace(txtPrice.Text.Trim()) || string.IsNullOrEmpty(txtPrice.Text.Trim()))
            {
                DataValidationMesaage.BlankTextBox("بهای میز");

                return;
            }

            DataBaseDataContext myConnection = Setting.DataBase;

            PlayingBoardType playingBoardType = (PlayingBoardType)lstPlayingBoardTypes.SelectedItems[0].Tag;

            if (!PlayingBoardType.Validation(playingBoardType.ID, myConnection))
            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

            playingBoardType = PlayingBoardType.Get(playingBoardType.ID, myConnection);

            if (
                myConnection.PlayingBoardTypes.Any(
                    a =>
                    a.Type == cmbType.SelectedItem.ToString() && a.PlayingBoard == playingBoard &&
                    a.ID != playingBoardType.ID))
            {
                DataValidationMesaage.DuplicateData(cmbType.SelectedItem.ToString());

                return;
            }

            if (myConnection.PlayingBoardTypes.Any(a =>
                                                   a.PlayingBoard == playingBoard &&
                                                   !a.PlayingBoard.IsAvailable))
            {
                DataValidationMesaage.DataInUse("میز بازی", lstPlayingBoardTypes.Text);

                return;
            }

            PlayingBoardType.Edit(playingBoardType, cmbType.SelectedItem.ToString(),
                                  int.Parse(txtPrice.Text.Trim()), myConnection);

            DataValidationMesaage.EditMessage();

            PlayingBoardType.ShowList_By_PlayingBoard(playingBoard, lstPlayingBoardTypes, myConnection);

            FormManagement.DisableYesNo(this.Controls);

            myConnection.Dispose();

            clearTextBox();
        }
예제 #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lstPlayingBoardTypes.SelectedItems.Count == 0)
            {
                DataValidationMesaage.NoSelectedItemFromList(lstPlayingBoardTypes.Text);

                return;
            }

            DataBaseDataContext myConnection = Setting.DataBase;

            PlayingBoardType playingBoardType = (PlayingBoardType)(lstPlayingBoardTypes.SelectedItems[0].Tag);

            if (!PlayingBoardType.Validation(playingBoardType.ID, myConnection))
            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

            playingBoardType = PlayingBoardType.Get(playingBoardType.ID, myConnection);

            DialogResult message = DataValidationMesaage.ConfirmDeleteData(playingBoardType.Type);

            if (message == DialogResult.Yes)
            {
                PlayingBoardType.Delete(playingBoardType, myConnection);

                DataValidationMesaage.DeleteMessage();

                PlayingBoardType.ShowList_By_PlayingBoard(FrmPlayingBoard.SelectedPlayingBoard, lstPlayingBoardTypes,
                                                          myConnection);
            }

            myConnection.Dispose();
        }
예제 #3
0
        private void btnGameStart_Click(object sender, EventArgs e)
        {
            if (gridMember.SelectedRows.Count == 0)
            {
                DataValidationMesaage.NoSelectedItemFromList(gridMember.Text);

                return;
            }

            if (gridPlayingBoard.SelectedRows.Count == 0)
            {
                DataValidationMesaage.NoSelectedItemFromList(gridPlayingBoard.Text);

                return;
            }

            DataBaseDataContext myConnection = Setting.DataBase;

            #region PlayingBoard Cast

            int playingBoardId = int.Parse(gridPlayingBoard.SelectedRows[0].Cells[1].Value.ToString());

            if (!PlayingBoard.Validation(playingBoardId, myConnection))
            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

            PlayingBoard playingBoard = PlayingBoard.Get(playingBoardId, myConnection);

            #endregion

            #region Memeber Cast

            int memberId = int.Parse(gridMember.SelectedRows[0].Cells[1].Value.ToString());

            if (!Member.Validation(memberId, myConnection))
            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

            Member member = Member.Get(memberId, myConnection);
            #endregion

            if (!myConnection.PlayingBoardTypes.Any(a => a.PlayingBoard == playingBoard))
            {
                MessageBox.Show("برای این میز بازی هیچ قیمتی ثبت نشده است.", "کاربر گرامی", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return;
            }

            if (myConnection.RaspBerryPlayingBoards.Any(a => a.PlayingBoard == playingBoard))
            {
                #region RaspBerryPlayingBoard Cast

                if (!RaspBerryPlayingBoard.Validation_By_PlayingBoardID(playingBoardId, myConnection))
                {
                    DataValidationMesaage.NoDataInBank();

                    return;
                }

                RaspBerryPlayingBoard raspBerryPlayingBoard = RaspBerryPlayingBoard.Get_By_PlayingBoardID(playingBoardId, myConnection);

                #endregion

                MemberRentPlayingBoard.PowerOnOff(raspBerryPlayingBoard.RaspberryPin, "1", Setting.RaspberryIPAddress, Setting.RaspberryPortNumber);
            }

            #region PlayingBoardType Cast

            int playingBoardTypeID = ((PlayingBoardType)cmbPlayingBoardType.SelectedItem).ID;

            if (!PlayingBoardType.Validation(playingBoardTypeID, myConnection))
            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

            PlayingBoardType playingBoardType = PlayingBoardType.Get(playingBoardTypeID, myConnection);

            #endregion

            MyRentPlayingBoard = RentPlayingBoard.Insert(playingBoardType, DateTime.Now,
                                                         DateTime.Now.ToString("HH:mm:ss"), DateTime.Now.ToString("HH:mm:ss"), true, myConnection);

            MemberRentPlayingBoard.Insert(MyRentPlayingBoard, member, "opener", myConnection);


            playingBoard.IsAvailable = false;

            myConnection.SubmitChanges();

            PlayingBoard.LoadGridAvailables(gridPlayingBoard, myConnection);

            MessageBox.Show("بازی شروع شد.", "کاربر گرامی", MessageBoxButtons.OK,
                            MessageBoxIcon.Asterisk);

            myConnection.Dispose();
        }