Exemple #1
0
        // GET: transfer/alterDatabase
        /// <summary>
        /// 修改数据库配置
        /// </summary>
        /// <returns></returns>
        public ActionResult alterdatabase()
        {
            string type         = Request.Params.Get("type");
            string serverName   = Request.Params.Get("servername");
            string databaseName = Request.Params.Get("databasename");
            string username     = Request.Params.Get("username");
            string password     = Request.Params.Get("password");

            //参数异常
            if (serverName == null || databaseName == null || username == null || password == null ||
                serverName == "" || databaseName == "" || username == "" || password == "" || (type != "target" && type != "source"))
            {
                return(Json(helper.DBHelper.SerializeDBReturnCode(helper.DBReturnCode.BAD_REQUEST), JsonRequestBehavior.AllowGet));
            }
            //init a model object
            Models.DK_DB obj = new Models.DK_DB();
            obj.database_type = type;
            obj.database_name = databaseName;
            obj.server_name   = serverName;
            obj.username      = username;
            obj.password      = password;

            Models.Maintain     db   = new Models.Maintain();
            helper.DBReturnCode code = DAL.TransferDbConfigService.AlterDbConfig(db, obj);
            return(Json(helper.DBHelper.SerializeDBReturnCode(code), JsonRequestBehavior.AllowGet));
        }
        /******************************
         * 数据转储相关页面
         * ***************************/
        public ViewResult TransDbConfig()
        {
            Models.Maintain db = new Models.Maintain();
            ViewBag.Databases = DAL.TransferDbConfigService.ListDbConfig(db);

            return(View());
        }
