Exemplo n.º 1
0
        private void Calculate_Click(object sender, EventArgs e)
        {
            //Declare Swimmer's Label, so we can write the Swimmer's Name, and store it with his/her proper Data

            string swimmerName;

            swimmerName = Console.ReadLine();

            swimmerName = lblSwimerName.ToString();

            //Declarations

            double longDistance;
            double longTime;
            double shortDistance;
            double shortTime;

            double workoutDistance;
            double workingTime;

            double CSS; //Critical Swim Speed
            double NSS; //Normalized Swim Speed
            double IF;  //Intensity Factor
            double TSS; //Training Stress Score

            //Inputs
            //This 4 lines (with code) are used to calculate the CSS
            longDistance = double.Parse(lblLongerDistance.Text);
            longTime     = double.Parse(lblLongerTime.Text);

            shortDistance = double.Parse(lblShorterDistance.Text);
            shortTime     = double.Parse(lblShorterTime.Text);

            //This 2 lines of code are used to calculate the NSS
            workoutDistance = double.Parse(lblWorkoutDistance.Text);
            workingTime     = double.Parse(lblWorkingTime.Text);

            //Processing

            CSS = (longDistance - shortDistance) / (longTime - shortTime); //Calculates the CSS
            NSS = (workoutDistance / workingTime);                         //Calculates tge NSS
            IF  = (NSS / CSS);                                             //Calculates the IF
            TSS = ((Math.Pow(IF, 3)) * (workingTime / 3600) * 100);        //Calculates the TSS

            //OutPut

            lblCSS.Text = CSS.ToString();
            lblNSS.Text = NSS.ToString();
            lblIF.Text  = IF.ToString();
            lblTSS.Text = TSS.ToString();
        }
