Beispiel #1
0
        public ActionResult BuyDetail(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("请输入正确的验货单编号"));
            }

            int bId = 0;
            int.TryParse(id, out bId);
            string uid = HttpContext.User.Identity.Name;
            if (bId <=0)
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("请输入正确的验货单编号"));
            }
            BBuy buy = null;
            try
            {
                UserManager userMgr = new UserManager(int.Parse(uid), null);
                BUser user = userMgr.CurrentUser;
                BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
                buy = buyManager.GetBuyFullInfo(bId);
            }
            catch (KMJXCException kex)
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode(kex.Message));
            }
            catch (Exception ex)
            {
                return Redirect("/Home/Error?message=" + HttpUtility.UrlEncode("未知错误"));
            }

            return View(buy);
        }
Beispiel #2
0
 public PQGridData ExportBuyOrders()
 {
     PQGridData data = new PQGridData();
     HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
     HttpRequestBase request = context.Request;
     string user_id = User.Identity.Name;
     UserManager userMgr = new UserManager(int.Parse(user_id), null);
     BUser user = userMgr.CurrentUser;
     BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
     int total = 0;
     int page = 1;
     int pageSize = 30;
     int.TryParse(request["page"], out page);
     int.TryParse(request["pageSize"], out pageSize);
     int order_id = 0;
     int supplier_id = 0;
     int.TryParse(request["order_id"], out order_id);
     int.TryParse(request["supplier_id"], out supplier_id);
     string keyword = request["keyword"];
     int[] orders = null;
     if (order_id > 0)
     {
         orders = new int[] { order_id };
     }
     int[] suppliers = null;
     if (supplier_id > 0)
     {
         suppliers = new int[] { supplier_id };
     }
     data.data = buyManager.SearchBuyOrders(orders, null, suppliers, null, keyword, 0, 0, page, pageSize, out total);
     data.totalRecords = total;
     return data;
 }
Beispiel #3
0
        public ApiMessage CreateBuyPrice()
        {
            ApiMessage message = new ApiMessage() { Status = "ok" };
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            try
            {
                string details = request["price_details"];
                string desc = request["desc"];
                string title = request["title"];
                int shopId = 0;
                int.TryParse(request["shop_id"], out shopId);
                if (!string.IsNullOrEmpty(details))
                {
                    details = HttpUtility.UrlDecode(details);
                }

                JArray jDetails = JArray.Parse(details);
                BBuyPrice buyPrice = new BBuyPrice() { Desc = desc, Title = title, Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now) };
                buyPrice.Shop = new BShop() { ID = buyManager.Shop.Shop_ID };
                if (shopId > 0)
                {
                    buyPrice.Shop = new BShop() { ID = shopId };
                }
                buyPrice.Details = new List<BBuyPriceDetail>();
                for (int i = 0; i < jDetails.Count(); i++)
                {
                    JObject jDetail = (JObject)jDetails[i];
                    BBuyPriceDetail bDetail = new BBuyPriceDetail();
                    bDetail.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                    bDetail.Price = (double)jDetail["price"];
                    bDetail.Product = new BProduct() { ID = (int)jDetail["sku_id"], ParentID = (int)jDetail["product_id"] };
                    bDetail.Supplier = new BSupplier() { ID = (int)jDetail["supplier_id"] };
                    buyPrice.Details.Add(bDetail);
                }

                bool result = buyManager.CreateBuyPrice(buyPrice);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbex)
            {
                message.Status = "failed";
                message.Message = dbex.Message;
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = ex.Message;
            }
            finally
            {

            }

            return message;
        }
Beispiel #4
0
        public PQGridData GetBuyPrices()
        {
            PQGridData data = new PQGridData();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            string keyword = request["keyword"];
            int total = 0;
            int page = 1;
            int pageSize = 30;
            int.TryParse(request["page"], out page);
            int.TryParse(request["pageSize"], out pageSize);
            int price_user_id = 0;
            int supplier_id = 0;
            int.TryParse(request["user_id"], out price_user_id);
            int.TryParse(request["supplier_id"], out supplier_id);
            int buyPriceId = 0;
            int.TryParse(request["price_id"], out buyPriceId);
            string keyWord = request["keyword"];
            if (page <= 0)
            {
                page = 1;
            }

            if (pageSize <= 0)
            {
                pageSize = 30;
            }

            data.data = buyManager.SearchBuyPrices(buyPriceId, price_user_id, supplier_id, 0,keyword, page, pageSize, out total);
            data.totalRecords = total;
            data.curPage = page;
            data.pageSize = pageSize;
            return data;
        }
