Example #1
0
 public DataTable LoadParts()
 {
     PartsTable = new DataTable();
     try
     {
         SQLQueryModel queryBuilder = new SQLQueryModel();
         string        query        = string.Format("SELECT partID, partName, price, categoryID FROM part;");
         PartsTable = queryBuilder.ExecuteMySQLQuery(query);
         Parts      = new ObservableCollection <PartTable>();
         foreach (DataRow row in PartsTable.Rows)
         {
             _partTable            = new PartTable();
             _partTable.PartID     = Convert.ToInt32(row["partID"]);
             _partTable.PartName   = row["partName"].ToString();
             _partTable.Price      = Convert.ToInt32(row["price"]);
             _partTable.CategoryID = Convert.ToInt32(row["categoryID"]);
             //_partTable.RequiredPartID = Convert.ToInt32(row["requiredPartID"]);
         }
         return(PartsTable);
     }
     catch (ArgumentNullException nullex)
     {
         return(null);
     }
 }
        public MainScreen()
        {
            InitializeComponent();
            PartTable.DataSource = Inventory.AllParts;
            PartTable.ClearSelection();

            ProductTable.DataSource = Inventory.Products;
            ProductTable.ClearSelection();
        }
        public void AddRelation <To, ToKeyType>(
            RelationItemInfo <To, ToKeyType> ThisRelation,
            Table <To, ToKeyType> .RelationTableInfo <ValueType, KeyType> ThatRelation)
            where ToKeyType : IComparable <ToKeyType>
        {
#if TRACE
            Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_1_X");
#endif
            var RelationName = ThisRelation.Link.Body.ToString() + ThatRelation.Link.Body.ToString();

            this._AddRelationForLoading(RelationName,
                                        ThisRelation);

            ThisRelation.LinkArray._AddRelationForLoading(RelationName,
                                                          ThatRelation,
                                                          Accepted: (Key, AcceptedKey, PartTable) =>
            {
#if TRACE
                Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_1_X >> Accepted");
#endif
                using (ThisRelation.LinkArray.IgnoreUpdateAble.Block())
                {
                    PartTable.SaveToParent();
                }

                using (this.IgnoreUpdateAble.Block())
                {
                    this.Update(AcceptedKey,
                                (c) => ThisRelation.Field.Value(c, (f) => { f.Key = Key; return(f); }));
                }
            },
                                                          Ignored: (Key, IgnoredKey, PartTable) =>
            {
#if TRACE
                Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_1_X >> Ignored");
#endif
                using (ThisRelation.LinkArray.IgnoreUpdateAble.Block())
                {
                    PartTable.SaveToParent();
                }


                using (this.IgnoreUpdateAble.Block())
                {
                    if (this.PositionOf(IgnoredKey) > -1)
                    {
                        this.Update(IgnoredKey,
                                    (c) => ThisRelation.Field.Value(c, (f) => { f.Key = null; return(f); }));
                    }
                }
            },
                                                          MakeNew: (c) =>
            {
                ThisRelation.Field.Value(c.NewValue, (f) =>
                {
                    f.Key = ThatRelation.OwnerArray.GetKey(c.LoadedValue);
                    return(f);
                });
            });

            this.KeyChanged += (info) =>
            {
#if TRACE
                Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_1_X >> KeyChanged");
#endif
                if (Run.Use(RelationName))
                {
                    using (ThisRelation.LinkArray.IgnoreUpdateAble.Block())
                    {
                        var ThisRelationArray = ThisRelation.Field.Value(info.Value);
                        if (ThisRelationArray.Key != null)
                        {
                            ThisRelation.LinkArray.Update((ToKeyType)ThisRelationArray.Key,
                                                          (c) =>
                            {
                                ThatRelation.Field.Value(c).Ignore(info.OldKey);
                                ThatRelation.Field.Value(c).Accept(info.NewKey);
                            });
                        }
                    }
                }
            };

            ThisRelation.LinkArray.KeyChanged += (info) =>
            {
#if TRACE
                Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_1_X >> KeyChanged");
#endif
                if (Run.Use(RelationName))
                {
                    using (this.IgnoreUpdateAble.Block())
                    {
                        var ThatRelation_array = ThatRelation.Field.Value(info.Value);
                        for (int i = 0; i < ThatRelation_array.KeysInfo.Keys.Length; i++)
                        {
                            var ThisValue = ThatRelation_array[i];
                            var Key       = this.GetKey(ThisValue);
                            ThisRelation.Field.Value(ThisValue.Value, (f) => { f.Key = info.NewKey; return(f); });
                            ThisRelation.Field.Value(ThisValue.Value, (f) => { f.OldKey = info.NewKey; return(f); });
                            this.Update(Key, ThisValue);
                        }
                    }
                }
            };

            this.Events.Deleted += (Info) =>
            {
#if TRACE
                Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_1_X >> Deleted");
#endif
                if (Run.Use(RelationName))
                {
                    using (ThisRelation.LinkArray.IgnoreUpdateAble.Block())
                    {
                        var ThisRelationArray = ThisRelation.Field.Value(Info.Value);
                        if (ThisRelationArray.Key != null)
                        {
                            ThisRelation.LinkArray.Update((ToKeyType)ThisRelationArray.Key,
                                                          (c) =>
                            {
                                ThatRelation.Field.Value(c).Ignore((KeyType)Info.Info[KeyPos].Key);
                            });
                        }
                    }
                }
            };

            if (ThisRelation.IsChild)
            {
                ThisRelation.LinkArray.Events.Deleted += (info) =>
                {
#if TRACE
                    Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_1_X >> Deleted IsChild");
#endif
                    if (Run.Use(RelationName))
                    {
                        var ThatRelation_array = ThatRelation.Field.Value(info.Value);
                        foreach (var ThisKey in ThatRelation_array.KeysInfo.Keys)
                        {
                            this.Delete(ThisKey);
                        }
                    }
                };
            }
            else
            {
                ThisRelation.LinkArray.Events.Deleted += (info) =>
                {
#if TRACE
                    Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_1_X >> Deleted");
#endif
                    if (Run.Use(RelationName))
                    {
                        var ThatRelation_array = ThatRelation.Field.Value(info.Value);
                        for (int i = 0; i < ThatRelation_array.KeysInfo.Keys.Length; i++)
                        {
                            var ThisValue = ThatRelation_array[i];
                            var Key       = this.GetKey(ThisValue);
                            ThisRelation.Field.Value(ThisValue.Value, (f) => { f.Key = null; return(f); });
                            this.Update(Key, ThisValue);
                        }
                    }
                };
            }

            Action <(ValueType Value, Events <ValueType> .ValueInfo[] Info)> OnSave = (Value) =>
            {
#if TRACE
                Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_1_X >> OnSave");
#endif
                if (Run.Use(RelationName))
                {
#if TRACE
                    Console.WriteLine(">> var ThisRelationArray = ThisRelation.Field.Value(ref Value.Value);");
#endif
                    var ThisRelationArray = ThisRelation.Field.Value(Value.Value);
                    var Key    = ThisRelationArray.Key;
                    var OldKey = ThisRelationArray.OldKey;
                    if (Compare(Key, OldKey) != 0)
                    {
                        var ChangedKey = this.GetKey(Value.Value);
                        if (Key != null)
                        {
                            ThisRelation.LinkArray.Update((ToKeyType)ThisRelationArray.Key,
                                                          (c) =>
                            {
#if TRACE
                                Console.WriteLine(">> Key != null");
#endif
                                ThatRelation.Field.Value(c).Accept(ChangedKey);
                            });
                        }
                        if (OldKey != null)
                        {
#if TRACE
                            Console.WriteLine(">> OldKey != null");
#endif
                            ThisRelation.LinkArray.Update((ToKeyType)ThisRelationArray.Key,
                                                          (c) =>
                            {
                                ThatRelation.Field.Value(c).Ignore(ChangedKey);
                            });
                        }
                    }
                }
            };

            this.Events.Inserted += (Value) => OnSave(Value);
            this.Events.Updated  += (Value) => OnSave(Value);

            if (ThatRelation.IsUpdateAble)
            {
                this.Events.Updated += (info) =>
                {
#if TRACE
                    Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_1_X >> Updated");
#endif
                    if (this.IgnoreUpdateAble.BlockLengths == 0)
                    {
                        var ThatValue = ThisRelation.Field.Value(info.Value);
                        if (ThatValue.Key != null)
                        {
                            if (Run.Use(RelationName + "UP"))
                            {
                                using (ThisRelation.LinkArray.IgnoreUpdateAble.Block())
                                {
                                    ThisRelation.LinkArray.Update(ThatValue, (c) =>
                                    {
                                        var MyInfo = info.Info[KeyPos];
                                        ThatRelation.Field.Value(c).UpdateAble.Changed(
                                            (KeyType)MyInfo.OldKey, (KeyType)MyInfo.OldKey);
                                    });
                                }
                            }
                        }
                    }
                };
            }


            ThisRelation.LinkArray.Events.Saving += (Value) =>
            {
            };
            if (ThatRelation.ClearRelationOnSendUpdate)
            {
                ThisRelation.LinkArray._ClearRelation(ThatRelation.Link);
            }
            ThisRelation.OwnerArray._MoveRelations(ThisRelation.Link);
        }
