xuyi
9/10/2019 - 12:34 AM

Page.New

<commonData:SecurityPage
     xmlns:commonData="clr-namespace:HD.SL.Common.Data.CommonData;assembly=HD.SL.Common.Data"
     xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"     
	x:Class="HD.SL.***New" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="TransportNew Page">
   <telerik:RadBusyIndicator x:Name="busyIndicator" >
        <Grid x:Name="gridLayout" Margin="2,10,2,2">
            <StackPanel Orientation="Horizontal" Margin="0,4,0,0" HorizontalAlignment="Right">
                <telerik:RadButton x:Name="btnCreate" Content="创  建" Width="90" Height="24" Click="btnCreate_Click" Margin="0,0,4,0"/>
                <telerik:RadButton x:Name="btnClose" Content="关  闭" Width="90" Height="24" Click="btnClose_Click"/>
            </StackPanel>
        </Grid>
    </telerik:RadBusyIndicator>
</commonData:SecurityPage>
using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows;
using HD.SL.Common.Data.CommonData;
using Telerik.Windows.Controls;
using HD.SL.Common.Controls;
using HD.SL.Common.Data.Operation;
using HD.SL.Common.Data.UI.Validation;
using HD.SL.Common.Asset.ResouceLists;
using HD.SVR.***.DataAccess.DataServices;
using HD.SL.***.DataAccess.DataModels;
using HD.SVR.***.DataAccess.DataModels;

namespace HD.SL.***
{
    public partial class ***New : SecurityPage
    {
        protected static ***New currentObject;
        public static ***New GetInstance()
        {
            if (currentObject == null)
            {
                currentObject = new ***New();
                currentObject.OnDispose += (sender, e) =>
                {
                    currentObject = null;
                };
            }
            currentObject.InitialPage();
            return currentObject;
        }

        private DBContext ctx;
        private ValidationManager validMaster;
        private ***New()
        {
            ctx = new DBContext();
            InitializeComponent();
            validMaster = new ValidationManager();

            #region 设置验证
            validMaster.RegisterValidation<RsTransport>(p => p.TRANS_ID, new RequirementValidation());
            #endregion

            SmartTextBox txtTRANS_ID = TextBoxExtension.CreateSmartTextBoxWithBind<RsTransport>(p => p.TRANS_ID, StyleList.dataSmartTextBox, validMaster);
            SmartTextBox txtTRANS_NAME = TextBoxExtension.CreateSmartTextBoxWithBind<RsTransport>(p => p.TRANS_NAME, StyleList.dataSmartTextBox, validMaster);
            var comboUSE_FLAG = RadComboBoxExtension.CreateRadComboBoxWithSourceBind<RsTransport, SystemStatus>(t => t.USE_FLAG, s => s.StatusName,
                s => s.StatusID, StyleList.radComboBox, new SystemOption().GetYesOrNoOption, validMaster);
            RadNumericUpDown numberTRANS_SEQ = RadNumericUpDownExtension.CreateNumericUpDownWithBind<RsTransport>(p => p.TRANS_SEQ, StyleList.rdNumericUpDown, validMaster);
            gridLayout.AddField<RsTransport>(p => p.TRANS_ID, "", StyleList.dataNullable, txtTRANS_ID, "", 1, 1, validMaster);
            gridLayout.AddField<RsTransport>(p => p.TRANS_NAME, "", StyleList.dataNullable, txtTRANS_NAME, "", 1, 1, validMaster);
            gridLayout.AddField<RsTransport>(p => p.TRANS_SEQ, "", StyleList.dataNullable, numberTRANS_SEQ, "", 1, 1, validMaster);
            gridLayout.AddField<RsTransport>(p => p.USE_FLAG, "", StyleList.dataNullable, comboUSE_FLAG, "", 1, 1, validMaster);
            
            gridLayout.SetLayout(100, 200, 1);
        }

        private void InitialPage()
        {
            this.busyIndicator.IsBusy = false;
            this.gridLayout.ClearValError_ForAllChildCtrls();
            this.ctx.EntityContainer.Clear();
            this.gridLayout.DataContext = new RsTransport();
        }

        private async void btnCreate_Click(object sender, RoutedEventArgs e)
        {
            var currentItem = this.gridLayout.DataContext as RsTransport;
            if (!validMaster.ValidMasterItem(currentItem)) return;

            this.busyIndicator.BusyContent = "正在保存中...";
            this.busyIndicator.IsBusy = true;

            var checkOper = await ctx.CheckRsTransportByID(currentItem.TRANS_ID).AsTask();
            if (checkOper.Value)
            {
                MessageBox.Show("已存在该编号");
                this.busyIndicator.IsBusy = false;
                return;
            }
            var m_RS_TRANSPORT = new RS_TRANSPORT();
            DataExchange.CopyDataItem(currentItem, m_RS_TRANSPORT);
            DataExchange.SetCreationLog(m_RS_TRANSPORT);
            this.ctx.RS_TRANSPORTs.Add(m_RS_TRANSPORT);

            var operationSave = await ctx.SubmitChanges().AsTask();
            this.busyIndicator.IsBusy = false;
            if (!this.CheckLoadDataArgs(ExceptionManager.CheckDataContextResult(operationSave))) return;
            RadWindowExtension.CloseRadWindow(this, true);

        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            RadWindowExtension.CloseRadWindow(this, false);
        }

    }
}