Exemplo n.º 1
0
        // Not used anymore

        /*
         * private static void ReadAssociateStruct(BinaryReader br, Header h, ViewModel vm)
         * {
         *  AssociateStruct[] asc = new AssociateStruct[h.amount];
         *  for (int i = 0; i < h.amount; i++)
         *  {
         *      asc[i] = ReadStructData<AssociateStruct>(br, h);
         *  }
         *
         *  if (h.Name == "CustomerModel")
         *      AddAssociateStructToList<CustomerModel>(asc, vm.CustomerList);
         *  else if (h.Name == "SupplierModel")
         *      AddAssociateStructToList<SupplierModel>(asc, vm.Supplier);
         * }
         *
         * private static void AddAssociateStructToList<T>(AssociateStruct[] cs, ObservableCollection<T> vmList) where T : AssociateModel
         * {
         *  for (int i = 0; i < cs.Length; i++)
         *  {
         *      T cm = (T)Activator.CreateInstance(typeof(T));
         *
         *      cm.Name = cs[i].Name;
         *      cm.Address = cs[i].Address;
         *      cm.Phone = cs[i].Phone;
         *
         *      vmList.Add(cm);
         *  }
         * }
         */

        private static void ReadSupplierStruct(BinaryReader br, Header h, ViewModel vm)
        {
            SupplierStruct[] ss = new SupplierStruct[h.amount];
            for (int i = 0; i < h.amount; i++)
            {
                ss[i] = ReadStructData <SupplierStruct>(br, h);
            }
            AddSupplierStructToList(ss, vm);
        }
Exemplo n.º 2
0
        //private static void HandleAssociateModel<T>(ObservableCollection<T> associateCollection) where T : AssociateModel
        //{
        //    AssociateStruct[] assStruct = new AssociateStruct[associateCollection.Count];
        //    for (int i = 0; i < associateCollection.Count; i++)
        //    {
        //        assStruct[i].Name = associateCollection[i].Name;
        //        assStruct[i].Address = associateCollection[i].Address;
        //        assStruct[i].Phone = associateCollection[i].Phone;
        //    }

        //    Header h = new Header
        //    {
        //        Name = typeof(T).Name,
        //        size = Marshal.SizeOf(typeof(AssociateStruct)),
        //        amount = associateCollection.Count
        //    };

        //    ObjectToByteArray(assStruct, h);
        //}


        private static void HandleSupplierModel(ObservableCollection <SupplierModel> supp)
        {
            SupplierStruct[] suppStruct = new SupplierStruct[supp.Count];
            for (int i = 0; i < supp.Count; i++)
            {
                suppStruct[i].Name    = supp[i].Name;
                suppStruct[i].Address = supp[i].Address;
                suppStruct[i].Phone   = supp[i].Phone;
            }

            Header h = new Header
            {
                Name   = typeof(SupplierStruct).Name,
                size   = Marshal.SizeOf(typeof(SupplierStruct)),
                amount = supp.Count
            };

            ObjectToByteArray(suppStruct, h);
        }