示例#1
0
        public void TestRandomSelectLargestElement()
        {
            var inputArray   = new[] { 0, 5, 1 };
            var actualResult = OrderStatistics.RSelect(inputArray, 0, inputArray.Length - 1, 3);

            Assert.That(actualResult, Is.EqualTo(5));
        }
示例#2
0
        public void TestRandomSelectSecondSmallestItemEven()
        {
            var inputArray   = new[] { 0, 9, 1, 3, 5, 7 };
            var actualResult = OrderStatistics.RSelect(inputArray, 0, inputArray.Length - 1, 2);

            Assert.That(actualResult, Is.EqualTo(1));
        }
示例#3
0
        private void btnQuery_Click(object sender, EventArgs e)
        {
            DateTime date;

            try
            {
                date = DateTime.Parse(txtDate.Text);
            }
            catch (Exception)
            {
                return;
            }
            List <Order>           orders          = (List <Order>)orderManager.GetByOrderDate(date);
            List <OrderStatistics> orderStatistics = new List <OrderStatistics>();

            foreach (Order order in orders)
            {
                OrderStatistics oS = new OrderStatistics();
                oS.OrderId        = order.OrderId;
                oS.NumberOfPeople = order.NumberofPeople;
                oS.TotalAmount    = order.Items.Select(it => it.Price * it.ItemAmount).Sum();
                oS.StartTime      = order.StartTime;
                oS.FinishTime     = order.FinishTime;
                orderStatistics.Add(oS);
            }
            dgvStatistics.DataSource = new BindingList <OrderStatistics>(orderStatistics);
            txtTurnover.Text         = orderStatistics.Select(os => os.TotalAmount).Sum().ToString();
            txtCustomerVolume.Text   = orderStatistics.Select(os => os.NumberOfPeople).Sum().ToString();
        }
示例#4
0
        public void TestRandomSelectWithOneItemInArray()
        {
            var inputArray   = new[] { 0 };
            var actualResult = OrderStatistics.RSelect(inputArray, 0, inputArray.Length - 1, 2);

            Assert.That(actualResult, Is.EqualTo(0));
        }
示例#5
0
        public static List <OrderStatistics> LoadOrderStatistics(
            string customerCode
            , DateTime sendDateFrom
            , DateTime sendDateTo
            , string banderNo
            , string containerNo)
        {
            var list = new List <OrderStatistics>();

            SqlParameter[] parameters = new SqlParameter[5];
            parameters[0]       = new SqlParameter("@khbh", SqlDbType.VarChar);
            parameters[0].Value = customerCode;
            parameters[1]       = new SqlParameter("@SendDateFrom", SqlDbType.Date);
            parameters[1].Value = sendDateFrom;
            parameters[2]       = new SqlParameter("@SendDateTo", SqlDbType.Date);
            parameters[2].Value = sendDateTo;
            parameters[3]       = new SqlParameter("@banderNo", SqlDbType.VarChar);
            parameters[3].Value = banderNo;
            parameters[4]       = new SqlParameter("@container", SqlDbType.VarChar);
            parameters[4].Value = containerNo;

            using (var reader = SqlHelper.ExecuteReader(
                       ConnectionHelper.ConnectionString
                       , CommandType.StoredProcedure
                       , "t_sale_khys_Load"
                       , parameters))
            {
                while (reader.Read())
                {
                    var statistic = new OrderStatistics();
                    statistic.SendDate      = reader.GetDateTime(0);
                    statistic.BanderNo      = reader.IsDBNull(1) ? "" : reader.GetString(1);
                    statistic.ContainerType = reader.GetString(2);
                    statistic.ContainerNo   = reader.GetString(3);
                    if (!reader.IsDBNull(4))
                    {
                        statistic.Filled = Convert.ToDouble(reader.GetDecimal(4));
                    }

                    statistic.CustomerCode = reader.GetString(5);
                    statistic.Complete     = Convert.ToDouble(reader.GetDecimal(6));
                    statistic.ContainerSum = reader.GetInt32(7);
                    statistic.Id           = reader.GetInt32(8);
                    if (!reader.IsDBNull(9))
                    {
                        statistic.ChangeDate = reader.GetDateTime(9);
                    }

                    statistic.CustomerName = reader.IsDBNull(10)?"":reader.GetString(10);
                    statistic.ContractNo   = reader.GetString(11);
                    statistic.HTBH         = reader.GetString(12);

                    list.Add(statistic);
                }


                return(list);
            }
        }
示例#6
0
        public void TestGetStatistics()
        {
            var arr = new[] { 3, 41, 52, 26, 38, 57, 9, 49 };

            var res = OrderStatistics.GetStatistics(arr, 3);

            Assert.AreEqual(38, res);
        }
示例#7
0
 public static void Insert(UnitOfWork uow, OrderStatistics orderStatistics, Guid id)
 {
     int rowCountUpdated = uow.DbConnection.Execute(
         InsertOrderStatisticsQuery,
         new
     {
         Id               = id,
         TotalOrders      = orderStatistics.TotalOrders,
         Version          = 1,
         UpdatedTimestamp = DateTimeOffset.UtcNow
     },
         uow.Transaction);
 }
示例#8
0
        public async Task <OrderStatistics> GetOrdersStatistics()
        {
            OrderStatistics os;
            ConfigModels    model = await context.Configs.FirstOrDefaultAsync();

            os = new OrderStatistics {
                OrdersGettingCount       = model.OrdersGettingCount,
                OrdersSendingCount       = model.OrdersSendingCount,
                OrdersGettingActiveCount = model.OrdersGettingActiveCount,
                OrdersSendingActiveCount = model.OrdersSendingActiveCount,
                OrdersActiveCount        = model.OrdersGettingActiveCount + model.OrdersSendingActiveCount,
                OrdersAllCount           = model.OrdersGettingCount + model.OrdersSendingCount
            };
            return(os);
        }
