public static void Edit(RaspberryPin raspberryPin, string pinNumber, bool isAvailable,
                                DataBaseDataContext connection)
        {
            raspberryPin.PinNumber = pinNumber;

            raspberryPin.IsAvailable = isAvailable;

            connection.SubmitChanges();
        }
        public static RaspberryPin Insert(string pinNumber, bool isAvailable, DataBaseDataContext connection)
        {
            RaspberryPin raspberryPin = new RaspberryPin(pinNumber, isAvailable);

            connection.RaspberryPins.InsertOnSubmit(raspberryPin);

            connection.SubmitChanges();

            return(raspberryPin);
        }
        private void FrmSetRaspberryRelays_Load(object sender, EventArgs e)
        {
            DataBaseDataContext myConnection = Setting.DataBase;

            RaspBerryPlayingBoard.ShowList(lstRaspberryRelays, myConnection);

            RaspberryPin.LoadComboBoxAvailables(cmbRaspberryRelay, myConnection);

            PlayingBoardGroupTitle.LoadComboBox(cmbPlayingBoardGroupTitle, myConnection);

            if (myConnection.PlayingBoardGroupTitles.Any())
            {
                #region PlayingBoardGroupTitle Cast

                int playingBoardGroupTitleId = ((PlayingBoardGroupTitle)cmbPlayingBoardGroupTitle.SelectedItem).ID;

                if (!PlayingBoardGroupTitle.Validation(playingBoardGroupTitleId, myConnection))
                {
                    DataValidationMesaage.NoDataInBank();

                    return;
                }

                PlayingBoardGroupTitle playingBoardGroupTitle = PlayingBoardGroupTitle.Get(playingBoardGroupTitleId,
                                                                                           myConnection);

                #endregion

                PlayingBoardTitle.LoadComboBox_By_PlayingBoardGroupTitle(cmbPlayingBoardTitle, playingBoardGroupTitle,
                                                                         myConnection);

                if (myConnection.PlayingBoardTitles.Any(a => a.PlayingBoardGroupTitle.Equals(playingBoardGroupTitle)))
                {
                    #region PlayingBoardTitle Cast

                    int playingBoardTitleId = ((PlayingBoardTitle)cmbPlayingBoardTitle.SelectedItem).ID;

                    if (!PlayingBoardTitle.Validation(playingBoardTitleId, myConnection))
                    {
                        DataValidationMesaage.NoDataInBank();

                        return;
                    }

                    PlayingBoardTitle playingBoardTitle = PlayingBoardTitle.Get(playingBoardTitleId, myConnection);

                    #endregion

                    PlayingBoard.LoadComboBoxByFilter(cmbPlayingBoard, playingBoardTitle, myConnection);
                }
            }
        }
Exemple #4
0
        //public static List<int> ReservedPins = new List<int>
        //{1, 2, 4, 6, 9, 14, 17, 20, 25, 27, 28, 30, 34};

        //public static List<int> GpioPins = new List<int>()
        //{3, 5, 7, 8, 10, 11, 12, 13, 15, 16, 18, 19, 21, 22, 23, 24, 26, 29, 31, 32, 33, 35, 36, 37};

        public static RaspBerryPlayingBoard Insert(RaspberryPin raspberryPin, PlayingBoard playingBoard, DataBaseDataContext connection)
        {
            RaspBerryPlayingBoard raspBerryPlayingBoard = new RaspBerryPlayingBoard();

            raspBerryPlayingBoard.RaspberryPin = raspberryPin;

            raspBerryPlayingBoard.PlayingBoard = playingBoard;

            connection.RaspBerryPlayingBoards.InsertOnSubmit(raspBerryPlayingBoard);

            connection.SubmitChanges();

            return(raspBerryPlayingBoard);
        }
        public static void PowerOnOff(RaspberryPin raspberryPin, string message, string ipAddress, int portNumber)
        {
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
                                     ProtocolType.Udp);

            IPAddress serverIPAddr = IPAddress.Parse(ipAddress);

            IPEndPoint endPoint = new IPEndPoint(serverIPAddr, portNumber);

            byte[] send_buffer =
                Encoding.ASCII.GetBytes(message + "," + (int.Parse(raspberryPin.PinNumber) - 1));

            sock.SendTo(send_buffer, endPoint);
        }
        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();
        }
        public static void Delete(RaspberryPin raspberryPin, DataBaseDataContext connection)
        {
            connection.RaspberryPins.DeleteOnSubmit(raspberryPin);

            connection.SubmitChanges();
        }
