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);
}
}
}