Esempio n. 1
0
        /// <summary>
        /// 添加站点,不用
        /// </summary>
        //private void Add(CEntityStation entity)
        //{
        //    String sqlStr = GetInsertSQL(entity);
        //    ExecuteNonQuery(sqlStr);
        //}

        //private String GetInsertSQL(CEntityStation entity)
        //{
        //    String strStationID = entity.StationID;
        //    String strSubCenterID = entity.SubCenterID.HasValue ? entity.SubCenterID.Value.ToString() : "null";
        //    String strCName = String.Format("'{0}'", entity.StationName);
        //    String strCType = CEnumHelper.StationTypeToDBStr(entity.StationType);

        //    String strWaterBase = entity.DWaterBase.HasValue ? entity.DWaterBase.ToString() : "null";
        //    String strWaterMax = entity.DWaterMax.HasValue ? entity.DWaterMax.ToString() : "null";
        //    String strWaterMin = entity.DWaterMin.HasValue ? entity.DWaterMin.ToString() : "null";
        //    String strWaterChange = entity.DWaterChange.HasValue ? entity.DWaterChange.ToString() : "null";

        //    String strRainAccuracy = entity.DRainAccuracy.ToString();
        //    String strRainChange =entity.DRainChange.ToString();
        //    String strCommParam = entity.CommParam == null ? "null" : String.Format("'{0}'", entity.CommParam);
        //    String strGSM = entity.GSM == null ? "null" : String.Format("'{0}'", entity.GSM);

        //    String strGprs = entity.GPRS == null ? "null" : String.Format("'{0}'", entity.GPRS);
        //    String strPstv = entity.PSTV == null ? "null" : String.Format("'{0}'", entity.PSTV);
        //    String strBD = entity.BDSatellite == null ? "null" : String.Format("'{0}'", entity.BDSatellite);
        //    String strSerialPort = entity.SerialPort == null ? "null" : String.Format("'{0}'", entity.SerialPort);
        //    return String.Format(
        //        "INSERT INTO {0} ([{1}],[{2}],[{3}],[{4}],[{5}],[{6}],[{7}],[{8}],[{9}],[{10}],[{11}],[{12}],[{13}],[{14}],[{15}],[{16}]) VALUES ({17},{18},{19},{20},{21},{22},{23},{24},{25},{26},{27},{28},{29},{30},{31},{32})",

        //        CT_TableName,

        //        CN_StationID, CN_SubCenterID, CN_StationName, CN_StationType,
        //        CN_WaterBase, CN_WaterMax, CN_WaterMin, CN_WaterChange,
        //        CN_RainAccuracy, CN_RainChange, CN_CommParam, CN_GSM,
        //        CN_GPRS, CN_PSTV, CN_BDSatellite, CN_SerialPort,

        //        strStationID, strSubCenterID, strCName, strCType,
        //        strWaterBase, strWaterMax, strWaterMin, strWaterChange,
        //        strRainAccuracy, strRainChange, strCommParam, strGSM,
        //        strGprs, strPstv, strBD, strSerialPort
        //    );
        //}

        ///// <summary>
        ///// 删除分站点
        ///// </summary>
        //public void Delete(CEntityStation entity)
        //{
        //    String sqlStr = GetDeleteSQL(entity);
        //    ExecuteNonQuery(sqlStr);
        //}

        //private String GetDeleteSQL(CEntityStation entity)
        //{
        //    return String.Format("DELETE FROM {0} WHERE [{1}]={2}",
        //        CT_TableName,

        //        CN_StationID, entity.StationID
        //    );
        //}

        /// <summary>
        /// 修改站点信息
        /// </summary>
        //public void Update(CEntityStation entity)
        //{
        //    String sqlStr = GetUpdateSQL(entity);
        //    ExecuteNonQuery(sqlStr);
        //}

        private String GetUpdateSQL(CEntityStation entity)
        {
            String strStationID   = entity.StationID;
            String strSubCenterID = entity.SubCenterID.HasValue ? entity.SubCenterID.Value.ToString() : "null";
            String strCName       = String.Format("'{0}'", entity.StationName);
            String strCType       = CEnumHelper.StationTypeToDBStr(entity.StationType);

            String strWaterBase   = entity.DWaterBase.HasValue ? entity.DWaterBase.ToString() : "null";
            String strWaterMax    = entity.DWaterMax.HasValue ? entity.DWaterMax.ToString() : "null";
            String strWaterMin    = entity.DWaterMin.HasValue ? entity.DWaterMin.ToString() : "null";
            String strWaterChange = entity.DWaterChange.HasValue ? entity.DWaterChange.ToString() : "null";
            String strVoltageMin  = entity.DVoltageMin.HasValue ? entity.DVoltageMin.ToString() : "null";

            String strRainAccuracy = entity.DRainAccuracy.ToString();
            String strRainChange   = entity.DRainChange.HasValue ? entity.DRainChange.ToString() : "null";

            String strGSM  = entity.GSM == null ? "null" : String.Format("'{0}'", entity.GSM);
            String strGprs = entity.GPRS == null ? "null" : String.Format("'{0}'", entity.GPRS);

            String strBD       = entity.BDSatellite == null ? "null" : String.Format("'{0}'", entity.BDSatellite);
            String strBDMember = entity.BDMemberSatellite == null ? "null" : String.Format("'{0}'", entity.BDMemberSatellite);

            String strMaintran       = entity.Maintran == null ? "null" : String.Format("'{0}'", entity.Maintran);
            String strSubtran        = entity.Subtran == null ? "null" : String.Format("'{0}'", entity.Subtran);
            String strDataprotocol   = entity.Datapotocol == null ? "null" : String.Format("'{0}'", entity.Datapotocol);
            String strWatersensor    = entity.Watersensor == null ? "null" : String.Format("'{0}'", CEnumHelper.WaterSensorTypeToDBStr(entity.Watersensor));
            String strRainsensor     = entity.Rainsensor == null ? "null" : String.Format("'{0}'", CEnumHelper.RainSensorTypeToDBStr(entity.Rainsensor));
            String strReportinterval = entity.Reportinterval == null ? "null" : String.Format("'{0}'", entity.Reportinterval);

            //  String strSerialPort = entity.SerialPort == null ? "null" : String.Format("'{0}'", entity.SerialPort);

            //  string strBatchType = CEnumHelper.StationBatchTypeToDBStr(entity.BatchTranType);

            return(String.Format(
                       "UPDATE {0} SET [{1}]={2},[{3}]={4},[{5}]={6},[{7}]={8},[{9}]={10},[{11}]={12},[{13}]={14},[{15}]={16},[{17}]={18},[{19}]={20},[{21}]={22},[{23}]={24},[{25}]={26},[{27}]={28},[{29}]={30},[{31}]={32},[{33}]={34} ,[{35}]={36},[{37}]={38},[{39}]={40} WHERE [{41}]='{42}';",
                       CT_TableName,

                       CN_SubCenterID, strSubCenterID,
                       CN_StationName, strCName,
                       CN_StationType, strCType,
                       CN_WaterBase, strWaterBase,
                       CN_WaterMax, strWaterMax,
                       CN_WaterMin, strWaterMin,
                       CN_WaterChange, strWaterChange,
                       CN_RainAccuracy, strRainAccuracy,
                       CN_RainChange, strRainChange,
                       CN_GSM, strGSM,
                       CN_GPRS, strGprs,
                       CN_BDSatellite, strBD,
                       CN_BDMember, strBDMember,
                       CN_VoltageMin, strVoltageMin,
                       CN_Maintran, strMaintran,
                       CN_Subtran, strSubtran,
                       CN_Dataprotocol, strDataprotocol,
                       CN_Watersensor, strWatersensor,
                       CN_Rainsensor, strRainsensor,
                       CN_Reportinterval, strReportinterval,
                       CN_StationID, strStationID
                       ));
        }
        /// <summary>
        /// 更新一系列站点的配置数据
        /// </summary>
        /// <param name="listStation"></param>
        /// <returns></returns>
        public bool UpdateSoilStation(List <CEntitySoilStation> listStation)
        {
            if (listStation.Count <= 0)
            {
                return(true);
            }
            StringBuilder sql = new StringBuilder();
            int           currentBatchCount = 0;

            for (int i = 0; i < listStation.Count; i++)
            {
                ++currentBatchCount;
                string formatstr = "update {0} set " + GenerateSQL(34, 1) + " , {69}='{70}' ,{71}='{72}' ,{73}='{74}' , {75}='{76}' ,{77}='{78}',  "
                                   + " {79}='{80}' , {81}='{82}' , {83}='{84}' "
                                   + " where {85} = {86};";
                sql.AppendFormat(formatstr,
                                 CT_TableName,
                                 CN_SubCenterID, listStation[i].SubCenterID,
                                 CN_StationName, String.Format("'{0}'", listStation[i].StationName),
                                 CN_StationType, CEnumHelper.StationTypeToDBStr(listStation[i].StationType),
                                 //   CN_DeviceNumber, listStation[i].StrDeviceNumber,
                                 CN_Voltagemin, listStation[i].VoltageMin,
                                 CN_A10, GetNullableSQLString(listStation[i].A10),
                                 CN_B10, GetNullableSQLString(listStation[i].B10),
                                 CN_C10, GetNullableSQLString(listStation[i].C10),
                                 CN_D10, GetNullableSQLString(listStation[i].D10),
                                 CN_M10, GetNullableSQLString(listStation[i].M10),
                                 CN_N10, GetNullableSQLString(listStation[i].N10),
                                 CN_A20, GetNullableSQLString(listStation[i].A20),
                                 CN_B20, GetNullableSQLString(listStation[i].B20),
                                 CN_C20, GetNullableSQLString(listStation[i].C20),
                                 CN_D20, GetNullableSQLString(listStation[i].D20),
                                 CN_M20, GetNullableSQLString(listStation[i].M20),
                                 CN_N20, GetNullableSQLString(listStation[i].N20),
                                 CN_A30, GetNullableSQLString(listStation[i].A30),
                                 CN_B30, GetNullableSQLString(listStation[i].B30),
                                 CN_C30, GetNullableSQLString(listStation[i].C30),
                                 CN_D30, GetNullableSQLString(listStation[i].D30),
                                 CN_M30, GetNullableSQLString(listStation[i].M30),
                                 CN_N30, GetNullableSQLString(listStation[i].N30),
                                 CN_A40, GetNullableSQLString(listStation[i].A40),
                                 CN_B40, GetNullableSQLString(listStation[i].B40),
                                 CN_C40, GetNullableSQLString(listStation[i].C40),
                                 CN_D40, GetNullableSQLString(listStation[i].D40),
                                 CN_M40, GetNullableSQLString(listStation[i].M40),
                                 CN_N40, GetNullableSQLString(listStation[i].N40),
                                 CN_A60, GetNullableSQLString(listStation[i].A60),
                                 CN_B60, GetNullableSQLString(listStation[i].B60),
                                 CN_C60, GetNullableSQLString(listStation[i].C60),
                                 CN_D60, GetNullableSQLString(listStation[i].D60),
                                 CN_M60, GetNullableSQLString(listStation[i].M60),
                                 CN_N60, GetNullableSQLString(listStation[i].N60),
                                 CN_GSM, listStation[i].GSM,
                                 CN_GPRS, listStation[i].GPRS,
                                 CN_BDSatellite, listStation[i].BDSatellite,
                                 CN_BDMember, listStation[i].BDMemberSatellite,
                                 CN_Maintran, listStation[i].Maintran,
                                 CN_Subtran, listStation[i].Subtran,
                                 CN_Dataprotocol, listStation[i].Datapotocol,
                                 CN_Reportinterval, listStation[i].Reportinterval,
                                 CN_StationId, listStation[i].StationID
                                 );
                if (currentBatchCount >= CDBParams.GetInstance().UpdateBufferMax)
                {
                    // 更新数据库
                    if (!this.ExecuteSQLCommand(sql.ToString()))
                    {
                        // 保存失败
                        return(false);
                    }
                    sql.Clear(); //清除以前的所有命令
                    currentBatchCount = 0;
                }
            }
            // 更新数据库
            if (!this.ExecuteSQLCommand(sql.ToString()))
            {
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
        private DtuList FindDtuList(Subcenter subcenter)
        {
            DtuList dtuList = new DtuList();

            List <ModemInfoStruct>               stateList    = new List <ModemInfoStruct>();
            List <CEntityStation>                stations     = new List <CEntityStation>();
            List <CEntitySoilStation>            soilStations = new List <CEntitySoilStation>();
            List <CEntitySubCenter>              subCenters   = new List <CEntitySubCenter>();
            Dictionary <string, ModemInfoStruct> gprsDic      = new Dictionary <string, ModemInfoStruct>();

            stateList    = Clone <ModemInfoStruct>(CProtocolEventManager.Instance.GetOnlineStatusList());
            stations     = CDBDataMgr.Instance.GetAllStation();
            soilStations = CDBSoilDataMgr.Instance.GetAllSoilStation();
            subCenters   = CDBDataMgr.Instance.GetAllSubCenter();

            if (stateList.Count() != 0)
            {
                for (int i = 0; i < stateList.Count(); i++)
                {
                    string uid = ((uint)stateList[i].m_modemId).ToString("X").PadLeft(8, '0');
                    gprsDic.Add(uid, stateList[i]);
                }
            }

            foreach (var s in stations)
            {
                if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                {
                    if (gprsDic.Count() != 0)
                    {
                        if (gprsDic.ContainsKey(s.GPRS))
                        {
                            Dtu dtu = new Dtu();

                            ModemInfoStruct state       = gprsDic[s.GPRS];
                            string          phoneno     = CGprsUtil.Byte11ToPhoneNO(state.m_phoneno, 0);
                            string          dynIP       = CGprsUtil.Byte4ToIP(state.m_dynip, 0);
                            string          connectTime = CGprsUtil.ULongToDatetime(state.m_conn_time).ToString();
                            string          refreshTime = CGprsUtil.ULongToDatetime(state.m_refresh_time).ToString();

                            dtu.SubcenterId = s.SubCenterID.ToString();
                            string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                            dtu.SubcenterName = subName;
                            dtu.StationId     = s.StationID;
                            dtu.StationName   = s.StationName;
                            dtu.GprsId        = s.GPRS;
                            dtu.GsmNum        = phoneno;
                            dtu.IpAddr        = dynIP;
                            dtu.ConnTime      = connectTime;
                            dtu.RefreshTime   = refreshTime;
                            dtu.State         = "1";
                            dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                            dtuList.Dtu.Add(dtu);
                        }
                    }
                    else
                    {
                        Dtu dtu = new Dtu();
                        dtu.SubcenterId = s.SubCenterID.ToString();
                        string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                        dtu.SubcenterName = subName;
                        dtu.StationId     = s.StationID;
                        dtu.StationName   = s.StationName;
                        dtu.GprsId        = s.GPRS;
                        dtu.State         = "2";
                        dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                        dtuList.Dtu.Add(dtu);
                    }
                }
            }

            foreach (var s in stations)
            {
                if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                {
                    if (gprsDic.Count() != 0)
                    {
                        if (!gprsDic.ContainsKey(s.GPRS))
                        {
                            Dtu dtu = new Dtu();
                            dtu.SubcenterId = s.SubCenterID.ToString();
                            string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                            dtu.SubcenterName = subName;
                            dtu.StationId     = s.StationID;
                            dtu.StationName   = s.StationName;
                            dtu.GprsId        = s.GPRS;
                            dtu.State         = "2";
                            dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                            dtuList.Dtu.Add(dtu);
                        }
                    }
                }
            }

            foreach (var s in soilStations)
            {
                if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                {
                    if (gprsDic.Count() != 0)
                    {
                        if (gprsDic.ContainsKey(s.GPRS))
                        {
                            Dtu dtu = new Dtu();

                            ModemInfoStruct state       = gprsDic[s.GPRS];
                            string          phoneno     = CGprsUtil.Byte11ToPhoneNO(state.m_phoneno, 0);
                            string          dynIP       = CGprsUtil.Byte4ToIP(state.m_dynip, 0);
                            string          connectTime = CGprsUtil.ULongToDatetime(state.m_conn_time).ToString();
                            string          refreshTime = CGprsUtil.ULongToDatetime(state.m_refresh_time).ToString();

                            if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                            {
                                dtu.SubcenterId = s.SubCenterID.ToString();
                                string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                                dtu.SubcenterName = subName;
                                dtu.StationId     = s.StationID;
                                dtu.StationName   = s.StationName;
                                dtu.GprsId        = s.GPRS;
                                dtu.GsmNum        = phoneno;
                                dtu.IpAddr        = dynIP;
                                dtu.ConnTime      = connectTime;
                                dtu.RefreshTime   = refreshTime;
                                dtu.State         = "1";
                                dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                                dtuList.Dtu.Add(dtu);
                            }
                        }
                    }
                    else
                    {
                        Dtu dtu = new Dtu();
                        dtu.SubcenterId = s.SubCenterID.ToString();
                        string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                        dtu.SubcenterName = subName;
                        dtu.StationId     = s.StationID;
                        dtu.StationName   = s.StationName;
                        dtu.GprsId        = s.GPRS;
                        dtu.State         = "2";
                        dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                        dtuList.Dtu.Add(dtu);
                    }
                }
            }

            foreach (var s in soilStations)
            {
                if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                {
                    if (gprsDic.Count() != 0)
                    {
                        if (!gprsDic.ContainsKey(s.GPRS))
                        {
                            Dtu dtu = new Dtu();
                            dtu.SubcenterId = s.SubCenterID.ToString();
                            string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                            dtu.SubcenterName = subName;
                            dtu.StationId     = s.StationID;
                            dtu.StationName   = s.StationName;
                            dtu.GprsId        = s.GPRS;
                            dtu.State         = "2";
                            dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                            dtuList.Dtu.Add(dtu);
                        }
                    }
                }
            }

            return(dtuList);
        }