using Api.Framework; using Api.Framework.Model; using Api.Framework.Tools; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using UI.Framework.Forms; namespace FLSystem.Forms { public partial class notice_robotapi_editform : BaseForm { public notice_robotapi_editform(fl_noticeapi_info model = null) { InitializeComponent(); this.model = model; comboBox1.DataSource = null; comboBox1.DataSource = Enum.GetNames(typeof(NoticeApiType)); this.comboBox1.SelectedIndex = 0; this.simpleButton3.Enabled = false; if (model != null) { this.textBox1.Text = this.model.name; this.textBox1.ReadOnly = true; for (int i = 0; i < this.comboBox1.Items.Count; i++) { var text = this.comboBox1.Items[i].ToString(); if (model.notice_apitype.ToString() == text) { this.comboBox1.SelectedIndex = i; break; } } this.textBox2.Text = this.model.remark; this.textBox3.Text = this.model.api_location; this.textBox4.Text = this.model.token; this.simpleButton3.Enabled = true; } } public bool IsUpdate { get; private set; } fl_noticeapi_info model; private void simpleButton1_Click(object sender, EventArgs e) { try { //fl_noticeapi_info temp = null; if (model == null) model = new fl_noticeapi_info() { name = this.textBox1.Text }; model.notice_apitype = Util.ConvertEnum(this.comboBox1.Text); model.api_location = this.textBox3.Text; model.token = this.textBox4.Text; model.remark = this.textBox2.Text; var session = ApiClient.GetSession(); if (model.id == 0) session.Insertable(model).ExecuteCommand(); else session.Updateable(model).ExecuteCommand(); IsUpdate = true; this.Close(); } catch (Exception ex) { BaseForm.ShowError(ex); } } private void simpleButton2_Click(object sender, EventArgs e) { try { fl_noticeapi_info temp = new fl_noticeapi_info() { name = "测试", notice_apitype = Util.ConvertEnum(this.comboBox1.Text), remark = string.Empty, api_location = this.textBox3.Text, token = this.textBox4.Text }; ApiClient.SendNoticeMessage(temp, "这是一条FLsystem的测试消息!", false); BaseForm.ShowSuccess("已发送测试消息,请注意查收!"); } catch (Exception ex) { BaseForm.ShowError(ex); } } private void simpleButton3_Click(object sender, EventArgs e) { try { var session = ApiClient.GetSession(); session.ExcuteSQL("delete from fl_noticeapi_info where id=" + model.id); IsUpdate = true; this.Close(); } catch (Exception ex) { BaseForm.ShowError(ex); } } } }