Example #1
0
        /// <summary>
        /// Prend en charge l'alimentation de la classe pour les valeurs d'initialisation.
        /// </summary>
        /// <param name="classe">Classe concernée.</param>
        /// <param name="item">Bean d'initialisation.</param>
        protected void HandleCorrectInit(ModelClass classe, TableInit item)
        {
            if (!DictionaryItemInit.ContainsKey(classe))
            {
                DictionaryItemInit.Add(classe, item);
            }

            foreach (ItemInit itemInit in item.ItemInitList)
            {
                IDictionary <string, object> definition = itemInit.Bean;
                string propertyName  = GetReferenceKeyName(classe);
                object propertyValue = definition[propertyName];
                if (propertyValue.GetType() == typeof(string))
                {
                    propertyValue = "\"" + propertyValue + "\"";
                }

                string libelleName = GetLibelleName(definition);
                string libelle     = null;
                if (libelleName != null)
                {
                    libelle = (string)definition[libelleName];
                }
                else
                {
                    libelle = itemInit.VarName;
                }

                classe.ConstValues.Add(itemInit.VarName, new StaticListElement()
                {
                    Code = propertyValue, Libelle = libelle, CodeType = propertyValue.GetType().ToString()
                });
            }
        }
Example #2
0
        // Обработка
        #region
        /// <summary>
        /// Добавляем заказ в БД
        /// </summary>
        /// <param name="ord"></param>
        /// <param name="sqc"></param>
        /// <param name="flag"></param>
        protected void addOrdToDb(Order ord, QueryGenerator.SomeSqlCommand sqc, UpdateType flag)
        {
            using (var adapter = new SqlDataAdapter())
            {
                string connectionString = ConfigurationManager.ConnectionStrings["tpDb"].ConnectionString;
                //инициируем таблицу-представление
                var ordTable = TableInit.OrderInit();
                //генерация новой записи
                var newRow = TableInit.OrderAddRow(ordTable, ord);
                ordTable.Rows.Add(newRow);
                // Проверим, есть ли в таблице данный пользователь
                if (flag == UpdateType.Update)
                {
                    if (custList.Where(c => c.Phone == ord.Customer.Phone).Count() == 0)
                    {
                        DataContext db = new DataContext(connectionString);
                        db.GetTable <Customer>().InsertOnSubmit(ord.Customer);
                        db.SubmitChanges();
                    }
                }
                //инициировать строку запроса

                adapter.InsertCommand = sqc(connectionString, flag);
                adapter.Update(ordTable);
            }
        }
Example #3
0
        /// <summary>
        /// Prend en charge l'alimentation de la classe pour les valeurs d'initialisation.
        /// </summary>
        /// <param name="classe">Classe concernée.</param>
        /// <param name="item">Bean d'initialisation.</param>
        protected void HandleCorrectInit(ModelClass classe, TableInit item)
        {
            if (!DictionaryItemInit.ContainsKey(classe))
            {
                DictionaryItemInit.Add(classe, item);
            }

            foreach (ItemInit itemInit in item.ItemInitList)
            {
                BeanDefinition         definition         = BeanDescriptor.GetDefinition(itemInit.Bean);
                BeanPropertyDescriptor propertyDescriptor = GetReferenceKeyDescriptor(classe, definition);
                object propertyValue = propertyDescriptor.GetValue(itemInit.Bean);
                if (propertyDescriptor.PrimitiveType == typeof(string))
                {
                    propertyValue = "\"" + propertyValue + "\"";
                }

                BeanPropertyDescriptor libelleDescriptor = GetLibelleDescriptor(classe, definition);
                string libelle = null;
                if (libelleDescriptor != null)
                {
                    libelle = (string)libelleDescriptor.GetValue(itemInit.Bean);
                }
                else
                {
                    libelle = itemInit.VarName;
                }

                classe.ConstValues.Add(itemInit.VarName, new StaticListElement()
                {
                    Code = propertyValue, Libelle = libelle, CodeType = propertyDescriptor.PrimitiveType.ToString()
                });
            }
        }
Example #4
0
        /// <summary>
        /// Ecrit dans le writer le script d'insertion dans la table staticTable ayant pour model modelClass.
        /// </summary>
        /// <param name="writer">Writer.</param>
        /// <param name="staticTable">Classe de reference statique.</param>
        /// <param name="modelClass">Modele de la classe.</param>
        /// <param name="isStatic">True if generation for static list.</param>
        private void WriteInsert(StreamWriter writer, TableInit staticTable, ModelClass modelClass, bool isStatic)
        {
            writer.WriteLine("/**\t\tInitialisation de la table " + modelClass.Name + "\t\t**/");
            foreach (ItemInit initItem in staticTable.ItemInitList)
            {
                writer.WriteLine(GetInsertLine(modelClass, initItem, isStatic));
            }

            writer.WriteLine();
        }
