Exemplo n.º 1
0
        /// <summary>
        /// 获取报警记录
        /// </summary>
        /// <param name="totalCount">总的数量</param>
        /// <param name="searchName">查找字段</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每一页显示多少条</param>
        /// <param name="orderEnum">排序枚举</param>
        /// <param name="ascending">标示正反排序的字段</param>
        /// <param name="searchStartTime">搜索开始时间</param>
        /// <param name="searchEndTime">搜索结束时间</param>
        /// <returns></returns>
        public CResult <List <WebAlarm> > GetAllAlarm(out int totalCount, string searchName = "", int pageIndex = 1, int pageSize = 100, AlarmOrderEnum orderEnum = AlarmOrderEnum.AlarmTime, bool ascending = false, DateTime?searchStartTime = null, DateTime?searchEndTime = null)
        {
            totalCount = 0;
            using (var db = new WarehouseContext()) {
                Expression <Func <Alarm, bool> > filter = r => true;
                if (searchStartTime.HasValue)
                {
                    filter = filter.And(r => r.AlarmTime >= searchStartTime);
                }
                if (searchEndTime.HasValue)
                {
                    var endTime = searchEndTime.Value.AddDays(1);
                    filter = filter.And(r => r.AlarmTime < endTime);
                }

                var alarmIQuery = RepositoryIoc.GetAlarmRepository(db).Get(out totalCount, filter, null, orderEnum.ToString(), ascending, pageIndex, pageSize);
                var result      = new List <WebAlarm>();
                foreach (var item in alarmIQuery)
                {
                    result.Add(new WebAlarm()
                    {
                        AlarmTypeInt  = item.AlarmTypeInt,
                        AlarmContent  = item.AlarmContent,
                        AlarmTime     = item.AlarmTime,
                        Operator      = item.Operator,
                        AlarmTypeName = ((AlarmType)item.AlarmTypeInt).ToString(),
                    });
                }
                return(new CResult <List <WebAlarm> >(result));
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 添加部门
 /// </summary>
 /// <param name="departmentName">部门名称</param>
 /// <returns></returns>
 public CResult <bool> AddDepartment(string departmentName)
 {
     if (string.IsNullOrWhiteSpace(departmentName))
     {
         return(new CResult <bool>(false, ErrorCode.ParameterError));
     }
     using (var db = new WarehouseContext()) {
         var repository = RepositoryIoc.GetDepartmentRepository(db);
         var department = repository.FirstOrDefault(r => r.DepartmentName == departmentName);
         if (department == null)
         {
             department = new Department();
             department.DepartmentName = departmentName;
             repository.Insert(department);
             if (db.SaveChanges() > 0)
             {
                 _department.Add(department);
                 return(new CResult <bool>(true));
             }
             else
             {
                 return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
             }
         }
         return(new CResult <bool>(false, ErrorCode.DepartmentHasExist));
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 保存出库订单表
        /// </summary>
        /// <param name="webOrder"></param>
        /// <returns></returns>
        public static CResult <int> SaveRemalWarehouseOrder(WebRemovalWarehouseOrder webOrder)
        {
            if (string.IsNullOrWhiteSpace(webOrder.SpeedChangeBoxName) || webOrder.Count <= 0)
            {
                return(new CResult <int>(-1, ErrorCode.ParameterError));
            }
            using (var db = new WarehouseContext())
            {
                var order = new RemovalWarehouseOrder();
                order.DispathPlace       = webOrder.DispathPlace;
                order.DispathTime        = DateTime.Now;
                order.SpeedChangeBoxName = webOrder.SpeedChangeBoxName;
                order.Staff     = webOrder.Staff;
                order.StateID   = (int)RecordState.Show;
                order.PlanCount = webOrder.PlanCount;

                RepositoryIoc.GetRemovalWarehouseOrderRepository(db).Insert(order);
                if (db.SaveChanges() > 0)
                {
                    return(new CResult <int>(order.OrderID));
                }
                else
                {
                    return(new CResult <int>(-1, ErrorCode.SaveDbChangesFailed));
                }
            }
        }
        public CResult <bool> AddSpeedChangeBoxType(string speedChangeBoxName)
        {
            if (string.IsNullOrWhiteSpace(speedChangeBoxName))
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }
            using (var db = new WarehouseContext()) {
                var repository = RepositoryIoc.GetSpeedChangeBoxTypeRepository(db);
                if (repository.Count(r => r.SpeedChangeBoxName == speedChangeBoxName) > 0)
                {
                    return(new CResult <bool>(false, ErrorCode.SpeedChangeBoxHasExist));
                }

                var speedChangeBox = new SpeedChangeBoxType();
                speedChangeBox.SpeedChangeBoxName = speedChangeBoxName;
                repository.Insert(speedChangeBox);
                if (db.SaveChanges() > 0)
                {
                    return(new CResult <bool>(true));
                }
                else
                {
                    return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// 修改部门
 /// </summary>
 /// <param name="departmentName"></param>
 /// <param name="departmentID"></param>
 /// <returns></returns>
 public CResult <bool> UpdateDepartment(string departmentName, int departmentID)
 {
     if (string.IsNullOrWhiteSpace(departmentName))
     {
         return(new CResult <bool>(false, ErrorCode.ParameterError));
     }
     using (var db = new WarehouseContext()) {
         var repository = RepositoryIoc.GetDepartmentRepository(db);
         var department = repository.FirstOrDefault(r => r.DepartmentID == departmentID);
         if (department == null)
         {
             return(new CResult <bool>(false, ErrorCode.DepartmentHasNoExist));
         }
         department.DepartmentName = departmentName;
         if (repository.Update(department) == EntityState.Modified)
         {
             if (db.SaveChanges() > 0)
             {
                 return(new CResult <bool>(true));
             }
             else
             {
                 return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
             }
         }
         else
         {
             return(new CResult <bool>(true));
         }
     }
 }
        public CResult <bool> DelSpeedChangeBox(int speedChangeID)
        {
            if (speedChangeID <= 0)
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }
            using (var db = new WarehouseContext()) {
                var repository = RepositoryIoc.GetSpeedChangeBoxTypeRepository(db);

                var speedChange = repository.FirstOrDefault(r => r.SpeedChangeBoxTypeID == speedChangeID, CommonHelper.GetPropName <SpeedChangeBoxType>(r => r.TwoDimensioncodes));
                if (speedChange.TwoDimensioncodes.Count() > 0)
                {
                    return(new CResult <bool>(false, ErrorCode.SpeedChangeHasTwoDimensioncodes));
                }
                repository.Delete(speedChange);
                if (db.SaveChanges() > 0)
                {
                    return(new CResult <bool>(true));
                }
                else
                {
                    return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
                }
            }
        }
Exemplo n.º 7
0
        public CResult <bool> AddUser(WebUserInfo webUser)
        {
            if (string.IsNullOrWhiteSpace(webUser.UserName))
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }
            using (var db = new WarehouseContext()) {
                MembershipCreateStatus status;
                var user  = Membership.CreateUser(webUser.UserName, webUser.PassWord, null, null, null, true, out status);
                var roles = new List <string>();
                if (webUser.IsMonitor)
                {
                    roles.Add(PermissionEnum.班长.ToString());
                }
                if (webUser.IsPutinMan)
                {
                    roles.Add(PermissionEnum.入库员.ToString());
                }
                if (webUser.IsRemovalMan)
                {
                    roles.Add(PermissionEnum.出库员.ToString());
                }

                if (status == MembershipCreateStatus.Success)
                {
                    if (roles.Count() > 0)
                    {
                        Roles.AddUserToRoles(user.UserName, roles.ToArray());
                    }
                    var userInfo = new UsersInfo();
                    userInfo.ID           = (int)user.ProviderUserKey;
                    userInfo.Adress       = webUser.Adress;
                    userInfo.DepartmentID = webUser.DepartmentID;
                    userInfo.StateID      = (int)RecordState.Show;
                    userInfo.Phone        = webUser.Phone;
                    RepositoryIoc.GetUsersInfoRepository(db).Insert(userInfo);
                    if (db.SaveChanges() > 0)
                    {
                        return(new CResult <bool>(true));
                    }
                    else
                    {
                        return(new CResult <bool>(false, ErrorCode.AddUserInfoFailed));
                    }
                }
                else
                {
                    //Membership.DeleteUser(user.UserName, true);
                    return(new CResult <bool>(false, 1, status.ToString()));
                }
            }
        }
Exemplo n.º 8
0
 public CResult <string> TwoDimensionCodeByBarID(int barCodeID)
 {
     using (var db = new WarehouseContext())
     {
         var warehouse = RepositoryIoc.GetWarehouseMRepository(db).FirstOrDefault(r => r.WarehouseID == barCodeID && r.StateID == (int)RecordState.Show, CommonHelper.GetPropName <WarehouseM>(r => r.TwoDimensioncode));
         if (warehouse == null)
         {
             return(new CResult <string>(string.Empty, ErrorCode.BarCodeNotExist));
         }
         var twoDimensioncode = warehouse.TwoDimensioncode;
         var codeType         = warehouse.TwoDimensioncode.SpeedChangeBoxType.SpeedChangeBoxName;
         return(new CResult <string>(codeType + "~" + twoDimensioncode.TwoDimensionCodeNum));
     }
 }
 public CResult <List <WebSpeedChangeBoxType> > GetSpeedChangeBoxList()
 {
     using (var db = new WarehouseContext()) {
         var speedChangeList = RepositoryIoc.GetSpeedChangeBoxTypeRepository(db).Get();
         var result          = new List <WebSpeedChangeBoxType>();
         foreach (var item in speedChangeList)
         {
             result.Add(new WebSpeedChangeBoxType()
             {
                 SpeedChangeBoxTypeID = item.SpeedChangeBoxTypeID,
                 SpeedChangeBoxName   = item.SpeedChangeBoxName,
             });
         }
         return(new CResult <List <WebSpeedChangeBoxType> >(result));
     }
 }
Exemplo n.º 10
0
 public static CResult <int> GetDepartmentIDByUserName(string userName)
 {
     if (string.IsNullOrWhiteSpace(userName))
     {
         return(new CResult <int>(-1, ErrorCode.ParameterError));
     }
     using (var db = new WarehouseContext()) {
         var user     = Membership.GetUser(userName);
         var id       = (int)user.ProviderUserKey;
         var userInfo = RepositoryIoc.GetUsersInfoRepository(db).FirstOrDefault(r => r.ID == id);
         if (userInfo == null)
         {
             return(new CResult <int>(-1, ErrorCode.UserInfoNoExist));
         }
         return(new CResult <int>(userInfo.DepartmentID.Value));
     }
 }
Exemplo n.º 11
0
        public CResult <List <WebUserInfo> > GetUserInfoListByDepartment(string userName)
        {
            using (var db = new WarehouseContext()) {
                MembershipUserCollection users = Membership.GetAllUsers();
                var userInfoRepository         = RepositoryIoc.GetUsersInfoRepository(db);
                var role            = Roles.GetRolesForUser(userName);
                var currentUser     = Membership.GetUser(userName);
                var currentUserInfo = userInfoRepository.FirstOrDefault(r => r.ID == (int)currentUser.ProviderUserKey);
                if (currentUserInfo == null)
                {
                    return(new CResult <List <WebUserInfo> >(new List <WebUserInfo>(), ErrorCode.UserInfoNoExist));
                }

                var currentDepartmentID = currentUserInfo.DepartmentID;
                var userInfos           = new List <WebUserInfo>();

                foreach (MembershipUser item in users)
                {
                    var userID = (int)item.ProviderUserKey;
                    var info   = userInfoRepository.FirstOrDefault(r => r.ID == userID && r.StateID == (int)RecordState.Show, CommonHelper.GetPropName <UsersInfo>(r => r.Department));
                    if (info == null)
                    {
                        continue;
                    }
                    var currentRoles = Roles.GetRolesForUser(item.UserName);
                    if ((role.Contains(PermissionEnum.系统管理员.ToString()) && currentRoles.Contains(PermissionEnum.班长.ToString())) ||
                        (info.DepartmentID == currentDepartmentID && !currentRoles.Contains(PermissionEnum.班长.ToString()) && !currentRoles.Contains(PermissionEnum.系统管理员.ToString())))
                    {
                        userInfos.Add(new WebUserInfo()
                        {
                            ID             = userID,
                            UserName       = (item.UserName),
                            Phone          = info.Phone,
                            DepartmentID   = info.DepartmentID,
                            DepartmentName = info.Department.DepartmentName,
                            Adress         = info.Adress,
                            IsMonitor      = currentRoles.Contains(PermissionEnum.班长.ToString()),
                            IsRemovalMan   = currentRoles.Contains(PermissionEnum.出库员.ToString()),
                            IsPutinMan     = currentRoles.Contains(PermissionEnum.入库员.ToString()),
                        });
                    }
                }
                return(new CResult <List <WebUserInfo> >(userInfos));
            }
        }
Exemplo n.º 12
0
 public CResult <string> TwoDimensionCodeByBarCode(string barCode)
 {
     barCode = barCode.Trim();
     if (string.IsNullOrWhiteSpace(barCode))
     {
         return(new CResult <string>(string.Empty, ErrorCode.ParameterError));
     }
     using (var db = new WarehouseContext())
     {
         var warehouse = RepositoryIoc.GetWarehouseMRepository(db).FirstOrDefault(r => r.BarCode == barCode && r.StateID == (int)RecordState.Show, CommonHelper.GetPropName <WarehouseM>(r => r.TwoDimensioncode));
         if (warehouse == null)
         {
             return(new CResult <string>(string.Empty, ErrorCode.BarCodeNotExist));
         }
         var twoDimensioncode = warehouse.TwoDimensioncode;
         return(new CResult <string>(twoDimensioncode.TwoDimensionCodeNum));
     }
 }
Exemplo n.º 13
0
 /// <summary>
 /// 添加报警
 /// </summary>
 /// <param name="webAlarm"></param>
 /// <returns></returns>
 public CResult <bool> AddAlarm(WebAlarm webAlarm)
 {
     using (var db = new WarehouseContext()) {
         var alarm = new Alarm();
         alarm.AlarmContent = webAlarm.AlarmContent;
         alarm.AlarmTime    = DateTime.Now;
         alarm.AlarmTypeInt = webAlarm.AlarmTypeInt;
         alarm.Operator     = webAlarm.Operator;
         RepositoryIoc.GetAlarmRepository(db).Insert(alarm);
         if (db.SaveChanges() > 0)
         {
             return(new CResult <bool>(true));
         }
         else
         {
             return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
         }
     }
 }
Exemplo n.º 14
0
 /// <summary>
 /// 判断当前的扫描的产品是第一次入库还是重复入库
 /// </summary>
 /// <param name="barCode"></param>
 /// <returns></returns>
 public static PutInResultEnum IsCurrentPutInInfoRight(string barCode)
 {
     using (var db = new WarehouseContext())
     {
         var warehouse = RepositoryIoc.GetWarehouseMRepository(db).FirstOrDefault(r => r.BarCode == barCode);
         if (warehouse == null)
         {
             return(PutInResultEnum.第一次入库);
         }
         if (warehouse.StateID == (int)RecordState.Delete)
         {
             return(PutInResultEnum.重复入库);
         }
         else
         {
             return(PutInResultEnum.仓库已经存在此货物);
         }
     }
 }
Exemplo n.º 15
0
        public CResult <WebUserInfo> GetUserInfoByUserID(int userID)
        {
            if (userID <= 0)
            {
                return(new CResult <WebUserInfo>(new WebUserInfo(), ErrorCode.ParameterError));
            }

            using (var db = new WarehouseContext()) {
                var user     = Membership.GetUser(userID);
                var userInfo = RepositoryIoc.GetUsersInfoRepository(db).FirstOrDefault(r => r.StateID == (int)RecordState.Show &&
                                                                                       r.ID == (int)user.ProviderUserKey, CommonHelper.GetPropName <UsersInfo>(r => r.Department));
                if (userInfo == null)
                {
                    return(new CResult <WebUserInfo>(new WebUserInfo(), ErrorCode.UserInfoNoExist));
                }

                var webUserInfo = ConverToWebUser(user, userInfo);

                return(new CResult <WebUserInfo>(webUserInfo));
            }
        }
Exemplo n.º 16
0
        public CResult <bool> DeleteUserByID(int userID)
        {
            if (userID <= 0)
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }
            using (var db = new WarehouseContext()) {
                var user = Membership.GetUser(userID);
                if (user == null)
                {
                    return(new CResult <bool>(false, ErrorCode.UserNoExist));
                }
                user.IsApproved = false;
                Membership.UpdateUser(user);

                var repository = RepositoryIoc.GetUsersInfoRepository(db);
                var info       = repository.FirstOrDefault(r => r.ID == (int)user.ProviderUserKey);
                if (info.StateID == (int)RecordState.Delete)
                {
                    return(new CResult <bool>(false, ErrorCode.UserHasDeleted));
                }
                info.StateID = (int)RecordState.Delete;
                if (repository.Update(info) == EntityState.Modified)
                {
                    if (db.SaveChanges() > 0)
                    {
                        return(new CResult <bool>(true));
                    }
                    else
                    {
                        return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
                    }
                }
                else
                {
                    return(new CResult <bool>(true));
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// 保存二维码信息
        /// </summary>
        /// <param name="twoDimensioncodeNum"></param>
        /// <param name="warehouseIDs"></param>
        /// <param name="speedChangeTypeID"></param>
        /// <returns></returns>
        public static CResult <bool> SaveTwoDimensioncode(string twoDimensioncodeNum, IEnumerable <int> warehouseIDs, int speedChangeTypeID)
        {
            if (string.IsNullOrWhiteSpace(twoDimensioncodeNum))
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }

            using (var db = new WarehouseContext())
            {
                var twoDimensioncodeRepository = RepositoryIoc.GetTwoDimensioncodeRepository(db);
                var twoDimensionCode           = twoDimensioncodeRepository.FirstOrDefault(r => r.TwoDimensionCodeNum == twoDimensioncodeNum);
                if (twoDimensionCode == null)
                {
                    twoDimensionCode = new TwoDimensioncode();
                    twoDimensionCode.TwoDimensionCodeNum = twoDimensioncodeNum;
                    twoDimensionCode.Count = warehouseIDs.Count();
                    twoDimensionCode.SpeedChangeBoxTypeID = speedChangeTypeID;
                }
                else
                {
                    return(new CResult <bool>(false, ErrorCode.TwoDimensioncodeHasExist));
                }
                if (db.SaveChanges() > 0)
                {
                    var warehouseRepository = RepositoryIoc.GetWarehouseMRepository(db);
                    var warehouseList       = warehouseRepository.Get(r => warehouseIDs.Contains(r.WarehouseID));
                    foreach (var item in warehouseList)
                    {
                        item.TwoDimensioncodeID = twoDimensionCode.TwoDimensioncodeID;
                    }
                    return(new CResult <bool>(db.SaveChanges() > 0));
                }
                else
                {
                    return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
                }
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// 根据ID删除部门
 /// </summary>
 /// <param name="departmentID">部门ID</param>
 /// <returns></returns>
 public CResult <bool> DeleteDepartmentByID(int departmentID)
 {
     using (var db = new WarehouseContext()) {
         var repository = RepositoryIoc.GetDepartmentRepository(db);
         var department = repository.FirstOrDefault(r => r.DepartmentID == departmentID);
         if (department == null)
         {
             return(new CResult <bool>(false, ErrorCode.DepartmentHasNoExist));
         }
         if (RepositoryIoc.GetUsersInfoRepository(db).Count(r => r.DepartmentID == departmentID) > 0)
         {
             return(new CResult <bool>(false, ErrorCode.DepartmentHasUser));
         }
         repository.Delete(department);
         if (db.SaveChanges() > 0)
         {
             return(new CResult <bool>(true));
         }
         else
         {
             return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
         }
     }
 }
Exemplo n.º 19
0
 /// <summary>
 /// 获取部门列表
 /// </summary>
 /// <returns></returns>
 public List <WebDepartment> GetAllDepartment()
 {
     using (var db = new WarehouseContext()) {
         List <Department> departments;
         if (_department == null || _department.Count() == 0)
         {
             departments = RepositoryIoc.GetDepartmentRepository(db).Get().ToList();
         }
         else
         {
             departments = _department;
         }
         var result = new List <WebDepartment>();
         foreach (var item in departments)
         {
             result.Add(new WebDepartment()
             {
                 DepartmentID   = item.DepartmentID,
                 DepartmentName = item.DepartmentName
             });
         }
         return(result);
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// 保存出库记录表
        /// </summary>
        /// <param name="currentArrayCount"></param>
        /// <param name="twoDimensionCode"></param>
        /// <param name="orderID"></param>
        /// <param name="speedChangeBoxID"></param>
        /// <param name="planTotoalCount"></param>
        /// <param name="totalCount"></param>
        /// <param name="isForceRemoval"></param>
        /// <returns></returns>
        public static RemovalResultEnum SaveRemalWarehouseInfo(out List <WebPutInWarehouseRecord> barCodeList, out int currentArrayCount, string twoDimensionCode, int orderID, int speedChangeBoxID, int planTotoalCount, int totalCount, bool isForceRemoval = false)
        {
            currentArrayCount = 0;
            barCodeList       = new List <WebPutInWarehouseRecord>();
            if (string.IsNullOrWhiteSpace(twoDimensionCode))
            {
                return(RemovalResultEnum.参数错误);
            }
            using (var db = new WarehouseContext())
            {
                var twoDimensionCodeList = RepositoryIoc.GetTwoDimensioncodeRepository(db).FirstOrDefault(r => r.TwoDimensionCodeNum == twoDimensionCode && r.StateID == (int)RecordState.Show, string.Format("{0},{1}", CommonHelper.GetPropName <TwoDimensioncode>(r => r.WarehouseMs), CommonHelper.GetPropName <TwoDimensioncode>(r => r.SpeedChangeBoxType)));
                if (twoDimensionCodeList == null)
                {
                    return(RemovalResultEnum.此二维码信息不存在);
                }

                if (twoDimensionCodeList.SpeedChangeBoxType.SpeedChangeBoxTypeID != speedChangeBoxID)
                {
                    return(RemovalResultEnum.变速箱型号不一致);
                }

                var warehouseList = twoDimensionCodeList.WarehouseMs;
                var removalWarehouseRepository = RepositoryIoc.GetRemovalWarehourseRecordRepository(db);
                var order = RepositoryIoc.GetRemovalWarehouseOrderRepository(db).FirstOrDefault(r => r.OrderID == orderID);
                if (order == null)
                {
                    return(RemovalResultEnum.出库订单信息不存在);
                }

                currentArrayCount = warehouseList.Count();

                foreach (var item in warehouseList)
                {
                    var removalWarehouse = new RemovalWarehouseRecord();
                    if (removalWarehouse.StateID == (int)RecordState.Delete)
                    {
                        return(RemovalResultEnum.当前二维码已经出库);
                    }

                    removalWarehouse.StateID              = (int)RecordState.Show;
                    removalWarehouse.WarehouseID          = item.WarehouseID;
                    removalWarehouse.RemovalWarehouseTime = DateTime.Now;
                    removalWarehouse.OrderID              = order.OrderID;
                    removalWarehouseRepository.Insert(removalWarehouse);
                    removalWarehouse.RemovalWarehouseTime = DateTime.Now;
                    item.StateID = (int)RecordState.Delete;

                    barCodeList.Add(new WebPutInWarehouseRecord()
                    {
                        BarCode       = item.BarCode,
                        Place         = item.Place,
                        PutInUserName = item.PutInUserName,
                        PutInTime     = item.WarehouseTime,
                    });
                }

                if (!isForceRemoval)
                {
                    if (currentArrayCount + totalCount > planTotoalCount)
                    {
                        return(RemovalResultEnum.当前出库数量已经大于设置的出库数量);
                    }
                }

                twoDimensionCodeList.StateID = (int)RecordState.Delete;
                if (db.SaveChanges() > 0)
                {
                    return(RemovalResultEnum.执行成功);
                }
                barCodeList.Clear();
                return(RemovalResultEnum.保存失败);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// 根据订单ID获得出库记录表
        /// </summary>
        /// <param name="orderID"></param>
        /// <param name="totalCount"></param>
        /// <param name="searchName"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="orderEnum"></param>
        /// <param name="ascending"></param>
        /// <returns></returns>
        public CResult <List <WebRemovalWarehouse> > GetRemovalWarehouseInfoListByOrderID(int orderID, out int totalCount, string searchName = "", int pageIndex = -1, int pageSize = 100, RemovalListOrderEnum orderEnum = RemovalListOrderEnum.DispathTime, bool ascending = false)
        {
            totalCount = 0;
            using (var db = new WarehouseContext())
            {
                Expression <Func <RemovalWarehouseRecord, bool> > filter = r => r.StateID == (int)RecordState.Show;
                filter = filter.And(r => r.OrderID == orderID);
                if (!string.IsNullOrWhiteSpace(searchName))
                {
                    filter = filter.And(r => r.RemovalWarehouseOrder.Staff.Contains(searchName) ||
                                        r.WarehouseM.BarCode.Contains(searchName) ||
                                        r.RemovalWarehouseOrder.DispathPlace.Contains(searchName));
                }
                var removalWareIQueary = RepositoryIoc.GetRemovalWarehourseRecordRepository(db).LazyGet(out totalCount, filter, CommonHelper.GetPropName <RemovalWarehouseRecord>(r => r.WarehouseM));
                switch (orderEnum)
                {
                case RemovalListOrderEnum.BarCode:
                    if (ascending)
                    {
                        removalWareIQueary = removalWareIQueary.OrderBy(r => r.WarehouseM.BarCode);
                    }
                    else
                    {
                        removalWareIQueary = removalWareIQueary.OrderByDescending(r => r.WarehouseM.BarCode);
                    }
                    break;

                case RemovalListOrderEnum.DispathPlace:
                    if (ascending)
                    {
                        removalWareIQueary = removalWareIQueary.OrderBy(r => r.RemovalWarehouseOrder.DispathPlace);
                    }
                    else
                    {
                        removalWareIQueary = removalWareIQueary.OrderByDescending(r => r.RemovalWarehouseOrder.DispathPlace);
                    }
                    break;

                case RemovalListOrderEnum.DispathTime:
                    if (ascending)
                    {
                        removalWareIQueary = removalWareIQueary.OrderBy(r => r.RemovalWarehouseTime);
                    }
                    else
                    {
                        removalWareIQueary = removalWareIQueary.OrderByDescending(r => r.RemovalWarehouseTime);
                    }
                    break;

                case RemovalListOrderEnum.Staff:
                    if (ascending)
                    {
                        removalWareIQueary = removalWareIQueary.OrderBy(r => r.RemovalWarehouseOrder.Staff);
                    }
                    else
                    {
                        removalWareIQueary = removalWareIQueary.OrderByDescending(r => r.RemovalWarehouseOrder.Staff);
                    }
                    break;
                }
                removalWareIQueary = removalWareIQueary.Page(out totalCount, null, true, pageIndex, pageSize);
                var result = (from f in removalWareIQueary
                              select new WebRemovalWarehouse()
                {
                    BarCode = f.WarehouseM.BarCode,
                    RemovalWarehouseTime = f.RemovalWarehouseTime,
                    SpeedChangeBoxName = f.WarehouseM.TwoDimensioncode.SpeedChangeBoxType.SpeedChangeBoxName,
                    Staff = f.RemovalWarehouseOrder.Staff,
                    DispathPlace = f.RemovalWarehouseOrder.DispathPlace,
                }).ToList();
                return(new CResult <List <WebRemovalWarehouse> >(result));
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// 获得出库订单表
        /// </summary>
        /// <param name="totalCount"></param>
        /// <param name="searchName"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="orderEnum"></param>
        /// <param name="ascending"></param>
        /// <returns></returns>
        public CResult <List <WebRemovalWarehouseOrder> > GetRemovalWarehouseOrderList(out int totalCount, string searchName = "", int pageIndex = -1, int pageSize = 100,
                                                                                       WarehouseOrderOrderEnum orderEnum     = WarehouseOrderOrderEnum.DispathTime, bool ascending = false, DateTime?searchStarttime = null,
                                                                                       DateTime?searchEndTime = null)
        {
            totalCount = 0;
            using (var db = new WarehouseContext())
            {
                Expression <Func <RemovalWarehouseOrder, bool> > filter = r => r.StateID == (int)RecordState.Show &&
                                                                          r.RemovalWarehouseRecords.Count > 0;
                if (!string.IsNullOrWhiteSpace(searchName))
                {
                    filter = filter.And(r => r.Staff.Contains(searchName) ||
                                        r.SpeedChangeBoxName.Contains(searchName) ||
                                        r.DispathPlace.Contains(searchName));
                }
                if (searchStarttime.HasValue)
                {
                    filter = filter.And(r => r.DispathTime >= searchStarttime);
                }
                if (searchEndTime.HasValue)
                {
                    searchEndTime = searchEndTime.Value.AddDays(1);
                    filter        = filter.And(r => r.DispathTime <= searchEndTime);
                }

                var removalWareOrderIQueary = RepositoryIoc.GetRemovalWarehouseOrderRepository(db).LazyGet(out totalCount, filter);
                switch (orderEnum)
                {
                case WarehouseOrderOrderEnum.Count:
                    if (ascending)
                    {
                        removalWareOrderIQueary = removalWareOrderIQueary.OrderBy(r => r.RemovalWarehouseRecords.Count());
                    }
                    else
                    {
                        removalWareOrderIQueary = removalWareOrderIQueary.OrderByDescending(r => r.RemovalWarehouseRecords.Count());
                    }
                    break;

                case WarehouseOrderOrderEnum.DispathTime:
                    if (ascending)
                    {
                        removalWareOrderIQueary = removalWareOrderIQueary.OrderBy(r => r.DispathTime);
                    }
                    else
                    {
                        removalWareOrderIQueary = removalWareOrderIQueary.OrderByDescending(r => r.DispathTime);
                    }
                    break;

                case WarehouseOrderOrderEnum.DispathPlace:
                    if (ascending)
                    {
                        removalWareOrderIQueary = removalWareOrderIQueary.OrderBy(r => r.DispathPlace);
                    }
                    else
                    {
                        removalWareOrderIQueary = removalWareOrderIQueary.OrderByDescending(r => r.DispathPlace);
                    }
                    break;

                case WarehouseOrderOrderEnum.Staff:
                    if (ascending)
                    {
                        removalWareOrderIQueary = removalWareOrderIQueary.OrderBy(r => r.Staff);
                    }
                    else
                    {
                        removalWareOrderIQueary = removalWareOrderIQueary.OrderByDescending(r => r.Staff);
                    }
                    break;
                }
                removalWareOrderIQueary = removalWareOrderIQueary.Page(out totalCount, null, true, pageIndex, pageSize);
                var result = (from f in removalWareOrderIQueary
                              select new WebRemovalWarehouseOrder()
                {
                    OrderID = f.OrderID,
                    SpeedChangeBoxName = f.SpeedChangeBoxName,
                    Count = f.RemovalWarehouseRecords.Count(),
                    Staff = f.Staff,
                    DispathPlace = f.DispathPlace,
                    DispathTime = f.DispathTime,
                    PlanCount = f.PlanCount,
                }).ToList();
                return(new CResult <List <WebRemovalWarehouseOrder> >(result));
            }
        }
Exemplo n.º 23
0
        public CResult <bool> UpdateUser(WebUserInfo webUser)
        {
            if (string.IsNullOrWhiteSpace(webUser.UserName))
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }
            using (var db = new WarehouseContext()) {
                var user = Membership.GetUser(webUser.UserName);
                if (user == null)
                {
                    return(new CResult <bool>(false, ErrorCode.UserNoExist));
                }

                var roles       = new List <string>();
                var hasAddRoles = Roles.GetRolesForUser(webUser.UserName);
                if (webUser.IsMonitor)
                {
                    roles.Add(PermissionEnum.班长.ToString());
                }
                if (webUser.IsPutinMan)
                {
                    roles.Add(PermissionEnum.入库员.ToString());
                }
                if (webUser.IsRemovalMan)
                {
                    roles.Add(PermissionEnum.出库员.ToString());
                }
                var hasExistRoles = hasAddRoles.Intersect(roles);
                var toDelRoles    = hasAddRoles.Except(hasExistRoles);
                var toAddRoles    = roles.Except(hasExistRoles);
                if (toDelRoles.Count() > 0)
                {
                    Roles.RemoveUserFromRoles(webUser.UserName, toDelRoles.ToArray());
                }
                if (toAddRoles.Count() > 0)
                {
                    Roles.AddUserToRoles(webUser.UserName, toAddRoles.ToArray());
                }

                var userID     = (int)user.ProviderUserKey;
                var repository = RepositoryIoc.GetUsersInfoRepository(db);
                var userInfo   = repository.FirstOrDefault(r => r.ID == userID);
                if (userInfo == null)
                {
                    return(new CResult <bool>(false, ErrorCode.UserNoExist));
                }
                userInfo.Phone  = webUser.Phone;
                userInfo.Adress = webUser.Adress;
                if (repository.Update(userInfo) == EntityState.Modified)
                {
                    if (db.SaveChanges() > 0)
                    {
                        return(new CResult <bool>(true));
                    }
                    else
                    {
                        return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
                    }
                }
                else
                {
                    return(new CResult <bool>(true));
                }
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// 获得库存信息
        /// </summary>
        /// <param name="totalCount"></param>
        /// <param name="searchName"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="orderEnum"></param>
        /// <param name="ascending"></param>
        /// <returns></returns>
        public CResult <List <WebPutInWarehouseRecord> > GetWarehouseInfoList(out int totalCount, string searchName = "", int pageIndex = 1, int pageSize = 100, PutInListOrderEnum orderEnum = PutInListOrderEnum.PutInTime, bool ascending = false, DateTime?searchStartTime = null,
                                                                              DateTime?searchEndTime = null)
        {
            totalCount = 0;
            using (var db = new WarehouseContext())
            {
                Expression <Func <WarehouseM, bool> > filter = r => r.StateID == (int)RecordState.Show;
                if (!string.IsNullOrWhiteSpace(searchName))
                {
                    filter = filter.And(r => r.PutInUserName.Contains(searchName) ||
                                        r.BarCode.Contains(searchName) ||
                                        r.Place.Contains(searchName));
                }
                if (searchStartTime.HasValue)
                {
                    filter = filter.And(r => r.WarehouseTime >= searchStartTime.Value);
                }
                if (searchEndTime.HasValue)
                {
                    searchEndTime = searchEndTime.Value.AddDays(1);
                    filter        = filter.And(r => r.WarehouseTime <= searchEndTime);
                }

                var warehouseIQueary = RepositoryIoc.GetWarehouseMRepository(db).LazyGet(out totalCount, filter, CommonHelper.GetPropName <PutInWarehouseRecord>(r => r.WarehouseM));
                switch (orderEnum)
                {
                case PutInListOrderEnum.BarCode:
                    if (ascending)
                    {
                        warehouseIQueary = warehouseIQueary.OrderBy(r => r.BarCode);
                    }
                    else
                    {
                        warehouseIQueary = warehouseIQueary.OrderByDescending(r => r.BarCode);
                    }
                    break;

                case PutInListOrderEnum.Place:
                    if (ascending)
                    {
                        warehouseIQueary = warehouseIQueary.OrderBy(r => r.Place);
                    }
                    else
                    {
                        warehouseIQueary = warehouseIQueary.OrderByDescending(r => r.Place);
                    }
                    break;

                case PutInListOrderEnum.PutInTime:
                    if (ascending)
                    {
                        warehouseIQueary = warehouseIQueary.OrderBy(r => r.WarehouseTime);
                    }
                    else
                    {
                        warehouseIQueary = warehouseIQueary.OrderByDescending(r => r.WarehouseTime);
                    }
                    break;

                case PutInListOrderEnum.PutInUserName:
                    if (ascending)
                    {
                        warehouseIQueary = warehouseIQueary.OrderBy(r => r.PutInUserName);
                    }
                    else
                    {
                        warehouseIQueary = warehouseIQueary.OrderByDescending(r => r.PutInUserName);
                    }
                    break;
                }
                warehouseIQueary = warehouseIQueary.Page(out totalCount, null, true, pageIndex, pageSize);
                var result = (from f in warehouseIQueary
                              select new WebPutInWarehouseRecord()
                {
                    BarCode = f.BarCode,
                    PutInTime = f.WarehouseTime,
                    PutInUserName = f.PutInUserName,
                    Place = f.Place,
                    WarehouseID = f.WarehouseID,
                }).ToList();
                return(new CResult <List <WebPutInWarehouseRecord> >(result));
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// 保存入库信息
        /// </summary>
        /// <param name="barCodeList">条形码</param>
        /// <param name="twoDimensioncodeNum">二维码型号</param>
        /// <param name="speedChangeTypeID">产品类型ID</param>
        /// <param name="putInUserName">UserName</param>
        /// <param name="place">地点</param>
        /// <returns></returns>
        public static CResult <bool> SavePutInWarehouseInfo(List <string> barCodeList, string twoDimensioncodeNum, int speedChangeTypeID, string putInUserName, string place)
        {
            if (barCodeList == null)
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }

            if (string.IsNullOrWhiteSpace(twoDimensioncodeNum))
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }

            using (var db = new WarehouseContext())
            {
                var twoDimensioncodeRepository = RepositoryIoc.GetTwoDimensioncodeRepository(db);
                var twoDimensionCode           = twoDimensioncodeRepository.FirstOrDefault(r => r.TwoDimensionCodeNum == twoDimensioncodeNum);
                if (twoDimensionCode == null)
                {
                    twoDimensionCode = new TwoDimensioncode();
                    twoDimensionCode.TwoDimensionCodeNum = twoDimensioncodeNum;
                    twoDimensionCode.Count   = barCodeList.Count();
                    twoDimensionCode.StateID = (int)RecordState.Show;
                    twoDimensionCode.SpeedChangeBoxTypeID = speedChangeTypeID;
                    twoDimensioncodeRepository.Insert(twoDimensionCode);
                }
                else
                {
                    return(new CResult <bool>(false, ErrorCode.TwoDimensioncodeHasExist));
                }
                if (db.SaveChanges() <= 0)
                {
                    return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
                }
                var warehouseRepository = RepositoryIoc.GetWarehouseMRepository(db);
                foreach (var item in barCodeList)
                {
                    var warehouse = warehouseRepository.FirstOrDefault(r => r.BarCode == item);
                    if (warehouse == null)
                    {
                        warehouse                    = new WarehouseM();
                        warehouse.BarCode            = item;
                        warehouse.StateID            = (int)RecordState.Show;
                        warehouse.WarehouseTime      = DateTime.Now;
                        warehouse.PutInUserName      = putInUserName;
                        warehouse.Place              = place;
                        warehouse.TwoDimensioncodeID = twoDimensionCode.TwoDimensioncodeID;

                        var putInWare = new PutInWarehouseRecord();
                        putInWare.PutInTime     = DateTime.Now;
                        putInWare.Place         = place;
                        putInWare.PutInUserName = putInUserName;
                        putInWare.StateID       = (int)RecordState.Show;
                        putInWare.WarehouseID   = warehouse.WarehouseID;
                        warehouse.PutInWarehouseRecords.Add(putInWare);

                        warehouseRepository.Insert(warehouse);
                    }
                    else
                    {
                        if (warehouse.StateID == (int)RecordState.Show)
                        {
                            return(new CResult <bool>(false, ErrorCode.PutInInfoHasExist));
                        }
                        else
                        {
                            warehouse.WarehouseTime      = DateTime.Now;
                            warehouse.PutInUserName      = putInUserName;
                            warehouse.Place              = place;
                            warehouse.StateID            = (int)RecordState.Show;
                            warehouse.TwoDimensioncodeID = twoDimensionCode.TwoDimensioncodeID;
                            var putInWare = new PutInWarehouseRecord();
                            putInWare.PutInTime     = DateTime.Now;
                            putInWare.Place         = place;
                            putInWare.PutInUserName = putInUserName;
                            putInWare.StateID       = (int)RecordState.Show;
                            putInWare.WarehouseID   = warehouse.WarehouseID;
                            warehouse.PutInWarehouseRecords.Add(putInWare);
                        }
                    }
                }
                if (db.SaveChanges() > 0)
                {
                    return(new CResult <bool>(true));
                }
                else
                {
                    twoDimensioncodeRepository.Delete(twoDimensionCode);
                    db.SaveChanges();
                    return(new CResult <bool>(false, ErrorCode.SaveDbChangesFailed));
                }
            }
        }