Пример #1
0
        public T Create(T t)
        {
            DbSet.Add(t);

            Context.SaveChanges();

            return(t);
        }
Пример #2
0
        //页面加载
        //public static PageList getDepart(int pageIndex, int pageSize)
        //{
        //    WarehouseEntities con = new WarehouseEntities();
        //    PageList list = new PageList();
        //    var obj = from p in con.Depart
        //              where p.IsDelete == 0
        //              orderby p.Id
        //              select new
        //              {
        //                  Id = p.Id,
        //                  DepartNum = p.DepartNum,
        //                  DepartName = p.DepartName,
        //                  CreateTime = p.CreateTime
        //              };
        //    list.DataList = obj.Skip((pageIndex - 1) * pageSize).Take(pageSize);
        //    //设置总页数
        //    int rows = obj.Count();
        //    list.PageCount = rows; //rows % pageSize == 0 ? rows / pageSize : rows / pageSize + 1;

        //    return list;
        //}

        //新增
        public static int Add(Depart det)
        {
            WarehouseEntities con = new WarehouseEntities();

            con.Depart.Add(det);
            return(con.SaveChanges());
        }
Пример #3
0
        //新增
        public static int AddCustomer(Customer cus)
        {
            WarehouseEntities con = new WarehouseEntities();

            con.Customer.Add(cus);
            return(con.SaveChanges());
        }
Пример #4
0
        //新增
        public static int Add(Function fun)
        {
            WarehouseEntities con = new WarehouseEntities();

            con.Function.Add(fun);
            return(con.SaveChanges());
        }
Пример #5
0
        //新增
        public static int AddMeasure(Measure mes)
        {
            WarehouseEntities con = new WarehouseEntities();

            con.Measure.Add(mes);
            return(con.SaveChanges());
        }
Пример #6
0
        public static int Add(MoveReport b)
        {
            WarehouseEntities entity = new WarehouseEntities();

            entity.MoveReport.Add(b);
            return(entity.SaveChanges());
        }
        public DBResult DeleteAll(List <InventoryList> entities)
        {
            if (entities == null)
            {
                return(DBResult.WrongParameter);
            }

            using (var db = new WarehouseEntities())
            {
                foreach (var entity in entities)
                {
                    if (string.IsNullOrEmpty(entity.POID))
                    {
                        return(DBResult.WrongParameter);
                    }

                    var inventoryList = db.InventoryList.FirstOrDefault(l => l.POID == entity.POID);
                    if (inventoryList == null)
                    {
                        return(DBResult.NotFound);
                    }

                    db.InventoryList.Remove(inventoryList);
                }

                db.SaveChanges();
                return(DBResult.Succeed);
            }
        }
        public DBResult EditAll(List <InventoryList> entities)
        {
            if (entities == null)
            {
                return(DBResult.WrongParameter);
            }

            using (var db = new WarehouseEntities())
            {
                foreach (var entity in entities)
                {
                    if (EntityHelper.HasNullProperty(entity))
                    {
                        return(DBResult.WrongParameter);
                    }

                    var inventoryList = db.InventoryList.FirstOrDefault(l => l.POID == entity.POID);
                    if (inventoryList == null)
                    {
                        return(DBResult.NotFound);
                    }

                    EntityHelper.CopyEntity(entity, inventoryList);
                }

                db.SaveChanges();
                return(DBResult.Succeed);
            }
        }
        public void DeleteFromRepository(WarehouseLocation item)
        {
            if (_repositoryContext.GetEntityDescriptor(item) != null)
            {
                //if it exists in the db delete it from the db
                WarehouseEntities context = new WarehouseEntities(_rootUri);
                context.MergeOption = MergeOption.AppendOnly;
                context.IgnoreResourceNotFoundException = true;
                WarehouseLocation deletedWarehouseLocation = (from q in context.WarehouseLocations
                                                              where q.WarehouseLocationID == item.WarehouseLocationID
                                                              select q).FirstOrDefault();
                if (deletedWarehouseLocation != null)
                {
                    context.DeleteObject(deletedWarehouseLocation);
                    context.SaveChanges();
                }
                context = null;

                _repositoryContext.MergeOption = MergeOption.AppendOnly;
                //if it is being tracked remove it...
                if (GetWarehouseLocationEntityState(item) != EntityStates.Detached)
                {
                    _repositoryContext.Detach(item);
                }
            }
        }
