本文整理汇总了C#中Collection.Sum方法的典型用法代码示例。如果您正苦于以下问题:C# Collection.Sum方法的具体用法?C# Collection.Sum怎么用?C# Collection.Sum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection.Sum方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public static long Add(DateTime valueDate, int officeId, int userId, long logOnId, int costCenterId, string referenceNumber, Collection<MixERP.Net.Common.Models.Transactions.TransactionDetailModel> details)
{
if(details == null)
{
return 0;
}
if(details.Count.Equals(0))
{
return 0;
}
string sql = string.Empty;
long transactionMasterId = 0;
decimal debitTotal = details.Sum(d => (d.Debit));
decimal creditTotal = details.Sum(d => (d.Credit));
string tranType = string.Empty;
decimal amount = 0;
if(debitTotal != creditTotal)
{
return 0;
}
using(NpgsqlConnection connection = new NpgsqlConnection(DBFactory.DBConnection.ConnectionString()))
{
connection.Open();
using(NpgsqlTransaction transaction = connection.BeginTransaction())
{
try
{
sql = "INSERT INTO transactions.transaction_master(transaction_master_id, transaction_counter, transaction_code, book, value_date, user_id, login_id, office_id, cost_center_id, reference_number) SELECT nextval(pg_get_serial_sequence('transactions.transaction_master', 'transaction_master_id')), transactions.get_new_transaction_counter(@ValueDate), transactions.get_transaction_code(@ValueDate, @OfficeId, @UserId, @LogOnId), @Book, @ValueDate, @UserId, @LogOnId, @OfficeId, @CostCenterId, @ReferenceNumber;SELECT currval(pg_get_serial_sequence('transactions.transaction_master', 'transaction_master_id'));";
using(NpgsqlCommand master = new NpgsqlCommand(sql, connection))
{
master.Parameters.AddWithValue("@ValueDate", valueDate);
master.Parameters.AddWithValue("@OfficeId", officeId);
master.Parameters.AddWithValue("@UserId", userId);
master.Parameters.AddWithValue("@LogOnId", logOnId);
master.Parameters.AddWithValue("@Book", "Journal");
master.Parameters.AddWithValue("@CostCenterId", costCenterId);
master.Parameters.AddWithValue("@ReferenceNumber", referenceNumber);
transactionMasterId = MixERP.Net.Common.Conversion.TryCastLong(master.ExecuteScalar());
}
foreach(MixERP.Net.Common.Models.Transactions.TransactionDetailModel model in details)
{
sql = "INSERT INTO transactions.transaction_details(transaction_master_id, tran_type, account_id, statement_reference, cash_repository_id, amount) SELECT @TransactionMasterId, @TranType, core.get_account_id_by_account_code(@AccountCode::text), @StatementReference, office.get_cash_repository_id_by_cash_repository_name(@CashRepositoryName::text), @Amount;";
if(model.Credit > 0 && model.Debit > 0)
{
throw new InvalidOperationException(MixERP.Net.Common.Helpers.LocalizationHelper.GetResourceString("Warnings", "BothSidesHaveValue"));
}
else
{
if(model.Credit.Equals(0) && model.Debit > 0)
{
tranType = "Dr";
amount = model.Debit;
}
else
{
tranType = "Cr";
amount = model.Credit;
}
using(NpgsqlCommand transactionDetail = new NpgsqlCommand(sql, connection))
{
transactionDetail.Parameters.AddWithValue("@TransactionMasterId", transactionMasterId);
transactionDetail.Parameters.AddWithValue("@TranType", tranType);
transactionDetail.Parameters.AddWithValue("@AccountCode", model.AccountCode);
transactionDetail.Parameters.AddWithValue("@StatementReference", model.StatementReference);
transactionDetail.Parameters.AddWithValue("@CashRepositoryName", model.CashRepositoryName);
transactionDetail.Parameters.AddWithValue("@Amount", amount);
transactionDetail.ExecuteNonQuery();
}
}
}
transaction.Commit();
return transactionMasterId;
}
catch(NpgsqlException)
{
transaction.Rollback();
throw;
}
catch(InvalidOperationException)
{
transaction.Rollback();
throw;
}
}
}
}
示例2: InstallUpdates
/// <summary>Installs updates.</summary>
/// <param name="applications">The collection of applications to install updates.</param>
/// <param name="downloadDirectory">The directory containing the app update files.</param>
public static void InstallUpdates(Collection<Sui> applications, string downloadDirectory)
{
if (applications == null)
{
throw new ArgumentNullException("applications");
}
if (applications.Count < 1)
{
throw new ArgumentNullException("applications");
}
IsInstalling = true;
updateCount = applications.Sum(t => t.Updates.Count);
int completedUpdates = 0, failedUpdates = 0;
ReportProgress(0);
for (int x = 0; x < applications.Count; x++)
{
for (int y = 0; y < applications[x].Updates.Count; y++)
{
errorOccurred = false;
if (cancelInstall)
{
Environment.Exit(0);
}
currentUpdateName = Utilities.GetLocaleString(applications[x].Updates[y].Name);
ReportProgress(5);
SetRegistryItems(applications[x].Updates[y].RegistryItems, applications[x].AppInfo.Platform);
ReportProgress(25);
UpdateFiles(applications[x].Updates[y].Files, Path.Combine(downloadDirectory, currentUpdateName));
ReportProgress(75);
SetShortcuts(applications[x].Updates[y].Shortcuts, applications[x].AppInfo);
ReportProgress(95);
if (errorOccurred)
{
failedUpdates++;
AddHistory(applications[x], applications[x].Updates[y]);
}
else
{
completedUpdates++;
AddHistory(applications[x], applications[x].Updates[y]);
}
// if (applications[x].AppInfo.Directory == Utilities.ConvertPath(@"%PROGRAMFILES%\Seven Update",
// true, Platform.AnyCpu)) { selfUpdate = true; }
ReportProgress(100);
updateIndex++;
}
}
ReportProgress(100);
if (Utilities.RebootNeeded)
{
string fileName = Path.Combine(
Environment.ExpandEnvironmentVariables("%WINDIR%"), "Temp", "reboot.lock");
if (!File.Exists(fileName))
{
using (FileStream file = File.Create(fileName))
{
file.WriteByte(0);
}
}
NativeMethods.MoveFileExW(
Path.Combine(Environment.ExpandEnvironmentVariables("%WINDIR%"), "Temp", "reboot.lock"),
null,
MoveOnReboot);
if (Directory.Exists(downloadDirectory))
{
NativeMethods.MoveFileExW(downloadDirectory, null, MoveOnReboot);
}
}
else
{
// Delete the downloads directory if no errors were found and no reboot is needed
if (!errorOccurred)
{
if (Directory.Exists(downloadDirectory))
{
try
{
Directory.Delete(downloadDirectory, true);
//.........这里部分代码省略.........
示例3: Add
public static long Add(DateTime valueDate, int officeId, int userId, long logOnId, int costCenterId, string referenceNumber, string statementReference, StockMasterModel stockMaster, Collection<StockMasterDetailModel> details, Collection<int> transactionIdCollection, Collection<Attachment> attachments)
{
if (stockMaster == null)
{
return 0;
}
if (details == null)
{
return 0;
}
if (details.Count.Equals(0))
{
return 0;
}
if (stockMaster.AgentId.Equals(0))
{
return 0;
}
decimal total = details.Sum(d => (d.Price * d.Quantity));
decimal discountTotal = details.Sum(d => d.Discount);
decimal taxTotal = details.Sum(d => d.Tax);
const string creditInvariantParameter = "Sales.Receivables";
const string salesInvariantParameter = "Sales";
const string salesTaxInvariantParamter = "Sales.Tax";
const string salesDiscountInvariantParameter = "Sales.Discount";
using (NpgsqlConnection connection = new NpgsqlConnection(DbConnection.ConnectionString()))
{
connection.Open();
using (NpgsqlTransaction transaction = connection.BeginTransaction())
{
try
{
#region TransactionMaster
string sql = "INSERT INTO transactions.transaction_master(transaction_master_id, transaction_counter, transaction_code, book, value_date, user_id, login_id, office_id, cost_center_id, reference_number, statement_reference) SELECT nextval(pg_get_serial_sequence('transactions.transaction_master', 'transaction_master_id')), transactions.get_new_transaction_counter(@ValueDate), transactions.get_transaction_code(@ValueDate, @OfficeId, @UserId, @LogOnId), @Book, @ValueDate, @UserId, @LogOnId, @OfficeId, @CostCenterId, @ReferenceNumber, @StatementReference;SELECT currval(pg_get_serial_sequence('transactions.transaction_master', 'transaction_master_id'));";
long transactionMasterId;
using (NpgsqlCommand tm = new NpgsqlCommand(sql, connection))
{
tm.Parameters.AddWithValue("@ValueDate", valueDate);
tm.Parameters.AddWithValue("@OfficeId", officeId);
tm.Parameters.AddWithValue("@UserId", userId);
tm.Parameters.AddWithValue("@LogOnId", logOnId);
tm.Parameters.AddWithValue("@Book", "Sales.Delivery");
tm.Parameters.AddWithValue("@CostCenterId", costCenterId);
tm.Parameters.AddWithValue("@ReferenceNumber", referenceNumber);
tm.Parameters.AddWithValue("@StatementReference", statementReference);
transactionMasterId = Conversion.TryCastLong(tm.ExecuteScalar());
}
#region TransactionDetails
sql = "INSERT INTO transactions.transaction_details(transaction_master_id, tran_type, account_id, statement_reference, amount) SELECT @TransactionMasterId, @TranType, core.get_account_id_by_parameter(@ParameterName), @StatementReference, @Amount;";
using (NpgsqlCommand salesRow = new NpgsqlCommand(sql, connection))
{
salesRow.Parameters.AddWithValue("@TransactionMasterId", transactionMasterId);
salesRow.Parameters.AddWithValue("@TranType", "Cr");
salesRow.Parameters.AddWithValue("@ParameterName", salesInvariantParameter);
salesRow.Parameters.AddWithValue("@StatementReference", statementReference);
salesRow.Parameters.AddWithValue("@Amount", total);
salesRow.ExecuteNonQuery();
}
if (taxTotal > 0)
{
using (NpgsqlCommand taxRow = new NpgsqlCommand(sql, connection))
{
taxRow.Parameters.AddWithValue("@TransactionMasterId", transactionMasterId);
taxRow.Parameters.AddWithValue("@TranType", "Cr");
taxRow.Parameters.AddWithValue("@ParameterName", salesTaxInvariantParamter);
taxRow.Parameters.AddWithValue("@StatementReference", statementReference);
taxRow.Parameters.AddWithValue("@Amount", taxTotal);
taxRow.ExecuteNonQuery();
}
}
if (discountTotal > 0)
{
using (NpgsqlCommand discountRow = new NpgsqlCommand(sql, connection))
{
discountRow.Parameters.AddWithValue("@TransactionMasterId", transactionMasterId);
discountRow.Parameters.AddWithValue("@TranType", "Dr");
discountRow.Parameters.AddWithValue("@ParameterName", salesDiscountInvariantParameter);
discountRow.Parameters.AddWithValue("@StatementReference", statementReference);
discountRow.Parameters.AddWithValue("@Amount", discountTotal);
discountRow.ExecuteNonQuery();
}
}
using (NpgsqlCommand creditRow = new NpgsqlCommand(sql, connection))
{
creditRow.Parameters.AddWithValue("@TransactionMasterId", transactionMasterId);
//.........这里部分代码省略.........
示例4: Add
public static long Add(DateTime valueDate, int officeId, int userId, long logOnId, int costCenterId, string referenceNumber, string statementReference, MixERP.Net.Common.Models.Transactions.StockMasterModel stockMaster, Collection<MixERP.Net.Common.Models.Transactions.StockMasterDetailModel> details)
{
if(stockMaster == null)
{
return 0;
}
if(details == null)
{
return 0;
}
if(details.Count.Equals(0))
{
return 0;
}
string sql = string.Empty;
long transactionMasterId = 0;
long stockMasterId = 0;
decimal total = details.Sum(d => (d.Price * d.Quantity));
decimal discountTotal = details.Sum(d => d.Discount);
decimal taxTotal = details.Sum(d => d.Tax);
string creditInvariantParameter = "Sales.Receivables";
string salesInvariantParameter = "Sales";
string salesTaxInvariantParamter = "Sales.Tax";
string salesDiscountInvariantParameter = "Sales.Discount";
using(NpgsqlConnection connection = new NpgsqlConnection(DBFactory.DBConnection.ConnectionString()))
{
connection.Open();
using(NpgsqlTransaction transaction = connection.BeginTransaction())
{
try
{
#region TransactionMaster
sql = "INSERT INTO transactions.transaction_master(transaction_master_id, transaction_counter, transaction_code, book, value_date, user_id, login_id, office_id, cost_center_id, reference_number, statement_reference) SELECT nextval(pg_get_serial_sequence('transactions.transaction_master', 'transaction_master_id')), transactions.get_new_transaction_counter(@ValueDate), transactions.get_transaction_code(@ValueDate, @OfficeId, @UserId, @LogOnId), @Book, @ValueDate, @UserId, @LogOnId, @OfficeId, @CostCenterId, @ReferenceNumber, @StatementReference;SELECT currval(pg_get_serial_sequence('transactions.transaction_master', 'transaction_master_id'));";
using(NpgsqlCommand tm = new NpgsqlCommand(sql, connection))
{
tm.Parameters.AddWithValue("@ValueDate", valueDate);
tm.Parameters.AddWithValue("@OfficeId", officeId);
tm.Parameters.AddWithValue("@UserId", userId);
tm.Parameters.AddWithValue("@LogOnId", logOnId);
tm.Parameters.AddWithValue("@Book", "Sales.Direct");
tm.Parameters.AddWithValue("@CostCenterId", costCenterId);
tm.Parameters.AddWithValue("@ReferenceNumber", referenceNumber);
tm.Parameters.AddWithValue("@StatementReference", statementReference);
transactionMasterId = MixERP.Net.Common.Conversion.TryCastLong(tm.ExecuteScalar());
}
#region TransactionDetails
sql = "INSERT INTO transactions.transaction_details(transaction_master_id, tran_type, account_id, statement_reference, cash_repository_id, amount) SELECT @TransactionMasterId, @TranType, core.get_account_id_by_parameter(@ParameterName), @StatementReference, @CashRepositoryId, @Amount;";
using(NpgsqlCommand salesRow = new NpgsqlCommand(sql, connection))
{
salesRow.Parameters.AddWithValue("@TransactionMasterId", transactionMasterId);
salesRow.Parameters.AddWithValue("@TranType", "Cr");
salesRow.Parameters.AddWithValue("@ParameterName", salesInvariantParameter);
salesRow.Parameters.AddWithValue("@StatementReference", statementReference);
salesRow.Parameters.AddWithValue("@CashRepositoryId", DBNull.Value);
salesRow.Parameters.AddWithValue("@Amount", total);
salesRow.ExecuteNonQuery();
}
if(taxTotal > 0)
{
using(NpgsqlCommand taxRow = new NpgsqlCommand(sql, connection))
{
taxRow.Parameters.AddWithValue("@TransactionMasterId", transactionMasterId);
taxRow.Parameters.AddWithValue("@TranType", "Cr");
taxRow.Parameters.AddWithValue("@ParameterName", salesTaxInvariantParamter);
taxRow.Parameters.AddWithValue("@StatementReference", statementReference);
taxRow.Parameters.AddWithValue("@CashRepositoryId", DBNull.Value);
taxRow.Parameters.AddWithValue("@Amount", taxTotal);
taxRow.ExecuteNonQuery();
}
}
if(discountTotal > 0)
{
using(NpgsqlCommand discountRow = new NpgsqlCommand(sql, connection))
{
discountRow.Parameters.AddWithValue("@TransactionMasterId", transactionMasterId);
discountRow.Parameters.AddWithValue("@TranType", "Dr");
discountRow.Parameters.AddWithValue("@ParameterName", salesDiscountInvariantParameter);
discountRow.Parameters.AddWithValue("@StatementReference", statementReference);
discountRow.Parameters.AddWithValue("@CashRepositoryId", DBNull.Value);
discountRow.Parameters.AddWithValue("@Amount", discountTotal);
discountRow.ExecuteNonQuery();
}
}
if(stockMaster.IsCredit)
{
//.........这里部分代码省略.........