/// <summary> /// 准备数据 /// </summary> /// <returns></returns> private ModelSYSTEM_ROLE PrepareModelSystemRole() { //创建操作类 ModelSYSTEM_ROLE model = new ModelSYSTEM_ROLE(); //编号 model.F_ROLE_ID = txtF_ROLE_ID.Text; //名称 model.F_ROLE_NAME = txtF_ROLE_NAME.Text; //描述 model.F_DESC = txtF_DESC.Text; //创建时间 DateTime optDateTime = DateTime.Now; model.F_CREATE_TIME = optDateTime; //操作员 model.F_OPERATOR_ID = AppGlobal.GUserId; //操作时间 model.F_OPERATIONTIME = optDateTime; //是否删除 model.F_DEL = 0; return(model); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { try { Log.Info(GetType() + "->" + ApplicationCommon.GetMethodName() + "---START"); //检查必填字段 bool isAllOk = CheckNotNullField(); if (!isAllOk) { return; } //准备要存储的数据 ModelSYSTEM_ROLE modelSystemRole = PrepareModelSystemRole(); //判断此数据是否已经存在 bool isDataExist = _bllSystemRole.Exists(modelSystemRole.F_ROLE_ID); if (isDataExist) { //已经存在判断是否更新 DialogResult dialogResult = XtraMessageBox.Show("当前数据已存在,是否更新?", "选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { return; } //更新数据 bool status = _bllSystemRole.Update(modelSystemRole); //获得当前rowhandle var rowhandle = gvList.FocusedRowHandle; //绑定数据 BindGridview(); //设置焦点行 gvList.FocusedRowHandle = rowhandle; if (status) { XtraMessageBox.Show("此数据已更新。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show("没有数据被更新,操作中断。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { _bllSystemRole.Add(modelSystemRole); //获得当前rowhandle var rowhandle = gvList.FocusedRowHandle; //绑定数据 BindGridview(); //设置焦点行 gvList.FocusedRowHandle = rowhandle + 1; XtraMessageBox.Show("此数据已增加。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { Log.Error(GetType() + "->" + ApplicationCommon.GetMethodName() + "---FAILED", ex); throw ex; } }