public CreateUserDataNextTurn(string UserName)
        {
            var t = (from p in dr.DurationSystems
                     where DateTime.Now >= p.StartDate
                     where DateTime.Now <= p.EndDate
                     select p.DurationId).First();

            Assessment asm = new Assessment();

            // Set properties before insert
            asm.UserName = UserName;
            asm.DurationId = t + 1;
            asm.G_Organize = 0;
            asm.G_SelfDev = 0;
            asm.G_Professional = 0;
            asm.G_TeamWork = 0;
            asm.G_Communicate = 0;
            asm.G_Mind = 0;
            asm.U_Strength = "";
            asm.U_Weakness = "";
            asm.D_Teach = 0;
            asm.E_Teach = 0;
            asm.G_Teach = 0;
            asm.P_Teach = 20;
            asm.D_Research = 0;
            asm.E_Research = 0;
            asm.G_Research = 0;
            asm.P_Research = 10;
            asm.D_Service = 0;
            asm.E_Service = 0;
            asm.G_Service = 0;
            asm.P_Service = 5;
            asm.D_Other = 0;
            asm.E_Other = 0;
            asm.G_Other = 0;
            asm.P_Other = 5;

            asm.E_CarryWork = 0;
            asm.G_CarryWork = 0;

            asm.Pro_AssessStatus = false;
            asm.Dean_AssessStatus = false;
            asm.Dept_AssessStatus = false;
            asm.Uni_AssessStatus = false;

            db.Assessments.InsertOnSubmit(asm);
            db.SubmitChanges();
        }
        public CreateAssessment(string UserName)
        {
            var t = (from p in dr.DurationSystems
                     where DateTime.Now >= p.StartDate
                     where DateTime.Now <= p.EndDate
                     select p.DurationId).First();

            var h = (from p in db.Users
                    where p.UserName == UserName
                    select p.DeptId).First();

            var UserHeader = (from p in db.Users
                     where p.DeptId == h
                     where p.UserLevelId == 1
                     select p.UserName).First();

            Assessment asm = new Assessment();

            // Set properties before insert
            asm.UserName = UserName;                // ชื่อเข้าใช้งานระบบ (Username)
            asm.DurationId = t;                     // ช่วงเวลา

            asm.E_CarryWork = 1;                    // ค่าความคาดหวัง
            asm.E_Teach = 1;
            asm.E_Research = 1;
            asm.E_Service = 1;
            asm.E_Other = 1;

            asm.P_Teach = 20;                       // เปอร์เซนต์คาดหวัง
            asm.P_Research = 10;
            asm.P_Service = 5;
            asm.P_Other = 5;

            asm.DealWorkLoadDetail = "";            // บันทึกข้อตกลง
            asm.DealTeachDetail = "";
            asm.DealResearchDetail = "";
            asm.DealServiceDetail = "";
            asm.DealOtherDetail = "";

            asm.DealCreate = true;                 // สถานะจัดทำข้อตกลง

            asm.G_CarryWork = 0;                    //คะแนนที่ได้จาก หัวหน้าภาค
            asm.G_Teach = 0;
            asm.G_Research = 0;
            asm.G_Service = 0;
            asm.G_Other = 0;
            asm.G_Organize = 0;
            asm.G_SelfDev = 0;
            asm.G_Professional = 0;
            asm.G_TeamWork = 0;
            asm.G_Communicate = 0;
            asm.G_Mind = 0;

            asm.D_CarryWork = 1;                    //คะแนนที่ได้จาก คณบดี
            asm.D_Teach = 1;
            asm.D_Research = 1;
            asm.D_Service = 1;
            asm.D_Other = 1;
            asm.D_Organize = 1;
            asm.D_SelfDev = 1;
            asm.D_Professional = 1;
            asm.D_TeamWork = 1;
            asm.D_Communicate = 1;
            asm.D_Mind = 1;

            asm.Assessor = UserHeader;              // Username ผู้ทำการประเมิณ

            asm.U_Strength = "";
            asm.U_Weakness = "";

            asm.AssessComplete = false;             // สถานะการประเมิณจากหัวหน้าภาควิชา
            asm.AssessApproved = false;             // สถานะการยื่นยันจาก คณบดี

            db.Assessments.InsertOnSubmit(asm);
            db.SubmitChanges();
        }
		private void detach_Assessments(Assessment entity)
		{
			this.SendPropertyChanging();
			entity.User = null;
		}
		private void attach_Assessments(Assessment entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}
 partial void DeleteAssessment(Assessment instance);
 partial void UpdateAssessment(Assessment instance);
 partial void InsertAssessment(Assessment instance);
        private void hightLightLabelHeader(Assessment q)
        {
            if (q.E_CarryWork > q.G_CarryWork)
            {
                lblG_CarryWork.ForeColor = Color.Red;
            }
            else
            {
                lblG_CarryWork.ForeColor = Color.Black;
            }

            if (q.E_Teach > q.G_Teach)
            {
                lblG_Teach.ForeColor = Color.Red;
            }
            else
            {
                lblG_Teach.ForeColor = Color.Black;
            }

            if (q.E_Research > q.G_Research)
            {
                lblG_Research.ForeColor = Color.Red;
            }
            else
            {
                lblG_Research.ForeColor = Color.Black;
            }

            if (q.E_Service > q.G_Service)
            {
                lblG_Service.ForeColor = Color.Red;
            }
            else
            {
                lblG_Service.ForeColor = Color.Black;
            }

            if (q.E_Other > q.G_Other)
            {
                lblG_Other.ForeColor = Color.Red;
            }
            else
            {
                lblG_Other.ForeColor = Color.Black;
            }

            // University
            if (q.Duration.Organize > q.G_Organize)
            {
                lblG_Organize.ForeColor = Color.Red;
            }
            else
            {
                lblG_Organize.ForeColor = Color.Black;
            }

            if (q.Duration.SelfDev > q.G_SelfDev)
            {
                lblG_SelfDev.ForeColor = Color.Red;
            }
            else
            {
                lblG_SelfDev.ForeColor = Color.Black;
            }

            if (q.Duration.Professional > q.G_Professional)
            {
                lblG_Professional.ForeColor = Color.Red;
            }
            else
            {
                lblG_Professional.ForeColor = Color.Black;
            }

            if (q.Duration.Communicate > q.G_Communicate)
            {
                lblG_Communicate.ForeColor = Color.Red;
            }
            else
            {
                lblG_Communicate.ForeColor = Color.Black;
            }

            if (q.Duration.TeamWork > q.G_TeamWork)
            {
                lblG_TeamWork.ForeColor = Color.Red;
            }
            else
            {
                lblG_TeamWork.ForeColor = Color.Black;
            }

            if (q.Duration.Mind > q.G_Mind)
            {
                lblG_Mind.ForeColor = Color.Red;
            }
            else
            {
                lblG_Mind.ForeColor = Color.Black;
            }
        }
        public void CreateAssessment(string UserName,int duraId)
        {
            Random r = new Random();
            var q = (from p in db.Users
                     where p.UserName == UserName
                     select p).First();

            var UserHeader = (from p in db.Users
                              where p.DeptId == q.DeptId
                              where p.UserLevelId == 1
                              select p.UserName).First();

            Assessment asm = new Assessment();

            // Set properties before insert
            asm.UserName = UserName;                // ชื่อเข้าใช้งานระบบ (Username)
            asm.DurationId = duraId;                     // ช่วงเวลา

            asm.E_CarryWork = r.Next(1, 5);                    // ค่าความคาดหวัง
            asm.E_Teach = r.Next(1, 5);
            asm.E_Research = r.Next(1, 5);
            asm.E_Service = r.Next(1, 5);
            asm.E_Other = r.Next(1, 5);

            int a = r.Next(1, 5);

            if (a==1)
            {
                asm.P_Teach = 20;                       // เปอร์เซนต์คาดหวัง
                asm.P_Research = 10;
                asm.P_Service = 5;
                asm.P_Other = 5;
            }
            else if (a == 2)
            {
                asm.P_Teach = 10;                       // เปอร์เซนต์คาดหวัง
                asm.P_Research = 20;
                asm.P_Service = 5;
                asm.P_Other = 5;
            }
            else if (a == 3)
            {
                asm.P_Teach = 5;                       // เปอร์เซนต์คาดหวัง
                asm.P_Research = 10;
                asm.P_Service = 20;
                asm.P_Other = 5;
            }
            else if (a == 4)
            {
                asm.P_Teach = 5;                       // เปอร์เซนต์คาดหวัง
                asm.P_Research = 10;
                asm.P_Service = 5;
                asm.P_Other = 20;
            }
            else if (a == 5)
            {
                asm.P_Teach = 5;                       // เปอร์เซนต์คาดหวัง
                asm.P_Research = 10;
                asm.P_Service = 20;
                asm.P_Other = 5;
            }

            asm.DealWorkLoadDetail = "";            // บันทึกข้อตกลง
            asm.DealTeachDetail = "";
            asm.DealResearchDetail = "";
            asm.DealServiceDetail = "";
            asm.DealOtherDetail = "";

            asm.DealCreate = true;                 // สถานะจัดทำข้อตกลง

            //asm.G_CarryWork = r.Next(1, 5);                     //คะแนนที่ได้จาก หัวหน้าภาค
            //asm.G_Teach = r.Next(1, 5);
            //asm.G_Research = r.Next(1, 5);
            //asm.G_Service = r.Next(1, 5);
            //asm.G_Other = r.Next(1, 5);
            //asm.G_Organize = r.Next(1, 5);
            //asm.G_SelfDev = r.Next(1, 5);
            //asm.G_Professional = r.Next(1, 5);
            //asm.G_TeamWork = r.Next(1, 5);
            //asm.G_Communicate = r.Next(1, 5);
            //asm.G_Mind = r.Next(1, 5);

            //asm.D_CarryWork = r.Next(1, 5); ;                    //คะแนนที่ได้จาก คณบดี
            //asm.D_Teach = r.Next(1, 5); ;
            //asm.D_Research = r.Next(1, 5); ;
            //asm.D_Service = r.Next(1, 5); ;
            //asm.D_Other = r.Next(1, 5); ;
            //asm.D_Organize = r.Next(1, 5); ;
            //asm.D_SelfDev = r.Next(1, 5); ;
            //asm.D_Professional = r.Next(1, 5); ;
            //asm.D_TeamWork = r.Next(1, 5); ;
            //asm.D_Communicate = r.Next(1, 5); ;
            //asm.D_Mind = r.Next(1, 5); ;

            asm.G_CarryWork = 0;                     //คะแนนที่ได้จาก หัวหน้าภาค
            asm.G_Teach = 0;
            asm.G_Research = 0;
            asm.G_Service = 0;
            asm.G_Other = 0;
            asm.G_Organize = 0;
            asm.G_SelfDev = 0;
            asm.G_Professional = 0;
            asm.G_TeamWork = 0;
            asm.G_Communicate = 0;
            asm.G_Mind = 0;

            asm.D_CarryWork = 1;                     //คะแนนที่ได้จาก คณบดี
            asm.D_Teach = 1;
            asm.D_Research = 1;
            asm.D_Service = 1;
            asm.D_Other = 1 ;
            asm.D_Organize =1;
            asm.D_SelfDev = 1;
            asm.D_Professional = 1 ;
            asm.D_TeamWork = 1 ;
            asm.D_Communicate = 1 ;
            asm.D_Mind =1 ;

            asm.Assessor = UserHeader;              // Username ผู้ทำการประเมิณ

            asm.U_Strength = "";
            asm.U_Weakness = "";

            asm.AssessComplete = false;             // สถานะการประเมิณจากหัวหน้าภาควิชา
            asm.AssessApproved = false;             // สถานะการยื่นยันจาก คณบดี

            db.Assessments.InsertOnSubmit(asm);
            db.SubmitChanges();
        }