Exemplo n.º 1
0
        /// <summary>
        /// 提交收货单表单(新增、编辑)
        /// </summary>
        /// <param name="keyValue">收货单主键</param>
        /// <param name="entity">收货单实体</param>
        /// <param name="receiptItemJson">收货单明细</param>
        /// <returns></returns>
        public ActionResult SubmitReceiptForm(string keyValue, ReceiptEntity entity, string receiptItemJson)
        {
            IDatabase     database    = DataFactory.Database();
            DbTransaction isOpenTrans = database.BeginTrans();

            try
            {
                string message = keyValue == "" ? "新增成功。" : "修改成功。";
                if (!string.IsNullOrEmpty(keyValue))
                {
                    var receipt = database.FindEntity <ReceiptEntity>("ReceiptId", keyValue);
                    if (receipt.Status != 0)
                    {
                        throw new Exception("非初始状态的收货单不能修改");
                    }
                    database.Delete <ReceiptEntity>("ReceiptId", keyValue, isOpenTrans);
                    database.Delete <ReceiptItemEntity>("ReceiptId", keyValue, isOpenTrans);
                    entity.Create();
                    entity.ReceiptDate = DateTime.Now;
                    entity.Modify(keyValue);
                    database.Insert(entity, isOpenTrans);
                }
                else
                {
                    entity.Create();
                    entity.ReceiptDate = DateTime.Now;
                    database.Insert(entity, isOpenTrans);
                    _codeRuleBll.OccupyBillCode(ManageProvider.Provider.Current().UserId, ReceiptCodeName, isOpenTrans);
                }

                var receiptItemList = receiptItemJson.JonsToList <ReceiptItemViewModel>();
                foreach (var item in receiptItemList)
                {
                    if (!string.IsNullOrEmpty(item.ProductId))
                    {
                        ProductEntity product   = _productBll.GetProduct(item.ProductId);
                        var           orderItem = new ReceiptItemEntity();
                        orderItem.Create();
                        orderItem.ReceiptId   = entity.ReceiptId;
                        orderItem.ProductId   = product.ProductId;
                        orderItem.SourceNo    = item.SourceNo;
                        orderItem.Code        = product.Code;
                        orderItem.ProductName = product.ProductName;
                        orderItem.Qty         = item.Qty;
                        database.Insert(orderItem, isOpenTrans);
                    }
                }
                database.Commit();
                return(Content(new JsonMessage {
                    Success = true, Code = "1", Message = message
                }.ToString()));
            }
            catch (Exception ex)
            {
                database.Rollback();
                return(Content(new JsonMessage {
                    Success = false, Code = "-1", Message = "操作失败:" + ex.Message
                }.ToString()));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 审核订单
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public int Audit(PurchaseOrderEntity order)
        {
            IDatabase     database    = DataFactory.Database();
            DbTransaction isOpenTrans = database.BeginTrans();

            try
            {
                PurchaseOrderEntity purchaseOrder = DataFactory.Database().FindEntity <PurchaseOrderEntity>(order.OrderId);
                if (purchaseOrder == null)
                {
                    throw new Exception("采购单不存在");
                }

                StringBuilder strSql = new StringBuilder();
                strSql.Append(@"UPDATE dbo.PurchaseOrder
                            SET Status = 1, ModifyUserId = @ModifyUserId,
                                ModifyUserName = @ModifyUserName, ModifyDate = @ModifyDate
                            WHERE OrderId = @OrderId
                                AND Status = 0");
                List <DbParameter> parameter = new List <DbParameter>();
                parameter.Add(DbFactory.CreateDbParameter("@ModifyUserId", order.ModifyUserId));
                parameter.Add(DbFactory.CreateDbParameter("@ModifyUserName", order.ModifyUserName));
                parameter.Add(DbFactory.CreateDbParameter("@ModifyDate", order.ModifyDate));
                parameter.Add(DbFactory.CreateDbParameter("@OrderId", order.OrderId));
                int result = database.ExecuteBySql(strSql, parameter.ToArray(), isOpenTrans);
                if (result > 0)
                {
                    string userId = ManageProvider.Provider.Current().UserId;

                    ReceiptEntity entity = new ReceiptEntity();
                    entity.ReceiptId   = CommonHelper.GetGuid;
                    entity.ReceiptNo   = _codeRuleBLL.GetBillCode(userId, "Receipt");
                    entity.ReceiptDate = purchaseOrder.OrderDate;
                    entity.ReceiptType = 1;
                    entity.WarehouseId = purchaseOrder.WarehouseId;
                    entity.MerchantId  = purchaseOrder.MerchantId;
                    entity.SourceNo    = purchaseOrder.OrderNo;
                    entity.Status      = 0;
                    entity.Create();

                    database.Insert(entity, isOpenTrans);

                    List <PurchaseOrderItemEntity> orderItemList = GetOrderItemList(order.OrderId);

                    foreach (PurchaseOrderItemEntity item in orderItemList)
                    {
                        var orderItem = new ReceiptItemEntity();
                        orderItem.Create();
                        orderItem.ReceiptId   = entity.ReceiptId;
                        orderItem.ProductId   = item.ProductId;
                        orderItem.Code        = item.Code;
                        orderItem.ProductName = item.ProductName;
                        orderItem.Qty         = item.Qty;
                        database.Insert(orderItem, isOpenTrans);
                    }
                }
                database.Commit();
                return(result);
            }
            catch
            {
                database.Rollback();
                return(-1);
            }
        }