示例#1
0
        /// <summary>
        /// 登入 Method
        /// </summary>
        private void LoginMethod()
        {
            if (String.IsNullOrEmpty(txtID.Text.Trim()) || String.IsNullOrEmpty(txtPassword.Password))
            {
                lblMessage.Content = "帳號或密碼不得為空";
            }
            else
            {
                WFTPDbContext db = new WFTPDbContext();
                string account = txtID.Text.Trim();
                string pwd = txtPassword.Password;

                CEmployee user = (from employe in db.Employees
                                  where employe.Account == account && employe.Password == pwd
                                  select employe).FirstOrDefault();

                if (user != null && user.Activity)
                {
                    // 登入成功時儲存登入頁面相關欄位資料
                    Properties.Settings.Default.Id = account;
                    Properties.Settings.Default.RememberId = Convert.ToBoolean(togRememberId.IsChecked);
                    Properties.Settings.Default.Pwd = pwd;
                    Properties.Settings.Default.RememberPwd = Convert.ToBoolean(togRememberPwd.IsChecked);
                    Properties.Settings.Default.Save();
                    int rank = Convert.ToInt32(user.Rank);

                    // 儲存全域需要的帳號資訊
                    GlobalHelper.AdminItem = new AdminItem();
                    GlobalHelper.AdminItem.IsAdmin = (rank > 5) ? true : false; // 管理權限定義
                    GlobalHelper.AdminItem.Rank = rank;
                    GlobalHelper.AdminItem.Activity = user.Activity;
                    GlobalHelper.LoginUserID = account;

                    // 顯示可執行的頁面按鈕
                    Switcher.Switch(Switcher.query);
                    Switcher.main.btnQuery.Visibility = Visibility.Visible;
                    // 使用者管理暫不實做
                    //Switcher.main.btnManage.Visibility = (GlobalHelper.AdminItem.IsAdmin) ? Visibility.Visible : Visibility.Collapsed;
                    Switcher.main.btnManage.Visibility = Visibility.Collapsed;
                    Switcher.main.btnUpload.Visibility = Visibility.Visible;
                    Switcher.main.btnProgress.Visibility = Visibility.Visible;

                    // 更新使用者最後登入日期
                    using (SqlConnection conn = new SqlConnection(DBHelper.GetConnctionString()))
                    {
                        SqlCommand cmd = new SqlCommand("UPDATE [dbo].[Employees] SET [LastLoginDate] = @time WHERE [Account] = @account");
                        cmd.CommandType = CommandType.Text;
                        cmd.Connection = conn;
                        cmd.Parameters.AddWithValue("@time", DateTime.Now);
                        cmd.Parameters.AddWithValue("@account", account);
                        conn.Open();
                        cmd.ExecuteNonQuery();
                    }
                }
                else
                {
                    lblMessage.Content = "帳號或密碼有誤";
                }
            }
        }
示例#2
0
 public static void Delete(int id, string loginUserId)
 {
     WFTPDbContext db = new WFTPDbContext();
     try
     {
         var category = (from categories in db.GetTable<CFileCategory>()
                         where categories.FileCategoryId == id
                         select categories).SingleOrDefault();
         string record = String.Format("FileCategoryId:{0}, ClassName:{1}, ClassNickName:{2}, CreateDate:{3}", category.FileCategoryId, category.ClassName, category.ClassNickName, category.CreateDate);
         DeleteLog.Insert("dbo.FileCategorys", record, loginUserId);
         db.Lv5FileCategorys.DeleteOnSubmit(category);
         db.SubmitChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#3
0
 public static void Delete(int id, string loginUserId)
 {
     WFTPDbContext db = new WFTPDbContext();
     try
     {
         var classify = (from classifies in db.GetTable<CLv1Classify>()
                         where classifies.ClassifyId == id
                         select classifies).SingleOrDefault();
         string record = String.Format("ClassifyId:{0}, ClassName:{1}, NickName:{2}",classify.ClassifyId,classify.ClassName,classify.NickName);
         DeleteLog.Insert("dbo.Lv1Classifications",record,loginUserId);
         db.Lv1Classifications.DeleteOnSubmit(classify);
         db.SubmitChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#4
0
        // Just provide insert for log
        public static void Insert(string tableName, string record, string loginUserId)
        {
            WFTPDbContext db = new WFTPDbContext();

            try
            {
                DeleteLog log = new DeleteLog();
                log.TableName = tableName;
                log.Record = record;
                log.Date = DateTime.Now;
                log.EditUser = loginUserId;
                db.DeleteLogs.InsertOnSubmit(log);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#5
0
 public static void Delete(int lineId, string loginUserId)
 {
     WFTPDbContext db = new WFTPDbContext();
     try
     {
         var line = (from lines in db.GetTable<CLv4Line>()
                     where lines.LineId == lineId
                     select lines).SingleOrDefault();
         string record = String.Format("LineId:{0}, BranchId:{1}, LineName:{2}, LineNickName:{3}, CreateDate:{4}", line.LineId, line.BranchId, line.LineName, line.LineNickName, line.CreateDate);
         DeleteLog.Insert("dbo.Lv4Lines", record, loginUserId);
         db.Lv4Lines.DeleteOnSubmit(line);
         db.SubmitChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#6
0
        public static void InsertOrUpdate(int? lineId, string lineName, string lineNickName, int branchId)
        {
            WFTPDbContext db = new WFTPDbContext();
            if (lineId == null) //Insert
            {
                try
                {
                    CLv4Line line = new CLv4Line();
                    line.LineName = lineName;
                    line.LineNickName = lineNickName;
                    line.CreateDate = DateTime.Now;
                    line.BranchId = branchId;
                    db.Lv4Lines.InsertOnSubmit(line);
                    db.SubmitChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
            else //Update
            {
                try
                {
                    var line = (from lines in db.GetTable<CLv4Line>()
                                where lines.LineId == lineId
                                select lines).SingleOrDefault();
                    if (branchId>0)
                        line.BranchId = branchId;

                    if (!String.IsNullOrEmpty(lineName))
                        line.LineName = lineName;

                    if (!String.IsNullOrEmpty(lineNickName))
                    line.LineNickName = lineNickName;

                    db.SubmitChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
示例#7
0
 private dynamic GetAdvanceFileList(int skipNum, int recordNum)
 {
     WFTPDbContext db = new WFTPDbContext();
     var tmp = db.Lv6Files.Select(x => x);
     foreach (KeyValuePair<string, string> condiction in _searchConditions)
     {
         if (!String.IsNullOrEmpty(condiction.Value))
         {
             switch (condiction.Key)
             {
                 case "FileCategoryId":
                     int value = Int32.TryParse(condiction.Value, out value) ? value : 0;
                     tmp = tmp.Where(x => x.FileCategoryId == value);
                     break;
                 case "LastUploadDateStart":
                     DateTime dateStart = DateTime.TryParse(condiction.Value.ToString(), out dateStart) ? dateStart : DateTime.Now.AddDays(-1);
                     tmp = tmp.Where(x => x.LastUploadDate >= dateStart);
                     break;
                 case "LastUploadDateEnd":
                     DateTime dateEnd = DateTime.TryParse(condiction.Value.ToString(), out dateEnd) ? dateEnd : DateTime.Now;
                     tmp = tmp.Where(x => x.LastUploadDate < dateEnd);
                     break;
                 case "FileName":
                     string fileWord = condiction.Value.ToString();
                     tmp = tmp.Where(x => x.FileName.Contains(fileWord));
                     break;
                 case "LineId":
                     int line = Convert.ToInt32(condiction.Value);
                     tmp = tmp.Where(x => x.LineId == line);
                     break;
                 case "CompanyId":
                     int companyId = Convert.ToInt32(condiction.Value);
                     List<int> branchIds = db.Lv3CustomerBranches.Where(b => b.CompanyId == companyId).Select(br => br.BranchId).ToList();
                     List<int> lineIds = db.Lv4Lines.Where(li => branchIds.Contains(li.BranchId)).Select(y => y.LineId).ToList();
                     tmp = tmp.Where(x => lineIds.Contains(x.LineId));
                     break;
             }
         }
     }
     return tmp.Where(x => x.IsDeleted == false).Select(n => new { Id = n.FileId, Name = n.FileName, NickName = n.FileName, FullPath = n.Path }).Skip(skipNum).Take(recordNum);
 }
示例#8
0
        // Advance:從資料庫取得檔案分類名稱(階層 1)
        private dynamic GetOnlyFileCatalog()
        {
            WFTPDbContext db = new WFTPDbContext();
            var fileCatalogList = from fileCatalog in db.Lv5FileCategorys
                                  orderby fileCatalog.ClassNickName
                                  select new
                                  {
                                      Id = fileCatalog.FileCategoryId,
                                      Name = fileCatalog.ClassName,
                                      NickName = fileCatalog.ClassNickName
                                  };

            return fileCatalogList;
        }
示例#9
0
文件: File.cs 项目: CalvertYang/WFTP
        public static void InsertOrUpdate(int? fileId,int categoryId, int lineId, string originFileName, string fileName, bool? isDelete, string loginUserID, string fileHash)
        {
            WFTPDbContext db = new WFTPDbContext();
            if (fileId == null) //Insert
            {
                try
                {
                    CFile f = new CFile();
                    f.FileCategoryId = categoryId;
                    f.LineId = lineId;
                    f.OriginFileName = originFileName;
                    f.FileName = fileName;
                    f.FileHash = fileHash;
                    f.IsDeleted = false;
                    f.CreateDate = DateTime.Now;
                    f.LastUploadDate = DateTime.Now;
                    f.LastEditUser = loginUserID;
                    f.CreateUser = loginUserID;
                    db.Lv6Files.InsertOnSubmit(f);
                    db.SubmitChanges();
                    f.Path = DBHelper.GenerateFileFullPath(f.FileId);
                    db.SubmitChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
            else //Update
            {
                try
                {
                    var file = (from files in db.GetTable<CFile>()
                                where files.FileId == fileId
                                select files).SingleOrDefault();
                    if (categoryId > 0)
                        file.FileCategoryId = categoryId;

                    if (!String.IsNullOrEmpty(fileName))
                        file.FileName = fileName;

                    if (isDelete.HasValue)
                        file.IsDeleted = (bool)isDelete;

                    file.LastEditUser = loginUserID;
                    file.LastUploadDate = DateTime.Now;

                    if(lineId > 0)
                        file.LineId = lineId;

                    if (!String.IsNullOrEmpty(originFileName))
                        file.OriginFileName = originFileName;

                    file.Path = DBHelper.GenerateFileFullPath(file.FileId);
                    db.SubmitChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
示例#10
0
        // Advance:從資料庫取得所有公司分類
        private dynamic GetCompanyList()
        {
            WFTPDbContext db = new WFTPDbContext();
            var companyList = from customer in db.Lv2Customers
                              orderby customer.CompanyNickName
                              select new
                              {
                                  CompanyId = customer.CompanyId,
                                  CompanyNickName = customer.CompanyNickName,
                                  ClassifyId = customer.ClassifyId
                              };

            return companyList;
        }
示例#11
0
        private dynamic GetLv3Catalog()
        {
            WFTPDbContext db = new WFTPDbContext();

            var lv3Catalog = from branch in db.Lv3CustomerBranches
                             where branch.CompanyId == _catalogLevelId[2]
                             let subCount =
                                 (from line in db.Lv4Lines
                                  where line.BranchId == branch.BranchId
                                  select line).Count()
                             select new
                             {
                                 Id = branch.BranchId,
                                 Name = branch.BranchName,
                                 NickName = branch.BranchNickName,
                                 Counts = subCount
                             };

            return lv3Catalog;
        }
示例#12
0
        private dynamic GetLv2Catalog()
        {
            WFTPDbContext db = new WFTPDbContext();

            var lv2Catalog = from customer in db.Lv2Customers
                             where customer.ClassifyId == _catalogLevelId[1]
                             let subCount =
                                 (from branch in db.Lv3CustomerBranches
                                  where branch.CompanyId == customer.CompanyId
                                  select branch).Count()
                             select new
                             {
                                 Id = customer.CompanyId,
                                 Name = customer.CompanyName,
                                 NickName = customer.CompanyNickName,
                                 Counts = subCount
                             };

            return lv2Catalog;
        }
示例#13
0
        private dynamic GetLv1Catalog()
        {
            WFTPDbContext db = new WFTPDbContext();

            var lv1Catalog = from classify in db.Lv1Classifications
                             let subCount =
                                 (from customer in db.Lv2Customers
                                  where customer.ClassifyId == classify.ClassifyId
                                  select customer).Count()
                             select new
                             {
                                 Id = classify.ClassifyId,
                                 Name = classify.ClassName,
                                 NickName = classify.NickName,
                                 Counts = subCount
                             };

            return lv1Catalog;
        }
示例#14
0
        private dynamic GetFileCatalog()
        {
            WFTPDbContext db = new WFTPDbContext();

            var fileCatalogList = from fileCatalog in db.Lv5FileCategorys
                                  let subCount =
                                      (from file in db.Lv6Files
                                       where file.LineId == _catalogLevelId[4] && file.FileCategoryId == fileCatalog.FileCategoryId
                                       select file).Count()
                                  select new
                                  {
                                      Id = fileCatalog.FileCategoryId,
                                      Name = fileCatalog.ClassName,
                                      NickName = fileCatalog.ClassNickName,
                                      Counts = subCount
                                  };

            return fileCatalogList;
        }
示例#15
0
        /// <summary>
        /// 處理 _catalogLevelId , _catalogLevelName 全域物件
        /// </summary>
        /// <param name="level">更新該階層資料</param>
        /// <param name="condition">所有階層過濾的條件</param>
        private void GetCatalogInfo(int level, string condition)
        {
            WFTPDbContext db = new WFTPDbContext();
            int id = 0;
            string name = "";

            switch (level)
            {
                case 1:
                    var lv1 = from classify in db.Lv1Classifications
                              where classify.NickName == condition
                              select new
                              {
                                  classify.ClassifyId,
                                  classify.ClassName
                              };
                    if (lv1.Count() > 0)
                    {
                        id = lv1.First().ClassifyId;
                        name = lv1.First().ClassName;
                    }
                    else
                    {
                        return;
                    }
                    break;
                case 2:
                    var lv2 = from customer in db.Lv2Customers
                              where customer.CompanyNickName == condition
                                    && customer.ClassifyId == _catalogLevelId[level - 1]
                              select new
                              {
                                  customer.CompanyId,
                                  customer.CompanyName
                              };
                    id = lv2.First().CompanyId;
                    name = lv2.First().CompanyName;
                    break;
                case 3:
                    var lv3 = from branch in db.Lv3CustomerBranches
                              where branch.BranchNickName == condition
                                    && branch.CompanyId == _catalogLevelId[level - 1]
                              select new
                              {
                                  branch.BranchId,
                                  branch.BranchName
                              };
                    id = lv3.First().BranchId;
                    name = lv3.First().BranchName;
                    break;
                case 4:
                    var lv4 = from line in db.Lv4Lines
                              where line.LineNickName == condition
                                    && line.BranchId == _catalogLevelId[level - 1]
                              select new
                              {
                                  line.LineId,
                                  line.LineName
                              };
                    id = lv4.First().LineId;
                    name = lv4.First().LineName;
                    break;
                case 5:
                    var lv5 = from catalog in db.Lv5FileCategorys
                              where catalog.ClassNickName == condition
                              select new
                              {
                                  catalog.FileCategoryId,
                                  catalog.ClassName
                              };
                    id = lv5.First().FileCategoryId;
                    name = lv5.First().ClassName;
                    break;
            }
            _catalogLevelId[level] = id;
            _catalogLevelName[level + 1] = name;
        }
示例#16
0
        public static void Delete(int branchId, string loginUserId)
        {
            WFTPDbContext db = new WFTPDbContext();
               try
               {
               var branch = (from branches in db.GetTable<CLv3CustomerBranch>()
                             where branches.BranchId == branchId
                             select branches).SingleOrDefault();
               string record = String.Format("BranchId:{0}, BranchName:{1}, BranchNickName:{2}, CompanyId:{3}, CreateDate:{4}", branch.BranchId, branch.BranchName, branch.BranchNickName, branch.CompanyId, branch.CreateDate);
               DeleteLog.Insert("dbo.Lv3CustomerBranches", record, loginUserId);

               db.GetTable<CLv3CustomerBranch>().DeleteOnSubmit(branch);
               db.SubmitChanges();
               }
               catch (Exception ex)
               {
               throw ex;
               }
        }
示例#17
0
        public static void InsertOrUpdate(int? branchId, string branchName, string branchNickName, int companyId)
        {
            WFTPDbContext db = new WFTPDbContext();
               if (branchId == null) //Insert
               {
               try
               {
                   CLv3CustomerBranch branch = new CLv3CustomerBranch();
                   branch.BranchName = branchName;
                   branch.BranchNickName = branchNickName;
                   branch.CreateDate = DateTime.Now;
                   branch.CompanyId = companyId;
                   db.Lv3CustomerBranches.InsertOnSubmit(branch);
                   db.SubmitChanges();
               }
               catch (Exception ex)
               {
                   throw ex;
               }

               }
               else //Update
               {
               try
               {
                   var branch = (from branches in db.GetTable<CLv3CustomerBranch>()
                                 where branches.BranchId == branchId
                                 select branches).SingleOrDefault();
                   if (companyId > 0)
                       branch.CompanyId = companyId;

                   if (!String.IsNullOrEmpty(branchName))
                       branch.BranchName = branchName;

                   if (!String.IsNullOrEmpty(branchNickName))
                       branch.BranchNickName = branchNickName;

                   db.SubmitChanges();
               }
               catch (Exception ex)
               {
                   throw ex;
               }
               }
        }
示例#18
0
        /// <summary>
        /// Query:從資料庫取得分類名稱及其子項目數量(階層 1)
        /// </summary>
        /// <returns>Lv1 資料</returns>
        private dynamic GetLv1Catalog()
        {
            WFTPDbContext db = new WFTPDbContext();
            var lv1Catalog = from classify in db.Lv1Classifications
                             orderby classify.NickName
                             select new
                             {
                                 Id = classify.ClassifyId,
                                 Name = classify.ClassName,
                                 NickName = classify.NickName,
                             };

            return lv1Catalog;
        }
示例#19
0
 /// <summary>
 /// 處理 _catalogLevelId , _catalogLevelName 全域物件
 /// </summary>
 /// <param name="level">更新該階層資料</param>
 /// <param name="condition">所有階層過濾的條件</param>
 /// <returns></returns>
 private int GetCatalogInfo(int level, string[] condition)
 {
     WFTPDbContext db = new WFTPDbContext();
     int id = 0;
     int tmpLevel = level;
     string name = "";
     WHEN_DATA_NULL:
     switch (level)
     {
         case 1:
             var lv1 = from classify in db.Lv1Classifications
                       where classify.NickName == condition[0]
                       orderby classify.NickName
                       select new
                       {
                           classify.ClassifyId,
                           classify.ClassName
                       };
             if (lv1.Count() > 0)
             {
                 id = lv1.First().ClassifyId;
                 name = lv1.First().ClassName;
             }
             else
             {
                 level--;
                 goto WHEN_DATA_NULL;
             }
             break;
         case 2:
             var lv2 = from customer in db.Lv2Customers
                       where customer.CompanyNickName == condition[1]
                             && customer.ClassifyId == _catalogLevelId[level - 1]
                       orderby customer.CompanyNickName
                       select new
                       {
                           customer.CompanyId,
                           customer.CompanyName
                       };
             if (lv2.Count() > 0)
             {
                 id = lv2.First().CompanyId;
                 name = lv2.First().CompanyName;
             }
             else
             {
                 level--;
                 goto WHEN_DATA_NULL;
             }
             break;
         case 3:
             var lv3 = from branch in db.Lv3CustomerBranches
                       where branch.BranchNickName == condition[2]
                             && branch.CompanyId == _catalogLevelId[level - 1]
                       orderby branch.BranchNickName
                       select new
                       {
                           branch.BranchId,
                           branch.BranchName
                       };
             if (lv3.Count() > 0)
             {
                 id = lv3.First().BranchId;
                 name = lv3.First().BranchName;
             }
             else
             {
                 level--;
                 goto WHEN_DATA_NULL;
             }
             break;
         case 4:
             var lv4 = from line in db.Lv4Lines
                       where line.LineNickName == condition[3]
                             && line.BranchId == _catalogLevelId[level - 1]
                       orderby line.LineNickName
                       select new
                       {
                           line.LineId,
                           line.LineName
                       };
             if (lv4.Count() > 0)
             {
                 id = lv4.First().LineId;
                 name = lv4.First().LineName;
             }
             else
             {
                 level--;
                 goto WHEN_DATA_NULL;
             }
             break;
         case 5:
             var lv5 = from catalog in db.Lv5FileCategorys
                       where catalog.ClassNickName == condition[4]
                       orderby catalog.ClassNickName
                       select new
                       {
                           catalog.FileCategoryId,
                           catalog.ClassName
                       };
             if (lv5.Count() > 0)
             {
                 id = lv5.First().FileCategoryId;
                 name = lv5.First().ClassName;
             }
             else
             {
                 level--;
                 goto WHEN_DATA_NULL;
             }
             break;
     }
     _catalogLevelId[level] = id;
     _catalogLevelName[level+1] = name;
     if ((tmpLevel - level) > 0)
     {
         MessageBox.Show("警告:該目錄已被刪除或不存在.");
     }
     return level;
 }
示例#20
0
        /// <summary>
        /// Query:從資料庫取得分類名稱及其子項目數量(階層 3)
        /// </summary>
        /// <returns>Lv3 資料</returns>
        private dynamic GetLv3Catalog()
        {
            WFTPDbContext db = new WFTPDbContext();
            var lv3Catalog = from branch in db.Lv3CustomerBranches
                             where branch.CompanyId == _catalogLevelId[2]
                             orderby branch.BranchNickName
                             select new
                             {
                                 Id = branch.BranchId,
                                 Name = branch.BranchName,
                                 NickName = branch.BranchNickName,
                             };

            return lv3Catalog;
        }
示例#21
0
 /// <summary>
 /// Query:從資料庫取得分類名稱及其子項目數量(階層 6)
 /// </summary>
 /// <returns>Lv6 資料</returns>
 private dynamic GetFileList()
 {
     WFTPDbContext db = new WFTPDbContext();
     var fileList = from file in db.Lv6Files
                    where file.LineId == _catalogLevelId[4] && file.FileCategoryId == _catalogLevelId[5] && file.IsDeleted == false
                    orderby file.FileName
                    select new
                    {
                        Id = file.FileId,
                        Name = file.FileName,
                        NickName = file.FileName
                    };
     return fileList;
 }
示例#22
0
文件: File.cs 项目: CalvertYang/WFTP
 public static void Delete(int fileId, string loginUserId)
 {
     WFTPDbContext db = new WFTPDbContext();
     try
     {
         var file = (from files in db.GetTable<CFile>()
                     where files.FileId == fileId
                     select files).SingleOrDefault();
         string record = String.Format("FileId:{0}, LineId:{1}, FileName:{2}, FileHash:{3}, Path:{4}, CreateDate:{5}", file.FileId, file.LineId, file.FileName, file.FileHash, file.Path, file.CreateDate);
         DeleteLog.Insert("dbo.Files", record, loginUserId);
         db.Lv6Files.DeleteOnSubmit(file);
         db.SubmitChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#23
0
        /// <summary>
        /// Query:從資料庫取得分類名稱及其子項目數量(階層 2)
        /// </summary>
        /// <returns>Lv2 資料</returns>
        private dynamic GetLv2Catalog()
        {
            WFTPDbContext db = new WFTPDbContext();

            var lv2Catalog = from customer in db.Lv2Customers
                             where customer.ClassifyId == _catalogLevelId[1]
                             orderby customer.CompanyNickName
                             select new
                             {
                                 Id = customer.CompanyId,
                                 Name = customer.CompanyName,
                                 NickName = customer.CompanyNickName,
                             };

            return lv2Catalog;
        }
示例#24
0
        private void GetSystemConfig()
        {
            WFTPDbContext db = new WFTPDbContext();

            SystemConfig config = (from conf in db.SystemConfigs select conf).FirstOrDefault();
            GlobalHelper.ApiKey = config.ApiKey;
            GlobalHelper.ApiHost = config.ApiHost;
            GlobalHelper.ApiPort = config.ApiPort;
            GlobalHelper.ComponentCode = config.FtpComponentCode;
            GlobalHelper.FtpHost = config.FtpHost;
            GlobalHelper.FtpUsername = config.FtpUsername;
            GlobalHelper.FtpPasswrod = config.FtpPassword;

            GlobalHelper.SetApiPath();
        }
示例#25
0
        //
        /// <summary>
        /// Query:從資料庫取得分類名稱及其子項目數量(階層 4)
        /// </summary>
        /// <returns>Lv4 資料</returns>
        private dynamic GetLv4Catalog()
        {
            WFTPDbContext db = new WFTPDbContext();

            var lv4Catalog = from line in db.Lv4Lines
                             where line.BranchId == _catalogLevelId[3]
                             let subCount =
                                 (from fileCatalog in db.Lv5FileCategorys
                                  select fileCatalog).Count()
                             orderby line.LineNickName
                             select new
                             {
                                 Id = line.LineId,
                                 Name = line.LineName,
                                 NickName = line.LineNickName,
                                 Counts = subCount
                             };

            return lv4Catalog;
        }
示例#26
0
        public void UpdateProgressList(string type, string remoteFilePath, string localFilePath, string fileHash="")
        {
            // Create fileId
            string fileId = String.Format("{0}_{1}",
                type, Guid.NewGuid().ToString().Replace("-", String.Empty));

            // Get remote file size
            ApiHelper api = new ApiHelper();
            long fileSize = 0;
            if (type.Equals("Download"))
            {
                fileSize = api.GetFileSize(remoteFilePath);
            }
            else
            {
                fileSize = new FileInfo(localFilePath).Length;
            }

            // Prepare CFile Object
            CFile dbFile = new CFile();
            dbFile.FileHash = fileHash;
            dbFile.OriginFileName = remoteFilePath.Substring(remoteFilePath.LastIndexOf('/') + 1).Replace(GlobalHelper.TempUploadFileExt,"");

            // Read progress list
            List<ProgressInfo> progressList = JsonConvert.DeserializeObject<List<ProgressInfo>>(
                File.ReadAllText(GlobalHelper.ProgressList)).Select(c => (ProgressInfo)c).ToList();

            // Check file is duplicated
            if (type.Equals("Download"))
            {
                if (File.Exists(localFilePath) || File.Exists(localFilePath + GlobalHelper.TempDownloadFileExt))
                {
                    int i = 1;
                    string filePathWithoutExt = String.Format(@"{0}\{1}",
                        System.IO.Path.GetDirectoryName(localFilePath),
                        System.IO.Path.GetFileNameWithoutExtension(localFilePath));
                    string filePathExt = System.IO.Path.GetExtension(localFilePath);

                    while (true)
                    {
                        localFilePath = String.Format("{0} ({1}){2}",
                            filePathWithoutExt,
                            i,
                            filePathExt);
                        if (File.Exists(localFilePath) || File.Exists(localFilePath + GlobalHelper.TempDownloadFileExt))
                        {
                            i++;
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    localFilePath += GlobalHelper.TempDownloadFileExt;
                }
            }
            else
            {
                string[] splitPath = remoteFilePath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                // 命名規則:公司名稱_產線編號_檔案分類編號_時間戳記.副檔名
                WFTPDbContext db = new WFTPDbContext();
                var info =
                    (from classify in db.Lv1Classifications
                    from customer in db.Lv2Customers
                    from branch in db.Lv3CustomerBranches
                    from line in db.Lv4Lines
                    from category in db.Lv5FileCategorys
                    where classify.ClassName == splitPath[0] &&
                          customer.CompanyName == splitPath[1] && customer.ClassifyId == classify.ClassifyId &&
                          branch.BranchName == splitPath[2] && branch.CompanyId == customer.CompanyId &&
                          line.LineName == splitPath[3] && line.BranchId == branch.BranchId &&
                          category.ClassName == splitPath[4]
                    select new
                    {
                        CompanyName = customer.CompanyName,
                        LineId = line.LineId,
                        CategoryId = category.FileCategoryId
                    }).First();

                remoteFilePath = String.Format("{0}/{1}_{2}_{3}_{4}{5}{6}",
                    remoteFilePath.Substring(0, remoteFilePath.LastIndexOf('/')),
                    info.CompanyName,
                    info.LineId.ToString(),
                    info.CategoryId.ToString(),
                    System.DateTime.Now.ToString("yyyyMMddHHmmssffff"),
                    System.IO.Path.GetExtension(remoteFilePath),
                    GlobalHelper.TempUploadFileExt);

                // Fill complete CFile value
                dbFile.FileCategoryId = info.CategoryId;
                dbFile.FileName = remoteFilePath.Substring(remoteFilePath.LastIndexOf('/') + 1).Replace(GlobalHelper.TempUploadFileExt, "");
                dbFile.LineId = info.LineId;
                dbFile.Path = remoteFilePath.Replace(GlobalHelper.TempUploadFileExt, "");

            }

            // Create new progress info
            ProgressInfo progressInfo = new ProgressInfo()
            {
                Type = type,
                RemoteFilePath = remoteFilePath,
                LocalFilePath = localFilePath,
                FileSize = fileSize,
                FileId = fileId
            };

            progressList.Add(progressInfo);

            // Serialize progress list to json format
            string jsonList = JsonConvert.SerializeObject(progressList, Formatting.Indented);

            // Overwrite progress list
            File.WriteAllText(GlobalHelper.ProgressList, jsonList, Encoding.UTF8);

            if (type.Equals("Download"))
            {
                // Add file to download list
                Switcher.progress._dataDownloadFiles.Add(new FileProgressItem
                {
                    Name = System.IO.Path.GetFileName(localFilePath).Replace(GlobalHelper.TempDownloadFileExt, String.Empty),
                    Progress = 0,
                    FileId = fileId
                });

                // Download file from FTP server
                Dictionary<string, string> fileInfo = new Dictionary<string, string>();
                fileInfo.Add("FileId", fileId);
                fileInfo.Add("RemoteFilePath", remoteFilePath);
                fileInfo.Add("LocalFilePath", System.IO.Path.GetDirectoryName(localFilePath));
                fileInfo.Add("LocalFileName", System.IO.Path.GetFileName(localFilePath));
                fileInfo.Add("RemoteFileSize", Convert.ToString(fileSize));

                StartDownload(fileInfo);
            }
            else
            {
                // Add file to upload list
                Switcher.progress._dataUploadFiles.Add(new FileProgressItem
                {
                    Name = System.IO.Path.GetFileName(localFilePath).Replace(GlobalHelper.TempUploadFileExt, String.Empty),
                    Progress = 0,
                    FileId = fileId
                });

                // Upload file to FTP server
                Dictionary<string, string> fileInfo = new Dictionary<string, string>();
                fileInfo.Add("FileId", fileId);
                fileInfo.Add("RemoteFilePath", remoteFilePath);
                fileInfo.Add("LocalFilePath", localFilePath);
                //fileInfo.Add("LocalFileName", System.IO.Path.GetFileName(localFilePath));
                fileInfo.Add("LocalFileSize", Convert.ToString(fileSize));
                fileInfo.Add("ModelCreateUser", dbFile.CreateUser);
                fileInfo.Add("ModelFileCategoryId", dbFile.FileCategoryId.ToString());
                fileInfo.Add("ModelFileHash", dbFile.FileHash);
                fileInfo.Add("ModelFileName", dbFile.FileName);
                fileInfo.Add("ModelLastEditUser", dbFile.LastEditUser);
                fileInfo.Add("ModelLineId", dbFile.LineId.ToString());
                fileInfo.Add("ModelOriginFileName", dbFile.OriginFileName);
                fileInfo.Add("ModelPath", dbFile.Path);

                StartUpload(fileInfo);
            }
        }
示例#27
0
        /// <summary>
        /// Query:效能改善: 延遲載入
        /// </summary>
        /// <param name="level">選擇到的層級才載入</param>
        public void GetBreadcrumbBarPath(int level)
        {
            WFTPDbContext db = new WFTPDbContext();

            // Get remote folder list
            ApiHelper api = new ApiHelper();
            List<string> remoteFolderList = api.Dir(_ftpPath, true).ToList();

            switch (level)
            {
                case 2:
                    var lv2 = from company in db.Lv2Customers
                              where company.ClassifyId == _catalogLevelId[1]
                              orderby company.CompanyNickName
                              select company;
                    string expr = String.Format("/bc/bc[@id={0}]", _catalogLevelId[1]);
                    XmlNode xndClassify = _xdoc.SelectSingleNode(expr);
                    if (xndClassify.ChildNodes.Count > 0)
                    {
                        XPathNavigator navigator = _xdoc.CreateNavigator();
                        XPathNavigator first = navigator.SelectSingleNode(expr + "/bc[1]");
                        XPathNavigator last = navigator.SelectSingleNode(expr + "/bc[last()]");
                        navigator.MoveTo(first);
                        navigator.DeleteRange(last);
                    }
                    foreach (var company in lv2)
                    {
                        if (!remoteFolderList.Contains(company.CompanyName)) continue;
                        XmlElement xelCompany = _xdoc.CreateElement("bc");
                        xelCompany.SetAttribute("title", company.CompanyNickName);
                        xelCompany.SetAttribute("id", company.CompanyId.ToString());
                        xndClassify.AppendChild(xelCompany);
                    }
                    break;
                case 3:
                    var lv3 = from branch in db.Lv3CustomerBranches
                              where branch.CompanyId == _catalogLevelId[2]
                              orderby branch.BranchNickName
                              select branch;
                    expr = String.Format("/bc/bc[@id={0}]/bc[@id={1}]", _catalogLevelId[1], _catalogLevelId[2]);
                    XmlNode xndCompany = _xdoc.SelectSingleNode(expr);
                    if (xndCompany.ChildNodes.Count > 0)
                    {
                        XPathNavigator navigator = _xdoc.CreateNavigator();
                        XPathNavigator first = navigator.SelectSingleNode(expr + "/bc[1]");
                        XPathNavigator last = navigator.SelectSingleNode(expr + "/bc[last()]");
                        navigator.MoveTo(first);
                        navigator.DeleteRange(last);
                    }
                    foreach (var branch in lv3)
                    {
                        if (!remoteFolderList.Contains(branch.BranchName)) continue;
                        XmlElement xelBranch = _xdoc.CreateElement("bc");
                        xelBranch.SetAttribute("title", branch.BranchNickName);
                        xelBranch.SetAttribute("id", branch.BranchId.ToString());
                        xndCompany.AppendChild(xelBranch);
                    }
                    break;
                case 4:
                    var lv4 = from line in db.Lv4Lines
                              where line.BranchId == _catalogLevelId[3]
                              orderby line.LineNickName
                              select line;
                    expr = String.Format("/bc/bc[@id={0}]/bc[@id={1}]/bc[@id={2}]", _catalogLevelId[1], _catalogLevelId[2], _catalogLevelId[3]);
                    XmlNode xndBranch = _xdoc.SelectSingleNode(expr);
                    if (xndBranch.ChildNodes.Count > 0)
                    {
                        XPathNavigator navigator = _xdoc.CreateNavigator();
                        XPathNavigator first = navigator.SelectSingleNode(expr + "/bc[1]");
                        XPathNavigator last = navigator.SelectSingleNode(expr + "/bc[last()]");
                        navigator.MoveTo(first);
                        navigator.DeleteRange(last);
                    }
                    foreach (var line in lv4)
                    {
                        if (!remoteFolderList.Contains(line.LineName)) continue;
                        XmlElement xelLine = _xdoc.CreateElement("bc");
                        xelLine.SetAttribute("title", line.LineNickName);
                        xelLine.SetAttribute("id", line.LineId.ToString());
                        xndBranch.AppendChild(xelLine);
                    }
                    break;
                case 5:
                    var lv5 = from category in db.Lv5FileCategorys
                              orderby category.ClassNickName
                              select category;
                    expr = String.Format("/bc/bc[@id={0}]/bc[@id={1}]/bc[@id={2}]/bc[@id={3}]", _catalogLevelId[1], _catalogLevelId[2], _catalogLevelId[3], _catalogLevelId[4]);
                    XmlNode xndLine = _xdoc.SelectSingleNode(expr);
                    if (xndLine.ChildNodes.Count > 0)
                    {
                        // nothing.
                    }
                    else
                    {
                        foreach (var category in lv5)
                        {
                            XmlElement xelCategory = _xdoc.CreateElement("bc");
                            xelCategory.SetAttribute("title", category.ClassNickName);
                            xelCategory.SetAttribute("id", category.FileCategoryId.ToString());
                            xndLine.AppendChild(xelCategory);
                        }
                    }
                    break;
            }
        }
示例#28
0
        public static void Delete(int eid, string loginUserId)
        {
            WFTPDbContext db = new WFTPDbContext();
            try
            {
                var empolyee = (from e in db.GetTable<CEmployee>()
                                where e.EId == eid
                                select e).SingleOrDefault();

                string record = String.Format("EId:{0}, Account:{1}, Email:{2}, LastLoginDate:{3}, Name:{4}, Password:{5}, Rank:{6}, RecvNotify:{7}", empolyee.EId, empolyee.Account, empolyee.Activity, empolyee.Email, empolyee.LastLoginDate, empolyee.Name, empolyee.Password, empolyee.Rank, empolyee.RecvNotify);
                DeleteLog.Insert("dbo.Files", record, loginUserId);
                db.Employees.DeleteOnSubmit(empolyee);
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#29
0
        /// <summary>
        /// Query:改善效能第一次載入只讀取第一層
        /// </summary>
        private void GetBreadcrumbBarPath()
        {
            // Combination Datasource of Folder secheme
            // Initialize root
            _xdoc = new XmlDocument();
            XmlNode root = _xdoc.CreateElement("bc");
            XmlAttribute xmlns = _xdoc.CreateAttribute("xmlns");
            xmlns.Value = "";
            XmlAttribute t = _xdoc.CreateAttribute("title");
            t.Value = "分類";
            root.Attributes.Append(xmlns);
            root.Attributes.Append(t);
            _xdoc.AppendChild(root);

            // Append child node
            WFTPDbContext db = new WFTPDbContext();
            // Lv1 must load
            var lv1 = from classify in db.Lv1Classifications
                      orderby classify.NickName
                      select classify;

            foreach (var cls in lv1)
            {
                XmlElement xelClassify = _xdoc.CreateElement("bc");
                xelClassify.SetAttribute("title", cls.NickName);
                xelClassify.SetAttribute("id", cls.ClassifyId.ToString());
                root.AppendChild(xelClassify);
            }

            // edit static provider
            XmlDataProvider dataFolders = this.FindResource("dataProvider") as XmlDataProvider;
            dataFolders.Document = _xdoc;
        }
示例#30
0
        public static void InsertOrUpdate(int? eId, string account, string pwd, DateTime createDate, DateTime LastLoginDate, string rank, string name, string email, bool? recvNotify, bool? activity)
        {
            WFTPDbContext db = new WFTPDbContext();
            if (eId == null) //Insert
            {
                try
                {
                    CEmployee e = new CEmployee();
                    e.Account = account;
                    e.Activity = (bool)activity;
                    e.Email = email;
                    e.CreateDate = createDate;
                    e.Name = name;
                    e.Password = pwd;
                    e.Rank = rank;
                    e.RecvNotify = (bool)recvNotify;

                    db.Employees.InsertOnSubmit(e);
                    db.SubmitChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }

            }
            else //Update
            {
                try
                {
                    var empolyee = (from e in db.GetTable<CEmployee>()
                                where e.EId == eId
                                select e).SingleOrDefault();
                    if (!String.IsNullOrEmpty(account))
                        empolyee.Account = account;

                    if (!String.IsNullOrEmpty(pwd))
                        empolyee.Password = pwd;

                    if (!String.IsNullOrEmpty(rank))
                        empolyee.Rank = rank;

                    if (!String.IsNullOrEmpty(name))
                        empolyee.Name = name;

                    if (!String.IsNullOrEmpty(email))
                        empolyee.Email = email;

                    if (!String.IsNullOrEmpty(rank))
                        empolyee.Rank = rank;

                    if (!String.IsNullOrEmpty(rank))
                        empolyee.Rank = rank;

                    empolyee.LastLoginDate = DateTime.Now;

                    if (recvNotify.HasValue)
                        empolyee.RecvNotify = (bool)recvNotify;

                    if (activity.HasValue)
                        empolyee.Activity = (bool)activity;

                    db.SubmitChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }