diff --git a/Lab/.DS_Store b/Lab/.DS_Store new file mode 100644 index 0000000..c4e6f59 Binary files /dev/null and b/Lab/.DS_Store differ diff --git a/Lab/Lab.xcodeproj/project.pbxproj b/Lab/Lab.xcodeproj/project.pbxproj new file mode 100644 index 0000000..eb24b84 --- /dev/null +++ b/Lab/Lab.xcodeproj/project.pbxproj @@ -0,0 +1,472 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 55; + objects = { + +/* Begin PBXBuildFile section */ + 04E6467727784736008FB107 /* Customer VC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04E6467627784736008FB107 /* Customer VC.swift */; }; + FA256450276F3CC3004A0462 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA25644F276F3CC3004A0462 /* AppDelegate.swift */; }; + FA256452276F3CC3004A0462 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA256451276F3CC3004A0462 /* SceneDelegate.swift */; }; + FA256457276F3CC3004A0462 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FA256455276F3CC3004A0462 /* Main.storyboard */; }; + FA25645A276F3CC3004A0462 /* Lab.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = FA256458276F3CC3004A0462 /* Lab.xcdatamodeld */; }; + FA25645C276F3CCC004A0462 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FA25645B276F3CCC004A0462 /* Assets.xcassets */; }; + FA25645F276F3CCC004A0462 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FA25645D276F3CCC004A0462 /* LaunchScreen.storyboard */; }; + FA30C69D27749398001C869F /* NewOrder.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA30C69C27749398001C869F /* NewOrder.swift */; }; + FA30C69F2774A63A001C869F /* SupplierVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA30C69E2774A63A001C869F /* SupplierVC.swift */; }; + FA30C6A12774AB2B001C869F /* NewSupplier.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA30C6A02774AB2B001C869F /* NewSupplier.swift */; }; + FA30C6A32774AB5F001C869F /* PartVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA30C6A22774AB5F001C869F /* PartVC.swift */; }; + FA30C6A52774ABE0001C869F /* TabVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA30C6A42774ABE0001C869F /* TabVC.swift */; }; + FA55657E27750D2E00482EB8 /* LifeTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA55657D27750D2D00482EB8 /* LifeTime.swift */; }; + FA5565802775114000482EB8 /* NewLifeTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA55657F2775114000482EB8 /* NewLifeTime.swift */; }; + FA5565882775275E00482EB8 /* NewPart.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5565872775275E00482EB8 /* NewPart.swift */; }; + FA87726327744A10008B080E /* DataServiec.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA87726227744A10008B080E /* DataServiec.swift */; }; + FA87726727744B90008B080E /* OrderVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA87726627744B90008B080E /* OrderVC.swift */; }; + FA8772692774585A008B080E /* NewCustomer.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8772682774585A008B080E /* NewCustomer.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 04E6467627784736008FB107 /* Customer VC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Customer VC.swift"; sourceTree = ""; }; + FA25644C276F3CC3004A0462 /* Lab.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Lab.app; sourceTree = BUILT_PRODUCTS_DIR; }; + FA25644F276F3CC3004A0462 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + FA256451276F3CC3004A0462 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + FA256456276F3CC3004A0462 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + FA256459276F3CC3004A0462 /* Lab.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Lab.xcdatamodel; sourceTree = ""; }; + FA25645B276F3CCC004A0462 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + FA25645E276F3CCC004A0462 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + FA256460276F3CCC004A0462 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + FA30C69C27749398001C869F /* NewOrder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewOrder.swift; sourceTree = ""; }; + FA30C69E2774A63A001C869F /* SupplierVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupplierVC.swift; sourceTree = ""; }; + FA30C6A02774AB2B001C869F /* NewSupplier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewSupplier.swift; sourceTree = ""; }; + FA30C6A22774AB5F001C869F /* PartVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartVC.swift; sourceTree = ""; }; + FA30C6A42774ABE0001C869F /* TabVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabVC.swift; sourceTree = ""; }; + FA55657D27750D2D00482EB8 /* LifeTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LifeTime.swift; sourceTree = ""; }; + FA55657F2775114000482EB8 /* NewLifeTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewLifeTime.swift; sourceTree = ""; }; + FA5565872775275E00482EB8 /* NewPart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewPart.swift; sourceTree = ""; }; + FA87726227744A10008B080E /* DataServiec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataServiec.swift; sourceTree = ""; }; + FA87726627744B90008B080E /* OrderVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderVC.swift; sourceTree = ""; }; + FA8772682774585A008B080E /* NewCustomer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewCustomer.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + FA256449276F3CC3004A0462 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + FA256443276F3CC3004A0462 = { + isa = PBXGroup; + children = ( + FA25644E276F3CC3004A0462 /* Lab */, + FA25644D276F3CC3004A0462 /* Products */, + ); + sourceTree = ""; + }; + FA25644D276F3CC3004A0462 /* Products */ = { + isa = PBXGroup; + children = ( + FA25644C276F3CC3004A0462 /* Lab.app */, + ); + name = Products; + sourceTree = ""; + }; + FA25644E276F3CC3004A0462 /* Lab */ = { + isa = PBXGroup; + children = ( + FA25644F276F3CC3004A0462 /* AppDelegate.swift */, + FA256451276F3CC3004A0462 /* SceneDelegate.swift */, + FA30C6A42774ABE0001C869F /* TabVC.swift */, + FA55658627751D8300482EB8 /* Serviec */, + FA55658127751CBA00482EB8 /* Customer */, + FA55658227751CC800482EB8 /* Order */, + FA55658327751CD300482EB8 /* LifeTime */, + FA55658427751D1B00482EB8 /* Supplier */, + FA55658527751D5900482EB8 /* Part */, + FA256455276F3CC3004A0462 /* Main.storyboard */, + FA25645B276F3CCC004A0462 /* Assets.xcassets */, + FA25645D276F3CCC004A0462 /* LaunchScreen.storyboard */, + FA256460276F3CCC004A0462 /* Info.plist */, + FA256458276F3CC3004A0462 /* Lab.xcdatamodeld */, + ); + path = Lab; + sourceTree = ""; + }; + FA55658127751CBA00482EB8 /* Customer */ = { + isa = PBXGroup; + children = ( + FA8772682774585A008B080E /* NewCustomer.swift */, + 04E6467627784736008FB107 /* Customer VC.swift */, + ); + path = Customer; + sourceTree = ""; + }; + FA55658227751CC800482EB8 /* Order */ = { + isa = PBXGroup; + children = ( + FA30C69C27749398001C869F /* NewOrder.swift */, + FA87726627744B90008B080E /* OrderVC.swift */, + ); + path = Order; + sourceTree = ""; + }; + FA55658327751CD300482EB8 /* LifeTime */ = { + isa = PBXGroup; + children = ( + FA55657D27750D2D00482EB8 /* LifeTime.swift */, + FA55657F2775114000482EB8 /* NewLifeTime.swift */, + ); + path = LifeTime; + sourceTree = ""; + }; + FA55658427751D1B00482EB8 /* Supplier */ = { + isa = PBXGroup; + children = ( + FA30C69E2774A63A001C869F /* SupplierVC.swift */, + FA30C6A02774AB2B001C869F /* NewSupplier.swift */, + ); + path = Supplier; + sourceTree = ""; + }; + FA55658527751D5900482EB8 /* Part */ = { + isa = PBXGroup; + children = ( + FA30C6A22774AB5F001C869F /* PartVC.swift */, + FA5565872775275E00482EB8 /* NewPart.swift */, + ); + path = Part; + sourceTree = ""; + }; + FA55658627751D8300482EB8 /* Serviec */ = { + isa = PBXGroup; + children = ( + FA87726227744A10008B080E /* DataServiec.swift */, + ); + path = Serviec; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + FA25644B276F3CC3004A0462 /* Lab */ = { + isa = PBXNativeTarget; + buildConfigurationList = FA256463276F3CCC004A0462 /* Build configuration list for PBXNativeTarget "Lab" */; + buildPhases = ( + FA256448276F3CC3004A0462 /* Sources */, + FA256449276F3CC3004A0462 /* Frameworks */, + FA25644A276F3CC3004A0462 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Lab; + productName = Lab; + productReference = FA25644C276F3CC3004A0462 /* Lab.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + FA256444276F3CC3004A0462 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1310; + LastUpgradeCheck = 1310; + TargetAttributes = { + FA25644B276F3CC3004A0462 = { + CreatedOnToolsVersion = 13.1; + }; + }; + }; + buildConfigurationList = FA256447276F3CC3004A0462 /* Build configuration list for PBXProject "Lab" */; + compatibilityVersion = "Xcode 13.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = FA256443276F3CC3004A0462; + productRefGroup = FA25644D276F3CC3004A0462 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + FA25644B276F3CC3004A0462 /* Lab */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + FA25644A276F3CC3004A0462 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + FA25645F276F3CCC004A0462 /* LaunchScreen.storyboard in Resources */, + FA25645C276F3CCC004A0462 /* Assets.xcassets in Resources */, + FA256457276F3CC3004A0462 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + FA256448276F3CC3004A0462 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + FA8772692774585A008B080E /* NewCustomer.swift in Sources */, + FA30C69D27749398001C869F /* NewOrder.swift in Sources */, + 04E6467727784736008FB107 /* Customer VC.swift in Sources */, + FA55657E27750D2E00482EB8 /* LifeTime.swift in Sources */, + FA87726727744B90008B080E /* OrderVC.swift in Sources */, + FA30C6A52774ABE0001C869F /* TabVC.swift in Sources */, + FA5565802775114000482EB8 /* NewLifeTime.swift in Sources */, + FA30C69F2774A63A001C869F /* SupplierVC.swift in Sources */, + FA256450276F3CC3004A0462 /* AppDelegate.swift in Sources */, + FA5565882775275E00482EB8 /* NewPart.swift in Sources */, + FA87726327744A10008B080E /* DataServiec.swift in Sources */, + FA30C6A12774AB2B001C869F /* NewSupplier.swift in Sources */, + FA256452276F3CC3004A0462 /* SceneDelegate.swift in Sources */, + FA25645A276F3CC3004A0462 /* Lab.xcdatamodeld in Sources */, + FA30C6A32774AB5F001C869F /* PartVC.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + FA256455276F3CC3004A0462 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + FA256456276F3CC3004A0462 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + FA25645D276F3CCC004A0462 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + FA25645E276F3CCC004A0462 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + FA256461276F3CCC004A0462 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 15.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + FA256462276F3CCC004A0462 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 15.0; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + FA256464276F3CCC004A0462 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = Lab/Info.plist; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; + INFOPLIST_KEY_UIMainStoryboardFile = Main; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.mun.Lab; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + FA256465276F3CCC004A0462 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = Lab/Info.plist; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; + INFOPLIST_KEY_UIMainStoryboardFile = Main; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.mun.Lab; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + FA256447276F3CC3004A0462 /* Build configuration list for PBXProject "Lab" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + FA256461276F3CCC004A0462 /* Debug */, + FA256462276F3CCC004A0462 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + FA256463276F3CCC004A0462 /* Build configuration list for PBXNativeTarget "Lab" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + FA256464276F3CCC004A0462 /* Debug */, + FA256465276F3CCC004A0462 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCVersionGroup section */ + FA256458276F3CC3004A0462 /* Lab.xcdatamodeld */ = { + isa = XCVersionGroup; + children = ( + FA256459276F3CC3004A0462 /* Lab.xcdatamodel */, + ); + currentVersion = FA256459276F3CC3004A0462 /* Lab.xcdatamodel */; + path = Lab.xcdatamodeld; + sourceTree = ""; + versionGroupType = wrapper.xcdatamodel; + }; +/* End XCVersionGroup section */ + }; + rootObject = FA256444276F3CC3004A0462 /* Project object */; +} diff --git a/Lab/Lab.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Lab/Lab.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/Lab/Lab.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Lab/Lab.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Lab/Lab.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Lab/Lab.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Lab/Lab.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate b/Lab/Lab.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..1169bf2 Binary files /dev/null and b/Lab/Lab.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Lab/Lab.xcodeproj/project.xcworkspace/xcuserdata/macbook.xcuserdatad/UserInterfaceState.xcuserstate b/Lab/Lab.xcodeproj/project.xcworkspace/xcuserdata/macbook.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..119eb5d Binary files /dev/null and b/Lab/Lab.xcodeproj/project.xcworkspace/xcuserdata/macbook.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Lab/Lab.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist b/Lab/Lab.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..f6f4697 --- /dev/null +++ b/Lab/Lab.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + Lab.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/Lab/Lab.xcodeproj/xcuserdata/macbook.xcuserdatad/xcschemes/xcschememanagement.plist b/Lab/Lab.xcodeproj/xcuserdata/macbook.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..f6f4697 --- /dev/null +++ b/Lab/Lab.xcodeproj/xcuserdata/macbook.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + Lab.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/Lab/Lab/.DS_Store b/Lab/Lab/.DS_Store new file mode 100644 index 0000000..3d02a28 Binary files /dev/null and b/Lab/Lab/.DS_Store differ diff --git a/Lab/Lab/AppDelegate.swift b/Lab/Lab/AppDelegate.swift new file mode 100644 index 0000000..62949e5 --- /dev/null +++ b/Lab/Lab/AppDelegate.swift @@ -0,0 +1,37 @@ +// +// AppDelegate.swift +// Lab +// +// Created by PC on 15/05/1443 AH. +// + +import UIKit +import CoreData + +@main +class AppDelegate: UIResponder, UIApplicationDelegate { + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + + DataService.shared.load() + + return true + } + + // MARK: UISceneSession Lifecycle + + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + } + + func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. + } +} + diff --git a/Lab/Lab/Assets.xcassets/AccentColor.colorset/Contents.json b/Lab/Lab/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/Lab/Lab/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Lab/Lab/Assets.xcassets/AppIcon.appiconset/Contents.json b/Lab/Lab/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..9221b9b --- /dev/null +++ b/Lab/Lab/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "83.5x83.5" + }, + { + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Lab/Lab/Assets.xcassets/Contents.json b/Lab/Lab/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/Lab/Lab/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Lab/Lab/Base.lproj/LaunchScreen.storyboard b/Lab/Lab/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..865e932 --- /dev/null +++ b/Lab/Lab/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Lab/Lab/Base.lproj/Main.storyboard b/Lab/Lab/Base.lproj/Main.storyboard new file mode 100644 index 0000000..25a7638 --- /dev/null +++ b/Lab/Lab/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Lab/Lab/Customer/Customer VC.swift b/Lab/Lab/Customer/Customer VC.swift new file mode 100644 index 0000000..8f36420 --- /dev/null +++ b/Lab/Lab/Customer/Customer VC.swift @@ -0,0 +1,122 @@ +// +// Customer VC.swift +// Lab +// +// Created by PC on 22/05/1443 AH. +// + +import UIKit +import CoreData +var selectedIndex = -1 +class CustomersVC: UITableViewController, NSFetchedResultsControllerDelegate { + + var fetchedResultsController: NSFetchedResultsController? + + override func viewDidLoad() { + super.viewDidLoad() + + navigationItem.rightBarButtonItem = UIBarButtonItem( + title: "Add", + style: .done, + target: self, + action: #selector(add) + ) + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + setupFetchedResultsController() + } + + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + fetchedResultsController = nil + } + + func setupFetchedResultsController() { + let fetchRequest: NSFetchRequest = Customer.fetchRequest() + fetchRequest.sortDescriptors = [ + NSSortDescriptor(key: "firstname", ascending: false), +// NSSortDescriptor(key: "lastName", ascending: false), + ] + + fetchedResultsController = NSFetchedResultsController( + fetchRequest: fetchRequest, + managedObjectContext: DataService.shared.viewContext, + sectionNameKeyPath: nil, + cacheName: nil + ) + fetchedResultsController?.delegate = self + + do { + try fetchedResultsController?.performFetch() + tableView.reloadData() + } catch { + fatalError("The fetch could not be performd: \(error.localizedDescription)") + } + } + + + @objc func add() { + let newVC = NewCustomer() + present(newVC, animated: true, completion: nil) + } + + func controllerDidChangeContent(_ controller: NSFetchedResultsController) { + + tableView.reloadData() + } +} + +extension CustomersVC { + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + guard let customers = fetchedResultsController?.fetchedObjects else { return 0 } + + return customers.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = UITableViewCell.init(style: .subtitle, reuseIdentifier: "123") + + let customer = fetchedResultsController?.fetchedObjects?[indexPath.row] + + cell.textLabel?.text = "First Name: \(customer?.firstname ?? "")" + cell.detailTextLabel?.text = "Last Name:\(customer?.lastName ?? "")" + + return cell + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + + guard let customer = fetchedResultsController?.fetchedObjects?[indexPath.row] else { + return + } + + let newVC = OrderVC() + newVC.customer = customer + newVC.title = fetchedResultsController?.fetchedObjects?[indexPath.row].firstname + let navController = UINavigationController(rootViewController: newVC) + present(navController, animated: true, completion: nil) + } + + + override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { + return UISwipeActionsConfiguration( + actions: [ + UIContextualAction( + style: .destructive, + title: "Delete", + handler: { _, _, _ in + guard let customer = self.fetchedResultsController?.fetchedObjects?[indexPath.row] else { + return + } + DataService.shared.viewContext.delete(customer) + DataService.shared.saveContext() + } + ) + ] + ) + } +} + + diff --git a/Lab/Lab/Customer/NewCustomer.swift b/Lab/Lab/Customer/NewCustomer.swift new file mode 100644 index 0000000..972b5c7 --- /dev/null +++ b/Lab/Lab/Customer/NewCustomer.swift @@ -0,0 +1,144 @@ +// +// NewCustomer.swift +// Lab +// +// Created by PC on 19/05/1443 AH. +// + +import UIKit + + +class NewCustomer: UIViewController, UITextFieldDelegate { + + + var a : Customer? + + lazy var TF1: UITextField = { + let tf = UITextField() + tf.translatesAutoresizingMaskIntoConstraints = false + tf.placeholder = NSLocalizedString("", comment:" ") + tf.backgroundColor = .white + tf.textAlignment = .right + tf.delegate = self + tf.layer.cornerRadius = 20 + return tf + }() + + lazy var TF2: UITextField = { + let tf = UITextField() + tf.translatesAutoresizingMaskIntoConstraints = false + tf.placeholder = NSLocalizedString("", comment:" ") + tf.backgroundColor = .white + tf.textAlignment = .right + tf.delegate = self + tf.layer.cornerRadius = 20 + return tf + }() + + lazy var addButton: UIButton = { + let b = UIButton() + b.addTarget(self, action: #selector(add), for: .touchUpInside) + b.translatesAutoresizingMaskIntoConstraints = false + b.setTitle(NSLocalizedString("add", comment:""), for: .normal) + b.titleLabel?.font = UIFont(name: "Avenir-Light", size: 27.0) + b.layer.cornerRadius = 25 + b.backgroundColor = UIColor(red: (87/255), green: (107/255), blue: (96/255), alpha: 1) + return b + }() + + public let LabelN: UILabel = { + let label = UILabel() + label.font = UIFont(name: "Avenir-Light", size: 20) + label.textColor = UIColor(named: "Color2") + label.text = NSLocalizedString("First Name", comment:" ") + label.textAlignment = .right + + return label + }() + public let LabelID: UILabel = { + let label = UILabel() + label.font = UIFont(name: "Avenir-Light", size: 20) + label.textColor = UIColor(named: "Color2") + label.text = NSLocalizedString(" Last Name ", comment:"") + label.textAlignment = .right + return label + }() + + + + + + + @objc func add() { + + + let s = Customer( + context: DataService.shared.viewContext + ) + s.firstname = TF1.text ?? "" + s.lastName = TF2.text ?? "" + + DataService.shared.saveContext() + } + + + + + override func viewDidLoad() { + super.viewDidLoad() + view.backgroundColor = .gray + + + TF1.text = a?.firstname + TF2.text = a?.lastName + view.addSubview(LabelN) + view.addSubview(LabelID) + view.addSubview(addButton) + view.addSubview(TF1) + + + + LabelN.frame = CGRect(x: 290, + y: 70, + width: 110, + height:130) + + LabelID.frame = CGRect(x: 260, + y: 150, + width: 140, + height:130) + NSLayoutConstraint.activate([ + TF1.centerXAnchor.constraint(equalTo: view.centerXAnchor), + TF1.topAnchor.constraint(equalTo: view.topAnchor, constant: 150), + TF1.heightAnchor.constraint(equalToConstant: 48), + TF1.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -48) + ]) + + view.addSubview(TF2) + NSLayoutConstraint.activate([ + TF2.topAnchor.constraint(equalTo: view.topAnchor, constant: 250), + TF2.centerXAnchor.constraint(equalTo: view.centerXAnchor), + TF2.heightAnchor.constraint(equalToConstant: 48), + TF2.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -48) + ]) + NSLayoutConstraint.activate([ + addButton.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -80), + addButton.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 80), + addButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -300), + addButton.widthAnchor.constraint(equalToConstant: 400), + addButton.heightAnchor.constraint(equalToConstant: 60), + ]) + + + + } + + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + + dismiss(animated: true, completion: nil) + return true + } + + + +} diff --git a/Lab/Lab/Info.plist b/Lab/Lab/Info.plist new file mode 100644 index 0000000..dd3c9af --- /dev/null +++ b/Lab/Lab/Info.plist @@ -0,0 +1,25 @@ + + + + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + + diff --git a/Lab/Lab/Lab.xcdatamodeld/.xccurrentversion b/Lab/Lab/Lab.xcdatamodeld/.xccurrentversion new file mode 100644 index 0000000..bff2847 --- /dev/null +++ b/Lab/Lab/Lab.xcdatamodeld/.xccurrentversion @@ -0,0 +1,8 @@ + + + + + _XCCurrentVersionName + Lab.xcdatamodel + + diff --git a/Lab/Lab/Lab.xcdatamodeld/Lab.xcdatamodel/contents b/Lab/Lab/Lab.xcdatamodeld/Lab.xcdatamodel/contents new file mode 100644 index 0000000..91d101f --- /dev/null +++ b/Lab/Lab/Lab.xcdatamodeld/Lab.xcdatamodel/contents @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab/Lab/LifeTime/LifeTime.swift b/Lab/Lab/LifeTime/LifeTime.swift new file mode 100644 index 0000000..88c738b --- /dev/null +++ b/Lab/Lab/LifeTime/LifeTime.swift @@ -0,0 +1,250 @@ +// +// LifeTime.swift +// Lab +// +// Created by PC on 19/05/1443 AH. +// + + +import UIKit +import CoreData + +class LifeTime: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate { + var lifetime: Order? + + + var fetchedResultsController: NSFetchedResultsController? + + lazy var tableView: UITableView = { + let tablaView = UITableView() + tablaView.translatesAutoresizingMaskIntoConstraints = false + tablaView.delegate = self + tablaView.dataSource = self + tablaView.register(Cell2.self, forCellReuseIdentifier: Cell2.identifire) + tablaView.backgroundColor = .white + return tablaView + }() + override func viewDidLoad() { + super.viewDidLoad() + view.addSubview(tableView) + + NSLayoutConstraint.activate([ + tableView.topAnchor.constraint(equalTo: view.topAnchor), + tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor), + tableView.rightAnchor.constraint(equalTo: view.rightAnchor), + tableView.leftAnchor.constraint(equalTo: view.leftAnchor), + ]) + navigationItem.rightBarButtonItem = UIBarButtonItem( + title: "Add", + style: .done, + target: self, + action: #selector(add) + ) + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + setupFetchedResultsController() + } + + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + fetchedResultsController = nil + } + + func setupFetchedResultsController() { + let fetchRequest: NSFetchRequest = Lifetime.fetchRequest() + fetchRequest.sortDescriptors = [ + NSSortDescriptor(key: "shipInstructions", ascending: false), +// NSSortDescriptor(key: "lastName", ascending: false), + ] + + fetchedResultsController = NSFetchedResultsController( + fetchRequest: fetchRequest, + managedObjectContext: DataService.shared.viewContext, + sectionNameKeyPath: nil, + cacheName: nil + ) + fetchedResultsController?.delegate = self + + do { + try fetchedResultsController?.performFetch() + tableView.reloadData() + } catch { + fatalError("The fetch could not be performd: \(error.localizedDescription)") + } + } + + + @objc func add() { + let newVC = NewLifeTime() + present(newVC, animated: true, completion: nil) + } + + func controllerDidChangeContent(_ controller: NSFetchedResultsController) { + + tableView.reloadData() + } +} + +extension LifeTime { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + guard let lifetimes = fetchedResultsController?.fetchedObjects else { return 0 } + + return lifetimes.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: Cell2.identifire, for: indexPath) as! Cell2 + + + let lifetime = fetchedResultsController?.fetchedObjects?[indexPath.row] + + cell.label2.text = "Status: \(lifetime?.shipInstructions ?? "")" + cell.label3.text = "return flag:\(lifetime!.returnFlag)" + cell.label4.text = "Ship Date:\(lifetime!.shipDate ?? Date())" + cell.label5.text = "Recipt Date:\(lifetime!.reciptDate ?? Date())" + cell.label6.text = "shipping: \(lifetime!.quantity)" + + + return cell + } + + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + if indexPath.row == selectedIndex { + return 370 + }else { + return 225 + } + } + + + func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { + return UISwipeActionsConfiguration( + actions: [ + UIContextualAction( + style: .destructive, + title: "Delete", + handler: { _, _, _ in + guard let lifetime = self.fetchedResultsController?.fetchedObjects?[indexPath.row] else { + return + } + DataService.shared.viewContext.delete(lifetime) + DataService.shared.saveContext() + } + ) + ] + ) + } +} + + +class Cell2: UITableViewCell { + + static let identifire = "Cell" + + public let label2: UILabel = { + let label = UILabel() + label.font = UIFont.systemFont(ofSize: 20, weight: .regular) + label.textColor = .black + label.textAlignment = .left + label.font = UIFont(name: "Avenir-Light", size: 20) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + public let label3: UILabel = { + let label = UILabel() + label.font = UIFont.systemFont(ofSize: 18, weight: .regular) + label.textColor = .black + label.textAlignment = .left + label.font = UIFont(name: "Avenir-Light", size: 18) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + public let label4: UILabel = { + let label = UILabel() + label.font = UIFont.systemFont(ofSize: 18, weight: .regular) + label.textColor = .black + label.font = UIFont(name: "Avenir-Light", size: 18) + label.translatesAutoresizingMaskIntoConstraints = false + label.textAlignment = .left + return label + }() + public let label5: UILabel = { + let label = UILabel() + label.font = UIFont.systemFont(ofSize: 18, weight: .regular) + label.textColor = .black + label.textAlignment = .left + label.font = UIFont(name: "Avenir-Light", size: 18) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + public let label6: UILabel = { + let label = UILabel() +// label.text = "a" + label.textAlignment = .left + label.font = UIFont.systemFont(ofSize: 18, weight: .regular) + label.textColor = .black + label.font = UIFont(name: "Avenir-Light", size: 18) + label.translatesAutoresizingMaskIntoConstraints = false + return label + + }() + + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + contentView.clipsToBounds = true + contentView.backgroundColor = #colorLiteral(red: 1, green: 0.9926941103, blue: 0.9993625388, alpha: 1) + contentView.layer.cornerRadius = 13 + + + self.addSubview(label2) + self.addSubview(label3) + self.addSubview(label4) + self.addSubview(label5) + self.addSubview(label6) + + NSLayoutConstraint.activate([ + label2.topAnchor.constraint(equalTo: self.topAnchor, constant: 5), + label2.rightAnchor.constraint(equalTo: self.rightAnchor ), + label2.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 9), + + label3.topAnchor.constraint(equalTo: label2.bottomAnchor, constant: 10), + label3.rightAnchor.constraint(equalTo: self.rightAnchor), + label3.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 9), + + label4.topAnchor.constraint(equalTo: label3.bottomAnchor, constant: 10), + label4.rightAnchor.constraint(equalTo: self.rightAnchor), + label4.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 9), + + label6.topAnchor.constraint(equalTo: label4.bottomAnchor, constant: 10), + label6.rightAnchor.constraint(equalTo: self.rightAnchor), + label6.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 9), + + label5.topAnchor.constraint(equalTo: label6.bottomAnchor, constant: 10), + label5.rightAnchor.constraint(equalTo: self.rightAnchor), + label5.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 9), + ]) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func layoutSubviews() { + super.layoutSubviews() + + contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)) + + + + + + + } + +} diff --git a/Lab/Lab/LifeTime/NewLifeTime.swift b/Lab/Lab/LifeTime/NewLifeTime.swift new file mode 100644 index 0000000..93e9903 --- /dev/null +++ b/Lab/Lab/LifeTime/NewLifeTime.swift @@ -0,0 +1,210 @@ +// +// NewLifeTime.swift +// Lab +// +// Created by PC on 19/05/1443 AH. +// + + +import UIKit + + +class NewLifeTime: UIViewController, UITextFieldDelegate { + + + var b : Lifetime? + lazy var datePicker: UIDatePicker = { + let dp = UIDatePicker() + dp.translatesAutoresizingMaskIntoConstraints = false + dp.addTarget(self, action: #selector(dateChanged), for: .valueChanged) + dp.datePickerMode = .date + dp.layer.cornerRadius = 12 + return dp + }() + lazy var datePicker2: UIDatePicker = { + let dp = UIDatePicker() + dp.translatesAutoresizingMaskIntoConstraints = false + dp.addTarget(self, action: #selector(dateChanged2), for: .valueChanged) + dp.datePickerMode = .date + dp.layer.cornerRadius = 12 + return dp + }() + + lazy var TF1: UITextField = { + let tf = UITextField() + tf.translatesAutoresizingMaskIntoConstraints = false + tf.placeholder = NSLocalizedString("", comment:" ") + tf.backgroundColor = .white + tf.textAlignment = .right + tf.delegate = self + tf.layer.cornerRadius = 20 + return tf + }() + + lazy var TF2: UITextField = { + let tf = UITextField() + tf.translatesAutoresizingMaskIntoConstraints = false + tf.placeholder = NSLocalizedString("", comment:" ") + tf.backgroundColor = .white + tf.textAlignment = .right + tf.delegate = self + tf.layer.cornerRadius = 20 + return tf + }() + lazy var TF3: UITextField = { + let tf = UITextField() + tf.translatesAutoresizingMaskIntoConstraints = false + tf.placeholder = NSLocalizedString("", comment:" ") + tf.backgroundColor = .white + tf.textAlignment = .right + tf.delegate = self + tf.layer.cornerRadius = 20 + return tf + }() + lazy var addButton: UIButton = { + let b = UIButton() + b.addTarget(self, action: #selector(add), for: .touchUpInside) + b.translatesAutoresizingMaskIntoConstraints = false + b.setTitle(NSLocalizedString("add", comment:""), for: .normal) + b.titleLabel?.font = UIFont(name: "Avenir-Light", size: 27.0) + b.layer.cornerRadius = 25 + b.backgroundColor = UIColor(red: (87/255), green: (107/255), blue: (96/255), alpha: 1) + return b + }() + + public let LabelN: UILabel = { + let label = UILabel() + label.font = UIFont(name: "Avenir-Light", size: 20) + label.textColor = UIColor(named: "Color2") + label.text = NSLocalizedString("Ship Instructions:", comment:" ") + label.textAlignment = .left + + return label + }() + public let LabelID: UILabel = { + let label = UILabel() + label.font = UIFont(name: "Avenir-Light", size: 20) + label.textColor = UIColor(named: "Color2") + label.text = NSLocalizedString("Return Flag:", comment:"") + label.textAlignment = .left + return label + }() + public let LabelI: UILabel = { + let label = UILabel() + label.font = UIFont(name: "Avenir-Light", size: 20) + label.textColor = UIColor(named: "Color2") + label.text = NSLocalizedString(" Quantity: ", comment:"") + label.textAlignment = .left + return label + }() + + + + + + @objc func add() { + + + let s = Lifetime( + context: DataService.shared.viewContext + ) + s.shipInstructions = TF1.text ?? "" + s.returnFlag = Bool(TF2.text ?? "") ?? true + s.shipDate = datePicker.date + s.reciptDate = datePicker2.date + s.quantity = Int32(TF3.text ?? "") ?? 0 + + DataService.shared.saveContext() + } + + + @objc func dateChanged() { + + print("New date = \(datePicker.date)") + } + @objc func dateChanged2() { + + print("New date = \(datePicker.date)") + } + + override func viewDidLoad() { + super.viewDidLoad() + view.backgroundColor = .gray + + + TF1.text = b?.shipInstructions + view.addSubview(LabelN) + view.addSubview(LabelID) + view.addSubview(LabelI) + view.addSubview(addButton) + view.addSubview(TF1) + + + + LabelN.frame = CGRect(x: 10, + y: 16, + width: 110, + height:130) + + LabelID.frame = CGRect(x: 10, + y: 115, + width: 140, + height:130) + LabelI.frame = CGRect(x: 10, + y: 218, + width: 140, + height:130) + NSLayoutConstraint.activate([ + TF1.centerXAnchor.constraint(equalTo: view.centerXAnchor), + TF1.topAnchor.constraint(equalTo: view.topAnchor, constant: 110), + TF1.heightAnchor.constraint(equalToConstant: 48), + TF1.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -48) + ]) + + view.addSubview(TF2) + NSLayoutConstraint.activate([ + TF2.topAnchor.constraint(equalTo: view.topAnchor, constant: 200), + TF2.centerXAnchor.constraint(equalTo: view.centerXAnchor), + TF2.heightAnchor.constraint(equalToConstant: 48), + TF2.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -48) + ]) + view.addSubview(TF3) + NSLayoutConstraint.activate([ + TF3.topAnchor.constraint(equalTo: view.topAnchor, constant: 300), + TF3.centerXAnchor.constraint(equalTo: view.centerXAnchor), + TF3.heightAnchor.constraint(equalToConstant: 48), + TF3.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -48) + ]) + NSLayoutConstraint.activate([ + addButton.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -80), + addButton.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 80), + addButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -300), + addButton.widthAnchor.constraint(equalToConstant: 400), + addButton.heightAnchor.constraint(equalToConstant: 60), + ]) + + + view.addSubview(datePicker) + NSLayoutConstraint.activate([ + datePicker.centerXAnchor.constraint(equalTo: view.centerXAnchor), + datePicker.topAnchor.constraint(equalTo: view.topAnchor, constant: 380), + + ]) + view.addSubview(datePicker2) + NSLayoutConstraint.activate([ + datePicker2.centerXAnchor.constraint(equalTo: view.centerXAnchor), + datePicker2.topAnchor.constraint(equalTo: view.topAnchor, constant: 410), + + ]) + } + + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + + dismiss(animated: true, completion: nil) + return true + } + + + +} + diff --git a/Lab/Lab/Order/NewOrder.swift b/Lab/Lab/Order/NewOrder.swift new file mode 100644 index 0000000..24c9e8d --- /dev/null +++ b/Lab/Lab/Order/NewOrder.swift @@ -0,0 +1,184 @@ + +import UIKit + + +class NewOrder: UIViewController, UITextFieldDelegate { + + + var b : Order? + lazy var datePicker: UIDatePicker = { + let dp = UIDatePicker() + dp.translatesAutoresizingMaskIntoConstraints = false + dp.addTarget(self, action: #selector(dateChanged), for: .valueChanged) + dp.datePickerMode = .date + dp.layer.cornerRadius = 12 + return dp + }() + + lazy var TF1: UITextField = { + let tf = UITextField() + tf.translatesAutoresizingMaskIntoConstraints = false + tf.placeholder = NSLocalizedString("", comment:" ") + tf.backgroundColor = .white + tf.textAlignment = .right + tf.delegate = self + tf.layer.cornerRadius = 20 + return tf + }() + + lazy var TF2: UITextField = { + let tf = UITextField() + tf.translatesAutoresizingMaskIntoConstraints = false + tf.placeholder = NSLocalizedString("", comment:" ") + tf.backgroundColor = .white + tf.textAlignment = .right + tf.delegate = self + tf.layer.cornerRadius = 20 + return tf + }() + lazy var TF3: UITextField = { + let tf = UITextField() + tf.translatesAutoresizingMaskIntoConstraints = false + tf.placeholder = NSLocalizedString("", comment:" ") + tf.backgroundColor = .white + tf.textAlignment = .right + tf.delegate = self + tf.layer.cornerRadius = 20 + return tf + }() + lazy var addButton: UIButton = { + let b = UIButton() + b.addTarget(self, action: #selector(add), for: .touchUpInside) + b.translatesAutoresizingMaskIntoConstraints = false + b.setTitle(NSLocalizedString("add", comment:""), for: .normal) + b.titleLabel?.font = UIFont(name: "Avenir-Light", size: 27.0) + b.layer.cornerRadius = 25 + b.backgroundColor = UIColor(red: (87/255), green: (107/255), blue: (96/255), alpha: 1) + return b + }() + + public let LabelN: UILabel = { + let label = UILabel() + label.font = UIFont(name: "Avenir-Light", size: 20) + label.textColor = UIColor(named: "Color2") + label.text = NSLocalizedString("Status", comment:" ") + label.textAlignment = .left + + return label + }() + public let LabelID: UILabel = { + let label = UILabel() + label.font = UIFont(name: "Avenir-Light", size: 20) + label.textColor = UIColor(named: "Color2") + label.text = NSLocalizedString(" Total Price ", comment:"") + label.textAlignment = .left + return label + }() + public let LabelI: UILabel = { + let label = UILabel() + label.font = UIFont(name: "Avenir-Light", size: 20) + label.textColor = UIColor(named: "Color2") + label.text = NSLocalizedString(" Shipping ", comment:"") + label.textAlignment = .left + return label + }() + + + + + + @objc func add() { + + + let s = Order( + context: DataService.shared.viewContext + ) + s.status = TF1.text ?? "" + s.totalPrice = Double(TF2.text ?? "")! + s.orderDate = datePicker.date + s.shippingPriority = Int16(TF3.text ?? "")! + + DataService.shared.saveContext() + } + + + @objc func dateChanged() { + + print("New date = \(datePicker.date)") + } + + override func viewDidLoad() { + super.viewDidLoad() + view.backgroundColor = .gray + + + TF1.text = b?.status + view.addSubview(LabelN) + view.addSubview(LabelID) + view.addSubview(LabelI) + view.addSubview(addButton) + view.addSubview(TF1) + + + + LabelN.frame = CGRect(x: 10, + y: 16, + width: 110, + height:130) + + LabelID.frame = CGRect(x: 10, + y: 115, + width: 140, + height:130) + LabelI.frame = CGRect(x: 10, + y: 218, + width: 140, + height:130) + NSLayoutConstraint.activate([ + TF1.centerXAnchor.constraint(equalTo: view.centerXAnchor), + TF1.topAnchor.constraint(equalTo: view.topAnchor, constant: 110), + TF1.heightAnchor.constraint(equalToConstant: 48), + TF1.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -48) + ]) + + view.addSubview(TF2) + NSLayoutConstraint.activate([ + TF2.topAnchor.constraint(equalTo: view.topAnchor, constant: 200), + TF2.centerXAnchor.constraint(equalTo: view.centerXAnchor), + TF2.heightAnchor.constraint(equalToConstant: 48), + TF2.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -48) + ]) + view.addSubview(TF3) + NSLayoutConstraint.activate([ + TF3.topAnchor.constraint(equalTo: view.topAnchor, constant: 300), + TF3.centerXAnchor.constraint(equalTo: view.centerXAnchor), + TF3.heightAnchor.constraint(equalToConstant: 48), + TF3.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -48) + ]) + NSLayoutConstraint.activate([ + addButton.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -80), + addButton.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 80), + addButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -300), + addButton.widthAnchor.constraint(equalToConstant: 400), + addButton.heightAnchor.constraint(equalToConstant: 60), + ]) + + + view.addSubview(datePicker) + NSLayoutConstraint.activate([ + datePicker.centerXAnchor.constraint(equalTo: view.centerXAnchor), + datePicker.topAnchor.constraint(equalTo: view.topAnchor, constant: 380), + + ]) + } + + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + + dismiss(animated: true, completion: nil) + return true + } + + + +} + diff --git a/Lab/Lab/Order/OrderVC.swift b/Lab/Lab/Order/OrderVC.swift new file mode 100644 index 0000000..6a87331 --- /dev/null +++ b/Lab/Lab/Order/OrderVC.swift @@ -0,0 +1,253 @@ + +// +// VC.swift +// Lab +// +// Created by PC on 19/05/1443 AH. +// +import UIKit +import CoreData + +class OrderVC: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate { + var customer: Customer? + + + var fetchedResultsController: NSFetchedResultsController? + + lazy var tableView: UITableView = { + let tablaView = UITableView() + tablaView.translatesAutoresizingMaskIntoConstraints = false + tablaView.delegate = self + tablaView.dataSource = self + tablaView.register(Cell.self, forCellReuseIdentifier: Cell.identifire) + tablaView.backgroundColor = .white + return tablaView + }() + override func viewDidLoad() { + super.viewDidLoad() + view.addSubview(tableView) + + NSLayoutConstraint.activate([ + tableView.topAnchor.constraint(equalTo: view.topAnchor), + tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor), + tableView.rightAnchor.constraint(equalTo: view.rightAnchor), + tableView.leftAnchor.constraint(equalTo: view.leftAnchor), + ]) + navigationItem.rightBarButtonItem = UIBarButtonItem( + title: "Add", + style: .done, + target: self, + action: #selector(add) + ) + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + setupFetchedResultsController() + } + + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + fetchedResultsController = nil + } + + func setupFetchedResultsController() { + let fetchRequest: NSFetchRequest = Order.fetchRequest() + fetchRequest.sortDescriptors = [ + NSSortDescriptor(key: "status", ascending: false), +// NSSortDescriptor(key: "lastName", ascending: false), + ] + + fetchedResultsController = NSFetchedResultsController( + fetchRequest: fetchRequest, + managedObjectContext: DataService.shared.viewContext, + sectionNameKeyPath: nil, + cacheName: nil + ) + fetchedResultsController?.delegate = self + + do { + try fetchedResultsController?.performFetch() + tableView.reloadData() + } catch { + fatalError("The fetch could not be performd: \(error.localizedDescription)") + } + } + + + @objc func add() { + let newVC = NewOrder() + present(newVC, animated: true, completion: nil) + } + + func controllerDidChangeContent(_ controller: NSFetchedResultsController) { + + tableView.reloadData() + } +} + +extension OrderVC { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + guard let orders = fetchedResultsController?.fetchedObjects else { return 0 } + + return orders.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: Cell.identifire, for: indexPath) as! Cell +// let cell = UITableViewCell.init(style: .subtitle, reuseIdentifier: "123") + + let order = fetchedResultsController?.fetchedObjects?[indexPath.row] + + cell.label2.text = "Status: \(order?.status ?? "")" + cell.label3.text = "Total Price:\(order!.totalPrice)" + cell.label4.text = "Order Date:\(order!.orderDate ?? Date())" + cell.label6.text = "shipping: \(order!.shippingPriority)" + + + return cell + } + + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + if indexPath.row == selectedIndex { + return 370 + }else { + return 225 + } + } + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + guard let order = fetchedResultsController?.fetchedObjects?[indexPath.row] else { + return + } + let newVC = LifeTime() + newVC.lifetime = order + let navController = UINavigationController(rootViewController: newVC) + present(navController, animated: true, completion: nil) + } + + + func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { + return UISwipeActionsConfiguration( + actions: [ + UIContextualAction( + style: .destructive, + title: "Delete", + handler: { _, _, _ in + guard let order = self.fetchedResultsController?.fetchedObjects?[indexPath.row] else { + return + } + DataService.shared.viewContext.delete(order) + DataService.shared.saveContext() + } + ) + ] + ) + } +} + + +class Cell: UITableViewCell { + + static let identifire = "Cell" + + public let label2: UILabel = { + let label = UILabel() + label.font = UIFont.systemFont(ofSize: 20, weight: .regular) + label.textColor = .black + label.textAlignment = .left + label.font = UIFont(name: "Avenir-Light", size: 20) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + public let label3: UILabel = { + let label = UILabel() + label.font = UIFont.systemFont(ofSize: 18, weight: .regular) + label.textColor = .black + label.textAlignment = .left + label.font = UIFont(name: "Avenir-Light", size: 18) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + public let label4: UILabel = { + let label = UILabel() + label.font = UIFont.systemFont(ofSize: 18, weight: .regular) + label.textColor = .black + label.font = UIFont(name: "Avenir-Light", size: 18) + label.translatesAutoresizingMaskIntoConstraints = false + label.textAlignment = .left + return label + }() + public let label5: UILabel = { + let label = UILabel() + label.font = UIFont.systemFont(ofSize: 18, weight: .regular) + label.textColor = .black + label.textAlignment = .left + label.font = UIFont(name: "Avenir-Light", size: 18) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + public let label6: UILabel = { + let label = UILabel() +// label.text = "a" + label.textAlignment = .left + label.font = UIFont.systemFont(ofSize: 18, weight: .regular) + label.textColor = .black + label.font = UIFont(name: "Avenir-Light", size: 18) + label.translatesAutoresizingMaskIntoConstraints = false + return label + + }() + + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + contentView.clipsToBounds = true + contentView.backgroundColor = #colorLiteral(red: 1, green: 0.9926941103, blue: 0.9993625388, alpha: 1) + contentView.layer.cornerRadius = 13 + + + + self.addSubview(label2) + self.addSubview(label3) + self.addSubview(label4) + self.addSubview(label6) + + NSLayoutConstraint.activate([ + label2.topAnchor.constraint(equalTo: self.topAnchor, constant: 5), + label2.rightAnchor.constraint(equalTo: self.rightAnchor ), + label2.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 9), + + label3.topAnchor.constraint(equalTo: label2.bottomAnchor, constant: 10), + label3.rightAnchor.constraint(equalTo: self.rightAnchor), + label3.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 9), + + label4.topAnchor.constraint(equalTo: label3.bottomAnchor, constant: 10), + label4.rightAnchor.constraint(equalTo: self.rightAnchor), + label4.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 9), + + label6.topAnchor.constraint(equalTo: label4.bottomAnchor, constant: 10), + label6.rightAnchor.constraint(equalTo: self.rightAnchor), + label6.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 9), + ]) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func layoutSubviews() { + super.layoutSubviews() + + contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)) + + + + + + + } + +} diff --git a/Lab/Lab/Part/NewPart.swift b/Lab/Lab/Part/NewPart.swift new file mode 100644 index 0000000..3192952 --- /dev/null +++ b/Lab/Lab/Part/NewPart.swift @@ -0,0 +1,247 @@ +// +// NewPart.swift +// Lab +// +// Created by PC on 20/05/1443 AH. +// + + +import UIKit + + +class NewPart: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate , UINavigationControllerDelegate { + + + + + + lazy var TF1: UITextField = { + let tf = UITextField() + tf.translatesAutoresizingMaskIntoConstraints = false + tf.placeholder = NSLocalizedString("", comment:" ") + tf.backgroundColor = .white + tf.textAlignment = .right + tf.delegate = self + tf.layer.cornerRadius = 20 + return tf + }() + + lazy var TF2: UITextField = { + let tf = UITextField() + tf.translatesAutoresizingMaskIntoConstraints = false + tf.placeholder = NSLocalizedString("", comment:" ") + tf.backgroundColor = .white + tf.textAlignment = .right + tf.delegate = self + tf.layer.cornerRadius = 20 + return tf + }() + lazy var TF3: UITextField = { + let tf = UITextField() + tf.translatesAutoresizingMaskIntoConstraints = false + tf.placeholder = NSLocalizedString("", comment:" ") + tf.backgroundColor = .white + tf.textAlignment = .right + tf.delegate = self + tf.layer.cornerRadius = 20 + return tf + }() + lazy var img: UIImageView = { + let image = UIImageView() + image.translatesAutoresizingMaskIntoConstraints = false + // image.backgroundColor = .yellow + image.image = UIImage(systemName: "person") + + image.isUserInteractionEnabled = true + return image + }() + lazy var imagePicker : UIImagePickerController = { + let imagePicker = UIImagePickerController() + imagePicker.delegate = self + imagePicker.sourceType = .photoLibrary + imagePicker.allowsEditing = true + return imagePicker + }() + lazy var addButton: UIButton = { + let b = UIButton() + b.addTarget(self, action: #selector(add), for: .touchUpInside) + b.translatesAutoresizingMaskIntoConstraints = false + b.setTitle(NSLocalizedString("add", comment:""), for: .normal) + b.titleLabel?.font = UIFont(name: "Avenir-Light", size: 27.0) + b.layer.cornerRadius = 25 + b.backgroundColor = UIColor(red: (87/255), green: (107/255), blue: (96/255), alpha: 1) + return b + }() + + public let LabelN: UILabel = { + let label = UILabel() + label.font = UIFont(name: "Avenir-Light", size: 20) + label.textColor = UIColor(named: "Color2") + label.text = NSLocalizedString("Name:", comment:" ") + label.textAlignment = .left + + return label + }() + public let LabelID: UILabel = { + let label = UILabel() + label.font = UIFont(name: "Avenir-Light", size: 20) + label.textColor = UIColor(named: "Color2") + label.text = NSLocalizedString(" Retail Price: ", comment:"") + label.textAlignment = .left + return label + }() + public let LabelI: UILabel = { + let label = UILabel() + label.font = UIFont(name: "Avenir-Light", size: 20) + label.textColor = UIColor(named: "Color2") + label.text = NSLocalizedString(" Size: ", comment:"") + label.textAlignment = .left + return label + }() + + + + + + @objc func add() { + + + let s = Part( + context: DataService.shared.viewContext + ) + s.name = TF1.text ?? "" + s.retailPrice = Double(TF2.text ?? "")! + s.size = Double(TF3.text ?? "")! + s.image = img.image?.pngData() + + DataService.shared.saveContext() + } + + + + + override func viewDidLoad() { + super.viewDidLoad() + view.backgroundColor = .gray + let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageTapped)) + img.addGestureRecognizer(tapRecognizer) + + view.addSubview(LabelN) + view.addSubview(LabelID) + view.addSubview(LabelI) + view.addSubview(addButton) + view.addSubview(TF1) + + + + LabelN.frame = CGRect(x: 10, + y: 16, + width: 110, + height:130) + + LabelID.frame = CGRect(x: 10, + y: 115, + width: 140, + height:130) + LabelI.frame = CGRect(x: 10, + y: 218, + width: 140, + height:130) + NSLayoutConstraint.activate([ + TF1.centerXAnchor.constraint(equalTo: view.centerXAnchor), + TF1.topAnchor.constraint(equalTo: view.topAnchor, constant: 110), + TF1.heightAnchor.constraint(equalToConstant: 48), + TF1.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -48) + ]) + + view.addSubview(TF2) + NSLayoutConstraint.activate([ + TF2.topAnchor.constraint(equalTo: view.topAnchor, constant: 200), + TF2.centerXAnchor.constraint(equalTo: view.centerXAnchor), + TF2.heightAnchor.constraint(equalToConstant: 48), + TF2.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -48) + ]) + view.addSubview(TF3) + NSLayoutConstraint.activate([ + TF3.topAnchor.constraint(equalTo: view.topAnchor, constant: 300), + TF3.centerXAnchor.constraint(equalTo: view.centerXAnchor), + TF3.heightAnchor.constraint(equalToConstant: 48), + TF3.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -48) + ]) + NSLayoutConstraint.activate([ + addButton.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -80), + addButton.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 80), + addButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -300), + addButton.widthAnchor.constraint(equalToConstant: 400), + addButton.heightAnchor.constraint(equalToConstant: 60), + ]) + + view.addSubview(img) + NSLayoutConstraint.activate([ + img.topAnchor.constraint(equalTo: view.topAnchor, constant: 370), + img.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -150), + img.heightAnchor.constraint(equalToConstant: 100), + img.widthAnchor.constraint(equalTo: img.heightAnchor,multiplier: 200/200)]) + + } + + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + + dismiss(animated: true, completion: nil) + return true + } + + @objc func imageTapped() { + print("Image tapped") + presentPhotoInputActionsheet() + // present(imagePicker, animated: true) + } + func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { + let image = info[.editedImage] ?? info [.originalImage] as? UIImage + img.image = image as? UIImage + dismiss(animated: true) + } + + @objc private func presentPhotoInputActionsheet() { + let actionSheet = UIAlertController(title: "تغيير الصوره", + message: " تغيير صوره الملف الشخصي من", + preferredStyle: .actionSheet) + actionSheet.addAction(UIAlertAction(title: "الكاميرا📷 ", style: .default, handler: { [weak self] _ in + + let picker = UIImagePickerController() + picker.sourceType = .camera + picker.delegate = self + picker.allowsEditing = true + self?.present(picker, animated: true) + + })) + actionSheet.addAction(UIAlertAction(title: "مكتبه الصور🌄", style: .default, handler: { [weak self] _ in + + let picker = UIImagePickerController() + picker.sourceType = .photoLibrary + picker.delegate = self + picker.allowsEditing = true + self?.present(picker, animated: true) + + })) + actionSheet.addAction(UIAlertAction(title: "إلغاء", style: .cancel, handler: nil)) + + present(actionSheet, animated: true) + // setupImagePicker() + } + + func setUpImage() { + + img.isUserInteractionEnabled = true + let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(presentPhotoInputActionsheet)) + + img.addGestureRecognizer(tapRecognizer) + + view.addSubview(img) + } + + + + +} + diff --git a/Lab/Lab/Part/PartVC.swift b/Lab/Lab/Part/PartVC.swift new file mode 100644 index 0000000..9a95b45 --- /dev/null +++ b/Lab/Lab/Part/PartVC.swift @@ -0,0 +1,265 @@ +// +// PartVC.swift +// Lab +// +// Created by PC on 19/05/1443 AH. +// + + +import UIKit +import CoreData + +class PartVC: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate { + var supplier: Supplier? + + + var fetchedResultsController: NSFetchedResultsController? + + lazy var tableView: UITableView = { + let tablaView = UITableView() + tablaView.translatesAutoresizingMaskIntoConstraints = false + tablaView.delegate = self + tablaView.dataSource = self + tablaView.register(Cell3.self, forCellReuseIdentifier: Cell3.identifire) + tablaView.backgroundColor = .white + return tablaView + }() + override func viewDidLoad() { + super.viewDidLoad() + view.addSubview(tableView) + + NSLayoutConstraint.activate([ + tableView.topAnchor.constraint(equalTo: view.topAnchor), + tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor), + tableView.rightAnchor.constraint(equalTo: view.rightAnchor), + tableView.leftAnchor.constraint(equalTo: view.leftAnchor), + ]) + navigationItem.rightBarButtonItem = UIBarButtonItem( + title: "Add", + style: .done, + target: self, + action: #selector(add) + ) + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + setupFetchedResultsController() + } + + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + fetchedResultsController = nil + } + + func setupFetchedResultsController() { + let fetchRequest: NSFetchRequest = Part.fetchRequest() + fetchRequest.sortDescriptors = [ + NSSortDescriptor(key: "name", ascending: false), +// NSSortDescriptor(key: "lastName", ascending: false), + ] + + fetchedResultsController = NSFetchedResultsController( + fetchRequest: fetchRequest, + managedObjectContext: DataService.shared.viewContext, + sectionNameKeyPath: nil, + cacheName: nil + ) + fetchedResultsController?.delegate = self + + do { + try fetchedResultsController?.performFetch() + tableView.reloadData() + } catch { + fatalError("The fetch could not be performd: \(error.localizedDescription)") + } + } + + + @objc func add() { + let newVC = NewPart() + present(newVC, animated: true, completion: nil) + } + + func controllerDidChangeContent(_ controller: NSFetchedResultsController) { + + tableView.reloadData() + } +} + +extension PartVC { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + guard let orders = fetchedResultsController?.fetchedObjects else { return 0 } + + return orders.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: Cell.identifire, for: indexPath) as! Cell3 +// let cell = UITableViewCell.init(style: .subtitle, reuseIdentifier: "123") + + let order = fetchedResultsController?.fetchedObjects?[indexPath.row] + print(order) + cell.label2.text = "Name: \(order?.name ?? "")" + cell.label3.text = "Retail Price:\(order!.retailPrice)" + cell.label6.text = "Size: \(order!.size)" + cell.img.image = UIImage(data: order!.image!) + + + return cell + } + + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + if indexPath.row == selectedIndex { + return 370 + }else { + return 225 + } + } + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let fetchSupplier = fetchedResultsController?.fetchedObjects?[indexPath.row] + + print(fetchSupplier) + } + + func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { + return UISwipeActionsConfiguration( + actions: [ + UIContextualAction( + style: .destructive, + title: "Delete", + handler: { _, _, _ in + guard let order = self.fetchedResultsController?.fetchedObjects?[indexPath.row] else { + return + } + DataService.shared.viewContext.delete(order) + DataService.shared.saveContext() + } + ) + ] + ) + } +} + + +class Cell3: UITableViewCell { + + static let identifire = "Cell" + + public let label2: UILabel = { + let label = UILabel() + label.font = UIFont.systemFont(ofSize: 20, weight: .regular) + label.textColor = .black + label.textAlignment = .left + label.font = UIFont(name: "Avenir-Light", size: 20) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + public let label3: UILabel = { + let label = UILabel() + label.font = UIFont.systemFont(ofSize: 18, weight: .regular) + label.textColor = .black + label.textAlignment = .left + label.font = UIFont(name: "Avenir-Light", size: 18) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + public let label4: UILabel = { + let label = UILabel() + label.font = UIFont.systemFont(ofSize: 18, weight: .regular) + label.textColor = .black + label.font = UIFont(name: "Avenir-Light", size: 18) + label.translatesAutoresizingMaskIntoConstraints = false + label.textAlignment = .left + return label + }() + public let label5: UILabel = { + let label = UILabel() + label.font = UIFont.systemFont(ofSize: 18, weight: .regular) + label.textColor = .black + label.textAlignment = .left + label.font = UIFont(name: "Avenir-Light", size: 18) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + public let label6: UILabel = { + let label = UILabel() +// label.text = "a" + label.textAlignment = .left + label.font = UIFont.systemFont(ofSize: 18, weight: .regular) + label.textColor = .black + label.font = UIFont(name: "Avenir-Light", size: 18) + label.translatesAutoresizingMaskIntoConstraints = false + return label + + }() + lazy var img: UIImageView = { + let image = UIImageView() + image.translatesAutoresizingMaskIntoConstraints = false + // image.backgroundColor = .yellow + image.image = UIImage(systemName: "person") + + image.isUserInteractionEnabled = true + return image + }() + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + contentView.clipsToBounds = true + contentView.backgroundColor = #colorLiteral(red: 1, green: 0.9926941103, blue: 0.9993625388, alpha: 1) + contentView.layer.cornerRadius = 13 + + + + self.addSubview(label2) + self.addSubview(label3) + self.addSubview(label4) + self.addSubview(label6) + self.addSubview(img) + + NSLayoutConstraint.activate([ + label2.topAnchor.constraint(equalTo: self.topAnchor, constant: 5), + label2.rightAnchor.constraint(equalTo: self.rightAnchor ), + label2.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 9), + + label3.topAnchor.constraint(equalTo: label2.bottomAnchor, constant: 10), + label3.rightAnchor.constraint(equalTo: self.rightAnchor), + label3.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 9), + + label4.topAnchor.constraint(equalTo: label3.bottomAnchor, constant: 10), + label4.rightAnchor.constraint(equalTo: self.rightAnchor), + label4.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 9), + + label6.topAnchor.constraint(equalTo: label4.bottomAnchor, constant: 10), + label6.rightAnchor.constraint(equalTo: self.rightAnchor), + label6.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 9), + img.topAnchor.constraint(equalTo: label6.bottomAnchor, constant: 10), +// img.rightAnchor.constraint(equalTo: self.rightAnchor, constant: -150), + img.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 30), + img.heightAnchor.constraint(equalToConstant: 100), + img.widthAnchor.constraint(equalToConstant: 100) + ]) + + + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func layoutSubviews() { + super.layoutSubviews() + + contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)) + + + + + + + } + +} diff --git a/Lab/Lab/SceneDelegate.swift b/Lab/Lab/SceneDelegate.swift new file mode 100644 index 0000000..3e90e01 --- /dev/null +++ b/Lab/Lab/SceneDelegate.swift @@ -0,0 +1,67 @@ +// +// SceneDelegate.swift +// Lab +// +// Created by PC on 15/05/1443 AH. +// + +import UIKit + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + + var window: UIWindow? + + + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + /// 1. Capture the scene + guard let windowScene = (scene as? UIWindowScene) else { return } + + /// 2. Create a new UIWindow using the windowScene constructor which takes in a window scene. + let window = UIWindow(windowScene: windowScene) + + /// 3. Create a view hierarchy programmatically + let viewController = tabViewController() + let navigation = UINavigationController(rootViewController: viewController) + + /// 4. Set the root view controller of the window with your view controller + window.rootViewController = navigation + + /// 5. Set the window and call makeKeyAndVisible() + self.window = window + window.makeKeyAndVisible() + } + + func sceneDidDisconnect(_ scene: UIScene) { + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when its session is discarded. + // Release any resources associated with this scene that can be re-created the next time the scene connects. + // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). + } + + func sceneDidBecomeActive(_ scene: UIScene) { + // Called when the scene has moved from an inactive state to an active state. + // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. + } + + func sceneWillResignActive(_ scene: UIScene) { + // Called when the scene will move from an active state to an inactive state. + // This may occur due to temporary interruptions (ex. an incoming phone call). + } + + func sceneWillEnterForeground(_ scene: UIScene) { + // Called as the scene transitions from the background to the foreground. + // Use this method to undo the changes made on entering the background. + } + + func sceneDidEnterBackground(_ scene: UIScene) { + // Called as the scene transitions from the foreground to the background. + // Use this method to save data, release shared resources, and store enough scene-specific state information + // to restore the scene back to its current state. + + // Save changes in the application's managed object context when the application transitions to the background. + DataService.shared.saveContext() + } + + +} + diff --git a/Lab/Lab/Serviec/DataServiec.swift b/Lab/Lab/Serviec/DataServiec.swift new file mode 100644 index 0000000..f15e876 --- /dev/null +++ b/Lab/Lab/Serviec/DataServiec.swift @@ -0,0 +1,80 @@ +// +// DataServiec.swift +// Lab +// +// Created by PC on 19/05/1443 AH. +// +// +//import Foundation +//import CoreData +// +// +//class DataService { +// +// static let shared = DataService() +// +// private let persistentContainer = NSPersistentContainer(name: "Lab") +// +// var viewContext: NSManagedObjectContext { +// return persistentContainer.viewContext +// } +// +// func load() { +// persistentContainer.loadPersistentStores(completionHandler: { (storeDescription, error) in +// if let error = error as NSError? { +// fatalError("Unresolved error \(error), \(error.userInfo)") +// } +// }) +// } +// +// func saveContext () { +// let context = persistentContainer.viewContext +// if context.hasChanges { +// do { +// try context.save() +// } catch { +// // Replace this implementation with code to handle the error appropriately. +// // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. +// let nserror = error as NSError +// fatalError("Unresolved error \(nserror), \(nserror.userInfo)") +// } +// } +// } +//} + +import Foundation +import CoreData + + +class DataService { + + static let shared = DataService() + + private let persistentContainer = NSPersistentContainer(name: "Lab") + + var viewContext: NSManagedObjectContext { + return persistentContainer.viewContext + } + + func load() { + persistentContainer.loadPersistentStores(completionHandler: { (storeDescription, error) in + if let error = error as NSError? { + fatalError("Unresolved error \(error), \(error.userInfo)") + } + }) + } + + func saveContext () { + let context = persistentContainer.viewContext + if context.hasChanges { + do { + try context.save() + } catch { + // Replace this implementation with code to handle the error appropriately. + // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. + let nserror = error as NSError + fatalError("Unresolved error \(nserror), \(nserror.userInfo)") + } + } + } +} diff --git a/Lab/Lab/Supplier/NewSupplier.swift b/Lab/Lab/Supplier/NewSupplier.swift new file mode 100644 index 0000000..5eca222 --- /dev/null +++ b/Lab/Lab/Supplier/NewSupplier.swift @@ -0,0 +1,81 @@ +// +// NewSupplier.swift +// Lab +// +// Created by PC on 19/05/1443 AH. +// + +import UIKit + +class NewSupplier: UIViewController, UITextFieldDelegate { + + + var data: Supplier? + + lazy var contentTF: UITextField = { + let tf = UITextField() + tf.translatesAutoresizingMaskIntoConstraints = false + tf.placeholder = "Add name .." + tf.delegate = self + tf.layer.borderWidth = 1 + tf.layer.borderColor = UIColor.black.cgColor + tf.layer.cornerRadius = 25 + + return tf + }() + + lazy var contentTF2: UITextField = { + let tf = UITextField() + tf.translatesAutoresizingMaskIntoConstraints = false + tf.placeholder = "Add website" + tf.delegate = self + tf.layer.borderWidth = 1 + tf.layer.borderColor = UIColor.black.cgColor + tf.layer.cornerRadius = 25 + return tf + }() + + + override func viewDidLoad() { + super.viewDidLoad() + title = NSLocalizedString("Add new supplier", comment:"") + view.backgroundColor = .white + + view.backgroundColor = .white + view.addSubview(contentTF) + view.addSubview(contentTF2) + + NSLayoutConstraint.activate([ + contentTF.topAnchor.constraint(equalTo: view.topAnchor, constant: 100), + contentTF.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 16), + contentTF.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -16), + contentTF.heightAnchor.constraint(equalToConstant: 100), + + + + contentTF2.topAnchor.constraint(equalTo: view.topAnchor, constant: 180), + contentTF2.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 16), + contentTF2.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -16), + contentTF2.heightAnchor.constraint(equalToConstant: 100), + + ]) + contentTF.text = data?.name + contentTF2.text = data?.website?.absoluteString + +} + + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + contentTF.resignFirstResponder() + contentTF2.resignFirstResponder() + + let supplier = Supplier( + context: DataService.shared.viewContext + ) + supplier.name = contentTF.text ?? "" + supplier.website = URL(string: contentTF2.text ?? "") + + DataService.shared.saveContext() + + return true + } +} diff --git a/Lab/Lab/Supplier/SupplierVC.swift b/Lab/Lab/Supplier/SupplierVC.swift new file mode 100644 index 0000000..344c268 --- /dev/null +++ b/Lab/Lab/Supplier/SupplierVC.swift @@ -0,0 +1,179 @@ +// +// SupplierVC.swift +// Lab +// +// Created by PC on 19/05/1443 AH. +// +import UIKit +import CoreData + + +class SupplierVc : UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate { + + var fetchedResultsController: NSFetchedResultsController? + + lazy var tableView1: UITableView = { + let tablaView = UITableView() + tablaView.translatesAutoresizingMaskIntoConstraints = false + tablaView.delegate = self + tablaView.dataSource = self + tablaView.register(SupplierCell.self, forCellReuseIdentifier: SupplierCell.identifire) + tablaView.backgroundColor = .white + return tablaView + }() + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return fetchedResultsController?.fetchedObjects?.count ?? 0 + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "SupplierCell", for: indexPath) as! SupplierCell + + let data = fetchedResultsController?.fetchedObjects?[indexPath.row] + cell.nameLable.text = "Name: \(data!.name!)" + cell.websiteLable.text = "Website: \((data!.website?.absoluteString)!)" + + return cell + } + + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + guard let fetchSupplier = fetchedResultsController?.fetchedObjects?[indexPath.row] else { + return + } + let partVC = PartVC() + partVC.supplier = fetchSupplier + let navController = UINavigationController(rootViewController: partVC) + present(navController, animated: true, completion: nil) + } + + func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { + return UISwipeActionsConfiguration( + actions: [ + UIContextualAction( + style: .destructive, + title: "Delete", + handler: { _, _, _ in + guard let supplier = self.fetchedResultsController?.fetchedObjects?[indexPath.row] else { + return + } + DataService.shared.viewContext.delete(supplier) + DataService.shared.saveContext() + } + ) + ] + ) + } + + override func viewDidLoad() { + super.viewDidLoad() + + view.addSubview(tableView1) + NSLayoutConstraint.activate([ + tableView1.topAnchor.constraint(equalTo: view.topAnchor), + tableView1.bottomAnchor.constraint(equalTo: view.bottomAnchor), + tableView1.rightAnchor.constraint(equalTo: view.rightAnchor), + tableView1.leftAnchor.constraint(equalTo: view.leftAnchor), + ]) + + navigationItem.rightBarButtonItem = UIBarButtonItem( + title: "Add", + style: .done, + target: self, + action: #selector(addSupplier) + ) + } + + func controllerDidChangeContent(_ controller: NSFetchedResultsController) { + tableView1.reloadData() + } + + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + return 120 + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + setupFetchedResultsController() + } + + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + fetchedResultsController = nil + } + + func setupFetchedResultsController() { + let fetchRequest: NSFetchRequest = Supplier.fetchRequest() + fetchRequest.sortDescriptors = [ + NSSortDescriptor(key: "name", ascending: false), + ] + + fetchedResultsController = NSFetchedResultsController( + fetchRequest: fetchRequest, + managedObjectContext: DataService.shared.viewContext, + sectionNameKeyPath: nil, + cacheName: nil + ) + fetchedResultsController?.delegate = self + + do { + try fetchedResultsController?.performFetch() + tableView1.reloadData() + } catch { + fatalError("The fetch could not be performd: \(error.localizedDescription)") + } + } + + @objc func addSupplier() { + let vc = NewSupplier() + self.present(vc, animated: true, completion: nil) + } + +} + + +class SupplierCell: UITableViewCell { + static let identifire = "SupplierCell" + + let nameLable: UILabel = { + let label = UILabel() + label.textColor = .black + label.text = "" + label.font = label.font.withSize(19) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + let websiteLable: UILabel = { + let label = UILabel() + label.textColor = .black + label.text = "" + label.font = label.font.withSize(19) + label.translatesAutoresizingMaskIntoConstraints = false + return label + }() + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: .subtitle, reuseIdentifier: reuseIdentifier) + + contentView.backgroundColor = .white + + self.addSubview(nameLable) + self.addSubview(websiteLable) + + NSLayoutConstraint.activate([ + nameLable.topAnchor.constraint(equalTo: self.topAnchor), + nameLable.rightAnchor.constraint(equalTo: self.rightAnchor, constant: 20), + nameLable.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 10), + + websiteLable.topAnchor.constraint(equalTo: nameLable.bottomAnchor, constant: 27), + websiteLable.rightAnchor.constraint(equalTo: self.rightAnchor, constant: 10), + websiteLable.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 10), + ]) + } + + + required init?(coder: NSCoder) { + super.init(coder: coder) + } + +} diff --git a/Lab/Lab/TabVC.swift b/Lab/Lab/TabVC.swift new file mode 100644 index 0000000..998d5cf --- /dev/null +++ b/Lab/Lab/TabVC.swift @@ -0,0 +1,47 @@ +// +// TabVC.swift +// Lab +// +// Created by PC on 19/05/1443 AH. +// +import UIKit + + class tabViewController: UITabBarController { + + + fileprivate func createNavController(for rootViewController: UIViewController, + title: String, + image: UIImage) -> UIViewController { + + let navController = UINavigationController(rootViewController: rootViewController) + + navController.tabBarItem.title = title + navController.tabBarItem.image = image + navController.navigationBar.prefersLargeTitles = true + rootViewController.navigationItem.title = title + navController.navigationBar.backgroundColor = .quaternarySystemFill + + return navController + } + + func setupVCs() { + + viewControllers = [ + + + createNavController(for:CustomersVC(), title: NSLocalizedString("Customer", comment: ""), image: UIImage(systemName: "person")!), + + createNavController(for:SupplierVc(), title: NSLocalizedString("Supplier", comment: ""), image: UIImage(systemName: "person")!), + ] + } + + override func viewDidLoad() { + + super.viewDidLoad() + setupVCs() + + view.backgroundColor = UIColor.cyan + + } + + }