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); } } }
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 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); } } }
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(); }