📄 fmeditgroups.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace AddressList.Forms
{
public partial class fmEditGroups : AddressList.Forms.fmEditBaseForm
{
protected fmEditGroups()
{
InitializeComponent();
}
public fmEditGroups(BillStates billState, int intKey)
: base(billState, intKey)
{
InitializeComponent();
}
protected override bool BeforeSave()
{
errProvider.Clear();
bool result = base.BeforeSave();
if (EditIsBlank(textGroup, "组别名称", true))
{
const string sNeedInputName = "组别名称不能为空,请录入";
errProvider.SetError(textGroup, sNeedInputName);
result = false;
}
if (result)
{
int maxID = -1;
if (BillStates.bsEdit == BillState) maxID = IntegerID;
if (ValueExists(maxID, "t_FriendGroup", "FName", "FInterID", textGroup.Text))
{
const string sGroupNameExists = "组别名称已经存在,请重新录入";
errProvider.SetError(textGroup, sGroupNameExists);
textGroup.Focus();
ShowErrorMsg(sGroupNameExists);
result = false;
}
}
return result;
}
/// <summary>
/// 保存数据
/// </summary>
protected override void Saveing()
{
base.Saveing();
const string updateSql = "UPDATE t_FriendGroup SET FName='{0}' WHERE FInterID > 0 AND FInterID={1}";
const string insertSql = "INSERT INTO t_FriendGroup(FInterID, FParentID, FName) VALUES({0}, {1}, {2})";
int keyValue = 1;
string groupName = QuoteStr(textGroup.Text);
string sqlString;
if (BillState == BillStates.bsNew)
{
keyValue = GetMaxID("t_FriendGroup", "FInterID", string.Empty) + 1;
int parentID = IntegerID;
parentID = 0; //TODO:只允许增加一级组别
sqlString = string.Format(insertSql, keyValue, parentID, groupName);
}
else
{
sqlString = string.Format(updateSql, groupName, IntegerID);
}
if (DBConn.DBCommand(sqlString).ExecuteNonQuery() < 1)
ShowErrorMsg("数据保存失败!");
}
protected override void AfterSave()
{
base.AfterSave();
textGroup.Modified = false;
}
private void buttonOk_Click(object sender, EventArgs e)
{
DoSave(true);
}
protected override void LoadData(int intKey)
{
const string getGroupName = "SELECT FName FROM t_FriendGroup WHERE FInterID={0}";
object[] value = DBConn.DBSelectValue(string.Format(getGroupName, intKey));
if (null != value)
{
string groupName = value[0].ToString();
textGroup.Text = groupName;
}
}
private void textGroup_KeyPress(object sender, KeyPressEventArgs e)
{
//if ('\'' == e.KeyChar)
// e.Handled = true;
}
private void fmEditGroups_FormClosing(object sender, FormClosingEventArgs e)
{
if (textGroup.Modified)
{
switch(MessageBox.Show("数据被修改,是否保存?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
{
case DialogResult.Yes:
DoSave(true);
break;
case DialogResult.Cancel:
e.Cancel = true;
break;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -