예제 #1
0
        private ShortMessage ConvertByteToShortMessage(Byte[] data, int len)
        {
            String       Time;
            ShortMessage Message        = new ShortMessage();
            String       MessageContent = "";
            String       ResponseData   = System.Text.Encoding.UTF8.GetString(data, 0, len);

            String[] Cmd = ResponseData.Split(' ');
            if (Cmd[0] == "")
            {
                messageBox.Dispatcher.Invoke((Action) delegate { messageBox.Show("通讯故障,服务器传入空串。"); });
                System.Threading.Thread.Sleep(3000);
                Environment.Exit(0);
            }
            Message.SetId((int.Parse(Cmd[0])));
            Message.SetSendNumber(Cmd[1]);
            Message.SetReceiveNumber(Cmd[2]);
            Time = Convert.ToDateTime(Cmd[3]) + " " + Convert.ToDateTime(Cmd[4]);
            Message.SetTime(Convert.ToDateTime(Cmd[3] + " " + Cmd[4]));
            for (int i = 5; i < Cmd.Length - 1; i++)
            {
                MessageContent += Cmd[i];
                MessageContent += " ";
            }
            MessageContent += Cmd[Cmd.Length - 1];
            Message.SetContent(MessageContent);
            return(Message);
        }
예제 #2
0
        private void send_message_Click(object sender, RoutedEventArgs e)
        {
            if (ReplyBox.Text == "")
            {
                //this.StatusBar.Content = "不能发送空消息!";
                messageBox.Show("不能发送空消息!");
                return;
            }
            ShortMessage shortMessage = new ShortMessage(mainForm.openForm.client.GetPhoneNumber(), this.PhoneNumber, DateTime.Now, ReplyBox.Text);

            mainForm.openForm.client.MyDBController.Insert(shortMessage);
            shortMessage.SetId(mainForm.openForm.client.MyDBController.GetMessageId(shortMessage));
            mainForm.openForm.client.Send(shortMessage);

            //--------界面-----------
            //Messagebox.Items.Add(ReplyBox.Text);
            this.showMessage();
            ReplyBox.Clear();
        }
예제 #3
0
        public ArrayList GetMessageListByKeyWord(String keyWord)
        {
            reader.Close();
            ArrayList result = new ArrayList();

            sql    = @"select * from ShortMessage where Owner = '" + Owner + "' and  content like '%" + keyWord + "%'";
            cmd    = new SqlCommand(sql, conn);
            reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                ShortMessage msg = new ShortMessage();
                msg.SetId((int)reader[0]);
                msg.SetSendNumber(reader[2].ToString().Trim());
                msg.SetReceiveNumber(reader[3].ToString().Trim());
                //msg.SetTime(DateTime.Parse(reader[4].ToString().Trim()));
                msg.SetContent(reader[5].ToString().Trim());
                result.Add(msg);
            }
            reader.Close();
            return(result);
        }
예제 #4
0
        private void send_message_Click(object sender, RoutedEventArgs e)
        {
            ShortMessage shortMessage;

            if (NewmessageBox.Text == "")
            {
                messageBox.Show("不能发送空消息!");
                //this.StatusBar.Content = "不能发送空消息!";
                //MessageBox.Show("不能发送空消息!");
                return;
            }
            string phNum = textBox1.Text;

            String[] cmd = textBox1.Text.Split(' ');
            if (Timebox.IsChecked == true)
            {
                //DateTime time = DateTime.Parse(GetTime.SelectedDate.ToString() + ' ' + hour.Text + ' ' + min.Text + sec.Text);
                DateTime time;
                if (int.Parse(hour.Text) < 0 || int.Parse(hour.Text) > 24 || int.Parse(min.Text) < 0 || int.Parse(min.Text) > 60 || int.Parse(sec.Text) < 0 || int.Parse(sec.Text) > 60)
                {
                    messageBox.Show("输入时间有误");
                    return;
                }
                try
                {
                    time = (DateTime)GetTime.SelectedDate;
                }
                catch
                {
                    messageBox.Show("请输入日期!");
                    return;
                }
                time = time.AddHours((double.Parse(hour.Text)));
                time = time.AddMinutes((double.Parse(min.Text)));
                time = time.AddSeconds((double.Parse(sec.Text)));
                if (time < DateTime.Now)
                {
                    messageBox.Show("请选择将来的时间");
                    return;
                }
                else
                {
                    //ArrayList PhoneNumbers = new ArrayList();
                    for (int i = 0; i < cmd.Length; i++)
                    {
                        if (cmd[i].Length != 11)
                        {
                            if (cmd[i] == "")
                            {
                                continue;
                            }
                            //NumberForm numForm = new NumberForm();
                            messageBox.Show("号码格式错误!");
                            return;
                            //numForm.Show();
                        }
                        shortMessage = new ShortMessage(mainForm.openForm.client.GetPhoneNumber(), cmd[i], time, NewmessageBox.Text);
                        mainForm.openForm.client.MyDBController.Insert(shortMessage);
                        shortMessage.SetId(mainForm.openForm.client.MyDBController.GetMessageId(shortMessage));
                        mainForm.openForm.client.Send(shortMessage);
                    }
                    mainForm.UpdateMainForm();
                }
            }
            else
            {
                for (int i = 0; i < cmd.Length; i++)
                {
                    if (cmd[i].Length != 11)
                    {
                        if (cmd[i] == "")
                        {
                            continue;
                        }
                        //NumberForm numForm = new NumberForm();
                        messageBox.Show("号码格式错误!");
                        return;
                        //numForm.Show();
                    }
                    shortMessage = new ShortMessage(mainForm.openForm.client.GetPhoneNumber(), cmd[i], DateTime.Now, NewmessageBox.Text);
                    mainForm.openForm.client.MyDBController.Insert(shortMessage);
                    shortMessage.SetId(mainForm.openForm.client.MyDBController.GetMessageId(shortMessage));
                    mainForm.openForm.client.Send(shortMessage);
                    mainForm.UpdateMainForm();
                }
            }
            NewmessageBox.Clear();
            if (cmd.Length == 1)
            {
                DialogForm dialogForm = new DialogForm(mainForm, cmd[0]);
                dialogForm.Show();
                this.Hide();
            }
        }