Exemple #1
0
        //轮询订单数据库,查看是否需要添加
        private void check_Orders()
        {
            //var dao = new DAO(connectionString);
            var dc = new WatcherDBDataContext(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);
                                //dc.SubmitChanges();
                            }
                            //string cmd_str = @" declare @status int"
                            //    + @" declare @ordering bit, @paying bit"
                            //    + @" select @status=status, @paying=paying, @ordering=ordering from [Seat] where text='"
                            //    + seat.text + "'"
                            //    + @" if (@status=2 or @status=6 or @status=7) and (@paying is null or @paying=0) and (@ordering is null or @ordering=0)"
                            //    + @" insert into [Orders](menu,text,systemId,number,money,technician,techType,inputTime,inputEmployee,paid)"
                            //    + @"values('" + max_order.menu + "','" + max_order.text + "','" + seat.systemId + "',1," + the_menu.price + ",";
                            //if (max_order.technician == null)
                            //    cmd_str += "null";
                            //else
                            //    cmd_str += "'" + max_order.technician + "'";

                            //if (max_order.techType == null)
                            //    cmd_str += ",null";
                            //else
                            //    cmd_str += ",'" + max_order.techType + "'";

                            //cmd_str += ",getdate(),'电脑加收','False')";
                            //dao.execute_command(cmd_str);
                        }
                        else if (the_menu.addType == "按时间")
                        {
                            //string cmd_str = @" declare @status int"
                            //    + @" declare @ordering bit, @paying bit"
                            //    + @" select @status=status, @paying=paying, @ordering=ordering from [Seat] where text='"
                            //    + seat.text + "'"
                            //    + @" if (@status=2 or @status=6 or @status=7) and (@paying is null or @paying=0) and (@ordering is null or @ordering=0)"
                            //    + @" insert into [Orders](menu,text,systemId,number,priceType,money,technician,techType,inputTime,inputEmployee,paid)"
                            //    + @"values('" + max_order.menu + "','" + max_order.text + "','" + seat.systemId + "',1,'每小时'," +
                            //    Convert.ToDouble(the_menu.addMoney) + ",";
                            //if (max_order.technician == null)
                            //    cmd_str += "null";
                            //else
                            //    cmd_str += "'" + max_order.technician + "'";

                            //if (max_order.techType == null)
                            //    cmd_str += ",null";
                            //else
                            //    cmd_str += ",'" + max_order.techType + "'";

                            //cmd_str += ",getdate(),'电脑加收','False')";
                            //dao.execute_command(cmd_str);
                            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();
        }
 partial void UpdateOrders(Orders instance);
 partial void DeleteOrders(Orders instance);
 partial void InsertOrders(Orders instance);