Example #4
0
        private void _AddRelation <To, ToKeyType>(
            string RelationName,
            RelationTableInfo <To, ToKeyType> ThisRelation,
            Table <To, ToKeyType> .RelationTableInfo <ValueType, KeyType> ThatRelation)
            where ToKeyType : IComparable <ToKeyType>
        {
#if TRACE
            Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_X_X");
#endif

            _AddRelationForLoading(RelationName,
                                   ThisRelation,
                                   Accepted: (Key, AcceptedKey, PartTable) =>
            {
#if TRACE
                Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_X_X >> Accepted");
#endif
                using (this.IgnoreUpdateAble.UseBlock())
                {
                    PartTable.SaveToParent();
                }


                using (ThisRelation.LinkArray.IgnoreUpdateAble.UseBlock())
                {
                    ThisRelation.LinkArray.Update(AcceptedKey,
                                                  (c) => ThatRelation.Field.Value(c).Accept(Key));
                }
            },
                                   Ignored: (Key, IgnoredKey, PartTable) =>
            {
#if TRACE
                Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_X_X >> Ignored");
#endif
                using (this.IgnoreUpdateAble.UseBlock())
                {
                    PartTable.SaveToParent();
                }


                using (ThisRelation.LinkArray.IgnoreUpdateAble.UseBlock())
                {
                    ThisRelation.LinkArray.Update(IgnoredKey,
                                                  (c) => (ThatRelation.Field.Value(c)).Ignore(Key));
                }
            });

            this.KeyChanged += (info) =>
            {
#if TRACE
                Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_X_X >> KeyChanged");
#endif
                if (Run.Use(RelationName))
                {
                    using (ThisRelation.LinkArray.IgnoreUpdateAble.UseBlock())
                    {
                        var ThisValue = ThisRelation.Field.Value(info.Value);
                        foreach (var ThatValue in ThisValue)
                        {
                            var ThatRelationTbl = ThatRelation.Field.Value(ThatValue);
                            ThatRelationTbl.KeysInfo.Keys.BinaryDelete(info.OldKey);
                            ThatRelationTbl.KeysInfo.Keys.BinaryInsert(info.NewKey);
                            ThisRelation.LinkArray.Update(ThatValue);
                        }
                    }
                }
            };

            this.Events.Deleted += (info) =>
            {
#if TRACE
                Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_X_X >> Deleted");
#endif
                if (Run.Use(RelationName))
                {
                    using (ThisRelation.LinkArray.IgnoreUpdateAble.UseBlock())
                    {
                        ThisRelation.LinkArray.Update(ThisRelation.Field.Value(info.Value),
                                                      (c) => ThatRelation.Field.Value(c).Ignore(
                                                          (KeyType)info.Info[ThatRelation.Field.Value(c).KeyPos].Key));
                    }
                }
            };

            var RelationName_Update = "U" + ThisRelation.Link.ToString() + RelationName;
            if (ThisRelation.IsUpdateAble)
            {
                this.Events.Updated += (info) =>
                {
#if TRACE
                    Console.WriteLine("@ " + this.GetType().Namespace + this.GetType().Name + " _AddRelation_X_X >> Updated");
#endif
                    if (this.IgnoreUpdateAble.BlockLengths == 0)
                    {
                        if (Run.Use(RelationName_Update))
                        {
                            using (ThisRelation.LinkArray.IgnoreUpdateAble.UseBlock())
                            {
                                var ThisValue = ThisRelation.Field.Value(info.Value);
                                foreach (var ThatValue in ThisValue)
                                {
                                    ThisRelation.LinkArray.Update(ThatValue, (c) =>
                                    {
                                        var MyInfo = info.Info[KeyPos];
                                        ThatRelation.Field.Value(c).UpdateAble.Changed(
                                            (KeyType)MyInfo.OldKey, (KeyType)MyInfo.OldKey);
                                    });
                                }
                            }
                        }
                    }
                };
            }
            if (ThisRelation.ClearRelationOnSendUpdate)
            {
                this._ClearRelation(ThisRelation.Link);
            }
            if (ThatRelation.ClearRelationOnSendUpdate)
            {
                ThisRelation.LinkArray._ClearRelation(ThatRelation.Link);
            }
        }
