using
System.Windows;
using
System.Windows.Controls;
using
Telerik.Windows.Controls;
using
Telerik.Windows.Controls.DragDrop;
using
System.ServiceModel.DomainServices.Client;
using
System;
using
Telerik.Windows.Controls.GridView;
using
System.Collections.Generic;
using
System.Collections;
using
System.Collections.ObjectModel;
using
System.Linq;
using
Telerik.Windows.Controls.TreeView;
using
System.Windows.Media;
using
SilverFinancials.Web.Models;
namespace
SilverFinancials.Windows
{
public
partial
class
DragExample : RadWindow
{
#region private member
private
bool
hasConcurrencyIssue =
false
;
#endregion
#region Constructor
public
DragExample()
{
try
{
InitializeComponent();
//xxTable2DataSource.DomainContext.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(DomainContext_PropertyChanged);
}
catch
(Exception ex)
{
RadWindow.Alert(
"Screen timed out. Please open again!"
);
}
//MyBusinessObjects businessObjectGenerator = new MyBusinessObjects();
//SilverFinancials.Web.Services.xxTable1 x = new SilverFinancials.Web.Services.xxTable1();
//EntityQuery<SilverFinancials.Web.Models.xxTable1> xx = x.GetXxTable1Query();
//foreach (SilverFinancials.Web.Models.xxTable1 sd in x.GetXxTable1Query())
//{
//}
RadDragAndDropManager.AddDropQueryHandler(billTypeRadGridView, OnDropQuery);
RadDragAndDropManager.AddDropInfoHandler(billTypeRadGridView, OnDropInfoxxTable2);
RadDragAndDropManager.AddDragQueryHandler(billTypeRadGridView, OnDragQuery);
RadDragAndDropManager.AddDragInfoHandler(billTypeRadGridView, OnDragInfoxxTable1);
RadDragAndDropManager.AddDropQueryHandler(billTypeRadGridViewDrop, OnDropQuery);
RadDragAndDropManager.AddDropInfoHandler(billTypeRadGridViewDrop, OnDropInfoxxTable1);
RadDragAndDropManager.AddDragQueryHandler(billTypeRadGridViewDrop, OnDragQuery);
RadDragAndDropManager.AddDragInfoHandler(billTypeRadGridViewDrop, OnDragInfoxxTable2);
}
private
void
DomainContext_PropertyChanged(
object
sender, System.ComponentModel.PropertyChangedEventArgs e)
{
//saveRBTN.IsEnabled = billTypeDomainDataSource.DomainContext.HasChanges;
//cancelRBTN.IsEnabled = billTypeDomainDataSource.DomainContext.HasChanges;
//xxTable2DataSource.Clear();
//xxTable2DataSource.Load();
}
#endregion
#region Load event handler for the domain data source
private
void
billTypeDomainDataSource_LoadedData(
object
sender, LoadedDataEventArgs e)
{
if
(e.HasError)
{
System.Windows.MessageBox.Show(e.Error.ToString(),
"Load Error"
, System.Windows.MessageBoxButton.OK);
e.MarkErrorAsHandled();
}
}
private
void
billTypeDomainDataSource_LoadingData(
object
sender, LoadingDataEventArgs e)
{
e.LoadBehavior = System.ServiceModel.DomainServices.Client.LoadBehavior.RefreshCurrent;
}
#endregion
#region Save/Cancel button event handlers
private
void
saveRBTN_Click(
object
sender, RoutedEventArgs e)
{
//saveRBTN.IsEnabled = false;
//billTypeRadGridView.CommitEdit();
//billTypeDomainDataSource.DomainContext.SubmitChanges(OnSubmitCompleted, null);
}
private
void
cancelRBTN_Click(
object
sender, RoutedEventArgs e)
{
xxTable1DataSource.DomainContext.RejectChanges();
xxTable2DataSource.DomainContext.RejectChanges();
}
////////// Handle Update Concurrency///////////////////
private
void
OnSubmitCompleted(SubmitOperation so)
{
//saveRBTN.IsEnabled = true;
if
(so.HasError)
{
hasConcurrencyIssue =
false
;
foreach
(Entity entity
in
so.EntitiesInError)
{
//Process entity conflict concurrency
if
(entity.EntityConflict !=
null
)
{
hasConcurrencyIssue =
true
;
RadWindow.Alert(
"An update concurrency issue occurs."
, closed);
break
;
}
}
so.MarkErrorAsHandled();
if
(!hasConcurrencyIssue)
{
MessageBox.Show(
"Save failed."
);
}
}
else
{
MessageBox.Show(
"Save successfully."
);
}
}
private
void
closed(
object
sender, WindowClosedEventArgs e)
{
xxTable1DataSource.Clear();
xxTable1DataSource.Load();
xxTable2DataSource.Clear();
xxTable2DataSource.Load();
}
#endregion
#region Save closing feature
private
void
RadWindow_Closed(
object
sender, WindowClosedEventArgs e)
{
}
#endregion
// OnDragQuery event handler
private
void
OnDragQuery(
object
sender, DragDropQueryEventArgs e)
{
RadGridView gridView = sender
as
RadGridView;
if
(gridView !=
null
)
{
e.Options.Payload = gridView.SelectedItem;
}
e.QueryResult =
true
;
e.Handled =
true
;
}
// OnDragInfo event handler
private
void
OnDragInfoxxTable1(
object
sender, DragDropEventArgs e)
{
RadGridView gridView = sender
as
RadGridView;
xxTable1 draggedItem = e.Options.Payload
as
xxTable1;
if
(e.Options.Status == DragStatus.DragInProgress)
{
//Setting up a drag cue:
ContentControl cue =
new
ContentControl();
//Choosing a template for the items:
//cue.ContentTemplate = this.Resources["ProductTemplate"] as DataTemplate;
cue.Content = draggedItem;
e.Options.DragCue = cue;
}
else
if
(e.Options.Status == DragStatus.DragComplete)
{
//deleting the dragged item from the RadGridView
IList<xxTable1> source = gridView.ItemsSource
as
IList<xxTable1>;
gridView.Items.Remove(draggedItem);
// source.Remove(draggedItem);
}
}
private
void
OnDragInfoxxTable2(
object
sender, DragDropEventArgs e)
{
RadGridView gridView = sender
as
RadGridView;
xxTable2 draggedItem = e.Options.Payload
as
xxTable2;
if
(e.Options.Status == DragStatus.DragInProgress)
{
//Setting up a drag cue:
ContentControl cue =
new
ContentControl();
//Choosing a template for the items:
//cue.ContentTemplate = this.Resources["ProductTemplate"] as DataTemplate;
cue.Content = draggedItem;
e.Options.DragCue = cue;
}
else
if
(e.Options.Status == DragStatus.DragComplete)
{
//deleting the dragged item from the RadGridView
IList<xxTable2> source = gridView.ItemsSource
as
IList<xxTable2>;
gridView.Items.Remove(draggedItem);
// source.Remove(draggedItem);
}
}
// OnDropQuery event handler
private
void
OnDropQuery(
object
sender, DragDropQueryEventArgs e)
{
RadGridView destination = sender
as
RadGridView;
if
(destination !=
null
)
{
e.Handled =
true
;
e.QueryResult =
true
;
}
}
// OnDropInfo event handler
private
void
OnDropInfoxxTable1(
object
sender, DragDropEventArgs e)
{
RadGridView destination = sender
as
RadGridView;
xxTable1 draggedItem = e.Options.Payload
as
xxTable1;
if
(e.Options.Status == DragStatus.DropComplete)
{
xxTable2 x =
new
xxTable2();
x.Description = draggedItem.Description;
x.Amount = draggedItem.Amount;
(xxTable2DataSource.DomainContext
as
SilverFinancials.Web.Services.xxTable2).xxTable2s.Add(x);
//billTypeRadGridViewDrop.ItemsSource= xxTable2DataSource;
xxTable2DataSource.DomainContext.SubmitChanges();
//xxTable2DataSource.Clear();
billTypeRadGridViewDrop.ItemsSource =
null
;
// billTypeRadGridViewDrop.ItemsSource = xxTable2DataSource.DomainContext.Load(SilverFinancials.Web.Services.xxTable2()) ;
xxTable2DataSource.Clear();
xxTable2DataSource.Load();
// billTypeRadGridViewDrop.ItemsSource = xxTable2DataSource;
// billTypeRadGridViewDrop
//// xxTable2DataSource.DataView.Add(draggedItem);
//xxTable2DataSource.DomainContext.
// destination.Items.Add(x);
//(destination.ItemsSource as IList<xxTable2>).Add(e.Options.Payload as xxTable2);
}
///xxTable2DataSource.Clear();
//xxTable2DataSource.Load();
}
private
void
OnDropInfoxxTable2(
object
sender, DragDropEventArgs e)
{
RadGridView destination = sender
as
RadGridView;
xxTable2 draggedItem = e.Options.Payload
as
xxTable2;
if
(e.Options.Status == DragStatus.DropComplete)
{
xxTable1 x =
new
xxTable1();
x.Description = draggedItem.Description;
x.Amount = draggedItem.Amount;
(xxTable1DataSource.DomainContext
as
SilverFinancials.Web.Services.xxTable1).xxTable1s.Add(x);
//billTypeRadGridViewDrop.ItemsSource= xxTable2DataSource;
xxTable1DataSource.DomainContext.SubmitChanges();
//xxTable2DataSource.Clear();
billTypeRadGridViewDrop.ItemsSource =
null
;
// billTypeRadGridViewDrop.ItemsSource = xxTable2DataSource.DomainContext.Load(SilverFinancials.Web.Services.xxTable2()) ;
xxTable1DataSource.Clear();
xxTable1DataSource.Load();
// billTypeRadGridViewDrop.ItemsSource = xxTable2DataSource;
// billTypeRadGridViewDrop
//// xxTable2DataSource.DataView.Add(draggedItem);
//xxTable2DataSource.DomainContext.
// destination.Items.Add(x);
//(destination.ItemsSource as IList<xxTable2>).Add(e.Options.Payload as xxTable2);
}
///xxTable2DataSource.Clear();
//xxTable2DataSource.Load();
}
void
TaskDDS_SubmittedChanges(
object
sender, SubmittedChangesEventArgs e)
{
//dc.Load(dc.GetReportsQuery());
//// Report is the name of usercotrol
//// RepDataGrid is the name of DataGrid control is inside the Report
//Report.RepDataGrid.ItemsSource = dc.Reports;
}
}
}