Esempio n. 1
0
        public Chat ChatCreate(Chat chat)
        {
            User user = Program.user;
            this.SendPostApi(this.apiChatCreate, "token=" + user.token + "&text=" + chat.chat_text + "&to=" + chat.chat_user_id);

            try
            {
                if (this.items != "")
                {
                    return (Chat)JsonConvert.DeserializeObject(this.items, typeof(Chat));
                }
                return null;
            }
            catch (Exception ex)
            {
                Console.WriteLine(" API Chat add 出错 " + ex.Message);
                return null;
            }
        }
Esempio n. 2
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            if (this.richTextBoxChat.Text == "")
            {
                MessageBox.Show("请填写信息。", "提示信息");
                this.richTextBoxChat.Focus();
                return;
            }

            try
            {
                //label1.Text = "正在发布中。。。。";
                Response res = new Response();

                Artifact.Api.Chat chat = new Api.Chat();
                string filePath = Application.StartupPath + "\\chat\\" + DateTime.Now.ToString("yyyyMMdd") + "\\";//存放到相对路径

                Random seed = new Random();

                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
                string text = "";
                for (int i = 0; i < this.richTextBoxChat.TextLength; i++)
                {
                    this.richTextBoxChat.Select(i, 1);
                    RichTextBoxSelectionTypes rt = this.richTextBoxChat.SelectionType;
                    //MessageBox.Show(rt.ToString());
                    if (rt == RichTextBoxSelectionTypes.Object)
                    {
                        //label1.Text = "正在上传截图。。。。";
                        //当然也可能是其它的类型
                        //MessageBox.Show("这是一个图片");
                        this.richTextBoxChat.Copy();
                        Image img = Clipboard.GetImage();
                        if (img != null)
                        {
                            //string snapPath = filePath + DateTime.Now.ToString("HHmmss") + seed.Next(10, 99).ToString() + ".jpg";
                            //img.Save(snapPath, ImageFormat.Jpeg);

                            //上传到服务器
                            Snap snap = res.ChatUpload(img);
                            img.Dispose();

                            if (snap != null)
                            {
                                text += "<img src='" + snap.url + "' />";
                            }
                        }
                        //label1.Text = "上传完成";
                    }
                    else
                        text += this.richTextBoxChat.SelectedText;

                }

                chat.chat_text = text;
                if (this.listBoxService.Items.Count > 0)
                {
                    User user = (User)this.listBoxService.SelectedItem;
                    chat.chat_user_id = user.user_id;
                }
                Artifact.Api.Chat chat_add = res.ChatCreate(chat);
                if (chat_add != null)
                {
                    this.richTextBoxChat.Text = "";
                    //MessageBox.Show("发布成功!", "提示信息");
                }
                else
                    MessageBox.Show("发布失败!" + res.message, "提示信息");

                //label1.Text = "";

            }
            catch (Exception ex)
            {
                MessageBox.Show("获取信息出错!" + ex.Message);
            }
        }
Esempio n. 3
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            if (this.richTextBoxChat.Text == "")
            {
                MessageBox.Show("请填写信息。", "提示信息");
                this.richTextBoxChat.Focus();
                return;
            }

            try
            {
                //label1.Text = "正在发布中。。。。";
                Response res = new Response();

                Artifact.Api.Chat chat     = new Api.Chat();
                string            filePath = Application.StartupPath + "\\chat\\" + DateTime.Now.ToString("yyyyMMdd") + "\\";//存放到相对路径

                Random seed = new Random();


                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
                string text = "";
                for (int i = 0; i < this.richTextBoxChat.TextLength; i++)
                {
                    this.richTextBoxChat.Select(i, 1);
                    RichTextBoxSelectionTypes rt = this.richTextBoxChat.SelectionType;
                    //MessageBox.Show(rt.ToString());
                    if (rt == RichTextBoxSelectionTypes.Object)
                    {
                        //label1.Text = "正在上传截图。。。。";
                        //当然也可能是其它的类型
                        //MessageBox.Show("这是一个图片");
                        this.richTextBoxChat.Copy();
                        Image img = Clipboard.GetImage();
                        if (img != null)
                        {
                            //string snapPath = filePath + DateTime.Now.ToString("HHmmss") + seed.Next(10, 99).ToString() + ".jpg";
                            //img.Save(snapPath, ImageFormat.Jpeg);

                            //上传到服务器
                            Snap snap = res.ChatUpload(img);
                            img.Dispose();

                            if (snap != null)
                            {
                                text += "<img src=\"" + snap.url + "\" data-preview-src=\"\" data-preview-group=\"1\"  class=\"msg-content-image\" />";
                            }
                        }
                        //label1.Text = "上传完成";
                    }
                    else
                    {
                        text += this.richTextBoxChat.SelectedText;
                    }
                }

                chat.chat_text = text;
                if (this.listBoxService.Items.Count > 0)
                {
                    User user = (User)this.listBoxService.SelectedItem;
                    chat.chat_user_id = user.user_id;
                }
                Artifact.Api.Chat chat_add = res.ChatCreate(chat);
                if (chat_add != null)
                {
                    this.richTextBoxChat.Text = "";
                    //MessageBox.Show("发布成功!", "提示信息");
                }
                else
                {
                    MessageBox.Show("发布失败!" + res.message, "提示信息");
                }

                //label1.Text = "";
            }
            catch (Exception ex)
            {
                MessageBox.Show("获取信息出错!" + ex.Message);
            }
        }