예제 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     pid       = RequestTool.RequestInt("pid", 0);
     inputname = RequestTool.RequestString("input");
     if (inputname == "")
     {
         inputname = "Images";
     }
     images = RequestTool.RequestString("images");
     list   = new List <LBimage>();
     string[] arr = images.Split('@');
     foreach (string str in arr)
     {
         if (str != "")
         {
             LBimage model = new LBimage();
             model.original = str;
             model.small    = str + "&w=100&h=100";
             model.medium   = str + "&w=300&h=300";
             model.big      = str + "&w=800&h=800";
             list.Add(model);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// 导入淘宝商品数据
        /// </summary>
        public void taobao_product_in()
        {
            if (!Power("supplier_product_datainout", "导入导出"))
            {
                AjaxNoPower();
                return;
            }
            int    tb_typeid = RequestTool.RequestInt("tb_typeid", 0);
            string tb_file   = RequestTool.RequestString("tb_file");
            string tb_folder = RequestTool.RequestString("tb_folder");
            string fileName  = HttpContext.Current.Server.MapPath(@"~/" + WebPath + tb_file);
            int    tb_split  = RequestTool.RequestInt("tb_split", 0);
            string tbin_lang = RequestTool.RequestString("tbin_lang");
            int    i         = 0;

            if (File.Exists(fileName))
            {
                DataTable dt   = new DataTable();
                char      flag = '\t';
                if (tb_split == 2)
                {
                    flag = ',';
                }
                using (FileStream fs = new FileStream(fileName, FileMode.Open))
                {
                    using (StreamReader reader = new StreamReader(fs, Encoding.Default))
                    {
                        string text = string.Empty;
                        while (!reader.EndOfStream)
                        {
                            text = reader.ReadLine();
                            if (i == 1)
                            {
                                string[] arr = text.Split(flag);
                                foreach (string col in arr)
                                {
                                    dt.Columns.Add(col);
                                }
                            }
                            else if (i > 1)
                            {
                                string[] arr = text.Split(flag);
                                DataRow  r   = dt.NewRow();
                                int      j   = 0;
                                foreach (string col in arr)
                                {
                                    if (j >= dt.Columns.Count)
                                    {
                                        break;
                                    }
                                    try
                                    {
                                        r[j] = col.Replace("\"", "");
                                    }
                                    catch
                                    {
                                        r[j] = "";
                                    }
                                    j++;
                                }
                                dt.Rows.Add(r);
                            }
                            i++;
                        }
                    }
                }
                //======================================
                if (!dt.Columns.Contains("outer_id"))
                {
                    Response.Write("{\"msg\":\"请检查是否包含outer_id字段\"}");
                    return;
                }
                string number = "";
                int    count  = 0;
                for (int m = 0; m < dt.Rows.Count; m++)
                {
                    try
                    {
                        if (dt.Columns.Contains("outer_id"))
                        {
                            number = dt.Rows[m]["outer_id"].ToString();
                        }
                        bool         addflag = false;
                        Lebi_Product pro     = B_Lebi_Product.GetModel("Supplier_id =" + CurrentSupplier.id + " and Number=lbsql{'" + number + "'}");
                        if (pro == null)
                        {
                            pro        = new Lebi_Product();
                            addflag    = true;
                            pro.Number = dt.Rows[m]["outer_id"].ToString();
                            pro.Type_id_ProductStatus = 101;
                            pro.Type_id_ProductType   = 320;
                            pro.Supplier_id           = CurrentSupplier.id;
                            pro.IsSupplierTransport   = CurrentSupplierGroup.IsSubmit;
                        }
                        pro.Pro_Type_id = tb_typeid;

                        if (dt.Columns.Contains("title"))
                        {
                            pro.Name = Language.GetString(dt.Rows[m]["title"].ToString(), pro.Name, tbin_lang);
                        }
                        if (dt.Columns.Contains("description"))
                        {
                            pro.Description = Language.GetString(dt.Rows[m]["description"].ToString(), pro.Description, tbin_lang);
                        }
                        if (dt.Columns.Contains("wireless_desc"))
                        {
                            pro.MobileDescription = Language.GetString(dt.Rows[m]["wireless_desc"].ToString(), pro.MobileDescription, tbin_lang);
                        }

                        if (dt.Columns.Contains("price"))
                        {
                            if (dt.Columns.Contains("price"))
                            {
                                string p = dt.Rows[m]["price"].ToString();
                                pro.Price = Convert.ToDecimal(p);
                            }
                            pro.Price_Market = pro.Price;
                            pro.Price_Cost   = pro.Price;
                        }
                        if (dt.Columns.Contains("num"))
                        {
                            int Count_Stock = 0;
                            int.TryParse(Convert.ToString(dt.Rows[m]["num"]), out Count_Stock);
                            pro.Count_Stock = Count_Stock;
                        }
                        if (dt.Columns.Contains("item_weight"))
                        {
                            int Weight = 0;
                            int.TryParse(Convert.ToString(dt.Rows[m]["item_weight"]), out Weight);
                            pro.Weight = Weight;
                        }
                        if (dt.Columns.Contains("VolumeL"))
                        {
                            int VolumeL = 0;
                            int.TryParse(Convert.ToString(dt.Rows[m]["VolumeL"]), out VolumeL);
                            pro.VolumeL = VolumeL;
                        }
                        if (dt.Columns.Contains("VolumeW"))
                        {
                            int VolumeW = 0;
                            int.TryParse(Convert.ToString(dt.Rows[m]["VolumeW"]), out VolumeW);
                            pro.VolumeW = VolumeW;
                        }
                        if (dt.Columns.Contains("VolumeH"))
                        {
                            int VolumeH = 0;
                            int.TryParse(Convert.ToString(dt.Rows[m]["VolumeH"]), out VolumeH);
                            pro.VolumeH = VolumeH;
                        }
                        if (dt.Columns.Contains("PackageRate"))
                        {
                            int PackageRate = 1;
                            int.TryParse(Convert.ToString(dt.Rows[m]["PackageRate"]), out PackageRate);
                            pro.PackageRate = PackageRate;
                        }
                        if (addflag)
                        {
                            B_Lebi_Product.Add(pro);
                            pro.id = B_Lebi_Product.GetMaxId();
                        }
                        else
                        {
                            B_Lebi_Product.Update(pro);
                        }
                        if (dt.Columns.Contains("picture"))
                        {
                            try
                            {
                                string img    = dt.Rows[m]["picture"].ToString();
                                string images = "";
                                if (tb_folder == "")
                                {
                                    //1f6edf58105f3abb1ef9665129eb6c52
                                    //1f6edf58105f3abb1ef9665129eb6c52:1:0:|http://img01.taobaocdn.com/bao/uploaded/i1/T1Oys1FgNeXXXXXXXX_!!0-item_pic.jpg;
                                    //5327022ebfe958090d3abff999c8c800:1:1:|http://img02.taobaocdn.com/bao/uploaded/i2/24197542/T2wnCFXtNXXXXXXXXX_!!24197542.jpg;
                                    //b7972e16753d746d77f2f769002268d5:1:2:|http://img01.taobaocdn.com/bao/uploaded/i1/24197542/T2n6BuXvhXXXXXXXXX_!!24197542.jpg;
                                    //06e5fd8cdb3babd4664b7b736258290a:1:3:|http://img03.taobaocdn.com/bao/uploaded/i3/24197542/T2yX1BXwhXXXXXXXXX_!!24197542.jpg;
                                    //d1a5c9c441a994310db75a83005628b7:1:4:|http://img03.taobaocdn.com/bao/uploaded/i3/24197542/T2I4XAXpJaXXXXXXXX_!!24197542.jpg;
                                    //处理图片
                                    string[,] arr = RegexTool.GetRegArray(img, @"\|(.*?);");
                                    for (int ai = 0; ai < arr.GetUpperBound(0); ai++)
                                    {
                                        string v = RegexTool.GetRegValue(arr[ai, 1], @"\|(.*?);");
                                        if (v == null || v == "")
                                        {
                                            continue;
                                        }
                                        LBimage lbimg = ImageHelper.DownLoadImage(v, pro);
                                        if (ai == 0)
                                        {
                                            pro.ImageBig      = lbimg.big;
                                            pro.ImageMedium   = lbimg.medium;
                                            pro.ImageOriginal = lbimg.original;
                                            pro.ImageSmall    = lbimg.small;
                                        }
                                        else
                                        {
                                            images += "@" + lbimg.original;
                                        }
                                    }
                                }
                                else
                                {
                                    //上传文件夹导入图片的方式
                                    img           = ";" + img;
                                    string[,] arr = RegexTool.GetRegArray(img, @";(.*?):");
                                    string ServerPath = System.Web.HttpContext.Current.Server.MapPath("~/");
                                    for (int ai = 0; ai < arr.GetUpperBound(0); ai++)
                                    {
                                        string v = RegexTool.GetRegValue(arr[ai, 1], @";(.*?):");
                                        if (v == null || v == "")
                                        {
                                            continue;
                                        }
                                        v = ServerPath + tb_folder + "/" + v + ".tbi";
                                        v = v.Replace("//", "/");
                                        LBimage lbimg = ImageHelper.CreateTaobaoImage(v, pro);
                                        if (ai == 0)
                                        {
                                            pro.ImageBig      = lbimg.big;
                                            pro.ImageMedium   = lbimg.medium;
                                            pro.ImageOriginal = lbimg.original;
                                            pro.ImageSmall    = lbimg.small;
                                        }
                                        else
                                        {
                                            images += "@" + lbimg.original;
                                        }
                                    }
                                }
                                pro.Images = images;
                                B_Lebi_Product.Update(pro);
                            }
                            catch
                            {
                            }
                        }
                        count++;
                    }
                    catch
                    {
                        continue;
                    }
                }
                Log.Add("导入淘宝商品", "Product", "");
                Response.Write("{\"msg\":\"OK\",\"count\":\"" + count + "\"}");
            }
            else
            {
                Response.Write("{\"msg\":\"" + Tag("数据文件错误") + "\"}");
                return;
            }
        }