📄 money_intablelogics.cs
字号:
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using Orphean.WinFormHelper.Framework.Data;
using Orphean.WinFormHelper.Framework.BusinessLogic;
namespace DataModal
{
public partial class HidaKitDataSet
{
public partial class MONEY_INDataTable
{
public CommonLogic CommonLogic = new CommonLogic();
public void InitLogic()
{
TableNewRow += new DataTableNewRowEventHandler(MONEY_INDataTable_TableNewRow);
ColumnChanging += new DataColumnChangeEventHandler(CommonLogic.CustomerCheckLogic);
}
void MONEY_INDataTable_TableNewRow(object sender, DataTableNewRowEventArgs e)
{
e.Row["MONEY_IN_ID"] = Guid.NewGuid();
e.Row["IN_DATE"] = DateTime.Today;
e.Row["CASH_TOTAL"] = 0;
e.Row["CHECKEN_TOTAL"] = 0;
e.Row["CHANGE_TOTAL"] = 0;
}
}
public partial class MONEY_IN_DETAILDataTable
{
private bool _recurriveFlag;
public void InitLogic()
{
TableNewRow += new DataTableNewRowEventHandler(MONEY_IN_DETAILDataTable_TableNewRow);
RowChanging += new DataRowChangeEventHandler(MONEY_IN_DETAILDataTable_RowChanging);
ColumnChanging += new DataColumnChangeEventHandler(MONEY_IN_DETAILDataTable_ColumnChanging);
}
void MONEY_IN_DETAILDataTable_ColumnChanging(object sender, DataColumnChangeEventArgs e)
{
if (e.Column.ColumnName.Equals("DEC_TOTAL"))
{
if (_recurriveFlag) return;
double orderTotal = (e.Row.IsNull("ORDER_TOTAL") ? 0 : (double)e.Row["ORDER_TOTAL"]);
double decTotal = (e.ProposedValue == DBNull.Value ? 0 : Convert.ToDouble(e.ProposedValue));
if (decTotal > orderTotal)
{
_recurriveFlag = true;
try
{
e.ProposedValue = GetPayTotal(e.Row);
e.Row.RowError = Resources.Messages.SDebtOverflow;
ValidationException ex =
new ValidationException(e.Row, e.Column, ValidationConst.E_INVALIDINPUT, e.Row.RowError);
DataErrorContext.AddError(e.Row, ex);
throw ex;
}
finally
{
_recurriveFlag = false;
}
}
else
{
e.Row.RowError = string.Empty;
DataErrorContext.ClearErrors(e.Row);
}
}
}
double GetPayTotal(DataRow row)
{
DataRow parentRow = row.GetParentRow("FK_MONEY_IN_MONEY_IN_DETAIL");
return (parentRow.IsNull("CHECKEN_TOTAL") ? 0 : (double)parentRow["CHECKEN_TOTAL"]) +
(parentRow.IsNull("CHANGE_TOTAL") ? 0 : (double)parentRow["CHANGE_TOTAL"]) +
(parentRow.IsNull("CASH_TOTAL") ? 0 : (double)parentRow["CASH_TOTAL"]);
}
void CheckOverflow(DataRow currentRow)
{
DataRow parentRow = currentRow.GetParentRow("FK_MONEY_IN_MONEY_IN_DETAIL");
double total = 0;
foreach (DataRow row in parentRow.GetChildRows("FK_MONEY_IN_MONEY_IN_DETAIL", DataRowVersion.Current))
{
if(row != currentRow)
total += (row.IsNull("DEC_TOTAL") ? 0 : (double)row["DEC_TOTAL"]);
}
total += (currentRow.IsNull("DEC_TOTAL") ? 0 : (double)currentRow["DEC_TOTAL", DataRowVersion.Proposed]);
if (total > GetPayTotal(currentRow))
{
currentRow.RowError = Resources.Messages.SDebtOverflow2;
ValidationException ex =
new ValidationException(currentRow, currentRow.Table.Columns["DEC_TOTAL"], ValidationConst.E_INVALIDINPUT, currentRow.RowError);
DataErrorContext.AddError(currentRow, ex);
throw ex;
}
else
{
currentRow.RowError = string.Empty;
DataErrorContext.ClearErrors(currentRow);
}
}
void MONEY_IN_DETAILDataTable_RowChanging(object sender, DataRowChangeEventArgs e)
{
if (e.Action == DataRowAction.Add)
CheckOverflow(e.Row);
else if (e.Action == DataRowAction.Change)
CheckOverflow(e.Row);
}
void MONEY_IN_DETAILDataTable_TableNewRow(object sender, DataTableNewRowEventArgs e)
{
e.Row["AUTO_ID"] = Guid.NewGuid();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -