Exemplo n.º 1
0
        public void AddDeviceWrapper(string devName, bool isMfccAddDevice, System.Data.Odbc.OdbcConnection cnn)
        {
            OdbcDataReader rd = null;
              OdbcConnection cn = null; ;
              OdbcCommand cmd;
              try
              {

              devName = devName.Trim();
              if (isMfccAddDevice)
                  cn = new OdbcConnection(Global.Db2ConnectionString);
              else
                  cn = cnn;

              cmd = new OdbcCommand();
              cmd.Connection = cn;
              if (this.devices.ContainsKey(devName))
                  throw new Exception(devName + "already in list");

              if (isMfccAddDevice)
                 cn.Open();
              if (devName.StartsWith("VD"))
                  cmd.CommandText = "select tbldeviceconfig.devicename,device_type,mfccid,location,lineid,direction,mile_m,ip,port,hw_status_1,hw_status_2,hw_status_3,hw_status_4,op_mode,op_status,start_mileage,end_mileage from tbldeviceconfig inner join tblVDConfig on tbldeviceconfig.devicename=tblVDConfig.devicename where enable='Y' and tbldeviceconfig.devicename='" + devName + "'";
              else if(devName.StartsWith("RD"))
                  cmd.CommandText = "select tbldeviceconfig.devicename,device_type,mfccid,location,lineid,direction,mile_m,ip,port,hw_status_1,hw_status_2,hw_status_3,hw_status_4,op_mode,op_status,start_mileage,end_mileage from tbldeviceconfig inner join tblRDConfig on tbldeviceconfig.devicename=tblRDConfig.devicename where enable='Y' and tbldeviceconfig.devicename='" + devName + "'";
              else if (devName.StartsWith("VI"))
                  cmd.CommandText = "select tbldeviceconfig.devicename,device_type,mfccid,location,lineid,direction,mile_m,ip,port,hw_status_1,hw_status_2,hw_status_3,hw_status_4,op_mode,op_status,start_mileage,end_mileage from tbldeviceconfig inner join tblVIConfig on tbldeviceconfig.devicename=tblVIConfig.devicename where enable='Y' and tbldeviceconfig.devicename='" + devName + "'";
              else if (devName.StartsWith("WD")  || devName.StartsWith("TWD"))
                  cmd.CommandText = "select tbldeviceconfig.devicename,device_type,mfccid,location,lineid,direction,mile_m,ip,port,hw_status_1,hw_status_2,hw_status_3,hw_status_4,op_mode,op_status,start_mileage,end_mileage from tbldeviceconfig inner join tblWDConfig on tbldeviceconfig.devicename=tblWDConfig.devicename where enable='Y' and tbldeviceconfig.devicename='" + devName + "'";

              else
                  cmd.CommandText = "select devicename,device_type,mfccid,location,lineid,direction,mile_m,ip,port,hw_status_1,hw_status_2,hw_status_3,hw_status_4,op_mode,op_status from tbldeviceconfig where enable='Y' and devicename='" + devName + "'";
              rd = cmd.ExecuteReader();

              if (!rd.Read())
                  throw new Exception(devName + " not  found in database!");
              else
              {

                  string devicename = (rd[0] as string).Trim();
                  string devicetype = rd[1] as string;
                  string mfccid = rd[2] as string;
                  string location = rd[3] as string;
                  string lineid = rd[4] as string;
                  string direction = rd[5] as string;

                  int mile_m = System.Convert.ToInt32(rd[6]);
                  string ip = rd[7] as string;
                  int port = System.Convert.ToInt32(rd[8]);

                  byte[] hwstatus = new byte[4];
                  hwstatus[0] = System.Convert.ToByte(rd[9]);
                  hwstatus[1] = System.Convert.ToByte(rd[10]);
                  hwstatus[2] = System.Convert.ToByte(rd[11]);
                  hwstatus[3] = System.Convert.ToByte(rd[12]);
                  byte opmode = System.Convert.ToByte(rd[13]);
                  byte opstatus = System.Convert.ToByte(rd[14]);

                  if (devicetype == "VD")
                  {
                      int start_mileage, end_mileage;
                      start_mileage = System.Convert.ToInt32(rd[15]);

                      end_mileage = System.Convert.ToInt32(rd[16]);
                      TC.VDDeviceWrapper wrapper = new TC.VDDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction,start_mileage,end_mileage);

                      if( isMfccAddDevice)
                      wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);

                  }
                  else if (devicetype == "RGS")
                  {
                      TC.RGSDeviceWrapper wrapper = new TC.RGSDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                     if (isMfccAddDevice)
                      wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "CMS")
                  {

                      TC.CMSDeviceWrapper wrapper = new TC.CMSDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                     if (isMfccAddDevice)
                      wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "RMS")
                  {
                      TC.RMSDeviceWrapper wrapper = new TC.RMSDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                     if (isMfccAddDevice)
                      wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "WIS")
                  {
                      TC.WISDeviceWrapper wrapper = new TC.WISDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                      if (isMfccAddDevice)
                      wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "LCS")
                  {
                      TC.LCSDeviceWrapper wrapper = new TC.LCSDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                      if (isMfccAddDevice)
                      wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "CSLS")
                  {
                      TC.CSLSDeviceWrapper wrapper = new TC.CSLSDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                      if (isMfccAddDevice)
                      wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "AVI")
                  {
                      TC.AVIDeviceWrapper wrapper = new TC.AVIDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                      if (isMfccAddDevice)
                          wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "RD")
                  {
                      int start_mileage, end_mileage;
                      start_mileage = System.Convert.ToInt32(rd[15]);

                      end_mileage = System.Convert.ToInt32(rd[16]);

                      TC.RDDeviceWrapper wrapper = new TC.RDDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction,start_mileage,end_mileage);
                      if (isMfccAddDevice)
                          wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "VI")
                  {
                      int start_mileage, end_mileage;
                      start_mileage = System.Convert.ToInt32(rd[15]);

                      end_mileage = System.Convert.ToInt32(rd[16]);
                      TC.VIDeviceWrapper wrapper = new TC.VIDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction,start_mileage,end_mileage);
                      if (isMfccAddDevice)
                          wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "WD")
                  {
                      int start_mileage, end_mileage;
                      start_mileage = System.Convert.ToInt32(rd[15]);

                      end_mileage = System.Convert.ToInt32(rd[16]);
                      TC.WDDeviceWrapper wrapper = new TC.WDDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction,start_mileage,end_mileage);
                      if (isMfccAddDevice)
                          wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                          devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "TTS")
                  {
                      TC.TTSDeviceWrapper wrapper = new TC.TTSDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                      if (isMfccAddDevice)
                          wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "FS")
                  {
                      TC.FSDeviceWrapper wrapper = new TC.FSDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                      if (isMfccAddDevice)
                          wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "MAS")
                  {
                      TC.MASDeviceWrapper wrapper = new TC.MASDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                      if (isMfccAddDevice)
                          wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "IID")
                  {
                      TC.IIDDeviceWrapper wrapper = new TC.IIDDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                      if (isMfccAddDevice)
                          wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "ETTU")
                  {
                      TC.ETTUDeviceWrapper wrapper = new TC.ETTUDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                      if (isMfccAddDevice)
                          wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "LS")
                  {
                      TC.LSDeviceWrapper wrapper = new TC.LSDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                      if (isMfccAddDevice)
                          wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "TEM")
                  {
                      TC.TEMDeviceWrapper wrapper = new TC.TEMDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                      if (isMfccAddDevice)
                          wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "CMSRST")
                  {
                      TC.CMSRSTDeviceWrapper wrapper = new TC.CMSRSTDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                      if (isMfccAddDevice)
                          wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }
                  else if (devicetype == "BS")
                  {
                      TC.BSDeviceWrapper wrapper = new TC.BSDeviceWrapper(mfccid, devicename, devicetype, ip, port, location, lineid, mile_m, hwstatus, opmode, opstatus, direction);
                      if (isMfccAddDevice)
                          wrapper.getRemoteObj().AddDevice(wrapper.deviceName);
                      devices.Add(devicename, wrapper);
                  }

              }

              }

              finally
              {
              try
              {
                  rd.Close();
                  rd.Dispose();
                  if (isMfccAddDevice)
                         cn.Close();
              }
              catch (Exception ex){
                  Console.WriteLine(ex.Message+ex.StackTrace);
                  ;}

              }
        }