Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
1
Answer
Link progress bar with value in function during function execution
Rabih Nasr
4y
431
1
Reply
I've Created a class with public function returns a list during execution public int increasing to 100 at the end of function this value for progress bar is increasing during function how to make synchronization between public int in the class and the progress bar in the wpf form at the end I want the sList as result and WeekListsProgress as progressbar vlaue is changing during WeekLists execute
public
class
SchedHandler
{
public
static
List<Subject4Sched> SubSchedList = GetSchedSubList();
public
static
int
WeekSum = SubSchedList.Sum(x => x.WeekCount);
public
static
int
AssignSum = SubSchedList.Sum(x => x.Assigned);
public
static
SchoolEntitiesProFinal ProDb;
public
static
int
WeekListsProgress = 0;
public
static
List<SubWeekCount> GetSubList(
int
semId)
{
ProDb =
new
SchoolEntitiesProFinal();
List<sp_GetSubWeekCountList_Result> subs = ProDb.sp_GetSubWeekCountList(semId).ToList();
return
subs.Select(item =>
new
SubWeekCount(item.subid, item.subject, item.sessioncount)).ToList();
}
public
List<SubWeekCount> SubList = GetSubList(1);
//1- Insert Subjects With 0 Assigned
public
static
void
InsertSubjects(
int
subid,
string
subName,
int
week,
int
ass)
{
var sub =
new
tbl_schedule();
sub.subid = subid;
sub.subname = subName;
sub.weekly = week;
sub.assigned = ass;
try
{
using
(var db =
new
SchoolEntitiesProFinal())
{
db.tbl_schedule.Add(sub);
db.SaveChanges();
}
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public
static
void
UpdtaeSubjects(
int
subid)
{
tbl_schedule sub = ProDb.tbl_schedule.FirstOrDefault(x => x.subid == subid);
try
{
if
(sub !=
null
) sub.assigned = sub.assigned + 1;
ProDb.SaveChanges();
}
catch
(Exception)
{
MessageBox.Show(
"Error With Databse!!!"
);
}
}
public
static
void
RemoveSubjects(
int
subid)
{
tbl_schedule sub = ProDb.tbl_schedule.FirstOrDefault(x => x.subid == subid);
try
{
if
(sub!=
null
)
{
if
(sub.assigned == sub.weekly)
{
ProDb.tbl_schedule.Remove(sub);
ProDb.SaveChanges();
}
}
}
catch
(Exception)
{
MessageBox.Show(
"Error With Databse!!!"
);
}
}
public
static
void
RemoveAllSubjects()
{
List<tbl_schedule> sub = ProDb.tbl_schedule.ToList();
try
{
ProDb.tbl_schedule.RemoveRange(sub);
ProDb.SaveChanges();
}
catch
(Exception)
{
MessageBox.Show(
"Error With Databse!!!"
);
}
}
public
static
int
GetSubAssigned(
int
subid)
{
ProDb =
new
SchoolEntitiesProFinal();
var sub = ProDb.tbl_schedule.FirstOrDefault(x => x.subid == subid);
int
count = 0;
if
(sub !=
null
) count = sub.assigned;
return
count;
}
public
static
List<Subject4Sched> GetSchedSubList()
{
ProDb =
new
SchoolEntitiesProFinal();
var subs = ProDb.tbl_schedule.ToList();
return
subs.Select(item =>
new
Subject4Sched(item.subid, item.subname, item.weekly, item.assigned)).ToList();
}
public
static
Subject4Sched GetSub()
{
ProDb =
new
SchoolEntitiesProFinal();
var f = ProDb.tbl_schedule.First();
var sub =
new
Subject4Sched(f.subid, f.subname,f.weekly,f.assigned);
return
sub;
}
public
static
List<Sessions> WeekLists(
int
semId)
{
WeekListsProgress = 0;
var sat =
new
List<Subject4Sched>();
var sun =
new
List<Subject4Sched>();
var mon =
new
List<Subject4Sched>();
var tues =
new
List<Subject4Sched>();
var wed =
new
List<Subject4Sched>();
var thur =
new
List<Subject4Sched>();
var fri =
new
List<Subject4Sched>();
string
[] weekEnds = File.ReadAllLines(@
"C:\Program Files\School Manager\Pars Text\WeekEnds.txt"
);
var holidaylist = weekEnds.Select(line => line.Split(
','
)).Select(tokens => tokens[0]).ToList();
// Get Subjects For Semester
var subList = GetSubList(semId);
RemoveAllSubjects();
int
v = 0;
foreach
(var sub
in
subList)
{
InsertSubjects(sub.SubId, sub.SubName, sub.WeekCount, 0);
v += (20/subList.Count);
}
WeekListsProgress = 20;
int
weekDaysCount = 7 - holidaylist.Count;
int
sessionsCount = subList.Sum(x => x.WeekCount);
var sessionsPerDay = Math.Ceiling(Convert.ToDouble(sessionsCount) / Convert.ToDouble(weekDaysCount));
for
(
int
x = 0; x < sessionsCount; x++)
{
foreach
(var sched
in
SubSchedList.ToList())
{
for
(
int
i = 0; i < sched.WeekCount; i++)
{
if
(i < sched.WeekCount)
{
if
(sat.Count < sessionsPerDay && !holidaylist.Contains(DayOfWeek.Saturday.ToString()))
{
int
subCount = sat.Count(y => y.SubId == sched.SubId) +
sun.Count(y => y.SubId == sched.SubId) +
mon.Count(y => y.SubId == sched.SubId) +
tues.Count(y => y.SubId == sched.SubId) +
wed.Count(y => y.SubId == sched.SubId) +
thur.Count(y => y.SubId == sched.SubId) +
fri.Count(y => y.SubId == sched.SubId);
WeekListsProgress += 60 / sessionsCount;
if
(subCount < sched.WeekCount)
{
sat.Add(
new
Subject4Sched(sched.SubId, sched.SubName, sched.WeekCount, sched.Assigned++));
UpdtaeSubjects(sched.SubId);
i++;
x++;
}
}
}
else
{
break
;
}
if
(i < sched.WeekCount)
{
if
(sun.Count < sessionsPerDay && !holidaylist.Contains(DayOfWeek.Sunday.ToString()))
{
int
subCount = sat.Count(y => y.SubId == sched.SubId) +
sun.Count(y => y.SubId == sched.SubId) +
mon.Count(y => y.SubId == sched.SubId) +
tues.Count(y => y.SubId == sched.SubId) +
wed.Count(y => y.SubId == sched.SubId) +
thur.Count(y => y.SubId == sched.SubId) +
fri.Count(y => y.SubId == sched.SubId);
WeekListsProgress += 60 / sessionsCount;
if
(subCount < sched.WeekCount)
{
sun.Add(
new
Subject4Sched(sched.SubId, sched.SubName, sched.WeekCount,
sched.Assigned++));
UpdtaeSubjects(sched.SubId);
i++;
x++;
}
}
}
else
{
break
;
}
if
(i < sched.WeekCount)
{
if
(mon.Count < sessionsPerDay && !holidaylist.Contains(DayOfWeek.Monday.ToString()))
{
int
subCount = sat.Count(y => y.SubId == sched.SubId) +
sun.Count(y => y.SubId == sched.SubId) +
mon.Count(y => y.SubId == sched.SubId) +
tues.Count(y => y.SubId == sched.SubId) +
wed.Count(y => y.SubId == sched.SubId) +
thur.Count(y => y.SubId == sched.SubId) +
fri.Count(y => y.SubId == sched.SubId);
WeekListsProgress += 60 / sessionsCount;
if
(subCount < sched.WeekCount)
{
mon.Add(
new
Subject4Sched(sched.SubId, sched.SubName, sched.WeekCount,
sched.Assigned++));
UpdtaeSubjects(sched.SubId);
i++;
x++;
}
}
}
else
{
break
;
}
if
(i < sched.WeekCount)
{
if
(tues.Count < sessionsPerDay && !holidaylist.Contains(DayOfWeek.Tuesday.ToString()))
{
int
subCount = sat.Count(y => y.SubId == sched.SubId) +
sun.Count(y => y.SubId == sched.SubId) +
mon.Count(y => y.SubId == sched.SubId) +
tues.Count(y => y.SubId == sched.SubId) +
wed.Count(y => y.SubId == sched.SubId) +
thur.Count(y => y.SubId == sched.SubId) +
fri.Count(y => y.SubId == sched.SubId);
WeekListsProgress += 60 / sessionsCount;
if
(subCount < sched.WeekCount)
{
tues.Add(
new
Subject4Sched(sched.SubId, sched.SubName, sched.WeekCount,
sched.Assigned++));
UpdtaeSubjects(sched.SubId);
i++;
x++;
}
}
}
else
{
break
;
}
if
(i < sched.WeekCount)
{
if
(wed.Count < sessionsPerDay && !holidaylist.Contains(DayOfWeek.Wednesday.ToString()))
{
int
subCount = sat.Count(y => y.SubId == sched.SubId) +
sun.Count(y => y.SubId == sched.SubId) +
mon.Count(y => y.SubId == sched.SubId) +
tues.Count(y => y.SubId == sched.SubId) +
wed.Count(y => y.SubId == sched.SubId) +
thur.Count(y => y.SubId == sched.SubId) +
fri.Count(y => y.SubId == sched.SubId);
WeekListsProgress += 60 / sessionsCount;
if
(subCount < sched.WeekCount)
{
wed.Add(
new
Subject4Sched(sched.SubId, sched.SubName, sched.WeekCount,
sched.Assigned++));
UpdtaeSubjects(sched.SubId);
i++;
x++;
}
}
}
else
{
break
;
}
if
(i < sched.WeekCount)
{
if
(thur.Count < sessionsPerDay && !holidaylist.Contains(DayOfWeek.Thursday.ToString()))
{
int
subCount = sat.Count(y => y.SubId == sched.SubId) +
sun.Count(y => y.SubId == sched.SubId) +
mon.Count(y => y.SubId == sched.SubId) +
tues.Count(y => y.SubId == sched.SubId) +
wed.Count(y => y.SubId == sched.SubId) +
thur.Count(y => y.SubId == sched.SubId) +
fri.Count(y => y.SubId == sched.SubId);
WeekListsProgress += 60 / sessionsCount;
if
(subCount < sched.WeekCount)
{
thur.Add(
new
Subject4Sched(sched.SubId, sched.SubName, sched.WeekCount,
sched.Assigned++));
UpdtaeSubjects(sched.SubId);
i++;
x++;
}
}
}
else
{
break
;
}
if
(i < sched.WeekCount)
{
if
(fri.Count < sessionsPerDay && !holidaylist.Contains(DayOfWeek.Friday.ToString()))
{
int
subCount = sat.Count(y => y.SubId == sched.SubId) +
sun.Count(y => y.SubId == sched.SubId) +
mon.Count(y => y.SubId == sched.SubId) +
tues.Count(y => y.SubId == sched.SubId) +
wed.Count(y => y.SubId == sched.SubId) +
thur.Count(y => y.SubId == sched.SubId) +
fri.Count(y => y.SubId == sched.SubId);
WeekListsProgress += 60 / sessionsCount;
if
(subCount < sched.WeekCount)
{
fri.Add(
new
Subject4Sched(sched.SubId, sched.SubName, sched.WeekCount,
sched.Assigned++));
UpdtaeSubjects(sched.SubId);
i++;
x++;
}
}
}
else
{
break
;
}
}
}
}
WeekListsProgress = 80;
int
[] counts = {sat.Count, sun.Count, mon.Count, tues.Count, wed.Count, thur.Count, fri.Count};
////////////////////////////////////////////////////////////////////////////////////////////////////
var sList=
new
List<Sessions>();
for
(
int
i = 0; i < counts.Max(); i++)
{
string
s1=
""
;
string
s2 =
""
;
string
s3 =
""
;
string
s4 =
""
;
string
s5 =
""
;
string
s6 =
""
;
string
s7 =
""
;
if
(sat.Count>i)
{
s1 = sat[i].SubName;
}
if
(sun.Count > i)
{
s2 = sun[i].SubName;
}
if
(mon.Count > i)
{
s3 = mon[i].SubName;
}
if
(tues.Count > i)
{
s4 = tues[i].SubName;
}
if
(wed.Count > i)
{
s5 = wed[i].SubName;
}
if
(thur.Count > i)
{
s6 = thur[i].SubName;
}
if
(fri.Count > i)
{
s7 = fri[i].SubName;
}
sList.Add(
new
Sessions(i,s1,s2,s3,s4,s5,s6,s7));
WeekListsProgress += 20/counts.Max();
}
WeekListsProgress = 100;
return
sList;
}
Attachment:
SchedHandler.rar
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
How to give Efficent,better,latest Datatypes in sql server
how to return xml while using webservice?