示例#9
0
        public void Can_Insert_OrderStatistics_Row()
        {
            Guid id = Guid.NewGuid();

            using (var uow = new UnitOfWork(TestConfig.GetConnectionString(domain)))
            {
                OrderStatistics totalOrderStatistics = new OrderStatistics()
                {
                    TotalOrders = 123
                };
                OrderStatisticsRepository.Insert(uow, totalOrderStatistics, id);
                uow.Commit();
            }

            using (var uow = new UnitOfWork(TestConfig.GetConnectionString(domain)))
            {
                var repositoryResult = OrderStatisticsRepository.GetDbRow(id, uow);
                Assert.IsTrue(repositoryResult.HasValue);
            }
        }
示例#10
0
        public static List <OrderStatistics> Search(string sqlStr, params SqlParameter[] parameters)
        {
            List <OrderStatistics> list = new List <OrderStatistics>();

            using (DbCommand cmd = db.GetSqlStringCommand(sqlStr))
            {
                cmd.Parameters.AddRange(parameters);
                DataSet ds = db.ExecuteDataSet(cmd);
                if (ds != null && ds.Tables.Count > 0)
                {
                    DataTable table = ds.Tables[0];
                    foreach (DataRow dr in table.Rows)
                    {
                        OrderStatistics model = new OrderStatistics(dr);
                        list.Add(model);
                    }
                }
            }
            return(list);
        }
示例#11
0
        public static bool Save(OrderStatistics model)
        {
            string sqlStr           = "select count(1) from OrderStatistics where 1=1 ";
            List <SqlParameter> pms = new List <SqlParameter>();

            sqlStr += " and OrderID=@OrderID ";
            pms.Add(new SqlParameter("OrderID", model.OrderID));
            using (DbCommand cmd = db.GetSqlStringCommand(sqlStr))
            {
                cmd.Parameters.AddRange(pms.ToArray());
                int i = (int)db.ExecuteScalar(cmd);
                if (i > 0)
                {
                    return(Update(model));
                }
                else
                {
                    return(Insert(model));
                }
            }
        }
示例#12
0
        public static void Update(
            UnitOfWork uow,
            OrderStatistics orderStatistics,
            OrderStatisticsRow orderStatisticsRow)
        {
            int rowCountUpdated = uow.DbConnection.Execute(
                UpdateOrderStatisticsQuery,
                new
            {
                Id                    = orderStatisticsRow.Id,
                TotalOrders           = orderStatistics.TotalOrders,
                NewVersionNumber      = orderStatisticsRow.Version + 1,
                UpdatedTimestamp      = DateTimeOffset.UtcNow,
                ExistingVersionNumber = orderStatisticsRow.Version
            },
                uow.Transaction);

            if (rowCountUpdated != 1)
            {
                throw new Exception("OrderStatistics: Concurrency Exception, (probably!)");
            }
        }
示例#13
0
        public async Task <JsonResult> GetOrdersStatistics()
        {
            OrderStatistics os = await OrderManager.GetOrdersStatistics();

            return(Json(os));
        }
示例#14
0
 public OrderStatisticsTests()
 {
     orderStatistics = new OrderStatistics();
 }
示例#15
0
        public static bool Insert(OrderStatistics model)
        {
            string              sqlStr  = "";
            List <string>       fileds  = new List <string>();
            List <string>       pFileds = new List <string>();
            List <SqlParameter> pms     = new List <SqlParameter>();

            #region 添加字段

            if (model.OrderID != null)
            {
                fileds.Add("[OrderID]");
                pFileds.Add("@OrderID");
                pms.Add(new SqlParameter("OrderID", model.OrderID));
            }

            if (model.OrderCode != null)
            {
                fileds.Add("[OrderCode]");
                pFileds.Add("@OrderCode");
                pms.Add(new SqlParameter("OrderCode", model.OrderCode));
            }

            if (model.UnitPrice != null)
            {
                fileds.Add("[UnitPrice]");
                pFileds.Add("@UnitPrice");
                pms.Add(new SqlParameter("UnitPrice", model.UnitPrice));
            }

            if (model.CustomerID != null)
            {
                fileds.Add("[CustomerID]");
                pFileds.Add("@CustomerID");
                pms.Add(new SqlParameter("CustomerID", model.CustomerID));
            }

            if (model.Amount != null)
            {
                fileds.Add("[Amount]");
                pFileds.Add("@Amount");
                pms.Add(new SqlParameter("Amount", model.Amount));
            }

            if (model.Used != null)
            {
                fileds.Add("[Used]");
                pFileds.Add("@Used");
                pms.Add(new SqlParameter("Used", model.Used));
            }

            if (model.Scheduling != null)
            {
                fileds.Add("[Scheduling]");
                pFileds.Add("@Scheduling");
                pms.Add(new SqlParameter("Scheduling", model.Scheduling));
            }

            if (model.Unsubscribe != null)
            {
                fileds.Add("[Unsubscribe]");
                pFileds.Add("@Unsubscribe");
                pms.Add(new SqlParameter("Unsubscribe", model.Unsubscribe));
            }

            #endregion
            StringBuilder sb = new StringBuilder();
            sb.Append("INSERT INTO OrderStatistics (");
            sb.Append(string.Join(",", fileds.ToArray()));
            sb.Append(") values (");
            sb.Append(string.Join(",", pFileds.ToArray()));
            sb.Append(")");
            sqlStr = sb.ToString();
            using (DbCommand cmd = db.GetSqlStringCommand(sqlStr))
            {
                cmd.Parameters.AddRange(pms.ToArray());
                int i = db.ExecuteNonQuery(cmd);
                return(i > 0);
            }
        }