public CONGVIEC GetCONGVIEC(int id) { using (QLCVEntities e = new QLCVEntities()) { CONGVIEC cv = e.CONGVIECs.Include("PHANCONGs").Where(a => a.ID == id).FirstOrDefault(); return(cv); } }
public void UpdateTaskAfterInsert(int id, string thumuc) { using (QLCVEntities e = new QLCVEntities()) { CONGVIEC cv = e.CONGVIECs.Find(id); cv.THUMUC = thumuc; e.SaveChanges(); } }
public ActionResult Insert(TaskInsertViewModel model) { //CheckLoggingIn(); if (model.numPC == 0) { ModelState.AddModelError("Error", "Ex: This login failed"); return(RedirectToAction("Insert")); } CONGVIEC cv = new CONGVIEC(); cv.TIEUDE = model.tieude; cv.NOIDUNG = model.noidung; cv.IDNGUOITAO = model.idNguoiTao; cv.NGAYTAO = DateTime.Now; cv.HOANTHANH = false; cv.XOA = false; string extension = ""; if (model.taptin != null) { cv.TAPTIN = model.taptin.FileName; extension = Path.GetExtension(model.taptin.FileName); } //cv.THUMUC = "1_" + DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second +extension; List <PHANCONG> pcs = new List <PHANCONG>(); for (int i = 0; i < model.numPC; i++) { string[] idNguoiNhans = model.listIDNguoiNhans[i].ToString().Split(','); foreach (string id in idNguoiNhans) { PHANCONG pc = new PHANCONG(); pc.IDPHANCONG = i; pc.TENPHANCONG = model.pcs[i].TENPHANCONG; pc.NOIDUNG = model.pcs[i].NOIDUNG; pc.IDNGUOINHAN = int.Parse(id); pc.NGAYBATDAU = model.pcs[i].NGAYBATDAU; pc.NGAYKETTHUC = model.pcs[i].NGAYKETTHUC; pc.IDTRANGTHAI = 1; pcs.Add(pc); } } //Upload(model.taptin, DateTime.Now, 1); cv.PHANCONGs = pcs; int idFileName = dao_task.InsertTask(cv); if (model.taptin != null) { string fileName = idFileName.ToString() + "_" + cv.NGAYTAO.GetValueOrDefault().Day + cv.NGAYTAO.GetValueOrDefault().Month + cv.NGAYTAO.GetValueOrDefault().Year + cv.NGAYTAO.GetValueOrDefault().Hour + cv.NGAYTAO.GetValueOrDefault().Minute + cv.NGAYTAO.GetValueOrDefault().Second; Upload(model.taptin, fileName); dao_task.UpdateTaskAfterInsert(idFileName, fileName + extension); } return(RedirectToAction("Detail", new { id = idFileName })); }
public int InsertTask(CONGVIEC cv) { using (QLCVEntities e = new QLCVEntities()) { e.CONGVIECs.Add(cv); e.SaveChanges(); int id = cv.ID; return(id); } }
public ActionResult Detail(int id) { //CheckLoggingIn(); NGUOIDUNG userLogin = Session["USER"] as NGUOIDUNG; CONGVIEC cv = dao_task.GetCONGVIEC(id); List <int> listNguoiDungTrongCongViec = dao_task.GetNGuoiDungTrongCongViec(id); if (!listNguoiDungTrongCongViec.Contains(userLogin.ID) && userLogin.ID != cv.IDNGUOITAO) { return(RedirectToAction("Login", "Account")); } List <NGUOIDUNG> nds1 = dao_user.GetNGUOIDUNGs(); ViewBag.NDs = nds1; //CONGVIEC cv = dao_task.GetCONGVIEC(id); TaskDetailViewModel model = new TaskDetailViewModel(); model.id = cv.ID; model.tieude = cv.TIEUDE; model.noidung = cv.NOIDUNG; model.ngaytao = cv.NGAYTAO.GetValueOrDefault(); if (cv.NGAYCAPNHAT != null) { model.ngaycapnhat = cv.NGAYCAPNHAT.GetValueOrDefault(); } //model.ngaycapnhat = cv.NGAYCAPNHAT.GetValueOrDefault(); model.hoanthanh = cv.HOANTHANH.GetValueOrDefault(); model.idNguoiTao = cv.IDNGUOITAO.GetValueOrDefault(); //model.pcs = cv.PHANCONGs.ToList(); List <PHANCONG> pcs = new List <PHANCONG>(); List <string> listId = new List <string>(); List <int> listIdPC = new List <int>(); foreach (PHANCONG pc in cv.PHANCONGs) { List <int> nds = dao_task.GetIDNGUOIDUNGinPHANCONG(cv.ID, pc.IDPHANCONG); listId.Add(string.Join(",", nds)); listIdPC.Add(pc.IDPHANCONG); } List <int> listIdPCDistinct = listIdPC.Distinct().ToList(); for (int i = 0; i < listIdPC.Distinct().Count(); i++) { PHANCONG pc = dao_task.GetPHANCONG(cv.ID, listIdPCDistinct[i]); pcs.Add(pc); } model.pcs = pcs; model.listId = listId.ToList(); model.numPC = listIdPC.Distinct().Count(); model.taptin = cv.TAPTIN; model.thumuc = cv.THUMUC; return(View(model)); }
public void UpdateTask(CONGVIEC cv1) { using (QLCVEntities e = new QLCVEntities()) { CONGVIEC cv2 = e.CONGVIECs.Find(cv1.ID); cv2.TIEUDE = cv1.TIEUDE; cv2.NOIDUNG = cv1.NOIDUNG; cv2.TAPTIN = cv1.TAPTIN; cv2.NGAYCAPNHAT = cv1.NGAYCAPNHAT; cv2.PHANCONGs.Clear(); cv2.PHANCONGs = cv1.PHANCONGs; e.SaveChanges(); } }
public void UpdateTrangThaiCongViec(int idCongViec) { using (QLCVEntities e = new QLCVEntities()) { CONGVIEC cv = e.CONGVIECs.Find(idCongViec); if (cv.HOANTHANH == true) { cv.NGAYCAPNHAT = DateTime.Now; cv.HOANTHANH = false; } else { cv.NGAYCAPNHAT = DateTime.Now; cv.HOANTHANH = true; } e.SaveChanges(); } }
public ActionResult Edit(TaskDetailViewModel model) { CONGVIEC cv = dao_task.GetCONGVIEC(model.id); cv.TIEUDE = model.tieude; cv.NOIDUNG = model.noidung; if (model.taptinUpload != null) { cv.TAPTIN = model.taptinUpload.FileName; string extension = Path.GetExtension(model.taptinUpload.FileName); string fileName = model.id.ToString() + "_" + cv.NGAYTAO.GetValueOrDefault().Day + cv.NGAYTAO.GetValueOrDefault().Month + cv.NGAYTAO.GetValueOrDefault().Year + cv.NGAYTAO.GetValueOrDefault().Hour + cv.NGAYTAO.GetValueOrDefault().Minute + cv.NGAYTAO.GetValueOrDefault().Second; cv.THUMUC = fileName + extension; Upload(model.taptinUpload, fileName); } List <PHANCONG> pcs = new List <PHANCONG>(); for (int i = 0; i < model.numPC; i++) { string[] idNguoiNhans = model.listIDNguoiNhans[i].ToString().Split(','); foreach (string id in idNguoiNhans) { PHANCONG pc = new PHANCONG(); pc.IDPHANCONG = i; pc.TENPHANCONG = model.pcs[i].TENPHANCONG; pc.NOIDUNG = model.pcs[i].NOIDUNG; pc.IDNGUOINHAN = int.Parse(id); pc.NGAYBATDAU = model.pcs[i].NGAYBATDAU; pc.NGAYKETTHUC = model.pcs[i].NGAYKETTHUC; pc.IDTRANGTHAI = model.pcs[i].IDTRANGTHAI; //pc.NGAYCAPNHAT = DateTime.Now; pcs.Add(pc); } } cv.NGAYCAPNHAT = DateTime.Now; cv.PHANCONGs = pcs; dao_task.UpdateTask(cv); return(RedirectToAction("Detail", new { id = model.id })); }
private void calculatedField1_GetValue(object sender, GetValueEventArgs e) { CONGVIEC cv = (CONGVIEC)e.GetColumnValue("CONGVIEC"); bool tt = (bool)e.GetColumnValue("TrangThai"); string trangthai = ""; if (!tt) { if (DateTime.Compare(cv.NgayHetHan, DateTime.Now) < 0) { trangthai = "Chậm tiến độ"; } else { trangthai = "Đang tiến hành"; } } else { trangthai = "Đã hoàn thành"; } e.Value = trangthai; //e.Value = (int)((DateTime)columnValue).DayOfWeek; }
public ActionResult QLCongviec(string submitButton, string showButton, CONGVIEC congviec, FormCollection collection) { var id = collection["jobID"]; var idCD = collection["campaignID"]; var name = collection["jobName"]; var place = collection["jobPlace"]; var detail = collection["jobDetails"]; var pneed = collection["jobPneeded"]; var reservation = collection["reservation"]; var startday = reservation.Split('-')[0]; var endday = reservation.Split('-')[1]; var time = DateTime.Parse(endday) - DateTime.Parse(startday); var cost = collection["jobCost"]; var moreinfo = collection["jobMoreinfo"]; var numofteam = (int)(int.Parse(pneed) / 10); var totalFee = (float)(int.Parse(pneed) * float.Parse(cost)); switch (submitButton) { case "Add": if (ModelState.IsValid) { congviec.Id = id; congviec.IdCD = idCD; congviec.TenCV = name; congviec.DiaDiem = place; congviec.SoLuongNguoi = int.Parse(pneed); congviec.NgayBatDau = DateTime.Parse(startday); congviec.ThoiGian = time.Days; congviec.ChiPhiMotNguoi = decimal.Parse(cost); congviec.MoreInfo = moreinfo; congviec.NoiDung = detail; db.CONGVIECs.InsertOnSubmit(congviec); db.SubmitChanges(); for (int i = 1; i <= numofteam; i++) { DOI doi = new DOI(); doi.Id = id + "-" + i.ToString(); doi.IdCD = idCD; doi.SoLuongThanhVienThamGia = 0; if (i == numofteam) { doi.SoLuongThanhVien = int.Parse(pneed) - (10 * numofteam) + 10; } else { doi.SoLuongThanhVien = 10; } db.DOIs.InsertOnSubmit(doi); db.SubmitChanges(); CTCONGVIEC ctcv = new CTCONGVIEC(); ctcv.IdCV = id; ctcv.IdDoi = id + "-" + i.ToString(); ctcv.KetQuaCV = '0'; db.CTCONGVIECs.InsertOnSubmit(ctcv); db.SubmitChanges(); } PHIEUTHANHTOAN ptt = db.PHIEUTHANHTOANs.FirstOrDefault(n => n.IdCD == idCD); ptt.ChiPhiDuDinh += totalFee; ptt.TongChiPhi = ptt.ChiPhiDuDinh + ptt.CHiPhiPhatSinh; UpdateModel(ptt); db.SubmitChanges(); } return(RedirectToAction("QLCongviec")); case "Edit": var cv = db.CONGVIECs.SingleOrDefault(n => n.Id == id); if (ModelState.IsValid) { cv.IdCD = idCD; cv.TenCV = name; cv.DiaDiem = place; cv.SoLuongNguoi = int.Parse(pneed); cv.NgayBatDau = DateTime.Parse(startday); cv.ThoiGian = time.Days; cv.ChiPhiMotNguoi = decimal.Parse(cost); cv.MoreInfo = moreinfo; cv.NoiDung = detail; UpdateModel(cv); db.SubmitChanges(); } return(RedirectToAction("QLCongviec")); case "Delete": var cvDel = db.CONGVIECs.SingleOrDefault(n => n.Id == id); db.CONGVIECs.DeleteOnSubmit(cvDel); db.SubmitChanges(); return(RedirectToAction("QLCongviec")); default: return(RedirectToAction("QLCongviec")); } }