Ejemplo n.º 1
0
        protected void btnNew_Click(object sender, System.EventArgs e)
        {
            DateTime dtStart, dtEnd;

            try
            {
                dtStart = DateTime.Parse(txttimeStart.Text);
                dtEnd   = DateTime.Parse(txtTimeEnd.Text);
            }
            catch
            {
                Response.Write(MyUtility.Alert("输入错误"));
                return;
            }
            StreamWriter sw = new StreamWriter("C:/Users/ted/Desktop/Graduation Design/选课系统/time.txt", false);

            sw.WriteLine(dtStart.ToString());
            sw.WriteLine(dtEnd.ToString());
            sw.Close();
            lbTime.Text          = "选课时间为:" + dtStart.ToString() + "到" + dtEnd.ToString();
            Label2.Visible       = false;
            Label3.Visible       = false;
            Label1.Visible       = false;
            txttimeStart.Visible = false;
            btnNew.Visible       = false;
            txtTimeEnd.Visible   = false;
        }
Ejemplo n.º 2
0
        protected void btnUpdate_Click(object sender, System.EventArgs e)
        {
            try
            {
                int age = Int32.Parse(txtSAge.Text.Trim());
            }
            catch
            {
                Response.Write(MyUtility.Alert("请正确输入年龄!"));
                return;
            }
            string sql = "update Student set SName = '" + txtSName.Text.Trim() + "'" +
                         ",SSex = '" + ddlSSex.SelectedItem.Text + "'" +
                         ",SAge = " + txtSAge.Text.Trim() +
                         ",SAddress = '" + txtSAddress.Text.Trim() + "'" +
                         ",SPhone = '" + txtSPhone.Text.Trim() + "'" +
                         " where SId like '" + Session["Id"].ToString() + "'";

            if (Db.ExecuteSql(sql) == 1)
            {
                Response.Write(MyUtility.Alert("修改成功!"));
            }
            else
            {
                Response.Write(MyUtility.Alert("修改失败!"));
            }
        }
Ejemplo n.º 3
0
        private void dgSC_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            string sid       = dgSC.DataKeys[e.Item.ItemIndex].ToString().Trim();
            string str_score = ((TextBox)(e.Item.Cells[2].Controls[0])).Text;
            float  score     = 0;

            try
            {
                score = float.Parse(str_score);
            }
            catch
            {
                Response.Write(MyUtility.Alert("请正确输入"));
                Response.Write(MyUtility.Back(-1));
            }
            float   preScore = 0;
            string  sql      = "select Score from SC where CId = " + lbCId.Text + " and SId like '" + sid + "'";
            DataSet ds       = Db.ExecuteSelectSql(sql);

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                preScore = float.Parse(ds.Tables[0].Rows[0][0].ToString());
            }
            int flag = 0;

            if (preScore < 60 && score > 60)   //成绩合格学风增加
            {
                flag = 1;
            }
            else if (preScore > 60 && score < 60)  //不合格学分减少
            {
                flag = -1;
            }
            if (flag != 0)
            {
                sql = "select CCredit from Course where CId = " + lbCId.Text;
                DataSet ds1 = Db.ExecuteSelectSql(sql);
                if (ds1 != null && ds1.Tables.Count > 0 && ds1.Tables[0].Rows.Count > 0)
                {
                    float credit = (float)flag * float.Parse(ds1.Tables[0].Rows[0][0].ToString());
                    sql = "update SC set Score = " + score.ToString() + " where CId = " + lbCId.Text + " and SId like '" + sid + "'";
                    Db.ExecuteSql(sql);
                    sql = "update Student set SCredit = SCredit + " + credit.ToString() + " where SId like '" + sid + "'";
                    Db.ExecuteSql(sql);
                }
            }
            dgSC.EditItemIndex = -1;
            sql = "select SC.*,SName from SC,Student where CId = " + lbCId.Text + " and SC.SId like Student.SId";
            DataSet ds2 = Db.ExecuteSelectSql(sql);

            if (ds2 != null && ds2.Tables.Count > 0)
            {
                dgSC.DataSource   = ds2.Tables[0];
                dgSC.DataKeyField = "SId";
                dgSC.DataBind();
            }
        }
