public ActionResult Detail(Collector collectorInfo)
 {
     int id = int.Parse(Request.QueryString["id"]);
     CollectorInfoService collectorInfoService = CollectorInfoService.GetInstance();
     collectorInfo = collectorInfoService.GetCollectorById(id);
     return View(collectorInfo);
 }
Example #2
0
 public ActionResult Admin(Collector collector)
 {
     try
     {
         collectorInfoservice.Save(collector);
     }
     catch
     {
         ViewData["error"] = "The DataLogger already exist!";
     }
     Hashtable hashPara = new Hashtable();
     hashPara["sd"] = DateTime.Now.AddYears(-5).ToString("yyyy-MM-dd");
     hashPara["ed"] = DateTime.Now.ToString("yyyy-MM-dd");
     Pager page = new Pager() { PageSize = ComConst.PageSize, PageIndex = 1 };
     hashPara["page"] = page;
     CollectorInfoService collectorInfoService = CollectorInfoService.GetInstance();
     IList<Collector> collectorInfos = collectorInfoService.GetCollectorsByPage(hashPara);
     ViewData["page"] = page;
     ViewData["data"] = collectorInfos;
     return View();
 }
Example #3
0
 /// <summary>
 /// 将采集器下面的设备和单元做物理关联
 /// </summary>
 /// <param name="collector"></param>
 /// <param name="plantUnitId"></param>
 private void bindDeviceToUnit(Collector collector, int plantUnitId)
 {
     if (collector == null) return;
     foreach (Device device in collector.devices)
     {
         //已有属主的话就不在更新了
         if (device.plantUnitId != null && device.plantUnitId.Value > 0)
         {
                 continue;
         }
         device.parentId = 0;
         device.plantUnitId = plantUnitId;
         if (device.deviceModel == null) device.deviceModel = new DeviceModel();
         DeviceService.GetInstance().Save(device);
     }
 }
