using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; using System.Text; using AspNet = System.Web.UI.WebControls; using BLL; namespace FineUIPro.Web.WeldMat.BaseInfo { public partial class Supplier : PageBase { #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 BindGrid(); } } #endregion #region 绑定数据 /// /// 绑定数据 /// private void BindGrid() { string strSql = @"SELECT SupplierId, SupplierCode, SupplierName, ContactMan, ContactPhone" + @" FROM Weld_Supplier WHERE 1=1 "; List listStr = new List(); if (!string.IsNullOrEmpty(this.txtCode.Text.Trim())) { strSql += " AND SupplierCode LIKE @SupplierCode"; listStr.Add(new SqlParameter("@SupplierCode", "%" + this.txtCode.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtName.Text.Trim())) { strSql += " AND SupplierName LIKE @SupplierName"; listStr.Add(new SqlParameter("@SupplierName", "%" + this.txtName.Text.Trim() + "%")); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); // 2.获取当前分页数据 //var table = this.GetPagedDataTable(Grid1, tb1); 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 Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } /// /// 分页下拉选择 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// /// /// /// protected void Grid1_FilterChange(object sender, EventArgs e) { BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 删除事件 /// /// 删除 /// /// /// protected void btnDelete_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.CLGL_SupplierMenuId, Const.BtnDelete)) { if (judgementDelete(hfFormID.Text, true)) { BLL.SupplierService.DeleteSupplierById(hfFormID.Text); BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除供应商信息"); // 重新绑定表格,并模拟点击[新增按钮] BindGrid(); PageContext.RegisterStartupScript("onNewButtonClick();"); } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.CLGL_SupplierMenuId, Const.BtnDelete)) { this.DeleteData(); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } /// /// 删除方法 /// private void DeleteData() { if (Grid1.SelectedRowIndexArray.Length > 0) { bool isShow = true; if (Grid1.SelectedRowIndexArray.Length > 1) { isShow = false; } foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); if (judgementDelete(rowID, isShow)) { BLL.SupplierService.DeleteSupplierById(rowID); BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除供应商信息"); ShowNotify("删除完成!", MessageBoxIcon.Success); } } BindGrid(); PageContext.RegisterStartupScript("onNewButtonClick();"); } } #endregion #region 编辑 /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.CLGL_SupplierMenuId, Const.BtnModify)) { this.EditData(); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } /// /// 编辑数据方法 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string Id = Grid1.SelectedRowID; var supplier = BLL.SupplierService.GetSupplierById(Id); if (supplier != null) { this.txtSupplierCode.Text = supplier.SupplierCode; this.txtSupplierName.Text = supplier.SupplierName; this.txtContactMan.Text = supplier.ContactMan; this.txtContactPhone.Text = supplier.ContactPhone; hfFormID.Text = Id; this.btnDelete.Enabled = true; } } #endregion #region 提交按钮 /// /// 提交按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.CLGL_SupplierMenuId, Const.BtnSave)) { string strRowID = hfFormID.Text; if (BLL.SupplierService.IsExitSupplierCode(this.txtSupplierCode.Text.Trim(), strRowID)) { Alert.ShowInTop("此供应商代号已存在!", MessageBoxIcon.Warning); return; } Model.Weld_Supplier supplier = new Model.Weld_Supplier(); supplier.SupplierCode = this.txtSupplierCode.Text.Trim(); supplier.SupplierName = this.txtSupplierName.Text.Trim(); supplier.ContactMan = this.txtContactMan.Text.Trim(); supplier.ContactPhone = this.txtContactPhone.Text.Trim(); if (string.IsNullOrEmpty(strRowID)) { strRowID = SQLHelper.GetNewID(typeof(Model.Weld_Supplier)); supplier.SupplierId = strRowID; BLL.SupplierService.AddSupplier(supplier); BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加供应商信息"); } else { supplier.SupplierId = strRowID; BLL.SupplierService.UpdateSupplier(supplier); BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改供应商信息"); } // 重新绑定表格,并点击当前编辑或者新增的行 BindGrid(); ShowNotify("保存成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript("onNewButtonClick();"); //PageContext.RegisterStartupScript(String.Format("F('{0}').selectRow('{1}');", Grid1.ClientID, UnitQualitySort.UnitQualitySortId)); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #endregion #region 判断是否可删除 /// /// 判断是否可以删除 /// /// private bool judgementDelete(string id, bool isShow) { string content = string.Empty; //if (BLL.HJGL_PW_JointInfoService.GetJointInfoByFloorWeld(id) > 0) //{ // content = "焊口中已经使用了该焊缝类型,不能删除!"; //} if (string.IsNullOrEmpty(content)) { return true; } else { if (isShow) { Alert.ShowInTop(content, MessageBoxIcon.Error); } return false; } } #endregion #region 查询 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #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(); } /// /// 导出方法 /// /// /// private string GetGridTableHtml(Grid grid) { StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(""); sb.Append(""); this.Grid1.PageSize = 10000; BindGrid(); 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 } }