public void Save() { if (InputsOutputs.Count(io => io.Id == Id) != 0) { Update(); return; } //If InputsOutputs already exist; using (IDbConnection cnn = new SQLiteConnection(DBPath)) { cnn.Execute($"INSERT INTO InputsOutputs VALUES(@Id, @GeneralId, @Input, @Output, @ProductionTime, @Weight, @MaterialWeight);", this); } }
//TODO: расчёт веса и операции с весом #region //===== WEIGHT =====// public static void Refresh(string materialId = "") { if (materialId == "") { for (int i = 0; i < InputsOutputs.Length; i++) { InputsOutputs[i].Update(); } } else { InputOutput[] inputOutputs; inputOutputs = InputsOutputs.Where(io => (io.Inputs != null && io.Inputs.Count(bc => bc.Id == materialId) != 0) || (io.Outputs != null && io.Outputs.Count(bc => bc.Id == materialId) != 0)).ToArray(); foreach (InputOutput inputOutput in inputOutputs) { Item[] items; items = inputOutput.Inputs.Where(item => Material.GetMaterial(item.Id) != null).ToArray(); inputOutput.Input = string.Join(";", items.Select(item => item.Id + " " + item.Amount)); if (inputOutput.Input == "") { inputOutput.Input = null; } items = inputOutput.Outputs.Where(item => Material.GetMaterial(item.Id) != null).ToArray(); inputOutput.Output = string.Join(";", items.Select(item => item.Id + " " + item.Amount)); if (inputOutput.Output == "") { inputOutput.Output = null; } inputOutput.Update(); } } }
public static InputOutput GetInputOutput(string id) => InputsOutputs.First(io => io.Id == id);