Exemplo n.º 1
0
        internal List <Repairs> ShowStudentsRequest(string stud_id)
        {
            Repairs        repair_request;
            List <Repairs> repair_requests = new List <Repairs>();

            try
            {
                string        QueryString = "select * from students_requests where student_id = @sid and repair_date is null;";
                NpgsqlCommand Command     =
                    new NpgsqlCommand(QueryString, sqlConnection.CreateConnection.connection);
                Command.Parameters.AddWithValue("@sid", Convert.ToInt32(stud_id));
                NpgsqlDataReader dataReader = Command.ExecuteReader();
                foreach (DbDataRecord dbDataRecord in dataReader)
                {
                    repair_request = new Repairs(
                        dbDataRecord["id"].ToString(),
                        dbDataRecord["type"].ToString(),
                        dbDataRecord["theme"].ToString(),
                        dbDataRecord["request_date"].ToString(),
                        dbDataRecord["student_id"].ToString());
                    repair_requests.Add(repair_request);
                }
                dataReader.Close();
            }
            catch (PostgresException ex)
            {
                MessageBox.Show("Ошибка базы данных \n" + Convert.ToString(ex));
            }
            return(repair_requests);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //Generate request
            var receptionist = new Receptionist();
            var mechanic     = new Mechanic();
            var manager      = new Manager();

            //Set up chain of successors
            receptionist.SuccessorA = mechanic;
            mechanic.SuccessorA     = manager;
            manager.SuccessorA      = mechanic;
            manager.SuccessorB      = receptionist;

            //generate car repairs
            var repairs = new Repairs()
            {
                clientName = "Robert Paulson",
                carMake    = "Ford",
                carModel   = "Mustang",
                carYear    = 2002,
                parts      = new List <RepairPart>()
                {
                    new RepairPart()
                    {
                        partName = "exhaust pipe", partId = "EXH192383", laborCost = 75.0, partCost = 115.0
                    }
                }
            };

            //start chain of responsibility
            receptionist.ProcessRequest(repairs);

            //display console
            Console.ReadLine();
        }
