Ejemplo n.º 1
0
        //查询营业报表
        private void find_Day_Table()
        {
            try
            {
                var accountList = db.Account.Where(x => x.payTime >= lastTime && x.payTime <= thisTime && x.abandon == null);
                if (!accountList.Any())
                {
                    return;
                }
                var idLst = accountList.Select(x => x.id).ToList();

                #region  照项目类别统计结账项目信息

                var catgoryList = db.Catgory.Select(x => x.name);
                foreach (string catgory in catgoryList)
                {
                    bool   first       = true;
                    double totalMoney  = 0;
                    double totalNumber = 0;
                    var    menuList    = db.Menu.Where(x => x.catgoryId == db.Catgory.FirstOrDefault(s => s.name == catgory).id).Select(x => x.name);
                    foreach (string menu in menuList)
                    {
                        var m         = db.Menu.FirstOrDefault(x => x.name == menu);
                        var orderList = db.HisOrders.Where(x => x.menu == menu && idLst.Contains(x.accountId.Value) && x.deleteEmployee == null);
                        if (orderList.Any())
                        {
                            double money  = BathClass.get_orders_money(accountList.ToList(), orderList.ToList());
                            double number = orderList.Sum(x => x.number);

                            string money_str = money.ToString();
                            double s_number  = 0;
                            if (menu.Contains("浴资"))
                            {
                                s_number   = orderList.Where(x => x.money != 0).Sum(x => x.number);
                                money_str += "(" + s_number.ToString() + ")";
                            }
                            if (first)
                            {
                                first = false;
                                this.Invoke(new delegate_add_row(add_row),
                                            (Object)(new object[] { catgory, menu, number, m.price * number, money_str }));
                            }
                            else
                            {
                                this.Invoke(new delegate_add_row(add_row),
                                            (Object)(new object[] { "", menu, number, m.price * number, money_str }));
                            }
                            totalMoney  += money;
                            totalNumber += number;
                        }
                    }
                    if (!first)
                    {
                        this.Invoke(new delegate_add_row(add_row),
                                    (Object)(new object[] { "", "小计", totalNumber, "", totalMoney }));
                        this.Invoke(new delegate_change_dgv_color(change_dgv_color), Color.LightBlue);
                    }
                }

                #endregion

                #region 查找套餐

                double cTotal    = 0;
                double cNumber   = 0;
                var    comboList = db.Combo.Select(x => x.id.ToString());
                bool   firstRow  = true;
                foreach (string comboId in comboList)
                {
                    string menu      = "套餐" + comboId + "优惠";
                    var    orderList = db.HisOrders.Where(x => x.menu == menu && idLst.Contains(x.accountId.Value));
                    if (orderList.Any())
                    {
                        double money  = Convert.ToDouble(orderList.Sum(x => x.money));
                        double number = orderList.Count();
                        cTotal  += money;
                        cNumber += number;
                        if (firstRow)
                        {
                            firstRow = false;
                            this.Invoke(new delegate_add_row(add_row),
                                        (Object)(new object[] { "套餐", menu, "", number, money }));
                        }
                        else
                        {
                            this.Invoke(new delegate_add_row(add_row),
                                        (Object)(new object[] { "", menu, "", number, money }));
                        }
                    }
                }
                if (!firstRow)
                {
                    this.Invoke(new delegate_add_row(add_row),
                                (Object)(new object[] { "", "小计", cNumber, "", cTotal }));
                    this.Invoke(new delegate_change_dgv_color(change_dgv_color), Color.LightBlue);
                }

                #endregion

                #region 查找售卡

                firstRow = true;
                var cardsale = db.CardSale.Where(x => x.payTime >= lastTime && x.payTime <= thisTime);

                double cardsale_cash = 0;
                double cardsale_bank = 0;
                var    card_cash     = cardsale.Where(x => x.cash != null);
                var    card_bank     = cardsale.Where(x => x.bankUnion != null);
                if (card_cash.Any())
                {
                    cardsale_cash = card_cash.Sum(x => x.cash).Value;
                }

                if (card_bank.Any())
                {
                    cardsale_bank = card_bank.Sum(x => x.bankUnion).Value;
                }

                var balance_list = cardsale.Select(x => x.balance);
                foreach (var balance in balance_list)
                {
                    var card_balance = cardsale.Where(x => x.balance == balance);

                    double card_balance_money = 0;
                    var    card_balance_cash  = card_balance.Where(x => x.cash != null);
                    if (card_balance_cash.Any())
                    {
                        card_balance_money += card_balance_cash.Sum(x => x.cash).Value;
                    }

                    var card_balance_bank = card_balance.Where(x => x.bankUnion != null);
                    if (card_balance_bank.Any())
                    {
                        card_balance_money += card_balance_bank.Sum(x => x.bankUnion).Value;
                    }

                    if (firstRow)
                    {
                        firstRow = false;
                        this.Invoke(new delegate_add_row(add_row),
                                    (Object)(new object[] { "会员卡", MConvert <int> .ToTypeOrDefault(balance, 0).ToString() + "会员卡", "",
                                                            card_balance.Count(), card_balance_money }));
                    }
                    else
                    {
                        this.Invoke(new delegate_add_row(add_row),
                                    (Object)(new object[] { "", MConvert <int> .ToTypeOrDefault(balance, 0).ToString() + "会员卡", "",
                                                            card_balance.Count(), card_balance_money }));
                    }
                }
                if (!firstRow)
                {
                    this.Invoke(new delegate_add_row(add_row),
                                (Object)(new object[] { "", "", "小计", cardsale.Count(), cardsale_cash + cardsale_bank }));
                    this.Invoke(new delegate_change_dgv_color(change_dgv_color), Color.LightBlue);
                }

                #endregion

                #region 查找充值
                firstRow = true;
                var    cardpop       = db.CardSale.Where(x => x.explain != null && x.payTime >= lastTime && x.payTime <= thisTime);
                double cardpop_cash  = 0;
                double cardpop_bank  = 0;
                var    card_pop_cash = cardpop.Where(x => x.cash != null);
                var    card_pop_bank = cardpop.Where(x => x.bankUnion != null);
                if (card_pop_cash.Any())
                {
                    cardpop_cash = card_pop_cash.Sum(x => x.cash).Value;
                }

                if (card_pop_bank.Any())
                {
                    cardpop_bank = card_pop_bank.Sum(x => x.bankUnion).Value;
                }

                this.Invoke(new delegate_add_row(add_row),
                            (Object)(new object[] { "会员充值", "", "现金", card_pop_cash.Count().ToString(),
                                                    cardpop_cash.ToString() }));
                this.Invoke(new delegate_add_row(add_row),
                            (Object)(new object[] { "", "", "银联", card_pop_bank.Count().ToString(),
                                                    cardpop_bank.ToString() }));
                this.Invoke(new delegate_add_row(add_row),
                            (Object)(new object[] { "", "", "小计", cardpop.Count().ToString(),
                                                    (cardpop_cash + cardpop_bank).ToString() }));
                this.Invoke(new delegate_change_dgv_color(change_dgv_color), Color.LightBlue);
                #endregion

                #region 查找其他类别
                cTotal   = 0;
                cNumber  = 0;
                firstRow = true;
                var other_orders = db.HisOrders.Where(x => idLst.Contains(x.accountId.Value) && x.deleteEmployee == null &&
                                                      !x.menu.Contains("套餐") && db.Menu.FirstOrDefault(y => y.name == x.menu) == null);
                var other_menus = other_orders.Select(x => x.menu).Distinct();
                foreach (var om in other_menus)
                {
                    var tmp_orders = other_orders.Where(x => x.menu == om);
                    if (tmp_orders.Any())
                    {
                        double money  = tmp_orders.Sum(x => x.money);
                        double number = tmp_orders.Sum(x => x.number);
                        cTotal  += money;
                        cNumber += number;
                        if (firstRow)
                        {
                            firstRow = false;
                            this.Invoke(new delegate_add_row(add_row),
                                        (Object)(new object[] { "其他", om, "", number, money }));
                        }
                        else
                        {
                            object[] row = { "", om, "", number, money };
                            this.Invoke(new delegate_add_row(add_row),
                                        (Object)(new object[] { "", om, "", number, money }));
                        }
                    }
                }
                if (!firstRow)
                {
                    this.Invoke(new delegate_add_row(add_row),
                                (Object)(new object[] { "", "", "小计", cNumber, cTotal }));
                    this.Invoke(new delegate_change_dgv_color(change_dgv_color), Color.LightBlue);
                }

                #endregion

                double totalAmount = cardsale_bank + cardsale_cash;
                double actualMoney = totalAmount;
                double cash        = 0;
                double bankUnion   = 0;

                if (dgv.Rows.Count == 0)
                {
                    return;
                }

                #region 收银信息汇总

                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                //dgv.Rows.Add();

                double tmp_Money = Convert.ToDouble(accountList.Where(x => x.cash != null).Sum(x => x.cash));
                totalAmount += tmp_Money;
                actualMoney += tmp_Money;
                cash        += tmp_Money;

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.changes != null).Sum(x => x.changes));
                totalAmount -= tmp_Money;
                actualMoney -= tmp_Money;
                cash        -= tmp_Money;
                //dgv.Rows.Add("现金", cash);
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "现金", cash }));

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.bankUnion != null).Sum(x => x.bankUnion));
                totalAmount += tmp_Money;
                actualMoney += tmp_Money;
                //dgv.Rows.Add("银联", bankUnion + tmp_Money);
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "银联", bankUnion + tmp_Money }));

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.creditCard != null).Sum(x => x.creditCard));
                totalAmount += tmp_Money;
                //dgv.Rows.Add("储值卡", tmp_Money);
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "储值卡", tmp_Money }));

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.coupon != null).Sum(x => x.coupon));
                totalAmount += tmp_Money;
                //dgv.Rows.Add("优惠券", tmp_Money);
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "优惠券", tmp_Money }));

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.groupBuy != null).Sum(x => x.groupBuy));
                totalAmount += tmp_Money;
                //dgv.Rows.Add("团购优惠", tmp_Money);
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "团购优惠", tmp_Money }));


                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.zero != null).Sum(x => x.zero));
                totalAmount += tmp_Money;
                //dgv.Rows.Add("挂账", tmp_Money);
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "挂账", tmp_Money }));

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.server != null).Sum(x => x.server));
                totalAmount += tmp_Money;
                //dgv.Rows.Add("招待", tmp_Money);
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "招待", tmp_Money }));

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.wipeZero != null).Sum(x => x.wipeZero));
                totalAmount += tmp_Money;

                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "抹零", tmp_Money }));
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));

                #endregion

                #region 售卡信息汇总

                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "现金售卡", cardsale_cash }));
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "银联售卡", cardsale_bank }));
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));

                #endregion

                #region 充值信息

                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "现金充值", cardpop_cash }));
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "银联售卡", cardpop_bank }));
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));

                #endregion

                #region 人数 总营业额 统计信息

                var act_orders    = db.HisOrders.Where(x => idLst.Contains(x.accountId.Value) && x.deleteEmployee == null);
                var anmoMenuLst   = db.Menu.Where(x => db.Catgory.FirstOrDefault(y => y.id == x.catgoryId).name == "按摩").Select(x => x.name).ToList();
                var anmoOrderList = db.HisOrders.Where(x => idLst.Contains(x.accountId.Value) && anmoMenuLst.Contains(x.menu) && x.menu != "小费" && x.deleteEmployee == null).Select(x => x.systemId);
                int male_pop      = act_orders.Where(x => seat_male.Contains(x.text)).Select(x => x.systemId).Distinct().Count();
                int female_pop    = act_orders.Where(x => seat_female.Contains(x.text)).Select(x => x.systemId).Distinct().Count();
                int totalPop      = male_pop + female_pop;
                int anmoPop       = anmoOrderList.Distinct().Count();

                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "总人数", totalPop }));
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "男宾人数", male_pop }));
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { "女宾人数", female_pop }));
                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));

                string[] t_row = { "总营业额", totalAmount.ToString() };
                dgv.Rows.Insert(0, t_row);
                dgv.Rows.Insert(1, 1);

                #endregion

                this.Invoke(new delegate_set_dgv_fit(BathClass.set_dgv_fit), dgv);
            }
            catch (System.Exception e)
            {
                BathClass.printErrorMsg(e.Message);
            }
        }