Beispiel #5
0
        public ApiMessage GetBuyPriceFullInfo()
        {
            ApiMessage message = new ApiMessage() { Status = "ok" };
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            BBuyPrice buyPrice = null;
            int priceId = 0;
            try
            {
                int.TryParse(request["buy_price_id"], out priceId);
                if (priceId <= 0)
                {
                    message.Status = "failed";
                    message.Message = "没有输入询价单编号";
                    return message;
                }

                buyPrice = buyManager.GetBuyPriceFullInfo(priceId);

                if (buyPrice == null)
                {
                    message.Status = "failed";
                    message.Message = "询价单编号错误";
                    return message;
                }

                message.Item = buyPrice;
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbex)
            {
                message.Status = "failed";
                message.Message = dbex.Message;
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = ex.Message;
            }
            finally
            {

            }

            return message;
        }
Beispiel #6
0
        public ApiMessage VerifyOrder()
        {
            ApiMessage message = new ApiMessage();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            try
            {
                int oid = 0;
                long comeDate = 0;
                string odetails = request["order_products"];
                string desc = request["description"];
                int.TryParse(request["oid"], out oid);

                if (!string.IsNullOrEmpty(request["comedate"]))
                {
                    comeDate = DateTimeUtil.ConvertDateTimeToInt(Convert.ToDateTime(request["comedate"]));
                }

                BBuy buy = new BBuy();
                buy.ID = 0;
                buy.Order = new BBuyOrder() { ID = oid };
                buy.ComeDate = comeDate;
                buy.Description = desc;
                buy.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                buy.Shop = new BShop() { ID = buyManager.Shop.Shop_ID };
                buy.User = new BUser() { ID = buyManager.CurrentUser.ID };

                if (!string.IsNullOrEmpty(odetails))
                {
                    odetails = HttpUtility.UrlDecode(odetails);
                    buy.Details = new List<BBuyDetail>();

                    JArray jsons = JArray.Parse(odetails);
                    if (jsons != null && jsons.Count > 0)
                    {

                        for (int i = 0; i < jsons.Count; i++)
                        {
                            JObject jOrder = (JObject)jsons[i];
                            int parent_product_id = (int)jOrder["product_id"];
                            JArray cjorders = (JArray)jOrder["orders"];

                            if (cjorders != null && cjorders.Count > 0)
                            {
                                for (int j = 0; j < cjorders.Count; j++)
                                {
                                    JObject json = (JObject)cjorders[j];
                                    BBuyDetail oDetail = new BBuyDetail();
                                    oDetail.Buy_Order_ID = oid;
                                    double price = 0;
                                    int quantity = 0;
                                    double.TryParse(json["price"].ToString(), out price);
                                    int.TryParse(json["quantity"].ToString(), out quantity);
                                    oDetail.Price = price;
                                    oDetail.Product = new BProduct() { ID = (int)json["child_id"] };
                                    oDetail.Quantity = quantity;

                                    if (quantity <= 0)
                                    {
                                        continue;
                                    }
                                    oDetail.Parent_Product_ID = parent_product_id;
                                    buy.Details.Add(oDetail);
                                }
                            }
                        }
                    }
                }

                bool result = buyManager.VerifyBuyOrder(buy);

                if (result)
                {
                    message.Status = "ok";
                }
                else
                {
                    message.Status = "failed";
                    message.Message = "验货单创建失败";
                }
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = ex.Message;
            }
            finally
            {

            }

            return message;
        }
