public int InsertAuthorityTable(EntityAuthority entity) { string SqlStr = ""; SqlStr = "insert into TC_Authority"; SqlStr += " values('" + entity.Authority_user_code.Trim() + "','" + entity.Authority_password.Trim() + "','" + entity.Authority_level.Trim() + "','" + entity.Staff_code.Trim() + "')"; SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = SqlStr; try { ExcuteSql(sqlCommand); } catch { return(Constants.SystemConfig.SERVER_ERROR); } return(Constants.SystemConfig.SERVER_SUCCESS); }
public int UpdateAuthorityTable(EntityAuthority entity) { string SqlStr = ""; SqlStr = "update tc_Authority"; SqlStr += " set authority_user_code = '" + entity.Authority_user_code.Trim() + "',authority_password = '******',authority_level = '" + entity.Authority_level.Trim() + "',staff_code = '" + entity.Staff_code.Trim(); SqlStr += "' where authority_id = " + entity.Id + " "; SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = SqlStr; ExcuteSql(sqlCommand); return(Constants.SystemConfig.SERVER_SUCCESS); }
private void btnRepassword_Click(object sender, EventArgs e) { if (LoginUser.UserAuthority == "0") { EntityAuthority entity = new EntityAuthority(); entity.Authority_level = "1"; entity.Authority_user_code = "admin"; try { entity.Authority_password = Util.GetHashCode("123456"); entity.Staff_code = "管理员"; entity.Id = 2; dataAccess = new DataAccess(); dataAccess.Open(); dataAccess.BeginTransaction(); GetData getData = new GetData(dataAccess.Connection, dataAccess.Transaction); result = getData.UpdateAuthorityTable(entity); dataAccess.Commit(); } catch (COMException comex) { MessageBox.Show("加密狗未找到,请插入加密狗!", "长白ERP系统", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } catch (Exception ex) { dataAccess.Rollback(); MessageBox.Show(ex.Message); throw ex; } finally { if (dataAccess == null) { dataAccess.Close(); } } if (result == 0) { MessageBox.Show("管理员密码已初始化成功!新密码为 \"123456\"!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); BandingDgv(); } else { MessageBox.Show("数据删除时发生错误,请检查数据库!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { if (dgv.SelectedRows.Count > 1 || dgv.SelectedRows.Count < 1) { MessageBox.Show("只能选择一位用户进行初始化!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (MessageBox.Show("您确定要初始化该用户密码吗?", Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { EntityAuthority entity = new EntityAuthority(); entity.Authority_level = "2"; entity.Authority_user_code = dgv.SelectedRows[0].Cells["Authority_user_code"].Value.ToString(); entity.Staff_code = dgv.SelectedRows[0].Cells["Staff_code"].Value.ToString(); entity.Id = Int32.Parse(dgv.SelectedRows[0].Cells["Authority_id"].Value.ToString()); try { //加密狗 entity.Authority_password = Util.GetHashCode("000000"); dataAccess = new DataAccess(); dataAccess.Open(); dataAccess.BeginTransaction(); GetData getData = new GetData(dataAccess.Connection, dataAccess.Transaction); result = getData.UpdateAuthorityTable(entity); dataAccess.Commit(); } catch (COMException comex) { MessageBox.Show("加密狗未找到,请插入加密狗!", "长白ERP系统", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } catch (Exception ex) { dataAccess.Rollback(); MessageBox.Show(ex.Message); throw ex; } finally { if (dataAccess.Connection != null) { dataAccess.Close(); } } if (result == 0) { MessageBox.Show("用户密码已初始化成功!新密码为 \"000000\"!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); BandingDgv(); } else { MessageBox.Show("数据删除时发生错误,请检查数据库!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
//*********************************************************************** /// <summary> /// 保存按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// 完成信息:李梓楠 2010/7/15 完成 /// 更新信息: /// </history> //*********************************************************************** private void btnCommit_Click(object sender, EventArgs e) { //判断有效日期不能为空 if (txtStaff_name.Text.Trim() == string.Empty || txtStaff_name.Text == "双击选择员工...") { MessageBox.Show("用户姓名不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtStaff_name.Focus(); return; } //判断产品名称不能为空 if (txtAuthority_user_code.Text.Trim() == string.Empty) { MessageBox.Show("登录账号不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtAuthority_user_code.Focus(); return; } //判断非法字符 foreach (Control control in groupBox1.Controls) { if (control is TextBox) { if (Util.CheckRegex(control.Text.Trim()) && !((TextBox)control).ReadOnly) { MessageBox.Show("不可以输入非法字符,请重新输入!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); control.Focus(); return; } } } EntityAuthority entity = new EntityAuthority(); try { result = -1; //如果是添加 if (dataType == DataType.Insert) { entity.Authority_level = "2"; entity.Authority_user_code = txtAuthority_user_code.Text; entity.Staff_code = staffCode; //加密狗 entity.Authority_password = Util.GetHashCode("000000"); dataAccess = new DataAccess(); dataAccess.Open(); SearchParameter sp = new SearchParameter(); sp.SetValue(":Authority_user_code", txtAuthority_user_code.Text); GetData getData = new GetData(dataAccess.Connection); DataTable dt = getData.GetSingleTableByConditionUnLike("tc_Authority", sp); dataAccess.Open(); sp.Clear(); sp.SetValue(":staff_code", staffCode); getData = new GetData(dataAccess.Connection); DataTable dt2 = getData.GetSingleTableByConditionUnLike("tc_Authority", sp); if (dt != null && dt.Rows.Count != 0 && dt2 != null && dt2.Rows.Count != 0) { MessageBox.Show("该用户已经存在自己的登录账号!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtStaff_name.Focus(); return; } if (dt != null && dt.Rows.Count != 0) { MessageBox.Show("登录账号已存在!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtAuthority_user_code.Focus(); return; } else if (dt2 != null && dt2.Rows.Count != 0) { MessageBox.Show("该用户已经存在自己的登录账号!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtStaff_name.Focus(); return; } else { dataAccess.Open(); result = getData.InsertAuthorityTable(entity); } } } catch (COMException comex) { MessageBox.Show("加密狗未找到,请插入加密狗!", "长白ERP系统", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } catch (Exception ex) { if (dataAccess.Transaction != null) { //回滚 dataAccess.Rollback(); } //提示错误 MessageBox.Show("数据添加时发生错误,请检查数据库!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); throw ex; } finally { //关闭数据库连接 if (dataAccess.Connection != null) { dataAccess.Close(); } } if (result == 0) { MessageBox.Show("数据已经保存成功!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); BandingDgv(); } else { MessageBox.Show("数据保存时发生错误,请检查数据库!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } //设置按钮状态 dataType = DataType.None; setButtonState(); }
public List <EntityAuthority> GetAuthority(string random, int _user_id) { EntityAuthority entity; List <EntityAuthority> entityList = new List <EntityAuthority>(); #region 認証処理 string companyId = ""; string groupId = ""; string userId = ""; string ipAdress = ""; string sessionString = ""; try { companyId = ExCast.zCStr(HttpContext.Current.Session[ExSession.COMPANY_ID]); groupId = ExCast.zCStr(HttpContext.Current.Session[ExSession.GROUP_ID]); userId = ExCast.zCStr(HttpContext.Current.Session[ExSession.USER_ID]); ipAdress = ExCast.zCStr(HttpContext.Current.Session[ExSession.IP_ADRESS]); sessionString = ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]); string _message = ExSession.SessionUserUniqueCheck(random, ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]), ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID])); if (_message != "") { entity = new EntityAuthority(); entity.MESSAGE = _message; entityList.Add(entity); return(entityList); } } catch (Exception ex) { CommonUtl.ExLogger.Error(Authority_NM + ".GetAuthority(認証処理)", ex); entity = new EntityAuthority(); entity.MESSAGE = Authority_NM + ".GetAuthority : 認証処理に失敗しました。" + Environment.NewLine + ex.Message.ToString();; entityList.Add(entity); return(entityList); } #endregion StringBuilder sb; DataTable dt; ExMySQLData db; try { db = ExSession.GetSessionDb(ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]), ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR])); sb = new StringBuilder(); #region SQL sb.Append("SELECT IFNULL(AR.USER_ID, " + _user_id.ToString() + ") AS USER_ID" + Environment.NewLine); sb.Append(" ,MT.ID AS PG_ID " + Environment.NewLine); sb.Append(" ,IFNULL(AR.AUTHORITY_KBN, 0) AS AUTHORITY_KBN" + Environment.NewLine); sb.Append(" ,IFNULL(AR.MEMO, '') AS MEMO" + Environment.NewLine); sb.Append(" ,IFNULL(AR.DISPLAY_INDEX, 0) AS DISPLAY_INDEX" + Environment.NewLine); sb.Append(" FROM SYS_M_PG AS MT" + Environment.NewLine); #region Join sb.Append(" LEFT JOIN M_AUTHORITY AS AR" + Environment.NewLine); sb.Append(" ON AR.DELETE_FLG = 0 " + Environment.NewLine); sb.Append(" AND AR.DISPLAY_FLG = 1 " + Environment.NewLine); sb.Append(" AND AR.USER_ID = " + _user_id + Environment.NewLine); sb.Append(" AND AR.PG_ID = MT.ID " + Environment.NewLine); #endregion sb.Append(" WHERE MT.DELETE_FLG = 0 " + Environment.NewLine); sb.Append(" AND MT.DISPLAY_FLG = 1 " + Environment.NewLine); #endregion dt = db.GetDataTable(sb.ToString()); // 排他制御 DataPgLock.geLovkFlg lockFlg; string strErr = DataPgLock.SetLockPg(companyId, userId, PG_NM, _user_id.ToString(), ipAdress, db, out lockFlg); if (strErr != "") { entity = new EntityAuthority(); entity.MESSAGE = Authority_NM + ".GetAuthority : 排他制御(ロック情報取得)に失敗しました。" + Environment.NewLine + strErr; entityList.Add(entity); return(entityList); } if (dt.DefaultView.Count > 0) { for (int i = 0; i <= dt.DefaultView.Count - 1; i++) { #region Set Entity entity = new EntityAuthority(); entity.user_id = ExCast.zCInt(dt.DefaultView[i]["USER_ID"]); entity.pg_id = ExCast.zCStr(dt.DefaultView[i]["PG_ID"]); entity.authority_kbn = ExCast.zCInt(dt.DefaultView[i]["AUTHORITY_KBN"]); entity.display_index = ExCast.zCInt(dt.DefaultView[i]["DISPLAY_INDEX"]); entity.memo = ExCast.zCStr(dt.DefaultView[i]["MEMO"]); entity.lock_flg = (int)lockFlg; if (entity.pg_id == "ReportTotal" && _user_id == ExCast.zCInt(userId)) { HttpContext.Current.Session[ExSession.REPORT_TOTAL_AUTHORITY_KBN] = entity.authority_kbn; } entityList.Add(entity); #endregion } } } catch (Exception ex) { CommonUtl.ExLogger.Error(Authority_NM + ".GetAuthority", ex); entityList.Clear(); entity = new EntityAuthority(); entity.MESSAGE = Authority_NM + ".GetAuthority : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message.ToString(); entityList.Add(entity); } finally { db = null; } svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]), companyId, userId, ipAdress, sessionString, PG_NM, DataPgEvidence.geOperationType.Select, ""); return(entityList); }
private void btnCommit_Click(object sender, EventArgs e) { //判断非法字符 foreach (Control control in this.Controls) { if (control is TextBox) { if (Util.CheckRegex(control.Text.Trim()) && !((TextBox)control).ReadOnly) { MessageBox.Show("不可以输入非法字符,请重新输入!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); control.Focus(); return; } } } //密码不能为空 if (txtOldPassword.Text.Trim() == string.Empty) { MessageBox.Show("原密码不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtOldPassword.Focus(); return; } //密码不能为空 if (txtNewPassword1.Text.Trim() == string.Empty) { MessageBox.Show("新密码不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtNewPassword1.Focus(); return; } if (txtNewPassword2.Text.Trim() == string.Empty) { MessageBox.Show("确认密码不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtNewPassword2.Focus(); return; } if (txtNewPassword1.Text != txtNewPassword2.Text) { MessageBox.Show("请检查您两次输入的新密码是否一致!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtNewPassword2.Focus(); return; } EntityAuthority entity = new EntityAuthority(); //entity.Authority_user_code = LoginUser.UserCode; //entity.Authority_password = txtOldPassword.Text; SearchParameter sp = new SearchParameter(); sp.SetValue(":authority_user_code", LoginUser.UserCode); try { sp.SetValue(":authority_password", Util.GetHashCode(txtOldPassword.Text)); } catch (COMException comex) { MessageBox.Show("加密狗未找到,请插入加密狗!", "长白ERP系统", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } DataAccess dataAccess = new DataAccess(); int result = -1; DataTable dt = null; GetData getData = null; try { dataAccess.Open(); getData = new GetData(dataAccess.Connection); dt = getData.GetSingleTableByConditionUnLike("tc_authority", sp); if (dt == null) { MessageBox.Show("请查看数据库是否正常!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (dt.Rows.Count == 0) { MessageBox.Show("请检查原密码是否正确!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); txtOldPassword.Focus(); return; } } catch (Exception ex) { MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { dataAccess.Close(); } entity.Authority_user_code = dt.Rows[0]["Authority_user_code"].ToString(); entity.Id = Convert.ToInt32(dt.Rows[0]["authority_id"].ToString()); try { entity.Authority_password = Util.GetHashCode(txtNewPassword1.Text); } catch (COMException comex) { MessageBox.Show("加密狗未找到,请插入加密狗!", "长白ERP系统", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } entity.Authority_level = LoginUser.UserAuthority; entity.Staff_code = dt.Rows[0]["staff_code"].ToString(); try { dataAccess.Open(); getData = new GetData(dataAccess.Connection, dataAccess.Transaction); //取得结果符 result = getData.UpdateAuthorityTable(entity); //提交事务 dataAccess.Commit(); } catch (Exception ex) { MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { dataAccess.Close(); } if (result == 0) { MessageBox.Show("密码修改成功!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("密码修改时发生错误,请检查数据库!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } }