protected void btnDetail_Click(object sender, EventArgs e) { LinkButton btn = (LinkButton)(sender); int id = int.Parse(btn.CommandArgument); BO.Job job = JobBLL.getJob(id); jobList.Add(job); DetailsView1.DataSource = jobList; DetailsView1.DataBind(); switch (DetailsView1.Rows[5].Cells[1].Text) { case "0": { DetailsView1.Rows[5].Cells[1].Text = "Chưa hoàn thành"; } break; case "1": { DetailsView1.Rows[5].Cells[1].Text = "Đã hoàn thành"; } break; } switch (DetailsView1.Rows[7].Cells[1].Text) { case "0": { DetailsView1.Rows[7].Cells[1].Text = "Công khai"; } break; case "1": { DetailsView1.Rows[7].Cells[1].Text = "Cá nhân"; } break; } btnEdit.CommandArgument = job.id.ToString(); mpePopUp.Show(); }
protected void Accept_Edit(object sender, EventArgs e) { int id = int.Parse(btnAccept.CommandArgument); BO.Job job = new BO.Job(); job.id = id; job.user_id = int.Parse(userID.SelectedItem.Value); if (title.Value != "") { job.title = title.Value; } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Tên công việc không được bỏ trống')</script>"); title.Focus(); return; } job.startDate = Convert.ToDateTime(startDate.Value); if (finishDate.Value != "" && DateTime.Compare(Convert.ToDateTime(finishDate.Value).Date, Convert.ToDateTime(startDate.Value).Date) >= 0 && DateTime.Compare(Convert.ToDateTime(finishDate.Value).Date, DateTime.Now.Date) >= 0) { job.finishDate = Convert.ToDateTime(finishDate.Value); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Ngày kết thúc phải sau hoặc cùng ngày bắt đầu')</script>"); finishDate.Focus(); return; } if (coworker.SelectedItem.Value == "0") { job.coworker = null; } else { job.coworker = coworker.SelectedItem.Value; } job.privacy = int.Parse(privacy.Value); job.status = int.Parse(status.Value); string filePath = ""; string currentFile = ""; if (attach.HasFile) { if (!JobBLL.CheckFileType(attach.FileName)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('File không phù hợp')</script>"); return; } job.attach = JobBLL.GenerateNameFile(attach.FileName); filePath = MapPath("../File/" + job.attach); if (divFileName.InnerText != "") { currentFile = divFileName.InnerText; } } else { job.attach = null; } if (JobBLL.editJob(job)) { ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "alert('Sửa công việc thành công'); window.location='" + Request.ApplicationPath + "Manager/Job.aspx';", true); if (attach.HasFile) { attach.SaveAs(filePath); } if (currentFile != "") { JobBLL.deleteFile(currentFile); } } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "alert('Xảy ra lỗi'); window.location='" + Request.ApplicationPath + "Manager/JobForm.aspx';", true); } }
protected void Accept_Add(object sender, EventArgs e) { BO.Job job = new BO.Job(); job.user_id = int.Parse(Request.Cookies["userInfo"]["id"]); if (title.Value != "") { job.title = title.Value; } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Tên công việc không được bỏ trống')</script>"); title.Focus(); return; } if (startDate.Value != "" && DateTime.Compare(Convert.ToDateTime(startDate.Value).Date, DateTime.Now.Date) == 0) { job.startDate = Convert.ToDateTime(startDate.Value); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Ngày bắt đầu phải là ngày hiện tại')</script>"); startDate.Focus(); return; } if (finishDate.Value != "" && DateTime.Compare(Convert.ToDateTime(finishDate.Value).Date, Convert.ToDateTime(startDate.Value).Date) >= 0) { job.finishDate = Convert.ToDateTime(finishDate.Value); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Ngày kết thúc phải sau hoặc cùng ngày bắt đầu')</script>"); finishDate.Focus(); return; } if (coworker.SelectedItem.Value == "0") { job.coworker = null; } else { job.coworker = coworker.SelectedItem.Value; } job.privacy = int.Parse(privacy.Value); job.status = int.Parse(status.Value); string filePath = ""; if (attach.HasFile) { if (!JobBLL.CheckFileType(attach.FileName)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('File không phù hợp')</script>"); return; } job.attach = JobBLL.GenerateNameFile(attach.FileName); filePath = MapPath("File/" + job.attach); } else { job.attach = null; } if (JobBLL.addJob(job)) { ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "alert('Thêm công việc thành công'); window.location='" + Request.ApplicationPath + "Job.aspx';", true); if (attach.HasFile) { attach.SaveAs(filePath); } } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "alert('Xảy ra lỗi'); window.location='" + Request.ApplicationPath + "JobForm.aspx';", true); } }
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { UserBLL userBLL = new UserBLL(); List <User> listUser = userBLL.getAllUserExceptAdmin(); userID.DataTextField = "name"; userID.DataValueField = "id"; userID.DataSource = listUser; userID.DataBind(); User temp = new User(); temp.id = 0; temp.name = "Không có"; listUser.Insert(0, temp); coworker.DataTextField = "name"; coworker.DataValueField = "id"; coworker.DataSource = listUser; coworker.DataBind(); if (Request.QueryString["id"] != null) { int id = int.Parse(Request.QueryString["id"]); BO.Job job = JobBLL.getJob(id); //var localDateTime = DateTime.Now.ToString(""); <---- have to format like that to set value to input date type userID.SelectedValue = job.user_id.ToString(); title.Value = job.title.ToString(); startDate.Value = job.startDate.ToString("yyyy-MM-dd"); finishDate.Value = job.finishDate.ToString("yyyy-MM-dd"); privacy.Value = job.privacy.ToString(); status.Value = job.status.ToString(); if (job.coworker == null) { coworker.SelectedValue = "0"; } else { coworker.SelectedValue = int.Parse(job.coworker).ToString(); } if (job.attach != null) { divFileName.InnerText = job.attach; } btnAccept.CommandName = "Edit"; btnAccept.CommandArgument = Request.QueryString["id"]; btnDelete.CommandArgument = Request.QueryString["id"]; startDate.Disabled = true; lblTitle.Text = "<h3>Sửa công việc " + job.id.ToString() + "</h3>"; } else { btnAccept.CommandName = "Add"; startDate.Value = DateTime.Now.ToString("yyyy-MM-dd"); lblTitle.Text = "<h3>Thêm công việc</h3>"; } } }
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { UserBLL userBLL = new UserBLL(); List <User> listUser = userBLL.getAllUserExceptMe(int.Parse(Request.Cookies["userInfo"]["id"])); User temp = new User(); temp.id = 0; temp.name = "Không có"; listUser.Insert(0, temp); coworker.DataTextField = "name"; coworker.DataValueField = "id"; coworker.DataSource = listUser; coworker.DataBind(); if (Request.QueryString["id"] != null) { if (!JobBLL.canAccess(int.Parse(Request.Cookies["userInfo"]["id"]), int.Parse(Request.QueryString["id"]))) { ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "alert('Bạn không có quyền truy cập'); window.location='" + Request.ApplicationPath + "Job.aspx';", true); } int id = int.Parse(Request.QueryString["id"]); BO.Job job = JobBLL.getJob(id); //var localDateTime = DateTime.Now.ToString(""); <---- have to format like that to set value to input date type title.Value = job.title.ToString(); startDate.Value = job.startDate.ToString("yyyy-MM-dd"); finishDate.Value = job.finishDate.ToString("yyyy-MM-dd"); privacy.Value = job.privacy.ToString(); status.Value = job.status.ToString(); if (job.coworker == null) { coworker.SelectedValue = ""; } else { coworker.SelectedValue = int.Parse(job.coworker).ToString(); } if (job.attach != null) { divFileName.InnerText = job.attach; } btnAccept.CommandName = "Edit"; btnAccept.CommandArgument = Request.QueryString["id"]; btnDelete.CommandArgument = Request.QueryString["id"]; if (DateTime.Compare(Convert.ToDateTime(job.finishDate.ToString("yyyy-MM-dd")).Date, DateTime.Now.Date) < 0) { title.Disabled = true; startDate.Disabled = true; finishDate.Disabled = true; privacy.Disabled = true; coworker.Enabled = false; coworker.CssClass = "form-control"; } lblTitle.Text = "<h3>Sửa công việc " + job.id.ToString() + "</h3>"; } else { btnAccept.CommandName = "Add"; startDate.Value = DateTime.Now.ToString("yyyy-MM-dd"); lblTitle.Text = "<h3>Thêm công việc</h3>"; } } }