Exemplo n.º 2
0
        public void XmppCon_OnMessage(object sender, CSS.IM.XMPP.protocol.client.Message msg)
        {
            if (InvokeRequired)
            {
                // Windows Forms are not Thread Safe, we need to invoke this :(
                // We're not in the UI thread, so we need to call BeginInvoke
                Invoke(new OnMessageDelegate(XmppCon_OnMessage), new object[] { sender, msg });
                return;
            }

            // Dont handle GroupChat Messages here, they have their own callbacks in the
            // GroupChat Form
            if (msg.Type == MessageType.groupchat)
            {
                //Debug.WriteLine("创建聊天室发送了消息:"+msg.Body);
                return;
            }
            if (msg.Type == MessageType.error)
            {
                //Handle errors here
                // we dont handle them in this example
                return;
            }
            //if (msg.Type == MessageType.normal)
            //{
            //    filename = msg.Body;
            //    Debug.WriteLine(msg.ToString());
            //    return;
            //}

            // check for xData Message

            if (msg.HasTag(typeof(Data)))//如果是文件
            {
                Element e = msg.SelectSingleElement(typeof(Data));
                Data xdata = e as Data;
                if (xdata.Type == XDataFormType.form)
                {
                    //frmXData fXData = new frmXData(xdata);
                    //fXData.Text = "xData Form from " + msg.From.ToString();
                    //fXData.Show();
                }
            }
            else if (msg.HasTag(typeof(CSS.IM.XMPP.protocol.extensions.ibb.Data)))
            {
                // ignore IBB messages
                return;
            }
            else
            {
                if (msg.Body != null)
                {
                    if (msg.GetTag("subject") == "notify")//xu
                    {
                        filename = msg.Body;
                        return;
                    }
                    if (msg.From.ToString() == msg.From.Server)
                    {
                        if (CSS.IM.UI.Util.Path.ReveiveSystemNotification)//是否接收服务器消息
                        {
                            if (CSS.IM.UI.Util.Path.SystemSwitch)
                                SoundPlayEx.MsgPlay(CSS.IM.UI.Util.Path.SystemPath);

                            MessageBoxForm sBox = new MessageBoxForm("系统通知", msg);
                            try
                            {
                                sBox.TopMost = true;
                                sBox.Show();
                            }
                            catch (Exception)
                            {

                            }

                            string sqlstr = "insert into MessageLog (Belong,MessageType,MessageLog,[DateNow]) values ({0},{1},{2},{3})";
                            sqlstr = String.Format(sqlstr,
                                "'" + XmppCon.MyJID.Bare.ToString() + "'",
                                "'0'",
                                "'" + msg.ToString() + "'",
                                 "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                            CSS.IM.Library.Data.OleDb.ExSQL(sqlstr);
                        }
                    }
                    else
                    {
                        if (!Util.ChatForms.ContainsKey(msg.From.Bare))//查看聊天窗口是否已经打开了
                        {

                            //RosterNode rn = rosterControl.GetRosterItem(msg.From);
                            //string nick = msg.From.Bare;
                            //if (rn != null)
                            //    nick = rn.Text;
                            try
                            {
                                //string sqlstr = "insert into ChatMessageLog (Jid,[MessageLog],[DateNow])values ({0},{1},{2})";
                                //sqlstr = String.Format(sqlstr,
                                //    "'" + msg.From.Bare.ToString() + "'",
                                //    "'" + msg.ToString() + "'",
                                //     "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                                //CSS.IM.Library.Data.OleDb.ExSQL(sqlstr);

                                if (msg.GetTagInt("m_type") == 0)//如果为0就是正常消息,就播放声音
                                {
                                    if (CSS.IM.UI.Util.Path.MsgSwitch)
                                        SoundPlayEx.MsgPlay(CSS.IM.UI.Util.Path.MsgPath);
                                }
                                else//代码进入到这里,说明,聊天的窗口已经关闭,接收到属于聊天窗口里面的业务不做处理
                                {
                                    //6发图片
                                    //1接收视频

                                    if (!(msg.GetTagInt("m_type")==6||msg.GetTagInt("m_type")==1))
                                    {
                                        return;
                                    }
                                }

                                Friend flfriend = friendListView.Rosters[msg.From.User];

                                if (CSS.IM.UI.Util.Path.ChatOpen)
                                {
                                    //friendListView.flickerFriend(new Jid(msg.From.Bare));
                                    //ChatMessageBox.GetInstance(this).AddFriendMessage(msg.From, XmppCon, msg.From.Bare);
                                    //timer_notifyIco.Enabled = true;

                                    ChatForm chatForm = new ChatForm(msg.From, XmppCon, msg.From.Bare);
                                    try
                                    {
                                        chatForm.UpdateFriendOnline(flfriend.IsOnline);//设置好友在线状态
                                        chatForm.Show();
                                        chatForm.Activate();
                                        chatForm.IncomingMessage(msg);
                                    }
                                    catch (Exception)
                                    {

                                    }

                                }
                                else
                                {
                                    if (msgBox.ContainsKey(msg.From.Bare.ToString()))
                                    {
                                        List<CSS.IM.XMPP.protocol.client.Message> msgs = msgBox[msg.From.Bare.ToString()];
                                        msgs.Add(msg);
                                        msgBox.Remove(msg.From.Bare.ToString());
                                        msgBox.Add(msg.From.Bare.ToString(), msgs);
                                        friendListView.flickerFriend(new Jid(msg.From.Bare));

                                    }
                                    else
                                    {
                                        if (friendListView.Rosters.ContainsKey(msg.From.User))
                                        {
                                            List<CSS.IM.XMPP.protocol.client.Message> msgs = new List<XMPP.protocol.client.Message>();
                                            msgs.Add(msg);
                                            msgBox.Add(msg.From.Bare.ToString(), msgs);
                                            friendListView.flickerFriend(new Jid(msg.From.Bare));
                                            ChatMessageBox.GetInstance(this).AddFriendMessage(msg.From, XmppCon, msg.From.Bare);
                                            timer_notifyIco.Enabled = true;
                                        }
                                        else
                                        {
                                            ChatForm chatForm = new ChatForm(msg.From, XmppCon, msg.From.Bare);
                                            try
                                            {
                                                chatForm.UpdateFriendOnline(flfriend.IsOnline);//设置好友在线状态
                                                chatForm.Show();
                                                chatForm.Activate();
                                                chatForm.IncomingMessage(msg);
                                            }
                                            catch (Exception)
                                            {

                                            }

                                        }

                                        //Friend item=friendListView.Rosters[msg.From.Bare.ToString()];
                                    }
                                }

                                //ChatForm chatForm = new ChatForm(msg.From, XmppCon, msg.From.Bare);
                                //chatForm.Show();
                                //chatForm.IncomingMessage(msg);
                            }
                            catch (Exception)
                            {
                                //MessageBox.Show(ex.Message);
                            }

                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新消息显示
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="isSend"></param>
        public void RTBRecord_Show(CSS.IM.XMPP.protocol.client.Message msg, bool isSend)
        {
            string sqlstr = "insert into ChatMessageLog (Belong,Jid,[MessageLog],[DateNow])values ({0},{1},{2},{3})";
            sqlstr = String.Format(sqlstr,
                "'" + XmppConn.MyJID.Bare.ToString() + "'",
                "'" + (isSend == true ? msg.To.Bare.ToString() : msg.From.Bare.ToString()) + "'",
                "'" + msg.ToString() + "'",
                 "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
            CSS.IM.Library.Data.OleDb.ExSQL(sqlstr);

            System.Drawing.FontStyle fontStyle = new System.Drawing.FontStyle();
            System.Drawing.Font ft = null;

            #region 获取字体
            try
            {
                if (msg.GetTagBool("FBold"))
                {
                    fontStyle = System.Drawing.FontStyle.Bold;
                }
                if (msg.GetTagBool("FItalic"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Italic;
                }
                if (msg.GetTagBool("FStrikeout"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Strikeout;
                }
                if (msg.GetTagBool("FUnderline"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Underline;
                }
                ft = new System.Drawing.Font(msg.GetTag("FName"), float.Parse(msg.GetTag("FSize")), fontStyle);
            }
            catch (Exception)
            {
                ft = RTBRecord.Font;
            }
            #endregion

            #region 获取颜色
            Color cl = RTBRecord.ForeColor;
            try
            {
                byte[] cby = new byte[4];
                cby[0] = Byte.Parse(msg.GetTag("CA"));
                cby[1] = Byte.Parse(msg.GetTag("CR"));
                cby[2] = Byte.Parse(msg.GetTag("CG"));
                cby[3] = Byte.Parse(msg.GetTag("CB"));
                cl = Color.FromArgb(BitConverter.ToInt32(cby, 0));

            }
            catch
            {
                cl = RTBRecord.ForeColor;
            }
            #endregion

            int iniPos = this.RTBRecord.TextLength;//获得当前记录richBox中最后的位置
            String msgtext = msg.Body;
            RTBRecord.Select(RTBRecord.TextLength, 0);
            RTBRecord.ScrollToCaret();

            string face = "";
            try
            {
                if (msg.GetTag("face")!=null)
                {
                    face = msg.GetTag("face").ToString();
                }
                else
                {
                    face = "";
                }
            }
            catch (Exception)
            {

            }

            if (face != "")//如果消息中有图片,则添加图片
            {
                string[] imagePos = face.Split('|');
                int addPos = 0;//
                int currPos = 0;//当前正要添加的文本位置
                int textPos = 0;
                for (int i = 0; i < imagePos.Length - 1; i++)
                {
                    string[] imageContent = imagePos[i].Split(',');//获得图片所在的位置、图片名称
                    currPos = Convert.ToInt32(imageContent[0]);//获得图片所在的位置

                    this.RTBRecord.AppendText(msgtext.Substring(textPos, currPos - addPos));
                    this.RTBRecord.SelectionStart = this.RTBRecord.TextLength;

                    textPos += currPos - addPos;
                    addPos += currPos - addPos;

                    Image image = null;

                    if (emotionDropdown==null)
                    {
                        emotionDropdown = new EmotionDropdown();
                        emotionDropdown.EmotionContainer.ItemClick += new UI.Face.EmotionItemMouseEventHandler(EmotionContainer_ItemClick);
                    }

                    if (emotionDropdown.faces.ContainsKey(imageContent[1]))
                    {
                        if (this.RTBRecord.findPic(imageContent[1]) == null)
                            image = CSS.IM.UI.Util.ResClass.GetImgRes("_" + int.Parse(imageContent[1].ToString()).ToString());
                        else
                            image = this.RTBRecord.findPic(imageContent[1]).Image;

                        this.RTBRecord.addGifControl(imageContent[1], image);
                    }
                    else
                    {
                        try
                        {
                            if (isSend)
                            {
                                image = this.rtfSend.findPic(imageContent[1]).Image;
                                this.RTBRecord.addGifControl(imageContent[1], image);

                            }
                            else
                            {
                                image = CSS.IM.UI.Util.ResClass.GetImgRes("wite");
                                this.RTBRecord.addGifControl(imageContent[1] + "_r", image);
                            }

                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    addPos++;
                }
                this.RTBRecord.AppendText(msgtext.Substring(textPos, msgtext.Length - textPos) + "  \n");
            }
            else
            {
                this.RTBRecord.AppendText(msgtext + "\n");
            }

            this.RTBRecord.Select(iniPos, this.RTBRecord.TextLength - iniPos);
            this.RTBRecord.SelectionFont = ft;
            this.RTBRecord.SelectionColor = cl;
            this.RTBRecord.Select(this.RTBRecord.TextLength, 0);
            this.RTBRecord.ScrollToCaret();
        }
Exemplo n.º 4
0
        public void AddStyle(CSS css)
        {
            HtmlElement c = new HtmlElement("style", css.ToString());

            this.AddChild(c);
        }