| | |
| | | try |
| | | { |
| | | //获取计量单位组信息 |
| | | sql = @"select code,name,'1' as isGroup,data_sources from TUnitGroup "; |
| | | sql = @"select code,name,'1' as isGroup,igrouptype,data_sources from TUnitGroup "; |
| | | var data = DapperHelper.selecttable(sql); |
| | | mes.code = "200"; |
| | | mes.message = "查询成功!"; |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region[计量单位组新增/编辑] |
| | | public static ToMessage AddUpdateTUnitGroup(string OperType, List<ObjectDataCont> json, User us) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | list.Clear(); |
| | | if (OperType == "Add") |
| | | { |
| | | //判断计量单位组编码是否重复 |
| | | sql = @"select * from TUnitGroup where code=@tunitgroupcode"; |
| | | dynamicParams.Add("@tunitgroupcode", json[0].code); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "计量单位组编码已存在,请重新输入!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //判断计量单位组名称是否重复 |
| | | sql = @"select * from TUnitGroup where name=@tunitgroupname"; |
| | | dynamicParams.Add("@tunitgroupname", json[0].name); |
| | | var data1 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data1.Rows.Count > 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "计量单位组名称已存在,请重新输入!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //循环写入计量单位组表 |
| | | for (int i = 0; i < json.Count; i++) |
| | | { |
| | | sql = @"insert into TUnitGroup(code,name,igrouptype,lm_user,lm_date,data_sources) values(@code,@name,@username,@createdate,@data_sources)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | code = json[i].code, |
| | | name = json[i].name, |
| | | igrouptype = json[i].group, |
| | | username = us.usercode, |
| | | createdate = DateTime.Now.ToString(), |
| | | data_sources = "MES" |
| | | } |
| | | }); |
| | | } |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "新增", "新增了计量单位组:" + string.Join(",", json.Select(m => m.code)), us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "操作成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "操作失败!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | | if (OperType == "Update") |
| | | { |
| | | //判断设备名称是否重复 |
| | | sql = @"select * from TUnitGroup where code<>@tunitgroupcode and name=@tunitgroupname"; |
| | | dynamicParams.Add("@tunitgroupcode", json[0].code); |
| | | dynamicParams.Add("@tunitgroupname", json[0].name); |
| | | var data1 = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data1.Rows.Count > 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "计量单位组名称已存在,请重新输入!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | for (int i = 0; i < json.Count; i++) |
| | | { |
| | | sql = @"update TUnitGroup set name=@tunitgroupname,lm_user=@lm_user,lm_date=@lm_date |
| | | where code=@tunitgroupcode"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | tunitgroupcode = json[i].code, |
| | | tunitgroupname = json[i].name, |
| | | lm_user = us.usercode, |
| | | lm_date = DateTime.Now.ToString() |
| | | } |
| | | }); |
| | | } |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "修改", "修改了计量单位组:" + string.Join(",", json.Select(m => m.code)), us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "操作成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "操作失败!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | #region[计量单位组删除] |
| | | public static ToMessage DeleteTUnitGroup(string tunitgroupcode, User us) |
| | | { |
| | | var sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | list.Clear(); |
| | | sql = @"delete TUnitGroup where code=@code"; |
| | | list.Add(new { str = sql, parm = new { code = tunitgroupcode } }); |
| | | sql = @"delete TUnit where idunitgroup=@tunitgroupcode"; |
| | | list.Add(new { str = sql, parm = new { tunitgroupcode = tunitgroupcode } }); |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "删除", "删除了计量单位组:" + tunitgroupcode, us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "删除成功!"; |
| | | mes.data = null; |
| | | } |
| | | else |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "删除失败!"; |
| | | mes.data = null; |
| | | } |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = e.Message; |
| | | mes.data = null; |
| | | } |
| | | return mes; |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | |
| | | #region[计量单位信息列表] |
| | | public static ToMessage TUnitData(string tunittype, string tunitgroupcode, int startNum, int endNum, string prop, string order) |
| | | public static ToMessage TUnitData(string tunitgroupcode, int startNum, int endNum, string prop, string order) |
| | | { |
| | | var dynamicParams = new DynamicParameters(); |
| | | string sql = ""; |
| | | string search = "", sql = ""; |
| | | IEnumerable<object> data; |
| | | try |
| | | { |
| | | if (tunittype == "" || tunittype == null) |
| | | if (tunitgroupcode != "" && tunitgroupcode != null) |
| | | { |
| | | sql = @"select AA.code,AA.name,U.username as lm_user,AA.lm_date,AA.isGroup,AA.idunitgroup,AA.data_sources |
| | | from( |
| | | select code,name,lm_user,lm_date,isGroup,idunitgroup,data_sources |
| | | from TUnit T |
| | | where T.isGroup='0' |
| | | union all |
| | | select code,name,lm_user,lm_date,'1' as isGroup,code as idunitgroup,data_sources |
| | | from TUnitGroup |
| | | ) as AA |
| | | left join TUser U on AA.lm_user=U.usercode "; |
| | | search += "and T.idunitgroup=@tunitgroupcode "; |
| | | dynamicParams.Add("@tunitgroupcode", tunitgroupcode); |
| | | } |
| | | if (tunittype == "S") //单计量 |
| | | { |
| | | sql = @"select T.code,T.name,U.username as lm_user,T.lm_date,T.isGroup,T.idunitgroup,T.data_sources |
| | | from TUnit T |
| | | left join TUser U on T.lm_user=U.usercode |
| | | where T.isSingleUnit='1' and T.isGroup='0'"; |
| | | } |
| | | if (tunittype == "M" && (tunitgroupcode == "" || tunitgroupcode == null)) //多计量,且多计量组编码为空 |
| | | { |
| | | sql = @"select T.code,T.name,U.usercode as lm_user,T.lm_date,'1' as isGroup,T.code as idunitgroup,T.data_sources |
| | | from TUnitGroup T |
| | | left join TUser U on T.lm_user=U.usercode"; |
| | | } |
| | | if (tunittype == "M" && (tunitgroupcode != "" && tunitgroupcode != null)) //多计量,且多计量组编码不为空 |
| | | { |
| | | sql = @"select T.code,T.name,T.isMainUnit,T.changeRate,T.rateDescription,U.username as lm_user,T.lm_date,T.isGroup,T.idunitgroup,T.data_sources |
| | | from TUnit T |
| | | left join TUser U on T.lm_user=U.usercode |
| | | where T.isSingleUnit='0' and T.isGroup='1' and T.idunitgroup=@tunitgroupcode"; |
| | | dynamicParams.Add("@tunitgroupcode", tunitgroupcode); |
| | | } |
| | | where 1=1 " + search; |
| | | // --------------查询指定数据-------------- |
| | | var total = 0; //总条数 |
| | | data = DapperHelper.GetPageList<object>(sql, dynamicParams, prop, order, startNum, endNum, out total); |
| | |
| | | mes.message = "查询成功!"; |
| | | mes.count = total; |
| | | mes.data = data.ToList(); |
| | | LogHelper.OperateLog("999", "查询", "查询了计量单位", "PC"); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | #endregion |
| | | |
| | | #region[计量单位新增、编辑保存] |
| | | public static ToMessage AddUpdateTUnit(string menucode, string data_sources, string tunittype, string tunitgroupcode, string OperType, List<Unit> listjson, User us) |
| | | public static ToMessage AddUpdateTUnit(string menucode, string data_sources, string tunitgroupcode, string OperType, List<Unit> listjson, User us) |
| | | { |
| | | string sql = ""; |
| | | List<object> list = new List<object>(); |
| | |
| | | { |
| | | return mes; |
| | | } |
| | | if (tunittype == "S") //单计量 |
| | | { |
| | | |
| | | sql = @"select * from TUnit where isGroup='0' and name=@name"; |
| | | dynamicParams.Add("@name", listjson[0].unitname); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | } |
| | | if (tunittype == "M")//多计量 |
| | | { |
| | | sql = @"select * from TUnitGroup where name=@name"; |
| | | dynamicParams.Add("@name", listjson[0].unitname); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "计量单位组的名称不能重复,请重新输入!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //写入计量单位组 |
| | | sql = @"insert into TUnitGroup(code,name,lm_user,lm_date,data_sources) |
| | | values(@code,@name,@lm_user,@lm_date,@data_sources)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | code = ((List<string>)mes.data)[0].ToString(), |
| | | name = listjson[0].unitname, |
| | | data_sources = data_sources, |
| | | lm_user = us.usercode, |
| | | lm_date = DateTime.Now.ToString() |
| | | } |
| | | }); |
| | | } |
| | | for (int i = 0; i < listjson[0].children.Count; i++) |
| | | { |
| | | //写入计量单位 |
| | |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | code = tunittype == "S" ? ((List<string>)mes.data)[0].ToString() : listjson[0].children[i].unitcode, |
| | | code = listjson[0].children[i].unitcode, |
| | | name = listjson[0].children[i].unitname, |
| | | isMainUnit = listjson[0].children[i].isMainUnit, |
| | | changeRate = listjson[0].children[i].changeRate, |
| | |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "新增", "新增了计量单位:"+ tunittype == "S" ? ((List<string>)mes.data)[0].ToString() : string.Join(",", listjson[0].children.Select(m => m.unitcode)), us.usertype); |
| | | LogHelper.DbOperateLog(us.usercode, "新增", "新增了计量单位:" + string.Join(",", listjson[0].children.Select(m => m.unitcode)), us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "新增操作成功!"; |
| | |
| | | } |
| | | if (OperType == "Update") |
| | | { |
| | | if (tunittype == "S") //单计量 |
| | | { |
| | | sql = @"select * from TUnit where isGroup='0' and code<>@code and name=@name"; |
| | | dynamicParams.Add("@code", listjson[0].unitcode); |
| | | dynamicParams.Add("@name", listjson[0].unitname); |
| | |
| | | } |
| | | |
| | | //更新计量单位(单计量) |
| | | sql = @"update TUnit set name=@name,lm_user=@lm_user,lm_date=@lm_date |
| | | where code=@code and isSingleUnit=@isSingleUnit and isGroup=@isGroup"; |
| | | sql = @"update TUnit set name=@name,lm_user=@lm_user,lm_date=@lm_date,isMainUnit=@isMainUnit,changeRate=@changeRate,rateDescription=@rateDescription,isSingleUnit=@isSingleUnit,disabled=@disabled,idunitgroup=@idunitgroup,isGroup=@isGroup |
| | | where code=@code"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | { |
| | | code = listjson[0].children[0].unitcode, |
| | | name = listjson[0].children[0].unitname, |
| | | isMainUnit = listjson[0].children[0].isMainUnit, |
| | | changeRate = listjson[0].children[0].changeRate, |
| | | rateDescription = listjson[0].children[0].rateDescription, |
| | | isSingleUnit = listjson[0].children[0].isSingleUnit, |
| | | disabled = listjson[0].children[0].disabled, |
| | | idunitgroup = ((List<string>)mes.data)[0].ToString(), |
| | | isGroup = listjson[0].children[0].isGroup, |
| | | lm_user = us.usercode, |
| | | lm_date = DateTime.Now.ToString() |
| | | } |
| | | }); |
| | | |
| | | } |
| | | if (tunittype == "M")//多计量 |
| | | { |
| | | sql = @"select * from TUnitGroup where code<>@code and name=@name"; |
| | | dynamicParams.Add("@code", listjson[0].unitcode); |
| | | dynamicParams.Add("@name", listjson[0].unitname); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "计量单位组的名称不能重复,请重新输入!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //修改计量单位组 |
| | | sql = @"update TUnitGroup set name=@name,lm_user=@lm_user,lm_date=@lm_date where code=@code"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | code = listjson[0].unitcode, |
| | | name = listjson[0].unitname, |
| | | lm_user = us.usercode, |
| | | lm_date = DateTime.Now.ToString() |
| | | } |
| | | }); |
| | | //删除计量单位组明细(从计量单位表删除) |
| | | sql = @"delete TUnit where idunitgroup=@idunitgroup"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | idunitgroup = tunitgroupcode |
| | | } |
| | | }); |
| | | for (int i = 0; i < listjson[0].children.Count; i++) |
| | | { |
| | | //写入计量单位 |
| | | sql = @"insert into TUnit(code,name,isMainUnit,changeRate,rateDescription,isSingleUnit,disabled,idunitgroup,isGroup,data_sources,lm_user,lm_date) |
| | | values(@code,@name,@isMainUnit,@changeRate,@rateDescription,@isSingleUnit,@disabled,@idunitgroup,@isGroup,@data_sources,@lm_user,@lm_date)"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | code = listjson[0].children[i].unitcode, |
| | | name = listjson[0].children[i].unitname, |
| | | isMainUnit = listjson[0].children[i].isMainUnit, |
| | | changeRate = listjson[0].children[i].changeRate, |
| | | rateDescription = listjson[0].children[i].rateDescription, |
| | | isSingleUnit = listjson[0].children[i].isSingleUnit, |
| | | disabled = listjson[0].children[i].disabled, |
| | | idunitgroup = listjson[0].children[i].idunitgroup, |
| | | isGroup = listjson[0].children[i].isGroup, |
| | | data_sources = listjson[0].children[i].data_sources, |
| | | lm_user = us.usercode, |
| | | lm_date = DateTime.Now.ToString() |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "修改", "修改了计量单位:" + tunittype == "S" ? ((List<string>)mes.data)[0].ToString() : string.Join(",", listjson[0].children.Select(m => m.unitcode)), us.usertype); |
| | | LogHelper.DbOperateLog(us.usercode, "修改", "修改了计量单位:" + string.Join(",", listjson[0].children.Select(m => m.unitcode)), us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "修改操作成功!"; |
| | |
| | | #endregion |
| | | |
| | | #region[计量单位删除] |
| | | public static ToMessage DeleteTUnit(string data_sources, string tunittype, string tunitgroupcode, string tunitcode, User us) |
| | | public static ToMessage DeleteTUnit(string data_sources, string tunitgroupcode, string tunitcode, User us) |
| | | { |
| | | string sql = ""; |
| | | List<object> list = new List<object>(); |
| | | var dynamicParams = new DynamicParameters(); |
| | | try |
| | | { |
| | | if (tunittype == "S") //单计量 |
| | | { |
| | | |
| | | sql = @"select * from TMateriel_Info where isSingleUnit='1' and idunit=@idunit"; |
| | | dynamicParams.Add("@idunit", tunitcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | |
| | | return mes; |
| | | } |
| | | //删除计量单位 |
| | | sql = @"delete TUnit where isSingleUnit='1' and isGroup='0' and code=@code and data_sources=@data_sources"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | code = tunitcode, |
| | | data_sources = data_sources |
| | | } |
| | | }); |
| | | } |
| | | if (tunittype == "M" && (tunitgroupcode != "" || tunitgroupcode != null) && (tunitcode == "" || tunitcode == null)) //多计量,且多计量组编码不为空,明细编码为空 |
| | | { |
| | | sql = @"select * from TUnit T |
| | | inner join TMateriel_Info M on T.idunitgroup=M.idunitgroup and T.code=M.idunit |
| | | where T.isSingleUnit='0' and T.idunitgroup=@idunitgroup"; |
| | | dynamicParams.Add("@idunitgroup", tunitgroupcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "多计量单位组中有计量单位被使用,不允许删除!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //删除多计量单位组 |
| | | sql = @"delete TUnitGroup where code=@code and data_sources=@data_sources"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | code = tunitgroupcode, |
| | | data_sources = data_sources |
| | | } |
| | | }); |
| | | //删除多计量单位组下所有计量单位 |
| | | sql = @"delete TUnit where isSingleUnit='0' and isGroup='1' and idunitgroup=@idunitgroup and data_sources=@data_sources"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | | parm = new |
| | | { |
| | | idunitgroup = tunitgroupcode, |
| | | data_sources = data_sources |
| | | } |
| | | }); |
| | | } |
| | | if (tunittype == "M" && (tunitgroupcode != "" && tunitgroupcode != null) && (tunitcode != "" || tunitcode != null)) //多计量,且多计量组编码不为空,明细编码不为空 |
| | | { |
| | | sql = @"select * from TUnit T |
| | | inner join TMateriel_Info M on T.idunitgroup=M.idunitgroup and T.code=M.idunit |
| | | where T.isSingleUnit='0' and M.isSingleUnit='0' and T.idunitgroup=@idunitgroup and T.code=@idunit"; |
| | | dynamicParams.Add("@idunitgroup", tunitgroupcode); |
| | | dynamicParams.Add("@idunit", tunitcode); |
| | | var data = DapperHelper.selectdata(sql, dynamicParams); |
| | | if (data.Rows.Count > 0) |
| | | { |
| | | mes.code = "300"; |
| | | mes.count = 0; |
| | | mes.message = "多计量单位已被使用,不允许删除!"; |
| | | mes.data = null; |
| | | return mes; |
| | | } |
| | | //删除多计量单位组下指定计量单位 |
| | | sql = @"delete TUnit where isSingleUnit='0' and isGroup='1' and idunitgroup=@idunitgroup and code=@code and data_sources=@data_sources"; |
| | | sql = @"delete TUnit where idunitgroup=@idunitgroup and code=@code and data_sources=@data_sources"; |
| | | list.Add(new |
| | | { |
| | | str = sql, |
| | |
| | | data_sources = data_sources |
| | | } |
| | | }); |
| | | } |
| | | bool aa = DapperHelper.DoTransaction(list); |
| | | if (aa) |
| | | { |
| | | //写入操作记录表 |
| | | LogHelper.DbOperateLog(us.usercode, "新增", "新增了计量单位:" + tunittype == "S" ? tunitcode : tunittype == "M"&& (tunitgroupcode != "" || tunitgroupcode != null) && (tunitcode == "" || tunitcode == null)? tunitgroupcode: tunitgroupcode+"-->"+tunitcode, us.usertype); |
| | | LogHelper.DbOperateLog(us.usercode, "删除", "删除了计量单位:"+tunitcode, us.usertype); |
| | | mes.code = "200"; |
| | | mes.count = 0; |
| | | mes.message = "删除操作成功!"; |