Пример #1
0
        public void OnSyncAll(object InObj, JsonData InJsonData)
        {
            if (InJsonData.Count != propertyInfoLength)
            {
                Debug.LogError(classType.Name + " 协议数量不匹配。\n属性个数 : " + infoDict.Count + " != 协议个数:" + InJsonData.Count);
            }

            try
            {
                foreach (KeyValuePair <string, PropertyInfo> itor in infoDict)
                {
                    JsonData jsonData = InJsonData[itor.Key];
                    itor.Value.SetValue(InObj, ConvertTypeUtility.ChangeType(jsonData == null ? string.Empty : jsonData.ToString(), itor.Value.PropertyType), null);
                }
            }
            catch (Exception e)
            {
                string log = string.Empty;
                foreach (KeyValuePair <string, PropertyInfo> itor in infoDict)
                {
                    log += itor.Key + ", ";
                }
                Debug.LogError(InJsonData.ToJson() + "\n" + log + "\n" + e.Message + "\n" + e.StackTrace);
            }
        }
Пример #2
0
 public void OnSyncOne(object InObj, PropertyInfo InInfo, object InValue)
 {
     if (null != InObj && null != InInfo && null != InValue)
     {
         object oldValue = InInfo.GetValue(InObj, null);
         if (!InValue.Equals(oldValue))
         {
             if (null == oldValue || InValue.GetType() != InInfo.PropertyType)
             {
                 InValue = ConvertTypeUtility.ChangeType(InValue, InInfo.PropertyType);
             }
             InInfo.SetValue(InObj, InValue, null);
             if (InObj is SyncBase)
             {
                 (InObj as SyncBase).OnPropertyChanged(InInfo.Name, oldValue, InValue);
             }
         }
     }
 }
Пример #3
0
        public static void Creator(ref TableData InTableData, string InDatabasePath)
        {
            string path = Application.dataPath + "/" + InDatabasePath;

            SQLite3Operate handle = new SQLite3Operate(path, SQLite3OpenFlags.Create | SQLite3OpenFlags.ReadWrite);

            StringBuilder sb = new StringBuilder(256);

            handle.Exec("DROP TABLE IF EXISTS " + InTableData.TableName);

            sb.Append("CREATE TABLE ")
            .Append(InTableData.TableName)
            .Append("(");

            int length = InTableData.ColumnName.Length;

            for (int i = 0; i < length; i++)
            {
                if (InTableData.IsColumnEnables[i])
                {
                    sb.Append(InTableData.ColumnName[i])
                    .Append(" ")
                    .Append(InTableData.SQLite3Types[i])
                    .Append(GetConnstraint(InTableData.SQLite3Constraints[i]))
                    .Append(", ");
                }
            }
            sb.Remove(sb.Length - 2, 2);
            sb.Append(")");
            handle.Exec(sb.ToString());

            if (null != InTableData.ExcelContents)
            {
                length = InTableData.ExcelContents.Length;
                int   subLength;
                ICell cell;
                for (int i = 0; i < length; i++)
                {
                    subLength = InTableData.ExcelContents[i].Length;
                    sb.Remove(0, sb.Length);
                    sb.Append("INSERT INTO ").Append(InTableData.TableName).Append(" VALUES(");
                    for (int j = 0; j < subLength; j++)
                    {
                        if (InTableData.IsColumnEnables[j])
                        {
                            cell = InTableData.ExcelContents[i][j];
                            switch (InTableData.SQLite3Types[j])
                            {
                            case SQLite3ValueType.INTEGER:
                                if (null == cell)
                                {
                                    sb.Append(0);
                                }
                                else
                                {
                                    switch (cell.CellType)
                                    {
                                    case CellType.Numeric:
                                        sb.Append((int)cell.NumericCellValue);
                                        break;

                                    case CellType.String:
                                        int result;
                                        sb.Append(int.TryParse(cell.StringCellValue, out result)
                                                    ? result
                                                    : 0);
                                        break;

                                    case CellType.Boolean:
                                        sb.Append(cell.BooleanCellValue ? 1 : 0);
                                        break;

                                    default:
                                        sb.Append(0);
                                        break;
                                    }
                                }
                                break;

                            case SQLite3ValueType.REAL:
                                if (null == cell)
                                {
                                    sb.Append(0);
                                }
                                else
                                {
                                    switch (cell.CellType)
                                    {
                                    case CellType.Numeric:
                                        sb.Append(cell.NumericCellValue);
                                        break;

                                    case CellType.String:
                                        double result;
                                        sb.Append(double.TryParse(cell.StringCellValue, out result)
                                                    ? result
                                                    : 0);
                                        break;

                                    case CellType.Boolean:
                                        sb.Append(cell.BooleanCellValue ? 1 : 0);
                                        break;

                                    default:
                                        sb.Append(0);
                                        break;
                                    }
                                }
                                break;

                            default:
                                if (null == cell)
                                {
                                    sb.Append("''");
                                }
                                else
                                {
                                    switch (cell.CellType)
                                    {
                                    case CellType.Numeric:
                                        sb.Append("\'")
                                        .Append(cell.NumericCellValue)
                                        .Append("\'");
                                        break;

                                    case CellType.String:
                                        sb.Append(ConvertTypeUtility.CheckSingleQuoteMatch(cell.StringCellValue));
                                        break;

                                    case CellType.Boolean:
                                        sb.Append("\'")
                                        .Append(cell.BooleanCellValue.ToString())
                                        .Append("\'");
                                        break;

                                    default:
                                        sb.Append("''");
                                        break;
                                    }
                                }
                                break;
                            }
                            sb.Append(", ");
                        }
                    }
                    sb.Remove(sb.Length - 2, 2);
                    sb.Append(")");
                    handle.Exec(sb.ToString());
                }
            }

            handle.CloseDB();
        }