Example #1
0
        public bool OpenDyns(string pStrSQL, string pTableName, ref DataSet pDataSet)
        {
            OracleDataAdapter oda;
            DataSet           ds = new DataSet();
            bool vCheck          = false;

            if (mConnect)
            {
                try
                {
                    oda = new OracleDataAdapter(pStrSQL, mConnOracle);
                    oda.Fill(ds, pTableName);
                    pDataSet = ds;
                    CheckExecute(true);
                    vCheck = true;
                }
                catch (Exception exp)
                {
                    CheckExecute(vCheck);
                    clogfile p = new clogfile();
                    mLog.WriteErrLog("Cannot open [" + pStrSQL + "]");
                    mLog.WriteErrLog(exp.Message);
                }
                ds  = null;
                oda = null;
            }
            return(vCheck);
        }
Example #2
0
        private bool OpenPort()
        {
            bool vIsAvailable = true;

            try
            {
                if (mArgumentPort.IsTCP)
                {
                    Application.DoEvents();
                    IPGlobalProperties         ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
                    TcpConnectionInformation[] tcpConnInfoArray   = ipGlobalProperties.GetActiveTcpConnections();
                    foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
                    {
                        if (tcpi.LocalEndPoint.Port == mArgumentPort.IP_Port)
                        {
                            vIsAvailable = false;
                            break;
                        }
                    }

                    if (vIsAvailable)
                    {
                        tc = new TcpClient(mArgumentPort.IP_Address, mArgumentPort.IP_Port);
                        //tc = new TcpClient("192.168.1.193", 7734);
                        tc.SendTimeout = 1000;
                        mStm           = tc.GetStream();
                        mMsg           = "Comport =" + mArgumentPort.IP_Address + " : " + mArgumentPort.IP_Port + " Open successfull.";
                        Addlistbox(mMsg);
                    }
                }
                else    //serial port
                {
                    string[] spli = mArgumentPort.portSetting.Split(',');
                    if (spli.Length != 4)
                    {
                        return(false);
                    }
                    mSp = new SerialPort();
                    //mSp.DataReceived += SerialPort_DataReceived;
                    mSp.PortName = mArgumentPort.portNo;
                    mSp.BaudRate = Int32.Parse(spli[0]);
                    switch (spli[1].ToString().ToUpper().Trim())
                    {
                    case "E": mSp.Parity = Parity.Even; break;

                    case "M": mSp.Parity = Parity.Mark; break;

                    case "O": mSp.Parity = Parity.Odd; break;

                    case "S": mSp.Parity = Parity.Space; break;

                    default: mSp.Parity = Parity.None; break;
                    }
                    mSp.DataBits = Int32.Parse(spli[2]);
                    switch (spli[3].Trim())
                    {
                    case "1": mSp.StopBits = StopBits.One; break;

                    case "1.5": mSp.StopBits = StopBits.OnePointFive; break;

                    case "2": mSp.StopBits = StopBits.Two; break;

                    default: mSp.StopBits = StopBits.None; break;
                    }
                    mSp.ReadTimeout  = 500;
                    mSp.WriteTimeout = 500;
                    mSp.Open();
                    mSp.DiscardInBuffer();
                    mSp.DiscardOutBuffer();
                }
                mArgumentPort.IsOpen = true;
                mArgumentPort.IsIdle = true;
                mConnect             = true;
                mMsg = "Comport =" + mArgumentPort.portNo + " : " + mArgumentPort.portSetting + " Open successfull.";
                Addlistbox(mMsg);
            }
            catch (Exception exp)
            {
                //Addlistbox(exp.Message.ToString());
                if (mCountWriteLog > 120)
                {
                    mCountWriteLog = 0;
                    mLog.WriteErrLog(exp.ToString());
                    mArgumentPort.IsOpen = false;
                }
                else
                {
                    mCountWriteLog += 1;
                }
                return(false);
            }
            return(true);
        }