Ejemplo n.º 1
0
        public void Run()
        {
            Console.WriteLine("-----------定点保存当天库存开始-----------");
            string ConString = new ConfigurationBuilder()
                               .SetBasePath(Directory.GetCurrentDirectory())
                               .AddJsonFile("host.json", optional: true).Build().GetSection("ghSource").Value;
            SqlConnection con = new SqlConnection(ConString);

            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            SqlTransaction tran = con.BeginTransaction();

            try
            {
                BllRateTotal Bll        = new BllRateTotal(con);
                string       CreateTime = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd");//时间减一个小时,防止程序执行时间耽误正确时间:23:59:59
                Bll.InsertToCirculationStock(CreateTime, tran);
                Bll.InsertToFeeding(CreateTime, tran);
                Bll.InsertToOutInOfStorage(CreateTime, tran);
                Bll.InsertToStorage(CreateTime, tran);
                tran.Commit();
                Console.WriteLine("-----------定点保存当天库存结束-----------");
            }
            catch (Exception ex)
            {
                tran.Rollback();
                string     fileName  = "TimeJobError.txt";
                string     textToAdd = DateTime.Now.ToString() + ":" + ex.Message;
                FileStream fs        = null;
                fs = new FileStream(fileName, FileMode.Append);
                using (StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8))
                {
                    sw.WriteLine(textToAdd);
                }
                fs.Dispose();
                Console.WriteLine("-----------定点保存当天库存异常-----------");
                throw ex;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }



            //Job要执行的逻辑代码

            //LogHelper.Info("Start crawling");
            //AddToLatestMovieList(100);
            //AddToHotMovieList();
            //LogHelper.Info("Finish crawling");
        }
Ejemplo n.º 2
0
        public void TestMethod1()
        {
            string ConString = "Data Source=10.10.152.113;Initial Catalog=gh;Persist Security Info=True;" +
                               "User ID=productUser;Password=ghtest Product;Connect Timeout=500";
            RateTotalController Bll = new RateTotalController();

            using (SqlConnection con = new SqlConnection(ConString))
            {
                //con.Open();
                BllRateTotal Rate      = new BllRateTotal(con);
                Stopwatch    Stopwatch = new Stopwatch();
                Stopwatch.Start();
                //for (int i=0;i<30;i++)
                //{
                //    Bll.GetPut("", "", "", "", "2017-11-1", "2017-12-1", false, con, "1");
                //}
                Stopwatch.Stop();
                Console.WriteLine(Stopwatch);
            }
        }