Example #5
0
        protected void addD2AToBD(D2A d2a)
        {
            using (var adapter = new SqlDataAdapter())
            {
                DataTable d2aTable = TableInit.D2AInit();
                DataRow   dr       = TableInit.D2AAddRow(d2aTable, d2a);
                d2aTable.Rows.Add(dr);
                adapter.InsertCommand = QueryGenerator.D2AGenerateInsertQuery(ConfigurationManager.ConnectionStrings["tpDb"].ConnectionString);

                adapter.Update(d2aTable);
            }
        }
Example #6
0
        /// <summary>
        /// Генерирует список адрессов в соответствии с базой данных
        /// </summary>
        /// <param name="connectionString">Строка подключений</param>
        /// <param name="adapter">SqlDataAdapter  для заполнения DataSet</param>
        /// <returns></returns>
        public static List <Address> GetAddresses(string connectionString, SqlDataAdapter adapter)
        {
            List <Address> la    = new List <Address>();
            DataTable      Table = TableInit.AddressInit();

            adapter.SelectCommand = QueryGenerator.GenerateSelectQuery("Address order by street", connectionString);
            adapter.Fill(Table);
            foreach (DataRow row in Table.Rows)
            {
                la.Add(TableInit.AddressGetRow(row));
            }
            return(la);
        }
Example #7
0
        public static List <D2A> GetD2As(string connectionString, SqlDataAdapter adapter, List <Car> carList, List <Driver> driverList)
        {
            List <D2A> d2al  = new List <D2A>();
            DataTable  Table = TableInit.D2AInit();

            adapter.SelectCommand = QueryGenerator.GenerateSelectQuery("Drivers2Auto", connectionString);
            adapter.Fill(Table);
            foreach (DataRow row in Table.Rows)
            {
                d2al.Add(TableInit.D2AGetRow(row, carList, driverList));
            }
            return(d2al);
        }
Example #8
0
 /// <summary>
 /// Vérifie que le bean d'init concerne une liste de reference.
 /// </summary>
 /// <param name="item">Le bean d'init.</param>
 /// <param name="classe">La classe considérée.</param>
 /// <param name="messageList">Liste des potentiels messages d'erreur.</param>
 protected void CheckStereotype(TableInit item, ModelClass classe, ICollection <NVortexMessage> messageList)
 {
     if (classe.Stereotype != GetStereotype())
     {
         messageList.Add(new NVortexMessage()
         {
             Category    = Category.Error,
             IsError     = true,
             Description = item.FactoryName + " définit une initialisation pour le type " + item.ClassName + " qui n'est pas une liste de référence.",
             FileName    = classe.Namespace.Model.ModelFile
         });
     }
 }
Example #9
0
 /// <summary>
 /// Vérifie que la classe ne pointe pas sur elle même (directement ou indirectement).
 /// </summary>
 /// <param name="item">Model class.</param>
 /// <param name="classe">La classe considérée.</param>
 /// <param name="messageList">Liste des potentiels messages d'erreur.</param>
 private static void CheckFkNoBoucle(TableInit item, ModelClass classe, ICollection <NVortexMessage> messageList)
 {
     if (IsLinked(classe, classe))
     {
         messageList.Add(new NVortexMessage()
         {
             Category    = Category.Error,
             IsError     = true,
             Description = "La liste de référence statique de type " + item.ClassName + " pointe sur elle même (directement ou indirectement).",
             FileName    = classe.Namespace.Model.ModelFile
         });
     }
 }
Example #10
0
File: Car.cs Project: andru196/Taxi
        /// <summary>
        /// Возвращает список автомобилей из БД
        /// </summary>
        /// <param name="connectionString">Строка соединения</param>
        /// <param name="adapter">SqlDataAdapter</param>
        /// <returns></returns>
        public static List <Car> GetCars(string connectionString, SqlDataAdapter adapter)
        {
            List <Car> lc    = new List <Car>();
            DataTable  Table = TableInit.AutoInit();

            adapter.SelectCommand = QueryGenerator.GenerateSelectQuery("auto", connectionString);
            adapter.Fill(Table);
            foreach (DataRow row in Table.Rows)
            {
                lc.Add(TableInit.CarGetRow(row));
            }
            return(lc);
        }