Ejemplo n.º 4
0
        protected void btnUpdateKey_Click(object sender, System.EventArgs e)
        {
            if (txtKey.Text.Trim() != txtKeyConfirm.Text.Trim())
            {
                Response.Write(MyUtility.Alert("两次输入密码不相符合"));
                return;
            }
            string sql = "update Student set SKey = '" + MyUtility.MD5(txtKey.Text.Trim()) + "' where SId = '" + Session["Id"].ToString() + "'";

            if (Db.ExecuteSql(sql) == 1)
            {
                Response.Write(MyUtility.Alert("修改成功!"));
            }
            else
            {
                Response.Write(MyUtility.Alert("修改失败!"));
            };
        }
Ejemplo n.º 5
0
        protected void lkbView_Click(object sender, System.EventArgs e)
        {
            if (ddlBuilding.SelectedIndex < 0)
            {
                Response.Write(MyUtility.Alert("请选择一个教学楼!"));
                return;
            }
            dgView.DataSource = null;
            dgView.DataBind();
            string  sql = "select RoomId,RoomName,RoomSize from Room where BuildingId = " + ddlBuilding.SelectedItem.Value;
            DataSet ds  = Db.ExecuteSelectSql(sql);

            if (ds != null && ds.Tables.Count > 0)
            {
                dgView.DataSource = ds.Tables[0];

                dgView.DataBind();
            }
        }
Ejemplo n.º 6
0
        protected void btnAddRoom_Click(object sender, System.EventArgs e)
        {
            if (ddlBuilding.SelectedIndex < 0)
            {
                Response.Write(MyUtility.Alert("请选择一个教学楼!"));
                return;
            }
            if (txtRoomName.Text.Trim() == "")
            {
                Response.Write(MyUtility.Alert("请选输入教室名称!"));
                return;
            }
            if (txtRoomSize.Text.Trim() == "")
            {
                Response.Write(MyUtility.Alert("请输入教室能容纳的人数!"));
                return;
            }
            int size = 0;

            try
            {
                size = Int32.Parse(txtRoomSize.Text.Trim());
            }
            catch
            {
                Response.Write(MyUtility.Alert("请输入正确的教室能容纳的人数!"));
                return;
            }
            string sql = "insert into Room(RoomName,BuildingId,RoomSize) values('" + txtRoomName.Text.Trim() + "'," + ddlBuilding.SelectedItem.Value + "," + size.ToString() + ")";

            Db.ExecuteSql(sql);
            sql = "select RoomId,RoomName,RoomSize from Room where BuildingId = " + ddlBuilding.SelectedItem.Value;
            DataSet ds = Db.ExecuteSelectSql(sql);

            if (ds != null && ds.Tables.Count > 0)
            {
                dgView.DataSource = ds.Tables[0];
                dgView.DataBind();
            }
        }
Ejemplo n.º 7
0
        private void SelectCourse(int cid)
        {
            int     max = 0, current = 0;
            string  sql = "select CMax from Course where CId = " + cid.ToString();
            DataSet ds  = Db.ExecuteSelectSql(sql);

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                max = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
            }
            else
            {
                return;
            }
            sql = "select count(*) from SC where SId like '" + Session["Id"].ToString() + "' and CId = " + cid.ToString();
            DataSet ds1 = Db.ExecuteSelectSql(sql);

            if (ds1 != null && ds1.Tables.Count > 0 && ds1.Tables[0].Rows.Count > 0)
            {
                current = Int32.Parse(ds1.Tables[0].Rows[0][0].ToString());
            }
            else
            {
                return;
            }
            if (current > max)
            {
                Response.Write(MyUtility.Alert("人数已满!"));
                return;
            }
            sql = "insert into SC values('" + Session["Id"].ToString() + "'," + cid + ",0)";
            if (Db.ExecuteSql(sql) == 1)
            {
                Response.Write(MyUtility.Alert("选课成功"));
            }
            else
            {
                Response.Write(MyUtility.Alert("选课失败"));
            }
        }
