using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Data; using System.Linq; using BLL; using System.Text; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.HJGL.MaterialManage { public partial class UsingPlan : PageBase { #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); string lastPlan = @"SELECT p.UsingPlanId FROM dbo.Weld_UsingPlan p WHERE p.OrderDate 0) { for (int i = 0; i < dt.Rows.Count; i++) { string usingPlanId = dt.Rows[i]["UsingPlanId"].ToString(); BLL.UsingPlanService.UpdateIsCancel(usingPlanId, "超时未领用"); } } // 绑定表格 BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { string strSql = @"SELECT UsingPlan.UsingPlanId, UsingPlan.WeldId, UsingPlan.ProjectId, UsingPlan.UsePosition,team.TeamGroupName,UsingPlan.STE_Name, unit.UnitName AS UsingUnit,UsingPlan.Amount, UsingPlan.UsingManOne, UsingPlan.InPutDate, UsingPlan.OrderDate,UsingPlan.OrderTime, UsingPlan.CancelDate,UsingPlan.IsNeedConfirm, (CASE UsingPlan.IsSteelStru WHEN 1 THEN '是' WHEN 0 THEN '否' ELSE '' END) AS IsSteelStru, (CASE UsingPlan.IsSubmit WHEN 1 THEN '是' WHEN 0 THEN '否' ELSE '' END) AS IsSubmit, (CASE UsingPlan.IsCancel WHEN 1 THEN '是' WHEN 0 THEN '否' ELSE '' END) AS IsCancel, Weld.ConsumablesCode,Weld.ConsumablesName,Weld.SteelFormat,Weld.WeldUnit,case Weld.ConsumablesType when '1' then '焊丝' when '2' then '焊条' when '3' then '焊剂' else '' end as WeldTypeName, Project.ProjectCode,Welder.WED_Name+'('+Welder.WED_Code+')' AS UsingManOneName,UsingPlan.IsSubmit AS WelderAudit, (CASE WHEN UsingPlan.InPutMan IS NOT NULL THEN (CASE WHEN userInput.UserName IS NOT NULL THEN userInput.UserName ELSE welderInput.WED_Name END) ELSE '' END) AS InPutMan, --man.UserName AS InPutMan, ((SELECT ISNULL(SUM(ISNULL(us.Amount,0)),0) FROM dbo.Weld_UsingMat us WHERE us.UsingPlanId=UsingPlan.UsingPlanId)- (SELECT ISNULL(SUM(ISNULL(re.RecycleAmount,0)),0) FROM dbo.Weld_RecycleMat re WHERE re.UsingPlanId=UsingPlan.UsingPlanId)) AS UsedAmount,(CASE UsingPlan.IsFinish WHEN 1 THEN '是' WHEN 0 THEN '否' ELSE NULL END) AS IsFinish FROM dbo.Weld_UsingPlan AS UsingPlan LEFT JOIN dbo.Base_Consumables AS Weld ON Weld.ConsumablesId=UsingPlan.WeldId LEFT JOIN dbo.Base_Project AS Project ON Project.ProjectId =UsingPlan.ProjectId LEFT JOIN dbo.BS_Welder AS Welder ON Welder.WED_ID = UsingPlan.UsingManOne LEFT JOIN dbo.Base_Unit unit ON unit.UnitId=UsingPlan.UsingUnit LEFT JOIN dbo.Sys_User AS userInput ON userInput.UserId=UsingPlan.InPutMan LEFT JOIN dbo.BS_Welder AS welderInput ON welderInput.WED_ID=UsingPlan.InPutMan LEFT JOIN dbo.ProjectData_TeamGroup team ON team.TeamGroupId = UsingPlan.TeamGroupId WHERE 1=1 "; List listStr = new List(); if (this.rblUsed.SelectedValue == "0") // 未领用 { strSql += " AND IsCancel=0 AND (SELECT COUNT(*) FROM dbo.Weld_UsingMat u WHERE u.UsingPlanId=UsingPlan.UsingPlanId)=0 "; } else if (this.rblUsed.SelectedValue == "1") // 已领用 { strSql += " AND (SELECT COUNT(*) FROM dbo.Weld_UsingMat u WHERE u.UsingPlanId=UsingPlan.UsingPlanId)>0 "; } else // 已作废 { strSql += " AND IsCancel=1"; } strSql += " AND UsingPlan.ProjectId = @ProjectId"; listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); if (!string.IsNullOrEmpty(this.txtWeldCode.Text.Trim())) { strSql += " AND Weld.ConsumablesCode LIKE @ConsumablesCode"; listStr.Add(new SqlParameter("@ConsumablesCode", "%" + this.txtWeldCode.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtUsingMan.Text.Trim())) { strSql += " AND Welder.WED_Name LIKE @UsingMan"; listStr.Add(new SqlParameter("@UsingMan", "%" + this.txtUsingMan.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtInputMan.Text.Trim())) { strSql += " AND (CASE WHEN UsingPlan.InPutMan IS NOT NULL THEN (CASE WHEN userInput.UserName IS NOT NULL THEN userInput.UserName ELSE welderInput.WED_Name END) ELSE '' END) LIKE @InputMan"; listStr.Add(new SqlParameter("@InputMan", "%" + this.txtInputMan.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtUsingUnit.Text.Trim())) { strSql += " AND unit.UnitName LIKE @UnitName"; listStr.Add(new SqlParameter("@UnitName", "%" + this.txtUsingUnit.Text.Trim() + "%")); } //if (cbIsNeedConfirm.Checked) //{ // strSql += " AND UsingPlan.IsNeedConfirm = 1"; //} SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); Grid1.RecordCount = tb.Rows.Count; tb = GetFilteredTable(Grid1.FilteredData, tb); var table = this.GetPagedDataTable(Grid1, tb); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region 查询 /// ///查询 /// /// /// protected void drpProjectId_SelectedIndexChanged(object sender, EventArgs e) { BindGrid(); } protected void btnSelect_Click(object sender, EventArgs e) { BindGrid(); } protected void rblUsed_SelectedIndexChanged(object sender, EventArgs e) { BindGrid(); } #endregion protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "ConfirmFinish") { if (!string.IsNullOrEmpty(this.Grid1.SelectedRowID)) { var plan = BLL.UsingPlanService.GetUsingPlanById(this.Grid1.SelectedRowID); if (plan.IsFinish == null || plan.IsFinish == false) { string window = String.Format("../../FingerMark/FingerConfirm.aspx?keyId={0}&flag=2&grid=4", this.Grid1.SelectedRowID, "编辑 - "); PageContext.RegisterStartupScript(Window2.GetSaveStateReference(this.Grid1.SelectedRowID) + Window2.GetShowReference(window)); } else { ShowNotify("该领料计划已完成"); } } } } protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { DataRowView row = e.DataItem as DataRowView; //bool con = false; //if (row["IsNeedConfirm"].ToString()!="") //{ // con= Convert.ToBoolean(row["IsNeedConfirm"]); //} //if (con) //{ // e.RowCssClass = "color1"; //} //var plan = BLL.UsingPlanService.GetUsingPlanById(e.RowID); //if (plan != null) //{ // var welder = BLL.HJGL_PersonManageService.GetWelderByWenId(plan.InPutMan); // if (welder == null) // { // CheckBoxField cb = Grid1.FindColumn("WelderAudit") as CheckBoxField; // e.CellCssClasses[cb.ColumnIndex] = "hidethis"; // } //} } #region 表头过滤 protected void Grid1_FilterChange(object sender, EventArgs e) { BindGrid(); } #endregion #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #region 弹出编辑窗口关闭事件 /// /// 弹出编辑窗体关闭事件 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion #region 查询 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { BindGrid(); } #endregion #region 增加按钮 /// /// 增加按钮 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.CLGL_UsingPlanMenuId, BLL.Const.BtnAdd)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("UsingPlanEdit.aspx?UsingPlanId={0}", string.Empty, "编辑 - "))); } } #endregion #region 编辑 /// /// 双击Grid事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { this.EditData(); } /// /// 编辑按钮 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { this.EditData(); } /// /// 编辑数据方法 /// private void EditData() { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.CLGL_UsingPlanMenuId, BLL.Const.BtnModify)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID; if (!string.IsNullOrEmpty(id)) { var usedMat = BLL.UsingMatService.GetUsingMatByPlanId(id); if (usedMat == null) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("UsingPlanEdit.aspx?UsingPlanId={0}", id, "编辑 - "))); } else { Alert.ShowInTop("已有领用,不能修改!", MessageBoxIcon.Warning); return; } } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #endregion /// /// 复制按钮 /// /// /// protected void btnMenuCopy_Click(object sender, EventArgs e) { this.CopyData(); } /// /// 复制数据方法 /// private void CopyData() { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.CLGL_UsingPlanMenuId, BLL.Const.BtnModify)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID; if (!string.IsNullOrEmpty(id)) { var oldUsedPlan = BLL.UsingPlanService.GetUsingPlanById(id); Model.Weld_UsingPlan usingPlan = new Model.Weld_UsingPlan(); usingPlan.WeldId = oldUsedPlan.WeldId; usingPlan.ProjectId = oldUsedPlan.ProjectId; usingPlan.UsePosition = oldUsedPlan.UsePosition; usingPlan.UsingUnit = oldUsedPlan.UsingUnit; usingPlan.STE_ID = oldUsedPlan.STE_ID; usingPlan.STE_Name = oldUsedPlan.STE_Name; usingPlan.Amount = oldUsedPlan.Amount; usingPlan.UsingManOne = oldUsedPlan.UsingManOne; usingPlan.InPutDate = DateTime.Now; usingPlan.OrderDate = DateTime.Now; usingPlan.OrderTime = oldUsedPlan.OrderTime; usingPlan.TeamGroupId = oldUsedPlan.TeamGroupId; usingPlan.CancelDate = oldUsedPlan.CancelDate; usingPlan.IsCancel = oldUsedPlan.IsCancel; usingPlan.CancelResult = oldUsedPlan.CancelResult; usingPlan.IsSubmit = oldUsedPlan.IsSubmit; usingPlan.InPutMan = CurrUser.UserId; usingPlan.IsSteelStru = oldUsedPlan.IsSteelStru; usingPlan.Type = "1"; usingPlan.UsingPlanId = SQLHelper.GetNewID(typeof(Model.Weld_UsingPlan)); BLL.UsingPlanService.AddUsingPlan(usingPlan); BLL.LogService.AddSys_Log(this.CurrUser, usingPlan.InPutDate.ToString(), usingPlan.UsingPlanId, BLL.Const.CLGL_UsingPlanMenuId, "拷贝领料计划录入"); this.BindGrid(); Alert.ShowInTop("拷贝成功!", MessageBoxIcon.Success); } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } protected void btnConfirm_Click(object sender, EventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.CLGL_UsingPlanMenuId, BLL.Const.BtnAuditing)) { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID; if (!string.IsNullOrEmpty(id)) { var noComfirm = BLL.UsingPlanService.GetUsingPlanById(id); if (noComfirm.UsingUnit == CurrUser.UnitId) { if (noComfirm != null && noComfirm.IsNeedConfirm == true) { BLL.UsingPlanService.UpdateIsNeedConfirm(noComfirm.UsingPlanId, false); Alert.ShowInTop("已审核确认!", MessageBoxIcon.Success); BindGrid(); } else { Alert.ShowInTop("正常计划不用确认!", MessageBoxIcon.Warning); return; } } else { Alert.ShowInTop("非本单位数据,不能审核确认!", MessageBoxIcon.Warning); return; } } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } /// /// 焊工录入计划审核 /// /// /// protected void btnAudit_Click(object sender, EventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.CLGL_UsingPlanMenuId, BLL.Const.BtnAuditing)) { bool selectItem = false; CheckBoxField cb = Grid1.FindColumn("WelderAudit") as CheckBoxField; for (int i = 0; i < Grid1.Rows.Count; i++) { string planId = Grid1.DataKeys[i][0].ToString(); var plan = BLL.UsingPlanService.GetUsingPlanById(planId); //var welder = BLL.HJGL_PersonManageService.GetWelderByWenId(plan.InPutMan); //if (cb.GetCheckedState(i) == true && welder != null) //{ // BLL.UsingPlanService.UpdateIsSubmit(planId); // selectItem = true; //} } if (selectItem) { BindGrid(); ShowNotify("所选记录已审核!", MessageBoxIcon.Success); } else { Alert.ShowInTop("请选择要审核的记录!", MessageBoxIcon.Warning); return; } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #region 删除 /// /// 右键删除事件 /// /// /// //protected void btnMenuDelete_Click(object sender, EventArgs e) //{ // this.DeleteData(); //} /// /// 删除方法 /// private void DeleteData() { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.CLGL_UsingPlanMenuId, BLL.Const.BtnDelete)) { if (Grid1.SelectedRowIndexArray.Length > 0) { bool isShow = false; if (Grid1.SelectedRowIndexArray.Length == 1) { isShow = true; } foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var plan = BLL.UsingPlanService.GetUsingPlanById(rowID); if (this.judgementDelete(rowID, isShow)) { BLL.UsingPlanService.DeleteUsingPlanById(rowID); BLL.LogService.AddSys_Log(this.CurrUser, plan.InPutDate.ToString(), rowID, BLL.Const.CLGL_UsingPlanMenuId, "删除领料计划录入"); } } this.BindGrid(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } /// /// 判断是否可删除 /// /// /// /// private bool judgementDelete(string rowID, bool isShow) { string content = string.Empty; if (string.IsNullOrEmpty(content)) { return true; } else { if (isShow) { Alert.ShowInTop(content); } return false; } } #endregion #region 导入 /// /// 导入 /// /// /// protected void btnImport_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("UsingPlanImport.aspx", "导入 - "))); } #endregion #region 导出按钮 /// 导出按钮 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { Response.ClearContent(); string filename = Funs.GetNewFileName(); Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("领料计划" + filename, System.Text.Encoding.UTF8) + ".xls"); Response.ContentType = "application/excel"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Write(GetGridTableHtml(Grid1)); Response.End(); } #pragma warning disable CS0108 // “TrainRecord.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。 /// /// 导出方法 /// /// /// private string GetGridTableHtml(Grid grid) #pragma warning restore CS0108 // “TrainRecord.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。 { StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(""); sb.Append(""); this.Grid1.PageSize = 100000; BindGrid(); foreach (GridColumn column in grid.Columns) { if (column.ColumnIndex < 20) { sb.AppendFormat("", column.HeaderText); } } sb.Append(""); foreach (GridRow row in grid.Rows) { sb.Append(""); foreach (GridColumn column in grid.Columns) { if (column.ColumnIndex < 20) { string html = row.Values[column.ColumnIndex].ToString(); if (column.ColumnID == "tfNumber") { html = (row.FindControl("lblNumber") as AspNet.Label).Text; } //sb.AppendFormat("", html); sb.AppendFormat("", html); } } sb.Append(""); } sb.Append("
{0}
{0}{0}
"); return sb.ToString(); } #endregion } }