This example contains the source code for the XAF Project Management Application - Stage 4. The complete description can be found in the XAF – Project Management Application #6 blog post.
using System;
using System.Data;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Xpo;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
using DevExpress.Xpo.Helpers;
namespace XProject.Module.Win {
public partial class DumpDataController : ViewController {
public DumpDataController() {
InitializeComponent();
RegisterActions(components);
}
private void LoadDumpFromXML_Execute(object sender, SimpleActionExecuteEventArgs e) {
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
if (openFile.ShowDialog() == DialogResult.OK) {
LoadDumpFromFile(openFile.FileName);
}
}
private void DumpToXML_Execute(object sender, SimpleActionExecuteEventArgs e) {
OpenFileDialog openFile = new OpenFileDialog();
openFile.CheckFileExists = false;
openFile.FileName = View.ObjectTypeInfo.Name;
openFile.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
if (openFile.ShowDialog() == DialogResult.OK) {
DumpToFile(openFile.FileName);
}
}
private void DumpToFile(string fileName) {
Session sourceSession = ((XPObjectSpace)View.ObjectSpace).Session;
DataSet dataSet = new DataSet();
DataSetDataStore dataStore = new DataSetDataStore(dataSet, AutoCreateOption.DatabaseAndSchema);
IDataLayer dataLayer = new SimpleDataLayer(sourceSession.Dictionary, dataStore);
UnitOfWork destinationSession = new UnitOfWork(dataLayer);
ClonerHelper.Clone(sourceSession, destinationSession, View.SelectedObjects);
destinationSession.CommitChanges();
dataSet.WriteXml(fileName, XmlWriteMode.WriteSchema);
}
private void LoadDumpFromFile(string fileName) {
UnitOfWork destinationSession = ((XPObjectSpace)View.ObjectSpace).Session as UnitOfWork;
if (destinationSession == null) return;
DataSet dataSet = new DataSet();
DataSetDataStore dataStore = new DataSetDataStore(dataSet, AutoCreateOption.DatabaseAndSchema);
IDataLayer dataLayer = new SimpleDataLayer(destinationSession.Dictionary, dataStore);
dataSet.ReadXml(fileName);
UnitOfWork sourceSession = new UnitOfWork(dataLayer);
ClonerHelper.Clone(sourceSession, destinationSession, View.ObjectTypeInfo.Type);
destinationSession.CommitChanges();
}
}
}
Facebook
Twitter
Google+