Ejemplo n.º 8
0
        protected void btnAddTearcher_Click(object sender, System.EventArgs e)
        {
            if (txtTId.Text.Trim() == "")
            {
                Response.Write(MyUtility.Alert("请输入教师编号!"));
                return;
            }
            if (txtTName.Text.Trim() == "")
            {
                Response.Write(MyUtility.Alert("请输入教师姓名!"));
                return;
            }
            string sql = "insert into Teacher(TId,TKey,TName) values('" + txtTId.Text.Trim() + "','" + MyUtility.MD5(txtTId.Text.Trim()) + "','" + txtTName.Text.Trim() + "')";

            try
            {
                if (Db.ExecuteSql(sql) == 1)
                {
                    sql = "select * from Teacher";
                    DataSet ds1 = Db.ExecuteSelectSql(sql);
                    if (ds1 != null && ds1.Tables.Count > 0)
                    {
                        dgViewT.DataSource = ds1.Tables[0];
                        dgViewT.DataBind();
                    }
                }
                else
                {
                    Response.Write(MyUtility.Alert("添加失败-_-,请检查编号是否已经存在!"));
                    return;
                }
            }
            catch
            {
                Response.Write(MyUtility.Alert("添加失败-_-,请检查编号是否已经存在!"));
                return;
            }
        }
Ejemplo n.º 9
0
        protected void btnAddStudent_Click(object sender, System.EventArgs e)
        {
            if (txtSId.Text.Trim() == "")
            {
                Response.Write(MyUtility.Alert("请输入学生学号!"));
                return;
            }
            if (txtSName.Text.Trim() == "")
            {
                Response.Write(MyUtility.Alert("请输入学生姓名!"));
                return;
            }
            string sql = "insert into Student(SId,SKey,SName,SCredit,SLocked) values('" + txtSId.Text.Trim() + "','" + MyUtility.MD5(txtSId.Text.Trim()) + "','" + txtSName.Text.Trim() + "',0,0)";

            try
            {
                if (Db.ExecuteSql(sql) == 1)
                {
                    sql = "select * from Student";
                    DataSet ds1 = Db.ExecuteSelectSql(sql);
                    if (ds1 != null && ds1.Tables.Count > 0)
                    {
                        dgViewS.DataSource = ds1.Tables[0];
                        dgViewS.DataBind();
                    }
                }
                else
                {
                    Response.Write(MyUtility.Alert("添加失败-_-,请检查学号是否已经存在!"));
                    return;
                }
            }
            catch
            {
                Response.Write(MyUtility.Alert("添加失败-_-,请检查学号是否已经存在!"));
                return;
            }
        }
Ejemplo n.º 10
0
        protected void btnLock_Click(object sender, System.EventArgs e)
        {
            string  sql     = "select count(*) from SC where SId like '" + Session["Id"].ToString() + "'";
            DataSet ds      = Db.ExecuteSelectSql(sql);
            int     nCourse = 0;

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                nCourse = Int32.Parse(ds.Tables[0].Rows[0][0].ToString());
            }
            if (nCourse < 2)
            {
                Response.Write(MyUtility.Alert("您必须选择至少两门选修课程!"));
                return;
            }
            else
            {
                //先将所有必修课程加入到选课表中再锁定
                sql = "select CId from Course where CType = '必修'";
                DataSet ds2 = Db.ExecuteSelectSql(sql);
                if (ds2 != null && ds2.Tables.Count > 0)
                {
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string cid = ds2.Tables[0].Rows[i][0].ToString();
                        sql = "insert into SC(SId,CId,Score) values('" + Session["Id"].ToString() + "'," + cid + ",0)";
                        Db.ExecuteSql(sql);
                    }
                }
                sql = "update Student set SLocked = 1 where SId like '" + Session["Id"].ToString() + "'";
                if (Db.ExecuteSql(sql) == 1)
                {
                    lbLock.Text       = "选课信息已被锁定!";
                    Session["Locked"] = "true";
                    Response.Redirect("Selectedcourse.aspx");
                }
            }
        }
