コード例 #1
0
        public int UpdateEspInfo(v1_gateway_espVModel Esp, out string msg)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Clear();
            DataTable obj = new DataTable();

            msg = "";
            if (Esp.Esp_id == 0)
            {
                strSql.Clear();
                strSql.Append("select max(Esp_id) as cnt from v1_gateway_esp where Ledger=@Ledger");
                obj        = SQLHelper.Query(strSql.ToString(), new { Ledger = this.Ledger });
                Esp.Esp_id = obj.Rows.Count > 0 ? CommFunc.ConvertDBNullToInt32(obj.Rows[0]["cnt"]) + 1 : 1;
            }
            obj = null;
            strSql.Clear();
            strSql.Append("select count(*) as cnt from v1_gateway_esp where Ledger=@Ledger and Esp_id!=@Esp_id and Gw_id=@Gw_id and (EspName=@EspName or EspAddr=@EspAddr)");
            obj = SQLHelper.Query(strSql.ToString(), new { Ledger = this.Ledger, Esp_id = Esp.Esp_id, Gw_id = Esp.Gw_id, EspName = Esp.EspName, EspAddr = Esp.EspAddr });
            if (CommFunc.ConvertDBNullToInt32(obj.Rows[0]["cnt"]) > 0)
            {
                msg = "采集器名称" + Esp.EspName + "或地址" + Esp.EspAddr + "重复";
                throw new Exception("采集器名称" + Esp.EspName + "或地址" + Esp.EspAddr + "重复");
            }

            obj = null;
            strSql.Clear();
            strSql.Append("select GwIp from v1_gateway where Ledger=@Ledger and Gw_id=@Gw_id");
            obj = SQLHelper.Query(strSql.ToString(), new { Ledger = this.Ledger, Gw_id = Esp.Gw_id });
            string EspIp = CommFunc.ConvertDBNullToString(obj.Rows[0]["GwIp"]);

            strSql.Clear();
            strSql.Append("insert into v1_gateway_esp(");
            strSql.Append("Ledger,Esp_id,Gw_id,EspName,EspAddr,TransferType,EspIp,EspPort,Timeout,EspType,ComPort,Baud,DataBit,StopBit,Parity,Inst_loc,Remark,Create_by,Create_dt,Update_by,Update_dt)");
            strSql.Append(" values (");
            strSql.Append("@Ledger,@Esp_id,@Gw_id,@EspName,@EspAddr,@TransferType,@EspIp,@EspPort,1000,'',@ComPort,@Baud,@DataBit,@StopBit,@Parity,'','',@SysUid,now(),@SysUid,now())");
            strSql.Append(" ON DUPLICATE KEY UPDATE EspAddr=@EspAddr,TransferType=@TransferType,EspIp=@EspIp,EspPort=@EspPort,ComPort=@ComPort,Baud=@Baud,DataBit=@DataBit,StopBit=@StopBit,Parity=@Parity,Update_by=@SysUid,Update_dt=now();");
            SQLHelper.Execute(strSql.ToString(), new { Ledger = this.Ledger, Esp_id = Esp.Esp_id, Gw_id = Esp.Gw_id, EspName = Esp.EspName, EspAddr = Esp.EspAddr, TransferType = Esp.TransferType, EspIp = EspIp, EspPort = Esp.EspPort, ComPort = Esp.ComPort, Baud = Esp.Baud, DataBit = Esp.DataBit, StopBit = Esp.StopBit, Parity = Esp.Parity, SysUid = this.SysUid });
            return(Esp.Esp_id);
        }
