private void AddEditTeacherFrm_Load(object sender, EventArgs e)
        {
            // Init database
            _db = ((MainFrm)Parent)._db;

            // For branch combobox
            _db.SQLCommand = "SELECT * FROM teacher_branch";
            _db.Query();
            while (_db.Result.Read())
            {
                cmbBrch.Items.Add((string)_db.Result.GetValue(1));
                _lstBrch.Add(new Branch { BranchID = (string)_db.Result.GetValue(0), BranchName = (string)_db.Result.GetValue(1) });
            }

            // For Edit mode
            if (EditMode == true)
            {
                _db.SQLCommand = "SELECT * FROM teacher WHERE tech_id='" + TechID + "'";
                _db.Query();
                if (_db.Result.HasRows)
                {
                    _db.Result.Read();
                    txtName.Text = (string)_db.Result.GetValue(1);
                    cmbBrch.Text = LookupBranchName((string)_db.Result.GetValue(2));
                    txtUsername.Text = (string)_db.Result.GetValue(3);
                    txtPassword.Text = (string)_db.Result.GetValue(4);
                    cmbQuestion.Text = (string)_db.Result.GetValue(7);
                    txtAnswer.Text = (string)_db.Result.GetValue(8);
                }
            }
        }
        protected void LoadGvCtAss()
        {
            var data = new MySQLDatabase();

            var sid = data.Query("GetStudentTableIdByUserId",
                                 new Dictionary <string, object>
            {
                { "@uid", User.Identity.GetUserId() }
            }, true);
            var a = sid.First()["id"];

            var table = data.Query("GeAllDatesPresentsByTcidSid",
                                   new Dictionary <string, object>
            {
                { "@tcid", ddlSelectCourse.SelectedValue },
                { "@sid", a }
            }, true);

            gvCtAss.DataSource = table.Select(x => new
            {
                Dates      = Convert.ToDateTime(x["dateColumn"]).ToString("dd-MM-yy"),
                Attendance = x["present"]
            }).ToList();
            gvCtAss.DataBind();
        }
Esempio n. 3
0
        protected void bindGridView()
        {
            MySQLDatabase data       = new MySQLDatabase();
            var           courseName = data.Query("GetAllCourselListByUserId",
                                                  new Dictionary <string, object>
            {
                { "@uid", User.Identity.GetUserId() }
            }, true);
            var count = from x in courseName
                        let v = data.Query("GetStudentCourseIdByTCID",
                                           new Dictionary <string, object>
            {
                { "@tcid", x["id"] }
            }, true)
                                select new
            {
                Courses = x["prefix"] + " " + x["course_no"]
                          + " " + x["course_tittle"] + " " + x["postfix"] +
                          " (" + x["session"] + ")",
                Students = v.Count.ToString(),
                Status   = (x["isclosed"].ToString() == "True") ? "Close" : "Open"
            };

            gvCourse.DataSource = count.ToList();
            gvCourse.DataBind();
        }
        protected void gvTakeAttendence_dataBound()
        {
            MySQLDatabase data      = new MySQLDatabase();
            var           markIdSId = data.Query("GetMSIdSidByTCId",
                                                 new Dictionary <string, object>
            {
                { "@tcid", ddlSelectCourse.SelectedValue }
            }, true);

            if (markIdSId != null)
            {
                var rep = from x in markIdSId
                          let v = data.Query("GetSidSnameBysid",
                                             new Dictionary <string, object>
                {
                    { "@sid", x["studentId"] }
                }, true)
                                  select new
                {
                    studentid = v[0]["studentId"],
                    name      = v[0]["FirstName"] + " " + v[0]["LastName"],
                    markid    = x["id"]
                };
                gvTakeAttendence.DataSource = rep.ToList();
                gvTakeAttendence.DataBind();
            }
        }
Esempio n. 5
0
        protected void Page_Load(object o, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlAs.Items.Add(new ListItem("Student", "student"));
                if (User.IsInRole("Admin"))
                {
                    ddlAs.Items.Add(new ListItem("Teacher", "teacher"));
                    ddlAs.Items.Add(new ListItem("Admin", "admin"));
                }
                ddlDesignation.DataSource = db.Query("getAllDesignation", null, true).
                                            Select(x => new TextValuePair {
                    Text  = x["designation"],
                    Value = x["id"]
                }).ToList();
                ddlDesignation.DataBind();

                ddlClass.DataSource = db.Query("getClassByYId",
                                               new Dictionary <string, object>()
                {
                    { "@YId", db.QueryValue("getYearId", new Dictionary <string, object>()
                        {
                            { "@pyear", DateTime.Now.Year }
                        }, true) }
                }, true).Select(x => new TextValuePair {
                    Text  = x["class"],
                    Value = x["classid"]
                }).ToList();
                ddlClass.DataBind();
            }
        }
Esempio n. 6
0
        private void LoadPostsAccordingToDDL()
        {
            MySQLDatabase db = new MySQLDatabase();
            List <Dictionary <string, string> > res = null;

            if (ddlCatagory.SelectedValue == "All")
            {
                res = db.Query("getAllIdTitle", null, true);
            }
            else
            {
                Dictionary <string, object> dict = new Dictionary <string, object>(1);
                dict.Add("@ptype", int.Parse(ddlCatagory.SelectedValue));
                res = db.Query("getIdTitleByType", dict, true);
            }

            PostList.Controls.Clear();
            int?postId = Convert.ToInt32(Request.QueryString["postid"]);

            foreach (var item in res)
            {
                PostListItem post = LoadControl("~/User Control/PostListItem.ascx") as PostListItem;
                post.Title  = item["title"];
                post.PostID = Convert.ToInt32(item["id"]);
                post.Body   = item["date"];
                if (postId != null && postId == post.PostID)
                {
                    post.SetActive();
                }
                post.PostClick += delegate {
                    Response.Redirect(Request.Url.AbsolutePath + "?postid=" + item["id"] + "&posttype=" + ddlCatagory.SelectedValue, true);
                };
                PostList.Controls.Add(post);
            }
        }
Esempio n. 7
0
        protected void LoadDdlCourse()
        {
            var data = new MySQLDatabase();

            var sid = data.Query("GetStudentTableIdByUserId",
                                 new Dictionary <string, object>
            {
                { "@uid", User.Identity.GetUserId() }
            }, true);
            var a      = sid.First()["id"];
            var course = data.Query("GetAllCTitleSessionBySID",
                                    new Dictionary <string, object>
            {
                { "@sid", a }
            }, true);

            ddlSelectCourse.DataSource = course.Select(x => new
            {
                t = x["prefix"] + " " + x["course_no"] + " " + x["course_tittle"] + " " + x["postfix"] + " (" + x["session"] + ")",
                v = x["id"]
            }).ToList();
            ddlSelectCourse.DataTextField  = "t";
            ddlSelectCourse.DataValueField = "v";
            ddlSelectCourse.DataBind();
        }
