Imagara 3 anos atrás
pai
commit
ce42f40f02

+ 2 - 2
PartsWarehouse/App.config

@@ -14,6 +14,6 @@
     </providers>
   </entityFramework>
 <connectionStrings>
-  
-<add name="EDMEntities" connectionString="metadata=res://*/EDM.csdl|res://*/EDM.ssdl|res://*/EDM.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=mssql;initial catalog=gr692_gav;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings>
+<add name="EDMEntities" connectionString="metadata=res://*/EDM.csdl|res://*/EDM.ssdl|res://*/EDM.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(localdb)\MSSQLLocalDB;initial catalog=PartsWarehouseDataBase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
+</connectionStrings>
 </configuration>

+ 172 - 0
PartsWarehouse/EDM.edmx.sql

@@ -0,0 +1,172 @@
+
+-- --------------------------------------------------
+-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
+-- --------------------------------------------------
+-- Date Created: 04/27/2022 01:28:49
+-- Generated from EDMX file: C:\Users\milic\source\repos\PartsWarehouse\PartsWarehouse\EDM.edmx
+-- --------------------------------------------------
+
+SET QUOTED_IDENTIFIER OFF;
+GO
+USE [PartsWarehouseDataBase];
+GO
+IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
+GO
+
+-- --------------------------------------------------
+-- Dropping existing FOREIGN KEY constraints
+-- --------------------------------------------------
+
+IF OBJECT_ID(N'[dbo].[FK_Parts_Car]', 'F') IS NOT NULL
+    ALTER TABLE [dbo].[Parts] DROP CONSTRAINT [FK_Parts_Car];
+GO
+IF OBJECT_ID(N'[dbo].[FK_UserCar_Car]', 'F') IS NOT NULL
+    ALTER TABLE [dbo].[UserCar] DROP CONSTRAINT [FK_UserCar_Car];
+GO
+IF OBJECT_ID(N'[dbo].[FK_UserCar_User]', 'F') IS NOT NULL
+    ALTER TABLE [dbo].[UserCar] DROP CONSTRAINT [FK_UserCar_User];
+GO
+
+-- --------------------------------------------------
+-- Dropping existing tables
+-- --------------------------------------------------
+
+IF OBJECT_ID(N'[dbo].[Car]', 'U') IS NOT NULL
+    DROP TABLE [dbo].[Car];
+GO
+IF OBJECT_ID(N'[dbo].[Parts]', 'U') IS NOT NULL
+    DROP TABLE [dbo].[Parts];
+GO
+IF OBJECT_ID(N'[dbo].[User]', 'U') IS NOT NULL
+    DROP TABLE [dbo].[User];
+GO
+IF OBJECT_ID(N'[dbo].[UserCar]', 'U') IS NOT NULL
+    DROP TABLE [dbo].[UserCar];
+GO
+
+-- --------------------------------------------------
+-- Creating all tables
+-- --------------------------------------------------
+
+-- Creating table 'Car'
+CREATE TABLE [dbo].[Car] (
+    [IdCar] int  NOT NULL,
+    [Company] nvarchar(50)  NOT NULL,
+    [Name] nvarchar(50)  NOT NULL,
+    [Generation] int  NOT NULL
+);
+GO
+
+-- Creating table 'Parts'
+CREATE TABLE [dbo].[Parts] (
+    [IdPart] int  NOT NULL,
+    [IdCar] int  NOT NULL,
+    [Type] nvarchar(50)  NOT NULL,
+    [Name] nvarchar(50)  NOT NULL,
+    [Manufacturer] nvarchar(50)  NOT NULL,
+    [Description] nvarchar(50)  NOT NULL,
+    [Image] varbinary(max)  NULL,
+    [Remain] int  NOT NULL,
+    [Price] float  NOT NULL,
+    [PartNum] int  NOT NULL,
+    [Original] nvarchar(15)  NOT NULL
+);
+GO
+
+-- Creating table 'User'
+CREATE TABLE [dbo].[User] (
+    [IdUser] int  NOT NULL,
+    [Login] nvarchar(50)  NOT NULL,
+    [Password] nvarchar(50)  NOT NULL
+);
+GO
+
+-- Creating table 'UserCar'
+CREATE TABLE [dbo].[UserCar] (
+    [Id] int  NOT NULL,
+    [IdUser] int  NOT NULL,
+    [IdCar] int  NOT NULL,
+    [Vin] nvarchar(50)  NOT NULL
+);
+GO
+
+-- --------------------------------------------------
+-- Creating all PRIMARY KEY constraints
+-- --------------------------------------------------
+
+-- Creating primary key on [IdCar] in table 'Car'
+ALTER TABLE [dbo].[Car]
+ADD CONSTRAINT [PK_Car]
+    PRIMARY KEY CLUSTERED ([IdCar] ASC);
+GO
+
+-- Creating primary key on [IdPart] in table 'Parts'
+ALTER TABLE [dbo].[Parts]
+ADD CONSTRAINT [PK_Parts]
+    PRIMARY KEY CLUSTERED ([IdPart] ASC);
+GO
+
+-- Creating primary key on [IdUser] in table 'User'
+ALTER TABLE [dbo].[User]
+ADD CONSTRAINT [PK_User]
+    PRIMARY KEY CLUSTERED ([IdUser] ASC);
+GO
+
+-- Creating primary key on [Id] in table 'UserCar'
+ALTER TABLE [dbo].[UserCar]
+ADD CONSTRAINT [PK_UserCar]
+    PRIMARY KEY CLUSTERED ([Id] ASC);
+GO
+
+-- --------------------------------------------------
+-- Creating all FOREIGN KEY constraints
+-- --------------------------------------------------
+
+-- Creating foreign key on [IdCar] in table 'Parts'
+ALTER TABLE [dbo].[Parts]
+ADD CONSTRAINT [FK_Parts_Car]
+    FOREIGN KEY ([IdCar])
+    REFERENCES [dbo].[Car]
+        ([IdCar])
+    ON DELETE NO ACTION ON UPDATE NO ACTION;
+GO
+
+-- Creating non-clustered index for FOREIGN KEY 'FK_Parts_Car'
+CREATE INDEX [IX_FK_Parts_Car]
+ON [dbo].[Parts]
+    ([IdCar]);
+GO
+
+-- Creating foreign key on [IdCar] in table 'UserCar'
+ALTER TABLE [dbo].[UserCar]
+ADD CONSTRAINT [FK_UserCar_Car]
+    FOREIGN KEY ([IdCar])
+    REFERENCES [dbo].[Car]
+        ([IdCar])
+    ON DELETE NO ACTION ON UPDATE NO ACTION;
+GO
+
+-- Creating non-clustered index for FOREIGN KEY 'FK_UserCar_Car'
+CREATE INDEX [IX_FK_UserCar_Car]
+ON [dbo].[UserCar]
+    ([IdCar]);
+GO
+
+-- Creating foreign key on [IdUser] in table 'UserCar'
+ALTER TABLE [dbo].[UserCar]
+ADD CONSTRAINT [FK_UserCar_User]
+    FOREIGN KEY ([IdUser])
+    REFERENCES [dbo].[User]
+        ([IdUser])
+    ON DELETE NO ACTION ON UPDATE NO ACTION;
+GO
+
+-- Creating non-clustered index for FOREIGN KEY 'FK_UserCar_User'
+CREATE INDEX [IX_FK_UserCar_User]
+ON [dbo].[UserCar]
+    ([IdUser]);
+GO
+
+-- --------------------------------------------------
+-- Script has ended
+-- --------------------------------------------------

