Ejemplo n.º 1
0
        private void DoWorkProportion(object arg)
        {
            try
            {
                string[] arr = arg as string[];

                var sourceFolder = arr[0];

                #region 装载图片
                ls800     = new List <string>();
                sourceDir = new DirectoryInfo(sourceFolder);
                foreach (FileSystemInfo fs in sourceDir.GetFileSystemInfos())
                {
                    int    staridx   = fs.FullName.LastIndexOf('\\');
                    string imagefile = fs.FullName.Substring(staridx + 1);
                    int    idx       = imagefile.LastIndexOf(".");
                    ls800.Add(imagefile.Substring(0, idx));
                }
                #endregion

                //创建新连接
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["OracleConnectionString"].ToString()))
                {
                    try
                    {
                        conn.Open();
                        SqlCommand cmd = conn.CreateCommand();
                        cmd.CommandText = "SELECT * FROM PdProduct where DealerSysNo=108  ORDER BY SYSNO";

                        DataTable      dt      = new DataTable();
                        SqlDataAdapter adapter = new SqlDataAdapter();
                        adapter.SelectCommand = cmd;
                        adapter.Fill(dt);

                        if (dt != null)
                        {
                            //调整进度
                            UpdateProgress(dt.Rows.Count, 0);

                            int i = 0;
                            foreach (DataRow dr in dt.Rows)
                            {
                                string sysNo = dr["sysNo"].ToString();
                                //系统编号

                                #region 查找同一个产品的其它图片
                                ls = new List <string>();
                                foreach (var drr in ls800)
                                {
                                    string[] arrr = drr.Split('_');
                                    if (drr == sysNo)
                                    {
                                        ls.Add(drr);
                                    }
                                    if (arrr.Length > 1)
                                    {
                                        if (arrr[1] == sysNo)
                                        {
                                            ls.Add(drr);
                                        }
                                    }
                                }
                                #endregion

                                int k = 0;
                                foreach (var itemNo in ls)
                                {
                                    string fileName      = NewFileName(".jpg");
                                    string fileSmallName = fileName + ".small.jpg";
                                    string filePath      = string.Format(@"{0}\\{1}.jpg", sourceFolder, itemNo);

                                    //数据库格式文件
                                    string dbbasePath = string.Format(productImageConfig.ProductImagePathFormat, "{1}", fileName);
                                    //检查文件是否正在
                                    if (System.IO.File.Exists(filePath))
                                    {
                                        ImageUtil.CreateThumbnail(sourceFolder + "\\" + itemNo + ".jpg", targetFolder + "\\Base\\" + fileName, 800, 800, ImageUtil.ThumbnailMode.WidthHeighLimitted);
                                        ImageUtil.CreateThumbnail(sourceFolder + "\\" + itemNo + ".jpg", targetFolder + "\\Big\\" + fileName, 460, 460, ImageUtil.ThumbnailMode.WidthHeighLimitted);
                                        ImageUtil.CreateThumbnail(sourceFolder + "\\" + itemNo + ".jpg", targetFolder + "\\Small\\" + fileSmallName, 100, 100, ImageUtil.ThumbnailMode.WidthHeighLimitted);

                                        int status = 0;
                                        if (k == 0)
                                        {
                                            status = 1;
                                        }
                                        string sql =
                                            string.Format(
                                                "insert into PdProductImage(ProductSysNo,ImageUrl,Status,DisplayOrder) values({0}, '{1}', {2}, {3})",
                                                sysNo, "{0}" + dbbasePath, status, k);

                                        cmd.CommandText = sql;
                                        cmd.ExecuteNonQuery();
                                        k++;
                                    }
                                }
                                i++;
                                UpdateProgress(dt.Rows.Count, i);
                            }
                            UpdateProgress(dt.Rows.Count, dt.Rows.Count);
                        }
                        conn.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 读取所有产品生成缩略图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //#region 装载图片
                //ls800 = new List<string>();
                //sourceDir = new DirectoryInfo(sourceFolder);
                //foreach (FileSystemInfo fs in sourceDir.GetFileSystemInfos())
                //{
                //    int staridx = fs.FullName.LastIndexOf('\\');
                //    string imagefile = fs.FullName.Substring(staridx + 1);
                //    int idx = imagefile.LastIndexOf(".");
                //    ls800.Add(imagefile.Substring(0, idx));
                //}
                //#endregion

                //创建新连接
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["OracleConnectionString"].ToString()))
                {
                    try
                    {
                        conn.Open();
                        SqlCommand cmd = conn.CreateCommand();

                        cmd.CommandText = "SELECT  pimg.[ProductSysNo],pimg.[ImageUrl] FROM [PdProductImage] as pimg inner join PdProduct as p on p.sysNo=pimg.ProductSysNo  where p.DealerSysNo=108 and pimg.status=1";
                        //cmd.CommandText = "SELECT  pimg.[ProductSysNo],pimg.[ImageUrl] FROM [PdProductImage] as pimg inner join PdProduct as p on p.sysNo=pimg.ProductSysNo  where pimg.status=1";

                        DataTable      dt      = new DataTable();
                        SqlDataAdapter adapter = new SqlDataAdapter();
                        adapter.SelectCommand = cmd;
                        adapter.Fill(dt);

                        if (dt != null)
                        {
                            //调整进度
                            UpdateProgress(dt.Rows.Count, 0);

                            int i = 0;
                            foreach (DataRow dr in dt.Rows)
                            {
                                string sysNo = dr["ProductSysNo"].ToString();
                                //系统编号

                                string filePath = dr["ImageUrl"].ToString();



                                int k = 0;


                                sourceFolder = "D:\\RNBXiaoQuShangChao\\StaticFiles\\SG\\Images\\";

                                string fileName      = sysNo + ".jpg";
                                string fileSmallName = fileName + ".small.jpg";
                                //string filePath = string.Format(@"{0}\\{1}.jpg", sourceFolder, itemNo);
                                fileName = sourceFolder + string.Format(filePath, "", "Base").Replace("/", "\\");

                                string saveFile = sourceFolder + "Product\\Image100\\" + sysNo + ".jpg";

                                //检查文件是否正在
                                if (System.IO.File.Exists(fileName))
                                {
                                    // ImageUtil.CreateThumbnail(sourceFolder + "\\" + itemNo + ".jpg", targetFolder + "\\Base\\" + fileName, 800, 800, ImageUtil.ThumbnailMode.WidthHeighLimitted);
                                    // ImageUtil.CreateThumbnail(sourceFolder + "\\" + itemNo + ".jpg", targetFolder + "\\Big\\" + fileName, 460, 460, ImageUtil.ThumbnailMode.WidthHeighLimitted);
                                    // ImageUtil.CreateThumbnail(sourceFolder + "\\" + itemNo + ".jpg", targetFolder + "\\Small\\" + fileSmallName, 100, 100, ImageUtil.ThumbnailMode.WidthHeighLimitted);

                                    ImageUtil.CreateThumbnail(fileName, saveFile, 240, 240, ImageUtil.ThumbnailMode.WidthHeighLimitted);



                                    k++;
                                }

                                i++;
                                UpdateProgress(dt.Rows.Count, i);
                            }
                            UpdateProgress(dt.Rows.Count, dt.Rows.Count);
                        }
                        conn.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                throw;
            }
        }