Esempio n. 8
0
        protected void LoadGvCtAss()
        {
            var data = new MySQLDatabase();

            var sid = data.Query("GetStudentTableIdByUserId",
                                 new Dictionary <string, object>
            {
                { "@uid", User.Identity.GetUserId() }
            }, true);
            var a = sid.First()["id"];

            var table = data.Query("GetAllCtAssNameMarkByTcidSid",
                                   new Dictionary <string, object>
            {
                { "@tcid", ddlSelectCourse.SelectedValue },
                { "@sid", a }
            }, true);

            gvCtAss.DataSource = table.Select(x => new
            {
                Name  = x["name"],
                Marks = x["mark"]
            }).ToList();
            gvCtAss.DataBind();
        }
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            if (ViewState["YCSId"] == null)
            {
                ReloadYCSId(null, null);
            }

            MySQLDatabase db        = new MySQLDatabase();
            var           teacherId = new UserTable <ApplicationUser>(db).GetUserId(User.Identity.Name);

            #region Load Mark
            int teacherSubjectId = Convert.ToInt32(
                db.QueryValue("getTeacherSubjectId",
                              new Dictionary <string, object>()
            {
                { "@TUN", User.Identity.Name },
                { "@ycsid", ViewState["YCSId"] },
                { "@psubjectid", ddlSubject.SelectedValue }
            },
                              true));
            var res2 = db.Query("getMarkPortionIdByTSId", new Dictionary <string, object>()
            {
                { "@TSId", teacherSubjectId }
            }, true);

            marks.Controls.Clear();
            //ViewState["clicks"] = new List<MarkPortion>();
            foreach (var item in res2)
            {
                MarkPortion markPortion = LoadControl("~/User Control/MarkPortion.ascx") as MarkPortion;
                markPortion.PortionName   = item["portionname"];
                markPortion.MarkPortionId = Convert.ToInt32(item["markportionid"]);
                var resMark = db.Query("getMarkByMPIdSIdTid",
                                       new Dictionary <string, object>()
                {
                    { "@MPId", item["markportionid"] },
                    { "@SId", ddlStudent.SelectedValue },
                    { "@Tid", ddlTerm.SelectedValue }
                }, true);
                if (resMark.Count == 0)
                {
                    markPortion.Mark   = null;
                    markPortion.MarkId = null;
                }
                else
                {
                    markPortion.Mark   = Convert.ToInt32(resMark[0]["mark"]);
                    markPortion.MarkId = Convert.ToInt32(resMark[0]["markid"]);
                }
                markPortion.SubmitClick += MarkPortion_SubmitClick;
                //AsyncPostBackTrigger trigger = new AsyncPostBackTrigger() { ControlID = markPortion.ID, EventName = "SubmitClick" };
                //up.Triggers.Add(trigger);
                //(ViewState["clicks"] as List<MarkPortion>).Add(markPortion);
                marks.Controls.Add(markPortion);
            }
            #endregion
        }
Esempio n. 10
0
 protected void LoadDDLYear(object o, EventArgs e)
 {
     ddlYear.DataSource = db.Query("getAllYear", null, true).
                          Select(x => new TextValuePair {
         Text = x["year"], Value = x["yearid"]
     }).ToList();
     ddlYear.DataBind();
     LoadDDLClass(null, null);
 }
Esempio n. 11
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            var data  = new MySQLDatabase();
            var value = ddlSearchBy.SelectedValue;

            if (value == "1")
            {
                var books = data.Query("SearchByTitleLanguage", new Dictionary <string, object> {
                    { "@name", txtSerach.Text }
                }, true);
                gvBooks.DataSource = books.Select(x => new
                {
                    title    = x["title"],
                    price    = x["price"],
                    language = x["language"],
                    count    = x["COUNT(*)"],
                    category = x["catagoty_name"],
                    author   = x["first_name"] + " " + x["last_name"]
                }).ToList();
                gvBooks.DataBind();
            }
            else if (value == "2")
            {
                var books = data.Query("SearchByAuthorName", new Dictionary <string, object> {
                    { "@author", txtSerach.Text }
                }, true);
                gvBooks.DataSource = books.Select(x => new
                {
                    title    = x["title"],
                    price    = x["price"],
                    language = x["language"],
                    count    = x["COUNT(*)"],
                    category = x["catagoty_name"],
                    author   = x["first_name"] + " " + x["last_name"]
                }).ToList();
                gvBooks.DataBind();
            }
            else if (value == "3")
            {
                var books = data.Query("SearchByCatagoryName", new Dictionary <string, object> {
                    { "@catagory", txtSerach.Text }
                }, true);
                gvBooks.DataSource = books.Select(x => new
                {
                    title    = x["title"],
                    price    = x["price"],
                    language = x["language"],
                    count    = x["COUNT(*)"],
                    category = x["catagoty_name"],
                    author   = x["first_name"] + " " + x["last_name"]
                }).ToList();
                gvBooks.DataBind();
            }
        }
Esempio n. 12
0
        protected void LoadDDLClass(object o, EventArgs e)
        {
            ddlClass.DataSource = db.Query("getClassByYId", new Dictionary <string, object>()
            {
                { "@yid", yearId }
            }, true).
                                  Select(x => new TextValuePair {
                Text = x["class"], Value = x["classid"]
            }).ToList();
            ddlClass.DataBind();

            LoadDDLSection(null, null);
        }
Esempio n. 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            MySQLDatabase db    = new MySQLDatabase();
            var           res   = db.Query("getAllApplication", null, true);
            var           appid = Request.QueryString["appid"];

            foreach (var item in res)
            {
                PostListItem post = LoadControl("~/User Control/PostListItem.ascx") as PostListItem;
                post.PostID = Convert.ToInt32(item["id"]);
                if (item["id"] == appid)
                {
                    post.SetActive();
                }
                post.Title = item["title"];
                if (item["type"] == "1")
                {
                    post.Badge     = "stu";
                    post.CssClass += " stu";
                }
                else
                {
                    post.Badge     = "tea";
                    post.CssClass += " tea";
                }
                post.Body       = item["date"];
                post.PostClick += delegate { Response.Redirect(Request.Url.AbsolutePath + "?appid=" + post.PostID); };

                Applications.Controls.Add(post);
            }

            if (appid != null)
            {
                var res2 = db.Query("getResponseByAId",
                                    new Dictionary <string, object>()
                {
                    { "@AId", Convert.ToInt32(appid) }
                },
                                    true);
                foreach (var item in res2)
                {
                    PostListItem post = LoadControl("~/User Control/PostListItem.ascx") as PostListItem;
                    post.PostID = Convert.ToInt32(item["id"]);
                    post.Title  = item["name"];
                    post.Body   = item["email"];
                    //post.PostClick += delegate { Response.Redirect; };
                    post.OnClientClick += "window.open('" + ("Response?resid=" + post.PostID) + "','_blank')";
                    Responses.Controls.Add(post);
                }
            }
        }
Esempio n. 14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            MySQLDatabase db = new MySQLDatabase();
            List <Dictionary <string, string> > res = db.Query("getAllSpeechSummary", null, true);

            foreach (var item in res)
            {
                Tile tile = LoadControl("~/User Control/Tile.ascx") as Tile;
                tile.PostID     = Convert.ToInt32(item["id"]);
                tile.Title      = item["title"];
                tile.Detail     = item["summary"];
                tile.Type       = 3;
                tile.WidthClass = "col-sm-12";

                tile.TitleClick += delegate {
                    Response.Redirect("~/Post.aspx?postid=" + tile.PostID + "&posttype=3");
                };

                speeches.Controls.Add(tile);
            }

            if (!IsPostBack)
            {
                //TODO Load History from Xml
            }
        }