Example #11
0
 private void InitDictionary()
 {
     Dictionary.Clear();
     ResourceManager.PrepareResource <TextAsset>("Table/Dictionary.txt", asset =>
     {
         if (asset == null)
         {
             Logger.Error("PreInit Dictionary Table error!!!");
             return;
         }
         TableInit.Table_Init(asset.bytes, Dictionary, TableType.Dictionary);
     }, true, false, true, true, false);
 }
Example #12
0
        public static List <Driver> GetDrivers(string connectionString, SqlDataAdapter adapter)
        {
            List <Driver> ld    = new List <Driver>();
            DataTable     Table = TableInit.DriversInit();

            adapter.SelectCommand = QueryGenerator.GenerateSelectQuery("drivers", connectionString);
            adapter.Fill(Table);
            foreach (DataRow row in Table.Rows)
            {
                ld.Add(TableInit.DriverGetRow(row));
            }

            return(ld);
        }
Example #13
0
        /// <summary>
        /// Returns collection of TableInit from a file.
        /// </summary>
        /// <param name="listFactoryFileName">Fichier de factory.</param>
        /// <returns>Collection of TableInit.</returns>
        private ICollection <TableInit> LoadTableInitListFromFile(string listFactoryFileName)
        {
            IDictionary <string, TableInit> dictionary = null;

            if (!string.IsNullOrEmpty(listFactoryFileName))
            {
                dictionary = new Dictionary <string, TableInit>();

                string fileContent = File.ReadAllText(listFactoryFileName);

                if (!string.IsNullOrEmpty(fileContent))
                {
                    var factory = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, Dictionary <string, object> > > >(fileContent);

                    foreach (KeyValuePair <string, Dictionary <string, Dictionary <string, object> > > tableFactory in factory)
                    {
                        string tableName = tableFactory.Key;

                        if (string.IsNullOrEmpty(tableName))
                        {
                            throw new ArgumentNullException("tableName");
                        }

                        if (dictionary.ContainsKey(tableName))
                        {
                            throw new NotSupportedException();
                        }

                        foreach (string itemTableName in dictionary.Keys.Where(itemTableName => string.Compare(itemTableName, tableName, StringComparison.OrdinalIgnoreCase) > 0))
                        {
                            throw new NotSupportedException("L'initialisation des listes statiques/références doit être effectuée dans l'ordre alphabétique, l'élément " + itemTableName + " précède l'élément " + tableName + ".");
                        }

                        TableInit table = new TableInit {
                            ClassName = tableName, FactoryName = this.GetType().Name
                        };

                        foreach (KeyValuePair <string, Dictionary <string, object> > value in tableFactory.Value)
                        {
                            table.AddItem(value.Key, value.Value);
                        }

                        dictionary.Add(tableName, table);
                    }
                }
            }

            return(dictionary?.Values);
        }
Example #14
0
        /// <summary>
        /// Prend en charge l'alimentation de la classe pour les valeurs d'initialisation.
        /// </summary>
        /// <param name="classe">Classe concernée.</param>
        /// <param name="item">Bean d'initialisation.</param>
        protected void HandleCorrectInit(ModelClass classe, TableInit item)
        {
            if (!DictionaryItemInit.ContainsKey(classe))
            {
                DictionaryItemInit.Add(classe, item);
            }

            foreach (ItemInit itemInit in item.ItemInitList)
            {
                BeanDefinition         definition         = BeanDescriptor.GetDefinition(itemInit.Bean);
                BeanPropertyDescriptor propertyDescriptor = GetReferenceKeyDescriptor(classe, definition);
                object propertyValue = propertyDescriptor.GetValue(itemInit.Bean);
                if (propertyDescriptor.PrimitiveType == typeof(string))
                {
                    propertyValue = "\"" + propertyValue + "\"";
                }

                classe.ConstValues.Add(itemInit.VarName, propertyValue.ToString());
            }
        }
