private void btnAdd_Click(object sender, EventArgs e) { if ((tbRoomNumber.Text == "") || (tbHFName.Text == "")) { MessageBox.Show("Vui lòng nhập đầy đủ thông tin", MessageDefine.CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { HOMEFLEET hf = new HOMEFLEET(); hf.HFNAME = tbHFName.Text; hf.NUMBEROFROOM = int.Parse(tbRoomNumber.Text); hf.STATUSS = 1; db.HOMEFLEETs.Add(hf); db.SaveChanges(); MessageBox.Show("Đã thêm thông tin tòa nhà mới", MessageDefine.CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); int index = dgAllHF.Rows.Add(); dgAllHF.Rows[index].Cells[0].Value = hf.HFID; dgAllHF.Rows[index].Cells[1].Value = hf.HFNAME; dgAllHF.Rows[index].Cells[2].Value = hf.NUMBEROFROOM; tbHFName.Text = ""; txtHFID.Text = ""; } catch (Exception ex) { lbInformation.Text = "ERROR: " + ex.Message; } }
private void btnAdd_Click(object sender, EventArgs e) { try { RENT rent = new RENT(); STUDENT student = (STUDENT)cbbStudent.SelectedItem; ROOM room = (ROOM)cbbRoom.SelectedItem; rent.RENTER = student.STUDENTID; rent.ROOM = room.ROOMID; rent.TOTALFEE = double.Parse(tbTotalFee.Text); rent.PAID = double.Parse(tbPaid.Text); rent.CREATEDATE = dateRegistation.Value; rent.STARTDATE = dateStart.Value; rent.ENDDATE = dateEnd.Value; //Nếu đã thanh toán đủ tiền if (rent.TOTALFEE <= rent.PAID) { rent.STATUSS = 1; // Status chuyển thành 1 = "đã thanh toán" } else { rent.STATUSS = 0; // 0 = "Chưa thanh toán" } rent.THELEASE = CommonUsing.CURRENT_USER_ID; // Thêm bản ghi vào bảng RENT db.RENTs.Add(rent); db.SaveChanges(); // Chuyển trạng thái sinh viên thành "đã có phòng" student.STATUSS = 0; db.Entry(student).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); // Giảm số lượng giường trống của phòng được chọn, nếu hết giường trống thì chuyển trạng thái về 0 để biếu thị full room.BEDEMPTY = room.BEDEMPTY - 1; if (room.BEDEMPTY == 0) { room.STATUSS = 0; } db.Entry(room).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Đã đăng kí thành công", MessageDefine.CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); FmRentManage rm = new FmRentManage(); rm.Show(); } catch (Exception ex) { lbInformation.Text = ex.Message; } }
private void btnDelete_Click(object sender, EventArgs e) { try { var option = MessageBox.Show(MessageDefine.ConfirmDeleteStudent, "Xác nhận xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (option == DialogResult.Yes) { STUDENT student = new STUDENT(); string studentId = dgAllStudent.CurrentRow.Cells["ColStudentId"].Value.ToString(); student = db.STUDENTs.Where(d => d.STUDENTID.Equals(studentId)).FirstOrDefault(); if (student == null) { MessageBox.Show(MessageDefine.RecordRequestedNoExist); return; } db.STUDENTs.Remove(student); db.SaveChanges(); MessageBox.Show(MessageDefine.DeleteRecordSuccessful, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); dgAllStudent.Rows.Remove(dgAllStudent.CurrentRow); } } catch (Exception ex) { MessageBox.Show(MessageDefine.ExceptionMessage + ex.Message); } }
private void btnSave_Click(object sender, EventArgs e) { try { ROOM rm = db.ROOMs.Where(d => d.ROOMID == room.ROOMID).FirstOrDefault(); rm.ROOMNAME = tbRoomName.Text; rm.BEDNUMBER = int.Parse(tbBed.Text); rm.BEDEMPTY = int.Parse(tbBedEmpty.Text); if (cbbGender.SelectedItem.ToString().Equals("Nam")) { rm.FORGENDER = 1; } else { rm.FORGENDER = 2; } HOMEFLEET hf = (HOMEFLEET)cbbHF.SelectedItem; rm.HOMEFLEET = hf.HFID; rm.INCLUDED = tbIncluded.Text; db.Entry(rm).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Chỉnh sửa thông tin phòng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); FmRoomManage roomManage = new FmRoomManage(); roomManage.Show(); } catch (Exception ex) { lbInformation.Text = ex.Message; } }
private void btnDelete_Click(object sender, EventArgs e) { var result = MessageBox.Show(MessageDefine.ConfirmDeleteStudent, MessageDefine.CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { int id = int.Parse(dgAllRoom.CurrentRow.Cells["ColRoomId"].Value.ToString()); ROOM room = db.ROOMs.Where(d => d.ROOMID == id).FirstOrDefault(); db.ROOMs.Remove(room); db.SaveChanges(); MessageBox.Show(MessageDefine.DeleteRecordSuccessful, MessageDefine.CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); dgAllRoom.Rows.Remove(dgAllRoom.CurrentRow); } }
private void btnDelete_Click(object sender, EventArgs e) { try { var option = MessageBox.Show(MessageDefine.ConfirmDeleteStudent, MessageDefine.CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (option == DialogResult.Yes) { int code = int.Parse(dgRent.CurrentRow.Cells["ColCode"].Value.ToString()); RENT rent = db.RENTs.Where(r => r.ID == code).FirstOrDefault(); // tăng số giường trống của phòng ROOM room = db.ROOMs.Where(r => r.ROOMID == rent.ROOM).FirstOrDefault(); if (room.BEDEMPTY < room.BEDNUMBER) { room.BEDEMPTY = room.BEDEMPTY + 1; } if (room.BEDEMPTY == 0) { room.STATUSS = 0; } else { room.STATUSS = 1; } db.Entry(room).State = System.Data.Entity.EntityState.Modified; // update lại trạng thái của student STUDENT student = db.STUDENTs.Where(s => s.STUDENTID == rent.RENTER).FirstOrDefault(); student.STATUSS = 1; db.Entry(student).State = System.Data.Entity.EntityState.Modified; // Thực thi xóa record db.RENTs.Remove(rent); db.SaveChanges(); MessageBox.Show("Đã xóa thành công", MessageDefine.CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); dgRent.Rows.Remove(dgRent.CurrentRow); } } catch (Exception ex) { MessageBox.Show("Opps! Đã có lỗi xảy ra", MessageDefine.CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSave_Click(object sender, EventArgs e) { try { var rs = MessageBox.Show("Bạn có chắc chắn muốn lưu lại không?", MessageDefine.CAPTION, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (rs == DialogResult.Yes) { int paidPlus = 0; if (tbPaidPlus.Text != "") { paidPlus = int.Parse(tbPaidPlus.Text); } ROOM rm = (ROOM)cbbRoom.SelectedItem; RENT rt = db.RENTs.Where(r => r.ID == rent.ID).FirstOrDefault(); rt.STARTDATE = dateStart.Value; rt.ENDDATE = dateEnd.Value; rt.TOTALFEE = int.Parse(tbTotalFee.Text); rt.PAID = int.Parse(tbPaid.Text) + paidPlus; rt.ROOM = rm.ROOMID; if (rt.PAID >= rent.TOTALFEE) { rt.STATUSS = 1; } else { rt.STATUSS = 0; } db.Entry(rt).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Chỉnh sửa thông tin đăng kí thành công", MessageDefine.CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); FmRentManage fmRent = new FmRentManage(); fmRent.Show(); } } catch (Exception ex) { lbInformation.Text = "Đã có lỗi xảy ra"; } }
private void btnDelete_Click(object sender, EventArgs e) { try { var option = MessageBox.Show(MessageDefine.ConfirmDeleteStudent, "Xác nhận xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (option == DialogResult.Yes) { db.STUDENTs.Remove(student); db.SaveChanges(); MessageBox.Show(MessageDefine.DeleteRecordSuccessful, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); StudentManage studentManage = new StudentManage(); studentManage.Show(); } } catch (Exception ex) { MessageBox.Show(MessageDefine.ExceptionMessage + ex.Message); } }
private void btnSave_Click(object sender, EventArgs e) { try { // Xác thực thông tin nhập vào if (txtStudentId.Text == "") { lbInformation.Text = "Thông báo lỗi: " + MessageDefine.StudentIdNull; return; } // thêm thông tin sinh viên sau chỉnh sửa vào csdl STUDENT student = new STUDENT(); student.STUDENTID = txtStudentId.Text; student.STUDENTNAME = txtFullName.Text; student.DOB = dob.Value; if (cbbGender.SelectedItem.ToString().Equals("Nam")) { student.GENDER = 1; } else { student.GENDER = 2; } student.RELIGION = txtReligion.Text; student.FOLK = txtFolk.Text; student.ADDRESSS = txtAddress.Text; student.CMND = txtCMND.Text; student.DATECMND = dateCMND.Value; student.ISSUEDBY = txtIssuedBy.Text; student.NATION = txtNation.Text; student.PHONENUMBER = txtPhoneNumber.Text; student.STUDYAT = txtSchool.Text; student.STUDENTYEAR = int.Parse(txtYear.Text); student.DEPARTMENT = txtDepartment.Text; student.PHOTO = lbImageName.Text; student.STATUSS = 1; student.EMAIL = txtEmail.Text; db.Entry(student).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); // Upload file ảnh avatar vào hệ thống if (avatarPath != "") { File.Copy(avatarPath, CommonUsing.ImagePath() + Path.GetFileName(avatarPath), true); } MessageBox.Show("Chỉnh sửa thông tin sinh viên thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); StudentManage studentManage = new StudentManage(); studentManage.Show(); } catch (Exception ex) { lbInformation.Text = ex.Message; } }