Esempio n. 15
0
        private void LoadDDLTeacher()
        {
            MySQLDatabase db = new MySQLDatabase();

            ddlTeacher.DataSource = db.Query("getAllTeacher", null, true).Select(x => new { Text = x["name"], Value = x["id"] }).ToList();
            ddlTeacher.DataBind();
        }
Esempio n. 16
0
        private void LoadPost(int?id)
        {
            if (id == null)
            {
                Server.Transfer("~/Error.html", true);
            }

            MySQLDatabase db = new MySQLDatabase();
            Dictionary <string, object> dict = new Dictionary <string, object>(1);

            dict.Add("@pid", id);
            List <Dictionary <string, string> > res = db.Query("getPostById", dict, true);

            if (res.Count > 0)
            {
                ddlCatagory.SelectedValue = res[0]["type"];
                postTitle.Text            = res[0]["title"];
                postSummary.Text          = res[0]["summary"];
                postBody.Text             = res[0]["body"];
                Title = res[0]["title"];
            }
            else
            {
                Server.Transfer(Statics.Error);
            }
        }
Esempio n. 17
0
        private void ReloadDDLSection(object yearId)
        {
            MySQLDatabase db = new MySQLDatabase();

            ddlSection.DataSource = db.Query(
                "getSectionByYIdCId",
                new Dictionary <string, object>()
            {
                { "@YId", yearId },
                { "@CId", ddlClass.SelectedValue }
            }, true)
                                    .Select(x => new {
                Text  = x["section"],
                Value = x["sectionid"]
            }).ToList();
            ddlSection.DataBind();

            if (ddlSection.Items.Count > 0)
            {
                ReloadDDLStudent(yearId);
            }
            else
            {
                ddlStudent.Items.Clear();
            }
        }
Esempio n. 18
0
 protected void LoadGVTerm(object o, EventArgs e)
 {
     if (ddlSection.Items.Count > 0)
     {
         gvTerm.Columns[0].Visible = true;
         //new TermYearClassSectionTable(db).GetTermPercentageByYearClassSection(ddlYear.SelectedValue, ddlClass.SelectedValue, ddlSection.SelectedValue);
         gvTerm.DataSource =
             db.Query("getTermByYCSId", new Dictionary <string, object>()
         {
             { "@YCSId", new YearClassSectionTable(db).GetYearClassSectionId(ddlYear.SelectedValue, ddlClass.SelectedValue, ddlSection.SelectedValue) }
         }, true).
             Select(x => new
         {
             Text  = x["term"],
             Value = x["percentage"],
             Id    = x["id"]
         }).ToList();
     }
     else
     {
         gvTerm.Columns[0].Visible = true;
         gvTerm.DataSource         = new DataTable();
     }
     gvTerm.DataBind();
     gvTerm.Columns[0].Visible = false;
 }
Esempio n. 19
0
        static Response getResponseById(int id)
        {
            Response      response = null;
            MySQLDatabase db       = new MySQLDatabase();
            List <Dictionary <string, string> > res = db.Query("getResponseById", new Dictionary <string, object>()
            {
                { "@pid", id }
            }, true);

            if (res.Count > 0)
            {
                response = new Response()
                {
                    Id                       = id,
                    ApplicatoinId            = Convert.ToInt32(res[0]["applicationid"]),
                    FirstName                = res[0]["firstname"],
                    LastName                 = res[0]["lastname"],
                    FathersName              = res[0]["fathersname"],
                    MothersName              = res[0]["mothersname"],
                    Gender                   = Convert.ToInt32(res[0]["gender"]),
                    BirthDate                = DateTime.Parse(res[0]["birthdate"]),
                    Address                  = res[0]["address"],
                    Email                    = res[0]["email"],
                    PhoneNumber              = res[0]["phoneNumber"],
                    DesignationId            = Convert.ToInt32(res[0]["designationId"]),
                    Qualification            = res[0]["qualification"],
                    Class                    = Convert.ToInt32(res[0]["class"]),
                    GaurdianOccupation       = res[0]["GaurdianOccupation"],
                    GaurdianOccupationDetail = res[0]["GaurdianOccupationDetail"]
                };
            }

            return(response);
        }
        protected void btnPush_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                MySQLDatabase db   = new MySQLDatabase();
                var           TUId = Context.GetOwinContext().GetUserManager <ApplicationUserManager>().FindByName(User.Identity.Name).Id;
                var           res1 = db.Query("GetStudentIdByGId",
                                              new Dictionary <string, object>()
                {
                    { "@GId", ddlTo.SelectedValue }
                }, true);

                var id = db.QueryValue("addNotification",
                                       new Dictionary <string, object>()
                {
                    { "@TUId", TUId },
                    { "@ptitle", txtSubject.Text },
                    { "@pbody", txtDetail.Text }
                }, true);

                foreach (var item in res1)
                {
                    db.Execute("addStudentNotification",
                               new Dictionary <string, object>()
                    {
                        { "@SId", item["studentId"] },
                        { "@NId", id }
                    }, true);
                }
                notificatinName.InnerText = txtSubject.Text;
                groupName.InnerText       = ddlTo.SelectedItem.Text;
                divSuccessful.Visible     = true;
            }
        }
        private void TeacherPopUp_Load(object sender, EventArgs e)
        {
            // Init database
            _db = ((MainFrm)Parent)._db;

            // Setup datagrid columns
            dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dgv.AllowUserToAddRows = false;
            dgv.AllowUserToDeleteRows = false;
            dgv.MultiSelect = false;
            dgv.ReadOnly = true;
            dgv.ColumnCount = 3;
            dgv.Columns[0].HeaderText = "รหัส";
            dgv.Columns[0].Visible = false;
            dgv.Columns[1].HeaderText = "ชื่อ-นามสกุล";
            dgv.Columns[1].Width = 125;
            dgv.Columns[2].HeaderText = "คณะ";
            dgv.Columns[2].Width = 200;

            // Load data
            _db.SQLCommand = _sqlShowAll;
            _db.Query();
            while (_db.Result.Read())
            {
                if (_db.Result["tech_name"].ToString() == "admin")
                {
                    continue;
                }
                dgv.Rows.Add(_db.Result["tech_id"], _db.Result["tech_name"], _db.Result["tech_brch_name"]);
            }
        }
Esempio n. 22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                divSuccessful.Visible = false;
            }
            if (Request.QueryString["appid"] == null || Request.QueryString["type"] == null)
            {
                Server.Transfer(Statics.Error404, true);
            }

            #region Initialize Application Area

            MySQLDatabase db = new MySQLDatabase();
            Dictionary <string, object> dict = new Dictionary <string, object>(1);
            dict.Add("@pid", Convert.ToInt32(Request.QueryString["appid"]));
            List <Dictionary <string, string> > res = db.Query("getApplicationById", dict, true);
            if (res.Count > 0)
            {
                applicationTitle.InnerText   = res[0]["title"];
                applicationSummary.InnerText = res[0]["summary"];
                applicationUrl.HRef          = res[0]["noticeUrl"];
                setVisibility(Convert.ToInt32(Request.QueryString["type"]), Convert.ToInt32(res[0]["idValue"]));
            }
            else
            {
                Server.Transfer("~/Error.html");
            }

            #endregion
        }
