Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
            }
        }