Exemple #1
0
        //处理历史没完成的任务
        public void HistoryWork()
        {
            //找出所有历史任务
            string sql = "select * from BaiduUpload_service where path<>''";

            var       client = new Baidu.Aip.ImageSearch.ImageSearch(API_KEY, SECRET_KEY);
            DataTable dt     = SqlHelper.SqlHelper.ExcuteDataTable(sql);

            foreach (DataRow item in dt.Rows)
            {
                try
                {
                    var image = File.ReadAllBytes(item["path"].ToString());
                    Dictionary <string, object> options = new Dictionary <string, object> {
                        { "brief", "{\"fGoodsCode\":\"" + item["fGoodsCode"].ToString() + "\"}" },
                        { "url", item["path"].ToString() }
                    };
                    var res = client.ProductAdd(image, options);
                    if (res.Count == 2)
                    {
                        //上传成功
                        string         sql2        = "update  BaiduUpload_info set cont_sign=@cont_sign where fGoodsCode=@fGoodsCode";
                        SqlParameter[] parameters2 = new SqlParameter[] {
                            new SqlParameter("@cont_sign", res["cont_sign"].ToString()),
                            new SqlParameter("@fGoodsCode", item["fGoodsCode"].ToString())
                        };
                        int count = SqlHelper.SqlHelper.ExcuteNonQuery(sql2, parameters2);

                        if (count > 0)
                        {
                            sw.WriteLine("成功更新历史任务 品号:" + item["fGoodsCode"].ToString() + "--时间:" + DateTime.Now);
                            string         sql_deltete = "delete  from BaiduUpload_service where  fGoodsCode=@fGoodsCode";
                            SqlParameter[] parameters3 = new SqlParameter[] {
                                new SqlParameter("@fGoodsCode", item["fGoodsCode"].ToString())
                            };
                            SqlHelper.SqlHelper.ExcuteNonQuery(sql_deltete, parameters3);
                        }
                        else
                        {
                            sw.WriteLine("更新历史任务失败 品号:" + item["fGoodsCode"].ToString() + "--时间:" + DateTime.Now);
                        }
                    }
                    else
                    {
                        //报错
                        string error    = res["error_code"].ToString();
                        string id       = Guid.NewGuid().ToString();
                        string sql_text = "insert into BaiduUpload_err values(@id,@fGoodSCode,@flieName,@cont_same,@upLoadDate,@err_Code)";

                        SqlParameter[] parameters = new SqlParameter[] {
                            new SqlParameter("@id", id),
                            new SqlParameter("@fGoodSCode", item["fGoodsCode"].ToString()),
                            new SqlParameter("@flieName", item["path"].ToString()),
                            new SqlParameter("@cont_same", res["cont_sign"].ToString()),
                            new SqlParameter("@upLoadDate", DateTime.Now),
                            new SqlParameter("@err_Code", error),
                        };
                        int count = SqlHelper.SqlHelper.ExcuteNonQuery(sql_text, parameters);

                        string sql_deltete = "delete  from BaiduUpload_service where  fGoodsCode=@fGoodsCode";

                        SqlParameter[] parameters3 = new SqlParameter[] {
                            new SqlParameter("@fGoodsCode", item["fGoodsCode"].ToString())
                        };
                        SqlHelper.SqlHelper.ExcuteNonQuery(sql_deltete, parameters3);

                        Console.WriteLine("删除" + item["fGoodsCode"].ToString());



                        if (count > 0)
                        {
                            sw.WriteLine(item["fGoodsCode"].ToString() + "更新失败状态码" + error + "时间:" + DateTime.Now);
                        }
                    }
                }
                catch (Exception ex)
                {
                    sw.WriteLine("处理历史任务出现异常" + ex.Message);
                }


                System.Threading.Thread.Sleep(1000);
                sw.Flush();
                F.Flush();
            }



            sw.WriteLine("处理历史" + dt.Rows.Count + "个" + DateTime.Now);
        }
