Page d'Accueil

Répertoires

 

Introduction

Un répertoire est une section d'un médium utilisée pour délimiter un groupe de fichiers. parce que c'est un secteur « physique », il peut effectuer des opérations non disponibles sur des fichiers. En fait, il y a fondamentalement beaucoup de différences entre les deux :

  • Un fichier est utilisé pour contenir des données. Un répertoire ne contient pas les données
  • Un répertoire peut contenir un ou plusieurs fichiers et pas vice-versa
  • Un répertoire peut contenir d'autres répertoires
  • Un fichier peut être déplacé d'un répertoire à l'autre. Cette opération inverse n'est pas possible puisqu'un fichier ne peut pas contenir un répertoire

Les similitudes entre les deux types sont :

  • Un répertoire ou un fichier peut être créé. Une des restrictions est que deux fichiers ne peuvent pas avoir le même nom à l'intérieur d'un même répertoire. Deux répertoires ne peuvent pas avoir le même nom à l'intérieur d'un même répertoire parent.
  • Un répertoire ou un fichier peut être renommé. Si un répertoire est renommé, le « chemin » de ses fichiers change
  • Un répertoire ou un fichier peut être supprimé. Si un répertoire est supprimé, ses fichiers seront également supprimés 
  • Un répertoire ou un fichier peut être déplacé. Si un répertoire est déplace, il « amène » tous ses fichiers au nouvel emplacement
  • Un répertoire ou un fichier peut être copié. Un fichier peut être copié d'un répertoire à l'autre. Si un répertoire est copié à un nouvel emplacement, tous ses fichiers seront également copiés au nouvel emplacement

Étude pratiqueÉtude pratique : Présentation des répertoires

  1. Commencez Microsoft Visual C# et créez une application de console appelée GeorgetownCleaningServices5
  2. Pour créer une nouvelle classe, dans Explorateur de solution, droit-cliquez GeorgetownCleaningServices5 - > Ajouter - > classe…
  3. Placez le nom client et cliquez OK
  4. Changez le fichier comme suit :
     
    using System;
    
    namespace GeorgetownCleaningServices6
    {
        public class Customer
        {
            public string Name;
            public string PhoneNumber;
        }
    }
  5. Pour créer une nouvelle classe, sur le menu principal, cliquez projet - > Ajouter la classe…
  6. Placez le nom CleaningOrderDetails et appuyez Enter
  7. Changez le fichier comme suit :
     
    using System;
    
    namespace GeorgetownCleaningServices6
    {
        public sealed class CleaningOrderDetails
        {
            // The date the cleaning items were deposited
            public DateTime OrderDate;
            public DateTime OrderTime;
            // Numbers to represent cleaning items
            public uint NumberOfShirts;
            public uint NumberOfPants;
            public uint NumberOtherItems;
    
            // Price of items
            public decimal PriceOneShirt = 0.95M;
            public decimal PriceAPairOfPants = 2.95M;
            public decimal PriceOtherItems = 4.55M;
            public decimal TaxRate = 0.0575M;  // 5.75%
    
            // Each of these sub totals will be used for cleaning items
            public decimal SubTotalShirts;
            public decimal SubTotalPants;
            public decimal SubTotalOtherItems;
    
            // Values used to process an order
            public decimal TotalOrder;
            public decimal TaxAmount;
            public decimal SalesTotal;
        }
    }
  8. Pour Sauvegardez le projet, sur la barre d'outils standard, cliquez le bouton Enregistrer toutÉconomiser tous
  9. Acceptez tous le défauts et cliquez Enregistrer

Création d'un répertoire

Avant d'utiliser un répertoire, vous devez d'abord l'avoir. Vous pouvez utiliser un répertoire existant si le logiciel d'exploitation ou quelqu'un d'autre en avait déjà créé un. Vous pouvez également créer un nouveau répetoire. les répertoires sont créés et contrôlés par diverses classes mais la classe fondamentale  Directory. Un répertoire est une classe statique, ce qui signifie que toutes ses méthodes sont statiques, ce qui signifie que vous n'aurez jamais besoin de déclarer une instance d'une classe Directory afin de l'utiliser.

