|
@@ -14,6 +14,7 @@ namespace Hotel_Course_Project
|
|
public partial class ClientChangeOrAddPage : Page
|
|
public partial class ClientChangeOrAddPage : Page
|
|
{
|
|
{
|
|
public Client _client;
|
|
public Client _client;
|
|
|
|
+ public Client addClient;
|
|
public int idClient;
|
|
public int idClient;
|
|
public byte[] PassportImage;
|
|
public byte[] PassportImage;
|
|
public string FilePath;
|
|
public string FilePath;
|
|
@@ -22,6 +23,7 @@ namespace Hotel_Course_Project
|
|
InitializeComponent();
|
|
InitializeComponent();
|
|
DataContext = client;
|
|
DataContext = client;
|
|
_client = client;
|
|
_client = client;
|
|
|
|
+ addClient = client;
|
|
if (DataContext != null)
|
|
if (DataContext != null)
|
|
{
|
|
{
|
|
|
|
|
|
@@ -43,12 +45,7 @@ namespace Hotel_Course_Project
|
|
ClientChangeOrAddBtn.Content = "Добавить клиента";
|
|
ClientChangeOrAddBtn.Content = "Добавить клиента";
|
|
this.Title = "Окно добавления клиента";
|
|
this.Title = "Окно добавления клиента";
|
|
ClientDeleteOrRestoreBtn.Visibility = Visibility.Collapsed;
|
|
ClientDeleteOrRestoreBtn.Visibility = Visibility.Collapsed;
|
|
- }
|
|
|
|
- if (client == null || client.Passport == null)
|
|
|
|
- {
|
|
|
|
- CPassportPhoto.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/PersDefaultPhoto.png"));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private void ClientChangeOrAddBtn_Click(object sender, RoutedEventArgs e)
|
|
private void ClientChangeOrAddBtn_Click(object sender, RoutedEventArgs e)
|
|
@@ -69,19 +66,31 @@ namespace Hotel_Course_Project
|
|
else
|
|
else
|
|
{
|
|
{
|
|
if (DataContext == null)
|
|
if (DataContext == null)
|
|
- {
|
|
|
|
- Client client = new Client()
|
|
|
|
|
|
+ {
|
|
|
|
+ if (TestAddClient(CLName.Text, CFName.Text, CMName.Text) == true)
|
|
{
|
|
{
|
|
- LName = CLName.Text,
|
|
|
|
- FName = CFName.Text,
|
|
|
|
- MName = CMName.Text,
|
|
|
|
- Passport = PassportImage,
|
|
|
|
- Id_PersStatus = 1
|
|
|
|
- };
|
|
|
|
- DataBase.db.Client.Add(client);
|
|
|
|
- var lastId = DataBase.db.Client.OrderByDescending(item => item.Id).FirstOrDefault().Id;
|
|
|
|
- DataBase.db.SaveChanges();
|
|
|
|
- MessageBox.Show("Клиент добавлен в базу.");
|
|
|
|
|
|
+ DataBase.db.Client.Add(addClient);
|
|
|
|
+ var lastId = DataBase.db.Client.OrderByDescending(item => item.Id).FirstOrDefault().Id;
|
|
|
|
+ DataBase.db.Client.SingleOrDefault(item => item.Id == lastId).Passport = PassportImage;
|
|
|
|
+ DataBase.db.SaveChanges();
|
|
|
|
+ MessageBox.Show("Клиент добавлен в базу.");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("Ключевые поля не были заполнены!");
|
|
|
|
+ }
|
|
|
|
+ //Client client = new Client()
|
|
|
|
+ //{
|
|
|
|
+ // LName = CLName.Text,
|
|
|
|
+ // FName = CFName.Text,
|
|
|
|
+ // MName = CMName.Text,
|
|
|
|
+ // Passport = PassportImage,
|
|
|
|
+ // Id_PersStatus = 1
|
|
|
|
+ //};
|
|
|
|
+ //DataBase.db.Client.Add(client);
|
|
|
|
+ //var lastId = DataBase.db.Client.OrderByDescending(item => item.Id).FirstOrDefault().Id;
|
|
|
|
+ //DataBase.db.SaveChanges();
|
|
|
|
+ //MessageBox.Show("Клиент добавлен в базу.");
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -93,6 +102,26 @@ namespace Hotel_Course_Project
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public bool TestAddClient(string LName, string FName, string MName)
|
|
|
|
+ {
|
|
|
|
+ if (LName == null || LName == "" || FName == null || FName == "")
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Client client = new Client()
|
|
|
|
+ {
|
|
|
|
+ LName = LName,
|
|
|
|
+ FName = FName,
|
|
|
|
+ MName = MName,
|
|
|
|
+ Id_PersStatus = 1
|
|
|
|
+ };
|
|
|
|
+ addClient = client;
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private void ClientDeleteOrRestoreBtn_Click(object sender, RoutedEventArgs e)
|
|
private void ClientDeleteOrRestoreBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
if (_client.Id_PersStatus == 1)
|
|
if (_client.Id_PersStatus == 1)
|
|
@@ -125,5 +154,13 @@ namespace Hotel_Course_Project
|
|
FilePath = string.Empty;
|
|
FilePath = string.Empty;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void Page_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ if (_client == null || _client.Passport == null)
|
|
|
|
+ {
|
|
|
|
+ CPassportPhoto.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/PersDefaultPhoto.png"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|