Ejemplo n.º 1
0
 private void btDownloadImg_Click(object sender, EventArgs e)
 {
     DBToolTableAdapters.View_SanPhamImageTableAdapter adt = new DBToolTableAdapters.View_SanPhamImageTableAdapter();
     DBTool.View_SanPhamImageDataTable dt = new DBTool.View_SanPhamImageDataTable();
     adt.Connection.ConnectionString = QT.Entities.Server.ConnectionString;
     if (adt.Connection.State == ConnectionState.Closed)
     {
         adt.Connection.Open();
     }
     adt.FillByAll_Da_TaiImage(dt);
     DowloadImageV2(dt);
     dt.Dispose();
     adt.Dispose();
 }
Ejemplo n.º 2
0
 private void btDownloadImageChuaTai_Click(object sender, EventArgs e)
 {
     /// Download lại toàn bộ ảnh của những sản phẩm chưa được kiểm tra
     ///
     DBToolTableAdapters.View_SanPhamImageTableAdapter adt = new DBToolTableAdapters.View_SanPhamImageTableAdapter();
     DBTool.View_SanPhamImageDataTable dt = new DBTool.View_SanPhamImageDataTable();
     adt.Connection.ConnectionString = QT.Entities.Server.ConnectionString;
     if (adt.Connection.State == ConnectionState.Closed)
     {
         adt.Connection.Open();
     }
     adt.FillBy_SanPhamChuaKiemTra(dt);
     DowloadImageV2(dt);
     dt.Dispose();
     adt.Dispose();
 }
