339 lines
13 KiB
C#
339 lines
13 KiB
C#
using BLL;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
namespace FineUIPro.Web.common.ProjectSet
|
|
{
|
|
public partial class EditOrganization : PageBase
|
|
{
|
|
/// <summary>
|
|
///单位主键
|
|
/// </summary>
|
|
public string UnitId
|
|
{
|
|
get
|
|
{
|
|
return (string)ViewState["UnitId"];
|
|
}
|
|
set
|
|
{
|
|
ViewState["UnitId"] = value;
|
|
}
|
|
}
|
|
|
|
private bool AppendToEnd = false;
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
string projectUnitId = Request.Params["projectUnitId"];
|
|
//string projectId = Request.Params["projectId"];
|
|
|
|
Model.Project_Unit pUnit = BLL.Project_UnitService.GetProject_UnitByProjectUnitId(projectUnitId);
|
|
if (pUnit != null)
|
|
{
|
|
UnitId = pUnit.UnitId;
|
|
var unit = BLL.Base_UnitService.GetUnit(UnitId);
|
|
if (unit.IsSubUnit == true)
|
|
{
|
|
this.drpUnitType.DataTextField = "Text";
|
|
drpUnitType.DataValueField = "Value";
|
|
drpUnitType.DataSource = BLL.DropListService.UnitTypeSubSearchList();
|
|
drpUnitType.DataBind();
|
|
}
|
|
else
|
|
{
|
|
this.drpUnitType.DataTextField = "Text";
|
|
drpUnitType.DataValueField = "Value";
|
|
drpUnitType.DataSource = BLL.DropListService.UnitTypeNotSubSearchList();
|
|
drpUnitType.DataBind();
|
|
}
|
|
if (pUnit.InTime != null)
|
|
{
|
|
txtInTime.Text = string.Format("{0:yyyy-MM-dd}", pUnit.InTime);
|
|
}
|
|
if (pUnit.OutTime != null)
|
|
{
|
|
this.txtOutTime.Text = string.Format("{0:yyyy-MM-dd}", pUnit.OutTime);
|
|
}
|
|
this.txtPhone.Text = pUnit.Phone;
|
|
if (pUnit.ProjectRange != null)
|
|
{
|
|
this.txtProjectRange.Text = pUnit.ProjectRange.Trim();
|
|
}
|
|
}
|
|
|
|
// 删除选中单元格的客户端脚本
|
|
string deleteScript = GetDeleteScript();
|
|
// 新增数据初始值
|
|
JObject defaultObj = new JObject();
|
|
defaultObj.Add("Post", "");
|
|
defaultObj.Add("CardNo", "");
|
|
defaultObj.Add("PersonName", "");
|
|
defaultObj.Add("CellPhone", "");
|
|
defaultObj.Add("Telephone", "");
|
|
defaultObj.Add("Email", "");
|
|
defaultObj.Add("Delete", String.Format("<a href=\"javascript:;\" onclick=\"{0}\"><img src=\"{1}\"/></a>", deleteScript, IconHelper.GetResolvedIconUrl(Icon.Delete)));
|
|
|
|
// 在第一行新增一条数据
|
|
btnNew.OnClientClick = Grid1.GetAddNewRecordReference(defaultObj, AppendToEnd);
|
|
|
|
// 删除选中行按钮
|
|
btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("请至少选择一项!") + deleteScript;
|
|
|
|
|
|
// 绑定表格
|
|
BindGrid();
|
|
|
|
// 删除选中单元格的客户端脚本
|
|
string deleteScript2 = GetDeleteScript2();
|
|
// 新增数据初始值
|
|
JObject defaultObj2 = new JObject();
|
|
defaultObj2.Add("TeamGroupCode", "");
|
|
defaultObj2.Add("TeamGroupName", "");
|
|
defaultObj2.Add("Remark", "");
|
|
defaultObj2.Add("Delete", String.Format("<a href=\"javascript:;\" onclick=\"{0}\"><img src=\"{1}\"/></a>", deleteScript2, IconHelper.GetResolvedIconUrl(Icon.Delete)));
|
|
|
|
// 在第一行新增一条数据
|
|
btnNew2.OnClientClick = Grid2.GetAddNewRecordReference(defaultObj2, AppendToEnd);
|
|
|
|
// 删除选中行按钮
|
|
btnDelete2.OnClientClick = Grid2.GetNoSelectionAlertReference("请至少选择一项!") + deleteScript2;
|
|
|
|
|
|
// 绑定表格
|
|
BindGrid2();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定数据
|
|
/// </summary>
|
|
private void BindGrid()
|
|
{
|
|
string strSql = @"select * from dbo.Base_Organization where ProjectId=@ProjectId and UnitId=@UnitId order by Post";
|
|
|
|
SqlParameter[] parameter = new SqlParameter[]
|
|
{
|
|
new SqlParameter("@ProjectId",Request.Params["projectId"]),
|
|
new SqlParameter("@UnitId",this.UnitId),
|
|
};
|
|
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
|
|
Grid1.DataSource = tb;
|
|
Grid1.DataBind();
|
|
}
|
|
|
|
private void BindGrid2()
|
|
{
|
|
string strSql = @"select * from dbo.Base_TeamGroup where ProjectId=@ProjectId and UnitId=@UnitId order by TeamGroupCode";
|
|
|
|
SqlParameter[] parameter = new SqlParameter[]
|
|
{
|
|
new SqlParameter("@ProjectId",Request.Params["projectId"]),
|
|
new SqlParameter("@UnitId",this.UnitId),
|
|
};
|
|
|
|
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|
|
|
Grid2.DataSource = tb;
|
|
Grid2.DataBind();
|
|
}
|
|
|
|
protected void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.ProjectUnitMenuId, Const.BtnSave))
|
|
{
|
|
if (!string.IsNullOrEmpty(this.txtPhone.Text.Trim()))
|
|
{
|
|
if (this.txtPhone.Text.Trim().Length > 15)
|
|
{
|
|
ShowNotify("电话不能超过15位",MessageBoxIcon.Warning);
|
|
return;
|
|
}
|
|
}
|
|
string projectUnitId = Request.Params["projectUnitId"];
|
|
// 项目单位信息
|
|
Model.Project_Unit pUnit = BLL.Project_UnitService.GetProject_UnitByProjectUnitId(projectUnitId);
|
|
if (!string.IsNullOrEmpty(this.txtInTime.Text))
|
|
{
|
|
pUnit.InTime = Convert.ToDateTime(this.txtInTime.Text);
|
|
}
|
|
else
|
|
{
|
|
pUnit.InTime = null;
|
|
}
|
|
if (!string.IsNullOrEmpty(this.txtOutTime.Text))
|
|
{
|
|
pUnit.OutTime = Convert.ToDateTime(this.txtOutTime.Text);
|
|
}
|
|
else
|
|
{
|
|
pUnit.OutTime = null;
|
|
}
|
|
pUnit.Phone = this.txtPhone.Text.Trim();
|
|
if (!string.IsNullOrEmpty(this.txtProjectRange.Text))
|
|
{
|
|
pUnit.ProjectRange = this.txtProjectRange.Text.Trim();
|
|
}
|
|
else
|
|
{
|
|
pUnit.ProjectRange = null;
|
|
}
|
|
pUnit.UnitType = drpUnitType.SelectedValue;
|
|
|
|
BLL.Project_UnitService.UpdateProject_Unit(pUnit);
|
|
|
|
// 项目单位组织机构
|
|
//if (Grid1.GetModifiedData().Count == 0 && Grid2.GetModifiedData().Count == 0)
|
|
//{
|
|
// ShowNotify("数据没有变化!");
|
|
// return;
|
|
//}
|
|
if (Grid1.GetDeletedList().Count() > 0)
|
|
{
|
|
foreach (int i in Grid1.GetDeletedList())
|
|
{
|
|
string rowID = Grid1.DataKeys[i][0].ToString();
|
|
BLL.Base_OrganizationService.DeleteOrganization(rowID);
|
|
}
|
|
}
|
|
if (Grid1.GetModifiedData().Count > 0)
|
|
{
|
|
JArray mergedData = Grid1.GetMergedData();
|
|
foreach (JObject mergedRow in mergedData)
|
|
{
|
|
string status = mergedRow.Value<string>("status");
|
|
JObject values = mergedRow.Value<JObject>("values");
|
|
Model.Base_Organization org = new Model.Base_Organization();
|
|
|
|
org.ProjectId = Request.Params["projectId"];
|
|
org.UnitId = this.UnitId;
|
|
org.Post = values.Value<string>("Post");
|
|
org.CardNo = values.Value<string>("CardNo");
|
|
org.PersonName = values.Value<string>("PersonName");
|
|
org.Telephone = values.Value<string>("Telephone");
|
|
org.CellPhone = values.Value<string>("CellPhone");
|
|
org.Email = values.Value<string>("Email");
|
|
|
|
if (status == "newadded")
|
|
{
|
|
BLL.Base_OrganizationService.AddOrganization(org);
|
|
}
|
|
else
|
|
{
|
|
org.OrganizationId = mergedRow.Value<string>("id");
|
|
BLL.Base_OrganizationService.UpdateOrganization(org);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
if (Grid2.GetDeletedList().Count() > 0)
|
|
{
|
|
foreach (int i in Grid2.GetDeletedList())
|
|
{
|
|
string rowID = Grid2.DataKeys[i][0].ToString();
|
|
BLL.Base_TeamGroupService.DeleteTeamGroup(rowID);
|
|
}
|
|
}
|
|
|
|
if (Grid2.GetModifiedData().Count > 0)
|
|
{
|
|
JArray teamGroupData = Grid2.GetMergedData();
|
|
foreach (JObject teamGroupRow in teamGroupData)
|
|
{
|
|
string status = teamGroupRow.Value<string>("status");
|
|
JObject values = teamGroupRow.Value<JObject>("values");
|
|
Model.Base_TeamGroup team = new Model.Base_TeamGroup();
|
|
|
|
team.ProjectId = Request.Params["projectId"];
|
|
team.UnitId = this.UnitId;
|
|
team.TeamGroupCode = values.Value<string>("TeamGroupCode");
|
|
team.TeamGroupName = values.Value<string>("TeamGroupName");
|
|
team.Remark = values.Value<string>("Remark");
|
|
|
|
if (status == "newadded")
|
|
{
|
|
BLL.Base_TeamGroupService.AddTeamGroup(team);
|
|
}
|
|
else
|
|
{
|
|
team.TeamGroupId = teamGroupRow.Value<string>("id");
|
|
BLL.Base_TeamGroupService.UpdateTeamGroup(team);
|
|
}
|
|
|
|
}
|
|
}
|
|
BindGrid();
|
|
BindGrid2();
|
|
|
|
ShowNotify("数据提交成功!(表格数据已重新绑定)");
|
|
}
|
|
else
|
|
{
|
|
ShowNotify("您没有这个权限,请与管理员联系!");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 排序
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
|
|
{
|
|
Grid1.SortDirection = e.SortDirection;
|
|
Grid1.SortField = e.SortField;
|
|
BindGrid();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 排序
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Grid2_Sort(object sender, FineUIPro.GridSortEventArgs e)
|
|
{
|
|
Grid2.SortDirection = e.SortDirection;
|
|
Grid2.SortField = e.SortField;
|
|
BindGrid2();
|
|
}
|
|
|
|
// 删除选中行的脚本
|
|
private string GetDeleteScript()
|
|
{
|
|
return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question, Grid1.GetDeleteSelectedRowsReference(), String.Empty);
|
|
}
|
|
|
|
private string GetDeleteScript2()
|
|
{
|
|
return Confirm.GetShowReference("删除选中行?", String.Empty, MessageBoxIcon.Question, Grid2.GetDeleteSelectedRowsReference(), String.Empty);
|
|
}
|
|
|
|
protected void Grid1_PreDataBound(object sender, EventArgs e)
|
|
{
|
|
// 设置LinkButtonField的点击客户端事件
|
|
LinkButtonField deleteField = Grid1.FindColumn("Delete") as LinkButtonField;
|
|
deleteField.OnClientClick = GetDeleteScript();
|
|
}
|
|
|
|
protected void Grid2_PreDataBound(object sender, EventArgs e)
|
|
{
|
|
// 设置LinkButtonField的点击客户端事件
|
|
LinkButtonField deleteField = Grid2.FindColumn("Delete") as LinkButtonField;
|
|
deleteField.OnClientClick = GetDeleteScript2();
|
|
}
|
|
|
|
}
|
|
} |