Close() private method

private Close ( MySqlDataReader reader ) : void
reader MySqlDataReader
return void
コード例 #1
0
ファイル: index.aspx.cs プロジェクト: RoyalBob/Git
 protected void Page_Load(object sender, EventArgs e)
 {
     //准备用于发起请求的HttpWebRequest对象
     conn.Open();
     MySqlDataReader reader = new MySqlCommand("select * from files where publishdate='" + DateTime.Today.ToString("yyyy-MM-dd") + "'", conn).ExecuteReader();
     if (reader.HasRows)
     {
         reader.Close();
         conn.Close();
     }
     else
     {
         reader.Close();
         conn.Close();
         GetNews.getTencentNews(Url.TencentUrl, conn);
         GetNews.getAoyunNews(Url.AoyunUrl, conn);
         GetNews.getFenghuangNews(Url.FenghuangUrl, conn);
     }
 }
コード例 #2
0
        /// <summary>
        /// Closes the MySqlDataReader object.
        /// </summary>
        public override void Close()
        {
            if (!isOpen)
            {
                return;
            }

            bool shouldCloseConnection = (commandBehavior & CommandBehavior.CloseConnection) != 0;

            commandBehavior   = CommandBehavior.Default;
            connection.Reader = null;

            // we set the nextResultDone var to true inside NextResult when
            // it returns false.  This allows us to avoid calling NextResult
            // here unnecessarily.  Calling NextResult here will work but this
            // is just an optimization.
            if (!nextResultDone)
            {
                while (NextResult())
                {
                }
            }

            // we now give the command a chance to terminate.  In the case of
            // stored procedures it needs to update out and inout parameters
            command.Close();

            if (shouldCloseConnection)
            {
                connection.Close();
            }

            command    = null;
            connection = null;

            isOpen = false;
        }
コード例 #3
0
        /// <summary>
        /// Closes the MySqlDataReader object.
        /// </summary>
        public override void Close()
        {
            if (!isOpen)
            {
                return;
            }

            bool shouldCloseConnection = (commandBehavior & CommandBehavior.CloseConnection) != 0;

            commandBehavior = CommandBehavior.Default;

            // clear all remaining resultsets
            try
            {
                while (NextResult())
                {
                }
            }
            catch (MySqlException ex)
            {
                // Ignore aborted queries
                if (!ex.IsQueryAborted)
                {
                    // ignore IO exceptions.
                    // We are closing or disposing reader, and  do not
                    // want exception to be propagated to used. If socket is
                    // is closed on the server side, next query will run into
                    // IO exception. If reader is closed by GC, we also would
                    // like to avoid any exception here.
                    bool isIOException = false;
                    for (Exception exception = ex; exception != null;
                         exception = exception.InnerException)
                    {
                        if (exception is System.IO.IOException)
                        {
                            isIOException = true;
                            break;
                        }
                    }
                    if (!isIOException)
                    {
                        // Ordinary exception (neither IO nor query aborted)
                        throw;
                    }
                }
            }
            catch (System.IO.IOException)
            {
                // eat, on the same reason we eat IO exceptions wrapped into
                // MySqlExceptions reasons, described above.
            }
            finally
            {
                // always ensure internal reader is null (Bug #55558)
                connection.Reader = null;
            }
            // we now give the command a chance to terminate.  In the case of
            // stored procedures it needs to update out and inout parameters
            command.Close(this);

            if (this.command.Canceled && connection.driver.Version.isAtLeast(5, 1, 0))
            {
                // Issue dummy command to clear kill flag
                ClearKillFlag();
            }

            if (shouldCloseConnection)
            {
                connection.Close();
            }

            command            = null;
            connection.IsInUse = false;
            connection         = null;
            isOpen             = false;
        }
