コード例 #1
0
        private static async Task CheckItem(InRiverProcessorItem item, InRiverDestination dest)
        {
            string sql = "";

            switch (dest)
            {
            case InRiverDestination.Products:
                sql = String.Format("Select count(StockNo) from ProductMaster where StockNo='{0}'", item.StockNoOrPart);
                break;

            case InRiverDestination.Parts:
                sql = String.Format("Select count(Part) from Part where CompanyId={0} and Part='{1}'", item.CompanyID, item.StockNoOrPart);
                break;
            }

            using (SqlConnection connection = new SqlConnection(APIModels.Data.ConnectionManager.ProductDataHubConnectionString))
            {
                connection.Open();

                SqlCommand cmd = new SqlCommand(sql, connection);

                object result = await cmd.ExecuteScalarAsync();

                if (result != null)
                {
                    int cnt = 0;
                    int.TryParse(result.ToString(), out cnt);

                    if (cnt == 0)
                    {
                        await Task.Run(() =>
                        {
                            //pull from Unidata to SQL
                            if (dest == InRiverDestination.Products)
                            {
                                Console.WriteLine("Adding Product " + item.StockNoOrPart);

                                ProductMaster pm = new ProductMaster(item.StockNoOrPart);

                                pm.Save(APIModels.Data.ConnectionManager.ProductDataHubConnectionString);
                            }
                            else
                            {
                                Console.WriteLine("Adding Part " + item.StockNoOrPart);

                                SellingPart sp = new SellingPart(item.CompanyID, item.StockNoOrPart);

                                sp.SaveSQL(APIModels.Data.ConnectionManager.ProductDataHubConnectionString);
                            }
                        });
                    }
                }
            }

            return;
        }