/// <summary> /// 按钮启用自动校验(EnableAutoValidate属性为True)后事件处理程序,根据校验结果看是否更新数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOK_AfterAutoValidate(object sender, AutoValidateResultEventArgs e) { //如果校验通过 if (e.Result) { //绑定界面数据&设置标题 switch (this.formState) { case FormState.Edit: try { //收集数据 this.CollectData(); //更新 this.customerService.Update(this.basicRow); MsgBoxUtility.ShowTips("修改成功!"); //执行更新成功事件 if (this.UpdateSucceed != null) { this.UpdateSucceed(this, new TEventArgs <CustomerDataSet.BasicInfoRow>(this.basicRow)); } } catch (Exception ex) { MsgBoxUtility.ShowError("修改失败:" + ex.Message); } break; case FormState.Add: try { //收集数据 this.CollectData(); //新增 this.customerService.Add(this.basicRow); MsgBoxUtility.ShowTips("新增成功!"); //执行添加成功事件 if (this.AddSucceed != null) { this.AddSucceed(this, new TEventArgs <CustomerDataSet.BasicInfoRow>(this.basicRow)); } } catch (Exception ex) { MsgBoxUtility.ShowError("新增失败:" + ex.Message); } break; default: break; } } }
/// <summary> /// 打开查看窗体 /// </summary> private void OpenViewForm() { CustomerDataSet.BasicInfoRow basicRow = GetSelectedRow(); if (basicRow == null) { MsgBoxUtility.ShowError("请选择一条记录!"); return; } DemoCustomerDetailForm frm = new DemoCustomerDetailForm(FormState.View, basicRow, null); frm.ShowDialog(); }
/// <summary> /// 查询客户信息操作然后绑定客户信息 /// </summary> private void QueryAndBindGrid() { try { //先置分页数据源为空 this.hsPager1.TargetDataSource = null; //重新查询 this.hsPager1.TargetDataSource = this.CustomerService.GetCustomers(this.hsLabelTextBox1.Value, this.hsLabelTextBox2.Value, this.hsLabelComboBox1.Value, this.hsLabelTextBox3.Value); } catch (Exception ex) { MsgBoxUtility.ShowError(ex.Message); } }
/// <summary> /// 校验窗体输入参数 /// </summary> private bool ValidateParams() { if (basicRow == null && (this.formState == FormState.View || this.formState == FormState.Edit)) { MsgBoxUtility.ShowError("请指定客户信息!"); return(false); } if (customerService == null && (this.formState == FormState.Add || this.formState == FormState.Edit)) { MsgBoxUtility.ShowError("请指定客户信息服务接口!"); return(false); } return(true); }
/// <summary> /// 编辑按钮单击 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolBtnEdit_Click(object sender, EventArgs e) { CustomerDataSet.BasicInfoRow basicRow = GetSelectedRow(); if (basicRow == null) { MsgBoxUtility.ShowError("请选择一条记录!"); return; } DemoCustomerDetailForm frm = new DemoCustomerDetailForm(FormState.Edit, basicRow, this.CustomerService); //绑定窗体更新成功事件 frm.UpdateSucceed += (obj, args) => { // 记住分页信息的查询客户信息操作然后绑定客户信息 this.RemeberPagerQueryAndBind(); }; frm.ShowDialog(); }
/// <summary> /// 删除按钮单击 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolBtnDelete_Click(object sender, EventArgs e) { CustomerDataSet.BasicInfoRow basicRow = GetSelectedRow(); if (basicRow == null) { MsgBoxUtility.ShowError("请选择一条记录!"); return; } try { this.CustomerService.Delete(basicRow.CustomerID); // 记住分页信息的查询客户信息操作然后绑定客户信息 this.RemeberPagerQueryAndBind(); } catch (Exception ex) { MsgBoxUtility.ShowTips(ex.Message); } }