Exemplo n.º 1
0
        public static void showInfo(OnlineMessage message, MainForm form)
        {
            if (message != null && message.userinfo != null)
            {
                form.labelAeraValue.Text = message.userinfo.area_name;

                form.labelIPValue.Text = UintIP2String(message.userinfo.useripv4);
                DateTime time = GlobalFunction.unixTimestamp2DateTime(message.userinfo.acctstarttime * 1000);
                form.labelLoginTimeValue.Text = time.ToLocalTime().ToString();
                form.labelNameValue.Text      = message.userinfo.fullname;
                String balance = message.userinfo.balance / 100 + ".";
                balance += message.userinfo.balance % 100 < 10 ? ("0" + (message.userinfo.balance % 100).ToString()) : (message.userinfo.balance % 100).ToString();
                form.labelBalanceValue.Text  = balance;
                form.labelUsernameValue.Text = message.userinfo.username;
            }
            else
            {
                if (message.reply_code == AutoConnect.INVALID_PASSWORD)
                {
                    form.labelUsernameValue.Text = "密码错误";
                }
                else
                {
                    form.labelUsernameValue.Text = "未登录";
                }
                form.labelNameValue.Text      = "";
                form.labelIPValue.Text        = "";
                form.labelAeraValue.Text      = "";
                form.labelLoginTimeValue.Text = "";
                form.labelBalanceValue.Text   = "";
            }
        }
Exemplo n.º 2
0
        private void mainForm_Load(object sender, EventArgs e)
        {
            textBoxUsername.Text            = Properties.Settings.Default.username;
            textBoxPassword.Text            = Properties.Settings.Default.password;
            checkBoxAutoLogin.Checked       = Properties.Settings.Default.autoLogin;
            checkBoxReconnectOnFail.Checked = Properties.Settings.Default.autoReconnect;

            OnlineMessage onlineState = OnlineState.getOnlineState();

            if (onlineState.reply_code == OnlineState.OPERATE_SUCCESS && onlineState.reply_msg != null)
            {
                GlobalFunction.showInfo(onlineState, this);
            }

            if (checkBoxAutoLogin.Checked)
            {
                if (!textBoxUsername.Text.Equals("") && !textBoxPassword.Text.Equals(""))
                {
                    OnlineMessage ret = null;
                    do
                    {
                        ret = AutoConnect.connect(textBoxUsername.Text, textBoxPassword.Text);
                    } while (ret == null || ret.userinfo == null);
                    GlobalFunction.showInfo(ret, this);
                }
                this.WindowState = FormWindowState.Minimized;
            }
            if (Properties.Settings.Default.autoReconnect)
            {
                timer.Enabled = true;
            }
        }
