Beispiel #1
0
        public ContentResult SearchSingle()
        {
            string    locationId = GetParam("ID");
            BLocation loc        = lService.GetLocationById(Convert.ToInt32(locationId));

            return(ReturnResult(loc));
        }
        public IHttpActionResult Put(int id, BLocation bLocation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bLocation.location_id)
            {
                return(BadRequest());
            }

            db.Entry(bLocation).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BLocationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
        /// <summary>
        /// 添加存储单元
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        public int AddLocation(BLocation location)
        {
            //添加存储单元
            object id = lRepository.Insert(location);

            return(Convert.ToInt32(id));
        }
        public IHttpActionResult Get(int id)
        {
            BLocation bLocation = db.BLocations.Find(id);

            if (bLocation == null)
            {
                return(NotFound());
            }

            return(Ok(bLocation));
        }
        public IHttpActionResult Post(BLocation bLocation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.BLocations.Add(bLocation);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = bLocation.location_id }, bLocation));
        }
Beispiel #6
0
        /// <summary>
        /// 递归
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="orgs"></param>
        /// <returns></returns>
        private void GetLocationChild(BLocation parent, List <BLocation> orgs)
        {
            List <BLocation> children = orgs.Select(t => t).Where(o => o.ParentID == parent.ID).ToList();

            if (children.Count > 0)
            {
                parent.Children.AddRange(children);
                foreach (BLocation child in children)
                {
                    GetLocationChild(child, orgs);
                }
            }
        }
Beispiel #7
0
        public string CheckLocation(string location, string title)
        {
            if (location == null || "".Equals(location))
            {
                return(title + ERROR_NULL);
            }
            BLocation bLocation = new BLocation();

            if (bLocation.Exists(location))
            {
                return("");
            }
            return(title + ERROR_EXIST);
        }
        public IHttpActionResult Delete(int id)
        {
            BLocation bLocation = db.BLocations.Find(id);

            if (bLocation == null)
            {
                return(NotFound());
            }

            db.BLocations.Remove(bLocation);
            db.SaveChanges();

            return(Ok(bLocation));
        }
Beispiel #9
0
 /// <summary>
 /// 构建子节点
 /// </summary>
 /// <param name="location"></param>
 /// <param name="parentTn"></param>
 public void BuildChildTree(BLocation location, TreeNode parentTn)
 {
     foreach (BLocation loc in location.Children)
     {
         TreeNode tn = new TreeNode();
         tn.id   = loc.ID.ToString();
         tn.text = loc.LocationDesc;
         tn.name = loc.LocationCode;
         if (loc.Children.Count > 0)
         {
             BuildChildTree(loc, tn);
         }
         parentTn.children.Add(tn);
     }
 }
Beispiel #10
0
 /// <summary>
 ///
 /// </summary>
 private void initLocation()
 {
     if (!string.IsNullOrEmpty(txtWarehouseCode.Text.Trim()) && !string.IsNullOrEmpty(txtProductCode.Text.Trim()))
     {
         BLocation bLocation = new BLocation();
         DataSet   ds        = bLocation.GetList(" WAREHOUSE_CODE='" + txtWarehouseCode.Text.Trim() + "' and PRODUCT_CODE='" + txtProductCode.Text.Trim() + "'");
         if (ds.Tables[0].Rows.Count > 0)
         {
             txtProduct_Group_Code.Text = CConvert.ToString(ds.Tables[0].Rows[0]["CODE"]);
             txtProduct_Group_Name.Text = CConvert.ToString(ds.Tables[0].Rows[0]["NAME"]);
         }
     }
     else
     {
         txtProduct_Group_Code.Text = "";
         txtProduct_Group_Name.Text = "";
     }
 }
Beispiel #11
0
 /// <summary>
 /// 非空验证
 /// </summary>
 /// <param name="location"></param>
 /// <returns></returns>
 public string CheckLocation(BLocation location)
 {
     if (string.IsNullOrWhiteSpace(location.LocationCode))
     {
         return("存储单元编码不能为空.");
     }
     //if (location.OrgID < 1)
     //{
     //    return "组织机构不能为空.";
     //}
     if (location.ID > 0)
     {
         if (location.ID == location.ParentID)
         {
             return("上级存储单元不能选择自身.");
         }
     }
     return(string.Empty);
 }
Beispiel #12
0
        public ContentResult Update()
        {
            ResultData <string> rt = new ResultData <string>();

            BLocation locaiton = GetUpdate <BLocation>();

            //非空验证和属性格式验证
            string msg = lService.CheckLocation(locaiton);

            if (!string.IsNullOrEmpty(msg))
            {
                rt.message = msg;
                rt.status  = -1;
                return(ReturnResult(rt));
            }

            locaiton.UpdateDate = DateTime.Now;
            locaiton.UpdateBy   = this.CurrentUser.ID;

            //更新顶级仓库
            BLocation pLocation = lService.GetLocationById(locaiton.ParentID);

            if (pLocation != null)
            {
                locaiton.TopLocationID = pLocation.TopLocationID;
            }

            //是否存在
            if (lService.IsNotExits(locaiton, false))
            {
                lService.UpdateLocation(locaiton);
            }
            else
            {
                rt.status  = -1;
                rt.message = "存储单元已经存在.";
            }
            return(ReturnResult(rt));
        }
