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 加载 /// /// 页面加载 /// /// /// 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 附件上传 /// /// 附件上传 /// /// /// 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 保存 /// /// 保存按钮 /// /// /// 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 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集合 /// /// 检查并保存集合 /// private List jerqueSaveList() { List details = new List(); var list = BLL.DriverPrepareSchemePlanItemService.GetModelList(); foreach (JObject mergedRow in Grid1.GetMergedData()) { JObject values = mergedRow.Value("values"); int i = mergedRow.Value("index"); Model.DriverPrepare_SchemePlanItem detail = new Model.DriverPrepare_SchemePlanItem(); detail.SchemePlanItemId = this.Grid1.Rows[i].RowID; detail.SolutionName = values.Value("SolutionName"); var item = list.FirstOrDefault(x => x.SolutionName == detail.SolutionName); if (item != null) { detail.SortIndex = item.SortIndex; } details.Add(detail); } return details; } #endregion #region 搜索 /// /// 搜索 /// /// /// 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 关闭弹出窗口 /// /// 关闭弹出窗口 /// /// /// 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 /// /// 选择事件 /// /// /// 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("status"); JObject values = mergedRow.Value("values"); names += values.Value("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)); } } }