/// <summary>
        /// 获取仓库相信
        /// </summary>
        /// <returns></returns>
        public StorageBinResult GetWh_nameList()
        {
            StorageBinResult result = new StorageBinResult();

            using (var db = SugarDao.GetInstance(LoginUser.GetConstr()))
            {
                try
                {
                    var list = db.Queryable <base_wh_warehouse>().Where(a => a.del_flag).OrderBy("wh_id DESC").ToList();
                    if (list.Count <= 0)
                    {
                        result.success = false;
                        result.Msg     = "暂无仓库信息!";
                        return(result);
                    }
                    var list1 = "<option value=\"0\">请选择...</option>";
                    foreach (var item in list)
                    {
                        list1 += "<option value=\"" + item.wh_id + "\">" + item.wh_name + "</option>";
                    }

                    result.success = true;
                    result.Msg     = list1;
                    return(result);
                }
                catch (Exception ex)
                {
                    result.success = false;
                    result.Msg     = "获取仓库信息失败!";
                    return(result);
                }
            }
        }
 public ActionResult GetWh_nameList()
 {
     StorageBinResult com = new StorageBinResult();
     try
     {
         com = _service.GetWh_nameList();
         return Json(com);
     }
     catch (Exception ex)
     {
         com.Msg = ex.ToString();
         com.success = false;
         return Json(com);
     }
 }
 public ActionResult SaveInOut(Guid? id, Decimal count, int type)
 {
     StorageBinResult com = new StorageBinResult();
     try
     {
         com = _service.StockInOut(id, count, type);
         return Json(com);
     }
     catch (Exception ex)
     {
         com.Msg = ex.ToString();
         com.success = false;
         return Json(com);
     }
 }
 public ActionResult Save_sku(Int64 wh_id, Int64 locat_id, string sku, int skucount)
 {
     StorageBinResult com = new StorageBinResult();
     try
     {
         com = _service.Save_sku(wh_id, locat_id, sku, skucount);
         return Json(com);
     }
     catch (Exception ex)
     {
         com.Msg = ex.ToString();
         com.success = false;
         return Json(com);
     }
 }
 public ActionResult Save(base_location model)
 {
     StorageBinResult com = new StorageBinResult();
     try
     {
         com = _service.Save(model);
         return Json(com);
     }
     catch (Exception ex)
     {
         com.Msg = ex.ToString();
         com.success = false;
         return Json(com);
     }
 }
        public ActionResult Getpage(string pagenum, string onepagecount, long? wh_id, string locat_code, string sku_code, int ty_pe)
        {
            StorageBinResult com = new StorageBinResult();
            if (!Regex.IsMatch(pagenum, @"(?i)^[0-9a-z\u4e00-\u9fa5]+$") && !string.IsNullOrEmpty(pagenum))
            {
                com.Msg = "页数不正确";
                com.success = false;
                return Json(com);
            }

            if (!Regex.IsMatch(onepagecount, @"(?i)^[0-9a-z\u4e00-\u9fa5]+$") && !string.IsNullOrEmpty(onepagecount))
            {
                com.Msg = "每页数量不正确";
                com.success = false;
                return Json(com);
            }
            int totil = 0;
            int totilpage = 0;
            string exmsg = string.Empty;
            List<StorageBinModel> mylist = new List<StorageBinModel>();
            if (ty_pe == 1)
            {
                mylist = _service.GetStorageBinList(Convert.ToInt32(pagenum), Convert.ToInt32(onepagecount), out totil, out totilpage, out exmsg, wh_id, locat_code);
            }
            else if (ty_pe == 2)
            {
                mylist = _service.GetStorageBinInOutList(Convert.ToInt32(pagenum), Convert.ToInt32(onepagecount), out totil, out totilpage, out exmsg, wh_id, locat_code, sku_code);
            }

            if (!string.IsNullOrEmpty(exmsg))
            {
                com.Msg = exmsg;
                com.success = false;
                return Json(com);
            }
            else
            {
                StorageBinViewModel mylistview = new StorageBinViewModel();
                mylistview.supplist = mylist;
                mylistview.totil = totil.ToString();
                mylistview.totilcount = totilpage.ToString();
                com.DataResult = mylistview;
                com.success = true;
                com.ty_pe = ty_pe;
                return Json(com);
            }
        }
 public ActionResult GetStorageBinEList(long? wh_id, long? locat_id)
 {
     StorageBinResult com = new StorageBinResult();
     string exmsg = string.Empty;
     List<StorageBinModel> mylist = _service.GetStorageBinEList(out exmsg, wh_id, locat_id);
     if (!string.IsNullOrEmpty(exmsg))
     {
         com.Msg = exmsg;
         com.success = false;
         return Json(com);
     }
     else
     {
         StorageBinViewModel mylistview = new StorageBinViewModel();
         mylistview.supplist = mylist;
         com.DataResult = mylistview;
         com.success = true;
         return Json(com);
     }
 }
        /// <summary>
        /// 修改 添加的方法
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public StorageBinResult Save(base_location model)
        {
            bool             rstNum = false;
            StorageBinResult result = new StorageBinResult();

            using (var db = SugarDao.GetInstance(LoginUser.GetConstr()))
            {
                #region 判断
                if (model == null)
                {
                    result.success = false;
                    result.Msg     = "请填写信息!";
                    return(result);
                }

                if (model.wh_id == 0)
                {
                    result.success = false;
                    result.Msg     = "请选择仓库!";
                    return(result);
                }

                if (string.IsNullOrWhiteSpace(model.locat_code))
                {
                    result.success = false;
                    result.Msg     = "请填写库位号!";
                    return(result);
                }
                #endregion

                if (model.locat_id > 0)
                {
                }
                else
                {
                    var base_shop = db.Queryable <base_location>().Where(c => c.del_flag && c.locat_code == model.locat_code).ToList();
                    if (base_shop.Count > 0)
                    {
                        result.success = false;
                        result.Msg     = "该仓库已存在的库位号,操作失败!";
                        return(result);
                    }
                    model.remark         = model.locat_code;
                    model.locat_status   = true;
                    model.locat_type     = 2;
                    model.create_time    = DateTime.Now;
                    model.create_user_id = LoginUser.Current.user_id;
                    model.del_flag       = true;
                    model.del_user_id    = 0;
                    model.del_time       = DateTime.Now;
                    model.edit_time      = DateTime.Now;
                    model.edit_user_id   = 0;
                    var id = db.Insert <base_location>(model);
                    if (id.ObjToInt() > 0)
                    {
                        rstNum = true;
                    }
                }
                if (rstNum)
                {
                    result.success = true;
                    result.URL     = "/StorageBin/Index";
                    result.Msg     = "操作成功";
                    return(result);
                }
                else
                {
                    result.success = false;
                    result.Msg     = "操作失败";
                    return(result);
                }
            }
        }
        public StorageBinResult Save_sku(Int64 wh_id, Int64 locat_id, string sku, int skucount)
        {
            bool             rstNum  = false;
            bool             rstNums = false;
            StorageBinResult result  = new StorageBinResult();

            using (var db = SugarDao.GetInstance(LoginUser.GetConstr()))
            {
                db.BeginTran();
                if (wh_id == 0 || locat_id == 0)
                {
                    db.RollbackTran();
                    result.success = false;
                    result.Msg     = "参数错误!";
                    return(result);
                }

                if (skucount <= 0)
                {
                    db.RollbackTran();
                    result.success = false;
                    result.Msg     = "请填写正确的数量!";
                    return(result);
                }

                if (string.IsNullOrEmpty(sku))
                {
                    db.RollbackTran();
                    result.success = false;
                    result.Msg     = "请填写sku!";
                    return(result);
                }
                var list = db.Queryable <base_prod_code>().Where(a => a.del_flag && a.sku_code == sku).FirstOrDefault();
                if (list == null)
                {
                    db.RollbackTran();
                    result.success = false;
                    result.Msg     = "系统中不存在的sku!";
                    return(result);
                }

                var wh_stock = db.Queryable <base_wh_stock>().Where(a => a.del_flag && a.wh_id == wh_id && a.location_id == locat_id && a.code_id == list.code_id).FirstOrDefault();
                if (wh_stock == null)
                {
                    var           _supp_rel = db.Queryable <base_prod_supp_rel>().Where(a => a.del_flag && a.prod_id == list.prod_id).ToList();
                    long          suppid    = _supp_rel.Find(b => b.lev_purch == _supp_rel.Min(s => s.lev_purch)).supp_id;
                    base_wh_stock _stock    = new base_wh_stock();
                    _stock.prod_id        = list.prod_id;
                    _stock.occupied_qty   = 0;
                    _stock.pallet_id      = 0;
                    _stock.purchase_price = 0;
                    _stock.remark         = "库存采购";
                    _stock.reserve_qty    = 0;
                    _stock.service_life   = "";
                    _stock.stock_barcode  = "";
                    _stock.stock_class    = 3;
                    _stock.stock_code     = "1";
                    _stock.stock_qty      = skucount;
                    _stock.stock_status   = true;
                    _stock.retrieval_time = DateTime.Now;
                    _stock.storage_time   = DateTime.Now;
                    _stock.supplier_id    = suppid;
                    _stock.using_state    = 1;
                    _stock.wh_id          = 1;
                    _stock.location_id    = locat_id;
                    _stock.locking_qty    = 0;
                    _stock.area_id        = 0;
                    _stock.asset_class_id = 0;
                    _stock.code_id        = list.code_id;
                    _stock.consignor_id   = 0;
                    _stock.create_time    = DateTime.Now;
                    _stock.create_user_id = LoginUser.Current.user_id;
                    _stock.del_flag       = true;
                    _stock.del_user_id    = 0;
                    _stock.edit_user_id   = 0;
                    _stock.del_time       = DateTime.Now;
                    _stock.edit_time      = DateTime.Now;
                    _stock.stock_id       = Guid.NewGuid();
                    var id = db.Insert <base_wh_stock>(_stock);
                    if (id.ObjToBool())
                    {
                        rstNums = true;
                    }
                }
                else
                {
                    rstNums = db.Update <base_wh_stock>(new { stock_qty = wh_stock.stock_qty + skucount }, s => s.stock_id == wh_stock.stock_id);
                }
                if (rstNums)
                {
                    db.CommitTran();
                    result.success = true;
                    result.Msg     = "操作成功";
                    return(result);
                }
                else
                {
                    db.RollbackTran();
                    result.success = false;
                    result.Msg     = "操作失败";
                    return(result);
                }
            }
        }
        /// <summary>
        /// 上下架
        /// </summary>
        /// <param name="id"></param>
        /// <param name="count"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public StorageBinResult StockInOut(Guid?id, Decimal count, int state)
        {
            bool             rstNum  = false;
            bool             rstNums = false;
            StorageBinResult result  = new StorageBinResult();

            using (var db = SugarDao.GetInstance(LoginUser.GetConstr()))
            {
                db.BeginTran();
                if (string.IsNullOrWhiteSpace(id.ToString()) || state == 0)
                {
                    db.RollbackTran();
                    result.success = false;
                    result.Msg     = "参数错误!";
                    return(result);
                }

                if (count <= 0)
                {
                    db.RollbackTran();
                    result.success = false;
                    result.Msg     = "请填写正确的数量!";
                    return(result);
                }

                var list = db.Queryable <base_wh_stock>().InSingle(id.Value);
                if (list == null)
                {
                    db.RollbackTran();
                    result.success = false;
                    result.Msg     = "不存在的库存信息,操作失败!";
                    return(result);
                }

                if (!list.del_flag)
                {
                    db.RollbackTran();
                    result.success = false;
                    result.Msg     = "已删除的库存信息,操作失败!";
                    return(result);
                }

                Decimal stock_qty = list.stock_qty;
                if (state == 1)
                {
                    list.stock_qty = list.stock_qty + count;
                    rstNum         = db.Update <base_wh_stock>(list);
                    if (rstNum)
                    {
                        db.Update <base_wh_stock>(new { stock_qty = list.stock_qty }, s => s.stock_id == id);

                        base_wh_stock_inout model = new base_wh_stock_inout();
                        model.add_time   = DateTime.Now;
                        model.last_count = list.stock_qty;
                        model.oper_count = count;
                        model.oper_type  = state;
                        model.pre_count  = stock_qty;
                        model.user_id    = LoginUser.Current.user_id;
                        model.user_name  = LoginUser.Current.real_name;
                        model.stock_id   = id.Value;
                        var issuc = db.Insert <base_wh_stock_inout>(model);
                        if (issuc.ObjToInt() > 0)
                        {
                            rstNums = true;
                        }
                    }
                }
                else if (state == 2)
                {
                    if (stock_qty < count)
                    {
                        db.RollbackTran();
                        result.success = false;
                        result.Msg     = "下架数量不得大于商品数量,操作失败!";
                        return(result);
                    }

                    list.stock_qty = list.stock_qty - count;
                    rstNum         = db.Update <base_wh_stock>(list);
                    if (rstNum)
                    {
                        db.Update <base_wh_stock>(new { stock_qty = list.stock_qty }, s => s.stock_id == id);

                        base_wh_stock_inout model = new base_wh_stock_inout();
                        model.add_time   = DateTime.Now;
                        model.last_count = list.stock_qty;
                        model.oper_count = count;
                        model.oper_type  = state;
                        model.pre_count  = stock_qty;
                        model.user_id    = LoginUser.Current.user_id;
                        model.user_name  = LoginUser.Current.real_name;
                        model.stock_id   = id.Value;
                        var issuc = db.Insert <base_wh_stock_inout>(model);
                        if (issuc.ObjToInt() > 0)
                        {
                            rstNums = true;
                        }
                    }
                }

                if (rstNums && rstNum)
                {
                    db.CommitTran();
                    result.success = true;
                    result.Msg     = "操作成功";
                    return(result);
                }
                else
                {
                    db.RollbackTran();
                    result.success = false;
                    result.Msg     = "操作失败";
                    return(result);
                }
            }
        }