Esempio n. 23
0
        private void BindDLL()
        {
            MySQLDatabase db     = new MySQLDatabase();
            var           yearId = db.QueryValue("getYearId", new Dictionary <string, object>()
            {
                { "@pyear", DateTime.Now.Year }
            }, true);
            var teacherId = Context.GetOwinContext().GetUserManager <ApplicationUserManager>().FindByName(User.Identity.Name).Id;

            ReloadDDLGroup();

            ddlClass.DataSource = db.Query(
                "getClassByTUIdYId",
                new Dictionary <string, object>()
            {
                { "@TUId", teacherId },
                { "@YId", yearId }
            },
                true)
                                  .Select(x => new {
                Text  = x["class"],
                Value = x["classid"]
            }).ToList();
            ddlClass.DataBind();

            ReloadDDLSection(teacherId, yearId);
        }
Esempio n. 24
0
        private void ReloadDDLStudent(object yearId)
        {
            MySQLDatabase db    = new MySQLDatabase();
            var           YCSId = db.QueryValue("getYearClassSectionId",
                                                new Dictionary <string, object>()
            {
                { "@pyearid", yearId },
                { "@pclassid", ddlClass.SelectedValue },
                { "@psectionid", ddlSection.SelectedValue }
            }, true);

            ddlStudent.DataSource = db.Query("getStudentByYCSId",
                                             new Dictionary <string, object>()
            {
                { "@YCSId", YCSId }
            }, true).Select(x => new {
                Text  = x["student"],
                Value = x["studentid"]
            }).ToList();
            ddlStudent.DataBind();
            //Reload Textboxes according to new ddl selection
            if (ddlStudent.Items.Count > 0)
            {
                ReloadTextBox(Convert.ToInt32(ddlStudent.SelectedValue), (int)YCSId);
            }
            else
            {
                txtClass.Text   = string.Empty;
                txtSection.Text = string.Empty;
                txtRoll.Text    = string.Empty;
            }
        }
Esempio n. 25
0
        //protected void LoadCBL(object o, EventArgs e) {
        //	MySQLDatabase db = new MySQLDatabase();
        //	var yid = db.QueryValue("getYearId", new Dictionary<string, object>() { { "@pyear", DateTime.Now.Year } }, true);
        //	var ycsId = db.QueryValue("getYearClassSectionId",
        //		new Dictionary<string, object>() {
        //			{"@pyearid", yid },
        //			{"@pclassid", ddlClass.SelectedValue },
        //			{"@psectionid", ddlSection.SelectedValue }
        //		}, true);
        //	cblDue.DataSource = db.Query("getStudentByTUNYCSId",
        //		new Dictionary<string, object>() {
        //			{"@TUN", User.Identity.Name},
        //			{"@YCSId", ycsId },
        //			{"@pdue", Convert.ToInt32(txtDueGreaterThen.Text.Length==0?"0":txtDueGreaterThen.Text) }
        //		}, true).Select(x => new TextValuePair {
        //			Text = x["student"],
        //			Value = x["studentid"]
        //		}).ToList();
        //	cblDue.DataBind();
        //}

        private List <TextValuePair> getStudents()
        {
            MySQLDatabase db  = new MySQLDatabase();
            var           yid = db.QueryValue("getYearId", new Dictionary <string, object>()
            {
                { "@pyear", DateTime.Now.Year }
            }, true);
            var ycsId = db.QueryValue("getYearClassSectionId",
                                      new Dictionary <string, object>()
            {
                { "@pyearid", yid },
                { "@pclassid", ddlClass.SelectedValue },
                { "@psectionid", ddlSection.SelectedValue }
            }, true);

            return(db.Query("getStudentByTUNYCSId",
                            new Dictionary <string, object>()
            {
                { "@TUN", User.Identity.Name },
                { "@YCSId", ycsId }
            }, true).Select(x => new TextValuePair {
                Text = x["student"],
                Value = x["studentid"]
            }).ToList());
        }
Esempio n. 26
0
        protected void LoadCBAdd(object obj, EventArgs e)
        {
            //TODO remove students who are already in the group
            MySQLDatabase db     = new MySQLDatabase();
            var           yearId = db.QueryValue("getYearId", new Dictionary <string, object>()
            {
                { "@pyear", DateTime.Now.Year }
            }, true);
            var YCSId = db.QueryValue("getYearClassSectionId",
                                      new Dictionary <string, object>()
            {
                { "@pyearid", yearId },
                { "@pclassid", ddlClass.SelectedValue },
                { "@psectionid", ddlSection.SelectedValue }
            }, true);

            cbAdd.DataSource = db.Query("getStudentByTUNYCSId",
                                        new Dictionary <string, object>()
            {
                { "@TUN", User.Identity.Name },
                { "@YCSId", YCSId }
            }, true).Select(x => new {
                Text  = x["firstname"] + x["lastname"],
                Value = x["studentid"]
            }).ToList();
            cbAdd.DataBind();
        }
Esempio n. 27
0
        private void LoadStudentClass()
        {
            MySQLDatabase db     = new MySQLDatabase();
            var           yearId = db.QueryValue("getYearId", new Dictionary <string, object>()
            {
                { "@pyear", DateTime.Now.Year }
            }, true);

            ddlClass.DataSource = db.Query(
                "getClassByYId",
                new Dictionary <string, object>()
            {
                { "@YId", yearId }
            },
                true)
                                  .Select(x => new {
                Text  = x["class"],
                Value = x["classid"]
            }).ToList();
            ddlClass.DataBind();

            if (ddlClass.Items.Count > 0)
            {
                ReloadDDLSection(yearId);
            }
            else
            {
                ddlSection.Items.Clear();
            }
        }
Esempio n. 28
0
        private void ReloadDDLSection(object yearId)
        {
            MySQLDatabase db = new MySQLDatabase();

            ddlSection.DataSource = db.Query(
                "getSectionByYIdCId",
                new Dictionary <string, object>()
            {
                { "@YId", yearId },
                { "@CId", Convert.ToInt32(ddlClass.SelectedValue) }
            }, true)
                                    .Select(x => new {
                Text  = x["section"],
                Value = x["sectionid"]
            }).ToList();
            ddlSection.DataBind();

            if (ddlSection.Items.Count > 0)
            {
                ReloadDDLCanTransact(yearId);
            }
            else
            {
                ddlTransact.Enabled = false;
            }
            hInfo.Visible = false;
        }
Esempio n. 29
0
        private void LoadDDLDesignation()
        {
            MySQLDatabase db = new MySQLDatabase();

            ddlDesignation.DataSource = db.Query("getAllDesignation", null, true).Select(x => new { Text = x["designation"], Value = x["id"] }).ToList();
            ddlDesignation.DataBind();

            ChangeDDLDesignationAsDDLTeacher(null, null);
        }
