Example #1
0
        protected void SerachSubmit(object sender, EventArgs e)
        {
            //getItemStockInThisShop
            string condition = Request.Form["searchCondition"];
            string serachKey = Request.Form["searchKey"];

            System.Diagnostics.Debug.WriteLine("serach key and serach condition test :" + serachKey + condition);

            if (condition.Equals("staffName"))
            {
                searchResult = DBModel.sharedDBModel().getItemByItemName(serachKey);
            }
            else
            {
                searchResult = DBModel.sharedDBModel().getItemByItemId(serachKey);
            }

            for (int i = 0; i < searchResult.Length; i++)
            {
                stock x = DBModel.sharedDBModel().getItemStockInThisShop(theStaff.staffId, searchResult[i].itemId);
                thisStock[i] = x;
            }
        }
        /**
         * 35.店长为申请添加条目(补货)
         * 参数:申请表Id,货物Id和货物数量
         * 返回:是否成功添加了申请表细节(通过测试,需要先增加apply条目然后再增加applyDetail)
         */
        public bool addApplyDetailInfoFromSystemWithApplyIdItemIdAndItemAmount(string staffId, string currentApplyId,string currentItemId, int currentItemAmount) 
        {
            using (YMDBEntities db = new YMDBEntities())
            {

                string shopId = getShopIdByStaffId(staffId);
                try
                {
                    applyDetail tem = db.applyDetail.Where(p => p.applyId == currentApplyId & p.itemId == currentApplyId).FirstOrDefault();
                    if (tem == null)
                    {
                        applyDetail newApplyDetail = new applyDetail
                        {
                            applyId = currentApplyId,
                            itemId = currentItemId,
                            applyAmount = currentItemAmount,
                        };
                        db.applyDetail.Add(newApplyDetail);
                    }
                    else
                    {
                        tem.applyAmount = tem.applyAmount + currentItemAmount;
                    }

                    stock newStock = new stock
                    {
                        itemId = currentItemId,
                        shopId = shopId,
                        stockAmount = currentItemAmount,
                        saleAmount = 0,
                        stockLimit = 1000,
                        purchaseAmount = 0,
                    };
                    db.stock.Add(newStock);

                    inBase newIn = addNewInBaseRecord(staffId);
                    addInDetailToInWithItemIdAndItemAmount(newIn.inId, currentItemId, currentItemAmount);

                    
                    db.SaveChanges();
                    return true;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("申请表细节添加失败,八成是你applyId输错了.");
                    System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                    return false;
                }                
            }
        }
        /**
         * 37.店长为申请添加条目(调货)
         * 参数:申请表Id,货物Id和货物数量
         * 返回:是否成功添加了申请表细节(需要优化)
         * 注意:如果申请调货的店没有对应的货会报空指针错误
         */
        public bool addApplyDetailInfoFromOtherShopWithApplyIdItemIdAndItemAmount(string staffId ,string currentApplyId,string currentItemId, int currentItemAmount) 
        {
            bool isSucceed = false;

            using (YMDBEntities db = new YMDBEntities())
            {

                string shopId = getShopIdByStaffId(staffId);

                try
                {
                    apply outShop = db.apply.Where(p => p.applyId == currentApplyId).FirstOrDefault();
                    stock itemStock = db.stock.Where(p => p.shopId == outShop.outShop & p.itemId == currentItemId).FirstOrDefault();
                    decimal realAmount = itemStock.stockAmount;
                    if (currentItemAmount > realAmount)
                    {
                        return false;
                    }
                    else
                    {
                        applyDetail tem = db.applyDetail.Where(p => p.applyId == currentApplyId & p.itemId == currentApplyId).FirstOrDefault();

                        if (tem == null)
                        {
                            applyDetail newApplyDetail = new applyDetail
                            {
                                applyId = currentApplyId,
                                itemId = currentItemId,
                                applyAmount = currentItemAmount,
                            };
                            db.applyDetail.Add(newApplyDetail);
                        }
                        else
                        {
                            if (tem.applyAmount + currentItemAmount > realAmount)
                            {
                                return false;
                            }
                            else
                            {
                                tem.applyAmount = tem.applyAmount + currentItemAmount;
                            }
                        }

                        stock newStock = new stock
                        {
                            itemId = currentItemId,
                            shopId = shopId,
                            stockAmount = currentItemAmount,
                            saleAmount = 0,
                            stockLimit = 1000,
                            purchaseAmount = 0,
                        };
                        db.stock.Add(newStock);

                        inBase newIn = addNewInBaseRecord(staffId);
                        addInDetailToInWithItemIdAndItemAmount(newIn.inId, currentItemId, currentItemAmount);

                        db.SaveChanges();
                        isSucceed = true;
                        return isSucceed;
                    } 
                }
                catch(NullReferenceException ex) 
                {
                    System.Diagnostics.Debug.WriteLine("店长申请增加条目失败,对应的店没有相应货物或是applyId不存在.");
                    System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                    return false;
                }
            }
        }