Exemplo n.º 3
0
        internal List <Repairs> GetAllRequests()
        {
            Repairs        repair;
            List <Repairs> repairs = new List <Repairs>();

            try
            {
                string        QueryString = "select * from repair_request";
                NpgsqlCommand Command     =
                    new NpgsqlCommand(QueryString, sqlConnection.CreateConnection.connection);
                NpgsqlDataReader dataReader = Command.ExecuteReader();
                foreach (DbDataRecord dbDataRecord in dataReader)
                {
                    repair = new Repairs(
                        dbDataRecord["id"].ToString(),
                        dbDataRecord["room_student_id"].ToString(),
                        dbDataRecord["type"].ToString(),
                        dbDataRecord["theme"].ToString(),
                        dbDataRecord["request_date"].ToString(),
                        dbDataRecord["repair_date"].ToString());
                    repairs.Add(repair);
                }
                dataReader.Close();
            }
            catch (PostgresException ex)
            {
                MessageBox.Show("Ошибка базы данных \n" + Convert.ToString(ex));
            }
            return(repairs);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Select the record for a name.
        /// </summary>
        //public static Repairs SelectForName(string pName, Database pDb = null)
        //{
        //    Database db;
        //    if (pDb == null)
        //    {
        //        db = new Database();
        //        db.Connect();
        //    }
        //    else
        //    {
        //        db = pDb;
        //    }

        //    SqlCommand command = db.CreateCommand(SQL_SELECT_NAME);

        //    command.Parameters.AddWithValue("@name", pName);
        //    SqlDataReader reader = db.Select(command);

        //    Collection<Repairs> repairss = Read(reader);
        //    Repairs v = null;
        //    if (repairss.Count == 1)
        //    {
        //        v = repairss[0];
        //    }
        //    reader.Close();

        //    if (pDb == null)
        //    {
        //        db.Close();
        //    }

        //    return v;
        //}


        private static Collection <Repairs> Read(SqlDataReader reader)
        {
            Collection <Repairs> repairss = new Collection <Repairs>();

            while (reader.Read())
            {
                Repairs repairs = new Repairs();
                int     i       = -1;
                repairs.id_repair = reader.GetInt32(++i);
                repairs.fault     = reader.GetString(++i);
                repairs.date      = reader.GetDateTime(++i);
                if (reader.IsDBNull(++i))
                {
                    repairs.date_end = null;
                }
                else
                {
                    repairs.date_end = reader.GetDateTime(i);
                }

                repairs.cost = reader.GetDecimal(++i);                   // repairs.email = reader.IsDBNull(++i) ? null : reader.GetString(++i);
                repairs.serviceman.id_serviceman = reader.GetInt32(++i); // reader.IsDBNull(++i) ? "" : reader.GetString(++i);
                repairs.vehicle.id_vehicle       = reader.GetInt32(++i);


                repairss.Add(repairs);
            }
            return(repairss);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Type,Price,Address,Description,Days,Area,imageUrl")] Repairs repairs)
        {
            if (id != repairs.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(repairs);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RepairsExists(repairs.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(GetRepairs)));
            }
            return(Ok(repairs));
        }
Exemplo n.º 6
0
        public void AddRepairsTest()
        {
            Exploitation     explo1     = new Exploitation(1250M, "Tyres changed", new DateTime(2017, 12, 01), "355/25R1 107 Y Pirelli PZERO");
            Insurance        insurance1 = new Insurance(1500M, "OC", new DateTime(2017, 05, 11), true, new DateTime(2018, 05, 10), "PZU S.A.");
            LooksMaintenance looks1     = new LooksMaintenance(12.50M, "Pranie tapicerki", new DateTime(2017, 12, 01), "Added wunderbaum");
            Repairs          repair1    = new Repairs(1250M, "Uszczelka pod głowica", new DateTime(2017, 12, 01), "U pana Stasia");
            Service          service1   = new Service(750M, "Distribution system fix", new DateTime(2017, 12, 01), "Zenek Serwis");

            User user = new User();
            Car  car1 = CreateNewCarBrandModelYear("Alfa Romeo", "159", new DateTime(2005, 01, 01));
            Car  car2 = CreateNewCarBrandModelYear("BMW", "I8", new DateTime(2010, 01, 01));

            user.AddNewCar(car1);
            user.AddNewCar(car2);

            //user.UserCars[1].Exploitation.Add(explo1);
            //user.UserCars[1].Insurance.Add(insurance1);
            //user.UserCars[1].LooksMaintenance.Add(looks1);
            //user.UserCars[1].Repairs.Add(repair1);
            //user.UserCars[1].Services.Add(service1);

            //Assert.AreEqual(1, user.UserCars[1].Exploitation.Count());
            //Assert.AreEqual(1, user.UserCars[1].Insurance.Count());
            //Assert.AreEqual(1, user.UserCars[1].LooksMaintenance.Count());
            //Assert.AreEqual(1, user.UserCars[1].Repairs.Count());
            //Assert.AreEqual(1, user.UserCars[1].Insurance.Count());
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Edit(Repairs repairToClose)
        {
            var repairs = await _context.Repairs
                          .Include(r => r.InstrumentInventory)
                          .Include(r => r.Technician)
                          .FirstAsync(m => m.TechnicianId == repairToClose.TechnicianId &&
                                      m.InstrumentInventoryId == repairToClose.InstrumentInventoryId &&
                                      m.RepairEnd == null);

            repairs.RepairEnd = DateTime.Now;
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(repairs);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RepairsExists(repairs.InstrumentInventoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["InstrumentInventoryId"] = new SelectList(_context.InstrumentInventory, "InstrumentInventoryId", "Manufacturer", repairs.InstrumentInventoryId);
            ViewData["TechnicianId"]          = new SelectList(_context.Technician, "TechnicianId", "TechnicianId", repairs.TechnicianId);
            return(View(repairs));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,ReceiveDate,ReleaseDate,Genre,Price,Rating")] Repairs repairs)
        {
            if (id != repairs.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(repairs);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RepairsExists(repairs.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(repairs));
        }
Exemplo n.º 9
0
 public void AddNewRepair(Repairs repair)
 {
     using (ServiceContext ctx = new ServiceContext())
     {
         ctx.Repairs.Add(repair);
         ctx.SaveChanges();
     }
 }
Exemplo n.º 10
0
 public void insertRepair(Repairs re)
 {
     db.Cmd             = db.Conn.CreateCommand();//String in apostrophes
     db.Cmd.CommandText = "INSERT INTO Repairs "
                          + "VALUES (" + re.RentalID + ", '" + re.DamageDetails + "' ," + re.RepairCost + "," + "@RepairDate" + "," + "@RepairPaymentDate" + ")";
     db.Cmd.Parameters.AddWithValue("@RepairDate", re.RepairDate);
     db.Cmd.Parameters.AddWithValue("@RepairPaymentDate", re.RepairPaymentDate);
     db.Cmd.ExecuteNonQuery();
 }
Exemplo n.º 11
0
 /// <summary>
 /// Prepare a command.
 /// </summary>
 private static void PrepareCommand(SqlCommand command, Repairs r)
 {
     command.Parameters.AddWithValue("@id_repair", r.id_repair);
     command.Parameters.AddWithValue("@fault", r.fault);
     command.Parameters.AddWithValue("@date", r.date);
     command.Parameters.AddWithValue("@date_end", r.date_end);
     command.Parameters.AddWithValue("@cost ", r.cost);
     command.Parameters.AddWithValue("@id_serviceman", r.serviceman.id_serviceman);
     command.Parameters.AddWithValue("@id_vehicle", r.vehicle.id_vehicle);
 }
Exemplo n.º 12
0
        public async Task <IActionResult> Create([Bind("Id,Type,Price,Address,Description,Days,Area,imageUrl")] Repairs repairs)
        {
            if (ModelState.IsValid)
            {
                _context.Add(repairs);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(GetRepairs)));
            }
            return(Ok(repairs));
        }
 public void AddRepair(  )
 {
     Repairs.Add(new RepairAction()
     {
         RepairName  = RepairName,
         Description = RepairDescription,
         ActionID    = Repairs.Count + 1
     }
                 )
     ;
 }
Exemplo n.º 14
0
        public async Task <IActionResult> Create([Bind("Id,Title,ReceiveDate,ReleaseDate,Genre,Price,Rating")] Repairs repairs)
        {
            if (ModelState.IsValid)
            {
                _context.Add(repairs);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(repairs));
        }
Exemplo n.º 15
0
    private static List <IRepair> GetRepairs(string[] inputParts)
    {
        List <IRepair> repairs = new List <IRepair>();

        for (int i = 6; i < inputParts.Length - 1; i += 2)
        {
            IRepair repair = new Repairs(inputParts[i], int.Parse(inputParts[i + 1]));
            repairs.Add(repair);
        }
        return(repairs);
    }
Exemplo n.º 16
0
        public Repairs getRepairsFromReader(SqlDataReader reader)
        {
            Repairs newRepair = new Repairs();

            newRepair.RepairID          = reader.GetInt32(0);
            newRepair.RentalID          = reader.GetInt32(1);
            newRepair.DamageDetails     = reader.GetString(2);
            newRepair.RepairCost        = reader.GetDouble(3);
            newRepair.RepairDate        = reader.GetDateTime(4);
            newRepair.RepairPaymentDate = reader.GetDateTime(5);
            return(newRepair);
        }
Exemplo n.º 17
0
        public async Task <IActionResult> Create([Bind("InstrumentInventoryId,TechnicianId,RepairStart,RepairEnd")] Repairs repairs)
        {
            if (ModelState.IsValid)
            {
                _context.Add(repairs);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["InstrumentInventoryId"] = new SelectList(_context.InstrumentInventory, "InstrumentInventoryId", "Manufacturer", repairs.InstrumentInventoryId);
            ViewData["TechnicianId"]          = new SelectList(_context.Technician, "TechnicianId", "TechnicianId", repairs.TechnicianId);
            return(View(repairs));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Update the record.
        /// </summary>
        /// <param name="Repairs"></param>
        /// <returns></returns>
        public static int Update(Repairs r)
        {
            Database db = new Database();

            db.Connect();
            SqlCommand command = db.CreateCommand(SQL_UPDATE);

            PrepareCommand(command, r);
            int ret = db.ExecuteNonQuery(command);

            db.Close();
            return(ret);
        }
 public Repairs[] SortByPriority(Repairs[] ToBeSorted)
 {
     for (int i = 0; i < ToBeSorted.Length; i++)
     {
         for (int j = 0; j < ToBeSorted.Length-1; j++)
         {
             if (CheckPriority(ToBeSorted[j]) > CheckPriority(ToBeSorted[j+1]))
             {
                 Swap(ref ToBeSorted,j);
             }
         }
     }
     return ToBeSorted;
 }
 public void SouldSwapAStructOfTwoByPriority()
 {
     var repairs = new Repairs[]
     {
      new Repairs("work", "Medium"),
      new Repairs("shoping", "High")
     };
     var expected = new Repairs[]
     {
      new Repairs("shoping", "High"),
      new Repairs("work", "Medium")
     };
     CollectionAssert.AreEqual(expected,SortByPriority(repairs));
 }
Exemplo n.º 21
0
        public Repairs getRepairsByID(int id)
        {
            Repairs newRepair = new Repairs();

            db.Cmd             = db.Conn.CreateCommand();
            db.Cmd.CommandText = "SELECT * FROM Repair WHERE RepairNo =" + id;
            db.Rdr             = db.Cmd.ExecuteReader();
            while (db.Rdr.Read())
            {
                newRepair = getRepairsFromReader(db.Rdr);
            }
            db.Rdr.Close();
            return(newRepair);
        }
Exemplo n.º 22
0
        private void repair_see(object sender, RoutedEventArgs e)
        {
            // again, same as Browse.cs
            try
            {
                var repairTracking = new requestRepair((int)id, username_global);

                Repairs selected_id = (Repairs)repair_history.SelectedItems[0];
                repairTracking.tracking_show((int)selected_id.ID);
            }
            catch (Exception Ex)
            {
                MessageBox.Show("You must have selected an item before proceeding!" /*Error: " + Ex + ". Actual Error Message: " + Ex.Message*/, "Alert!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
Exemplo n.º 23
0
        public void UpdateRepair(Repairs repair)
        {
            var oldValues = FindRepair(repair.RepairId);

            oldValues.CustomerId = repair.CustomerId;
            oldValues.UserId     = repair.UserId;
            oldValues.DeviceId   = repair.DeviceId;
            oldValues.Costs      = repair.Costs;
            oldValues.Note       = repair.Note;
            oldValues.StartDate  = repair.StartDate;
            oldValues.EndDate    = repair.EndDate;
            oldValues.Status     = repair.Status;

            ctx.SaveChanges();
        }
Exemplo n.º 24
0
        private void InitDb()
        {
            Database.EnsureCreated();
            foreach (var statusEntity in StatusEntities)
            {
                StatusEntities.Remove(statusEntity);
            }
            foreach (var repair in Repairs)
            {
                Repairs.Remove(repair);
            }
            foreach (var carType in CarTypes)
            {
                CarTypes.Remove(carType);
            }
            foreach (var car in Cars)
            {
                Cars.Remove(car);
            }
            foreach (var user in Users)
            {
                Users.Remove(user);
            }

            SaveChanges();
            StatusEntities.Add(new StatusEntity()
            {
                Status = Status.Finished
            });
            StatusEntities.Add(new StatusEntity()
            {
                Status = Status.AddedForService
            });
            StatusEntities.Add(new StatusEntity()
            {
                Status = Status.WaitingForParts
            });
            StatusEntities.Add(new StatusEntity()
            {
                Status = Status.WorkingOnCarNow
            });
            SaveChanges();
        }
Exemplo n.º 25
0
        /// <summary>
        /// Select records for category.
        /// </summary>
        public static Repairs Select(int id)
        {
            Database db = new Database();

            db.Connect();
            SqlCommand command = db.CreateCommand(SQL_SELECT_ID);

            command.Parameters.AddWithValue("@id_repair", id);
            SqlDataReader reader = db.Select(command);

            Collection <Repairs> repairs = Read(reader);
            Repairs r = null;

            if (repairs.Count == 1)
            {
                r = repairs[0];
            }
            reader.Close();
            db.Close();
            return(r);
        }
Exemplo n.º 26
0
 public static void Edit(Repair model)
 {
     using (DataContext2 db = new DataContext2())
     {
         Repairs Repairs = new Repairs
         {
             kRepairId           = model.kRepairId,
             kCustomerId         = model.kCustomerId,
             kProductId          = model.kProductId,
             kBookingId          = model.kBookingId ?? Guid.Empty,
             kOwnerId            = model.kOwnerId ?? Guid.Empty,
             kStaffId            = model.kStaffId ?? Guid.Empty,
             kQCId               = model.kQCId ?? Guid.Empty,
             sRepairNo           = model.sRepairNo,
             sColor              = model.sColor,
             sSerial             = model.sSerial,
             dtInsuranceExpire   = model.dtInsuranceExpire,
             sNote               = model.sNote,
             sProductAccessories = model.sProductAccessories,
             iDayWarranty        = model.iDayWarranty,
             dtEndWarranty       = model.dtEndWarranty,
             dtDueDate           = model.dtDueDate,
             dtDateAdd           = model.dtDateAdd,
             dtDateUpdate        = model.dtDateUpdate,
             IsComplete          = model.IsComplete,
             IsCustomerRecieved  = model.IsCustomerRecieved,
             iRemind             = model.iRemind,
             kCloseStatusId      = model.kCloseStatusId ?? Guid.Empty,
             IsNormal            = model.IsNormal,
             IsNoCredit          = model.IsNoCredit,
             IsQCPass            = model.IsQCPass,
             IsBack              = model.IsBack,
             IsInsurance         = model.IsInsurance,
             IsCancle            = model.IsCancle,
             IsFree              = model.IsFree
         };
         db.Entry(Repairs).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Exemplo n.º 27
0
        private void btnAddRepair_Click(object sender, EventArgs e)
        {
            RepairDBAccess C  = new RepairDBAccess(Db);
            Repairs        re = new Repairs();

            //try
            //{
            re.RentalID          = int.Parse(txtRepairRentalID.Text);
            re.RepairDate        = dtpRepairDate.Value;
            re.DamageDetails     = txtDamageDetails.Text;
            re.RepairCost        = double.Parse(txtRepairCost.Text);
            re.RepairPaymentDate = dtpRepairPaymentDate.Value;

            C.insertRepair(re);
            MessageBox.Show("Student added", "Success");

            //}
            //catch
            //{
            //    MessageBox.Show("Student not added", "Error");
            //}
        }
Exemplo n.º 28
0
        public void Add(Repairs repairs)
        {
            StateClassRepos stateClassRepos = new StateClassRepos();
            string          sql             =
                "insert into `repairs` (`date`,`idmachine`,`comment`) values (" +
                "\'" + repairs.date.ToString("yyyy-MM-dd HH:mm:ss") + "\'," + repairs.idmachine + ",\'" + repairs.comment + "\'" + ");";
            MySqlCommand cmd = new MySqlCommand();

            using (MySqlConnection conn = DBUtils.GetDBConnection())
            {
                try
                {
                    conn.Open();
                    cmd.Connection  = conn;
                    cmd.CommandText = sql;
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Exemplo n.º 29
0
 public void AddRepair(Repair repair)
 {
     Repairs.Add(repair);
 }
Exemplo n.º 30
0
 private static int SFindIndexOfMinim(Repairs[] sourceArray, int index)
 {
     for (int j = index + 1; j < sourceArray.Length; j++)
     {
         if ((int)(sourceArray[j].priority) < (int)sourceArray[index].priority)
         {
             index = j;
         }
     }
     return index;
 }
Exemplo n.º 31
0
        private void SortClients(ref Repairs[] clients)
        {
            int indexOfMinim;
            for (int i = 0; i < clients.Length - 1; i++)
            {
                indexOfMinim = SFindIndexOfMinim(clients, i);
                if (indexOfMinim != i)
                {
                    Repairs temp;
                    temp = clients[i];
                    clients[i] = clients[indexOfMinim];
                    clients[indexOfMinim] = temp;

                }
            }
        }
Exemplo n.º 32
0
        private decimal CalculateTotalRepairCosts()
        {
            var costs = Repairs.Any() ? Repairs.Sum(x => x.Cost) : 0.0M;

            return(costs);
        }
Exemplo n.º 33
0
        public override bool HasChanges()
        {
            var rval = base.HasChanges();

            return(rval | Repairs.Count((r) => r.HasChanges()) > 0);
        }
 private int CheckPriority(Repairs toBeSorted)
 {
     return Array.FindIndex(Prio,priority => priority.Contains (toBeSorted.priority));
 }
 private void Swap(ref Repairs[] toBeSorted, int pos)
 {
     Repairs temp = toBeSorted[pos];
     toBeSorted[pos] = toBeSorted[pos+1];
     toBeSorted[pos + 1] = temp;
 }
Exemplo n.º 36
0
 //Chain Of Responsibility method
 public void ProcessRequest(Repairs repairs)
 {
     OnRequest(new RepairEventArgs {
         Repairs = repairs
     });
 }
 public void SouldReturnAStructOrderdByPriority()
 {
     var expected = new Repairs[] { new Repairs("shoping", "High") };
     var result =SortByPriority(new Repairs[] { new Repairs("shoping", "High") });
     CollectionAssert.AreEqual(expected, result);
 }
 public void SouldReturnZeroForRepairWithHighPrio()
 {
     var repair = new Repairs("shoping", "High");
     Assert.AreEqual(0,CheckPriority(repair));
 }
 public void SouldReturnOneForRepairWithMediumPrio()
 {
     var repair = new Repairs("shoping", "Medium");
     Assert.AreEqual(1, CheckPriority(repair));
 }