예제 #1
0
        public LogReports RegulateNewUser(string email, string password, User user, DeviceTag deviceTag, string ipAddress)
        {
            var result = new LogReports();

            // Set initial userStatus
            user.StatusId = UserStatuses.PendingEmailValidation;

            if (email.EndsWith("@fake.fake"))
            {
                result.Add(new LogReport(LogTag.EmailValidationBypassedForTestEmail, new { email }));
                user.StatusId = UserStatuses.Valid;
            }

            return(result);
        }
예제 #2
0
        public void UpdateFromDiscovered(IColorTargetData data)
        {
            var dData = (DreamScreenData)data;

            Brightness  = dData.Brightness;
            LastSeen    = data.LastSeen;
            GroupNumber = dData.GroupNumber;
            DeviceTag   = dData.DeviceTag;
            LastSeen    = DateTime.Now.ToString(CultureInfo.InvariantCulture);
            IpAddress   = dData.IpAddress;
            if (DeviceTag.Contains("DreamScreen"))
            {
                Enable = false;
            }
        }
예제 #3
0
        /// <summary>
        /// Sets the variable value.
        /// </summary>
        private void SetVariable(VarItem varItem, CnlData[] cnlData, int dataIndex, DateTime timestamp)
        {
            try
            {
                DeviceTag deviceTag  = varItem.DeviceTag;
                int       dataLength = deviceTag.DataLength;
                object    value      = 0.0;

                switch (deviceTag.DataType)
                {
                case TagDataType.Double:
                    value = deviceTag.IsArray ?
                            (object)CnlDataConverter.GetDoubleArray(cnlData, dataIndex, dataLength) :
                            CnlDataConverter.GetDouble(cnlData, dataIndex);
                    break;

                case TagDataType.Int64:
                    value = deviceTag.IsArray ?
                            (object)CnlDataConverter.GetInt64Array(cnlData, dataIndex, dataLength) :
                            CnlDataConverter.GetInt64(cnlData, dataIndex);
                    break;

                case TagDataType.ASCII:
                    value = CnlDataConverter.GetAscii(cnlData, dataIndex, dataLength);
                    break;

                case TagDataType.Unicode:
                    value = CnlDataConverter.GetUnicode(cnlData, dataIndex, dataLength);
                    break;
                }

                BaseDataVariableState variable = varItem.Variable;
                variable.Value      = value;
                variable.StatusCode = CnlDataConverter.GetStatus(cnlData, dataIndex, dataLength) > CnlStatusID.Undefined ?
                                      StatusCodes.Good : StatusCodes.Bad;
                variable.Timestamp = timestamp;
                variable.ClearChangeMasks(SystemContext, false);
            }
            catch (Exception ex)
            {
                log.WriteException(ex, Locale.IsRussian ?
                                   "Ошибка при установке значения переменной {0}" :
                                   "Error setting the variable {0}", varItem.Variable.NodeId);
            }
        }
        public LogReports RegulateNewUser(string email, string password, User user, DeviceTag deviceTag, string clientIpAddress)
        {
            //Andriy: I can't setup regulator for now with Ninject properly. So I use this approach for now:
            switch (user.BirthMonth)
            {
            case 1: user.StatusId = UserStatuses.PendingEmailValidation; break;

            case 2: user.StatusId = UserStatuses.Valid; break;

            case 3: user.StatusId = UserStatuses.Valid; user.Banned = true; break;

            case 4: user.StatusId = UserStatuses.PendingSignUpReview; break;

            default: throw new Exception("Can't assign user status. Unexpected BirthMonth.");
            }
            var result = new LogReports();

            return(result);
        }
        public DeviceTagDto Update(CreateDeviceTagDto input)
        {
            var deviceQuery = _deviceRepository.GetAll().Where(d => d.DeviceName == input.DeviceName);

            if (!deviceQuery.Any())
            {
                throw new ApplicationException("该设备不存在");
            }

            var device    = deviceQuery.FirstOrDefault();
            var deviceTag = new DeviceTag()
            {
                TagId  = input.TagId,
                Device = device,
                Id     = input.Id
            };
            var result = _deviceTagRepository.Update(deviceTag);

            CurrentUnitOfWork.SaveChanges();
            return(ObjectMapper.Map <DeviceTagDto>(result));
        }
예제 #6
0
        /// <summary>
        /// Builds a payload based on the device tag data to publish.
        /// </summary>
        public string BuildPayload(DeviceTag deviceTag, CnlData[] cnlData, int dataIndex)
        {
            int  dataLength    = deviceTag.DataLength;
            int  stat          = CnlDataConverter.GetStatus(cnlData, dataIndex, dataLength);
            bool formatIsEmpty = string.IsNullOrEmpty(dsOptions.PublishOptions.PublishFormat);

            if (formatIsEmpty && stat <= CnlStatusID.Undefined)
            {
                return(dsOptions.PublishOptions.UndefinedValue);
            }

            string valStr = "";

            switch (deviceTag.DataType)
            {
            case TagDataType.Double:
                valStr = deviceTag.IsNumericArray
                        ? ArrayToString(CnlDataConverter.GetDoubleArray(cnlData, dataIndex, dataLength))
                        : CnlDataConverter.GetDouble(cnlData, dataIndex).ToString(NumberFormatInfo.InvariantInfo);
                break;

            case TagDataType.Int64:
                valStr = deviceTag.IsNumericArray
                        ? ArrayToString(CnlDataConverter.GetInt64Array(cnlData, dataIndex, dataLength))
                        : CnlDataConverter.GetInt64(cnlData, dataIndex).ToString(NumberFormatInfo.InvariantInfo);
                break;

            case TagDataType.ASCII:
                valStr = CnlDataConverter.GetAscii(cnlData, dataIndex, dataLength);
                break;

            case TagDataType.Unicode:
                valStr = CnlDataConverter.GetUnicode(cnlData, dataIndex, dataLength);
                break;
            }

            return(formatIsEmpty
                ? valStr
                : MqttUtils.FormatPayload(dsOptions.PublishOptions.PublishFormat, valStr, stat));
        }