Example #4
0
        /// <summary>
        /// 按照设备
        /// </summary>
        /// <param name="device"></param>
        /// <param name="collector"></param>
        /// <returns></returns>
        private string getInverterRunDataStr(Device device, Collector collector)
        {
            //1	逆变器运行状态	 	 	0:待机(waiting)1:正常(normal)3:故障(fault)	1
            string[] dataarr = new string[37];
            if (device.runData != null && device.runData.rundatastr != null)
                analyzeArr(device.runData.rundatastr, dataarr, invert_no_mcodemap);

            dataarr[0] = device.getStatusDefinedValue().ToString();
            double dv, dc;
            double.TryParse(dataarr[1], out dv);
            double.TryParse(dataarr[2], out dc);
            dataarr[4] = (dv * dc).ToString();//第一路电池板输出功率

            double.TryParse(dataarr[4], out dv);
            double.TryParse(dataarr[5], out dc);
            dataarr[7] = (dv * dc).ToString();//直流电压2 *直流电流2 第二路电池板输出功率

            dataarr[33] = collector.code;
            dataarr[34] = "000";//逆变器地址
            //将浮点状态值转成整形
            if (!string.IsNullOrEmpty(dataarr[23]))
                dataarr[23] = int.Parse(dataarr[23]).ToString();

            //12 + 15 +18
            //处理37	逆变器交流输出总功率	W	0.1W	第一、二、三相交流输出功率之和	4893.9
            if (dataarr[12] == null) dataarr[12] = "0";
            if (dataarr[15] == null) dataarr[15] = "0";
            if (dataarr[18] == null) dataarr[18] = "0";
            dataarr[36] = Math.Round(double.Parse(dataarr[12]) + double.Parse(dataarr[15]) + double.Parse(dataarr[18]),2).ToString();
            return buildRunDataStr(dataarr);
            //sb.Append(device.getStatusDefinedValue()).Append(",");
            ////2	逆变器输入总功率	W	0.1W
            //sb.Append("333.4").Append(",");
            ////3	第一路电池板电压	V	0.1V
            //sb.Append("33.4").Append(",");
            ////4	第一路电池板电流	A	0.1A
            //sb.Append("23.4").Append(",");
            ////5	第一路电池板输出功率	W	0.1W
            //sb.Append("23.4").Append(",");
            ////6	第二路电池板电压	V	0.1V
            //sb.Append("23.4").Append(",");
            ////7	第二路电池板电流	A	0.1A
            //sb.Append("23.4").Append(",");
            ////8	第二路电池板输出功率	W	0.1W
            //sb.Append("23.4").Append(",");
            ////9	逆变器输出总功率	W	0.1W
            //sb.Append("23.4").Append(",");
            ////10	电网频率	Hz	0.01Hz
            //sb.Append("224.14").Append(",");
            ////11	第一相电压	V	0.1V
            //sb.Append("23.4").Append(",");
            ////12	第一相电流	A	0.1A
            //sb.Append("23.4").Append(",");
            ////13	第一相输出功率	W	0.1W
            //sb.Append("23.4").Append(",");
            ////14	第二相电压	V	0.1V
            //sb.Append("23.4").Append(",");
            ////15	第二相电流	A	0.1A
            //sb.Append("23.4").Append(",");
            ////16	第二相输出功率	W	0.1W
            //sb.Append("23.4").Append(",");
            ////17	第三相电压	V	0.1V
            //sb.Append("23.4").Append(",");
            ////18	第三相电流	A	0.1A
            //sb.Append("23.4").Append(",");
            ////19	第三相输出功率	W	0.1W
            //sb.Append("23.4").Append(",");
            ////20	今日发电量	KWH	0.1KWH
            //sb.Append("23.4").Append(",");
            ////21	累计发电量	KWH	0.1KWH
            //sb.Append("23.4").Append(",");
            ////22	总发电时间	S	0.5S
            //sb.Append("23.4").Append(",");
            ////23	逆变器内部温度	℃	0.1℃
            //sb.Append("23.4").Append(",");
            ////24	逆变器运行错误码
            //sb.Append("9984").Append(",");
            ////25	逆变器输出功率因数
            //sb.Append("1.4").Append(",");
            ////26	第一路电池板今日发电量	KWH	0.1KWH
            //sb.Append("23.4").Append(",");
            ////27	第一路电池板累计发电量	KWH	0.1KWH
            //sb.Append("23.4").Append(",");
            ////28	第二路电池板今日发电量	KWH	0.1KWH
            //sb.Append("23.4").Append(",");
            ////29	第二路电池板累计发电量	KWH	0.1KWH
            //sb.Append("23.4").Append(",");
            ////30	电池板累计发电量	KWH	0.1KWH
            //sb.Append("23.4").Append(",");
            ////31	交流端无功功率	Var	0.1Var
            //sb.Append("23.4").Append(",");
            ////32	今日无功电能	KVarH	0.1KVarH
            //sb.Append("23.4").Append(",");
            ////33	累计无功电能	KVarH	0.1KVarH
            //sb.Append("23.4").Append(",");
            ////34	数据采集器序列号
            //sb.Append(collector.code).Append(",");
            ////35	逆变器序列号
            //sb.Append("");
        }
Example #5
0
        /// <summary>
        /// 取得采集器id
        /// </summary>
        /// <returns></returns>
        public int GetCollectorId()
        {
            string collectorCode = this.messageHeader.CollectorCode;
            Collector collector = CollectorInfoService.GetInstance().getCollectorbyCode(collectorCode);
            int id = 0;
            if (collector == null)
            {
                //如果没有则创建一个
                collector = new Collector();
                collector.code = collectorCode;
                //collector.password = "123456";//按照规则生成
                collector.isUsed = true;
                try
                {
                    id = CollectorInfoService.GetInstance().Save(collector);
                }
                catch (Exception e)
                {
                    LogUtil.info("save collector " + collectorCode + " error:" + e.Message);
                    id = 0;
                }
            }else
                id = collector.id;

            return id;
        }
