private int UpdateDatabase(int DBV)
        {
            string        S_read = "", S_tmp;
            int           dbversion = 0;
            string        filename = Directory.GetCurrentDirectory() + "\\DatabaseUpdate.txt", sql;
            StreamReader  SR      = new StreamReader(@filename);
            SQLiteCommand sqlcomm = new SQLiteCommand(SQLConnect);

            S_read = SR.ReadToEnd();
            SR.Close();

            S_read = S_read.Replace("\r\n", " ");


            while (S_read.IndexOf("}") > 0)
            {
                S_tmp  = S_read.Substring(0, S_read.IndexOf("}") + 1);
                S_read = S_read.Substring(S_read.IndexOf("}") + 1);
                try
                {
                    dbversion = Convert.ToInt16(S_tmp.Substring(S_tmp.IndexOf("[") + 1, S_tmp.IndexOf("]") - S_tmp.IndexOf("[") - 1).Trim());
                }
                catch
                {
                    return(-1);
                }
                if (dbversion <= DBV)
                {
                    continue;
                }
                int s = S_tmp.IndexOf("{") + 1;
                int e = S_tmp.IndexOf("}") - s - 1;
                S_tmp = S_tmp.Substring(s, e);
                while (S_tmp.IndexOf(";") > 0)
                {
                    sql   = S_tmp.Substring(0, S_tmp.IndexOf(";"));
                    S_tmp = S_tmp.Substring(S_tmp.IndexOf(";") + 1);
                    sqlcomm.CommandText = sql;
                    try
                    {
                        sqlcomm.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        GlobalValue.WriteLog(DateTime.Now.ToString() + ":SQL" + sql + ":" + ex.Message.ToString(), logfile);
                        continue;
                    }
                }
            }
            sql = "update TAT_Dictonary set kvalue = '" + dbversion + "' where ktype='DBV' and Kname='DatabaseVersion'";
            sqlcomm.CommandText = sql;
            sqlcomm.ExecuteNonQuery();



            return(0);
        }
        public SocketClient(string IpAddress, Int32 PortNo)
        {
            Ipadressport      = IpAddress + ":" + PortNo;
            this.ipendpoint   = new IPEndPoint(IPAddress.Parse(IpAddress), PortNo);
            this.clientthread = new Thread(new ThreadStart(ClientThread));
            this.clientthread.IsBackground = true;

            this.LogFolder = GlobalValue.LogPath + "\\CPORT" + PortNo + "\\";
            GlobalValue.CreateFolder(this.LogFolder);
            this.LogFile = LogFolder + DateTime.Today.ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo) + DateTime.Now.ToString("HHmmss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + ".TXT";



            clientthread.Start();
            ;
        }
        public int ExecuteSQL(string sql)
        {
            SQLiteCommand sqlcomm = new SQLiteCommand(SQLConnect);

            try
            {
                sqlcomm.CommandText = sql;
                sqlcomm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                GlobalValue.WriteLog(DateTime.Now.ToString() + ":SQL" + sql + ":" + ex.Message.ToString(), logfile);
                return(-1);
            }
            sqlcomm.Dispose();
            return(0);
        }
Beispiel #4
0
        public Boolean initport(int port)
        {
            checkport(port);
            if (!portinuse)
            {
                this.listener1 = new TcpListener(IPAddress.Any, port);

                this.listenserthread1 = new Thread(new ThreadStart(openport));
                this.listenserthread1.IsBackground = true;

                this.LogFolder = GlobalValue.LogPath + "\\SPORT" + port + "\\";
                GlobalValue.CreateFolder(this.LogFolder);
                this.LogFile = LogFolder + DateTime.Today.ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo) + DateTime.Now.ToString("HHmmss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + ".TXT";



                listenserthread1.Start();
            }
            return(true);
        }
        public int GetSelectValue(string sql)
        {
            SQLiteCommand    sqlcom = new SQLiteCommand(sql, SQLConnect);
            SQLiteDataReader reader = sqlcom.ExecuteReader();
            int count = 0;

            reader.Read();
            try
            {
                if (reader.HasRows)
                {
                    count = reader.GetInt32(0);
                }
            }
            catch (Exception ex)
            {
                GlobalValue.WriteLog(DateTime.Now.ToString() + ":SQL" + sql + ":" + ex.Message.ToString(), logfile);
                count = 0;
            }
            reader.Close();
            sqlcom.Dispose();
            return(count);
        }
 public void LOG(string msg, string type)
 {
     msg = DateTime.Today.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + " " + type + " : " + msg;
     GlobalValue.WriteLog(msg, LogFile);
     this.log += GlobalValue.ReplaceASCII(msg) + GlobalValue.CR + GlobalValue.LF;
 }