11.一覧表画面
DataGridと一覧表画面
データベースのデータは、一般的には、抽出条件をComboBoxで指定してDataGrid、又はDataGridView(一覧表)に表示します。このComboBoxのデータもデータベースを使用できます。又、抽出条件の指定は、RadioButtonやCheckBoxもよく使われます。
このサンプルでは、
①ComboBox②RadioButton
③DataGrid
④TextBox
を使用します。
画像の一番下の行はTextBox(txtMessage)で、開発段階では、データベースを操作する言語であるSQl 文を表示しています。このSQL文をコピーして、SQL実行ツールで抽出データの確認をするのに便利です。
View(画像をクリックすると拡大)
ComboBox・RadioButton・Button

抽出条件と表示
この画面は、プロジェクトという単位で販売を管理している会社の販売実績の照会画面です。この画面に表示するプロジェクトは、ComboBoxで作成者を指定(抽出条件)します。進行状況はRadioButtonで選択します。DataGridへの表示は「表示」ボタンのクリックで行います。
View(DataGrid行)
表示されたDataGridの行をクリックしますと行の内容が下のTextBoxに表示されます。行の先頭の「選択」ボタンをクリックしますと別の画面が開いて詳細が表示されます。
View(TextBox)
View(画像をクリックすると拡大)
一覧表画面のZAMLは下記です。
ComboBoxは、75~86行(反転)、RadioButton(状況)は、88~110行(反転)、DataGridは、117~226行(反転)で記述されています。
View
<Window x:Class="LivetWPFApplication100.Views.Window64"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:l="http://schemas.livet-mvvm.net/2011/wpf"
xmlns:local="clr-namespace:LivetWPFApplication100"
xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"
xmlns:v="clr-namespace:LivetWPFApplication100.Views"
xmlns:vm="clr-namespace:LivetWPFApplication100.ViewModels"
xmlns:my="http://www.codeplex.com/prism"
xmlns:clr="clr-namespace:LivetWPFApplication100"
WindowStartupLocation="CenterScreen"
Title="Window64" Height="714" Width="1035" >
<Window.DataContext>
<vm:ViewModel64 />
</Window.DataContext>
<Window.Resources>
<ResourceDictionary>
<vm:XComboBoxEmptyItemConverter x:Key="XComboBoxEmptyItemConverter"/>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources/Styles.xaml"/>
<ResourceDictionary Source="/Resources/Styles2.xaml"/>
<ResourceDictionary Source="/Resources/StylesBG.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<i:Interaction.Triggers>
<!--WindowのContentRenderedイベントのタイミングでViewModelのInitialize
メソッドが呼ばれます-->
<i:EventTrigger EventName="ContentRendered">
<l:LivetCallMethodAction MethodTarget="{Binding}"
MethodName="Initialize"/>
</i:EventTrigger>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding Path=Loaded}"
CommandParameter="{Binding Mode=OneTime,RelativeSource=
{RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}"/>
</i:EventTrigger>
<i:EventTrigger EventName="Closing">
<i:InvokeCommandAction Command="{Binding Path=Closing}"
CommandParameter="{Binding Mode=OneTime,RelativeSource=
{RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}}}"/>
</i:EventTrigger>
<l:InteractionMessageTrigger MessageKey="Close"
Messenger="{Binding Messenger}">
<l:WindowInteractionMessageAction/>
</l:InteractionMessageTrigger>
<l:InteractionMessageTrigger
MessageKey="MessageKey74" Messenger="{Binding Messenger}">
<l:TransitionInteractionMessageAction
WindowType="{x:Type v:Window74}" Mode="Modal"/>
</l:InteractionMessageTrigger>
</i:Interaction.Triggers>
<Grid Background="#FFE6E6FA" >
<Grid.RowDefinitions>
<RowDefinition Height="679*" />
<RowDefinition Height="9*" />
</Grid.RowDefinitions>
<Label Content="作成者"
Height="25" HorizontalAlignment="Left"
Margin="17,12,0,0" Name="label1" VerticalAlignment="Top"
Width="60" />
<ComboBox Text="{Binding cmbDada作成者}"
ItemsSource="{Binding Persons,
Converter={StaticResource XComboBoxEmptyItemConverter}}"
DisplayMemberPath="作成者"
SelectedValuePath="作成者"
SelectedValue="{Binding SelectedValueChanged, Mode=TwoWay}"
Height="25"
Margin="74,12,0,0"
Name="cmbDada作成者"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Width="112" SelectedIndex="-1" />
<GroupBox Header="検索(状況)" Height="45" HorizontalAlignment="Left"
Margin="212,6,0,0" Name="groupBox1"
VerticalAlignment="Top" Width="260">
<Grid Width="220">
<Grid.RowDefinitions>
<RowDefinition Height="22*" />
<RowDefinition Height="9*" />
</Grid.RowDefinitions>
<RadioButton Content="{Binding 準備・遅延中}" Height="18"
HorizontalAlignment="Left"
Margin="6,7,0,0"
Name="rbtn準備" VerticalAlignment="Top" Width="91"
Grid.RowSpan="2"
IsChecked="{Binding Click1, Mode=TwoWay}" />
<RadioButton Content="{Binding 完了・保管・中止}" Height="18"
HorizontalAlignment="Left"
Margin="114,7,0,0"
Name="rbtn保管" VerticalAlignment="Top" Width="115"
Grid.RowSpan="2"
IsChecked="{Binding Click2, Mode=TwoWay}" />
</Grid>
</GroupBox>
<Button Background="{Binding Path=ColorName}"
Command="{Binding GetDataCommand2}"
Content="表示" HorizontalAlignment="Left" Margin="499,11,0,621"
Name="button18" Width="88" />
<DataGrid x:Name="プロジェクト"
AutoGenerateColumns="False"
AlternatingRowBackground="#E6FCFCB8"
ItemsSource="{Binding Estimates}"
SelectionMode="Single"
SelectedItem="{Binding SelectedEstimate, Mode=TwoWay}"
SelectionUnit="FullRow"
CanUserAddRows="false" Margin="12,58,18,0" Height="480"
VerticalAlignment="Top" >
<DataGrid.Columns>
<!-- 追加 Start -->
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Button Content="選択" Margin="3"
Command=
"{Binding Path=DataContext.DisplayWindowCommand,
RelativeSource={RelativeSource AncestorType=
{x:Type DataGrid}}}"
CommandParameter="555" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<!-- 追加 End -->
<!-- **************************** -->
<DataGridTextColumn Header="状況" Width="70"
Binding="{Binding 状況}" >
<DataGridColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Background" Value="Blue"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>
</DataGridColumn.HeaderStyle>
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="Blue"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<!-- **************************** -->
<DataGridTextColumn Header="区分" Width="60" Binding=
"{Binding 台帳区分}" FontSize="12"/>
<DataGridTextColumn Header="コード" Width="60" Binding=
"{Binding 年度プロジェクトコード}"/>
<DataGridTextColumn Header="プロジェクト名" Width="175" Binding=
"{Binding プロジェクト名}" >
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
<Setter Property="TextBlock.TextAlignment" Value="Left"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<!-- **************************** -->
<DataGridTextColumn Header="販売金額" Width="80" Binding=
"{Binding 販売金額, StringFormat=#\,0千円}" >
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<!-- **************************** -->
<DataGridTextColumn Header="販売先名" Width="124" Binding=
"{Binding 販売先名}">
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
<Setter Property="TextBlock.TextAlignment" Value="Left"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="検収" Width="70" Binding=
"{Binding 検収}"/>
<!-- **************************** -->
<DataGridTextColumn Header="仕入金額" Width="80" Binding=
"{Binding 仕入金額, StringFormat=#\,0千円}" >
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<!-- **************************** -->
<DataGridTextColumn Header="作成日" Width="70" Binding=
"{Binding 作成日}"/>
<DataGridTextColumn Header="部名" Width="105" Binding=
"{Binding 部名}">
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
<Setter Property="TextBlock.TextAlignment" Value="Left"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="作成者" Width="52" Binding=
"{Binding 作成者}"/>
</DataGrid.Columns>
</DataGrid>
<TextBox Text="{Binding Path=SelectedEstimate.年度プロジェクトコード,
Mode=TwoWay}" Height="26" HorizontalAlignment="Left"
Margin="16,546,0,0"
Name="textBox1" VerticalAlignment="Top" Width="69" />
<TextBox Text="{Binding Path=SelectedEstimate.プロジェクト名}" Height="26"
HorizontalAlignment="Left" Margin="91,546,0,0"
Name="textBox2" VerticalAlignment="Top" Width="334" />
<TextBox Text="{Binding Path=SelectedEstimate.作成日}" Height="26"
HorizontalAlignment="Left" Margin="431,546,0,0"
Name="textBox5" VerticalAlignment="Top" Width="84" />
<TextBox Text="{Binding Path=SelectedEstimate.部名}" Height="26"
HorizontalAlignment="Left" Margin="521,546,0,0"
Name="textBox4" VerticalAlignment="Top" Width="218" />
<TextBox Text="{Binding Path=SelectedEstimate.作成者}" Height="26"
HorizontalAlignment="Right" Margin="0,546,179,0"
Name="textBox3" VerticalAlignment="Top" Width="89" />
<v:UserControlFooterN2 HorizontalAlignment="Left" VerticalAlignment=
"Bottom" Grid.RowSpan="2" />
</Grid>
</Window>
22行目の「XComboBoxEmptyItemConverter」と77行目の「Converter={StaticResource XComboBoxEmptyItemConverter} 」はComboBoxの最初のItemとして空行を追加するためのクラスで、ViewModelsフォルダに作成しています。
XComboBoxEmptyItemConverter
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//IValueConverter
using System.Globalization;
using System.Windows.Data;
//DynamicObject
using System.ComponentModel;
using System.Dynamic;
//IEnumerable
using System.Collections;
namespace LivetWPFApplication100.ViewModels
{
public class XComboBoxEmptyItemConverter : IValueConverter
{
private class EmptyItem : DynamicObject
{
public override bool TryGetMember(GetMemberBinder binder,
out object result)
{
result = null;
return true;
}
}
public object Convert(object value, Type targetType, object parameter,
CultureInfo culture)
{
IEnumerable container = value as IEnumerable;
if (container != null)
{
IEnumerable<object> genericContainer = container.OfType<object>();
IEnumerable<object> emptyItem = new object[] { new EmptyItem() };
return emptyItem.Concat(genericContainer);
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
ViewModelは下記の通りです。
ViewModel
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Livet;
using Livet.Commands;
using Livet.Messaging;
using Livet.Messaging.IO;
using Livet.EventListeners;
using Livet.Messaging.Windows;
using System.Data.OracleClient;
using System.Windows;
//参照設定が必要
using System.Configuration;
using System.Data;
//CollectionViewSource
using System.Windows.Data;
//ICommand
using System.Windows.Input;
using Common;
using System.Windows.Interactivity;
using LivetWPFApplication100.Models;
using LivetWPFApplication100.Views;
using LivetWPFApplication100.ViewModels;
using System.Threading;
using System.Globalization;
namespace LivetWPFApplication100.ViewModels
{
class ViewModel64 : ViewModel
{
#region txtMessage・txt本日変更通知プロパティ
//-----------------------------------------------
public string txtMessage { get; set; }
public string txt本日 { get; set; }
//-----------------------------------------------
#endregion
Window win = null;
public ViewModel64()
{
txt本日 = DB.str本日;
Loaded = new Livet.Commands.ListenerCommand<Window>((w) =>
{
if (NeedHideOwner && w.Owner != null && w.Owner.Visibility ==
Visibility.Visible)
{
win = w;
//w.Owner.Hide();
}
});
Closing = new Livet.Commands.ListenerCommand<Window>((w) =>
{
if (NeedHideOwner && w.Owner != null)
{
w.Owner.Show();
}
});
}
public bool NeedHideOwner { get; set; }
public ICommand Loaded { get; private set; }
public ICommand Closing { get; private set; }
public void Initialize()
{
if (win != null) win.Owner.Hide();
Thread.CurrentThread.CurrentCulture = new CultureInfo("ja-JP");
XCloseButtonManager.Disable();
Click1 = true;
//【Combo】
//★★★---------------------------------------------------------
//クラスの実体化、Collectionの実体化
Person = new Person();
Persons = new ObservableCollection<Person>();
//Collectionのイベントの登録
Persons.CollectionChanged += new System.Collections.Specialized.
NotifyCollectionChangedEventHandler
(Persons_CollectionChanged);
GetPersonData();
//★★★---------------------------------------------------------
//【Grid】
//★★★---------------------------------------------------------
//クラスの実体化、Collectionの実体化
Estimate = new Estimate();
Estimates = new ObservableCollection<Estimate>();
//Collectionのイベントの登録
Estimates.CollectionChanged += new System.Collections.Specialized.
NotifyCollectionChangedEventHandler(Estimates_CollectionChanged);
//★★★---------------------------------------------------------
//【74向け】
//★★★---------------------------------------------------------
//クラスの実体化、Collectionの実体化
Project = new Project();
Projects = new ObservableCollection<Project>();
//Collectionのイベントの登録
Projects.CollectionChanged += new System.Collections.Specialized.
NotifyCollectionChangedEventHandler
(Projects_CollectionChanged);
//★★★---------------------------------------------------------
}
#region CloseCommand
private ViewModelCommand _CloseCommand;
public ViewModelCommand CloseCommand
{
get
{
if (_CloseCommand == null)
{
_CloseCommand = new ViewModelCommand(Close);
}
return _CloseCommand;
}
}
public void Close()
{
//Messenger.Raise(new WindowActionMessage("Close", WindowAction.Close));
var window = Application.Current.Windows.OfType<Window>().
SingleOrDefault((w) => w.IsActive);
window.Close();
}
#endregion
#region Persons変更通知プロパティ
//★★★ ItemsSource -----------------------------------------------
//①クラスのプロパティの設定
private Person _Person;
public Person Person
{
get
{
return _Person;
}
set
{
if (_Person == value)
return;
_Person = value;
RaisePropertyChanged("Person");
}
}
//②ObservableCollectionへの設定
private ObservableCollection<Person> _Persons;
public ObservableCollection<Person> Persons
{
get
{
return _Persons;
}
set
{
_Persons = value;
RaisePropertyChanged("Persons");
}
}
//Whenever new item is added to the collection, am explicitly calling
notify property changed
//新しいアイテムが収集に加えられる場合は、常に変更されたプロパティに明示的に
通知する。
//③ObservableCollectionの変更の通知
void Persons_CollectionChanged(object sender, System.Collections.
Specialized.NotifyCollectionChangedEventArgs e)
{
RaisePropertyChanged("Persons");
}
//クラスのプロパティの設定
//★★★ SelectedItem ------------------------------------------
//クラスのプロパティの設定
private Person _selectedPerson;
public Person SelectedPerson
{
get
{
return _selectedPerson;
}
set
{
_selectedPerson = value;
RaisePropertyChanged("SelectedPerson");
}
}
#endregion
#region GetDataCommandコマンド
private ViewModelCommand _getDataCommand;
public ViewModelCommand GetDataCommand
{
get
{
if (_getDataCommand == null)
{
_getDataCommand = new ViewModelCommand(GetPersonData);
}
return _getDataCommand;
}
}
public void GetPersonData()
{
string CmdString = string.Empty;
string strWhere = " WHERE 区分 = 'プロジェクト' ";
string strState = "";
using (OracleConnection con = new OracleConnection())
{
con.ConnectionString = "User Id=beluran; Password=beluran;
Data Source=beluran;Pooling=false;";
con.Open();
//
if (Click1)
{
strState = " AND (SUBSTR(状況,1,1) = '1' OR SUBSTR(状況,1,1) =
'2' OR SUBSTR(状況,1,1) = '3' OR SUBSTR(状況,1,1) =
'4' OR SUBSTR(状況,1,1) = '5' OR SUBSTR(状況,1,1) = '6' ) ";
}
//else if (state == "9")
else if (Click2)
{
strState = " AND (SUBSTR(状況,1,1) = '7' OR SUBSTR(状況,1,1) =
'8' OR SUBSTR(状況,1,1) = '0') ";
}
CmdString = "SELECT 作成者 FROM プロジェクトヘッダ " +
strWhere +
strState +
" GROUP BY 作成者 ORDER BY 作成者";
OracleCommand oracmd = new OracleCommand(CmdString, con);
OracleDataReader reader = oracmd.ExecuteReader();
//*** Tran ***
//tx.Commit();
int i = 0;
Persons.Clear();
while (reader.Read() == true)
{
Persons.Add(new Person()
{
作成者 = reader["作成者"].ToString()
});
i++;
}
}
}
#endregion
#region SelectedValueChanged
private string _SelectedValue;
public string SelectedValue
{
get
{
return _SelectedValue;
}
set
{
if (value == _SelectedValue)
return;
_SelectedValue = value;
RaisePropertyChanged("SelectedValue");
EstimateGetData();
}
}
#endregion
#region Click1,2
private string _準備・遅延中 = "準備~遅延中";
public string 準備・遅延中
{
get { return this._準備・遅延中; }
set
{
this._準備・遅延中 = value;
RaisePropertyChanged("準備・遅延中");
}
}
private string _完了・保管・中止 = "完了・保管・中止";
public string 完了・保管・中止
{
get { return this._完了・保管・中止; }
set
{
this._完了・保管・中止 = value;
RaisePropertyChanged("完了・保管・中止");
}
}
private bool _Click1;
int iGClick = 0;
public bool Click1
{
get { return this._Click1; }
set
{
if (this.Click1 == value)
return;
this._Click1 = value;
RaisePropertyChanged("Click1");
//
if (iGClick > 0)
{
EstimateGetData();
}
iGClick++;
}
}
//----------------
private bool _Click2;
public bool Click2
{
get { return this._Click2; }
set
{
if (this.Click2 == value)
return;
this._Click2 = value;
RaisePropertyChanged("Click2");
//
if (iGClick > 0)
{
EstimateGetData();
}
iGClick++;
}
}
#endregion
//------------------------------------------
public void ClickGetData()
{
if (Click1)
{
State = "1";
}
else if (Click2)
{
State = "9";
}
}
//------------------------------------------
#region 変更通知プロパティ
//---------------------------------------------------------------------
public string Copy { get; set; }
public string Paste { get; set; }
public string cmbCategory { get; set; }
public string State { get; set; }
public string txtSQL { get; set; }
public string txtPosition { get; set; }
public string textBox1 { get; set; }
//---------------------------------------------------------------------
#endregion
//【Grid】
#region ObservableCollectionへの設定
//★★★ ItemsSource -----------------------------------------------
//①クラスのプロパティの設定
private Estimate _estimate;
public Estimate Estimate
{
get
{
return _estimate;
}
set
{
_estimate = value;
RaisePropertyChanged("Estimate");
}
}
//②ObservableCollectionへの設定
private ObservableCollection<Estimate> _estimates;
public ObservableCollection<Estimate> Estimates
{
get
{
return _estimates;
}
set
{
_estimates = value;
RaisePropertyChanged("Estimates");
}
}
//Whenever new item is added to the collection, am explicitly
calling notify property changed
//新しいアイテムが収集に加えられる場合は、常に変更されたプロパティに明示的に
通知する。
//③ObservableCollectionの変更の通知
void Estimates_CollectionChanged(object sender, System.Collections.
Specialized.
NotifyCollectionChangedEventArgs e)
{
RaisePropertyChanged("Estimates");
}
#endregion
#region クラスのプロパティの設定
//★★★ SelectedItem ------------------------------------------
//クラスのプロパティの設定
private Estimate _selectedEstimate;
public Estimate SelectedEstimate
{
get
{
return _selectedEstimate;
}
set
{
_selectedEstimate = value;
RaisePropertyChanged("SelectedEstimate");
}
}
//★★★---------------------------------------------------------
#endregion
//【74】
#region ObservableCollectionへの設定
//★★★ ItemsSource -----------------------------------------------
//①クラスのプロパティの設定
private Project _project;
public Project Project
{
get
{
return _project;
}
set
{
_project = value;
RaisePropertyChanged("Project");
}
}
//②ObservableCollectionへの設定
private ObservableCollection<Project> _projects;
public ObservableCollection<Project> Projects
{
get
{
return _projects;
}
set
{
_projects = value;
RaisePropertyChanged("Projects");
}
}
//Whenever new item is added to the collection, am explicitly calling
notify property changed
//新しいアイテムが収集に加えられる場合は、常に変更されたプロパティに明示的に
通知する。
//③ObservableCollectionの変更の通知
void Projects_CollectionChanged(object sender, System.Collections.
Specialized.NotifyCollectionChangedEventArgs e)
{
RaisePropertyChanged("Projects");
}
#endregion
#region クラスのプロパティの設定
//★★★ SelectedItem ------------------------------------------
//クラスのプロパティの設定
private Project _selectedProject;
public Project SelectedProject
{
get
{
return _selectedProject;
}
set
{
_selectedProject = value;
RaisePropertyChanged("SelectedProject");
}
}
//★★★---------------------------------------------------------
#endregion
#region FileData
private DataTable _fileData;
public DataTable FileData
{
get
{
return _fileData;
}
set
{
_fileData = value;
RaisePropertyChanged("FileData");
}
}
#endregion
//--------------------------------------------------
public void EstimateGetData()
{
string[] array = new string[2];
array = GetEstimateData(SelectedValue, State);
txtSQL = array[0];
txtPosition = array[1];
}
#region GetEstimateData
public string[] GetEstimateData(string name, string state)
{
string CmdString = string.Empty;
string strWhere = " WHERE 区分 = 'プロジェクト' ";
string strState = "";
if (Click1)
{
strState = " AND (SUBSTR(状況,1,1) = '1' OR SUBSTR(状況,1,1) = '2'
OR SUBSTR(状況,1,1) = '3' OR SUBSTR(状況,1,1) = '4'
OR SUBSTR(状況,1,1) = '5' OR SUBSTR(状況,1,1) = '6' ) ";
}
//else if (state == "9")
else if (Click2)
{
strState = " AND (SUBSTR(状況,1,1) = '7' OR SUBSTR(状況,1,1) = '8'
OR SUBSTR(状況,1,1) = '0') ";
}
string strOrderBy = " ORDER BY SUBSTR(状況,1,1),年度プロジェクトコード
DESC ";
if (name != null)
{
strWhere = strWhere + " AND 作成者 = '" + name + "' ";
}
using (OracleConnection con = new OracleConnection())
{
con.ConnectionString = "User Id=beluran; Password=beluran;
Data Source=beluran;Pooling=false;";
con.Open();
//
CmdString = "SELECT 状況,区分, 年度プロジェクトコード, プロジェクト名,
作成日, 作成者, 部名, 販売金額, 販売先名, 検収, 仕入金額" +
" FROM プロジェクトヘッダ" +
strWhere +
strState +
strOrderBy;
OracleCommand oracmd = new OracleCommand(CmdString, con);
OracleDataReader reader = oracmd.ExecuteReader();
//*** Tran ***
//tx.Commit();
int i = 0;
Estimates.Clear();
while (reader.Read() == true)
{
Estimates.Add(new Estimate()
{
状況 = reader["状況"].ToString(),
区分 = reader["区分"].ToString(),
年度プロジェクトコード = reader["年度プロジェクトコード"].
ToString(),
プロジェクト名 = reader["プロジェクト名"].ToString(),
作成日 = reader["作成日"].ToString(),
作成者 = reader["作成者"].ToString(),
部名 = reader["部名"].ToString(),
販売金額 = Convert.ToInt32(reader["販売金額"].ToString()),
販売先名 = reader["販売先名"].ToString(),
検収 = reader["検収"].ToString(),
仕入金額 = Convert.ToInt32(reader["仕入金額"].ToString())
});
i++;
}
string[] array = new string[2];
array[0] = CmdString;
//レコード件数
array[1] = i.ToString();
return array;
}
}
#endregion
#region DisplayWindowCommand
// Copy処理のコマンドを定義します。
private ViewModelCommand _displayWindowCommand;
public ViewModelCommand DisplayWindowCommand
{
get
{
if (this._displayWindowCommand == null)
{
this._displayWindowCommand = new ViewModelCommand(
DisplayWindowExecute, CanDisplayWindowExecute);
}
return this._displayWindowCommand;
}
}
// Copy処理のコマンドの実行を行います。
private void DisplayWindowExecute()
{
CopyExecute();
//どちらも可
//①
Messenger.Raise(new TransitionMessage(new ViewModel74(this.Project) {
NeedHideOwner = true }, "MessageKey74"));
//②
//using (var vm = new ViewModel74(this.Project))
//{
// NeedHideOwner = true;
// Messenger.Raise(new TransitionMessage(vm, "MessageKey74"));
//}
}
// Copy処理が実行可能かどうかの判定を行います。
private bool CanDisplayWindowExecute()
{
return true;
}
#endregion
#region CopyCommand
private ViewModelCommand _copyCommand;
public ViewModelCommand CopyCommand
{
get
{
if (this._copyCommand == null)
{
this._copyCommand = new ViewModelCommand(CopyExecute,
CanCopyExecute);
}
return this._copyCommand;
}
}
private void CopyExecute()
{
Paste = SelectedEstimate.年度プロジェクトコード;
DB.str年度プロジェクトコード = SelectedEstimate.年度プロジェクトコード;
DB.str状況 = SelectedEstimate.状況;
DB.str区分 = SelectedEstimate.区分;
DB.strプロジェクト名 = SelectedEstimate.プロジェクト名;
DB.str作成日 = SelectedEstimate.作成日;
DB.str作成者 = SelectedEstimate.作成者;
DB.str部名 = SelectedEstimate.部名;
DB.lng販売金額 = SelectedEstimate.販売金額;
DB.str販売先名 = SelectedEstimate.販売先名;
DB.str検収 = SelectedEstimate.検収;
DB.lng仕入金額 = SelectedEstimate.仕入金額;
Project.年度プロジェクトコード = SelectedEstimate.年度プロジェクトコード;
Project.状況 = SelectedEstimate.状況;
Project.区分 = SelectedEstimate.区分;
Project.プロジェクト名 = SelectedEstimate.プロジェクト名;
Project.作成日 = SelectedEstimate.作成日;
Project.作成者 = SelectedEstimate.作成者;
Project.部名 = SelectedEstimate.部名;
DB.lng販売金額 = SelectedEstimate.販売金額;
Project.販売金額 = SelectedEstimate.販売金額;
Project.販売先名 = SelectedEstimate.販売先名;
Project.検収 = SelectedEstimate.検収;
Project.仕入金額 = SelectedEstimate.仕入金額;
}
// Copy処理が実行可能かどうかの判定を行います。
private bool CanCopyExecute()
{
return true;
}
#endregion
#region ColorName
//-------------------------------------------------------------------
public static string _ColorName = "Red";
public string ColorName
{
get
{
_ColorName = "LightGreen";
return _ColorName;
}
}
//-------------------------------------------------------------------
#endregion
}
}
ここで使われているデータベースは下記の通りです。
プロジェクトヘッダCONNECT beluran/beluran@beluran;
DROP TABLE プロジェクトヘッダ CASCADE CONSTRAINTS;
CREATE TABLE プロジェクトヘッダ
(
区分 NVARCHAR2(10),
作成日 NVARCHAR2(20),
作成者 NVARCHAR2(10),
年度プロジェクトコード VARCHAR2(10),
プロジェクト名 NVARCHAR2(100),
部署コード VARCHAR2(10),
部名 VARCHAR2(50),
販売金額 NUMBER(9,0) DEFAULT 0,
販売先名 NVARCHAR2(50),
検収 VARCHAR2(100),
仕入金額 NUMBER(9,0) DEFAULT 0,
仕入先名 NVARCHAR2(50),
状況 NVARCHAR2(10),
SYS_NOT_UPD VARCHAR2(5),
SYS_DEL_FLG CHAR(1) DEFAULT '0' NOT NULL ENABLE,
SYS_UPD_PG VARCHAR2(50),
SYS_UPD_DTTM CHAR(15),
SYS_UPD_USER_CD VARCHAR2(14),
PRIMARY KEY (年度プロジェクトコード)
);
