using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace CloudWaterNetwork { public static class Global { public static PropertyForm PropertyForm; public static MapViewer map; public static Templates Templates; public static List mapObjectRecords = new List(); public static int RecordIndex=0; } public class MapOption { public float Link_multiply { get; set; } = 0.6667f; public float junction_multiply { get; set; } = 1f; public bool _ShowValve { get; set; } = true; public bool _ShowJunction { get; set; } = true; } //public class AutoBuildParams //{ // public int MaxLevel; // public int FloorHeigh; //} public enum MapObjectType { ALL, Junction, Reservoir, Tank, Pipe, Valve, Repeater, } public static class GlobalExtension { public static Type GetObjType(this MapObjectType type) { switch (type) { case MapObjectType.ALL: return null; case MapObjectType.Junction:return typeof(Junction); case MapObjectType.Reservoir: return typeof(Reservoir); case MapObjectType.Tank: return typeof(Tank); case MapObjectType.Pipe: return typeof(Pipe); case MapObjectType.Valve: return typeof(Valve); case MapObjectType.Repeater: return typeof(Repeater); default: return null; } } } public class MapObjectRecord { public MapObject mapObject { get; set; } public string ValueName { get; set; } public dynamic Value { get; set; } } public class Parts { List _parts = null; public int Length { get { if (_parts != null) return _parts.Count; else return -1; } } public int Count { get { if (_parts != null) return _parts.Count; else return -1; } } public Parts(string[] strings) { _parts = strings.ToList(); } public string this[int index] { get { if (_parts != null && _parts.Count > index) return _parts[index]; else return null; } set { _parts[index] = value; } } } public class message { public static bool show(string caption, string content, MessageBoxButtons boxButtons = MessageBoxButtons.OKCancel) { var result = MessageBox.Show(content, caption, boxButtons, MessageBoxIcon.Information); if (result == DialogResult.OK || result == DialogResult.Yes) return true; else return false; } } public class Default { static string _filePath =Path.Combine( Directory.GetCurrentDirectory() ,@"default.ini"); //public static string JunctionPre = "J"; //public static string ReservoirPre = "R"; //public static string TankPre = "T"; //public static string PipePre = "P"; //public static string ValvePre = "V"; //public static string MeterPre = "M"; //public static string RepeaterPre = "Repeater"; public Node junction; public Reservoir reservoir; public Tank tank; public Meter meter; public Link pipe; public Valve valve; public Repeater repeater; public static Default GetfaultINI() { StreamReader sr = new StreamReader(_filePath); string json = sr.ReadToEnd(); sr.Close(); return JsonConvert.DeserializeObject(json); } public void SaveFile() { StreamWriter sw = new StreamWriter(_filePath); sw.WriteLine(JsonConvert.SerializeObject(this)); sw.Close(); } public static Dictionary PreName = new Dictionary() { {"Junction","J" }, {"Reservoir","R" }, {"Tank","T" }, {"Meter","M" }, {"Pipe","P" }, {"Valve","V" }, {"Repeater","Rp" }, }; public static string GetPreString(MapObject obj) { return PreName[obj.GetTypeString()]; } } public enum MouseState { 无, 新增节点, 新建水库, 新建水池, 新增管线, 新建阀门, 新建水表, 新建重复器, } }