zoukankan      html  css  js  c++  java
  • 点击和焦点事件

    private void text_GotFocus(object sender, EventArgs e)
            {
                using (var db = new FiDbContext())
                {
                    ComboBoxLink com = (ComboBoxLink)sender;
    
                    if (com.ItemsSource == null)
                    {
                        //科目绑定
                        List<Fi_Subject> sub = db.Subjects.ToList();
                        ComboBox aa = new ComboBox();
    
                        // aa.ItemsSource
                        //com.ItemSource = new ObservableCollection<Fi_Subject>(sub);
                        com.ItemsSource = new ObservableCollection<Fi_Subject>(sub);
                        com.DisplayMemberPath = "Name";
                        com.SelectedValuePath = "ID";
    
                        //com.SelectedValue = "1";
                    }
                }
            }
            private void textT_LostFocus(object sender, RoutedEventArgs e)
            {
                CompreFunction data = new CompreFunction();
                //失去焦点文本如为负数修改前景色为Red  
                TextBox tt = (TextBox)sender;
                if (tt.Text != "")
                {
                    decimal isok = decimal.Parse(tt.Text);
                    if (isok < 0)
                    {
                        tt.Foreground = new SolidColorBrush(Colors.Red);
                        tt.Text = (isok * (-1)).ToString();
                    }
                }
                int rows = MainGrid.RowDefinitions.Count - 1;
                TextBlock text = FindChild<TextBlock>(Application.Current.MainWindow, ("tbkSum" + rows + 3));
                TextBlock textTwo = FindChild<TextBlock>(Application.Current.MainWindow, ("tbkSum" + rows + 2));
                TextBlock textFirst = FindChild<TextBlock>(Application.Current.MainWindow, ("tbkSum" + rows + 0));
                decimal Sum = 0;
                for (int r = 1; r < rows; r++)
                {
                    TextBox texts = FindChild<TextBox>(Application.Current.MainWindow, ("text" + r + 3));
                    if (!string.IsNullOrWhiteSpace(texts.Text))
                    {
                        if (texts.Foreground.ToString() == "#FFFF0000")
                        {
                            Sum = Sum + (decimal.Parse(texts.Text.ToString()) * (-1));
                        }
                        else
                        {
                            Sum = Sum + decimal.Parse(texts.Text.ToString());
                        }
                    }
                }
    
                if (Sum < 0)
                {
                    Sum = Sum * (-1);
                    text.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    text.Foreground = new SolidColorBrush(Colors.Black);
                }
                text.Text = Sum.ToString();
                if (text.Text != "" && textTwo.Text != "")
                {
                    if (text.Foreground.ToString() == "#FFFF0000" && textTwo.Foreground.ToString() == "#FFFF0000")
                    {
                        if (decimal.Parse(text.Text) == decimal.Parse(textTwo.Text) && decimal.Parse(text.Text) != 0 && decimal.Parse(textTwo.Text) != 0)
                        {
                            textFirst.Text = "合计:负" + data.CmycurD(Sum);
                            textFirst.Foreground = new SolidColorBrush(Colors.Red);
                        }
                        else
                        {
                            textFirst.Text = "合计:";
                            textFirst.Foreground = new SolidColorBrush(Colors.Black);
                        }
                    }
                    if ((text.Foreground.ToString() == "#FFFF0000" && textTwo.Foreground.ToString() != "#FFFF0000") || (text.Foreground.ToString() != "#FFFF0000" && textTwo.Foreground.ToString() == "#FFFF0000"))
                    {
                        textFirst.Text = "合计:";
                        textFirst.Foreground = new SolidColorBrush(Colors.Black);
                    }
                    if (text.Foreground.ToString() != "#FFFF0000" && textTwo.Foreground.ToString() != "#FFFF0000")
                    {
                        if (decimal.Parse(text.Text) == decimal.Parse(textTwo.Text) && decimal.Parse(text.Text) != 0 && decimal.Parse(textTwo.Text) != 0)
                        {
                            textFirst.Text = "合计:" + data.CmycurD(Sum);
                        }
                        else
                        {
                            textFirst.Text = "合计:";
                            textFirst.Foreground = new SolidColorBrush(Colors.Black);
                        }
                    }
                }
            }
    
            private void text_LostFocus(object sender, RoutedEventArgs e)
            {
                CompreFunction data = new CompreFunction();
                TextBox tt = (TextBox)sender;
                if (tt.Text != "")
                {
                    decimal isok = decimal.Parse(tt.Text);
                    if (isok < 0)
                    {
                        tt.Foreground = new SolidColorBrush(Colors.Red);
                        tt.Text = (isok * (-1)).ToString();
                    }
                }
                int rows = MainGrid.RowDefinitions.Count - 1;
                TextBlock text = FindChild<TextBlock>(Application.Current.MainWindow, ("tbkSum" + rows + 2));
                TextBlock textLast = FindChild<TextBlock>(Application.Current.MainWindow, ("tbkSum" + rows + 3));
                TextBlock textFirst = FindChild<TextBlock>(Application.Current.MainWindow, ("tbkSum" + rows + 0));
                decimal Sum = 0;
                for (int r = 1; r < rows; r++)
                {
                    TextBox texts = FindChild<TextBox>(Application.Current.MainWindow, ("text" + r + 2));
                    if (!string.IsNullOrWhiteSpace(texts.Text))
                    {
                        if (texts.Foreground.ToString() == "#FFFF0000")
                        {
                            Sum = Sum + (decimal.Parse(texts.Text.ToString()) * (-1));
                        }
                        else
                        {
                            Sum = Sum + decimal.Parse(texts.Text.ToString());
                        }
                    }
                }
                if (Sum < 0)
                {
                    Sum = Sum * (-1);
                    text.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    text.Foreground = new SolidColorBrush(Colors.Black);
                }
                text.Text = Sum.ToString();
                if (text.Text != "" && textLast.Text != "")
                {
                    if (text.Foreground.ToString() == "#FFFF0000" && textLast.Foreground.ToString() == "#FFFF0000")
                    {
                        if (decimal.Parse(text.Text) == decimal.Parse(textLast.Text) && decimal.Parse(text.Text) != 0 && decimal.Parse(textLast.Text) != 0)
                        {
                            textFirst.Text = "合计:负" + data.CmycurD(Sum);
                            textFirst.Foreground = new SolidColorBrush(Colors.Red);
                        }
                        else
                        {
                            textFirst.Text = "合计:";
                            textFirst.Foreground = new SolidColorBrush(Colors.Black);
                        }
                    }
                    if ((text.Foreground.ToString() == "#FFFF0000" && textLast.Foreground.ToString() != "#FFFF0000") || (text.Foreground.ToString() != "#FFFF0000" && textLast.Foreground.ToString() == "#FFFF0000"))
                    {
                        textFirst.Text = "合计:";
                        textFirst.Foreground = new SolidColorBrush(Colors.Black);
                    }
                    if (text.Foreground.ToString() != "#FFFF0000" && textLast.Foreground.ToString() != "#FFFF0000")
                    {
                        if (decimal.Parse(text.Text) == decimal.Parse(textLast.Text) && decimal.Parse(text.Text) != 0 && decimal.Parse(textLast.Text) != 0)
                        {
                            textFirst.Text = "合计:" + data.CmycurD(Sum);
                        }
                        else
                        {
                            textFirst.Text = "合计:";
                            textFirst.Foreground = new SolidColorBrush(Colors.Black);
                        }
                    }
                }
            }
    
            private void textCol_LinkClick(object sender, EventArgs e)
            {
                ComboBoxLink link = (ComboBoxLink)sender;
                SelectAllSubject select = new SelectAllSubject(link);
                this.ShowMessageWindow(select, "科目", 500, 600);
            }
  • 相关阅读:
    当你不知道今天星期几,不妨在编辑器写下这段代码
    自定义注解!绝对是程序员装逼的利器!!
    什么是可串行化MVCC
    Jetpack新成员,一篇文章带你玩转Hilt和依赖注入
    连接真机开发安卓(Android)移动app MUI框架 添加购物车等——混合式开发(四)
    从前世今生聊一聊,大厂为啥亲睐时序数据库
    工作五年,面试官说我只会CRUD!竟然只给我10K!
    bootstrap知识总结
    数据处理的两个基本问题05 零基础入门学习汇编语言42
    转移指令的原理02 零基础入门学习汇编语言44
  • 原文地址:https://www.cnblogs.com/happinesshappy/p/5018316.html
Copyright © 2011-2022 走看看