using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Data; using BLL; namespace FineUIPro.Web.WeldMat.BaseInfo { public partial class StoremanInfo : 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 StoremanId, StoreCode, StoreName, IdentityCard,SignatureUrl" + @" FROM Weld_Storeman WHERE 1=1 "; List listStr = new List(); if (!string.IsNullOrEmpty(this.txtName.Text.Trim())) { strSql += " AND StoreName LIKE @StoreName"; listStr.Add(new SqlParameter("@StoreName", "%" + 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_StoremanInfoMenuId, Const.BtnDelete)) { if (judgementDelete(hfFormID.Text, true)) { BLL.StoremanInfoService.DeleteStoreManById(hfFormID.Text); BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除保管员信息"); // 重新绑定表格,并模拟点击[新增按钮] BindGrid(); } } 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_StoremanInfoMenuId, 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.StoremanInfoService.DeleteStoreManById(rowID); BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "删除保管员信息"); ShowNotify("删除完成!", MessageBoxIcon.Success); } } BindGrid(); } } #endregion #region 编辑 /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.CLGL_StoremanInfoMenuId, 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 storemanInfo = BLL.StoremanInfoService.GetStoremanById(Id); if (storemanInfo != null) { //this.txtStoreCode.Text = storemanInfo.StoreCode; this.txtStoreName.Text = storemanInfo.StoreName; this.txtIdentityCard.Text = storemanInfo.IdentityCard; imgPhoto.ImageUrl = storemanInfo.SignatureUrl; hfFormID.Text = Id; this.btnDelete.Enabled = true; } } #endregion protected void Grid1_RowClick(object sender, GridRowClickEventArgs e) { EditData(); } #region 提交按钮 /// /// 提交按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { if (CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.CLGL_StoremanInfoMenuId, Const.BtnSave)) { string strRowID = hfFormID.Text; if (BLL.StoremanInfoService.IsExitStoreName(this.txtStoreName.Text.Trim(), strRowID)) { Alert.ShowInTop("此保管员姓名已存在!", MessageBoxIcon.Warning); return; } Model.Weld_Storeman storeman = new Model.Weld_Storeman(); //storeman.StoreCode = this.txtStoreCode.Text.Trim(); storeman.StoreName = this.txtStoreName.Text.Trim(); storeman.IdentityCard = this.txtIdentityCard.Text.Trim(); storeman.SignatureUrl = imgPhoto.ImageUrl; if (!string.IsNullOrEmpty(strRowID)) { storeman.StoremanId = strRowID; BLL.StoremanInfoService.UpdateStoreMan(storeman); BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "修改保管员信息"); //strRowID = SQLHelper.GetNewID(typeof(Model.Weld_Storeman)); //storeman.StoremanId = strRowID; //BLL.StoremanInfoService.AddStoreMan(storeman); //BLL.Sys_LogService.AddLog(BLL.Const.System_7, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "添加保管员信息"); } else { Alert.ShowInTop("请选择要修改的行!", MessageBoxIcon.Warning); } // 重新绑定表格,并点击当前编辑或者新增的行 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 登记指纹 /// /// 焊工识别人脸练习(指纹) /// /// /// protected void lbWelderRead_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(Grid1.SelectedRowID)) { Alert.ShowInTop("请选中登记的人员!", MessageBoxIcon.Warning); return; } string identityCard = string.Empty; var storeman = BLL.StoremanInfoService.GetStoremanById(this.Grid1.SelectedRowID); if (storeman != null) { identityCard = storeman.IdentityCard; } PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/FingerMark/RegisterFinger.aspx?userId={0}&flag=2", storeman.StoremanId), "登记指纹", 560, 500)); } #endregion #region 判断是否可删除 /// /// 判断是否可以删除 /// /// private bool judgementDelete(string id, bool isShow) { string content = string.Empty; if (BLL.RecycleMatTopService.GetRecycleMatTopByStockMan(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 filePhoto_FileSelected(object sender, EventArgs e) { if (filePhoto.HasFile) { string fileName = filePhoto.ShortFileName; if (!ValidateFileType(fileName)) { ShowNotify("无效的文件类型!"); return; } fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_"); fileName = DateTime.Now.Ticks.ToString() + "_" + fileName; filePhoto.SaveAs(Server.MapPath("~/upload/" + fileName)); imgPhoto.ImageUrl = "~/upload/" + fileName; // 清空文件上传组件 filePhoto.Reset(); } } #endregion #region Grid行选择事件 /// /// Grid行选择事件 /// /// /// protected void Grid1_RowSelect(object sender, GridRowSelectEventArgs e) { this.EditData(); } #endregion /// /// 人脸采集 /// /// /// protected void btnWelderFaceRead_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(Grid1.SelectedRowID)) { Alert.ShowInTop("请选中要采集的人员!", MessageBoxIcon.Warning); return; } string identityCard = string.Empty; var storeman = BLL.StoremanInfoService.GetStoremanById(this.Grid1.SelectedRowID); if (storeman != null) { identityCard = storeman.IdentityCard; } PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("~/RLSB/WelderTrain.aspx?identityCard={0}", identityCard), "人脸训练", 1260, 680)); } } }