public List <DichVu_Ent> GetDichVus()
        {
            List <DichVu_Ent> dv_ents = new List <DichVu_Ent>();

            var dsDichVu = from ldv in db.LoaiDichVus
                           join dv in db.DichVus on ldv.id_LoaiDichVu equals dv.id_loai_dich_vu
                           select new
            {
                maDV          = dv.id_DichVu,
                tenDichVu     = dv.ten_dich_vu,
                donGiaDV      = dv.gia_dich_vu,
                maLoai        = ldv.id_LoaiDichVu,
                tenLoaiDichVu = ldv.ten_loai_dich_vu
            };

            foreach (var dv in dsDichVu)
            {
                DichVu_Ent dv_ent = new DichVu_Ent();

                dv_ent.Id_DichVu     = dv.maDV;
                dv_ent.TenDichVu     = dv.tenDichVu;
                dv_ent.DonGia        = dv.donGiaDV;
                dv_ent.Id_LoaiDichVu = dv.maLoai;
                dv_ent.TenLoaiDichVu = dv.tenLoaiDichVu;

                dv_ents.Add(dv_ent);
            }

            return(dv_ents);
        }
        private void frmTextDichVu_Load(object sender, EventArgs e)
        {
            DichVu_WCFClient tempdv_wcf = new DichVu_WCFClient();

            cbx_LoaiDichVu.DataSource = InitializeTenLoaiDV(tempdv_wcf.GetDichVus().ToList());

            lbTieuDe.Text = Lb_TitleName;

            //Load Dữ Liệu Thêm Dịch Vụ
            if (KieuForm == 1)
            {
                txtTenDichVu.Text            = "Bún Thịt Nướng";
                txtGiaDichVu.Text            = "50000";
                cbx_LoaiDichVu.SelectedIndex = 0;
            }

            //Load Dữ Liệu Dịch Vụ Cần Sửa
            if (KieuForm == 2)
            {
                DichVu_WCFClient dv_wcf = new DichVu_WCFClient();

                DichVu_Ent dv_ent = dv_wcf.GetDichVu_byIdDichVu(Id_DichVu);
                txtTenDichVu.Text   = dv_ent.TenDichVu;
                txtGiaDichVu.Text   = dv_ent.DonGia.ToString().Trim();
                cbx_LoaiDichVu.Text = dv_ent.TenLoaiDichVu;
            }
        }
        public DichVu_Ent GetDichVu_byIdDichVu(int idDV)
        {
            DichVu     dv     = db.DichVus.Where(n => n.id_DichVu == idDV).SingleOrDefault();
            DichVu_Ent dv_ent = new DichVu_Ent();

            if (dv != null)
            {
                dv_ent.Id_DichVu     = dv.id_DichVu;
                dv_ent.TenDichVu     = dv.ten_dich_vu;
                dv_ent.DonGia        = dv.gia_dich_vu;
                dv_ent.Id_LoaiDichVu = dv.id_loai_dich_vu;
                dv_ent.TenLoaiDichVu = GetTenLoaiDichVu_byIdLoaiDichVu(dv.id_loai_dich_vu);
            }

            return(dv_ent);
        }
        public bool ThemDichVu(DichVu_Ent dv_ent)
        {
            DichVu     dichVu = db.DichVus.Where(n => n.ten_dich_vu.Equals(dv_ent.TenDichVu)).SingleOrDefault();
            LoaiDichVu loaiDV = db.LoaiDichVus.Where(n => n.ten_loai_dich_vu.Equals(dv_ent.TenLoaiDichVu)).SingleOrDefault();

            if (dichVu != null)
            {
                return(false);
            }

            if (loaiDV == null)
            {
                try
                {
                    LoaiDichVu ldv = new LoaiDichVu();

                    ldv.ten_loai_dich_vu = dv_ent.TenLoaiDichVu;

                    db.LoaiDichVus.InsertOnSubmit(ldv);
                    db.SubmitChanges();
                }
                catch
                {
                    return(false);
                }
            }

            db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, db.LoaiDichVus);

            try
            {
                DichVu dv = new DichVu();

                dv.ten_dich_vu     = dv_ent.TenDichVu;
                dv.gia_dich_vu     = dv_ent.DonGia;
                dv.id_loai_dich_vu = db.LoaiDichVus.Where(n => n.ten_loai_dich_vu.Equals(dv_ent.TenLoaiDichVu)).SingleOrDefault().id_LoaiDichVu;

                db.DichVus.InsertOnSubmit(dv);
                db.SubmitChanges();
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
        private void Luu_Sua()
        {
            isClickBtnHuy = true;

            if (!CheckNull())
            {
                MessageBox.Show("Chưa Nhập Đủ Thông Tin", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            DichVu_WCFClient dv_wcf = new DichVu_WCFClient();

            DichVu_Ent dv_ent = new DichVu_Ent();

            dv_ent.Id_DichVu     = Id_DichVu;
            dv_ent.TenDichVu     = txtTenDichVu.Text.Trim();
            dv_ent.DonGia        = Convert.ToDouble(txtGiaDichVu.Text.Trim());
            dv_ent.TenLoaiDichVu = cbx_LoaiDichVu.Text;

            if (dv_wcf.CapNhatDichVu(dv_ent))
            {
                DialogResult ds = MessageBox.Show("Lưu Thành Công, Tiếp Tục ?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                if (ds == DialogResult.Yes)
                {
                    return;
                }
                else
                {
                    this.Close();
                }
            }
            else
            {
                DialogResult ds = MessageBox.Show("Lưu Thất Bại, Thử Lại ?", "Lỗi", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                if (ds == DialogResult.Yes)
                {
                    return;
                }
                else
                {
                    this.Close();
                }
            }
        }