Exemple #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            //找到奥特莱斯所有产品
            var task = Task.Run(() =>
            {
                if (this.textBox1.Text == "")
                {
                    MessageBox.Show("还没选择路径");
                    return;
                }



                string sql = "SELECT fGoodsCode,fSimplePicFile FROM t_BOMM_GoodsMst where fSimplePicFile is not null and fCFlag='1' and fBrandCode='11' and fSimplePicFile<>'' and fDevProperty<>'2'";
                SqlParameter[] parameters = new SqlParameter[] {
                };

                DataTable dt = SqlHelper.SqlHelper.ExcuteDataTable(sql, parameters);

                var client = new Baidu.Aip.ImageSearch.ImageSearch(API_KEY, SECRET_KEY);



                foreach (DataRow item in dt.Rows)
                {
                    try
                    {
                        var options = new Dictionary <string, object> {
                            { "brief", "{\"fGoodsCode\":\"" + item["fGoodsCode"].ToString() + "\"}" },
                            { "url", Guid.NewGuid().ToString() }
                        };



                        var image = File.ReadAllBytes(this.textBox1.Text + "\\" + item["fSimplePicFile"].ToString());

                        var result = client.ProductAdd(image, options);


                        if (result.Count == 2)
                        {
                            string sql2 = "insert into BaiduUpload_info values(@fGoodsCode,@cont_sign)";
                            SqlParameter[] parameters2 = new SqlParameter[] {
                                new SqlParameter("@fGoodsCode", item["fGoodsCode"].ToString()),
                                new SqlParameter("@cont_sign", result["cont_sign"].ToString())
                            };

                            int count = SqlHelper.SqlHelper.ExcuteNonQuery(sql2, parameters2);
                            if (count > 0)
                            {
                                setList fc = new setList(Settext);
                                this.BeginInvoke(fc, item["fGoodsCode"].ToString() + "上传成功"); //调用代理
                                                                                              // Console.WriteLine(FullName + "上传成功");
                            }
                        }
                        else
                        {
                            setList fc = new setList(Settext2);

                            this.BeginInvoke(fc, item["fGoodsCode"].ToString() + "状态码:" + result["error_code"].ToString());//调用代理


                            Console.WriteLine(result);

                            sw.WriteLine(item["fGoodsCode"].ToString() + "状态码:" + result["error_code"].ToString());
                        }
                    }
                    catch (Exception ex)
                    {
                        setList fc = new setList(Settext2);
                        this.BeginInvoke(fc, item["fGoodsCode"].ToString() + "找不到文件");//调用代理
                    }

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

                sw.Close();
                F.Close();


                MessageBox.Show("全部上传完成");
            });
        }
Exemple #3
0
        private void handle(string contSign, string path, string fGoodsCode)
        {
            //删除百度
            var client = new Baidu.Aip.ImageSearch.ImageSearch(API_KEY, SECRET_KEY);

            var result = client.ProductDeleteBySign(contSign);
            //上传百度

            var image = File.ReadAllBytes(path);

            // 如果有可选参数
            var options = new Dictionary <string, object> {
                { "brief", "{\"fGoodsCode\":\"" + fGoodsCode + "\"}" },
                { "url", path }
            };
            var res = client.ProductAdd(image, options);


            if (res.Count == 2)
            {
                //上传成功更新数据库

                string         sql2        = "update  BaiduUpload_info set cont_sign=@cont_sign where fGoodsCode=@fGoodsCode";
                SqlParameter[] parameters2 = new SqlParameter[] {
                    new SqlParameter("@cont_sign", res["cont_sign"].ToString()),

                    new SqlParameter("@fGoodsCode", fGoodsCode)
                };
                int count = SqlHelper.SqlHelper.ExcuteNonQuery(sql2, parameters2);
                if (count > 0)
                {
                    sw.WriteLine(fGoodsCode + "更新成功" + DateTime.Now.ToString("yyyy-MM-dd"));
                }
                else
                {
                    string         sql3 = "insert into  BaiduUpload_info values(@fGoodsCode,@cont_sign)";
                    SqlParameter[] p    = new SqlParameter[] {
                        new SqlParameter("@cont_sign", res["cont_sign"].ToString()),
                        new SqlParameter("@fGoodsCode", fGoodsCode)
                    };
                    int row = SqlHelper.SqlHelper.ExcuteNonQuery(sql3, p);
                    if (row > 0)
                    {
                        sw.WriteLine(fGoodsCode + "新增成功" + DateTime.Now.ToString("yyyy-MM-dd"));
                    }
                }
            }
            else
            {
                string error    = res["error_code"].ToString();
                string id       = Guid.NewGuid().ToString();
                string sql_text = "insert into BaiduUpload_err values(@id,@fGoodSCode,@flieName,@cont_same,@upLoadDate,@err_Code)";

                SqlParameter[] parameters = new SqlParameter[] {
                    new SqlParameter("@id", id),
                    new SqlParameter("@fGoodSCode", fGoodsCode),
                    new SqlParameter("@flieName", path),
                    new SqlParameter("@cont_same", res["cont_sign"].ToString()),
                    new SqlParameter("@upLoadDate", DateTime.Now),
                    new SqlParameter("@err_Code", error),
                };
                int count = SqlHelper.SqlHelper.ExcuteNonQuery(sql_text, parameters);
                if (count > 0)
                {
                    sw.WriteLine(fGoodsCode + "更新失败" + DateTime.Now);
                }
            }
        }
