private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lstRaspberryRelays.SelectedItems.Count == 0)
            {
                DataValidationMesaage.NoSelectedItemFromList("لیست دستگاه ها و رله ها");

                return;
            }

            DataBaseDataContext myConnection = Setting.DataBase;

            #region RaspBerryPlayingBoard Cast

            int playingBoardId = (int)((RaspBerryPlayingBoard)lstRaspberryRelays.SelectedItems[0].Tag).PlayingBoardID;

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

                return;
            }

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

            DialogResult message = DataValidationMesaage.ConfirmDeleteData(raspBerryPlayingBoard.RaspberryPin.PinNumber);

            if (message == DialogResult.Yes)
            {
                raspBerryPlayingBoard.RaspberryPin.IsAvailable = true;

                RaspBerryPlayingBoard.Delete(raspBerryPlayingBoard, myConnection);

                myConnection.SubmitChanges();

                DataValidationMesaage.DeleteMessage();

                RaspberryPin.LoadComboBoxAvailables(cmbRaspberryRelay, myConnection);

                RaspBerryPlayingBoard.ShowList(lstRaspberryRelays, myConnection);
            }

            myConnection.Dispose();
        }
Example #2
0
        private void btnPayment_Click(object sender, EventArgs e)
        {
            if (gridMember.SelectedRows.Count == 0)
            {
                DataValidationMesaage.NoSelectedItemFromList(gridMember.Text);

                return;
            }

            DataBaseDataContext myConnection = Setting.DataBase;

            #region RentPlayingBoard Cast

            int rentid = memberRentPlayingBoard.RentPlayingBoardID;

            if (!RentPlayingBoard.Validation(rentid, myConnection))
            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

            RentPlayingBoard rentPlayingBoard = RentPlayingBoard.Get(rentid, myConnection);

            #endregion

            if (radioOther.Checked)
            {
                #region Member Cast

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

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

                    return;
                }

                _member = Member.Get(id, myConnection);

                #endregion
            }

            if (radioMySelf.Checked)
            {
                #region Member Cast

                int id = memberRentPlayingBoard.Member.ID;

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

                    return;
                }

                _member = Member.Get(id, myConnection);

                #endregion
            }

            RentPlayingBoard myRentPlayingBoard = RentPlayingBoard.Edit(rentPlayingBoard,
                                                                        DateTime.Now.ToString("HH:mm:ss"), false, myConnection);

            MemberRentPlayingBoard closerMemberRentPlayingBoard = MemberRentPlayingBoard.Insert(myRentPlayingBoard, _member, "Closer", myConnection);

            myRentPlayingBoard.PlayingBoardType.PlayingBoard.IsAvailable = true;

            int playingBoardID = myRentPlayingBoard.PlayingBoardType.PlayingBoardID;

            #region Raspberry Check and Turn off

            if (myConnection.RaspBerryPlayingBoards.Any(a => a.PlayingBoardID.Equals(playingBoardID)))
            {
                if (!RaspBerryPlayingBoard.Validation_By_PlayingBoardID(playingBoardID, myConnection))
                {
                    DataValidationMesaage.NoDataInBank();

                    return;
                }

                #region RaspBerryPlayingBoard Cast

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

                #endregion

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

            #endregion

            bool isCredit = true && cmbIsCredit.SelectedText.Equals("نسیه");

            bool isCard = true && radioCard.Checked;

            if (string.IsNullOrWhiteSpace(txtPrice.Text.Trim()) || string.IsNullOrEmpty(txtPrice.Text.Trim()))
            {
                DataValidationMesaage.BlankTextBox("مبلغ پرداختی");

                return;
            }

            if (isCard)
            {
                if (string.IsNullOrWhiteSpace(txtCardPaymentIdentity.Text.Trim()) || string.IsNullOrEmpty(txtCardPaymentIdentity.Text.Trim()))
                {
                    DataValidationMesaage.BlankTextBox("شناسه پرداخت");

                    return;
                }

                if (myConnection.CardSerialPayments.Any(a => a.CardPaymentIdentity.Equals(txtCardPaymentIdentity.Text.Trim())))
                {
                    DataValidationMesaage.DuplicateData("شناسه پرداخت");

                    return;
                }
            }

            Payment payment = Payment.Insert(int.Parse(txtPrice.Text.Trim()), DateTime.Now, isCredit, isCard, "", closerMemberRentPlayingBoard.ID, _member, myConnection);

            if (isCard)
            {
                CardSerialPayment.Insert(txtCardPaymentIdentity.Text.Trim(), txtCardNumber.Text.Trim(),
                                         txtAccountNumber.Text.Trim(), payment, (BankAccount)cmbBankAccount.SelectedItem, myConnection);
            }

            myConnection.SubmitChanges();



            MessageBox.Show("بازی تمام شد.");

            DialogResult message = MessageBox.Show(
                "پرداخت انجام شد و میز بازی بسته شد. آیا مایل هستید پنجره جاری بسته شود؟ ",
                "کاربر گرامی", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (message == DialogResult.Yes)
            {
                this.Close();
            }
            myConnection.Dispose();
        }
Example #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();
        }