Exemplo n.º 1
0
        private void InitEvent()
        {
            LawDownloader instance = Singleton_LawDownloader.GetInstance();

            Start_callback      = (LawListCT_DownloadFileStart_Function)Delegate.Combine(Start_callback, new LawListCT_DownloadFileStart_Function(LawListCT_DownloadFileStart_Callback));
            Progress_callback   = (LawListCT_DownloadProgressChanged_Function)Delegate.Combine(Progress_callback, new LawListCT_DownloadProgressChanged_Function(LawListCT_DownloadProgressChanged_Callback));
            Finish_callback     = (LawListCT_DownloadFileCompleted_Function)Delegate.Combine(Finish_callback, new LawListCT_DownloadFileCompleted_Function(LawListCT_DownloadFileCompleted_Callback));
            UnZip_callback      = (LawListCT_UnZip_Function)Delegate.Combine(UnZip_callback, new LawListCT_UnZip_Function(LawListCT_UnZip_Callback));
            UnZipError_callback = (LawListCT_UnZipError_Function)Delegate.Combine(UnZipError_callback, new LawListCT_UnZipError_Function(LawListCT_UnZipError_Callback));
            GetBookVMs_ByMeetingFileCate_callback             = new LawListCT_GetBookVMs_ByMeetingFileCate_Function(LawListCT_GetBookVMs_ByMeetingFileCate_Callback);
            instance.LawListCT_DownloadFileStart_Event       += Start_callback;
            instance.LawListCT_DownloadProgressChanged_Event += Progress_callback;
            instance.LawListCT_DownloadFileCompleted_Event   += Finish_callback;
            instance.LawListCT_UnZip_Event      += UnZip_callback;
            instance.LawListCT_UnZipError_Event += UnZipError_callback;
            txtKeyword.MouseEnter += new MouseEventHandler(_003CInitEvent_003Eb__15);
            TextBox textBox = txtKeyword;

            if (CS_0024_003C_003E9__CachedAnonymousMethodDelegate17 == null)
            {
                CS_0024_003C_003E9__CachedAnonymousMethodDelegate17 = new MouseEventHandler(_003CInitEvent_003Eb__16);
            }
            textBox.MouseLeave += CS_0024_003C_003E9__CachedAnonymousMethodDelegate17;
            txtKeyword.KeyUp   += new KeyEventHandler(txtKeyword_KeyUp);
            txtKeyword.Focus();
        }
Exemplo n.º 2
0
        private void btnDownload_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (lawItem == null)
            {
                return;
            }
            // 記得必須隱藏得先做,才不會被看見
            btnDownload.Visibility = Visibility.Collapsed;

            txtPercent.Text       = "等待中";
            txtPercent.Foreground = Brushes.Gray;
            txtPercent.Visibility = Visibility.Visible;
            pb.Foreground         = Brushes.Wheat;
            pb.Background         = Brushes.Gray;
            pb.Visibility         = Visibility.Visible;


            if (lawItem.StorageFileName.EndsWith(".update"))
            {
                lawItem.FileType = LawFileType.更新檔排入下載中;
            }
            else
            {
                lawItem.FileType = LawFileType.排入下載中;
            }
            LawDownloader lawDownloader = Singleton_LawDownloader.GetInstance();

            lawDownloader.AddItem(lawItem);
        }
Exemplo n.º 3
0
        private void InitEvent()
        {
            LawDownloader lawDownloader = Singleton_LawDownloader.GetInstance();

            Start_callback      += new LawListCT_DownloadFileStart_Function(LawListCT_DownloadFileStart_Callback);
            Progress_callback   += new LawListCT_DownloadProgressChanged_Function(LawListCT_DownloadProgressChanged_Callback);
            Finish_callback     += new LawListCT_DownloadFileCompleted_Function(LawListCT_DownloadFileCompleted_Callback);
            UnZip_callback      += new LawListCT_UnZip_Function(LawListCT_UnZip_Callback);
            UnZipError_callback += new LawListCT_UnZipError_Function(LawListCT_UnZipError_Callback);
            GetBookVMs_ByMeetingFileCate_callback = new LawListCT_GetBookVMs_ByMeetingFileCate_Function(LawListCT_GetBookVMs_ByMeetingFileCate_Callback);

            lawDownloader.LawListCT_DownloadFileStart_Event       += Start_callback;
            lawDownloader.LawListCT_DownloadProgressChanged_Event += Progress_callback;
            lawDownloader.LawListCT_DownloadFileCompleted_Event   += Finish_callback;
            lawDownloader.LawListCT_UnZip_Event      += UnZip_callback;
            lawDownloader.LawListCT_UnZipError_Event += UnZipError_callback;

            txtKeyword.MouseEnter += (sender, e) => { MouseTool.ShowIBeam(); txtKeyword.Focus(); };
            txtKeyword.MouseLeave += (sender, e) => { MouseTool.ShowArrow(); }; //Keyboard.ClearFocus();
            txtKeyword.KeyUp      += txtKeyword_KeyUp;
            txtKeyword.Focus();
        }