Beispiel #13
0
        /// <summary>
        /// 编辑存储单元
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        public bool UpdateLocation(BLocation location)
        {
            var             oldEntity = lRepository.GetLocationById(location.ID);
            int             oldOrgId  = oldEntity.OrgID;
            DatabaseContext db        = lRepository.DbCondext;

            try
            {
                db.BeginTransaction();
                bool result = lRepository.Update(location);
                //如果修改了组织,下属的货区货位的组织也要跟着变
                if (oldOrgId != location.OrgID)
                {
                    db.Connection.Execute(string.Format("Update BLocation set OrgId={0} where ID<>{1} and TopLocationID={1}", location.OrgID, location.ID));
                }
                db.CompleteTransaction();
                return(result);
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                throw ex;
            }
        }
Beispiel #14
0
        public ContentResult Add()
        {
            ResultData <string> rt = new ResultData <string>();

            BLocation location = GetAdd <BLocation>();

            //非空验证和属性格式验证
            string msg = lService.CheckLocation(location);

            if (!string.IsNullOrEmpty(msg))
            {
                rt.message = msg;
                rt.status  = -1;
                return(ReturnResult(rt));
            }

            //判断是否子存储单元,添加顶级存储单元
            if (location.ParentID > 0)
            {
                BLocation parent = lService.GetLocationById(location.ParentID);
                location.TopLocationID = parent.TopLocationID;
                location.LocationLevel = parent.LocationLevel + 1;
                ////如果是货位,默认货区的类型
                //if (location.LocationLevel == 3)
                //{
                //    location.LocationClass = parent.LocationClass;
                //}
            }
            else
            {
                location.LocationLevel = 1;
            }


            //判断是否存在其他货位也是默认货位
            //if (location.LocationLevel == 2)
            //{
            //    if (location.IsDefault > 0)
            //    {
            //        BLocation dftLocation = lService.GetDefaultLocation(location.ParentID, location.LocationClass);
            //        if (dftLocation != null)
            //        {
            //            rt.status = -1;
            //            rt.message = "当前仓库已经存在默认货区(" + dftLocation.LocationCode + ")";
            //            return ReturnResult(rt);
            //        }
            //    }
            //}

            //是否存在
            if (lService.IsNotExits(location, false))
            {
                location.CreateBy   = this.CurrentUser.ID;
                location.CreateDate = DateTime.Now;
                location.UpdateDate = DateTime.Now;
                int locId = lService.AddLocation(location);

                //如果添加为仓库,则跟新顶级存储单元ID
                if (location.ParentID < 1)
                {
                    location.ID            = locId;
                    location.TopLocationID = locId;
                    lService.UpdateLocation(location);
                }
            }
            else
            {
                rt.status  = -1;
                rt.message = "存储单元已经存在.";
            }


            return(ReturnResult(rt));
        }
Beispiel #15
0
        public override string[] doUpdateDB()
        {
            BaseLocationTable LocationTable = null;
            BLocation         bLocation     = new BLocation();
            StringBuilder     strError      = new StringBuilder();
            int    successData    = 0;
            int    failureData    = 0;
            string errorFilePath  = "";
            string backupFilePath = "";

            //数据导入处理
            foreach (DataRow dr in _csvDataTable.Rows)
            {
                StringBuilder str = new StringBuilder();
                //编号
                if (!string.IsNullOrEmpty(CConvert.ToString(GetValue(dr, "CODE"))))
                {
                    str.Append(CheckString(GetValue(dr, "CODE"), 20, "编号"));
                }
                else
                {
                    str.Append("编号不能为空!");
                }
                //名称
                str.Append(CheckLenght(GetValue(dr, "NAME"), 100, "名称"));
                //状态
                str.Append(CheckInt(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL_STATUS), 9, "状态"));

                if (str.ToString().Trim().Length > 0)
                {
                    strError.Append(GetStringBuilder(dr, str.ToString().Trim()));
                    failureData++;
                    continue;
                }
                try
                {
                    LocationTable                  = new BaseLocationTable();
                    LocationTable.CODE             = CConvert.ToString(GetValue(dr, "CODE"));
                    LocationTable.NAME             = CConvert.ToString(GetValue(dr, "NAME"));
                    LocationTable.STATUS_FLAG      = CConvert.ToInt32(GetValue(dr, "STATUS_FLAG", CConstant.NORMAL_STATUS));
                    LocationTable.CREATE_USER      = _userInfo.CODE;
                    LocationTable.LAST_UPDATE_USER = _userInfo.CODE;

                    if (!bLocation.Exists(LocationTable.CODE))
                    {
                        LocationTable.CREATE_DATE_TIME = DateTime.Now;
                        LocationTable.LAST_UPDATE_TIME = DateTime.Now;
                        bLocation.Add(LocationTable);
                    }
                    else
                    {
                        LocationTable.LAST_UPDATE_TIME = DateTime.Now;
                        bLocation.Update(LocationTable);
                    }
                    successData++;
                }
                catch
                {
                    strError.Append(GetStringBuilder(dr, " 数据导入失败,请与系统管理员联系!").ToString());
                    failureData++;
                }
            }
            //错误记录处理
            if (strError.Length > 0)
            {
                errorFilePath = WriteFile(strError.ToString());
            }

            //备份处理
            backupFilePath = BackupFile();

            return(new string[] { successData.ToString(), failureData.ToString(), errorFilePath, backupFilePath });
        }
Beispiel #16
0
 /// <summary>
 /// 判断是否存在
 /// </summary>
 /// <param name="location"></param>
 /// <returns></returns>
 public bool IsNotExits(BLocation location, bool isAdd)
 {
     return(lRepository.IsNotExits(location, isAdd));
 }