コード例 #4
0
        private static IEnumerable<int> CheckAndAddProducts(IList<string> productSubNumbers, string productMainDescr, IList<string> productSubDescriptions)
        {
            var productIds = new List<int>();
            var productAttributes = new List<string>();

            if (productSubNumbers.Count > 1)
            {
                var attributes = "Rozmiar";

                var productNumberLength = productSubNumbers[0].Length - 2;
                string productNumber = productSubNumbers[0].Substring(0, productNumberLength);

                const string attributesRegex = "((rozm\\.)|(Rozmiar)|(rozmiar))\\s*\\w*";
                foreach (var productSubDescription in productSubDescriptions)
                {
                    var temp = new Regex(attributesRegex).Match(productSubDescription).Value;
                    try
                    {
                        productAttributes.Add(temp.Split(' ')[1]);
                    }
                    catch(Exception)
                    {
                        try
                        {
                            productAttributes.Add(temp.Split('.')[1]);
                        }
                        catch(Exception)
                        {
                            var tempSubDescr = productSubDescription.Split(' ');
                            productAttributes.Add(tempSubDescr[tempSubDescr.Length - 1]);
                        }
                    }
                }

                var productTemp = new Regex(attributesRegex).Match(productSubDescriptions[0]).Value;
                string productName = "";
                try
                {
                    productName = productSubDescriptions[0].Replace(productTemp, "");
                }
                catch(Exception)
                {
                    var tempProductNameAll = productSubDescriptions[0].Split(' ');
                    var tempProductName = "";
                    for (var i = 0; i < tempProductNameAll.Length - 1; i++)
                    {
                        tempProductName += tempProductNameAll[i] + " ";
                    }

                    productName = tempProductName;
                }

                for (var i = 0; i < productSubNumbers.Count; i++)
                {
                    attributes += String.Format(",({0}) {1}", productSubNumbers[i], productAttributes[i]);
                }

                var selectQuery = "select * from jos_vm_product where product_sku = " + productNumber;
                selectQuery = productSubNumbers.Aggregate(selectQuery, (current, productSubNumber) => current + (" or attribute like \"%" + productSubNumber + "%\""));

                var selectCommand = new MySqlCommand(selectQuery, _mySqlConnect).ExecuteReader();

                if (!selectCommand.Read())
                {
                    selectCommand.Close();

                    var insertQuery = String.Format("insert into jos_vm_product (vendor_id, product_parent_id, product_sku, product_s_desc, product_desc, product_thumb_image, product_full_image, product_publish, product_weight, product_weight_uom, product_length, product_width, product_height, product_lwh_uom, product_url, product_in_stock, product_available_date, product_availability, product_special, product_discount_id, ship_code_id, cdate, mdate, product_name, product_sales, attribute, custom_attribute, product_tax_id, product_unit, product_packaging, child_options, quantity_options, child_option_ids, product_order_levels) VALUES (1, 0, {0}, '', '{1}', '', '', 'Y', '0.0000', 'kg', '0.0000', '0.0000', '0.0000', 'cm', '', 0, 1279843200, '', 'N', 0, NULL, 1279922325, 1279922577, '{2}', 0, '{3}', '', 3, 'szt.', 0, 'N,N,N,N,N,Y,20%,10%,', 'none,0,0,1', '', '0,0')", productNumber, productMainDescr, productName, attributes);
                    var insertCommand = new MySqlCommand(insertQuery, _mySqlConnect);
                    insertCommand.ExecuteNonQuery();
                    productIds.Add((int)insertCommand.LastInsertedId);
                }
                else
                {
                    productIds.Add(selectCommand.GetInt32("product_id"));
                    selectCommand.Close();
                }
            }
            else
            {
                for (var j = 0; j < productSubNumbers.Count; j++)
                {
                    var selectQuery = "select * from jos_vm_product where product_sku = " + productSubNumbers[j];
                    selectQuery = productSubNumbers.Aggregate(selectQuery, (current, productSubNumber) => current + (" or attribute like \"%" + productSubNumber + "%\""));

                    var selectCommand = new MySqlCommand(selectQuery, _mySqlConnect).ExecuteReader();

                    if (!selectCommand.Read())
                    {
                        selectCommand.Close();

                        var insertQuery = String.Format("insert into jos_vm_product (vendor_id, product_parent_id, product_sku, product_s_desc, product_desc, product_thumb_image, product_full_image, product_publish, product_weight, product_weight_uom, product_length, product_width, product_height, product_lwh_uom, product_url, product_in_stock, product_available_date, product_availability, product_special, product_discount_id, ship_code_id, cdate, mdate, product_name, product_sales, attribute, custom_attribute, product_tax_id, product_unit, product_packaging, child_options, quantity_options, child_option_ids, product_order_levels) VALUES (1, 0, {0}, '', '{1}', '', '', 'Y', '0.0000', 'kg', '0.0000', '0.0000', '0.0000', 'cm', '', 0, 1279843200, '', 'N', 0, NULL, 1279922325, 1279922577, '{2}', 0, '', '', 3, 'szt.', 0, 'N,N,N,N,N,Y,20%,10%,', 'none,0,0,1', '', '0,0')", productSubNumbers[j], productMainDescr, productSubDescriptions[j]);
                        var insertCommand = new MySqlCommand(insertQuery, _mySqlConnect);
                        insertCommand.ExecuteNonQuery();
                        productIds.Add((int)insertCommand.LastInsertedId);
                    }
                    else
                    {
                        productIds.Add(selectCommand.GetInt32("product_id"));
                        selectCommand.Close();
                        continue;
                    }
                }
            }

            return productIds;
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: stwalkerster/solar-uploader
 private void buttonDbTest_Click(object sender, EventArgs e)
 {
     reopenDatabase();
     comboBoxSchema.Items.Clear();
     MySqlDataReader dr = new MySqlCommand("SHOW DATABASES;", _conn).ExecuteReader();
     while(dr.Read())
     {
         comboBoxSchema.Items.Add(dr.GetString(0));
     }
     dr.Close();
 }
コード例 #6
0
        public object[] DLookupA(string table, string fieldName, string clauses, string[] orderByFieldNames, bool orderByAsc)
        {
            List<object> data = new List<object>();
            bool connectedP = isConnectedDo;
            string query = "";
            try
            {
                query = "SELECT " + fieldName + " FROM " + table + " WHERE (" + clauses + ")" + ((orderByFieldNames.Length > 0) ? " ORDER BY " + getOrderByData(orderByFieldNames) + " " + ((orderByAsc) ? "ASC" : "DESC") : "");

                if (dbType == DatabaseType.MSSQL)
                {
                    getQueryDbChanger(query, SqlTypes.SELECT);
                    SqlDataReader Dr = new SqlCommand(query, MSSQLConn).ExecuteReader();
                    while (Dr.Read())
                    {
                        data.Add(Dr[0]);
                    }
                    Dr.Close();
                }
                else if (dbType == DatabaseType.MYSQL)
                {
                    MySqlDataReader Dr = new MySqlCommand(query, MySQLConn).ExecuteReader();
                    while (Dr.Read())
                    {
                        data.Add(Dr[0]);
                    }
                    Dr.Close();
                }
                else if (dbType == DatabaseType.MSACCESS2003 | dbType == DatabaseType.MSACCESS2007)
                {
                    OleDbDataReader Dr = new OleDbCommand(query, MSDBSQLConn).ExecuteReader();
                    while (Dr.Read())
                    {
                        data.Add(Dr[0]);
                    }
                    Dr.Close();
                }
            }
            catch (Exception eee)
            {
                OnError(eee);
                data.Clear();
                data.Add("ERROR: " + eee.Message);
                data.Add("ERRORI: " + table);
                data.Add("ERRORI: " + fieldName);
                data.Add("ERRORI: " + clauses);
                data.Add("ERRORI: " + query);
            }
            finally
            {
                if (!connectedP)
                    closeConnection();
            }
            return data.ToArray();
        }
コード例 #7
0
 public object DLookup(string sqlQuery)
 {
     object data = null;
     bool connectedP = isConnectedDo;
     try
     {
         if (dbType == DatabaseType.MSSQL)
         {
             getQueryDbChanger(sqlQuery, SqlTypes.SELECT);
             SqlDataReader Dr = new SqlCommand(sqlQuery, MSSQLConn).ExecuteReader();
             if (Dr.Read())
             {
                 data = Dr[0];
             }
             Dr.Close();
         }
         else if (dbType == DatabaseType.MYSQL)
         {
             MySqlDataReader Dr = new MySqlCommand(sqlQuery, MySQLConn).ExecuteReader();
             if (Dr.Read())
             {
                 data = Dr[0];
             }
             Dr.Close();
         }
         else if (dbType == DatabaseType.MSACCESS2003 | dbType == DatabaseType.MSACCESS2007)
         {
             OleDbDataReader Dr = new OleDbCommand(sqlQuery, MSDBSQLConn).ExecuteReader();
             if (Dr.Read())
             {
                 data = Dr[0];
             }
             Dr.Close();
         }
     }
     catch (Exception eee)
     {
         OnError(eee);
         data = eee.Message;
     }
     finally
     {
         if (!connectedP)
             closeConnection();
     }
     return data;
 }
コード例 #8
0
        public object DLookup(string table, string fieldName, string clauses, string[] orderByFieldNames, bool orderByAsc)
        {
            object data = null;
            bool connectedP = isConnectedDo;
            try
            {
                string query = "SELECT TOP 1 " + fieldName + " FROM " + table + " WHERE (" + clauses + ")" + ((orderByFieldNames.Length > 0) ? " ORDER BY " + getOrderByData(orderByFieldNames) + " " + ((orderByAsc) ? "ASC" : "DESC") : "");

                if (dbType == DatabaseType.MSSQL)
                {
                    getQueryDbChanger(query, SqlTypes.SELECT);
                    SqlDataReader Dr = new SqlCommand(query, MSSQLConn).ExecuteReader();
                    if (Dr.Read())
                    {
                        data = Dr[0];
                    }
                    Dr.Close();
                }
                else if (dbType == DatabaseType.MYSQL)
                {
                    MySqlDataReader Dr = new MySqlCommand(query, MySQLConn).ExecuteReader();
                    if (Dr.Read())
                    {
                        data = Dr[0];
                    }
                    Dr.Close();
                }
                else if (dbType == DatabaseType.MSACCESS2003 | dbType == DatabaseType.MSACCESS2007)
                {
                    OleDbDataReader Dr = new OleDbCommand(query, MSDBSQLConn).ExecuteReader();
                    if (Dr.Read())
                    {
                        data = Dr[0];
                    }
                    Dr.Close();
                }
            }
            catch (Exception eee)
            {
                OnError(eee);
                data = eee.Message;
            }
            finally
            {
                if (!connectedP)
                    closeConnection();
            }
            return data;
        }
コード例 #9
0
ファイル: GetNews.cs プロジェクト: RoyalBob/Git
    public static void getTencentNews(string url, MySqlConnection conn)
    {
        string filename = "", publishdate = "", typename = "", sql = "";
        string[] picimg = new string[200];
        string[] pictxt = new string[200];
        int picimgPos = 0, pictxtPos = 0;

        HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);
        HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
        Stream receiveStream = httpResponse.GetResponseStream();
        StreamReader streamReader = new StreamReader(receiveStream, Encoding.Default);
        string htmlstr = streamReader.ReadToEnd();  //htmlstr是新闻标题页源代码
        streamReader.Close();
        try
        {
            //正则表达式获取<a href></a>内容url
            MatchCollection matches = Regex.Matches(htmlstr, "<a target=\"_blank\" class=\"linkto\" href=\"(.*?).htm\"(.*?)>(.*?)</a>", RegexOptions.IgnoreCase);
            foreach (Match match in matches)
            {
                //matches2 获取 matches 中的新闻标题
                MatchCollection matches2 = Regex.Matches(match.Value.ToString(), "(>)(.*?)(</a>)", RegexOptions.IgnoreCase);
                foreach (Match match2 in matches2)
                {
                    filename = match2.Value.ToString().Substring(1).Replace("</a>", "");
                    sql = "insert into files(filename,typename,typeid,filecontent,publisher,publishdate,link) values('" + filename + "',";
                }

                //matches3 获取 matches 中的新闻网址
                MatchCollection matches3 = Regex.Matches(match.Value.ToString(), "href=\"([^\"]*?)\"", RegexOptions.IgnoreCase);
                foreach (Match match3 in matches3)
                {
                    string filecontent = "";
                    picimgPos = 0;
                    pictxtPos = 0;
                    string newshtml = match3.Value.ToString().Substring(5).Replace("\"", "");   //newshtml 是新闻网址
                    HttpWebRequest httpRequest2 = (HttpWebRequest)WebRequest.Create(newshtml);
                    HttpWebResponse httpResponse2;
                    try
                    {
                        httpResponse2 = (HttpWebResponse)httpRequest2.GetResponse();
                    }
                    catch (WebException ex)
                    {
                        httpResponse2 = (HttpWebResponse)ex.Response;
                    }
                    Stream receiveStream2 = httpResponse2.GetResponseStream();
                    StreamReader streamReader2 = new StreamReader(receiveStream2, Encoding.Default);
                    string htmlstr2 = streamReader2.ReadToEnd();    //htmlstr2是新闻详情页的源代码
                    streamReader2.Close();

                    //matches5 获取新闻内的图片
                    MatchCollection matches5 = Regex.Matches(htmlstr2, "<img alt=(.*?) src=\"(.*?)\">", RegexOptions.IgnoreCase);
                    foreach (Match match5 in matches5)
                    {
                        picimg[picimgPos] = match5.Value.ToString();
                        picimgPos++;
                    }
                    //matches6 获取新闻内图片的说明
                    MatchCollection matches6 = Regex.Matches(htmlstr2, "<p class=pictext align=center>(.*?)</p>", RegexOptions.IgnoreCase);
                    foreach (Match match6 in matches6)
                    {
                        pictxt[pictxtPos] = match6.Value.ToString();
                        pictxtPos++;
                    }

                    //matches7 获取新闻发布时间
                    MatchCollection matches7 = Regex.Matches(htmlstr2, "<span class=\"article-time\">(.*?)</span>", RegexOptions.IgnoreCase);
                    foreach (Match match7 in matches7)
                    {
                        MatchCollection matches8 = Regex.Matches(match7.Value.ToString(), ">(.*?)</span>", RegexOptions.IgnoreCase);
                        foreach (Match match8 in matches8)
                        {
                            publishdate = match8.Value.ToString().Substring(1).Replace("</span>", "");
                        }
                    }

                    //matches9 获取新闻类型
                    MatchCollection matches9 = Regex.Matches(htmlstr2, "<a target=\"_blank\" accesskey=\"5\" href=\"(.*?)\" title=\"(.*?)\">(.*?)</a>", RegexOptions.IgnoreCase);
                    foreach (Match match9 in matches9)
                    {
                        MatchCollection matches10 = Regex.Matches(match9.Value.ToString(), ">(.*?)</a>", RegexOptions.IgnoreCase);
                        foreach (Match match10 in matches10)
                        {
                            typename = match10.Value.ToString().Substring(1).Replace("</a>", "");
                        }
                    }

                    for (int i = 0; i < (picimgPos > pictxtPos ? pictxtPos : picimgPos); i++)
                        filecontent = filecontent + picimg[i] + pictxt[i];
                    MatchCollection matches4 = Regex.Matches(htmlstr2, "<P style=\"TEXT-INDENT: 2em\">(.*?)</P>", RegexOptions.IgnoreCase);
                    foreach (Match match4 in matches4)
                    {
                        filecontent = filecontent + match4.Value.ToString().Replace("'", "\\'");
                    }
                    conn.Open();
                    MySqlDataReader reader_select_typeid = new MySqlCommand("select typeid from type where typename='" + typename + "'", conn).ExecuteReader();
                    int typeid = 99;
                    while (reader_select_typeid.Read())
                    {
                        if (reader_select_typeid.HasRows)
                            typeid = reader_select_typeid.GetInt32(0);
                        else
                            new MySqlCommand("insert into type(typename) values('" + typename + "')", conn).ExecuteNonQuery();
                    }
                    reader_select_typeid.Close();
                    MySqlDataReader reader_typeid = new MySqlCommand("select typeid from type where typename='" + typename + "'", conn).ExecuteReader();
                    if (reader_typeid.Read())
                        typeid = reader_typeid.GetInt32(0);
                    reader_typeid.Close();
                    sql += "'" + typename + "'," + typeid + ",'" + filecontent + "','UM','" + publishdate + "','" + newshtml + "')";

                    MySqlDataReader reader_filename = new MySqlCommand("select filename from files where filename='" + filename + "'", conn).ExecuteReader();
                    if (reader_filename.HasRows || filecontent.Equals("") || filecontent.Length < 300)
                    {
                        reader_filename.Close();
                    }
                    else
                    {
                        reader_filename.Close();
                        new MySqlCommand(sql, conn).ExecuteNonQuery();
                    }
                    conn.Close();
                }
            }
        }
        catch (Exception msg) { }
    }