예제 #7
0
        /// <summary>
        /// Sets value, status and format of the specified tag.
        /// </summary>
        private void SetTagData(int tagIndex, object val, int stat)
        {
            try
            {
                DeviceTag deviceTag = DeviceTags[tagIndex];

                if (deviceTag.Aux is DeviceTagMeta tagMeta && val != null)
                {
                    tagMeta.ActualDataType = val.GetType();
                }

                if (val is string strVal)
                {
                    deviceTag.DataType = TagDataType.Unicode;
                    deviceTag.Format   = TagFormat.String;
                    DeviceData.SetUnicode(tagIndex, strVal, stat);
                }
                else if (val is DateTime dtVal)
                {
                    deviceTag.DataType = TagDataType.Double;
                    deviceTag.Format   = TagFormat.DateTime;
                    DeviceData.SetDateTime(tagIndex, dtVal, stat);
                }
                else
                {
                    deviceTag.DataType = TagDataType.Double;
                    deviceTag.Format   = TagFormat.FloatNumber;
                    DeviceData.Set(tagIndex, Convert.ToDouble(val), stat);
                }
            }
            catch (Exception ex)
            {
                Log.WriteInfo(ex.BuildErrorMessage(Locale.IsRussian ?
                                                   "Ошибка при установке данных тега" :
                                                   "Error setting tag data"));
            }
        }
예제 #8
0
        /// <summary>
        /// Raised when the Value attribute is written.
        /// </summary>
        private ServiceResult OnSimpleWriteValue(ISystemContext context, NodeState node, ref object value)
        {
            string varPath = node.NodeId.ToString();

            try
            {
                log.WriteAction(Locale.IsRussian ?
                                "Запись переменной {0} = {1}" :
                                "Write variable {0} = {1}", varPath, value?.ToString() ?? "");

                if (varByPath.TryGetValue(varPath, out VarItem varItem))
                {
                    DeviceTag deviceTag = varItem.DeviceTag;
                    double    cmdVal    = 0.0;
                    byte[]    cmdData   = null;

                    switch (deviceTag.DataType)
                    {
                    case TagDataType.Double:
                        if (deviceTag.IsArray)
                        {
                            cmdData = DoubleArrayToCmdData(value as Array, deviceTag.DataLength);
                        }
                        else
                        {
                            cmdVal = Convert.ToDouble(value);
                        }
                        break;

                    case TagDataType.Int64:
                        if (deviceTag.IsArray)
                        {
                            cmdData = Int64ArrayToCmdData(value as Array, deviceTag.DataLength);
                        }
                        else
                        {
                            cmdVal = Convert.ToInt64(value);
                        }
                        break;

                    case TagDataType.ASCII:
                    case TagDataType.Unicode:
                        cmdData = TeleCommand.StringToCmdData(value?.ToString());
                        break;
                    }

                    commContext.SendCommand(new TeleCommand
                    {
                        CommandID    = ScadaUtils.GenerateUniqueID(),
                        CreationTime = DateTime.UtcNow,
                        CmdTypeID    = CmdTypeID.Standard,
                        DeviceNum    = varItem.DeviceNum,
                        CmdCode      = varItem.DeviceTag.Code,
                        CmdVal       = cmdVal,
                        CmdData      = cmdData
                    }, DriverUtils.DriverCode);
                }

                return(ServiceResult.Good);
            }
            catch (Exception ex)
            {
                log.WriteException(ex, Locale.IsRussian ?
                                   "Ошибка при записи переменной {0}" :
                                   "Error writing the variable {0}", varPath);
                return(new ServiceResult(StatusCodes.Bad));
            }
        }
예제 #9
0
        /// <summary>
        /// Creates a new variable according to the device tag.
        /// </summary>
        private BaseDataVariableState CreateVariable(NodeState parent, string pathPrefix, DeviceTag deviceTag)
        {
            NodeId opcDataType  = DataTypeIds.Double;
            object defaultValue = 0.0;
            bool   isArray      = deviceTag.IsArray;

            switch (deviceTag.DataType)
            {
            case TagDataType.Double:
                defaultValue = isArray ? (object)new double[deviceTag.DataLength] : 0.0;
                break;

            case TagDataType.Int64:
                opcDataType  = DataTypeIds.Int64;
                defaultValue = isArray ? (object)new long[deviceTag.DataLength] : (long)0;
                break;

            case TagDataType.ASCII:
            case TagDataType.Unicode:
                opcDataType  = DataTypeIds.String;
                defaultValue = "";
                break;
            }

            BaseDataVariableState variable = CreateVariable(parent, pathPrefix + deviceTag.Code,
                                                            deviceTag.Code, deviceTag.Name, opcDataType, isArray, defaultValue);

            return(variable);
        }
예제 #10
0
 public DeviceTag Update(DeviceTag entity)
 {
     return(_deviceTagRepository.Update(entity));
 }
