public string CreateAndUpdateMaintenance(int id,int machineID, DateTime startDate, DateTime startTime, DateTime endDate, DateTime endTime)
 {
     DateTime startDateTime = startDate.Add(startTime.TimeOfDay);
     DateTime endDateTime = endDate.Add(endTime.TimeOfDay);
     Maintenance newMaintenance = new Maintenance(id,machineID,startDateTime,endDateTime);
     return dataMachine.UpdateMaintenance(newMaintenance);
 }
Exemple #2
0
 public string SaveMaintenance(Maintenance maintenance)
 {
     try
     {
         SqlCommand saveMaintenanceCmd = new SqlCommand("saveMaintenance", conn);
         saveMaintenanceCmd.CommandType = CommandType.StoredProcedure;
         saveMaintenanceCmd.Parameters.Add(new SqlParameter("@MachineID", maintenance.MachineID));
         saveMaintenanceCmd.Parameters.Add(new SqlParameter("@StartTime", maintenance.StartTime));
         saveMaintenanceCmd.Parameters.Add(new SqlParameter("@EndTime", maintenance.EndTime));
         conn.Open();
         saveMaintenanceCmd.ExecuteNonQuery();
         conn.Close();
         return "Maintenance saved";
     }
     catch(SqlException e)
     {
         return e.Message; 
     }
 }
Exemple #3
0
        public List<Machine> getMachineList()
        {
            List<Machine> allMachines = new List<Machine>();

            SqlCommand getMachinesCmd = new SqlCommand("getMachines", conn);
            getMachinesCmd.CommandType = CommandType.StoredProcedure;
            DataTable machineTable = new DataTable();
            SqlDataAdapter adapter = new SqlDataAdapter(getMachinesCmd);
            conn.Open();
            adapter.Fill(machineTable);
            SqlDataReader reader = getMachinesCmd.ExecuteReader();
            reader.Read();
            conn.Close();
            foreach (DataRow row in machineTable.Rows)
            {                
                Machine newMachine = new Machine(int.Parse(row["ID"].ToString()), row["Name"].ToString(), bool.Parse(row["ProductionUse"].ToString()), DateTime.Parse(row["DateBought"].ToString()), double.Parse(row["PurchasePrice"].ToString()), double.Parse(row["ScrapValue"].ToString()), int.Parse(row["Lifespan"].ToString()), double.Parse(row["InterestRate"].ToString()));
                allMachines.Add(newMachine);
            }
            foreach(Machine tempMachine in allMachines)
            {
                SqlCommand getMaintenanceCmd = new SqlCommand("getMaintenance", conn);
                getMaintenanceCmd.CommandType = CommandType.StoredProcedure;
                getMaintenanceCmd.Parameters.Add(new SqlParameter("@MachineId", tempMachine.Id));
                DataTable maintenanceTable = new DataTable();
                SqlDataAdapter adapter2 = new SqlDataAdapter(getMaintenanceCmd);
                conn.Open();
                adapter2.Fill(maintenanceTable);
                SqlDataReader reader2 = getMaintenanceCmd.ExecuteReader();
                reader2.Read();
                conn.Close();
                List<Maintenance> maintenanceList = new List<Maintenance>();
                foreach (DataRow row2 in maintenanceTable.Rows)
                {
                    Maintenance newMaintenance = new Maintenance(int.Parse(row2["ID"].ToString()), int.Parse(row2["MachineID"].ToString()), DateTime.Parse(row2["StartTime"].ToString()), DateTime.Parse(row2["EndTime"].ToString()));
                    tempMachine.maintenanceDaysList.Add(newMaintenance);
                }
            }

            return allMachines;
        }
Exemple #4
0
 public List<Maintenance> GetAllMaintenance()
 {
     SqlCommand GetAllMaintenanceCMD = new SqlCommand("GetAllMaintenance", conn);
     GetAllMaintenanceCMD.CommandType = CommandType.StoredProcedure;
     DataTable maintenanceTable = new DataTable();
     SqlDataAdapter adapter2 = new SqlDataAdapter(GetAllMaintenanceCMD);
     conn.Open();
     adapter2.Fill(maintenanceTable);
     SqlDataReader reader2 = GetAllMaintenanceCMD.ExecuteReader();
     reader2.Read();
     conn.Close();
     List<Maintenance> maintenanceList = new List<Maintenance>();
     foreach (DataRow row2 in maintenanceTable.Rows)
     {
         Maintenance newMaintenance = new Maintenance(int.Parse(row2["ID"].ToString()), int.Parse(row2["MachineID"].ToString()), DateTime.Parse(row2["StartTime"].ToString()), DateTime.Parse(row2["EndTime"].ToString()));
         maintenanceList.Add(newMaintenance);
     }
     return maintenanceList;
 }