/// <summary> /// 添加或编辑 /// </summary> /// <param name="entity"></param> /// <param name="operatorFlag">添加或编辑</param> /// <returns></returns> public int Save(BusReasonEntity entity, bool isNew) { IMapper map = DatabaseInstance.Instance(); int ret = -2; if (isNew) { //检查编号是否已经存在 if (IsCodeExists(entity)) { return(-1); } ret = map.Execute("INSERT INTO WM_BUG_REASON(BUG_CODE, BUG_NAME) VALUES(@BUG_CODE, @BUG_NAME)", new { BUG_CODE = entity.BugCode, BUG_NAME = entity.BugName }); } else { //更新 ret = map.Execute("UPDATE WM_BUG_REASON SET BUG_NAME = @BUG_NAME WHERE BUG_CODE = @BUG_CODE", new { BUG_CODE = entity.BugCode, BUG_NAME = entity.BugName }); } return(ret); }
private void OnCreateChanage(object sender, EventArgs e) { BusReasonEntity newEntity = (BusReasonEntity)sender; bindingSource1.Add(newEntity); bindingSource1.ResetBindings(false); }
/// <summary> /// 检查编码是否已存在 /// </summary> /// <param name="dept"></param> /// <returns></returns> private bool IsCodeExists(BusReasonEntity entity) { IMapper map = DatabaseInstance.Instance(); string id = map.ExecuteScalar <string>("SELECT BUG_CODE FROM WM_BUG_REASON WHERE BUG_CODE = @BUG_CODE", new { BUG_CODE = entity.BugCode }); return(!string.IsNullOrEmpty(id)); }
///<summary> ///基础管理(不合格原因-查询所有不合格原因) ///</summary> ///<returns></returns> public List <BusReasonEntity> GetAllNotHeGe() { List <BusReasonEntity> list = new List <BusReasonEntity>(); try { #region 请求数据 System.Text.StringBuilder loStr = new System.Text.StringBuilder(); //loStr.Append("roleId=").Append(roleId); string jsonQuery = WebWork.SendRequest(string.Empty, WebWork.URL_GetAllNotHeGe); if (string.IsNullOrEmpty(jsonQuery)) { MsgBox.Warn(WebWork.RESULT_NULL); //LogHelper.InfoLog(WebWork.RESULT_NULL); return(list); } #endregion #region 正常错误处理 JsonGetAllNotHeGe bill = JsonConvert.DeserializeObject <JsonGetAllNotHeGe>(jsonQuery); if (bill == null) { MsgBox.Warn(WebWork.JSON_DATA_NULL); return(list); } if (bill.flag != 0) { MsgBox.Warn(bill.error); return(list); } #endregion #region 赋值数据 foreach (JsonGetAllNotHeGeResult jbr in bill.result) { BusReasonEntity asnEntity = new BusReasonEntity(); #region asnEntity.BugCode = jbr.bugCode; asnEntity.BugName = jbr.bugName; #endregion list.Add(asnEntity); } return(list); #endregion } catch (Exception ex) { MsgBox.Err(ex.Message); } return(list); }
public BusReasonEntity PrepareSave() { BusReasonEntity editEntity = bugEntity; if (editEntity == null) { editEntity = new BusReasonEntity(); } editEntity.BugCode = txtCode.Text.Trim(); editEntity.BugName = txtName.Text.Trim(); return(editEntity); }
/// <summary> /// 编辑 /// </summary> private void ShowEditForm() { BusReasonEntity editEntity = SelectedRow; if (editEntity == null) { MsgBox.Warn("没有要修改的数据。"); return; } FrmBugReasonEdit frmEdit = new FrmBugReasonEdit(editEntity); frmEdit.DataSourceChanged += OnEditChanage; frmEdit.ShowDialog(); }
public bool DoDelete(BusReasonEntity removeEntity) { bool result = false; try { result = DeleteUnit(removeEntity.BugCode); if (result) { RemoveRowFromGrid(removeEntity); } } catch (Exception ex) { MsgBox.Warn(ex.Message); } return(result); }
/// <summary> /// 添加或编辑 /// </summary> /// <param name="entity"></param> /// <param name="operatorFlag">添加或编辑</param> /// <returns></returns> public bool SaveAddBugReason(BusReasonEntity entity, bool isNew) { try { #region 请求数据 System.Text.StringBuilder loStr = new System.Text.StringBuilder(); loStr.Append("bugCode=").Append(entity.BugCode).Append("&"); loStr.Append("bugName=").Append(entity.BugName); string jsonQuery = WebWork.SendRequest(loStr.ToString(), WebWork.URL_SaveAddBugReason); if (string.IsNullOrEmpty(jsonQuery)) { MsgBox.Warn(WebWork.RESULT_NULL); //LogHelper.InfoLog(WebWork.RESULT_NULL); return(false); } #endregion #region 正常错误处理 Sucess bill = JsonConvert.DeserializeObject <Sucess>(jsonQuery); if (bill == null) { MsgBox.Warn(WebWork.JSON_DATA_NULL); return(false); } if (bill.flag != 0) { MsgBox.Warn(bill.error); return(false); } #endregion return(true); } catch (Exception ex) { MsgBox.Err(ex.Message); } return(false); }
private bool Save() { if (!IsFieldValueValid()) { return(false); } bool success = false; try { BusReasonEntity editEntity = PrepareSave(); //int ret = bugDal.Save(editEntity, isNew); //if (ret == -1) // MsgBox.Warn("编号已存在,请改为其他的编号。"); //else if (ret == -2) // MsgBox.Warn("更新失败,该行已经被其他人删除。"); //else bool ret; if (isNew) { ret = SaveAddBugReason(editEntity, isNew); } else { ret = SaveUpdateBugReason(editEntity, isNew); } if (ret) { success = true; if (DataSourceChanged != null) { DataSourceChanged(editEntity, null); } } } catch (Exception ex) { MsgBox.Warn(ex.Message); } return(success); }
/// <summary> /// 删除 /// </summary> private void DoDeleteSelected() { BusReasonEntity removeEntity = SelectedRow; if (removeEntity == null) { MsgBox.Warn("没有要删除的数据。"); return; } if (MsgBox.AskOK(string.Format("确定要删除“({0}){1}”吗?", removeEntity.BugCode, removeEntity.BugName)) == DialogResult.OK) { bool ret = DoDelete(removeEntity); if (ret) { ReLoad(); } //else // MsgBox.Warn("删除失败。"); } }
public void RemoveRowFromGrid(BusReasonEntity obj) { bindingSource1.Remove(obj); }
private void ShowEditInfo(BusReasonEntity bugEntity) { txtCode.Text = bugEntity.BugCode; txtName.Text = bugEntity.BugName; }
public FrmBugReasonEdit(BusReasonEntity bugEntity) : this() { this.bugEntity = bugEntity; }