예제 #11
0
 public void Delete(DeviceTag entity)
 {
     _deviceTagRepository.Delete(entity);
 }
        public void ReadXlsData(string sProject, string sUser, string filename)
        {
            //DisplayInfoHanlder displayinfo = new DisplayInfoHanlder(Disp);
            //this.Invoke(displayinfo, new object[] { "准备提取数据 ", "",0 });

        
            Disp("准备提取数据  ", "", 0);

            m_app = new Microsoft.Office.Interop.Excel.Application();
            m_app.UserControl = true;//干什么用的?
            m_app.Visible = false; m_app.DisplayAlerts = false;


            m_wkbook = m_app.Workbooks.Add(filename);
            m_wksheet = m_wkbook.Worksheets.get_Item(1) as Worksheet;
            m_range = m_wksheet.UsedRange;

            int count = m_range.Rows.Count;



            string projectId = sProject;

            List<ProjectBlock> blockList = ProjectBlock.FindAll(projectId);
            List<ProjectSystem> systemList = ProjectSystem.FindAll(int.Parse(projectId));
            List<ProjectDeck> deckList = ProjectDeck.FindAll(projectId);
            List<ProjectRoom> roomList = ProjectRoom.FindAll(projectId);
            List<ProjectZone> zoneList = ProjectZone.FindAll(projectId);
          //  List<string> taglist = Device.FindAllTagNo(projectId);

            string blockName="", upblockName=""; ProjectBlock pbTmp = null, pubTmp = null;
            string systemName=""; ProjectSystem psTmp = null;
            string deckName=""; ProjectDeck pdTmp = null;
            string roomName=""; ProjectRoom prTmp = null;
            string zoneName=""; ProjectZone pzTmp = null;


            string pdName1 = ""; Equipment.BatchImport.Core.ProjectDrawing pdTmp1 = null;
            string pdName2 = ""; Equipment.BatchImport.Core.ProjectDrawing pdTmp2 = null;
            string spack = ""; DevicePackage DevicePackageTem = null;
            List<DevicePackage> devicePackList = DevicePackage.FindAll(int.Parse(projectId));
            List< Equipment.BatchImport.Core.ProjectDrawing> pdrawingList = Equipment.BatchImport.Core.ProjectDrawing.FindAll(projectId);
            List<DeviceProdReqDpt> DvProDepList = DeviceProdReqDpt.FindAll();
            List<DeviceDiscipline> DVDspList = DeviceDiscipline.FindAll(int.Parse(projectId));
            string sProdRequireDept_Name="", sDiscipline_Name="";
            DeviceProdReqDpt cDvProDept = null;
            DeviceDiscipline cDvDs = null;


            
            List<Device> deviceList = new List<Device>();


            List<Device> deviceListadd = new List<Device>();
            List<Device> deviceListupdate = new List<Device>();

            Device d = null;
            System.Diagnostics.Trace.WriteLine(count);


            bool hasError = false, hanErrorAll = false; int errcount = 0;
            string tagno = "", equname = "", equnamec = "", majequ = "", equtype = "";

            string blockIds = string.Empty;  string upblockIds = string.Empty;

            string txtfilename =  System.Windows.Forms.Application.StartupPath+"\\错误信息.txt";
            StreamWriter sw = new StreamWriter(txtfilename, false, Encoding.GetEncoding("gb2312"));
         
            try
            {
                for (int i = 4; i <= count; i++)
                {
                    hasError = false;

                    blockIds = upblockIds = string.Empty;
                    blockName = upblockName = deckName = roomName = zoneName = equname = equnamec = string.Empty;
                   spack = tagno = majequ = equtype=sProdRequireDept_Name = sDiscipline_Name = pdName1 = pdName2 = string.Empty;

                    pbTmp = null;
                    pubTmp = null;
                    psTmp = null;
                     pdTmp = null;
                     prTmp = null;
                     pzTmp = null;
                     pdTmp1 = null;
                     pdTmp2 = null;
                     DevicePackageTem = null;
                     cDvProDept = null;
                     cDvDs = null;


                     if (m_range.get_Range("C" + i, "C" + i).Value2 == null)
                        break;

                    //*****判断是否为空,要运行测试

                    Disp("正在提取数据  ", Math.Round((i - 3.0) / count, 2) * 100.0 + "%", Convert.ToInt32(Math.Round((i - 3.0) / count, 2) * 100));
                    //this.Invoke(displayinfo, new object[] { "正在提取数据", Math.Round((i - 3.0) / count, 2) * 100.0 + "%", Convert.ToInt32(Math.Round((i - 3.0) / count, 2) * 100) });


                    #region  判断数据


                    //EquiName_eng
                    if (m_range.get_Range("C" + i, "C" + i).Value2 != null)
                    {
                        equname = m_range.get_Range("C" + i, "C" + i).Value2.ToString().Trim();
                        if (equname == string.Empty)
                        {
                            SetInfoText("第 " + i + "行数据中[" + equname + "]设备英文名有误!请修改!");
                            hasError = true;
                            hanErrorAll = true;
                            System.Diagnostics.Trace.WriteLine("第 " + i + "行数据中[" + equname + "]设备英文名有误!请修改!");
                            sw.WriteLine("第 " + i + "行数据中[" + equname + "]设备英文名有误!请修改!");
                        }
                    }
                    else
                    {
                        SetInfoText("第 " + i + "行数据中[" + equname + "]设备英文名有误1!请修改!");
                        hasError = true;
                        hanErrorAll = true;
                        System.Diagnostics.Trace.WriteLine("第 " + i + "行数据中[" + equname + "]设备英文名有误!请修改!");
                        sw.WriteLine("第 " + i + "行数据中[" + equname + "]设备英文名有误!请修改!");
                        //   continue;
                    }

                    //EquiName_chn

                    if (m_range.get_Range("D" + i, "D" + i).Value2 != null)
                    {

                        equnamec = m_range.get_Range("D" + i, "D" + i).Value2.ToString().Trim();
                        if (equnamec == string.Empty)
                        {
                            SetInfoText("第 " + i + "行数据中[" + equnamec + "]设备中文名有误!请修改!");
                            hasError = true;
                            hanErrorAll = true;
                            System.Diagnostics.Trace.WriteLine("第 " + i + "行数据中[" + equnamec + "]设备中文名有误!请修改!");
                            sw.WriteLine("第 " + i + "行数据中[" + equnamec + "]设备中文名有误!请修改!");
                        }
                    }
                    else
                    {
                        SetInfoText("第 " + i + "行数据中[" + equnamec + "]设备中文名有误!请修改!");
                        hasError = true;
                        hanErrorAll = true;
                        System.Diagnostics.Trace.WriteLine("第 " + i + "行数据中[" + equnamec + "]设备中文名有误!请修改!");
                        sw.WriteLine("第 " + i + "行数据中[" + equnamec + "]设备中文名有误!请修改!");
                    }


                    //包号  devicePackList
                    if (m_range.get_Range("L" + i, "L" + i).Value2 != null && m_range.get_Range("L" + i, "L" + i).Value2.ToString().Trim() != "")
                    {

                        spack = m_range.get_Range("L" + i, "L" + i).Value2.ToString().Trim();
                        System.Diagnostics.Trace.WriteLine(spack);
                        DevicePackageTem = devicePackList.Find((DevicePackage dp) => dp.PACKAGE_NO.Trim().ToUpper() == spack.ToUpper());
                        if (DevicePackageTem == null)
                        {
                            SetInfoText("第 " + i + "行数据中[" + spack + "]包号有误!请修改!");
                            hasError = true;
                            hanErrorAll = true;
                            sw.WriteLine("第 " + i + "行数据中[" + spack + "]包号有误!请修改!");

                        }



                        //    Core.Device.GetPackageId(Convert.ToInt32(projectId), m_range.get_Range("L" + i, "L" + i).Value2.ToString().Trim());
                        //System.Diagnostics.Trace.WriteLine("第 " + i + "行数据中[" + ipack + "]包号 ");
                        //if (ipack == 0)
                        //{
                        //    SetInfoText("第 " + i + "行数据中[" + pdName1 + "]包号有误!请修改!");
                        //    hasError = true;
                        //    hanErrorAll = true;
                        //    sw.WriteLine("第 " + i + "行数据中[" + pdName1 + "]包号有误!请修改!");

                        //    //  continue;
                        //}

                    }


                    //系统原理图号
                    if (m_range.get_Range("T" + i, "T" + i).Value2 != null && m_range.get_Range("T" + i, "T" + i).Value2.ToString().Trim() != "")
                    {
                        pdName1 = m_range.get_Range("T" + i, "T" + i).Value2.ToString().Trim();
                        pdTmp1 = pdrawingList.Find(( Equipment.BatchImport.Core.ProjectDrawing pdraw) => pdraw.DRAWING_NO.Trim().ToUpper() == pdName1.ToUpper());
                        if (pdTmp1 == null)
                        {
                            SetInfoText("第 " + i + "行数据中[" + pdName1 + "]系统原理图号有误!请修改!");
                            hasError = true;
                            hanErrorAll = true;
                            sw.WriteLine("第 " + i + "行数据中[" + pdName1 + "]系统原理图号有误!请修改!");

                            //  continue;
                        }

                    }


                    //布置图号
                    if (m_range.get_Range("U" + i, "U" + i).Value2 != null && m_range.get_Range("U" + i, "U" + i).Value2.ToString().Trim() != "")
                    {
                        pdName2 = m_range.get_Range("U" + i, "U" + i).Value2.ToString().Trim();
                        pdTmp2 = pdrawingList.Find(( Equipment.BatchImport.Core.ProjectDrawing pdraw) => pdraw.DRAWING_NO.Trim().ToUpper() == pdName2.ToUpper());
                        if (pdTmp2 == null)
                        {
                            SetInfoText("第 " + i + "行数据中[" + pdName2 + "]系统布置图号有误!请修改!");
                            hasError = true;
                            hanErrorAll = true;
                            sw.WriteLine("第 " + i + "行数据中[" + pdName2 + "]系统布置图号有误!请修改!");

                            //  continue;
                        }

                    }
               


                 
                    //生产需求部门
                    if (m_range.get_Range("V" + i, "V" + i).Value2 != null && m_range.get_Range("V" + i, "V" + i).Value2.ToString().Trim() != "")
                    {
                        sProdRequireDept_Name = m_range.get_Range("V" + i, "V" + i).Value2.ToString().Trim();
                      
                        cDvProDept = DvProDepList.Find((DeviceProdReqDpt dvprodept) => dvprodept.DptName.Trim() == sProdRequireDept_Name);
                      
                        if (cDvProDept == null)
                        {
                            SetInfoText("第 " + i + "行数据中[" + sProdRequireDept_Name + "]生产需求部门名有误!请修改!");
                            hasError = true;
                            hanErrorAll = true;
                            sw.WriteLine("第 " + i + "行数据中[" + sProdRequireDept_Name + "]生产需求部门名有误!请修改!");
                        }

                    }
                    //else
                    //{
                    //    SetInfoText("第 " + i + "行数据中[" + sProdRequireDept_Name + "]生产需求部门名有误!请修改!");
                    //    hasError = true;
                    //    hanErrorAll = true;
                    //    sw.WriteLine("第 " + i + "行数据中[" + sProdRequireDept_Name + "]生产需求部门名有误!请修改!");

                    //}
                    //技术专业
                    if (m_range.get_Range("W" + i, "W" + i).Value2 != null && m_range.get_Range("W" + i, "W" + i).Value2.ToString().Trim() != "")
                    {
                        sDiscipline_Name = m_range.get_Range("W" + i, "W" + i).Value2.ToString().Trim();
                        cDvDs = DVDspList.Find((DeviceDiscipline dvdisp) => dvdisp.CODE.Trim() == sDiscipline_Name);
                        if (cDvDs == null)
                        {
                            SetInfoText("第 " + i + "行数据中[" + sDiscipline_Name + "]技术专业名有误!请修改!");
                            hasError = true;
                            hanErrorAll = true;
                            sw.WriteLine("第 " + i + "行数据中[" + sDiscipline_Name + "]技术专业名有误!请修改!");

                            //  continue;
                        }

                    }
                    //else
                    //{
                    //    SetInfoText("第 " + i + "行数据中[" + sDiscipline_Name + "]技术专业名有误!请修改!");
                    //    hasError = true;
                    //    hanErrorAll = true;
                    //    sw.WriteLine("第 " + i + "行数据中[" + sDiscipline_Name + "]技术专业名有误!请修改!");
                    //}


                    //System
                    if (m_range.get_Range("AC" + i, "AC" + i).Value2 != null && m_range.get_Range("AC" + i, "AC" + i).Value2.ToString().Trim() != "")
                    {
                        systemName = m_range.get_Range("AC" + i, "AC" + i).Value2.ToString().Trim();
                        //systemName = systemName.Substring(5, systemName.Length - 5);
                        System.Diagnostics.Trace.WriteLine(systemName);
                        psTmp = systemList.Find(delegate(ProjectSystem ps) { return ps.Code.Trim()==systemName; });
                        if (psTmp == null)
                        {
                            SetInfoText("第 " + i + "行数据中[" + systemName + "]子系统名有误!请修改!");
                            hasError = true;
                            hanErrorAll = true;
                            System.Diagnostics.Trace.WriteLine("第 " + i + "行数据中[" + systemName + "]子系统名有误!请修改!");
                            sw.WriteLine("第 " + i + "行数据中[" + systemName + "]子系统名有误!请修改!");
                            //   continue;
                        }

                    }
                    //else
                    //{
                    //    SetInfoText("第 " + i + "行数据中[" + systemName + "]子系统名有误!请修改!");
                    //    hasError = true;
                    //    hanErrorAll = true; sw.WriteLine("第 " + i + "行数据中[" + systemName + "]子系统名有误!请修改!");
                    //}

                    System.Uri u;
                    
                 

                    //Block 
                    if (m_range.get_Range("AD" + i, "AD" + i).Value2 != null && m_range.get_Range("AD" + i, "AD" + i).Value2.ToString().Trim().ToLower() != "")
                    {
                        blockName = m_range.get_Range("AD" + i, "AD" + i).Value2.ToString().Trim().ToLower();
                       
                        foreach (string block in blockName.Split(','))
                        {


                            pbTmp = blockList.Find(delegate(ProjectBlock pb) { return pb.Description.Trim().ToLower() == block.Trim(); });
                            if (pbTmp == null)
                            {
                                SetInfoText("第 " + i + "行数据中[" + block + "]分段名有误!请修改!");
                                hasError = true;
                                hanErrorAll = true;
                                System.Diagnostics.Trace.WriteLine("第 " + i + "行数据中[" + block + "]分段名有误!请修改!");
                                sw.WriteLine("第 " + i + "行数据中[" + block + "]分段名有误!请修改!");

                            }
                            else
                                blockIds += "," + pbTmp.Block_Id.ToString();
                        }
                        if (blockIds.StartsWith(",")) blockIds = blockIds.Substring(1);

                    }

                    //Upper Block
                    if (m_range.get_Range("AE" + i, "AE" + i).Value2 != null && m_range.get_Range("AE" + i, "AE" + i).Value2.ToString().Trim().ToLower() != "")
                    {
                        upblockName = m_range.get_Range("AE" + i, "AE" + i).Value2.ToString().Trim().ToLower();

                        foreach (string block in upblockName.Split(','))
                        {

                            pubTmp = blockList.Find(delegate(ProjectBlock pb) { return pb.Description.Trim().ToLower() == block.Trim(); });
                            if (pubTmp == null)
                            {
                                SetInfoText("第 " + i + "行数据中[" + block + "]上分段名有误!请修改!");
                                hasError = true;
                                hanErrorAll = true;
                                System.Diagnostics.Trace.WriteLine("第 " + i + "行数据中[" + block + "]上分段名有误!请修改!");
                                sw.WriteLine("第 " + i + "行数据中[" + block + "]上分段名有误!请修改!");
                            }
                            else
                                upblockIds += "," + pubTmp.Block_Id.ToString();
                        }
                        if (upblockIds.StartsWith(",")) upblockIds = upblockIds.Substring(1);
                    }

                    //Deck 
                    if (m_range.get_Range("AF" + i, "AF" + i).Value2 != null && m_range.get_Range("AF" + i, "AF" + i).Value2.ToString().Trim() != "")
                    {
                        deckName = m_range.get_Range("AF" + i, "AF" + i).Value2.ToString().Trim();
                        pdTmp = deckList.Find(delegate(ProjectDeck pd) { return pd.Description.Trim().ToLower() == deckName.ToLower(); });
                        if (pdTmp == null)
                        {
                            //  excelRange.get_Range("P" + i, "P" + i).Value2 = "未找到Zone[" + zoneName + "]";
                            SetInfoText("第 " + i + "行数据中[" + deckName + "]甲板名有误!请修改!");
                            hasError = true;
                            hanErrorAll = true;
                            System.Diagnostics.Trace.WriteLine("第 " + i + "行数据中[" + deckName + "]甲板名有误!请修改!");
                            sw.WriteLine("第 " + i + "行数据中[" + deckName + "]甲板名有误!请修改!");
                            // continue;
                        }

                    }
                   // else
                    //{
                        
                        //SetInfoText("第 " + i + "行数据中[" + deckName + "]甲板名有误!请修改!");
                        //hasError = true;
                        //hanErrorAll = true; sw.WriteLine("第 " + i + "行数据中[" + deckName + "]甲板名有误!请修改!");
                   // }


                    //Room
                    if (m_range.get_Range("AG" + i, "AG" + i).Value2 != null && m_range.get_Range("AG" + i, "AG" + i).Value2.ToString().Trim().ToLower() != "")
                    {

                        roomName = m_range.get_Range("AG" + i, "AG" + i).Value2.ToString().Trim().ToLower();


                        prTmp = roomList.Find(delegate(ProjectRoom pr) { return pr.Room_Key.Trim().ToLower() == roomName; });
                        if (prTmp == null)
                        {
                            SetInfoText("第 " + i + "行数据中[" + roomName + "]房间名有误!请修改!");
                            hasError = true;
                            hanErrorAll = true;
                            System.Diagnostics.Trace.WriteLine("第 " + i + "行数据中[" + roomName + "]房间名有误!请修改!");
                            sw.WriteLine("第 " + i + "行数据中[" + roomName + "]房间名有误!请修改!");
                            //sw.WriteLine(roomName);
                        }

                    }
                    //else
                    //{
                    //    SetInfoText("第 " + i + "行数据中[" + roomName + "]房间名有误!请修改!");
                    //    hasError = true;
                    //    hanErrorAll = true; sw.WriteLine("第 " + i + "行数据中[" + roomName + "]房间名有误!请修改!");
                    //}

                    //Zone //
                    if (m_range.get_Range("AH" + i, "AH" + i).Value2 != null && m_range.get_Range("AH" + i, "AH" + i).Value2.ToString().Trim() != "")
                    {
                        zoneName = m_range.get_Range("AH" + i, "AH" + i).Value2.ToString().Trim();
                        pzTmp = zoneList.Find(delegate(ProjectZone pz) { return pz.Description.Trim().ToLower() == zoneName.ToLower(); });
                        if (pzTmp == null)
                        {
                            SetInfoText("第 " + i + "行数据中[" + zoneName + "]区域名有误!请修改!");
                            hasError = true;
                            hanErrorAll = true;
                            System.Diagnostics.Trace.WriteLine("第 " + i + "行数据中[" + zoneName + "]区域名有误!请修改!");
                            sw.WriteLine("第 " + i + "行数据中[" + zoneName + "]区域名有误!请修改!");
                            //   continue;
                        }

                    }
                    //else
                    //{
                    //    SetInfoText("第 " + i + "行数据中[" + zoneName + "]区域名有误!请修改!");
                    //    hasError = true;
                    //    hanErrorAll = true; sw.WriteLine("第 " + i + "行数据中[" + zoneName + "]区域名有误!请修改!");
                    //}

                    //主设备
                    if (m_range.get_Range("AL" + i, "AL" + i).Value2 != null)
                    {
                        majequ = m_range.get_Range("AL" + i, "AL" + i).Value2.ToString().Trim().ToUpper();
                        if (majequ == "N") majequ = "F";
                        else if (majequ == "Y") majequ = "M";
                    }
                    else
                    {
                        majequ = "";
                    }



                    #endregion
                    string des1, des2, tec1, tec2;
                 
                    #region //将数据加到列表中

                    if (!hasError)
                    {
                        d = new Device();

                        d.Project_Id = projectId.ToString();
                        tagno = m_range.get_Range("B" + i, "B" + i).Value2 == null ? "" : m_range.get_Range("B" + i, "B" + i).Value2.ToString().Trim().ToUpper();
                        d.Tag_No = tagno;
                        d.Equipment = equname;
                        d.EQ_NAME_CN = equnamec;
                        d.DUTYORSTANDBY = (m_range.get_Range("E" + i, "E" + i).Value2 == null) ? string.Empty : m_range.get_Range("E" + i, "E" + i).Value2.ToString().Trim();//Duty或备用
                        d.Power = (m_range.get_Range("F" + i, "F" + i).Value2 == null) ? string.Empty : m_range.get_Range("F" + i, "F" + i).Value2.ToString().Trim();//功率
                        d.Power_Factor = (m_range.get_Range("G" + i, "G" + i).Value2 == null) ? string.Empty : m_range.get_Range("G" + i, "G" + i).Value2.ToString().Trim();//功率因数
                        des1 = (m_range.get_Range("H" + i, "H" + i).Value2 == null) ? string.Empty : m_range.get_Range("H" + i, "H" + i).Value2.ToString().Trim();
                        des2 = (m_range.get_Range("I" + i, "I" + i).Value2 == null) ? string.Empty : m_range.get_Range("I" + i, "I" + i).Value2.ToString().Trim();
                        d.DETAIL_DESCRIPTION = des1 + "###" + des2 == "###" ? "" : des1 + "###" + des2;//详细描述
                        tec1 = (m_range.get_Range("J" + i, "J" + i).Value2 == null) ? string.Empty : m_range.get_Range("J" + i, "J" + i).Value2.ToString().Trim();
                        tec2 = (m_range.get_Range("K" + i, "K" + i).Value2 == null) ? string.Empty : m_range.get_Range("K" + i, "K" + i).Value2.ToString().Trim();
                        d.Remark = tec1 + "###" + tec2 == "###" ? "" : tec1 + "###" + tec2;//技术参数


                       //L
                        d.PackageId = DevicePackageTem == null ? 0 : DevicePackageTem.ID;
                        //if ((m_range.get_Range("L" + i, "L" + i).Value2 != null))
                        //{
                           
                        // // d.PackageId = m_range.get_Range("L" + i, "L" + i).Value2.ToString().Trim() == "" ? 0 : Core.Device.GetPackageId(Convert.ToInt32(projectId), m_range.get_Range("L" + i, "L" + i).Value2.ToString().Trim());
                        //}


                        d.ERP_CODE = (m_range.get_Range("M" + i, "M" + i).Value2 == null) ? string.Empty : m_range.get_Range("M" + i, "M" + i).Value2.ToString().Trim();//物资编码
                        d.MEO_NO = m_range.get_Range("N" + i, "N" + i).Value2 == null ? string.Empty : m_range.get_Range("N" + i, "N" + i).Value2.ToString().Trim();//MEO
                        d.MSS_NO = m_range.get_Range("O" + i, "O" + i).Value2 == null ? string.Empty : m_range.get_Range("O" + i, "O" + i).Value2.ToString().Trim(); ;//MSS NO.
                        d.Maker = m_range.get_Range("P" + i, "P" + i).Value2 == null ? string.Empty : m_range.get_Range("P" + i, "P" + i).Value2.ToString().Trim();//生产厂家
                        d.Contractor = m_range.get_Range("Q" + i, "Q" + i).Value2 == null ? string.Empty : m_range.get_Range("Q" + i, "Q" + i).Value2.ToString().Trim();//合同方名称
                        d.InfoStatusD = m_range.get_Range("R" + i, "R" + i).Value2 == null ? string.Empty : m_range.get_Range("R" + i, "R" + i).Value2.ToString().Trim();
                        d.InfoStatusF = m_range.get_Range("S" + i, "S" + i).Value2 == null ? string.Empty : m_range.get_Range("S" + i, "S" + i).Value2.ToString().Trim();

                        d.FoundationFlag = m_range.get_Range("X" + i, "X" + i).Value2 == null ? string.Empty : m_range.get_Range("X" + i, "X" + i).Value2.ToString().Trim(); //是否需要基座
                        d.CoamingFlag = m_range.get_Range("Y" + i, "Y" + i).Value2 == null ? string.Empty : m_range.get_Range("Y" + i, "Y" + i).Value2.ToString().Trim();//是否需要接水/油盘
                        d.Ofe_Bfe = m_range.get_Range("Z" + i, "Z" + i).Value2 == null ? string.Empty : m_range.get_Range("Z" + i, "Z" + i).Value2.ToString().Trim();

                        d.StoreMaintainFlag = m_range.get_Range("AA" + i, "AA" + i).Value2 == null ? string.Empty : m_range.get_Range("AA" + i, "AA" + i).Value2.ToString().Trim();
                        d.CableConectFlag = m_range.get_Range("AB" + i, "AB" + i).Value2 == null ? string.Empty : m_range.get_Range("AB" + i, "AB" + i).Value2.ToString().Trim();





                        
                        d.ProdRequireDept = cDvProDept==null?0:cDvProDept.Id;
                        d.Discipline_Id =cDvDs==null?0: cDvDs.Id;

                        d.System_Id = psTmp == null ? 0 : psTmp.System_Id;
                        d.Deck_Id = deckName==string.Empty?0: pdTmp.Deck_Id;
                        d.Room_Id = roomName==string.Empty ?0: prTmp.Room_ID;
                        d.Zone_Id = zoneName ==string.Empty?0: pzTmp.Zone_Id;



                        d.Dry_Weight = m_range.get_Range("AI" + i, "AI" + i).Value2 == null ? string.Empty : m_range.get_Range("AI" + i, "AI" + i).Value2.ToString().Trim();
                        d.Operating_weight = m_range.get_Range("AJ" + i, "AJ" + i).Value2 == null ? string.Empty : m_range.get_Range("AJ" + i, "AJ" + i).Value2.ToString().Trim();

                        d.OVERALL_DIMENSION = m_range.get_Range("AK" + i, "AK" + i).Value2 == null ? string.Empty : m_range.get_Range("AK" + i, "AK" + i).Value2.ToString().Trim();

                        d.MajorFlag = majequ;//AL


                        d.Creater = tbCreater.Text.Trim();// "shihai.liu";
                        
                        d.NewFlag = "Y";
                        d.DeleteFlag = "N";

                        d.EquipType = equtype;

               

                        d.newBlock = blockIds;// pbTmp.Block_Id;
                        d.UPPERFLAG_NO = "N";

                        d.UpperBlock = upblockIds;// pubTmp.Block_Id;
                        d.UPPERFLAG_YES = "Y";
                        
                        //原理图和布置图
                        d.PIDDrawNo =pdTmp1==null?0: pdTmp1.DRAWING_ID;
                        d.ArrangementDrawNo =pdTmp2==null?0: pdTmp2.DRAWING_ID;
                   
                        

                         deviceList.Add(d);


            

                    }
                    else
                        errcount++;
                    #endregion
                }



                Disp("提取数据完成  ", "100%", 100);
                //区分添加和更新
                //取出所有设备ID,TAGNO
                Disp("正在转换数据  ", "", 0);
                dic = DeviceTag .GetDeviceTag(projectId);
                
                int tagcount = deviceList.Count;
                double  tagnum = 0;
                foreach (Device de in deviceList)
                {
                    tagnum++;
                    Disp("正在转换数据  ", Math.Round((tagnum) / tagcount, 2) * 100.0 + "%", Convert.ToInt32(Math.Round((tagnum) / tagcount, 2) * 100));
                 
                    if (de.Tag_No == "")
                        deviceListadd.Add(de);
                    else
                    {

                        if (dic.ContainsKey(de.Tag_No))
                        {
                            de.Device_Id = dic[de.Tag_No];
                            de.Updater = tbCreater.Text.Trim().ToLower();
                   //         if (deviceListupdate.Exists(delegate(Device dd) { return dd.Tag_No == de.Tag_No; }))
                            if (deviceListupdate.Exists((dd) =>  dd.Tag_No == de.Tag_No ))
                            {
                                SetInfoText("Tag_No为[" + de.Tag_No + "]的设备有重复!请修改!");
                                hasError = true;
                                hanErrorAll = true;
                                System.Diagnostics.Trace.WriteLine("Tag_No为[" + de.Tag_No + "]的设备有重复!请修改!");
                                sw.WriteLine("Tag_No为[" + de.Tag_No + "]的设备有重复!请修改!");
                            }
                            else
                                deviceListupdate.Add(de);
                        }
                        else
                        {
                            if (deviceListadd.Exists(  dd=>  dd.Tag_No == de.Tag_No))
                            {
                                SetInfoText("Tag_No为[" + de.Tag_No + "]的设备有重复!请修改!");
                                hasError = true;
                                hanErrorAll = true;
                                System.Diagnostics.Trace.WriteLine("Tag_No为[" + de.Tag_No + "]的设备有重复!请修改!");
                                sw.WriteLine("Tag_No为[" + de.Tag_No + "]的设备有重复!请修改!");
                            }
                            else
                                deviceListadd.Add(de);
                        }
                          

                    }

                }

              //  this.Invoke(displayinfo, new object[] { "准备导入数据库 ", "", 0 });

                Disp("准备导入数据库 ", "", 0);
                System.Diagnostics.Trace.WriteLine(deviceListadd.Count);
                System.Diagnostics.Trace.WriteLine(deviceListupdate.Count);

          
            }

            catch (Exception et) { MessageBox.Show(et.Message); }


            finally
            {
                if (hanErrorAll == true)
                {
                    if (errcount > 10)
                     MessageBox.Show("错误数据太多,程序已暂时结束,请修改后再进行此操作!", "Import Equipment Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    else
                    MessageBox.Show("数据有错误,请修改后再进行此操作!", "Import Equipment Information", MessageBoxButtons.OK, MessageBoxIcon.Error);


                }
                else
                {
                    if (deviceListadd.Count > 0)//添加新的设备纪录
                    {
                        
                        //Device.md = new Device.mydel(this.Disp);

                        //if (Device.Add(deviceListadd))
                        //{

                        //    SetInfoText("成功导入成功了" + deviceListadd.Count + "个设备信息!");
                        //    System.Diagnostics.Trace.WriteLine("成功导入成功了" + deviceListadd.Count + "个设备信息!");
                        //}
                        //else
                        //{
                        //    SetInfoText("导入出现错误!");
                        //    System.Diagnostics.Trace.WriteLine("导入出现错误!");


                        //}

                    }

                    if (deviceListupdate.Count > 0)//更新设备纪录
                    {
                        //Device.md = new Device.mydel(this.Disp);

                        //if (Device.Update(deviceListupdate))
                        //{
                        //    SetInfoText("成功更新成功了" + deviceListupdate.Count + "个设备信息!");
                        //    System.Diagnostics.Trace.WriteLine("成功更新成功了" + deviceListupdate.Count + "个设备信息!");
                        //}
                        //else
                        //{
                        //    SetInfoText("更新出现错误!");
                        //    System.Diagnostics.Trace.WriteLine("更新导入出现错误!");

                        //}
                    }
                }

                Disp("程序运行完毕 ", "", 0);

                string s = string.Format("符合数据{0}条,不匹配数据{1}条", deviceListadd.Count + deviceListupdate.Count , errcount);
                System.Diagnostics.Trace.WriteLine(s);
                SetInfoText(s);

                sw.Close();
                close();

            }

        }