Ejemplo n.º 11
0
        protected void btnAddBuilding_Click(object sender, System.EventArgs e)
        {
            if (txtBuilding.Text.Trim() == "")
            {
                Response.Write(MyUtility.Alert("请输入教学楼名称!"));
                return;
            }
            string sql = "insert into Building(BuildingName) values('" + txtBuilding.Text.Trim() + "')";

            Db.ExecuteSql(sql);
            sql = "select * from Building";
            DataSet ds = Db.ExecuteSelectSql(sql);

            if (ds != null && ds.Tables.Count > 0)
            {
                DataView dv = new DataView(ds.Tables[0]);
                ddlBuilding.DataSource     = dv;
                ddlBuilding.DataTextField  = "BuildingName";
                ddlBuilding.DataValueField = "BuildingId";
                ddlBuilding.DataBind();
                Response.Write(MyUtility.Alert("教学楼添加成功,您添加的教学楼是: " + txtBuilding.Text));
            }
        }
Ejemplo n.º 12
0
        protected void lkbDeleteBuilding_Click(object sender, System.EventArgs e)
        {
            if (ddlBuilding.SelectedIndex < 0)
            {
                Response.Write(MyUtility.Alert("请选择一个教学楼!"));
                return;
            }
            string  sql     = "select count(*) from Room where BuildingId = " + ddlBuilding.SelectedItem.Value;
            DataSet ds      = Db.ExecuteSelectSql(sql);
            int     roomNum = 0;

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                roomNum = (int)ds.Tables[0].Rows[0][0];
            }
            if (roomNum > 0)
            {
                Response.Write(MyUtility.Alert("请先删除该教学楼所有教室!"));
                return;
            }
            else
            {
                sql = "delete from Building where BuildingId = " + ddlBuilding.SelectedItem.Value;
                Db.ExecuteSql(sql);
                sql = "select * from Building";
                DataSet ds2 = Db.ExecuteSelectSql(sql);
                if (ds2 != null && ds2.Tables.Count > 0)
                {
                    DataView dv = new DataView(ds2.Tables[0]);
                    ddlBuilding.DataSource     = dv;
                    ddlBuilding.DataTextField  = "BuildingName";
                    ddlBuilding.DataValueField = "BuildingId";
                    ddlBuilding.DataBind();
                }
            }
        }
Ejemplo n.º 13
0
        protected void btnUpdate_Click(object sender, System.EventArgs e)
        {
            try
            {
                int age = Int32.Parse(txtTAge.Text.Trim());
            }
            catch
            {
                Response.Write(MyUtility.Alert("年龄输入错误"));
                return;
            }
            string sql = "update Teacher set TName = '" + txtTName.Text.Trim() +
                         "',TAge = " + txtTAge.Text.Trim() +
                         ",TSex = '" + ddlTSex.SelectedItem.Text +
                         "',TPhone = '" + txtTPhone.Text.Trim() +
                         "',TMail = '" + txtTMail.Text.Trim() +
                         "' where TId = '" + Session["Id"].ToString() + "'";

            if (Db.ExecuteSql(sql) == 1)
            {
                Response.Write(MyUtility.Alert("修改成功!"));
            }
            return;
        }
