Guest User

Untitled

a guest
Jul 16th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Web;
  7. using System.Web.UI.WebControls;
  8.  
  9. using NCM2.Core.Utilities;
  10. using NCM2.Component.Member.Web.Downloads;
  11.  
  12. namespace NCM2.Web.MemberSite
  13. {
  14.     public class PTAProductPageHelper
  15.     {
  16.         public static bool VerifyWebPTAExists(string memberGroupNumber, string memberNumber, string memberZipcode)
  17.         {
  18.             return GetWebPTAFiles(memberGroupNumber, memberNumber, memberZipcode).Count > 0;
  19.         }
  20.  
  21.         public static ICollection<string> GetWebPTAFiles(string memberGroupNumber, string memberNumber, string memberZipCode)
  22.         {
  23. #if DEBUG
  24.             string _path = @"c:\ncmsecure";
  25. #else
  26.             string _path = NCMDirectory.GetPath("WEBCOMPOSITE");
  27. #endif      
  28.             string FileDirectory = _path + "\\WebPTA";
  29.             string searchString = memberGroupNumber + memberNumber + memberZipCode.Substring(0, 3);
  30.             if (System.IO.Directory.Exists(FileDirectory))
  31.             {
  32.                 string[] files = System.IO.Directory.GetFiles(FileDirectory);
  33.                 var memberFiles = from x in files
  34.                                   where x.Substring(FileDirectory.Length + 1, 9) == searchString
  35.                                   select x;
  36.                 return new List<string>(memberFiles);
  37.             }
  38.             else
  39.             {
  40.                 return new List<string>();
  41.             }
  42.         }
  43.  
  44.         public static bool TryGetPickListForPTADashboard(out ICollection<KeyValuePair<string, string>> pickList)
  45.         {
  46.             SessionManager session = SessionManager.GetSessionManager();
  47. #if DEBUG
  48.             string path = @"c:\ncmsecure";
  49. #else
  50.             string path = NCMDirectory.GetPath("WEBCOMPOSITE");
  51. #endif
  52.  
  53.             PTADashboardDownloads downloads = new PTADashboardDownloads(path, session.MemberGroupNumber, session.MemberNumber, session.MemberZipCode);
  54.             List<string> fileList = downloads.GetFilesDesc();
  55.             pickList = new List<KeyValuePair<string, string>>();
  56.             foreach (string file in fileList)
  57.             {
  58.                 string displayText;
  59.                 string valueText;
  60.                 DateTime fileDate;
  61.                 string fileName = Path.GetFileName(file);
  62.  
  63.                 valueText = fileName.Substring(18, 4);
  64.                 fileDate = DateTime.Parse(string.Format("{0}/1/{1}", fileName.Substring(18, 2), fileName.Substring(20, 2)));
  65.                 displayText = fileDate.ToString("MMM yyyy");
  66.                 pickList.Add(new KeyValuePair<string, string>(valueText, displayText));
  67.             }
  68.             return pickList.Count > 0;
  69.         }
  70.  
  71.         public static bool TryGetLatestMonthYearForPTADashboard(out string monthYear)
  72.         {
  73.             ICollection<KeyValuePair<string, string>> ptaPickList;
  74.             bool hasValueToReturn = TryGetPickListForPTADashboard(out ptaPickList);
  75.             if (hasValueToReturn)
  76.             {
  77.                 monthYear = ptaPickList.First().Key;
  78.             }
  79.             else
  80.             {
  81.                 monthYear = string.Empty;
  82.             }
  83.             return hasValueToReturn;
  84.         }
  85.     }
  86. }
Add Comment
Please, Sign In to add comment