public async Task <VerifyRecordResult> UpdateAsync(FlowMasterAdapterModel paraObject)
        {
            try
            {
                FlowMaster itemData = Mapper.Map <FlowMaster>(paraObject);
                CleanTrackingHelper.Clean <FlowMaster>(context);
                FlowMaster item = await context.FlowMaster
                                  .AsNoTracking()
                                  .FirstOrDefaultAsync(x => x.Id == paraObject.Id);

                if (item == null)
                {
                    return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.無法修改紀錄));
                }
                else
                {
                    CleanTrackingHelper.Clean <FlowMaster>(context);
                    context.Entry(itemData).State = EntityState.Modified;
                    await context.SaveChangesAsync();

                    CleanTrackingHelper.Clean <FlowMaster>(context);
                    return(VerifyRecordResultFactory.Build(true));
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "修改記錄發生例外異常");
                return(VerifyRecordResultFactory.Build(false, "修改記錄發生例外異常", ex));
            }
        }
        public async Task <VerifyRecordResult> DeleteAsync(int id)
        {
            try
            {
                CleanTrackingHelper.Clean <FlowMaster>(context);
                FlowMaster item = await context.FlowMaster
                                  .AsNoTracking()
                                  .FirstOrDefaultAsync(x => x.Id == id);

                if (item == null)
                {
                    return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.無法刪除紀錄));
                }
                else
                {
                    #region 刪除其他關連紀錄
                    CleanTrackingHelper.Clean <FlowUser>(context);
                    CleanTrackingHelper.Clean <FlowHistory>(context);
                    CleanTrackingHelper.Clean <FlowInbox>(context);
                    var auditUsers = await context.FlowUser
                                     .Where(x => x.FlowMasterId == id)
                                     .ToListAsync();

                    context.FlowUser.RemoveRange(auditUsers);
                    var auditHistories = await context.FlowHistory
                                         .Where(x => x.FlowMasterId == id)
                                         .ToListAsync();

                    context.FlowHistory.RemoveRange(auditHistories);
                    var flowInbox = await context.FlowInbox
                                    .Where(x => x.FlowMasterId == id)
                                    .ToListAsync();

                    context.FlowInbox.RemoveRange(flowInbox);
                    await context.SaveChangesAsync();

                    #endregion

                    CleanTrackingHelper.Clean <FlowMaster>(context);
                    context.Entry(item).State = EntityState.Deleted;
                    await context.SaveChangesAsync();

                    CleanTrackingHelper.Clean <FlowInbox>(context);
                    CleanTrackingHelper.Clean <FlowMaster>(context);
                    CleanTrackingHelper.Clean <FlowHistory>(context);
                    return(VerifyRecordResultFactory.Build(true));
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "刪除記錄發生例外異常");
                return(VerifyRecordResultFactory.Build(false, "刪除記錄發生例外異常", ex));
            }
        }
        public async Task <FlowMasterAdapterModel> GetAsync(int id)
        {
            FlowMaster item = await context.FlowMaster
                              .Include(x => x.MyUser)
                              .Include(x => x.PolicyHeader)
                              .AsNoTracking()
                              .FirstOrDefaultAsync(x => x.Id == id);

            FlowMasterAdapterModel result = Mapper.Map <FlowMasterAdapterModel>(item);

            await OhterDependencyData(result);

            return(result);
        }
        public async Task <FlowMasterAdapterModel> GetAsync(string code)
        {
            FlowMaster item = await context.FlowMaster
                              .Include(x => x.MyUser)
                              .Include(x => x.PolicyHeader)
                              .AsNoTracking()
                              .FirstOrDefaultAsync(x => x.Code == code);

            if (item == null)
            {
                return(null);
            }
            FlowMasterAdapterModel result = Mapper.Map <FlowMasterAdapterModel>(item);

            await OhterDependencyData(result);

            return(result);
        }
