Exemplo n.º 1
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.º 2
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 //續傳
            //{
            //    //目前不支援
            //}
        }