Esempio n. 1
0
 public DbTableAttribute(string tableName)
 {
     TableName = DBKeywords.GetNoKeywordName(tableName);
 }
Esempio n. 2
0
        public static void Convert(SQLiteHelper db, Excel excel)
        {
            foreach (var table in excel.Tables)
            {
                if (!table.TableName.EndsWith(ExportExtra))
                {
                    continue;
                }

                List <string> colNames = new List <string>();
                List <string> coltypes = new List <string>();

                #region 创建表

                if (table.NumberOfRows < 2)
                {
                    Debug.LogError("Data format error : NumberOfRows is less than 2");
                }

                string tableName = table.TableName.Replace(ExportExtra, "");

                tableName = DBKeywords.GetNoKeywordName(tableName);

                {
                    for (int j = 1; j <= table.NumberOfColumns; j++)
                    {
                        if (colNames.Contains(table.GetCell(1, j).Value))
                        {
                            Debug.LogError(string.Format("tableName [{0}] repeated in table [{1}]",
                                                         table.GetCell(1, j).Value, table.TableName));
                            return;
                        }

                        colNames.Add(table.GetCell(1, j).Value);
                        var cel = table.GetCell(2, j).Value;

                        if (!TypeLimits.Contains(cel))
                        {
                            Debug.LogError(string.Format("Type error in table [ {0} ] in ( {1},{2} ) error type {3}",
                                                         tableName, 2, j, cel));
                            return;
                        }

                        coltypes.Add(cel);
                    }

                    if (colNames.Count != coltypes.Count)
                    {
                        Debug.LogError("ColNames do not match ColTypes in count : " + table.TableName);
                    }

                    db.DeleteTable(tableName);
                    db.CreateTable(tableName, colNames.ToArray(), coltypes.ToArray());
                }

                #endregion 创建表

                #region 插入数据

                for (int i = 3; i <= table.NumberOfRows; i++)
                {
                    List <string> cols = new List <string>();

                    for (int j = 1; j <= table.NumberOfColumns; j++)
                    {
                        var cel = table.GetCell(i, j).Value;

                        //Remove empty line
                        if (j == 1 && string.IsNullOrEmpty(cel))
                        {
                            break;
                        }

                        cols.Add(cel);
                    }


                    if (cols.Count > 0 && colNames.Count != cols.Count)
                    {
                        Debug.LogError("ColNames do not match Cols in count : " + table.TableName);
                        return;
                    }


                    db.InsertValues(tableName, colNames.ToArray(), cols.ToArray());
                }

                #endregion 插入数据
            }
        }