Esempio n. 5
0
        public ActionResult _OrderDetailList(string flow, string orderNo)
        {
            ViewBag.isManualCreateDetail = false;
            ViewBag.flow      = flow;
            ViewBag.orderNo   = orderNo;
            ViewBag.newOrEdit = "New";
            ViewBag.status    = null;

            FlowMaster flowMaster = null;

            if (!string.IsNullOrEmpty(orderNo))
            {
                ViewBag.status               = base.genericMgr.FindById <OrderMaster>(orderNo).Status;
                ViewBag.newOrEdit            = "Edit";
                ViewBag.isManualCreateDetail = ViewBag.status == com.Sconit.CodeMaster.OrderStatus.Create;
            }
            if (!string.IsNullOrEmpty(flow))
            {
                string flowcheckStr = "select f from FlowMaster as f where code = ? and type in (" + (int)com.Sconit.CodeMaster.OrderType.Distribution + "," + (int)com.Sconit.CodeMaster.OrderType.Transfer + "," + (int)com.Sconit.CodeMaster.OrderType.SubContractTransfer + ") and f.IsActive = " + true;
                flowMaster = base.genericMgr.FindAll <FlowMaster>(flowcheckStr, flow).SingleOrDefault <FlowMaster>();
                if (flowMaster != null)
                {
                    ViewBag.isManualCreateDetail = flowMaster.IsManualCreateDetail;
                    ViewBag.status = com.Sconit.CodeMaster.OrderStatus.Create;
                }
            }
            if (ViewBag.Status == com.Sconit.CodeMaster.OrderStatus.Create)
            {
                #region comboBox
                //IList<Item> items = base.genericMgr.FindAll<Item>(selecItemStatement, true);
                //ViewData.Add("items", items);
                IList <Uom> uoms = base.genericMgr.FindAll <Uom>();
                ViewData.Add("uoms", uoms);
                IList <Location> locationFroms = new List <Location>();
                if (flowMaster.PartyFrom != null)
                {
                    locationFroms = base.genericMgr.FindAll <Location>(selecLocationStatement, new object[] { flowMaster.PartyFrom, true });
                }
                ViewData.Add("locationFroms", locationFroms);
                #endregion
            }

            return(PartialView());
        }
Esempio n. 6
0
        public ActionResult _SelectBatchEditing(string orderNo, string flow)
        {
            IList <OrderDetail> orderDetailList = new List <OrderDetail>();

            if (!string.IsNullOrEmpty(flow) || !string.IsNullOrEmpty(orderNo))
            {
                if (!string.IsNullOrEmpty(orderNo))
                {
                    orderDetailList = base.genericMgr.FindAll <OrderDetail>(selectOrderDetailStatement, orderNo);
                }
                else
                {
                    string     flowcheckStr = "select f from FlowMaster as f where code = ? and type in (" + (int)com.Sconit.CodeMaster.OrderType.Distribution + "," + (int)com.Sconit.CodeMaster.OrderType.Transfer + "," + (int)com.Sconit.CodeMaster.OrderType.SubContractTransfer + ") and f.IsActive = " + true;
                    FlowMaster flowMaster   = base.genericMgr.FindAll <FlowMaster>(flowcheckStr, flow).SingleOrDefault <FlowMaster>();
                    if (flowMaster != null)
                    {
                        orderDetailList = TransformFlowDetailList2OrderDetailList(flow);
                    }
                }
            }
            return(View(new GridModel(orderDetailList)));
        }
Esempio n. 7
0
        public ActionResult _AjaxFlowDetailList(GridCommand command, FlowDetailSearchModel searchModel)
        {
            SearchStatementModel   searchStatementModel = PrepareDetailFlowSearchStatement(command, searchModel);
            GridModel <FlowDetail> List = GetAjaxPageData <FlowDetail>(searchStatementModel, command);

            if (!string.IsNullOrEmpty(searchModel.Flow))
            {
                FlowMaster flowMaster = base.genericMgr.FindById <FlowMaster>(searchModel.Flow);

                foreach (FlowDetail flowDetail in List.Data)
                {
                    flowDetail.ManufactureParty = flowMaster.PartyFrom;
                    flowDetail.LotNo            = LotNoHelper.GenerateLotNo();
                }

                foreach (FlowDetail flowDetail in List.Data)
                {
                    Item item = base.genericMgr.FindById <Item>(flowDetail.Item);
                    flowDetail.ItemDescription = item.Description;
                }
            }
            return(PartialView(List));
        }
