|
/*===================================================================
|
* 程序说明: yhj_womdaa的数据管理窗体
|
* 作者资料: 孙中吕
|
* 创建日期: 2024/07/19 02:11:40
|
* 最后修改: 2024/07/19 02:11:40
|
*
|
* 注: 本文件由代码生成器(Code Generator)自动生成。
|
* 版权所有 Copyright 2006~2024, C/S框架网(www.cscode.net)
|
*===================================================================*/
|
|
using System;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Windows.Forms;
|
using CSFrameworkV5.Business;
|
using CSFrameworkV5.Common;
|
using CSFrameworkV5.Core;
|
using CSFrameworkV5.Interfaces;
|
using CSFrameworkV5.Library;
|
using CSFrameworkV5.Library.CommonClass;
|
using CSFrameworkV5.Models;
|
using DevExpress.XtraEditors;
|
using DevExpress.XtraGrid;
|
using DevExpress.XtraGrid.Views.Base;
|
using DevExpress.XtraGrid.Views.Grid;
|
|
namespace CSFrameworkV5.womcaa
|
{
|
///<summary>
|
/// yhj_womdaa的资料管理窗体,由代码生成器(Code Generator)自动生成
|
/// </summary>
|
public partial class frmyhj_womdaa : frmBaseBusinessForm
|
{
|
private bllyhj_womdaa _BLLInstance;//业务逻辑层对象引用
|
|
public frmyhj_womdaa()
|
{
|
InitializeComponent();
|
}
|
|
private void frmyhj_womdaa_Load(object sender, EventArgs e)
|
{
|
this.InitializeForm();//自定义初始化操作
|
if(this.splitContainerEditorAndDetailGrid != null && this.layoutGroup.OptionsTableLayoutGroup.RowDefinitions.Count != 0){
|
this.splitContainerEditorAndDetailGrid.SplitterPosition = Convert.ToInt32(Math.Round(this.layoutGroup.OptionsTableLayoutGroup.RowDefinitions.Count * this.layoutGroup.OptionsTableLayoutGroup.RowDefinitions[0].Height, 0)) + 30; }
|
if(this.splitContainerSearchAndSummary != null && this.layoutGroupSearch.OptionsTableLayoutGroup.RowDefinitions.Count != 0){
|
this.splitContainerSearchAndSummary.SplitterPosition = Convert.ToInt32(Math.Round((this.layoutGroupSearch.OptionsTableLayoutGroup.RowDefinitions.Count - 1) * this.layoutGroupSearch.OptionsTableLayoutGroup.RowDefinitions[0].Height, 0)) + 60; }
|
}
|
|
protected override void InitializeForm()
|
{
|
_BLL = new bllyhj_womdaa(); //实例化基类的业务逻辑层
|
_BLLInstance = _BLL as bllyhj_womdaa; //当前窗体的业务层逻辑层对象引用
|
|
_SummaryView = new DevGridView(gvSummary);//实例化数据视图,此接口可支持不同的视图,比如表格GridControl,树视图TreeList.
|
//_ActiveEditor = txtid;//进入修改状态,显示第一个焦点的输入框,可以不设置
|
//_KeyEditor = txtid;//主键字段输入框,可以不设置
|
_DetailGroupControl = pcDetailEditor;//【资料编辑】页面所有文本输入框的容器
|
|
base.InitializeForm();
|
picNote.Image = Globals.LoadImage("32_Notes.png");
|
|
frmGridCustomize.RegisterGrid(gvSummary);//注册表格组件,自动添加样式管理、弹出菜单
|
DevStyle.SetGridControlLayout(gcSummary, false);//主表表格样式设置
|
DevStyle.SetSummaryGridViewLayout(gvSummary);//主表表格样式设置
|
BindingSummaryNavigator(controlNavigatorSummary, gcSummary); //绑定表格导航按钮的数据源.
|
gvSummary.DoubleClick += new EventHandler(OnGridViewDoubleClick); //绑定主表的DoubleClick事件
|
gvSummary.Click += new EventHandler(OnGridViewClick); //绑定主表的DoubleClick事件
|
|
DevStyle.SetGridControlLayout(this.gcDetail0, true);//明细表表格样式设置
|
DevStyle.SetDetailGridViewLayout(this.gvDetail0);//明细表表格样式设置
|
this.gcDetail0.EmbeddedNavigator.ButtonClick += new NavigatorButtonClickEventHandler(this.OnEmbeddedNavigatorButtonClick); //绑定明细表格的按钮事件
|
this.gvDetail0.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(OnCellValueChanged); //绑定明细表格单元格数据修改时触发的事件
|
#region 以下代码全自动生成,请调整排版和顺序
|
#endregion
|
|
this.ShowSummaryPage(true); //初始化完成后显示表格页
|
}
|
|
#region 自动生成的事件或方法的主体部份
|
#endregion
|
//修改单元格数据时触发的事件
|
private void OnCellValueChanged(object sender, CellValueChangedEventArgs e)
|
{
|
//开发实例:修改单元格关联更新其它列的值
|
//参考(frmPO/frmSO).OnCellValueChanged方法}
|
}
|
|
/// <summary>
|
/// 明细表格按钮事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void OnEmbeddedNavigatorButtonClick(object sender, NavigatorButtonClickEventArgs e)
|
{
|
try
|
{
|
GridControl gc = (GridControl)((GridControlNavigator)sender).Parent;
|
GridView gridView = (GridView)gc.Views[0]; //每个GridControl默认有一个GridView.
|
if (e.Button.ImageIndex == DetailButtons.Add || e.Button.ImageIndex == DetailButtons.Insert)
|
{
|
CreateOneDetail(gridView, e.Button.ImageIndex);
|
}
|
else if (e.Button == gc.EmbeddedNavigator.Buttons.CustomButtons[DetailButtons.Delete])
|
{
|
if (Msg.AskQuestion("确定要删除这条记录?"))
|
gridView.DeleteRow(gridView.FocusedRowHandle);
|
}
|
e.Handled = true;
|
}
|
catch (Exception ex)
|
{
|
LogUserOperate.Write(ex);
|
Msg.ShowException(ex);
|
}
|
}
|
|
/// <summary>
|
/// 重要!!当按钮状态改变时触发的事件,
|
/// </summary>
|
/// <param name="currentState"></param>
|
protected override void ButtonStateChanged(UpdateType currentState)
|
{
|
bool isEditMode = (currentState == UpdateType.Add) || (currentState == UpdateType.Modify);
|
|
//设置编辑页面的文本框控件只读和可编辑状态
|
this.SetDetailEditorsAccessable(pcDetailEditor, isEditMode);
|
//设置明细表格的按钮禁用和可用状态
|
base.SetGridCustomButtonAccessable(this.gcDetail0, isEditMode);
|
//设置明细表格的可修改状态
|
this.gvDetail0.OptionsBehavior.Editable = isEditMode;
|
//业务单据的主键都不支持修改
|
txtid.Enabled= false;
|
txtid.Properties.ReadOnly = true;
|
lbStateName.Text = this.UpdateTypeName;
|
}
|
|
//有明细表:绑定单据明细表的数据源.
|
protected override void DoBindingDetailGrid(DataSet dataSource)
|
{
|
this.gcDetail0.DataSource = null;
|
this.gcDetail0.DataSource = dataSource.Tables[yhj_womdab.__TableName];
|
this.gcDetailPeek0.DataSource = null;
|
this.gcDetailPeek0.DataSource = dataSource.Tables[yhj_womdab.__TableName];
|
}
|
/// <summary>
|
/// 绑定【编辑页面】所有文本输入框的数据源
|
/// </summary>
|
/// <param name="summary">数据源</param>
|
protected override void DoBindingSummaryEditor(DataTable summary)
|
{
|
this.DoBindingEditorPanel(pcDetailEditor, summary);
|
|
//在此绑定其它自定义组件的数据源,参考frmCustomer的DoBindingSummaryEditor方法
|
}
|
|
public override void DoAdd(IButtonInfo sender)
|
{
|
base.DoAdd(sender);
|
if (this._UpdateType == UpdateType.Add){
|
// 在此添加所需的代码
|
}
|
}
|
|
//创建一条明细记录
|
private void CreateOneDetail(GridView gridView, int buttonIndex)
|
{
|
var gridControl = gridView.GridControl;
|
var detailTableName = (string) gridView.Tag;
|
//若要取排序序号,要将光标移到最后一行
|
if (buttonIndex == DetailButtons.Add){ gridView.MoveLast();}
|
|
//若表格无记录,转换为新增状态
|
if (gridView.RowCount == 0) buttonIndex = DetailButtons.Add;
|
|
DataRow row = _BLL.CurrentBusiness.Tables[detailTableName].NewRow();
|
row["ID"] = Guid.NewGuid();
|
row["PID"] = _BLL.DataBindRow["ID"];
|
//增加一条明细记录
|
if (buttonIndex == DetailButtons.Add)
|
{
|
_BLL.CurrentBusiness.Tables[detailTableName].Rows.Add(row);
|
gridControl.RefreshDataSource();//立即刷新数据源
|
gridView.FocusedRowHandle = gridView.RowCount - 1;//光标移到到最后一条记录
|
}
|
else if (buttonIndex == DetailButtons.Insert)//插入一条明细记录
|
{
|
_BLL.CurrentBusiness.Tables[detailTableName].Rows.InsertAt(row, gridView.FocusedRowHandle);
|
gridView.FocusedRowHandle = gridView.FocusedRowHandle - 1;
|
}
|
gridView.FocusedColumn = gridView.VisibleColumns[0];
|
}
|
|
public override void DoSave(IButtonInfo sender)// 保存数据
|
{
|
this.UpdateLastControl();//更新最后一个文本输入框的数据
|
|
try
|
{
|
frmWaitingEx.ShowMe(this);
|
|
DataSet dsTemplate = _BLL.CreateSaveData(_BLL.CurrentBusiness); //创建用于保存的临时数据
|
SaveResult result = _BLL.Update(dsTemplate);//调用业务逻辑层Update()方法保存数据
|
|
if (result.Success) //保存成功, 不需要重新加载数据,更新缓存数据即可.
|
{
|
if (_UpdateType == UpdateType.Add) _BLL.DataBindRow[yhj_womdaa.__KeyName] = result.GUID;
|
if (_UpdateType == UpdateType.Modify) _BLL.NotifyUser();//发送短信或Email通知制单人
|
this.UpdateSummaryCurrentRow(_BLL.DataBindRow);//刷新表格当前记录的缓存数据.
|
this.DoBindingSummaryEditor(_BLL.DataBinder); //重新绑定文本框的数据源,刷新数据
|
if (this._UpdateType == UpdateType.Add) {
|
var dt = (this.gvSummary.DataSource as DataView).ToTable();
|
var rowIndex = -1;
|
|
for (rowIndex = 0; rowIndex < dt.Rows.Count; rowIndex++) {
|
if (dt.Rows[rowIndex]["ID"].ToString() == result.GUID) {
|
break;
|
}
|
}
|
|
if (rowIndex != -1) {
|
this.gvSummary.FocusedRowHandle = rowIndex;
|
this.gvSummary.MakeRowVisible(rowIndex);
|
}
|
}
|
|
base.DoSave(sender); //调用基类的方法. 此行代码应放较后位置.
|
|
frmWaitingEx.HideMe(this);
|
Msg.ShowInformation("保存成功!");
|
}
|
else
|
{
|
Msg.Warning("保存失败!");
|
}
|
}
|
finally
|
{
|
frmWaitingEx.HideMe(this);
|
}
|
}
|
|
/// <summary>
|
/// 保存数据后,更新表格中当前记录的数据(更新缓存资料)
|
/// </summary>
|
/// <param name="currentRow">当前修改的记录</param>
|
/// <param name="docNo">当前单据号码</param>
|
protected void UpdateSummaryCurrentRow(DataRow currentRow)
|
{
|
//若表格没有数据源,要下载当前单据的数据
|
if (gcSummary.DataSource == null || gvSummary.RowCount == 0)
|
{
|
//实例化查询参数
|
Queryyhj_womdaa P = new Queryyhj_womdaa
|
{
|
daa001="",
|
sccj="",
|
scxt="",
|
daa014=""
|
};
|
|
DataTable dt = _BLLInstance.Query(P);//获取数据
|
DoBindingSummaryGrid(dt); //绑定主表表格的数据源
|
}
|
else
|
{
|
//调用基类方法更新表格中当前记录的缓存数据
|
base.UpdateSummaryRow(currentRow);
|
}
|
}
|
private void btnEmpty_Click(object sender, EventArgs e)
|
{
|
base.ClearContainerEditorText(pnlSearch);
|
}
|
|
private void btnQuery_Click(object sender, EventArgs e)
|
{
|
//查询数据
|
try
|
{
|
frmWaitingEx.ShowMe(this);
|
|
//实例化查询参数
|
Queryyhj_womdaa P = new Queryyhj_womdaa
|
{
|
daa001=ConvertEx.ToString(txt_daa001.EditValue),
|
sccj=ConvertEx.ToString(txt_sccj.EditValue),
|
scxt=ConvertEx.ToString(txt_scxt.EditValue),
|
daa014=ConvertEx.ToString(txt_daa014.EditValue)
|
};
|
|
|
DataTable dt = _BLLInstance.Query(P);
|
this.DoBindingSummaryGrid(dt);//绑定主表的Grid
|
this.ShowSummaryPage(true); //显示Summary页面.
|
if (gvSummary.RowCount == 0){ Msg.Warning("没有找到数据!");
|
}
|
else
|
{
|
this.gvSummary.FocusedRowHandle = 0;
|
this.gvSummary.SelectRow(0);
|
this.BindDetailGrids();
|
}
|
}
|
finally
|
{
|
frmWaitingEx.HideMe(this);
|
}
|
|
}
|
|
|
//给明细表绑定KeyDown事件,控制按回车事件
|
private void gvDetail_KeyDown(object sender, KeyEventArgs e)
|
{
|
var gridView = (GridView) sender;
|
//表格按回车键自动跳转到下一个可编辑列, 若是最后一列,自动新增一条记录
|
GridMovetor.OnGridViewKeyDown(gridView, e);
|
}
|
}
|
}
|