예제 #1
0
        /// <summary>
        /// 保存按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Bt_save_Click(object sender, RoutedEventArgs e)
        {
            if (!CbZhanghao.Text.Equals(null) && !Tb_odd.Text.Equals(null) && !TbDevelopmentTime.Text.Equals(null) && !Tb_vip_account.Text.Equals(null) && !Tb_number_of_people.Text.Equals(null) && !Tb_discount.Text.Equals(null) && !Tb_remark.Text.Equals(null))
            {
                string People = Tb_number_of_people.Text.Trim();

                string vip_account = Tb_vip_account.Text.Trim();

                int gruest_id = M.VIP_Table.Where(t => t.Accounts == vip_account).FirstOrDefault().ID_Guest;
                user_id = M.VIP_Table.Where(t => t.Accounts == vip_account).FirstOrDefault().ID_Guest;
                //新增预定
                YW_Subscribe m = new YW_Subscribe();
                m.ID_VIP = M.VIP_Table.Where(t => t.Accounts == vip_account).FirstOrDefault().ID_VIP;//会员id


                //m.ID_AgreementUser = (int)M.SYS_Guest.Where(g=>g.ID_Guest ==(M.VIP_Table.Where(t=>t.Accounts == vip_account).FirstOrDefault().ID_Guest)).Single().ID_AgreementUser;//协议用户id
                if (CbBargainingUnit.IsEnabled)
                {
                    string Cb_bargaining_name = CbBargainingUnit.Text.Trim();

                    m.ID_AgreementUser = M.AG_AgreementUser.Where(a => a.MC_AgreementUser.Trim() == Cb_bargaining_name).Single().ID_AgreementUser;
                }
                else
                {
                    m.ID_AgreementUser = 0;
                }

                m.ID_Guest         = gruest_id;                                  //客人id
                m.Number_Subscribe = Tb_odd.Text.Trim();                         //预约单号

                m.Time_Predict     = Convert.ToDateTime(TbDevelopmentTime.Text); //开台时间
                m.Number_People    = Convert.ToInt32(People);                    //人数
                m.Remark           = Tb_remark.Text.Trim();
                m.HouseStageID     = Reture(Tb_discount.Text, user_id);          //房台id
                m.State_Secrecy    = true;                                       //有效否
                m.Type_CheckIn     = "餐饮";
                m.Number_OpenStage = STATIC_cache.ID_Class.ToString();
                M.YW_Subscribe.Add(m);
                // M.SaveChanges();
                if (M.SaveChanges() > 0)
                {
                    MessageBox.Show("保存成功", "大海提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                    Refresh_table(gruest_id, STATIC_cache.ID_Class);
                    Common.Clear();
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("请将信息填写完整", "大海提示", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
 /// <summary>
 /// 预定取消
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BtDueToCancellation_Click(object sender, RoutedEventArgs e)
 {
     //获取单号
     string odd = TbOddNumbers.Text.ToString();
     //房台id集合
     string ftid = m.YW_Subscribe.Where(p => p.Number_Subscribe == odd).Single().HouseStageID;
     List<string> vs = ftid.Split(',').ToList();
     foreach (var item in vs)
     {
         SYS_RoomStage SRS = m.SYS_RoomStage.Where(p => p.ID_RoomStage.ToString().Trim() == item.Trim()).SingleOrDefault();
         SRS.ID_Guest = null;
         SRS.State_RoomStage = "未用";
     }
     YW_Subscribe YWS = m.YW_Subscribe.Where(p => p.Number_Subscribe == odd).SingleOrDefault();
     m.YW_Subscribe.Remove(YWS);
     if (m.SaveChanges()>0)
     {
         MessageBox.Show("预定取消成功!","大海提示",MessageBoxButton.OKCancel,MessageBoxImage.Asterisk);
     }
 }
예제 #3
0
        /// <summary>
        /// 保存
        /// </summary>
        public void Save()
        {
            string _name = String.Empty;

            if (!Integrity())
            {
                return;
            }

            if (base_names == "Bt_the_guest_book")
            {
                _name = "预定";
                //修改房台状态
                SYS_RoomStage sr = m.SYS_RoomStage.Where(c => c.ID_RoomStage == ID_RoomStage).SingleOrDefault();
                sr.State_RoomStage = "预定";
                sr.ID_Guest        = ID_Guest;
                sr.ID_room_type    = int.Parse(ck_tag);
                m.Entry(sr).State  = System.Data.Entity.EntityState.Modified;

                //添加预定信息
                YW_Subscribe sb = new YW_Subscribe();
                sb.ID_Guest         = ID_Guest;
                sb.ID_VIP           = ID_VIP;
                sb.ID_AgreementUser = ID_AgreementUser;
                sb.Number_Subscribe = Tb_Deposit_receipt_no.Text.Trim().ToString();
                sb.Time_Predict     = DateTime.Parse(Dp_the_date_of_arrival.Text.Trim());
                sb.Time_Leave       = DateTime.Parse(Dp_departure_time.Text.Trim());
                sb.Number_People    = int.Parse(Tb_number_of_people.Text.Trim());
                sb.Money_Pledge     = decimal.Parse(Tb_The_first_deposit.Text.Trim());
                sb.State_Secrecy    = true;
                sb.Remark           = Tb_note.Text.Trim();
                sb.Type_CheckIn     = ck_tag;

                string _ID_houseID = string.Empty;
                foreach (var item in right)
                {
                    _ID_houseID += item.ID_RoomStage + ",";
                }
                sb.HouseStageID = _ID_houseID;
                m.YW_Subscribe.Add(sb);

                m.SaveChanges();

                int _IDsub = m.YW_Subscribe.Where(c => c.Number_Subscribe == sb.Number_Subscribe && c.State_Secrecy == true).Single().ID_Subscribe;

                //添加账单信息 预定押金的
                CW_Bill cb = new CW_Bill();
                cb.Price       = decimal.Parse(Tb_The_first_deposit.Text.Trim());
                cb.SuOp_ID     = _IDsub;
                cb.Number_Bill = Tb_Deposit_receipt_no.Text.Trim();
                cb.State_Bill  = "未结账";
                m.CW_Bill.Add(cb);
                m.SaveChanges();

                int _IDbill = m.CW_Bill.Where(c => c.Number_Bill == cb.Number_Bill).Single().ID_Bill;

                //添加消费记录
                CW_Consumption cp = new CW_Consumption();
                cp.ID_Bill          = _IDbill;
                cp.ID_RoomStage     = ID_RoomStage;
                cp.ID_ProjectDetail = 0;
                cp.Prict            = decimal.Parse(Tb_The_first_deposit.Text.Trim());
                cp.Discount         = 1;
                cp.Effective        = true;
                m.CW_Consumption.Add(cp);
            }

            //房台登记
            if (base_names == "Bt_The_guest_registration")
            {
                _name = "登记";
                SYS_RoomStage sr = m.SYS_RoomStage.Where(c => c.ID_RoomStage == ID_RoomStage).SingleOrDefault();
                //有预定的情况

                if (sr.State_RoomStage.Trim() == "未用")
                {
                    //添加账单信息 预定押金的
                    CW_Bill cb = new CW_Bill();
                    cb.Price       = decimal.Parse(Tb_The_first_deposit.Text.Trim());
                    cb.SuOp_ID     = 0;
                    cb.Number_Bill = Tb_Deposit_receipt_no.Text.Trim();
                    cb.State_Bill  = "未结账";
                    m.CW_Bill.Add(cb);
                    m.SaveChanges();

                    int _IDbill = m.CW_Bill.Where(c => c.Number_Bill == cb.Number_Bill).Single().ID_Bill;

                    //添加消费记录
                    CW_Consumption cp = new CW_Consumption();
                    cp.ID_Bill          = _IDbill;
                    cp.ID_RoomStage     = ID_RoomStage;
                    cp.ID_ProjectDetail = 0;
                    cp.Prict            = decimal.Parse(Tb_The_first_deposit.Text.Trim());
                    cp.Discount         = 1;
                    cp.Effective        = true;

                    m.CW_Consumption.Add(cp);
                }

                //修改房台状态
                sr.State_RoomStage = "已用";
                sr.ID_Guest        = ID_Guest;
                sr.ID_room_type    = int.Parse(ck_tag);
                m.Entry(sr).State  = System.Data.Entity.EntityState.Modified;

                YW_OpenStage os = new YW_OpenStage();
                os.ID_VIP           = ID_VIP;
                os.ID_AgreementUser = m.AG_AgreementUser.Where(c => c.MC_AgreementUser == Cb_bargaining_unit_l.Text.Trim()).Single().ID_AgreementUser;
                os.Number_OpenStage = Tb_Deposit_receipt_no.Text.Trim().ToString();
                os.Time_Predict     = DateTime.Parse(Dp_the_date_of_arrival.Text.Trim());
                os.Time_Leave       = DateTime.Parse(Dp_departure_time.Text.Trim());
                os.Number_People    = int.Parse(Tb_number_of_people.Text.Trim());
                os.Money_Pledge     = decimal.Parse(Tb_The_first_deposit.Text.Trim());
                os.State_Secrecy    = true;
                os.Remark           = Tb_note.Text.Trim();
                os.Type_CheckIn     = ck_tag;
                os.Content_Message  = Tb_note.Text.Trim();

                string _ID_houseID = string.Empty;

                foreach (var item in right)
                {
                    _ID_houseID += item.ID_RoomStage + ",";
                }

                os.HouseStageID = _ID_houseID;
                m.YW_OpenStage.Add(os);
            }

            //客人续住
            if (base_names == "Bt_guest_delay")
            {
                _name = "续住登记";
                YW_OpenStage os = m.YW_OpenStage.Where(c => c.Number_OpenStage.Trim() == Tb_Deposit_receipt_no.Text.Trim()).SingleOrDefault();
                os.Time_Leave     = Dp_departure_time.SelectedDate.Value;
                m.Entry(os).State = System.Data.Entity.EntityState.Modified;
            }

            if (m.SaveChanges() > 0)
            {
                MessageBoxResult result = MessageBox.Show("房台" + _name + "成功", "大海提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                if (result == MessageBoxResult.OK)
                {
                    this.Close();
                    refresh();
                }
            }
        }
        /// <summary>
        /// 添加按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtAdd_Click(object sender, RoutedEventArgs e)
        {
            //获取选中行
            if (RsLeft == null || RsLeft.Count == 0)
            {
                RsLeft = STATIC_cache.StaticRoomStages;
                //STATIC_cache.StaticRoomStages.Clear();
            }
            if (RsLeft == null || RsLeft.Count == 0)
            {
                MessageBox.Show("请选择需要添加的房台", "大海提示", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                return;
            }
            string tbAccounts = TbAccounts.Text.Trim();

            if (string.IsNullOrEmpty(tbAccounts))
            {
                MessageBox.Show("请选择客人信息", "大海提示", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                return;
            }
            else
            {
                //获取账号信息
                zhanghao = m.VIP_Table.Where(p => p.ID_Guest == (m.SYS_Guest.Where(g => g.MC_Guest == tbAccounts).FirstOrDefault().ID_Guest)).FirstOrDefault().Accounts;
            }
            //会员id
            vip_id = m.VIP_Table.Where(p => p.Accounts == zhanghao).SingleOrDefault().ID_VIP;
            //客人id
            int krid = m.VIP_Table.Where(p => p.ID_VIP == vip_id).SingleOrDefault().ID_Guest;

            ////查看预约表中是否存在对应会员  p.State_Secrecy ==true  标志是否有效
            int Sub = m.YW_Subscribe.Where(p => p.ID_VIP == vip_id && p.State_Secrecy == true).Count();

            int Os_id = 0;
            int id_;
            int isOp = 0;
            List <RoomStage> _Rooms = rS;

            // 查询开台表信息
            var id = (from tv in m.VIP_Table
                      join to in m.YW_OpenStage on tv.ID_VIP equals to.ID_VIP
                      where tv.Accounts.Trim() == zhanghao && to.State_Message == true
                      select new
            {
                tv.ID_VIP,
            }).SingleOrDefault();

            if (id != null)
            {
                id_  = id.ID_VIP;
                isOp = m.YW_OpenStage.Where(l => l.ID_VIP == id_ && l.State_Message == true).FirstOrDefault().ID_OpenStage;
            }
            //预约表中有对应的数据数据
            if (Sub > 0)
            {
                string Sub_room_id = m.YW_Subscribe.Where(p => p.ID_VIP == vip_id && p.State_Secrecy == true).FirstOrDefault().HouseStageID;
                //开台表
                YW_OpenStage oS = new YW_OpenStage();
                oS.ID_VIP = vip_id;
                //oS.Number_People = Convert.ToInt32(TbPopulation.Text);
                oS.Remark          = TbRemark.Text.ToString();
                oS.HouseStageID    = Sub_room_id.Trim();
                oS.Type_CheckIn    = "足浴";
                oS.Remark          = "鬼知道你备注什么";
                oS.Content_Message = "谁设计的奇葩";
                oS.Time_Predict    = DateTime.Now;
                oS.State_Message   = true;
                oS.GuestID         = krid;
                m.YW_OpenStage.Add(oS);
                m.SaveChanges();
                //查询新增的开台表id
                Os_id = m.YW_OpenStage.Where(p => p.ID_VIP == vip_id && p.State_Message == true).FirstOrDefault().ID_OpenStage;
                //改变预定表数据的有效性
                YW_Subscribe yws = m.YW_Subscribe.Where(p => p.ID_VIP == vip_id && p.State_Secrecy == true).SingleOrDefault();
                yws.State_Secrecy  = false;
                m.Entry(yws).State = System.Data.Entity.EntityState.Modified;
                m.SaveChanges();


                //改变房台状态
                _Rooms.Clear();
                List <string> vs = Sub_room_id.Split(',').ToList();
                for (int i = 0; i < vs.Count; i++)
                {
                    int vsid = 0;
                    if (vs[i] == "")
                    {
                        vs.Remove(vs[i]);
                    }
                    else
                    {
                        try
                        {
                            vsid = Convert.ToInt32(vs[i]);
                        }
                        catch (Exception)
                        {
                            continue;
                        }
                    }

                    // 改变房台状态
                    SYS_RoomStage sRs = m.SYS_RoomStage.Where(p => p.ID_RoomStage == vsid).SingleOrDefault();
                    sRs.ID_Guest        = krid;
                    sRs.State_RoomStage = "已用";
                    m.Entry(sRs).State  = System.Data.Entity.EntityState.Modified;
                    m.SaveChanges();
                    _Rooms.AddRange(from tb in m.SYS_RoomStage
                                    where tb.ID_RoomStage == vsid
                                    select new RoomStage
                    {
                        Number_RoomStage = tb.Number_RoomStage,
                        MC_RoomStage     = tb.MC_RoomStage,
                        State_RoomStage  = tb.State_RoomStage,
                        Describe         = tb.Describe,
                        JionSign         = (int)tb.JionSign,
                    });
                }
            }
            //如果开台表已存在开台表就只做修改
            else if (isOp > 0)
            {
                YW_OpenStage os = m.YW_OpenStage.Where(p => p.ID_OpenStage == isOp).SingleOrDefault();
                os.HouseStageID   = os.HouseStageID + RsLeft[0].ID_RoomStage + ",";
                m.Entry(os).State = System.Data.Entity.EntityState.Modified;
                m.SaveChanges();
                int           room_id = RsLeft[0].ID_RoomStage;
                SYS_RoomStage rs      = m.SYS_RoomStage.Where(p => p.ID_RoomStage == room_id).SingleOrDefault();
                rs.State_RoomStage = "已用";
                rs.ID_Guest        = krid;
                m.Entry(rs).State  = System.Data.Entity.EntityState.Modified;
                m.SaveChanges();

                Os_id = isOp;
            }
            //假如没有就直接新增
            else if (Sub == 0)
            {
                //根据会员 id 找到客人id
                int Guest_id = m.SYS_Guest.Where(p => p.ID_Guest ==
                                                 (m.VIP_Table.Where(v => v.ID_VIP == vip_id).FirstOrDefault().ID_Guest)).SingleOrDefault().ID_Guest;

                //房台状态
                int           id_Rs = rS[0].ID_RoomStage;
                SYS_RoomStage Sr    = m.SYS_RoomStage.Where(p => p.ID_RoomStage == id_Rs).Single();
                Sr.ID_Guest        = krid;
                Sr.State_RoomStage = "已用";
                m.Entry(Sr).State  = System.Data.Entity.EntityState.Modified;
                m.SaveChanges();

                //新增开台表
                YW_OpenStage oS = new YW_OpenStage();
                oS.ID_VIP          = vip_id;
                oS.Number_People   = 0;
                oS.Remark          = TbRemark.Text.ToString();
                oS.GuestID         = Guest_id;
                oS.Type_CheckIn    = "足浴";
                oS.Remark          = "鬼知道你备注什么";
                oS.Content_Message = "谁设计的奇葩";
                oS.State_Message   = true;
                oS.HouseStageID    = rS[0].ID_RoomStage + ",";
                oS.Time_Predict    = DateTime.Now;
                oS.Time_Leave      = DateTime.Now;
                m.YW_OpenStage.Add(oS);
                m.SaveChanges();


                Os_id = m.YW_OpenStage.Where(p => p.ID_VIP == vip_id && p.State_Message == true).FirstOrDefault().ID_OpenStage;
            }



            //嵌套右边表格
            View.Windows.W_UC.W_RoomTableDataGridRight w_RoomTableDataGridRight = new W_UC.W_RoomTableDataGridRight(0, 0, Os_id);
            w_RoomTableDataGridRight.RetM += new ReuntMessage(ReceiveRight);//定义委托
            heeh.Content    = w_RoomTableDataGridRight;
            heeh.IsSelected = true;

            //嵌套左边的表格
            View.Windows.W_UC.W_RoomTableDastaGridLeft w_RoomTableDataGridLeft = new W_UC.W_RoomTableDastaGridLeft(_Rooms);
            w_RoomTableDataGridLeft.ReuntLeft += new GetGridMessage(ReceiveLeft);//定义委托
            kexuanfangtai.Content              = w_RoomTableDataGridLeft;
            kexuanfangtai.IsSelected           = true;
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtPreserve_Click(object sender, RoutedEventArgs e)
        {
          
            if (string.IsNullOrEmpty(TbAccounts.Text.ToString()) || 
                string.IsNullOrEmpty(TbRoomTable.Text.ToString())|| 
                string.IsNullOrEmpty(TbRoomTableName.Text.ToString()) ||
                string.IsNullOrEmpty(TbOddNumbers.Text.ToString())||
                string.IsNullOrEmpty(TbDevelopmentTime.Text.ToString()) ||
                string.IsNullOrEmpty(TbPopulation.Text.ToString())||
                string.IsNullOrEmpty(TbDiscount.Text.ToString())||
                string.IsNullOrEmpty(TbRemark.Text.ToString()))
            {
                MessageBox.Show("请将信息填写完整", "大海提示",MessageBoxButton.OKCancel,MessageBoxImage.Asterisk);
                return;
            }
                


            //预定单号
            string odd = TbOddNumbers.Text.ToString();
            YW_Subscribe YWS = m.YW_Subscribe.Where(p => p.Number_Subscribe == odd).SingleOrDefault();
            YWS.Time_Predict = Convert.ToDateTime(TbDevelopmentTime.Text.Trim());
            YWS.Number_People = Convert.ToInt32(TbPopulation.Text);
            YWS.Remark = TbRemark.Text.Trim();
            m.Entry(YWS).State = System.Data.Entity.EntityState.Modified;
            m.SaveChanges();
            //折扣



            //生成账单
                int yddid = m.YW_Subscribe.Where(p => p.Number_Subscribe == odd).SingleOrDefault().ID_Subscribe;//预订单id

                string  Mun = "ZD000" + m.CW_Bill.Count() + 1;//账单号
                CW_Bill Cb = new CW_Bill();
                Cb.SuOp_ID = yddid;//预订单id
                Cb.Number_Bill = Mun;
                Cb.Remark = "预定";//备注
                Cb.State_Bill = "预定";//状态
                m.CW_Bill.Add(Cb);
                m.SaveChanges();
            //保存数据
           // STATIC_cache.ScBill_id = Mun;

            //预订单房台id
            string ftid = m.YW_Subscribe.Where(p => p.Number_Subscribe == odd).SingleOrDefault().HouseStageID;
            List<string> vs = ftid.Split(',').ToList();
            //生成消费单方法
            int mSc=0;
            foreach (var item in vs)
            {
                if (item != "")
                {
                    CW_Consumption Cc = new CW_Consumption();
                    //房台id 
                    Cc.ID_RoomStage = Convert.ToInt32(item);
                    //账单id 
                    Cc.ID_Bill = m.CW_Bill.Where(p => p.SuOp_ID == yddid).SingleOrDefault().ID_Bill;
                    Cc.Effective = true;
                    //折扣、TbDiscount
                    Cc.Discount = Convert.ToDecimal(TbDiscount.Text);
                    m.CW_Consumption.Add(Cc);
                    mSc= m.SaveChanges();
                }
                else
                {
                    break; 
                }
            }
            if (mSc >0)
            {
              MessageBoxResult messageBoxResult =  MessageBox.Show("保存成功", "大海提示", MessageBoxButton.OKCancel, MessageBoxImage.Asterisk);
                if (messageBoxResult ==MessageBoxResult.OK)
                {
                    this.Close();
                    Resh();
                }
                
            }
          
        }
        /// <summary>
        /// 移除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Remove_Click(object sender, RoutedEventArgs e)
        {
            //目标数据
            string ycft = (m.YW_Subscribe.Where(p => p.ID_Guest ==(m.VIP_Table.Where(q => q.Accounts.Trim().ToString()
            == zhanghao).FirstOrDefault().ID_Guest)).Single().HouseStageID);
            if (RsRight ==null || RsLeft.Count == 0)
            {
                RsRight = STATIC_cache.StaticRoomStages;
            }
            //预定房台.Except(RsRight[0].ID_RoomStage);
            //分割字符
            List<string> vs = ycft.Split(',').ToList();
            List<string> s =vs;

            //移出房台id
            string RRIDR = RsRight[0].ID_RoomStage.ToString();
            for (int i = 0;  i < vs.Count; i++)
            {
                if (vs[i] =="")
                {
                    vs.RemoveAt(i);
                }
                if (vs[i] == RRIDR)
                {
                    vs.RemoveAt(i);
                }
            }
            //剩下的房台id 
            ycft = "";
            foreach (var item in vs)
                {
               
                if (item =="")
                {
                    
                    ycft += null ;
                }
                else
                {
                    ycft += item + ",";
                }
                    
                }
            
                   
            
            //目标订单id 
            int yddid = m.YW_Subscribe.Where(p => p.ID_Guest == 
            (m.VIP_Table.Where(o => o.Accounts.Trim() == zhanghao.Trim()).FirstOrDefault().ID_Guest)).Single().ID_Subscribe;


            YW_Subscribe yW = m.YW_Subscribe.Where(p => p.ID_Subscribe == yddid).Single();
            yW.HouseStageID = ycft;
            m.Entry(yW).State = System.Data.Entity.EntityState.Modified;
            m.SaveChanges();
            int Id_RoomStage = RsRight[0].ID_RoomStage;
            SYS_RoomStage RS = m.SYS_RoomStage.Where(p => p.ID_RoomStage == Id_RoomStage).Single();
            RS.ID_Guest = null;
            RS.State_RoomStage = "未用";
            m.Entry(RS).State = System.Data.Entity.EntityState.Modified;


            //获取已修改的房台数据
            List<RoomStage> rooms = (from tb in m.SYS_RoomStage
                                     where tb.ID_RoomStage == Id_RoomStage
                                     select new RoomStage
                                     {
                                         ID_RoomStage = tb.ID_RoomStage,
                                         Number_RoomStage = tb.Number_RoomStage,//房号
                                         MC_RoomStage = tb.MC_RoomStage,
                                         //State_RoomStage = tb.State_RoomStage == "已用" ? "" : "否"
                                     }).ToList();
            if (m.SaveChanges()>0)
            {
                //右边表格刷新
                View.Windows.W_UC.W_RoomTableDataGridRight w_RoomTableDataGridRight = new W_UC.W_RoomTableDataGridRight(Yydid,0,0);

                heeh.Content = null;
                heeh.Content = w_RoomTableDataGridRight;
                w_RoomTableDataGridRight.UserControl_Loaded(null, null);
                //左边表格刷新

                View.Windows.W_UC.W_RoomTableDastaGridLeft w_RoomTableDataGridLeft = new W_UC.W_RoomTableDastaGridLeft(rooms);
                kexuanfangtai.Content = null;
                kexuanfangtai.Content = w_RoomTableDataGridLeft;
                w_RoomTableDataGridLeft.UserControl_Loaded(null, null);
            }
            RsRight.Clear();
        }
        /// <summary>
        ///  添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtAdd_Click(object sender, RoutedEventArgs e)
        {
            // 预约单号
           
            //获取选中行
            if (RsLeft ==null ||RsLeft.Count ==0)
            {
                RsLeft = STATIC_cache.StaticRoomStages;
                //STATIC_cache.StaticRoomStages.Clear();
            }
            if (string.IsNullOrEmpty(zhanghao))//客户帐号
            {
                MessageBox.Show("请选中客户信息","大海提示",MessageBoxButton.OK,MessageBoxImage.Asterisk);
                return;
            }
            var id = (from tv in m.VIP_Table
                      join ty in m.YW_Subscribe on tv.ID_Guest equals ty.ID_Guest
                      where tv.Accounts.Trim() == zhanghao.Trim() select new
                      {
                          ty.ID_Guest,
                          ty.ID_Subscribe
                      }).SingleOrDefault();

            //没有对应的预约单就添加
            if (id ==null)
            {

                string count = "YYD0" + (m.YW_Subscribe.ToList().Count + 1);//获取 预约单条数      
               EntityVo.STATIC_cache.Number_Subscribe = count;
                TbOddNumbers.Text = count.Trim();
                YW_Subscribe s = new YW_Subscribe();
                s.ID_Guest = m.VIP_Table.Where(p => p.Accounts.Trim() == zhanghao).Single().ID_Guest;//客人id
                s.ID_VIP = m.VIP_Table.Where(p => p.Accounts.Trim() == zhanghao).Single().ID_VIP;//vipid
                s.HouseStageID = "";//房台id
                s.Number_Subscribe = count;//单号
                s.Remark = "我是黑大帅";
                s.Type_CheckIn = "足浴";
                m.YW_Subscribe.Add(s);
                s.State_Secrecy = true;
                m.SaveChanges();
            }

             id = (from tv in m.VIP_Table
                      join ty in m.YW_Subscribe on tv.ID_Guest equals ty.ID_Guest
                      where tv.Accounts.Trim() == zhanghao.Trim()
                      select new
                      {
                          ty.ID_Guest,
                          ty.ID_Subscribe
                      }).SingleOrDefault();

            //roomStage.ID_RoomStage;
            // dgdt.ItemsSource[roomStage.ID_RoomStage].
            //id.ID_Subscribe

            ///不知道为啥会报错
            try
            {
                int id_sbb = id.ID_Subscribe;
            }
            catch (Exception)
            {

                return;
            }
         

           
            string strHouseStageID = m.YW_Subscribe.Where(p => p.ID_Subscribe == id.ID_Subscribe).SingleOrDefault().HouseStageID;

            if (RsLeft[0].ID_RoomStage.ToString().Trim() == strHouseStageID)
            {
                strHouseStageID = null;
            }
            YW_Subscribe y = m.YW_Subscribe.Where(p => p.ID_Subscribe == id.ID_Subscribe).SingleOrDefault();
            y.HouseStageID = strHouseStageID +  RsLeft[0].ID_RoomStage.ToString().Trim() + ",";
            m.Entry(y).State = System.Data.Entity.EntityState.Modified;
            m.SaveChanges();
            int getIDR = RsLeft[0].ID_RoomStage;
            int krid=   m.YW_Subscribe.Where(p => p.ID_Subscribe == id.ID_Subscribe).SingleOrDefault().ID_Guest;
            SYS_RoomStage o = m.SYS_RoomStage.Where(p => p.ID_RoomStage == getIDR).SingleOrDefault();
            o.ID_Guest = krid;
            o.State_RoomStage = "预定";



            //获取已修改的房台数据
            List<RoomStage> rooms = (from tb in m.SYS_RoomStage where tb.ID_RoomStage == getIDR
                                     select new RoomStage
                                     {
                                         ID_RoomStage = tb.ID_RoomStage,
                                         Number_RoomStage = tb.Number_RoomStage,//房号
                                         MC_RoomStage = tb.MC_RoomStage,
                                         //State_RoomStage = tb.State_RoomStage == "已用" ? "" : "否"
                                     }).ToList() ;

            if (m.SaveChanges()>0)
            {
              MessageBoxResult messageBoxResult =   MessageBox.Show("添加成功!","大海提示",MessageBoxButton.OK,MessageBoxImage.Asterisk);
                if (messageBoxResult ==MessageBoxResult.OK)
                {
                    // YYid
                    Yydid = m.YW_Subscribe.Where(p => p.Number_Subscribe.Trim() == EntityVo.STATIC_cache.Number_Subscribe.Trim()).SingleOrDefault().ID_Subscribe;

                    //右边表格刷新  EntityVo.STATIC_cache.Number_Subscribe
                    View.Windows.W_UC.W_RoomTableDataGridRight w_RoomTableDataGridRight = new W_UC.W_RoomTableDataGridRight(Yydid,0,0);
                    heeh.Content = null;
                    heeh.Content = w_RoomTableDataGridRight;
                    w_RoomTableDataGridRight.UserControl_Loaded(null, null);

                    //左边表格刷新
                    View.Windows.W_UC.W_RoomTableDastaGridLeft w_RoomTableDataGridLeft = new W_UC.W_RoomTableDastaGridLeft(rooms);
                    kexuanfangtai.Content = null;
                    kexuanfangtai.Content = w_RoomTableDataGridLeft;
                    w_RoomTableDataGridLeft.UserControl_Loaded(null,null);
                
                }
            }
            RsLeft.Clear();
        }
예제 #8
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Bt_save_Click(object sender, RoutedEventArgs e)
        {
            //代码还有整合得空间,算了懒得去搞~
            if (Cb_Founding_account.Text.Equals(string.Empty) && Tb_Founding_account.Equals(string.Empty) || Tb_Room_table.Text.Equals(string.Empty) || Tb_Room_table_name.Text.Equals(string.Empty) || Tb_odd.Text.Equals(string.Empty) || Tb_Founding_time.Text.Equals(string.Empty) || Tb_number_of_people.Text.Equals(string.Empty) || Tb_discount.Text.Equals(string.Empty) || Tb_account.Text.Equals(string.Empty) || Tb_postscript.Text.Equals(string.Empty))
            {
                MessageBox.Show("请将信息填写完整", "大海提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            string hsid = string.Empty;

            //未定状态
            if (Cb_Founding_account.IsVisible)
            {
                int?Guest = m.SYS_Guest.Where(c => c.MC_Guest.Trim() == Cb_Founding_account.Text).SingleOrDefault().ID_AgreementUser;


                foreach (var item in RightOc)
                {
                    hsid += item.ID_RoomStage + ",";


                    //账单表
                    CW_Bill b = new CW_Bill();
                    //b.ID_Bill = c.ID_Consumption;
                    b.Number_Bill = Tb_odd.Text.Trim();
                    m.CW_Bill.Add(b);
                    m.SaveChanges();


                    //消费表
                    CW_Consumption c = new CW_Consumption();
                    c.ID_RoomStage = item.ID_RoomStage;
                    /// c.ID_Bill = b.ID_Bill;
                    //c.ID_Bill = m.CW_Bill.AsEnumerable().Last().ID_Bill;//查询表格中最后一条数据
                    c.ID_Bill = m.CW_Bill.Where(t => t.Number_Bill == Tb_odd.Text.Trim() &&
                                                t.State_Bill == null).Single().ID_Bill;
                    c.Discount  = Convert.ToDecimal(Tb_discount.Text.Trim());
                    c.Effective = true;
                    m.CW_Consumption.Add(c);
                    m.SaveChanges();


                    //房台
                    SYS_RoomStage r = m.SYS_RoomStage.Where(d => d.ID_RoomStage == item.ID_RoomStage).FirstOrDefault();
                    r.State_RoomStage = "已用";
                    r.ID_Guest        = item.ID_Guest;
                    m.Entry(r).State  = System.Data.Entity.EntityState.Modified;
                    m.SaveChanges();
                }
                ;
                var ID_VIP = m.VIP_Table.Where(c => c.Accounts == Tb_account.Text.Trim()).FirstOrDefault().ID_VIP;
                //预约
                YW_OpenStage o = new YW_OpenStage();
                o.Number_People    = int.Parse(Tb_number_of_people.Text.Trim());//人数
                o.Number_OpenStage = Tb_odd.Text.Trim();
                o.ID_VIP           = ID_VIP;
                o.State_Secrecy    = true;
                o.Remark           = Tb_postscript.Text.Trim();
                o.Type_CheckIn     = "餐饮";
                o.Content_Message  = string.Empty;
                if (!Guest.Equals(null))
                {
                    o.ID_AgreementUser = (int)Guest;
                }
                o.HouseStageID = hsid;
                o.Time_Predict = Convert.ToDateTime(Tb_Founding_time.Text.Trim());
                m.YW_OpenStage.Add(o);

                if (m.SaveChanges() > 0)
                {
                    MessageBox.Show("开台成功", "大海提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                    Close();
                    return;
                }
            }

            //预定状态
            if (Tb_Founding_account.IsVisible)
            {
                foreach (var item in RightOc)
                {
                    //查看该房台是否存在消费但
                    var date = m.CW_Consumption.Where(c => c.ID_RoomStage == item.ID_RoomStage && c.Effective == true).FirstOrDefault();
                    if (date.Equals(null))
                    {
                        CW_Bill b = new CW_Bill();
                        //  b.ID_Bill = c.ID_Consumption;
                        b.Number_Bill = Tb_odd.Text.Trim();
                        m.CW_Bill.Add(b);
                        m.SaveChanges();

                        CW_Consumption c = new CW_Consumption();
                        c.ID_RoomStage = item.ID_RoomStage;
                        c.Discount     = Convert.ToDecimal(Tb_discount.Text.Trim());
                        c.ID_Bill      = m.CW_Bill.Where(t => t.Number_Bill == Tb_odd.Text.Trim() &&
                                                         t.State_Bill == null).Single().ID_Bill;
                        c.Effective = true;
                        m.CW_Consumption.Add(c);
                        m.SaveChanges();
                    }
                    //修改房台信息
                    SYS_RoomStage r = m.SYS_RoomStage.Where(c => c.ID_RoomStage == item.ID_RoomStage && c.State_RoomStage.Trim() == "预定").SingleOrDefault();
                    r.ID_Guest        = null;
                    r.State_RoomStage = "已用";
                    m.Entry(r).State  = System.Data.Entity.EntityState.Modified;
                }
                var ID_VIP = m.VIP_Table.Where(c => c.Accounts == Tb_account.Text.Trim()).FirstOrDefault().ID_VIP;

                //修改预定信息
                YW_Subscribe w = m.YW_Subscribe.Where(c => c.ID_VIP == ID_VIP && c.State_Secrecy == true).SingleOrDefault();
                w.State_Secrecy  = false;
                m.Entry(w).State = System.Data.Entity.EntityState.Modified;
                m.SaveChanges();

                YW_OpenStage o = new YW_OpenStage();
                o.Number_People    = int.Parse(Tb_number_of_people.Text.Trim());//人数
                o.Number_OpenStage = Tb_odd.Text.Trim();
                o.ID_VIP           = ID_VIP;
                o.State_Secrecy    = true;
                o.Remark           = Tb_postscript.Text.Trim();
                o.HouseStageID     = hsid;
                o.Time_Predict     = Convert.ToDateTime(Tb_Founding_time.Text.Trim());
                o.Type_CheckIn     = "餐饮";
                o.Content_Message  = string.Empty;
                m.YW_OpenStage.Add(o);

                if (m.SaveChanges() > 0)
                {
                    MessageBox.Show("开台成功", "大海提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                    Close();
                    return;
                }
            }
        }