Exemplo n.º 3
0
        public static OnlineMessage getOnlineState()
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(STATE_URL);

            request.Method = "POST";

            try
            {
                OnlineMessage returnMessage = null;
                do
                {
                    Stream requestStream = request.GetRequestStream();

                    HttpWebResponse            response       = (HttpWebResponse)request.GetResponse();
                    Stream                     responseStream = response.GetResponseStream();
                    DataContractJsonSerializer serializer     = new DataContractJsonSerializer(typeof(OnlineMessage));
                    returnMessage = (OnlineMessage)serializer.ReadObject(responseStream);
                    responseStream.Close();
                } while (returnMessage == null);

                return(returnMessage);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 4
0
 public static String getTip(OnlineMessage message)
 {
     String tip = "";
     tip += "接入区域:" + message.userinfo.area_name + "\n";
     tip += "服务类别:" + message.userinfo.service_name + "\n";
     String balance = message.userinfo.balance / 100 + ".";
     balance += message.userinfo.balance % 100 < 10 ? ("0" + (message.userinfo.balance % 100).ToString()) : (message.userinfo.balance % 100).ToString();
     balance += " 元";
     tip += "网费余额:" + balance + "\n";
     return tip;
 }
Exemplo n.º 5
0
        public static OnlineMessage getOnlineStateStrict()
        {
            OnlineMessage returnMessage = null;
            int           maxRetry      = 0;

            do
            {
                returnMessage = getOnlineState();
                maxRetry++;
            } while ((returnMessage == null || returnMessage.userinfo == null) && maxRetry < 5);
            return(returnMessage);
        }
Exemplo n.º 6
0
        public static OnlineMessage connect(String username, String password)
        {
            String postData = "username="******"&password="******"POST";
            request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";

            try
            {
                Stream       requestStream = request.GetRequestStream();
                StreamWriter streamWriter  = new StreamWriter(requestStream, Encoding.ASCII);
                streamWriter.Write(postData);
                streamWriter.Close();

                HttpWebResponse            response       = (HttpWebResponse)request.GetResponse();
                Stream                     responseStream = response.GetResponseStream();
                DataContractJsonSerializer serializer     = new DataContractJsonSerializer(typeof(ReturnMessage));
                ReturnMessage              returnMessage  = (ReturnMessage)serializer.ReadObject(responseStream);
                responseStream.Close();

                switch (returnMessage.reply_code)
                {
                case LOGIN_SUCCESS:
                case ALREADY_LOGGED_IN:
                    return(OnlineState.getOnlineStateStrict());

                case INVALID_PASSWORD:
                    OnlineMessage onlineMessage = new OnlineMessage();
                    onlineMessage.reply_code = returnMessage.reply_code;
                    onlineMessage.reply_msg  = returnMessage.reply_msg;
                    onlineMessage.userinfo   = null;
                    return(onlineMessage);

                case PROCESSING:
                default:
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 7
0
        public static void showInfo(OnlineMessage message, MainForm form)
        {
            form.labelAeraValue.Text = message.userinfo.area_name;

            form.labelIPValue.Text = UintIP2String(message.userinfo.useripv4);
            form.labelIPv6Value.Text = message.userinfo.useripv6;
            form.labelMACValue.Text = message.userinfo.mac;
            DateTime time = GlobalFunction.unixTimestamp2DateTime(message.userinfo.acctstarttime * 1000);
            form.labelLoginTimeValue.Text = time.ToLocalTime().ToString();
            form.labelNameValue.Text = message.userinfo.fullname;
            String balance = message.userinfo.balance / 100 + ".";
            balance += message.userinfo.balance % 100 < 10 ? ("0" + (message.userinfo.balance % 100).ToString()) : (message.userinfo.balance % 100).ToString();
            balance += " 元";
            form.labelBalanceValue.Text = balance;
            form.labelUsernameValue.Text = message.userinfo.username;

            form.labelUsernameValue.Text = message.userinfo.username;
        }
Exemplo n.º 8
0
        private void timer_Tick(object sender, EventArgs e)
        {
            OnlineMessage onlineState = OnlineState.getOnlineState();

            GlobalFunction.showInfo(onlineState, this);

            if (onlineState.reply_code == OnlineState.NO_PORTAL_MESSAGE)            //未登录
            {
                OnlineMessage ret = null;
                if (Properties.Settings.Default.username == "" || Properties.Settings.Default.password == "")
                {
                    ret = AutoConnect.connect(Properties.Settings.Default.username, Properties.Settings.Default.password);
                }
                else
                {
                    ret = AutoConnect.connect(textBoxUsername.Text, textBoxPassword.Text);
                }
                GlobalFunction.showInfo(ret, this);
            }
        }
Exemplo n.º 9
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            saveOptions();

            if (textBoxUsername.Text.Equals("") || textBoxPassword.Text.Equals(""))
            {
                MessageBox.Show("用户名和密码不能为空!", "Auto p.nju", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (checkBoxAutoLogin.Checked)
            {
                saveUsernameAndPassword();
            }
            else
            {
                clearUsernameAndPassword();
            }
            OnlineMessage ret = null;

            do
            {
                ret = AutoConnect.connect(textBoxUsername.Text, textBoxPassword.Text);
            } while (ret == null);

            if (ret.reply_code == AutoConnect.INVALID_PASSWORD)
            {
                timer.Enabled = false;
                MessageBox.Show(ret.reply_msg, "Oops", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //else if(ret.reply_code==AutoConnect.PROCESSING)
            //{
            //    timer.Enabled = false;
            //    MessageBox.Show(ret.reply_msg, "Oops", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            else
            {
                Thread.Sleep(1000);
                GlobalFunction.showInfo(OnlineState.getOnlineStateStrict(), this);
            }
        }
Exemplo n.º 10
0
        private void stateRefreshTimer_Tick(object sender, EventArgs e)
        {
            OnlineMessage onlineState = OnlineState.getOnlineState();

            GlobalFunction.showInfo(onlineState, this);
        }