2016-05-03 10 views
0

私は薬局プロジェクトをC# で作成しようとしています。患者の病気を診断し、適切な治療薬を印刷するコードを書いています。既に私の薬局に入っているかどうか(利用可能な薬は別のクラスで定義されています) もし存在すればプログラムはそれを販売方​​法に渡し、存在しなければリストに追加して注文することができます後で 問題が複数回リストに追加された項目

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace pharmacy 
{ 
class OrganSystems 
    { 
    protected string[,] GastSystem; 

    public void GastDefine() 
    { 
     GastSystem = new string[3, 4]; 
     GastSystem[0, 0] = "Gastroparesis"; 
     GastSystem[0, 1] = "-Nausea \n-Vomiting \n-An early feeling of fullness when eating \n-Weight loss " + 
      "\n-Abdominal bloating \n-Abdominal discomfort"; 
     GastSystem[0, 2] = "Premperan"; 
     GastSystem[0, 3] = "--Follow the doctor's instructions--"; 

     GastSystem[1, 0] = "Heartburn"; 
     GastSystem[1, 1] = "-Persistent sore throat \n-Hoarseness \n-Chronic cough \n-Asthma \n-Chest pain " + 
      "\n-Feeling like there is a lump in your throat"; 
     GastSystem[1, 2] = "Salbutamol"; 
     GastSystem[1, 3] = "--Follow the doctor's instructions--"; 

     GastSystem[2, 0] = "Acute pancreatitis"; 
     GastSystem[2, 1] = "-Constant pain in the upper abdomen, in the back and other areas \n-" + 
      "Pain may be sudden and intense or may begin as a mild pain that is aggravated by eating and drinking \n-" + 
      "Elevated pulse \n-Fever \n-Nausea and vomiting \n-Swollen and tender abdomen"; 

     GastSystem[2, 2] = "Ganton"; 
     GastSystem[2, 3] = "--Follow the doctor's instructions--"; 

    } 
} 

} 

