using HStation.WinFrmUI.Dict.Core;
|
using Mapster;
|
|
namespace HStation.WinFrmUI.Dict
|
{
|
public partial class SetDictDataDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public SetDictDataDlg()
|
{
|
InitializeComponent();
|
this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
|
}
|
|
private long _typeId;
|
|
private Yw.BLL.SysDictData _bll;
|
private List<DictDataViewModel> _allBindingList;
|
|
public async void SetBindingData(long typeId)
|
{
|
_typeId = typeId;
|
_bll = new Yw.BLL.SysDictData();
|
var alllist = await _bll.GetByTypeID(typeId);
|
_allBindingList = new List<DictDataViewModel>();
|
if (alllist != null)
|
{
|
foreach (var item in alllist)
|
{
|
_allBindingList.Add(new DictDataViewModel(item));
|
}
|
}
|
this.dictDataViewModelBindingSource.DataSource = _allBindingList;
|
this.dictDataViewModelBindingSource.ResetBindings(false);
|
}
|
|
//完成
|
private async void BtnOk_Click(object sender, EventArgs e)
|
{
|
bool isfinish = false;
|
var AddSysPropChoices = new List<Yw.Vmo.SysDictDataVmo>();
|
foreach (var item in _allBindingList)
|
{
|
var choiceitem = item.Adapt<DictDataViewModel, Yw.Vmo.SysDictDataVmo>();
|
choiceitem.TypeID = _typeId;
|
AddSysPropChoices.Add(choiceitem);
|
}
|
if (AddSysPropChoices.Count <= 0)
|
{
|
if (await _bll.DeleteByTypeID(_typeId))
|
{
|
isfinish = true;
|
}
|
}
|
else
|
{
|
if (await _bll.GetByTypeID(_typeId) == null)
|
{
|
if (await _bll.Inserts(AddSysPropChoices))
|
{
|
isfinish = true;
|
}
|
}
|
else if ((await _bll.GetByTypeID(_typeId)).Count == 0)
|
{
|
if (await _bll.Inserts(AddSysPropChoices))
|
{
|
isfinish = true;
|
}
|
}
|
else
|
{
|
if (await _bll.DeleteByTypeID(_typeId))
|
{
|
if (await _bll.Inserts(AddSysPropChoices))
|
{
|
isfinish = true;
|
}
|
}
|
}
|
}
|
if (isfinish)
|
{
|
TipFormHelper.ShowSucceed("设置成功!");
|
}
|
else
|
{
|
TipFormHelper.ShowError("设置失败!");
|
}
|
this.DialogResult = DialogResult.OK;
|
this.Close();
|
}
|
|
//删除
|
private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
|
{
|
if (_allBindingList == null || _allBindingList.Count < 1)
|
return;
|
var row = this.gridView1.GetCurrentViewModel(_allBindingList);
|
if (row == null)
|
return;
|
if (e.Column == this.ColDelete)
|
_allBindingList.Remove(row);
|
this.dictDataViewModelBindingSource.ResetBindings(false);
|
}
|
}
|
}
|