This question is locked. New answers and comments are not allowed.
I am trying to use QSDCV for my Sales Order Page to perform a CRUD, but seems like not getting there! here is what i am doing.
Model :
ViewModel :
Model :
- I have Sales Order Entity called SOPDoc
- I have a Child Entity to SOPDoc, called SOPDocDetails. This holds all the items for a specific Order and can be accessed like SOPDoc.SOPDocDetails which returns IEnumerable<SOPDocDetails>. I am using OpenAccess for Model.
ViewModel :
- QueryableDomainServiceCollectionView for SOPDoc, which loads a single record.
public
const
string
qsdcvSOPDocPropertyName =
"qsdcvSOPDoc"
;
private
QueryableDomainServiceCollectionView<SOPDoc> _qsdcvSOPDoc;
public
QueryableDomainServiceCollectionView<SOPDoc> qsdcvSOPDoc
{
get
{
return
_qsdcvSOPDoc;
}
set
{
if
(_qsdcvSOPDoc == value)
{
return
;
}
var oldValue = _qsdcvSOPDoc;
_qsdcvSOPDoc = value;
RaisePropertyChanged(qsdcvSOPDocPropertyName, oldValue, value,
true
);
}
}
- Current Sales Order ID, this holds the ID of current sales order and is used while loading QSDCV
public
const
string
CurrentSalesOrderIdPropertyName =
"CurrentSalesOrderId"
;
private
int
_currentSalesOrderId;
public
int
CurrentSalesOrderId
{
get
{
return
_currentSalesOrderId;
}
set
{
if
(_currentSalesOrderId == value)
{
return
;
}
var oldValue = _currentSalesOrderId;
_currentSalesOrderId = value;
RaisePropertyChanged(CurrentSalesOrderIdPropertyName, oldValue, value,
true
);
}
}
- Current Order Entity, When QSDCV Loaded Event Fires, from the result, FirstOrDefault() is populated to 'entCurrentOrder'. This is then used to bind different View Controls, e.g. Order Date, Ordering Customer, Discount Amount or Carriage etc.
-
publicconst
string
entCurrentOrderPropertyName =
"entCurrentOrder"
;
private
SOPDoc _entCurrentOrder;
public
SOPDoc entCurrentOrder
{
get
{
return
_entCurrentOrder;
}
set
{
if
(_entCurrentOrder == value)
{
return
;
}
_entCurrentOrder = value;
RaisePropertyChanged(entCurrentOrderPropertyName);
}
}
- entSOPDocDetail is used as CurrentItem binding for the RadGridView & RadDataForm in the view.
public
const
string
entSOPDocDetailPropertyName =
"entSOPDocDetail"
;
private
SOPDocDetail _entSOPDocDetail;
public
SOPDocDetail entSOPDocDetail
{
get
{
return
_entSOPDocDetail;
}
set
{
if
(_entSOPDocDetail == value)
{
return
;
}
var oldValue = _entSOPDocDetail;
_entSOPDocDetail = value;
RaisePropertyChanged(entSOPDocDetailPropertyName, oldValue, value,
true
);
}
}
- ViewModelConstructor
public
SalesOrderViewModel()
{
CurrentSalesOrderId = 1;
// this is just for example while testing the page, so that it loads the SalesOrder with ID = 1
ctx =
new
KERPDomainContext();
qry = ctx.GetSalesOrderByIdQuery(CurrentSalesOrderId);
qsdcvSOPDoc =
new
QueryableDomainServiceCollectionView<SOPDoc>(ctx, qry);
qsdcvSOPDoc.Load();
qsdcvSOPDoc.LoadedData += qsdcvSOPDoc_LoadedData;
}
- Loaded Event for QSDCV, here i bind entCurrentOrder to the returned entity and depending on the PageMode Value (this is another property which i set to establish a new order being saved or existing one to be pulled), i.e. 'New' or 'Edit'.
void
qsdcvSOPDoc_LoadedData(
object
sender, LoadedDataEventArgs e)
{
if
(!e.HasError)
{
entCurrentOrder = (SOPDoc) e.Entities.FirstOrDefault();
// Loads the Current Order in an Entity so that it can be boudn to the veiw controls
if
(PageMode == Enums.SODModes.New.ToString() && CurrentSalesOrderId <= 0)
{
// Do something ......
}
if
(PageMode == Enums.SODModes.Edit.ToString() && CurrentSalesOrderId > 0)
{
if
(entCurrentOrder !=
null
)
{
OrderingCustomer = entCurrentOrder.Customer;
// assign current Customer to a <Customer> OrderingCustomer to be used in View databinding
GrossAmount = entCurrentOrder.SOPDocDetails.Sum(i => i.NetAmount);
Carriage = entCurrentOrder.Carriage;
Discount = entCurrentOrder.Discount;
}
}
}
}
View : My View is of a Single Page for Editing and Updating
PROBLEM :
Please do not get put off by the length of the question, my question is very simple and it is just the concept i am after, all the code snippets are just to help you understand and please tell me if i am doing it wrong.
Any Help will be HUGELY appreciated since even cant get help from StackOverFlow !!! question remained unanswered!! .... PLEASE HELP....thx
- SalesOrderView.xaml, it is a silvelright page which holds multiple user controls, all binds to the SalesOrderViewModel.cs, one of the UserControl is SalesItems.xaml
<telerik:RadGridView Grid.Row=
"1"
AutoExpandGroups=
"True"
AutoGenerateColumns=
"False"
ColumnWidth=
"*"
CurrentItem=
"{Binding entSOPDocDetail}"
IsSynchronizedWithCurrentItem=
"True"
IsReadOnly=
"False"
ItemsSource=
"{Binding rocTest}"
>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn Header=
"Product Code"
DataMemberBinding=
"{Binding ProductCode}"
Width=
"1.5*"
/>
<telerik:GridViewDataColumn Header=
"Description"
DataMemberBinding=
"{Binding Description}"
Width=
"5*"
/>
<telerik:GridViewDataColumn Header=
"Qty"
DataMemberBinding=
"{Binding Qty}"
Width=
"*"
/>
<telerik:GridViewDataColumn Header=
"UnitType"
DataMemberBinding=
"{Binding UnitType}"
/>
<telerik:GridViewDataColumn Header=
"Unit Price"
DataMemberBinding=
"{Binding UnitPrice}"
DataFormatString=
"{}{0:0,0.00}"
/>
<telerik:GridViewDataColumn Header=
"Line Total"
DataMemberBinding=
"{Binding NetAmount}"
DataFormatString=
"{}{0:0,0.00}"
/>
<telerik:GridViewColumn Width=
"90"
>
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<telerik:RadButton Content=
"Delete"
Command=
"telerik:RadGridViewCommands.Delete"
CommandParameter=
"{Binding}"
/>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
<telerik:RadDataForm x:Name=
"dataForm"
CommandButtonsVisibility=
"Cancel,Commit"
AutoGenerateFields=
"False"
ValidationSummaryVisibility=
"Collapsed"
EditEnded=
"RadDataForm_EditEnded"
CurrentItemChanged=
"OnDataFormCurrentItemChanged"
LabelPosition=
"Above"
EditTemplate=
"{StaticResource SOItemsEditTemplate}"
NewItemTemplate=
"{StaticResource SOItemsEditTemplate}"
VerticalContentAlignment=
"Stretch"
HorizontalContentAlignment=
"Stretch"
CurrentItem=
"{Binding entSOPDocDetail}"
ItemsSource=
"{Binding rocTest}"
Margin=
"0,0,0,14"
Grid.RowSpan=
"2"
HorizontalAlignment=
"Left"
Width=
"321"
/>
- In the same page SOPItems.xaml i have two buttons bound to RadDataForm 'Add' and 'Edit' Commands
<telerik:RadButton Tag=
"Add"
Command=
"telerik:RadDataFormCommands.AddNew"
CommandTarget=
"{Binding ElementName=dataForm}"
/>
<telerik:RadButton Tag=
"Edit"
Command=
"telerik:RadDataFormCommands.BeginEdit"
CommandTarget=
"{Binding ElementName=dataForm}"
/>
PROBLEM :
- When i bind RadDataForm's ItemSource property to IEnumerable<SOPDoc.SOPDocDetails>, the Edit and Add buttons are disabled. Also i cant seem to find out a way to set 'CurrentSalesOrderId' in usercontrol's Loaded event because the ViewModel Constructor is executed long before the execution of UserControl's Loaded Event.
- How do i SaveChanges to QSDCV which includes changing the existing entity but if this is a new order, it saves a new entity.... i am totally lost by experimenting so many things so many times, i cant seems to grab the concept
Please do not get put off by the length of the question, my question is very simple and it is just the concept i am after, all the code snippets are just to help you understand and please tell me if i am doing it wrong.
Any Help will be HUGELY appreciated since even cant get help from StackOverFlow !!! question remained unanswered!! .... PLEASE HELP....thx