En plus de la classe Directory, des opérations additionnelles sur les dossiers et sous dossiers  peuvent être exécutées en utilisant la classe DirectoryInfo.

Pour créer un répertoire, vous pouvez appeler la méthode CreateDirectory () de la classe Directory. Cette méthode est disponible dans deux versions. Une des versions utilise la syntaxe suivante :

public static DirectoryInfo CreateDirectry(string path);

Cette méthode prend comme argument le chemin (complet) du répertoire désiré. Voici un exemple:

E:\Programs\Business Orders\Customer Information

Quand cette méthode est appelée :

  1. Il cherche d'abord l'unité de disque parent, dans ce cas E.
    Si l'unité de disque n'existe pas, parce que cette méthode ne peut pas créer une unité de disque, le compilateur rejetterait une exception DirectoryNotFoundException
  2. Si l'unité de disque (dans ce cas-ci E) existe, le compilateur se déplace à la première partie du répertoire du chemin ; dans ce cas-ci ce serait le dossier du programmes dans le lunité de disque E.
    Si le dossier n'existe pas, le compilateur le créerait. Si ce premier répertoire n'existe pas, ceci veut dire que d'autres répertoires sous le premier, le cas échéant, n'existent pas. Ainsi, le compilateur les ou le créerait
  3. Si le premier répertoire existe et s'il n'y a aucun autre répetoire sous ce répetoire, le compilateur arrêterait et ne ferait pas n'importe quoi plus loin.
  4. Si le répetoire existe et qu'il y a un sous-répertoire indiqué sous lui, le compilateur vérifierait l'existence de ce répetoire.
    Si le sous-répertoire existe, le compilateur ne ferait rien plus loin et s'arrêterait.
    Si le sous-répertoire n'existe pas, le compilateur le créerait
  5. Le compilateur répètent l'étape 4 jusqu'à la fin du chemin indiqué

La méthode Directory.CreateDirectory () renvoie un objet DirectoryInfo que vous pouvez utiliser comme vous voulez.

Vérification de l'existence d'un répertoire

Avant d'utiliser ou créer un répetoire, vous pouvez premièrement vérifier s'il existe. C'est parce que, si un répetoire existe déjà dans l'emplacement où vous voulez le créer, vous seriez empêchés d'en créer un avec le même nom. De la même manière, si vous décidez juste d'utiliser directement un répetoire qui n'existe pas, l'opération que vous voulez effectuer peut échouer parce que le répetoire ne serait pas trouvé.

Avant d'utiliser ou créer un répetoire, vérifiez d'abord s'il existe ou pas, vous pouvez appeler la méthode booléenne Directory.Exists (). Sa syntaxe est :

public static bool Exists(string path);

Cette méthode reçoit le chemin (complet) du répetoire. Si le chemin est vérifié, la méthode renvoie vrai. Si le répetoire existe, la méthode renvoie faux.

Pour créer un répetoire, vous pouvez appeler la méthode CreateDirectory () de la classe Directory.

Localisation d'un fichier

Une des opérations les plus courantes à exécuté dans un répertoire consiste à rechercher un fichier. Les logiciels d'exploitation de Microsoft Windows et l'intuition de l'utilisateurs ont différentes manières d'aborder cette question. .NET Framework fournit également ses propres moyens pour effectuer cette opération, par diverses techniques. Vous pouvez commencer par vérifier les sous-répertoires et les fichiers à l'intérieur de du répertoire principal.

Pour rechercher les fichiers dans un répertoire, la classe DirectoryInfo peut vous aider avec sa méthode GetFiles (), qui est disponible dans trois versions.

Étude pratiqueÉtude pratique : utiliser les répertoires et les fichiers

  1. Pour créer une nouvelle classe, dans Affichage de classe, droit-cliquez GeorgetownCleaningOrder6 - > Ajouter - > classe…
  2. Placez le nom CleaningDeposit et appuyez Enter
  3. Changez le fichier comme suit :
     
    using System;
    using System.IO;
    
    namespace GeorgetownCleaningServices6
    {
        public abstract class CustomerOrder
        {
            public abstract void ProcessOrder();
            public abstract void ShowReceipt();
        }
    
        public class CleaningDeposit : CustomerOrder
        {
            private Customer custInfo;
            public CleaningOrderDetails depot;
            private decimal AmountTended;
            private decimal Difference;
    
            public CleaningDeposit()
            {
                this.custInfo = new Customer();
                this.depot = new CleaningOrderDetails();
            }
    
            private Customer IdentifyCustomer()
            {
                string strCustomerName;
                string strTelephoneNumber, strPhoneFormatted;
    
                Console.Write("Enter Customer Phone Number: ");
                strTelephoneNumber = Console.ReadLine();
    
                // Remove the spaces, parentheses, if any, and dashes, if any
                strTelephoneNumber = strTelephoneNumber.Replace(" ", "");
                strTelephoneNumber = strTelephoneNumber.Replace("(", "");
                strTelephoneNumber = strTelephoneNumber.Replace(")", "");
                strTelephoneNumber = strTelephoneNumber.Replace("-", "");
                if (strTelephoneNumber.Length != 10)
                {
                    Console.WriteLine("Invalid telphone number: {0} " +
                                      "characters instead of 10 digits",
                                      strTelephoneNumber.Length);
                    return null;
                }
                strPhoneFormatted = "(" + strTelephoneNumber.Substring(0, 3) +
                                    ") " + strTelephoneNumber.Substring(3, 3) +
                                    "-" + strTelephoneNumber.Substring(6, 4);
    
                string strFilename = strTelephoneNumber + @".gcs";
                string strPath = @"C:\Georgetown Cleaning Services\Customers\" +
                                 @"\" + strFilename;
    
                if (File.Exists(strPath))
                {
                    FileStream stmCustomer =
                        File.Open(strPath, FileMode.Open, FileAccess.Read);
                    BinaryReader bnrCustomer = new BinaryReader(stmCustomer);
    
                    custInfo.Name = bnrCustomer.ReadString();
                    custInfo.PhoneNumber = bnrCustomer.ReadString();
    
                    Console.WriteLine("\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
                    Console.WriteLine("-/- Georgetown Cleaning Services -/-");
                    Console.WriteLine("------------------------------------");
                    Console.WriteLine("Customer Name: {0}", custInfo.Name);
                    Console.WriteLine("Phone Number:  {0}", custInfo.PhoneNumber);
                    Console.WriteLine("------------------------------------\n");
                }
                else // If the customer information was not found in a file
                {
                    Console.WriteLine("It looks like this is the first time you " +
                                      "are trusting  us with your cleaning order");
    Directory.CreateDirectory(@"C:\Georgetown Cleaning Services\Customers");
                    FileStream stmCustomer = File.Create(strPath);
                    BinaryWriter bnwCustomer =
                        new BinaryWriter(stmCustomer);
                    Console.Write("Enter Customer Name: ");
                    strCustomerName = Console.ReadLine();
                    bnwCustomer.Write(strCustomerName);
                    bnwCustomer.Write(strPhoneFormatted);
    
                    custInfo.Name = strCustomerName;
                    custInfo.PhoneNumber = strTelephoneNumber;
                }
    
                return custInfo;
            }
    
            public override void ProcessOrder()
            {
                Console.WriteLine("-/- Georgetown Cleaning Services -/-");
                Customer client = this.IdentifyCustomer();
    
                try
                {
                    Console.Write("Enter the order date(mm/dd/yyyy):  ");
                    this.depot.OrderDate = DateTime.Parse(Console.ReadLine());
                }
                catch (FormatException)
                {
                    Console.WriteLine("The value you entered is not a valid date");
                }
                try
                {
                    Console.Write("Enter the order time(hh:mm AM/PM): ");
                    this.depot.OrderTime = DateTime.Parse(Console.ReadLine());
                }
                catch
                {
                    Console.WriteLine("The value you entered is not a valid time");
                }
    
                // Request the quantity of each category of items
                try
                {
                    Console.Write("Number of Shirts:      ");
                    this.depot.NumberOfShirts =
                        uint.Parse(Console.ReadLine());
                    if (this.depot.NumberOfShirts < uint.MinValue)
                        throw new OverflowException("Negative value not " +
                                                    "allowed for shirts");
                }
                catch (FormatException)
                {
                    Console.WriteLine("The value you typed for the number of " +
                                      "shirts is not a valid number");
                }
                try
                {
                    Console.Write("Number of Pants:       ");
                    this.depot.NumberOfPants =
                        uint.Parse(Console.ReadLine());
                }
                catch (FormatException)
                {
                    Console.WriteLine("The value you typed for the number of " +
                                      "pair or pants is not a valid number");
                }
                try
                {
                    Console.Write("Number of Other Items: ");
                    this.depot.NumberOtherItems = uint.Parse(Console.ReadLine());
                }
                catch (FormatException)
                {
                    Console.WriteLine("The value you typed for the number of " +
                                      "other items is not a valid number");
                }
                // Perform the necessary calculations
                this.depot.SubTotalShirts =
                    this.depot.NumberOfShirts * this.depot.PriceOneShirt;
                this.depot.SubTotalPants =
                    this.depot.NumberOfPants * this.depot.PriceAPairOfPants;
                this.depot.SubTotalOtherItems =
                    this.depot.NumberOtherItems * this.depot.PriceOtherItems;
                // Calculate the "temporary" total of the order
                this.depot.TotalOrder = this.depot.SubTotalShirts +
                                        this.depot.SubTotalPants +
                                        this.depot.SubTotalOtherItems;
    
                // Calculate the tax amount using a constant rate
                this.depot.TaxAmount = this.depot.TotalOrder * this.depot.TaxRate;
                // Add the tax amount to the total order
                this.depot.SalesTotal = this.depot.TotalOrder + this.depot.TaxAmount;
    
                // Communicate the total to the user...
                Console.WriteLine("\nThe Total order is: {0:C}",
    		this.depot.SalesTotal);
                // and request money for the order
                try
                {
                    Console.Write("Amount Tended? ");
                    AmountTended = decimal.Parse(Console.ReadLine());
                }
                catch (FormatException)
                {
                    Console.WriteLine("You were asked to enter an " +
                                      "amount of money but...");
                }
                // Calculate the difference owed to the customer
                // or that the customer still owes to the store
                Difference = AmountTended - this.depot.SalesTotal;
    
                this.ShowReceipt();
                this.Save();
            }
    
            public override void ShowReceipt()
            {
                Console.WriteLine();
                // Display the receipt
                Console.WriteLine("====================================");
                Console.WriteLine("-/- Georgetown Cleaning Services -/-");
                Console.WriteLine("====================================");
                Console.WriteLine("Customer:    {0}", this.custInfo.Name);
                Console.WriteLine("Home Phone:  {0}", this.custInfo.PhoneNumber);
                Console.WriteLine("Order Date:  {0:D}", this.depot.OrderDate);
                Console.WriteLine("Order Time:  {0:t}", this.depot.OrderTime);
                Console.WriteLine("------------------------------------");
                Console.WriteLine("Item Type    Qty Unit/Price Sub-Total");
                Console.WriteLine("------------------------------------");
                Console.WriteLine("Shirts      {0,3}   {1,4}      {2,6}",
                                  this.depot.NumberOfShirts,
                                  this.depot.PriceOneShirt,
                                  this.depot.SubTotalShirts);
                Console.WriteLine("Pants       {0,3}   {1,4}      {2,6}",
                                 this.depot.NumberOfPants,
                                 this.depot.PriceAPairOfPants,
                                 this.depot.SubTotalPants);
                Console.WriteLine("Other Items {0,3}   {1,4}      {2,6}",
                                  this.depot.NumberOtherItems,
                                  this.depot.PriceOtherItems,
                                  this.depot.SubTotalOtherItems);
                Console.WriteLine("------------------------------------");
                Console.WriteLine("Total Order:   {0,6}",
                                  this.depot.TotalOrder.ToString("C"));
                Console.WriteLine("Tax Rate:      {0,6}",
                                  this.depot.TaxRate.ToString("P"));
                Console.WriteLine("Tax Amount:    {0,6}",
                                  this.depot.TaxAmount.ToString("C"));
                Console.WriteLine("Net Price:     {0,6}",
                                  this.depot.SalesTotal.ToString("C"));
                Console.WriteLine("------------------------------------");
                Console.WriteLine("Amount Tended: {0,6}",
                                  AmountTended.ToString("C"));
                Console.WriteLine("Difference:    {0,6}",
                                  Difference.ToString("C"));
                Console.WriteLine("====================================");
            }
    
            public virtual void Save()
            {
                string strPhoneNumber = this.custInfo.PhoneNumber;
    
                // Remove the spaces, parentheses, and dashes
                strPhoneNumber = strPhoneNumber.Replace(" ", "");
                strPhoneNumber = strPhoneNumber.Replace("(", "");
                strPhoneNumber = strPhoneNumber.Replace(")", "");
                strPhoneNumber = strPhoneNumber.Replace("-", "");
    
                string strMonth = depot.OrderDate.Month.ToString();
                if (depot.OrderDate.Month < 10)
                    strMonth = "0" + strMonth;
    
                string strDay = depot.OrderDate.Day.ToString();
                if (depot.OrderDate.Day < 10)
                    strDay = "0" + strDay;
    
                string strYear = depot.OrderDate.Year.ToString();
    
                string strFilename = strMonth + strDay + strYear + @".gcs";
    
                string strPath =
    		 @"C:\Georgetown Cleaning Services\Cleaning Orders\" +
                     @"\" + strPhoneNumber + @"\" + strFilename;
    
    Directory.CreateDirectory(@"C:\Georgetown Cleaning Services\Cleaning Orders\"
                                          + strPhoneNumber);
    
                FileStream stmCleaningOrder = File.Create(strPath);
                BinaryWriter bnwCleaningOrder =
                    new BinaryWriter(stmCleaningOrder);
    
                bnwCleaningOrder.Write(this.custInfo.Name);
                bnwCleaningOrder.Write(this.custInfo.PhoneNumber);
                bnwCleaningOrder.Write(this.depot.OrderDate.ToString());
                bnwCleaningOrder.Write(this.depot.OrderTime.ToString());
                bnwCleaningOrder.Write(this.depot.NumberOfShirts.ToString());
                bnwCleaningOrder.Write(this.depot.NumberOfPants.ToString());
                bnwCleaningOrder.Write(this.depot.NumberOtherItems.ToString());
                bnwCleaningOrder.Write(this.depot.PriceOneShirt.ToString());
                bnwCleaningOrder.Write(this.depot.PriceAPairOfPants.ToString());
                bnwCleaningOrder.Write(this.depot.PriceOtherItems.ToString());
                bnwCleaningOrder.Write(this.depot.TaxRate.ToString());
                bnwCleaningOrder.Write(this.depot.SubTotalShirts.ToString());
                bnwCleaningOrder.Write(this.depot.SubTotalPants.ToString());
                bnwCleaningOrder.Write(this.depot.SubTotalOtherItems.ToString());
                bnwCleaningOrder.Write(this.depot.TotalOrder.ToString());
                bnwCleaningOrder.Write(this.depot.TaxAmount.ToString());
                bnwCleaningOrder.Write(this.depot.SalesTotal.ToString());
            }
        }
    }
  4. Pour créer une nouvelle classe, dans Explorateur de solution, droit-cliquez GeorgetownCleaningOrder6- > Ajouter - > classe…
  5. Placez le nom CleaningRetrieval et appuyez enter
  6. Changez le fichier comme suit :
     
    using System;
    using System.IO;
    
    namespace GeorgetownCleaningServices6
    {
        public class CleaningRetrieval
        {
            private Customer custInfo;
            private CleaningOrderDetails depot;
            private string strPhoneNumber;
    
            public CleaningRetrieval()
            {
                this.custInfo = new Customer();
                this.depot = new CleaningOrderDetails();
            }
    
            public virtual void Open()
            {
                Console.Write("Enter Receipt Number: ");
                string strFilename = Console.ReadLine();
    
                string strPath = @"C:\Georgetown Cleaning Services\Cleaning Orders\" +
                                 @"\" + strFilename + @"\" + strFilename + ".gcs";
    
                DirectoryInfo di =
             new DirectoryInfo(@"C:\Georgetown Cleaning Services\Cleaning Orders");
                FileInfo[] aryFiles = di.GetFiles("*", SearchOption.AllDirectories);
    
                string strFileFullname = "";
                bool found = false;
    
                foreach (FileInfo fle in aryFiles)
                {
                    if (fle.Name == (strFilename + ".gcs"))
                    {
                        found = true;
                        strFileFullname = fle.FullName;
                    }
                }
    
                if (found == true)
                {
                    FileStream stmCleaningOrder =
                                       File.Open(strFileFullname,
                                                 FileMode.Open,
                                                 FileAccess.Read);
                    BinaryReader bnrCleaningOrder = 
    			new BinaryReader(stmCleaningOrder);
                    this.custInfo.Name = bnrCleaningOrder.ReadString();
                    this.custInfo.PhoneNumber = bnrCleaningOrder.ReadString();
                    this.depot.OrderDate = 
    			DateTime.Parse(bnrCleaningOrder.ReadString());
                    this.depot.OrderTime = 
    			DateTime.Parse(bnrCleaningOrder.ReadString());
                    this.depot.NumberOfShirts =
    			uint.Parse(bnrCleaningOrder.ReadString());
                    this.depot.NumberOfPants = 
    			uint.Parse(bnrCleaningOrder.ReadString());
                    this.depot.NumberOtherItems = 
    			uint.Parse(bnrCleaningOrder.ReadString());
                    this.depot.PriceOneShirt = 
    			decimal.Parse(bnrCleaningOrder.ReadString());
                    this.depot.PriceAPairOfPants = 
    			decimal.Parse(bnrCleaningOrder.ReadString());
                    this.depot.PriceOtherItems = 
    			decimal.Parse(bnrCleaningOrder.ReadString());
                    this.depot.TaxRate = 
    			decimal.Parse(bnrCleaningOrder.ReadString());
                    this.depot.SubTotalShirts = 
    			decimal.Parse(bnrCleaningOrder.ReadString());
                    this.depot.SubTotalPants = 
    			decimal.Parse(bnrCleaningOrder.ReadString());
                    this.depot.SubTotalOtherItems = 
    			decimal.Parse(bnrCleaningOrder.ReadString());
                    this.depot.TotalOrder = 
    			decimal.Parse(bnrCleaningOrder.ReadString());
                    this.depot.TaxAmount = 
    			decimal.Parse(bnrCleaningOrder.ReadString());
                    this.depot.SalesTotal = 
    			decimal.Parse(bnrCleaningOrder.ReadString());
    
                    this.strPhoneNumber = "(" + 
    				      this.custInfo.PhoneNumber.Substring(0, 3) +
                                          ") " + 
    				      this.custInfo.PhoneNumber.Substring(3, 3) +
                                          "-" + 
    				      this.custInfo.PhoneNumber.Substring(6, 4);
                    this.ShowReceipt();
                }
                else
                    Console.WriteLine("No cleaning order of " +
    				  "that receipt number was found");
            }
    
            public void ShowReceipt()
            {
                Console.WriteLine();
                // Display the receipt
                Console.WriteLine("====================================");
                Console.WriteLine("-/- Georgetown Cleaning Services -/-");
                Console.WriteLine("====================================");
                Console.WriteLine("Customer:    {0}", this.custInfo.Name);
                Console.WriteLine("Home Phone:  {0}", this.custInfo.PhoneNumber);
                Console.WriteLine("Order Date:  {0:D}", this.depot.OrderDate);
                Console.WriteLine("Order Time:  {0:t}", this.depot.OrderTime);
                Console.WriteLine("------------------------------------");
                Console.WriteLine("Item Type   Qty Unit/Price Sub-Total");
                Console.WriteLine("------------------------------------");
                Console.WriteLine("Shirts      {0,3}   {1,4}      {2,6}",
                                  this.depot.NumberOfShirts,
                                  this.depot.PriceOneShirt,
                                  this.depot.SubTotalShirts);
                Console.WriteLine("Pants       {0,3}   {1,4}      {2,6}",
                                 this.depot.NumberOfPants,
                                 this.depot.PriceAPairOfPants,
                                 this.depot.SubTotalPants);
                Console.WriteLine("Other Items {0,3}   {1,4}      {2,6}",
                                  this.depot.NumberOtherItems,
                                  this.depot.PriceOtherItems,
                                  this.depot.SubTotalOtherItems);
                Console.WriteLine("------------------------------------");
                Console.WriteLine("Total Order:   {0,6}",
                                  this.depot.TotalOrder.ToString("C"));
                Console.WriteLine("Tax Rate:      {0,6}",
                                  this.depot.TaxRate.ToString("P"));
                Console.WriteLine("Tax Amount:    {0,6}",
                                  this.depot.TaxAmount.ToString("C"));
                Console.WriteLine("Net Price:     {0,6}",
                                  this.depot.SalesTotal.ToString("C"));
                Console.WriteLine("====================================");
            }
        }
    }
  7. Accédez au fichier Program.cs et changez le comme suit :
     
    using System;
    
    namespace GeorgetownCleaningServices6
    {
        class Program
        {
            static int Main(string[] args)
            {
                char answer = 'q';
    
                Console.WriteLine("Is this a new order or the customer is " +
                                  "retrieving items previously left for cleaning?");
                Console.WriteLine("0. Quit");
                Console.WriteLine("1. This is a new order");
                Console.WriteLine("2. The customer is retrieving an existing order");
                Console.Write("Your Choice: ");
                answer = char.Parse(Console.ReadLine());
    
                switch (answer)
                {
                    case '1':
                        CleaningDeposit depotOrder = new CleaningDeposit();
                        depotOrder.ProcessOrder();
                        break;
    
                    case '2':
                        CleaningRetrieval previousOrder = new CleaningRetrieval();
                        previousOrder.Open();
                        break;
    
                    default:
                        break;
                }
    
                Console.WriteLine();
                return 0;
            }
        }
    }
  8. Exécutez l'application et l'examiner. Voici un exemple :
     
    Is this a new order or the customer is retrieving 
    items previously left for cleaning?
    0. Quit
    1. This is a new order
    2. The customer is retrieving an existing order
    Your Choice: 0
    
    Press any key to continue . . .
  9. Fermez la fenêtre DOS
  10. Exécutez l'application et créez un nouvel ordre. Voici un exemple :
     
    Is this a new order or the customer is retrieving 
    items previously left for cleaning?
    0. Quit
    1. This is a new order
    2. The customer is retrieving an existing order
    Your Choice: 1
    -/- Georgetown Cleaning Services -/-
    Enter Customer Phone Number: 202 103 0443
    It looks like this is the first time you are trusting 
    us with your cleaning order
    Enter Customer Name: Arsene Cranston
    Enter the order date(mm/dd/yyyy):  11/20/2006
    Enter the order time(hh:mm AM/PM): 08:12 AM
    Number of Shirts:      6
    Number of Pants:       4
    Number of Other Items: 2
    
    The Total order is: $28.13
    Amount Tended? 30
    
    ====================================
    -/- Georgetown Cleaning Services -/-
    ====================================
    Customer:    Arsene Cranston
    Home Phone:  2021030443
    Order Date:  Monday, November 20, 2006
    Order Time:  8:12 AM
    ------------------------------------
    Item Type    Qty Unit/Price Sub-Total
    ------------------------------------
    Shirts        6   0.95        5.70
    Pants         4   2.95       11.80
    Other Items   2   4.55        9.10
    ------------------------------------
    Total Order:   $26.60
    Tax Rate:      5.75 %
    Tax Amount:     $1.53
    Net Price:     $28.13
    ------------------------------------
    Amount Tended: $30.00
    Difference:     $1.87
    ====================================
    
    Press any key to continue . . .
  11.  Rappelez vous de la date où vous avez fournie et fermé la fenêtre DOS
  12. Exécutez l'application et créer un nouvel ordre. Voici un exemple :
     
    Is this a new order or the customer is retrieving items 
    previously left for cleaning?
    0. Quit
    1. This is a new order
    2. The customer is retrieving an existing order
    Your Choice: 1
    -/- Georgetown Cleaning Services -/-
    Enter Customer Phone Number: 301-022-1077
    It looks like this is the first time you are trusting 
    us with your cleaning order
    Enter Customer Name: Helene Craft
    Enter the order date(mm/dd/yyyy):  11/21/2006
    Enter the order time(hh:mm AM/PM): 9:25
    Number of Shirts:      3
    Number of Pants:       0
    Number of Other Items: 5
    
    The Total order is: $27.07
    Amount Tended? 40
    
    ====================================
    -/- Georgetown Cleaning Services -/-
    ====================================
    Customer:    Helene Craft
    Home Phone:  3010221077
    Order Date:  Tuesday, November 21, 2006
    Order Time:  9:25 AM
    ------------------------------------
    Item Type    Qty Unit/Price Sub-Total
    ------------------------------------
    Shirts        3   0.95        2.85
    Pants         0   2.95        0.00
    Other Items   5   4.55       22.75
    ------------------------------------
    Total Order:   $25.60
    Tax Rate:      5.75 %
    Tax Amount:     $1.47
    Net Price:     $27.07
    ------------------------------------
    Amount Tended: $40.00
    Difference:    $12.93
    ====================================
    
    Press any key to continue . . .
  13. Rappelez vous de la date où vous avez fournie et fermé la fenêtre DOS
  14. Exécutez l'application et choisissez d'ouvrir un ordre existant. Voici un exemple :
     
    Is this a new order or the customer is retrieving 
    items previously left for cleaning?
    0. Quit
    1. This is a new order
    2. The customer is retrieving an existing order
    Your Choice: 2
    Enter Receipt Number: 11202006
    
    ====================================
    -/- Georgetown Cleaning Services -/-
    ====================================
    Customer:    Arsene Cranston
    Home Phone:  2021030443
    Order Date:  Monday, November 20, 2006
    Order Time:  8:12 AM
    ------------------------------------
    Item Type   Qty Unit/Price Sub-Total
    ------------------------------------
    Shirts        6   0.95        5.70
    Pants         4   2.95       11.80
    Other Items   2   4.55        9.10
    ------------------------------------
    Total Order:   $26.60
    Tax Rate:      5.75 %
    Tax Amount:     $1.53
    Net Price:     $28.13
    ====================================
    
    Press any key to continue . . .
  15. Fermez la fenêtre DOS
 

Précédent Copyright © 2007, Yevol