Ejemplo n.º 2
0
        //查询
        private void dgv_show()
        {
            dgv.Rows.Clear();
            List <Account> accountList = findAccount();

            if (!accountList.Any())
            {
                return;
            }

            //第一部分:账单部分
            double totalMoney = 0;

            foreach (var act in accountList)
            {
                var    money    = BathClass.get_account_money(act);
                string act_text = string.Join("\n", act.text.Split('|').ToArray());

                var money_str = "";
                if (act.cash != null)
                {
                    if (act.changes == null)
                    {
                        money_str += act.cash + "现";
                    }
                    else
                    {
                        money_str += act.cash - act.changes + "现";
                    }
                }
                if (act.bankUnion != null)
                {
                    money_str = money_str == "" ? money_str + act.bankUnion + "银" : money_str + "\n" + act.bankUnion + "银";
                }
                if (act.creditCard != null)
                {
                    money_str = money_str == "" ? money_str + act.creditCard + "卡" : money_str + "\n" + act.creditCard + "卡";
                }
                if (act.coupon != null)
                {
                    money_str = money_str == "" ? money_str + act.coupon + "券" : money_str + "\n" + act.coupon + "券";
                }
                if (act.groupBuy != null)
                {
                    money_str = money_str == "" ? money_str + act.groupBuy + "团" : money_str + "\n" + act.groupBuy + "团";
                }
                if (act.zero != null)
                {
                    money_str = money_str == "" ? money_str + act.zero + "挂" : money_str + "\n" + act.zero + "挂";
                }
                if (act.server != null)
                {
                    money_str = money_str == "" ? money_str + act.server + "招" : money_str + "\n" + act.server + "招";
                }
                if (act.wipeZero != null)
                {
                    money_str = money_str == "" ? money_str + act.wipeZero + "抹" : money_str + "\n" + act.wipeZero + "抹";
                }

                dgv.Rows.Add(act.id, act_text, act.payTime.ToString("MM-dd HH:mm"), money_str);
                totalMoney += money;
            }
            dgv.Rows.Add("合计", "", "", totalMoney);

            totalMoney = 0;
            dgv.Rows.Add();

            //第二部分:订单部分
            var orders = db.HisOrders.Where(x => idList.Contains(x.accountId.Value) && x.deleteEmployee == null);
            var menus  = orders.Select(x => x.menu).Distinct();

            foreach (var menu in menus)
            {
                var menu_orders = orders.Where(x => x.menu == menu);
                var tmp_menu    = db.Menu.FirstOrDefault(x => x.name == menu);

                double t_number = menu_orders.Sum(x => x.number);
                double money    = BathClass.get_orders_money(accountList, menu_orders.ToList());
                double t_money  = 0;
                if (tmp_menu != null)
                {
                    t_money = t_number * tmp_menu.price;
                }

                dgv.Rows.Add(menu, t_number, t_money, money);
                totalMoney += money;
            }

            //第三部分:售卡部分
            double card_cash = 0, card_bank = 0;
            var    cardsale = db.CardSale.Where(x => (x.macAddress == macAdd || x.macAddress == null) && x.payTime >= lastTime && x.payTime <= thisTime);

            var cardsale_free = cardsale.Where(x => x.note == "赠送卡");

            if (cardsale_free.Any())
            {
                dgv.Rows.Add("赠送卡", cardsale_free.Count());
            }

            cardsale = cardsale.Where(x => x.note == null);
            //dgv.Rows.Add(MConvert<int>.ToTypeOrDefault(balance).ToString() + "会员卡", card_balance.Count(), "", card_balance_money);
            var balance_list = cardsale.Select(x => x.balance).Distinct();

            foreach (var balance in balance_list)
            {
                var    card_balance       = cardsale.Where(x => x.balance == balance);
                double card_balance_money = 0;
                var    card_balance_cash  = card_balance.Where(x => x.cash != null);
                if (card_balance_cash.Any())
                {
                    double cash = card_balance_cash.Sum(x => x.cash).Value;
                    card_balance_money += cash;
                    card_cash          += cash;
                }

                var card_balance_bank = card_balance.Where(x => x.bankUnion != null);
                if (card_balance_bank.Any())
                {
                    double bank = card_balance_bank.Sum(x => x.bankUnion).Value;
                    card_balance_money += bank;
                    card_bank          += bank;
                }

                totalMoney += card_balance_money;
                dgv.Rows.Add(MConvert <int> .ToTypeOrDefault(balance, 0) + "会员卡", card_balance.Count(), "", card_balance_money);
            }

            dgv.Rows.Add("合计", "", "", totalMoney);
            dgv.Rows.Add();


            //第四部分:汇总部分
            string[] cashRow     = { "现金", "", "", card_cash.ToString() };
            string[] bankRow     = { "银联", "", "", card_bank.ToString() };
            string[] cardRow     = { "储值卡", "", "", "0" };
            string[] couponRow   = { "优惠券", "", "", "0" };
            string[] groupBuyRow = { "团购优惠", "", "", "0" };
            string[] discountRow = { "挂账", "", "", "0" };
            string[] serverRow   = { "免单", "", "", "0" };
            string[] otherRow    = { "扣卡", "", "", "0" };
            string[] wipeRow     = { "抹零", "", "", "0" };

            double act_money = card_bank + card_cash;

            double tmp_Money = Convert.ToDouble(accountList.Where(x => x.cash != null).Sum(x => x.cash));

            cashRow[3] = (Convert.ToDouble(cashRow[3]) + tmp_Money).ToString();
            act_money += tmp_Money;

            tmp_Money  = Convert.ToDouble(accountList.Where(x => x.changes != null).Sum(x => x.changes));
            cashRow[3] = (Convert.ToDouble(cashRow[3]) - tmp_Money).ToString();
            act_money -= tmp_Money;

            tmp_Money  = Convert.ToDouble(accountList.Where(x => x.bankUnion != null).Sum(x => x.bankUnion));
            bankRow[3] = (Convert.ToDouble(bankRow[3]) + tmp_Money).ToString();
            act_money += tmp_Money;

            tmp_Money  = Convert.ToDouble(accountList.Where(x => x.creditCard != null).Sum(x => x.creditCard));
            cardRow[3] = tmp_Money.ToString();
            act_money += tmp_Money;

            tmp_Money    = Convert.ToDouble(accountList.Where(x => x.coupon != null).Sum(x => x.coupon));
            couponRow[3] = tmp_Money.ToString();
            act_money   += tmp_Money;

            tmp_Money      = Convert.ToDouble(accountList.Where(x => x.groupBuy != null).Sum(x => x.groupBuy));
            groupBuyRow[3] = tmp_Money.ToString();
            act_money     += tmp_Money;

            tmp_Money      = Convert.ToDouble(accountList.Where(x => x.zero != null).Sum(x => x.zero));
            discountRow[3] = tmp_Money.ToString();
            act_money     += tmp_Money;

            tmp_Money    = Convert.ToDouble(accountList.Where(x => x.server != null).Sum(x => x.server));
            serverRow[3] = tmp_Money.ToString();
            act_money   += tmp_Money;

            tmp_Money   = Convert.ToDouble(accountList.Where(x => x.deducted != null).Sum(x => x.deducted));
            otherRow[3] = tmp_Money.ToString();
            act_money  += tmp_Money;

            tmp_Money  = Convert.ToDouble(accountList.Where(x => x.wipeZero != null).Sum(x => x.wipeZero));
            wipeRow[3] = tmp_Money.ToString();
            act_money += tmp_Money;

            dgv.Rows.Add(cashRow);
            dgv.Rows.Add(bankRow);
            dgv.Rows.Add(cardRow);
            dgv.Rows.Add(couponRow);
            dgv.Rows.Add(groupBuyRow);
            dgv.Rows.Add(discountRow);
            dgv.Rows.Add(serverRow);
            dgv.Rows.Add(otherRow);
            dgv.Rows.Add(wipeRow);
            dgv.Rows.Add("合计", "", "", act_money);

            BathClass.set_dgv_fit(dgv);
        }