Exemple #8
0
        public static void Edit(RaspBerryPlayingBoard raspBerryPlayingBoard, PlayingBoard playingBoard, RaspberryPin raspberryPin,
                                DataBaseDataContext connection)
        {
            raspBerryPlayingBoard.RaspberryPin = raspberryPin;

            raspBerryPlayingBoard.PlayingBoard = playingBoard;

            connection.SubmitChanges();
        }
Exemple #9
0
        static void Main()
        {
            DataBaseDataContext myConnection = Setting.DataBase;

            if (!myConnection.DatabaseExists())
            {
                myConnection.CreateDatabase();

                #region Insert RaspberryPins

                for (int i = 1; i <= 24; i++)
                {
                    RaspberryPin.Insert(i.ToString(), true, myConnection);
                }

                #endregion

                #region Insert SocialNetworkTypes

                SocialNetworkType.Insert("اینستاگرام", myConnection);
                SocialNetworkType.Insert("تلگرام", myConnection);
                SocialNetworkType.Insert("وایبر", myConnection);
                SocialNetworkType.Insert("وی چت", myConnection);
                SocialNetworkType.Insert("توییتر", myConnection);
                SocialNetworkType.Insert("لینکداین", myConnection);
                SocialNetworkType.Insert("فیسبوک", myConnection);

                #endregion

                #region Insert PhoneOperators

                Phone.Insert("ایرانسل", myConnection);
                Phone.Insert("همراه اول", myConnection);
                Phone.Insert("رایتل", myConnection);
                Phone.Insert("تالیا", myConnection);
                Phone.Insert("تلفن ثابت", myConnection);

                #endregion

                #region Insert Levels

                Level.Insert("طلایی", myConnection);
                Level.Insert("نقره ای", myConnection);
                Level.Insert("برنزی", myConnection);
                Level.Insert("VIP", myConnection);

                #endregion

                #region BankAccounts

                BankAccount.Insert("کشاورزی", "", "", myConnection);
                BankAccount.Insert("ملی", "", "", myConnection);
                BankAccount.Insert("ملت", "", "", myConnection);


                #endregion
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FrmMain());
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            DataBaseDataContext myConnection = Setting.DataBase;

            if (cmbPlayingBoard.SelectedItem == null)
            {
                DataValidationMesaage.NoSelectedItemFromList("لیست میزهای بازی");

                return;
            }

            #region PlayingBoard Cast

            int playingBoardId = ((PlayingBoard)cmbPlayingBoard.SelectedItem).ID;

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

                return;
            }

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

            #endregion

            #region RaspberryPin Cast

            int raspberryPinID = ((RaspberryPin)cmbRaspberryRelay.SelectedItem).ID;

            if (!RaspberryPin.Validation(raspberryPinID, myConnection))
            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

            RaspberryPin raspberryPin = RaspberryPin.Get(raspberryPinID, myConnection);

            #endregion

            if (myConnection.RaspBerryPlayingBoards.Any(a => a.PlayingBoard == playingBoard))
            {
                MessageBox.Show("برای این میز بازی یک رله اختصاص داده شده است.", "کاربر گرامی", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return;
            }

            RaspBerryPlayingBoard.Insert(raspberryPin, playingBoard, myConnection);

            raspberryPin.IsAvailable = false;

            myConnection.SubmitChanges();

            DataValidationMesaage.AcceptMessage();

            RaspberryPin.LoadComboBoxAvailables(cmbRaspberryRelay, myConnection);

            RaspBerryPlayingBoard.ShowList(lstRaspberryRelays, myConnection);
        }