// 保存数据
 public override bool DoSave()
 {
     if (this.IsCurrentCellInEditMode)
     {
         //MessageBox.Show("请完成当前的编辑");
         this.EndEdit();
         //return false;
     }
     //base.DoSave();
     // 更新
     GetUpdatedData();
     if (m_listAddedWater.Count > 0 || m_listUpdated.Count > 0 || m_listDeleteWaters_StationId.Count > 0)
     {
         bool result = true;
         // 增加
         if (m_listAddedWater.Count > 0)
         {
             //直接添加,不需要等待1分钟
             m_proxyWater.AddNewRows_1(m_listAddedWater);
             m_listAddedWater.Clear();
         }
         // 修改
         if (m_listUpdated.Count > 0)
         {
             result = result && m_proxyWater.UpdateRows(m_listUpdated);
             m_listUpdated.Clear();
         }
         // 删除
         if (m_listDeleteWaters_StationId.Count > 0)
         {
             result = result && m_proxyWater.DeleteRows(m_listDeleteWaters_StationId, m_listDeleteWaters_StationDate);
             m_listDeleteWaters.Clear();
         }
         if (result)
         {
             //MessageBox.Show("保存成功,新增记录稍有延迟");
         }
         else
         {
             // 保存失败
             //MessageBox.Show("保存失败");
             return(false);
         }
         SetWaters(m_proxyWater.GetPageData(base.m_iCurrentPage));
     }
     else
     {
         //MessageBox.Show("没有任何修改,无需保存");
     }
     return(true);
 }