Example #5
0
            public async Task MakeUpdate(ulong ServerLastUpCode)
            {
                if (Table.UpdateAble.UpdateCode > ServerLastUpCode)
                {
                    Table.UpdateAble.Clear();
                    if (IsPartOfTable)
                    {
                        ParentTable.UpdateAble.Clear();
                    }
                }
                while (StartPos <= EndPos)
                {
                    await FindLastTrue();

                    StartPos++;
                    if (StartPos >= ServerItemsCount)
                    {
                        break;
                    }
                    else
                    {
                        var NextUpCode = await GetUpdateCodeAtPos(StartPos);

                        DeleteExtraItems(NextUpCode);
                        if (StartPos >= Table.UpdateAble.UpdateCodes.Length)
                        {
                            break;
                        }
                        var MyUpCode = Table.UpdateAble.UpdateCodes[StartPos];
                        if (MyUpCode.UpdateCode > NextUpCode)
                        {
                            await UpdateFromPosToUpCode(StartPos, MyUpCode.UpdateCode);
                        }
                    }
                }
                if (StartPos < ServerItemsCount)
                {
                    await UpdateFromPosToEnd(StartPos);
                }
                else
                {
                    DeleteItemsFrom(ServerItemsCount);
                }

                if (IsPartOfTable)
                {
                    foreach (var Delete in ShouldDelete)
                    {
                        if (await IsExistAtParent(Delete))
                        {
                            PartTable.Ignore(Delete);
                        }
                        else
                        {
                            PartTable.Delete(Delete);
                        }
                    }
                }
                else
                {
                    foreach (var Delete in ShouldDelete)
                    {
                        Table.Delete(Delete);
                    }
                }

                Table.UpdateAble.UpdateCode.Save(ServerLastUpCode);

                if (IsPartOfTable)
                {
                    PartTable.SaveToParent();
                }
#if DEBUG_UpdateAble
                await Debuger();
#endif
            }