コード例 #10
0
ファイル: GetNews.cs プロジェクト: RoyalBob/Git
    public static void getAoyunNews(string url, MySqlConnection conn)
    {
        string filename = "", publishdate = "", sql = "";
        string[] picimg = new string[200];
        int picimgPos = 0;

        HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);
        HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
        Stream receiveStream = httpResponse.GetResponseStream();
        StreamReader streamReader = new StreamReader(receiveStream, Encoding.Default);
        string htmlstr = streamReader.ReadToEnd();  //htmlstr是新闻标题页源代码
        streamReader.Close();
        try
        {
            //正则表达式获取<a href></a>内容url
            MatchCollection matches = Regex.Matches(htmlstr, "<a target=\"_blank\" href=\"(.*?).htm\"(.*?)>(.*?)</a>", RegexOptions.IgnoreCase);
            foreach (Match match in matches)
            {
                //matches2 获取 matches 中的新闻标题
                MatchCollection matches2 = Regex.Matches(match.Value.ToString(), "(>)(.*?)(</a>)", RegexOptions.IgnoreCase);
                foreach (Match match2 in matches2)
                {
                    filename = match2.Value.ToString().Substring(1).Replace("</a>", "");
                    sql = "insert into files(filename,typename,typeid,filecontent,publisher,publishdate,link) values('" + filename + "',";
                }

                //matches3 获取 matches 中的新闻网址
                MatchCollection matches3 = Regex.Matches(match.Value.ToString(), "href=\"([^\"]*?)\"", RegexOptions.IgnoreCase);
                foreach (Match match3 in matches3)
                {
                    string filecontent = "";
                    picimgPos = 0;
                    string newshtml = match3.Value.ToString().Substring(5).Replace("\"", "");   //newshtml 是新闻网址
                    HttpWebRequest httpRequest2 = (HttpWebRequest)WebRequest.Create(newshtml);
                    HttpWebResponse httpResponse2;
                    try
                    {
                        httpResponse2 = (HttpWebResponse)httpRequest2.GetResponse();
                    }
                    catch (WebException ex)
                    {
                        httpResponse2 = (HttpWebResponse)ex.Response;
                    }
                    Stream receiveStream2 = httpResponse2.GetResponseStream();
                    StreamReader streamReader2 = new StreamReader(receiveStream2, Encoding.Default);
                    string htmlstr2 = streamReader2.ReadToEnd();    //htmlstr是新闻详情页源代码
                    streamReader2.Close();

                    //matches5 获取新闻内的图片
                    MatchCollection matches5 = Regex.Matches(htmlstr2, "<img alt=(.*?) src=\"(.*?)\">", RegexOptions.IgnoreCase);
                    foreach (Match match5 in matches5)
                    {
                        picimg[picimgPos] = match5.Value.ToString();
                        picimgPos++;
                    }

                    //matches7 获取新闻发布时间
                    MatchCollection matches7 = Regex.Matches(htmlstr2, "<span class=\"a_time\">(.*?)</span>", RegexOptions.IgnoreCase);
                    foreach (Match match7 in matches7)
                    {
                        MatchCollection matches8 = Regex.Matches(match7.Value.ToString(), ">(.*?)</span>", RegexOptions.IgnoreCase);
                        foreach (Match match8 in matches8)
                        {
                            publishdate = match8.Value.ToString().Substring(1, 10).Replace("</span>", "");
                        }
                    }

                    for (int i = 0; i < picimgPos; i++)
                        filecontent = filecontent + picimg[i];
                    //matches4 获取新闻正文内容
                    MatchCollection matches4 = Regex.Matches(htmlstr2, "<[pP] style=\"TEXT-INDENT: 2em\">(.*?)</[pP]>", RegexOptions.IgnoreCase);
                    foreach (Match match4 in matches4)
                    {
                        filecontent = filecontent + match4.Value.ToString().Replace("'", "\\'");
                    }
                    sql += "'" + "奥运体育" + "'," + 9 + ",'" + filecontent + "','UM','" + publishdate + "','" + newshtml + "')";

                    conn.Open();
                    MySqlDataReader reader_filename = new MySqlCommand("select filename from files where filename='" + filename + "'", conn).ExecuteReader();
                    if (reader_filename.HasRows || filecontent.Equals("") || filecontent.Length < 80)
                    {
                        reader_filename.Close();
                    }
                    else
                    {
                        reader_filename.Close();
                        new MySqlCommand(sql, conn).ExecuteNonQuery();
                    }
                    conn.Close();
                }
            }
        }
        catch (Exception msg) { conn.Close(); }
    }
