I've been searching with google/stackoverflow for a while, but I couldn't find proper answer for my problem.
I have to create simple program in VS Windows Forms (.net Framework). I have created few DataGridViews with showing exact data I need. I added buttons to "Add" to create new row, or "Remove" selected row. Now I need to change data in selected row with single button click. When I click "Add" button, new dialog window pop-up, where you choose from subclasses Car or Motorbike, then when you choose what to add, new dialog will pop-up, and there you fill proper information (like Manufacturer, or year of creation etc.)
When I want to "Edit" selected row, I want the app to directly go to dialog where you can change the data to new ones. I thought simple "if" could help me easily, but i cannot find the code to create it. My thought was something like this:
F1Automobil f1 = new F1Automobil();
F1Motorka f2 = new F1Motorka();
int indCar = dgvVozovyPark.CurrentCell.RowIndex;
if (/*index of selected row where subclass equals to "automobil" = true)
{
{
f1.Action = F1Automobil.ActionType.Edit;
f1.CarInstance = (Automobil)dgvVozovyPark.CurrentRow.DataBoundItem;
f1.ShowDialog();
}
else
{
f2.Action = F1Motorka.ActionType.Edit;
f2.BikeInstance = (Motorka)dgvVozovyPark.CurrentRow.DataBoundItem;
f2.ShowDialog();
}
}
But VS shows me several mistakes. Could somebody please help, because i don't know what to do. I tried a lot of combinations like Database.Equals(something) = true
, but none worked.
Also, I need help with other thing, so I will write it here, because I don't want to create new thread. I want to implement one if
function for NumericUpDown. I will share code below:
public void InitializeDate()
{
if (numMonth.Value.Equals(2) == true)
{
numDay.Maximum = 28;
}
else if (numMonth.Value.Equals(4 | 6 | 9 | 11) == true)
{
numDay.Maximum = 30;
}
else
{
numDay.Maximum = 31;
}
}
This code show no mistake or error, but it's not working properly. Could anyone help with this aswell ?
I would like to point out, that I never programmed as professional, and I am learning everything in school from distance learning for Bachelor degree, and I have no option to communicate with my teacher to discuss this problem. Thank you all very much for help in advance.
Edit:
namespace Semestrální_projekt___Půjčovna_vozidel
{
[Serializable()]
public class Vozidla
{
public string Vyrobce { get; set; }
public string Model { get; set; }
public int RokVyroby { get; set; }
public int CenaVypujcky { get; set; }
public int CenaProdejni { get; set; }
public Vozidla(string vyrobce, string model, int rokVyroby, int cenaVypujcky, int cenaProdejni)
{
Vyrobce = vyrobce;
Model = model;
RokVyroby = rokVyroby;
CenaVypujcky = cenaVypujcky;
CenaProdejni = cenaProdejni;
}
}
[Serializable()]
public class Motorka: Vozidla
{
public int Kubatura { get; set; }
public string Typ { get; set; }
public Motorka(string vyrobce, string model, int rokVyroby, int cenaVypujcky, int cenaProdejni, int kubatura, string typ)
:base (vyrobce, model, rokVyroby, cenaVypujcky, cenaProdejni)
{
Kubatura = kubatura;
Typ = typ;
}
}
[Serializable()]
public class Automobil: Vozidla
{
public int ObsahMotoru { get; set; }
public string Typ { get; set; }
public string Prevodovka { get; set; }
public int PocetMistSezeni { get; set; }
public Automobil(string vyrobce, string model, int rokVyroby, int cenaVypujcky, int cenaProdejni, int obsahMotoru, string typ, string prevodovka,int pocetMistSezeni)
:base(vyrobce, model, rokVyroby, cenaVypujcky, cenaProdejni)
{
ObsahMotoru = obsahMotoru;
Typ = typ;
Prevodovka = prevodovka;
PocetMistSezeni = pocetMistSezeni;
}
}
}
Aucun commentaire:
Enregistrer un commentaire