Пример #1
0
        public DynamicType Import(ASYCUDA adoc, IDynamicEntity docSet)
        {
            try
            {
                a = adoc;
                var ads = docSet;

                da.xcuda_Item = new List <DynamicType>()
                {
                };
                da.XMLId      = a.id;
                da.ASYCUDA_Id = 0;
                da.xcuda_ASYCUDA_ExtendedProperties = new DynamicType("xcuda_ASYCUDA_ExtendedProperties", da.ASYCUDA_Id);
                da.xcuda_Suppliers_documents        = new List <DynamicType>();

                SaveGeneralInformation();
                SaveDeclarant();
                SaveTraders();
                SaveProperty();
                SaveIdentification();
                SaveTransport();
                SaveFinancial();
                Save_Warehouse();
                Save_Valuation();
                SaveContainer();


                Save_Items();

                if (!((List <DynamicType>)da.xcuda_Item).Any())
                {
                    return(new DynamicType("xcuda_ASYCUDA", 0));
                }


                Save_Suppliers_Documents();
                da.xcuda_ASYCUDA_ExtendedProperties.ImportComplete       = true;
                da.xcuda_ASYCUDA_ExtendedProperties.AsycudaDocumentSetId = docSet.Id;
                da.xcuda_ASYCUDA_ExtendedProperties.Total_CIF            = Convert.ToSingle(a.Valuation.Total_CIF);

                foreach (var itm in da.xcuda_Item)
                {
                    if (itm.ImportComplete != false)
                    {
                        continue;
                    }
                    da.xcuda_ASYCUDA_ExtendedProperties.ImportComplete = false;
                    break;
                }
                return(da);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        private static void OnImport(IStartAddin msg)
        {
            //StatusModel.Timer("Importing Documents");
            //import asycuda xml id and details
            if (msg.Entity == null || msg.Entity.Id == 0)
            {
                MessageBox.Show("Please Select Asycuda Document Set");
                return;
            }


            var od = new OpenFileDialog();

            od.DefaultExt  = ".xml";
            od.Filter      = "Xml Documents (.xml)|*.xml";
            od.Multiselect = true;
            var result = od.ShowDialog();

            if (result == true)
            {
                //StatusModel.Timer(string.Format("Importing {0} files", od.FileNames.Count()));
                //StatusModel.StartStatusUpdate("Importing files", od.FileNames.Count());
                //StatusModel.RefreshNow();
                foreach (var f in od.FileNames)
                {
                    if (ASYCUDA.CanLoadFromFile(f))
                    {
                        var a   = Asycuda421.ASYCUDA.LoadFromFile(f);
                        var res = AsycudaToDataBase421.Instance.Import(a, msg.Entity);
                        var de  = new DynamicEntity(
                            new DynamicEntityType("xcuda_ASYCUDA", "xcuda_ASYCUDA",
                                                  new List <IEntityKeyValuePair>(), new Dictionary <string, List <dynamic> >(),
                                                  new ObservableDictionary <string, Dictionary <int, dynamic> >(),
                                                  new List <IDynamicRelationshipType>(), new List <IDynamicRelationshipType>(),
                                                  DynamicEntityType.NullEntityType(),
                                                  new ObservableList <IAddinAction>()), 0,
                            new Dictionary <string, object>());

                        EventMessageBus.Current.Publish(new UpdateEntityWithChanges(de,
                                                                                    res.Properties.ToDictionary(x => x.Key, x => x.Value),
                                                                                    new StateCommandInfo(msg.Process,
                                                                                                         RevolutionData.Context.CommandFunctions.UpdateCommandData(de.EntityType.Name,
                                                                                                                                                                   RevolutionData.Context.Entity.Commands.CreateEntity)), msg.Process, Source));
                    }
                    else
                    {
                        throw new ApplicationException(string.Format("Can not Load file '{0}'", f));
                    }
                }

                var cnt = od.FileNames.Length;
                var t   = 0;
                EventMessageBus.Current.GetEvent <IEntityWithChangesUpdated>(
                    new StateEventInfo(msg.Process, Entity.Events.EntityUpdated), Source)
                .Where(x => x.EntityType.Name == "xcuda_ASYCUDA" && x.Process.Id == msg.Process.Id)
                .Subscribe(x =>
                {
                    t += 1;
                    if (t == cnt)
                    {
                        MessageBox.Show("Complete");
                    }
                });


                //StatusModel.StopStatusUpdate();
            }
            // StatusModel.StopStatusUpdate();
        }