Beispiel #7
0
        public ApiMessage UpdateBuyOrder()
        {
            ApiMessage message = new ApiMessage();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            try
            {
                int oid = 0;
                long writedate = 0;
                long issuedate = 0;
                long enddate = 0;
                int supplier_id = 0;
                int order_user = 0;
                string odetails = request["order_products"];
                string desc = request["description"];
                int.TryParse(request["oid"],out oid);

                if (!string.IsNullOrEmpty(odetails))
                {
                    odetails = HttpUtility.UrlDecode(odetails);
                }

                if (!string.IsNullOrEmpty(request["writedate"]))
                {
                    writedate = DateTimeUtil.ConvertDateTimeToInt(Convert.ToDateTime(request["writedate"]));
                }

                if (!string.IsNullOrEmpty(request["issuedate"]))
                {
                    issuedate = DateTimeUtil.ConvertDateTimeToInt(Convert.ToDateTime(request["issuedate"]));
                }

                if (!string.IsNullOrEmpty(request["enddate"]))
                {
                    enddate = DateTimeUtil.ConvertDateTimeToInt(Convert.ToDateTime(request["enddate"]));
                }

                int.TryParse(request["supplier"], out supplier_id);
                int.TryParse(request["order_user"], out order_user);
                BBuyOrder order = new BBuyOrder();
                order.ID = oid;
                //order.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                //order.Created_By = new BUser() { ID = buyManager.CurrentUser.ID };
                order.Description = desc;
                order.EndTime = enddate;
                order.InsureTime = issuedate;
                order.OrderUser = new BUser() { ID = order_user };
                order.Shop = new BShop() { ID = buyManager.Shop.Shop_ID };
                order.Status = 0;
                order.Supplier = new Supplier() { Supplier_ID = supplier_id };
                order.WriteTime = writedate;
                if (!string.IsNullOrEmpty(odetails))
                {
                    JArray jOrders = JArray.Parse(odetails);
                    order.Details = new List<BBuyOrderDetail>();
                    if (jOrders != null && jOrders.Count > 0)
                    {
                        for (int i = 0; i < jOrders.Count; i++)
                        {
                            JObject jOrder = (JObject)jOrders[i];
                            int parent_product_id = (int)jOrder["product_id"];
                            JArray cjorders = (JArray)jOrder["orders"];
                            if (cjorders != null && cjorders.Count > 0)
                            {
                                for (int j = 0; j < cjorders.Count; j++)
                                {
                                    BBuyOrderDetail oDetail = new BBuyOrderDetail();
                                    oDetail.Parent_Product_ID = parent_product_id;
                                    double price = 0;
                                    int quantity = 0;
                                    double.TryParse(cjorders[j]["price"].ToString(), out price);
                                    int.TryParse(cjorders[j]["quantity"].ToString(), out quantity);
                                    oDetail.Product = new BProduct() { ID = (int)cjorders[j]["child_id"] };
                                    oDetail.Quantity = quantity;
                                    oDetail.Status = 0;
                                    oDetail.Price = price;
                                    if (quantity <= 0)
                                    {
                                        continue;
                                    }
                                    order.Details.Add(oDetail);
                                }
                            }
                        }
                    }
                }

                bool result = buyManager.UpdateBuyOrder(order);
                if (result)
                {
                    message.Status = "ok";
                }
                else
                {
                    message.Status = "failed";
                    message.Message = "更新失败";
                }
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = ex.Message;
            }
            finally
            {

            }

            return message;
        }
Beispiel #8
0
        public PQGridData GetBuys()
        {
            PQGridData data = new PQGridData();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            int total = 0;
            int page = 1;
            int pageSize = 30;
            int.TryParse(request["page"], out page);
            int.TryParse(request["pageSize"], out pageSize);
            if (page <= 0)
            {
                page = 1;
            }

            if (pageSize <= 0)
            {
                pageSize = 30;
            }
            data.data = buyManager.SearchBuys(null,null,null,null,null,0,0,page,pageSize,out total);
            data.totalRecords = total;
            return data;
        }
Beispiel #9
0
 public List<BBuyDetail> GetBuyDetails()
 {
     HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
     HttpRequestBase request = context.Request;
     string user_id = User.Identity.Name;
     UserManager userMgr = new UserManager(int.Parse(user_id), null);
     BUser user = userMgr.CurrentUser;
     BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
     int buy_id = 0;
     int.TryParse(request["buy_id"],out buy_id);
     List<BBuyDetail> details = buyManager.GetBuyDetails(buy_id);
     return details;
 }
Beispiel #10
0
        public PQGridData SearchStocks()
        {
            PQGridData data = new PQGridData();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            StockManager stockManager = new StockManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            int page = 1;
            int pageSize = 30;
            int storeHouse = 0;
            bool paging = false;
            string product_ids = request["products"];
            int.TryParse(request["house"], out storeHouse);
            int.TryParse(request["page"], out page);
            int.TryParse(request["pageSize"], out pageSize);
            string keyword = request["keyword"];
            int total = 0;
            List<int> storeHouses = new List<int>();
            if (storeHouse > 0)
            {
                storeHouses.Add(storeHouse);
            }

            List<int> products = new List<int>();
            if (!string.IsNullOrEmpty(product_ids))
            {
                string[] ids = product_ids.Split(',');
                foreach (string id in ids)
                {
                    products.Add(int.Parse(id));
                }
            }

            if (!string.IsNullOrEmpty(request["paging"]) && request["paging"] == "1")
            {
                paging = true;
            }
            else
            {
                paging = false;
            }
            if (page <= 0)
            {
                page = 1;
            }

            if (pageSize <= 0)
            {
                pageSize = 30;
            }

            data.data = stockManager.SearchStocks(products, storeHouses, page, pageSize, out total, paging);
            data.curPage = page;
            data.totalRecords = total;
            return data;
        }
Beispiel #11
0
 public PQGridData SearchProductWastage()
 {
     PQGridData data = new PQGridData();
     HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
     HttpRequestBase request = context.Request;
     string user_id = User.Identity.Name;
     UserManager userMgr = new UserManager(int.Parse(user_id), null);
     BUser user = userMgr.CurrentUser;
     StockManager stockManager = new StockManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
     BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
     int page = 1;
     int pageSize = 30;
     int? category_id = null;
     int.TryParse(request["page"], out page);
     int.TryParse(request["pageSize"], out pageSize);
     string keyword = request["keyword"];
     int[] sids = null;
     string suppliers = request["suppliers"];
     sids = base.ConvertToIntArrar(suppliers);
     if (request["cid"] != null && request["cid"].ToString() != "" && request["cid"].ToString() != "0")
     {
         int cid = 0;
         int.TryParse(request["cid"], out cid);
         if (cid > 0)
         {
             category_id = cid;
         }
     }
     int total = 0;
     data.data = stockManager.SearchProductWastage(sids, keyword, category_id, page, pageSize, out total);
     data.curPage = page;
     data.totalRecords = total;
     return data;
 }
Beispiel #12
0
        public PQGridData SearchProductsStore()
        {
            PQGridData data = new PQGridData();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            StockManager stockManager = new StockManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            int page = 1;
            int pageSize = 30;
            int category = 0;
            int storeHouse = 0;

            int.TryParse(request["cid"],out category);
            int.TryParse(request["house"],out storeHouse);
            int.TryParse(request["page"],out page);
            int.TryParse(request["pageSize"],out pageSize);
            string keyword = request["keyword"];
            int total = 0;
            data.data=stockManager.SearchProductsStocks(null, category, storeHouse, keyword, page, pageSize, out total);
            data.curPage = page;
            data.totalRecords = total;
            return data;
        }
Beispiel #13
0
        public PQGridData SearchLeaveStock()
        {
            PQGridData data = new PQGridData();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            StockManager stockManager = new StockManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            int page = 1;
            int pageSize = 30;
            string sale_id = request["sale_id"];
            int leave_id=0;
            int uid = 0;
            long stime = 0;
            long etime = 0;
            if (!string.IsNullOrEmpty(request["sdate"]))
            {
                DateTime sdate = DateTime.MinValue;
                DateTime.TryParse(request["sdate"],out sdate);
                if (sdate != DateTime.MinValue)
                {
                    stime = DateTimeUtil.ConvertDateTimeToInt(sdate);
                }
            }
            if (!string.IsNullOrEmpty(request["edate"]))
            {
                DateTime edate = DateTime.MinValue;
                DateTime.TryParse(request["edate"], out edate);
                if (edate != DateTime.MinValue)
                {
                    etime = DateTimeUtil.ConvertDateTimeToInt(edate);
                }
            }
            int.TryParse(request["page"], out page);
            int.TryParse(request["pageSize"], out pageSize);

            int.TryParse(request["leave_id"], out leave_id);
            int.TryParse(request["user_id"], out uid);
            int total = 0;

            int[] leave_ids = null;
            int[] user_ids = null;
            string[] sale_ids = null;
            if (leave_id > 0)
            {
                leave_ids = new int[] { leave_id };
            }
            if (uid > 0)
            {
                user_ids = new int[] { uid };
            }

            if (!string.IsNullOrEmpty(sale_id))
            {
                sale_ids = new string[] { sale_id };
            }

            data.data = stockManager.SearchLeaveStocks(leave_ids, sale_ids, user_ids, stime, etime, page, pageSize, out total);
            data.curPage = page;
            data.totalRecords = total;
            return data;
        }
Beispiel #14
0
        public PQGridData GetStoreHouses()
        {
            PQGridData data = new PQGridData();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            StockManager stockManager = new StockManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);

            List<BStoreHouse> houses = stockManager.GetStoreHouses();
            data.totalRecords = houses.Count;
            data.data = houses;
            data.curPage = 1;
            return data;
        }
Beispiel #15
0
        public ApiMessage EnterStockFromBuy()
        {
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            StockManager stockManager = new StockManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            ApiMessage message = new ApiMessage();

            int[] buy_ids =null;
            int updateStock = 0;
            int shouseId = 0;

            buy_ids = base.ConvertToIntArrar(request["buy_ids"]);
            int.TryParse(request["update_stock"], out updateStock);
            int.TryParse(request["house_id"], out shouseId);
            try
            {
                if (buy_ids != null)
                {
                    foreach (int buy_id in buy_ids)
                    {
                        BEnterStock stock = new BEnterStock();
                        stock.BuyID = buy_id;
                        stock.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                        stock.StoreHouse = new BStoreHouse() { ID = shouseId, Shop = new BShop() { ID = stockManager.Shop.Shop_ID } };
                        if (updateStock == 1)
                        {
                            stock.UpdateStock = true;
                        }

                        stockManager.CreateEnterStock(stock);
                    }
                }

                message.Status = "ok";
                message.Message = "";
            }
            catch (JXC.Common.KMException.KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = "未知错误";
            }
            finally
            {

            }

            return message;
        }
Beispiel #16
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BEnterStock GetEnterStockFullInfo(int id)
        {
            BEnterStock bstock = null;
            using (KuanMaiEntities db = new KuanMaiEntities())
            {

                bstock = (from stock in db.Enter_Stock
                          where stock.Enter_Stock_ID == id
                          select new BEnterStock
                          {
                              ID = stock.Enter_Stock_ID,
                              Created = (Int32)stock.Enter_Date,
                              Created_By = (from user in db.User
                                            where user.User_ID == stock.User_ID
                                            select new BUser
                                            {
                                                ID=user.User_ID,
                                                Name=user.Name,
                                                Mall_ID=user.Mall_ID,
                                                Mall_Name=user.Mall_Name
                                            }).FirstOrDefault<BUser>(),
                              Shop = (from shop in db.Shop
                                      where shop.Shop_ID == stock.Shop_ID
                                      select new BShop
                                      {
                                          ID = shop.Shop_ID,
                                          Mall_ID = shop.Mall_Shop_ID,
                                          Created = (int)shop.Created,
                                          Description = shop.Description,
                                          Title = shop.Name
                                      }).FirstOrDefault<BShop>(),
                              Status = (int)stock.Status,
                              StoreHouse = (from house in db.Store_House
                                            where house.StoreHouse_ID == stock.StoreHouse_ID
                                            select new BStoreHouse
                                            {
                                                ID=house.StoreHouse_ID,
                                                Name=house.Title,
                                                Phone=house.Phone,
                                                Address=house.Address
                                            }).FirstOrDefault<BStoreHouse>(),
                              BuyID = (int)stock.Buy_ID

                          }).FirstOrDefault<BEnterStock>();

                if (bstock == null)
                {
                    throw new KMJXCException("编号为:"+id+" 的入库单信息不存在");
                }

                if (bstock != null)
                {
                    BuyManager buyManager = new BuyManager(this.CurrentUser,this.Shop,this.CurrentUserPermission);
                    bstock.Buy = buyManager.GetBuyFullInfo(bstock.BuyID);
                    bstock.Details = (from detail in db.Enter_Stock_Detail
                                      where detail.Enter_Stock_ID == id
                                      select new BEnterStockDetail
                                      {
                                          Created = (int)detail.Create_Date,
                                          InvoiceAmount = (double)detail.Invoice_Amount,
                                          Invoiced = (bool)detail.Have_Invoice,
                                          InvoiceNumber = detail.Invoice_Num,
                                          Price = (double)detail.Price,
                                          Quantity = detail.Quantity,
                                          StockProductId = detail.Product_ID
                                      }).ToList<BEnterStockDetail>();
                }
            }
            return bstock;
        }