コード例 #2
0
ファイル: ExpYdModuleHelper.cs プロジェクト: ZQuanLi/Test
        /// <summary>
        /// 保存采集器数据
        /// </summary>
        /// <param name="ComPortNum"></param>
        /// <param name="ep">对象:Esp_id=采集器编号,Gw_id=集中器序号,EspName=采集器名称,EspAddr=采集器地址,TransferType=通讯方式,Baud=波特率,DataBit=数据位,StopBit=停止位,Parity=校验方式,EspPort=端口,Timeout=超时秒,Inst_loc=安装位置,Remark=备注</param>
        /// <returns></returns>
        public APIRst YdModuleOnSaveEsp(int ComPortNum, v1_gateway_espVModel ep)
        {
            APIRst rst = new APIRst();

            try
            {
                if (ep.TransferType == 0)
                {
                    ep.ComPort = "COM" + ComPortNum;//COM口
                }
                else
                {
                    ep.ComPort = "";
                }

                if (ep.Gw_id == 0)
                {
                    throw new Exception("所属集中器错误");
                }
                if (string.IsNullOrEmpty(ep.EspName))
                {
                    throw new Exception("采集器名称不能为空");
                }

                int espid = bll.IsExistYdEspName(ep.Gw_id, ep.Esp_id, ep.EspName, ep.Esp_id > 0);

                if (espid > 0 && (ep.Esp_id == 0 || (ep.Esp_id > 0 && ep.Esp_id != espid)))
                {
                    throw new Exception("采集器名称" + ep.EspName + "重复,请查询后再操作");
                }
                if (string.IsNullOrEmpty(ep.EspAddr))
                {
                    throw new Exception("采集器地址不能为空");
                }
                if (ep.Timeout == 0)
                {
                    throw new Exception("采集器延时设置(毫秒)不能为零");
                }
                if (ep.TransferType == 0 && ComPortNum == 0)
                {
                    throw new Exception("通讯方式为COM口,不能为空");
                }
                if (ep.TransferType != 0 && ep.EspPort == 0)
                {
                    throw new Exception("通讯方式为网络方式,TCP端口不能为空");
                }

                int total = 0;
                bll.YdModuleOnSaveEsp(ep);
                object rows = this.GetYdModuleOnDetail(0, ep.Esp_id, 0, 0, out total);

                object obj = new { total = total, rows = rows };
                rst.data = obj;
            }
            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);
        }
コード例 #3
0
        /// <summary>
        /// 设置采集器信息
        /// </summary>
        /// <param name="Esp"></param>
        /// <returns></returns>
        public int YdModuleOnSaveEsp(v1_gateway_espVModel Esp)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Clear();
            DataTable obj = new DataTable();

            if (Esp.Esp_id == 0)
            {
                strSql.Clear();
                strSql.Append("select max(Esp_id) as cnt from v1_gateway_esp where Ledger=@Ledger");
                obj        = SQLHelper.Query(strSql.ToString(), new { Ledger = this.Ledger });
                Esp.Esp_id = obj.Rows.Count > 0 ? CommFunc.ConvertDBNullToInt32(obj.Rows[0]["cnt"]) + 1 : 1;
                //Esp.Esp_id = CommFunc.ConvertDBNullToInt32(obj.Rows[0]["cnt"]) + 1;
                //Gw.Gw_id = CommFunc.ConvertDBNullToInt32(SQLUtilities.ExecuteScalar(strSql.ToString(), params01)) + 1;
                //params01[1].Value = Gw.Gw_id;
                strSql.Clear();
                strSql.Append("insert into v1_gateway_esp(");
                strSql.Append("Ledger,Esp_id,Gw_id,EspName,EspAddr,TransferType,EspIp,EspPort,Timeout,EspType,ComPort,Baud,DataBit,StopBit,Parity,Inst_loc,Remark,Create_by,Create_dt,Update_by,Update_dt)");
                strSql.Append(" values (");
                strSql.Append("@Ledger,@Esp_id,@Gw_id,@EspName,@EspAddr,@TransferType,@EspIp,@EspPort,@Timeout,@EspType,@ComPort,@Baud,@DataBit,@StopBit,@Parity,@Inst_loc,@Remark,@Uid,now(),@Uid,now())");
                if (SQLHelper.Execute(strSql.ToString(), new { Ledger = this.Ledger, Esp_id = Esp.Esp_id, Gw_id = Esp.Gw_id, EspName = Esp.EspName, EspAddr = Esp.EspAddr, TransferType = Esp.TransferType, EspIp = Esp.EspIp, EspPort = Esp.EspPort, Timeout = Esp.Timeout, EspType = Esp.EspType, ComPort = Esp.ComPort, Uid = this.SysUid, Baud = Esp.Baud, DataBit = Esp.DataBit, StopBit = Esp.StopBit, Parity = Esp.Parity, Inst_loc = Esp.Inst_loc, Remark = Esp.Remark }) > 0)
                {
                    return(Esp.Esp_id);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                strSql.Clear();
                strSql.Append("update v1_gateway_esp set ");
                strSql.Append("EspName=@EspName,");
                strSql.Append("EspAddr=@EspAddr,");
                strSql.Append("TransferType=@TransferType,");
                strSql.Append("EspIp=@EspIp,");
                strSql.Append("EspPort=@EspPort,");
                strSql.Append("Timeout=@Timeout,");
                strSql.Append("EspType=@EspType,");
                strSql.Append("ComPort=@ComPort,");
                strSql.Append("Baud=@Baud,");
                strSql.Append("DataBit=@DataBit,");
                strSql.Append("StopBit=@StopBit,");
                strSql.Append("Parity=@Parity,");
                strSql.Append("Inst_loc=@Inst_loc,");
                strSql.Append("Remark=@Remark,");
                strSql.Append("Disabled=@Disabled,");
                strSql.Append("Update_by=@Uid,");
                strSql.Append("Update_dt=now()");
                strSql.Append(" where Ledger=@Ledger and Esp_id=@Esp_id ");
                if (SQLHelper.Execute(strSql.ToString(), new { Ledger = this.Ledger, Esp_id = Esp.Esp_id, EspName = Esp.EspName, EspAddr = Esp.EspAddr, TransferType = Esp.TransferType, EspIp = Esp.EspIp, EspPort = Esp.EspPort, Timeout = Esp.Timeout, EspType = Esp.EspType, ComPort = Esp.ComPort, Uid = this.SysUid, Baud = Esp.Baud, DataBit = Esp.DataBit, StopBit = Esp.StopBit, Parity = Esp.Parity, Inst_loc = Esp.Inst_loc, Remark = Esp.Remark, Disabled = string.IsNullOrEmpty(Esp.Disabled.ToString()) ? 0 : Esp.Disabled }) > 0)
                {
                    return(Esp.Esp_id);
                }
                else
                {
                    return(0);
                }
            }
        }