Example #6
0
            private async Task UpdateNextItems()
            {
                var Len = await Client.GetData <int>();

                var ServerUpCodes = new ulong[Len];

                ulong[] ServerUpCodes_Parent = null;
                if (IsPartOfTable)
                {
                    ServerUpCodes_Parent = new ulong[Len];
                }
                for (int i = 0; i < Len; i++)
                {
                    var UpCode = await Client.GetData <ulong>();

                    if (IsPartOfTable)
                    {
                        var ParentUpCode = await Client.GetData <ulong>();

                        if (ParentTable.UpdateAble.IsExist(ParentUpCode))
                        {
                            var ParentUpDate = ParentTable.UpdateAble[ParentUpCode];
                            if (PartTable.IsExist(ParentUpDate.Key) == false)
                            {
                                PartTable.Accept(ParentUpDate.Key);
                            }
                            Added(ParentUpDate.Key, UpCode);
                            await Client.SendData(false);

                            StartPos++;
                            Len--;
                            i--;
                        }
                        else
                        {
                            await Client.SendData(true);

                            ServerUpCodes[i]        = UpCode;
                            ServerUpCodes_Parent[i] = ParentUpCode;
                        }
                    }
                    else
                    {
                        await Client.SendData(true);

                        ServerUpCodes[i] = UpCode;
                    }
                }
                for (int i = 0; i < Len; i++)
                {
                    var Value = await Client.GetData <ValueType>();

                    var Key    = Table.GetKey(Value);
                    var Update = new UpdateAble <KeyType>()
                    {
                        Key = Key, UpdateCode = ServerUpCodes[i]
                    };
                    Table.UpdateOrInsert(Key, (c) =>
                    {
                        Table.MoveRelations(c, Value);
                        return(Value);
                    });
                    if (IsPartOfTable)
                    {
                        Added(Key, ServerUpCodes[i], ServerUpCodes_Parent[i]);
                    }
                    else
                    {
                        Added(Key, ServerUpCodes[i]);
                    }
                    StartPos++;
                }
            }
 public Log GetLog(PartTable parts, LocaleTable locales)
 {
     return new Log(new Qualifier.Unique(parts.GetPart(PartId), locales.GetLocale(LocaleId), Key), Date);
 }
        public void Reload()
        {
            using (var connector = Connect()) {
                var connection = connector.Connection;
                var server = GetServer(connection);
                var database = GetDatabase(server);
                if (!database.Schemas.Contains(_tableConfiguration.Schema)) {
                    var schema = new Schema(database, _tableConfiguration.Schema);
                    database.Schemas.Add(schema);
                    schema.Create();
                }

                _partTable = new PartTable(connection, database, _tableConfiguration);
                _localeTable = new LocaleTable(connection, database, _tableConfiguration);
                _valueTable = new ValueTable(connection, database, _tableConfiguration);
                _logTable = new LogTable(database, _tableConfiguration);
            }
        }
            public DBValue GetValue(PartTable.DBPart part, LocaleTable.DBLocale locale, String key)
            {
                try
                {
                    return _valuesByQualifier[new InternalQualifier(part.Id, locale.Id, key)];
                }
                catch(KeyNotFoundException)
                {
                    var parent = part.Parent as PartTable.DBPart;
                    if (parent != null)
                        return GetValue(parent, locale, key);
                }

                return null;
            }
 public IEnumerable<QualifiedValue> GetQualifiedValues(PartTable partTable, LocaleTable localeTable)
 {
     return _valuesByQualifier
         .Select(qv => new QualifiedValue(
             new Qualifier.Unique(
                 partTable.GetPart(qv.Key.PartId),
                 localeTable.GetLocale(qv.Key.LocaleId),
                 qv.Key.Key
             ),
             qv.Value.Content
         )).ToList();
 }