珂珂的个人博客 - 一个程序猿的个人网站

股票工具

<Window x:Class="StockTool.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:c="clr-namespace:FYJ.Winui.Controls;assembly=FYJ.Winui"

        xmlns:util="clr-namespace:StockTool.Util"

        xmlns:m="clr-namespace:StockTool.Model"

        Title="股票工具" Height="600" Width="800" Icon="股票.ico" >

    <Window.Resources>

        <Style TargetType="TextBlock" x:Key="grayTextBlock">

            <Setter Property="Foreground" Value="Gray"></Setter>

        </Style>

        <Style TargetType="TextBlock" x:Key="numberShow">

            <Setter Property="FontWeight" Value="Bold"></Setter>

        </Style>

        <util:PercentConvert x:Key="percentConvert"></util:PercentConvert>

        <util:DatetimeConvert x:Key="dateConvert" Format="yyyy-MM-dd"></util:DatetimeConvert>

        <util:MoneyConvert x:Key="moneyConvert" ></util:MoneyConvert>

        <util:VisibilityConvert x:Key="visibilityConvert" ></util:VisibilityConvert>

        <m:MenuModel x:Key="menuModel"></m:MenuModel>

        <SolidColorBrush x:Key="redBrush">Red</SolidColorBrush>

        <Style x:Key="contentCenterStyle" TargetType="{x:Type TextBlock}">

            <Setter Property="HorizontalAlignment" Value="Center" />

        </Style>

        <Style x:Key="ColumnHeaderStyle" TargetType="DataGridColumnHeader">

            <Setter Property="HorizontalContentAlignment" Value="Center"/>

        </Style>

    </Window.Resources>

    <Window.ContextMenu>

        <ContextMenu>

            <MenuItem Header="刷新(F)" x:Name="menuRefresh" Click="menuRefresh_Click"></MenuItem>

            <MenuItem Header="买进预警..." x:Name="menuBuyWarn" Click="menuBuyWarn_Click"></MenuItem>

            <MenuItem Header="卖出预警..." x:Name="menuSaleWarn" Click="menuSaleWarn_Click"></MenuItem>

            <MenuItem Header="停止刷新" x:Name="menuStopRefresh" Click="menuStopRefresh_Click"></MenuItem>

            <MenuItem Header="添加自选股..." x:Name="menuAddStock" Click="menuAddStock_Click"></MenuItem>

            <MenuItem Header="删除自选股" x:Name="menuDeleteStock" Click="menuDeleteStock_Click"></MenuItem>

            <!--<MenuItem Header="显示隐藏股"></MenuItem>

            <MenuItem Header="标记"></MenuItem>

            <MenuItem Header="取消标记"></MenuItem>

            <MenuItem Header="隐藏"></MenuItem>

            <MenuItem Header="取消隐藏"></MenuItem>-->

        </ContextMenu>

    </Window.ContextMenu>

    <DockPanel>

        <Menu DockPanel.Dock="Top">

            <MenuItem Header="文件(F)">

                <MenuItem Header="退出(X)"></MenuItem>

            </MenuItem>

            <MenuItem Header="查看(V)">

                <MenuItem Header="分析栏" IsChecked="True" x:Name="menuIsShowKline" IsCheckable="True"></MenuItem>

            </MenuItem>

            <MenuItem Header="工具(T)">

                <MenuItem Header="代码查询..."  Command="{Binding Path=ShowCommand,Source={StaticResource menuModel}}" CommandParameter="StockSelectForm"></MenuItem>

                <MenuItem Header="交易记录..."  Command="{Binding Path=ShowCommand,Source={StaticResource menuModel}}" CommandParameter="OrderForm"></MenuItem>

                <MenuItem Header="持仓..." Command="{Binding Path=ShowCommand,Source={StaticResource menuModel}}" CommandParameter="HoldForm"></MenuItem>

                <MenuItem Header="计算..." Command="{Binding Path=ShowCommand,Source={StaticResource menuModel}}" CommandParameter="CalculateForm"></MenuItem>

                <MenuItem Header="选项..." Command="{Binding Path=ShowCommand,Source={StaticResource menuModel}}" CommandParameter="SettingForm"></MenuItem>

            </MenuItem>

            <MenuItem Header="帮助(H)"></MenuItem>

        </Menu>

        <WrapPanel DockPanel.Dock="Bottom">

            <c:TextBlockEx Text="就绪" x:Name="txtStatus"></c:TextBlockEx>

        </WrapPanel>

        <Grid DockPanel.Dock="Bottom" Height="375" Visibility="{Binding ElementName=menuIsShowKline,Path=IsChecked,Converter={StaticResource visibilityConvert}}">

            <Grid.ColumnDefinitions>

                <ColumnDefinition Width="220"></ColumnDefinition>

                <ColumnDefinition Width="*"></ColumnDefinition>

            </Grid.ColumnDefinitions>

            <StackPanel Grid.Column="0" Background="Black">

                <DockPanel LastChildFill="False" Margin="5" >

                    <TextBlock Text="委比:"  Style="{StaticResource grayTextBlock}" />

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.Weibi,Converter={StaticResource percentConvert}}" Width="80" Foreground="{Binding ElementName=dataGrid1,Path=SelectedItem.WeibiColor}" Style="{StaticResource numberShow}" Margin="5,0,0,0" x:Name="txtWeibi"></TextBlock>

                    <TextBlock Text="委差:" Style="{StaticResource grayTextBlock}"></TextBlock>

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.Weicha}" Width="70" DockPanel.Dock="Right"  Foreground="{Binding ElementName=dataGrid1,Path=SelectedItem.WeichaColor}" Style="{StaticResource numberShow}" Margin="5,0,0,0" x:Name="txtWeicha"></TextBlock>

                </DockPanel>

                <Border BorderBrush="Gray" BorderThickness="0,1,0,0"  >

                </Border>

                <DockPanel LastChildFill="False" Margin="5,5,0,0"  >

                    <TextBlock Text="卖一:"  Style="{StaticResource grayTextBlock}"  />

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.SalePrice1}" Foreground="{Binding ElementName=dataGrid1,Path=SelectedItem.SalePriceColor1}" Style="{StaticResource numberShow}" Margin="5,0,0,0" x:Name="txtSalePrice1"></TextBlock>

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.SaleCount1}" Foreground="#FFD4CD2B" Style="{StaticResource numberShow}" Margin="5,0,0,0" Width="70" DockPanel.Dock="Right"></TextBlock>

                </DockPanel>


                <DockPanel LastChildFill="False" Margin="5,5,0,0"  >

                    <TextBlock Text="卖二:"  Style="{StaticResource grayTextBlock}" />

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.SalePrice2}" Foreground="{Binding ElementName=dataGrid1,Path=SelectedItem.SalePriceColor2}" Style="{StaticResource numberShow}" Margin="5,0,0,0" x:Name="txtSalePrice2"></TextBlock>

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.SaleCount2}" Foreground="#FFD4CD2B" Style="{StaticResource numberShow}" Margin="5,0,0,0" Width="70" DockPanel.Dock="Right"></TextBlock>

                </DockPanel>

                <DockPanel LastChildFill="False" Margin="5,5,0,0" >

                    <TextBlock Text="卖三:"  Style="{StaticResource grayTextBlock}" />

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.SalePrice3}" Foreground="{Binding ElementName=dataGrid1,Path=SelectedItem.SalePriceColor3}" Style="{StaticResource numberShow}" Margin="5,0,0,0" x:Name="txtSalePrice3"></TextBlock>

                    <TextBlock Width="70" DockPanel.Dock="Right" Text="{Binding ElementName=dataGrid1,Path=SelectedItem.SaleCount3}" Foreground="#FFD4CD2B" Style="{StaticResource numberShow}" Margin="5,0,0,0"></TextBlock>

                </DockPanel>

                <DockPanel LastChildFill="False" Margin="5,5,0,0">

                    <TextBlock Text="卖四:"  Style="{StaticResource grayTextBlock}" />

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.SalePrice4}" Foreground="{Binding ElementName=dataGrid1,Path=SelectedItem.SalePriceColor4}" Style="{StaticResource numberShow}" Margin="5,0,0,0" x:Name="txtSalePrice4"></TextBlock>

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.SaleCount4}" Foreground="#FFD4CD2B" Style="{StaticResource numberShow}" Margin="5,0,0,0" Width="70" DockPanel.Dock="Right"></TextBlock>

                </DockPanel>

                <DockPanel LastChildFill="False" Margin="5,5,0,0">

                    <TextBlock Text="卖五:"  Style="{StaticResource grayTextBlock}" />

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.SalePrice5}" Foreground="{Binding ElementName=dataGrid1,Path=SelectedItem.SalePriceColor5}" Style="{StaticResource numberShow}" Margin="5,0,0,0" x:Name="txtSalePrice5"></TextBlock>

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.SaleCount5}" Foreground="#FFD4CD2B" Style="{StaticResource numberShow}" Margin="5,0,0,0" Width="70" DockPanel.Dock="Right"></TextBlock>

                </DockPanel>


                <Border BorderBrush="Gray" BorderThickness="0,1,0,0"  >

                </Border>

                <DockPanel LastChildFill="False" Margin="5,5,0,0">

                    <TextBlock Text="买一:"  Style="{StaticResource grayTextBlock}" />

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyPrice1}" Foreground="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyPriceColor1}" Style="{StaticResource numberShow}" Margin="5,0,0,0" ></TextBlock>

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyCount1}" Foreground="#FFD4CD2B" Style="{StaticResource numberShow}" Margin="5,0,0,0" Width="70" DockPanel.Dock="Right"></TextBlock>

                </DockPanel>

                <DockPanel LastChildFill="False" Margin="5,5,0,0">

                    <TextBlock Text="买二:"  Style="{StaticResource grayTextBlock}" />

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyPrice2}" Foreground="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyPriceColor2}" Style="{StaticResource numberShow}" Margin="5,0,0,0" x:Name="txtBuyPrice2"></TextBlock>

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyCount2}" Foreground="#FFD4CD2B" Style="{StaticResource numberShow}" Margin="5,0,0,0" Width="70" DockPanel.Dock="Right"></TextBlock>

                </DockPanel>

                <DockPanel LastChildFill="False" Margin="5,5,0,0">

                    <TextBlock Text="买三:"  Style="{StaticResource grayTextBlock}" />

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyPrice3}" Foreground="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyPriceColor3}" Style="{StaticResource numberShow}" Margin="5,0,0,0" x:Name="txtBuyPrice3"></TextBlock>

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyCount3}" Foreground="#FFD4CD2B" Style="{StaticResource numberShow}" Margin="5,0,0,0" Width="70" DockPanel.Dock="Right"></TextBlock>

                </DockPanel>

                <DockPanel LastChildFill="False" Margin="5,5,0,0">

                    <TextBlock Text="买四:"  Style="{StaticResource grayTextBlock}" />

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyPrice4}" Foreground="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyPriceColor4}" Style="{StaticResource numberShow}" Margin="5,0,0,0" x:Name="txtBuyPrice4"></TextBlock>

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyCount4}" Foreground="#FFD4CD2B" Style="{StaticResource numberShow}" Margin="5,0,0,0" Width="70" DockPanel.Dock="Right"></TextBlock>

                </DockPanel>

                <DockPanel LastChildFill="False" Margin="5,5,0,0">

                    <TextBlock Text="买五:"  Style="{StaticResource grayTextBlock}" />

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyPrice5}" Foreground="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyPriceColor5}" Style="{StaticResource numberShow}" Margin="5,0,0,0" x:Name="txtBuyPrice5"></TextBlock>

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.BuyCount5}" Foreground="#FFD4CD2B" Style="{StaticResource numberShow}" Margin="5,0,0,0" Width="70" DockPanel.Dock="Right"></TextBlock>

                </DockPanel>

                <Border BorderBrush="Gray" BorderThickness="0,1,0,0"  >

                </Border>

                <DockPanel LastChildFill="False" Margin="5,5,0,0">

                    <TextBlock Text="外盘:"  Style="{StaticResource grayTextBlock}" />

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.Waipan}" Width="80" Foreground="#FFFD1E08" Style="{StaticResource numberShow}" Margin="5,0,0,0"></TextBlock>

                    <TextBlock Text="内盘:" Style="{StaticResource grayTextBlock}"></TextBlock>

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.Neipan}" Foreground="Green" Style="{StaticResource numberShow}" Margin="5,0,0,0" Width="70" DockPanel.Dock="Right"></TextBlock>

                </DockPanel>

                <DockPanel LastChildFill="False" Margin="5,5,0,0">

                    <TextBlock Text="总量:"  Style="{StaticResource grayTextBlock}" />

                    <TextBlock Text="{Binding ElementName=dataGrid1,Path=SelectedItem.Total}" Width="80" Foreground="#FFD4CD2B" Style="{StaticResource numberShow}" Margin="5,0,0,0"></TextBlock>

                    <TextBlock Text="量比:" Style="{StaticResource grayTextBlock}"></TextBlock>

                    <TextBlock Text="N/A"  Foreground="Gray"  Style="{StaticResource numberShow}" Margin="5,0,0,0" Width="70" DockPanel.Dock="Right"></TextBlock>

                </DockPanel>

                <WrapPanel Margin="5,5,0,0">

                    <TextBlock Text="提示:以上4个数据不准确" Foreground="Red"></TextBlock>

                </WrapPanel>

            </StackPanel>

            <StackPanel Grid.Column="1">

                <GroupBox Header="K线">

                    <WrapPanel>

                        <RadioButton Content="分时线"  x:Name="radioMin"  Checked="radioKline_Checked"></RadioButton>

                        <RadioButton Content="日K"  x:Name="radioDaily" Checked="radioKline_Checked"></RadioButton>

                        <RadioButton Content="周K"  x:Name="radioWeekly" Checked="radioKline_Checked"></RadioButton>

                        <RadioButton Content="月K"  x:Name="radioMonthly" Checked="radioKline_Checked"></RadioButton>

                        <TextBlock Text="刷新时间:" Margin="10,0,0,0"></TextBlock>

                        <TextBox Text="10" Width="40"  Margin="5,0,0,0"></TextBox>

                        <TextBlock Text="s"></TextBlock>

                    </WrapPanel>

                </GroupBox>

                <Image HorizontalAlignment="Left" x:Name="imgKLine" Width="540" Height="300"></Image>

            </StackPanel>

        </Grid>


        <DataGrid x:Name="dataGrid1" Margin="0,10,0,0" IsReadOnly="True" SelectionMode="Single"   SelectionChanged="dataGrid1_SelectionChanged" AutoGenerateColumns="False" HorizontalGridLinesBrush="#FF959191" VerticalGridLinesBrush="#FF959191"  >

            <DataGrid.RowStyle>

                <Style TargetType="DataGridRow">

                    <Setter Property="Background" Value="Black"></Setter>

                    <Setter Property="Foreground" Value="Gray"></Setter>

                </Style>

            </DataGrid.RowStyle>

            <DataGrid.Columns>

                <DataGridTextColumn Binding="{Binding Path=Code}"   Header="代码" Foreground="#FFD4CD2B" FontWeight="Bold"/>

                <DataGridTextColumn Binding="{Binding Path=Name}" HeaderStyle="{StaticResource ColumnHeaderStyle}" ElementStyle="{StaticResource contentCenterStyle}"   Width="100"   Header="名称" Foreground="#FFD4CD2B" FontSize="14" />

                <DataGridTemplateColumn Header="涨跌幅%" CanUserSort="True" SortMemberPath="Rose">

                    <DataGridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <TextBlock FontWeight="Bold" Text="{Binding Path=Rose,Converter={StaticResource percentConvert}}" Foreground="{Binding RoseColor}"></TextBlock>

                        </DataTemplate>

                    </DataGridTemplateColumn.CellTemplate>

                </DataGridTemplateColumn>

                

                <DataGridTemplateColumn Header="今日开盘价" CanUserSort="True" SortMemberPath="OpenPrice">

                    <DataGridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <TextBlock  FontWeight="Bold" Text="{Binding Path=OpenPrice}" Foreground="{Binding OpenPriceColor}"></TextBlock>

                        </DataTemplate>

                    </DataGridTemplateColumn.CellTemplate>

                </DataGridTemplateColumn>

                <DataGridTextColumn Binding="{Binding Path=ClosedPrice}"   Header="昨日收盘价" FontWeight="Bold"/>

               

                <DataGridTemplateColumn Header="当前价格" CanUserSort="True" SortMemberPath="CurrentPrice">

                    <DataGridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <TextBlock  FontWeight="Bold" Text="{Binding Path=CurrentPrice}" Foreground="{Binding CurrentPriceColor}"></TextBlock>

                        </DataTemplate>

                    </DataGridTemplateColumn.CellTemplate>

                </DataGridTemplateColumn>

                

                <DataGridTemplateColumn Header="涨跌" CanUserSort="True" SortMemberPath="UpAndDownPrice">

                    <DataGridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <TextBlock  FontWeight="Bold" Text="{Binding Path=UpAndDownPrice}" Foreground="{Binding UpAndDownPriceColor}"></TextBlock>

                        </DataTemplate>

                    </DataGridTemplateColumn.CellTemplate>

                </DataGridTemplateColumn>


                <DataGridTextColumn   Header="买进预警" Binding="{Binding Path=BuyWarn}" FontWeight="Bold"/>

                <DataGridTextColumn   Header="卖出预警" Binding="{Binding Path=SaleWarn}" FontWeight="Bold"/>

                <DataGridTemplateColumn Header="今日最高价" CanUserSort="True" SortMemberPath="HighPrice">

                    <DataGridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <TextBlock  FontWeight="Bold" Text="{Binding Path=HighPrice}" Foreground="{Binding HighPriceColor}"></TextBlock>

                        </DataTemplate>

                    </DataGridTemplateColumn.CellTemplate>

                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="今日最低价" CanUserSort="True" SortMemberPath="LowerPrice">

                    <DataGridTemplateColumn.CellTemplate>

                        <DataTemplate>

                            <TextBlock  FontWeight="Bold" Text="{Binding Path=LowerPrice}" Foreground="{Binding LowerPriceColor}"></TextBlock>

                        </DataTemplate>

                    </DataGridTemplateColumn.CellTemplate>

                </DataGridTemplateColumn>

                <DataGridTextColumn Binding="{Binding Path=DealCount}"   Header="成交股数"/>

                <DataGridTextColumn Binding="{Binding Path=DealMoney,Converter={StaticResource moneyConvert}}"   Header="成交金额"/>


                <DataGridTextColumn Binding="{Binding Path=Date,Converter={StaticResource dateConvert}}"   Header="时间"/>

            </DataGrid.Columns>

        </DataGrid>

    </DockPanel>

    

