Witam, mam mały-duży problem. Zamysł jest taki że kiedy jestem zalogowany to wtedy mogę dodać ogłoszenia ale jak zrobić aby dane ogłoszenie było przypisane do UserID? i tak samo categoria?
Poza tym nie bardzo wiem jak ma wyglądać wyszukiwanie.
Main Form:
public partial class BlocketForm : Form
{
private BlocketEntities1 _dbConnection;
public static BlocketForm instance;
public BlocketForm()
{
InitializeComponent();
instance = this;
InvisibleBtn();
}
private void LogSignBtn_Click(object sender, EventArgs e)
{
LoginForm log_In = new LoginForm();
log_In.ShowDialog();
}
private void CloseBtn_Click(object sender, EventArgs e)
{
this.Close();
}
private void NewAdvertBtn_Click(object sender, EventArgs e)
{
//Nie gotowe
AdvertRepo repo = new AdvertRepo();
Category category = new Category();
if (TitleBox.Text != "")
{
Advert advert = new Advert();
advert.Title = TitleBox.Text;
advert.Price = PriceBox.Text;
advert.Description = DescriptionBox.Text;
category.CategoryName = CategoryComboBox.SelectedItem.ToString();
repo.InsertNewAdvert(advert);
}
else
{
MessageBox.Show("All informations must be filled");
}
}
private void UpdateBtn_Click(object sender, EventArgs e)
{
//Nie gotowe
int advertID = int.Parse(listBox1.SelectedValue.ToString());
AdvertRepo repo = new AdvertRepo();
Advert advert = new Advert();
Category category = new Category();
advert.AdvertID = advertID;
advert.Title = TitleBox.Text;
advert.Price = PriceBox.Text;
advert.Description = DescriptionBox.Text;
category.CategoryName = CategoryComboBox.SelectedItem.ToString();
repo.UpdateAdverts(advert);
}
private void DeleteBtn_Click(object sender, EventArgs e)
{
int advertID = int.Parse(listBox1.SelectedValue.ToString());
AdvertRepo repo = new AdvertRepo();
Advert advert = new Advert();
repo.DeleteAdvert(advertID);
}
private void ShowMyBtn_Click(object sender, EventArgs e)
{
try
{
int advertID = int.Parse(listBox1.SelectedValue.ToString());
AdvertRepo repo = new AdvertRepo();
Advert adverts = repo.GetAdverts(advertID);
listBox1.DisplayMember = "Title" + " " + "Price" + " " + "Description";
listBox1.ValueMember = "UserID";
listBox1.DataSource = repo.GetAdverts(advertID);
}
catch (Exception)
{
MessageBox.Show("Error");
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//Nie gotowe
int advertID = int.Parse(listBox1.SelectedValue.ToString());
AdvertRepo repo = new AdvertRepo();
Advert adverts = repo.GetAdverts(advertID);
TitleBox.Text = adverts.Title;
PriceBox.Text = adverts.Price;
DescriptionBox.Text = adverts.Description;
}
private void SearchBtn_Click(object sender, EventArgs e)
{
//Nie gotowe
Advert advert = new Advert();
var items = _dbConnection.Adverts.Where(x => x.Title.Contains(SearchBox.Text));
}
Registry form:
private void SaveBtn_Click(object sender, EventArgs e)
{
UserRepo repo = new UserRepo();
if (UserBox.Text != "")
{
User user= new User();
user.Username = UserBox.Text;
if (PassBox.Text != ConfirmPassBox.Text)
{
MessageBox.Show("Not same password");
}
else
user.Password = PassBox.Text;
repo.InsertNewUser(user);
}
else
{
MessageBox.Show("Username and password must be filled");
}
}
public void InsertNewUser(User user)
{
_dbConnection.Users.Add(user);
_dbConnection.SaveChanges();
}