コード例 #11
0
ファイル: GetNews.cs プロジェクト: RoyalBob/Git
    public static void getFenghuangNews(string url, MySqlConnection conn)
    {
        string filename = "", publishdate = "", sql = "";
        string[] picimg = new string[200];
        int picimgPos = 0;

        HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url);
        HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
        Stream receiveStream = httpResponse.GetResponseStream();
        StreamReader streamReader = new StreamReader(receiveStream, Encoding.UTF8);
        string htmlstr = streamReader.ReadToEnd();  //htmlstr是新闻标题页源代码
        streamReader.Close();
        try
        {
            //正则表达式获取<a href></a>内容url
            MatchCollection matches = Regex.Matches(htmlstr, "[<][h][2][>]<a href=\"(.*?)\" target=\"_blank\" title=\"(.*?)\">(.*?)</a>", RegexOptions.IgnoreCase);
            foreach (Match match in matches)
            {
                //matches2 获取 matches 中的新闻标题
                MatchCollection matches2 = Regex.Matches(match.Value.ToString(), ">[^<](.*?)</a>", RegexOptions.IgnoreCase);
                foreach (Match match2 in matches2)
                {
                    filename = match2.Value.ToString().Substring(1).Replace("</a>", "");
                    sql = "insert into files(filename,typename,typeid,filecontent,publisher,publishdate,link) values('" + filename + "',";
                }

                //matches3 获取 matches 中的新闻网址
                MatchCollection matches3 = Regex.Matches(match.Value.ToString(), "href=\"([^\"]*?)\"", RegexOptions.IgnoreCase);
                foreach (Match match3 in matches3)
                {
                    string filecontent = "";
                    picimgPos = 0;
                    string newshtml = match3.Value.ToString().Substring(5).Replace("\"", "");   //newshtml 是新闻网址
                    HttpWebRequest httpRequest2 = (HttpWebRequest)WebRequest.Create(newshtml);
                    HttpWebResponse httpResponse2;
                    try
                    {
                        httpResponse2 = (HttpWebResponse)httpRequest2.GetResponse();
                    }
                    catch (WebException ex)
                    {
                        httpResponse2 = (HttpWebResponse)ex.Response;
                    }
                    Stream receiveStream2 = httpResponse2.GetResponseStream();
                    StreamReader streamReader2 = new StreamReader(receiveStream2, Encoding.UTF8);
                    string htmlstr2 = streamReader2.ReadToEnd();    //htmlstr是新闻详情页源代码
                    streamReader2.Close();

                    //matches5 获取新闻内的图片
                    MatchCollection matches5 = Regex.Matches(htmlstr2, "<img src=\"(.*?)\" width=\"(.*?)\" height=\"(.*?)\" alt=\"(.*?)\" />", RegexOptions.IgnoreCase);
                    foreach (Match match5 in matches5)
                    {
                        picimg[picimgPos] = match5.Value.ToString();
                        picimgPos++;
                    }

                    //matches7 获取新闻发布时间
                    MatchCollection matches7 = Regex.Matches(htmlstr2, "<span itemprop=\"datePublished\" class=\"ss01\">(.*?)</span>", RegexOptions.IgnoreCase);
                    foreach (Match match7 in matches7)
                    {
                        MatchCollection matches8 = Regex.Matches(match7.Value.ToString(), ">(.*?)</span>", RegexOptions.IgnoreCase);
                        foreach (Match match8 in matches8)
                            publishdate = match8.Value.ToString().Substring(1, 10).Replace("</span>", "").Replace("年","-").Replace("月","-");
                    }

                    for (int i = 0; i < picimgPos; i++)
                        filecontent = filecontent + picimg[i];
                    //matches4 获取新闻正文内容
                    MatchCollection matches4 = Regex.Matches(htmlstr2, "<div id=\"main_content\" class=\"js_selection_area\">(.*?)</div>", RegexOptions.Singleline);
                    foreach (Match match4 in matches4)
                    {
                        MatchCollection matches_newscontent = Regex.Matches(match4.Value.ToString(), "<[pP]>(.*?)</[pP]>", RegexOptions.Singleline);
                        foreach (Match match_newscontent in matches_newscontent)
                            filecontent = filecontent + match_newscontent.Value.ToString().Replace("'", "\\'");
                    }

                    sql += "'" + "奥运体育" + "'," + 9 + ",'" + filecontent + "','UM','" + publishdate + "','" + newshtml + "')";

                    conn.Open();
                    MySqlDataReader reader_filename = new MySqlCommand("select filename from files where filename='" + filename + "'", conn).ExecuteReader();
                    if (reader_filename.HasRows || filecontent.Equals("") || filecontent.Length < 80)
                    {
                        reader_filename.Close();
                    }
                    else
                    {
                        reader_filename.Close();
                        new MySqlCommand(sql, conn).ExecuteNonQuery();
                    }
                    conn.Close();
                }
            }
        }
        catch (Exception msg)
        {
            Console.Write("FenghuangNews,Error:" + msg.ToString());
            Console.WriteLine();
            if (conn != null)
                conn.Close();
        }
    }
