|  |  |  | 
|---|
|  |  |  | SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); | 
|---|
|  |  |  | DataSet ds; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 角色列表 | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 返回用户角色列表 | 
|---|
|  |  |  | ///参数:string sql。 | 
|---|
|  |  |  | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | if (sWhere == null || sWhere.Equals("")) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | ds = oCN.RunProcReturn("select * from h_v_System_UserGroup " + sWhere, "h_v_System_UserGroup"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string sql1 = "select * from h_v_System_UserGroup where 1 = 1 "; | 
|---|
|  |  |  | string sql = sql1 + sWhere; | 
|---|
|  |  |  | ds = oCN.RunProcReturn(sql, "h_v_System_UserGroup"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ds = oCN.RunProcReturn("select * from h_v_System_UserGroup   where 1 = 1 " + sWhere, "h_v_System_UserGroup"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //if (ds.Tables[0].Rows.Count != 0 || ds != null) | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | objJsonResult.code = "1"; | 
|---|
|  |  |  | objJsonResult.count = 1; | 
|---|
|  |  |  | objJsonResult.Message = "Sucess!"; | 
|---|
|  |  |  | objJsonResult.data = ds.Tables[0]; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | //else | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //objJsonResult.code = "0"; | 
|---|
|  |  |  | //objJsonResult.count = 0; | 
|---|
|  |  |  | //objJsonResult.Message = "无数据"; | 
|---|
|  |  |  | //objJsonResult.data = null; | 
|---|
|  |  |  | //return objJsonResult; | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception e) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 角色绑定用户数据 | 
|---|
|  |  |  | [Route("Xt_UserGroup/UserGroupInfoList")] | 
|---|
|  |  |  | [HttpGet] | 
|---|
|  |  |  | public object UserGroupInfoList(string sWhere) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string sql = "select * from System_UserGroupInfo where 1=1 " + sWhere; | 
|---|
|  |  |  | ds = oCN.RunProcReturn(sql, "System_UserGroupInfo"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | objJsonResult.code = "1"; | 
|---|
|  |  |  | objJsonResult.count = 1; | 
|---|
|  |  |  | objJsonResult.Message = "Sucess!"; | 
|---|
|  |  |  | objJsonResult.data = ds.Tables[0]; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception e) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = "Exception!" + e.ToString(); | 
|---|
|  |  |  | objJsonResult.data = null; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 角色列表  添加/修改 | 
|---|
|  |  |  | public class Xt_UserGroup | 
|---|
|  |  |  | { | 
|---|
|  |  |  | public int HGroupID; | 
|---|
|  |  |  | public string GroupName { get; set; } | 
|---|
|  |  |  | public string HLev { get; set; } | 
|---|
|  |  |  | public string Explain { get; set; } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | [Route("Xt_UserGroup/UserGroupInfoEdit")] | 
|---|
|  |  |  | [HttpPost] | 
|---|
|  |  |  | public object UserGroupInfoEdit([FromBody] JObject sMainSub) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var _value = sMainSub["sMainSub"].ToString(); | 
|---|
|  |  |  | string msg1 = _value.ToString(); | 
|---|
|  |  |  | oCN.BeginTran(); | 
|---|
|  |  |  | //保存主表 | 
|---|
|  |  |  | objJsonResult = AddBillMain(msg1); | 
|---|
|  |  |  | if (objJsonResult.code == "0") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | oCN.RollBack(); | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = objJsonResult.Message; | 
|---|
|  |  |  | objJsonResult.data = null; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | oCN.Commit(); | 
|---|
|  |  |  | objJsonResult.code = "1"; | 
|---|
|  |  |  | objJsonResult.count = 1; | 
|---|
|  |  |  | objJsonResult.Message = "成功!"; | 
|---|
|  |  |  | objJsonResult.data = null; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public json AddBillMain(string msg1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); | 
|---|
|  |  |  | string msg2 = sArray[0].ToString(); | 
|---|
|  |  |  | string msg3 = sArray[1].ToString(); | 
|---|
|  |  |  | int OperationType = int.Parse(sArray[2].ToString());//数据类型 1添加 3修改 | 
|---|
|  |  |  | string user = sArray[3].ToString(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Xt_UserGroup omdelMian = Newtonsoft.Json.JsonConvert.DeserializeObject<Xt_UserGroup>(msg2); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var num = msg3.Split(','); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (OperationType == 1)//新增 | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //主表 | 
|---|
|  |  |  | oCN.RunProc("insert into  System_UserGroup (GroupName,HLev,Explain)values" + | 
|---|
|  |  |  | $"('{omdelMian.GroupName}','{omdelMian.HLev}','{omdelMian.Explain}')"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //新增后查询  确保数据添加成功 | 
|---|
|  |  |  | ds = oCN.RunProcReturn("Select * from  System_UserGroup where GroupName='" + omdelMian.GroupName + "'", "System_UserGroup"); | 
|---|
|  |  |  | if (ds == null || ds.Tables[0].Rows.Count == 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = "用户新增失败!"; | 
|---|
|  |  |  | objJsonResult.data = null; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var HGroupID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["GroupID"]); | 
|---|
|  |  |  | oCN.RunProc("delete from  System_UserGroupInfo where GroupId=" + HGroupID.ToString()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (num[0] != "-1") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | for (int i = 0; i < num.Length; i++) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | oCN.RunProc("insert into  System_UserGroupInfo (GroupId,UserId) values (" + HGroupID.ToString() + ",'" + num[i] + "')"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (OperationType == 3) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | oCN.RunProc("update  System_UserGroup set GroupName='" + omdelMian.GroupName + "',HLev='" + omdelMian.HLev + "',Explain='" + omdelMian.Explain + "'" | 
|---|
|  |  |  | + " where GroupId=" + omdelMian.HGroupID); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | oCN.RunProc("delete from  System_UserGroupInfo where GroupId=" + omdelMian.HGroupID); | 
|---|
|  |  |  | for (int i = 0; i < num.Length; i++) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | oCN.RunProc("insert into  System_UserGroupInfo (GroupId,UserId) values (" + omdelMian.HGroupID + ",'" + num[i] + "')"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | objJsonResult.code = "1"; | 
|---|
|  |  |  | objJsonResult.count = 1; | 
|---|
|  |  |  | objJsonResult.Message = null; | 
|---|
|  |  |  | objJsonResult.data = null; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception e) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = "Exception!" + e.ToString(); | 
|---|
|  |  |  | objJsonResult.data = null; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 角色列表 删除 | 
|---|
|  |  |  | [Route("Xt_UserGroup/DelXt_UserGroupList")] | 
|---|
|  |  |  | [HttpGet] | 
|---|
|  |  |  | public object DelXt_UserGroupList(string HInterID,string User) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | ds = oCN.RunProcReturn("select * from h_v_System_UserGroup where 1=1 and HGroupID=" + HInterID, "h_v_System_UserGroup"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (ds.Tables[0].Rows.Count > 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | oCN.BeginTran();//开启事务 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | oCN.RunProc($"delete from h_v_System_UserGroup where HGroupID={HInterID}"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | oCN.Commit();//结束事务 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | objJsonResult.code = "1"; | 
|---|
|  |  |  | objJsonResult.count = 1; | 
|---|
|  |  |  | objJsonResult.Message = "删除成功!"; | 
|---|
|  |  |  | objJsonResult.data = null; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = "当前单据不存在,无法删除!"; | 
|---|
|  |  |  | objJsonResult.data = null; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception e) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | oCN.RollBack();//回滚事务 | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = e.ToString(); | 
|---|
|  |  |  | objJsonResult.data = null; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|