<Window.Resources>
<CollectionViewSource x:Key="Centerlist" />
<CollectionViewSource x:Key="Centerlist1"/>
<CollectionViewSource x:Key="ItemList"/>
<CollectionViewSource x:Key="MasterViewSource" />
<CollectionViewSource Source="{Binding TransferDetails, Source={StaticResource MasterViewSource}}" x:Key="DetailsViewSource" />
</Window.Resources>
<Grid Background="{DynamicResource InputBackgroundBrush}" DataContext="{Binding Source={StaticResource MasterViewSource}}">
<Grid.RowDefinitions>
<RowDefinition Height="0.112*"/>
<RowDefinition Height="0.08*"/>
<RowDefinition Height="0.073*"/>
<RowDefinition Height="0.091*"/>
<RowDefinition Height="0.551*"/>
<RowDefinition Height="0.093*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock TextWrapping="Wrap" Text="Date:" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{DynamicResource AvatarTextBlockStyle}"/>
<telerik:RadDatePicker x:Name="Transferdate" VerticalAlignment="Center" HorizontalAlignment="Center" Width="93.157" SelectedValue="{Binding TransferDate}"/>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Text="SourceCenter:" VerticalAlignment="Center" Style="{DynamicResource AvatarTextBlockStyle}" Margin="5,0,0,0"/>
<telerik:RadComboBox x:Name="cmbSourcecenter"
ItemsSource="{Binding Source={StaticResource Centerlist }}"
DisplayMemberPath="CenterName"
OpenDropDownOnFocus="True"
IsEditable="True"
SelectedItem="{Binding CenterMaster}"
Width="140" HorizontalAlignment="Center"
VerticalAlignment="Center"
Style="{DynamicResource Customradcombobox}"
Height="25"
DropDownOpened="cmbSourcecenter_DropDownOpened" >
</telerik:RadComboBox>
<TextBlock TextWrapping="Wrap" Text="To" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="15,0" Foreground="#FFDA1A1A" FontSize="13.333"/>
<TextBlock TextWrapping="Wrap" Text="DestinationCenter:" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{DynamicResource AvatarTextBlockStyle}"/>
<telerik:RadComboBox x:Name="cmbdestinationcenter"
Width="140"
ItemsSource="{Binding Source={StaticResource Centerlist1}}"
DisplayMemberPath="CenterName"
IsEditable="True"
SelectedItem="{Binding CenterMaster}"
OpenDropDownOnFocus="True"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Height="25"
Style="{DynamicResource Customradcombobox}"
DropDownOpened="cmbdestinationcenter_DropDownOpened">
</telerik:RadComboBox>
</StackPanel>
<StackPanel Grid.Row="3" Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Text="Remark:" VerticalAlignment="Center" Style="{DynamicResource AvatarTextBlockStyle}"/>
<telerik:RadWatermarkTextBox
x:Name="txtremark"
Text="{Binding Remark}"
WatermarkContent="Remark" TabIndex="2" VerticalAlignment="Center" Width="270.45" />
</StackPanel>
<StackPanel Grid.Row="4">
<DataGrid AutoGenerateColumns="False"
HorizontalAlignment="Stretch"
x:Name="CenterGrid"
IsSynchronizedWithCurrentItem="True"
CanUserAddRows="True"
CanUserDeleteRows="True"
Focusable="True"
ItemsSource="{Binding Source={StaticResource DetailsViewSource}}"
TabIndex="4" SelectionMode="Single" FontSize="10.667" HeadersVisibility="Column" >
<DataGrid.Columns>
<DataGridComboBoxColumn x:Name="cmbCentername" Header="ItemName"
ItemsSource="{Binding Source={StaticResource ItemList}}"
SelectedItemBinding="{Binding ItemMaster}"
DisplayMemberPath="ItemName"
SelectedValuePath="ItemId"
Width="150" HeaderStyle="{DynamicResource DataGridColumnHeaderStyle1}">
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="IsEditable" Value="True" />
<Setter Property="IsDropDownOpen" Value="True"/>
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
<DataGridTextColumn x:Name="txtqty" Header="Qty" Width="*" Binding="{Binding Qty, UpdateSourceTrigger=PropertyChanged}" HeaderStyle="{DynamicResource DataGridColumnHeaderStyle1}" />
</DataGrid.Columns>
</DataGrid>
</StackPanel>
<StackPanel Grid.Row="5" Orientation="Horizontal">
<Button x:Name="btnNew" Content="New" Height="29" Width="70" RenderTransformOrigin="0.493,-0.349" Click="btnNew_Click" Style="{DynamicResource imagebutton}" Margin="0,0.978,5,14.01" HorizontalAlignment="Right"/>
<Button x:Name="btnview" Height="29" Width="70" Click="btnview_Click" Style="{DynamicResource NormalButtonStyle}" Content="View" Margin="0,0.978,5,14.01" HorizontalAlignment="Right" />
<Button x:Name="btnSave" Content="Save" Height="29" Width="70" Click="btnSave_Click" RenderTransformOrigin="0.5,0.5" Style="{DynamicResource NormalButtonStyle}" Margin="0,0.978,5,14.01" TabIndex="14" HorizontalAlignment="Right" />
<Button x:Name="btnDelete" Content="Delete" Height="29" Width="70" Click="btnDelete_Click" Style="{DynamicResource NormalButtonStyle}" BorderThickness="3,3,475,3" Margin="0,0.978,0,14.01" HorizontalAlignment="Right"/>
</StackPanel>
</Grid>
code Behind
------------------------------------------------
namespace HTBookSystem.Form
{
/// <summary>
/// Interaction logic for TransferDetail.xaml
/// </summary>
public partial class TransferData : Window
{
HTBookEntities book = new HTBookEntities();
IList<Transfer> Transferdata;
IList<TransferDetail> Transferdatalist;
private CollectionViewSource MasterViewSource;
private CollectionViewSource DetailViewSource;
Transfer Tra;
int iid;
DataGridForm dgf;
public TransferData()
{
InitializeComponent();
}
private void btnNew_Click(object sender, RoutedEventArgs e)
{
iid = 0;
MethodMasterView();
}
private void btnview_Click(object sender, RoutedEventArgs e)
{
Tra = new Transfer();
dgf = new DataGridForm();
var grid = Tra.GridTransfer();
dgf.GridFormText("Outward");
iid = dgf.Returnid(grid);
MethodMasterView();
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
foreach (var idetail in Transferdatalist)
{
if (idetail.Transfer == null)
{
book.DeleteObject(idetail);
}
}
try
{
book.SaveChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
MessageBox.Show("Transfer data saved.", this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
}
private void btnDelete_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("Are you Sure To Delete This Entry?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
{
}
else
{
book.DeleteObject(Tra);
book.SaveChanges();
MessageBox.Show("Entry Successfully deleted");
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
IQueryable<ItemMaster> itemlist = from i in book.ItemMasters select i;
this.MasterViewSource = (CollectionViewSource)this.FindResource("MasterViewSource");
this.DetailViewSource = (CollectionViewSource)this.FindResource("DetailsViewSource");
CollectionViewSource productSource = (CollectionViewSource)this.FindResource("ItemList");
productSource.Source = itemlist.ToList();
var Centerlist = (from i in book.CenterMasters orderby i.CenterName select i);
CollectionViewSource Namesource = (CollectionViewSource)this.FindResource("Centerlist");
Namesource.Source = Centerlist.ToList();
var Centerlist1 = (from i in book.CenterMasters orderby i.CenterName select i);
CollectionViewSource Destinationsource = (CollectionViewSource)this.FindResource("Centerlist1");
Destinationsource.Source = Centerlist1.ToList();
this.MasterViewSource.Source = this.Transferdata;
iid = 2;
MethodMasterView();
}
public void MethodMasterView()
{
if (iid == 0)
{
Tra= new Transfer();
book.Transfers.AddObject(Tra);
}
else
{
Tra = (from i in book.Transfers.Include("TransferDetails")
where i.TransferId == iid
select i).First();
}
Transferdata = (from i in book.Transfers.Include("TransferDetails")
where i.TransferId == 0
select i).ToList();
Transferdata.Clear();
Transferdata.Add(Tra);
Transferdatalist = Tra.TransferDetails.ToList();
this.MasterViewSource.Source = this.Transferdata;
}
private void cmbSourcecenter_DropDownOpened(object sender, EventArgs e)
{
var Centerlist = (from i in book.CenterMasters orderby i.CenterName select i);
CollectionViewSource Namesource = (CollectionViewSource)this.FindResource("Centerlist");
Namesource.Source = Centerlist.ToList();
}
private void cmbdestinationcenter_DropDownOpened(object sender, EventArgs e)
{
var Centerlist1 = (from i in book.CenterMasters orderby i.CenterName select i);
CollectionViewSource Namesource = (CollectionViewSource)this.FindResource("Centerlist1");
Namesource.Source = Centerlist1.ToList();
}
}
<CollectionViewSource x:Key="Centerlist" />
<CollectionViewSource x:Key="Centerlist1"/>
<CollectionViewSource x:Key="ItemList"/>
<CollectionViewSource x:Key="MasterViewSource" />
<CollectionViewSource Source="{Binding TransferDetails, Source={StaticResource MasterViewSource}}" x:Key="DetailsViewSource" />
</Window.Resources>
<Grid Background="{DynamicResource InputBackgroundBrush}" DataContext="{Binding Source={StaticResource MasterViewSource}}">
<Grid.RowDefinitions>
<RowDefinition Height="0.112*"/>
<RowDefinition Height="0.08*"/>
<RowDefinition Height="0.073*"/>
<RowDefinition Height="0.091*"/>
<RowDefinition Height="0.551*"/>
<RowDefinition Height="0.093*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock TextWrapping="Wrap" Text="Date:" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{DynamicResource AvatarTextBlockStyle}"/>
<telerik:RadDatePicker x:Name="Transferdate" VerticalAlignment="Center" HorizontalAlignment="Center" Width="93.157" SelectedValue="{Binding TransferDate}"/>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Text="SourceCenter:" VerticalAlignment="Center" Style="{DynamicResource AvatarTextBlockStyle}" Margin="5,0,0,0"/>
<telerik:RadComboBox x:Name="cmbSourcecenter"
ItemsSource="{Binding Source={StaticResource Centerlist }}"
DisplayMemberPath="CenterName"
OpenDropDownOnFocus="True"
IsEditable="True"
SelectedItem="{Binding CenterMaster}"
Width="140" HorizontalAlignment="Center"
VerticalAlignment="Center"
Style="{DynamicResource Customradcombobox}"
Height="25"
DropDownOpened="cmbSourcecenter_DropDownOpened" >
</telerik:RadComboBox>
<TextBlock TextWrapping="Wrap" Text="To" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="15,0" Foreground="#FFDA1A1A" FontSize="13.333"/>
<TextBlock TextWrapping="Wrap" Text="DestinationCenter:" HorizontalAlignment="Center" VerticalAlignment="Center" Style="{DynamicResource AvatarTextBlockStyle}"/>
<telerik:RadComboBox x:Name="cmbdestinationcenter"
Width="140"
ItemsSource="{Binding Source={StaticResource Centerlist1}}"
DisplayMemberPath="CenterName"
IsEditable="True"
SelectedItem="{Binding CenterMaster}"
OpenDropDownOnFocus="True"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Height="25"
Style="{DynamicResource Customradcombobox}"
DropDownOpened="cmbdestinationcenter_DropDownOpened">
</telerik:RadComboBox>
</StackPanel>
<StackPanel Grid.Row="3" Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Text="Remark:" VerticalAlignment="Center" Style="{DynamicResource AvatarTextBlockStyle}"/>
<telerik:RadWatermarkTextBox
x:Name="txtremark"
Text="{Binding Remark}"
WatermarkContent="Remark" TabIndex="2" VerticalAlignment="Center" Width="270.45" />
</StackPanel>
<StackPanel Grid.Row="4">
<DataGrid AutoGenerateColumns="False"
HorizontalAlignment="Stretch"
x:Name="CenterGrid"
IsSynchronizedWithCurrentItem="True"
CanUserAddRows="True"
CanUserDeleteRows="True"
Focusable="True"
ItemsSource="{Binding Source={StaticResource DetailsViewSource}}"
TabIndex="4" SelectionMode="Single" FontSize="10.667" HeadersVisibility="Column" >
<DataGrid.Columns>
<DataGridComboBoxColumn x:Name="cmbCentername" Header="ItemName"
ItemsSource="{Binding Source={StaticResource ItemList}}"
SelectedItemBinding="{Binding ItemMaster}"
DisplayMemberPath="ItemName"
SelectedValuePath="ItemId"
Width="150" HeaderStyle="{DynamicResource DataGridColumnHeaderStyle1}">
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="IsEditable" Value="True" />
<Setter Property="IsDropDownOpen" Value="True"/>
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
<DataGridTextColumn x:Name="txtqty" Header="Qty" Width="*" Binding="{Binding Qty, UpdateSourceTrigger=PropertyChanged}" HeaderStyle="{DynamicResource DataGridColumnHeaderStyle1}" />
</DataGrid.Columns>
</DataGrid>
</StackPanel>
<StackPanel Grid.Row="5" Orientation="Horizontal">
<Button x:Name="btnNew" Content="New" Height="29" Width="70" RenderTransformOrigin="0.493,-0.349" Click="btnNew_Click" Style="{DynamicResource imagebutton}" Margin="0,0.978,5,14.01" HorizontalAlignment="Right"/>
<Button x:Name="btnview" Height="29" Width="70" Click="btnview_Click" Style="{DynamicResource NormalButtonStyle}" Content="View" Margin="0,0.978,5,14.01" HorizontalAlignment="Right" />
<Button x:Name="btnSave" Content="Save" Height="29" Width="70" Click="btnSave_Click" RenderTransformOrigin="0.5,0.5" Style="{DynamicResource NormalButtonStyle}" Margin="0,0.978,5,14.01" TabIndex="14" HorizontalAlignment="Right" />
<Button x:Name="btnDelete" Content="Delete" Height="29" Width="70" Click="btnDelete_Click" Style="{DynamicResource NormalButtonStyle}" BorderThickness="3,3,475,3" Margin="0,0.978,0,14.01" HorizontalAlignment="Right"/>
</StackPanel>
</Grid>
code Behind
------------------------------------------------
namespace HTBookSystem.Form
{
/// <summary>
/// Interaction logic for TransferDetail.xaml
/// </summary>
public partial class TransferData : Window
{
HTBookEntities book = new HTBookEntities();
IList<Transfer> Transferdata;
IList<TransferDetail> Transferdatalist;
private CollectionViewSource MasterViewSource;
private CollectionViewSource DetailViewSource;
Transfer Tra;
int iid;
DataGridForm dgf;
public TransferData()
{
InitializeComponent();
}
private void btnNew_Click(object sender, RoutedEventArgs e)
{
iid = 0;
MethodMasterView();
}
private void btnview_Click(object sender, RoutedEventArgs e)
{
Tra = new Transfer();
dgf = new DataGridForm();
var grid = Tra.GridTransfer();
dgf.GridFormText("Outward");
iid = dgf.Returnid(grid);
MethodMasterView();
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
foreach (var idetail in Transferdatalist)
{
if (idetail.Transfer == null)
{
book.DeleteObject(idetail);
}
}
try
{
book.SaveChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
MessageBox.Show("Transfer data saved.", this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
}
private void btnDelete_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("Are you Sure To Delete This Entry?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
{
}
else
{
book.DeleteObject(Tra);
book.SaveChanges();
MessageBox.Show("Entry Successfully deleted");
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
IQueryable<ItemMaster> itemlist = from i in book.ItemMasters select i;
this.MasterViewSource = (CollectionViewSource)this.FindResource("MasterViewSource");
this.DetailViewSource = (CollectionViewSource)this.FindResource("DetailsViewSource");
CollectionViewSource productSource = (CollectionViewSource)this.FindResource("ItemList");
productSource.Source = itemlist.ToList();
var Centerlist = (from i in book.CenterMasters orderby i.CenterName select i);
CollectionViewSource Namesource = (CollectionViewSource)this.FindResource("Centerlist");
Namesource.Source = Centerlist.ToList();
var Centerlist1 = (from i in book.CenterMasters orderby i.CenterName select i);
CollectionViewSource Destinationsource = (CollectionViewSource)this.FindResource("Centerlist1");
Destinationsource.Source = Centerlist1.ToList();
this.MasterViewSource.Source = this.Transferdata;
iid = 2;
MethodMasterView();
}
public void MethodMasterView()
{
if (iid == 0)
{
Tra= new Transfer();
book.Transfers.AddObject(Tra);
}
else
{
Tra = (from i in book.Transfers.Include("TransferDetails")
where i.TransferId == iid
select i).First();
}
Transferdata = (from i in book.Transfers.Include("TransferDetails")
where i.TransferId == 0
select i).ToList();
Transferdata.Clear();
Transferdata.Add(Tra);
Transferdatalist = Tra.TransferDetails.ToList();
this.MasterViewSource.Source = this.Transferdata;
}
private void cmbSourcecenter_DropDownOpened(object sender, EventArgs e)
{
var Centerlist = (from i in book.CenterMasters orderby i.CenterName select i);
CollectionViewSource Namesource = (CollectionViewSource)this.FindResource("Centerlist");
Namesource.Source = Centerlist.ToList();
}
private void cmbdestinationcenter_DropDownOpened(object sender, EventArgs e)
{
var Centerlist1 = (from i in book.CenterMasters orderby i.CenterName select i);
CollectionViewSource Namesource = (CollectionViewSource)this.FindResource("Centerlist1");
Namesource.Source = Centerlist1.ToList();
}
}
Dipak Sutare