+ 9 - 9
PartsWarehouse/ImagesManip.cs

@@ -35,15 +35,15 @@ namespace PartsWarehouse
             #endregion
         }
 
-        //public static BitmapImage NewImage(Chat chat)
-        //{
-        //    MemoryStream ms = new MemoryStream(chat.ImgSource);
-        //    BitmapImage image = new BitmapImage();
-        //    image.BeginInit();
-        //    image.StreamSource = ms;
-        //    image.EndInit();
-        //    return image;
-        //}
+        public static BitmapImage NewImage(Parts part)
+        {
+            MemoryStream ms = new MemoryStream(part.Image);
+            BitmapImage image = new BitmapImage();
+            image.BeginInit();
+            image.StreamSource = ms;
+            image.EndInit();
+            return image;
+        }
 
         //public static BitmapImage NewImage(User user)
         //{

+ 3 - 1
PartsWarehouse/MainWindow.xaml

@@ -70,7 +70,9 @@
                 <TextBox Name="VinBox"
                          Height="30"
                          Margin="5"
-                         Text="Vin...">
+                         Text="Vin..."
+                         PreviewMouseDown="VinBox_PreviewMouseDown"
+                         LostFocus="VinBox_LostFocus">
                 </TextBox>
                 <Button Height="30"
                         Margin="5"