Ejemplo n.º 3
0
        private void DoWork(object arg)
        {
            string[] arr = arg as string[];

            var sourceFolder = arr[0];
            var targetFolder = arr[1];

            string[] files = Directory.GetFiles(sourceFolder, "*.jpg");

            //创建新连接
            using (OracleConnection conn = new OracleConnection(ConfigurationManager.AppSettings["OracleConnectionString"].ToString()))
            {
                try
                {
                    conn.Open();
                    OracleCommand cmd = conn.CreateCommand();
                    cmd.CommandText = "SELECT SYSNO FROM PdProduct ORDER BY SYSNO";

                    DataTable         dt      = new DataTable();
                    OracleDataAdapter adapter = new OracleDataAdapter();
                    adapter.SelectCommand = cmd;
                    adapter.Fill(dt);
                    if (dt != null)
                    {
                        //调整进度
                        UpdateProgress(dt.Rows.Count, 0);

                        int i = 0;
                        foreach (DataRow dr in dt.Rows)
                        {
                            i++;
                            string sysNo    = dr["sysNo"].ToString();
                            string filePath = string.Format(sourceFolder + "\\" + dr["sysNo"] + ".jpg");

                            //检查文件是否正在
                            if (System.IO.File.Exists(filePath))
                            {
                                if (cb460.Checked)
                                {
                                    ImageUtil.CreateThumbnail(sourceFolder + "\\" + sysNo + ".jpg", targetFolder + "\\Image460\\" + sysNo + ".jpg", 460, 460, ImageUtil.ThumbnailMode.WidthHeighLimitted);
                                }
                                if (cb240.Checked)
                                {
                                    ImageUtil.CreateThumbnail(sourceFolder + "\\" + sysNo + ".jpg", targetFolder + "\\Image240\\" + sysNo + ".jpg", 240, 240, ImageUtil.ThumbnailMode.WidthHeighLimitted);
                                }
                                if (cb200.Checked)
                                {
                                    ImageUtil.CreateThumbnail(sourceFolder + "\\" + sysNo + ".jpg", targetFolder + "\\Image200\\" + sysNo + ".jpg", 200, 200, ImageUtil.ThumbnailMode.WidthHeighLimitted);
                                }
                                if (cb180.Checked)
                                {
                                    ImageUtil.CreateThumbnail(sourceFolder + "\\" + sysNo + ".jpg", targetFolder + "\\Image180\\" + sysNo + ".jpg", 180, 180, ImageUtil.ThumbnailMode.WidthHeighLimitted);
                                }
                                if (cb120.Checked)
                                {
                                    ImageUtil.CreateThumbnail(sourceFolder + "\\" + sysNo + ".jpg", targetFolder + "\\Image120\\" + sysNo + ".jpg", 120, 120, ImageUtil.ThumbnailMode.WidthHeighLimitted);
                                }
                                if (cb100.Checked)
                                {
                                    ImageUtil.CreateThumbnail(sourceFolder + "\\" + sysNo + ".jpg", targetFolder + "\\Image100\\" + sysNo + ".jpg", 100, 100, ImageUtil.ThumbnailMode.WidthHeighLimitted);
                                }
                                if (cb80.Checked)
                                {
                                    ImageUtil.CreateThumbnail(sourceFolder + "\\" + sysNo + ".jpg", targetFolder + "\\Image80\\" + sysNo + ".jpg", 80, 80, ImageUtil.ThumbnailMode.WidthHeighLimitted);
                                }
                                if (cb60.Checked)
                                {
                                    ImageUtil.CreateThumbnail(sourceFolder + "\\" + sysNo + ".jpg", targetFolder + "\\Image60\\" + sysNo + ".jpg", 60, 60, ImageUtil.ThumbnailMode.WidthHeighLimitted);
                                }
                            }

                            //调整进度
                            UpdateProgress(dt.Rows.Count, i);
                        }
                    }
                    conn.Close();
                    //调整进度
                    UpdateProgress(dt.Rows.Count, dt.Rows.Count);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }