Xmal:
<Window.Resources>
<CollectionViewSource x:Key="MasterViewSource" />
<CollectionViewSource Source="{Binding Source={StaticResource MasterViewSource}, Path='InwardDetails'}" x:Key="DetailsViewSource" />
<CollectionViewSource x:Key="PartyList" />
<CollectionViewSource x:Key="ItemList" />
</Window.Resources>
<Grid DataContext="{Binding Source={StaticResource MasterViewSource}}">
<Grid.RowDefinitions>
<RowDefinition Height="38*" />
<RowDefinition Height="86*" />
<RowDefinition Height="230*" />
<RowDefinition Height="115*" />
<RowDefinition Height="28*" />
</Grid.RowDefinitions>
<TextBlock Height="16"
HorizontalAlignment="Left"
Margin="621,6,0,0"
Name="textBlock1"
Text="Date:"
VerticalAlignment="Top"
TextAlignment="Justify" Grid.Row="1" />
<telerik:RadDatePicker
HorizontalAlignment="Left"
Margin="654,2,0,0"
Name="dtpInwarddate"
VerticalAlignment="Top"
SelectedValue="{Binding Path=InwardDate}"
Width="105" Grid.Row="1" />
<TextBlock Height="16"
HorizontalAlignment="Left"
Margin="613,41,0,0"
Name="textBlock2"
Text="Bill No:"
TextAlignment="Justify"
VerticalAlignment="Top"
Grid.Row="1" />
<telerik:RadWatermarkTextBox
Grid.Row="1" Height="23"
HorizontalAlignment="Left"
Margin="654,36,0,0"
Name="txtbillNo"
Text="{Binding Path=BillNo}"
WatermarkContent="Enter Bill No"
VerticalAlignment="Top" Width="105" />
<telerik:RadComboBox Grid.Row="1"
HorizontalAlignment="Left"
Margin="0,6,0,0"
Name="cmbparty"
ItemsSource="{Binding Source={StaticResource PartyList}}"
DisplayMemberPath="PartyName"
SelectedItem="{Binding Path=PartyMaster}"
VerticalAlignment="Top"
Width="250" >
<!--<telerik:RadComboBoxItem Content="Item 1" />
<telerik:RadComboBoxItem Content="Item 2" />
<telerik:RadComboBoxItem Content="Item 3" />-->
</telerik:RadComboBox>
<telerik:RadWatermarkTextBox Grid.Row="3"
Height="23" HorizontalAlignment="Left"
Margin="42,11,0,0"
Name="txtRemark"
Text="{Binding Path=Remark}"
VerticalAlignment="Top" Width="272" />
<TextBlock
Height="15" HorizontalAlignment="Left"
Margin="0,14,0,0" Name="textBlock3"
Text="Remark:" TextAlignment="Justify"
VerticalAlignment="Top" Grid.Row="3" />
<GroupBox Grid.Row="3" Header="groupBox1" Height="87" HorizontalAlignment="Left" Margin="616,1,0,0" Name="groupBox1" VerticalAlignment="Top" Width="113">
<Grid Width="102">
<TextBlock Height="15" HorizontalAlignment="Left" Margin="3,15,0,0" Name="textBlock4" Text="Add:" TextAlignment="Justify" VerticalAlignment="Top" />
<TextBlock Height="15" HorizontalAlignment="Left" Margin="1,44,0,0" Name="textBlock5" Text="Less:" TextAlignment="Justify" VerticalAlignment="Top" />
<telerik:RadWatermarkTextBox Height="23" Text="{Binding Path=AmountAdd}" HorizontalAlignment="Left" Margin="27,10,0,0" Name="txtAdd" VerticalAlignment="Top" Width="69" />
<telerik:RadWatermarkTextBox Height="23" Text="{Binding Path=AmountLess}" HorizontalAlignment="Left" Margin="27,39,0,0" Name="txtless" VerticalAlignment="Top" Width="69" />
</Grid>
</GroupBox>
<telerik:RadWatermarkTextBox
Height="23" Margin="563,93,0,0" Name="txtpaid"
VerticalAlignment="Top" Grid.Row="3" Text="{Binding Path=Paid}" HorizontalAlignment="Left" Width="69" />
<TextBlock Height="15" HorizontalAlignment="Left"
Margin="536,99,0,0" Name="textBlock7"
Text="Paid:" TextAlignment="Justify"
VerticalAlignment="Top" Grid.Row="3" Width="29" />
<TextBlock Height="15" HorizontalAlignment="Left"
Margin="648,98,0,0" Name="textBlock8"
Text="Total:" TextAlignment="Justify"
VerticalAlignment="Top" Width="32" Grid.Row="3" />
<telerik:RadWatermarkTextBox Height="23" HorizontalAlignment="Right"
Margin="0,93,12,0" Name="txttotal"
VerticalAlignment="Top" Width="69"
Grid.Row="3"
Text="{Binding Path=Total}"/>
<TextBlock Height="15" HorizontalAlignment="Left" Margin="12,42,0,0" Name="textBlock6" Text="Paid:" TextAlignment="Justify" VerticalAlignment="Top" Grid.Row="3" />
<telerik:RadWatermarkTextBox Height="23"
Margin="42,39,0,0" Name="txtpaidremark"
VerticalAlignment="Top" Grid.Row="3"
HorizontalAlignment="Left" Width="216"
Text="{Binding Path=PaidRemark}"/>
<ListView Grid.Row="2" Name="ListView1"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding Source={StaticResource DetailsViewSource}}" PreviewKeyDown="ListView1_PreviewKeyDown">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<EventSetter Event="GotFocus" Handler="Item_GotFocus" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Item" Width="150">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox IsEditable="False"
Name="cboProduct"
IsSynchronizedWithCurrentItem="False"
ItemsSource="{Binding Source={StaticResource ItemList}}"
SelectedItem="{Binding Path=ItemMaster}"
SelectedValuePath="ItemId"
DisplayMemberPath="ItemName"
Margin="-6,0,-6,0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Qty" Width="75">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Qty}"
Margin="-6,0,-6,0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Rate" Width="75">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Rate}"
Margin="-6,0,-6,0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Amount" Width="75">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Path=Amount}"
Margin="-6,0,-6,0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<telerik:RadButton Content="New" Height="23" Margin="68,0,631,5" Name="btnNew" Width="60" Grid.Row="4" Click="btnNew_Click" />
<telerik:RadButton Content="View" Height="23" Margin="143,0,556,5" Name="Btnview" Width="60" Grid.Row="4" Click="Btnview_Click" />
<telerik:RadButton Content="Save" Height="23" Margin="218,0,481,5" Name="btnSave" Width="60" Grid.Row="4" Click="btnSave_Click" />
<telerik:RadButton Content="Delete" Height="23" Margin="293,0,406,5" Name="btnDelete" Width="60" Grid.Row="4" Click="btnDelete_Click" />
</Grid>
</Window>
C#Code behind
public partial class inwddetail : Window
{
HTBookEntities book = new HTBookEntities();
private InwardCollection inwarddata; // inherits from ObservableCollection
private CollectionViewSource MasterViewSource;
private CollectionViewSource DetailViewSource;
Inward iwd;
int iid;
DataGridForm dgf;
// Provides currency to controls (position & movement in the collections)
private ListCollectionView MasterView;
private BindingListCollectionView DetailsView;
public inwddetail()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
iid = 8;
MethodMasterView(iid);
//IQueryable<Inward> query = from i in book.Inwards.Include("InwardDetails")
// where i.InwardId == 7
// select i;
//this.inwarddata = new InwardCollection(query, book);
IQueryable<PartyMaster> partylist = from p in book.PartyMasters select p;
IQueryable<ItemMaster> itemlist = from i in book.ItemMasters select i;
this.MasterViewSource = (CollectionViewSource)this.FindResource("MasterViewSource");
this.DetailViewSource = (CollectionViewSource)this.FindResource("DetailsViewSource");
this.MasterViewSource.Source = this.inwarddata;
CollectionViewSource customerSource = (CollectionViewSource)this.FindResource("PartyList");
customerSource.Source = partylist.ToList();
CollectionViewSource productSource = (CollectionViewSource)this.FindResource("ItemList");
productSource.Source = itemlist.ToList();
this.MasterView = (ListCollectionView)this.MasterViewSource.View;
MasterView.CurrentChanged += new EventHandler(MasterView_CurrentChanged);
this.DetailsView = (BindingListCollectionView)this.DetailViewSource.View;
}
private void MasterView_CurrentChanged(object sender, System.EventArgs e)
{
this.DetailsView = (BindingListCollectionView)this.DetailViewSource.View;
}
private void btnSave_Click(object sender, RoutedEventArgs e)
{
try
{
book.SaveChanges();
MessageBox.Show("Order data saved.", this.Title, MessageBoxButton.OK, MessageBoxImage.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void Item_GotFocus(object sender, System.Windows.RoutedEventArgs e)
{
// This will keep the View position in sync with the selected
// row even when a control is being edited in the ListViewItem
ListViewItem item = (ListViewItem)sender;
this.ListView1.SelectedItem = item.DataContext;
}
private void btnNew_Click(object sender, RoutedEventArgs e)
{
this.MasterView.AddNew();
this.MasterView.CommitNew();
}
private void ListView1_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Subtract)
{
if (this.DetailsView.CurrentPosition > -1)
this.DetailsView.RemoveAt(this.DetailsView.CurrentPosition);
e.Handled = true;
}
if (e.Key == Key.Add)
{
this.DetailsView.AddNew();
this.DetailsView.CommitNew();
}
}
private void Btnview_Click(object sender, RoutedEventArgs e)
{
iwd = new Inward();
dgf = new DataGridForm();
var grid = iwd.Gridinward();
dgf.GridFormText("Inward");
iid = dgf.Returnid(grid);
//this.MasterView.MoveCurrentToPosition(iid);
MethodMasterView(iid);
}
private void btnDelete_Click(object sender, RoutedEventArgs e)
{
if (this.MasterView.CurrentPosition > -1)
this.MasterView.RemoveAt(this.MasterView.CurrentPosition);
book.SaveChanges();
MessageBox.Show("Entry Deleted");
}
public void MethodMasterView(int id)
{
IQueryable<Inward> query = from i in book.Inwards.Include("InwardDetails")
where i.InwardId == id
select i;
this.inwarddata = new InwardCollection(query, book);
}
}
0 comments :
Post a Comment