Example #1
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "applicatoin/json";

            string roomCode = string.Empty;
            string studentCode = string.Empty;
            RoomInfo roomInfo;
            Student student;

            StringBuilder sbResult = new StringBuilder();

            #region Validation and Get Basic Info

            if (string.IsNullOrEmpty(context.Request.Form["roomCode"]) ||
                string.IsNullOrEmpty(context.Request.Form["studentCode"]))
            {
                context.Response.Write("{success: false, msg: '参数不正确'}");
                return;
            }
            roomCode = context.Request.Form["roomCode"];
            studentCode = context.Request.Form["studentCode"];

            roomInfo = RoomInfo.GetByCode(roomCode);
            student = Student.GetStudentByCode(studentCode);
            if (roomInfo == null || student == null)
            {
                context.Response.Write("{success: false, msg: '参数不正确'}");
                return;
            }

            if (roomInfo.AvailNum == 0)
            {
                context.Response.Write("{success: false, msg: '房间住满'}");
                return;
            }

            #endregion

            StudentRoom sr = new StudentRoom();
            sr.StudentCode = studentCode;
            sr.RoomCode = roomCode;
            sr.StayStartDate = DateTime.Now;
            sr.IsState = true;
            sr.Save();

            // reload roominfo
            roomInfo = RoomInfo.GetByCode(roomCode);
            if (roomInfo.AvailNum == 0)
            {
                roomInfo.RoomState = "Full";
                roomInfo.Save();
            }

            sbResult.Append("{success: true}");

            context.Response.Write(sbResult.ToString());
        }
Example #2
0
        public Core.Business.StudentRoom GetStudentRoomByStudentCode(string studentCode)
        {
            SqlServerUtility sqlhelper = new SqlServerUtility();

            sqlhelper.AddParameter("@StudentCode", SqlDbType.NVarChar, studentCode);

            SqlDataReader reader = sqlhelper.ExecuteSqlReader(SqlGetStudentRoomByStudentCode);

            Core.Business.StudentRoom studentRoom = null;

            if (reader != null)
            {
                while (reader.Read())
                {
                    studentRoom = new StudentRoom();

                    if (!reader.IsDBNull(0)) studentRoom.Id = reader.GetInt32(0);
                    if (!reader.IsDBNull(1)) studentRoom.StudentCode = reader.GetString(1);
                    if (!reader.IsDBNull(2)) studentRoom.RoomCode = reader.GetString(2);
                    if (!reader.IsDBNull(3)) studentRoom.StayStartDate = reader.GetDateTime(3);
                    if (!reader.IsDBNull(4)) studentRoom.StayEndDate = reader.GetDateTime(4);
                    if (!reader.IsDBNull(5)) studentRoom.IsState = reader.GetBoolean(5);

                    studentRoom.MarkOld();
                }
                reader.Close();
            }
            return studentRoom;
        }
Example #3
0
        protected void bt_Assign_Click(object sender, EventArgs e)
        {
            int count = 0;
            List<string> stdcode = new List<string>();
            for (int i = 0; i < StudentList.Rows.Count; i++)
            {
                CheckBox cb = (CheckBox)StudentList.Rows[i].FindControl("chkSelect");
                if (cb.Checked == true)
                {
                    count = count + 1;
                    stdcode.Add(StudentList.DataKeys[i].Value.ToString());
                }
            }

            if (count > anum)
            {
                JsHelper.Alert(this.Page, "提示", "分配数大于剩余床位,请重新分配!");
                for (int i = 0; i < StudentList.Rows.Count; i++)
                {
                    CheckBox cb = (CheckBox)StudentList.Rows[i].FindControl("chkSelect");
                    cb.Checked = false;
                }
                return;
            }
            if (stdcode.Count == 0)
            {
                JsHelper.Alert(this.Page, "错误", "没有选取任何学生");
                return;
            }
            try
            {
                foreach (string c in stdcode)
                {
                    if (StudentRoom.GetStudentRoomByStudentCode(c) == null)
                    {
                        StudentRoom sr = new StudentRoom();
                        sr.StudentCode = c;
                        sr.RoomCode = roomCode;
                        sr.IsState = true;
                        sr.StayStartDate = DateTime.Now;
                        sr.Save();
                    }
                    else
                    {
                        StudentRoom sr = StudentRoom.GetStudentRoomByStudentCode(c);
                        sr.StudentCode = c;
                        sr.RoomCode = roomCode;
                        sr.IsState = true;
                        sr.Save();
                    }
                }
                RoomInfo ri = RoomInfo.GetByCode(roomCode);
                int a = ri.ExistNum;
                a +=stdcode.Count;
                //ri.ExistNum = a;
                if ((ri.AvailNum-a)==0)
                    ri.RoomState = "Full";
                ri.Save();
                Page.ClientScript.RegisterStartupScript(this.Page.GetType(),"","<script>alert('分配成功!');window.close();</script>");
            }
            catch (Exception exx)
            {
                JsHelper.Alert(this.Page, "提fd示", "分配bu成功");
                lb_Error.Text =exx.Message.ToString();
            }
        }