<control:BasePage x:Class="TrainDiagramSchedule.CreateTrainDiagramPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TrainDiagramSchedule"
xmlns:control="clr-namespace:CustomControls;assembly=CustomControls"
mc:Ignorable="d"
Title="CreateTrainDiagramPage"
Width="450" Height="675"
Loaded="Page_Loaded">
<Grid Background="{StaticResource PageMiddleZoneBackground}">
<Grid.RowDefinitions>
<!-- <RowDefinition Height="185"></RowDefinition> -->
<!-- <RowDefinition Height="350"></RowDefinition> -->
<!-- <RowDefinition Height="95"></RowDefinition> -->
<RowDefinition Height="200"></RowDefinition>
<RowDefinition Height="335"></RowDefinition>
<RowDefinition Height="95"></RowDefinition>
</Grid.RowDefinitions>
<GroupBox Header="基本信息" FontSize="14" FontWeight="Bold"
BorderBrush="{StaticResource BorderBrush}">
<Grid Margin="0,0,5,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90"></ColumnDefinition>
<ColumnDefinition Width="2*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="5"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock FontSize="14" Grid.Row="0" Grid.Column="0" Text="运行图名称:" FontWeight="Normal"
HorizontalAlignment="Right" Margin="2">
</TextBlock>
<TextBox x:Name="TbxDiagramName" FontSize="14" Grid.Row="0" Grid.Column="1" BorderThickness=".5"
BorderBrush="{StaticResource BorderBrush}" Margin="2"
HorizontalContentAlignment="Left" VerticalContentAlignment="Center" FontWeight="Normal">
</TextBox>
<TextBlock FontSize="14" Grid.Row="1" Grid.Column="0" Text="运行图类型:" HorizontalAlignment="Right"
Margin="2" FontWeight="Normal">
</TextBlock>
<ComboBox Name="CbxDiagramType" Foreground="Black" Grid.Row="1" Grid.Column="1" Margin="2,0,2,0"
VerticalAlignment="Center" FontSize="14" FontWeight="Normal"
SelectionChanged="CbxDiagramTypeSelectionChanged">
</ComboBox>
<TextBlock FontSize="14" Grid.Row="2" Grid.Column="0" Text="运行图描述:" HorizontalAlignment="Right"
Margin="2" FontWeight="Normal">
</TextBlock>
<TextBox x:Name="TbxDiagramDescribe" FontSize="14" Grid.Row="2" Grid.Column="1" Grid.RowSpan="2"
BorderThickness=".5" BorderBrush="{StaticResource BorderBrush}" Margin="2"
HorizontalContentAlignment="Left" VerticalContentAlignment="Top" TextWrapping="Wrap"
FontWeight="Normal">
</TextBox>
<TextBlock FontSize="14" Grid.Row="4" Grid.Column="0" Text="编制人员:" HorizontalAlignment="Right"
Margin="2" FontWeight="Normal">
</TextBlock>
<TextBox x:Name="TbxCreateUser" FontSize="14" Grid.Row="4" Grid.Column="1" BorderThickness=".5"
BorderBrush="{StaticResource BorderBrush}" Margin="2" IsReadOnly="True"
HorizontalContentAlignment="Left" VerticalContentAlignment="Center" FontWeight="Normal">
</TextBox>
<TextBlock FontSize="14" Grid.Row="5" Grid.Column="0" Text="编制时间:" HorizontalAlignment="Right"
Margin="2" FontWeight="Normal">
</TextBlock>
<TextBox x:Name="TbxCreateTime" FontSize="14" Grid.Row="5" Grid.Column="1" BorderThickness=".5"
BorderBrush="{StaticResource BorderBrush}" Margin="2" IsReadOnly="True"
HorizontalContentAlignment="Left" VerticalContentAlignment="Center" FontWeight="Normal">
</TextBox>
<TextBlock FontSize="14" Grid.Row="6" Grid.Column="0" Text="使用类型:" HorizontalAlignment="Right"
Margin="2" FontWeight="Normal">
</TextBlock>
<ComboBox Name="CbxOperationType" Foreground="Black" Grid.Row="6" Grid.Column="1" Margin="2,0,2,0"
VerticalAlignment="Center" FontSize="14" FontWeight="Normal"
SelectionChanged="CbxOperationTypeSelectionChanged">
</ComboBox>
</Grid>
</GroupBox>
<GroupBox Header="编制线路" Grid.Row="1" Margin="0,10,0,0" FontSize="14" FontWeight="Bold"
BorderBrush="{StaticResource BorderBrush}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="20"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Border Margin="15,0,15,5" BorderThickness=".5" BorderBrush="{StaticResource BorderBrush}"
CornerRadius="3">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="线路列表:" FontSize="12" Margin="5,2,2,2" FontWeight="Normal"></TextBlock>
<ListView x:Name="LvwLineName" Grid.Row="1" Margin="5,0,5,5"
SelectionChanged="LvwLineName_SelectionChanged">
<ListView.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="IsSelected"
Value="{Binding LineStatus.IsCreateTrainDiagram,Mode=OneWay,UpdateSourceTrigger=PropertyChanged}" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<CheckBox Name="CbxLineName" Margin="5,0,0,0" Content="{Binding LineName}"
FontSize="14" HorizontalAlignment="Left" VerticalAlignment="Center"
IsChecked="{Binding LineStatus.IsCreateTrainDiagram,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
FontWeight="Normal"
Checked="CbxLineName_Checked">
</CheckBox>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Border>
<Border Margin="15,0,15,5" BorderThickness=".5" BorderBrush="{StaticResource BorderBrush}"
CornerRadius="3" Grid.Column="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="生成线路:" FontSize="12" Margin="5,2,2,2" FontWeight="Normal"></TextBlock>
<ListBox Name="LbxSelectedLineName" Grid.Row="1" Margin="5,0,5,5"
ItemsSource="{Binding SelectedItems,ElementName=LvwLineName}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Margin="20,0,0,0" Text="{Binding LineName}" FontWeight="Normal"
FontSize="13" HorizontalAlignment="Center"
VerticalAlignment="Center">
</TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Border>
<TextBlock Text="》》" Grid.Column="0" Grid.ColumnSpan="3" Margin="10,0,0,0" FontSize="20"
HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Normal">
</TextBlock>
<StackPanel Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Center" VerticalAlignment="Bottom">
<Button Height="16" Width="45" Content="全选" FontSize="10" Margin="0,0,0,5"
Background="{StaticResource PageTopZoneBackground}" BorderThickness=".5"
Name="BtnSelectAllLine" FontWeight="Normal" Click="BtnSelectAllLine_Click">
</Button>
<Button Height="16" Width="45" Content="取消全选" FontSize="10" Margin="0,0,0,5"
Background="{StaticResource PageTopZoneBackground}" BorderThickness=".5"
Name="BtnCancelSelectAllLine" FontWeight="Normal" Click="BtnCancelSelectAllLine_Click">
</Button>
</StackPanel>
<CheckBox Grid.Row="1" Grid.Column="2" IsChecked="False" Content="需生成跨线运行图" HorizontalAlignment="Right"
Margin="15,0,15,5"
Name="CbxConnectTrainDiagram" Click="CbxConnectTrainDiagram_Click" FontWeight="Normal"
Visibility="Collapsed">
</CheckBox>
</Grid>
</GroupBox>
<GroupBox Header="新建模式" Grid.Row="2" Margin="0,10,0,0" FontSize="14" FontWeight="Bold"
BorderBrush="{StaticResource BorderBrush}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
</Grid.RowDefinitions>
<RadioButton Name="RbtnLoadOperatePlan" FontSize="14" Content="加载运输方案" Margin="15,2,0,2"
GroupName="是否加载方案" FontWeight="Normal" HorizontalAlignment="Left"
VerticalAlignment="Center" Checked="RbtnCreateType_Checked">
</RadioButton>
<RadioButton IsChecked="True" FontSize="14" Grid.Column="2" Content="不加载运输方案"
GroupName="是否加载方案" FontWeight="Normal" HorizontalAlignment="Center"
VerticalAlignment="Center" Checked="RbtnCreateType_Checked" Visibility="Visible"
Name="RbtnUnLoadOperatePlan">
</RadioButton>
<RadioButton FontSize="14" Grid.Column="2" Content="外部导入" Margin="10,2,15,2"
GroupName="是否加载方案" FontWeight="Normal" HorizontalAlignment="Right"
VerticalAlignment="Center" Checked="RbtnCreateType_Checked" Visibility="Visible"
Name="RbtnImportExternalFile">
</RadioButton>
<TextBlock FontSize="14" Grid.Row="1" Grid.Column="0" Text="选择方案:" HorizontalAlignment="Left"
Margin="15,5,2,2" VerticalAlignment="Center" FontWeight="Normal">
</TextBlock>
<ComboBox Name="CbxOperatePlan" IsEnabled="{Binding IsChecked,ElementName=RbtnLoadOperatePlan}"
FontSize="14" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="95,5,15,5"
HorizontalContentAlignment="Left" VerticalContentAlignment="Center" FontWeight="Normal"
SelectionChanged="CbxOperatePlan_SelectionChanged">
</ComboBox>
</Grid>
</GroupBox>
</Grid>
</control:BasePage>; using CustomControls;
using DataDefine;
using MathNet.Numerics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using TrainDiagramAlgorithm;
using TrainDiagramGenerate;
namespace TrainDiagramSchedule
{
/// <summary>
/// CreateTrainDiagramPage.xaml 的交互逻辑
/// </summary>
public partial class CreateTrainDiagramPage : BasePage
{
public bool IsCreateConnectTrainDiagram;
public bool IsLoadOperatePlan;
public bool IsLoadExternalFile;
public string CurrentOperatePlan;
TrafficNetwork? CurrentNetwork;
public TrainDiagramAlgorithm.TrainDiagramGenerate? DiagramGenerate = null;
public int AlgorithmType = 1;//0-dqh算法,1-lc算法
public CreateTrainDiagramPage(CustomFunctionWindow window, TrafficNetwork? network)
{
CurrentWindow = window;
CurrentNetwork = network;
CurrentOperatePlan = string.Empty;
InitializeComponent();
window.Closing += Window_Closing;
}
private void Window_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
{
if (CurrentNetwork == null) return;
if (CurrentWindow?.DialogResult == true)
{
bool isClose = false;
for (int i = 0; i < CurrentNetwork.LineList.Count; i++)
{
TrafficLine line = CurrentNetwork.LineList[i];
if (line.LineStatus.IsCreateTrainDiagram)
{
isClose = true;
}
}
if (!isClose)
{
new CustomMessageWindow("请选择线路", 0, 1).Show();
e.Cancel = true;
}
}
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
if (CurrentNetwork == null) return;
if (CurrentNetwork.CityName == "重庆" || CurrentNetwork.CityName == "南宁" || CurrentNetwork.CityName == "深圳")
{
RbtnUnLoadOperatePlan.SetValue(Grid.ColumnProperty, 1);
RbtnImportExternalFile.Visibility = Visibility.Visible;
}
LvwLineName.ItemsSource = null;
LvwLineName.ItemsSource = CurrentNetwork.LineList;
TbxDiagramName.Text = "线网图" + DateTime.Now.ToString("yyyyMMddHHmmss");
TbxCreateUser.Text = "测试用户";
TbxCreateTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Type enumType = typeof(DiagramPeriodTypeEnum);
Array periodTypeList = Enum.GetValues(enumType);
CbxDiagramType.ItemsSource = periodTypeList;
CbxDiagramType.SelectedIndex = 0;
//使用类型
CbxOperationType.ItemsSource = Enum.GetValues(typeof(OperationTypeEnum2));
CbxOperationType.SelectedIndex = 0;
if (CurrentNetwork.LineList.Count == 1)
{
CurrentNetwork.LineList[0].LineStatus.IsCreateTrainDiagram = true;
}
else
{
//清除之前的选中状态
List<TrafficLine> trafficLines =
CurrentNetwork.LineList.Where(x => x.LineStatus.IsCreateTrainDiagram).ToList();
if (trafficLines.Count > 0)
{
foreach (TrafficLine item in trafficLines)
{
item.LineStatus.IsCreateTrainDiagram = false;
}
}
}
}
private void BtnSelectAllLine_Click(object sender, RoutedEventArgs e)
{
if (CurrentNetwork == null) return;
for (int i = 0; i < CurrentNetwork.LineList.Count; i++)
{
TrafficLine line = CurrentNetwork.LineList[i];
line.LineStatus.IsCreateTrainDiagram = true;
}
LvwLineName.Items.Refresh();
}
private void BtnCancelSelectAllLine_Click(object sender, RoutedEventArgs e)
{
if (CurrentNetwork == null) return;
for (int i = 0; i < CurrentNetwork.LineList.Count; i++)
{
TrafficLine line = CurrentNetwork.LineList[i];
line.LineStatus.IsCreateTrainDiagram = false;
}
LvwLineName.SelectedItems.Clear();
LvwLineName.Items.Refresh();
}
private void LvwLineName_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
TrafficLine line = (TrafficLine)LvwLineName.SelectedItem;
if (line == null) return;
if (!line.LineStatus.IsCreateTrainDiagram)
{
LvwLineName.SelectedIndex = -1;
}
LvwLineName.Items.Refresh();
}
private void CbxConnectTrainDiagram_Click(object sender, RoutedEventArgs e)
{
CheckBox checkBox = (CheckBox)sender;
if (checkBox.IsChecked == true)
{
IsCreateConnectTrainDiagram = true;
}
else
{
IsCreateConnectTrainDiagram = false;
}
}
private void CbxLineName_Checked(object sender, RoutedEventArgs e)
{
LoadOperatePlan();
}
private void CbxOperatePlan_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (CbxOperatePlan.SelectedItem != null)
{
CurrentOperatePlan = CbxOperatePlan.SelectedItem.ToString() ?? string.Empty;
}
}
private void CbxDiagramTypeSelectionChanged(object sender, SelectionChangedEventArgs e)
{
LoadOperatePlan();
}
private void CbxOperationTypeSelectionChanged(object sender, SelectionChangedEventArgs e)
{
int CbxOperationTypeSelectedIndex = CbxOperationType.SelectedIndex;
if (CbxOperationTypeSelectedIndex < 0) return;
}
private void RbtnCreateType_Checked(object sender, RoutedEventArgs e)
{
RadioButton radioButton = (RadioButton)sender;
string buttonName = radioButton.Name;
if (radioButton.Content?.ToString() == "加载运输方案")
{
IsLoadOperatePlan = true;
IsLoadExternalFile = false;
if (AlgorithmType == 0)
{
if (DiagramGenerate == null)
{
DiagramGenerate = new TrainDiagramAlgorithm.TrainDiagramGenerate();
DiagramGenerate.LoadNetworkDataFromPgsql();
DiagramGenerate.LoadAbleNetSchemeNameFromPgsql();
}
}
LoadOperatePlan();
}
else if (radioButton.Content?.ToString() == "不加载运输方案")
{
IsLoadOperatePlan = false;
IsLoadExternalFile = false;
CbxOperatePlan.ItemsSource = null;
}
else if (radioButton.Content?.ToString() == "外部导入")
{
IsLoadOperatePlan = false;
IsLoadExternalFile = true;
CbxOperatePlan.ItemsSource = null;
}
}
private void LoadOperatePlan()
{
if (AlgorithmType == 0)
{
LoadOperatePlan1();
}
else if (AlgorithmType == 1)
{
LoadOperatePlan2();
}
}
private void LoadOperatePlan1()
{
if (CurrentNetwork == null) return;
int CbxDiagramTypeSelectedIndex = CbxDiagramType.SelectedIndex;
if (CbxDiagramTypeSelectedIndex < 0)
{
MessageShowWindowHelper.ShowCustomMessageBox("请选择运行图类型!", 0);
return;
}
//Step01:先确定生成线路的显示内容
if (DiagramGenerate != null)
{
DiagramGenerate.TrainDiagram.GenerateLineList.Clear();
}
string GenerateLineName = string.Empty;
for (int i = 0; i < CurrentNetwork.LineList.Count; i++)
{
TrafficLine line = CurrentNetwork.LineList[i];
if (!line.LineStatus.IsCreateTrainDiagram) continue;
if (!string.IsNullOrEmpty(GenerateLineName))
{
GenerateLineName += "、";
}
GenerateLineName += line.LineName;
if (DiagramGenerate != null)
{
DiagramGenerate.TrainDiagram.GenerateLineList.Add(DiagramGenerate.GetLineByName(line.LineName));
}
}
int? count = DiagramGenerate?.AbleSchemeList.Count;
//清空下拉框
CbxOperatePlan.Items.Clear();
for (int i = 0; i < count; i++)
{
NetScheme ThisNetScheme = DiagramGenerate.AbleSchemeList[i];
bool IsNetSchemeSatisfy = true;
//s.t.01:总数量对应
if (DiagramGenerate.TrainDiagram.GenerateLineList.Count != ThisNetScheme.GenerateLineList.Count)
{
IsNetSchemeSatisfy = false;
}
//s.t.02:运行图生成线路每一条都需要被包含在方案生成线路内
for (int j = 0; j < DiagramGenerate.TrainDiagram.GenerateLineList.Count; j++)
{
BasicLine ThisGenerateLine = DiagramGenerate.TrainDiagram.GenerateLineList[j];
if (!ThisNetScheme.GenerateLineList.Contains(ThisGenerateLine))
{
IsNetSchemeSatisfy = false;
break;
}
}
if (IsNetSchemeSatisfy)
{
//Add
CbxOperatePlan.Items.Add(DiagramGenerate.AbleSchemeList[i].SchemeName);
}
//Show
if (DiagramGenerate.NetScheme != null && DiagramGenerate.NetScheme.SchemeName ==
DiagramGenerate.AbleSchemeList[i].SchemeName)
{
CbxOperatePlan.SelectedIndex = CbxOperatePlan.Items.Count - 1;
}
}
}
private void LoadOperatePlan2()
{
TrainDiagramGenerate.Generate.InitNetwork();
List<string> lineNameList = new List<string>();
for (int i = 0; i < CurrentNetwork.LineList.Count; i++)
{
if (CurrentNetwork.LineList[i].LineStatus.IsCreateTrainDiagram)
{
lineNameList.Add(CurrentNetwork.LineList[i].LineName);
}
}
//清空下拉框
List<string> CapRsceAllocProList = DataHandler.GetNetworkCapRsceAllocProList(lineNameList);
CbxOperatePlan.ItemsSource = null;
CbxOperatePlan.ItemsSource = CapRsceAllocProList;
}
}
}; 如果 线路列表 被选择了多个(大于1), 则 <RadioButton FontSize="14" Grid.Column="2" Content="外部导入" Margin="10,2,15,2"
GroupName="是否加载方案" FontWeight="Normal" HorizontalAlignment="Right"
VerticalAlignment="Center" Checked="RbtnCreateType_Checked" Visibility="Visible"
Name="RbtnImportExternalFile">
</RadioButton>; 外部导入 按钮被置灰,无法选择, 当 线路列表 只选择了一个 , 外部导入 按钮 可以被选择