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.SetSmallForm
{
public partial class AddNewActiveSmallForm : LYFZ.Software.UI.MarketingAllPerson.SetSmallForm.AddNewActiveSmallForm
{
LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
LYFZ.BLL.BLL_ErpTeamActiveSet tasbll = new BLL.BLL_ErpTeamActiveSet();
public AddNewActiveSmallForm()
{
this.Load += AddNewActiveSmallForm_Load;
this.Shown += AddNewActiveSmallForm_Shown;
this.btnNew.Click += btnNew_Click;
this.btnSaveed.Click += btnSaveed_Click;
this.btnDelete.Click += btnDelete_Click;
this.btnClose.Click += btnClose_Click;
this.dgvData.CellMouseClick += dgvData_CellMouseClick;
this.chkShow.Click += chkShow_Click;
this.chkHide.Click += chkHide_Click;
this.txtName.KeyPress += txtName_KeyPress;
this.txtBaodiTask.KeyPress += txtBaodiTask_KeyPress;
this.txtTargetTask.KeyPress += txtTargetTask_KeyPress;
this.txtSprintTask.KeyPress += txtSprintTask_KeyPress;
}
///
/// 是否保存
///
public bool IsSaveed = false;
///
/// 窗体加载事件
///
///
///
void AddNewActiveSmallForm_Load(object sender, EventArgs e)
{
DataTable dt = orbll.GetView_Custom("tb_ErpTeamActiveSet", StrWhere: "", ShowColumnName: "ID,Tas_Name AS 活动名称,(dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Tas_DateTimeStart)) + '至' + dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Tas_DateTimeEnd))) AS 截止日期,Tas_BaodiTask AS 保底任务,Tas_TargetTask AS 目标任务,Tas_SprintTask AS 冲刺任务,(case when Tas_IsEnabled = 0 then '隐藏' else '显示' end) AS 是否显示").Tables[0];
this.dgvData.DataSource(dt, strHideField: "ID");
}
///
/// 窗体加载事件
///
///
///
void AddNewActiveSmallForm_Shown(object sender, EventArgs e)
{
}
///
/// 新建
///
///
///
void btnNew_Click(object sender, EventArgs e)
{
this.IntClickID = 0;
this.txtName.Text = "";
this.dtpDateTimeStart.DateValue = "";
this.dtpDateTimeEnd.DateValue = "";
this.chkShow.Checked = true;
this.chkHide.Checked = false;
this.txtBaodiTask.Text = "";
this.txtTargetTask.Text = "";
this.txtSprintTask.Text = "";
this.btnSaveed.Text = " 保 存";
}
///
/// 保存
///
///
///
void btnSaveed_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
{ MessageBoxCustom.Show("活动名称不能为空!"); return; }
if (string.IsNullOrEmpty(this.dtpDateTimeStart.DateValue.Trim()))
{ MessageBoxCustom.Show("开始日期不能为空!"); return; }
if (string.IsNullOrEmpty(this.dtpDateTimeEnd.DateValue.Trim()))
{ MessageBoxCustom.Show("结束日期不能为空!"); return; }
if (string.IsNullOrEmpty(this.txtBaodiTask.Text.Trim()))
{ MessageBoxCustom.Show("保底任务不能为空!"); return; }
if (string.IsNullOrEmpty(this.txtTargetTask.Text.Trim()))
{ MessageBoxCustom.Show("目标任务不能为空!"); return; }
if (string.IsNullOrEmpty(this.txtSprintTask.Text.Trim()))
{ MessageBoxCustom.Show("冲刺不能为空!"); return; }
if (Convert.ToDateTime(this.dtpDateTimeStart.DateValue) > Convert.ToDateTime(this.dtpDateTimeEnd.DateValue))
{ MessageBoxCustom.Show("开始日期不能大于结束日期!"); return; }
if (Convert.ToDecimal(this.txtBaodiTask.Text.Trim()) > Convert.ToDecimal(this.txtTargetTask.Text.Trim()))
{ MessageBoxCustom.Show("目标任务不能小于保底任务!"); return; }
if (Convert.ToDecimal(this.txtTargetTask.Text.Trim()) > Convert.ToDecimal(this.txtSprintTask.Text.Trim()))
{ MessageBoxCustom.Show("冲刺任务不能小于目标任务!"); return; }
DateTime StrTime = SDateTime.Now;
string StrUserID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
LYFZ.Model.Model_ErpTeamActiveSet model = null;
if (this.IntClickID <= 0)
{
DataTable dt = orbll.GetView_Custom("tb_ErpTeamActiveSet", StrWhere: "Tas_Name = '" + this.txtName.Text.Trim() + "'", ShowColumnName: "ID").Tables[0];
if (dt.Rows.Count > 0)
{ MessageBoxCustom.Show("活动名称已存在,不能重复命名!"); return; }
model = new Model.Model_ErpTeamActiveSet();
model.Tas_Number = "MAN_" + LYFZ.WinAPI.CustomPublicMethod.GenerateId().ToString().Trim();
model.Tas_Name = this.txtName.Text.Trim();
model.Tas_DateTimeStart = Convert.ToDateTime(this.dtpDateTimeStart.DateValue);
model.Tas_DateTimeEnd = Convert.ToDateTime(this.dtpDateTimeEnd.DateValue).AddDays(1).AddSeconds(-1);
model.Tas_BaodiTask = Convert.ToDecimal(this.txtBaodiTask.Text.Trim());
model.Tas_TargetTask = Convert.ToDecimal(this.txtTargetTask.Text.Trim());
model.Tas_SprintTask = Convert.ToDecimal(this.txtSprintTask.Text.Trim());
model.Tas_IsEnabled = this.chkShow.Checked;
model.Tas_CreateDateTime = StrTime;
model.Tas_CreateName = StrUserID;
if (tasbll.Add(model))
{
this.IsSaveed = true;
MessageBoxCustom.Show("添加成功!");
this.AddNewActiveSmallForm_Load(this, null);
this.btnNew_Click(this, null);
}
else
{ MessageBoxCustom.Show("添加失败!"); }
}
else
{
DataTable dt = orbll.GetView_Custom("tb_ErpTeamActiveSet", StrWhere: "Tas_Name = '" + this.txtName.Text.Trim() + "' And ID != '" + this.IntClickID + "'", ShowColumnName: "ID").Tables[0];
if (dt.Rows.Count > 0)
{ MessageBoxCustom.Show("活动名称已存在,不能重复命名!"); return; }
model = tasbll.GetModel(this.IntClickID);
model.Tas_Name = this.txtName.Text.Trim();
model.Tas_DateTimeStart = Convert.ToDateTime(this.dtpDateTimeStart.DateValue);
model.Tas_DateTimeEnd = Convert.ToDateTime(this.dtpDateTimeEnd.DateValue).AddDays(1).AddSeconds(-1);
model.Tas_BaodiTask = Convert.ToDecimal(this.txtBaodiTask.Text.Trim());
model.Tas_TargetTask = Convert.ToDecimal(this.txtTargetTask.Text.Trim());
model.Tas_SprintTask = Convert.ToDecimal(this.txtSprintTask.Text.Trim());
model.Tas_IsEnabled = this.chkShow.Checked;
model.Tas_UpdateDateTime = StrTime;
model.Tas_UpdateName = StrUserID;
if (tasbll.Update(model))
{
this.IsSaveed = true;
MessageBoxCustom.Show("修改成功!");
this.AddNewActiveSmallForm_Load(this, null);
}
else
{ MessageBoxCustom.Show("修改失败!"); }
}
}
///
/// 删除
///
///
///
void btnDelete_Click(object sender, EventArgs e)
{
if (this.IntClickID > 0)
{
DataTable dt = orbll.GetView_Custom("tb_ErpTeamActiveSet", StrWhere: "ID = '" + this.IntClickID + "'", ShowColumnName: "Tas_Number").Tables[0];
if (dt.Rows.Count > 0)
{
dt = orbll.GetView_Custom("tb_ErpTeamMaxTaskSet", StrWhere: "Tmxt_TasNumber = '" + dt.Rows[0]["Tas_Number"].ToString().Trim() + "'", ShowColumnName: "ID").Tables[0];
if (dt.Rows.Count > 0)
{ MessageBoxCustom.Show("此活动名称已设置了大队,不能删除!"); return; }
}
if (MessageBoxCustom.Show("您确定要删除吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
if (tasbll.Delete(this.IntClickID))
{
this.IsSaveed = true;
MessageBoxCustom.Show("删除成功!");
this.AddNewActiveSmallForm_Load(this, null);
this.btnNew_Click(this, null);
}
else
{ MessageBoxCustom.Show("删除失败!"); }
}
}
else
{ MessageBoxCustom.Show("请选择你要删除的活动!"); }
}
///
/// 关闭
///
///
///
void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
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.txtName.Text = this.dgvData.Rows[e.RowIndex].Cells["活动名称"].Value.ToString().Trim();
string[] StrArray = this.dgvData.Rows[e.RowIndex].Cells["截止日期"].Value.ToString().Trim().Split('至');
this.dtpDateTimeStart.DateValue = StrArray[0].Trim();
this.dtpDateTimeEnd.DateValue = StrArray[1].Trim();
this.txtBaodiTask.Text = LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(this.dgvData.Rows[e.RowIndex].Cells["保底任务"].Value);
this.txtTargetTask.Text = LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(this.dgvData.Rows[e.RowIndex].Cells["目标任务"].Value);
this.txtSprintTask.Text = LYFZ.BLL.OtherCommonModel.RemoveLastExcessZero(this.dgvData.Rows[e.RowIndex].Cells["冲刺任务"].Value);
if (this.dgvData.Rows[e.RowIndex].Cells["是否显示"].Value.ToString().Trim() == "显示")
{
this.chkShow.Checked = true;
this.chkHide.Checked = false;
}
else
{
this.chkHide.Checked = true;
this.chkShow.Checked = false;
}
this.btnSaveed.Text = " 修 改";
}
}
}
///
/// 显示
///
///
///
void chkShow_Click(object sender, EventArgs e)
{
this.chkShow.Checked = true;
this.chkHide.Checked = false;
}
///
/// 隐藏
///
///
///
void chkHide_Click(object sender, EventArgs e)
{
this.chkHide.Checked = true;
this.chkShow.Checked = false;
}
///
/// 活动名称限制输入
///
///
///
void txtName_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; }
}
}
///
/// 保底限制输入
///
///
///
void txtBaodiTask_KeyPress(object sender, KeyPressEventArgs e)
{
if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar))
{ e.Handled = true; }
if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "[0-9]") && e.KeyChar != ' ' && e.KeyChar != '\b')
{ e.Handled = true; }
}
///
/// 目标限制输入
///
///
///
void txtTargetTask_KeyPress(object sender, KeyPressEventArgs e)
{
if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar))
{ e.Handled = true; }
if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "[0-9]") && e.KeyChar != ' ' && e.KeyChar != '\b')
{ e.Handled = true; }
}
///
/// 冲刺限制输入
///
///
///
void txtSprintTask_KeyPress(object sender, KeyPressEventArgs e)
{
if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar))
{ e.Handled = true; }
if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "[0-9]") && e.KeyChar != ' ' && e.KeyChar != '\b')
{ e.Handled = true; }
}
}
}