示例#1
0
        //
        // CUSTOM MODULES
        //
        public DTO.FactoryProformaInvoiceMng.EditFormData GetData(int userId, int id, int factoryId, string season, int factoryOrderId, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.FactoryProformaInvoiceMng.EditFormData data = new DTO.FactoryProformaInvoiceMng.EditFormData();
            data.Data         = new DTO.FactoryProformaInvoiceMng.FactoryProformaInvoice();
            data.Data.Details = new List <DTO.FactoryProformaInvoiceMng.FactoryProformaInvoiceDetail>();

            //try to get data
            try
            {
                // check permission
                if (id > 0 && fwFactory.CheckFactoryProformaInvoicePermission(userId, id) == 0)
                {
                    throw new Exception("Current user don't have access permission for the selected proforma invoice data!");
                }

                if (id <= 0 && fwFactory.CheckFactoryPermission(userId, factoryId) == 0)
                {
                    throw new Exception("Current user don't have access permission for the selected factory data!");
                }

                if (id <= 0 && fwFactory.CheckFactoryOrderPermission(userId, factoryOrderId) == 0)
                {
                    throw new Exception("Current user don't have access permission for the selected factory order data!");
                }

                using (FactoryProformaInvoiceMngEntities context = CreateContext())
                {
                    if (id == 0)
                    {
                        data.Data.Season    = season;
                        data.Data.FactoryID = factoryId;
                        DTO.Support.Factory dtoFactory = supportFactory.GetFactory().FirstOrDefault(o => o.FactoryID == factoryId);
                        FactoryProformaInvoiceMng_FactoryOrderSearchResult_View dbFactoryOrder = context.FactoryProformaInvoiceMng_FactoryOrderSearchResult_View.FirstOrDefault(o => o.FactoryOrderID == factoryOrderId);
                        if (dtoFactory != null)
                        {
                            data.Data.FactoryUD = dtoFactory.FactoryUD;
                        }
                        else
                        {
                            throw new Exception("Factory not found!");
                        }

                        if (dbFactoryOrder != null)
                        {
                            data.Data.FactoryOrderID = factoryOrderId;
                            data.Data.FactoryOrderUD = dbFactoryOrder.FactoryOrderUD;

                            // get products
                            int index = -1;
                            foreach (FactoryProformaInvoiceMng_FactoryOrderItemSearchResult_View dbDetail in context.FactoryProformaInvoiceMng_FactoryOrderItemSearchResult_View.Where(o => o.FactoryOrderID == factoryOrderId))
                            {
                                data.Data.Details.Add(new DTO.FactoryProformaInvoiceMng.FactoryProformaInvoiceDetail()
                                {
                                    FactoryProformaInvoiceDetailID = index,
                                    FactoryOrderDetailID           = dbDetail.FactoryOrderDetailID,
                                    FactoryOrderSparepartDetailID  = dbDetail.FactoryOrderSparepartDetailID,
                                    ArticleCode      = dbDetail.ArticleCode,
                                    Description      = dbDetail.Description,
                                    ClientUD         = dbDetail.ClientUD,
                                    FactoryOrderUD   = dbDetail.FactoryOrderUD,
                                    LDS              = dbDetail.LDS.Value.ToString("dd/MM/yyyy"),
                                    OrderQnt         = dbDetail.OrderQnt,
                                    ProductionStatus = dbDetail.ProductionStatus,
                                    PurchasingPrice  = dbDetail.PurchasingPrice,
                                    Remark           = string.Empty,
                                    UnitPrice        = dbDetail.PurchasingPrice
                                });
                                index--;
                            }
                        }
                        else
                        {
                            throw new Exception("Factory order not found!");
                        }
                    }
                    else
                    {
                        data.Data = converter.DB2DTO_FactoryProformaInvoice(context.FactoryProformaInvoiceMng_FactoryProformaInvoice_View.FirstOrDefault(o => o.FactoryProformaInvoiceID == id));
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }