Exemplo n.º 1
0
        public static bool ExecSql(string sql)
        {
            SqlDB db = new SqlDB();

            using (System.Data.SqlClient.SqlCommand cmd = db.CreateCmd(sql, "text"))
            {
                db.OpenConn();
                if (cmd.ExecuteNonQuery() <= 0)
                {
                    cmd.Dispose();
                    db.CloseConn();
                    return(false);
                }
                else
                {
                    cmd.Dispose();
                    db.CloseConn();
                    return(true);
                }
            }
        }
Exemplo n.º 2
0
        public static bool ExecProc(string sql, IDataParameter[] parameters)
        {
            SqlDB db = new SqlDB();

            using (System.Data.SqlClient.SqlCommand cmd = db.CreateCmd(sql, "proc", parameters))
            {
                db.OpenConn();
                if (cmd.ExecuteNonQuery() <= 0)
                {
                    cmd.Parameters.Clear();
                    cmd.Dispose();
                    db.CloseConn();
                    return(false);
                }
                else
                {
                    cmd.Dispose();
                    db.CloseConn();
                    return(true);
                }
            }
        }
Exemplo n.º 3
0
        public void FileToDatabase1(object obj)
        {
            SqlDB.SqlConnString = txtDataBase.Text;
            //int i=26;
            Int32 redisIndex = (Int32)obj - 1;

            redisClient[redisIndex] = new RedisOperation().Client;
            WriterFile(obj.ToString() + "线程开始同步");
            Version version      = GetVerion("{0}_登录成功(1)_.txt");
            string  fileFullPath = txtFilePath.Text + "\\" + version.VersionName;

            for (; File.Exists(fileFullPath);)
            {
                fileFullPath = txtFilePath.Text + "\\" + version.VersionName;
                WriterFile(obj.ToString() + "线程开始同步" + version.VersionName);
                StreamReader sr = new StreamReader(fileFullPath, Encoding.Default);
                String       line;

                int      successNumber = 0;
                int      repeatNumber  = 0;
                int      totaleNumber  = 0;
                int      indexes       = 0;
                DateTime currentTime   = DateTime.Now;
                line = sr.ReadToEnd();
                sr.Close();

                DataTable dataTable = CreateTable("User163", "username", "password", "datatype");;
                string[]  lineArray = Regex.Split(line, "\r\n");
                for (int i = version.Row; i < lineArray.Length; i++)
                {
                    SleepTempThread();
                    if (successNumber == 0)
                    {
                        dataTable = CreateTable("User163", "username", "password", "datatype");
                    }
                    MatchCollection collection = Regex.Matches(lineArray[i], "^(.*)----(.*)$");

                    if (collection.Count > 0)
                    {
                        totaleNumber++;
                        if (!ExistTempKey(redisIndex, collection[0].Groups[1].Value.ToLower(), collection[0].Groups[2].Value))
                        {
                            successNumber++;
                            DataRow dr = dataTable.NewRow();
                            dr["username"] = collection[0].Groups[1].Value;
                            dr["password"] = collection[0].Groups[2].Value;
                            dr["datatype"] = "163";
                            dataTable.Rows.Add(dr);
                        }
                        else
                        {
                            repeatNumber++;
                        }
                        if (totaleNumber % 10000 == 0)
                        {
                            WriterFile(string.Format(obj.ToString() + "线程:共{0},成功{1},失败{2},用时{3},当前时间:{4}",
                                                     totaleNumber, successNumber, repeatNumber, DateTime.Now - currentTime, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                            currentTime = DateTime.Now;
                        }
                        if (successNumber >= 10000)
                        {
                            WriteDataQueue(dataTable);

                            SqlDB.ExecSql(string.Format("update baseversion set row={0} where versionname='{1}'", lineArray.Length, version.VersionName));
                            successNumber = 0;
                        }
                    }
                }
                if (dataTable.Rows.Count > 0)
                {
                    WriteDataQueue(dataTable);
                    SqlDB.ExecSql(string.Format("update baseversion set row={0} where versionname='{1}'", lineArray.Length, version.VersionName));
                }
                lineArray = null;
                GC.Collect();

                SqlDB.ExecSql(string.Format("update baseversion set row={0},Finish=2,endtime=getdate() where versionname='{1}'", totaleNumber, version.VersionName));
                version = GetVerion("{0}_登录成功(1)_.txt");
            }
            WriterFile(obj + "线程结束同步");
        }