Example #6
0
        public ActionResult RegSource(string t, string id)
        {
            User user = UserUtil.getCurUser();
            IList<Collector> collectors = CollectorInfoService.GetInstance().GetCollectorsByUid(user.id);
            int days = (int)itemConfigService.GetItemConfig(ItemConfig.maxexpiredDaysId).value;
            int count = (int)itemConfigService.GetItemConfig(ItemConfig.maxCollectorCountId).value;
            foreach (Collector item in collectors)
            {
                if (item.plantID.Equals(0) == false)
                    item.plant = plantService.GetPlantInfoById(item.plantID);
                else
                {
                    if ((DateTime.Now - item.importDate).TotalDays > days)
                    {
                        CollectorInfoService.GetInstance().Delete(item.id);
                    }
                    item.plant = null;
                }
            }

            //此处说明隔天  今天统计数据清零
            if ((DateTime.Now - user.lastApplyCollectorDate).TotalDays > 1)
            {
                user.lastApplyCollectorDate = DateTime.Now;
                user.todayApplyCollectorCount = 0;
                userservice.UpdateApplyCollectorCount(user);
            }

            ViewData["applyed"] = user.todayApplyCollectorCount;
            ViewData["available"] = count - user.todayApplyCollectorCount < 0 ? 0 : count - user.todayApplyCollectorCount;

            if (t != null && t.Equals("create"))
            {
                if (user.todayApplyCollectorCount < count)
                {
                    Collector collector = new Collector();
                    collector.code = string.Format("DT{0}", Util.RandomString());
                    collector.importDate = DateTime.Now;
                    collector.limitDate = DateTime.Now.AddDays(days);
                    collector.password = new Random().Next(100000000, 999999999).ToString();
                    collector.userId = user.id;

                    while (CollectorInfoService.GetInstance().CheckCollectorExists(collector.code) > 0)
                    {
                        collector.code = string.Format("DT{0}", Util.RandomString());
                    }
                    CollectorInfoService.GetInstance().Add(collector);
                    user.lastApplyCollectorDate = DateTime.Now;
                    user.todayApplyCollectorCount++;
                    userservice.UpdateApplyCollectorCount(user);
                    // return Content("true");
                    TempData["message"] = string.Format(Resources.SunResource.REG_SOURCE_NOTICE + "{0}", collector.code);
                    return Redirect("/user/regsource");
                }
                else
                {
                    TempData["message"] = string.Format(Resources.SunResource.APPLY_RESOURCE_ERROR_MSG, count);
                    return Redirect("/user/regsource");
                }
            }

            if (t != null && t.Equals("del"))
            {
                int tint = 0;
                int.TryParse(id, out tint);
                Collector item = collectors.Single(m => m.id.Equals(tint));
                if (item != null && item.plantID > 0)
                    return Content("false");
                CollectorInfoService.GetInstance().Delete(tint);
                return Content("true");
            }

            collectors = collectors.Where(model => (DateTime.Now - model.importDate).TotalDays < days || model.plant != null).ToList<Collector>();

            return View(collectors);
        }
 /// <summary>
 /// 添加采集器信息
 /// </summary>
 /// <param name="collectorInfo">采集器实体</param>
 public void Add(Collector collectorInfo)
 {
     _stationInfoDao.Insert(collectorInfo);
 }
 /// <summary>
 /// 修改采集器信息
 /// </summary>
 /// <param name="collectorInfo">采集器实体</param>
 public void Update(Collector collectorInfo)
 {
     _stationInfoDao.UpdateCollector(collectorInfo);
 }
 public int Save(Collector collector)
 {
     if (collector.id > 0)
     {
         return _stationInfoDao.Update(collector);
     }
     else
         return _stationInfoDao.Insert(collector);
 }
Example #10
0
 public ActionResult Collector_Save(Collector collector)
 {
     collector.importDate = DateTime.Now;
     if (collector.id.Equals(0))
     {
         int id = collectorInfoservice.CheckCollectorExists(collector.code);
         if (id > 0)
         {
             ViewData["error"] = "此采集器已经存在";
             return View(@"collector/edit");
         }
     }
     collectorInfoservice.Save(collector);
     return RedirectToAction("collectors", "admin");
 }