コード例 #4
0
ファイル: ExpYdModuleBLL.cs プロジェクト: ZQuanLi/Test
 /// <summary>
 /// 设置采集器信息
 /// </summary>
 /// <param name="Gw"></param>
 /// <returns></returns>
 public int YdModuleOnSaveEsp(v1_gateway_espVModel Esp)
 {
     return(dal.YdModuleOnSaveEsp(Esp));
 }
コード例 #5
0
        private int EspInfo(DataRow dr, int gw_id)
        {
            v1_gateway_espVModel vm = new v1_gateway_espVModel
            {
                EspAddr      = CommFunc.ConvertDBNullToString(dr["EspAddr"]),
                EspName      = CommFunc.ConvertDBNullToString(dr["EspName"]),
                TransferType = CommFunc.ConvertDBNullToInt32(dr["TransferType"]),
                EspPort      = CommFunc.ConvertDBNullToInt32(dr["EspPort"]),
                ComPort      = CommFunc.ConvertDBNullToString(dr["ComPort"]),
                Baud         = CommFunc.ConvertDBNullToInt32(dr["Baud"]),
                DataBit      = CommFunc.ConvertDBNullToInt32(dr["DataBit"]),
                Parity       = CommFunc.ConvertDBNullToInt32(dr["Parity"]),
                StopBit      = CommFunc.ConvertDBNullToInt32(dr["StopBit"]),
            };
            string msg    = "";
            bool   isUp   = false;
            int    esp_id = 0;
            //更新
            DataTable dtMdInfo = dal.GetEspInfo(gw_id, vm.EspName);

            DataRow[] arr = dtMdInfo.Select();
            if (arr.Count() > 0)
            {
                esp_id = CommFunc.ConvertDBNullToInt32(arr[0]["Esp_id"]);
                if (!vm.EspName.Equals(CommFunc.ConvertDBNullToString(arr[0]["EspName"])))
                {
                    isUp = true;
                }
                else if (vm.TransferType != CommFunc.ConvertDBNullToInt32(arr[0]["TransferType"]))
                {
                    isUp = true;
                }
                else if (vm.EspPort != CommFunc.ConvertDBNullToInt32(arr[0]["EspPort"]))
                {
                    isUp = true;
                }
                else if (!vm.ComPort.Equals(CommFunc.ConvertDBNullToString(arr[0]["ComPort"])))
                {
                    isUp = true;
                }
                else if (vm.Baud != CommFunc.ConvertDBNullToInt32(arr[0]["Baud"]))
                {
                    isUp = true;
                }
                else if (vm.DataBit != CommFunc.ConvertDBNullToInt32(arr[0]["DataBit"]))
                {
                    isUp = true;
                }
                else if (vm.Parity != CommFunc.ConvertDBNullToInt32(arr[0]["Parity"]))
                {
                    isUp = true;
                }
                else if (vm.StopBit != CommFunc.ConvertDBNullToInt32(arr[0]["StopBit"]))
                {
                    isUp = true;
                }
            }
            else
            {
                isUp = true;
            }
            vm.Gw_id  = gw_id;
            vm.Esp_id = esp_id;
            if (isUp == true)
            {
                esp_id = dal.UpdateEspInfo(vm, out msg);
                if (esp_id == 0)
                {
                    dr["ErrCode"] = -1;
                    dr["ErrTxt"]  = msg;
                }
            }
            return(vm.Esp_id);
        }
コード例 #6
0
 public APIRst SetYdModuleOnSaveEsp(int ComPortNum, v1_gateway_espVModel ep)
 {
     return(infoHelper.YdModuleOnSaveEsp(ComPortNum, ep));
 }