Exemplo n.º 4
0
        private void InitSelectDB()
        {
            DataTable     dataTable = new DataTable();
            LawDownloader instance  = Singleton_LawDownloader.GetInstance();

            lawItem = instance.GetInList(lawDataLaw.ID);
            if (lawItem != null)
            {
                return;
            }
            DateTime dateTime = DateTime.Parse("2010/01/01");
            long     num      = 0L;
            long     num2     = 0L;

            dataTable = MSCE.GetDataTable("SELECT ID,AtDownloadFinished_XmlUpDate,Link,StorageFileName,DownloadBytes,TotalBytes FROM LawRow where ID=@1 and UserID=@2", lawDataLaw.ID, UserID);
            if (dataTable.Rows.Count > 0)
            {
                dataTable.Rows[0]["ID"].ToString();
                dateTime = (DateTime)dataTable.Rows[0]["AtDownloadFinished_XmlUpDate"];
                dataTable.Rows[0]["Link"].ToString();
                dataTable.Rows[0]["StorageFileName"].ToString();
                num  = long.Parse(dataTable.Rows[0]["DownloadBytes"].ToString().Equals("") ? "0" : dataTable.Rows[0]["DownloadBytes"].ToString());
                num2 = long.Parse(dataTable.Rows[0]["TotalBytes"].ToString().Equals("") ? "0" : dataTable.Rows[0]["TotalBytes"].ToString());
            }
            else
            {
                string text = "INSERT INTO LawRow(ID,AtDownloadFinished_XmlUpDate,DownloadBytes,TotalBytes,UserID) \r\n                                                    VALUES(@1,'2010/01/01',0,0,@2)";
                int    num3 = MSCE.ExecuteNonQuery(text, lawDataLaw.ID, UserID);
                if (num3 < 1)
                {
                    LogTool.Debug(new Exception("DB失敗: " + text));
                }
            }
            lawItem        = new Law_DownloadItemViewModel();
            lawItem.ID     = lawDataLaw.ID;
            lawItem.UserID = UserID;
            DateTime result;

            DateTime.TryParse(lawDataLaw.UpDate, out result);
            lawItem.UpDate = result;
            lawItem.Name   = lawDataLaw.Name;
            lawItem.Link   = lawDataLaw.Link;
            lawItem.Status = (LawDataStatus)Enum.Parse(typeof(LawDataStatus), lawDataLaw.Status);
            string baseDirectory         = AppDomain.CurrentDomain.BaseDirectory;
            string law_StorageFileFolder = Settings.Default.Law_StorageFileFolder2;

            lawItem.StorageFileFolder = Path.Combine(baseDirectory, law_StorageFileFolder);
            string arg = DateTime.Now.ToFileTime().ToString();

            try
            {
                Uri    uri      = new Uri(lawItem.Link);
                string fileName = Path.GetFileName(uri.LocalPath);
                if (!fileName.Equals("/"))
                {
                    arg = fileName;
                }
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex);
            }
            lawItem.StorageFileName = string.Format("{0}_{1}_{2}", UserID, lawDataLaw.ID, arg);
            lawItem.UnZipFileFolder = Path.Combine(ClickOnceTool.GetFilePath(), Settings.Default.Law_UnZipFileFolder);
            if (num == 0 || num < num2)
            {
                if (File.Exists(lawItem.StorageFilePath))
                {
                    File.Delete(lawItem.StorageFilePath);
                }
                lawItem.DownloadBytes = 0L;
                lawItem.TotalBytes    = 0L;
                lawItem.FileType      = LawFileType.從未下載;
            }
            else if (TimeSpan.Compare(new TimeSpan(result.Ticks), new TimeSpan(dateTime.Ticks)) > 0)
            {
                lawItem.StorageFileName += ".update";
                lawItem.DownloadBytes    = 0L;
                lawItem.TotalBytes       = 0L;
                lawItem.FileType         = LawFileType.更新檔未下載;
            }
            else
            {
                lawItem.FileType = LawFileType.已下載完成;
            }
        }
