示例#1
0
 public ActionResult Update(int incident_id, string reason, int year, int month, int day, int hour, int minute)
 {
     using (QuangHanhManufacturingEntities DBContext = new QuangHanhManufacturingEntities())
     {
         try
         {
             Incident1 i   = DBContext.Incident1.Find(incident_id);
             DateTime  end = new DateTime(year, month, day, hour, minute, 0);
             if (DateTime.Compare(i.start_time, end) >= 0)
             {
                 return(Json(new { success = false, message = "Thời gian bắt đầu phải nhỏ hơn thời gian kết thúc" }));
             }
             if (i == null)
             {
                 return(Json(new { success = false, message = "Mã sự cố sai" }));
             }
             else
             {
                 i.reason   = reason;
                 i.end_time = new DateTime(year, month, day, hour, minute, 0);
                 i.Equipment.current_status = 1;
                 DBContext.SaveChanges();
                 return(Json(new { success = true, message = "Cập nhật thành công" }));
             }
         }
         catch (Exception)
         {
             return(Json(new { success = false, message = "Có lỗi xảy ra, xin vui lòng thử lại" }));
         }
     }
 }
示例#2
0
        public ActionResult Edit(int incident_id, string equipment, string department, string reason, string detail, int yearStart, int monthStart, int dayStart, int hourStart, int minuteStart, int yearEnd, int monthEnd, int dayEnd, int hourEnd, int minuteEnd)
        {
            using (QuangHanhManufacturingEntities DBContext = new QuangHanhManufacturingEntities())
            {
                try
                {
                    string department_id = DBContext.Departments.Where(x => x.department_name == department).Select(x => x.department_id).FirstOrDefault();
                    if (department_id == null)
                    {
                        return(Json(new { success = false, message = "Phòng ban không tồn tại" }));
                    }
                    DateTime start = new DateTime(yearStart, monthStart, dayStart, hourStart, minuteStart, 0);
                    DateTime end   = new DateTime(yearEnd, monthEnd, dayEnd, hourEnd, minuteEnd, 0);
                    if (DateTime.Compare(start, end) >= 0)
                    {
                        return(Json(new { success = false, message = "Thời gian bắt đầu phải nhỏ hơn thời gian kết thúc" }));
                    }

                    Incident1 i = DBContext.Incident1.Find(incident_id);
                    i.department_id   = department_id;
                    i.detail_location = detail;
                    i.equipment_id    = equipment;
                    i.reason          = reason;
                    i.start_time      = start;
                    i.end_time        = end;

                    DBContext.SaveChanges();
                    return(Json(new { success = true, message = "Chỉnh sửa thành công" }));
                }
                catch (Exception)
                {
                    if (DBContext.Equipments.Find(equipment) == null)
                    {
                        return(Json(new { success = false, message = "Mã thiết bị không tồn tại" }));
                    }
                    else
                    {
                        return(Json(new { success = false, message = "Có lỗi xảy ra, xin vui lòng thử lại" }));
                    }
                }
            }
        }
示例#3
0
        public ActionResult Add(string equipment, string reason, string detail, int yearStart, int monthStart, int dayStart, int hourStart, int minuteStart, int yearEnd, int monthEnd, int dayEnd, int hourEnd, int minuteEnd, string checkBox)
        {
            if (reason == "" && checkBox == "no")
            {
                return(Json(new { success = false, message = "Vui lòng nhập trường lý do" }));
            }
            QuangHanhManufacturingEntities DBContext = new QuangHanhManufacturingEntities();
            Incident1 i = new Incident1();

            using (DbContextTransaction transaction = DBContext.Database.BeginTransaction())
            {
                try
                {
                    Equipment e        = DBContext.Equipments.Find(equipment);
                    string    departID = Session["departID"].ToString();
                    if (departID != "CV" && departID != "ĐK" && e.department_id != departID)
                    {
                        return(Json(new { success = false, message = "Thiết bị không thuộc phân xưởng hiện tại" }));
                    }
                    if (e.current_status == 4)
                    {
                        transaction.Rollback();
                        return(Json(new { success = false, message = "Thiết bị đang có trạng thái hỏng\n không thể thêm sự cố" }));
                    }
                    DateTime start = new DateTime(yearStart, monthStart, dayStart, hourStart, minuteStart, 0);
                    DateTime end   = new DateTime(yearEnd, monthEnd, dayEnd, hourEnd, minuteEnd, 0);
                    if (checkBox.Equals("no") && DateTime.Compare(start, end) >= 0)
                    {
                        return(Json(new { success = false, message = "Thời gian bắt đầu phải nhỏ hơn thời gian kết thúc" }));
                    }
                    i.department_id   = e.department_id;
                    i.detail_location = detail;
                    i.equipment_id    = equipment;
                    i.reason          = reason ?? "";
                    i.start_time      = start;
                    i.end_time        = end;
                    if (checkBox == "yes")
                    {
                        e.current_status = 4;
                        i.reason         = reason ?? "";
                        i.end_time       = null;
                    }

                    DBContext.Incident1.Add(i);
                    DBContext.SaveChanges();

                    Notification nt = new Notification
                    {
                        id_problem    = i.incident_id,
                        description   = "su co",
                        department_id = i.department_id,
                        date          = DateTime.Now.Date,
                        isread        = false
                    };
                    DBContext.Notifications.Add(nt);
                    DBContext.SaveChanges();

                    transaction.Commit();
                    return(Json(new { success = true, message = "Thêm thành công" }));
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    if (DBContext.Database.SqlQuery <Equipment>("SELECT * FROM Equipment WHERE equipment_id = N'" + equipment + "'").Count() == 0)
                    {
                        return(Json(new { success = false, message = "Mã thiết bị không tồn tại" }));
                    }
                    else
                    {
                        return(Json(new { success = false, message = "Có lỗi xảy ra, xin vui lòng thử lại" }));
                    }
                }
            }
        }