</Window>


后台CS

using StockTool.Model;
using StockTool.Util;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace StockTool
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        FYJ.Data.IDbHelper db = FYJ.Data.DbFactory.GetIDbHelper("stock");
        private System.Windows.Forms.Timer formTimer = new System.Windows.Forms.Timer();
        private bool isRefresh = true; //是否刷新
        //K线图
        private List<KLineModel> klineList = new List<KLineModel>();
        //数据
        private ObservableCollection<StockModel> data = new ObservableCollection<StockModel>();
        //这个方法比构造函数先执行
        protected async override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            formTimer = new System.Windows.Forms.Timer();
            formTimer.Interval = 10000;
            formTimer.Tick += formTimer_Tick;
            formTimer.Start();

            this.txtStatus.Text = "正在获取数据...";
            Task task = Task.Factory.StartNew(() =>
            {
                DataTable dt = db.GetDataTable("select * from stock_tb_show");
                foreach (DataRow dr in dt.Rows)
                {
                    StockModel model = new StockModel();
                    model.Code = dr["stockCode"].ToString();
                    if (dr["saleWarn"] != null && dr["saleWarn"].ToString() != "")
                    {
                        model.SaleWarn = Convert.ToDecimal(dr["saleWarn"]);
                    }
                    if (dr["buyWarn"] != null && dr["buyWarn"].ToString() != "")
                    {
                        model.BuyWarn = Convert.ToDecimal(dr["buyWarn"]);
                    }
                    data.Add(model);
                }
            });
            await task;
            this.txtStatus.Text = "正在刷新数据...";
            await RefreshData();
            this.dataGrid1.ItemsSource = data;
            this.txtStatus.Text = "就绪";
        }

        private async void formTimer_Tick(object sender, EventArgs e)
        {
            if (isRefresh == false)
            {
                return;
            }
            if (Util.StockHelper.IsInChargeTime())
            {
                this.txtStatus.Text = "正在刷新数据...";
                await RefreshData();
                this.txtStatus.Text = "就绪";
            }
            else
            {
                this.txtStatus.Text = "不在交易时段";
            }
        }

        private Task RefreshData()
        {
            Task task = Task.Factory.StartNew(() =>
            {
                StockHelper.RefreshData(data);
            });

            return task;
        }

        private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            radioKline_Checked(null, null);
        }

        private void radioKline_Checked(object sender, RoutedEventArgs e)
        {
            if (this.radioMin.IsChecked == true)
            {
                SetKline(KLineType.Min);
            }
            if (this.radioDaily.IsChecked == true)
            {
                SetKline(KLineType.Daily);
            }
            if (this.radioWeekly.IsChecked == true)
            {
                SetKline(KLineType.Weekly);
            }
            if (this.radioMonthly.IsChecked == true)
            {
                SetKline(KLineType.Monthly);
            }
        }

        public void SetKline(KLineType ktype)
        {
            StockModel model = (StockModel)this.dataGrid1.SelectedItem;
            if (model == null)
            {
                return;
            }
            string code = model.Code;
            KLineModel kline;
            //分时线每次都重新获取
            if (ktype == KLineType.Min)
            {
                kline = new KLineModel();
                kline.Code = code;
                kline.KType = ktype;
                kline.Source = StockHelper.GetKline(ktype, code);
            }
            else
            {
                kline = klineList.Where(c => c.Code == code && c.KType == ktype).FirstOrDefault();
                if (kline == null)
                {
                    kline = new KLineModel();
                    kline.Code = code;
                    kline.KType = ktype;
                    kline.Source = StockHelper.GetKline(ktype, code);
                    klineList.Add(kline);
                }
            }

            this.imgKLine.Source = kline.Source;
        }

        private async void menuRefresh_Click(object sender, RoutedEventArgs e)
        {
            this.txtStatus.Text = "正在刷新数据...";
            await RefreshData();
            this.txtStatus.Text = "就绪";
            this.menuStopRefresh.IsEnabled = true;
        }

        private async void menuAddStock_Click(object sender, RoutedEventArgs e)
        {
            AddForm frm = new AddForm();
            frm.ShowDialog();
            isRefresh = true;
            StockModel model = new StockModel();
            model.Code = frm.StockCode;
            model.Name = frm.StockName;
            data.Add(model);
            this.txtStatus.Text = "正在刷新数据...";
            await RefreshData();
            this.txtStatus.Text = "就绪";
        }

        private void menuDeleteStock_Click(object sender, RoutedEventArgs e)
        {
            StockModel model = (StockModel)this.dataGrid1.CurrentItem;
            if (model != null)
            {
                string sql = "delete from stock_tb_show where stockCode ='" + model.Code + "'";
                db.ExecuteSql(sql);
                data.Remove(model);
            }
        }

        private void menuBuyWarn_Click(object sender, RoutedEventArgs e)
        {
            StockModel model = (StockModel)this.dataGrid1.CurrentItem;
            if (model == null)
            {
                return;
            }

            WarnForm frm = new WarnForm();
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                db.ExecuteSql("update stock_tb_show set buyWarn='" + frm.WarnPrice + "' where stockCode='" + model.Code + "'");
                model.BuyWarn = frm.WarnPrice;
            }
        }

        private void menuSaleWarn_Click(object sender, RoutedEventArgs e)
        {
            StockModel model = (StockModel)this.dataGrid1.CurrentItem;
            if (model == null)
            {
                return;
            }

            WarnForm frm = new WarnForm();
            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                db.ExecuteSql("update stock_tb_show set saleWarn='" + frm.WarnPrice + "' where stockCode='" + model.Code + "'");
                model.SaleWarn = frm.WarnPrice;
            }
        }

        private void menuStopRefresh_Click(object sender, RoutedEventArgs e)
        {
            formTimer.Stop();
            isRefresh = false;
            this.txtStatus.Text = "刷新已停止";
            this.menuStopRefresh.IsEnabled = false;
        }
    }
}



上一篇:多线程域名查询工具

下一篇:个人代码全部开源


0 评论

查看所有评论

给个评论吧