Ejemplo n.º 3
0
        private void find_Day_Table_right()
        {
            try
            {
                var accountList = db.Account.Where(x => x.payTime >= lastTime && x.payTime <= thisTime && x.abandon == null);
                if (!accountList.Any())
                {
                    return;
                }
                var idLst = accountList.Select(x => x.id).ToList();

                #region  项目类别查找结账项目
                var catgoryList = db.Catgory.Select(x => x.name);
                foreach (string catgory in catgoryList)
                {
                    bool   first       = true;
                    double totalMoney  = 0;
                    double totalNumber = 0;
                    var    menuList    = db.Menu.Where(x => x.catgoryId == db.Catgory.FirstOrDefault(s => s.name == catgory).id).Select(x => x.name);
                    foreach (string menu in menuList)
                    {
                        var orderList = db.HisOrders.Where(x => x.menu == menu && idLst.Contains(x.accountId.Value) && x.deleteEmployee == null);
                        if (orderList.Any())
                        {
                            var price_list = orderList.Where(x => x.number != 0).Select(x => x.money / x.number).Distinct();
                            foreach (var price in price_list)
                            {
                                var    order_price_list = orderList.Where(x => x.number != 0 && x.money / x.number == price);
                                double money            = BathClass.get_orders_money(accountList.ToList(), order_price_list.ToList());
                                double number           = order_price_list.Sum(x => x.number);
                                if (first)
                                {
                                    first = false;
                                    this.Invoke(new delegate_add_row(add_row),
                                                (Object)(new object[] { catgory, menu, price, number, money }));
                                }
                                else
                                {
                                    this.Invoke(new delegate_add_row(add_row),
                                                (Object)(new object[] { "", menu, price, number, money }));
                                }
                                totalMoney  += money;
                                totalNumber += number;
                            }
                        }
                    }
                    if (!first)
                    {
                        this.Invoke(new delegate_add_row(add_row),
                                    (Object)(new object[] { "", "", "小计", totalNumber, totalMoney }));
                        this.Invoke(new delegate_change_dgv_color(change_dgv_color), Color.LightBlue);
                    }
                }
                #endregion

                #region 查找套餐
                double cTotal       = 0;
                double cNumber      = 0;
                var    comboList    = db.Combo.Select(x => x.id.ToString());
                bool   firstRow     = true;
                var    combo_orders = db.HisOrders.Where(x => x.menu.Contains("套餐") && idLst.Contains(x.accountId.Value));
                var    combo_menus  = combo_orders.Select(x => x.menu).Distinct();
                foreach (string combo_menu in combo_menus)
                {
                    var orderList = combo_orders.Where(x => x.menu == combo_menu);
                    if (orderList.Any())
                    {
                        double money  = Convert.ToDouble(orderList.Sum(x => x.money));
                        double number = orderList.Count();
                        cTotal  += money;
                        cNumber += number;
                        if (firstRow)
                        {
                            firstRow = false;
                            this.Invoke(new delegate_add_row(add_row),
                                        (Object)(new object[] { "套餐", combo_menu, "", number, money }));
                        }
                        else
                        {
                            this.Invoke(new delegate_add_row(add_row),
                                        (Object)(new object[] { "", combo_menu, "", number, money }));
                        }
                    }
                }
                if (!firstRow)
                {
                    this.Invoke(new delegate_add_row(add_row),
                                (Object)(new object[] { "", "", "小计", cNumber, cTotal }));
                    this.Invoke(new delegate_change_dgv_color(change_dgv_color), Color.LightBlue);
                }
                #endregion

                #region 查找售卡
                firstRow = true;
                var    cardsale      = db.CardSale.Where(x => x.explain == null && x.payTime >= lastTime && x.payTime <= thisTime && x.abandon == null);
                double cardsale_cash = 0;
                double cardsale_bank = 0;
                var    card_cash     = cardsale.Where(x => x.cash != null);
                var    card_bank     = cardsale.Where(x => x.bankUnion != null);
                if (card_cash.Any())
                {
                    cardsale_cash = card_cash.Sum(x => x.cash).Value;
                }

                if (card_bank.Any())
                {
                    cardsale_bank = card_bank.Sum(x => x.bankUnion).Value;
                }

                var balance_list = cardsale.Select(x => x.balance).Distinct();
                foreach (var balance in balance_list)
                {
                    var    card_balance       = cardsale.Where(x => x.balance == balance);
                    double card_balance_money = 0;
                    var    card_balance_cash  = card_balance.Where(x => x.cash != null);
                    if (card_balance_cash.Any())
                    {
                        card_balance_money += card_balance_cash.Sum(x => x.cash).Value;
                    }

                    var card_balance_bank = card_balance.Where(x => x.bankUnion != null);
                    if (card_balance_bank.Any())
                    {
                        card_balance_money += card_balance_bank.Sum(x => x.bankUnion).Value;
                    }
                    if (firstRow)
                    {
                        firstRow = false;
                        this.Invoke(new delegate_add_row(add_row),
                                    (Object)(new object[] { "会员卡", MConvert <int> .ToTypeOrDefault(balance, 0).ToString() + "会员卡", "",
                                                            card_balance.Count(), card_balance_money.ToString() }));
                    }
                    else
                    {
                        this.Invoke(new delegate_add_row(add_row),
                                    (Object)(new object[] { "", MConvert <int> .ToTypeOrDefault(balance, 0).ToString() + "会员卡", "",
                                                            card_balance.Count(), card_balance_money.ToString() }));
                    }
                }
                if (!firstRow)
                {
                    this.Invoke(new delegate_add_row(add_row),
                                (Object)(new object[] { "", "", "小计", cardsale.Count().ToString(),
                                                        (cardsale_bank + cardsale_cash).ToString() }));
                    this.Invoke(new delegate_change_dgv_color(change_dgv_color), Color.LightBlue);
                }

                #endregion

                #region 查找充值
                firstRow = true;
                var    cardpop       = db.CardSale.Where(x => x.explain != null && x.payTime >= lastTime && x.payTime <= thisTime);
                double cardpop_cash  = 0;
                double cardpop_bank  = 0;
                var    card_pop_cash = cardpop.Where(x => x.cash != null);
                var    card_pop_bank = cardpop.Where(x => x.bankUnion != null);
                if (card_pop_cash.Any())
                {
                    cardpop_cash = card_pop_cash.Sum(x => x.cash).Value;
                }

                if (card_pop_bank.Any())
                {
                    cardpop_bank = card_pop_bank.Sum(x => x.bankUnion).Value;
                }

                this.Invoke(new delegate_add_row(add_row),
                            (Object)(new object[] { "会员充值", "", "现金", card_pop_cash.Count().ToString(),
                                                    cardpop_cash.ToString() }));
                this.Invoke(new delegate_add_row(add_row),
                            (Object)(new object[] { "", "", "银联", card_pop_bank.Count().ToString(),
                                                    cardpop_bank.ToString() }));
                this.Invoke(new delegate_add_row(add_row),
                            (Object)(new object[] { "", "", "小计", cardpop.Count().ToString(),
                                                    (cardpop_cash + cardpop_bank).ToString() }));
                this.Invoke(new delegate_change_dgv_color(change_dgv_color), Color.LightBlue);
                #endregion

                #region 查找其他类别
                cTotal   = 0;
                cNumber  = 0;
                firstRow = true;
                var other_orders = db.HisOrders.Where(x => idLst.Contains(x.accountId.Value) && x.deleteEmployee == null &&
                                                      !x.menu.Contains("套餐") && db.Menu.FirstOrDefault(y => y.name == x.menu) == null);
                var other_menus = other_orders.Select(x => x.menu).Distinct();
                foreach (var om in other_menus)
                {
                    var tmp_orders = other_orders.Where(x => x.menu == om);
                    if (tmp_orders.Any())
                    {
                        double money  = tmp_orders.Sum(x => x.money);
                        double number = tmp_orders.Sum(x => x.number);
                        cTotal  += money;
                        cNumber += number;
                        if (firstRow)
                        {
                            firstRow = false;
                            this.Invoke(new delegate_add_row(add_row),
                                        (Object)(new object[] { "其他", om, "", number, money }));
                        }
                        else
                        {
                            this.Invoke(new delegate_add_row(add_row),
                                        (Object)(new object[] { "", om, "", number, money }));
                        }
                    }
                }
                if (!firstRow)
                {
                    this.Invoke(new delegate_add_row(add_row),
                                (Object)(new object[] { "", "", "小计", cNumber, cTotal }));
                    this.Invoke(new delegate_change_dgv_color(change_dgv_color), Color.LightBlue);
                }
                #endregion

                double totalAmount = cardsale_bank + cardsale_cash + cardpop_bank + cardpop_cash;
                double actualMoney = totalAmount;
                double cash        = 0;
                double bankUnion   = 0;

                if (dgv.Rows.Count == 0)
                {
                    return;
                }

                this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));

                #region 收款信息在营业报表右边
                double tmp_Money = Convert.ToDouble(accountList.Where(x => x.cash != null).Sum(x => x.cash));
                totalAmount += tmp_Money;
                actualMoney += tmp_Money;
                cash        += tmp_Money;

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.changes != null).Sum(x => x.changes));
                totalAmount -= tmp_Money;
                actualMoney -= tmp_Money;
                cash        -= tmp_Money;

                dgv.Rows[0].Cells[6].Value = "现金";
                dgv.Rows[0].Cells[7].Value = cash;

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.bankUnion != null).Sum(x => x.bankUnion));
                totalAmount += tmp_Money;
                actualMoney += tmp_Money;
                dgv.Rows[1].Cells[6].Value = "银联";
                dgv.Rows[1].Cells[7].Value = bankUnion + tmp_Money;

                int row_index = 3;
                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.creditCard != null).Sum(x => x.creditCard));
                totalAmount += tmp_Money;
                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                //dgv.Rows.Add();
                dgv.Rows[row_index - 1].Cells[6].Value = "储值卡";
                dgv.Rows[row_index - 1].Cells[7].Value = tmp_Money;
                row_index++;

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.coupon != null).Sum(x => x.coupon));
                totalAmount += tmp_Money;
                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                //dgv.Rows.Add();
                dgv.Rows[row_index - 1].Cells[6].Value = "优惠券";
                dgv.Rows[row_index - 1].Cells[7].Value = tmp_Money;
                row_index++;

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.groupBuy != null).Sum(x => x.groupBuy));
                totalAmount += tmp_Money;
                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                //dgv.Rows.Add();
                dgv.Rows[row_index - 1].Cells[6].Value = "团购优惠";
                dgv.Rows[row_index - 1].Cells[7].Value = tmp_Money;
                row_index++;

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.zero != null).Sum(x => x.zero));
                totalAmount += tmp_Money;
                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                //dgv.Rows.Add();
                dgv.Rows[row_index - 1].Cells[6].Value = "挂账";
                dgv.Rows[row_index - 1].Cells[7].Value = tmp_Money;
                row_index++;

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.server != null).Sum(x => x.server));
                totalAmount += tmp_Money;
                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                //dgv.Rows.Add();
                dgv.Rows[row_index - 1].Cells[6].Value = "招待";
                dgv.Rows[row_index - 1].Cells[7].Value = tmp_Money;
                row_index++;

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.deducted != null).Sum(x => x.deducted));
                totalAmount += tmp_Money;
                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                //dgv.Rows.Add();
                dgv.Rows[row_index - 1].Cells[6].Value = "扣卡";
                dgv.Rows[row_index - 1].Cells[7].Value = tmp_Money;
                row_index++;

                tmp_Money    = Convert.ToDouble(accountList.Where(x => x.wipeZero != null).Sum(x => x.wipeZero));
                totalAmount += tmp_Money;
                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                //dgv.Rows.Add();
                dgv.Rows[row_index - 1].Cells[6].Value = "抹零";
                dgv.Rows[row_index - 1].Cells[7].Value = tmp_Money;
                row_index++;

                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                row_index++;
                #endregion

                #region 售卡信息
                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                dgv.Rows[row_index - 1].Cells[6].Value = "现金售卡";
                dgv.Rows[row_index - 1].Cells[7].Value = cardsale_cash;
                row_index++;

                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                dgv.Rows[row_index - 1].Cells[6].Value = "银联售卡";
                dgv.Rows[row_index - 1].Cells[7].Value = cardsale_bank;
                row_index++;
                #endregion

                #region 充值信息

                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                dgv.Rows[row_index - 1].Cells[6].Value = "现金充值";
                dgv.Rows[row_index - 1].Cells[7].Value = cardpop_cash;
                row_index++;

                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                dgv.Rows[row_index - 1].Cells[6].Value = "银联充值";
                dgv.Rows[row_index - 1].Cells[7].Value = cardpop_bank;
                row_index++;

                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                row_index++;

                #endregion

                #region 人数 总营业额 统计信息

                var anmoMenuLst   = db.Menu.Where(x => db.Catgory.FirstOrDefault(y => y.id == x.catgoryId).name == "按摩").Select(x => x.name).ToList();
                var anmoOrderList = db.HisOrders.Where(x => idLst.Contains(x.accountId.Value) && anmoMenuLst.Contains(x.menu) && x.menu != "小费" && x.deleteEmployee == null).Select(x => x.systemId);
                int totalPop      = db.HisOrders.Where(x => idLst.Contains(x.accountId.Value) && x.deleteEmployee == null).Select(x => x.systemId).Distinct().Count();
                int anmoPop       = anmoOrderList.Distinct().Count();

                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                dgv.Rows[row_index - 1].Cells[6].Value = "总人数";
                dgv.Rows[row_index - 1].Cells[7].Value = totalPop;
                row_index++;

                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                dgv.Rows[row_index - 1].Cells[6].Value = "按摩人数";
                dgv.Rows[row_index - 1].Cells[7].Value = anmoPop;
                row_index++;

                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                dgv.Rows[row_index - 1].Cells[6].Value = "比例";
                dgv.Rows[row_index - 1].Cells[7].Value = ((double)anmoPop / (double)totalPop).ToString("p");
                row_index++;

                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                row_index++;

                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                dgv.Rows[row_index - 1].Cells[6].Value = "总营业额";
                dgv.Rows[row_index - 1].Cells[7].Value = totalAmount;
                row_index++;

                if (dgv.Rows.Count < row_index)
                {
                    this.Invoke(new delegate_add_row(add_row), (Object)(new object[] { }));
                }
                dgv.Rows[row_index - 1].Cells[6].Value = "实际收入";
                dgv.Rows[row_index - 1].Cells[7].Value = actualMoney;
                row_index++;

                #endregion

                this.Invoke(new delegate_set_dgv_fit(BathClass.set_dgv_fit), dgv);
            }
            catch (System.Exception e)
            {
                BathClass.printErrorMsg(e.Message);
            }
        }