using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Text; using AspNet = System.Web.UI.WebControls; namespace FineUIPro.Web.HJGL.PreDesign { public partial class PackagingManage : PageBase { #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 BindGrid(); } } /// /// 绑定数据 /// private void BindGrid() { // string strSql = @"select pack.PackagingManageId, // pack.PackagingCode, // com.PipelineComponentCode, // unit.UnitWorkName, // pipe.PlanStartDate, // pack.ProjectId, // pack.StackingPosition, // pack.State, // pack.ContactName, // pack.ContactPhone, //pack.ReceiveDate, //person.PersonName // from HJGL_PackagingManage as pack // left join HJGL_Pipeline_Component com on com.PipelineComponentId=pack.PipelineComponentId // left join HJGL_Pipeline pipe on pipe.PipelineId =com.PipelineId // left join WBS_UnitWork unit on pipe.UnitWorkId=unit.UnitWorkId // left join Person_Persons person on pack.ReceiveMan=person.PersonId // WHERE pack.ProjectId = @ProjectId "; // List listStr = new List(); // listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); // if (!string.IsNullOrEmpty(this.txtPackagingCode.Text.Trim())) // { // strSql += " AND pack.PackagingCode LIKE @PackagingCode"; // listStr.Add(new SqlParameter("@PackagingCode", "%" + this.txtPackagingCode.Text.Trim() + "%")); // } // 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(); var list= BLL.HJGL_PackagingmanageService.GetPackagingManageList(this.CurrUser.LoginProjectId, this.txtPackagingCode.Text.Trim()); Grid1.RecordCount = list.Count; Grid1.DataSource = list; Grid1.DataBind(); } #endregion #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 protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "cmd_detail" ) { string id = Grid1.SelectedRowID; string url = "PackagingManageView.aspx?PackagingManageId={0}"; PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format(url, id, "操作 - "))); } else if (e.CommandName== "cmd_print") { string Id = this.Grid1.SelectedRowID; Pring(Id); } } #region 增加按钮 /// /// 增加按钮 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.HJGL_PackagingManageMenuId, BLL.Const.BtnAdd)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PackagingManageEdit.aspx?PackagingManageId={0}", string.Empty, "编辑 - "))); } } #endregion #region 编辑 /// /// 双击Grid事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { this.EditData(); } /// /// 查看按钮 /// /// /// protected void btnMenuView_Click(object sender, EventArgs e) { string id = Grid1.SelectedRowID; string url = "PackagingManageView.aspx?PackagingManageId={0}"; PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format(url, id, "操作 - "))); } /// /// 编辑按钮 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { this.EditData(); } /// /// 编辑数据方法 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRowID; string url = string.Empty; var wpq = BLL.HJGL_PackagingmanageService.GetHJGL_PackagingManageById(id); if (wpq != null) { url = "PackagingManageEdit.aspx?PackagingManageId={0}"; PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format(url, id, "操作 - "))); } } #endregion #region 删除 /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { this.DeleteData(); } /// /// 删除方法 /// private void DeleteData() { if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.HJGL_PackagingManageMenuId, 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(); if (this.judgementDelete(rowID, isShow)) { BLL.HJGL_PackagingmanageService.DeleteHJGL_PackagingManageById(rowID); //BLL.Sys_LogService.AddLog(BLL.Const.System_2, this.CurrUser.LoginProjectId, this.CurrUser.PersonId, "删除焊接工艺评定台账"); } } 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 btnPrint_Click(object sender, EventArgs e) { string Id = this.Grid1.SelectedRowID; Pring(Id); } protected void btnOutPrint_Click(object sender, EventArgs e) { string Id = this.Grid1.SelectedRowID; var model = HJGL_PackagingmanageService.GetHJGL_PackagingManageById(Id); var PipelineComponent = model.PipelineComponentId.Split(','); foreach (var item in PipelineComponent) { HJGL_PipelineComponentService.UpdateOutState(item, model.PackagingCode); } HJGL_PackagingmanageService.PutOutOrder(Id); Pring(Id); } private void Pring(string Id) { BLL.FastReportService.ResetData(); if (string.IsNullOrEmpty(Id)) { ShowNotify("请选择要打印的项", MessageBoxIcon.Warning); return; } DataTable tb = BLL.HJGL_PackagingmanageService.GetPackagingDetailById(Id); var model = HJGL_PackagingmanageService.GetHJGL_PackagingManageById(Id); var dtTable = tb.AsEnumerable().OrderBy(o => o["PlanStartDate"]).CopyToDataTable(); string PlanStartDate = ""; if (dtTable.Rows != null && dtTable.Rows.Count > 0) { PlanStartDate = dtTable.Rows[0]["PlanStartDate"].ToString(); } Dictionary keyValuePairs = new Dictionary(); keyValuePairs.Add("ProjectName", ProjectService.GetProjectNameByProjectId(this.CurrUser.LoginProjectId)); keyValuePairs.Add("PackagingCode", model.PackagingCode); keyValuePairs.Add("PlanStartDate", PlanStartDate); keyValuePairs.Add("StackingPosition", model.StackingPosition); keyValuePairs.Add("ContactName", model.ContactName + "| " + model.ContactPhone); keyValuePairs.Add("ID", "PackagingManage$" + model.PackagingManageId); DataRow dataRow = tb.NewRow(); dataRow["num"] = "合计:" + tb.Rows.Count; tb.Rows.Add(dataRow); if (tb != null) { tb.TableName = "Data"; } BLL.FastReportService.AddFastreportTable(tb); BLL.FastReportService.AddFastreportParameter(keyValuePairs); string initTemplatePath = ""; string rootPath = Server.MapPath("~/"); initTemplatePath = "File\\Fastreport\\装箱单.frx"; if (File.Exists(rootPath + initTemplatePath)) { PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("~/Controls/Fastreport.aspx?ReportPath={0}", rootPath + initTemplatePath))); } } #endregion #region 导出按钮 /// 导出按钮 /// /// /// protected void btnExport_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; this.Grid1.PageSize = 500; this.BindGrid(); Response.Write(GetGridTableHtml(Grid1)); Response.End(); } /// /// 导出方法 /// /// /// private string GetGridTableHtml(Grid grid) { StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(""); sb.Append(""); foreach (GridColumn column in grid.Columns) { sb.AppendFormat("", column.HeaderText); } sb.Append(""); foreach (GridRow row in grid.Rows) { sb.Append(""); foreach (GridColumn column in grid.Columns) { string html = row.Values[column.ColumnIndex].ToString(); if (column.ColumnID == "tfNumber") { html = (row.FindControl("lblNumber") as AspNet.Label).Text; } sb.AppendFormat("", html); } sb.Append(""); } sb.Append("
{0}
{0}
"); return sb.ToString(); } #endregion /// /// 把状态转换代号为文字形式 /// /// /// protected string ConvertState(object state) { if (state != null) { string txt= HJGL_PackagingmanageService.GetState().FirstOrDefault(x => x.Value == state.ToString()).Text; return txt; } return ""; } // //获取办理人姓名 // // // protected string ConvertMan(object ApproveManId) { if (ApproveManId != null) { var user = BLL.Person_PersonsService.GetPerson_PersonsById(ApproveManId.ToString()); if (user != null) { return user.PersonName; } } return ""; } } }