Esempio n. 8
0
        public JsonResult QuickNew(OrderMaster orderMaster, [Bind(Prefix =
                                                                      "inserted")] IEnumerable <OrderDetail> insertedOrderDetails, [Bind(Prefix =
                                                                                                                                             "updated")] IEnumerable <OrderDetail> updatedOrderDetails)
        {
            try
            {
                if (string.IsNullOrEmpty(orderMaster.Flow))
                {
                    throw new BusinessException(Resources.ErrorMessage.Errors_Common_FieldRequired, Resources.ORD.OrderMaster.OrderMaster_Flow);
                }
                if (orderMaster.EffectiveDate == null)
                {
                    throw new BusinessException(Resources.ErrorMessage.Errors_Common_FieldRequired, Resources.ORD.OrderMaster.OrderMaster_EffectiveDate);
                }

                #region orderDetailList
                IList <OrderDetail> orderDetailList = new List <OrderDetail>();
                if (insertedOrderDetails != null && insertedOrderDetails.Count() > 0)
                {
                    foreach (OrderDetail orderDetail in insertedOrderDetails)
                    {
                        OrderDetail newOrderDetail = RefreshOrderDetail(orderMaster.Flow, orderDetail);
                        orderDetailList.Add(newOrderDetail);
                    }
                }
                if (updatedOrderDetails != null && updatedOrderDetails.Count() > 0)
                {
                    foreach (OrderDetail orderDetail in updatedOrderDetails)
                    {
                        if (!string.IsNullOrEmpty(orderDetail.LocationFrom))
                        {
                            orderDetail.LocationFromName = base.genericMgr.FindById <Location>(orderDetail.LocationFromName).Name;
                        }

                        orderDetailList.Add(orderDetail);
                    }
                }
                #endregion

                if (orderDetailList.Count == 0)
                {
                    throw new BusinessException(Resources.ORD.OrderMaster.Errors_OrderDetailIsEmpty);
                }

                FlowMaster  flow          = base.genericMgr.FindById <FlowMaster>(orderMaster.Flow);
                DateTime    effectiveDate = orderMaster.EffectiveDate.HasValue ? orderMaster.EffectiveDate.Value : DateTime.Now;
                OrderMaster newOrder      = orderMgr.TransferFlow2Order(flow, null, effectiveDate, false);

                newOrder.ReferenceOrderNo = orderMaster.ReferenceOrderNo;
                newOrder.ExternalOrderNo  = orderMaster.ExternalOrderNo;
                newOrder.IsQuick          = true;
                newOrder.OrderDetails     = orderDetailList;
                newOrder.WindowTime       = DateTime.Now;
                newOrder.StartTime        = DateTime.Now;

                orderMgr.CreateOrder(newOrder);
                SaveSuccessMessage(Resources.ORD.OrderMaster.OrderMaster_Added);
                return(Json(new { newOrder.OrderNo }));
            }
            catch (BusinessException ex)
            {
                SaveBusinessExceptionMessage(ex);
            }
            catch (Exception ex)
            {
                SaveErrorMessage(ex);
            }
            return(Json(null));
        }