Exemplo n.º 5
0
        private void InitSelectDB()
        {
            DataTable dt = new DataTable();

            // 初始化User
            // 效能要好請改用從LawListCT傳入建構子
            //dt = MSCE.GetDataTable("select UserID,UserName,UserPWD from NowLogin");
            //if (dt.Rows.Count > 0)
            //{
            //    UserID = dt.Rows[0]["UserID"].ToString();
            //    UserName = dt.Rows[0]["UserName"].ToString();
            //    UserPWD = dt.Rows[0]["UserPWD"].ToString();
            //}

            //更新檔不支援續傳
            //檢查是否再下載當中
            LawDownloader lawDownloader = Singleton_LawDownloader.GetInstance();

            lawItem = lawDownloader.GetInList(lawDataLaw.ID);
            if (lawItem != null)
            {
                return;
            }

            #region DB
            string   db_LawRowID = "";
            DateTime db_AtDownloadFinished_XmlUpDate = DateTime.Parse("2010/01/01");
            string   db_Link            = "";
            string   db_StorageFileName = "";
            long     db_DownloadBytes   = 0;
            long     db_TotalBytes      = 0;

            dt = MSCE.GetDataTable("SELECT ID,AtDownloadFinished_XmlUpDate,Link,StorageFileName,DownloadBytes,TotalBytes FROM LawRow where ID=@1 and UserID=@2"
                                   , lawDataLaw.ID
                                   , UserID);
            if (dt.Rows.Count > 0)
            {
                db_LawRowID = dt.Rows[0]["ID"].ToString();
                db_AtDownloadFinished_XmlUpDate = (DateTime)dt.Rows[0]["AtDownloadFinished_XmlUpDate"];
                db_Link            = dt.Rows[0]["Link"].ToString();
                db_StorageFileName = dt.Rows[0]["StorageFileName"].ToString();
                db_DownloadBytes   = long.Parse(dt.Rows[0]["DownloadBytes"].ToString().Equals("") ? "0" : dt.Rows[0]["DownloadBytes"].ToString());
                db_TotalBytes      = long.Parse(dt.Rows[0]["TotalBytes"].ToString().Equals("") ? "0" : dt.Rows[0]["TotalBytes"].ToString());
            }
            else
            {
                string SQL     = @"INSERT INTO LawRow(ID,AtDownloadFinished_XmlUpDate,DownloadBytes,TotalBytes,UserID) 
                                                    VALUES(@1,'2010/01/01',0,0,@2)";
                int    success = MSCE.ExecuteNonQuery(SQL
                                                      , lawDataLaw.ID
                                                      , UserID);
                if (success < 1)
                {
                    LogTool.Debug(new Exception(@"DB失敗: " + SQL));
                }
            }
            #endregion

            lawItem        = new Law_DownloadItemViewModel();
            lawItem.ID     = lawDataLaw.ID;
            lawItem.UserID = UserID;
            DateTime lawDataLaw_UpDate;
            DateTime.TryParse(lawDataLaw.UpDate, out lawDataLaw_UpDate);
            lawItem.UpDate = lawDataLaw_UpDate;
            lawItem.Name   = lawDataLaw.Name;
            lawItem.Link   = lawDataLaw.Link;
            lawItem.Status = (LawDataStatus)Enum.Parse(typeof(LawDataStatus), lawDataLaw.Status);

            string AppPath = System.AppDomain.CurrentDomain.BaseDirectory;
            string Law_StorageFileFolder = PaperLess_Emeeting.Properties.Settings.Default.Law_StorageFileFolder2;
            lawItem.StorageFileFolder = System.IO.Path.Combine(AppPath, Law_StorageFileFolder);

            #region 取得 Http URL 的檔名
            string fileName = DateTime.Now.ToFileTime().ToString();
            try
            {
                Uri    uri          = new Uri(lawItem.Link);
                string tempFileName = System.IO.Path.GetFileName(uri.LocalPath);
                if (tempFileName.Equals(@"/") == false)
                {
                    fileName = tempFileName;
                }
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex);
            }
            #endregion

            lawItem.StorageFileName = string.Format("{0}_{1}_{2}", UserID, lawDataLaw.ID, fileName);
            lawItem.UnZipFileFolder = System.IO.Path.Combine(ClickOnceTool.GetFilePath(), PaperLess_Emeeting.Properties.Settings.Default.Law_UnZipFileFolder);

            // 續傳才要用到
            //lawItem.DownloadBytes = db_DownloadBytes;
            //lawItem.TotalBytes = db_DownloadBytes;

            //bool Law_ResumeDownload = false;
            ////不續傳
            //if (Law_ResumeDownload == false)
            //{
            //未下載完成的
            if (db_DownloadBytes == 0 || db_DownloadBytes < db_TotalBytes)
            {
                //刪除未下載完成的
                if (File.Exists(lawItem.StorageFilePath) == true)
                {
                    File.Delete(lawItem.StorageFilePath);
                }

                lawItem.DownloadBytes = 0;
                lawItem.TotalBytes    = 0;
                lawItem.FileType      = LawFileType.從未下載;
            }
            else     //有下載完成的
            {
                //先判斷是否有更新檔
                //需要更新檔案,UpdDate 日期比較新
                if (TimeSpan.Compare(new TimeSpan(lawDataLaw_UpDate.Ticks), new TimeSpan(db_AtDownloadFinished_XmlUpDate.Ticks)) > 0)
                {
                    lawItem.StorageFileName = lawItem.StorageFileName + ".update";
                    lawItem.DownloadBytes   = 0;
                    lawItem.TotalBytes      = 0;
                    lawItem.FileType        = LawFileType.更新檔未下載;
                }
                else     //不需更新檔案
                {
                    lawItem.FileType = LawFileType.已下載完成;
                    //結束;
                }
            }

            //}
            //else //續傳
            //{
            //    //目前不支援
            //}
        }