示例#1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            lblHostName.Text = Dns.GetHostName();
            IPAddress[] ipa = Array.FindAll(Dns.GetHostEntry(string.Empty).AddressList, a => a.AddressFamily == AddressFamily.InterNetwork);
            LocalIP        = ipa[0].ToString();
            lblHostIP.Text = "本機IP=" + ipa[0].ToString();
            Array.Resize(ref SckSs, 1);
            Array.Resize(ref sckAccept, 1);
            Array.Resize(ref vec, 1);

            sckAccept[0] = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sckAccept[0].Bind(new IPEndPoint(IPAddress.Parse(LocalIP), port));
            sckAccept[0].Listen(5);
            SckSs[0] = new VESocket();
            vec[0]   = new VEClient();
            //SckSs[0].setSck();
            SckSsWaitAccept();
        }
示例#2
0
        // 初始化
        private void Initialize()
        {
            isLoadQuestion = false;
            myBook         = null;
            myExcel        = null;
            mySheet        = null;
            myRange        = null;
            question       = null;

            //把選項存入array

            /*selections[0] = radioButton1;
            *  selections[1] = radioButton2;
            *  selections[2] = radioButton3;
            *  selections[3] = radioButton4;*/

            timeCount     = TIME;   //預設15分鐘
            time          = new Timer();
            time.Interval = 1000;
            time.Tick    += new EventHandler(time_Tick);

            saveExam = new SaveExam();
            openExam = new OpenExam();

            ef  = new ExamForm();
            dlf = new DownloadForm();



            //veSocket = new VESocket(SignIn.IP);
            veSocket = new VESocket("219.85.200.148", SignIn.userName, SignIn.password);

            /*while(true)
             * {
             *  if(veSocket.getCorrect())
             *  {
             *      this.Show();
             *      break;
             *  }
             *
             * }*/
            toolStripStatusLabel2.Text = "連線中...";
            AddDownloadedExam();
        }
示例#3
0
        private void SckSAcceptProc()
        {
            Form.CheckForIllegalCrossThreadCalls = false;
            int Scki = SckCIndex;

            SckSs[Scki]     = new VESocket();
            vec[Scki - 1]   = new VEClient();
            sckAccept[Scki] = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                //Socket s = SckSs[Scki].getSck();
                //s = sckAccept.Accept();
                //SckSs[Scki].SckAccept(sckAccept);
                sckAccept[Scki] = sckAccept[0].Accept();
                accumulate++;
                lblAcc.Text = Convert.ToString(accumulate);
                //SckSs[Scki].setSck(s);
                SckSsWaitAccept();
                byte[] clientData = new byte[1024];
                while (true)
                {
                    // if (SckSs[Scki].getSck().Connected == true)
                    if (sckAccept[Scki].Connected == true)
                    {
                        //SckSs[Scki].getSck().Receive(clientData);
                        sckAccept[Scki].Receive(clientData);
                        BinaryFormatter  bf     = new BinaryFormatter();
                        MemoryStream     stream = new MemoryStream(clientData);
                        SQLiteDataReader sqlite_datareader;
                        object           obj = bf.Deserialize(stream);
                        if (obj.GetType() == vec[Scki - 1].GetType())
                        {
                            vec[Scki - 1] = (VEClient)obj;
                            //lblclientComputerName.Text = vec.getComputerName();
                            lblClientIpAddress.Text = vec[Scki - 1].getIpAddress();
                            listBox1.Items.Add(vec[Scki - 1].getComputerName());
                            //讀取SQLite

                            /*SQLiteConnection sqlite_conn = new SQLiteConnection();
                             * SQLiteCommand sqlite_cmd = new SQLiteCommand();
                             *
                             * bool isRepeated = true;
                             #region 檢查重複
                             *
                             * if (vec[Scki - 1].getCommand() == "檢查重複")
                             * {
                             *  sqlite_conn = new SQLiteConnection("Data source=" + SQLitePath.path);
                             *  sqlite_conn.Open();
                             *  sqlite_cmd = sqlite_conn.CreateCommand();
                             *  sqlite_cmd.CommandText = "SELECT * FROM UsersData";
                             *  sqlite_datareader = sqlite_cmd.ExecuteReader();
                             *  while (sqlite_datareader.Read())
                             *  {
                             *      if (sqlite_datareader["User"].ToString() == vec[Scki - 1].getUserName())
                             *      {
                             *          vec[Scki - 1].setCommand("重複");
                             *          Serialize(vec[Scki - 1], Scki);
                             *          isRepeated = true;
                             *          break;
                             *      }
                             *      isRepeated = false;
                             *  }
                             *  if (!isRepeated)
                             *  {
                             *      vec[Scki - 1].setCommand("可用");
                             *      Serialize(vec[Scki - 1], Scki);
                             *  }
                             *  sqlite_datareader.Close();
                             * }
                             #endregion
                             #region 註冊
                             * else if(vec[Scki - 1].getCommand()=="註冊")
                             * {
                             *  sqlite_conn = new SQLiteConnection("Data source=" + SQLitePath.path);
                             *  sqlite_conn.Open();
                             *  sqlite_cmd = sqlite_conn.CreateCommand();
                             *  sqlite_cmd.CommandText = "SELECT * FROM UsersData";
                             *  sqlite_cmd.ExecuteNonQuery();
                             *  sqlite_datareader = sqlite_cmd.ExecuteReader();
                             *  sqlite_cmd.CommandText = "INSERT INTO UsersData (User,Password,Name) VALUES('" + vec[Scki - 1].getUserName() + "','" + vec[Scki - 1].getPassword() + "','" + vec[Scki - 1].getName() + "')";
                             *  sqlite_cmd.ExecuteNonQuery();
                             *  sqlite_datareader.Close();
                             * }
                             #endregion
                             #region 登入
                             * else
                             * {
                             *  sqlite_conn = new SQLiteConnection("Data source=" + SQLitePath.path);
                             *  sqlite_conn.Open();
                             *  sqlite_cmd = sqlite_conn.CreateCommand();
                             *  sqlite_cmd.CommandText = "SELECT * FROM UsersData";
                             *  sqlite_datareader = sqlite_cmd.ExecuteReader();
                             *  bool isCorrceted = true;
                             *  while (sqlite_datareader.Read())
                             *  {
                             *      if (sqlite_datareader["User"].ToString() == vec[Scki - 1].getUserName())
                             *      {
                             *          if (sqlite_datareader["Password"].ToString() == vec[Scki - 1].getPassword())
                             *          {
                             *              vec[Scki - 1].setCommand("正確");
                             *              Serialize(vec[Scki - 1], Scki);
                             *              isCorrceted = true;
                             *              break;
                             *          }
                             *      }
                             *      isCorrceted = false;
                             *
                             *  }
                             *  if (!isCorrceted)
                             *  {
                             *      sckAccept[Scki].Close();
                             *  }
                             *  sqlite_datareader.Close();
                             *
                             * }
                             #endregion*/
                        }
                        else if (obj.GetType() == dlPath.GetType())
                        {
                            dlPath = (DownloadPath)obj;
                            sendMyExcelCollection(dlPath.getPath(), Scki);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.Message);
            }
        }