私は、コードを実行するたびに、それはその器官システム内のすべての病気のすべての薬を追加することが複数回あります
using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.Threading.Tasks; 

     namespace pharmacy 
    { 
class Diagnose:Drugs 
{ 

    public int systemChoice; 
    public Diagnose(int SysCh) 
    { 
     systemChoice = SysCh; 
    } 



    private int DetermineD; 

    public int dDicease 
    { 
     get { return DetermineD; } 
     set { DetermineD = value; } 
    } 


    public void Symptoms() 
    { 

     if (systemChoice == 1) 
     { 
      for (int j = 0; j <= 2; j++) 
      { 
       Console.WriteLine("{0}:\n {1}\n", j + 1, GastSystem[j, 1]); 

      } 

      Console.WriteLine("Are you having any of the following? (Type the number)"); 

      dDicease = int.Parse(Console.ReadLine()); 
      GastDiagnose(); 

     } 

     else if (systemChoice == 2) 
     { 
      for (int j = 0; j <= 2; j++) 
      { 
       Console.WriteLine("{0}:\n {1}\n", j + 1, RespSystem[j, 1]); 

      } 

      Console.WriteLine("Are you having any of the following? (Type the number)"); 

      dDicease = int.Parse(Console.ReadLine()); 
      RespDiagnose(); 

     } 

     else if (systemChoice == 3) 
     { 
      for (int j = 0; j < 2; j++) 
      { 
       Console.WriteLine("{0}:\n {1}\n", j + 1, CardSystem[j, 1]); 

      } 
      Console.WriteLine("Are you having any of the following? (Type the number)"); 

      dDicease = int.Parse(Console.ReadLine()); 
      CardDiagnose(); 


     } 

     else if (systemChoice == 4) 
     { 
      for (int j = 0; j < 2; j++) 
      { 
       Console.WriteLine("{0}:\n {1}\n", j + 1, EyeSystem[j, 1]); 

      } 

      Console.WriteLine("Are you having any of the following? (Type the number)"); 

      dDicease = int.Parse(Console.ReadLine()); 
      EyeDiagnose(); 
     } 

     else if (systemChoice == 5) 
     { 
      for (int j = 0; j <= 2; j++) 
      { 
       Console.WriteLine("{0}:\n {1}\n", j + 1, ENTSystem[j, 1]); 

      } 

      Console.WriteLine("Are you having any of the following? (Type the number)"); 

      dDicease = int.Parse(Console.ReadLine()); 
      ENTDiagnose(); 
     } 
    } 




    public void GastDiagnose() 
    { 

     switch (dDicease) 
     { 

      case 1: 
       Console.WriteLine("Dicease: {0}\nTreatment: {1}\nDrug: {2}\n\n-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-", 
         GastSystem[0, 0], GastSystem[0, 2], GastSystem[0, 3]); break; 
      case 2: 
       Console.WriteLine("Dicease: {0}\nTreatment: {1}\nDrug: {2}\n\n-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-", 
         GastSystem[1, 0], GastSystem[1, 2], GastSystem[1, 3]); break; 

      case 3: 
       Console.WriteLine("Dicease: {0}\nTreatment: {1}\nDrug: {2}\n\n-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-", 
         GastSystem[2, 0], GastSystem[2, 2], GastSystem[2, 3]); break; 

      default: 
       Console.WriteLine("\n\nNOT A VALID ENTRY!\n\nPlease choose the signs that match your state the best\n----------------"); 

       break; 

     } 

    } 

    public void RespDiagnose() 
    { 

     switch (dDicease) 
     { 

      case 1: 
       Console.WriteLine("Dicease: {0}\nTreatment: {1}\nDrug: {2}\n\n-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-", 
         RespSystem[0, 0], RespSystem[0, 2], RespSystem[0, 3]); break; 
      case 2: 
       Console.WriteLine("Dicease: {0}\nTreatment: {1}\nDrug: {2}\n\n-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-", 
         RespSystem[1, 0], RespSystem[1, 2], RespSystem[1, 3]); break; 

      case 3: 
       Console.WriteLine("Dicease: {0}\nTreatment: {1}\nDrug: {2}\n\n-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-", 
         RespSystem[2, 0], RespSystem[2, 2], RespSystem[2, 3]); break; 

      default: 
       Console.WriteLine("\n\nNOT A VALID ENTRY!\n\nPlease choose the signs that match your state the best\n----------------"); 
       Symptoms(); 
       break; 

     } 

    } 


    public void CardDiagnose() 
    { 

     switch (dDicease) 
     { 

      case 1: 
       Console.WriteLine("Dicease: {0}\nTreatment: {1}\nDrug: {2}\n\n-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-", 
         CardSystem[0, 0], CardSystem[0, 2], CardSystem[0, 3]); break; 
      case 2: 
       Console.WriteLine("Dicease: {0}\nTreatment: {1}\nDrug: {2}\n\n-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-", 
         CardSystem[1, 0], CardSystem[1, 2], CardSystem[1, 3]); break; 

      default: 
       Console.WriteLine("\n\nNOT A VALID ENTRY!\n\nPlease choose the signs that match your state the best\n----------------"); 
       Symptoms(); 
       break; 

     } 

    } 




    public void ENTDiagnose() 
    { 

     switch (dDicease) 
     { 

      case 1: 
       Console.WriteLine("Dicease: {0}\nTreatment: {1}\nDrug: {2}\n\n-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-", 
         ENTSystem[0, 0], ENTSystem[0, 2], ENTSystem[0, 3]); break; 
      case 2: 
       Console.WriteLine("Dicease: {0}\nTreatment: {1}\nDrug: {2}\n\n-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-", 
         ENTSystem[1, 0], ENTSystem[1, 2], ENTSystem[1, 3]); break; 

      case 3: 
       Console.WriteLine("Dicease: {0}\nTreatment: {1}\nDrug: {2}\n\n-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-", 
         ENTSystem[2, 0], ENTSystem[2, 2], ENTSystem[2, 3]); break; 

      default: 
       Console.WriteLine("\n\nNOT A VALID ENTRY!\n\nPlease choose the signs that match your state the best\n----------------"); 
       Symptoms(); 
       break; 

     } 

    } 

    public void EyeDiagnose() 
    { 

     switch (dDicease) 
     { 

      case 1: 
       Console.WriteLine("Dicease: {0}\nTreatment: {1}\nDrug: {2}\n\n-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-", 
         EyeSystem[0, 0], EyeSystem[0, 2], EyeSystem[0, 3]); break; 
      case 2: 
       Console.WriteLine("Dicease: {0}\nTreatment: {1}\nDrug: {2}\n\n-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-", 
         EyeSystem[1, 0], EyeSystem[1, 2], EyeSystem[1, 3]); break; 


      default: 
       Console.WriteLine("\n\nNOT A VALID ENTRY!\n\nPlease choose the signs that match your state the best\n----------------"); 
       Symptoms(); 
       break; 

     } 

    } 

    public List<string> ToBeOrdered = new List<string>(); 

    Drugsoperation ON; 

    public void MatchingMed() 
    { 
     getdrugs(); 
     foreach (Druginformation drugInfo in Definnewdrugs) 
     { 
      for (int i = 0; i < 3; i++) 
      { 
       if (systemChoice == 1 && GastSystem[i, 2].Contains(drugInfo.Drugname)) 
       { 
        ON = new Drugsoperation(GastSystem[i, 2]); 
        ON.order(); 
        break; 
       } 
       else if (systemChoice == 1 && !GastSystem[i, 2].Contains(drugInfo.Drugname)) 

        Console.WriteLine("This medicine is not available now, but we will make sure to have it soon."); 
       if (ToBeOrdered.Count < 2) 
       { 
        ToBeOrdered.Add(GastSystem[i, 2]); 
       } 
      } 

      for (int i = 0; i < 3; i++) 
      { 

       if (systemChoice == 2 && RespSystem[i, 2].Contains(drugInfo.Drugname)) 
       { 
        ON = new Drugsoperation(RespSystem[i, 2]); 
        ON.order(); 

       } 
       else if (systemChoice == 2 && !RespSystem[i, 2].Contains(drugInfo.Drugname)) 
       { 
        Console.WriteLine("This medicine is not available now, but we will make sure to have it soon."); 
        ToBeOrdered.Add(RespSystem[i, 2]); 
       } 

      } 

      for (int i = 0; i < 2; i++) 
      { 


       if (systemChoice == 3 && CardSystem[i, 2].Contains(drugInfo.Drugname)) 
       { 
        ON = new Drugsoperation(CardSystem[i, 2]); 
        ON.order(); 
       } 
       else if (systemChoice == 3 && !CardSystem[i, 2].Contains(drugInfo.Drugname)) 
       { 
        Console.WriteLine("This medicine is not available now, but we will make sure to have it soon."); 
        ToBeOrdered.Add(CardSystem[i, 2]); 
       } 
      } 


      for (int i = 0; i < 2; i++) 
      { 

       if (systemChoice == 4 && EyeSystem[i, 2].Contains(drugInfo.Drugname)) 
       { 
        ON = new Drugsoperation(EyeSystem[i, 2]); 
        ON.order(); 

       } 
       else if (systemChoice == 4 && !EyeSystem[i, 2].Contains(drugInfo.Drugname)) 
       { 
        Console.WriteLine("This medicine is not available now, but we will make sure to have it soon."); 
        ToBeOrdered.Add(EyeSystem[i, 2]); 
       } 

      } 

      for (int i = 0; i < 3; i++) 
      { 


       if (systemChoice == 5 && ENTSystem[i, 2].Contains(drugInfo.Drugname)) 
       { 
        ON = new Drugsoperation(ENTSystem[i, 2]); 
        ON.order(); 

       } 
       else if (systemChoice == 5 && !ENTSystem[i, 2].Contains(drugInfo.Drugname)) 
       { 
        Console.WriteLine("This medicine is not available now, but we will make sure to have it soon."); 
        ToBeOrdered.Add(ENTSystem[i, 2]); 
       } 
      } 
     }  

    } 


    public void PrintOrders() 
    { 

     Console.WriteLine("Medicines to be ordered:"); 
     foreach (string OMed in ToBeOrdered) 
     { 
      Console.WriteLine(OMed); 
     } 

    } 
    } 
} 

出力enter image description here

+0

だからあなたの質問は何ですか?それぞれの薬がリストに一度だけ表示される必要がありますか? – CodeNotFound

+0

systemChoiceはどこで定義されていますか? == 1ではないので、常にヒットするならあなたの他のように見え、あなたは薬を見つけられません。 –

+0

はい私はリストに反復薬物を入れたくない ザックM.質問を編集し、クラス全体を追加しました –

答えて

0

このコードは、このような混乱です。暗い魔法のようなもので、このプロジェクトの意味をなす。 リストがある場合は、linqを使用して固有の名前だけを取得します。

list = list.GroupBy(x => x.DrugName).Select(x => x.First()).ToList(); 
1

リストに文字列がすでに含まれているかどうかを確認します。これは簡単に行われます

// If the list of drugs to be ordered does not contain this drug name 
if(!ToBeOrdered.Contains("DrugNameGoesHere") 
{ 
    // Then, add this drug name to the list. 
    ToBeOrdered.Add("DrugNameGoesHere"); 
} 

あなたがここに含まれての詳細を読むことができます:http://www.dotnetperls.com/list-contains

関連する問題