using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
namespace FineUIPro.Web.TestRun.DriverPrepare
{
public partial class SchemePlanItemSelect : PageBase
{
#region 加载页面
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindGrid();
}
}
#endregion
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#region 数据绑定
///
/// 数据绑定
///
private void BindGrid()
{
string strSql = @"SELECT *
FROM dbo.DriverPrepare_SchemePlanItem
WHERE SchemePlanId=@SchemePlanId";
List listStr = new List();
listStr.Add(new SqlParameter("@SchemePlanId", this.rblType.SelectedValue));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
Model.DriverPrepare_SchemePlan plan = BLL.DriverPrepareSchemePlanService.GetDriverPlanByProjectId(this.CurrUser.LoginProjectId);
if (plan != null)
{
var items = BLL.DriverPrepareSchemePlanItemService.GetSchemePlanItemByschemePlanId(plan.SchemePlanId);
List nameLists = items.Select(x => x.SolutionName).ToList();
List ids = new List();
foreach (GridRow row in Grid1.Rows)
{
if (nameLists.Contains(row.DataKeys[1].ToString()))
{
ids.Add(row.RowID);
}
}
this.Grid1.SelectedRowIDArray = ids.ToArray();
}
}
#endregion
#region 排序
///
/// 排序
///
///
///
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
this.BindGrid();
}
#endregion
#region 确定按钮
///
/// 确定按钮
///
///
///
protected void btnAccept_Click(object sender, EventArgs e)
{
string schemePlanId = Request.Params["SchemePlanId"];
Model.DriverPrepare_SchemePlan newData = new Model.DriverPrepare_SchemePlan();
newData.SchemePlanCode = "001";
newData.SchemePlanName = "开车方案编制计划";
newData.CompileMan = this.CurrUser.UserId;
newData.CompileDate = DateTime.Now;
newData.ProjectId = this.CurrUser.LoginProjectId;
if (!string.IsNullOrEmpty(schemePlanId))
{
newData.SchemePlanId = schemePlanId;
BLL.DriverPrepareSchemePlanService.UpdateDriverPrepareDriverPlan(newData);
}
else
{
newData.SchemePlanId = SQLHelper.GetNewID(typeof(Model.DriverPrepare_SchemePlan));
BLL.DriverPrepareSchemePlanService.AddDriverPrepareDriverPlan(newData);
}
var items = BLL.DriverPrepareSchemePlanItemService.GetSchemePlanItemByschemePlanId(newData.SchemePlanId);
List nameLists = items.Select(x => x.SolutionName).ToList();
string[] selectRowId = Grid1.SelectedRowIDArray;
foreach (GridRow row in Grid1.Rows)
{
if (selectRowId.Contains(row.RowID) && !nameLists.Contains(row.DataKeys[1].ToString()))
{
Model.DriverPrepare_SchemePlanItem newItem = new Model.DriverPrepare_SchemePlanItem();
newItem.SchemePlanItemId = SQLHelper.GetNewID();
newItem.SchemePlanId = newData.SchemePlanId;
newItem.SolutionName = row.DataKeys[1].ToString();
newItem.SortIndex = row.RowIndex + 1;
BLL.DriverPrepareSchemePlanItemService.AddSchemePlanItem(newItem);
}
}
PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
}
#endregion
}
}