Esempio n. 30
0
        protected void BindGridView(object o, EventArgs e)
        {
            if (ViewState["YCSId"] == null)
            {
                ReloadYCSId(null, null);
            }

            MySQLDatabase db        = new MySQLDatabase();
            var           teacherId = new UserTable <ApplicationUser>(db).GetUserId(User.Identity.Name);
            List <Dictionary <string, string> > res2;

            if (ddlSubject.SelectedValue == "all")
            {
                res2 = db.Query("getMarkPortionByYCSId", new Dictionary <string, object>()
                {
                    { "@YCSId", ViewState["YCSId"] }
                }, true);
            }
            else
            {
                res2 = db.Query("getMarkPortionByTSId", new Dictionary <string, object>()
                {
                    { "@TSId", ddlSubject.SelectedValue }
                }, true);
            }
            var query = from x in res2
                        let v = db.Query("getMarkByMPIdSIdTid",
                                         new Dictionary <string, object>()
            {
                { "@MPId", x["markportionid"] },
                { "@SId", ddlStudent.SelectedValue },
                { "@Tid", ddlTerm.SelectedValue }
            }, true)
                                select new {
                Subject       = (v.Count == 0) ? null : v[0]["subject"],
                PortionName   = x["portionname"],
                MarkPortionId = x["markportionid"],
                Mark          = (v.Count == 0) ? null : v[0]["mark"],
                MarkId        = (v.Count == 0) ? null : v[0]["markid"]
            };

            gvMark.DataSource = query.ToList();
            gvMark.DataBind();
        }
 private void ForgetPasswordFrm_Load(object sender, EventArgs e)
 {
     _db = ((LoginFrm)Parent)._db;
     _db.SQLCommand = "SELECT tech_question, tech_answer, tech_password FROM teacher WHERE tech_username='******'";
     _db.Query();
     _db.Result.Read();
     txtQuestion.Text = (string)_db.Result.GetValue(0);
     _answer = (string)_db.Result.GetValue(1);
     _password = (string)_db.Result.GetValue(2);
 }
Esempio n. 32
0
        protected void LoadStudent(object o, EventArgs e)
        {
            MySQLDatabase db        = new MySQLDatabase();
            var           teacherId = Context.GetOwinContext().GetUserManager <ApplicationUserManager>().FindByName(User.Identity.Name).Id;

            if (ddlSubject.SelectedValue == "all")
            {
                ddlStudent.DataSource = db.Query(
                    "getStudentByTUNYCSId",
                    new Dictionary <string, object>()
                {
                    { "@TUN", User.Identity.Name },
                    { "@ycsid", ViewState["YCSId"] }
                },
                    true).Select(x => new {
                    Text  = x["student"],
                    Value = x["studentid"]
                }).ToList();
                ddlStudent.DataTextField  = "Text";
                ddlStudent.DataValueField = "Value";
                ddlStudent.DataBind();
            }
            else
            {
                ddlStudent.DataSource = db.Query(
                    "getStudentByTUNYCSIdSId",
                    new Dictionary <string, object>()
                {
                    { "@TUN", User.Identity.Name },
                    { "@YCSId", ViewState["YCSId"] },
                    { "@SId", ddlSubject.SelectedValue }
                },
                    true).Select(x => new {
                    Text  = x["student"],
                    Value = x["studentid"]
                }).ToList();
                ddlStudent.DataTextField  = "Text";
                ddlStudent.DataValueField = "Value";
                ddlStudent.DataBind();
            }

            //BindGridView(null, null);
        }
Esempio n. 33
0
        protected void LoadGridview()
        {
            var data = new MySQLDatabase();

            if (ddlMemberType.SelectedValue == "1")
            {
                gvNotApprovedMember.Visible = false;
                gvApprovedMembers.Visible   = true;
                var members = data.Query("GetAllApprovedMember",
                                         new Dictionary <string, object> {
                }, true);
                gvApprovedMembers.DataSource = members.Select(x => new
                {
                    uid          = x["Id"],
                    memberNumber = x["member_number"],
                    userName     = x["UserName"],
                    email        = x["Email"],
                    phone        = x["PhoneNumber"],
                    memberType   = x["type"],
                    DateRegister = Convert.ToDateTime(x["date_registered"]).ToString("dd-MM-yyyy"),
                }).ToList();
                gvApprovedMembers.DataBind();
            }
            else
            {
                gvApprovedMembers.Visible   = false;
                gvNotApprovedMember.Visible = true;
                var members = data.Query("GetAllNotApprovedMemmbers", new Dictionary <string, object> {
                }, true);

                gvNotApprovedMember.DataSource = members.Select(x => new
                {
                    uid          = x["Id"],
                    userName     = x["UserName"],
                    email        = x["Email"],
                    phone        = x["PhoneNumber"],
                    memberType   = x["type"],
                    DateRegister = Convert.ToDateTime(x["date_registered"]).ToString("dd-MM-yyyy"),
                }).ToList();
                gvNotApprovedMember.DataBind();
            }
        }
        private void AddEcitRegistrationFrm_Load(object sender, EventArgs e)
        {
            // Init database
            _db = ((MainFrm)Parent)._db;

            // For branch combobox
            _db.SQLCommand = "SELECT * FROM subject";
            _db.Query();
            while (_db.Result.Read())
            {
                cmbSubName.Items.Add((string)_db.Result.GetValue(2));
                _lstSubject.Add(new Subject { ID = (int)_db.Result.GetValue(0), SubjectID = (string)_db.Result.GetValue(1), SubjectName = (string)_db.Result.GetValue(2) });
            }

            // For Edit mode
            if (EditMode == true)
            {
                // Diable object
                txtStdID.Enabled = false;
                cmbYear.Enabled = false;

                // Retrieve data
                _db.SQLCommand = "SELECT * FROM registration WHERE reg_id='" + RegID + "'";
                _db.Query();
                if (_db.Result.HasRows)
                {
                    _db.Result.Read();
                    txtSubID.Text = LookupSubjectIDByID((int)_db.Result.GetValue(1));
                    cmbSubName.Text = LookupSubjectNameByID((int)_db.Result.GetValue(1));
                    txtStdID.Text = (string)_db.Result.GetValue(2);
                    cmbYear.Text = (string)_db.Result.GetValue(3);

                    // For student name
                    _db.SQLCommand = "SELECT std_name FROM student WHERE std_id='" + txtStdID.Text + "'";
                    _db.Query();
                    _db.Result.Read();
                    txtStdName.Text = (string)_db.Result.GetValue(0);
                }
            }
        }
        private void UserSettingFrm_Load(object sender, EventArgs e)
        {
            _db = ((MainFrm)Parent)._db;
            _db.SQLCommand = "SELECT * FROM teacher WHERE tech_id='" + TechID + "'";
            _db.Query();
            _db.Result.Read();

            txtName.Text = (string)_db.Result.GetValue(1);
            txtUsername.Text = (string)_db.Result.GetValue(3);
            txtPassword.Text = (string)_db.Result.GetValue(4);
            cmbQuestion.Text = (string)_db.Result.GetValue(7);
            txtAnswer.Text = (string)_db.Result.GetValue(8);
        }
 private void AddEditSubjectFrm_Load(object sender, EventArgs e)
 {
     _db = ((MainFrm)Parent)._db;
     if (EditMode == true)
     {
         _db.SQLCommand = "SELECT * FROM subject WHERE sub_id='" + SubjectID + "'";
         _db.Query();
         if (_db.Result.HasRows)
         {
             _db.Result.Read();
             txtSubID.Text = (string)_db.Result.GetValue(1);
             txtSubName.Text = (string)_db.Result.GetValue(2);
         }
     }
 }
 private bool IsForce80Checkin(string tech_id)
 {
     MySQLDatabase db = new MySQLDatabase();
     db.DBServer = _db.DBServer;
     db.DBUser = _db.DBUser;
     db.DBPassword = _db.DBPassword;
     db.DBName = _db.DBName;
     db.Connect();
     db.SQLCommand = "SELECT force_f_checkin FROM score_rating";
     db.Query();
     bool ret = false;
     if (db.Result.Read())
     {
         if ((int)db.Result["force_f_checkin"] == 1)
         {
             ret = true;
         }
     }
     db.Close();
     return ret;
 }
