示例#1
0
        public DTO.EditFormData GetData(int userId, int id, int bookingID, int factoryID, int offerLineID, int offerLineSampleProductID, int offerLineSparepartID, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.EditFormData data = new DTO.EditFormData();
            data.Data           = new DTO.PLC();
            data.Data.PLCImages = new List <DTO.PLCImage>();
            data.PLCImageTypes  = new List <Support.DTO.PLCImageType>();

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

                using (FactoryPLCMngEntities context = CreateContext())
                {
                    if (id == 0)
                    {
                        // get item info
                        FactoryPLCMng_ItemForCreatePLC_View dbInfo = null;
                        if (offerLineID > 0)
                        {
                            dbInfo = context.FactoryPLCMng_function_GetItemInfo(userId, factoryID, offerLineID, null, null).FirstOrDefault();
                        }
                        else if (offerLineSparepartID > 0)
                        {
                            dbInfo = context.FactoryPLCMng_function_GetItemInfo(userId, factoryID, null, offerLineSparepartID, null).FirstOrDefault();
                        }
                        else if (offerLineSampleProductID > 0)
                        {
                            dbInfo = context.FactoryPLCMng_function_GetItemInfo(userId, factoryID, null, null, offerLineSampleProductID).FirstOrDefault();
                        }
                        if (dbInfo != null)
                        {
                            data.Data.FactoryID = factoryID;
                            if (offerLineID > 0)
                            {
                                data.Data.OfferLineID = offerLineID;
                            }
                            else if (offerLineSparepartID > 0)
                            {
                                data.Data.OfferLineSparepartID = offerLineSparepartID;
                            }
                            else if (offerLineSampleProductID > 0)
                            {
                                data.Data.OfferLineSampleProductID = offerLineSampleProductID;
                            }
                            data.Data.ArticleCode    = dbInfo.ArticleCode;
                            data.Data.Description    = dbInfo.Description;
                            data.Data.FactoryOrderUD = dbInfo.FactoryOrderUD;
                            data.Data.ClientUD       = dbInfo.ClientUD;
                            data.Data.FactoryUD      = dbInfo.FactoryUD;

                            //packaging info
                            if (offerLineID > 0)
                            {
                                var dbPackaging = context.FactoryPLCMng_Packaging_View.Where(o => o.OfferLineID == offerLineID).FirstOrDefault();
                                if (dbPackaging != null)
                                {
                                    data.Data.PackagingMethodNM = dbPackaging.PackagingMethodNM;
                                    data.Data.NetWeight         = dbPackaging.NetWeight;
                                    data.Data.GrossWeight       = dbPackaging.GrossWeight;
                                    data.Data.CBMS   = dbPackaging.CBM;
                                    data.Data.PKGS   = dbPackaging.CTNS;
                                    data.Data.HSCode = dbPackaging.HSCode;
                                }
                            }
                            if (offerLineSampleProductID > 0)
                            {
                                var dbPackaging = context.FactoryPLCMng_SampleProductPackaging_View.Where(o => o.OfferLineSampleProductID == offerLineSampleProductID).FirstOrDefault();
                                if (dbPackaging != null)
                                {
                                    data.Data.PackagingMethodNM = dbPackaging.PackagingMethodNM;
                                    data.Data.NetWeight         = dbPackaging.NetWeight;
                                    data.Data.GrossWeight       = dbPackaging.GrossWeight;
                                    data.Data.CBMS   = dbPackaging.CBM;
                                    data.Data.PKGS   = dbPackaging.CTNS;
                                    data.Data.HSCode = dbPackaging.HSCode;
                                }
                            }
                        }
                        else
                        {
                            throw new Exception("Item not exists!");
                        }

                        // get booking info
                        FactoryPLCMng_BookingSearchResult_View bookingInfo = context.FactoryPLCMng_function_GetBookingInfo(userId, factoryID, bookingID).FirstOrDefault();
                        if (bookingInfo != null)
                        {
                            data.Data.BookingID     = bookingID;
                            data.Data.BookingUD     = bookingInfo.BookingUD;
                            data.Data.BLNo          = bookingInfo.BLNo;
                            data.Data.ContainerNo   = "";
                            data.Data.LoadingPlanUD = "";
                            data.Data.Season        = bookingInfo.Season;
                        }
                        else
                        {
                            throw new Exception("Booking not exists!");
                        }
                    }
                    else
                    {
                        data.Data = converter.DB2DTO_PLC(context.FactoryPLCMng_PLC_View.Include("FactoryPLCMng_PLCImage_View").FirstOrDefault(o => o.PLCID == id));
                    }

                    data.PLCImageTypes = supportFactory.GetPLCImageType();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }