public static List <SpareParts> GetByCard(RepairCard card) { List <SpareParts> parts = new List <SpareParts>(); using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); using (SqlCommand command = new SqlCommand( "SELECT id as ID, name as Name, number as Number, price as Price FROM card_parts p " + "LEFT JOIN parts part ON part.id = p.partId " + "WHERE p.cardId = @id", con)) { command.Parameters.Add("@id", SqlDbType.Int); command.Parameters["@id"].Value = card.Id; using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { parts.Add(new SpareParts(reader.GetInt32(0), reader.GetString(1).Trim(), reader.GetString(2).Trim(), reader.GetDouble(3))); } } } } return(parts); }
protected void SaveRepairCard_OnClick(object sender, EventArgs e) { CarServicePresentationUtility.ClearNotificationMsgList(this.notificationMsgList); CarServicePresentationUtility.HideNotificationMsgList(this.notificationMsgList); this.notificationMsgList.CssClass = CarServiceConstants.NEGATIVE_CSS_CLASS_NAME; DateTime?startRepairDate = null; string startRepairDateTxt = this.startRepairDate.SelectedDate; bool validStartRepairDate = CarServicePresentationUtility.ProcessStartRepairDate(startRepairDateTxt, this.notificationMsgList, out startRepairDate); decimal sparePartsPrice = 0M; decimal repairPrice = 0M; string repairPriceTxt = this.repairPrice.Text; string sparePartsPriceTxt = this.sparePartsPrice.Text; bool validPrices = CarServicePresentationUtility.ProcessRepairPrices(sparePartsPriceTxt, repairPriceTxt, this.notificationMsgList, out sparePartsPrice, out repairPrice); string automobileIdTxt = this.automobileDropDown.SelectedValue; Automobile automobile = CarServiceUtility.GetAutomobile(automobileIdTxt, this.persister); bool validAutomobileId = (automobile != null); ListItemCollection selectedSparePartItems = this.selectedSpareParts.Items; bool validSpareParts = CarServicePresentationUtility.IsSparePartItemsValid(selectedSparePartItems, this.notificationMsgList); if (validAutomobileId && validPrices && validSpareParts && (validStartRepairDate && startRepairDate.HasValue)) { string description = this.repairCardDescription.Text; object repairCardIdObject = Session[CarServiceConstants.REPAIR_CARD_ID_PARAM_NAME]; if (repairCardIdObject != null) { int repairCardId; if (Int32.TryParse(repairCardIdObject.ToString(), out repairCardId)) { DateTime?finishRepairDate = null; string finishRepairDateTxt = this.finishRepairDate.SelectedDate; bool validFinishRepairDate = CarServicePresentationUtility.ProcessFinishRepairDate(finishRepairDateTxt, this.notificationMsgList, out finishRepairDate); if (validFinishRepairDate == true) { RepairCard repairCard = this.persister.GetRepairCardById(repairCardId); UpdateRepairCard(repairCard, automobile, finishRepairDate, description, sparePartsPrice, repairPrice, selectedSparePartItems); CarServicePresentationUtility.AppendNotificationMsg("Repair card is updated successfully", this.notificationMsgList); this.notificationMsgList.CssClass = CarServiceConstants.POSITIVE_CSS_CLASS_NAME; } } } else { SaveRepairCard(automobile, startRepairDate.Value, description, sparePartsPrice, repairPrice, selectedSparePartItems); CarServicePresentationUtility.AppendNotificationMsg("Repair card is saved successfully", this.notificationMsgList); this.notificationMsgList.CssClass = CarServiceConstants.POSITIVE_CSS_CLASS_NAME; } } CarServicePresentationUtility.ShowNotificationMsgList(this.notificationMsgList); }
private void saveButton_Click(object sender, EventArgs e) { this.hideErrors(); bool error = false; if (numberTextbox.Text.Length <= 0) { numberPictureBox.Visible = true; error = true; } if (dateInDatetime.Value == null) { dateInPictureBox.Visible = true; error = true; } if (carDropdown.SelectedIndex == -1) { carPictureBox.Visible = true; error = true; } if (employeeDropdown.SelectedIndex == -1) { employeePictureBox.Visible = true; error = true; } if (descriptionTextbox.Text.Length <= 0) { descriptionPictureBox.Visible = true; error = true; } if (error) { return; } DateTime?dateOut = null; if (dateOutDatetime.Format != DateTimePickerFormat.Custom) { dateOut = dateOutDatetime.Value; } RepairCard p = new RepairCard(this.id, numberTextbox.Text, dateInDatetime.Value, dateOut, this.cars[carDropdown.SelectedIndex], descriptionTextbox.Text, this.employees[employeeDropdown.SelectedIndex]); if (p.Id == 0) { RepairCardRepository.Add(p); } else { RepairCardRepository.Update(p); } this.Close(); }
public RepairCard DrawRepairCard() { GameObject go = Instantiate(RepairCardPrefab); RepairCard newCard = go.GetComponent <RepairCard>(); newCard.Setup(this, repairCardFactory.GetRandomCard()); newCard.Initialize(); return(newCard); }
private void UpdateRepairCard(RepairCard repairCard, Automobile automobile, DateTime?finishRepairDate, string description, decimal sparePartsPrice, decimal repairPrice, ListItemCollection sparePartItems) { repairCard.Automobile = automobile; repairCard.Description = (string.IsNullOrEmpty(description) ? null : description); repairCard.FinishRepair = finishRepairDate; repairCard.PartPrice = sparePartsPrice; repairCard.CardPrice = repairPrice; CarServicePresentationUtility.AddSpareParts(repairCard, sparePartItems, this.persister); this.persister.SaveChanges(); }
public CardForm(int id = 0) { InitializeComponent(); this.hideErrors(); RepairCard card = null; cars = CarRepository.GetAll(); foreach (Car c in cars) { carDropdown.Items.Add(c.RegistrationNumber); } employees = EmployeeRepository.GetAll(); foreach (Employee e in employees) { employeeDropdown.Items.Add(e.Name); } if (id != 0) { this.id = id; card = RepairCardRepository.Get(id); } dateOutDatetime.CustomFormat = " "; dateOutDatetime.Format = DateTimePickerFormat.Custom; if (card != null) { this.getParts(); dateInDatetime.Value = card.In; if (card.Out != null) { dateOutDatetime.Value = (DateTime)card.Out; } descriptionTextbox.Text = card.Description; numberTextbox.Text = card.Number; carDropdown.Text = card.Car.RegistrationNumber; employeeDropdown.Text = card.Employee.Name; } else { carDropdown.Text = this.cars.Count > 0 ? this.cars[0].RegistrationNumber : ""; employeeDropdown.Text = this.employees.Count > 0 ? this.employees[0].Name : ""; partsGridView.Visible = false; addPartButton.Visible = false; removePartButton.Visible = false; this.Height = 320; } }
private void LoadRepairCardInfo(RepairCard repairCard) { this.repairCardIdLbl.Text = repairCard.CardId.ToString(); this.operatorLbl.Text = repairCard.aspnet_Users.UserName; List <Automobile> automobiles = new List <Automobile>(); automobiles.Add(repairCard.Automobile); var customAutomobileFormat = from auto in automobiles select new { AutomobileId = auto.AutomobileId, AutomobileRepresentation = auto.Vin + " / " + auto.ChassisNumber }; this.automobileDropDown.DataSource = customAutomobileFormat; this.automobileDropDown.DataBind(); this.sparePartsPrice.Text = repairCard.PartPrice.ToString(); this.repairPrice.Text = repairCard.CardPrice.ToString(); CultureInfo englishCultureInfo = new CultureInfo(CarServiceConstants.ENGLISH_CULTURE_INFO); this.startRepairDate.SelectedDate = repairCard.StartRepair.ToString(CarServiceConstants.DATE_FORMAT, englishCultureInfo); DateTime?finishRepairDate = repairCard.FinishRepair; if (finishRepairDate.HasValue) { this.finishRepairDate.SelectedDate = finishRepairDate.Value.ToString(CarServiceConstants.DATE_FORMAT, englishCultureInfo); DisableAllInputControls(); } else { this.finishRepairDate.Enabled = true; } EntityCollection <SparePart> selectedParts = repairCard.SpareParts; List <SparePart> unselectedParts = new List <SparePart>(); IQueryable <SparePart> activeSpareParts = this.persister.GetActiveSpareParts(); foreach (SparePart part in activeSpareParts) { if (selectedParts.Contains(part) == false) { unselectedParts.Add(part); } } object customUnselectedSpareParts = CarServicePresentationUtility.GetSparePartsFormatForListBox(unselectedParts); object customSelectedSpareParts = CarServicePresentationUtility.GetSparePartsFormatForListBox(selectedParts); CarServicePresentationUtility.BindListBox(this.unselectedSpareParts, customUnselectedSpareParts); CarServicePresentationUtility.BindListBox(this.selectedSpareParts, customSelectedSpareParts); this.repairCardDescription.Text = repairCard.Description; }
public void TestRepair() { RepairCard c = new RepairCard("Chance", "REPAIR", "repair house", 100, 100); Player p = new Player("Tom", 1000); Monopoly.Monopoly m = new Monopoly.Monopoly(); m.loadProperties(); Board.access().getProperty(1).setOwner(ref p); ((Residential)Board.access().getProperty(1)).addHouse(); c.ExecuteInstruction(p); Assert.Less(p.getBalance(), 1000); }
protected void Page_Load(object sender, EventArgs e) { if (this.persister == null) { this.persister = new CarServicePersister(); } if (IsPostBack == false) { this.finishRepairDate.Enabled = false; object repairCardIdObject = Session[CarServiceConstants.REPAIR_CARD_ID_PARAM_NAME]; if (repairCardIdObject != null) { int repairCardId; if (Int32.TryParse(repairCardIdObject.ToString(), out repairCardId)) { RepairCard repairCard = this.persister.GetRepairCardById(repairCardId); LoadRepairCardInfo(repairCard); Guid creatorUserId = repairCard.UserId; MembershipUser currentUser = Membership.GetUser(); Guid currentUserId = (Guid)currentUser.ProviderUserKey; if (currentUserId.Equals(creatorUserId) == false) { DisableAllInputControls(); } else { this.startRepairDate.Enabled = false; } } } else { IQueryable <SparePart> spareParts = this.persister.GetActiveSpareParts(); object customSpareParts = CarServicePresentationUtility.GetSparePartsFormatForListBox(spareParts); CarServicePresentationUtility.BindListBox(this.unselectedSpareParts, customSpareParts); this.startRepairDate.SelectedDate = DateTime.Now.ToString(CarServiceConstants.DATE_FORMAT, new CultureInfo(CarServiceConstants.ENGLISH_CULTURE_INFO)); this.finishRepairDate.Enabled = false; this.operatorLbl.Text = this.User.Identity.Name; } } CarServicePresentationUtility.ClearNotificationMsgList(this.notificationMsgList); CarServicePresentationUtility.HideNotificationMsgList(this.notificationMsgList); Session[CarServiceConstants.AUTOMOBILE_ID_REQUEST_PARAM_NAME] = null; }
public static void AddSpareParts(RepairCard repairCard, ListItemCollection selectedSparePartItems, ICarServicePersister persister) { repairCard.SpareParts.Clear(); foreach (ListItem item in selectedSparePartItems) { int sparePartId; if (Int32.TryParse(item.Value, out sparePartId)) { SparePart sparePart = persister.GetSparePartById(sparePartId); if (sparePart != null) { repairCard.SpareParts.Add(sparePart); } } } }
public static void Add(RepairCard card) { using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); using (SqlCommand command = new SqlCommand("INSERT INTO cards (dateIn, dateOut, carId, employeeId, description, number) VALUES(@dateIn, @dateOut, @carId, @employeeId, @description, @number)", con)) { command.Parameters.AddWithValue("@dateIn", card.In); command.Parameters.AddWithValue("@dateOut", card.Out != null ? card.Out : (object)DBNull.Value); command.Parameters.AddWithValue("@carId", card.Car.Id); command.Parameters.AddWithValue("@employeeId", card.Employee.Id); command.Parameters.AddWithValue("@description", card.Description); command.Parameters.AddWithValue("@number", card.Number); command.ExecuteNonQuery(); } } }
private void SaveRepairCard(Automobile automobile, DateTime startRepairDate, string description, decimal sparePartsPrice, decimal repairPrice, ListItemCollection sparePartItems) { MembershipUser currentUser = Membership.GetUser(); RepairCard newRepairCard = new RepairCard() { Automobile = automobile, UserId = ((System.Guid)currentUser.ProviderUserKey), StartRepair = startRepairDate, Description = (string.IsNullOrEmpty(description) ? null : description), PartPrice = sparePartsPrice, CardPrice = repairPrice }; CarServicePresentationUtility.AddSpareParts(newRepairCard, sparePartItems, this.persister); this.persister.CreateRepairCard(newRepairCard); this.persister.SaveChanges(); }
public static void Update(RepairCard card) { using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); using (SqlCommand command = new SqlCommand( "UPDATE cards SET dateIn = @dateIn, dateOut = @dateOut, carId = @carId, " + "employeeId = @employeeId, description = @description, number = @number " + "WHERE id = @id", con)) { command.Parameters.AddWithValue("@id", card.Id); command.Parameters.AddWithValue("@dateIn", card.In); command.Parameters.AddWithValue("@dateOut", card.Out != null ? card.Out : (object)DBNull.Value); command.Parameters.AddWithValue("@carId", card.Car.Id); command.Parameters.AddWithValue("@employeeId", card.Employee.Id); command.Parameters.AddWithValue("@description", card.Description); command.Parameters.AddWithValue("@number", card.Number); command.ExecuteNonQuery(); } } }
public RepairCard GetRepairCardById(int cardId) { RepairCard repairCard = this.carServiceEntities.RepairCards.FirstOrDefault(card => card.CardId == cardId); return(repairCard); }
public void DeleteRepairCard(RepairCard repairCard) { this.carServiceEntities.RepairCards.DeleteObject(repairCard); }
public void CreateRepairCard(RepairCard repairCard) { this.carServiceEntities.RepairCards.AddObject(repairCard); }