Esempio n. 9
0
        public JsonResult CreateHuByFlow(string FlowidStr, string FlowucStr, string FlowsupplierLotNoStr, string FlowqtyStr, bool FlowisExport)
        {
            try
            {
                IList <FlowDetail> nonZeroFlowDetailList = new List <FlowDetail>();
                if (!string.IsNullOrEmpty(FlowidStr))
                {
                    string[]   idArray            = FlowidStr.Split(',');
                    string[]   ucArray            = FlowucStr.Split(',');
                    string[]   supplierLotNoArray = FlowsupplierLotNoStr.Split(',');
                    string[]   qtyArray           = FlowqtyStr.Split(',');
                    FlowMaster flowMaster         = null;

                    if (idArray != null && idArray.Count() > 0)
                    {
                        for (int i = 0; i < idArray.Count(); i++)
                        {
                            FlowDetail flowDetail = base.genericMgr.FindById <FlowDetail>(Convert.ToInt32(idArray[i]));
                            if (flowMaster == null)
                            {
                                flowMaster = base.genericMgr.FindById <FlowMaster>(flowDetail.Flow);
                            }

                            flowDetail.UnitCount        = Convert.ToDecimal(ucArray[i]);
                            flowDetail.SupplierLotNo    = supplierLotNoArray[i];
                            flowDetail.LotNo            = LotNoHelper.GenerateLotNo();
                            flowDetail.ManufactureParty = flowMaster.PartyFrom;
                            flowDetail.HuQty            = Convert.ToDecimal(qtyArray[i]);
                            nonZeroFlowDetailList.Add(flowDetail);
                        }
                    }

                    base.genericMgr.CleanSession();
                    if (flowMaster != null)
                    {
                        IList <Hu> huList = huMgr.CreateHu(flowMaster, nonZeroFlowDetailList);
                        foreach (var hu in huList)
                        {
                            hu.ManufacturePartyDescription = base.genericMgr.FindById <Party>(hu.ManufactureParty).Name;
                        }

                        if (FlowisExport)
                        {
                            IList <PrintHu> printHuList = Mapper.Map <IList <Hu>, IList <PrintHu> >(huList);

                            IList <object> data = new List <object>();
                            data.Add(printHuList);
                            data.Add(CurrentUser.FullName);
                            reportGen.WriteToClient(flowMaster.HuTemplate, data, flowMaster.HuTemplate);
                            return(Json(null));
                        }
                        else
                        {
                            //CreateBarCode(huList, null);
                            string printUrl = PrintHuList(huList, flowMaster.HuTemplate);
                            SaveSuccessMessage("条码打印成功,共打印了{0}张条码", huList.Count.ToString());
                            return(Json(new { PrintUrl = printUrl }));
                        }
                    }
                }
                return(Json(null));
            }
            catch (BusinessException ex)
            {
                SaveBusinessExceptionMessage(ex);
            }
            catch (Exception ex)
            {
                SaveErrorMessage(ex);
            }
            return(Json(null));
        }
        public async Task <VerifyRecordResult> AddAsync(FlowMasterAdapterModel paraObject)
        {
            try
            {
                CleanTrackingHelper.Clean <FlowMaster>(context);
                CleanTrackingHelper.Clean <FlowUser>(context);
                CleanTrackingHelper.Clean <FlowHistory>(context);
                CleanTrackingHelper.Clean <MyUser>(context);
                FlowMaster itemParameter = Mapper.Map <FlowMaster>(paraObject);
                CleanTrackingHelper.Clean <FlowMaster>(context);
                await context.FlowMaster
                .AddAsync(itemParameter);

                await context.SaveChangesAsync();

                #region 產生要審核的使用者清單
                var user = await context.MyUser
                           .FirstOrDefaultAsync(x => x.Id == itemParameter.MyUserId);

                FlowUser auditUser = new FlowUser()
                {
                    MyUserId     = itemParameter.MyUserId,
                    FlowMasterId = itemParameter.Id,
                    Enable       = true,
                    Level        = 0,
                    OnlyCC       = false,
                    Name         = "發文者",
                };
                await context.FlowUser.AddAsync(auditUser);

                var policyDetails = await context.PolicyDetail
                                    .Where(x => x.PolicyHeaderId == paraObject.PolicyHeaderId)
                                    .OrderBy(x => x.Level)
                                    .ToListAsync();

                foreach (var item in policyDetails)
                {
                    if (item.Enable == false)
                    {
                        continue;
                    }
                    auditUser = new FlowUser()
                    {
                        MyUserId     = item.MyUserId,
                        FlowMasterId = itemParameter.Id,
                        Enable       = true,
                        Level        = item.Level,
                        OnlyCC       = item.OnlyCC,
                        Name         = item.Name,
                    };
                    await context.FlowUser.AddAsync(auditUser);
                }

                itemParameter.NextMyUserName = user.Name;
                context.FlowMaster.Update(itemParameter);
                await context.SaveChangesAsync();

                #endregion

                #region 增加簽核流程歷史紀錄 - 建立簽核表單
                FlowHistory history = new FlowHistory()
                {
                    FlowMasterId = itemParameter.Id,
                    MyUserId     = itemParameter.MyUserId,
                    Approve      = true,
                    Summary      = $"{user.Account} / {user.Name} 建立簽核表單",
                    Comment      = $"簽核單草稿",
                    Updatetime   = DateTime.Now,
                };
                await context.FlowHistory.AddAsync(history);

                await context.SaveChangesAsync();

                #endregion

                CleanTrackingHelper.Clean <FlowMaster>(context);
                CleanTrackingHelper.Clean <FlowUser>(context);
                CleanTrackingHelper.Clean <FlowHistory>(context);
                CleanTrackingHelper.Clean <MyUser>(context);
                return(VerifyRecordResultFactory.Build(true));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "新增記錄發生例外異常");
                return(VerifyRecordResultFactory.Build(false, "新增記錄發生例外異常", ex));
            }
        }