Exemple #4
0
        private void Run(string FullName, string fGoodsCode)
        {
            //var task = Task.Run(() =>
            //{

            try
            {
                var image = File.ReadAllBytes(FullName);
                // 调用商品检索—入库, 图片参数为本地图片,可能会抛出网络等异常,请使用try/catch捕获
                var client = new Baidu.Aip.ImageSearch.ImageSearch(API_KEY, SECRET_KEY);
                //var result = client.ProductAdd(image);

                // 如果有可选参数
                var options = new Dictionary <string, object> {
                    { "brief", "{\"fGoodsCode\":\"" + fGoodsCode + "\"}" },
                    { "url", FullName }
                };
                // 带参数调用商品检索—入库, 图片参数为本地图片
                // \"fGoodsName\":\""+item["fGoodsName"].ToString()+"\",\"fClrName\":\""+item["fClrName"].ToString()+"\",\"fStdSellUp\":\""+item["fStdSellUp"].ToString()+"\",\"fSizeDesc\":\""+item["fSizeDesc"].ToString()+"\",\"fMKName\":\""+item["fMKName"].ToString()+"\",\"url\":\""+files[i].Name+"\"}"
                var result = client.ProductAdd(image, options);

                if (result.Count == 2)
                {
                    string         id         = Guid.NewGuid().ToString();
                    string         sql        = "insert into BaiduUpload_info values(@fGoodsCode,@cont_sign,@fileName,@id,@upLoadDate)";
                    SqlParameter[] parameters = new SqlParameter[] {
                        new SqlParameter("@fGoodsCode", fGoodsCode),
                        new SqlParameter("@cont_sign", result["cont_sign"].ToString()),
                        new SqlParameter("@fileName", FullName),
                        new SqlParameter("@id", id),
                        new SqlParameter("@upLoadDate", DateTime.Now),
                    };

                    int count = SqlHelper.SqlHelper.ExcuteNonQuery(sql, parameters);
                    if (count > 0)
                    {
                        setList fc = new setList(Settext);
                        this.BeginInvoke(fc, FullName + "上传成功");         //调用代理
                        Console.WriteLine(FullName + "上传成功");
                    }
                }
                else
                {
                    string error    = result["error_code"].ToString();
                    string id       = Guid.NewGuid().ToString();
                    string sql_text = "insert into BaiduUpload_err values(@id,@fGoodSCode,@flieName,@cont_same,@upLoadDate,@err_Code)";

                    SqlParameter[] parameters = new SqlParameter[] {
                        new SqlParameter("@id", id),
                        new SqlParameter("@fGoodSCode", fGoodsCode),
                        new SqlParameter("@flieName", FullName),
                        new SqlParameter("@cont_same", result["cont_sign"].ToString()),

                        new SqlParameter("@upLoadDate", DateTime.Now),
                        new SqlParameter("@err_Code", error),
                    };
                    int count = SqlHelper.SqlHelper.ExcuteNonQuery(sql_text, parameters);
                    if (error.Equals("216681"))
                    {
                        if (count > 0)
                        {
                            setList f = new setList(Settext2);
                            this.BeginInvoke(f, FullName + "重复已记录");//调用代理
                        }
                    }
                    else
                    {
                        setList fc = new setList(Settext2);
                        this.BeginInvoke(fc, FullName + "状态码:" + error);//调用代理
                    }
                }
            }
            catch (Exception ex)
            {
                sw.WriteLine(fGoodsCode + "找不到:" + FullName);

                //文件找不到写入数据库

                string sql_text = "insert into BaiduUpload_service values(@id,@fGoodsCode,@path,@workDate)";

                SqlParameter[] parms = new SqlParameter[]
                {
                    new SqlParameter("@id", Guid.NewGuid().ToString()),
                    new SqlParameter("@fGoodsCode", fGoodsCode),
                    new SqlParameter("@path", FullName),
                    new SqlParameter("@workDate", DateTime.Now)
                };
                int count = SqlHelper.SqlHelper.ExcuteNonQuery(sql_text, parms);

                if (count > 0)
                {
                    sw.WriteLine(fGoodsCode + "没有找到图片文件插入到数据库");
                }
                else
                {
                    sw.WriteLine(fGoodsCode + "没有找到图片文件插入到数据库失败");
                }



                Console.WriteLine(ex);
                Console.WriteLine(FullName + "上传失败");
            }



            //});
        }