コード例 #12
0
        private int CheckForProduct(int articleNr)
        {
            var selectQuery = String.Format("select product_id from jos_vm_product where product_sku = \"{0}\" or attribute like \"%{0}%\"", articleNr);
            var selectCommand = new MySqlCommand(selectQuery, _mySqlConnect).ExecuteReader();

            if (!selectCommand.Read())
            {
                selectCommand.Close();
                return 0;
            }

            var temp = selectCommand.GetInt32("product_id");
            selectCommand.Close();
            return temp;
        }
コード例 #13
0
        private void AddPriceForProduct(int productNr, double price)
        {
            price = CheckPrice(price);

            if (productNr == 0) return;

            var selectQuery = String.Format("select product_id from jos_vm_product_price where product_id = {0}", productNr);
            var selectCommand = new MySqlCommand(selectQuery, _mySqlConnect).ExecuteReader();
            var priceString = price.ToString().Replace(',', '.');

            if (!selectCommand.Read())
            {
                selectCommand.Close();

                //nie znaleziono ceny w bazie
                var insertCommand = String.Format("insert into jos_vm_product_price (product_id, product_price, product_currency, product_price_vdate, product_price_edate, cdate, mdate, shopper_group_id, price_quantity_start, price_quantity_end) values ({0}, '{1}', 'EUR', 0, 0, 1280422085, 1280422085, 5, 0, 0)", productNr, priceString);
                new MySqlCommand(insertCommand, _mySqlConnect).ExecuteNonQuery();
            }
            else
            {
                selectCommand.Close();

                //znaleziono cenę w bazie
                var updateCommand = String.Format("update jos_vm_product_price set product_price = \"{0}\" where product_id = {1}", priceString, productNr);
                new MySqlCommand(updateCommand, _mySqlConnect).ExecuteNonQuery();

                //Euro - EUR, Poland - PLN
                updateCommand = String.Format("update jos_vm_product_price set product_currency = 'EUR' where product_id = {0}", productNr);
                new MySqlCommand(updateCommand, _mySqlConnect).ExecuteNonQuery();
            }
        }
