コード例 #1
0
ファイル: Driver.cs プロジェクト: borllor/Roadlight.Net
        public virtual List <MySqlError> ReportWarnings(MySqlConnection connection)
        {
            List <MySqlError> list = new List <MySqlError>();

            using (MySqlDataReader mySqlDataReader = new MySqlCommand("SHOW WARNINGS", connection)
            {
                InternallyCreated = true
            }.ExecuteReader())
            {
                while (mySqlDataReader.Read())
                {
                    list.Add(new MySqlError(mySqlDataReader.GetString(0), mySqlDataReader.GetInt32(1), mySqlDataReader.GetString(2)));
                }
            }
            MySqlInfoMessageEventArgs mySqlInfoMessageEventArgs = new MySqlInfoMessageEventArgs();

            mySqlInfoMessageEventArgs.errors = list.ToArray();
            if (connection != null)
            {
                connection.OnInfoMessage(mySqlInfoMessageEventArgs);
            }
            return(list);
        }
コード例 #2
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;
        }
コード例 #3
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;
        }
コード例 #4
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) { }
    }
コード例 #5
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;
        }