CSFrameworkV6旗舰版 - 单表基础资料窗体完整C#源码
设备管理窗体
数据查询
数据编辑
UI Form - 单表基础资料标准窗体
C# 全选
using CartonERP.Business;
using CartonERP.Common;
using CartonERP.Library;
using CartonERP.Library.CommonClass;
using CartonERP.Models;
using CSFrameworkV6.Core;
using CSFrameworkV6.Core.Extensions;
using System;
/*===================================================================
* 程序说明: Machine - 基础资料窗体
* 创建日期: 2023/08/18
* 最后修改: 2023/08/18
* 作者资料: CSFramework
* 版权所有 Copyright 2006~2023, C/S框架网 (www.csframework.com)
* ----------------------------------------------------------------
* 修改记录:
* 2023/08/18: 自动生成代码
* 2023/08/18: 您的修改记录
*===================================================================*/
namespace CartonERP.DataDictionary
{
///<summary>
/// Machine的资料管理窗体,由代码生成器(Code Generator)自动生成
/// </summary>
public partial class frm_Machine : frmBaseDataDictionary
{
private bll_Machine _BLL;
public frm_Machine()
{
InitializeComponent();
}
private void frm_Machine_Load(object sender, EventArgs e)
{
this.InitializeForm();//自定义初始化操作
}
protected override void InitializeForm()
{
_SummaryView = new DevGridView(gvSummary);//实例化主表表格数据视图,框架支持多种视图,比如表格GridControl,树视图TreeList.
_DetailGroupControl = pcDetailEditor;//【资料编辑】页面的输入框的容器组件
_BLL = new bll_Machine(); //实例化基类的业务逻辑层
base.InitializeForm();
this.BoundLookupData();
}
public override void BoundLookupData()
{
DataBinderTools.BoundUser(lucLastUpdatedBy);
DataBinderTools.BoundUser(lucCreatedBy);
DataBinderTools.BoundUser(txtCreatedBy.Properties);
DataBinderTools.BoundUser(txtLastUpdatedBy.Properties);
}
/// <summary>
/// 初始化界面按钮
/// </summary>
public override void InitButtons()
{
base.InitButtons();
_buttons.RemoveButton(ButtonNameList.btnRefreshDataDict);
}
protected override void ShowSummary()
{
//有查询条件:打开窗体时不显示数据
//打开窗体默认加载100条数据(DAL层控制记录数)
//gcSummary.DataSource = _BLL.GetSummaryData();
}
/// <summary>
/// 绑定修改页面所有文本框的数据源
/// </summary>
/// <param name="summary">数据源</param>
protected override void DoBindingSummaryEditor(object summary)
{
this.DoBindingEditorPanel(pcDetailEditor, summary);
}
/// <summary>
/// 新增记录, btnAdd按钮事件
/// </summary>
public override void DoAdd(IButtonInfo sender)
{
try
{
frmWaitingEx.ShowMe(this);
_BLL.CreateDataBinder(null);//实例化业务逻辑层_DataBinder成员变量
this.DoBindingSummaryEditor(_BLL.DataBinder); //绑定数据编辑页所有文本框的数据源
this._UpdateType = UpdateType.Add;//设置为新增模式
this.SetEditMode();//设置为编辑模式(Add或Modify模式),控制按钮显示/禁用状态
this.ButtonStateChanged(_UpdateType);//通知按钮状态事件
this.ShowDetailPage(true);
}
finally
{
frmWaitingEx.HideMe(this);
}
}
/// <summary>
/// 删除记录, btnDelete按钮事件
/// </summary>
public override void DoDelete(IButtonInfo sender)
{
AssertFocusedRow();
if (!Msg.AskQuestion("确定要删除吗?")) return;
try
{
frmWaitingEx.ShowMe(this);
var row = _SummaryView.GetFocusedRow() as dt_Machine;//获取表格中当前记录
var result = _BLL.Delete(row.isid);//调用BLL层删除接口,删除逻辑校验可放到DAL层
AssertEqual(result, true, "删除记录时发生错误!");
this.DeleteSummaryRow(_SummaryView.FocusedRowHandle);//删除表格中当前记录
if (_SummaryView.FocusedRowHandle < 0) //删除了表格最后一条记录,要显示查询页.
{
ShowSummaryPage(true);
}
else
{
_BLL.CreateDataBinder(_SummaryView.GetFocusedRow() as dt_Machine);
DoBindingSummaryEditor(_BLL.DataBinder);//绑定数据源
}
}
finally
{
frmWaitingEx.HideMe(this);
}
}
/// <summary>
/// 修改资料,btnEdit按钮事件
/// </summary>
public override void DoEdit(IButtonInfo sender)
{
//
//逻辑判断:是否可修改当前资料
//
//调用基类方法,修改事件代码逻辑可复用
base.DoEdit(sender);
}
/// <summary>
/// 查看资料,btnViewContent按钮事件。显示当前记录的详细资料
/// </summary>
public override void DoViewContent(IButtonInfo sender)
{
AssertFocusedRow();//检查是否选择一条记录.
try
{
frmWaitingEx.ShowMe(this);
_BLL.CreateDataBinder(_SummaryView.GetObject<dt_Machine>());
this.DoBindingSummaryEditor(_BLL.DataBinder);
this.ButtonStateChanged(_UpdateType);
this.ShowDetailPage(false);
}
finally
{
frmWaitingEx.HideMe(this);
}
}
/// <summary>
/// 保存资料,btnSave按钮事件
/// </summary>
public override void DoSave(IButtonInfo sender)
{
try
{
frmWaitingEx.ShowMe(this);
this.UpdateLastControl(); //更新最后一个输入控件的数据源
if (!ValidatingData()) return; //检查资料完整性
bool result = _BLL.Update(_UpdateType);//调用业务逻辑层接口保存数据
if (result)
{
var dt = _BLL.GetDataByKey(_BLL.DataBinder.isid);//获取最新数据
this.UpdateSummaryRow(dt); //刷新表格当前记录
this.DoSave_ResetState();//保存成功后要设置各种状态,调用基类通用逻辑
this.NotifyDataDictChanged<dt_Machine>();
}
else
{
Msg.Warning("保存失败!");
}
}
finally
{
frmWaitingEx.HideMe(this);
}
}
/// <summary>
/// 按钮状态改变时触发的事件
/// </summary>
/// <param name="currentState">当前操作状态</param>
protected override void ButtonStateChanged(UpdateType currentState)
{
base.ButtonStateChanged(currentState);
txtCreatedBy.Properties.ReadOnly = true;//禁止修改
txtCreationDate.Properties.ReadOnly = true;//禁止修改
txtLastUpdateDate.Properties.ReadOnly = true;//禁止修改
txtLastUpdatedBy.Properties.ReadOnly = true;//禁止修改
}
private void btnEmpty_Click(object sender, EventArgs e)
{
base.ClearContainerEditorText(pnlSearch);
}
private void btnQuery_Click(object sender, EventArgs e)
{
//搜索数据
try
{
frmWaitingEx.ShowMe(this);
var input = new req_Machine
{
MachineName = txt_MachineName.EditValue.ToStringEx(),
Model = txt_Model.EditValue.ToStringEx(),
};
var data = _BLL.Query(input);
this.DoBindingSummaryGrid(data); //绑定主表表格数据源
this.ShowSummaryPage(true);
}
finally
{
frmWaitingEx.HideMe(this);
}
}
//保存前检查数据完整性
protected override bool ValidatingData()
{
//多个输入项检查。若检查不通过,文本框右侧显示红色X图标
var isInvalid = false
| CommonTools.IsInvalid(txtMachineName)
| CommonTools.IsInvalid(txtInstallDate)
| CommonTools.IsInvalid(txtModel);
if (isInvalid) return false;
return true;
}
public override void DoShowLog(IButtonInfo button)
{
//显示审计日志
this.MainForm.OpenModuleForm(Globals.LogViewerForm, "", nameof(dt_Machine));
}
}
}
BLL - 业务逻辑层代码
C# 全选
using CartonERP.Common;
using CartonERP.DataAccess;
using CartonERP.Interfaces;
using CartonERP.Models;
using CartonERP.WebApiClient;
using CSFrameworkV6.Core;
using System;
using System.Collections.Generic;
/*===================================================================
* 程序说明: Machine 基础资料BLL(支持多种后台连接策略)
* 作者资料: CSFramework
* 创建日期: 2023/08/18 12:23:33
* 最后修改: 2023/08/18 12:23:33
*
* 注:本文件由CSFramework.CodeGenerator代码生成器自动生成。
* 请将源码文件复制到 YourProject 对应的项目。
*
* 版权所有 Copyright 2006~2023, C/S框架网 (www.csframework.com)
*===================================================================*/
namespace CartonERP.Business
{
/// <summary>
/// BLL业务逻辑层:bll_Machine
/// </summary>
public class bll_Machine : bllBaseDataDict<dt_Machine>
{
private IBridge_Machine _Bridge; //自定义策略接口(连接策略层)
public bll_Machine()
{
_SummaryTableName = nameof(dt_Machine);//表名
_KeyFieldName = nameof(dt_Machine.isid);//主键字段
_DataDictBridge = BridgeFactory.CreateDataDictBridge<dt_Machine>();
_Bridge = this.CreateBridge();//当前业务数据的策略接口(连接策略层)实例
}
/// <summary>
/// 创建连接策略策略层的实例
/// </summary>
/// <returns></returns>
private IBridge_Machine CreateBridge()
{
if (BridgeFactory.IsADODirect)//直连模式
return new dal_Machine(Loginer.CurrentUser);
if (BridgeFactory.IsWebApi)//WebApi模式
return new WebApi_Machine();
throw new CustomException(BridgeFactory.UNKNOW_BRIDGE_TYPE);
}
/// <summary>
/// 新增模式,需要实例化_DataBinder成员变量
/// </summary>
public override void CreateDataBinder(dt_Machine sourceRow)
{
base.CreateDataBinder(sourceRow);
if (sourceRow == null)//新增记录,设置默认值
{
_DataBinder.isid = IdHelper.GetId();//主键
_DataBinder.InstallDate = DateTime.Today;
//
//下面代码给其他字段赋值
//
}
}
public List<dt_Machine> Query(req_Machine input)
{
return _Bridge.Query(input);
}
}
}
DAL - 数据访问层代码
C# 全选
using CartonERP.Interfaces;
using CartonERP.Models;
using CartonERP.Models.UpdateModel;
using CSFrameworkV6.Core;
using CSFrameworkV6.Core.Extensions;
using System.Collections.Generic;
using System.Data;
using System.Linq;
/*===================================================================
* 程序说明: Machine 基础资料数据访问层
* 作者资料: CSFramework
* 创建日期: 2023/08/18 12:23:33
* 最后修改: 2023/08/18 12:23:33
*
* 注:本文件由CSFramework.CodeGenerator代码生成器自动生成。
* 请将源码文件复制到 YourProject 对应的项目。
*
* 版权所有 Copyright 2006~2023, C/S框架网 (www.csframework.com)
*===================================================================*/
namespace CartonERP.DataAccess
{
/// <summary>
/// DAL数据层:dal_Machine
/// </summary>
[DefaultORM_UpdateMode(typeof(dt_Machine), true)]
public class dal_Machine : dalBaseDataDict<dt_Machine>, IBridge_Machine
{
/// <summary>
/// 构造器
/// </summary>
/// <param name="loginer">当前登录用户</param>
public dal_Machine(Loginer loginer): base(loginer)
{
}
/// <summary>
/// 获取表格默认显示的数据
/// </summary>
/// <returns></returns>
public override List<dt_Machine> GetSummaryData()
{
var q = _Database.GetQueryable<dt_Machine>();
return q.Take(100).ToList();//默认显示100条记录
}
/// <summary>
/// 获取该主数据作为Lookup数据源的数据,如:返回Code,Name字段
/// </summary>
/// <returns></returns>
public override List<dt_Machine> GetLookupData()
{
//返回所有字段
return _Database.GetQueryable<dt_Machine>().ToList();
}
public override bool CheckNoExists(string keyValue)
{
//参考代码
var q = _Database.GetQueryable<dt_Machine>();
return q.Any(a => a.MachineName == keyValue);
}
/// <summary>
/// 根据主键获取一条主数据
/// </summary>
/// <param name="keyValue">主键</param>
/// <returns></returns>
public override dt_Machine GetDataByKey(string keyValue)
{
var q = _Database.GetQueryable<dt_Machine>();
return q.Where(w => w.isid == keyValue).FirstOrDefault();
}
/// <summary>
/// 删除
/// </summary>
/// <param name="keyValue">主键</param>
/// <returns></returns>
public override bool Delete(string keyValue)
{
return this.Delete(this.GetDataByKey(keyValue));
}
/// <summary>
/// 查询
/// </summary>
/// <param name="input">查询条件</param>
/// <returns></returns>
public List<dt_Machine> Query(req_Machine input)
{
var q = _Database.GetQueryable<dt_Machine>();
if (!input.MachineName.IsEmpty())
q = q.Where(w => w.MachineName.CompareTo(input.MachineName) == 0);
if (!input.Model.IsEmpty())
q = q.Where(w => w.Model.CompareTo(input.Model) == 0);
//返回查询结果
return q.ToList();
}
/// <summary>
/// 保存数据,用于提交自动生成流水号码的数据, SaveResult.DocNo返回最新号码。
/// </summary>
/// <param name="data">当前提交的数据</param>
/// <returns></returns>
public override SaveResult UpdateEx(MasterDataUpdate<dt_Machine> data)
{
return base.UpdateEx(data);
}
/// <summary>
/// 通用保存数据的方法
/// </summary>
/// <param name="data">当前提交的数据</param>
/// <returns></returns>
public override bool Update(MasterDataUpdate<dt_Machine> data)
{
return base.Update(data);
}
/// <summary>
/// 设置流水序号
/// </summary>
/// <param name="data">当前提交的数据</param>
/// <returns></returns>
protected override string SetDataSN(MasterDataUpdate<dt_Machine> data)
{
//注意:当前功能要设置流水序号? 参考:dalReports.SetDataSN方法
return string.Empty;
}
}//public class
}//namespace
Model - 设备管理实体模型
C# 全选
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
/*===================================================================
* 程序说明: dt_Machine 实体类(ORM模型)
* 作者资料: CSFramework
* 创建日期: 2023/08/18 12:23:33
* 最后修改: 2023/08/18 12:23:33
*
* 注:本文件由CSFramework.CodeGenerator代码生成器自动生成。
* 请将源码文件复制到 YourProject 对应的项目。
*
* 版权所有 Copyright 2006~2023, C/S框架网 (www.csframework.com)
*===================================================================*/
namespace CartonERP.Models
{
///<summary>
/// 数据表:dt_Machine的实体模型(ORM Model)。
/// </summary>
[Table("dt_Machine")]
public class dt_Machine
{
#region 所有字段属性
/// <summary>
/// isid
/// </summary>
[Key, Column(Order = 1)]
public String isid { get; set; }
/// <summary>
/// MachineName
/// </summary>
public String MachineName { get; set; }
/// <summary>
/// Model
/// </summary>
public String Model { get; set; }
/// <summary>
/// BrandName
/// </summary>
public String BrandName { get; set; }
/// <summary>
/// Manufacturer
/// </summary>
public String Manufacturer { get; set; }
/// <summary>
/// Quantity
/// </summary>
public Int32? Quantity { get; set; }
/// <summary>
/// CostAmount
/// </summary>
public Decimal? CostAmount { get; set; }
/// <summary>
/// InstallLocation
/// </summary>
public String InstallLocation { get; set; }
/// <summary>
/// InstallDate
/// </summary>
public DateTime? InstallDate { get; set; }
/// <summary>
/// CreatedBy
/// </summary>
public String CreatedBy { get; set; }
/// <summary>
/// CreationDate
/// </summary>
public DateTime? CreationDate { get; set; }
/// <summary>
/// LastUpdateDate
/// </summary>
public DateTime? LastUpdateDate { get; set; }
/// <summary>
/// LastUpdatedBy
/// </summary>
public String LastUpdatedBy { get; set; }
#endregion
}
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
CSFrameworkV6 C/S框架网