コード例 #14
0
ファイル: MySQL.cs プロジェクト: norgalyn/SteamBot
        public static Request getItem()
        {
            Request r = new Request();
            try
            {
                MySqlDataReader rdr = new MySqlCommand("SELECT `id`,`steam_id`,`type`,`priority` FROM `queue` WHERE `id` IN (SELECT `queue_id` FROM `queue_status` WHERE `active`=1 AND `status`=" + (int)RequestStatus.Waiting + ") ORDER BY `priority` DESC, `id` ASC LIMIT 1", QueueConnection).ExecuteReader();
                while (rdr.Read())
                {
                    r.ID = rdr.GetInt32(0);
                    r.User = rdr.GetUInt64(1);
                    r.TradeType = (Bot.TradeTypes)rdr.GetInt32(2);
                    r.Priority = rdr.GetInt32(3);
                }
                rdr.Close();
                r.Data = new string[Int32.Parse((new MySqlCommand("SELECT COUNT(`data`) FROM `queue_items` WHERE `queue_id`=" + r.ID, conn)).ExecuteScalar().ToString())];
                rdr = (new MySqlCommand("SELECT `data` FROM `queue_items` WHERE `queue_id`=" + r.ID, conn)).ExecuteReader();
                int i = 0;
                while (rdr.Read())
                    r.Data[i++] = rdr.GetString(0);
                rdr.Close();
            }
            catch (Exception e)
            {
                log.Error("Error getting new request: " + e.Message);
            }

            return r;
        }
