CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/TestRun/DriverPrepare/SchemePlanEdit.aspx.cs

220 lines
8.8 KiB
C#

using BLL;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
namespace FineUIPro.Web.TestRun.DriverPrepare
{
public partial class SchemePlanEdit : PageBase
{
#region
/// <summary>
/// 页面加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BLL.UserService.InitUserDropDownList(this.drpCompileMan, this.CurrUser.LoginProjectId, true);
string id = Request.Params["id"];
if (!string.IsNullOrEmpty(id))
{
Model.DriverPrepare_SchemePlan data = BLL.DriverPrepareSchemePlanService.GetDriverPlanById(id);
if (data != null)
{
this.hdId.Text = id;
this.txtCode.Text = data.SchemePlanCode;
this.txtName.Text = data.SchemePlanName;
if (!string.IsNullOrEmpty(data.CompileMan))
{
this.drpCompileMan.SelectedValue = data.CompileMan;
}
this.txtCompileDate.Text = data.CompileDate.HasValue ? string.Format("{0:yyyy-MM-dd}", data.CompileDate) : "";
this.txtRemark.Text = data.Remark;
}
}
else
{
this.txtCode.Text = "001";
this.txtName.Text = "开车方案编制计划";
this.drpCompileMan.SelectedValue = this.CurrUser.UserId;
this.txtCompileDate.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
}
}
}
#endregion
#region
/// <summary>
/// 附件上传
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAttach_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.hdId.Text)) //新增记录
{
this.hdId.Text = SQLHelper.GetNewID(typeof(Model.DriverPrepare_SchemePlan));
}
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/TestRun/DriverPrepare/SchemePlan&menuId={1}", this.hdId.Text, BLL.Const.SchemePlanMenuId)));
}
#endregion
#region
/// <summary>
/// 保存按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSave_Click(object sender, EventArgs e)
{
string id = Request.Params["id"];
Model.DriverPrepare_SchemePlan newData = new Model.DriverPrepare_SchemePlan();
newData.SchemePlanCode = this.txtCode.Text.Trim();
newData.SchemePlanName = this.txtName.Text.Trim();
if (this.drpCompileMan.SelectedValue != BLL.Const._Null)
{
newData.CompileMan = this.drpCompileMan.SelectedValue;
}
newData.CompileDate = Funs.GetNewDateTime(this.txtCompileDate.Text.Trim());
newData.Remark = this.txtRemark.Text.Trim();
newData.ProjectId = this.CurrUser.LoginProjectId;
if (!string.IsNullOrEmpty(id))
{
newData.SchemePlanId = id;
BLL.DriverPrepareSchemePlanService.UpdateDriverPrepareDriverPlan(newData);
}
else
{
if (!string.IsNullOrEmpty(this.hdId.Text))
{
newData.SchemePlanId = this.hdId.Text.Trim();
}
else
{
newData.SchemePlanId = SQLHelper.GetNewID(typeof(Model.DriverPrepare_SchemePlan));
this.hdId.Text = newData.SchemePlanId;
}
BLL.DriverPrepareSchemePlanService.AddDriverPrepareDriverPlan(newData);
}
ShowNotify("保存成功!", MessageBoxIcon.Success);
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
#endregion
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
string itemId = Grid1.DataKeys[e.RowIndex][0].ToString();
List<Model.DriverPrepare_SchemePlanItem> details = jerqueSaveList();
if (e.CommandName == "delete")
{
foreach (Model.DriverPrepare_SchemePlanItem detail in details)
{
if (detail.SchemePlanItemId == itemId)
{
details.Remove(detail);
break;
}
}
Grid1.DataSource = details;
Grid1.DataBind();
}
}
#region Grid集合
/// <summary>
/// 检查并保存集合
/// </summary>
private List<Model.DriverPrepare_SchemePlanItem> jerqueSaveList()
{
List<Model.DriverPrepare_SchemePlanItem> details = new List<Model.DriverPrepare_SchemePlanItem>();
var list = BLL.DriverPrepareSchemePlanItemService.GetModelList();
foreach (JObject mergedRow in Grid1.GetMergedData())
{
JObject values = mergedRow.Value<JObject>("values");
int i = mergedRow.Value<int>("index");
Model.DriverPrepare_SchemePlanItem detail = new Model.DriverPrepare_SchemePlanItem();
detail.SchemePlanItemId = this.Grid1.Rows[i].RowID;
detail.SolutionName = values.Value<string>("SolutionName");
var item = list.FirstOrDefault(x => x.SolutionName == detail.SolutionName);
if (item != null)
{
detail.SortIndex = item.SortIndex;
}
details.Add(detail);
}
return details;
}
#endregion
#region
/// <summary>
/// 搜索
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
string window = String.Format("SchemePlanItemAdd.aspx", "新增 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(hdItemsString.ClientID) + Window1.GetShowReference(window));
}
#endregion
#region
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
if (!string.IsNullOrEmpty(hdItemsString.Text))
{
string[] ids = hdItemsString.Text.Split(',');
int i = 1;
var details = jerqueSaveList();
foreach (var id in ids)
{
var oldDetail = details.FirstOrDefault(x => x.SolutionName == id);
if (oldDetail == null) //添加集合没有的新纪录
{
Model.DriverPrepare_SchemePlanItem detail = new Model.DriverPrepare_SchemePlanItem();
detail.SchemePlanItemId = SQLHelper.GetNewID();
detail.SolutionName = id;
details.Add(detail);
}
i++;
}
this.Grid1.DataSource = details;
this.Grid1.DataBind();
}
}
#endregion
/// <summary>
/// 选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSelect_Click(object sender, EventArgs e)
{
JArray mergedData = Grid1.GetMergedData();
string names = string.Empty;
foreach (JObject mergedRow in mergedData)
{
string status = mergedRow.Value<string>("status");
JObject values = mergedRow.Value<JObject>("values");
names += values.Value<string>("SolutionName").ToString() + ",";
}
if (!string.IsNullOrEmpty(names))
{
hdItemsString.Text = names.Substring(0, names.Length - 1);
}
string window = String.Format("SchemePlanItemSelect.aspx?names={0}", hdItemsString.Text, "选择 - ");
PageContext.RegisterStartupScript(Window1.GetSaveStateReference(this.hdItemsString.ClientID) + Window1.GetShowReference(window));
}
}
}