private void OnCreateChanage(object sender, EventArgs e) { PDAEntity newEntity = (PDAEntity)sender; bindingSource1.Add(newEntity); bindingSource1.ResetBindings(false); }
private bool Save() { if (!IsFieldValueValid()) { return(false); } bool success = false; try { PDAEntity editEntity = PrepareSave(); int ret = pdaDal.Save(editEntity, isNew); if (ret == -1) { MsgBox.Warn("编号已存在,请改为其他的编号。"); } else if (ret == -2) { MsgBox.Warn("更新失败,该行已经被其他人删除。"); } else { success = true; if (DataSourceChanged != null) { DataSourceChanged(editEntity, null); } } } catch (Exception ex) { MsgBox.Warn(ex.Message); } return(success); }
/// <summary> /// 检查编码是否已存在 /// </summary> /// <param name="dept"></param> /// <returns></returns> private bool IsCodeExists(PDAEntity entity) { IMapper map = DatabaseInstance.Instance(); string id = map.ExecuteScalar <string>("SELECT PDA_CODE FROM WM_PDA WHERE PDA_CODE = @COD", new { COD = entity.PDACode }); return(!string.IsNullOrEmpty(id)); }
private void ShowEditInfo(PDAEntity pdaEntity) { txtCode.Text = pdaEntity.PDACode; txtName.Text = pdaEntity.PDAName; cbWareHouse.EditValue = pdaEntity.WarehouseCode; txtIpAddress.Text = pdaEntity.IpAddress; comboBoxEdit1.Text = pdaEntity.IsActive; }
/// <summary> /// 编辑 /// </summary> private void ShowEditForm() { PDAEntity editEntity = SelectedRow; if (editEntity == null) { MsgBox.Warn("没有要修改的数据。"); return; } FrmPDAEdit frmEdit = new FrmPDAEdit(editEntity); frmEdit.DataSourceChanged += OnEditChanage; frmEdit.ShowDialog(); }
public PDAEntity PrepareSave() { PDAEntity editEntity = pdaEntity; if (editEntity == null) { editEntity = new PDAEntity(); } editEntity.PDACode = txtCode.Text.Trim(); editEntity.WarehouseCode = ConvertUtil.ToString(cbWareHouse.EditValue); editEntity.WarehouseName = cbWareHouse.Text; editEntity.PDAName = txtName.Text.Trim(); editEntity.IsActive = comboBoxEdit1.Text; editEntity.IpAddress = txtIpAddress.Text.Trim(); return(editEntity); }
public int Delete(PDAEntity removeEntity) { int result = 0; try { result = hhmDal.Delete(removeEntity.PDACode); if (result == 1) { RemoveRowFromGrid(removeEntity); } } catch (Exception ex) { MsgBox.Warn(ex.Message); } return(result); }
/// <summary> /// 添加或编辑 /// </summary> /// <param name="entity"></param> /// <param name="operatorFlag">添加或编辑</param> /// <returns></returns> public int Save(PDAEntity entity, bool isNew) { IMapper map = DatabaseInstance.Instance(); int ret = -2; if (isNew) { //检查编号是否已经存在 if (IsCodeExists(entity)) { return(-1); } ret = map.Execute("INSERT INTO WM_PDA(PDA_CODE, PDA_NAME, IP_ADDRESS, WH_CODE, IS_ACTIVE) " + "VALUES(@PDA_CODE, @PDA_NAME, @IP_ADDRESS, @WH_CODE, @IS_ACTIVE)", new { PDA_CODE = entity.PDACode, PDA_NAME = entity.PDAName, IP_ADDRESS = entity.IpAddress, WH_CODE = entity.WarehouseCode, IS_ACTIVE = entity.IsActive }); } else { //更新 ret = map.Execute("UPDATE WM_PDA SET PDA_NAME = @PDA_NAME, IP_ADDRESS = @IP_ADDRESS, WH_CODE = @WH_CODE, IS_ACTIVE = @IS_ACTIVE WHERE PDA_CODE = @PDA_CODE", new { PDA_NAME = entity.PDAName, IP_ADDRESS = entity.IpAddress, WH_CODE = entity.WarehouseCode, IS_ACTIVE = entity.IsActive, PDA_CODE = entity.PDACode }); } return(ret); }
/// <summary> /// 删除 /// </summary> private void DoDeleteSelected() { PDAEntity removeEntity = SelectedRow; if (removeEntity == null) { MsgBox.Warn("没有要删除的数据。"); return; } if (MsgBox.AskOK(string.Format("确定要删除编号为“{0}”的手持机吗?", removeEntity.PDACode)) == DialogResult.OK) { int ret = Delete(removeEntity); if (ret == 1) { ReLoad(); } else { MsgBox.Warn("删除失败。"); } } }
public void RemoveRowFromGrid(PDAEntity obj) { bindingSource1.Remove(obj); }
public FrmPDAEdit(PDAEntity pdaEntity) : this() { this.pdaEntity = pdaEntity; }