public ActionResult DeleteConfirmed(string id) { RENT rENT = db.RENTs.Find(id); db.RENTs.Remove(rENT); db.SaveChanges(); return(RedirectToAction("Index")); }
public FmEditRent(int code) { InitializeComponent(); Id = code; rent = new RENT(); rent = db.RENTs.Where(r => r.ID == Id).FirstOrDefault(); loadCbbData(); fillData(rent); }
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 fillData(RENT rt) { STUDENT st = db.STUDENTs.Where(s => s.STUDENTID == rt.RENTER).FirstOrDefault(); tbStudent.Text = st.STUDENTNAME; cbbRoom.SelectedItem = db.ROOMs.Where(r => r.ROOMID == rt.ROOM).FirstOrDefault(); dateRegistation.Value = (DateTime)rt.CREATEDATE; dateStart.Value = (DateTime)rt.STARTDATE; dateEnd.Value = (DateTime)rt.ENDDATE; tbTotalFee.Text = rt.TOTALFEE.ToString(); tbPaid.Text = rt.PAID.ToString(); }
public ActionResult Create([Bind(Include = "Rent_id,Price,IsActive,From_Date,To_Date,RoomType_id")] RENT rENT) { if (ModelState.IsValid) { rENT.Rent_id = createId(); db.RENTs.Add(rENT); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RoomType_id = new SelectList(db.ROOMTYPEs, "RoomType_id", "RType", rENT.RoomType_id); return(View(rENT)); }
// GET: RENTs/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RENT rENT = db.RENTs.Find(id); if (rENT == null) { return(HttpNotFound()); } return(View(rENT)); }
// GET: RENTs/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RENT rENT = db.RENTs.Find(id); if (rENT == null) { return(HttpNotFound()); } ViewBag.RoomType_id = new SelectList(db.ROOMTYPEs, "RoomType_id", "RType", rENT.RoomType_id); return(View(rENT)); }
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"; } }
public ActionResult Edit([Bind(Include = "Rent_id,Price,IsActive,From_Date,To_Date,RoomType_id")] RENT rENT) { if (ModelState.IsValid) { /* * string td = String.Format("{0:dd/MM/yyyy}", rENT.To_Date); * string fd = String.Format("{0:dd/MM/yyyy}", rENT.From_Date); * * DateTime date = DateTime.ParseExact(td, "MM/dd/yyyy", null); * rENT.To_Date = date; * date = DateTime.ParseExact(fd, "MM/dd/yyyy", null); * rENT.From_Date = date; */ db.Entry(rENT).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.RoomType_id = new SelectList(db.ROOMTYPEs, "RoomType_id", "RType", rENT.RoomType_id); return(View(rENT)); }
private static void Main() { var output = new StringBuilder(); int remainingTestCases = FastIO.ReadNonNegativeInt(); while (remainingTestCases-- > 0) { int orderCount = FastIO.ReadNonNegativeInt(); var orders = new FlightOrder[orderCount]; for (int o = 0; o < orderCount; ++o) { orders[o] = new FlightOrder( startTime: FastIO.ReadNonNegativeInt(), duration: FastIO.ReadNonNegativeInt(), profit: FastIO.ReadNonNegativeInt()); } output.Append( RENT.Solve(orderCount, orders)); output.AppendLine(); } Console.Write(output); }