Example #11
0
        public ActionResult Collector_Excel(HttpPostedFileBase uploadFile)
        {
            int index = 0;
            IList<Collector> failedCollectors = new List<Collector>();
            try
            {
                string folderPath = HttpContext.Server.MapPath("/mfile/");
                if (System.IO.Directory.Exists(folderPath) == false)
                    System.IO.Directory.CreateDirectory(folderPath);

                //保留文件  加上时间防止重名覆盖
                string filePath = Path.Combine(folderPath, Path.GetFileName(uploadFile.FileName));

                uploadFile.SaveAs(filePath);
                string ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + folderPath + uploadFile.FileName.Substring(uploadFile.FileName.LastIndexOf('\\') + 1) + ";Extended Properties=Excel 12.0;";
                using (OleDbConnection conn = new OleDbConnection(ConnectionString))
                {
                    conn.Open();
                    using (DataTable dtExcelSchema = conn.GetSchema("Tables"))
                    {
                        string sheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
                        string query = "select sn,pass,mac,pno,encryption,date,description,key from [" + sheetName + "]";
                        OleDbDataAdapter adapter = new OleDbDataAdapter(query, conn);
                        DataSet ds = new DataSet();
                        adapter.Fill(ds, "Items");
                        if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                        {
                            IList<Collector> collectors = CollectorInfoService.GetInstance().GetList();
                            bool isExist = false;
                            Collector temp = null;
                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            {
                                string dtStr = ds.Tables[0].Rows[i][5].ToString();
                                if (string.IsNullOrEmpty(dtStr) == false)
                                {
                                    DateTime dt;
                                    DateTime.TryParse(dtStr, out dt);
                                    if (dt.Equals(DateTime.MinValue))
                                        dt = DateTime.Now;
                                    dtStr = dt.ToString("yyyy-MM-dd");
                                }
                                else
                                    dtStr = DateTime.Now.ToString("yyyy-MM-dd");
                                temp = new Collector
                                {
                                    code = ds.Tables[0].Rows[i][0].ToString(),
                                    Descr = ds.Tables[0].Rows[i][6].ToString(),
                                    MAC = ds.Tables[0].Rows[i][2].ToString(),
                                    password = ds.Tables[0].Rows[i][1].ToString(),
                                    PNO = ds.Tables[0].Rows[i][3].ToString(),
                                    Encryption = ds.Tables[0].Rows[i][4].ToString(),
                                    importDate = DateTime.Now,
                                    Date = string.IsNullOrEmpty(dtStr) ? string.Empty : dtStr,
                                    Key = ds.Tables[0].Rows[i][7].ToString()
                                };
                                if (string.IsNullOrEmpty(temp.code)) continue;
                                string r = CheckDataValidate(temp);
                                if (string.IsNullOrEmpty(r) == false)
                                {
                                    temp.Descr = r;
                                    failedCollectors.Add(temp);
                                    continue;
                                }

                                isExist = false;
                                isExist = collectors.Where(m => m.code.ToLower().Equals(temp.code.ToLower())).Count() > 0;
                                if (isExist)
                                {
                                    temp.Descr = "此 SN 已存在数据库";
                                    failedCollectors.Add(temp);
                                    continue;
                                }
                                CollectorInfoService.GetInstance().Add(temp);
                                index++;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ViewData["result"] = string.Format("导入失败{0}", e.Message);
                return View(@"collector/excel");
            }
            ViewData["faildRecord"] = failedCollectors;
            ViewData["result"] = string.Format("总记录数:{0} 条, 导入成功:{1} 条, 导入失败:{2} 条", index + failedCollectors.Count, index, failedCollectors.Count);
            return View(@"collector/excel");
        }
Example #12
0
 public ActionResult Collector_Edit(Collector collector)
 {
     collectorInfoservice = CollectorInfoService.GetInstance();
     collectorInfoservice.Save(collector);
     return RedirectToAction("Collectors");
 }
Example #13
0
 private string CheckDataValidate(Collector collector)
 {
     if (collector.code.Length < 9 || collector.code.Length > 16)
         return "SN 位数错误";
     if (collector.password.Length < 6 || collector.password.Length > 32)
         return "PASS 位数错误";
     if (collector.MAC.Length < 12 || collector.MAC.Length > 16)
         return "MAC 位数错误";
     if (!(collector.PNO.Length == 20))
         return "PNO 位数错误";
     if (collector.Encryption.Length < 3 || collector.Encryption.Length > 32)
         return "ENCRYPTION 位数错误";
     //if (collector.Key.Length < 32)
     //    return "加密密匙最少需要32位";
     return string.Empty;
 }