private void ButtonEqual_Click(object sender, RoutedEventArgs e)
        {
            string str = TextBoxMain.Text;

            try
            {
                if (str.Contains('+'))
                {
                    int   position   = str.IndexOf('+');
                    float firstpart  = float.Parse(str.Substring(0, position));
                    float secondpart = float.Parse(str.Substring(position + 1, str.Length - position - 1));
                    TextBoxMain.Clear();
                    TextBoxMain.Text = (firstpart + secondpart).ToString();
                }
                if (str.Contains('-'))
                {
                    int   position   = str.IndexOf('-');
                    float firstpart  = float.Parse(str.Substring(0, position));
                    float secondpart = float.Parse(str.Substring(position + 1, str.Length - position - 1));
                    TextBoxMain.Clear();
                    TextBoxMain.Text = (firstpart - secondpart).ToString();
                }
                if (str.Contains('*'))
                {
                    int   position   = str.IndexOf('*');
                    float firstpart  = float.Parse(str.Substring(0, position));
                    float secondpart = float.Parse(str.Substring(position + 1, str.Length - position - 1));
                    TextBoxMain.Clear();
                    TextBoxMain.Text = (firstpart * secondpart).ToString();
                }
                if (str.Contains('/'))
                {
                    int   position   = str.IndexOf('/');
                    float firstpart  = float.Parse(str.Substring(0, position));
                    float secondpart = float.Parse(str.Substring(position + 1, str.Length - position - 1));
                    TextBoxMain.Clear();

                    if (secondpart == 0 || firstpart == 0)
                    {
                        throw new Exception("Dividing by zero");
                    }

                    TextBoxMain.Text = (firstpart / secondpart).ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void SendMessage()
        {
            Color tmpcolor = ColorPicker.Color;

            message.MessageContent = null;
            message.PictureLink    = null;
            message.Color          = null;

            string tmp = TextBoxMain.Text;

            if (CurrentLoginedUser == null)
            {
                this.ShowMessageAsync("Error", "You must login before sending message");
                return;
            }

            UsersFrom.SelectedItem = CurrentLoginedUser;

            message.Sender      = (UsersFrom.SelectedItem as Person);
            message.dateTime    = DateTime.Now;
            message.PictureLink = link;
            message.Color       = ColorPicker.Color.ToString();

            //      MessageBox.Show((RoomsFrom.SelectedItem as Rooms).Name, "within sendmessage");
            message.Room = RoomsFrom.SelectedItem as Rooms;



            CurrentLoginedUser.MessageCount++;

            //if (TextBoxMain.Text.ToLower().Contains("pink") {
            //  char.IsLetter(TextBoxMain.Text.IndexOf("!") + 1
            //}
            string res = "";

            foreach (var item in colors)
            {
                if (TextBoxMain.Text.Contains("!" + item.ToLower()))
                {
                    message.Color = item;
                }
                //if (char.IsLetter(TextBoxMain.Text[TextBoxMain.Text.IndexOf("!") + 1]) == true) { // kostil

                //}
            }

            try {
                for (int i = 0; i < tmp.Length; i++)
                {
                    if (tmp[i] == '!' && char.IsLetter(tmp[i + 1]))
                    {
                        continue;
                    }
                    else
                    {
                        res += tmp[i];
                    }
                }
            }
            catch (Exception) {
            }

            if (TextBoxMain.Text.Length <= 1 || TextBoxMain.Text == null)
            {
                this.ShowMessageAsync("Error", "You wrote nothing");
                return;
            }


            //foreach(char c in tmp) {
            //    if (c == '!')
            //        continue;
            //    else
            //        res += c;
            //}


            message.MessageContent = res;

            db.Messages.Add(message);
            db.SaveChanges();

            TextBoxMain.Clear();
            link = string.Empty;
            ButtonPhoto.Content = "🔗";
            ColorPicker.Color   = tmpcolor;

            UpdateContent();
        }
 private void ButtonClear_Click(object sender, RoutedEventArgs e)
 {
     TextBoxMain.Clear();
 }