/* * 3.删除员工 * 参数:员工id * 返回值:成功返回true,失败或员工不存在返回false */ public bool deleteStaffByStaffId(string deletedStaffId) { //从数据库中查询要删除的员工 using (YMDBEntities db = new YMDBEntities()) { try { //数据库删除员工 //成功后将deletedSucceed赋值为true db.staff.Remove(db.staff.Where(p => p.staffId == deletedStaffId).FirstOrDefault()); db.SaveChanges(); return true; } catch (ArgumentNullException ex) { System.Diagnostics.Debug.WriteLine("输入的staffId有问题."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return false; } } }
/** * 62.增加商店出库记录(测试通过) * 参数:员工Id * 返回值:出库记录 */ public outBase addNewOutBaseRecord(string staffId) { string shopId = getShopIdByStaffId(staffId); string newId = createNewId("outBase"); using (YMDBEntities db = new YMDBEntities()) { try { outBase newOutBase = new outBase { outId = newId, shopId = shopId, staffId = staffId, outTime = DateTime.Now, outType = "export", }; db.outBase.Add(newOutBase); db.SaveChanges(); return newOutBase; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("没找到shopId导致完整性约束不满足,拒绝插入数据库,请检查staffId."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return null; } } }
/** * 32.店长进行盘点(最终目的是检查是否有人偷东西) * 参数:员工Id * 返回:最近现在各个商品集合(包括名称和) * 备注:其实可以通过库存方法来获取(通过测试) */ public checkDetail[] getCheckDetailInfoWithStaffId(string currentCheckId, string staffId) { string shopId = getShopIdByStaffId(staffId); using (YMDBEntities db = new YMDBEntities()) { try { stock[] itemStock = db.stock.Where(p => p.shopId == shopId).ToArray(); checkDetail[] currentCheckDetail = new checkDetail[itemStock.Length]; for (int i = 0; i < itemStock.Length; i++) { currentCheckDetail[i] = new checkDetail { itemId = itemStock[i].itemId, checkId = currentCheckId, currentAmount = itemStock[i].stockAmount, }; db.checkDetail.Add(currentCheckDetail[i]); } db.SaveChanges(); return currentCheckDetail; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("检查checkId和staffId是否在checkDetail已经存在,或者两者输入错误."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); checkDetail[] emptyArray = { }; return emptyArray; } } }
/** * 34.店长申请从总库补货 * 参数:店长的Id * 返回:新建的补货申请表 * 备注:申请表的状态默认同意状态(通过测试) */ public apply addApplyFromSystem(string staffId) { string newId = createNewId("apply"); string shopId = getShopIdByStaffId(staffId); using (YMDBEntities db = new YMDBEntities()) { try { apply newApply = new apply { applyId = newId, outShop = "SYSTEM", inShop = shopId, state = "ok", applyTime = DateTime.Now, }; db.apply.Add(newApply); db.SaveChanges(); return newApply; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("你输错了总库不给你补货,回家去反省."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return null; } } }
/** * 24.员工为新建的入库登记表填写详细信息 * 参数:入库Id,商品Id,商品数量Amount * 返回:是否成功入库(未测) //增加修改库存信息 */ public bool addInDetailToInWithItemIdAndItemAmount(string currentInId, string currentItemId, int currentItemAmount) { bool isSucceed = false; using (YMDBEntities db = new YMDBEntities()) { inDetail currentInDetail = new inDetail { inId = currentInId, itemId = currentItemId, inAmount = currentItemAmount, }; db.inDetail.Add(currentInDetail); inBase currentInBase = db.inBase.Where(p => p.inId == currentInId).FirstOrDefault(); stock currentStock = db.stock.Where(p => p.shopId == currentInBase.shopId & p.itemId == currentItemId).FirstOrDefault(); currentStock.stockAmount = currentStock.stockAmount + currentItemAmount; db.SaveChanges(); } return isSucceed; }
/** * 26.员工为新建的出库登记表添加详细信息 * 参数:货物Id,货物数量 * 返回:是否成功出库(测试通过) //增加修改库存信息 */ public bool addOutDetailToOutWithItemIdAndItemAmount(string currentOutId, string currentItemId, int currentItemAmount) { using (YMDBEntities db = new YMDBEntities()) { try { outDetail currentOutDetail = new outDetail { outId = currentOutId, itemId = currentItemId, outAmount = currentItemAmount, }; db.outDetail.Add(currentOutDetail); outBase currentOutBase = db.outBase.Where(p => p.outId == currentOutId).FirstOrDefault(); stock currentStock = db.stock.Where(p => p.shopId == currentOutBase.shopId & p.itemId == currentItemId).FirstOrDefault(); currentStock.stockAmount = currentStock.stockAmount - currentItemAmount; db.SaveChanges(); return true; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("添加出库详细错误."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return false; } } }
/** * 42.Boss修改商品状态 * 参数:商品Id,商品的新状态 * 返回:是否修改成功(通过测试) */ public bool modifyStatusOfItem(string currentItemId, int newStatus) { if (newStatus != 0 && newStatus != 1) { return false; } using (YMDBEntities db = new YMDBEntities()) { try { item currentItem = db.item.Where(p => p.itemId == currentItemId).FirstOrDefault(); currentItem.itemStatus = newStatus; db.SaveChanges(); return true; } catch (NullReferenceException ex) { System.Diagnostics.Debug.WriteLine("拜托,修改商品状态又空指针了,认真一点输参数好不好."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return false; } } }
/** * 18.员工在订单中添加一条订单详细信息 * 参数:订单Id,货物Id,货物数量 * 返回:成功返回true,失败返回false * 注意:不要重复添加某一条商品的信息(通过测试) */ public bool addOrderDetailToOrderWithOrderIdAndItemIdAndItemAmount(string newOrderId, string newItemId, int newItemAmount) { using(YMDBEntities db = new YMDBEntities()) { try { string newId2 = "outBase_"; for (int i = 6; i < newOrderId.Length; i++) { newId2 = newId2 + newOrderId[i]; } order currentOrder = db.order.Where(p => p.orderId == newOrderId).FirstOrDefault(); orderDetail currentOrderDetail = new orderDetail { orderId = newOrderId, itemId = newItemId, itemAmount = newItemAmount, }; db.orderDetail.Add(currentOrderDetail); item currentItem = db.item.Where(p => p.itemId == newItemId).FirstOrDefault(); currentOrder.totalPrice = currentOrder.totalPrice + currentItem.itemPrice * newItemAmount; stock currentStock = db.stock.Where(p => p.shopId == currentOrder.shopId & p.itemId == newItemId).FirstOrDefault(); currentStock.stockAmount = currentStock.stockAmount - newItemAmount; currentStock.saleAmount = currentStock.saleAmount + newItemAmount; outDetail newOutBase = new outDetail { outId = newId2, itemId = newItemId, outAmount = newItemAmount, }; db.outDetail.Add(newOutBase); db.SaveChanges(); return true; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("添加orderDetail错误,可能是参数错误."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return false; } } }
/** * 40.Boss增加商品的图片信息 * 参数:需要增加的商品的Id,图片的地址(或者编号) * 返回:图片实例(通过测试) */ public image addImageToItem(string currentItemId, string currentImagePath) { using (YMDBEntities db = new YMDBEntities()) { try { image newImage = new image { imagePath = currentImagePath, itemId = currentItemId, }; db.image.Add(newImage); db.SaveChanges(); return newImage; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("haha~保存不了吧,好好看看参数是不输错了."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return null; } } }
/** * 41.Boss修改商品信息 * 参数:修改后的商品的名字、尺寸、颜色、价格 * 返回:商品实例(通过测试) */ public item modifyItemByBoss(string currentItemId, string currentItemName, string currentItemSize, string currentItemColor, double currentItemPrice) { if (currentItemSize.Length > 5) { return null; } using (YMDBEntities db = new YMDBEntities()) { try { item newItem = db.item.Where(p => p.itemId == currentItemId).FirstOrDefault(); newItem.itemName = currentItemName; newItem.itemSize = currentItemSize; newItem.itemColor = currentItemColor; newItem.itemPrice = (decimal)currentItemPrice; db.SaveChanges(); return newItem; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("修改商品信息参数输错了,回去再看一遍,仔细看!!!!!!!"); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return null; } } }
/** * 39.Boss增加商品 * 参数:新增商品的名字、尺寸、颜色、价格 * 返回:商品实例(测试通过) */ public item addItemByBoss(string currentItemName, string currentItemSize, string currenttemColor, double currentItemPrice) { if (currentItemSize.Length > 5) { return null; } string newId = createNewId("item"); using (YMDBEntities db = new YMDBEntities()) { //decimal newItem = new item().itemPrice; item newItem = new item { itemName = currentItemName, itemSize = currentItemSize, itemPrice = (decimal)currentItemPrice, itemColor = currenttemColor, itemDate = DateTime.Now, itemId = newId, itemStatus = 1, }; db.item.Add(newItem); db.SaveChanges(); return newItem; } }
/** * 38.店长对其他店的申请进行审批 * 参数:店长Id,是否同意bool值 * 返回:审批是否成功的bool值(通过测试) */ public bool dealWithApplyFromOtherShop(string currentApplyId, string staffId, bool dealFlag) { bool isAgree = true; string shopId = getShopIdByStaffId(staffId); using (YMDBEntities db = new YMDBEntities()) { try { apply currentApply = db.apply.Where(p => p.applyId == currentApplyId & p.outShop == shopId).FirstOrDefault(); if (dealFlag == true) { currentApply.state = "yes"; } else { currentApply.state = "no"; isAgree = false; } db.SaveChanges(); return isAgree; } catch (NullReferenceException ex) { System.Diagnostics.Debug.WriteLine("店长审批调货申请失败,空指针异常,未输入正确的参数."); 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; } } }
/* * 7.修改门店信息 * 参数:门店id,新地址,新电话,新的门店状态,不修改的值为null * 返回值:bool,成功返回true,失败返回false */ public bool modifyShopInfo(string shopId, string newAddress,int newStatus, string newPhone) { bool isSucceed = false; using(YMDBEntities db = new YMDBEntities()) { try { shop shopToChangeInfo = db.shop.Where(p => p.shopId == shopId).FirstOrDefault(); shopToChangeInfo.shopAddress = newAddress; shopToChangeInfo.shopStatus = newStatus; shopToChangeInfo.shopPhone = newPhone; db.SaveChanges(); isSucceed = true; } catch(Exception ex) { System.Diagnostics.Debug.WriteLine("没找到shop或者输入参数绝对有问题,仔细查外键约束!!!!"); System.Diagnostics.Debug.WriteLine(ex.Message); return false; } } return isSucceed; }
/** * 43.Boss指派店长 * 参数:商店Id,新店长的Id * 返回:新店长的实例(通过测试) */ public staff assignManagerToShop(string shopId, string managerId) { //写入数据库 using (YMDBEntities db = new YMDBEntities()) { try { staff manager = db.staff.Where(p => p.staffId == managerId).FirstOrDefault(); manager.staffJob = 1; manager.shopId = shopId; db.SaveChanges(); return manager; } catch (NullReferenceException ex) { System.Diagnostics.Debug.WriteLine("分配店长时空指针了吧,自己看着办吧,我是不管了."); System.Diagnostics.Debug.WriteLine(ex.Message); return null; } } }
/** * 17.员工增加订单记录 * 参数:staffId, 这次订单的详细信息数组 * 返回值:本次订单(需要修改stock) //个人感觉这个不需要修改库存,在添加细节的时候再修改库存------->请注意 */ public order addOrderInfo(string staffId) { string newId = createNewId("order"); string newId2 = "outBase_"; for (int i = 6; i < newId.Length; i++) { newId2 = newId2 + newId[i]; } string shopId = getShopIdByStaffId(staffId); using (YMDBEntities db = new YMDBEntities()) { try { staff targetStaff = findStaffByStaffId(staffId); order targetOrder = new order { orderId = newId, shopId = targetStaff.shopId, totalPrice = 0, orderTime = DateTime.Now, }; db.order.Add(targetOrder); outBase newOutBase = new outBase { outId = newId2, shopId = shopId, staffId = staffId, outTime = DateTime.Now, outType = "sell", }; db.outBase.Add(newOutBase); db.SaveChanges(); return targetOrder; } catch (NullReferenceException ex) { System.Diagnostics.Debug.WriteLine("输入staffId的时候有问题,回去查!!!!!"); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return null; } } }
/** * 44.Boss新增地址信息 * 参数:地址名称,详细地址 * 返回:新的地址的实例 * 完成测试 */ public address addNewAddress(string addressName, string addressDetail) { address newAddress = new address { addressId = createNewId("address"), addressName = addressName, addressDetail = addressDetail, }; //写入数据库 using(YMDBEntities db = new YMDBEntities()) { try { db.address.Add(newAddress); db.SaveChanges(); } catch(Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return null; } } return newAddress; }
/** * 23.员工新建入库登记表 * 参数:员工Id * 返回:一个新添加的入库登记表(通过测试) //个人感觉这个不需要修改库存,在添加细节的时候再修改库存------->请注意 */ public inBase addNewIn(string inStaffId){ string currentShopId = getShopIdByStaffId(inStaffId); using (YMDBEntities db = new YMDBEntities()) { try { string newId = createNewId("inBase"); inBase newInBase = new inBase { inId = newId, shopId = currentShopId, staffId = inStaffId, inTime = DateTime.Now, }; db.inBase.Add(newInBase); db.SaveChanges(); return newInBase; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("添加入库失败."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return null; } } }
/** * 4.更改员工信息 * 参数:员工id,姓名,电话,密码 * 返回值:成功返回true,失败返回false */ public bool modifyPersonalInformation(staff currentInfo) { using (YMDBEntities db = new YMDBEntities()) { try { staff oldStaff = db.staff.Where(p => p.staffId == currentInfo.staffId).FirstOrDefault(); oldStaff.staffLoginName = currentInfo.staffLoginName; oldStaff.password = currentInfo.password; oldStaff.staffPhone = currentInfo.staffPhone; db.SaveChanges(); return true; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("修改失败,没有这员工."); System.Diagnostics.Debug.WriteLine(ex.Message); return false; } } }
/** * 25.员工新建出库登记表 * 参数:员工Id,出库类型 * 返回:员工新建一个出库登记表(通过测试) */ public outBase addNewOut(string outStaffId,string currentOutType) { if (!currentOutType.Equals("调货") && !currentOutType.Equals("补货")) { System.Diagnostics.Debug.WriteLine("新建出库登记表出错啦."); return null; } string currentShopId = getShopIdByStaffId(outStaffId); using (YMDBEntities db = new YMDBEntities()) { try { string newId = createNewId("outBase"); outBase newOutBase = new outBase { outId = newId, shopId = currentShopId, staffId = outStaffId, outType = currentOutType, outTime = DateTime.Now, }; db.outBase.Add(newOutBase); db.SaveChanges(); return newOutBase; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("出库登记表添加失败."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return null; } } }
/** * 48.如果盘点后商品数量不一致,进行更改,修改库存(通过测试) * 参数:店长Id,货物Id,现有数量 * 返回值:库存信息 */ public stock changeStockByStaffIdAndItemId(string staffId, string itemId, int currentAmount) { try { if (currentAmount < 0) { return null; } string shopId = getShopIdByStaffId(staffId); using (YMDBEntities db = new YMDBEntities()) { stock currentItem = db.stock.Where(p => p.itemId == itemId & p.shopId == shopId).FirstOrDefault(); currentItem.stockAmount = currentAmount; db.SaveChanges(); return currentItem; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("输入有误,总之我不给你修改数据库,自己看着办."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return null; } }
/** * 2.添加新员工 * 参数:新员工名字 * 返回值:成功返回员工id,失败返回0 */ public staff addNewStaff(string newStaffName, string newStaffPassword, string newShopId, int newStaffJob, string newGender, string newPhone) { string newId = createNewId("staff");//根据一个算法产生ID staff newStaff = new staff { staffId = newId, staffName = newStaffName, password = newStaffPassword, staffLoginName = newId, shopId = newShopId, staffJob = newStaffJob, staffGender = newGender, staffPhone = newPhone }; //写入数据库 using (YMDBEntities db = new YMDBEntities()) { try { db.staff.Add(newStaff); db.SaveChanges(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("员工添加异常"); System.Diagnostics.Debug.WriteLine(ex.Message); } } return newStaff; }
/** * 58.新增盘点记录(测试通过) * 参数:员工Id * 返回值:盘点记录 */ public check addNewCheckRecord(string staffId) { string shopId = getShopIdByStaffId(staffId); System.Diagnostics.Debug.WriteLine("shopIdhihif:" + shopId); string newCheckId = createNewId("check"); using (YMDBEntities db = new YMDBEntities()) { try { check newCheck = new check { checkerId = staffId, shopId = shopId, checkTime = DateTime.Now, checkId = newCheckId, }; db.check.Add(newCheck); db.SaveChanges(); return newCheck; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("没找到shopId导致完整性约束不满足,拒绝插入数据库,请检查staffId."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return null; } } }
/** * 33.店长更改订单信息 * 参数:要修改的Order的Id,店长的Id * 返回:返回修改过的Order实例(通过测试) */ public orderDetail modifyOrderInfoWithOrderIdByShopManager(string originOrderId, string staffId, string currentItemId, int currentItemAmount) { using(YMDBEntities db = new YMDBEntities()) { try { order currentOrder = db.order.Where(p => p.orderId == originOrderId).FirstOrDefault(); orderDetail newOrder = db.orderDetail.Where(p => p.itemId == currentItemId & p.orderId == originOrderId).FirstOrDefault(); item currentItem = db.item.Where(p => p.itemId == currentItemId).FirstOrDefault(); decimal itemPrice = currentItem.itemPrice; decimal oldItemAmount = newOrder.itemAmount; newOrder.itemAmount = currentItemAmount; currentOrder.totalPrice = currentOrder.totalPrice - itemPrice * oldItemAmount + itemPrice * currentItemAmount; db.SaveChanges(); return newOrder; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("更改订单信息参数错了...已经懒得说你..."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return null; } } }
/* * 5.增加新门店 * 参数:店长id,新门店地址,新门店电话 * 返回值:门店实例,失败返回null */ public shop addNewShopWithManagerIdAndAddressIdAndShopPhone(string newShopManagerId, string newShopAddress, string newShopPhone) { //写入数据库 using (YMDBEntities db = new YMDBEntities()) { System.Diagnostics.Debug.WriteLine("lalalalalasdk:" + newShopAddress); shop newShop = new shop { shopAddress = newShopAddress, shopPhone = newShopPhone, shopId = createNewId("shop"), shopStatus = 1, }; try { System.Diagnostics.Debug.WriteLine("shop0Id:" + newShop.shopAddress); db.shop.Add(newShop); db.SaveChanges(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Address输入有误."); System.Diagnostics.Debug.WriteLine(ex.Message); return null; } return newShop; } }
/** * 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; } } }
/** * 36.店长申请从其他店面调货 * 参数:店长的Id,对方店面的Id * 返回:新建的调货申请表 * 备注:申请表的状态需要设置为申请状态(通过测试) */ public apply addApplyFromOtherShop(string staffId, string otherShopId) { string shopId = getShopIdByStaffId(staffId); if (shopId.Equals(otherShopId)) { System.Diagnostics.Debug.WriteLine("你这玩儿啥呢?自己向自己店申请调货?回去看看参数是不搞错了."); return null; } string newId = createNewId("apply"); using (YMDBEntities db = new YMDBEntities()) { try { apply newApply = new apply { applyId = newId, outShop = otherShopId, inShop = shopId, state = "ok", applyTime = DateTime.Now, }; db.apply.Add(newApply); db.SaveChanges(); return newApply; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("调货申请不满足外键约束,自己找问题吧."); System.Diagnostics.Debug.WriteLine(ex.StackTrace); return null; } } }