Form - 车辆管理窗体C#源码
表格编辑窗体特点
- 针对单表资料管理与维护
- 支持在表格内增、删、改记录操作
- 支持表格编辑数据,批量修改数据,一次性保存数据
窗体预览
修改完成,保存数据
Form - 车辆管理窗体C#源码
C# 全选
using CartonERP.Business;
using CartonERP.Common;
using CartonERP.Library;
using CartonERP.Library.CommonClass;
using CartonERP.Library.Extensions;
using CartonERP.Library.GridDataWatcher;
using CartonERP.Models;
using CSFrameworkV6.Core;
using CSFrameworkV6.Core.Extensions;
using DevExpress.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
/*===================================================================
* 程序说明: Car - 基础资料窗体
* 创建日期: 2023/04/25
* 最后修改: 2023/04/25
* 作者资料: CSFramework
* 版权所有 Copyright 2006~2023, C/S框架网 (www.csframework.com)
* ----------------------------------------------------------------
* 修改记录:
* 2023/04/25: 自动生成代码
* 2023/04/25: 您的修改记录
*===================================================================*/
namespace CartonERP.DataDictionary
{
///<summary>
/// Unit的资料管理窗体,由代码生成器(Code Generator)自动生成
/// </summary>
public partial class frm_Car : frmBaseDataDictionary
{
private bll_Car _BLL; //业务逻辑层
IGridDataWatcher<dt_Car> _Watcher; //表格数据监视器
public frm_Car()
{
InitializeComponent();
}
private void frm_Car_Load(object sender, EventArgs e)
{
this.InitializeForm();//自定义初始化操作
}
protected override void InitializeForm()
{
_SummaryView = new DevGridView(gvSummary);//实例化主表表格数据视图,框架支持多种视图,比如表格GridControl,树视图TreeList.
_DetailGroupControl = pcDetailEditor;//【资料编辑】页面的输入框的容器组件
_BLL = new bll_Car(); //实例化基类的业务逻辑层
_Watcher = new DevExpressGridViewWatcher<dt_Car>(gvSummary, w => w.isid);
//控制表格单元格是否可编辑
new DevGridEditable<dt_Car>(_Watcher)
.HandleKeyFields(nameof(dt_Car.isid), nameof(dt_Car.CarNo))
.HandleEvents(gvSummary);
DevStyle.SetGridControlLayout(gcSummary, false, false, false, false);//表格设置
DevStyle.SetSummaryGridViewLayout(gvSummary, true, true);
base.InitializeForm();
this.BoundLookupData();
//隐藏分页标签
tcBusiness.SelectedTabPage = tpSummary;
tcBusiness.ShowTabHeader = DefaultBoolean.False;
}
public override void BoundLookupData()
{
DataBinderTools.BoundUser(lucCreatedBy);
DataBinderTools.BoundUser(lucLastUpdatedBy);
DataBinderTools.BoundCheckEdit(txtDefWidthUnit);
DataBinderTools.BoundCheckEdit(txtDefNewMaterialUnit);
DataBinderTools.BoundCheckEdit(txtDefLengthUnit);
DataBinderTools.BoundCheckEdit(txtDefDimeUnit);
DataBinderTools.BoundCheckEdit(txtDefCartonDimeUnit);
DataBinderTools.BoundCheckEdit(repositoryItemCheckEdit1);
}
/// <summary>
/// 初始化界面按钮
/// </summary>
public override void InitButtons()
{
base.InitButtons();
_buttons.RemoveButton(ButtonNameList.btnView); //隐藏 btnView 查看 按钮
}
private void DoAddRow()
{
var newData = new dt_Car
{
CreatedBy = Loginer.CurrentUser.Account,
CreationDate = DateTime.Now,
LastUpdatedBy = Loginer.CurrentUser.Account,
LastUpdateDate = DateTime.Now,
};
gvSummary.AddRow(newData);
gcSummary.RefreshDataSource();
gvSummary.FocusedRowHandle = gvSummary.GetRowHandle(gvSummary.RowCount - 1); //定位最后一行
gvSummary.FocusedColumn = colCarNo; //定位到第1个可编辑列
_Watcher.SetAdded(newData); //重要:通知观察者设置为新增状态
}
protected override void ShowSummary()
{
gcSummary.DataSource = _BLL.GetSummaryData();
}
/// <summary>
/// 绑定修改页面所有文本框的数据源
/// </summary>
/// <param name="summary">数据源</param>
protected override void DoBindingSummaryEditor(object summary)
{
//
}
/// <summary>
/// 新增记录, btnAdd按钮事件
/// </summary>
public override void DoAdd(IButtonInfo sender)
{
//设置表格为可编辑
gvSummary.OptionsBehavior.Editable = true;
this._UpdateType = UpdateType.Add;
this.SetEditMode();
this.ButtonStateChanged(_UpdateType);
this._buttons.GetButtonByName(ButtonNameList.btnAdd).Enable = true;//允许连续新增
this._buttons.GetButtonByName(ButtonNameList.btnDelete).Enable = true;//允许连续删除
this.DoAddRow();
}
/// <summary>
/// 删除记录, btnDelete按钮事件
/// </summary>
public override void DoDelete(IButtonInfo sender)
{
AssertFocusedRow();
if (Msg.AskQuestion("确定要删除这条记录?"))
{
var obj = gvSummary.GetObject<dt_Car>();
if (this.IsViewMode)//直接从数据库删除
{
var ok = _BLL.Delete(obj.isid);
AssertEqual(ok, true, "删除失败!");
btnQuery.PerformClick();//刷新数据
}
else
{
gvSummary.DeleteRow(gvSummary.FocusedRowHandle);
}
}
}
/// <summary>
/// 修改资料,btnEdit按钮事件
/// </summary>
public override void DoEdit(IButtonInfo sender)
{
//设置表格为可编辑
gvSummary.OptionsBehavior.Editable = true;
this._UpdateType = UpdateType.Modify;
this.SetEditMode();
this.ButtonStateChanged(_UpdateType);
this._buttons.GetButtonByName(ButtonNameList.btnAdd).Enable = true;//允许连续新增
this._buttons.GetButtonByName(ButtonNameList.btnDelete).Enable = true;//允许连续删除
}
public override void DoViewContent(IButtonInfo sender)
{
//表格编辑记录,不支持查看详情
}
public override void DoCancel(IButtonInfo sender)
{
if (Msg.AskQuestion("要取消修改吗?"))
{
gvSummary.OptionsBehavior.Editable = false;//保存成功,表格不可编辑
this.SetViewMode();
this.ButtonStateChanged(_UpdateType);
btnQuery.PerformClick();//刷新数据
}
}
/// <summary>
/// 保存资料,btnSave按钮事件
/// </summary>
public override void DoSave(IButtonInfo sender)
{
this.UpdateLastControl();
if (_SummaryView.RowCount == 0)
{
Msg.Warning("没有数据!");
}
else
{
if (!ValidatingData()) return;
try
{
frmWaitingEx.ShowMe(this);
List<dt_Car> dt = _SummaryView.DataSource as List<dt_Car>;
var changes = _Watcher.GetChanges();
if (changes != null && changes.Count > 0)
{
var ok = _BLL.Update(changes);//保存
if (ok)
{
this.SetViewMode();
this.NotifyDataDictChanged<dt_Car>();
gvSummary.OptionsBehavior.Editable = false;//保存成功,表格不可编辑
btnQuery.PerformClick();//刷新数据
}
}
else
{
Msg.Warning("您没有修改数据!");
}
}
finally
{
frmWaitingEx.HideMe(this);
}
}
}
/// <summary>
/// 按钮状态改变时触发的事件
/// </summary>
/// <param name="currentState">当前操作状态</param>
protected override void ButtonStateChanged(UpdateType currentState)
{
//
}
private void btnEmpty_Click(object sender, EventArgs e)
{
base.ClearContainerEditorText(pnlSearch);
}
private void btnQuery_Click(object sender, EventArgs e)
{
var input = new req_Car
{
CarNo = txt_Car.EditValue.ToStringEx(),
};
var data = _BLL.Query(input);
this.DoBindingSummaryGrid(data); //绑定主表表格数据源
_Watcher.Reset(data);//重置数据
}
//保存前检查数据完整性
protected override bool ValidatingData()
{
var list = gvSummary.GetDataSource<dt_Car>();
var isDuplicated = list.Where(w => !w.CarNo.IsEmpty()).GroupBy(g => g.CarNo).IsDuplicated();
if (isDuplicated)
{
Msg.Warning("车牌号重复!");
return false;
}
var isNull = list.Any(w => w.CarNo.IsEmpty());
if (isNull)
{
Msg.Warning("车牌号不能为空!");
return false;
}
return true;
}
public override void DoShowLog(IButtonInfo button)
{
//显示审计日志
this.MainForm.OpenModuleForm(Globals.LogViewerForm, "", nameof(dt_Car));
}
}
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
CSFrameworkV6 C/S框架网