Esempio n. 38
0
        private void btnGenOPD_Click(object sender, EventArgs e)
        {
            try
            {
                txtVNOPD.Text = "";
                cmbVSDateOPD.Items.Clear();
                m_map.Clear();

                if (m_db != null && m_db.IsConnect())
                {
                    // Get HN from ipt table.
                    m_db.SQLCommand = "SELECT * FROM ovst WHERE hn='" + txtHNOPD.Text + "' ORDER BY vstdate DESC, vsttime DESC;";
                    if (m_db.Query() == false)
                    {
                        MessageBox.Show("There is no data for hn = " + txtHNOPD.Text + ". Please check.");
                        m_db.Result.Close();

                        // Clear
                        chkBlankOPD.Enabled = false;
                        dgViewOPD.Rows.Clear();
                        cmbVSDateOPD.Text = "";
                        pictureBoxOPD.Image = null;

                        return;
                    }

                    // Fill data in combo box
                    MySQLDatabase db = new MySQLDatabase();
                    db.DBServer = m_server;
                    db.DBUser = m_username;
                    db.DBPassword = m_password;
                    db.DBName = m_dbName;
                    db.Connect();
                    db.SQLCommand = "USE " + m_dbName + ";";
                    db.Query();
                    db.Result.Close();

                    string vstdate = null;
                    string vsttime = null;
                    string time = null;
                    string vn = null;
                    string hn = null;
                    string fname = null;
                    string lname = null;

                    while (m_db.Result.Read())
                    {
                        // Retrieve ovst's information
                        vn = (string)m_db.Result["vn"];
                        hn = (string)m_db.Result["hn"];
                        vstdate = ((DateTime)m_db.Result["vstdate"]).ToString("dd-MM-yyyy");
                        vsttime = (m_db.Result["vsttime"]).ToString();

                        // Retrieve patient's information
                        db.SQLCommand = "SELECT * FROM patient WHERE hn='" + hn + "';";
                        db.Query();
                        db.Result.Read();
                        fname = (string)db.Result["fname"];
                        lname = (string)db.Result["lname"];
                        db.Result.Close();

                        // Build timestamp
                        time = vstdate + "  " + vsttime;

                        // Add item to combo box
                        cmbVSDateOPD.Items.Add(time);

                        // Add to map
                        m_map.Add(time, new OVST { vn = vn, hn = hn, fname = fname, lname = lname });
                    }
                    cmbVSDateOPD.SelectedIndex = 0;
                    m_db.Result.Close();
                    db.Close();

                    // Disable checkbox if no item to be printed.
                    if (m_map.Count == 0)
                    {
                        chkBlankOPD.Enabled = false;
                    }
                    else
                    {
                        chkBlankOPD.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private double GetCheckinScore(string tech_id, string reg_id)
        {
            MySQLDatabase db = new MySQLDatabase();
            db.DBServer = _db.DBServer;
            db.DBUser = _db.DBUser;
            db.DBPassword = _db.DBPassword;
            db.DBName = _db.DBName;
            db.Connect();

            // Calculate checkin's score, the fomular is (15/10) = (20/x)
            double checkinScore = 0;   // This will calculate later.

            // Get a number of checkin's dates
            int countChkDate = 0;
            db.SQLCommand = "SELECT COUNT(date) FROM checkin_date WHERE tech_id='" + tech_id + "'";
            db.Query();
            if (db.Result.Read())
            {
                countChkDate = Convert.ToInt16(db.Result.GetValue(0));
            }
            else
            {
                countChkDate = 0;
            }

            // Get setting checkin score
            double settingChkinScore = 0;
            db.SQLCommand = "SELECT checkin FROM score_rating WHERE tech_id='" + tech_id + "'";
            db.Query();
            if (db.Result.Read())
            {
                settingChkinScore = Convert.ToInt16(db.Result["checkin"]);
            }
            else
            {
                settingChkinScore = 0;
            }

            // Get a number of checkin
            double countChkNormal = 0;
            db.SQLCommand = "SELECT COUNT(reg_id) FROM checkin WHERE reg_id='" + reg_id + "' AND status IN ('normal', 'absence')";
            db.Query();
            if (db.Result.Read())
            {
                countChkNormal = Convert.ToInt16(db.Result.GetValue(0));
            }
            else
            {
                countChkNormal = 0;
            }

            double countChkLate = 0;
            db.SQLCommand = "SELECT COUNT(reg_id) FROM checkin WHERE reg_id='" + reg_id + "' AND status='late'";
            db.Query();
            if (db.Result.Read())
            {
                countChkLate = Convert.ToInt16(db.Result.GetValue(0)) * 0.5;
            }
            else
            {
                countChkNormal = 0;
            }

            db.Close();

            // Then calculate the score
            if (countChkDate != 0)
            {
                checkinScore = (settingChkinScore * (countChkNormal + countChkLate)) / countChkDate;
            }
            return checkinScore;
        }
        private bool Check80OfCheckin(string tech_id, string reg_id)
        {
            // Get Checkin Count.
            MySQLDatabase db = new MySQLDatabase();
            db.DBServer = _db.DBServer;
            db.DBUser = _db.DBUser;
            db.DBPassword = _db.DBPassword;
            db.DBName = _db.DBName;
            db.Connect();

            // Calculate checkin's score, the fomular is (15/10) = (20/x)
            double checkinScore = 0;   // This will calculate later.

            // Get a number of checkin's dates
            int countChkDate = 0;
            db.SQLCommand = "SELECT COUNT(date) FROM checkin_date WHERE tech_id='" + tech_id + "'";
            db.Query();
            if (db.Result.Read())
            {
                countChkDate = Convert.ToInt16(db.Result.GetValue(0));
            }
            else
            {
                countChkDate = 0;
            }

            // Get a number of checkins.
            int countChk = 0;
            db.SQLCommand = "SELECT COUNT(reg_id) FROM checkin WHERE reg_id='" + reg_id + "'";
            db.Query();
            if (db.Result.Read())
            {
                countChk = Convert.ToInt16(db.Result.GetValue(0));
            }
            else
            {
                countChk = 0;
            }

            db.Close();

            // Calculate
            int countNeedCheckin = (80 * countChkDate) / 100;
            if (countChk >= countNeedCheckin)
            {
                return false;
            }

            return true;
        }
        private void AddEditStudentFrm_Load(object sender, EventArgs e)
        {
            // Init Database
            _db = ((MainFrm)Parent)._db;

            // Init FP engine
            _fpEngine = new AxZKFPEngX();
            _fpEngine.BeginInit();
            _fpEngine.OnEnroll += new IZKFPEngXEvents_OnEnrollEventHandler(_fpEngine_OnEnroll);
            _fpEngine.OnImageReceived += new IZKFPEngXEvents_OnImageReceivedEventHandler(_fpEngine_OnImageReceived);
            this.Controls.Add(_fpEngine);

            if (_fpEngine.InitEngine() != 0)
            {
                MessageBox.Show("ไม่สามารถติดต่อเครื่องสแกนลายนิ้วมือได้", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                _fpDeviceConnect = false;
            }
            else
            {
                _fpDeviceConnect = true;
            }

            // For Edit mode
            if (EditMode == true)
            {
                _db.SQLCommand = "SELECT * FROM student WHERE std_id='" + StudentID + "'";
                _db.Query();
                if (_db.Result.HasRows)
                {
                    _db.Result.Read();
                    txtStdID.Text = (string)_db.Result.GetValue(0);
                    txtStdName.Text = (string)_db.Result.GetValue(1);
                    txtStdMajor.Text = (string)_db.Result.GetValue(2);
                    if (_db.Result.GetValue(3) == null)
                    {
                        txtFinger.Text = "";
                    }
                    else
                    {
                        txtFinger.Text = (string)_db.Result.GetValue(3);
                    }
                }
            }
        }
        private void LoadRegisterToDGV(string sqlCmd)
        {
            AddColumnForStudentDGV();
            // Clear DGV
            dgvStudent.Rows.Clear();
            // Query all teacher.
            _db.SQLCommand = sqlCmd;
            _db.Query();

            if (_db.Result.HasRows == false)
            {
                //MessageBox.Show("ไม่มีรายการที่ต้องการแสดง", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //return;
            }

            // Insert rows to DGV
            int order = 0;
            while (_db.Result.Read())
            {
                order++;
                if ((string)_db.Result.GetValue(2) != "")
                {
                    dgvStudent.Rows.Add(
                        order.ToString(),
                        _db.Result["std_id"],
                        _db.Result["std_name"],
                        "scaned",
                        _db.Result["reg_id"],
                        LoadImage("finger2.png")
                        );
                }
                else
                {
                    dgvStudent.Rows.Add(
                        order.ToString(),
                        _db.Result["std_id"],
                        _db.Result["std_name"],
                        "noscan",
                        _db.Result["reg_id"],
                        LoadImage("nofinger2.png")
                        );
                }
            }

            int tech_id = (int)dgvSubject.CurrentRow.Cells["TechID"].Value;

            // Load others groups
            _db.SQLCommand = "SELECT * FROM checkin_date WHERE tech_id='" + tech_id + "' ORDER BY date";
            _db.Query();
            if (_db.Result.HasRows == true)
            {
                while (_db.Result.Read() == true)
                {
                    // Image column
                    DataGridViewImageColumn imgCol = new DataGridViewImageColumn();
                    imgCol.HeaderText = _db.Result["date"] as string;
                    imgCol.Width = 70;
                    int idx = dgvStudent.Columns.Add(imgCol);

                    // Status column
                    DataGridViewTextBoxColumn statusCol = new DataGridViewTextBoxColumn();
                    statusCol.HeaderText = _db.Result["date"] as string;
                    statusCol.Width = 70;
                    statusCol.Visible = false; // Status column
                    int idxStatus = dgvStudent.Columns.Add(statusCol);

                    MySQLDatabase localDB = new MySQLDatabase();
                    localDB.DBUser = _db.DBUser;
                    localDB.DBPassword = _db.DBPassword;
                    localDB.DBServer = _db.DBServer;
                    localDB.DBName = _db.DBName;
                    localDB.Connect();

                    foreach (DataGridViewRow item in dgvStudent.Rows)
                    {
                        string regID = Convert.ToString(item.Cells[4].Value); // TechID
                        string hisDate = imgCol.HeaderText;

                        // Must use a new db connection.
                        localDB.SQLCommand = "SELECT * FROM checkin WHERE date='" + hisDate + "' AND reg_id='" + regID + "'";
                        localDB.Query();

                        if (localDB.Result.HasRows == true)
                        {
                            localDB.Result.Read();
                            if (localDB.Result["status"] as string == "normal")
                            {
                                item.Cells[idx].Value = LoadImage("normal.png");
                                item.Cells[idxStatus].Value = "normal";
                            }
                            else if (localDB.Result["status"] as string == "absence")
                            {
                                item.Cells[idx].Value = LoadImage("absence.png");
                                item.Cells[idxStatus].Value = "absence";
                            }
                            else
                            {
                                item.Cells[idx].Value = LoadImage("late.png");
                                item.Cells[idxStatus].Value = "late";
                            }
                        }
                        else
                        {
                            item.Cells[idx].Value = LoadImage("uncheck.png");
                            item.Cells[idxStatus].Value = "uncheck";
                        }
                    }
                    localDB.Close();
                }
            }
        }
Esempio n. 43
0
        private void Form1_Load(object sender, EventArgs e)
        {
            this.FormClosed +=new FormClosedEventHandler(mainFrm_FormClosed);

            // Init controls
            txtHN.Enabled = false;
            txtFirstName.Enabled = false;
            txtLastName.Enabled = false;
            pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;

            txtVNOPD.Enabled = false;

            // Init datagrid view.
            dgView.AllowUserToAddRows = false;
            dgView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dgView.MultiSelect = false;
            dgView.ColumnCount = 1;
            dgView.Columns[0].HeaderText = "Barcode Label";
            dgView.Columns[0].Width = 250;

            dgViewOPD.AllowUserToAddRows = false;
            dgViewOPD.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dgViewOPD.MultiSelect = false;
            dgViewOPD.SelectionChanged += new EventHandler(dgViewOPD_SelectionChanged);
            dgViewOPD.CellContentClick += new DataGridViewCellEventHandler(dgViewOPD_CellContentClick);

            m_dgvColor = dgViewOPD.BackgroundColor;

            DataGridViewCheckBoxColumn chkCol = new DataGridViewCheckBoxColumn();
            chkCol.HeaderText = "";
            chkCol.Width = 30;
            dgViewOPD.Columns.Insert(0, chkCol);

            DataGridViewTextBoxColumn txtCol = new DataGridViewTextBoxColumn();
            txtCol.HeaderText = "Barcode Label";
            txtCol.Width = 250;
            dgViewOPD.Columns.Insert(1, txtCol);

            DataGridViewTextBoxColumn txtCol2 = new DataGridViewTextBoxColumn();
            txtCol2.HeaderText = "Hidden";
            txtCol2.Width = 50;
            txtCol2.Visible = false;
            dgViewOPD.Columns.Insert(2, txtCol2);

            // Init controls
            cmbVSDateOPD.SelectedIndexChanged += new EventHandler(cmbVSDateOPD_SelectedIndexChanged);
            chkBlankOPD.CheckedChanged += new EventHandler(chkBlankOPD_CheckedChanged);
            chkBlankOPD.Enabled = false;

            // Load config
            LoadFromXML();

            // Load previous data before closing form.
            if (File.Exists("savedata.txt") == true)
            {
                StreamReader sr = new StreamReader("savedata.txt");
                string line = sr.ReadLine();
                if (line != null)
                {
                    txtAN.Text = line.Substring(3);
                }
                line = sr.ReadLine();
                if (line != null)
                {
                    txtHNOPD.Text = line.Substring(3);
                }
                if (txtAN.Text != "")
                {
                    m_AN = Convert.ToInt32(txtAN.Text);
                }
                if (txtHNOPD.Text != "")
                {
                    m_HNOPD = Convert.ToInt32(txtHNOPD.Text);
                }
                sr.Close();
            }

            // Load history printing.
            ReloadHistory();

            if (tabControl.SelectedTab.Name == "tabPageIPD")
            {
                txtAN.Select();
            }
            else
            {
                txtHNOPD.Select();
            }

            try
            {
                // Init database
                m_db = new MySQLDatabase();
                m_db.DBServer = m_server;
                m_db.DBUser = m_username;
                m_db.DBPassword = m_password;
                m_db.DBName = m_dbName;
                m_db.Connect();
                m_db.SQLCommand = "USE " + m_dbName + ";";
                m_db.Query();
                m_db.Result.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void ScoreRateFrm_Load(object sender, EventArgs e)
        {
            // Init database
            _db = ((MainFrm)Parent)._db;

            // Load current score setting
            _db.SQLCommand = "SELECT * FROM score_rating WHERE tech_id='" + TeachingID + "'";
            _db.Query();
            // If the subject has been already set score rating
            if (_db.Result.Read() == true)
            {
                txtA.Text = _db.Result["a"].ToString();
                txtBP.Text = _db.Result["bp"].ToString();
                txtB.Text = _db.Result["b"].ToString();
                txtCP.Text = _db.Result["cp"].ToString();
                txtC.Text = _db.Result["c"].ToString();
                txtDP.Text = _db.Result["dp"].ToString();
                txtD.Text = _db.Result["d"].ToString();
                txtF.Text = _db.Result["f"].ToString();
                txtMid.Text = _db.Result["mid"].ToString();
                txtFinal.Text = _db.Result["final"].ToString();
                txtCheckin.Text = _db.Result["checkin"].ToString();
                txtScore1.Text = _db.Result["score1"].ToString();
                txtScore2.Text = _db.Result["score2"].ToString();
                txtScore3.Text = _db.Result["score3"].ToString();
                txtScore4.Text = _db.Result["score4"].ToString();
                txtScore5.Text = _db.Result["score5"].ToString();
                txtScore1Title.Text = _db.Result["score1_title"].ToString();
                txtScore2Title.Text = _db.Result["score2_title"].ToString();
                txtScore3Title.Text = _db.Result["score3_title"].ToString();
                txtScore4Title.Text = _db.Result["score4_title"].ToString();
                txtScore5Title.Text = _db.Result["score5_title"].ToString();
                txtScoreLab.Text = _db.Result["score_lab"].ToString();

                if ((int)_db.Result["force_f_checkin"] == 0)
                {
                    chkForce.Checked = false;
                }
                else
                {
                    chkForce.Checked = true;
                }

                if (LabMode == true)
                {
                    txtScoreLab.Text = _db.Result["score_lab"].ToString();
                }

                if (_db.Result["score_type"].ToString() == "grade")
                {
                    cmbType.SelectedIndex = 1;
                }
                else
                {
                    cmbType.SelectedIndex = 0;
                }

                _reallyCalcuate = false;
                btnCalc_Click(null, null);
            }
            else
            {
                cmbType.SelectedIndex = 1;
            }

            if (LabMode == true)
            {
                txtScoreLab.Visible = false;
                labScoreLab.Visible = false;
                labStar.Visible = false;
            }

            _ready = true;  // To prevent crash we this flag.
        }
        private double GetLabScore(string stdID)
        {
            double labScore = 0.0;

            MySQLDatabase localDB = new MySQLDatabase();
            localDB.DBServer = _db.DBServer;
            localDB.DBName = _db.DBName;
            localDB.DBUser = _db.DBUser;
            localDB.DBPassword = _db.DBPassword;
            localDB.Connect();

            // Get Lab Subject of Lec Subject
            localDB.SQLCommand = "SELECT * FROM subject WHERE sub_lec='" + dgvSubject.CurrentRow.Cells["SubLec"].Value as string + "' AND sub_lab<>''";
            localDB.Query();

            while (localDB.Result.Read())
            {
                // STD + Lab + Year Sub ID, look up in registration
                MySQLDatabase regDB = new MySQLDatabase();
                regDB.DBServer = _db.DBServer;
                regDB.DBName = _db.DBName;
                regDB.DBUser = _db.DBUser;
                regDB.DBPassword = _db.DBPassword;
                regDB.Connect();
                regDB.SQLCommand = "SELECT * FROM registration WHERE sub_id='" + (int)localDB.Result["id"] + "' AND std_id='" + stdID + "' AND year='" + dgvSubject.CurrentRow.Cells["SubYear"].Value + "'";
                regDB.Query();
                while (regDB.Result.Read())
                {
                    // REGID look up in score
                    int regid = (int)regDB.Result["reg_id"];
                    MySQLDatabase scoreDB = new MySQLDatabase();
                    scoreDB.DBServer = _db.DBServer;
                    scoreDB.DBName = _db.DBName;
                    scoreDB.DBUser = _db.DBUser;
                    scoreDB.DBPassword = _db.DBPassword;
                    scoreDB.Connect();
                    scoreDB.SQLCommand = "SELECT * FROM score WHERE reg_id='" + regid + "'";
                    scoreDB.Query();

                    // A = Sum all score
                    double all_score = 0;
                    if (scoreDB.Result.Read())
                    {
                        all_score = (int)scoreDB.Result["mid"] + (int)scoreDB.Result["final"] + (int)scoreDB.Result["score1"] +
                                    (int)scoreDB.Result["score2"] + (int)scoreDB.Result["score3"] + (int)scoreDB.Result["score4"] +
                                    (int)scoreDB.Result["score5"];

                        // TechID + SubID + Year, look up in teaching
                        MySQLDatabase techingDB = new MySQLDatabase();
                        techingDB.DBServer = _db.DBServer;
                        techingDB.DBName = _db.DBName;
                        techingDB.DBUser = _db.DBUser;
                        techingDB.DBPassword = _db.DBPassword;
                        techingDB.Connect();

                        techingDB.SQLCommand = "SELECT * FROM teaching WHERE tech_id='" + TechID + "' AND sub_id='" + localDB.Result["id"].ToString() + "' AND year='" + dgvSubject.CurrentRow.Cells["SubYear"].Value + "'";
                        techingDB.Query();
                        techingDB.Result.Read();

                        all_score += GetCheckinScore(techingDB.Result["id"].ToString(), regid.ToString());

                        techingDB.Close();
                    }

                    // B = Get Lab's score from score_rating
                    scoreDB.SQLCommand = "SELECT * FROM score_rating WHERE tech_id='" + dgvSubject.CurrentRow.Cells["TechID"].Value + "'";
                    scoreDB.Query();

                    double scoreLab = 0;
                    if (scoreDB.Result.Read())
                    {
                        scoreLab = (int)scoreDB.Result["score_lab"];
                    }

                    // Real score = (A * B)/100
                    labScore = (all_score * scoreLab) / 100;

                    scoreDB.Close();
                }
                regDB.Close();
            }
            localDB.Close();
            return labScore;
        }