Exemplo n.º 1
0
        public JsonResult notifi21()
        {
            if (Session["departID"] == null)
            {
                return(null);
            }
            string depart = Session["departID"].ToString();
            int    month  = DateTime.Now.Month;
            int    year   = DateTime.Now.Year;
            var    check  = db.Notifications.Where(x => x.description == "21" && x.department_id == depart && x.date.Month == month && x.date.Year == year).FirstOrDefault();

            if (check == null)
            {
                var qd = db.MonthlyPlans.Where(x => x.status == 1 && x.date.Month == month && x.date.Year == year && x.department_id == depart).ToList();
                if (qd.Count == 0)
                {
                    Notification no = new Notification
                    {
                        id_problem    = 21,
                        date          = DateTime.Now.Date,
                        description   = "21",
                        department_id = depart,
                        isread        = false
                    };
                    db.Notifications.Add(no);
                    db.SaveChanges();
                }
            }
            return(Json("", JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public ActionResult Add(string supply_id, string supply_name, string unit)
        {
            Supply s = db.Supplies.Find(supply_id);

            if (supply_id.Trim() == "")
            {
                return(Json(new { success = false, message = "Không được để trống trường Mã vật tư" }, JsonRequestBehavior.AllowGet));
            }
            else if (supply_name.Trim() == "")
            {
                return(Json(new { success = false, message = "Không được để trống trường Tên vật tư" }, JsonRequestBehavior.AllowGet));
            }
            else if (unit.Trim() == "")
            {
                return(Json(new { success = false, message = "Không được để trống trường Đơn vị" }, JsonRequestBehavior.AllowGet));
            }
            else if (s != null)
            {
                return(Json(new { success = false, message = "Vật tư đã tồn tại" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                s = new Supply
                {
                    supply_id   = supply_id,
                    supply_name = supply_name,
                    unit        = unit
                };
                db.Supplies.Add(s);
                db.SaveChanges();
                return(Json(new { success = true, message = "Tạo loại vật tư thành công" }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Update(string edit, int id)
        {
            if (edit != "")
            {
                using (DbContextTransaction transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        JArray list = JArray.Parse(edit);
                        foreach (JValue item in list)
                        {
                            if (item.Value.ToString() == "")
                            {
                                continue;
                            }

                            CameraRepairDetail temp = db.CameraRepairDetails.Where(x => x.documentary_id == id && x.room_id == item.Value.ToString()).FirstOrDefault();
                            if (temp.documentary_camera_repair_status == 0)
                            {
                                temp.documentary_camera_repair_status = 1;
                                Acceptance a = new Acceptance
                                {
                                    acceptance_date            = null,
                                    documentary_id             = id,
                                    room_id                    = item.Value.ToString(),
                                    acceptance_camera_quantity = temp.broken_camera_quantity
                                };
                                db.Acceptances.Add(a);
                            }
                        }
                        if ((from docu in db.Documentaries
                             join details in db.CameraRepairDetails on docu.documentary_id equals details.documentary_id
                             where docu.documentary_type == 8 && details.documentary_id == id && details.documentary_camera_repair_status == 0
                             select details).Count() == 0)
                        {
                            Documentary docu = db.Documentaries.Find(id);
                            docu.documentary_status = 2;
                        }

                        db.SaveChanges();
                        transaction.Commit();
                        return(Json(new { success = true, message = "Lưu thành công" }, JsonRequestBehavior.AllowGet));
                    }
                    catch (Exception e)
                    {
                        e.Message.ToString();
                        transaction.Rollback();
                        return(Json(new { success = false, message = "Có lỗi xảy ra" }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            return(Json(new { success = true, message = "Lưu thành công" }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 4
0
        public ActionResult AddCategory(Category ec, string[] id, string[] name, string[] unit)
        {
            QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities();
            Category category = db.Categories.Find(ec.equipment_category_id);

            if (category != null)
            {
                return(Json(new { success = false, message = "Mã loại thiết bị đã tồn tại" }));
            }
            using (DbContextTransaction dbc = db.Database.BeginTransaction())
            {
                try
                {
                    db.Categories.Add(ec);
                    db.SaveChanges();
                    if (id != null)
                    {
                        for (int i = 0; i < id.Count(); i++)
                        {
                            if (!id[i].Equals(""))
                            {
                                CategoryAttribute ea = db.CategoryAttributes.Find(id[i]);
                                if (ea != null)
                                {
                                    continue;
                                }
                                ea = new CategoryAttribute
                                {
                                    equipment_category_id           = ec.equipment_category_id,
                                    equipment_category_attribute_id = id[i],
                                    unit = unit[i],
                                    equipment_category_attribute_name = name[i]
                                };
                                db.CategoryAttributes.Add(ea);
                            }
                        }
                    }
                    db.SaveChanges();
                    dbc.Commit();
                    return(Search("", "", "", "", "", "", "", "", ""));
                }
                catch (Exception e)
                {
                    e.Message.ToString();
                    dbc.Rollback();
                    return(Json(new { success = false, message = "Có lỗi xảy ra" }));
                }
            }
        }
Exemplo n.º 5
0
 public ActionResult delete()
 {
     try
     {
         int work_group_type_id = Convert.ToInt32(Request["work_group_type_id"]);
         using (QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities())
         {
             WorkGroupType workGroupType = db.WorkGroupTypes.Find(work_group_type_id);
             if (workGroupType == null)
             {
                 return(Json(new { error = true, title = "Có lỗi", message = "Không tìm thấy loại công việc tương ứng." }));
             }
             else
             {
                 try
                 {
                     db.WorkGroupTypes.Remove(workGroupType);
                     db.SaveChanges();
                     return(Json(new { success = true, title = "Thành công", message = "Xóa thành công." }));
                 } catch (Exception e)
                 {
                     return(Json(new { error = true, title = "Có lỗi", message = "Dữ liệu về loại công việc đã được sử dụng nên không thể xóa." }));
                 }
             }
         }
     }
     catch (Exception e)
     {
         return(Json(new { error = true, title = "Có lỗi", message = "Có lỗi xảy ra." }));
     }
 }
Exemplo n.º 6
0
 public ActionResult update()
 {
     try
     {
         int    work_group_type_id   = Convert.ToInt32(Request["work_group_type_id"]);
         string work_group_type_name = Request["work_group_type_name"];
         if (work_group_type_name == null || work_group_type_name == "")
         {
             return(Json(new { error = true, title = "Có lỗi", message = "Tên diện công việc không thể để trống." }));
         }
         using (QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities())
         {
             WorkGroupType workGroupType = db.WorkGroupTypes.Find(work_group_type_id);
             if (workGroupType == null)
             {
                 return(Json(new { error = true, title = "Có lỗi", message = "Có lỗi xảy ra." }));
             }
             else
             {
                 workGroupType.name = work_group_type_name;
                 db.SaveChanges();
                 return(Json(new { success = true, title = "Thành công", message = "Cập nhật thành công." }));
             }
         }
     }
     catch (Exception e)
     {
         return(Json(new { error = true, title = "Có lỗi", message = "Có lỗi xảy ra." }));
     }
 }
Exemplo n.º 7
0
        public ActionResult delete()
        {
            try
            {
                string work_work_group_id_param = Request["work_work_group_id"];

                using (QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities())
                {
                    int work_work_group_id = Convert.ToInt32(work_work_group_id_param);
                    try
                    {
                        WorkWorkGroup workWorkGroup = db.WorkWorkGroups.Find(work_work_group_id);
                        db.WorkWorkGroups.Remove(workWorkGroup);
                        db.SaveChanges();
                        return(Json(new { success = true, title = "Thành công", message = "Xóa công việc - nhóm công việc thành công." }));
                    } catch (Exception e)
                    {
                        return(Json(new { success = false, title = "Có lỗi", message = "Dữ liệu công việc - nhóm công việc đang được sử dụng." }));
                    }
                }
            }
            catch (Exception e)
            {
                return(Json(new { error = true, title = "Có lỗi", message = "Có lỗi xảy ra." }));
            }
        }
Exemplo n.º 8
0
 public ActionResult add()
 {
     try
     {
         var add_work_group_type_name = Request["add_work_group_type_name"];
         if (add_work_group_type_name == null || add_work_group_type_name == "")
         {
             return(Json(new { error = true, title = "Có lỗi", message = "Tên diện công việc không thể để trống." }));
         }
         else
         {
             using (QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities())
             {
                 WorkGroupType workGroupType = db.WorkGroupTypes.Where(x => x.name.Equals(add_work_group_type_name)).FirstOrDefault();
                 if (workGroupType == null)
                 {
                     workGroupType      = new WorkGroupType();
                     workGroupType.name = add_work_group_type_name;
                     db.WorkGroupTypes.Add(workGroupType);
                     db.SaveChanges();
                     return(Json(new { success = true, title = "Thành công", message = "Thêm loại công việc mới thành công." }));
                 }
                 else
                 {
                     return(Json(new { error = true, title = "Có lỗi", message = "Đã có tên diện công việc." }));
                 }
             }
         }
     }
     catch (Exception e)
     {
         return(Json(new { error = true, title = "Có lỗi", message = "Có lỗi xảy ra." }));
     }
 }
        public ActionResult addDK(string id, string nameSup, int quan, string dvt)
        {
            QuangHanhManufacturingEntities DBContext = new QuangHanhManufacturingEntities();

            using (DbContextTransaction dbc = DBContext.Database.BeginTransaction())
            {
                try
                {
                    if (nameSup != null && quan != 0)
                    {
                        Equipment s = DBContext.Equipments.Where(x => x.equipment_name == nameSup).FirstOrDefault();

                        string sql_sup = "Equipment.Profile_Add_Update_DK 'add', {0}, {1}, {2}";
                        DBContext.Database.ExecuteSqlCommand(sql_sup, s.equipment_id, id, quan);
                    }
                    DBContext.SaveChanges();
                    dbc.Commit();
                    var sup = DBContext.Database.SqlQuery <ProfileGetListDK_Result>("Equipment.Profile_Get_List 'DK', {0}", id).ToList();
                    return(Json(new { success = true, data = sup }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    e.Message.ToString();
                    dbc.Rollback();
                    return(Json(new { success = false, message = e.Message }, JsonRequestBehavior.AllowGet));
                }
            }
        }
        public ActionResult Add(string supply_id, string supply_name, string unit)
        {
            QuangHanhManufacturingEntities DBContext = new QuangHanhManufacturingEntities();
            Supply s = DBContext.Supplies.Find(supply_id);

            if (supply_id.Trim() == "")
            {
                return(Json(new { success = false, message = "Không được để trống trường Mã vật tư" }, JsonRequestBehavior.AllowGet));
            }
            else
            if (supply_name.Trim() == "")
            {
                return(Json(new { success = false, message = "Không được để trống trường Tên vật tư" }, JsonRequestBehavior.AllowGet));
            }
            else
            if (unit.Trim() == "")
            {
                return(Json(new { success = false, message = "Không được để trống trường Đơn vị" }, JsonRequestBehavior.AllowGet));
            }
            else
            if (s != null)
            {
                return(Json(new { success = false, message = "Vật tư đã tồn tại" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                s             = new Supply();
                s.supply_id   = supply_id;
                s.supply_name = supply_name;
                s.unit        = unit;
                DBContext.Supplies.Add(s);
                DBContext.SaveChanges();
                return(Json(new { success = true, message = "Tạo loại vật tư thành công" }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 11
0
        public ActionResult AddNewDepartment(string departmentJson)
        {
            dynamic dataJson = JObject.Parse(departmentJson);
            string  mpb      = dataJson.mpb;
            string  tpb      = dataJson.tpb;
            string  lpb      = dataJson.lpb;
            bool    isInside = Convert.ToBoolean(dataJson.isInside);

            Department department = new Department {
                department_id = mpb, department_name = tpb, department_type = lpb, isInside = isInside
            };

            try
            {
                using (QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities())
                {
                    var pb = db.Departments.Add(department);
                    db.SaveChanges();
                    return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception)
            {
                return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Edit(int incident_id, string department, string reason, int quan, int yearStart, int monthStart, int dayStart, int hourStart, int minuteStart, int yearEnd, int monthEnd, int dayEnd, int hourEnd, int minuteEnd)
        {
            QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities();

            using (DbContextTransaction transaction = db.Database.BeginTransaction())
            {
                try
                {
                    Incident i     = db.Incidents.Find(incident_id);
                    Room     d     = db.Rooms.Where(x => x.room_name.Equals(department)).FirstOrDefault();
                    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 = "Bạn đã nhập ngày bắt đầu lớn hơn ngày kết thúc" }, JsonRequestBehavior.AllowGet));
                    }
                    i.room_id    = d.room_id;
                    i.reason     = reason;
                    i.start_time = start;
                    i.end_time   = end;
                    i.incident_camera_quantity = quan;


                    db.SaveChanges();
                    transaction.Commit();
                    return(Json(new { success = true, message = "Chỉnh sửa thành công" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return(Json(new { success = false, message = "Có lỗi xảy ra, xin vui lòng thử lại" }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Exemplo n.º 13
0
        public ActionResult SetPhoto()
        {
            QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities();

            using (DbContextTransaction transaction = db.Database.BeginTransaction())
            {
                try
                {
                    Room   r           = db.Rooms.Find(Request["room_id"]);
                    string path        = "/images/camera/";
                    Image  sourceimage = Image.FromStream(Request.Files["img"].InputStream, true, true);
                    r.image_link = r.room_id + ".jfif";
                    db.SaveChanges();
                    if (!Directory.Exists(HostingEnvironment.MapPath(path)))
                    {
                        Directory.CreateDirectory(HostingEnvironment.MapPath(path));
                    }
                    if (sourceimage.Size != null)
                    {
                        sourceimage.Save(HostingEnvironment.MapPath(path + r.image_link));
                    }
                    transaction.Commit();
                    return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Exemplo n.º 14
0
        public ActionResult DeleteDepartment(string department_id)
        {
            try
            {
                using (QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities())
                {
                    var department = db.Departments.Find(department_id);
                    db.Departments.Remove(department);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        return(Json(new { success = false, message = "Dữ liệu bạn xóa đang tồn tại ở những màn hình khác. Do vậy để xóa phân xưởng này bạn phải xóa dữ liệu tại các màn hình có liên quan tới dữ liệu trên." }));
                    }

                    return(Json(new { success = true, message = "Xóa phân xưởng thành công." }));
                }
            }
            catch (Exception e)
            {
                return(Json(new { success = false, message = "Có lỗi xảy ra." }));
            }
        }
Exemplo n.º 15
0
 public ActionResult Edit()
 {
     try
     {
         using (QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities())
         {
             Room r = db.Rooms.Find(Request["room_id"]);
             r.capacity           = Request["capacity"];
             r.disk_status        = Request["status"];
             r.series             = Request["serial"];
             r.note               = Request["note"];
             r.room_name          = Request["location"];
             r.department_id      = Request["department"];
             r.camera_quantity    = int.Parse(Request["quantity"].ToString());
             r.camera_available   = int.Parse(Request["quantity"].ToString());
             r.signal_loss_reason = "";
             r.login_information  = Request["login"];
             db.SaveChanges();
             return(Json(new { success = true, message = "Chỉnh sửa thành công" }));
         }
     }
     catch (Exception)
     {
         return(Json(new { success = false, message = "Có lỗi xảy ra" }));
     }
 }
Exemplo n.º 16
0
        public ActionResult Delete()
        {
            try
            {
                int documentary_id = int.Parse(Request["documentary_id"]);
                using (QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities())
                {
                    Documentary doc = db.Documentaries.Find(documentary_id);
                    if (doc == null)
                    {
                        return(Json(new { success = false, message = "Mã quyết định không tồn tại" }));
                    }

                    if (doc.documentary_code != null)
                    {
                        return(Json(new { success = false, message = "Bạn không được xóa quyết định này" }));
                    }

                    db.Documentaries.Remove(doc);
                    db.SaveChanges();
                    return(Json(new { success = true, message = "Xóa thành công" }));
                }
            }
            catch (Exception)
            {
                return(Json(new { success = false, message = "Có lỗi xảy ra" }));
            }
        }
Exemplo n.º 17
0
        public JsonResult NotYetDelete(string id)
        {
            QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities();

            db.Configuration.LazyLoadingEnabled = false;
            using (DbContextTransaction dbct = db.Database.BeginTransaction())
            {
                try
                {
                    List <Termination> list     = db.Terminations.Where(x => x.decision_id + "" == id).ToList();
                    string             listMaNV = "";
                    foreach (var MaNV in list)
                    {
                        listMaNV += "'" + MaNV.employee_id + "'" + ",";
                    }
                    listMaNV = listMaNV.Substring(0, listMaNV.Length - 1);
                    string query = @"update HumanResources.Employee set 
                        current_status_id = 1 where employee_id in(" + listMaNV + ") " +
                                   "delete from HumanResources.Termination where decision_id = @id " +
                                   "delete from HumanResources.Decision where decision_id = @id";
                    db.Database.ExecuteSqlCommand(query, new SqlParameter("id", id));
                    db.SaveChanges();
                    dbct.Commit();
                    return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    dbct.Rollback();
                    return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Exemplo n.º 18
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" }));
         }
     }
 }
        public ActionResult addTT(string idTT, string nameTT, int quan, string dvt, string eid)
        {
            QuangHanhManufacturingEntities DBContext = new QuangHanhManufacturingEntities();

            using (DbContextTransaction dbc = DBContext.Database.BeginTransaction())
            {
                try
                {
                    if (nameTT != null && quan != 0)
                    {
                        string sql_sup = "Equipment.Profile_Add_TT {0}, {1}, {2}, {3}, {4}";
                        DBContext.Database.ExecuteSqlCommand(sql_sup, idTT, nameTT, quan, dvt, eid);
                    }
                    DBContext.SaveChanges();
                    dbc.Commit();
                    var sup = DBContext.Database.SqlQuery <QUANGHANH2.Models.Attribute>("Equipment.Profile_Get_List 'TT', {0}", eid).ToList();
                    return(Json(new { success = true, data = sup }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    e.Message.ToString();
                    dbc.Rollback();
                    return(Json(new { success = false, message = e.Message }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Exemplo n.º 20
0
        public ActionResult EditFuel(int consumption_value, string fuel_type, string date1, String equipmentId, int fuelid)
        {
            QuangHanhManufacturingEntities DBContext = new QuangHanhManufacturingEntities();

            using (DbContextTransaction transaction = DBContext.Database.BeginTransaction())
            {
                try
                {
                    // only taken by each department.
                    string department_id = Session["departID"].ToString();

                    //update
                    Equipment i = DBContext.Equipments.Find(equipmentId);
                    //check vehicle eq exist in department
                    FuelDB check = DBContext.Database.SqlQuery <FuelDB>(@"select equipment_id , equipment_name from 
                         (select distinct e.equipment_id, e.equipment_name ,e.department_id from Equipment.Equipment e inner join Equipment.CategoryAttribute ea 
                          on ea.Equipment_category_id = e.Equipment_category_id where 
                         ea.Equipment_category_attribute_name = N'Số khung' or ea.Equipment_category_attribute_name = N'Số máy') as t 
                         where department_id = @department_id
                         AND equipment_id = @equipmentId "
                                                                        , new SqlParameter("department_id", department_id)
                                                                        , new SqlParameter("equipmentId", equipmentId)
                                                                        ).First();

                    Supply s    = DBContext.Database.SqlQuery <Supply>("select * from Supply.Supply where supply_id=@supply_id", new SqlParameter("supply_id", fuel_type)).First();
                    FuelDB f    = DBContext.Database.SqlQuery <FuelDB>("select * from Equipment.FuelActivitiesConsumption where fuel_id=" + fuelid + "").First();
                    string date = DateTime.ParseExact(date1, "dd/MM/yyyy", null).ToString("MM-dd-yyyy");
                    DBContext.Database.ExecuteSqlCommand("UPDATE Equipment.FuelActivitiesConsumption  set fuel_type =@fuel_type, [date] =@date1, consumption_value = @consumption_value, equipment_id = @equipmentId where fuel_id= @fuelid",
                                                         new SqlParameter("fuel_type", fuel_type), new SqlParameter("date1", date), new SqlParameter("consumption_value", consumption_value), new SqlParameter("equipmentId", equipmentId), new SqlParameter("fuelId", fuelid));

                    EditSupply_duphong(fuel_type, consumption_value);
                    //get old and new.

                    DBContext.SaveChanges();

                    transaction.Commit();
                    return(new HttpStatusCodeResult(201));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    string output = "";
                    if (DBContext.Database.SqlQuery <Equipment>("SELECT * FROM Equipment.Equipment WHERE equipment_id = N'" + equipmentId + "'").Count() == 0)
                    {
                        output += "Mã thiết bị không tồn tại\n";
                    }
                    if (DBContext.Supplies.Where(x => (x.supply_id == fuel_type)).Count() == 0)
                    {
                        output += "Mã Nhiên Liệu không tồn tại\n";
                    }
                    if (output == "")
                    {
                        output += "Có lỗi xảy ra, xin vui lòng nhập lại";
                    }
                    Response.Write(output);
                    return(new HttpStatusCodeResult(400));
                }
            }
        }
Exemplo n.º 21
0
 public ActionResult Add()
 {
     try
     {
         QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities();
         Room r = new Room
         {
             room_id            = Request["id"],
             capacity           = Request["capacity"],
             disk_status        = Request["status"],
             series             = Request["serial"],
             note               = Request["note"],
             room_name          = Request["location"],
             department_id      = Request["department"],
             camera_quantity    = int.Parse(Request["quantity"].ToString()),
             camera_available   = int.Parse(Request["quantity"].ToString()),
             signal_loss_reason = "",
             disk_saveable      = bool.Parse(Request["saveable"].ToString()),
             login_information  = Request["login"]
         };
         db.Rooms.Add(r);
         db.SaveChanges();
         if (Request.Files["img"] != null)
         {
             Image sourceimage = Image.FromStream(Request.Files["img"].InputStream, true, true);
             r.image_link = r.room_id + ".jfif";
             db.SaveChanges();
             string path = "/images/camera/";
             if (!Directory.Exists(HostingEnvironment.MapPath(path)))
             {
                 Directory.CreateDirectory(HostingEnvironment.MapPath(path));
             }
             if (sourceimage.Size != null)
             {
                 sourceimage.Save(HostingEnvironment.MapPath(path + r.image_link));
             }
         }
         return(Json(new { success = true, message = "Thêm thành công" }));
     }
     catch (Exception)
     {
         return(Json(new { success = false, message = "Có lỗi xảy ra" }));
     }
 }
Exemplo n.º 22
0
        public ActionResult Index(string type, string date, string month, string quarter, string year)
        {
            Wherecondition(type, date, month, quarter, year);
            List <content> content = new List <content>();
            int            tangbag = 0; int giambag = 0;

            using (QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities())
            {
                var nhom = db.Database.SqlQuery <CaName>("select ec.Equipment_category_name as MaNhom from Equipment e,Equipment_category ec where e.Equipment_category_id=ec.Equipment_category_id group by ec.Equipment_category_name").ToList();
                foreach (var item in nhom)
                {
                    if (ViewBag.ContentReportTang.Count > 0 || ViewBag.ContentReportGiam.Count > 0)
                    {
                        string find = item.MaNhom;
                        int    tang = 0, giam = 0, Thang = 0, Nam = 0;
                        string MaNhom = ""; string MaHieu = ""; DateTime usedDay = DateTime.Now;
                        foreach (var item1 in ViewBag.ContentReportTang)
                        {
                            if (find.Equals(item1.MaNhom))
                            {
                                tang++;
                                tangbag++;
                                MaNhom = item1.MaNhom; MaHieu = item1.MaHieu; usedDay = item1.usedDay; Thang = item1.Thang; Nam = item1.Nam;
                            }
                        }
                        foreach (var item1 in ViewBag.ContentReportGiam)
                        {
                            if (find.Equals(item1.MaNhom))
                            {
                                giam++;
                                giambag++;
                                MaNhom = item1.MaNhom; MaHieu = item1.MaHieu; usedDay = item1.usedDay; Thang = item1.Thang; Nam = item1.Nam;
                            }
                        }
                        if (!String.IsNullOrEmpty(MaNhom))
                        {
                            content.Add(new content
                            {
                                Thang   = Thang,
                                Nam     = Nam,
                                MaNhom  = MaNhom,
                                MaHieu  = MaHieu,
                                usedDay = usedDay.Date,
                                Tang    = tang,
                                Giam    = giam
                            });
                        }
                    }
                }
                db.SaveChanges();
            }
            ViewBag.Tang    = tangbag;
            ViewBag.Giam    = giambag;
            ViewBag.content = content;
            return(View("/Views/CDVT/Report/TangGiam.cshtml"));
        }
        public ActionResult Edit(string room_id, int documentary_id)
        {
            QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities();

            using (DbContextTransaction transaction = db.Database.BeginTransaction())
            {
                try
                {
                    Acceptance acceptance = db.Acceptances.Where(x => x.documentary_id == documentary_id && x.room_id == room_id).FirstOrDefault();
                    if (acceptance != null && acceptance.acceptance_date != null)
                    {
                        return(Json(new { success = false, message = "Thiết bị đã được nghiệm thu" }));
                    }

                    acceptance.acceptance_date = DateTime.Now;
                    db.SaveChanges();

                    int acceptance_left = db.Acceptances.Where(x => x.documentary_id == documentary_id && x.acceptance_date != null).Count();

                    if (acceptance_left == 0)
                    {
                        Documentary documentary = db.Documentaries.Find(documentary_id);
                        documentary.documentary_status = 3;
                    }

                    Room r = db.Rooms.Find(room_id);
                    CameraRepairDetail detail = db.CameraRepairDetails.Where(x => x.documentary_id == documentary_id && x.room_id == room_id).FirstOrDefault();
                    r.camera_available += detail.broken_camera_quantity;

                    db.SaveChanges();
                    transaction.Commit();
                    return(Json(new { success = true, message = "Nghiệm thu thành công" }));
                }
                catch (Exception e)
                {
                    e.Message.ToString();
                    transaction.Rollback();
                    return(Json(new { success = false, message = "Nghiệm thu thất bại" }));
                }
            }
        }
Exemplo n.º 24
0
        public void EditSupply_duphong(String supplyid, int quantity)
        {
            QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities();
            RepairRegularly1 duphong          = db.RepairRegularly1.Where(x => x.supply_id == supplyid).FirstOrDefault();

            if (duphong != null)
            {
                duphong.quantity       -= quantity;
                db.Entry(duphong).State = EntityState.Modified;
            }
            db.SaveChanges();
        }
Exemplo n.º 25
0
        public ActionResult EditFuel(int consumption_value, string fuel_type, string date1, String equipmentId, int fuelid)
        {
            QuangHanhManufacturingEntities DBContext = new QuangHanhManufacturingEntities();

            using (DbContextTransaction transaction = DBContext.Database.BeginTransaction())
            {
                try
                {
                    // only taken by each department.
                    string department_id = Session["departID"].ToString();

                    Equipment i = DBContext.Equipments.Where(x => (x.department_id == department_id && x.equipment_id == equipmentId)).First();

                    Supply s    = DBContext.Database.SqlQuery <Supply>("select * from Supply.Supply where supply_id=@supply_id", new SqlParameter("supply_id", fuel_type)).First();
                    fuelDB f    = DBContext.Database.SqlQuery <fuelDB>("select * from Equipment.FuelActivitiesConsumption where fuel_id=@fuelid", new SqlParameter("fuelid", fuelid)).First();
                    string date = DateTime.ParseExact(date1, "dd/MM/yyyy", null).ToString("MM-dd-yyyy");


                    DBContext.Database.ExecuteSqlCommand("UPDATE Equipment.FuelActivitiesConsumption  set fuel_type =@fuel_type, [date] =@date1, consumption_value = @consumption_value, equipment_id = @equipmentId where fuel_id= @fuelid",
                                                         new SqlParameter("fuel_type", fuel_type), new SqlParameter("date1", DateTime.ParseExact(date1, "dd/MM/yyyy", null)), new SqlParameter("consumption_value", consumption_value), new SqlParameter("equipmentId", equipmentId), new SqlParameter("fuelId", fuelid));


                    //edit supply du phong.
                    int    oldQuantity    = f.consumption_value;
                    string oldEquipmentId = f.equipment_id;
                    string oldSupplyId    = f.fuel_type;
                    EditSupply_duphong(oldEquipmentId, oldSupplyId, oldQuantity, equipmentId, fuel_type, consumption_value);

                    DBContext.SaveChanges();
                    transaction.Commit();
                    return(new HttpStatusCodeResult(201));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    string output = "";
                    if (DBContext.Database.SqlQuery <Equipment>("SELECT * FROM Equipment.Equipment WHERE equipment_id = N'" + equipmentId + "'").Count() == 0)
                    {
                        output += "Mã thiết bị không tồn tại\n";
                    }
                    if (DBContext.Supplies.Where(x => (x.supply_id == fuel_type)).Count() == 0)
                    {
                        output += "Mã Nhiên Liệu không tồn tại\n";
                    }
                    if (output == "")
                    {
                        output += "Có lỗi xảy ra, xin vui lòng nhập lại";
                    }
                    Response.Write(output);
                    return(new HttpStatusCodeResult(400));
                }
            }
        }
Exemplo n.º 26
0
        private void EditSupply_duphong(string oldEquipmentId, string oldSupplyid, int oldQuantity, string newEquipmentId, string newSupplyid, int newQuantity)
        {
            //find old supplies by device.
            QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities();

            using (DbContextTransaction transaction = db.Database.BeginTransaction())
            {
                try
                {
                    //if equipmentId and supplyId doesn't change after editing.
                    if (oldEquipmentId == newEquipmentId && oldSupplyid == newSupplyid)
                    {
                        RepairRegularly1 duphong = db.RepairRegularly1.Where(x => (x.supply_id == newSupplyid && x.equipment_id == newEquipmentId)).FirstOrDefault();
                        if (duphong != null)
                        {
                            duphong.quantity       += oldQuantity;
                            duphong.quantity       -= newQuantity;
                            db.Entry(duphong).State = EntityState.Modified;
                        }
                    }
                    else
                    {
                        //update quantity of old and new supplies remaining by each eqID.
                        RepairRegularly1 oldRecord = db.RepairRegularly1.Where(x => (x.supply_id == oldSupplyid && x.equipment_id == oldEquipmentId)).FirstOrDefault();
                        RepairRegularly1 newRecord = db.RepairRegularly1.Where(x => (x.supply_id == newSupplyid && x.equipment_id == newEquipmentId)).FirstOrDefault();
                        oldRecord.quantity += oldQuantity;

                        // if new doesn't exist => create new with quantity = -newQuantity
                        if (newRecord == null)
                        {
                            RepairRegularly1 sp = new RepairRegularly1()
                            {
                                supply_id    = newSupplyid,
                                equipment_id = newEquipmentId,
                                quantity     = -newQuantity
                            };
                            db.RepairRegularly1.Add(sp);
                        }
                        else
                        {
                            newRecord.quantity -= newQuantity;
                        }
                    }
                    db.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                }
            }
        }
Exemplo n.º 27
0
        public JsonResult UpdateSoQD(string id, string SoQD)
        {
            QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities();

            using (DbContextTransaction dbct = db.Database.BeginTransaction())
            {
                try
                {
                    if (!SoQD.Equals(""))
                    {
                        string          query  = @"select * from HumanResources.Decision where number = @SoQD";
                        List <Decision> qdList = db.Database.SqlQuery <Decision>(query, new SqlParameter("SoQD", SoQD)).ToList();

                        if (qdList.Count > 0)
                        {
                            return(Json(new { success = false, message = "Số quyết định trùng" }, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            int      MaQD = Convert.ToInt32(id);
                            Decision qd   = db.Decisions.Where(x => x.decision_id == MaQD).FirstOrDefault();
                            qd.number          = SoQD;
                            qd.date            = DateTime.Now.AddDays(2);
                            db.Entry(qd).State = EntityState.Modified;

                            List <string> maNV = db.Terminations.Where(x => x.decision_id == qd.decision_id).
                                                 Select(x => x.employee_id).ToList();
                            foreach (var item in maNV)
                            {
                                var Nv = db.Employees.Where(nv => nv.employee_id == item).FirstOrDefault();
                                Nv.current_status_id = 2;
                                db.Entry(Nv).State   = EntityState.Modified;
                            }

                            db.SaveChanges();
                            dbct.Commit();
                        }
                    }
                    else
                    {
                        return(Json(new { success = false, message = "Chưa nhập số quyết định" }, JsonRequestBehavior.AllowGet));
                    }
                    return(Json(new { success = true, message = "Thêm thành công" }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception e)
                {
                    dbct.Rollback();
                    return(Json(new { success = false, message = "Có lỗi khi thêm" }, JsonRequestBehavior.AllowGet));
                }
            }
        }
Exemplo n.º 28
0
 public JsonResult ResetPassword(string oldPass, string newPass, string rePass)
 {
     try
     {
         int    id      = Convert.ToInt32(Session["account_id"]);
         string passXc  = new XCryptEngine(XCryptEngine.AlgorithmType.MD5).Encrypt(oldPass, "pl");
         string rePasss = new XCryptEngine(XCryptEngine.AlgorithmType.MD5).Encrypt(rePass, "pl");
         var    user    = db.Accounts.Where(x => x.ID == id).FirstOrDefault();
         if (string.IsNullOrEmpty(oldPass) || string.IsNullOrEmpty(newPass) || string.IsNullOrEmpty(rePass))
         {
             return(Json(new Result()
             {
                 CodeError = 1,
                 Data = "Mật khẩu không được để trống"
             }, JsonRequestBehavior.AllowGet));
         }
         if (!newPass.Equals(rePass))
         {
             return(Json(new Result()
             {
                 CodeError = 1,
                 Data = "2 mật khẩu không trùng khớp"
             }, JsonRequestBehavior.AllowGet));
         }
         if (!user.Password.Equals(passXc))
         {
             return(Json(new Result()
             {
                 CodeError = 1,
                 Data = "Mật khẩu cũ không đúng"
             }, JsonRequestBehavior.AllowGet));
         }
         user.Password        = rePasss;
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(Json(new Result()
         {
             CodeError = 2,
             Data = "Thay đổi mật khẩu thành công"
         }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception e)
     {
         return(Json(new Result()
         {
             CodeError = 1,
             Data = "Có lỗi xảy ra. Vui lòng thử lại!"
         }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 29
0
        public ActionResult AddQDQT(int documentory_id)
        {
            QuangHanhManufacturingEntities dbContext = new QuangHanhManufacturingEntities();
            string  username = Session["Username"].ToString();
            Account account  = dbContext.Accounts.Where(x => x.Username.Equals(username)).FirstOrDefault <Account>();
            Important_Documentary checkDoc = dbContext.Important_Documentary.Where(x => x.documentary_id == documentory_id && x.AccountID == account.ID).FirstOrDefault();

            if (checkDoc == null)
            {
                Important_Documentary important_Documentary = new Important_Documentary
                {
                    documentary_id = documentory_id,
                    AccountID      = account.ID
                };
                dbContext.Important_Documentary.Add(important_Documentary);
                dbContext.SaveChanges();
            }
            else
            {
                dbContext.Important_Documentary.Remove(checkDoc);
                dbContext.SaveChanges();
            }
            return(Json(new { message = "Success" }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 30
0
 public ActionResult Delete(string room_id)
 {
     using (QuangHanhManufacturingEntities db = new QuangHanhManufacturingEntities())
     {
         try
         {
             db.Configuration.LazyLoadingEnabled = false;
             db.Rooms.Remove(db.Rooms.Find(room_id));
             db.SaveChanges();
             return(Json(new { success = true, message = "Xóa thành công" }));
         }
         catch (Exception)
         {
             Room r = db.Rooms.Find(Request["room_id"]);
             if (r != null)
             {
                 r.camera_quantity  = 0;
                 r.camera_available = 0;
                 db.SaveChanges();
             }
             return(Json(new { success = true, message = "Xóa thành công" }));
         }
     }
 }