WPF手机号码归属批量查询并导出到Excel
- 2020 年 7 月 8 日
- 筆記
工具下载地址://download.csdn.net/download/m0_37137902/12589801
1WPF页面xaml代码
<Window x:Class="CellPhoneNumberAttribution.MainWindow" xmlns="//schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="//schemas.microsoft.com/winfx/2006/xaml" xmlns:d="//schemas.microsoft.com/expression/blend/2008" xmlns:mc="//schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:CellPhoneNumberAttribution" xmlns:Metro="clr-namespace:Arthas.Controls.Metro;assembly=Arthas" mc:Ignorable="d" WindowStyle="None" Height="345" Width="960" Background="Transparent" Style="{StaticResource Window}" WindowStartupLocation="CenterScreen" ShowInTaskbar="True" x:Name="UserControl1" Icon="/Images/kunyu.png" SizeChanged="UserControl1_SizeChanged" AllowsTransparency="True" OpacityMask="White" ResizeMode="NoResize"> <Window.Resources> <ResourceDictionary> <WindowChrome x:Key="WindowChromeKey"> <WindowChrome.ResizeBorderThickness> <Thickness>5</Thickness> </WindowChrome.ResizeBorderThickness> </WindowChrome> </ResourceDictionary> </Window.Resources> <Grid Margin="0"> <Grid > <Grid.Background> <VisualBrush> <VisualBrush.Visual> <MediaElement> <MediaElement.Triggers> <EventTrigger RoutedEvent="MediaElement.Loaded"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard> <MediaTimeline x:Name="MP4" Source="..\Resources\花瓣飘落.mp4" RepeatBehavior="Forever"/> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> </MediaElement.Triggers> </MediaElement> </VisualBrush.Visual> </VisualBrush> </Grid.Background> <Grid.RowDefinitions> <RowDefinition Height="50"></RowDefinition> <RowDefinition Height="60"></RowDefinition> <RowDefinition Height="90"></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Grid Grid.Row="0" Margin="0,4,0,0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="30"></ColumnDefinition> <ColumnDefinition Width="105"></ColumnDefinition> <ColumnDefinition Width="520"></ColumnDefinition> <ColumnDefinition Width="120"></ColumnDefinition> <ColumnDefinition Width="120"></ColumnDefinition> <ColumnDefinition ></ColumnDefinition> </Grid.ColumnDefinitions> <Button Grid.Column="1" x:Name="btn_OpenExcel" Style="{StaticResource BUTTON_MENUBAR_PATH}" Background="{x:Null}" Content="打开文件 " FontSize="16" VerticalAlignment="Bottom" Foreground="White" Click="btn_OpenExcel_Click" Margin="8,0,0,0"/> <Grid Grid.Column="2"> <TextBlock x:Name="txt_FilePath" TextTrimming="CharacterEllipsis" Margin="0,0,0,5" Width="500" VerticalAlignment="Bottom" Foreground="White" FontSize="16" Text=""> </TextBlock> <Line X1="0" Y1="45" X2="510" Y2="45" StrokeEndLineCap="Round" StrokeThickness="2"> <Line.Stroke> <LinearGradientBrush EndPoint="0,0.5" StartPoint="1,1"> <GradientStop Color="White"/> <GradientStop Offset="100"/> </LinearGradientBrush> </Line.Stroke> </Line> </Grid> <ComboBox Name="Com_SelectWay" Style="{StaticResource ComboBoxStyle}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Background="Transparent" Grid.Column="3" Width="118" Height="40" Text="方式"> <ComboBoxItem Content="本地"></ComboBoxItem> <ComboBoxItem Content="联网"></ComboBoxItem> <ComboBoxItem Content="本地/联网"></ComboBoxItem> </ComboBox> <Button Grid.Column="4" x:Name="btn_Start" Style="{StaticResource BUTTON_DISAGREE}" Content="分析数据" VerticalAlignment="Center" HorizontalAlignment="Center" Width="118" Height="40" Foreground="White" FontSize="16" BorderThickness="0" Click="btn_Start_Click" /> <Button Grid.Column="5" x:Name="btn_Close" Style="{StaticResource BUTTON_MENUBAR_MINI}" VerticalAlignment="Center" HorizontalAlignment="Center" Width="30" Height="30" Click="btn_Close_Click" > <Button.Background> <ImageBrush ImageSource="/Images/close.png"/> </Button.Background> </Button> </Grid> <Grid Grid.Row="1"> </Grid> <Grid Grid.Row="2"> <Grid.RowDefinitions> <RowDefinition ></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Metro:MetroProgressBar x:Name="pb2" Grid.Row="0" Width="700" Margin="5" Grid.Column="1" Value="0" TextHorizontalAlignment="Right" Maximum="100" /> <TextBlock x:Name="txt_Pro" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" TextTrimming="CharacterEllipsis" FontSize="14" Height="25" Width="700" Foreground="White" /> <TextBlock x:Name="txt_info" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Center" TextTrimming="CharacterEllipsis" FontSize="14" Height="25" Width="700" Foreground="White" /> </Grid> <Grid Grid.Row="3"> <Grid.ColumnDefinitions> <ColumnDefinition Width="1.4*"></ColumnDefinition> <ColumnDefinition ></ColumnDefinition> <ColumnDefinition ></ColumnDefinition> <ColumnDefinition ></ColumnDefinition> <ColumnDefinition ></ColumnDefinition> </Grid.ColumnDefinitions> <Button Grid.Column="3" x:Name="btn_Export" Style="{StaticResource BUTTON_DISAGREE}" Content="导出" Margin="0,8,0,0" VerticalAlignment="Center" HorizontalAlignment="Center" Width="130" Height="40" Foreground="White" FontSize="16" BorderBrush="{x:Null}" Click="btn_Export_Click" /> <Button Grid.Column="4" x:Name="btn_Cancel" Style="{StaticResource BUTTON_DISAGREE}" Content="取消" FontSize="16" HorizontalAlignment="Center" VerticalAlignment="Center" Width="120" Height="40" Foreground="White" Margin="0,8,0,0" Click="btn_Close_Click" /> </Grid> </Grid> </Grid> </Window>
View Code
2xaml.cs代码
using Microsoft.Win32; using Org.BouncyCastle.Asn1.Cmp; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.OleDb; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; namespace CellPhoneNumberAttribution { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { DataTable PhoneNumberDt = new DataTable(); string SelectFilePath = string.Empty; String fileName = string.Empty; List<string> FaildPhoneNumberList = new List<string>(); string API_IphoneNumbers = "//tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel="; public MainWindow() { InitializeComponent(); this.Loaded += (r, s) => { this.MouseDown += (x, y) => { if (y.LeftButton == MouseButtonState.Pressed) { this.DragMove(); } }; }; string mp4filePath= System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "smjn.mp4"; MP4.Source= new Uri(mp4filePath); } /// <summary> /// 打开数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_OpenExcel_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "选择数据源文件"; openFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel 97-2003文件(*.xls)|*.xls"; openFileDialog.FileName = string.Empty; openFileDialog.FilterIndex = 1; openFileDialog.Multiselect = false; openFileDialog.RestoreDirectory = true; openFileDialog.DefaultExt = "txt"; if (openFileDialog.ShowDialog() == false) { return; } SelectFilePath = txt_FilePath.Text = openFileDialog.FileName; } /// <summary> /// 分析数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_Start_Click(object sender, RoutedEventArgs e) { if (File.Exists(SelectFilePath)) { if (Com_SelectWay.SelectedIndex > -1) { if (((ComboBoxItem)Com_SelectWay.SelectedItem).Content.ToString().Trim() == "本地") { Thread thread = new Thread(new ThreadStart(DataAnalyst)); thread.Start(); txt_Pro.Text = "数据库准备中..."; } else if (((ComboBoxItem)Com_SelectWay.SelectedItem).Content.ToString().Trim() == "联网") { Thread thread = new Thread(new ThreadStart(ApiSelect)); thread.Start(); txt_Pro.Text = "数据库准备中..."; } else if (((ComboBoxItem)Com_SelectWay.SelectedItem).Content.ToString().Trim() == "本地/联网") { Thread thread = new Thread(new ThreadStart(LocalAndApiAnalys)); thread.Start(); txt_Pro.Text = "数据库准备中..."; } } else { MessageBox.Show("请选择数据分析方式!"); } } else { MessageBox.Show("请选择电话号码Excel文件路径!"); } } /// <summary> /// 本地 /// </summary> private void DataAnalyst() { PhoneNumberDt = ReadExcelToDataTable.ReadExcel(SelectFilePath); Dictionary<string, string> DicTableProfessionalTable = new Dictionary<string, string>() { { "电话号码", "number" }, { "省", "province" }, { "市", "city" } }; foreach (DataColumn dc in PhoneNumberDt.Columns) { dc.ColumnName = DicTableProfessionalTable[dc.ColumnName]; } DataTable phonesDt = CSQLiteHelper.SelectData("select * from phones"); DataTable regionsDt = CSQLiteHelper.SelectData("select * from regions"); Dictionary<string, string> phonesDic = phonesDt.Rows.Cast<DataRow>().ToDictionary(x => x["number"].ToString(), x => x["region_id"].ToString()); Dictionary<string, string> regionsDic = regionsDt.Rows.Cast<DataRow>().ToDictionary(x => x["id"].ToString(), x => x["province"].ToString() + "省" + x["city"].ToString() + "市"); App.Current.Dispatcher.Invoke((Action)delegate () { txt_Pro.Text = "正在进行分析,请勿关闭程序"; }); for (int i = 0; i < PhoneNumberDt.Rows.Count; i++) { string number = PhoneNumberDt.Rows[i]["number"].ToString().Trim(); try { string region_id = phonesDic[number.Substring(0, 7)]; string area = regionsDic[region_id]; int indexProvince = area.IndexOf("省")+1; PhoneNumberDt.Rows[i]["province"] = area.Substring(0, indexProvince); PhoneNumberDt.Rows[i]["city"] = area.Substring(indexProvince, area.Length-indexProvince); double pro = Convert.ToDouble(i+1) / Convert.ToDouble(PhoneNumberDt.Rows.Count) * 100; App.Current.Dispatcher.Invoke((Action)delegate () { pb2.Value = pro; //string strs = "当前号吗:" + PhoneNumberDt.Rows[i]["number"].ToString().Trim() + "-" + area; //txt_Pro.Text = strs; }); } catch { FaildPhoneNumberList.Add(number); } } App.Current.Dispatcher.Invoke((Action)delegate () { txt_Pro.Text = "分析完成!共" + PhoneNumberDt.Rows.Count.ToString() + "条数据。 成功" + (PhoneNumberDt.Rows.Count - FaildPhoneNumberList.Count).ToString() + "个" + "失败" + FaildPhoneNumberList.Count.ToString() + "个,点击导出按钮即可导出分析结果"; txt_info.Text ="失败记录请于" + @"C:\Users\Administrator\Desktop\FaileNumbers.txt" + "文件中查看"; }); } /// <summary> /// 联网 /// </summary> private void ApiSelect() { PhoneNumberDt = ReadExcelToDataTable.ReadExcel(SelectFilePath); Dictionary<string, string> DicTableProfessionalTable = new Dictionary<string, string>() { { "电话号码", "number" }, { "省", "province" }, { "市", "city" } }; foreach (DataColumn dc in PhoneNumberDt.Columns) { dc.ColumnName = DicTableProfessionalTable[dc.ColumnName]; } App.Current.Dispatcher.Invoke((Action)delegate () { txt_Pro.Text = "正在进行分析,请勿关闭程序"; }); for (int i = 0; i < PhoneNumberDt.Rows.Count; i++) { string number = PhoneNumberDt.Rows[i]["number"].ToString().Trim(); try { string result = GetStringByUrl(API_IphoneNumbers + number.Substring(0,11)); int index = result.IndexOf("province:'"); int indexs = result.IndexOf("catName"); PhoneNumberDt.Rows[i]["province"] = result.Substring(index, indexs - index).Replace("',\n", "").Trim(); double pro = Convert.ToDouble(i + 1) / Convert.ToDouble(PhoneNumberDt.Rows.Count) * 100; App.Current.Dispatcher.Invoke((Action)delegate () { pb2.Value = pro; }); } catch { FaildPhoneNumberList.Add(number); } } App.Current.Dispatcher.Invoke((Action)delegate () { txt_Pro.Text = "分析完成!共" + PhoneNumberDt.Rows.Count.ToString() + "条数据。 成功" + (PhoneNumberDt.Rows.Count - FaildPhoneNumberList.Count).ToString() + "个" + "失败" + FaildPhoneNumberList.Count.ToString() + "个,点击导出按钮即可导出分析结果"; txt_info.Text = "失败记录请于" + @"C:\Users\Administrator\Desktop\FaileNumbers.txt" + "文件中查看"; }); } /// <summary> /// 本地/联网 /// </summary> private void LocalAndApiAnalys() { PhoneNumberDt = ReadExcelToDataTable.ReadExcel(SelectFilePath); Dictionary<string, string> DicTableProfessionalTable = new Dictionary<string, string>() { { "电话号码", "number" }, { "省", "province" }, { "市", "city" } }; foreach (DataColumn dc in PhoneNumberDt.Columns) { dc.ColumnName = DicTableProfessionalTable[dc.ColumnName]; } DataTable phonesDt = CSQLiteHelper.SelectData("select * from phones"); DataTable regionsDt = CSQLiteHelper.SelectData("select * from regions"); Dictionary<string, string> phonesDic = phonesDt.Rows.Cast<DataRow>().ToDictionary(x => x["number"].ToString(), x => x["region_id"].ToString()); Dictionary<string, string> regionsDic = regionsDt.Rows.Cast<DataRow>().ToDictionary(x => x["id"].ToString(), x => x["province"].ToString() + "省" + x["city"].ToString() + "市"); App.Current.Dispatcher.Invoke((Action)delegate () { txt_Pro.Text = "正在进行分析,请勿关闭程序"; }); for (int i = 0; i < PhoneNumberDt.Rows.Count; i++) { string number = PhoneNumberDt.Rows[i]["number"].ToString().Trim(); try { string region_id = phonesDic[number.Substring(0, 7)]; string area = regionsDic[region_id]; int indexProvince = area.IndexOf("省")+1; PhoneNumberDt.Rows[i]["province"] = area.Substring(0, indexProvince); PhoneNumberDt.Rows[i]["city"] = area.Substring(indexProvince, area.Length - indexProvince); //PhoneNumberDt.Rows[i]["province"] = area;//.Substring(0,area.IndexOf("省")); //PhoneNumberDt.Rows[i]["city"] = area.Substring( area.IndexOf("省"),area.Length); double pro = Convert.ToDouble(i + 1) / Convert.ToDouble(PhoneNumberDt.Rows.Count) * 100; App.Current.Dispatcher.Invoke((Action)delegate () { pb2.Value = pro; //string strs = "当前号吗:" + PhoneNumberDt.Rows[i]["number"].ToString().Trim() + "-" + area; //txt_Pro.Text = strs; }); } catch { try { string result = GetStringByUrl(API_IphoneNumbers + number.Substring(0,11)); int index = result.IndexOf("province:'"); int indexs = result.IndexOf("catName"); PhoneNumberDt.Rows[i]["province"] = result.Substring(index, indexs - index).Replace("',\n", "").Trim(); double pro = Convert.ToDouble(i + 1) / Convert.ToDouble(PhoneNumberDt.Rows.Count) * 100; App.Current.Dispatcher.Invoke((Action)delegate () { pb2.Value = pro; }); } catch { FaildPhoneNumberList.Add(number); } } } App.Current.Dispatcher.Invoke((Action)delegate () { txt_Pro.Text = "分析完成!共" + PhoneNumberDt.Rows.Count.ToString() + "条数据。 成功" + (PhoneNumberDt.Rows.Count - FaildPhoneNumberList.Count).ToString() + "个" + "失败" + FaildPhoneNumberList.Count.ToString() + "个,点击导出按钮即可导出分析结果"; txt_info.Text = "失败记录请于" + @"C:\Users\Administrator\Desktop\FaileNumbers.txt" + "文件中查看"; }); } /// <summary> /// 抓取网页html代码 /// </summary> /// <param name="strUrl">URL</param> /// <returns></returns> private static string GetStringByUrl(string strUrl) { //与指定URL创建HTTP请求 WebRequest wrt = WebRequest.Create(strUrl); //获取对应HTTP请求的响应 WebResponse wrse = wrt.GetResponse(); //获取响应流 Stream strM = wrse.GetResponseStream(); //对接响应流(以"GBK"字符集) StreamReader SR = new StreamReader(strM, Encoding.GetEncoding("GB2312")); //获取响应流的全部字符串 string strallstrm = SR.ReadToEnd(); //关闭读取流 SR.Close(); //返回网页html代码 return strallstrm; } /// <summary> /// 导出到Excel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_Export_Click(object sender, RoutedEventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel 97-2003文件(*.xls)|*.xls"; saveFileDialog.FilterIndex = 1; saveFileDialog.RestoreDirectory = true; saveFileDialog.FilterIndex = 1; saveFileDialog.RestoreDirectory = true; saveFileDialog.FileName = "电话号码" + DateTime.Now.ToString("yyyyMMddHHmm"); if (saveFileDialog.ShowDialog() == true) { fileName = saveFileDialog.FileName.ToString(); if (File.Exists(fileName)) { File.Delete(fileName); } Thread thread = new Thread(new ThreadStart(this.SaveExcel)); thread.Start(); } } private void SaveExcel() { string[] headList; headList = new string[] { "电话号码", "省", "市", }; ReadExcelToDataTable.ExportToExcel(PhoneNumberDt, headList, fileName); if (FaildPhoneNumberList.Count > 0) { FileStream fs = new FileStream(@"C:\Users\Administrator\Desktop\FaileNumbers.txt",FileMode.OpenOrCreate,FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.Flush(); sw.BaseStream.Seek(0,SeekOrigin.Begin); for(int i=0;i<FaildPhoneNumberList.Count;i++) { sw.WriteLine(FaildPhoneNumberList[i]); } } Process.Start(fileName); } /// <summary> /// 关闭程序 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_Close_Click(object sender, RoutedEventArgs e) { Environment.Exit(0); } /// <summary> /// 窗体圆角 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UserControl1_SizeChanged(object sender, SizeChangedEventArgs e) { System.Windows.Rect r = new System.Windows.Rect(e.NewSize); RectangleGeometry gm = new RectangleGeometry(r, 15, 15); // 40 is radius here ((UIElement)sender).Clip = gm; } } }
View Code
3资源字典
<ResourceDictionary xmlns="//schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="//schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:CellPhoneNumberAttribution"> <Style TargetType="ToggleButton" x:Key="ComboxStyleBtn"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Border x:Name="Back" Background="Transparent" BorderThickness="1" BorderBrush="Transparent"> <!--Combox三角--> <Path Name="PathFill" Fill="White" Width="8" Height="6" StrokeThickness="0" Data="M5,0 L10,10 L0,10 z" RenderTransformOrigin="0.5,0.5" Stretch="Fill"> <Path.RenderTransform> <TransformGroup> <ScaleTransform/> <SkewTransform/> <RotateTransform Angle="180"/> <TranslateTransform/> </TransformGroup> </Path.RenderTransform> </Path> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="PathFill" Property="Fill" Value="#f6f5ec"></Setter> <Setter TargetName="Back" Property="Background" Value="#f6f5ec"></Setter> <Setter TargetName="Back" Property="BorderBrush" Value="#f6f5ec"></Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="ToggleButton" x:Key="ComboxStyleBtnGray"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Border x:Name="Back" Background="Transparent" BorderThickness="1" BorderBrush="Transparent"> <!--Combox三角--> <Path Name="PathFill" Fill="Gray" Width="8" Height="6" StrokeThickness="0" Data="M5,0 L10,10 L0,10 z" RenderTransformOrigin="0.5,0.5" Stretch="Fill"> <Path.RenderTransform> <TransformGroup> <ScaleTransform/> <SkewTransform/> <RotateTransform Angle="180"/> <TranslateTransform/> </TransformGroup> </Path.RenderTransform> </Path> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="PathFill" Property="Fill" Value="#f6f5ec"></Setter> <Setter TargetName="Back" Property="Background" Value="#f6f5ec"></Setter> <Setter TargetName="Back" Property="BorderBrush" Value="#f6f5ec"></Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <ControlTemplate x:Key="CBCustomToggleButton" TargetType="ToggleButton"> <Grid> <Border Name="Border" BorderThickness="1,1,1,1"/> <Border Name="SmallBorder" BorderThickness="0,0,1,0" /> <Path Name="Arrow" Width="10" Data="M0,0 L0,2 L4,6 L8,2 L8,0 L4,4 z" Fill="White" /> </Grid> <ControlTemplate.Triggers> <Trigger Property="UIElement.IsMouseOver" Value="True"> <Setter TargetName="Border" Property="BorderBrush" Value="White" /> <Setter TargetName="SmallBorder" Property="BorderBrush" Value="White" /> <Setter TargetName="Arrow" Property="Fill" Value="White" /> </Trigger> <Trigger Property="ToggleButton.IsChecked" Value="True"> <Setter TargetName="Border" Property="BorderBrush" Value="White" /> <Setter TargetName="SmallBorder" Property="BorderBrush" Value="White" /> </Trigger> <Trigger Property="UIElement.IsEnabled" Value="False"> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> <Style x:Key="MyComBoxStyle" TargetType="{x:Type ComboBox}"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate TargetType="ComboBox"> <Grid> <ToggleButton Name="ToggleButton" Template="{StaticResource CBCustomToggleButton}" /> <ContentPresenter Name="ContentSite" Content="{TemplateBinding ComboBox.SelectionBoxItem}"/> <TextBox x:Name="PART_EditableTextBox" Foreground="{TemplateBinding Foreground}" IsReadOnly="{TemplateBinding IsReadOnly}" Background="Transparent" Visibility="Hidden" /> <Popup Name="PART_Popup"> <Grid Name="DropDown" MinWidth="{TemplateBinding FrameworkElement.ActualWidth}" MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}" SnapsToDevicePixels="True"> <Border Name="DropDownBorder" Background="{TemplateBinding ComboBox.Background}"> <ScrollViewer Margin="4,6,4,6"> <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" /> </ScrollViewer> </Border> </Grid> </Popup> </Grid> <ControlTemplate.Triggers> <Trigger SourceName="PART_Popup" Property="Window.AllowsTransparency" Value="True"> <Setter TargetName="DropDownBorder" Property="FrameworkElement.Margin" Value="0,2,0,0" /> </Trigger> <Trigger Property="ComboBox.IsEditable" Value="True"> <Setter Property="KeyboardNavigation.IsTabStop" Value="False" /> <Setter TargetName="PART_EditableTextBox" Property="UIElement.Visibility" Value="Visible" /> <Setter TargetName="ContentSite" Property="UIElement.Visibility" Value="Hidden" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type ComboBoxItem}"> <Setter Property="FrameworkElement.OverridesDefaultStyle" Value="True" /> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ComboBoxItem}"> <Border> <ContentPresenter /> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> <ControlTemplate x:Key="CustomToggleButton" TargetType="ToggleButton"> <Grid> <Border Name="Border" /> <Border Name="SmallBorder" /> <Path Name="Arrow" /> </Grid> </ControlTemplate> <Style TargetType="{x:Type ComboBox}"> <Setter Property="FrameworkElement.OverridesDefaultStyle" Value="True" /> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate TargetType="ComboBox"> <Grid> <ToggleButton Template="{StaticResource CustomToggleButton}" /> <ContentPresenter /> <TextBox /> <Popup> <Grid> <Border> <ScrollViewer> <ItemsPresenter /> </ScrollViewer> </Border> </Grid> </Popup> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <!--Combox--> <Style TargetType="ComboBox" x:Key="ComboBoxStyle"> <Setter Property="ItemContainerStyle"> <Setter.Value> <!--ComBoxItem--> <Style TargetType="ComboBoxItem"> <Setter Property="Height" Value="24"></Setter> <Setter Property="VerticalContentAlignment" Value="Center"></Setter> <Setter Property="HorizontalContentAlignment" Value="Center"></Setter> <Setter Property="VerticalAlignment" Value="Center"></Setter> <Setter Property="HorizontalAlignment" Value="Center"></Setter> <Setter Property="Width" Value="80"></Setter> <Setter Property="FontSize" Value="14"></Setter> <Setter Property="Foreground" Value="#a1a3a6"></Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ComboBoxItem"> <Border Name="Back" Background="Transparent" BorderThickness="0,0,0,0" BorderBrush="#a1a3a6" > <ContentPresenter ContentSource="{Binding Source}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,0,0,0"></ContentPresenter> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="Back" Property="Background" Value="#d3c6a6"></Setter> </Trigger> <Trigger Property="IsHighlighted" Value="True"> <Setter TargetName="Back" Property="Background" Value="#f6f5ec"></Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Setter.Value> </Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ComboBox"> <Grid > <Grid.ColumnDefinitions> <ColumnDefinition Width="0.7*"/> <ColumnDefinition Width="0.3*" MaxWidth="30"/> </Grid.ColumnDefinitions> <!--Combox分为Textbox Border Popup三个控件--> <TextBox Grid.Column="0" Foreground="White" FontSize="14" Background="Transparent" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" IsReadOnly="{TemplateBinding IsReadOnly}" BorderBrush="Transparent" Text="{TemplateBinding Text}"></TextBox> <Border Grid.Column="0" BorderThickness="1,1,0,1" BorderBrush="White" CornerRadius="7,0,0,7"> </Border> <Border Grid.Column="1" BorderThickness="0,1,1,1" BorderBrush="White" CornerRadius="0,7,7,0"> <ToggleButton Style="{StaticResource ComboxStyleBtn}" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"></ToggleButton> </Border> <Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" x:Name="Popup" Focusable="False" AllowsTransparency="True" PopupAnimation="Slide"> <Border CornerRadius="1" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True"> <Border.Effect> <DropShadowEffect Color="Black" BlurRadius="2" ShadowDepth="0" Opacity="0.5"/> </Border.Effect> <ScrollViewer Margin="4,6,4,6" Style="{DynamicResource ScrollViewerStyle}" MaxHeight="{TemplateBinding MaxDropDownHeight}" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True"> <!-- StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True --> <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" Background="White"/> </ScrollViewer> </Border> </Popup> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="ComboBox" x:Key="ComboBoxStyleGray"> <Setter Property="ItemContainerStyle"> <Setter.Value> <!--ComBoxItem--> <Style TargetType="ComboBoxItem"> <Setter Property="Height" Value="24"></Setter> <Setter Property="VerticalContentAlignment" Value="Center"></Setter> <Setter Property="HorizontalContentAlignment" Value="Center"></Setter> <Setter Property="VerticalAlignment" Value="Center"></Setter> <Setter Property="HorizontalAlignment" Value="Center"></Setter> <Setter Property="Width" Value="80"></Setter> <Setter Property="FontSize" Value="14"></Setter> <Setter Property="Foreground" Value="#a1a3a6"></Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ComboBoxItem"> <Border Name="Back" Background="Transparent" BorderThickness="0,0,0,0" BorderBrush="#a1a3a6" > <ContentPresenter ContentSource="{Binding Source}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,0,0,0"></ContentPresenter> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="Back" Property="Background" Value="#d3c6a6"></Setter> </Trigger> <Trigger Property="IsHighlighted" Value="True"> <Setter TargetName="Back" Property="Background" Value="#f6f5ec"></Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Setter.Value> </Setter> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ComboBox"> <Grid > <Grid.ColumnDefinitions> <ColumnDefinition Width="0.7*"/> <ColumnDefinition Width="0.3*" MaxWidth="30"/> </Grid.ColumnDefinitions> <!--Combox分为Textbox Border Popup三个控件--> <TextBox Grid.Column="0" Foreground="Gray" FontSize="14" Background="Transparent" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" IsReadOnly="{TemplateBinding IsReadOnly}" BorderBrush="Transparent" Text="{TemplateBinding Text}"></TextBox> <Border Grid.Column="0" BorderThickness="1,1,0,1" BorderBrush="Gray" CornerRadius="7,0,0,7"> </Border> <Border Grid.Column="1" BorderThickness="0,1,1,1" BorderBrush="Gray" CornerRadius="0,7,7,0"> <ToggleButton Style="{StaticResource ComboxStyleBtnGray}" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"></ToggleButton> </Border> <Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" x:Name="Popup" Focusable="False" AllowsTransparency="True" PopupAnimation="Slide"> <Border CornerRadius="1" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True"> <Border.Effect> <DropShadowEffect Color="Black" BlurRadius="2" ShadowDepth="0" Opacity="0.5"/> </Border.Effect> <ScrollViewer Margin="4,6,4,6" Style="{DynamicResource ScrollViewerStyle}" MaxHeight="{TemplateBinding MaxDropDownHeight}" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True"> <!-- StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True --> <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" Background="White"/> </ScrollViewer> </Border> </Popup> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="Window" TargetType="Window"> <Setter Property="WindowStyle" Value="None"/> <Setter Property="AllowsTransparency" Value="True"/> <Setter Property="Background" Value="Transparent"/> </Style> <Style x:Key="BUTTON_MENUBAR" TargetType="Button"> <Setter Property="VerticalAlignment" Value="Top"/> <Setter Property="HorizontalAlignment" Value="Right"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"> <Grid Name="g" Opacity="0" Background="LightGray"/> <Grid Name="grd" RenderTransformOrigin="0.5,0.5" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Background="{TemplateBinding Background}" VerticalAlignment="Center" HorizontalAlignment="Center" > <Grid.RenderTransform> <TransformGroup> <!--<RotateTransform x:Name="rotate" Angle="0"--> <ScaleTransform x:Name="scale" ScaleX="0.8" ScaleY="0.8"/> </TransformGroup> </Grid.RenderTransform> </Grid> <ContentPresenter HorizontalAlignment="Left" VerticalAlignment="Center" /> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Trigger.EnterActions> <BeginStoryboard > <Storyboard> <DoubleAnimation To="0.2" Duration="0:0:0.2" Storyboard.TargetName="g" Storyboard.TargetProperty="Opacity" /> <DoubleAnimation To="1" Duration="0:0:0.2" Storyboard.TargetName="scale" Storyboard.TargetProperty="ScaleX" /> <DoubleAnimation To="1" Duration="0:0:0.2" Storyboard.TargetName="scale" Storyboard.TargetProperty="ScaleY" /> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard > <Storyboard> <DoubleAnimation To="0" Duration="0:0:0.2" Storyboard.TargetName="g" Storyboard.TargetProperty="Opacity" /> <DoubleAnimation To="0.8" Duration="0:0:0.2" Storyboard.TargetName="scale" Storyboard.TargetProperty="ScaleX" /> <DoubleAnimation To="0.8" Duration="0:0:0.2" Storyboard.TargetName="scale" Storyboard.TargetProperty="ScaleY" /> </Storyboard> </BeginStoryboard> </Trigger.ExitActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="BUTTON_MENUBAR_PATH" TargetType="Button"> <Setter Property="VerticalAlignment" Value="Top"/> <Setter Property="HorizontalAlignment" Value="Left"/> <Setter Property="Foreground" Value="Gray" /> <Setter Property="Height" Value="30"/> <Setter Property="Width" Value="Auto"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"> <Grid Name="g" Background="LightGray" Opacity="0" /> <Grid Name="grd" Width="22" Height="22" Background="{TemplateBinding Background}" VerticalAlignment="Center" HorizontalAlignment="Center"/> <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" /> <Path Width="10" Height="30" HorizontalAlignment="Right" VerticalAlignment="Center" Data="M3,10 L7,15 L3,20" Stroke="White" StrokeThickness="1"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Trigger.EnterActions> <BeginStoryboard > <Storyboard> <DoubleAnimation To="0.4" Duration="0:0:0.2" Storyboard.TargetName="g" Storyboard.TargetProperty="Opacity" /> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard > <Storyboard> <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="g" Storyboard.TargetProperty="Opacity" /> </Storyboard> </BeginStoryboard> </Trigger.ExitActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="BUTTON_MENUBAR_MINI" TargetType="Button"> <Setter Property="VerticalAlignment" Value="Top"/> <Setter Property="HorizontalAlignment" Value="Right"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" ClipToBounds="True"> <Border Name="bdr" BorderBrush="LightGray" BorderThickness="2" Opacity="0"> <Border.Effect> <DropShadowEffect x:Name="effect" BlurRadius="20" Opacity="0.8" ShadowDepth="0" Color="LightGray"/> </Border.Effect> </Border> <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Background="{TemplateBinding Background}" VerticalAlignment="Center" HorizontalAlignment="Center" > </Grid> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Trigger.EnterActions> <BeginStoryboard > <Storyboard> <DoubleAnimation To="1" Duration="0:0:0.3" Storyboard.TargetName="bdr" Storyboard.TargetProperty="Opacity" /> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard > <Storyboard> <DoubleAnimation To="0" Duration="0:0:0.3" Storyboard.TargetName="bdr" Storyboard.TargetProperty="Opacity" /> </Storyboard> </BeginStoryboard> </Trigger.ExitActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type Button}" x:Key="DefaultButtonWhite"> <Setter Property="Foreground" Value="Gray"/> <Setter Property="FontFamily" Value="Microsoft YaHei"/> <Setter Property="FontSize" Value="13"/> <Setter Property="FontWeight" Value="Normal"/> <Setter Property="Height" Value="30"/> <Setter Property="Width" Value="60"/> <Setter Property="Margin" Value="0,0,0,0"/> <Setter Property="VerticalAlignment" Value="Center"/> <Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border x:Name="border" BorderBrush="#4977FC" BorderThickness="1" CornerRadius="15,15,15,15"> <Border.Background> <LinearGradientBrush EndPoint="0,1" StartPoint="0,0"> <GradientStop Color="White" Offset="0.0" /> <GradientStop Color="White" Offset="0.0" /> <GradientStop Color="White" Offset="0.0" /> </LinearGradientBrush> </Border.Background> <ContentPresenter Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center" VerticalAlignment="Center" /> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="border" Property="Background" Value="#4977FC"/> <Setter Property="Foreground" Value="White"/> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="border" Property="Background" Value="#5CACEE"/> <Setter Property="Foreground" Value="White"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type Button}" x:Key="DefaultButtonBlue"> <Setter Property="Foreground" Value="White"/> <Setter Property="FontFamily" Value="Microsoft YaHei"/> <Setter Property="FontSize" Value="18"/> <Setter Property="FontWeight" Value="Normal"/> <Setter Property="Height" Value="40"/> <Setter Property="Width" Value="100"/> <Setter Property="Margin" Value="0,0,0,0"/> <Setter Property="VerticalAlignment" Value="Center"/> <Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="0" CornerRadius="20,20,20,20"> <Border.Background> <LinearGradientBrush EndPoint="0,1" StartPoint="0,0"> <GradientStop Color="#4977FC" Offset="0.0" /> <GradientStop Color="#4977FC" Offset="0.2" /> <GradientStop Color="#4977FC" Offset="0.0" /> </LinearGradientBrush> </Border.Background> <ContentPresenter Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center" VerticalAlignment="Center" /> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="BUTTON_AGREE" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border Name="bdr" CornerRadius="3" Opacity="0.5" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1"> <!--可使用ContentPresenter代替--> <!--Foreground的值White可以替换为{TemplateBinding Foreground}--> <Label VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Foreground="White" Content="{TemplateBinding Content}"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Trigger.EnterActions> <BeginStoryboard > <Storyboard> <DoubleAnimation To="0.7" Duration="0:0:0.2" Storyboard.TargetName="bdr" Storyboard.TargetProperty="Opacity" /> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard > <Storyboard> <DoubleAnimation To="0.5" Duration="0:0:0.2" Storyboard.TargetName="bdr" Storyboard.TargetProperty="Opacity" /> </Storyboard> </BeginStoryboard> </Trigger.ExitActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="BUTTON_DISAGREE" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border CornerRadius="3" BorderBrush="#FFEBEBEB" BorderThickness="1"> <Grid> <Border Name="bdr" CornerRadius="3" Background="Gray" Opacity="0"/> <Label VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Foreground="{TemplateBinding Foreground}" Content="{TemplateBinding Content}"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Trigger.EnterActions> <BeginStoryboard > <Storyboard> <DoubleAnimation To="0.2" Duration="0:0:0.2" Storyboard.TargetName="bdr" Storyboard.TargetProperty="Opacity" /> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard > <Storyboard> <DoubleAnimation To="0" Duration="0:0:0.2" Storyboard.TargetName="bdr" Storyboard.TargetProperty="Opacity" /> </Storyboard> </BeginStoryboard> </Trigger.ExitActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="BtnInfoStyle" TargetType="Button"> <Setter Property="Width" Value="150"/> <Setter Property="Height" Value="55"/> <Setter Property="Foreground" Value="Gray"/> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Background" Value="Transparent"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True"> <TextBlock Text="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" VerticalAlignment="Center" HorizontalAlignment="Center"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="border" Property="Background" Value="Transparent"/> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="border" Property="Background" Value="Transparent"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <SolidColorBrush x:Key="SOLIDCOLORBRUSH_LIGHT" Color="#FF6FD1FF"/> <Color x:Key="COLOR_LIGHT" R="111" G="209" B="255" A="255" /> <Style x:Key="BUTTON_ELLIPSE" TargetType="{x:Type Button}"> <Setter Property="Cursor" Value="Hand"/> <Setter Property="ToolTip" Value="下一步"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border CornerRadius="15" Width="30" Height="30" Background="{DynamicResource SOLIDCOLORBRUSH_LIGHT}"> <Border.Effect> <DropShadowEffect x:Name="effect" BlurRadius="7" Opacity="0.6" ShadowDepth="0" Color="{DynamicResource COLOR_LIGHT}"/> </Border.Effect> <Grid> <Path Name="path" HorizontalAlignment="Left" Margin="0,0,0,0" Data="M5,15 L 15,23 L24,9" Stroke="White" StrokeThickness="1"/> <Path Name="path2" HorizontalAlignment="Left" Opacity="0" Margin="0,0,0,0" Data="M5,15 H25 L17,7 M25,15 L17,22 " Stroke="White" StrokeThickness="1"/> </Grid> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Trigger.EnterActions> <BeginStoryboard > <Storyboard> <DoubleAnimation To="0.9" Duration="0:0:0.3" Storyboard.TargetName="effect" Storyboard.TargetProperty="Opacity" /> <DoubleAnimation To="15" Duration="0:0:0.3" Storyboard.TargetName="effect" Storyboard.TargetProperty="BlurRadius" /> <DoubleAnimation To="0" Duration="0:0:0.5" Storyboard.TargetName="path" Storyboard.TargetProperty="Opacity" /> <DoubleAnimation To="1" Duration="0:0:0.5" BeginTime="0:0:0.3" Storyboard.TargetName="path2" Storyboard.TargetProperty="Opacity" /> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard > <Storyboard> <DoubleAnimation Duration="0:0:0.3" Storyboard.TargetName="effect" Storyboard.TargetProperty="Opacity" /> <DoubleAnimation Duration="0:0:0.3" Storyboard.TargetName="effect" Storyboard.TargetProperty="BlurRadius" /> <DoubleAnimation Duration="0:0:0.5" BeginTime="0:0:0.3" Storyboard.TargetName="path" Storyboard.TargetProperty="Opacity" /> <DoubleAnimation Duration="0:0:0.5" Storyboard.TargetName="path2" Storyboard.TargetProperty="Opacity" /> </Storyboard> </BeginStoryboard> </Trigger.ExitActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>
View Code
4读取导出Excel与DataTable转换的类
public class ReadExcelToDataTable { /// <summary> /// Excel->DataTable /// </summary> /// <param name="filePath">Excel文件路径</param> public static DataTable ReadExcel(string filePath) { IWorkbook iwkX; using (FileStream fs = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { iwkX = WorkbookFactory.Create(fs); fs.Close(); } //sheet DataTable dt = new DataTable(); for (int h = 0; h < iwkX.NumberOfSheets; h++) { ISheet sheet = iwkX.GetSheetAt(h); var rows = sheet.GetRowEnumerator(); bool isMove = rows.MoveNext(); //循环sheet if (isMove) { var Cols = (IRow)rows.Current; dt.TableName = sheet.SheetName; for (int i = 0; i < Cols.LastCellNum; i++) { string str = Cols.GetCell(i).ToString(); dt.Columns.Add(Cols.GetCell(i).ToString()); } while (rows.MoveNext()) { var row = (IRow)rows.Current; var dr = dt.NewRow(); for (int i = 0; i < row.LastCellNum; i++) { var cell = row.GetCell(i); if (cell == null) { dr[i] = ""; } else { string strdr = cell.ToString(); dr[i] = cell.ToString(); } } dt.Rows.Add(dr); } } } return dt; } /// <summary> /// DataTable导出到Excel /// </summary> /// <param name="dt">DataTable</param> /// <param name="array">首行数组</param> /// <param name="fileFullName">文件名</param> public static void ExportToExcel(DataTable dt, string[] array, string fileFullName) { #region XSSFWorkbook workbook = new XSSFWorkbook(); FileStream fs = new FileStream(fileFullName, FileMode.OpenOrCreate, FileAccess.ReadWrite); ISheet sheet = workbook.CreateSheet("Sheet0"); IRow row; row = sheet.CreateRow(0); for (int i = 0; i < array.Length; i++) { row.CreateCell(i).SetCellValue(array[i]); } for (int i = 0; i < dt.Rows.Count; i++) { row = sheet.CreateRow(i + 1); for (int j = 0; j < dt.Columns.Count; j++) { row.CreateCell(j).SetCellValue(dt.Rows[i][j].ToString()); } } workbook.Write(fs); //写入到excel #endregion // MessageBox.Show("导出成功!"); } }
View Code
5数据库:数据库415281条数据,很全,在下载的Demo里 phone.db
6在下的文件中(有使用说明)点击Debug目录下的CellPhoneNumberAttribution.exe运行,注意电脑上要装.NET Framework 4.5