/// <summary> /// 采集-保存并发送指令 /// </summary> /// <param name="Cmd"></param> /// <param name="Mm_id"></param> /// <param name="ModuleName">型号名称</param> /// <param name="ModuleType">型号</param> /// <param name="Disabled">是否弃用</param> /// <param name="ModulePwd">编程密码</param> /// <param name="ModuleUid">编程操作人</param> /// <param name="Level">密码级别</param> /// <param name="Spec">接线方式</param> /// <param name="Fty_prod">生产厂家</param> /// <param name="IsCharg">计费方式</param> /// <param name="Protocol">协议类型</param> /// <param name="Pmap"></param> /// <returns></returns> public APIRst SetYdModelsOnSave(int Cmd, int Mm_id, string ModuleName, string ModuleType, int Disabled, string ModulePwd, string ModuleUid, string Level, string Spec, string Fty_prod, int IsCharg, string Protocol, string Pmap) { APIRst rst = new APIRst(); try { v0_moduleVModel mm = new v0_moduleVModel(); mm.Mm_id = Mm_id; mm.ModuleName = ModuleName; mm.ModuleType = ModuleType; mm.Disabled = Disabled; mm.ModulePwd = ModulePwd == "undefined" || ModulePwd == "null" || ModulePwd == "{ModulePwd}" ? null : ModulePwd; mm.ModuleUid = ModuleUid == "undefined" || ModuleUid == "null" || ModuleUid == "{ModuleUid}" ? null : ModuleUid; mm.Level = Level == "undefined" || Level == "null" || Level == "{Level}" ? null : Level; mm.Spec = Spec == "undefined" || Spec == "null" || Spec == "{Spec}" ? null : Spec; mm.Fty_prod = Fty_prod == "undefined" || Fty_prod == "null" || Fty_prod == "{Fty_prod}" ? null : Fty_prod; mm.IsCharg = IsCharg; mm.Protocol = Protocol; if (string.IsNullOrEmpty(mm.ModuleType)) { throw new Exception("型号不能为空"); } if (string.IsNullOrEmpty(mm.ModuleName)) { throw new Exception("型号名称不能为空"); } int cmdNum = 0; DataTable dtSource = JsonHelper.ToDataTable(Pmap); bll.SetYdModelsOnSave(mm, dtSource); if (Cmd == 1) { DataTable dtCmd = bll.GetYdModelsSendCmd(mm.Mm_id); cmdNum = dtCmd.Rows.Count; this.GetYdModelsSendCmd(dtCmd); } DataTable dtNew = bll.GetYdModelsOnList(mm.Mm_id); var res1 = from s1 in dtNew.AsEnumerable() select new { RowId = dtSource.Rows.IndexOf(s1) + 1, Mm_id = CommFunc.ConvertDBNullToInt32(s1["Mm_id"]), ModuleType = CommFunc.ConvertDBNullToString(s1["ModuleType"]), ModuleName = CommFunc.ConvertDBNullToString(s1["ModuleName"]), Spec = CommFunc.ConvertDBNullToString(s1["Spec"]), Fty_prod = CommFunc.ConvertDBNullToString(s1["Fty_prod"]), IsCharg = CommFunc.ConvertDBNullToInt32(s1["IsCharg"]), ModulePwd = CommFunc.ConvertDBNullToString(s1["ModulePwd"]), ModuleUid = CommFunc.ConvertDBNullToString(s1["ModuleUid"]), Level = CommFunc.ConvertDBNullToString(s1["Level"]), Disabled = CommFunc.ConvertDBNullToInt32(s1["Disabled"]), }; rst.data = res1.ToList(); } catch (Exception ex) { rst.rst = false; rst.err.code = (int)ResultCodeDefine.Error; rst.err.msg = ex.Message; FileLog.WriteLog("采集-保存并发送指令错误:" + ex.Message + ex.StackTrace); } return(rst); }
public int SetYdModelsOnSave(v0_moduleVModel mm, DataTable v0_fun) { StringBuilder strSql = new StringBuilder(); strSql.Clear(); DataTable obj = null; strSql.Append("select count(*) from v0_module where Ledger=@Ledger and Mm_id!=@Mm_id and ModuleType=@ModuleType"); obj = SQLHelper.Query(strSql.ToString(), new { Ledger = this.Ledger, Mm_id = mm.Mm_id, ModuleType = mm.ModuleType }); int cnt = 0; if (CommFunc.ConvertDBNullToInt32(obj.Rows[0]["count(*)"]) > 0) { throw new Exception("已存在此型号:" + mm.ModuleType); } if (mm.Mm_id == 0) { strSql.Clear(); strSql.Append("select max(Mm_id) from v0_module where Ledger=@Ledger"); obj = SQLHelper.Query(strSql.ToString(), new { Ledger = this.Ledger }); mm.Mm_id = obj.Rows.Count > 0 ? CommFunc.ConvertDBNullToInt32(obj.Rows[0]["max(Mm_id)"]) + 1 : 1; //mm.Mm_id = CommFunc.ConvertDBNullToInt32(obj.Rows[0]["max(Mm_id)"]) + 1; // 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,@ModulePwd,@ModuleUid,@Level,@Spec,@Fty_prod,@IsCharg,@Protocol)"); cnt = cnt + SQLHelper.Execute(strSql.ToString(), new { Ledger = this.Ledger, Mm_id = mm.Mm_id, ModuleName = mm.ModuleName, ModuleType = mm.ModuleType, Disabled = mm.Disabled, ModulePwd = mm.ModulePwd, ModuleUid = mm.ModuleUid, Level = mm.Level, Spec = mm.Spec, Fty_prod = mm.Fty_prod, IsCharg = mm.IsCharg, Protocol = mm.Protocol }); } else { strSql.Clear(); strSql.Append("update v0_module set "); strSql.Append("ModuleName=@ModuleName,"); strSql.Append("ModuleType=@ModuleType,"); strSql.Append("Disabled=@Disabled,"); strSql.Append("ModulePwd=@ModulePwd,"); strSql.Append("ModuleUid=@ModuleUid,"); strSql.Append("Level=@Level,"); strSql.Append("Spec=@Spec,"); strSql.Append("Fty_prod=@Fty_prod,"); strSql.Append("IsCharg=@IsCharg,"); strSql.Append("Protocol=@Protocol"); strSql.Append(" where Ledger=@Ledger and Mm_id=@Mm_id;"); cnt = cnt + SQLHelper.Execute(strSql.ToString(), new { Ledger = this.Ledger, Mm_id = mm.Mm_id, ModuleName = mm.ModuleName, ModuleType = mm.ModuleType, Disabled = mm.Disabled, ModulePwd = mm.ModulePwd, ModuleUid = mm.ModuleUid, Level = mm.Level, Spec = mm.Spec, Fty_prod = mm.Fty_prod, IsCharg = mm.IsCharg, Protocol = mm.Protocol }); } foreach (DataRow dr in v0_fun.Rows) { dr["Mm_id"] = mm.Mm_id; int action = CommFunc.ConvertDBNullToInt32(dr["Action"]); if (action != 1) { dr["DataValue"] = ""; } else { if (CommFunc.ConvertDBNullToString(dr["FunType"]).Equals(V0Fun.IsRelay.ToString())) { if (CommFunc.ConvertDBNullToInt32(dr["DataValue"]) >= 2) { dr["DataValue"] = "129"; } else { dr["DataValue"] = CommFunc.ConvertDBNullToInt32(dr["DataValue"]); } } } cnt = cnt + this.YdModelsOnSaveInFun(dr); } return(cnt); }
public int SetYdModelsOnSave(v0_moduleVModel mm, DataTable v0_fun) { return(dal.SetYdModelsOnSave(mm, v0_fun)); }