Example #15
0
        /// <summary>
        /// Vérifie que toutes les propriétés sont saisis dans le bean d'init et que le bean d'init ne définit pas des propriétés inexistantes.
        /// </summary>
        /// <param name="item">Le bean d'init.</param>
        /// <param name="classe">La classe considérée.</param>
        /// <param name="messageList">Liste des potentiels messages d'erreurs.</param>
        protected static void CheckPropertyExists(TableInit item, ModelClass classe, ICollection <NVortexMessage> messageList)
        {
            foreach (ItemInit itemInit in item.ItemInitList)
            {
                BeanDefinition            definition        = BeanDescriptor.GetDefinition(itemInit.Bean);
                Dictionary <string, bool> visitedProperties = new Dictionary <string, bool>();
                foreach (ModelProperty property in classe.PersistentPropertyList)
                {
                    if (definition.Properties.Contains(property.Name) || property.DataDescription.IsPrimaryKey)
                    {
                        visitedProperties.Add(property.Name, true);
                    }
                    else
                    {
                        messageList.Add(new NVortexMessage()
                        {
                            Category    = Category.Error,
                            IsError     = true,
                            Description = item.FactoryName + " définit une initialisation pour le type " + item.ClassName + " mais ne précise pas la valeur de la propriété " + property.Name + ".",
                            FileName    = classe.Namespace.Model.ModelFile
                        });
                    }
                }

                foreach (BeanPropertyDescriptor property in definition.Properties)
                {
                    if (!visitedProperties.ContainsKey(property.PropertyName))
                    {
                        messageList.Add(new NVortexMessage()
                        {
                            Category    = Category.Error,
                            IsError     = true,
                            Description = item.FactoryName + " définit une initialisation pour le type " + item.ClassName + " avec la propriété " + property.PropertyName + " qui n'existe pas.",
                            FileName    = classe.Namespace.Model.ModelFile
                        });
                    }
                }
            }
        }
Example #16
0
        /// <summary>
        /// Заполняем списки разными способами
        /// </summary>
        /// <param name="take"></param>
        /// <param name="skip"></param>
        private void fillLists(int take, int skip)
        {
            void littleFiller <cl>(TableInit.Init a, TableInit.GetRow <cl> b, List <cl> lst, string c, SqlDataAdapter adapter, string connectionString1)
            {
                var Table = a();

                adapter.SelectCommand = QueryGenerator.GenerateSelectQuery(c, connectionString1);
                adapter.Fill(Table);
                foreach (DataRow row in Table.Rows)
                {
                    lst.Add(b(row));
                }
            }

            var connectionString = ConfigurationManager.ConnectionStrings["tpDb"].ConnectionString;

            using (var adapter = new SqlDataAdapter())
            {
                //Используя специальную функцию
                littleFiller(TableInit.CustomerInit, TableInit.CustomerGetRow, custList, "Customer", adapter, connectionString);
                //Испольхуя встроенные методы
                driverList = Driver.GetDrivers(connectionString, adapter);
                adList     = Address.GetAddresses(connectionString, adapter);
                carList    = Car.GetCars(connectionString, adapter);

                d2aList = D2A.GetD2As(connectionString, adapter, carList, driverList);
                //Ещё 1 метод
                var Table = TableInit.OrderInit();
                adapter.SelectCommand = QueryGenerator.GenerateSelectQuery("Orders", connectionString);
                adapter.Fill(Table);
                foreach (DataRow row in Table.Rows)
                {
                    ordList.Add(TableInit.OrderGetRow(row, d2aList, adList, custList));
                }


                Table = TableInit.WayInit();
                adapter.SelectCommand = QueryGenerator.GenerateSelectQuery("Metrics", connectionString);
                adapter.Fill(Table);
                foreach (DataRow row in Table.Rows)
                {
                    wayList.Add(TableInit.WayGetRow(row, adList));
                }

                //Сортировка
                switch (sortType.Value)
                {
                case "2":
                    ordList = ordList.OrderBy(o => o.Customer.Name).ToList();
                    break;

                case "3":
                    ordList = ordList.OrderBy(o => o.d2a.Auto.Mark).ToList();
                    break;

                case "4":
                    ordList = ordList.OrderBy(o => o.d2a.Driver.Name).ToList();
                    break;

                case "5":
                    ordList = ordList.OrderBy(o => o.Way.From.street).ToList();
                    break;

                case "6":
                    ordList = ordList.OrderBy(o => o.d2a.Date).ToList();
                    break;

                case "7":
                    ordList = ordList.OrderBy(o => o.Price).ToList();
                    break;

                default:
                    break;
                }
                ordList = ordList
                          .Skip(skip)
                          .Take(take)
                          .ToList();
            }
            //Используя LINQ-To-SQL
            DataContext db = new DataContext(connectionString);

            rsList = db.GetTable <RadioStation>().ToList();
        }
Example #17
0
 public void Setup()
 {
     TableInit.init();
 }
