Пример #1
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));
                }
            }
        }
Пример #2
0
 public ActionResult getFuelID(int fuelid)
 {
     try
     {
         QuangHanhManufacturingEntities DBContext = new QuangHanhManufacturingEntities();
         fuelDB activity = DBContext.Database.SqlQuery <fuelDB>(
             @"select f.fuel_id, f.[date], f.equipment_id, f.fuel_type, e.equipment_name , s.supply_name , f.consumption_value , s.unit ,sd.quantity 
              from Equipment.FuelActivitiesConsumption f, Equipment.Equipment e , Supply.Supply s , Supply.RepairRegularly sd
              where e.equipment_id = f.equipment_id and s.supply_id = f.fuel_type and sd.supply_id = s.supply_id and sd.equipment_id = e.equipment_id and f.fuel_id = @fuelid 
              order by f.[date] desc  ", new SqlParameter("fuelid", fuelid)).First();
         activity.stringDate = activity.date.ToString("dd/MM/yyyy");
         return(Json(activity));
     }
     catch (Exception)
     {
         Response.Write("Có lỗi xảy ra, xin vui lòng nhập lại");
         return(new HttpStatusCodeResult(400));
     }
 }