Esempio n. 2
0
        public void Import(CBatchStruct batch, DateTime DStartTime, DateTime DEndTime, bool isUpdate = false)
        {
            DateTime?     lastTime             = null;
            ERTDDataState tmpRTDWaterDataState = ERTDDataState.ENormal;
            ////gm  1024 $60091K02031610220800084505230800084505
            //string rawString = rawData;
            //string startTime = rawString.Substring(11, 10);
            //string endTime = rawString.Substring(27, 6);
            //string strYear = 20 + startTime.Substring(0, 2);
            //string strMonth = startTime.Substring(2, 2);
            //string strStartDay = startTime.Substring(4, 2);
            //string strStartHour = startTime.Substring(6, 2);
            //string strStartMinute = startTime.Substring(8, 2);
            //string strEndDay = endTime.Substring(0, 2);
            //string strEndHour = endTime.Substring(2, 2);
            //string strEndMinute = endTime.Substring(4, 2);

            ////DateTime DStartTime = new DateTime(int.Parse(strYear), int.Parse(strMonth), int.Parse(strStartDay), int.Parse(strStartHour), int.Parse(strStartMinute), 0);
            ////DateTime DEndTime = new DateTime(int.Parse(strYear), int.Parse(strMonth), int.Parse(strEndDay), int.Parse(strEndHour), int.Parse(strEndMinute), 0);

            List <CTimeAndData> datas = batch.Datas;
            string         stationid  = batch.StationID;
            EStationType   type       = batch.StationType;
            CEntityStation station    = m_proxyStation.QueryById(stationid);

            //  if (type == EStationType.ERainFall)
            if (type == EStationType.ERiverWater)
            // if (true)
            {
                for (int i = 0; i < datas.Count; i++)
                {
                    if (lastTime == datas[i].Time)
                    {
                        lastTime = datas[i].Time;
                        continue;
                    }
                    lastTime = datas[i].Time;
                    int                status          = 1;
                    DateTime           dt              = datas[i].Time;
                    string             data            = datas[i].Data.ToString();
                    int                RawtotalRain    = int.Parse(data.Substring(0, 4));
                    Nullable <Decimal> RawrainAccuracy = decimal.Parse((data.Substring(4, 2)));
                    Nullable <Decimal> rainAccuracy    = RawrainAccuracy / 10;
                    Nullable <Decimal> totalRain       = RawtotalRain * rainAccuracy;
                    CEntityRain        LastSharpMes    = new CEntityRain();
                    CEntityRain        LastDayMes      = new CEntityRain();
                    //如果是第一条数据,则通过数据库获取上一条数据
                    if (i == 0)
                    {
                        Nullable <Decimal>      lastTotalRain = null, lastDayTotalRain = null, lastSharpClockTotalRain = null;
                        Nullable <DateTime>     lastDayTime        = null;
                        Nullable <DateTime>     lastClockSharpTime = null;
                        Nullable <DateTime>     lastDataTime       = null;
                        Nullable <Decimal>      lastPeriodRain     = null;
                        Nullable <EChannelType> lastChannelType    = null;
                        Nullable <EMessageType> lastMessageType    = null;

                        LastSharpMes = m_proxyRain.GetLastSharpRain(stationid, dt);
                        LastDayMes   = m_proxyRain.GetLastDayRain(stationid, dt);

                        lastTotalRain           = m_proxyRain.GetLastRain(stationid, dt).TotalRain;
                        lastSharpClockTotalRain = LastSharpMes.TotalRain;
                        lastDayTotalRain        = LastDayMes.TotalRain;

                        lastClockSharpTime = LastSharpMes.TimeCollect;
                        lastDayTime        = LastDayMes.TimeCollect;

                        //改动

                        // 查询成功

                        station.LastTotalRain    = lastTotalRain;
                        station.LastDayTotalRain = lastDayTotalRain;
                        station.LastPeriodRain   = lastPeriodRain;
                        if (lastDataTime != null && lastDataTime.HasValue)
                        {
                            station.LastDataTime = lastDataTime;
                        }
                        if (lastClockSharpTime != null && lastClockSharpTime.HasValue)
                        {
                            station.LastClockSharpTime = lastClockSharpTime;
                        }
                        if (lastDayTime != null && lastDayTime.HasValue)
                        {
                            station.LastDayTime = lastDayTime;
                        }
                        if (lastChannelType != null && lastChannelType.HasValue)
                        {
                            station.LastChannelType = lastChannelType;
                        }
                        if (lastMessageType != null && lastMessageType.HasValue)
                        {
                            station.LastMessageType = lastMessageType;
                        }

                        //int year = dt.Year;
                        //int month = dt.Month;
                        //int day = dt.Day;
                        //DateTime tmp1 = new DateTime(year, month, day, 8, 0, 0);
                        //DateTime tmp2 = tmp1.Subtract(new TimeSpan(24, 0, 0));
                        //station.LastDayTime = tmp2;
                        //lastSharpClockTotalRain = m_proxyRain.GetLastClockSharpTotalRain(stationid, dt);
                        //lastDayTotalRain = m_proxyRain.GetLastDayTotalRain(stationid, tmp2);
                        station.LastTotalRain = lastTotalRain;

                        station.LastClockSharpTotalRain = lastSharpClockTotalRain;
                        station.LastClockSharpTime      = lastClockSharpTime;

                        station.LastDayTotalRain = lastDayTotalRain;
                        station.LastDayTime      = lastDayTime;
                    }
                    CEntityRain rain = new CEntityRain();
                    rain.StationID   = stationid;
                    rain.TimeCollect = dt;
                    rain.TotalRain   = totalRain;
                    // rain.DifferneceRain = CalDifferenceRain(rainAccuracy, RawtotalRain, station.LastTotalRain, station.DRainChange, ref status);

                    if ((dt.Minute + dt.Second) == 0)
                    {
                        //rain.PeriodRain = CalPeriodRain(rainAccuracy, RawtotalRain, dt, station.LastClockSharpTotalRain);
                        rain.PeriodRain = CalPeriodRain_2(rainAccuracy, RawtotalRain, dt, station.LastClockSharpTotalRain, station.LastClockSharpTime, station.LastTotalRain);
                        station.LastClockSharpTotalRain = totalRain;
                        station.LastClockSharpTime      = dt;
                    }
                    if (dt.Hour == 8)
                    {
                        //rain.DayRain = CalDayRain(rainAccuracy, RawtotalRain, dt, station.LastDayTime, station.LastDayTotalRain);
                        rain.DayRain             = CalDayRain_2(rainAccuracy, RawtotalRain, dt, station.LastDayTotalRain, station.LastDayTime);
                        station.LastDayTotalRain = totalRain;
                        station.LastDayTime      = dt;
                    }
                    rain.DifferneceRain   = CalDifferenceRain_1(rainAccuracy, RawtotalRain, station.LastTotalRain, station.DRainChange, ref status);
                    station.LastTotalRain = totalRain;
                    // 待检测
                    rain.ChannelType = EChannelType.GPRS;
                    rain.MessageType = EMessageType.Batch;

                    rain.TimeRecieved = DateTime.Now;
                    if (status == 1)
                    {
                        rain.BState = 1;
                    }
                    else
                    {
                        rain.BState = 0;
                    }

                    rainResults.Add(rain);
                }
                List <CEntityRain> listInsert   = new List <CEntityRain>();
                List <CEntityRain> listUpdate   = new List <CEntityRain>();
                List <DateTime>    listDateTime = m_proxyRain.getExistsTime(stationid, DStartTime, DEndTime);
                for (int i = 0; i < rainResults.Count; i++)
                {
                    if (listDateTime.Contains(rainResults[i].TimeCollect))
                    {
                        listUpdate.Add(rainResults[i]);
                    }
                    else
                    {
                        listInsert.Add(rainResults[i]);
                    }
                }
                m_proxyRain.AddNewRows(listInsert); //写入数据库
                m_proxyRain.UpdateRows(listUpdate); //更新

                //m_proxyRain.AddOrUpdate(rainResults);
            }
            //操作water表
            //   if (type == EStationType.ERiverWater)
            if (type == EStationType.ERainFall)
            {
                for (int i = 0; i < datas.Count; i++)
                {
                    decimal  data = 0;
                    DateTime dt   = datas[i].Time;
                    try
                    {
                        string strData = datas[i].Data.Trim();
                        //decimal data = int.Parse(datas[i].Data) / 100;
                        data = decimal.Parse(strData) / 100;
                    }
#pragma warning disable CS0168 // 声明了变量“e”,但从未使用过
                    catch (Exception e)
#pragma warning restore CS0168 // 声明了变量“e”,但从未使用过
                    {
                        break;
                    }
                    //操作water表
                    CEntityWater water = new CEntityWater();
                    water.StationID    = station.StationID;
                    water.TimeCollect  = dt;
                    water.TimeRecieved = DateTime.Now;
                    if (station.DWaterBase.HasValue)
                    {
                        // 减去水位基值
                        water.WaterStage = data + station.DWaterBase.Value;
                    }
                    else
                    {
                        water.WaterStage = data;
                    }
                    water.WaterFlow = CDBDataMgr.GetInstance().GetWaterFlowByWaterStageAndStation(stationid, data);
                    //此处 waterflow需要计算的
                    water.ChannelType = EChannelType.GPRS;
                    water.MessageType = EMessageType.Batch;
                    AssertWaterData(water, ref tmpRTDWaterDataState);
                    //if (tmpRTDWaterDataState == ERTDDataState.ENormal)
                    //{
                    //    water.state = 1;
                    //}
                    //if (tmpRTDWaterDataState == ERTDDataState.EError)
                    //{
                    //    water.state = 0;
                    //}
                    //if (tmpRTDWaterDataState == ERTDDataState.EWarning)
                    //{
                    //    water.state = 2;
                    //}

                    waterResults.Add(water);
                }
                List <CEntityWater> listInsert   = new List <CEntityWater>();
                List <CEntityWater> listUpdate   = new List <CEntityWater>();
                List <DateTime>     listDateTime = m_proxyWater.getExistsTime(stationid, DStartTime, DEndTime);
                for (int i = 0; i < waterResults.Count; i++)
                {
                    if (listDateTime.Contains(waterResults[i].TimeCollect))
                    {
                        listUpdate.Add(waterResults[i]);
                    }
                    else
                    {
                        listInsert.Add(waterResults[i]);
                    }
                }
                //
                m_proxyWater.AddNewRows(listInsert); //写入数据库
                m_proxyWater.UpdateRows(listUpdate); //更新数据库

                //m_proxyWater.AddOrUpdate(waterResults);
            }
        }