Esempio n. 1
0
        //自动滚项目
        private void order_auto_add_thread()
        {
            while (true)
            {
                try
                {
                    var dc = new BathDBDataContext(connectionString);
                    TransactionOptions transOptions = new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted };
                    using (new TransactionScope(TransactionScopeOption.Required, transOptions))
                    {
                        var all_menus = dc.Menu.Where(x => x.addAutomatic);
                        var menus = all_menus.Select(x => x.name).ToList();//需要自动续费的项目名称
                        var orders = dc.Orders.Where(x => menus.Contains(x.menu) && !x.paid && x.deleteEmployee == null &&
                            x.stopTiming == null);
                        var seats = dc.Seat.Where(x => x.status == 2 || x.status == 6 || x.status == 7);
                        seats = seats.Where(x => x.ordering == null || !x.ordering.Value);
                        seats = seats.Where(x => x.paying == null || !x.paying.Value);
                        foreach (var seat in seats)
                        {
                            var seat_orders = orders.Where(x => x.text == seat.text);
                            var add_menus = seat_orders.Select(x => x.menu).Distinct();
                            foreach (var add_menu in add_menus)
                            {
                                var add_orders = seat_orders.Where(x => x.menu == add_menu && (x.priceType == null || x.priceType != "停止消费"));
                                if (add_orders.Count() == 0)
                                    continue;

                                var max_time = add_orders.Max(x => x.inputTime);
                                var max_order = add_orders.OrderByDescending(x => x.inputTime).FirstOrDefault();
                                if (max_order == null || max_order.priceType == "每小时")
                                    continue;

                                var the_menu = all_menus.FirstOrDefault(x => x.name == add_menu);
                                double menu_time = the_menu.timeLimitHour.Value * 60 + the_menu.timeLimitMiniute.Value;
                                if ((the_menu.timeLimitType == null || the_menu.timeLimitType == "限时长") &&
                                    (DateTime.Now - max_order.inputTime).TotalMinutes < menu_time)
                                    continue;
                                else if ((the_menu.timeLimitType != null && the_menu.timeLimitType == "限时间"))
                                {
                                    DateTime dt = DateTime.Parse(DateTime.Now.ToLongDateString() + " "
                                        + the_menu.timeLimitHour.ToString() + ":"
                                        + the_menu.timeLimitMiniute.ToString() + ":00");

                                    DateTime dt_st = DateTime.Parse(DateTime.Now.ToLongDateString() + " 8:00:00");

                                    if (!(max_order.inputTime <= dt_st && DateTime.Now >= dt))
                                        continue;
                                }

                                if (the_menu.addType == "按项目单位")
                                {
                                    Orders new_order = new Orders();
                                    new_order.menu = max_order.menu;
                                    new_order.text = max_order.text;
                                    new_order.systemId = seat.systemId;
                                    new_order.number = 1;
                                    new_order.money = the_menu.price;
                                    new_order.technician = max_order.technician;
                                    new_order.techType = max_order.techType;
                                    new_order.inputTime = DateTime.Now;
                                    new_order.inputEmployee = "电脑加收";
                                    new_order.paid = false;

                                    //如果这个检查手牌的状态在进SeatExpenseForm之前,但是subitchanges在进SeatExpenseForm之后,
                                    //那么dgvExpense将会看不到超时浴资
                                    dc.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, seat);
                                    if ((seat.status == 2 || seat.status == 6 || seat.status == 7) &&
                                        (seat.paying == null || !seat.paying.Value) &&
                                        (seat.ordering == null || !seat.ordering.Value))
                                    {
                                        dc.Orders.InsertOnSubmit(new_order);
                                    }
                                }
                                else if (the_menu.addType == "按时间")
                                {
                                    Orders new_order = new Orders();
                                    new_order.menu = max_order.menu;
                                    new_order.text = max_order.text;
                                    new_order.systemId = seat.systemId;
                                    new_order.number = 1;
                                    new_order.priceType = "每小时";
                                    new_order.money = Convert.ToDouble(the_menu.addMoney);
                                    new_order.technician = max_order.technician;
                                    new_order.techType = max_order.techType;
                                    new_order.inputTime = DateTime.Now;
                                    new_order.inputEmployee = "电脑加收";
                                    new_order.paid = false;

                                    dc.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, seat);
                                    if ((seat.status == 2 || seat.status == 6 || seat.status == 7) &&
                                        (seat.paying == null || !seat.paying.Value) &&
                                        (seat.ordering == null || !seat.ordering.Value))
                                    {
                                        dc.Orders.InsertOnSubmit(new_order);
                                        //dc.SubmitChanges();
                                    }
                                }
                            }
                        }
                    }
                    dc.SubmitChanges();
                }
                catch
                {
                }
            }
        }