using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LYFZ.Software.MainBusiness.MarketingAllPerson.SuperSmallForm
{
public partial class MaxTeamNameSetSuperSmallForm : LYFZ.Software.UI.MarketingAllPerson.SuperSmallForm.MaxTeamNameSetSuperSmallForm
{
LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
LYFZ.BLL.BLL_ErpTeamMaxNameSet tmxnbll = new BLL.BLL_ErpTeamMaxNameSet();
public MaxTeamNameSetSuperSmallForm()
{
this.Load += MaxTeamNameSetSuperSmallForm_Load;
this.Shown += MaxTeamNameSetSuperSmallForm_Shown;
this.btnNew.Click += btnNew_Click;
this.btnSaveed.Click += btnSaveed_Click;
this.btnDelete.Click += btnDelete_Click;
this.dgvData.CellMouseClick += dgvData_CellMouseClick;
this.txtTeamMaxName.KeyPress += txtTeamMaxName_KeyPress;
}
///
/// 是否保存
///
public bool IsSaveed = false;
///
/// 窗体加载事件
///
///
///
void MaxTeamNameSetSuperSmallForm_Load(object sender, EventArgs e)
{
DataTable dt = orbll.GetView_Custom("tb_ErpTeamMaxNameSet", StrWhere: "", ShowColumnName: "ID,Tmxn_Name AS 大队名称").Tables[0];
this.dgvData.DataSource(dt, strHideField: "ID");
}
///
/// 窗体加载事件
///
///
///
void MaxTeamNameSetSuperSmallForm_Shown(object sender, EventArgs e)
{
}
///
/// 新建
///
///
///
void btnNew_Click(object sender, EventArgs e)
{
this.IntClickID = 0;
this.txtTeamMaxName.Text = "";
this.btnSaveed.Text = " 保 存";
}
///
/// 保存
///
///
///
void btnSaveed_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.txtTeamMaxName.Text.Trim()))
{ MessageBoxCustom.Show("大队名称不能为空!"); return; }
DateTime StrTime = SDateTime.Now;
string StrUserID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
LYFZ.Model.Model_ErpTeamMaxNameSet model = null;
if (this.IntClickID <= 0)
{
DataTable dt = orbll.GetView_Custom("tb_ErpTeamMaxNameSet", StrWhere: "Tmxn_Name = '" + this.txtTeamMaxName.Text.Trim() + "'", ShowColumnName: "ID").Tables[0];
if (dt.Rows.Count > 0)
{ MessageBoxCustom.Show("大队名称已存在,不能重复命名!"); return; }
model = new Model.Model_ErpTeamMaxNameSet();
model.Tmxn_Number = "MXN_" + LYFZ.WinAPI.CustomPublicMethod.GenerateId().ToString().Trim();
model.Tmxn_Name = this.txtTeamMaxName.Text.Trim();
model.Tmxn_CreateDateTime = StrTime;
model.Tmxn_CreateName = StrUserID;
if (tmxnbll.Add(model))
{
this.IsSaveed = true;
MessageBoxCustom.Show("添加成功!");
this.MaxTeamNameSetSuperSmallForm_Load(this, null);
this.btnNew_Click(this, null);
}
else
{ MessageBoxCustom.Show("添加失败!"); }
}
else
{
DataTable dt = orbll.GetView_Custom("tb_ErpTeamMaxNameSet", StrWhere: "Tmxn_Name = '" + this.txtTeamMaxName.Text.Trim() + "' And ID != '" + this.IntClickID + "'", ShowColumnName: "ID").Tables[0];
if (dt.Rows.Count > 0)
{ MessageBoxCustom.Show("大队名称已存在,不能重复命名!"); return; }
model = tmxnbll.GetModel(this.IntClickID);
model.Tmxn_Name = this.txtTeamMaxName.Text.Trim();
model.Tmxn_UpdateDateTime = StrTime;
model.Tmxn_UpdateName = StrUserID;
if (tmxnbll.Update(model))
{
this.IsSaveed = true;
MessageBoxCustom.Show("修改成功!");
this.MaxTeamNameSetSuperSmallForm_Load(this, null);
}
else
{ MessageBoxCustom.Show("修改失败!"); }
}
}
///
/// 删除
///
///
///
void btnDelete_Click(object sender, EventArgs e)
{
if (this.IntClickID > 0)
{
DataTable dt = orbll.GetView_Custom("tb_ErpTeamMaxNameSet", StrWhere: "ID = '" + this.IntClickID + "'", ShowColumnName: "Tmxn_Number").Tables[0];
if (dt.Rows.Count > 0)
{
dt = orbll.GetView_Custom("tb_ErpTeamMaxTaskSet", StrWhere: "Tmxt_TmxnNumber = '" + dt.Rows[0]["Tmxn_Number"].ToString().Trim() + "'", ShowColumnName: "ID").Tables[0];
if (dt.Rows.Count > 0)
{ MessageBoxCustom.Show("大队名称已有使用,不能删除!"); return; }
}
if (MessageBoxCustom.Show("您确定要删除吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
if (tmxnbll.Delete(this.IntClickID))
{
this.IsSaveed = true;
MessageBoxCustom.Show("删除成功!");
this.MaxTeamNameSetSuperSmallForm_Load(this, null);
this.btnNew_Click(this, null);
}
else
{ MessageBoxCustom.Show("删除失败!"); }
}
}
else
{ MessageBoxCustom.Show("请选择你要删除的大队!"); }
}
int IntClickID = 0;
///
/// 列表点击事件
///
///
///
void dgvData_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
{
if (this.dgvData.Rows.Count > 0)
{
this.IntClickID = Convert.ToInt32(this.dgvData.Rows[e.RowIndex].Cells["ID"].Value);
this.txtTeamMaxName.Text = this.dgvData.Rows[e.RowIndex].Cells["大队名称"].Value.ToString().Trim();
this.btnSaveed.Text = " 修 改";
}
}
}
///
/// 大队输入限制
///
///
///
void txtTeamMaxName_KeyPress(object sender, KeyPressEventArgs e)
{
if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar) && !Char.IsLetterOrDigit(e.KeyChar) && e.KeyChar != '_' && e.KeyChar != ' ')
{ e.Handled = true; }
if (Char.IsNumber(e.KeyChar))
{
if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "[0-9]") && e.KeyChar != '\b')
{ e.Handled = true; }
}
}
}
}