static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SplashScreen splash = new SplashScreen(); Task dbInitializerTask = new Task(() => { try { ToggleConnectionStringProtection(System.Windows.Forms.Application.ExecutablePath, false); EFERTDbUtility.InitializeDatabases(); splash.Invoke(new Action(() => { splash.Close(); })); } catch (Exception) { throw; } }); dbInitializerTask.Start(); splash.ShowDialog(); Application.Run(new LoginForm()); }
private void btnGenerate_Click(object sender, EventArgs e) { this.mLstCardHolders = new Dictionary <string, List <CardHolderReportInfo> >(); var lstCheckedInChls = (from checkIn in EFERTDbUtility.mEFERTDb.CheckedInInfos where checkIn != null select new { CardHolderId = checkIn.CardHolderId, DailyCardHolderId = checkIn.DailyCardHolderId, VisitorId = checkIn.VisitorId }).Distinct().ToList(); List <int> cardHolderIds = (from checkedInChl in lstCheckedInChls where checkedInChl != null && checkedInChl.CardHolderId != null select Convert.ToInt32(checkedInChl.CardHolderId)).ToList(); List <int> dailyCardHolderIds = (from checkedInChl in lstCheckedInChls where checkedInChl != null && checkedInChl.DailyCardHolderId != null select Convert.ToInt32(checkedInChl.DailyCardHolderId)).ToList(); List <int> visitorIds = (from checkedInChl in lstCheckedInChls where checkedInChl != null && checkedInChl.DailyCardHolderId != null select Convert.ToInt32(checkedInChl.DailyCardHolderId)).ToList(); List <EFERTDb.CardHolderInfo> chls = (from chl in EFERTDbUtility.mEFERTDb.CardHolders where chl != null && cardHolderIds.Contains(chl.CardHolderId) select chl).ToList(); List <DailyCardHolder> dailyChls = (from dailychl in EFERTDbUtility.mEFERTDb.DailyCardHolders where dailychl != null && dailyCardHolderIds.Contains(dailychl.DailyCardHolderId) select dailychl).ToList(); List <VisitorCardHolder> visitorChls = (from visitor in EFERTDbUtility.mEFERTDb.Visitors where visitor != null && visitorIds.Contains(visitor.VisitorId) select visitor).ToList(); foreach (EFERTDb.CardHolderInfo cardHolder in chls) { int daysCount = 0; LimitStatus limitStatus = EFERTDbUtility.CheckIfUserCheckedInLimitReached(cardHolder.CheckInInfos, cardHolder.BlockingInfos, ref daysCount, false); if (limitStatus == LimitStatus.LimitReached || limitStatus == LimitStatus.EmailAlerted) { string category = cardHolder.ConstractorInfo; category = string.IsNullOrEmpty(category) ? "Unknown" : category; string firstName = cardHolder.FirstName; string cnicNumber = cardHolder.CNICNumber; string companyName = cardHolder.Company.CompanyName; string blockedStatus = limitStatus == LimitStatus.LimitReached? "Blocked" : "Alarmed"; if (this.mLstCardHolders.ContainsKey(category)) { this.mLstCardHolders[category].Add(new CardHolderReportInfo() { FirstName = firstName, CNICNumber = cnicNumber, BlockedStatus = blockedStatus, Category = category, Company = companyName, TotalDaysCkekin = daysCount }); } else { List <CardHolderReportInfo> lstChls = new List <CardHolderReportInfo>(); lstChls.Add(new CardHolderReportInfo() { FirstName = firstName, CNICNumber = cnicNumber, BlockedStatus = blockedStatus, Category = category, Company = companyName, TotalDaysCkekin = daysCount }); this.mLstCardHolders.Add(category, lstChls); } } } foreach (EFERTDb.DailyCardHolder dailyCardHolder in dailyChls) { int daysCount = 0; LimitStatus limitStatus = EFERTDbUtility.CheckIfUserCheckedInLimitReached(dailyCardHolder.CheckInInfos, dailyCardHolder.BlockingInfos, ref daysCount, false); if (limitStatus == LimitStatus.LimitReached || limitStatus == LimitStatus.EmailAlerted) { string category = dailyCardHolder.ConstractorInfo; category = string.IsNullOrEmpty(category) ? "Unknown" : category; string firstName = dailyCardHolder.FirstName; string cnicNumber = dailyCardHolder.CNICNumber; string companyName = dailyCardHolder.CompanyName; string blockedStatus = limitStatus == LimitStatus.LimitReached ? "Blocked" : "Alarmed"; if (this.mLstCardHolders.ContainsKey(category)) { this.mLstCardHolders[category].Add(new CardHolderReportInfo() { FirstName = firstName, CNICNumber = cnicNumber, BlockedStatus = blockedStatus, Category = category, Company = companyName, TotalDaysCkekin = daysCount }); } else { List <CardHolderReportInfo> lstChls = new List <CardHolderReportInfo>(); lstChls.Add(new CardHolderReportInfo() { FirstName = firstName, CNICNumber = cnicNumber, BlockedStatus = blockedStatus, Category = category, Company = companyName, TotalDaysCkekin = daysCount }); this.mLstCardHolders.Add(category, lstChls); } } } foreach (EFERTDb.VisitorCardHolder visitor in visitorChls) { int daysCount = 0; LimitStatus limitStatus = EFERTDbUtility.CheckIfUserCheckedInLimitReached(visitor.CheckInInfos, visitor.BlockingInfos, ref daysCount, false); if (limitStatus == LimitStatus.LimitReached || limitStatus == LimitStatus.EmailAlerted) { string category = visitor.VisitorInfo; category = string.IsNullOrEmpty(category) ? "Unknown" : category; string firstName = visitor.FirstName; string cnicNumber = visitor.CNICNumber; string companyName = visitor.CompanyName; string blockedStatus = limitStatus == LimitStatus.LimitReached ? "Blocked" : "Alarmed"; if (this.mLstCardHolders.ContainsKey(category)) { this.mLstCardHolders[category].Add(new CardHolderReportInfo() { FirstName = firstName, CNICNumber = cnicNumber, BlockedStatus = blockedStatus, Category = category, Company = companyName, TotalDaysCkekin = daysCount }); } else { List <CardHolderReportInfo> lstChls = new List <CardHolderReportInfo>(); lstChls.Add(new CardHolderReportInfo() { FirstName = firstName, CNICNumber = cnicNumber, BlockedStatus = blockedStatus, Category = category, Company = companyName, TotalDaysCkekin = daysCount }); this.mLstCardHolders.Add(category, lstChls); } } } if (this.mLstCardHolders != null && this.mLstCardHolders.Count > 0) { this.saveFileDialog1.ShowDialog(this); } else { MessageBox.Show(this, "No data exist on current selected date range."); } }