using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; namespace FineUIPro.Web.CQMS.Models { public partial class QualityModel : PageBase { #region 加载页面 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { GetButtonPower(); BLL.CompanyModelKindService.InitCompanyModelKindDownList(this.drpCompanyModelKind, true); BindGrid(); btnNew.OnClientClick = Window1.GetShowReference("QualityModelEdit.aspx") + "return false;"; } } /// /// 数据绑定 /// public void BindGrid() { string strSql = @"select q.*,c.ModelType,CompanyModelKindName,CompanyModelKindCode from Model_QualityModel q left join Base_CompanyModel c on c.CompanyModelId=q.CompanyModelId left join Base_CompanyModelKind d on d.CompanyModelKindId=c.CompanyModelKindId where ProjectId=@ProjectId "; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId)); if (this.drpCompanyModelKind.SelectedValue != BLL.Const._Null) { strSql += " and c.CompanyModelKindId=@CompanyModelKindId"; listStr.Add(new SqlParameter("@CompanyModelKindId", this.drpCompanyModelKind.SelectedValue)); } 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 Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// 分页下拉框事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 查询 /// /// 查询 /// /// /// protected void btnSearch_Click(object sender, EventArgs e) { BindGrid(); } #endregion #region 关闭弹出窗口 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion #region 编辑 protected void btnMenuModify_Click(object sender, EventArgs e) { EditData(); } /// /// Grid行双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { EditData(); } /// /// 编辑 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning); return; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("QualityModelEdit.aspx?QualityModelId={0}", Grid1.SelectedRowID, "编辑 - "))); } #endregion #region 删除 /// /// 右键删除 /// /// /// protected void btnMenuDel_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var QualityModelIdInfo = BLL.QualityModelService.GetQualityModelById(rowID); if (QualityModelIdInfo != null) { BLL.QualityModelService.DeleteQualityModelById(rowID); } } BindGrid(); ShowNotify("删除数据成功!", MessageBoxIcon.Success); } } #endregion #region Grid行点击事件 /// /// Grid行点击事件 /// /// /// protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { string id = Grid1.DataKeys[e.RowIndex][0].ToString(); if (e.CommandName == "AttachUrl") { PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("~/AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/CQMS/Models&menuId={1}", id, BLL.Const.QualityModelMenuId))); } } #endregion /// /// 获取图片(放于Img中) /// /// /// protected string ConvertImageUrlByImage(object QualityModelId) { string url = string.Empty; if (QualityModelId != null) { var attachFile = BLL.AttachFileService.GetAttachFileByToKeyId(QualityModelId.ToString()); if (attachFile != null) { url = HttpUtility.HtmlDecode(BLL.UploadAttachmentService.ShowImage("../../", attachFile.AttachUrl)); } } return url; } #region 权限设置 /// /// 权限设置 /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, BLL.Const.QualityModelMenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnAdd)) { this.btnNew.Hidden = false; this.btnLoad.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuModify.Hidden = false; this.Grid1.EnableRowDoubleClickEvent = true; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnMenuDel.Hidden = false; } } } #endregion #region 抽取公司质量样板内容 /// /// 抽取公司质量样板内容 /// /// /// protected void btnLoad_Click(object sender, EventArgs e) { var qualityModels = from x in Funs.DB.Model_QualityModel where x.ProjectId == this.CurrUser.LoginProjectId select x; if (qualityModels.Count() == 0) { var companyModels = from x in Funs.DB.Base_CompanyModel select x; foreach (var item in companyModels) { Model.Model_QualityModel newQualityModel = new Model.Model_QualityModel(); newQualityModel.ProjectId = this.CurrUser.LoginProjectId; newQualityModel.CompanyModelId = item.CompanyModelId; newQualityModel.QualityModelId = SQLHelper.GetNewID(typeof(Model.Model_QualityModel)); newQualityModel.CompileMan = this.CurrUser.PersonId; newQualityModel.CompileDate = DateTime.Now; BLL.QualityModelService.AddQualityModel(newQualityModel); } } else { Alert.ShowInTop("该项目已存在公司质量样板内容,无法抽取!"); return; } //BLL.LogService.AddSys_Log(this.CurrUser, "抽取公司质量样板内容", null, BLL.Const.QualityModelMenuId, BLL.Const.BtnDownload); ShowNotify("抽取公司质量样板内容成功!", MessageBoxIcon.Success); BindGrid(); } #endregion protected void drpCompanyModelKind_SelectedIndexChanged(object sender, EventArgs e) { BindGrid(); } } }