public ActionResult ChangePassword(ChangePasswordModel model) { if (ModelState.IsValid) { Regex r = new Regex("^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])|(?=.*[A-Z])(?=.*[a-z])(?=.*[^A-Za-z0-9])|(?=.*[A-Z])(?=.*[0-9])(?=.*[^A-Za-z0-9])|(?=.*[a-z])(?=.*[0-9])(?=.*[^A-Za-z0-9])).{6,}|(?:(?=.*[A-Z])(?=.*[a-z])|(?=.*[A-Z])(?=.*[0-9])|(?=.*[A-Z])(?=.*[^A-Za-z0-9])|(?=.*[a-z])(?=.*[0-9])|(?=.*[a-z])(?=.*[^A-Za-z0-9])|(?=.*[0-9])(?=.*[^A-Za-z0-9])|).{8,}"); if (!r.IsMatch(model.ConfirmPassword)) { BusinessException ex = new BusinessException(); ex.AddMessage(Resources.ACC.User.User_Regex); SaveBusinessExceptionMessage(ex); } else { CurrentUser.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(model.ConfirmPassword, "MD5"); CurrentUser.IsActive = true; base.genericMgr.Update(CurrentUser); SaveSuccessMessage(Resources.ACC.User.User_PasswordChanged); //try //{ // CurrentUser.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(model.ConfirmPassword, "MD5"); // this.genericMgr.UpdateWithNativeQuery("exec USP_Busi_ChangePassword ?,?", // new object[] { CurrentUser.Id, CurrentUser.Password }, // new IType[] { NHibernateUtil.String, NHibernateUtil.String }); // SaveSuccessMessage(Resources.ACC.User.User_PasswordChanged); //} //catch (Exception ex) //{ // if (ex.InnerException != null) // { // if (ex.InnerException.InnerException != null) // { // SaveErrorMessage(ex.InnerException.InnerException.Message); // } // else // { // SaveErrorMessage(ex.InnerException.Message); // } // } // else // { // SaveErrorMessage(ex.Message); // } //} } } return(View(model)); }
public ActionResult ChangePassword(ChangePasswordModel model) { if (ModelState.IsValid) { bool changePasswordSucceeded = true; Regex r = new Regex("^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])|(?=.*[A-Z])(?=.*[a-z])(?=.*[^A-Za-z0-9])|(?=.*[A-Z])(?=.*[0-9])(?=.*[^A-Za-z0-9])|(?=.*[a-z])(?=.*[0-9])(?=.*[^A-Za-z0-9])).{6,}|(?:(?=.*[A-Z])(?=.*[a-z])|(?=.*[A-Z])(?=.*[0-9])|(?=.*[A-Z])(?=.*[^A-Za-z0-9])|(?=.*[a-z])(?=.*[0-9])|(?=.*[a-z])(?=.*[^A-Za-z0-9])|(?=.*[0-9])(?=.*[^A-Za-z0-9])|).{8,}"); if (!r.IsMatch(model.NewPassword)) { BusinessException ex = new BusinessException(); ex.AddMessage(Resources.ACC.User.User_Regex); SaveBusinessExceptionMessage(ex); changePasswordSucceeded = false; } //// ChangePassword will throw an exception rather ////than return false in certain failure scenarios. try { CurrentUser.Password = model.NewPassword; base.genericMgr.Update(CurrentUser); } catch (BusinessException ex) { SaveBusinessExceptionMessage(ex); changePasswordSucceeded = false; } catch (Exception) { changePasswordSucceeded = false; } if (changePasswordSucceeded) { return(RedirectToAction("ChangePasswordSuccess")); } ////else ////{ //// ModelState.AddModelError("", "The current password is incorrect or the new password is invalid."); ////} } //// If we got this far, something failed, redisplay form return(View(model)); }
public void CreateCustodian(Custodian custodian) { string ItemCodeStr = custodian.ItemCodes.Replace("\r\n", ","); string[] ItemCodeArray = ItemCodeStr.Split(','); BusinessException businessException = new BusinessException(); #region 判定Item是否有效 foreach (string itemCode in ItemCodeArray.Distinct()) { if (itemCode != null && itemCode != "") { IList <Item> items = this.genericMgr.FindAll <Item>("from Item where Code='" + itemCode + "'"); if (items == null || items.Count == 0) { businessException.AddMessage(itemCode.ToString() + ","); } } } if (businessException.HasMessage) { businessException.AddMessage("不存在。"); throw businessException; } #endregion #region 判定物料是否已经分配保管员 string hql = string.Empty; IList <object> parm = new List <object>(); foreach (string itemCode in ItemCodeArray.Distinct()) { if (hql == string.Empty) { hql = "from Custodian where Location=? and UserCode=? and item in (?"; parm.Add(custodian.Location); parm.Add(custodian.UserCode); } else { hql += ", ?"; } parm.Add(itemCode); } hql += ")"; IList <Custodian> CustodianList = this.genericMgr.FindAll <Custodian>(hql, parm.ToArray()); if (CustodianList != null && CustodianList.Count > 0) { foreach (Custodian cd in CustodianList) { businessException.AddMessage(cd.Item.ToString() + ","); } if (businessException.HasMessage) { businessException.AddMessage("已经分配保管员。"); throw businessException; } } #endregion foreach (string itemCode in ItemCodeArray.Distinct()) { if (itemCode != "") { Custodian cus = new Custodian(); cus.Item = itemCode; cus.Location = custodian.Location; cus.UserCode = custodian.UserCode; this.genericMgr.Create(cus); } } }
//[Transaction(TransactionMode.Requires)] public void BatchUpdateItemXls(Stream inputStream) { if (inputStream.Length == 0) { throw new BusinessException("Import.Stream.Empty"); } HSSFWorkbook workbook = new HSSFWorkbook(inputStream); ISheet sheet = workbook.GetSheetAt(0); IEnumerator rows = sheet.GetRowEnumerator(); ImportHelper.JumpRows(rows, 10); BusinessException businessException = new BusinessException(); #region 列定义 int colItem = 1; //件号 int colMinUC = 4; //上线包装 int colContainer = 5; //容器代码 int colContainerDesc = 6; //容器描述 #endregion IList <Item> exactItemList = new List <Item>(); int rowCount = 10; while (rows.MoveNext()) { rowCount++; HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 1, 2)) { break;//边界 } string itemCode = string.Empty; decimal minUC = 0; string container = string.Empty; string containerDesc = string.Empty; Item item = new Item(); #region 读取数据 #region 件号 itemCode = ImportHelper.GetCellStringValue(row.GetCell(colItem)); if (string.IsNullOrWhiteSpace(itemCode)) { businessException.AddMessage(string.Format("第{0}行物料编号不能为空", rowCount)); continue; } else { var items = this.genericMgr.FindAll <Item>(" select i from Item as i where i.Code=? ", itemCode); if (items == null) { businessException.AddMessage(string.Format("第{0}行物料编号{1}不存在。", rowCount, itemCode)); continue; } else { item = items.First(); } } #endregion #region 线包装 string readMinUC = ImportHelper.GetCellStringValue(row.GetCell(colMinUC)); if (string.IsNullOrWhiteSpace(readMinUC)) { //businessException.AddMessage(string.Format("第{0}行上线包装不能为空", rowCount)); } else { if (decimal.TryParse(readMinUC, out minUC)) { item.MinUnitCount = minUC; } else { businessException.AddMessage(string.Format("第{0}行上线包装{1},填写有误。", rowCount, readMinUC)); } } #endregion #region 容器代码 container = ImportHelper.GetCellStringValue(row.GetCell(colContainer)); if (string.IsNullOrWhiteSpace(container)) { //businessException.AddMessage(string.Format("第{0}行容器代码不能为空", rowCount)); } else { item.Container = container; } #endregion #region 容器描述 containerDesc = ImportHelper.GetCellStringValue(row.GetCell(colContainerDesc)); if (string.IsNullOrWhiteSpace(containerDesc)) { //businessException.AddMessage(string.Format("第{0}行容器描述不能为空", rowCount)); } else { item.ContainerDesc = containerDesc; } #endregion #endregion if (exactItemList == null || exactItemList.Count == 0) { exactItemList.Add(item); } else if (exactItemList.Where(e => e.Code == item.Code).Count() > 0) { businessException.AddMessage(string.Format("第{0}行物料编号{1}在模板中重复。", rowCount, itemCode)); } else { exactItemList.Add(item); } } if (businessException.HasMessage) { throw businessException; } if (exactItemList == null || exactItemList.Count == 0) { throw new BusinessException("模版为空,请确认。"); } foreach (Item item in exactItemList) { genericMgr.Update(item); this.genericMgr.Update(" update FlowDetail set MinUnitCount=?,UnitCount=?, Container =?,ContainerDesc=? where Item=? and exists( select 1 from FlowMaster as m where m.Code=Flow and m.Type=2 and exists( select 1 from FlowStrategy as fs where fs.Flow=m.Code and fs.Strategy<>7 ) )", new object[] { item.MinUnitCount, item.MinUnitCount, item.Container, item.ContainerDesc, item.Code }, new IType[] { NHibernate.NHibernateUtil.Decimal, NHibernate.NHibernateUtil.Decimal, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String }); this.genericMgr.Update(" update FlowDetail set MinUnitCount=?, Container =? where Item=? and exists( select 1 from FlowMaster as m where m.Code=Flow and m.Type=1 ) ", new object[] { item.MinUnitCount, item.Container, item.Code }, new IType[] { NHibernate.NHibernateUtil.Decimal, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String }); //this.genericMgr.Update(" update KanbanCard set Qty=?, Container =? where Item=? ", new object[] { item.MinUnitCount, item.Container, item.Code }, new IType[] { NHibernate.NHibernateUtil.Decimal, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String }); } }
public void CreateItemTraceXls(Stream inputStream) { if (inputStream.Length == 0) { throw new BusinessException("Import.Stream.Empty"); } HSSFWorkbook workbook = new HSSFWorkbook(inputStream); ISheet sheet = workbook.GetSheetAt(0); IEnumerator rows = sheet.GetRowEnumerator(); ImportHelper.JumpRows(rows, 10); BusinessException businessException = new BusinessException(); #region 列定义 int colItem = 1;//车系 #endregion IList <ItemTrace> exactItemTraceList = new List <ItemTrace>(); IList <Item> allItemList = this.genericMgr.FindAll <Item>(); IList <ItemTrace> allItemTraceList = this.genericMgr.FindAll <ItemTrace>(); int i = 10; while (rows.MoveNext()) { i++; HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 1, 2)) { break;//边界 } string itemCode = string.Empty; ItemTrace itemTrace = new ItemTrace(); #region 读取数据 itemCode = ImportHelper.GetCellStringValue(row.GetCell(colItem)); if (string.IsNullOrWhiteSpace(itemCode)) { businessException.AddMessage(string.Format("第{0}行关键件不能为空", i)); } else { var items = allItemList.FirstOrDefault(a => a.Code == itemCode); var existsItemTrace = allItemTraceList.FirstOrDefault(a => a.Item == itemCode); //var duplicateItemTrace= if (items == null) { businessException.AddMessage(string.Format("第{0}行{1}物料编号不存在。", i, itemCode)); } else if (existsItemTrace != null) { businessException.AddMessage(string.Format("第{0}行{1}关键件已经存在。", i, itemCode)); } else { itemTrace.Item = items.Code; itemTrace.ItemDescription = items.Description; if (exactItemTraceList == null || exactItemTraceList.Count == 0) { exactItemTraceList.Add(itemTrace); } else { bool isDuplicate = exactItemTraceList.Where(e => e.Item == itemCode).Count() > 0; if (isDuplicate) { businessException.AddMessage(string.Format("第{0}行{1}关键件在模板中重复。", i, itemCode)); } else { exactItemTraceList.Add(itemTrace); } } } } #endregion } if (businessException.HasMessage) { throw businessException; } if (exactItemTraceList == null || exactItemTraceList.Count == 0) { throw new BusinessException("模版为空,请确认。"); } foreach (ItemTrace itemTrace in exactItemTraceList) { genericMgr.Create(itemTrace); } }