コード例 #15
0
ファイル: Form7.cs プロジェクト: krishnapanakanti/Quiz
        private void BwOnDoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            while (_running)
            {
                if ((worker.CancellationPending == true))
                {
                    e.Cancel = true;
                    return;
                }
                else
                {
                    // Perform a time consuming operation and report progress.
                    String str1, str2;
                    MySqlDataReader rd1, rd2;
                    MySqlConnection Con = new MySqlConnection(
                            "Data Source=216.218.224.238;Database=chatapp;Uid=chatappuser;pwd=1234@ChatAppUser;MultipleActiveResultSets=true;");
                    // SqlConnection Con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=Test;User ID=;Password=;Connection Timeout=600");
                    Con.Open();

                    rd1 =
                        new MySqlCommand(
                            "select top 1 Chat from chat where  where email ='" + label4.Text + "'order by id Desc", Con)
                            .ExecuteReader();
                    rd1.Read();
                    str1 = rd1["Chat"].ToString();
                    rd1.Close();
                    rd2 =
                        new MySqlCommand(
                            "select top 1 UserInitial from chat where email ='" + label4.Text + "' order by id Desc",
                            Con)
                            .ExecuteReader();
                    rd2.Read();
                    str2 = rd2["UserInitial"].ToString();
                    rd2.Close();
                    if (str1 != str2)
                    {
                        MySqlDataReader rd3, rd4;
                        rd3 =
                            new MySqlCommand(
                                "select top 1 UserInitial from chat  where email ='" + label4.Text + "'order by id desc",
                                Con).ExecuteReader();

                        var value = rd3.Read();
                        rd3.Close();

                        if (richTextBox1.InvokeRequired)
                        {
                            richTextBox1.BeginInvoke(
                                new MethodInvoker(() => richTextBox1.Text += richTextBox1.Text + " <br /> " + value));
                        }
                        else
                        {
                            richTextBox1.Text = richTextBox1.Text + " <br /> " + value;
                        }
                        rd4 =
                            new MySqlCommand(
                                "Update top 1 chat set Chat = UserInitial  where email ='" + label4.Text +
                                "'order by id desc", Con).ExecuteReader();
                        rd4.Read();
                        rd4.Close();
                        Con.Close();
                    }

                  //  Thread.Sleep(1000); //sleep 1 second

                }
                //System.Threading.Thread.Sleep(500);
            }
        }