Exemplo n.º 1
0
        public static string UpdateData(Data.KaraokeEntities kara, IQueryable <TEntity> query, System.Data.Objects.ObjectSet <TEntity> obj, TEntity data)
        {
            string resuilt = "";

            try
            {
                TEntity entity = query.FirstOrDefault();
                if (entity == null)
                {
                    entity = data;
                    obj.AddObject(entity);
                }
                else
                {
                    ObjectConvert <TEntity> .Coppy(data, entity);

                    //kara.ObjectStateManager.ChangeObjectState(entity, System.Data.EntityState.Modified);
                }
                kara.SaveChanges();
            }
            catch (Exception ex)
            {
                resuilt = "Lỗi..." + ex.Message;
            }
            return(resuilt);
        }
 private void btnLuu_Click(object sender, RoutedEventArgs e)
 {
     foreach (var nhom in mQueryMenuNhom)
     {
         if (nhom.EntityState == System.Data.EntityState.Modified)
         {
             var queryMon = Data.BOMenuMon.GetAll(mKaraokeEntities, nhom);
             foreach (var item in queryMon)
             {
                 item.GiamGia = nhom.GiamGia;
             }
         }
     }
     mKaraokeEntities.SaveChanges();
 }
Exemplo n.º 3
0
        public void ImportItem(string url)
        {
            _OnImportExport("----------------------------", false);
            _OnImportExport(String.Format("Đọc tập tin excel..."), false);
            var listItem = ExcelReader.GetDataToList(url, MON, ImportExportItem.GetProductData);
            List <Data.MENUNHOM> listNhom = new List <Data.MENUNHOM>();

            //List<Data.MENUMON> listMon = new List<Data.MENUMON>();

            _OnImportExport(String.Format("Xóa dữ liệu cũ..."), false);
            mKaraokeEntities.ExecuteStoreCommand("SP_DELETE_ALL_MENU");

            _OnImportExport(String.Format("Tạo {0}...", MAYIN), false);
            Data.MAYIN mayin = new Data.MAYIN();
            mayin.TenMayIn = "Test";
            mayin.TieuDeIn = "BẾP";
            mayin.SoLanIn  = 1;
            mayin.Visual   = true;
            mKaraokeEntities.MAYINs.AddObject(mayin);

            _OnImportExport(String.Format("Tạo {0}...", MAYIN), false);
            Data.MAYIN mayinBill = new Data.MAYIN();
            mayinBill.TenMayIn    = "Test";
            mayinBill.TieuDeIn    = "HÓA ĐƠN";
            mayinBill.SoLanIn     = 1;
            mayinBill.MayInHoaDon = true;
            mayinBill.Visual      = true;
            mKaraokeEntities.MAYINs.AddObject(mayinBill);

            _OnImportExport(String.Format("Tạo {0}...", DONVI), false);
            Data.DONVI donvi = mKaraokeEntities.DONVIs.Where(o => o.DonViID == 1).FirstOrDefault();
            if (donvi == null)
            {
                donvi          = new Data.DONVI();
                donvi.TenDonVi = "Số lượng";
                donvi.Visual   = true;
                mKaraokeEntities.DONVIs.AddObject(donvi);
            }

            _OnImportExport(String.Format("Tạo {0}...", LOAIDONVIBAN), false);
            Data.LOAIBAN loaiban = mKaraokeEntities.LOAIBANs.Where(o => o.LoaiBanID == 1).FirstOrDefault();
            if (loaiban == null)
            {
                loaiban.TenLoaiBan   = "Cái";
                loaiban.KichThuocBan = 1;
                loaiban.Visual       = true;
                mKaraokeEntities.LOAIBANs.AddObject(loaiban);
                donvi.LOAIBANs.Add(loaiban);
            }

            foreach (var item in listItem)
            {
                var nhom = (from a in listNhom
                            where a.TenNgan == item.TenNhom
                            select a).FirstOrDefault();
                if (nhom == null)
                {
                    _OnImportExport(String.Format("Tạo {0}---{1}", NHOM, item.TenNhom), false);
                    nhom        = new Data.MENUNHOM();
                    nhom.TenDai = nhom.TenNgan = item.TenNhom;
                    nhom.Visual = true;
                    mKaraokeEntities.MENUNHOMs.AddObject(nhom);
                    listNhom.Add(nhom);
                }
                var mon = (from a in nhom.MENUMONs
                           where a.TenNgan == item.TenMon
                           select a).FirstOrDefault();
                if (mon == null)
                {
                    _OnImportExport(String.Format("Tạo {0}---{1}", MON, item.TenMon), false);
                    mon         = new Data.MENUMON();
                    mon.TenNgan = mon.TenDai = item.TenMon;
                    mon.Gia     = item.DonGia;
                    mon.Visual  = true;
                    nhom.MENUMONs.Add(mon);
                    donvi.MENUMONs.Add(mon);
                    nhom.SLMonChoPhepTonKho++;
                    Data.MENUITEMMAYIN monmayin = new Data.MENUITEMMAYIN();
                    mon.MENUITEMMAYINs.Add(monmayin);
                    mayin.MENUITEMMAYINs.Add(monmayin);
                    mKaraokeEntities.MENUMONs.AddObject(mon);
                    //listMon.Add(mon);
                }
                _OnImportExport(String.Format("Tạo {0}---{1}", CHITIETMON, item.ChiTietMon), false);
                Data.MENUKICHTHUOCMON ktm = new Data.MENUKICHTHUOCMON();
                ktm.TenLoaiBan       = item.ChiTietMon;
                ktm.GiaBanMacDinh    = item.DonGia;
                ktm.SoLuongBanBan    = item.SoLuongBanMacDinh;
                ktm.KichThuocLoaiBan = 1;
                ktm.Visual           = true;
                ktm.ChoPhepTonKho    = true;
                mon.SLMonChoPhepTonKho++;
                mon.MENUKICHTHUOCMONs.Add(ktm);
                loaiban.MENUKICHTHUOCMONs.Add(ktm);
                donvi.MENUKICHTHUOCMONs.Add(ktm);
                mKaraokeEntities.MENUKICHTHUOCMONs.AddObject(ktm);
            }
            _OnImportExport(String.Format("Lưu dữ liệu..."), false);
            mKaraokeEntities.SaveChanges();
            _OnImportExport(String.Format("Lưu dữ liệu thành công ...{0}", url), false);
        }