Example #18
0
    public static void ReloadDictionaryTable()
    {
        var ta = Resources.LoadAssetAtPath("Assets/Res/Table/Dictionary.txt", typeof(TextAsset)) as TextAsset;

        TableInit.Table_Init(ta.bytes, Dictionary, TableType.Dictionary);
    }
Example #19
0
    public static void ReloadSoundTable()
    {
        var res = Resources.LoadAssetAtPath <TextAsset>("Assets/Res/Table/Sound.txt");

        TableInit.Table_Init(res.bytes, SoundTable, TableType.Sound);
    }
Example #20
0
 /// <summary>
 /// Vérifie les éléments d'initialisation statiques.
 /// </summary>
 /// <param name="item">Data of the table.</param>
 /// <param name="classe">Table.</param>
 /// <param name="messageList">List of the error message.</param>
 protected override void CheckSpecific(TableInit item, ModelClass classe, ICollection <NVortexMessage> messageList)
 {
     CheckStereotype(item, classe, messageList);
     CheckPropertyExists(item, classe, messageList);
     CheckFkNoBoucle(item, classe, messageList);
 }
Example #21
0
    public static void CreateObstacle()
    {
        //根据当前场景名字获得场景名称
        string curScene = EditorApplication.currentScene.Substring(EditorApplication.currentScene.LastIndexOf('/') + 1);

        curScene = curScene.Substring(0, curScene.IndexOf('.'));
        //首先获取当前场景的SceneClass
        SceneRecord sceneDefine = null;

        Debug.Log("Remember to add mesh collider to all the meshes.");

        var name = "Table/Scene.txt";
        var path = "Assets/Res/" + name;
        Dictionary <int, IRecord> Scene = new Dictionary <int, IRecord>();
        var txt = Resources.LoadAssetAtPath(path, typeof(TextAsset)) as TextAsset;

        TableInit.Table_Init(txt.bytes, Scene, TableType.Scene);
        {
            // foreach(var record in Scene)
            var __enumerator1 = (Scene).GetEnumerator();
            while (__enumerator1.MoveNext())
            {
                var record = __enumerator1.Current;
                {
                    if (((SceneRecord)record.Value).ResName == curScene)
                    {
                        sceneDefine = (SceneRecord)record.Value;
                        break;
                    }
                }
            }
        }

        if (null == sceneDefine)
        {
            Debug.LogError("Scene Table Not Find, SceneID:" + curScene);
            return;
        }

        int nLenth = sceneDefine.TerrainHeightMapLength;
        int nWidth = sceneDefine.TerrainHeightMapWidth;

        //初始化文件
        string obstacleFilePath = GetCurSceneObstacleFilePath();

        FileStream fileStream = new FileStream(obstacleFilePath, FileMode.Create, FileAccess.ReadWrite);
        int        nSeek      = 0;

        //先将地图的长和宽写入文件头
        fileStream.Seek(nSeek, SeekOrigin.Begin);
        byte[] byteLen = System.BitConverter.GetBytes(nLenth);
        fileStream.Write(byteLen, 0, byteLen.Length);
        nSeek += byteLen.Length;

        fileStream.Seek(nSeek, SeekOrigin.Begin);
        byte[] byteWid = System.BitConverter.GetBytes(nWidth);
        fileStream.Write(byteWid, 0, byteWid.Length);
        nSeek += byteWid.Length;

        bool ok = false;

        //对当前场景进行遍历,进行寻路检测,得到每一个点的可行走类型
        for (float fX = 0.0f; fX <= (float)nWidth; fX += 0.5f)
        {
            for (float fZ = 0.0f; fZ <= (float)nLenth; fZ += 0.5f)
            {
                ObstacleInfo nState = GetScenePosPathState(fX, fZ);
                byte[]       write  = Struct2Byte(nState);

                if (nState.Value == NRun || nState.Value == NWalk)
                {
                    ok = true;
                }

                fileStream.Seek(nSeek, SeekOrigin.Begin);
                fileStream.Write(write, 0, write.Length);
                nSeek += write.Length;
            }
        }
        fileStream.Close();

        if (!ok)
        {
            Debug.Log("1. Check tag has added to the objects.");
            Debug.Log("2. Check mesh collider has added to the objects.");
        }
        else
        {
            Debug.Log("Server Obstacle Create OK");
        }
    }
Example #22
0
 /// <summary>
 /// To override.
 /// </summary>
 /// <param name="item">Data of the table.</param>
 /// <param name="classe">Table.</param>
 /// <param name="messageList">List of the error message.</param>
 protected abstract void CheckSpecific(TableInit item, ModelClass classe, ICollection <NVortexMessage> messageList);