예제 #1
0
 private void Libera()
 {
     if (bHideFormON == true)
     {
         this.Hide();
     }
     else if (bHideFormON == false && EstacaoRUN == false)
     {
         this.Show();
         if (bAvisoTempoFim == true)
         {
             bAvisoTempoFim = false;
             LanHouseFacil_Util.MessageBoxTimer msg = new LanHouseFacil_Util.MessageBoxTimer();
             msg.Show("TEMPO", "O SEU TEMPO ACABOU!", 0, 15000);
             TravaNavegacao();
         }
     }
 }
예제 #2
0
        private void Conecta()
        {
            // Thread.Sleep(350);
            SocketON = true;
            System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();

            string appConfIP = ConfigurationManager.AppSettings["IPServer"].ToString();
            string NClient   = "E" + ConfigurationManager.AppSettings["NClient"].ToString();

            clientSocket.Connect(appConfIP, iPortServer);

            NClient = NClient + "|RUN=" + EstacaoRUN.ToString() + "|HIDDEN=" + bHideFormON.ToString() + "|DTNOW:" + DateTime.Now.ToShortTimeString();
            NetworkStream serverSteam = clientSocket.GetStream();

            byte[] outStream = System.Text.Encoding.ASCII.GetBytes(NClient + "$");
            serverSteam.Write(outStream, 0, outStream.Length);
            serverSteam.Flush();

            string returndata = "";

            byte[] inStream = new byte[10025];
            try
            {
                serverSteam.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
                returndata = System.Text.Encoding.ASCII.GetString(inStream);
            }
            catch
            {
            }
            if (bControl == true)
            {
                try
                {
                    tSocketAlert.Abort();
                    tSocketAlert.Join();
                }
                catch (ThreadAbortException t)
                {
                    //
                }

                try
                {
                    AddListBoxItem(returndata);
                }
                catch (Exception ex)
                {
                    AddListBoxItem(ex.Message);
                }
            }

            if (returndata.Length > 0)
            {
                //SocketON = true;
                //try
                //{
                //    tSocketAlert.Abort();
                //}
                //catch
                //{
                //}
                string[] arr = returndata.Split('|');

                for (int i = 0; i <= (arr.Length - 1); i++)
                {
                    if (arr[i].ToString().StartsWith("SHUTDOWN"))
                    {
                        lst[0].Shutdown = Convert.ToBoolean(arr[i].ToString().Replace("SHUTDOWN=", ""));

                        if (lst[0].Shutdown == true)
                        {
                            DesligaPC();
                        }
                    }

                    if (arr[i].ToString().StartsWith("REBOOT"))
                    {
                        lst[0].Reboot = Convert.ToBoolean(arr[i].ToString().Replace("REBOOT=", ""));

                        if (lst[0].Reboot == true)
                        {
                            ReiniciarPC();
                        }
                    }

                    if (arr[i].ToString().StartsWith("TSEND"))
                    {
                        string   val  = arr[i].Replace("TSEND=", "").ToString();
                        string[] varr = val.Split(':');
                        TimeSpan hr2  = new TimeSpan(Convert.ToInt32(varr[0]), Convert.ToInt32(varr[1]), 0);
                        lst[0].TSEnd = hr2;
                    }

                    if (arr[i].ToString().ToUpper().StartsWith("DTSTART="))
                    {
                        if (arr[i].Replace("DTSTART=", "") != "")
                        {
                            lst[0].DTStart = Convert.ToDateTime(arr[i].Replace("DTSTART=", ""));
                        }
                    }

                    if (arr[i].ToString().ToUpper().StartsWith("ESTACAORUN=T"))
                    {
                        lst[0].EstacaoRUN = true;

                        //  bAvisoMensagemCincoMinutos = true;
                    }
                    if (arr[i].ToString().ToUpper().StartsWith("ESTACAORUN=F"))
                    {
                        lst[0].EstacaoRUN = false;
                    }
                    if (arr[i].ToString().StartsWith("HS"))
                    {
                        HS = Convert.ToDateTime(arr[i].ToString().Replace("HS=", ""));
                    }

                    // TempoFIm();

                    #region AvisoCincoMinutos
                    int Hora     = 0;
                    int minuto   = 0;
                    int umminuto = 0;
                    Hora     = lst[0].TSEnd.Hours;
                    minuto   = Convert.ToInt32(lst[0].TSEnd.Minutes);
                    umminuto = umminuto - 1;
                    minuto   = minuto - 5;


                    //Thread.Sleep(400);
                    //if (lst[0].DTStart != null) // estacao devera esta ativa
                    //{
                    if (Convert.ToInt32(HS.Hour) <= Hora &&
                        minuto <= Convert.ToInt32(HS.Minute) &&
                        EstacaoRUN == true &&
                        bAvisoMensagemCincoMinutos == true)
                    {
                        if (bAvisoCincoMinutosRecebido == false)
                        {
                            bAvisoCincoMinutosRecebido = true;
                            bAvisoMensagemCincoMinutos = false;

                            // MessageBox.Show("Faltam 5 minutos para terminar o seu tempo!");
                            LanHouseFacil_Util.MessageBoxTimer msg = new LanHouseFacil_Util.MessageBoxTimer();

                            if (minuto >= Convert.ToInt32(HS.Minute))
                            {
                                msg.Show("MessageBox Timeout", "Faltam 5 minutos para terminar o seu tempo!", 0, 12000);
                                Thread.Sleep(2000);
                            }
                            //else if (umminuto == Convert.ToInt32(HS.Minute))
                            ////{
                            ////    msg.Show("MessageBox Timeout", "Falta 1 minuto para terminar o seu tempo!", 0, 9000);
                            ////    Thread.Sleep(2000);
                            ////}
                            //else
                            //{
                            //    msg.Show("MessageBox Timeout", "O seu tempo está terminando!", 0, 9000);
                            //    Thread.Sleep(2000);
                            //}
                        }
                    }
                    //}
                    #endregion

                    #region AtivaEstacao
                    if (lst[0].EstacaoRUN == true)
                    {
                        if (EstacaoRUN == false && bAvisoTempoFim == false)
                        {
                            TimeSpan ts = new TimeSpan(HS.TimeOfDay.Hours, HS.TimeOfDay.Minutes, 0);
                            //if (ts.Hours <= lst[0].TSEnd.Hours && ts.Minutes <= lst[0].TSEnd.Minutes)
                            if (ts <= lst[0].TSEnd)
                            {
                                bAvisoMensagemCincoMinutos = true;
                                bAvisoTempoFim             = false;

                                EstacaoRUN = true;
                                bTaskbar   = true;

                                TravarBTarefas();
                                bHideFormON = true;

                                LiberarNAvegacao();
                            }
                        }
                    }
                    #endregion
                }
                serverSteam.Flush();

                serverSteam.Dispose();
                clientSocket.Close();
                SocketON = false;
            }
        }