Exemplo n.º 1
0
 private void PropEditorPropCellRow(PARAM.Cell cell, ref int id)
 {
     PropEditorPropRow(cell.Value, ref id, cell.Def.InternalName, FieldMetaData.Get(cell.Def), cell.Value.GetType(), cell.GetType().GetProperty("Value"), cell, null);
 }
Exemplo n.º 2
0
 public static MassEditResult PerformSingleMassEdit(string csvString, ActionManager actionManager, string param, string field, bool useSpace)
 {
     try
     {
         PARAM p = ParamBank.Params[param];
         if (p == null)
         {
             return(new MassEditResult(MassEditResultType.PARSEERROR, "No Param selected"));
         }
         string[]            csvLines    = csvString.Split('\n');
         int                 changeCount = 0;
         List <EditorAction> actions     = new List <EditorAction>();
         foreach (string csvLine in csvLines)
         {
             if (csvLine.Trim().Equals(""))
             {
                 continue;
             }
             string[] csvs = csvLine.Split(useSpace ? ' ' : ',', 2, StringSplitOptions.RemoveEmptyEntries);
             if (csvs.Length != 2)
             {
                 return(new MassEditResult(MassEditResultType.PARSEERROR, "CSV has wrong number of values"));
             }
             int       id    = int.Parse(csvs[0]);
             string    value = csvs[1];
             PARAM.Row row   = p[id];
             if (row == null)
             {
                 return(new MassEditResult(MassEditResultType.OPERATIONERROR, $@"Could not locate row {id}"));
             }
             if (field.Equals("Name"))
             {
                 if (row.Name == null || !row.Name.Equals(value))
                 {
                     actions.Add(new PropertiesChangedAction(row.GetType().GetProperty("Name"), -1, row, value));
                 }
             }
             else
             {
                 PARAM.Cell cell = row[field];
                 if (cell == null)
                 {
                     return(new MassEditResult(MassEditResultType.OPERATIONERROR, $@"Could not locate field {field}"));
                 }
                 // Array types are unhandled
                 if (cell.Value.GetType().IsArray)
                 {
                     continue;
                 }
                 object newval = PerformOperation(cell, "=", value);
                 if (newval == null)
                 {
                     return(new MassEditResult(MassEditResultType.OPERATIONERROR, $@"Could not assign {value} to field {cell.Def.InternalName}"));
                 }
                 if (!cell.Value.Equals(newval))
                 {
                     actions.Add(new PropertiesChangedAction(cell.GetType().GetProperty("Value"), -1, cell, newval));
                 }
             }
         }
         changeCount = actions.Count;
         if (changeCount != 0)
         {
             actionManager.ExecuteAction(new CompoundAction(actions));
         }
         return(new MassEditResult(MassEditResultType.SUCCESS, $@"{changeCount} rows affected"));
     }
     catch
     {
         return(new MassEditResult(MassEditResultType.PARSEERROR, "Unable to parse CSV into correct data types"));
     }
 }
Exemplo n.º 3
0
 private void PropEditorPropCellRow(PARAM.Cell cell, PARAM.Cell vcell, ref int id, Regex propSearchRx)
 {
     PropEditorPropRow(cell.Value, vcell == null?null:vcell.Value, ref id, cell.Def.InternalName, FieldMetaData.Get(cell.Def), cell.Value.GetType(), cell.GetType().GetProperty("Value"), cell, null, propSearchRx);
 }