Ejemplo n.º 14
0
 private void dgCourse_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
 {
     if (e.CommandName == "Select")
     {
         string  cid  = e.Item.Cells[0].Text;
         string  sql  = "select * from SC where CId = " + cid + " and SId like '" + Session["Id"].ToString() + "'";
         DataSet ds   = Db.ExecuteSelectSql(sql);
         bool    flag = false;          //是否已经选修过了
         if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
         {
             flag = true;
         }
         if (flag)
         {
             Response.Write(MyUtility.Alert("您已经选了该课程了!"));
             return;
         }
         else
         {
             sql = "select CPreCId from Course where CId = " + cid;
             DataSet ds1 = Db.ExecuteSelectSql(sql);
             if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
             {
                 string cpcid = ds.Tables[0].Rows[0][0].ToString();
                 bool   flag2 = false; //前导课程判断标志
                 //判断前导课程是否是必修课
                 sql = "select CType from Course where CId = " + cpcid;
                 DataSet ds2 = Db.ExecuteSelectSql(sql);
                 if (ds2 != null && ds2.Tables.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                 {
                     if (ds2.Tables[0].Rows[0][0].ToString() == "必修")
                     {
                         flag2 = true;
                     }
                 }
                 else
                 {
                     //判断是否在已经选择的选修课中
                     sql = "select * from SC where SId like '" + Session["Id"].ToString() + "' and CId = " + cpcid;
                     DataSet ds3 = Db.ExecuteSelectSql(sql);
                     if (ds3 != null && ds3.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                     {
                         flag2 = true;
                     }
                 }
                 if (flag2)
                 {//有前导课程,但前导课程是必修课或者已经选择了选修课程
                     SelectCourse(Int32.Parse(cid));
                     return;
                 }
                 else
                 {//有前导课程,前导课程不是是必修课,也不是已经选择了的选修课程,不能选
                     Response.Write(MyUtility.Alert("请先选择该课程的前导课程"));
                     return;
                 }
             }
             else //没有前导课程
             {
                 SelectCourse(Int32.Parse(cid));
             }
         }
     }
 }
Ejemplo n.º 15
0
        protected void btnAddTime_Click(object sender, System.EventArgs e)
        {
            #region check input
            if (ddlBuilding.SelectedIndex <= 0)
            {
                Response.Write(MyUtility.Alert("请选择课的教学楼!"));
                return;
            }
            if (ddlRoom.SelectedIndex <= 0)
            {
                Response.Write(MyUtility.Alert("请选择课的教室!"));
                return;
            }
            if (ddlCWeekStart.SelectedIndex <= 0)
            {
                Response.Write(MyUtility.Alert("请选择课程开始周次!"));
                return;
            }
            if (ddlCWeekEnd.SelectedIndex <= 0)
            {
                Response.Write(MyUtility.Alert("请选择课程结束周次!"));
                return;
            }
            if (ddlWeek.SelectedIndex <= 0 || ddlTime.SelectedIndex <= 0)
            {
                Response.Write(MyUtility.Alert("请选择上课的时间!"));
                return;
            }
            #endregion

            string  sql  = "select * from CourseTime where RoomId = " + ddlRoom.SelectedItem.Value + " and CTime like '" + ddlWeek.SelectedItem.Text + ddlTime.SelectedItem.Text + "'";
            DataSet ds   = Db.ExecuteSelectSql(sql);
            bool    flag = true;
            if (ds != null && ds.Tables.Count > 0)
            {
                int ws = Int32.Parse(ddlCWeekStart.SelectedItem.Text);
                int we = Int32.Parse(ddlCWeekEnd.SelectedItem.Text);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    int nws = Int32.Parse(ds.Tables[0].Rows[i]["CWeekStart"].ToString());
                    int nwe = Int32.Parse(ds.Tables[0].Rows[i]["CWeekEnd"].ToString());
                    if (we < nws || ws > nwe)
                    {
                        flag = true;
                    }
                    else
                    {
                        flag = false;
                    }
                }
            }
            if (flag == false)
            {
                Response.Write(MyUtility.Alert("您选择的时间地点和其他课程有冲突,抱歉,请再次选择!"));
                return;
            }
            else
            {
                if (CId != 0)
                {
                    sql = "insert into CourseTime(CId,RoomId,CWeekStart,CWeekEnd,CTime) " +
                          "values(" + CId.ToString() +
                          "," + ddlRoom.SelectedItem.Value +
                          "," + ddlCWeekStart.SelectedItem.Text +
                          "," + ddlCWeekEnd.SelectedItem.Text +
                          ",'" + ddlWeek.SelectedItem.Text + ddlTime.SelectedItem.Text + "')";
                    Db.ExecuteSql(sql);
                }
            }

            Label13.Visible       = false;
            ddlRoom.Visible       = false;
            Label9.Visible        = false;
            ddlBuilding.Visible   = false;
            lbTime2.Visible       = false;
            Label10.Visible       = false;
            ddlCWeekEnd.Visible   = false;
            Label11.Visible       = false;
            ddlCWeekStart.Visible = false;
            Label12.Visible       = false;
            Label5.Visible        = false;
            btnAddTime.Visible    = false;
            ddlWeek.Visible       = false;
            ddlTime.Visible       = false;

            sql = "select CourseTime.*,Building.*,Room.RoomName from CourseTime,Building,Room where CId = " + CId.ToString() + " and CourseTime.RoomId = Room.RoomId and Room.BuildingId = Building.BuildingId";
            DataSet ds1 = Db.ExecuteSelectSql(sql);
            if (ds1 != null && ds1.Tables.Count > 0)
            {
                dgTime.DataSource = ds1.Tables[0];
                dgTime.DataBind();
                lbCaption.Text = "该课程已有 " + ds1.Tables[0].Rows.Count.ToString() + " 个时间段!";
            }
            else
            {
                lbCaption.Text = "该课程还没有设置上课时间地点!请尽快设置!";
            }
        }
Ejemplo n.º 16
0
        protected void btnAdd_Click(object sender, System.EventArgs e)
        {
            if (txtCName.Text.Trim() == "")
            {
                Response.Write(MyUtility.Alert("请输入课程名称!"));
                return;
            }
            if (ddlCType.SelectedIndex <= 0)
            {
                Response.Write(MyUtility.Alert("请选择课程类型!"));
                return;
            }
            if (ddlCCredit.SelectedIndex <= 0)
            {
                Response.Write(MyUtility.Alert("请选择课程学分!"));
                return;
            }
            if (ddlCMax.SelectedIndex <= 0)
            {
                Response.Write(MyUtility.Alert("请选择课程最大人数!"));
                return;
            }
            string sql;

            sql = "select count(*) from Course where TId like '" + Session["Id"].ToString() + "'";
            DataSet ds      = Db.ExecuteSelectSql(sql);
            int     nCourse = 0;

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                nCourse = (int)ds.Tables[0].Rows[0][0];
            }
            if (nCourse >= 3)
            {
                Response.Write(MyUtility.Alert("您已经开设了3门课程了!不能再开设了"));
                return;
            }
            if (ddlCPreCId.SelectedIndex <= 0)
            {
                sql = "insert into Course(TId,CName,CType,CCredit,CMax,CNote) values(" +
                      Session["Id"].ToString() +
                      ",'" + txtCName.Text.Trim() +
                      "','" + ddlCType.SelectedItem.Text +
                      "'," + ddlCCredit.SelectedItem.Text +
                      "," + ddlCMax.SelectedItem.Text +
                      ",'" + MyUtility.Encode(txtCNote.Text) + "')";
            }
            else
            {
                sql = "insert into Course(TId,CName,CType,CCredit,CMax,CNote,CPreCId) values(" +
                      Session["Id"].ToString() +
                      ",'" + txtCName.Text.Trim() +
                      "','" + ddlCType.SelectedItem.Text +
                      "'," + ddlCCredit.SelectedItem.Text +
                      "," + ddlCMax.SelectedItem.Text +
                      ",'" + MyUtility.Encode(txtCNote.Text) +
                      "'," + ddlCPreCId.SelectedItem.Value + ")";
            }
            Db.ExecuteSql(sql);
            Response.Redirect("TeacherMain.aspx");
        }