Files
Nuvolar/Nuvolar.Module.Win/BusinessObjects/Business/BusinessTransactions/Offers/OfferIn/OfferInHeaderVC.vb
T
2017-03-08 11:21:27 +01:00

102 lines
4.4 KiB
VB.net

Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Text
Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.Persistent.Base
Imports DevExpress.ExpressApp.SystemModule
Imports System.IO
Imports FarPoint.Win.Spread
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.ExpressApp.Reports
Imports DevExpress.Data.Filtering
Imports DevExpress.ExpressApp.Editors
Public Class OfferInHeaderVC
Inherits DevExpress.ExpressApp.ViewController
Private _FpSpread As FpSpread
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
RegisterActions(components)
End Sub
Protected Overrides Sub OnActivated()
MyBase.OnActivated()
If View.Id = "OfferInHeader_DetailView" Then
AddHandler Frame.GetController(Of ModificationsController)().SaveAction.Executing, AddressOf SaveAction_Executing
AddHandler Frame.GetController(Of ModificationsController)().SaveAndCloseAction.Executing, AddressOf SaveAction_Executing
AddHandler Frame.GetController(Of ModificationsController)().SaveAndNewAction.Executing, AddressOf SaveAction_Executing
End If
End Sub
Protected Overrides Sub OnDeactivated()
MyBase.OnDeactivated()
If View.Id = "OffersInHeader_DetailView" Then
RemoveHandler Frame.GetController(Of ModificationsController)().SaveAction.Executing, AddressOf SaveAction_Executing
RemoveHandler Frame.GetController(Of ModificationsController)().SaveAndCloseAction.Executing, AddressOf SaveAction_Executing
RemoveHandler Frame.GetController(Of ModificationsController)().SaveAndNewAction.Executing, AddressOf SaveAction_Executing
End If
End Sub
Private Sub ExcelControlViewItem_ControlCreated(ByVal sender As Object, ByVal e As EventArgs)
Dim itemControl As Object = (CType(sender, ViewItem)).Control
_FpSpread = TryCast(itemControl, ExcelUserControl).FpSpreadControl
Dim _FileName As String = Path.GetTempPath & "Out.xls"
Dim _StreamFile As New FileStream(_FileName, FileMode.Create)
Dim _OfferInHeader As OfferInHeader = TryCast(View.SelectedObjects(0), OfferInHeader)
Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
If _ocur.Session.IsNewObject(_OfferInHeader) = False Then
If _OfferInHeader IsNot Nothing Then
If _OfferInHeader.ExcelFile IsNot Nothing Then
_OfferInHeader.ExcelFile.SaveToStream(_StreamFile)
_StreamFile.Close()
_FpSpread.OpenExcel(_FileName)
End If
End If
End If
End Sub
Protected Overrides Sub OnViewControlsCreated()
MyBase.OnViewControlsCreated()
If View.Id = "OfferInHeader_DetailView" Then
Dim _DetailView As DetailView = TryCast(View, DetailView)
Dim _ExcelControlViewItem As ViewItem
If _DetailView IsNot Nothing Then
If _DetailView.GetItems(Of ExcelPropertyEditor).Count > 0 Then
_ExcelControlViewItem = _DetailView.GetItems(Of ExcelPropertyEditor)(0)
If _ExcelControlViewItem IsNot Nothing Then
AddHandler _ExcelControlViewItem.ControlCreated, AddressOf ExcelControlViewItem_ControlCreated
End If
End If
End If
End If
End Sub
Sub SaveAction_Executing(sender As Object, e As System.ComponentModel.CancelEventArgs)
Dim _FileName As String = Path.GetTempPath & "In.xls"
Dim _StreamFile As New FileStream(_FileName, FileMode.Create)
Dim _OfferInHeader As OfferInHeader = TryCast(View.SelectedObjects(0), OfferInHeader)
Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
If _OfferInHeader IsNot Nothing Then
If _FpSpread IsNot Nothing Then
_FpSpread.SaveExcel(_StreamFile)
_StreamFile.Close()
Dim _StreamFile2 As New FileStream(_FileName, FileMode.Open)
_OfferInHeader.ExcelFile = New FileData(_ocur.Session)
_OfferInHeader.ExcelFile.LoadFromStream("Excel worksheet", _StreamFile2)
_OfferInHeader.Save()
_StreamFile2.Close()
End If
End If
End Sub
End Class