Exemple #3
0
        //GET: transfer/deleteerrordata
        /// <summary>
        /// 删除错误数据
        /// </summary>
        /// <returns></returns>
        public ActionResult deleteerrordata()
        {
            string   station8Id, type;
            DateTime time;

            //deal with params
            try
            {
                station8Id = Request.Params.Get("station8id");
                type       = Request.Params.Get("type");
                time       = DateTime.Parse(Request.Params.Get("time"));
                if (station8Id.Length != 8 || (type != "R" && type != "W"))
                {
                    throw new Exception();
                }
            }
            catch (Exception e)
            {
                return(Json(helper.DBHelper.SerializeDBReturnCode(helper.DBReturnCode.BAD_REQUEST), JsonRequestBehavior.AllowGet));
            }

            Models.Maintain     db   = new Models.Maintain();
            helper.DBReturnCode code = DAL.TransferDataService.DeleteErrorData(db, station8Id, time, type);
            string json = helper.DBHelper.SerializeDBReturnCode(code);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemple #4
0
        //GET: transfer/releasewarningdata
        /// <summary>
        /// 放行警报数据
        /// </summary>
        /// <returns></returns>
        public ActionResult releasewarningdata()
        {
            string   station8Id, type;
            DateTime time;
            decimal  data;

            //deal with params
            try
            {
                station8Id = Request.Params.Get("station8id");
                type       = Request.Params.Get("type");
                time       = DateTime.Parse(Request.Params.Get("time"));
                data       = Decimal.Parse(Request.Params.Get("data"));
                if (station8Id.Length != 8 || type != "R" || type != "W")
                {
                    throw new Exception();
                }
            }
            catch (Exception e)
            {
                return(Json(helper.DBHelper.SerializeDBReturnCode(helper.DBReturnCode.BAD_REQUEST), JsonRequestBehavior.AllowGet));
            }

            Models.Maintain     db   = new Models.Maintain();
            helper.DBReturnCode code = DAL.TransferDataService.ReleaseWarningData(db, station8Id, time, type, data);
            string json = helper.DBHelper.SerializeDBReturnCode(code);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemple #5
0
        //GET: transfer/database
        /// <summary>
        /// 读取数据库配置,原始库和目标库2个一起读。
        /// </summary>
        /// <returns></returns>
        public ActionResult database()
        {
            Models.Maintain db   = new Models.Maintain();
            string          json = JsonConvert.SerializeObject(DAL.TransferDbConfigService.ListDbConfig(db));

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemple #6
0
        //GET: transfer/statistic
        /// <summary>
        /// 获取数据转储统计信息,这里时间为年月日,直接在表中取当天9时-第二天8时之间的所有数据。只能查询一天的数据。
        /// @param date:YYYY-MM-DD
        /// </summary>
        /// <returns></returns>
        public ActionResult statistic()
        {
            DateTime from;
            int      id = 0;

            try
            {
                from = DateTime.Parse(Request.Params.Get("date"));
                id   = int.Parse(Request.Params.Get("isubcenter"));
            }
            catch (Exception e)
            {
                return(Json(helper.DBHelper.SerializeDBReturnCode(helper.DBReturnCode.BAD_REQUEST), JsonRequestBehavior.AllowGet));
            }
            Models.QueryResult     result   = new Models.QueryResult();
            Models.Maintain        db       = new Models.Maintain();
            List <Models.Station>  stations = DAL.StationService.ListStationBySubcenterId(id);
            List <Models.M_status> datas    = DAL.TransferDataService.ListMonitorData(db, from, 1); //仅查一天的数据

            foreach (Models.Station station in stations)
            {
                Models.M_status data = datas.FirstOrDefault(i => i.STCD == station.stationId);
                Models.TransferStatisticRecord record = new Models.TransferStatisticRecord(station, data);
                result.records.Add(record);
            }
            JavaScriptSerializer jsSerializer = new JavaScriptSerializer();

            jsSerializer.MaxJsonLength = Int32.MaxValue;
            string json = jsSerializer.Serialize(result);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemple #7
0
        public static void QueryTransferStatistic()
        {
            Models.Maintain db   = new Models.Maintain();
            DateTime        now  = DateTime.Now;
            DateTime        from = new DateTime(
                year: now.Year,
                month: now.Month,
                day: now.Day,
                hour: 9,
                minute: 0,
                second: 0
                );
            DateTime to = new DateTime(
                year: now.Year,
                month: now.Month,
                day: now.Day,
                hour: now.Hour,
                minute: 0,
                second: 0
                );
            List <Models.DK_E_INFO> dic = DAL.TransferDataService.ListErrorData(db, from, to);

            Models.TransferStatisticRecord records = new Models.TransferStatisticRecord(dic);
            foreach (KeyValuePair <DateTime, bool> data in records.datas)
            {
                Console.WriteLine(data.Key.ToString() + "\t" + (data.Value ? "Yes" : "No"));
            }
        }
Exemple #8
0
        /// <summary>
        /// 修改指定站点的所有可修改的信息
        /// </summary>
        /// 可能出现:信息超过允许的范围,站点不存在。
        /// <param name="station">传入一个站点对象。</param>
        /// <returns></returns>
        public static helper.DBReturnCode AlterStation(Models.Maintain db, Models.ID_TO_STCD_DK station)
        {
            if (!db.ID_TO_STCD_DK.Any(i => i.ID == station.ID)) //站点不存在
            {
                return(helper.DBReturnCode.NOT_EXIST);
            }
            ID_TO_STCD_DK target = db.ID_TO_STCD_DK.First(i => i.ID == station.ID);

            //修改所有属性
            target.STTYPE       = station.STTYPE;
            target.CNAME        = station.CNAME;
            target.WATERMAX     = station.WATERMAX;
            target.WATERMIN     = station.WATERMIN;
            target.WATERCHANGE  = station.WATERCHANGE;
            target.RAINCHANGE   = station.RAINCHANGE;
            target.BRAIN        = station.BRAIN;
            target.DAYWATERTJ   = station.DAYWATERTJ;
            target.DAYRAINTJ    = station.DAYRAINTJ;
            target.XUNWATERTJ   = station.XUNWATERTJ;
            target.XUNRAINTJ    = station.XUNRAINTJ;
            target.MONTHWATERTJ = station.MONTHWATERTJ;
            target.MONTHRAINTJ  = station.MONTHRAINTJ;
            target.sendflag     = station.sendflag;
            try
            {
                db.SaveChanges();
                return(helper.DBReturnCode.SUCCESS);
            }catch (Exception e)
            {
                return(helper.DBReturnCode.OP_ERROR);
            }
        }
Exemple #9
0
        //GET:transfer/stations
        /// <summary>
        /// 获取所有站点信息
        /// </summary>
        public ActionResult stations()
        {
            Models.Maintain             db     = new Models.Maintain();
            List <Models.ID_TO_STCD_DK> result = DAL.TransferStationService.ListStations(db);
            string json = JsonConvert.SerializeObject(result);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemple #10
0
        //GET:transfer/alterstation
        /// <summary>
        /// 修改一个站点的信息
        /// </summary>
        /// <returns></returns>
        public ActionResult alterstation()
        {
            string  station8Id, stationId, stationType, stationName, dayRain, dayWater, xunRain, xunWater, monthRain, monthWater, sendFlag;
            decimal?waterMax, waterMin, waterChange, rainChange, rainAdditional;

            //检查参数
            try
            {
                station8Id     = Request.Params.Get("station8id");
                stationId      = Request.Params.Get("stationid");
                stationType    = Request.Params.Get("stationtype");
                stationName    = Request.Params.Get("stationname");
                waterMax       = Decimal.Parse(Request.Params.Get("watermax"));
                waterMin       = Decimal.Parse(Request.Params.Get("watermin"));
                waterChange    = Decimal.Parse(Request.Params.Get("waterchange"));
                rainChange     = Decimal.Parse(Request.Params.Get("rainchange"));
                rainAdditional = Decimal.Parse(Request.Params.Get("rainadditional"));
                dayRain        = Request.Params.Get("dayrain");
                dayWater       = Request.Params.Get("daywater");
                xunRain        = Request.Params.Get("xunrain");
                xunWater       = Request.Params.Get("xunwater");
                monthRain      = Request.Params.Get("monthrain");
                monthWater     = Request.Params.Get("monthwater");
                sendFlag       = Request.Params.Get("sendflag");
                if (station8Id.Length != 8 || stationId.Length != 4 || dayRain.Length != 1 || dayWater.Length != 1 || xunRain.Length != 1 || xunWater.Length != 1 || monthRain.Length != 1 || monthWater.Length != 1 || sendFlag.Length != 1)
                {
                    throw new Exception();
                }
            }
            catch (Exception e)
            {
                return(Json(helper.DBHelper.SerializeDBReturnCode(helper.DBReturnCode.BAD_REQUEST), JsonRequestBehavior.AllowGet));
            }
            //init a station object
            Models.ID_TO_STCD_DK station = new Models.ID_TO_STCD_DK();
            station.ID           = stationId;
            station.STCD         = station8Id;
            station.CNAME        = stationName;
            station.STTYPE       = stationType;
            station.WATERMAX     = waterMax;
            station.WATERMIN     = waterMin;
            station.WATERCHANGE  = waterChange;
            station.RAINCHANGE   = rainChange;
            station.BRAIN        = rainAdditional;
            station.DAYRAINTJ    = dayRain;
            station.DAYWATERTJ   = dayWater;
            station.XUNRAINTJ    = xunRain;
            station.XUNWATERTJ   = xunWater;
            station.MONTHRAINTJ  = monthRain;
            station.MONTHWATERTJ = monthWater;
            station.sendflag     = sendFlag;

            Models.Maintain     db   = new Models.Maintain();
            helper.DBReturnCode code = DAL.TransferStationService.AlterStation(db, station);
            string json = helper.DBHelper.SerializeDBReturnCode(code);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Exemple #11
0
 /// <summary>
 /// 放行报警信息,数据使用用户指定。
 /// </summary>
 /// <param name="stationid"></param>
 /// <param name="time"></param>
 /// <param name="type"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public static helper.DBReturnCode ReleaseWarningData(Models.Maintain db, string station8Id, DateTime time, string type, decimal data)
 {
     helper.DBReturnCode code = WriteStandardDatabase(station8Id, time, type, data);
     if (code == helper.DBReturnCode.SUCCESS)
     {
         return(DeleteWarningData(db, station8Id, time, type));
     }
     else
     {
         return(code);
     }
 }
Exemple #12
0
        /// <summary>
        /// 获得警告信息
        /// </summary>
        /// <returns></returns>
        public ActionResult getwarningdata()
        {
            DateTime time_from = Convert.ToDateTime(Request.Params.Get("time_from"));
            DateTime time_to   = Convert.ToDateTime(Request.Params.Get("time_to"));

            Models.Maintain         db         = new Models.Maintain();
            List <Models.DK_P_INFO> tempResult = new List <Models.DK_P_INFO>();

            tempResult = DAL.TransferDataService.ListWarningData(db, time_from, time_to);
            var ret = JsonConvert.SerializeObject(tempResult);

            return(Json(ret, JsonRequestBehavior.AllowGet));
        }
Exemple #13
0
        /// <summary>
        /// 查询指定时间内的数据转储监控统计表里面的信息,用于转储监控统计页面
        /// </summary>
        /// <param name="db"></param>
        /// <param name="from">开始时间,当天信息包含在结果内</param>
        /// <param name="days">需要查询的天数</param>
        /// <returns></returns>
        public static List <Models.M_status> ListMonitorData(Models.Maintain db, DateTime from, int days)
        {
            //时间段设置为开始天的00:00:00和结束天的23:59:59
            DateTime to = from.AddDays(days - 1);

            to = new DateTime(
                year: to.Year,
                month: to.Month,
                day: to.Day,
                hour: 23,
                minute: 59,
                second: 59);
            return(db.M_status.Where(i => i.datatime <= to && i.datatime >= from).ToList());
        }
Exemple #14
0
 /// <summary>
 /// 根据给定的信息添加一个站点。
 /// </summary>
 /// 可能站点信息缺失,站点ID和报讯ID和其他站冲突。
 /// <param name="station"></param>
 /// <returns></returns>
 public static helper.DBReturnCode AddStation(Models.Maintain db, Models.ID_TO_STCD_DK station)
 {
     //联合主键不能冲突
     if (db.ID_TO_STCD_DK.Any(i => i.ID == station.ID) || db.ID_TO_STCD_DK.Any(i => i.STCD == station.STCD))
     {
         return(helper.DBReturnCode.DATA_CONFLICT);
     }
     db.ID_TO_STCD_DK.Add(station);
     try
     {
         db.SaveChanges();
         return(helper.DBReturnCode.SUCCESS);
     }catch (Exception e)
     {
         return(helper.DBReturnCode.OP_ERROR);
     }
 }
Exemple #15
0
 /// <summary>
 /// 删除错误信息
 /// </summary>
 /// <param name="stationid">8位报讯站号</param>
 /// <param name="time"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public static helper.DBReturnCode DeleteErrorData(Models.Maintain db, string station8Id, DateTime time, string type)
 {
     if (!db.DK_E_INFO.Any(i => i.STCD == station8Id && i.TM == time && i.DTYPE == type))
     {
         return(helper.DBReturnCode.NOT_EXIST);
     }
     try
     {
         Models.DK_E_INFO data = db.DK_E_INFO.First(i => i.STCD == station8Id && i.TM == time && i.DTYPE == type);
         db.DK_E_INFO.Remove(data);
         db.SaveChanges();
         return(helper.DBReturnCode.SUCCESS);
     }catch (Exception e)
     {
         return(helper.DBReturnCode.OP_ERROR);
     }
 }
Exemple #16
0
 /// <summary>
 /// 根据站点ID删除一个站点
 /// </summary>
 /// 可能出现:站点不存在
 /// <param name="id"></param>
 /// <returns></returns>
 public static helper.DBReturnCode DeleteStation(Models.Maintain db, string station8Id, string stationId)
 {
     if (!db.ID_TO_STCD_DK.Any(i => i.ID == station8Id && i.STCD == stationId))
     {
         return(helper.DBReturnCode.NOT_EXIST);
     }
     try
     {
         ID_TO_STCD_DK station = db.ID_TO_STCD_DK.First(i => i.ID == stationId && i.STCD == station8Id);
         db.ID_TO_STCD_DK.Remove(station);
         db.SaveChanges();
         return(helper.DBReturnCode.SUCCESS);
     }catch (Exception e)
     {
         return(helper.DBReturnCode.OP_ERROR);
     }
 }
 /// <summary>
 /// 修改数据库配置表,database_type字段是不可修改的而且必须等于source或target。
 /// </summary>
 /// <param name="db">数据库对象</param>
 /// <param name="data">需要修改的数据对象,字段database_type:转储的2个库的库类target/source</param>
 /// <returns></returns>
 public static helper.DBReturnCode AlterDbConfig(Models.Maintain db, Models.DK_DB data)
 {
     //type限定在原始库和目标库2个字段中间。
     if (data.database_type != "source" || data.database_type != "target")
     {
         return(helper.DBReturnCode.BAD_REQUEST);
     }
     Models.DK_DB target = db.DK_DB.First(i => i.database_type == data.database_type);
     //修改所有字段除了库类
     target.server_name   = data.server_name;
     target.database_name = data.database_name;
     target.username      = data.username;
     target.password      = data.password;
     try
     {
         db.SaveChanges();
         return(helper.DBReturnCode.SUCCESS);
     }
     catch (Exception e)
     {
         return(helper.DBReturnCode.OP_ERROR);
     }
 }
Exemple #18
0
        //GET:transfer/deleteStation
        /// <summary>
        /// 删除一个站点
        /// </summary>
        /// <returns></returns>
        public ActionResult deleteStation()
        {
            string station8Id, stationId;

            try
            {
                //deal with params
                station8Id = Request.Params.Get("station8id");
                stationId  = Request.Params.Get("stationid");
                if (station8Id.Length != 8 || stationId.Length != 4)
                {
                    throw new Exception();
                }
            }
            catch (Exception e)
            {
                return(Json(helper.DBHelper.SerializeDBReturnCode(helper.DBReturnCode.BAD_REQUEST), JsonRequestBehavior.AllowGet));
            }
            Models.Maintain     db   = new Models.Maintain();
            helper.DBReturnCode code = DAL.TransferStationService.DeleteStation(db, station8Id, stationId);
            string json = helper.DBHelper.SerializeDBReturnCode(code);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
 public static List <Models.DK_DB> ListDbConfig(Models.Maintain db)
 {
     return(db.DK_DB.ToList());
 }
Exemple #20
0
 /// <summary>
 /// 查询指定时间内报警信息
 /// </summary>
 /// <param name="db"></param>
 /// <param name="from"></param>
 /// <param name="to"></param>
 /// <returns>返回一个List,可能为空</returns>
 public static List <Models.DK_P_INFO> ListWarningData(Models.Maintain db, DateTime from, DateTime to)
 {
     return(db.DK_P_INFO.Where(i => i.TM <= to && i.TM >= from).ToList());
 }