Exemplo n.º 1
0
        public bool UpdateProduct(product product)
        {
            try
            {
                using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
                {
                    //data.products.Attach(product);
                    //data.Entry(product).State = EntityState.Modified;
                    //getItem.id = product.id;
                    var getItem = data.products.Single(p => p.id == product.id);//get the specific product

                    getItem.id_manufacturer = product.id_manufacturer;

                    getItem.id_save = product.id_save;

                    getItem.name = product.name;

                    getItem.sale_price = product.sale_price;

                    getItem.number = product.number;

                    getItem.image = product.image;

                    getItem.product_info = product.product_info;
                    data.SaveChanges();
                    return(true);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(false);
            }
        }
Exemplo n.º 2
0
 public bool DeleteProduct(int id)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             var product           = data.products.Single(p => p.id == id);
             var exportBill_Detail = data.export_bill_detail.Where(e => e.id_product == id).ToList();
             foreach (var item in exportBill_Detail)
             {
                 data.export_bill_detail.Remove(item);
             }
             var importBill_Detail = data.import_bill_detail.Where(i => i.id_product == id).ToList();
             foreach (var item in importBill_Detail)
             {
                 data.import_bill_detail.Remove(item);
             }
             data.products.Remove(product);
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }
Exemplo n.º 3
0
 public bool DeleteUser(int id)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             var user       = data.users.Single(u => u.id == id);
             var exportBill = data.export_bill.Where(e => e.id_user == id).ToList();
             foreach (var item in exportBill)
             {
                 var exportBill_Detail = data.export_bill_detail.Where(e => e.id_export_bill == item.id).ToList();
                 foreach (var item2 in exportBill_Detail)
                 {
                     data.export_bill_detail.Remove(item2);
                 }
                 data.export_bill.Remove(item);
             }
             data.users.Remove(user);
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }
Exemplo n.º 4
0
 public bool UpdateUser(user user)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             //Code first
             //data.Entry(user).State = EntityState.Modified;
             //data.SaveChanges();
             //return true;
             //////////// Code change
             var getItem = data.users.Single(p => p.id == user.id);
             getItem.id_role      = user.id_role;
             getItem.address      = user.address;
             getItem.email        = user.email;
             getItem.name         = user.name;
             getItem.password     = user.password;
             getItem.phone_number = user.phone_number;
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }
 public bool UpdateRole(role s)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             data.Entry(s).State = EntityState.Modified;
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }
 public bool AddRole(role s)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             data.roles.Add(s);
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }
 public bool AddSaveDate(Models.save_date s)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             data.save_date.Add(s);
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }
Exemplo n.º 8
0
 public bool AddProduct(product product)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             data.products.Add(product);
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }
Exemplo n.º 9
0
 public bool AddUser(user user)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             data.users.Add(user);
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }
 public bool AddExportBill_Detail(export_bill_detail eb)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             data.export_bill_detail.Add(eb);
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }
 public bool UpdateExportBill_Detail(export_bill_detail eb)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             data.Entry(eb).State = EntityState.Modified;
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }
 public bool AddImportBill(import_bill ib)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             data.import_bill.Add(ib);
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }
 public bool DeleteSaveDate(int id)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             var savedate = data.save_date.Single(s => s.id == id);
             data.save_date.Remove(savedate);
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }
Exemplo n.º 14
0
 public bool UpdateManufacturer(manufacturer s)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             //Test
             var getItem = data.manufacturers.Single(p => p.id == s.id);
             //data.Entry(s).State = EntityState.Modified;
             getItem = s;
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }
 public bool UpdateSaveDate(Models.save_date s)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             var saveDate = data.save_date.Single(p => p.id == s.id);
             saveDate.id         = s.id;
             saveDate.date_start = s.date_start;
             saveDate.date_end   = s.date_end;
             saveDate.id_save    = s.id_save;
             saveDate.content    = s.content;
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }
 public bool DeleteImportBill(int id)
 {
     try
     {
         using (QLBH_PHONE_ENTITY data = new QLBH_PHONE_ENTITY())
         {
             var my_data      = data.import_bill.Single(i => i.id == id);
             var importDetail = data.import_bill_detail.Where(i => i.id_import_bill == id).ToList();
             foreach (var item in importDetail)
             {
                 data.import_bill_detail.Remove(item);
             }
             data.import_bill.Remove(my_data);
             data.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(false);
     }
 }