/// <summary> /// 设置设备类型 /// </summary> /// <returns></returns> public APIResult SetMm(MeterTypeVModel mmType) { APIResult rst = new APIResult(); try { DataTable dtFun = this.GetMmFunTypeList(mmType.ModuleTypeId, mmType.ModuleType); bll.SetMm(mmType, dtFun); rst.Code = 0; rst.Msg = ""; rst.Data = this.GetMmList(mmType.ModuleTypeId, ""); } catch (Exception ex) { rst.Code = -1; rst.Msg = ex.Message; FileLog.WriteLog("获取设备类型列表信息错误(GetMmList):" + ex.Message + ex.StackTrace); } return(rst); }
/// <summary> /// 设置设备类型 /// </summary> /// <param name="mmType">设备信息</param> /// <param name="v0_fun"></param> /// <returns></returns> public int SetMm(MeterTypeVModel mmType, DataTable v0_fun) { StringBuilder strSql = new StringBuilder(); strSql.Clear(); strSql.Append("select count(*) from v0_module where Ledger=@Ledger and Mm_id!=@Mm_id and ModuleType=@ModuleType"); object obj = SQLHelper.ExecuteScalar(strSql.ToString(), new { Ledger = this.Ledger, Mm_id = mmType.ModuleTypeId, ModuleType = mmType.ModuleType }); if (CommFunc.ConvertDBNullToInt32(obj) > 0) { throw new Exception("已存在此型号:" + mmType.ModuleType); } if (mmType.ModuleTypeId == 0) { strSql.Clear(); strSql.Append("select max(Mm_id) from v0_module where Ledger=@Ledger "); obj = SQLHelper.ExecuteScalar(strSql.ToString(), new { Ledger = this.Ledger }); mmType.ModuleTypeId = CommFunc.ConvertDBNullToInt32(obj) + 1; } object params01 = new { Ledger = this.Ledger, Mm_id = mmType.ModuleTypeId, ModuleName = mmType.ModuleName, ModuleType = mmType.ModuleType, Disabled = mmType.Disabled, Spec = mmType.Spec, Fty_prod = mmType.Fty_prod }; strSql.Clear(); strSql.Append("insert into v0_module("); strSql.Append("Ledger,Mm_id,ModuleName,ModuleType,Disabled,ModulePwd,ModuleUid,Level,Spec,Fty_prod,IsCharg,Protocol)"); strSql.Append(" values ("); strSql.Append("@Ledger,@Mm_id,@ModuleName,@ModuleType,@Disabled,'','','',@Spec,@Fty_prod,0,'')"); strSql.Append("ON DUPLICATE KEY UPDATE ModuleName=@ModuleName,ModuleType=@ModuleType,Disabled=@Disabled,Spec=@Spec,Fty_prod=@Fty_prod;"); int cnt = SQLHelper.Execute(strSql.ToString(), params01); //////////////////////////////////////////////////// foreach (DataRow dr in v0_fun.Rows) { strSql.Clear(); strSql.Append("select count(*) from v0_fun where Ledger=@Ledger and Fun_id!=@Fun_id and Mm_id=@Mm_id and FunType=@FunType"); obj = SQLHelper.ExecuteScalar(strSql.ToString(), new { Ledger = this.Ledger, Fun_id = CommFunc.ConvertDBNullToInt32(dr["Fun_id"]), Mm_id = mmType.ModuleTypeId, FunType = CommFunc.ConvertDBNullToString(dr["FunType"]) }); if (CommFunc.ConvertDBNullToInt32(obj) > 0) { continue; } //throw new Exception("已存在此型号功能码:" + CommFunc.ConvertDBNullToString(dr["FunType"])); // int fun_id = CommFunc.ConvertDBNullToInt32(dr["Fun_id"]); if (fun_id == 0) { strSql.Clear(); strSql.Append("select max(Fun_id)as cnt from v0_fun where Ledger=@Ledger"); obj = SQLHelper.ExecuteScalar(strSql.ToString(), new { Ledger = this.Ledger }); fun_id = CommFunc.ConvertDBNullToInt32(obj) + 1; dr["Fun_id"] = fun_id; } object params_fn = new { Ledger = this.Ledger, Fun_id = fun_id, Mm_id = mmType.ModuleTypeId, FunName = CommFunc.ConvertDBNullToString(dr["FunName"]), FunType = CommFunc.ConvertDBNullToString(dr["FunType"]), Action = CommFunc.ConvertDBNullToInt32(dr["Action"]), DataValue = CommFunc.ConvertDBNullToString(dr["DataValue"]), DataType = CommFunc.ConvertDBNullToInt32(dr["DataType"]), Scale = CommFunc.ConvertDBNullToInt32(dr["Scale"]), Disabled = CommFunc.ConvertDBNullToInt32(dr["Disabled"]), OrdNo = CommFunc.ConvertDBNullToInt32(dr["OrdNo"]), OrdGrp = CommFunc.ConvertDBNullToInt32(dr["OrdGrp"]), Unit = CommFunc.ConvertDBNullToString(dr["Unit"]), PointType = CommFunc.ConvertDBNullToInt32(dr["PointType"]), AlarmModel = CommFunc.ConvertDBNullToInt32(dr["AlarmModel"]), SubTab = CommFunc.ConvertDBNullToString(dr["SubTab"]), }; strSql.Clear(); strSql.Append("insert into v0_fun("); strSql.Append("Ledger,Fun_id,Mm_id,FunName,FunType,Action,DataValue,DataType,Scale,Disabled,OrdNo,OrdGrp,Unit,PointType,AlarmModel,SubTab)"); strSql.Append(" values ("); strSql.Append("@Ledger,@Fun_id,@Mm_id,@FunName,@FunType,@Action,@DataValue,@DataType,@Scale,@Disabled,@OrdNo,@OrdGrp,@Unit,@PointType,@AlarmModel,@SubTab)"); strSql.Append(" ON DUPLICATE KEY UPDATE FunName=@FunName,DataType=@DataType,OrdNo=@OrdNo,OrdGrp=@OrdGrp,Unit=@Unit,PointType=@PointType,AlarmModel=@AlarmModel"); cnt = cnt + SQLHelper.Execute(strSql.ToString(), params_fn); } return(cnt); }
/// <summary> /// 设置设备类型 /// </summary> /// <param name="mmType">设备信息</param> /// <param name="v0_fun"></param> /// <returns></returns> public int SetMm(MeterTypeVModel mmType, DataTable v0_fun) { return(dal.SetMm(mmType, v0_fun)); }
public APIResult SetMeterType(MeterTypeVModel meterType) { return(baseInfoHelper.SetMm(meterType)); }
public APIResult AddMeterType(MeterTypeVModel meterType) { meterType.ModuleTypeId = 0; return(baseInfoHelper.SetMm(meterType)); }