124 lines
4.4 KiB
C#
124 lines
4.4 KiB
C#
|
using Api.Framework;
|
|||
|
using Api.Framework.Model;
|
|||
|
using Api.Framework.Tools;
|
|||
|
using DevExpress.XtraEditors;
|
|||
|
using SqlSugar;
|
|||
|
using System;
|
|||
|
using System.Linq;
|
|||
|
using System.Windows.Forms;
|
|||
|
using UI.Framework.Forms;
|
|||
|
|
|||
|
namespace FLSystem.Forms
|
|||
|
{
|
|||
|
public partial class EditGroup : BaseForm
|
|||
|
{
|
|||
|
private fl_group_person group = null;
|
|||
|
SqlSugarClient session = ApiClient.GetSession();
|
|||
|
public EditGroup(fl_group_person group = null)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
this.group = group;
|
|||
|
this.Text = Text.Replace("{0}", group == null ? "增加" : "修改");
|
|||
|
}
|
|||
|
|
|||
|
private void EditGroup_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (group != null)
|
|||
|
{
|
|||
|
textBox1.Text = group.groupid;
|
|||
|
textBox2.Text = group.groupname;
|
|||
|
if (group.mid != 0)
|
|||
|
{
|
|||
|
var member = session.FindSingle<fl_member_info>("select * from fl_member_info where username = @username", new { username = textBox3.Text });
|
|||
|
if (member != null)
|
|||
|
{
|
|||
|
textBox3.Text = member.username;
|
|||
|
textBox4.Text = member.usernick;
|
|||
|
linkLabel2.Tag = member.id;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var groupForm = new GroupForm();
|
|||
|
if (groupForm.ShowDialog() == DialogResult.OK)
|
|||
|
{
|
|||
|
if (groupForm.group != null)
|
|||
|
{
|
|||
|
textBox1.Text = groupForm.group.groupid;
|
|||
|
textBox2.Text = groupForm.group.groupname;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var memberForm = new MemberForm();
|
|||
|
if (memberForm.ShowDialog() == DialogResult.OK)
|
|||
|
{
|
|||
|
if (memberForm.member != null)
|
|||
|
{
|
|||
|
textBox3.Text = memberForm.member.username;
|
|||
|
textBox4.Text = memberForm.member.usernick;
|
|||
|
linkLabel2.Tag = memberForm.member.id;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
ShowError(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void EditGroup_FormClosing(object sender, FormClosingEventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (string.IsNullOrWhiteSpace(textBox1.Text)) throw new Exception("请填写群账号");
|
|||
|
if (string.IsNullOrWhiteSpace(textBox3.Text)) throw new Exception("请填写管理账号");
|
|||
|
|
|||
|
if (group == null)
|
|||
|
{
|
|||
|
var _group = session.Queryable<fl_group_person>().First(f => f.groupid == textBox1.Text.Trim());
|
|||
|
if (_group != null) throw new Exception("该群账号已经存在请核对后重试");
|
|||
|
group = new fl_group_person() { groupid = textBox1.Text.Trim(), groupname = textBox2.Text.Trim() };
|
|||
|
}
|
|||
|
|
|||
|
long mid = 0;
|
|||
|
if (linkLabel2.Tag != null)
|
|||
|
mid = long.Parse(linkLabel2.Tag.ToString());
|
|||
|
else
|
|||
|
{
|
|||
|
var member = session.FindSingle<fl_member_info>("select * from fl_member_info where username = @username",new { username = textBox3.Text });
|
|||
|
if (member == null) throw new Exception("输入的管理员账号不存在");
|
|||
|
mid = member.id;
|
|||
|
}
|
|||
|
group.mid = mid;
|
|||
|
session.SaveOrUpdate(group);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
if (XtraMessageBox.Show(ex.Message + ",是否关闭?", "操作失败", MessageBoxButtons.YesNo) == DialogResult.No)
|
|||
|
e.Cancel = true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|