📄 money_inadapterlogic.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
namespace DataModal.HidaKitDataSetTableAdapters
{
public partial class MONEY_INTableAdapter
{
public void InitTransaction(SqlTransaction trans)
{
Adapter.InsertCommand.Transaction = trans;
Adapter.DeleteCommand.Transaction = trans;
Adapter.UpdateCommand.Transaction = trans;
foreach (SqlCommand cmd in CommandCollection)
cmd.Transaction = trans;
}
public void InitLogic()
{
Adapter.AcceptChangesDuringUpdate = false;
Adapter.RowUpdating += new SqlRowUpdatingEventHandler(Adapter_RowUpdating);
}
void Adapter_RowUpdating(object sender, SqlRowUpdatingEventArgs e)
{
if (e.StatementType == StatementType.Insert || e.StatementType == StatementType.Update)
{
SqlConnection conn = ConnectionHelper.GetConnection();
try
{
HidaKitDataSetTableAdapters.CUSTOMERSTableAdapter adapter = HidaKitAdapterProxy.GetCustomerAdapter(conn);
if (adapter.GetDataByCustomerID((string)e.Row["CUSTOMER_ID"]).Rows.Count == 0)
throw new IDNotExistsException((string)e.Row["CUSTOMER_ID"],
string.Format(Resources.Messages.SCustomerNotFound, e.Row["CUSTOMER_ID"]));
}
finally
{
ConnectionHelper.ReleaseConnection(conn);
}
}
}
}
public partial class MONEY_IN_DETAILTableAdapter
{
public void InitTransaction(SqlTransaction trans)
{
Adapter.InsertCommand.Transaction = trans;
Adapter.DeleteCommand.Transaction = trans;
Adapter.UpdateCommand.Transaction = trans;
foreach (SqlCommand cmd in CommandCollection)
cmd.Transaction = trans;
}
public void InitLogic()
{
Adapter.AcceptChangesDuringUpdate = false;
Adapter.RowUpdating += new SqlRowUpdatingEventHandler(Adapter_RowUpdating);
}
void Adapter_RowUpdating(object sender, SqlRowUpdatingEventArgs e)
{
ORDERSTableAdapter adapter = HidaKitAdapterProxy.GetOrdersAdapter(Connection, false);
if (Adapter.UpdateCommand.Transaction != null)
adapter.InitTransaction(Adapter.UpdateCommand.Transaction);
if (e.StatementType == StatementType.Delete || e.StatementType == StatementType.Update)
{
try
{
HidaKitDataSet.ORDERSDataTable orderTable = adapter.GetDataByOrderId((string)e.Row["ORDER_ID", DataRowVersion.Original]);
if (orderTable.Rows.Count < 1)
throw new IDNotExistsException((string)e.Row["ORDER_ID", DataRowVersion.Original], "Order not found.");
DataColumn column = e.Row.Table.Columns["DEC_TOTAL"];
double currentDecTotal = (orderTable[0].IsNull("DEC_TOTAL") ? 0 : (double)orderTable[0]["DEC_TOTAL"]);
double decTotal = (e.Row.IsNull(column, DataRowVersion.Original) ? 0 : (double)e.Row["DEC_TOTAL", DataRowVersion.Original]);
orderTable[0]["DEC_TOTAL"] = currentDecTotal - decTotal;
adapter.Update(orderTable[0]);
}
catch (Exception ex)
{
if (e.StatementType != StatementType.Delete)
throw ex;
}
}
if (e.StatementType == StatementType.Insert || e.StatementType == StatementType.Update)
{
HidaKitDataSet.ORDERSDataTable orderTable = adapter.GetDataByOrderId((string)e.Row["ORDER_ID"]);
if (orderTable.Rows.Count < 1)
throw new IDNotExistsException((string)e.Row["ORDER_ID"], "Order not found.");
double currentDecTotal = (orderTable[0].IsNull("DEC_TOTAL") ? 0 : (double)orderTable[0]["DEC_TOTAL"]);
double decTotal = (e.Row.IsNull("DEC_TOTAL") ? 0 : (double)e.Row["DEC_TOTAL"]);
if ((double)orderTable[0].TOTAL < currentDecTotal + decTotal)
throw new ApplicationException(Resources.Messages.SDebtOverflow);
orderTable[0]["DEC_TOTAL"] = currentDecTotal + decTotal;
adapter.Update(orderTable[0]);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -