public void read_json() { if (File.Exists(curwarnfilename) == true) { string json = File.ReadAllText(curwarnfilename, Encoding.ASCII); JsonReader reader = new JsonReader(json); JsonData data = JsonMapper.ToObject(reader); int count = (int)Convert.ChangeType(data["warncount"].ToString(), typeof(int)); if (count > 0) { WarnManagement.Instance().clearlist(); } for (int i = 0; i < count; i++) { JsonData datasub = data["warnlist" + i.ToString()]; Warn warn = new Warn(); warn.setgreatorless(datasub["greatorless"].ToString()); warn.setprice(datasub["price"].ToString()); warn.setalerttype(datasub["alerttype"].ToString()); WarnManagement.Instance().addtolist(warn); } } }
public static WarnManagement Instance() { if (_instance == null) { _instance = new WarnManagement(); } return(_instance); }
private void Form2_Load(object sender, EventArgs e) { this.Text = Define.TitleBase; this.MaximizeBox = false; //this.MaximizeBox = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; combo_greatorless.Items.Add("小于"); combo_greatorless.Items.Add("大于"); check_warn1.Text = "声音报警"; check_warn2.Text = "任栏闪动"; if (BTCorLTC == 0) { radioBTCorLTC1.Checked = true; } else { radioBTCorLTC2.Checked = true; } if (BTCorLTC > -1 && index > -1) { WarnManagement.Instance().set_cur_warnlist(BTCorLTC); Warn warn = WarnManagement.Instance().get_Warn(index); if (warn != null) { radioBTCorLTC1.Enabled = false; radioBTCorLTC2.Enabled = false; if (warn.greatorless == 0) { //combo_greatorless.Select(warn.greatorless); combo_greatorless.SelectedIndex = warn.greatorless; } else { //combo_greatorless.Select(warn.greatorless); combo_greatorless.SelectedIndex = warn.greatorless; } txt_price.Text = warn.price.ToString(); if (warn.alerttype == 1) { check_warn1.Checked = true; } if (warn.alerttype == 2) { check_warn2.Checked = true; } if (warn.alerttype == 3) { check_warn1.Checked = true; check_warn2.Checked = true; } button1.Text = "确定修改"; } } }
private void button1_Click(object sender, EventArgs e) { if (combo_greatorless.Text.ToString().Length == 0 || txt_price.Text.ToString().Length == 0 || (check_warn1.Checked == false && check_warn2.Checked == false) ) { return; } int greatorless = 0; String price = txt_price.Text; int alerttype = 0; if (combo_greatorless.Text == "小于") { greatorless = 0; } else { greatorless = 1; } if (check_warn1.Checked == true) { alerttype = 1; } if (check_warn2.Checked == true) { alerttype = 2; } if (check_warn1.Checked == true && check_warn2.Checked == true) { alerttype = 3; } Warn warn = null; if (BTCorLTC > -1 && index > -1)//修改, { WarnManagement.Instance().set_cur_warnlist(BTCorLTC); warn = WarnManagement.Instance().get_Warn(index); warn.greatorless = greatorless; warn.setprice(txt_price.Text); warn.alerttype = alerttype; //WarnManagement.Instance().addtolist(warn); WarnManagement.Instance().write_json(); MessageBox.Show(this, "修改预警成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else //添加 { warn = new Warn(); warn.greatorless = greatorless; warn.setprice(txt_price.Text); warn.alerttype = alerttype; if (radioBTCorLTC1.Checked == true) { WarnManagement.Instance().set_cur_warnlist(0); } else { WarnManagement.Instance().set_cur_warnlist(1); } WarnManagement.Instance().addtolist(warn); WarnManagement.Instance().write_json(); MessageBox.Show(this, "预警添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } this.Close(); }
public static WarnManagement Instance() { if (_instance == null) _instance = new WarnManagement(); return _instance; }