Exemplo n.º 1
0
        private CommunicationClass.SihuiThermalPowerPlant.Models.checkpoints Getcheckresults_File(int patrolId, string deviceId)
        {
            string strResult = "";

            string basePath = AppDomain.CurrentDomain.BaseDirectory;
            string strPath  = basePath + "Data\\InspectionJson\\GetItem" + Convert.ToString(patrolId) + "_" + deviceId + ".txt";

            strResult = System.IO.File.ReadAllText(strPath, Encoding.Default);

            if (strResult.Contains("404 Not Found"))
            {
                throw new Exception("404 Not Found");
            }

            CommunicationClass.SihuiThermalPowerPlant.Models.checkpoints obj = Newtonsoft.Json.JsonConvert.DeserializeObject <CommunicationClass.SihuiThermalPowerPlant.Models.checkpoints>(strResult);

            return(obj);
        }
Exemplo n.º 2
0
        private void DealPatrolPointItem(Bll bll, List <InspectionTrack> All, List <InspectionTrackHistory> HAdd, List <PatrolPoint> PAll, List <PatrolPoint> PDelete, List <PatrolPointHistory> PHAdd, WebApiLib.Clients.BaseDataClient client)
        {
            try
            {
                List <PatrolPointItem>        ppiList  = bll.PatrolPointItems.ToList();
                List <PatrolPointItemHistory> ppiHList = bll.PatrolPointItemHistorys.ToList();
                if (ppiList == null)
                {
                    ppiList = new List <PatrolPointItem>();
                }

                if (ppiHList == null)
                {
                    ppiHList = new List <PatrolPointItemHistory>();
                }

                List <PatrolPointItem>        PIAll    = new List <PatrolPointItem>();
                List <PatrolPointItem>        PIAdd    = new List <PatrolPointItem>();
                List <PatrolPointItem>        PIEdit   = new List <PatrolPointItem>();
                List <PatrolPointItem>        PIDelete = new List <PatrolPointItem>();
                List <PatrolPointItemHistory> PIHAdd   = new List <PatrolPointItemHistory>();


                foreach (PatrolPoint item in PAll)
                {
                    int             Id       = item.Id;
                    string          deviceId = item.DeviceId;
                    int             ParentId = item.ParentId;
                    InspectionTrack it       = All.Find(p => p.Id == ParentId);
                    if (it == null)
                    {
                        continue;
                    }

                    int patrolId = (int)it.Abutment_Id;
                    CommunicationClass.SihuiThermalPowerPlant.Models.checkpoints recv = client.Getcheckresults(patrolId, deviceId);
                    if (recv == null || recv.checks.Count() <= 0)
                    {
                        continue;
                    }

                    foreach (CommunicationClass.SihuiThermalPowerPlant.Models.results item2 in recv.checks)
                    {
                        PatrolPointItem now = ppiList.Find(p => p.CheckId == item2.checkId && p.ParentId == Id);

                        if (now == null)
                        {
                            now             = new PatrolPointItem();
                            now.ParentId    = Id;
                            now.KksCode     = item2.kksCode;
                            now.CheckItem   = item2.checkItem;
                            now.StaffCode   = item2.staffCode;
                            now.CheckTime   = null;
                            now.dtCheckTime = null;
                            if (item2.checkTime != null)
                            {
                                now.CheckTime   = (item2.checkTime + nEightHourSecond) * 1000;
                                now.dtCheckTime = TimeConvert.TimeStampToDateTime((long)now.CheckTime);
                            }
                            now.CheckId     = item2.checkId;
                            now.CheckResult = item2.checkResult;
                            PIAdd.Add(now);
                        }
                        else
                        {
                            if (item2.checkTime != null)
                            {
                                now.CheckTime   = (item2.checkTime + nEightHourSecond) * 1000;
                                now.dtCheckTime = TimeConvert.TimeStampToDateTime((long)now.CheckTime);
                            }

                            now.CheckResult = item2.checkResult;
                            PIEdit.Add(now);
                        }
                    }
                }

                foreach (PatrolPoint item in PDelete)
                {
                    int Id = item.Id;
                    List <PatrolPointItem> lstDelete = ppiList.FindAll(p => p.ParentId == Id).ToList();
                    if (lstDelete != null && lstDelete.Count() > 0)
                    {
                        PIDelete.AddRange(lstDelete);
                    }
                }

                foreach (PatrolPointHistory item in PHAdd)
                {
                    int    Id                  = item.Id;
                    string deviceId            = item.DeviceId;
                    int    ParentId            = item.ParentId;
                    InspectionTrackHistory ith = HAdd.Find(p => p.Id == ParentId);
                    if (ith == null)
                    {
                        continue;
                    }

                    int patrolId = (int)ith.Abutment_Id;
                    CommunicationClass.SihuiThermalPowerPlant.Models.checkpoints recv = client.Getcheckresults(patrolId, deviceId);
                    if (recv == null || recv.checks.Count() <= 0)
                    {
                        continue;
                    }

                    foreach (CommunicationClass.SihuiThermalPowerPlant.Models.results item2 in recv.checks)
                    {
                        PatrolPointItemHistory history = bll.PatrolPointItemHistorys.Find(p => p.CheckId == item2.checkId && p.ParentId == Id);

                        if (history == null)
                        {
                            history             = new PatrolPointItemHistory();
                            history.ParentId    = Id;
                            history.KksCode     = item2.kksCode;
                            history.CheckItem   = item2.checkItem;
                            history.StaffCode   = item2.staffCode;
                            history.CheckTime   = null;
                            history.dtCheckTime = null;
                            if (item2.checkTime != null)
                            {
                                history.CheckTime   = (item2.checkTime + nEightHourSecond) * 1000;
                                history.dtCheckTime = TimeConvert.TimeStampToDateTime((long)history.CheckTime);
                            }
                            history.CheckId     = item2.checkId;
                            history.CheckResult = item2.checkResult;
                            PIHAdd.Add(history);
                        }
                    }
                }

                bll.PatrolPointItems.AddRange(PIAdd);
                bll.PatrolPointItems.EditRange(PIEdit);
                bll.PatrolPointItems.RemoveList(PIDelete);
                bll.PatrolPointItemHistorys.AddRange(PIHAdd);
            }
            catch (Exception ex)
            {
                string strMessage = ex.Message;
            }
            return;
        }