/// <summary>
        /// The generates a default transaction adjustment.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <returns>A <see cref="bool"/> indicating success.</returns>
        public static string GenerateDefaultTrans(LogRow row)
        {
            try
            {
                var transId  = GenerateTransId();
                var header   = Format.NewRow();
                var template = RowTemplates.First(p => p["PLUCode"].ToString() == "Delivery Charge");
                template["PollAmount"] = row.Amount;
                var colList = Format.Columns.OfType <DataColumn>().Where(col => col.ColumnName != "SalesMainID").Aggregate(
                    string.Empty,
                    (current, col) =>
                    $"{current}{(string.IsNullOrEmpty(current) ? string.Empty : ", ")}[{col.ColumnName}]");

                var insertText =
                    $"IF (SELECT COUNT(1) FROM {TableName} WHERE TransactionID = {transId}) = 0 BEGIN"
                    + $"\nINSERT INTO {TableName} ({colList}) \nSELECT {GenerateStatementColumns(header, row.Date, transId)} "
                    + $"\nUNION \nSELECT {GenerateStatementColumns(template, row.Date, transId)}; "
                    + $"\nSELECT 'Transaction inserted' as [Success] END \nELSE "
                    + $"\nSELECT 'TransactionID already exists in {TableName}! Use another TransactionID.' AS [Error]; "
                    + $"\nSELECT * FROM {TableName} WHERE TransactionID = {transId} ORDER BY SalesMainID";

                return(insertText);
            }
            catch (Exception error)
            {
                Tools.DebugLog($"Error generating transaction: {error.Message}");
            }

            return(string.Empty);
        }
Beispiel #2
0
 /// <summary>
 /// Removes a row.
 /// </summary>
 /// <param name="row">The row.</param>
 public void Remove(LogRow row)
 {
     this.Rows.Remove(row);
 }
Beispiel #3
0
 /// <summary>
 /// Adds a row.
 /// </summary>
 /// <param name="row">The row.</param>
 public void Add(LogRow row)
 {
     this.Rows.Add(row);
 }