Пример #10
0
        public static int Add(ReturnOrderStock b)
        {
            WarehouseEntities entity = new WarehouseEntities();

            entity.ReturnOrderStock.Add(b);
            return(entity.SaveChanges());
        }
Пример #11
0
        public static int AddCategory(ProductCategory pc)
        {
            WarehouseEntities entity = new WarehouseEntities();

            entity.ProductCategory.Add(pc);
            return(entity.SaveChanges());
        }
Пример #12
0
        public static int AddInStorage(InStorage ie)
        {
            WarehouseEntities entities = new WarehouseEntities();

            entities.InStorage.Add(ie);
            return(entities.SaveChanges());
        }
Пример #13
0
        /// <summary>
        /// Method that adds a new product to the database
        /// </summary>
        /// <param name="productToAdd">A specific product that is to be added</param>
        /// <returns>A product that was added to the database</returns>
        public Product AddProduct(Product productToAdd)
        {
            try
            {
                using (WarehouseEntities context = new WarehouseEntities())
                {
                    Product newProduct = new Product();
                    newProduct.ProductName    = productToAdd.ProductName;
                    newProduct.ProductCode    = productToAdd.ProductCode;
                    newProduct.ProductAmmount = 0;
                    newProduct.Price          = productToAdd.Price;
                    newProduct.InStock        = "NO";

                    context.Products.Add(newProduct);
                    context.SaveChanges();

                    logger.WriteToFile(DateTime.Now + "/ Added new product named " + productToAdd.ProductName + " ,code " + productToAdd.ProductCode + ".");

                    return(newProduct);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception " + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }
        }
Пример #14
0
        /// <summary>
        /// Updates a specific product
        /// </summary>
        /// <param name="product">A product with the changes that need to be saved</param>
        /// <returns>A changed product</returns>
        public Product UpdateProduct(Product product)
        {
            try
            {
                using (WarehouseEntities context = new WarehouseEntities())
                {
                    Product productToUpdate = (from p in context.Products where p.ProductID == product.ProductID select p).FirstOrDefault();
                    productToUpdate.ProductName = product.ProductName;
                    productToUpdate.ProductCode = product.ProductCode;
                    productToUpdate.Price       = product.Price;
                    if (product.ProductAmmount > 100 || product.ProductAmmount < 1)
                    {
                        productToUpdate.InStock        = "NO";
                        productToUpdate.ProductAmmount = 0;
                    }
                    else
                    {
                        productToUpdate.InStock        = "YES";
                        productToUpdate.ProductAmmount = product.ProductAmmount;
                    }
                    context.SaveChanges();

                    logger.WriteToFile(DateTime.Now + "/ Updated product named " + productToUpdate.ProductName + " ,code " + productToUpdate.ProductCode + " to " + product.ProductName + " ,code " + product.ProductCode + ". Ammount is " + product.ProductAmmount + ".");

                    return(product);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception " + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }
        }
Пример #15
0
        //修改产品状态(删除)
        public static int DelCategory(ProductCategory pc)
        {
            WarehouseEntities entity = new WarehouseEntities();
            var obj = (from p in entity.ProductCategory where p.Id == pc.Id select p).First();

            obj.IsDelete = pc.IsDelete;
            return(entity.SaveChanges());
        }
Пример #16
0
        //删除(修改表示ID)
        public static int delDepart(int id)
        {
            WarehouseEntities con = new WarehouseEntities();
            var obj = (from p in con.Depart where p.Id == id select p).First();

            obj.IsDelete = 1;
            return(con.SaveChanges());
        }
Пример #17
0
        //删除(修改表示ID)
        public static int delFunction(Function fun, int id)
        {
            WarehouseEntities con = new WarehouseEntities();
            var obj = (from p in con.Function where p.NodeId == id select p).First();

            obj.IsDelete = 1;
            return(con.SaveChanges());
        }
Пример #18
0
        //删除(修改表示ID)
        public static int delRole(int id)
        {
            WarehouseEntities entities = new WarehouseEntities();
            var obj = (from p in entities.Role where p.Id == id select p).First();

            obj.IsDelete = 1;
            return(entities.SaveChanges());
        }
Пример #19
0
        //修改
        public static int update(string id, string RoleName, string Remark)
        {
            WarehouseEntities entities = new WarehouseEntities();
            var obj = (from p in entities.Role where p.RoleNum == id select p).First();

            obj.RoleName = RoleName;
            obj.Remark   = Remark;
            return(entities.SaveChanges());
        }
Пример #20
0
        public static int ReturnOrderStockDel(string ReturnNum)
        {
            WarehouseEntities entity = new WarehouseEntities();
            var obj = (from p in entity.ReturnOrderStock where p.ReturnNum == ReturnNum select p).First();

            //修改
            obj.IsDelete = 1;
            return(entity.SaveChanges());
        }
Пример #21
0
        public static int MoveReportDel(string MoveNum)
        {
            WarehouseEntities entity = new WarehouseEntities();
            var obj = (from p in entity.MoveReport where p.MoveNum == MoveNum select p).First();

            //修改
            obj.IsDelete = 1;
            return(entity.SaveChanges());
        }
Пример #22
0
        //根据id修改
        public static int upMeasureById(Measure mes, int id)
        {
            WarehouseEntities con = new WarehouseEntities();
            var obj = (from p in con.Measure where p.Id == id select p).First();

            obj.MeasureName = mes.MeasureName;
            obj.CreateTime  = DateTime.Now;
            return(con.SaveChanges());
        }
Пример #23
0
        //根据id修改
        public static int upDepartById(string DepartName, int id)
        {
            WarehouseEntities con = new WarehouseEntities();
            var obj = (from p in con.Depart where p.Id == id select p).First();

            obj.DepartName = DepartName;
            obj.CreateTime = DateTime.Now;;
            return(con.SaveChanges());
        }
Пример #24
0
        public static int update(string name, string pwd)
        {
            WarehouseEntities entities = new WarehouseEntities();

            entities.Configuration.ProxyCreationEnabled = false;
            var obj = (from p in entities.Admin where p.UserName == name select p).First();

            obj.Password = pwd;
            return(entities.SaveChanges());
        }
Пример #25
0
        //根据id修改
        public static int upFunctionById(Function fun, int id)
        {
            WarehouseEntities con = new WarehouseEntities();
            var obj = (from p in con.Function where p.NodeId == id select p).First();

            obj.DisplayName = fun.DisplayName;
            obj.NodeURL     = fun.NodeURL;
            obj.CreateTime  = DateTime.Now;;
            return(con.SaveChanges());
        }
Пример #26
0
        //修改
        public static int adminidup(string id, string UserName, string RealName, string Email, string Phone, int DepartId, int RoleId)
        {
            WarehouseEntities entities = new WarehouseEntities();
            var obj = (from p in entities.Admin where p.UserCode == id select p).First();

            obj.UserName = UserName;
            obj.RealName = RealName;
            obj.Email    = Email;
            obj.Phone    = Phone;
            obj.DepartId = DepartId;
            obj.RoleId   = RoleId;
            return(entities.SaveChanges());
        }
Пример #27
0
        //新增
        public static int insert(string RoleNum, string RoleName, string Remark)
        {
            WarehouseEntities entities = new WarehouseEntities();
            var obj = new Role();

            obj.RoleNum    = RoleNum;
            obj.RoleName   = RoleName;
            obj.Remark     = Remark;
            obj.CreateTime = DateTime.Now;
            obj.IsDelete   = 0;
            entities.Role.Add(obj);
            return(entities.SaveChanges());
        }
Пример #28
0
        public int SaveChanges()
        {
            try
            {
                return(context.SaveChanges());
            }
            catch (DbEntityValidationException ex)
            {
                var exceptionMessage = ExceptionHandler(ex);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
        }
Пример #29
0
        public static int MoveReportEdit(MoveReport p)
        {
            WarehouseEntities entity = new WarehouseEntities();
            //先修改主表数据
            var obj = entity.MoveReport.Find(p.Id);

            obj.MoveTypeId = p.MoveTypeId;
            obj.ProductId  = p.ProductId;
            obj.Num        = p.Num;
            obj.Status     = p.Status;
            obj.AuditUser  = p.AuditUser;
            obj.AuditTime  = p.AuditTime;
            return(entity.SaveChanges());
        }
Пример #30
0
        public static int ReturnOrderStockEdit(ReturnOrderStock p)
        {
            WarehouseEntities entity = new WarehouseEntities();
            //先修改主表数据
            var obj = entity.ReturnOrderStock.Find(p.Id);

            obj.ReturnTypeId = p.ReturnTypeId;
            obj.ProductId    = p.ProductId;
            obj.Num          = p.Num;
            obj.Status       = p.Status;
            obj.Operation    = p.Operation;
            obj.AuditUser    = p.AuditUser;
            obj.AuditTime    = p.AuditTime;
            return(entity.SaveChanges());
        }