CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/Party/BasicInformation.aspx.cs

196 lines
8.5 KiB
C#

using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FineUIPro.Web.Party
{
public partial class BasicInformation : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetButtonPower();
string year = DateTime.Now.Year.ToString();
if (!string.IsNullOrEmpty(Request.Params["Year"]))
{
year = Request.Params["Year"];
}
var basicInformation = BLL.BasicInformationService.GetBasicInformationByYear(year);
if (basicInformation != null)
{
this.txtName.Text = basicInformation.Name;
if (basicInformation.StartDate != null)
{
this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", basicInformation.StartDate);
}
this.txtComponent.Text = basicInformation.Component;
this.txtPartyerNum.Text = basicInformation.PartyerNum;
this.txtPersonNum.Text = basicInformation.PersonNum;
this.txtPartyGroupNum.Text = basicInformation.PartyGroupNum;
var list = BLL.BasicInformationDetailService.GetBasicInformationDetailsById(basicInformation.BasicInformationId);
this.Grid1.DataSource = list;
this.Grid1.DataBind();
this.txtCommendation.Text = basicInformation.Commendation;
this.txtPunishment.Text = basicInformation.Punishment;
}
else
{
var oldBasicInformation = BLL.BasicInformationService.GetOldBasicInformation();
if (oldBasicInformation != null)
{
this.txtName.Text = oldBasicInformation.Name;
if (oldBasicInformation.StartDate != null)
{
this.txtStartDate.Text = string.Format("{0:yyyy-MM-dd}", oldBasicInformation.StartDate);
}
this.txtComponent.Text = oldBasicInformation.Component;
this.txtPartyerNum.Text = oldBasicInformation.PartyerNum;
this.txtPersonNum.Text = oldBasicInformation.PersonNum;
this.txtPartyGroupNum.Text = oldBasicInformation.PartyGroupNum;
var list = BLL.BasicInformationDetailService.GetBasicInformationDetailsById(oldBasicInformation.BasicInformationId);
this.Grid1.DataSource = list;
this.Grid1.DataBind();
}
}
}
}
#region
/// <summary>
/// 权限设置
/// </summary>
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.BasicInformationMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnNew.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnSave))
{
this.btnSave.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.Grid1.Columns[6].Hidden = false;
}
}
}
#endregion
#region
/// <summary>
/// 增加按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
var list = GetDetails();
Model.Party_BasicInformationDetail detail = new Model.Party_BasicInformationDetail();
detail.BasicInformationDetailId = SQLHelper.GetNewID();
list.Add(detail);
Grid1.DataSource = list;
Grid1.DataBind();
}
private List<Model.Party_BasicInformationDetail> GetDetails()
{
List<Model.Party_BasicInformationDetail> details = new List<Model.Party_BasicInformationDetail>();
foreach (JObject mergedRow in Grid1.GetMergedData())
{
JObject values = mergedRow.Value<JObject>("values");
int i = mergedRow.Value<int>("index");
Model.Party_BasicInformationDetail detail = new Model.Party_BasicInformationDetail();
detail.BasicInformationDetailId = Grid1.Rows[i].RowID;
detail.SortIndex = i;
detail.Name = values.Value<string>("Name");
detail.BirthDate = Funs.GetNewDateTime(values.Value<string>("BirthDate")+"-01");
detail.JoinPartyDate = Funs.GetNewDateTime(values.Value<string>("JoinPartyDate"));
detail.PartyPost = values.Value<string>("PartyPost");
detail.AdministrationPost = values.Value<string>("AdministrationPost");
detail.PartyPostJoinDate = Funs.GetNewDateTime(values.Value<string>("PartyPostJoinDate"));
details.Add(detail);
}
return details;
}
#endregion
#region
/// <summary>
/// Grid行点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
string basicInformationDetailId = Grid1.DataKeys[e.RowIndex][0].ToString();
var list = GetDetails();
if (e.CommandName == "del")//删除
{
var detail = list.FirstOrDefault(x => x.BasicInformationDetailId == basicInformationDetailId);
if (detail != null)
{
list.Remove(detail);
}
this.Grid1.DataSource = list;
this.Grid1.DataBind();
}
}
#endregion
protected void btnSave_Click(object sender, EventArgs e)
{
Model.Party_BasicInformation basicInformation = new Model.Party_BasicInformation();
string year = DateTime.Now.Year.ToString();
if (!string.IsNullOrEmpty(Request.Params["Year"]))
{
year = Request.Params["Year"];
}
basicInformation.Year = Funs.GetNewInt(year);
basicInformation.Name = txtName.Text.Trim();
basicInformation.StartDate = Funs.GetNewDateTime(this.txtStartDate.Text.Trim());
basicInformation.Component = txtComponent.Text.Trim();
basicInformation.PartyerNum = txtPartyerNum.Text.Trim();
basicInformation.PersonNum = txtPersonNum.Text.Trim();
basicInformation.PartyGroupNum = txtPartyGroupNum.Text.Trim();
basicInformation.Commendation = txtCommendation.Text.Trim();
basicInformation.Punishment = txtPunishment.Text.Trim();
var oldBasicInformation = BLL.BasicInformationService.GetBasicInformationByYear(year);
if (oldBasicInformation!=null)
{
basicInformation.BasicInformationId = oldBasicInformation.BasicInformationId;
BasicInformationService.UpdateBasicInformation(basicInformation);
}
else
{
basicInformation.BasicInformationId = SQLHelper.GetNewID();
BasicInformationService.AddBasicInformation(basicInformation);
}
BLL.BasicInformationDetailService.DeleteBasicInformationDetailsById(basicInformation.BasicInformationId);
var details = GetDetails();
foreach (var item in details)
{
item.BasicInformationId = basicInformation.BasicInformationId;
BLL.BasicInformationDetailService.AddBasicInformationDetail(item);
}
ShowNotify("保存成功!", MessageBoxIcon.Success);
}
protected void txtBirthDate_TextChanged(object sender, EventArgs e)
{
DatePicker d = sender as DatePicker;
if (!string.IsNullOrEmpty(d.Text))
{
d.Text = d.Text.Substring(0,7);
}
}
}
}