mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 06:27:15 +00:00
wip
This commit is contained in:
@@ -9,7 +9,7 @@ using System.Transactions;
|
||||
|
||||
namespace bnhtrade.Core.Data.Database.Sku
|
||||
{
|
||||
public class InsertSku : Connection
|
||||
internal class InsertSku : Connection
|
||||
{
|
||||
public int InsertNew(int productId, int conditionId, int accountTaxCodeId)
|
||||
{
|
||||
|
||||
@@ -28,8 +28,10 @@ namespace bnhtrade.Core.Logic.Sku
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return new Data.Database.Sku.InsertSku().InsertNew(productId, conditionId, accountTaxCodeId);
|
||||
else
|
||||
{
|
||||
return new Data.Database.Sku.InsertSku().InsertNew(productId, conditionId, accountTaxCodeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace bnhtrade.Core
|
||||
)
|
||||
{
|
||||
// first off, check if listing-item already exists, return id if it does
|
||||
int listingItemId = EbayListingItemGet(sqlConnectionString, itemNumber, listingEnd);
|
||||
int listingItemId = EbayListingItemGet(sqlConnectionString, itemNumber, listingEnd);
|
||||
if (listingItemId > 0)
|
||||
{ return (listingItemId, false, false); }
|
||||
|
||||
@@ -228,123 +228,6 @@ namespace bnhtrade.Core
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Sku
|
||||
{
|
||||
public class Sku
|
||||
{
|
||||
public static int GetSkuIdByType(string sqlConnectionString, int productId, int conditionId, int accountTaxCodeId, bool noMatchInsertNew)
|
||||
{
|
||||
using (TransactionScope scope = new TransactionScope())
|
||||
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
// look for existing entry
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
SELECT
|
||||
tblSku.skuSkuID
|
||||
FROM
|
||||
tblSku
|
||||
WHERE
|
||||
(((tblSku.skuProductID)=@productId) AND ((tblSku.skuSkuConditionID)=@conditionId) AND ((tblSku.AccountTaxCodeID)=@accountTaxCodeId));
|
||||
", conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@productId", productId);
|
||||
cmd.Parameters.AddWithValue("@conditionId", conditionId);
|
||||
cmd.Parameters.AddWithValue("@accountTaxCodeId", accountTaxCodeId);
|
||||
|
||||
object obj = cmd.ExecuteScalar();
|
||||
if (obj != null)
|
||||
{
|
||||
return (int)obj;
|
||||
}
|
||||
}
|
||||
|
||||
// value check insert bool
|
||||
if (noMatchInsertNew == false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// get this far, check tax code id is a valid for SKU
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
SELECT tblAccountTaxCode.InvoiceSales
|
||||
FROM tblAccountTaxCode
|
||||
WHERE (((tblAccountTaxCode.AccountTaxCodeID)=@accountTaxCodeId));
|
||||
", conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@accountTaxCodeId", accountTaxCodeId);
|
||||
|
||||
object obj = cmd.ExecuteScalar();
|
||||
|
||||
if (obj == null)
|
||||
{
|
||||
throw new Exception("AccountTaxCodeID=" + accountTaxCodeId + " doesn't exist!");
|
||||
}
|
||||
else
|
||||
{
|
||||
bool result = (bool)obj;
|
||||
if (result == false)
|
||||
{
|
||||
throw new Exception("AccountTaxCodeID=" + accountTaxCodeId + " is not a valid type for an SKU.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get info to create sku number
|
||||
int skuCount;
|
||||
int skuSuffix;
|
||||
using (SqlCommand cmd = new SqlCommand("SELECT NEXT VALUE FOR SkuCountSequence;", conn))
|
||||
{
|
||||
skuCount = (int)cmd.ExecuteScalar();
|
||||
}
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
SELECT tblSkuCondition.scnSkuNumberSuffix
|
||||
FROM tblSkuCondition
|
||||
WHERE (((tblSkuCondition.scnSkuConditionID)=@conditionId));
|
||||
", conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@conditionId", conditionId);
|
||||
|
||||
try
|
||||
{
|
||||
skuSuffix = (int)cmd.ExecuteScalar();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Error retriving SKU number suffix for SkuConditionID=" + conditionId + "." +
|
||||
System.Environment.NewLine + "Error Message: " + ex.Message);
|
||||
}
|
||||
}
|
||||
string skuNumber = skuCount.ToString("D6") + "-" + skuSuffix.ToString("D2");
|
||||
|
||||
// insert new sku
|
||||
int skuId;
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
INSERT INTO tblSku
|
||||
(skuSkuNumber, skuProductID, skuSkuConditionID, AccountTaxCodeID)
|
||||
OUTPUT INSERTED.skuSkuID
|
||||
VALUES
|
||||
(@skuNumber, @productId, @conditionId, @accountTaxCodeId)
|
||||
", conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@skuNumber", skuNumber);
|
||||
cmd.Parameters.AddWithValue("@productId", productId);
|
||||
cmd.Parameters.AddWithValue("@conditionId", conditionId);
|
||||
cmd.Parameters.AddWithValue("@accountTaxCodeId", accountTaxCodeId);
|
||||
|
||||
skuId = (int)cmd.ExecuteScalar();
|
||||
}
|
||||
|
||||
scope.Complete();
|
||||
return skuId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Stock
|
||||
{
|
||||
@@ -549,7 +432,7 @@ namespace bnhtrade.Core
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Manual delete of this stock type is not supported, use the moethod that created it!");
|
||||
throw new Exception("Manual delete of this stock type is not supported, use the method that created it!");
|
||||
}
|
||||
|
||||
// check there is only one stock journal entry for stock item
|
||||
@@ -879,6 +762,7 @@ namespace bnhtrade.Core
|
||||
}
|
||||
|
||||
// insert journal posts into database
|
||||
//new Data.Database.Stock
|
||||
Core.Stock.StockJournal.StockJournalPostInsert(conn, stockId, stockJournalId, journalPosts, isNewStock);
|
||||
|
||||
// consistency check
|
||||
|
||||
Reference in New Issue
Block a user