+ 11 - 0
PartsWarehouse/MainWindow.xaml.cs

@@ -76,5 +76,16 @@ namespace PartsWarehouse
             }
 
         }
+
+        private void VinBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
+        {
+            VinBox.Text = string.Empty;
+        }
+
+        private void VinBox_LostFocus(object sender, RoutedEventArgs e)
+        {
+            if (VinBox.Text.Trim() == "")
+                VinBox.Text = "Vin...";
+        }
     }
 }

+ 12 - 12
PartsWarehouse/СatalogPage.xaml.cs

@@ -38,7 +38,7 @@ namespace PartsWarehouse
 
         private void CarCompanyBox_LostFocus(object sender, RoutedEventArgs e)
         {
-            if (CarCompanyBox.Text == "")
+            if (CarCompanyBox.Text.Trim() == "")
                 CarCompanyBox.Text = "Марка";
         }
 
@@ -49,7 +49,7 @@ namespace PartsWarehouse
 
         private void CarNameBox_LostFocus(object sender, RoutedEventArgs e)
         {
-            if (CarNameBox.Text == "")
+            if (CarNameBox.Text.Trim() == "")
                 CarNameBox.Text = "Название";
         }
 
@@ -60,7 +60,7 @@ namespace PartsWarehouse
 
         private void CarGenerationBox_LostFocus(object sender, RoutedEventArgs e)
         {
-            if (CarGenerationBox.Text == "")
+            if (CarGenerationBox.Text.Trim() == "")
                 CarGenerationBox.Text = "Поколение";
         }
 
@@ -71,7 +71,7 @@ namespace PartsWarehouse
 
         private void PartTypeBox_LostFocus(object sender, RoutedEventArgs e)
         {
-            if (PartTypeBox.Text == "")
+            if (PartTypeBox.Text.Trim() == "")
                 PartTypeBox.Text = "Тип запчасти";
         }
 
@@ -82,7 +82,7 @@ namespace PartsWarehouse
 
         private void NameBox_LostFocus(object sender, RoutedEventArgs e)
         {
-            if (NameBox.Text == "")
+            if (NameBox.Text.Trim() == "")
                 NameBox.Text = "Название запчасти";
         }
 
@@ -93,7 +93,7 @@ namespace PartsWarehouse
 
         private void ModelBox_LostFocus(object sender, RoutedEventArgs e)
         {
-            if (ModelBox.Text == "")
+            if (ModelBox.Text.Trim() == "")
                 ModelBox.Text = "Модель";
         }
 
@@ -104,7 +104,7 @@ namespace PartsWarehouse
 
         private void OriginalBox_LostFocus(object sender, RoutedEventArgs e)
         {
-            if (OriginalBox.Text == "")
+            if (OriginalBox.Text.Trim() == "")
                 OriginalBox.Text = "Оригинал: Не важно";
         }
 
@@ -135,16 +135,16 @@ namespace PartsWarehouse
                 foreach (Parts part in list)
                 {
                     BitmapImage img = new BitmapImage();
-                    if (part.Image != null)
+                    if (part.Image == null)
                         img = new BitmapImage(new Uri("../Resources/NotFound.png", UriKind.RelativeOrAbsolute));
-                    //else
-                    //    img = ImagesManip.NewImage(cnt.db.User.Where(item => item.Id == idAuthor).FirstOrDefault());
+                    else
+                        img = ImagesManip.NewImage(part);
                     AddPart(part.Name, part.Description, part.PartNum, img);
                 }
             }
-            catch
+            catch (Exception ex)
             {
-                new ErrorWindow("биба").ShowDialog();
+                new ErrorWindow(ex.ToString()).ShowDialog();
             }
 
         }