using HStation.WinFrmUI.Xhs.PumpProduct;
|
|
namespace HStation.WinFrmUI
|
{
|
public partial class EditPumpPartPropDlg : DevExpress.XtraEditors.XtraForm
|
{
|
public EditPumpPartPropDlg()
|
{
|
InitializeComponent();
|
this.gridView1.Columns["PropGroupName"].Group();
|
}
|
|
private BLL.PumpPartMain _bll = null;
|
private List<PropGroupChoiceViewModel> _proplist = null;
|
|
private List<CurrentPartMainViewModel> _allBindingList = new List<CurrentPartMainViewModel>();
|
|
private Vmo.PumpMainAndPartMap _partmap = null;
|
|
private Vmo.PumpPartMain _pumpPart = null;
|
|
private long _catalogID; //分类ID
|
|
private long _seriesID; //系列ID
|
|
private List<Vmo.PumpPropContent> _allPropList = null;
|
|
//回调事件
|
public event Func<Vmo.PumpPartMain, List<Vmo.PumpPropContent>, Vmo.PumpMainAndPartMap, Task<bool>> ReloadEvent;
|
|
//数据绑定
|
public async void SetBindingData(Vmo.PumpMain pumpMain)
|
{
|
this.pumpProductListBox1.SetBindingData(pumpMain);
|
this.pumpProductListBox1.SelectReloadEvent += () =>
|
{
|
ListBoxPart_SelectedIndexChanged();
|
};
|
this.pumpProductListBox1.AddReloadEvent += () =>
|
{
|
BarBtnAddPumpPart_ItemClick();
|
};
|
_bll = new BLL.PumpPartMain();
|
var allpartlist = await _bll.GetByPumpMainID(pumpMain.ID); //获取所有产品
|
var series = await new BLL.PumpSeries().GetByID(pumpMain.PumpSeriesID); //获取系列
|
_pumpPart = new Vmo.PumpPartMain();
|
_seriesID = series.ID;
|
_pumpPart.SeriesID = _seriesID;
|
_catalogID = series.CatalogID;
|
_proplist = new List<PropGroupChoiceViewModel>();
|
_partmap = new Vmo.PumpMainAndPartMap();
|
_partmap.PumpID = pumpMain.ID;
|
_partmap.SeriesID = _seriesID;
|
|
// this.ListBoxPart.DataSource = _allBindingList;
|
// this.ListBoxPart.Refresh();
|
this.propGroupChoiceViewModelBindingSource.DataSource = _proplist;
|
this.propGroupChoiceViewModelBindingSource.ResetBindings(false);
|
}
|
|
//分类选择变换
|
private async void SetPropSelectedValue(CurrentPartMainViewModel partmain)
|
{
|
layoutControAddPart.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
|
var model = await _bll.GetByID(partmain.ID);
|
if (model == null) return;
|
this.TextEditNo.Text = partmain.NO.Trim();
|
this.TextEditProductCode.Text = partmain.Code.Trim();
|
this.TextEditProductName.Text = partmain.Name.Trim();
|
_proplist.Clear();
|
var bll = new Yw.BLL.SysPropStruct();
|
var catlog = await bll.GetByCatalogID(_catalogID);
|
if (catlog == null)
|
{
|
this.propGroupChoiceViewModelBindingSource.ResetBindings(false);
|
return;
|
}
|
_proplist.Clear();
|
foreach (var item in catlog)
|
{
|
foreach (var prop in item.PropList)
|
{
|
_proplist.Add(new PropGroupChoiceViewModel() { PropGroupName = item.Name, PropName = prop.Name, ID = prop.ID });
|
}
|
}
|
var propbll = new BLL.PumpPartPropContent();
|
var alllist = await propbll.GetByPumpPartID(model.ID);
|
_allPropList = alllist;
|
foreach (var item in alllist)
|
{
|
_proplist.Find(x => x.ID == item.PropID).Value = item.PropValue;
|
}
|
this.propGroupChoiceViewModelBindingSource.ResetBindings(false);
|
this.gridView1.ExpandAllGroups();
|
}
|
|
//产品列表聚焦改变
|
private void ListBoxPart_SelectedIndexChanged()
|
{
|
var vm = this.pumpProductListBox1.GetCurrentVm();
|
if (vm == null)
|
return;
|
SetPropSelectedValue(vm);
|
}
|
|
//确认编辑
|
private async void BtnOk_Click(object sender, EventArgs e)
|
{
|
var vm = this.pumpProductListBox1.GetCurrentVm();
|
if (vm == null)
|
return;
|
var updatepart = new Vmo.PumpPartMain();
|
updatepart.ID = vm.ID;
|
updatepart.Name = TextEditProductName.Text;
|
updatepart.NO = TextEditNo.Text;
|
updatepart.Code = TextEditProductCode.Text;
|
updatepart.SeriesID = _seriesID;
|
var updateproplist = new List<UpdatePumpPropContentDto>();
|
// var update = _allPropList.Select(x => x.Adapt<PumpPropContentDto, UpdatePumpPropContentDto>()).ToList();
|
foreach (var item in _proplist)
|
{
|
_allPropList.Find(x => x.PropID == item.ID).PropValue = item.Value;
|
}
|
if (await _bll.UpdateEx(updatepart, _allPropList))
|
{
|
vm.Reset(updatepart);
|
this.pumpProductListBox1.Refresh();
|
MessageBoxHelper.ShowSuccess("修改成功!");
|
}
|
else
|
{
|
MessageBoxHelper.ShowError("修改失败!");
|
}
|
}
|
|
//左侧树右击菜单事件
|
private void ListBoxPart_MouseUp(object sender, MouseEventArgs e)
|
{
|
if (e.Button == MouseButtons.Right)
|
{
|
Point screenPoint = Cursor.Position;
|
popupPumpPartMenu.ShowPopup(screenPoint);
|
}
|
}
|
|
//添加产品
|
private async void BtnAddPumpPart_Click(object sender, EventArgs e)
|
{
|
_pumpPart.Name = TextEditProductName.Text;
|
_pumpPart.NO = TextEditNo.Text;
|
_pumpPart.Code = TextEditProductCode.Text;
|
var PumpPropContent = new List<Vmo.PumpPropContent>();
|
foreach (var item in _proplist)
|
{
|
PumpPropContent.Add(new Vmo.PumpPropContent { PropID = item.ID, PropValue = item.Value, SeriesID = _pumpPart.SeriesID, MainID = _partmap.PumpID });
|
}
|
var id = await _bll.InsertEx(_pumpPart, PumpPropContent, _partmap);
|
if (id > 0)
|
{
|
var pumppart = await _bll.GetByID(id);
|
this.pumpProductListBox1._allBindingList.Add(new CurrentPartMainViewModel(pumppart));
|
this.pumpProductListBox1.Refresh();
|
MessageBoxHelper.ShowSuccess("添加成功!");
|
}
|
else
|
{
|
MessageBoxHelper.ShowError("添加失败!");
|
}
|
}
|
|
#region 菜单功能
|
|
//添加产品
|
private async void BarBtnAddPumpPart_ItemClick()
|
{
|
layoutControAddPart.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
|
TextEditProductName.Text = string.Empty;
|
TextEditNo.Text = string.Empty;
|
TextEditProductCode.Text = string.Empty;
|
var bll = new Yw.BLL.SysPropStruct();
|
try
|
{
|
var catlog = await bll.GetByCatalogID(_catalogID);
|
if (catlog == null)
|
{
|
this.propGroupChoiceViewModelBindingSource.ResetBindings(false);
|
return;
|
}
|
_proplist.Clear();
|
foreach (var item in catlog)
|
{
|
foreach (var prop in item.PropList)
|
{
|
_proplist.Add(new PropGroupChoiceViewModel() { PropGroupName = item.Name, PropName = prop.Name, ID = prop.ID, Value = prop.DefaultValue });
|
}
|
}
|
this.propGroupChoiceViewModelBindingSource.ResetBindings(false);
|
}
|
catch
|
{
|
}
|
this.TextEditProductName.Properties.NullText = "在此输入产品名称";
|
// 尝试改变焦点以触发控件更新
|
this.TextEditProductName.Focus();
|
// this.TextEditProductName.SelectAll();
|
|
this.TextEditNo.Properties.NullText = "在此输入产品编号";
|
this.TextEditProductCode.Properties.NullText = "在此输入产品图号";
|
}
|
|
// 删除产品
|
private async void BarBtnDeletePart_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
|
{
|
var vm = this.pumpProductListBox1.GetCurrentVm();
|
if (vm == null)
|
return;
|
if (!MessageBoxHelper.IsClickOk("确定删除数据行"))
|
{
|
if (await _bll.DeleteEx(vm.ID))
|
{
|
this.pumpProductListBox1._allBindingList.Remove(vm);
|
this.pumpProductListBox1.Refresh();
|
MessageBoxHelper.ShowSuccess("删除成功!");
|
}
|
else
|
{
|
MessageBoxHelper.ShowError("删除失败!");
|
}
|
}
|
}
|
|
#endregion 菜单功能
|
}
|
}
|