示例#1
0
        public void GetStockNoTest()
        {
            var request = new GetStockListByAuctionDateByBranchRequest()
            {
                PartnerId = PartnerID, UserRequestInfo = User, BranchCode = "811", AuctionDate = DateTimeOffset.Parse("2016-11-07 11:00:00.0")
            };
            var stockNo = Client.GetStockListByAuctionDateByBranch(request);

            Assert.IsTrue(stockNo.WasSuccessful);
        }
示例#2
0
        private void GetStockList()
        {
            BranchList.ForEach(branch =>
            {
                branch.Auctions.ForEach(auction =>
                {
                    var request = new GetStockListByAuctionDateByBranchRequest() { PartnerId = PartnerID, UserRequestInfo = User, BranchCode = branch.BranchCode, AuctionDate = auction.AuctionDate };
                    var response = Client.GetStockListByAuctionDateByBranch(request);

                    //Get response 
                    if (response.WasSuccessful && response.RequestedData != null)
                    {
                        auction.StockNums = new List<BranchAuctionStock>(response.RequestedData.ToList().ConvertAll(c => new BranchAuctionStock() { StockNum = c }).ToList());
                    }
                    else
                    {
                        clsLog.LogInfo("GetStockList - didn't get stock list for branch " + branch.BranchCode + " and auction date " + auction.AuctionDate.ToShortDateString());
                    }
                });

                System.Threading.Thread.Sleep(1000);
            });



            try
            {
                var connection = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;
                //and send it to DB. Merge this list with existing branch list

                var branchDataTable = new DataTable();

                var flatBranchList = from b in BranchList
                                     from a in b.Auctions
                                     from s in a.StockNums
                                     select new FlatBranch { BranchCode = b.BranchCode, AuctionDate = a.AuctionDate, StockNum = s.StockNum };

                using (var reader = ObjectReader.Create(flatBranchList))
                {
                    branchDataTable.Load(reader);
                }

                clsLog.LogInfo("GetStockList - trying to save stock list, Records - " + branchDataTable.Rows.Count);

                using (SqlConnection con = new SqlConnection(connection))
                {
                    using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))
                    {
                        sqlBulkCopy.DestinationTableName = "dyndata.dbo.Stock_stg";
                        sqlBulkCopy.ColumnMappings.Add("BranchCode", "BranchID");
                        sqlBulkCopy.ColumnMappings.Add("AuctionDate", "AuctionDateTime");
                        sqlBulkCopy.ColumnMappings.Add("StockNum", "StockNumber");
                        con.Open();
                        sqlBulkCopy.BulkCopyTimeout = 0;
                        sqlBulkCopy.WriteToServer(branchDataTable);



                        SqlCommand cmd = new SqlCommand("dyndata.dbo.SP_STOCK", con);
                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.ExecuteNonQuery();

                        con.Close();
                    }
                }

                clsLog.LogInfo("GetStockList - save stock list, Records - " + branchDataTable.Rows.Count);

            }
            catch (Exception ex)
            {
                clsLog.LogError("GetStockList - Error while getting stock list. Error " + ex.Message);
            }
        }