Esempio n. 1
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);
        }
Esempio n. 2
0
 private void showMessage()
 {
     this.Messagebox.Items.Clear();
     messageList = mainForm.openForm.client.MyDBController.GetMessageListByPhoneNumber(this.PhoneNumber);
     if (messageList.Count == 0)
     {
     }
     for (int i = 0; i < messageList.Count; i++)
     {
         ShortMessage msg = (ShortMessage)messageList[i];
         //if(msg.GetContent().Length<999)//如果长度小于70字
         //{
         Messagebox.Items.Add("发送者:" + msg.GetSendNumber() + " 接收者:" + msg.GetReceiveNumber() + " 时间:" + msg.GetTime() + " 内容:" + msg.GetContent());
         //}
         //else
         //{
         ///MessageBox.Show("信息过长,无法显示!");
         //}
         //else
         //{
         //    int length = 70;
         //    int temp;
         //    for (int j = 0; j*length < msg.GetContent().Length; j++)
         //    {
         //        temp = j * length;
         //        if (msg.GetContent().Length - j * length <length)
         //            Messagebox.Items.Add("(" + (j + 1) + ")" + "发送者:" + msg.GetSendNumber() + " 接收者:" + msg.GetReceiveNumber() + " 时间:" + msg.GetTime() + " 内容:" + msg.GetContent().Substring(j * length, msg.GetContent().Length - j*length));
         //        else
         //            Messagebox.Items.Add("(" + (j+1) + ")" + "发送者:" + msg.GetSendNumber() + " 接收者:" + msg.GetReceiveNumber() + " 时间:" + msg.GetTime() + " 内容:" + msg.GetContent().Substring(j*length, 70));
         //    }
         //}
     }
     //SendMessage(Messagebox.Handle, SB_BOTTOM, SB_LINEDOWN, 0);
     //Messagebox.SelectedIndex = Messagebox.Items.Count - 1;
     //Messagebox.ClearSelected();
 }
Esempio n. 3
0
        public void Receive()
        {
            //System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
            //                                           new DeleFunc(Func));
            //接收服务器的信息
            while (ShutDown == 0)
            {
                Byte[] Data = new byte[100000];
                int    Len;
                try
                {
                    Len = stream.Read(Data, 0, Data.Length);
                }
                catch (Exception e)
                {
                    messageBox.Dispatcher.Invoke((Action) delegate { messageBox.Show("服务器崩溃"); });
                    System.Threading.Thread.Sleep(3000);
                    Environment.Exit(0);
                    //messageBox.Show("服务器崩溃");
                    break;
                }
                String   ResponseData = System.Text.Encoding.UTF8.GetString(Data, 0, Len);
                string[] cmd          = ResponseData.Split(' ');
                if (cmd[0] == "Info")//如果读到服务器回执 id(string) (SUCCESS FAIL NOREGISTER NOTONLINE DELAY)
                {
                    if (cmd[2] == "SUCCESS")
                    {
                        messageBox.Dispatcher.Invoke((Action) delegate { messageBox.Show("你发送给 " + cmd[1] + " 的短信已经安全送达"); });
                    }
                    if (cmd[2] == "FAIL")
                    {
                        messageBox.Dispatcher.Invoke((Action) delegate { messageBox.Show("发送失败"); });

                        //messageBox.Show("发送失败");
                    }
                    if (cmd[2] == "NOREGISTER")
                    {
                        //openForm.mainForm.dialogForm.StatusBar.Text = "发送号码为空号";
                        messageBox.Dispatcher.Invoke((Action) delegate { messageBox.Show("发送号码为空号"); });
                        //messageBox.Show("发送号码为空号");
                    }
                    if (cmd[2] == "NOTONLINE")
                    {
                        messageBox.Dispatcher.Invoke((Action) delegate { messageBox.Show("向 " + cmd[1] + " 发送的短信因对方已经关机尚未送达"); });
                        //messageBox.Show("对方已关机");
                    }
                    if (cmd[2] == "DELAY")
                    {
                        messageBox.Dispatcher.Invoke((Action) delegate { messageBox.Show("发送给 " + cmd[1] + " 的短信经过延迟已经安全送达"); });
                        //messageBox.Show("已设置定时发送");
                    }
                    //if (cmd[2] == "ILLEGAL")
                    //{
                    //    messageBox.Dispatcher.Invoke((Action)delegate { messageBox.Show("发送成功"); });
                    //    messageBox.Show("禁止重复登录!");

                    //    this.openForm.IsLegal = 0;
                    //}
                    if (cmd[2] == "LEGAL")
                    {
                        //openForm.OpenMainForm();
                        this.openForm.IsLegal = 1;
                    }
                    //else
                }
                else
                {
                    ShortMessage receiveMessage = new ShortMessage();
                    receiveMessage = ConvertByteToShortMessage(Data, Len);
                    MyDBController.Insert(receiveMessage);
                    messageBox.Dispatcher.Invoke((Action) delegate { messageBox.Show("您有新短消息!    发送者:" + receiveMessage.GetSendNumber() + " 接收者:" + receiveMessage.GetReceiveNumber() + " 时间:" + receiveMessage.GetTime() + " 内容:" + receiveMessage.GetContent()); });
                    //Dispatcher.Invoke((Action)delegate
                    //{
                    openForm.Dispatcher.Invoke((Action) delegate
                    {
                        openForm.mainForm.UpdateMainForm();
                        try
                        {
                            openForm.mainForm.dialogForm.UpdateDialogForm();
                        }
                        catch
                        {
                        }
                    });
                    //})
                }
            }
            //messageBox.Show("hehe");
            recvThread.Abort();
        }
Esempio n. 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();
            }
        }