Ejemplo n.º 3
0
        void doDowload(Object id)
        {
            DBToolTableAdapters.View_SanPhamImageTableAdapter adt = new DBToolTableAdapters.View_SanPhamImageTableAdapter();
            DBTool.View_SanPhamImageDataTable dt = new DBTool.View_SanPhamImageDataTable();
            adt.Connection.ConnectionString = QT.Entities.Server.ConnectionString;
            if (adt.Connection.State == ConnectionState.Closed)
            {
                adt.Connection.Open();
            }
            long idCompany           = 0;
            bool isdownloadImageNhap = false;

            this.Invoke((MethodInvoker) delegate
            {
                this.laMess1.Text   = String.Format("Start download data");
                idCompany           = QT.Entities.Common.Obj2Int64(id);
                isdownloadImageNhap = chkImageAdmin.Checked;
            });
            switch (cboCommand.SelectedIndex)
            {
            case 0:     //Current Not Valid
                adt.FillBy_ChuaKiemTraTheoCongTy(dt, idCompany);
                break;

            case 1:     //Current All
                adt.FillBy_AllByCompany(dt, idCompany);
                break;

            case 2:     //All Check not valid
                adt.FillBy_ChuaKiemTraTheoCongTy(dt, idCompany);
                //DBTool.View_SanPhamImageDataTable dt1 = new DBTool.View_SanPhamImageDataTable();
                //foreach (DBTool.CompanyRow dr in this.dBTool.Company)
                //{
                //    if (dr.CheckD == true)
                //    {
                //        this.Invoke((MethodInvoker)delegate
                //        {
                //            this.laMess1.Text = String.Format("start download {0}", dr.Domain);
                //        });
                //        adt.FillBy_ChuaKiemTraTheoCongTy(dt1, dr.ID);
                //        dt.Merge(dt1);
                //    }
                //}
                //dt.AcceptChanges();
                break;

            case 3:     //All Check
                adt.FillBy_AllByCompany(dt, idCompany);
                //DBTool.View_SanPhamImageDataTable dt2 = new DBTool.View_SanPhamImageDataTable();
                //foreach (DBTool.CompanyRow dr in this.dBTool.Company)
                //{
                //    if (dr.CheckD == true)
                //    {
                //        this.Invoke((MethodInvoker)delegate
                //        {
                //            this.laMess1.Text = String.Format("start download {0}", dr.Domain);
                //        });
                //        adt.FillBy_AllByCompany(dt2, dr.ID);
                //        dt.Merge(dt2);
                //    }
                //}
                //dt.AcceptChanges();
                break;

            case 4:     //Config ananytic
                DBTool.View_SanPhamImageDataTable dt3 = new DBTool.View_SanPhamImageDataTable();
                this.Invoke((MethodInvoker) delegate
                {
                    this.laMess1.Text = String.Format("start download {0}", "quangtrung.vn");
                });
                if (isdownloadImageNhap)
                {
                    // Update ảnh ở bảng ProductImage sang

                    adt.FillBy_SanPhamGocCoAnhNhap(dt3, QT.Entities.Common.GetIDCompany("quangtrung.vn"));
                }
                else
                {
                    adt.FillBy_SPConfigAnanytic(dt3, QT.Entities.Common.GetIDCompany("quangtrung.vn"));
                }
                dt.Merge(dt3);
                dt.AcceptChanges();
                break;
            }
            this.Invoke((MethodInvoker) delegate
            {
                this.laMess1.Text = String.Format("download finish");
            });
            String path = "";

            path = "D:\\Beta\\img\\";
            path = QT.Entities.Common.FolderImage;
            DBToolTableAdapters.ProductImagePathTableAdapter adtPro = new DBToolTableAdapters.ProductImagePathTableAdapter();
            adtPro.Connection.ConnectionString = QT.Entities.Server.ConnectionString;
            if (adtPro.Connection.State == ConnectionState.Closed)
            {
                adtPro.Connection.Open();
            }

            int count = 0;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                try
                {
                    String url      = dt.Rows[i]["DetailUrl"].ToString();
                    Uri    root     = new Uri(url);
                    String namepath = root.DnsSafeHost.Replace("www.", "").Replace('.', '_');
                    //namepath = Common.UnicodeToKoDauAndGach(namepath.Replace("  ", " ").Replace("  ", " ").Trim());
                    if (cboCommand.SelectedIndex == 4)
                    {
                        namepath = "images";
                    }
                    string ss       = namepath + "\\";
                    string filename = QT.Entities.Common.UnicodeToKoDauAndGach(dt.Rows[i]["Name"].ToString());
                    string tempf    = filename.Replace("-", "");
                    string s3       = tempf.Substring(0, 3);
                    if (s3 == "bin")
                    {
                        s3 = "bin1";
                    }
                    ss += s3 + "\\";
                    if (filename.Length > 100)
                    {
                        filename = filename.Substring(0, 99);
                    }

                    String fullfile = path + ss + filename + ".jpg";

                    if (chkRedownload.Checked == true)
                    {
                        //Bitmap thumbBitmap = null;
                        //try
                        //{
                        //    thumbBitmap = new Bitmap(fullfile);
                        //    string pathsave = ss + filename + ".jpg";
                        //    pathsave = "Store/" + pathsave.Replace('\\', '/');
                        //    adtPro.UpdateQuery(pathsave, thumbBitmap.Width, thumbBitmap.Height, QT.Entities.Common.Obj2Int64(dt.Rows[i]["ID"].ToString()));
                        //}
                        //catch (Exception ex)
                        //{
                        //    this.Invoke((MethodInvoker)delegate
                        //    {
                        //        this.laMess1.Text = String.Format("Error {0}/{1}{2}", i, dt.Rows.Count, ex);
                        //    });
                        //}
                    }
                    else
                    {
                        if (!File.Exists(fullfile))
                        {
                            /// chưa có file --> tải lại dữ liệu
                            int    w = 0, h = 0;
                            string fileSave = QT.Entities.Common.SaveFile(dt.Rows[i]["ImageUrls"].ToString(), path + ss, filename + ".jpg", out w, out h, false);
                            count++;
                            if (fileSave != "")
                            {
                                string pathsave = ss + filename.Replace('\\', '/') + ".jpg";
                                pathsave = "Store/" + pathsave.Replace('\\', '/');
                                adtPro.UpdateQuery(pathsave, w, h, QT.Entities.Common.Obj2Int64(dt.Rows[i]["ID"].ToString()));
                                count++;
                            }
                        }
                        else
                        {
                            if (dt.Rows[i]["ImagePath"].ToString() == "")
                            {
                                Bitmap thumbBitmap = null;
                                try
                                {
                                    thumbBitmap = new Bitmap(fullfile);
                                    string pathsave = ss + filename + ".jpg";
                                    pathsave = "Store/" + pathsave.Replace('\\', '/');
                                    adtPro.UpdateQuery(pathsave, thumbBitmap.Width, thumbBitmap.Height, QT.Entities.Common.Obj2Int64(dt.Rows[i]["ID"].ToString()));
                                }
                                catch (Exception ex)
                                {
                                    this.Invoke((MethodInvoker) delegate
                                    {
                                        this.laMess1.Text = String.Format("Error {0}/{1}{2}", i, dt.Rows.Count, ex);
                                    });
                                }
                            }
                        }
                    }
                    this.Invoke((MethodInvoker) delegate
                    {
                        this.laMess1.Text = String.Format("{0}/{1} download:{2} - {3}\n{4}", i, dt.Rows.Count, count, dt.Rows[i]["Name"].ToString(), dt.Rows[i]["DetailUrl"].ToString());
                    });
                }
                catch (Exception ex)
                {
                    this.Invoke((MethodInvoker) delegate
                    {
                        this.laMess1.Text = String.Format("{0}/{1} download:{2} - {3}\n{4}\n{5}", i, dt.Rows.Count, count, dt.Rows[i]["Name"].ToString(), dt.Rows[i]["DetailUrl"].ToString(), ex.ToString());
                        Thread.Sleep(5000);
                    });
                }
            }
            adtPro.Dispose();
            dt.Clear();
            dt.Dispose();
            adt.Dispose();
        }